1 // Take a look at the license at the top of the repository in the LICENSE file.
2 
3 use libc::c_int;
4 use std::mem;
5 
6 use glib::translate::*;
7 
8 use glib::prelude::*;
9 use glib::subclass::prelude::*;
10 use glib::Object;
11 
12 use crate::prelude::*;
13 use crate::Allocation;
14 use crate::DragResult;
15 use crate::Inhibit;
16 use crate::Orientation;
17 use crate::SelectionData;
18 use crate::SizeRequestMode;
19 use crate::TextDirection;
20 use crate::Widget;
21 
22 pub trait WidgetImpl: WidgetImplExt + ObjectImpl {
adjust_baseline_allocation(&self, widget: &Self::Type, baseline: &mut i32)23     fn adjust_baseline_allocation(&self, widget: &Self::Type, baseline: &mut i32) {
24         self.parent_adjust_baseline_allocation(widget, baseline)
25     }
26 
adjust_baseline_request( &self, widget: &Self::Type, minimum_baseline: &mut i32, natural_baseline: &mut i32, )27     fn adjust_baseline_request(
28         &self,
29         widget: &Self::Type,
30         minimum_baseline: &mut i32,
31         natural_baseline: &mut i32,
32     ) {
33         self.parent_adjust_baseline_request(widget, minimum_baseline, natural_baseline)
34     }
35 
adjust_size_allocation( &self, widget: &Self::Type, orientation: Orientation, minimum_size: &mut i32, natural_size: &mut i32, allocated_pos: &mut i32, allocated_size: &mut i32, )36     fn adjust_size_allocation(
37         &self,
38         widget: &Self::Type,
39         orientation: Orientation,
40         minimum_size: &mut i32,
41         natural_size: &mut i32,
42         allocated_pos: &mut i32,
43         allocated_size: &mut i32,
44     ) {
45         self.parent_adjust_size_allocation(
46             widget,
47             orientation,
48             minimum_size,
49             natural_size,
50             allocated_pos,
51             allocated_size,
52         )
53     }
54 
adjust_size_request( &self, widget: &Self::Type, orientation: Orientation, minimum_size: &mut i32, natural_size: &mut i32, )55     fn adjust_size_request(
56         &self,
57         widget: &Self::Type,
58         orientation: Orientation,
59         minimum_size: &mut i32,
60         natural_size: &mut i32,
61     ) {
62         self.parent_adjust_size_request(widget, orientation, minimum_size, natural_size)
63     }
64 
button_press_event(&self, widget: &Self::Type, event: &gdk::EventButton) -> Inhibit65     fn button_press_event(&self, widget: &Self::Type, event: &gdk::EventButton) -> Inhibit {
66         self.parent_button_press_event(widget, event)
67     }
68 
button_release_event(&self, widget: &Self::Type, event: &gdk::EventButton) -> Inhibit69     fn button_release_event(&self, widget: &Self::Type, event: &gdk::EventButton) -> Inhibit {
70         self.parent_button_release_event(widget, event)
71     }
72 
child_notify(&self, widget: &Self::Type, child_property: &glib::ParamSpec)73     fn child_notify(&self, widget: &Self::Type, child_property: &glib::ParamSpec) {
74         self.parent_child_notify(widget, child_property)
75     }
76 
composited_changed(&self, widget: &Self::Type)77     fn composited_changed(&self, widget: &Self::Type) {
78         self.parent_composited_changed(widget)
79     }
80 
compute_expand(&self, widget: &Self::Type, hexpand: &mut bool, vexpand: &mut bool)81     fn compute_expand(&self, widget: &Self::Type, hexpand: &mut bool, vexpand: &mut bool) {
82         self.parent_compute_expand(widget, hexpand, vexpand)
83     }
84 
configure_event(&self, widget: &Self::Type, event: &gdk::EventConfigure) -> Inhibit85     fn configure_event(&self, widget: &Self::Type, event: &gdk::EventConfigure) -> Inhibit {
86         self.parent_configure_event(widget, event)
87     }
88 
damage_event(&self, widget: &Self::Type, event: &gdk::EventExpose) -> Inhibit89     fn damage_event(&self, widget: &Self::Type, event: &gdk::EventExpose) -> Inhibit {
90         self.parent_damage_event(widget, event)
91     }
92 
delete_event(&self, widget: &Self::Type, event: &gdk::Event) -> Inhibit93     fn delete_event(&self, widget: &Self::Type, event: &gdk::Event) -> Inhibit {
94         self.parent_delete_event(widget, event)
95     }
96 
destroy(&self, widget: &Self::Type)97     fn destroy(&self, widget: &Self::Type) {
98         self.parent_destroy(widget)
99     }
100 
destroy_event(&self, widget: &Self::Type, event: &gdk::Event) -> Inhibit101     fn destroy_event(&self, widget: &Self::Type, event: &gdk::Event) -> Inhibit {
102         self.parent_destroy_event(widget, event)
103     }
104 
direction_changed(&self, widget: &Self::Type, previous_direction: TextDirection)105     fn direction_changed(&self, widget: &Self::Type, previous_direction: TextDirection) {
106         self.parent_direction_changed(widget, previous_direction)
107     }
108 
dispatch_child_properties_changed(&self, widget: &Self::Type, pspecs: &[glib::ParamSpec])109     fn dispatch_child_properties_changed(&self, widget: &Self::Type, pspecs: &[glib::ParamSpec]) {
110         self.parent_dispatch_child_properties_changed(widget, pspecs)
111     }
112 
drag_begin(&self, widget: &Self::Type, context: &gdk::DragContext)113     fn drag_begin(&self, widget: &Self::Type, context: &gdk::DragContext) {
114         self.parent_drag_begin(widget, context)
115     }
116 
drag_data_delete(&self, widget: &Self::Type, context: &gdk::DragContext)117     fn drag_data_delete(&self, widget: &Self::Type, context: &gdk::DragContext) {
118         self.parent_drag_data_delete(widget, context)
119     }
120 
drag_data_get( &self, widget: &Self::Type, context: &gdk::DragContext, selection_data: &SelectionData, info: u32, time: u32, )121     fn drag_data_get(
122         &self,
123         widget: &Self::Type,
124         context: &gdk::DragContext,
125         selection_data: &SelectionData,
126         info: u32,
127         time: u32,
128     ) {
129         self.parent_drag_data_get(widget, context, selection_data, info, time)
130     }
131 
drag_data_received( &self, widget: &Self::Type, context: &gdk::DragContext, x: i32, y: i32, selection_data: &SelectionData, info: u32, time: u32, )132     fn drag_data_received(
133         &self,
134         widget: &Self::Type,
135         context: &gdk::DragContext,
136         x: i32,
137         y: i32,
138         selection_data: &SelectionData,
139         info: u32,
140         time: u32,
141     ) {
142         self.parent_drag_data_received(widget, context, x, y, selection_data, info, time)
143     }
144 
drag_drop( &self, widget: &Self::Type, context: &gdk::DragContext, x: i32, y: i32, time: u32, ) -> Inhibit145     fn drag_drop(
146         &self,
147         widget: &Self::Type,
148         context: &gdk::DragContext,
149         x: i32,
150         y: i32,
151         time: u32,
152     ) -> Inhibit {
153         self.parent_drag_drop(widget, context, x, y, time)
154     }
155 
drag_end(&self, widget: &Self::Type, context: &gdk::DragContext)156     fn drag_end(&self, widget: &Self::Type, context: &gdk::DragContext) {
157         self.parent_drag_end(widget, context)
158     }
159 
drag_failed( &self, widget: &Self::Type, context: &gdk::DragContext, result: DragResult, ) -> Inhibit160     fn drag_failed(
161         &self,
162         widget: &Self::Type,
163         context: &gdk::DragContext,
164         result: DragResult,
165     ) -> Inhibit {
166         self.parent_drag_failed(widget, context, result)
167     }
168 
drag_leave(&self, widget: &Self::Type, context: &gdk::DragContext, time: u32)169     fn drag_leave(&self, widget: &Self::Type, context: &gdk::DragContext, time: u32) {
170         self.parent_drag_leave(widget, context, time)
171     }
172 
drag_motion( &self, widget: &Self::Type, context: &gdk::DragContext, x: i32, y: i32, time: u32, ) -> Inhibit173     fn drag_motion(
174         &self,
175         widget: &Self::Type,
176         context: &gdk::DragContext,
177         x: i32,
178         y: i32,
179         time: u32,
180     ) -> Inhibit {
181         self.parent_drag_motion(widget, context, x, y, time)
182     }
183 
draw(&self, widget: &Self::Type, cr: &cairo::Context) -> Inhibit184     fn draw(&self, widget: &Self::Type, cr: &cairo::Context) -> Inhibit {
185         self.parent_draw(widget, cr)
186     }
187 
188     // fn can_activate_accel(&self, widget: &Self::Type, signal_id: u32) -> bool {
189     //     self.parent_can_activate_accel(widget, signal_id)
190     // }
191 
request_mode(&self, widget: &Self::Type) -> SizeRequestMode192     fn request_mode(&self, widget: &Self::Type) -> SizeRequestMode {
193         self.parent_request_mode(widget)
194     }
195 
preferred_width(&self, widget: &Self::Type) -> (i32, i32)196     fn preferred_width(&self, widget: &Self::Type) -> (i32, i32) {
197         self.parent_preferred_width(widget)
198     }
199 
200     #[doc(alias = "get_preferred_width_for_height")]
preferred_width_for_height(&self, widget: &Self::Type, height: i32) -> (i32, i32)201     fn preferred_width_for_height(&self, widget: &Self::Type, height: i32) -> (i32, i32) {
202         self.parent_preferred_width_for_height(widget, height)
203     }
204 
preferred_height(&self, widget: &Self::Type) -> (i32, i32)205     fn preferred_height(&self, widget: &Self::Type) -> (i32, i32) {
206         self.parent_preferred_height(widget)
207     }
208 
209     #[doc(alias = "get_preferred_height_for_width")]
preferred_height_for_width(&self, widget: &Self::Type, width: i32) -> (i32, i32)210     fn preferred_height_for_width(&self, widget: &Self::Type, width: i32) -> (i32, i32) {
211         self.parent_preferred_height_for_width(widget, width)
212     }
213 
size_allocate(&self, widget: &Self::Type, allocation: &Allocation)214     fn size_allocate(&self, widget: &Self::Type, allocation: &Allocation) {
215         self.parent_size_allocate(widget, allocation)
216     }
217 
realize(&self, widget: &Self::Type)218     fn realize(&self, widget: &Self::Type) {
219         self.parent_realize(widget);
220     }
221 
unrealize(&self, widget: &Self::Type)222     fn unrealize(&self, widget: &Self::Type) {
223         self.parent_unrealize(widget);
224     }
map(&self, widget: &Self::Type)225     fn map(&self, widget: &Self::Type) {
226         self.parent_map(widget);
227     }
228 
unmap(&self, widget: &Self::Type)229     fn unmap(&self, widget: &Self::Type) {
230         self.parent_unmap(widget);
231     }
232 
motion_notify_event(&self, widget: &Self::Type, event: &gdk::EventMotion) -> Inhibit233     fn motion_notify_event(&self, widget: &Self::Type, event: &gdk::EventMotion) -> Inhibit {
234         self.parent_motion_notify_event(widget, event)
235     }
236 
scroll_event(&self, widget: &Self::Type, event: &gdk::EventScroll) -> Inhibit237     fn scroll_event(&self, widget: &Self::Type, event: &gdk::EventScroll) -> Inhibit {
238         self.parent_scroll_event(widget, event)
239     }
240 
enter_notify_event(&self, widget: &Self::Type, event: &gdk::EventCrossing) -> Inhibit241     fn enter_notify_event(&self, widget: &Self::Type, event: &gdk::EventCrossing) -> Inhibit {
242         self.parent_enter_notify_event(widget, event)
243     }
244 
leave_notify_event(&self, widget: &Self::Type, event: &gdk::EventCrossing) -> Inhibit245     fn leave_notify_event(&self, widget: &Self::Type, event: &gdk::EventCrossing) -> Inhibit {
246         self.parent_leave_notify_event(widget, event)
247     }
248 }
249 
250 pub trait WidgetImplExt: ObjectSubclass {
parent_adjust_baseline_allocation(&self, widget: &Self::Type, baseline: &mut i32)251     fn parent_adjust_baseline_allocation(&self, widget: &Self::Type, baseline: &mut i32);
parent_adjust_baseline_request( &self, widget: &Self::Type, minimum_baseline: &mut i32, natural_baseline: &mut i32, )252     fn parent_adjust_baseline_request(
253         &self,
254         widget: &Self::Type,
255         minimum_baseline: &mut i32,
256         natural_baseline: &mut i32,
257     );
parent_adjust_size_allocation( &self, widget: &Self::Type, orientation: Orientation, minimum_size: &mut i32, natural_size: &mut i32, allocated_pos: &mut i32, allocated_size: &mut i32, )258     fn parent_adjust_size_allocation(
259         &self,
260         widget: &Self::Type,
261         orientation: Orientation,
262         minimum_size: &mut i32,
263         natural_size: &mut i32,
264         allocated_pos: &mut i32,
265         allocated_size: &mut i32,
266     );
parent_adjust_size_request( &self, widget: &Self::Type, orientation: Orientation, minimum_size: &mut i32, natural_size: &mut i32, )267     fn parent_adjust_size_request(
268         &self,
269         widget: &Self::Type,
270         orientation: Orientation,
271         minimum_size: &mut i32,
272         natural_size: &mut i32,
273     );
parent_button_press_event(&self, widget: &Self::Type, event: &gdk::EventButton) -> Inhibit274     fn parent_button_press_event(&self, widget: &Self::Type, event: &gdk::EventButton) -> Inhibit;
parent_button_release_event(&self, widget: &Self::Type, event: &gdk::EventButton) -> Inhibit275     fn parent_button_release_event(&self, widget: &Self::Type, event: &gdk::EventButton)
276         -> Inhibit;
277     // fn parent_can_activate_accel(&self, widget: &Self::Type, signal_id: u32) -> bool;
parent_child_notify(&self, widget: &Self::Type, child_property: &glib::ParamSpec)278     fn parent_child_notify(&self, widget: &Self::Type, child_property: &glib::ParamSpec);
parent_composited_changed(&self, widget: &Self::Type)279     fn parent_composited_changed(&self, widget: &Self::Type);
parent_compute_expand(&self, widget: &Self::Type, hexpand: &mut bool, vexpand: &mut bool)280     fn parent_compute_expand(&self, widget: &Self::Type, hexpand: &mut bool, vexpand: &mut bool);
parent_configure_event(&self, widget: &Self::Type, event: &gdk::EventConfigure) -> Inhibit281     fn parent_configure_event(&self, widget: &Self::Type, event: &gdk::EventConfigure) -> Inhibit;
parent_damage_event(&self, widget: &Self::Type, event: &gdk::EventExpose) -> Inhibit282     fn parent_damage_event(&self, widget: &Self::Type, event: &gdk::EventExpose) -> Inhibit;
parent_delete_event(&self, widget: &Self::Type, event: &gdk::Event) -> Inhibit283     fn parent_delete_event(&self, widget: &Self::Type, event: &gdk::Event) -> Inhibit;
parent_destroy(&self, widget: &Self::Type)284     fn parent_destroy(&self, widget: &Self::Type);
parent_destroy_event(&self, widget: &Self::Type, event: &gdk::Event) -> Inhibit285     fn parent_destroy_event(&self, widget: &Self::Type, event: &gdk::Event) -> Inhibit;
parent_direction_changed(&self, widget: &Self::Type, previous_direction: TextDirection)286     fn parent_direction_changed(&self, widget: &Self::Type, previous_direction: TextDirection);
parent_dispatch_child_properties_changed( &self, widget: &Self::Type, pspecs: &[glib::ParamSpec], )287     fn parent_dispatch_child_properties_changed(
288         &self,
289         widget: &Self::Type,
290         pspecs: &[glib::ParamSpec],
291     );
parent_drag_begin(&self, widget: &Self::Type, context: &gdk::DragContext)292     fn parent_drag_begin(&self, widget: &Self::Type, context: &gdk::DragContext);
parent_drag_data_delete(&self, widget: &Self::Type, context: &gdk::DragContext)293     fn parent_drag_data_delete(&self, widget: &Self::Type, context: &gdk::DragContext);
parent_drag_data_get( &self, widget: &Self::Type, context: &gdk::DragContext, selection_data: &SelectionData, info: u32, time: u32, )294     fn parent_drag_data_get(
295         &self,
296         widget: &Self::Type,
297         context: &gdk::DragContext,
298         selection_data: &SelectionData,
299         info: u32,
300         time: u32,
301     );
parent_drag_data_received( &self, widget: &Self::Type, context: &gdk::DragContext, x: i32, y: i32, selection_data: &SelectionData, info: u32, time: u32, )302     fn parent_drag_data_received(
303         &self,
304         widget: &Self::Type,
305         context: &gdk::DragContext,
306         x: i32,
307         y: i32,
308         selection_data: &SelectionData,
309         info: u32,
310         time: u32,
311     );
parent_drag_drop( &self, widget: &Self::Type, context: &gdk::DragContext, x: i32, y: i32, time: u32, ) -> Inhibit312     fn parent_drag_drop(
313         &self,
314         widget: &Self::Type,
315         context: &gdk::DragContext,
316         x: i32,
317         y: i32,
318         time: u32,
319     ) -> Inhibit;
parent_drag_end(&self, widget: &Self::Type, context: &gdk::DragContext)320     fn parent_drag_end(&self, widget: &Self::Type, context: &gdk::DragContext);
parent_drag_failed( &self, widget: &Self::Type, context: &gdk::DragContext, result: DragResult, ) -> Inhibit321     fn parent_drag_failed(
322         &self,
323         widget: &Self::Type,
324         context: &gdk::DragContext,
325         result: DragResult,
326     ) -> Inhibit;
parent_drag_leave(&self, widget: &Self::Type, context: &gdk::DragContext, time: u32)327     fn parent_drag_leave(&self, widget: &Self::Type, context: &gdk::DragContext, time: u32);
parent_drag_motion( &self, widget: &Self::Type, context: &gdk::DragContext, x: i32, y: i32, time: u32, ) -> Inhibit328     fn parent_drag_motion(
329         &self,
330         widget: &Self::Type,
331         context: &gdk::DragContext,
332         x: i32,
333         y: i32,
334         time: u32,
335     ) -> Inhibit;
parent_draw(&self, widget: &Self::Type, cr: &cairo::Context) -> Inhibit336     fn parent_draw(&self, widget: &Self::Type, cr: &cairo::Context) -> Inhibit;
parent_request_mode(&self, widget: &Self::Type) -> SizeRequestMode337     fn parent_request_mode(&self, widget: &Self::Type) -> SizeRequestMode;
parent_preferred_width(&self, widget: &Self::Type) -> (i32, i32)338     fn parent_preferred_width(&self, widget: &Self::Type) -> (i32, i32);
parent_preferred_width_for_height(&self, widget: &Self::Type, height: i32) -> (i32, i32)339     fn parent_preferred_width_for_height(&self, widget: &Self::Type, height: i32) -> (i32, i32);
parent_preferred_height(&self, widget: &Self::Type) -> (i32, i32)340     fn parent_preferred_height(&self, widget: &Self::Type) -> (i32, i32);
parent_preferred_height_for_width(&self, widget: &Self::Type, width: i32) -> (i32, i32)341     fn parent_preferred_height_for_width(&self, widget: &Self::Type, width: i32) -> (i32, i32);
parent_size_allocate(&self, widget: &Self::Type, allocation: &Allocation)342     fn parent_size_allocate(&self, widget: &Self::Type, allocation: &Allocation);
parent_realize(&self, widget: &Self::Type)343     fn parent_realize(&self, widget: &Self::Type);
parent_unrealize(&self, widget: &Self::Type)344     fn parent_unrealize(&self, widget: &Self::Type);
parent_map(&self, widget: &Self::Type)345     fn parent_map(&self, widget: &Self::Type);
parent_unmap(&self, widget: &Self::Type)346     fn parent_unmap(&self, widget: &Self::Type);
parent_motion_notify_event(&self, widget: &Self::Type, event: &gdk::EventMotion) -> Inhibit347     fn parent_motion_notify_event(&self, widget: &Self::Type, event: &gdk::EventMotion) -> Inhibit;
parent_scroll_event(&self, widget: &Self::Type, event: &gdk::EventScroll) -> Inhibit348     fn parent_scroll_event(&self, widget: &Self::Type, event: &gdk::EventScroll) -> Inhibit;
parent_enter_notify_event(&self, widget: &Self::Type, event: &gdk::EventCrossing) -> Inhibit349     fn parent_enter_notify_event(&self, widget: &Self::Type, event: &gdk::EventCrossing)
350         -> Inhibit;
parent_leave_notify_event(&self, widget: &Self::Type, event: &gdk::EventCrossing) -> Inhibit351     fn parent_leave_notify_event(&self, widget: &Self::Type, event: &gdk::EventCrossing)
352         -> Inhibit;
353 }
354 
355 impl<T: WidgetImpl> WidgetImplExt for T {
parent_adjust_baseline_allocation(&self, widget: &Self::Type, baseline: &mut i32)356     fn parent_adjust_baseline_allocation(&self, widget: &Self::Type, baseline: &mut i32) {
357         unsafe {
358             let data = T::type_data();
359             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
360             let f = (*parent_class)
361                 .adjust_baseline_allocation
362                 .expect("No parent class impl for \"adjust_baseline_allocation\"");
363             f(
364                 widget.unsafe_cast_ref::<Widget>().to_glib_none().0,
365                 baseline,
366             )
367         }
368     }
369 
parent_adjust_baseline_request( &self, widget: &Self::Type, minimum_baseline: &mut i32, natural_baseline: &mut i32, )370     fn parent_adjust_baseline_request(
371         &self,
372         widget: &Self::Type,
373         minimum_baseline: &mut i32,
374         natural_baseline: &mut i32,
375     ) {
376         unsafe {
377             let data = T::type_data();
378             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
379             let f = (*parent_class)
380                 .adjust_baseline_request
381                 .expect("No parent class impl for \"adjust_baseline_request\"");
382             f(
383                 widget.unsafe_cast_ref::<Widget>().to_glib_none().0,
384                 minimum_baseline,
385                 natural_baseline,
386             )
387         }
388     }
389 
parent_adjust_size_allocation( &self, widget: &Self::Type, orientation: Orientation, minimum_size: &mut i32, natural_size: &mut i32, allocated_pos: &mut i32, allocated_size: &mut i32, )390     fn parent_adjust_size_allocation(
391         &self,
392         widget: &Self::Type,
393         orientation: Orientation,
394         minimum_size: &mut i32,
395         natural_size: &mut i32,
396         allocated_pos: &mut i32,
397         allocated_size: &mut i32,
398     ) {
399         unsafe {
400             let data = T::type_data();
401             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
402             let f = (*parent_class)
403                 .adjust_size_allocation
404                 .expect("No parent class impl for \"adjust_size_allocation\"");
405             f(
406                 widget.unsafe_cast_ref::<Widget>().to_glib_none().0,
407                 orientation.into_glib(),
408                 minimum_size,
409                 natural_size,
410                 allocated_pos,
411                 allocated_size,
412             )
413         }
414     }
415 
parent_adjust_size_request( &self, widget: &Self::Type, orientation: Orientation, minimum_size: &mut i32, natural_size: &mut i32, )416     fn parent_adjust_size_request(
417         &self,
418         widget: &Self::Type,
419         orientation: Orientation,
420         minimum_size: &mut i32,
421         natural_size: &mut i32,
422     ) {
423         unsafe {
424             let data = T::type_data();
425             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
426             let f = (*parent_class)
427                 .adjust_size_request
428                 .expect("No parent class impl for \"adjust_size_request\"");
429             f(
430                 widget.unsafe_cast_ref::<Widget>().to_glib_none().0,
431                 orientation.into_glib(),
432                 minimum_size as *mut i32,
433                 natural_size as *mut i32,
434             )
435         }
436     }
437 
parent_button_press_event(&self, widget: &Self::Type, event: &gdk::EventButton) -> Inhibit438     fn parent_button_press_event(&self, widget: &Self::Type, event: &gdk::EventButton) -> Inhibit {
439         unsafe {
440             let data = T::type_data();
441             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
442             if let Some(f) = (*parent_class).button_press_event {
443                 let ev_glib = glib::translate::mut_override(event.to_glib_none().0);
444                 Inhibit(from_glib(f(
445                     widget.unsafe_cast_ref::<Widget>().to_glib_none().0,
446                     ev_glib,
447                 )))
448             } else {
449                 Inhibit(false)
450             }
451         }
452     }
453 
parent_button_release_event( &self, widget: &Self::Type, event: &gdk::EventButton, ) -> Inhibit454     fn parent_button_release_event(
455         &self,
456         widget: &Self::Type,
457         event: &gdk::EventButton,
458     ) -> Inhibit {
459         unsafe {
460             let data = T::type_data();
461             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
462             if let Some(f) = (*parent_class).button_release_event {
463                 let ev_glib = glib::translate::mut_override(event.to_glib_none().0);
464                 Inhibit(from_glib(f(
465                     widget.unsafe_cast_ref::<Widget>().to_glib_none().0,
466                     ev_glib,
467                 )))
468             } else {
469                 Inhibit(false)
470             }
471         }
472     }
473 
474     // fn parent_can_activate_accel(&self, widget: &Self::Type, signal_id: u32) -> bool {
475     //     unsafe {
476     //         let data = T::type_data();
477     //         let parent_class =
478     //             data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
479     //         let f = (*parent_class)
480     //             .can_activate_accel
481     //             .expect("No parent class impl for \"can_activate_accel\"");
482     //         f(widget.unsafe_cast_ref::<Widget>().to_glib_none().0, signal_id) != 0
483     //     }
484     // }
485 
parent_child_notify(&self, widget: &Self::Type, child_property: &glib::ParamSpec)486     fn parent_child_notify(&self, widget: &Self::Type, child_property: &glib::ParamSpec) {
487         unsafe {
488             let data = T::type_data();
489             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
490             if let Some(f) = (*parent_class).child_notify {
491                 let pspec_glib = glib::translate::mut_override(child_property.to_glib_none().0);
492                 f(
493                     widget.unsafe_cast_ref::<Widget>().to_glib_none().0,
494                     pspec_glib,
495                 )
496             }
497         }
498     }
499 
parent_composited_changed(&self, widget: &Self::Type)500     fn parent_composited_changed(&self, widget: &Self::Type) {
501         unsafe {
502             let data = T::type_data();
503             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
504             if let Some(f) = (*parent_class).composited_changed {
505                 f(widget.unsafe_cast_ref::<Widget>().to_glib_none().0)
506             }
507         }
508     }
509 
parent_compute_expand(&self, widget: &Self::Type, hexpand: &mut bool, vexpand: &mut bool)510     fn parent_compute_expand(&self, widget: &Self::Type, hexpand: &mut bool, vexpand: &mut bool) {
511         unsafe {
512             let data = T::type_data();
513             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
514             let widget = widget.unsafe_cast_ref::<Widget>();
515             if let Some(f) = (*parent_class).compute_expand {
516                 let mut hexpand_glib = hexpand.into_glib();
517                 let mut vexpand_glib = vexpand.into_glib();
518                 f(
519                     widget.to_glib_none().0,
520                     &mut hexpand_glib,
521                     &mut vexpand_glib,
522                 );
523                 *hexpand = from_glib(hexpand_glib);
524                 *vexpand = from_glib(vexpand_glib);
525             }
526         }
527     }
528 
parent_configure_event(&self, widget: &Self::Type, event: &gdk::EventConfigure) -> Inhibit529     fn parent_configure_event(&self, widget: &Self::Type, event: &gdk::EventConfigure) -> Inhibit {
530         unsafe {
531             let data = T::type_data();
532             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
533             if let Some(f) = (*parent_class).configure_event {
534                 let ev_glib = glib::translate::mut_override(event.to_glib_none().0);
535                 Inhibit(from_glib(f(
536                     widget.unsafe_cast_ref::<Widget>().to_glib_none().0,
537                     ev_glib,
538                 )))
539             } else {
540                 Inhibit(false)
541             }
542         }
543     }
544 
parent_damage_event(&self, widget: &Self::Type, event: &gdk::EventExpose) -> Inhibit545     fn parent_damage_event(&self, widget: &Self::Type, event: &gdk::EventExpose) -> Inhibit {
546         unsafe {
547             let data = T::type_data();
548             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
549             if let Some(f) = (*parent_class).damage_event {
550                 let ev_glib = glib::translate::mut_override(event.to_glib_none().0);
551                 Inhibit(from_glib(f(
552                     widget.unsafe_cast_ref::<Widget>().to_glib_none().0,
553                     ev_glib,
554                 )))
555             } else {
556                 Inhibit(false)
557             }
558         }
559     }
560 
parent_delete_event(&self, widget: &Self::Type, event: &gdk::Event) -> Inhibit561     fn parent_delete_event(&self, widget: &Self::Type, event: &gdk::Event) -> Inhibit {
562         unsafe {
563             let data = T::type_data();
564             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
565             if let Some(f) = (*parent_class).delete_event {
566                 let ev_glib = glib::translate::mut_override(event.to_glib_none().0);
567                 Inhibit(from_glib(f(
568                     widget.unsafe_cast_ref::<Widget>().to_glib_none().0,
569                     ev_glib,
570                 )))
571             } else {
572                 Inhibit(false)
573             }
574         }
575     }
576 
parent_destroy(&self, widget: &Self::Type)577     fn parent_destroy(&self, widget: &Self::Type) {
578         unsafe {
579             let data = T::type_data();
580             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
581             if let Some(f) = (*parent_class).destroy {
582                 f(widget.unsafe_cast_ref::<Widget>().to_glib_none().0)
583             }
584         }
585     }
586 
parent_destroy_event(&self, widget: &Self::Type, event: &gdk::Event) -> Inhibit587     fn parent_destroy_event(&self, widget: &Self::Type, event: &gdk::Event) -> Inhibit {
588         unsafe {
589             let data = T::type_data();
590             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
591             if let Some(f) = (*parent_class).destroy_event {
592                 let ev_glib = glib::translate::mut_override(event.to_glib_none().0);
593                 Inhibit(from_glib(f(
594                     widget.unsafe_cast_ref::<Widget>().to_glib_none().0,
595                     ev_glib,
596                 )))
597             } else {
598                 Inhibit(false)
599             }
600         }
601     }
602 
parent_direction_changed(&self, widget: &Self::Type, previous_direction: TextDirection)603     fn parent_direction_changed(&self, widget: &Self::Type, previous_direction: TextDirection) {
604         unsafe {
605             let data = T::type_data();
606             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
607             if let Some(f) = (*parent_class).direction_changed {
608                 f(
609                     widget.unsafe_cast_ref::<Widget>().to_glib_none().0,
610                     previous_direction.into_glib(),
611                 )
612             }
613         }
614     }
615 
parent_dispatch_child_properties_changed( &self, widget: &Self::Type, pspecs: &[glib::ParamSpec], )616     fn parent_dispatch_child_properties_changed(
617         &self,
618         widget: &Self::Type,
619         pspecs: &[glib::ParamSpec],
620     ) {
621         unsafe {
622             let data = T::type_data();
623             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
624             if let Some(f) = (*parent_class).dispatch_child_properties_changed {
625                 let mut pspecs_array = pspecs
626                     .iter()
627                     .map(|p| p.to_glib_none().0)
628                     .collect::<Vec<_>>();
629                 let pspecs_ptr = pspecs_array.as_mut_ptr();
630                 f(
631                     widget.unsafe_cast_ref::<Widget>().to_glib_none().0,
632                     pspecs.len() as u32,
633                     pspecs_ptr,
634                 )
635             }
636         }
637     }
638 
parent_drag_begin(&self, widget: &Self::Type, context: &gdk::DragContext)639     fn parent_drag_begin(&self, widget: &Self::Type, context: &gdk::DragContext) {
640         unsafe {
641             let data = T::type_data();
642             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
643             if let Some(f) = (*parent_class).drag_begin {
644                 f(
645                     widget.unsafe_cast_ref::<Widget>().to_glib_none().0,
646                     context.to_glib_none().0,
647                 )
648             }
649         }
650     }
651 
parent_drag_data_delete(&self, widget: &Self::Type, context: &gdk::DragContext)652     fn parent_drag_data_delete(&self, widget: &Self::Type, context: &gdk::DragContext) {
653         unsafe {
654             let data = T::type_data();
655             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
656             if let Some(f) = (*parent_class).drag_data_delete {
657                 f(
658                     widget.unsafe_cast_ref::<Widget>().to_glib_none().0,
659                     context.to_glib_none().0,
660                 )
661             }
662         }
663     }
664 
parent_drag_data_get( &self, widget: &Self::Type, context: &gdk::DragContext, selection_data: &SelectionData, info: u32, time: u32, )665     fn parent_drag_data_get(
666         &self,
667         widget: &Self::Type,
668         context: &gdk::DragContext,
669         selection_data: &SelectionData,
670         info: u32,
671         time: u32,
672     ) {
673         unsafe {
674             let data = T::type_data();
675             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
676             if let Some(f) = (*parent_class).drag_data_get {
677                 let selection_mut = glib::translate::mut_override(selection_data.to_glib_none().0);
678                 f(
679                     widget.unsafe_cast_ref::<Widget>().to_glib_none().0,
680                     context.to_glib_none().0,
681                     selection_mut,
682                     info,
683                     time,
684                 )
685             }
686         }
687     }
688 
parent_drag_data_received( &self, widget: &Self::Type, context: &gdk::DragContext, x: i32, y: i32, selection_data: &SelectionData, info: u32, time: u32, )689     fn parent_drag_data_received(
690         &self,
691         widget: &Self::Type,
692         context: &gdk::DragContext,
693         x: i32,
694         y: i32,
695         selection_data: &SelectionData,
696         info: u32,
697         time: u32,
698     ) {
699         unsafe {
700             let data = T::type_data();
701             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
702             if let Some(f) = (*parent_class).drag_data_received {
703                 let selection_mut = glib::translate::mut_override(selection_data.to_glib_none().0);
704                 f(
705                     widget.unsafe_cast_ref::<Widget>().to_glib_none().0,
706                     context.to_glib_none().0,
707                     x,
708                     y,
709                     selection_mut,
710                     info,
711                     time,
712                 )
713             }
714         }
715     }
716 
parent_drag_drop( &self, widget: &Self::Type, context: &gdk::DragContext, x: i32, y: i32, time: u32, ) -> Inhibit717     fn parent_drag_drop(
718         &self,
719         widget: &Self::Type,
720         context: &gdk::DragContext,
721         x: i32,
722         y: i32,
723         time: u32,
724     ) -> Inhibit {
725         unsafe {
726             let data = T::type_data();
727             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
728             if let Some(f) = (*parent_class).drag_drop {
729                 Inhibit(from_glib(f(
730                     widget.unsafe_cast_ref::<Widget>().to_glib_none().0,
731                     context.to_glib_none().0,
732                     x,
733                     y,
734                     time,
735                 )))
736             } else {
737                 Inhibit(false)
738             }
739         }
740     }
741 
parent_drag_end(&self, widget: &Self::Type, context: &gdk::DragContext)742     fn parent_drag_end(&self, widget: &Self::Type, context: &gdk::DragContext) {
743         unsafe {
744             let data = T::type_data();
745             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
746             if let Some(f) = (*parent_class).drag_end {
747                 f(
748                     widget.unsafe_cast_ref::<Widget>().to_glib_none().0,
749                     context.to_glib_none().0,
750                 )
751             }
752         }
753     }
754 
parent_drag_failed( &self, widget: &Self::Type, context: &gdk::DragContext, result: DragResult, ) -> Inhibit755     fn parent_drag_failed(
756         &self,
757         widget: &Self::Type,
758         context: &gdk::DragContext,
759         result: DragResult,
760     ) -> Inhibit {
761         unsafe {
762             let data = T::type_data();
763             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
764             if let Some(f) = (*parent_class).drag_failed {
765                 Inhibit(from_glib(f(
766                     widget.unsafe_cast_ref::<Widget>().to_glib_none().0,
767                     context.to_glib_none().0,
768                     result.into_glib(),
769                 )))
770             } else {
771                 Inhibit(false)
772             }
773         }
774     }
775 
parent_drag_leave(&self, widget: &Self::Type, context: &gdk::DragContext, time: u32)776     fn parent_drag_leave(&self, widget: &Self::Type, context: &gdk::DragContext, time: u32) {
777         unsafe {
778             let data = T::type_data();
779             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
780             if let Some(f) = (*parent_class).drag_leave {
781                 f(
782                     widget.unsafe_cast_ref::<Widget>().to_glib_none().0,
783                     context.to_glib_none().0,
784                     time,
785                 )
786             }
787         }
788     }
789 
parent_drag_motion( &self, widget: &Self::Type, context: &gdk::DragContext, x: i32, y: i32, time: u32, ) -> Inhibit790     fn parent_drag_motion(
791         &self,
792         widget: &Self::Type,
793         context: &gdk::DragContext,
794         x: i32,
795         y: i32,
796         time: u32,
797     ) -> Inhibit {
798         unsafe {
799             let data = T::type_data();
800             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
801             if let Some(f) = (*parent_class).drag_motion {
802                 Inhibit(from_glib(f(
803                     widget.unsafe_cast_ref::<Widget>().to_glib_none().0,
804                     context.to_glib_none().0,
805                     x,
806                     y,
807                     time,
808                 )))
809             } else {
810                 Inhibit(false)
811             }
812         }
813     }
814 
parent_draw(&self, widget: &Self::Type, cr: &cairo::Context) -> Inhibit815     fn parent_draw(&self, widget: &Self::Type, cr: &cairo::Context) -> Inhibit {
816         unsafe {
817             let data = T::type_data();
818             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
819             if let Some(f) = (*parent_class).draw {
820                 Inhibit(from_glib(f(
821                     widget.unsafe_cast_ref::<Widget>().to_glib_none().0,
822                     cr.to_glib_none().0,
823                 )))
824             } else {
825                 Inhibit(false)
826             }
827         }
828     }
829 
parent_request_mode(&self, widget: &Self::Type) -> SizeRequestMode830     fn parent_request_mode(&self, widget: &Self::Type) -> SizeRequestMode {
831         unsafe {
832             let data = T::type_data();
833             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
834             let f = (*parent_class).get_request_mode.unwrap();
835             from_glib(f(widget.unsafe_cast_ref::<Widget>().to_glib_none().0))
836         }
837     }
838 
parent_preferred_width(&self, widget: &Self::Type) -> (i32, i32)839     fn parent_preferred_width(&self, widget: &Self::Type) -> (i32, i32) {
840         unsafe {
841             let data = T::type_data();
842             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
843             let f = (*parent_class).get_preferred_width.unwrap();
844 
845             let mut minimum_size = mem::MaybeUninit::uninit();
846             let mut natural_size = mem::MaybeUninit::uninit();
847             f(
848                 widget.unsafe_cast_ref::<Widget>().to_glib_none().0,
849                 minimum_size.as_mut_ptr(),
850                 natural_size.as_mut_ptr(),
851             );
852             (minimum_size.assume_init(), natural_size.assume_init())
853         }
854     }
855 
parent_preferred_width_for_height(&self, widget: &Self::Type, height: i32) -> (i32, i32)856     fn parent_preferred_width_for_height(&self, widget: &Self::Type, height: i32) -> (i32, i32) {
857         unsafe {
858             let data = T::type_data();
859             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
860             let f = (*parent_class).get_preferred_width_for_height.unwrap();
861 
862             let mut minimum_size = mem::MaybeUninit::uninit();
863             let mut natural_size = mem::MaybeUninit::uninit();
864             f(
865                 widget.unsafe_cast_ref::<Widget>().to_glib_none().0,
866                 height,
867                 minimum_size.as_mut_ptr(),
868                 natural_size.as_mut_ptr(),
869             );
870             (minimum_size.assume_init(), natural_size.assume_init())
871         }
872     }
parent_preferred_height(&self, widget: &Self::Type) -> (i32, i32)873     fn parent_preferred_height(&self, widget: &Self::Type) -> (i32, i32) {
874         unsafe {
875             let data = T::type_data();
876             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
877             let f = (*parent_class).get_preferred_height.unwrap();
878             let mut minimum_size = mem::MaybeUninit::uninit();
879             let mut natural_size = mem::MaybeUninit::uninit();
880             f(
881                 widget.unsafe_cast_ref::<Widget>().to_glib_none().0,
882                 minimum_size.as_mut_ptr(),
883                 natural_size.as_mut_ptr(),
884             );
885             (minimum_size.assume_init(), natural_size.assume_init())
886         }
887     }
parent_preferred_height_for_width(&self, widget: &Self::Type, width: i32) -> (i32, i32)888     fn parent_preferred_height_for_width(&self, widget: &Self::Type, width: i32) -> (i32, i32) {
889         unsafe {
890             let data = T::type_data();
891             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
892             let f = (*parent_class).get_preferred_height_for_width.unwrap();
893             let mut minimum_size = mem::MaybeUninit::uninit();
894             let mut natural_size = mem::MaybeUninit::uninit();
895             f(
896                 widget.unsafe_cast_ref::<Widget>().to_glib_none().0,
897                 width,
898                 minimum_size.as_mut_ptr(),
899                 natural_size.as_mut_ptr(),
900             );
901             (minimum_size.assume_init(), natural_size.assume_init())
902         }
903     }
904 
parent_size_allocate(&self, widget: &Self::Type, allocation: &Allocation)905     fn parent_size_allocate(&self, widget: &Self::Type, allocation: &Allocation) {
906         unsafe {
907             let data = T::type_data();
908             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
909             let f = (*parent_class)
910                 .size_allocate
911                 .expect("No parent class impl for \"size_allocate\"");
912             f(
913                 widget.unsafe_cast_ref::<Widget>().to_glib_none().0,
914                 mut_override(allocation.to_glib_none().0),
915             );
916         }
917     }
918 
parent_realize(&self, widget: &Self::Type)919     fn parent_realize(&self, widget: &Self::Type) {
920         unsafe {
921             let data = T::type_data();
922             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
923             if let Some(f) = (*parent_class).realize {
924                 f(widget.unsafe_cast_ref::<Widget>().to_glib_none().0);
925             }
926         }
927     }
928 
parent_unrealize(&self, widget: &Self::Type)929     fn parent_unrealize(&self, widget: &Self::Type) {
930         unsafe {
931             let data = T::type_data();
932             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
933             if let Some(f) = (*parent_class).unrealize {
934                 f(widget.unsafe_cast_ref::<Widget>().to_glib_none().0);
935             }
936         }
937     }
938 
parent_map(&self, widget: &Self::Type)939     fn parent_map(&self, widget: &Self::Type) {
940         unsafe {
941             let data = T::type_data();
942             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
943             if let Some(f) = (*parent_class).map {
944                 f(widget.unsafe_cast_ref::<Widget>().to_glib_none().0);
945             }
946         }
947     }
948 
parent_unmap(&self, widget: &Self::Type)949     fn parent_unmap(&self, widget: &Self::Type) {
950         unsafe {
951             let data = T::type_data();
952             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
953             if let Some(f) = (*parent_class).unmap {
954                 f(widget.unsafe_cast_ref::<Widget>().to_glib_none().0);
955             }
956         }
957     }
958 
parent_motion_notify_event(&self, widget: &Self::Type, event: &gdk::EventMotion) -> Inhibit959     fn parent_motion_notify_event(&self, widget: &Self::Type, event: &gdk::EventMotion) -> Inhibit {
960         unsafe {
961             let data = T::type_data();
962             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
963             if let Some(f) = (*parent_class).motion_notify_event {
964                 Inhibit(from_glib(f(
965                     widget.unsafe_cast_ref::<Widget>().to_glib_none().0,
966                     mut_override(event.to_glib_none().0),
967                 )))
968             } else {
969                 Inhibit(false)
970             }
971         }
972     }
973 
parent_scroll_event(&self, widget: &Self::Type, event: &gdk::EventScroll) -> Inhibit974     fn parent_scroll_event(&self, widget: &Self::Type, event: &gdk::EventScroll) -> Inhibit {
975         unsafe {
976             let data = T::type_data();
977             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
978             if let Some(f) = (*parent_class).scroll_event {
979                 Inhibit(from_glib(f(
980                     widget.unsafe_cast_ref::<Widget>().to_glib_none().0,
981                     mut_override(event.to_glib_none().0),
982                 )))
983             } else {
984                 Inhibit(false)
985             }
986         }
987     }
988 
parent_enter_notify_event( &self, widget: &Self::Type, event: &gdk::EventCrossing, ) -> Inhibit989     fn parent_enter_notify_event(
990         &self,
991         widget: &Self::Type,
992         event: &gdk::EventCrossing,
993     ) -> Inhibit {
994         unsafe {
995             let data = T::type_data();
996             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
997             if let Some(f) = (*parent_class).enter_notify_event {
998                 Inhibit(from_glib(f(
999                     widget.unsafe_cast_ref::<Widget>().to_glib_none().0,
1000                     mut_override(event.to_glib_none().0),
1001                 )))
1002             } else {
1003                 Inhibit(false)
1004             }
1005         }
1006     }
1007 
parent_leave_notify_event( &self, widget: &Self::Type, event: &gdk::EventCrossing, ) -> Inhibit1008     fn parent_leave_notify_event(
1009         &self,
1010         widget: &Self::Type,
1011         event: &gdk::EventCrossing,
1012     ) -> Inhibit {
1013         unsafe {
1014             let data = T::type_data();
1015             let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1016             if let Some(f) = (*parent_class).leave_notify_event {
1017                 Inhibit(from_glib(f(
1018                     widget.unsafe_cast_ref::<Widget>().to_glib_none().0,
1019                     mut_override(event.to_glib_none().0),
1020                 )))
1021             } else {
1022                 Inhibit(false)
1023             }
1024         }
1025     }
1026 }
1027 
1028 unsafe impl<T: WidgetImpl> IsSubclassable<T> for Widget {
class_init(class: &mut ::glib::Class<Self>)1029     fn class_init(class: &mut ::glib::Class<Self>) {
1030         <Object as IsSubclassable<T>>::class_init(class);
1031 
1032         let klass = class.as_mut();
1033         klass.adjust_baseline_allocation = Some(widget_adjust_baseline_allocation::<T>);
1034         klass.adjust_baseline_request = Some(widget_adjust_baseline_request::<T>);
1035         klass.adjust_size_allocation = Some(widget_adjust_size_allocation::<T>);
1036         klass.adjust_size_request = Some(widget_adjust_size_request::<T>);
1037         klass.button_press_event = Some(widget_button_press_event::<T>);
1038         klass.button_release_event = Some(widget_button_release_event::<T>);
1039         // klass.can_activate_accel = Some(widget_can_activate_accel::<T>);
1040         klass.child_notify = Some(widget_child_notify::<T>);
1041         klass.composited_changed = Some(widget_composited_changed::<T>);
1042         klass.compute_expand = Some(widget_compute_expand::<T>);
1043         klass.configure_event = Some(widget_configure_event::<T>);
1044         klass.damage_event = Some(widget_damage_event::<T>);
1045         klass.delete_event = Some(widget_delete_event::<T>);
1046         klass.destroy = Some(widget_destroy::<T>);
1047         klass.destroy_event = Some(widget_destroy_event::<T>);
1048         klass.direction_changed = Some(widget_direction_changed::<T>);
1049         klass.dispatch_child_properties_changed =
1050             Some(widget_dispatch_child_properties_changed::<T>);
1051         klass.drag_begin = Some(widget_drag_begin::<T>);
1052         klass.drag_data_delete = Some(widget_drag_data_delete::<T>);
1053         klass.drag_data_get = Some(widget_drag_data_get::<T>);
1054         klass.drag_data_received = Some(widget_drag_data_received::<T>);
1055         klass.drag_drop = Some(widget_drag_drop::<T>);
1056         klass.drag_end = Some(widget_drag_end::<T>);
1057         klass.drag_failed = Some(widget_drag_failed::<T>);
1058         klass.drag_leave = Some(widget_drag_leave::<T>);
1059         klass.drag_motion = Some(widget_drag_motion::<T>);
1060         klass.draw = Some(widget_draw::<T>);
1061         klass.get_request_mode = Some(widget_get_request_mode::<T>);
1062         klass.get_preferred_width = Some(widget_get_preferred_width::<T>);
1063         klass.get_preferred_height_for_width = Some(widget_get_preferred_height_for_width::<T>);
1064         klass.get_preferred_height = Some(widget_get_preferred_height::<T>);
1065         klass.get_preferred_width_for_height = Some(widget_get_preferred_width_for_height::<T>);
1066         klass.size_allocate = Some(widget_size_allocate::<T>);
1067         klass.realize = Some(widget_realize::<T>);
1068         klass.unrealize = Some(widget_unrealize::<T>);
1069         klass.map = Some(widget_map::<T>);
1070         klass.unmap = Some(widget_unmap::<T>);
1071         klass.motion_notify_event = Some(widget_motion_notify_event::<T>);
1072         klass.scroll_event = Some(widget_scroll_event::<T>);
1073         klass.enter_notify_event = Some(widget_enter_notify_event::<T>);
1074         klass.leave_notify_event = Some(widget_leave_notify_event::<T>);
1075     }
1076 
instance_init(instance: &mut glib::subclass::InitializingObject<T>)1077     fn instance_init(instance: &mut glib::subclass::InitializingObject<T>) {
1078         <Object as IsSubclassable<T>>::instance_init(instance);
1079     }
1080 }
1081 
widget_adjust_baseline_allocation<T: WidgetImpl>( ptr: *mut ffi::GtkWidget, baseptr: *mut i32, )1082 unsafe extern "C" fn widget_adjust_baseline_allocation<T: WidgetImpl>(
1083     ptr: *mut ffi::GtkWidget,
1084     baseptr: *mut i32,
1085 ) {
1086     let instance = &*(ptr as *mut T::Instance);
1087     let imp = instance.impl_();
1088     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1089 
1090     imp.adjust_baseline_allocation(wrap.unsafe_cast_ref(), &mut *baseptr)
1091 }
1092 
widget_adjust_baseline_request<T: WidgetImpl>( ptr: *mut ffi::GtkWidget, minptr: *mut i32, natptr: *mut i32, )1093 unsafe extern "C" fn widget_adjust_baseline_request<T: WidgetImpl>(
1094     ptr: *mut ffi::GtkWidget,
1095     minptr: *mut i32,
1096     natptr: *mut i32,
1097 ) {
1098     let instance = &*(ptr as *mut T::Instance);
1099     let imp = instance.impl_();
1100     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1101 
1102     imp.adjust_baseline_request(wrap.unsafe_cast_ref(), &mut *minptr, &mut *natptr)
1103 }
1104 
widget_adjust_size_allocation<T: WidgetImpl>( ptr: *mut ffi::GtkWidget, orientation: ffi::GtkOrientation, minptr: *mut i32, natptr: *mut i32, posptr: *mut i32, sizeptr: *mut i32, )1105 unsafe extern "C" fn widget_adjust_size_allocation<T: WidgetImpl>(
1106     ptr: *mut ffi::GtkWidget,
1107     orientation: ffi::GtkOrientation,
1108     minptr: *mut i32,
1109     natptr: *mut i32,
1110     posptr: *mut i32,
1111     sizeptr: *mut i32,
1112 ) {
1113     let instance = &*(ptr as *mut T::Instance);
1114     let imp = instance.impl_();
1115     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1116     let wrap_orientation: Orientation = from_glib(orientation);
1117 
1118     imp.adjust_size_allocation(
1119         wrap.unsafe_cast_ref(),
1120         wrap_orientation,
1121         &mut *minptr,
1122         &mut *natptr,
1123         &mut *posptr,
1124         &mut *sizeptr,
1125     )
1126 }
1127 
widget_adjust_size_request<T: WidgetImpl>( ptr: *mut ffi::GtkWidget, orientation: ffi::GtkOrientation, minptr: *mut i32, natptr: *mut i32, )1128 unsafe extern "C" fn widget_adjust_size_request<T: WidgetImpl>(
1129     ptr: *mut ffi::GtkWidget,
1130     orientation: ffi::GtkOrientation,
1131     minptr: *mut i32,
1132     natptr: *mut i32,
1133 ) {
1134     let instance = &*(ptr as *mut T::Instance);
1135     let imp = instance.impl_();
1136     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1137     let wrap_orientation: Orientation = from_glib(orientation);
1138 
1139     imp.adjust_size_request(
1140         wrap.unsafe_cast_ref(),
1141         wrap_orientation,
1142         &mut *minptr,
1143         &mut *natptr,
1144     )
1145 }
1146 
widget_button_press_event<T: WidgetImpl>( ptr: *mut ffi::GtkWidget, btnptr: *mut gdk::ffi::GdkEventButton, ) -> glib::ffi::gboolean1147 unsafe extern "C" fn widget_button_press_event<T: WidgetImpl>(
1148     ptr: *mut ffi::GtkWidget,
1149     btnptr: *mut gdk::ffi::GdkEventButton,
1150 ) -> glib::ffi::gboolean {
1151     let instance = &*(ptr as *mut T::Instance);
1152     let imp = instance.impl_();
1153     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1154     let evwrap: Borrowed<gdk::EventButton> = from_glib_borrow(btnptr);
1155 
1156     imp.button_press_event(wrap.unsafe_cast_ref(), &evwrap)
1157         .into_glib()
1158 }
1159 
widget_button_release_event<T: WidgetImpl>( ptr: *mut ffi::GtkWidget, btnptr: *mut gdk::ffi::GdkEventButton, ) -> glib::ffi::gboolean1160 unsafe extern "C" fn widget_button_release_event<T: WidgetImpl>(
1161     ptr: *mut ffi::GtkWidget,
1162     btnptr: *mut gdk::ffi::GdkEventButton,
1163 ) -> glib::ffi::gboolean {
1164     let instance = &*(ptr as *mut T::Instance);
1165     let imp = instance.impl_();
1166     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1167     let evwrap: Borrowed<gdk::EventButton> = from_glib_borrow(btnptr);
1168 
1169     imp.button_release_event(wrap.unsafe_cast_ref(), &evwrap)
1170         .into_glib()
1171 }
1172 
1173 // unsafe extern "C" fn widget_can_activate_accel<T: WidgetImpl>(
1174 //     ptr: *mut ffi::GtkWidget,
1175 //     signal_id: u32,
1176 // ) -> glib::ffi::gboolean
1177 // {
1178 //     let instance = &*(ptr as *mut T::Instance);
1179 //     let imp = instance.get_impl();
1180 //     let wrap: Widget = from_glib_borrow(ptr);
1181 
1182 //     imp.can_activate_accel(wrap.unsafe_cast_ref(), signal_id) as glib::ffi::gboolean
1183 // }
1184 
widget_child_notify<T: WidgetImpl>( ptr: *mut ffi::GtkWidget, paramptr: *mut glib::gobject_ffi::GParamSpec, )1185 unsafe extern "C" fn widget_child_notify<T: WidgetImpl>(
1186     ptr: *mut ffi::GtkWidget,
1187     paramptr: *mut glib::gobject_ffi::GParamSpec,
1188 ) {
1189     let instance = &*(ptr as *mut T::Instance);
1190     let imp = instance.impl_();
1191     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1192     let paramwrap: Borrowed<glib::ParamSpec> = from_glib_borrow(paramptr);
1193 
1194     imp.child_notify(wrap.unsafe_cast_ref(), &paramwrap)
1195 }
1196 
widget_composited_changed<T: WidgetImpl>(ptr: *mut ffi::GtkWidget)1197 unsafe extern "C" fn widget_composited_changed<T: WidgetImpl>(ptr: *mut ffi::GtkWidget) {
1198     let instance = &*(ptr as *mut T::Instance);
1199     let imp = instance.impl_();
1200     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1201 
1202     imp.composited_changed(wrap.unsafe_cast_ref())
1203 }
1204 
widget_compute_expand<T: WidgetImpl>( ptr: *mut ffi::GtkWidget, hexpand_ptr: *mut glib::ffi::gboolean, vexpand_ptr: *mut glib::ffi::gboolean, )1205 unsafe extern "C" fn widget_compute_expand<T: WidgetImpl>(
1206     ptr: *mut ffi::GtkWidget,
1207     hexpand_ptr: *mut glib::ffi::gboolean,
1208     vexpand_ptr: *mut glib::ffi::gboolean,
1209 ) {
1210     let instance = &*(ptr as *mut T::Instance);
1211     let imp = instance.impl_();
1212     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1213 
1214     let widget = wrap.unsafe_cast_ref::<Widget>();
1215     let mut hexpand: bool = if widget.is_hexpand_set() {
1216         widget.hexpands()
1217     } else {
1218         from_glib(*hexpand_ptr)
1219     };
1220     let mut vexpand: bool = if widget.is_vexpand_set() {
1221         widget.vexpands()
1222     } else {
1223         from_glib(*vexpand_ptr)
1224     };
1225 
1226     imp.compute_expand(wrap.unsafe_cast_ref(), &mut hexpand, &mut vexpand);
1227     *hexpand_ptr = hexpand.into_glib();
1228     *vexpand_ptr = vexpand.into_glib();
1229 }
1230 
widget_configure_event<T: WidgetImpl>( ptr: *mut ffi::GtkWidget, confptr: *mut gdk::ffi::GdkEventConfigure, ) -> glib::ffi::gboolean1231 unsafe extern "C" fn widget_configure_event<T: WidgetImpl>(
1232     ptr: *mut ffi::GtkWidget,
1233     confptr: *mut gdk::ffi::GdkEventConfigure,
1234 ) -> glib::ffi::gboolean {
1235     let instance = &*(ptr as *mut T::Instance);
1236     let imp = instance.impl_();
1237     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1238     let evwrap: Borrowed<gdk::EventConfigure> = from_glib_borrow(confptr);
1239 
1240     imp.configure_event(wrap.unsafe_cast_ref(), &evwrap)
1241         .into_glib()
1242 }
1243 
widget_damage_event<T: WidgetImpl>( ptr: *mut ffi::GtkWidget, exposeptr: *mut gdk::ffi::GdkEventExpose, ) -> glib::ffi::gboolean1244 unsafe extern "C" fn widget_damage_event<T: WidgetImpl>(
1245     ptr: *mut ffi::GtkWidget,
1246     exposeptr: *mut gdk::ffi::GdkEventExpose,
1247 ) -> glib::ffi::gboolean {
1248     let instance = &*(ptr as *mut T::Instance);
1249     let imp = instance.impl_();
1250     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1251     let evwrap: Borrowed<gdk::EventExpose> = from_glib_borrow(exposeptr);
1252 
1253     imp.damage_event(wrap.unsafe_cast_ref(), &evwrap)
1254         .into_glib()
1255 }
1256 
widget_delete_event<T: WidgetImpl>( ptr: *mut ffi::GtkWidget, anyptr: *mut gdk::ffi::GdkEventAny, ) -> glib::ffi::gboolean1257 unsafe extern "C" fn widget_delete_event<T: WidgetImpl>(
1258     ptr: *mut ffi::GtkWidget,
1259     anyptr: *mut gdk::ffi::GdkEventAny,
1260 ) -> glib::ffi::gboolean {
1261     let instance = &*(ptr as *mut T::Instance);
1262     let imp = instance.impl_();
1263     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1264     let evwrap: Borrowed<gdk::Event> = from_glib_borrow(anyptr);
1265 
1266     imp.delete_event(wrap.unsafe_cast_ref(), &evwrap)
1267         .into_glib()
1268 }
1269 
widget_destroy<T: WidgetImpl>(ptr: *mut ffi::GtkWidget)1270 unsafe extern "C" fn widget_destroy<T: WidgetImpl>(ptr: *mut ffi::GtkWidget) {
1271     let instance = &*(ptr as *mut T::Instance);
1272     let imp = instance.impl_();
1273     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1274 
1275     imp.destroy(wrap.unsafe_cast_ref())
1276 }
1277 
widget_destroy_event<T: WidgetImpl>( ptr: *mut ffi::GtkWidget, anyptr: *mut gdk::ffi::GdkEventAny, ) -> glib::ffi::gboolean1278 unsafe extern "C" fn widget_destroy_event<T: WidgetImpl>(
1279     ptr: *mut ffi::GtkWidget,
1280     anyptr: *mut gdk::ffi::GdkEventAny,
1281 ) -> glib::ffi::gboolean {
1282     let instance = &*(ptr as *mut T::Instance);
1283     let imp = instance.impl_();
1284     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1285     let evwrap: Borrowed<gdk::Event> = from_glib_borrow(anyptr);
1286 
1287     imp.destroy_event(wrap.unsafe_cast_ref(), &evwrap)
1288         .into_glib()
1289 }
1290 
widget_direction_changed<T: WidgetImpl>( ptr: *mut ffi::GtkWidget, directnptr: ffi::GtkTextDirection, )1291 unsafe extern "C" fn widget_direction_changed<T: WidgetImpl>(
1292     ptr: *mut ffi::GtkWidget,
1293     directnptr: ffi::GtkTextDirection,
1294 ) {
1295     let instance = &*(ptr as *mut T::Instance);
1296     let imp = instance.impl_();
1297     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1298     let dirwrap: TextDirection = from_glib(directnptr);
1299 
1300     imp.direction_changed(wrap.unsafe_cast_ref(), dirwrap)
1301 }
1302 
widget_dispatch_child_properties_changed<T: WidgetImpl>( ptr: *mut ffi::GtkWidget, n_pspec_ptr: u32, pspecsptr: *mut *mut glib::gobject_ffi::GParamSpec, )1303 unsafe extern "C" fn widget_dispatch_child_properties_changed<T: WidgetImpl>(
1304     ptr: *mut ffi::GtkWidget,
1305     n_pspec_ptr: u32,
1306     pspecsptr: *mut *mut glib::gobject_ffi::GParamSpec,
1307 ) {
1308     let instance = &*(ptr as *mut T::Instance);
1309     let imp = instance.impl_();
1310     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1311     let pspecs: Vec<glib::ParamSpec> =
1312         FromGlibContainer::from_glib_none_num(pspecsptr, n_pspec_ptr as usize);
1313 
1314     imp.dispatch_child_properties_changed(wrap.unsafe_cast_ref(), &pspecs)
1315 }
1316 
widget_drag_begin<T: WidgetImpl>( ptr: *mut ffi::GtkWidget, ctxptr: *mut gdk::ffi::GdkDragContext, )1317 unsafe extern "C" fn widget_drag_begin<T: WidgetImpl>(
1318     ptr: *mut ffi::GtkWidget,
1319     ctxptr: *mut gdk::ffi::GdkDragContext,
1320 ) {
1321     let instance = &*(ptr as *mut T::Instance);
1322     let imp = instance.impl_();
1323     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1324     let context: Borrowed<gdk::DragContext> = from_glib_borrow(ctxptr);
1325 
1326     imp.drag_begin(wrap.unsafe_cast_ref(), &context)
1327 }
1328 
widget_drag_data_delete<T: WidgetImpl>( ptr: *mut ffi::GtkWidget, ctxptr: *mut gdk::ffi::GdkDragContext, )1329 unsafe extern "C" fn widget_drag_data_delete<T: WidgetImpl>(
1330     ptr: *mut ffi::GtkWidget,
1331     ctxptr: *mut gdk::ffi::GdkDragContext,
1332 ) {
1333     let instance = &*(ptr as *mut T::Instance);
1334     let imp = instance.impl_();
1335     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1336     let context: Borrowed<gdk::DragContext> = from_glib_borrow(ctxptr);
1337 
1338     imp.drag_data_delete(wrap.unsafe_cast_ref(), &context)
1339 }
1340 
widget_drag_data_get<T: WidgetImpl>( ptr: *mut ffi::GtkWidget, ctxptr: *mut gdk::ffi::GdkDragContext, selectptr: *mut ffi::GtkSelectionData, info: u32, time: u32, )1341 unsafe extern "C" fn widget_drag_data_get<T: WidgetImpl>(
1342     ptr: *mut ffi::GtkWidget,
1343     ctxptr: *mut gdk::ffi::GdkDragContext,
1344     selectptr: *mut ffi::GtkSelectionData,
1345     info: u32,
1346     time: u32,
1347 ) {
1348     let instance = &*(ptr as *mut T::Instance);
1349     let imp = instance.impl_();
1350     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1351     let context: Borrowed<gdk::DragContext> = from_glib_borrow(ctxptr);
1352     let selection_data: Borrowed<SelectionData> = from_glib_borrow(selectptr);
1353 
1354     imp.drag_data_get(
1355         wrap.unsafe_cast_ref(),
1356         &context,
1357         &selection_data,
1358         info,
1359         time,
1360     )
1361 }
1362 
widget_drag_data_received<T: WidgetImpl>( ptr: *mut ffi::GtkWidget, ctxptr: *mut gdk::ffi::GdkDragContext, x: i32, y: i32, selectptr: *mut ffi::GtkSelectionData, info: u32, time: u32, )1363 unsafe extern "C" fn widget_drag_data_received<T: WidgetImpl>(
1364     ptr: *mut ffi::GtkWidget,
1365     ctxptr: *mut gdk::ffi::GdkDragContext,
1366     x: i32,
1367     y: i32,
1368     selectptr: *mut ffi::GtkSelectionData,
1369     info: u32,
1370     time: u32,
1371 ) {
1372     let instance = &*(ptr as *mut T::Instance);
1373     let imp = instance.impl_();
1374     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1375     let context: Borrowed<gdk::DragContext> = from_glib_borrow(ctxptr);
1376     let selection_data: Borrowed<SelectionData> = from_glib_borrow(selectptr);
1377 
1378     imp.drag_data_received(
1379         wrap.unsafe_cast_ref(),
1380         &context,
1381         x,
1382         y,
1383         &selection_data,
1384         info,
1385         time,
1386     )
1387 }
1388 
widget_drag_drop<T: WidgetImpl>( ptr: *mut ffi::GtkWidget, ctxptr: *mut gdk::ffi::GdkDragContext, x: i32, y: i32, time: u32, ) -> glib::ffi::gboolean1389 unsafe extern "C" fn widget_drag_drop<T: WidgetImpl>(
1390     ptr: *mut ffi::GtkWidget,
1391     ctxptr: *mut gdk::ffi::GdkDragContext,
1392     x: i32,
1393     y: i32,
1394     time: u32,
1395 ) -> glib::ffi::gboolean {
1396     let instance = &*(ptr as *mut T::Instance);
1397     let imp = instance.impl_();
1398     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1399     let context: Borrowed<gdk::DragContext> = from_glib_borrow(ctxptr);
1400 
1401     imp.drag_drop(wrap.unsafe_cast_ref(), &context, x, y, time)
1402         .into_glib()
1403 }
1404 
widget_drag_end<T: WidgetImpl>( ptr: *mut ffi::GtkWidget, ctxptr: *mut gdk::ffi::GdkDragContext, )1405 unsafe extern "C" fn widget_drag_end<T: WidgetImpl>(
1406     ptr: *mut ffi::GtkWidget,
1407     ctxptr: *mut gdk::ffi::GdkDragContext,
1408 ) {
1409     let instance = &*(ptr as *mut T::Instance);
1410     let imp = instance.impl_();
1411     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1412     let context: Borrowed<gdk::DragContext> = from_glib_borrow(ctxptr);
1413 
1414     imp.drag_end(wrap.unsafe_cast_ref(), &context)
1415 }
1416 
widget_drag_failed<T: WidgetImpl>( ptr: *mut ffi::GtkWidget, ctxptr: *mut gdk::ffi::GdkDragContext, resultptr: ffi::GtkDragResult, ) -> glib::ffi::gboolean1417 unsafe extern "C" fn widget_drag_failed<T: WidgetImpl>(
1418     ptr: *mut ffi::GtkWidget,
1419     ctxptr: *mut gdk::ffi::GdkDragContext,
1420     resultptr: ffi::GtkDragResult,
1421 ) -> glib::ffi::gboolean {
1422     let instance = &*(ptr as *mut T::Instance);
1423     let imp = instance.impl_();
1424     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1425     let context: Borrowed<gdk::DragContext> = from_glib_borrow(ctxptr);
1426     let result: DragResult = from_glib(resultptr);
1427 
1428     imp.drag_failed(wrap.unsafe_cast_ref(), &context, result)
1429         .into_glib()
1430 }
1431 
widget_drag_leave<T: WidgetImpl>( ptr: *mut ffi::GtkWidget, ctxptr: *mut gdk::ffi::GdkDragContext, time: u32, )1432 unsafe extern "C" fn widget_drag_leave<T: WidgetImpl>(
1433     ptr: *mut ffi::GtkWidget,
1434     ctxptr: *mut gdk::ffi::GdkDragContext,
1435     time: u32,
1436 ) {
1437     let instance = &*(ptr as *mut T::Instance);
1438     let imp = instance.impl_();
1439     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1440     let context: Borrowed<gdk::DragContext> = from_glib_borrow(ctxptr);
1441 
1442     imp.drag_leave(wrap.unsafe_cast_ref(), &context, time)
1443 }
1444 
widget_drag_motion<T: WidgetImpl>( ptr: *mut ffi::GtkWidget, ctxptr: *mut gdk::ffi::GdkDragContext, x: i32, y: i32, time: u32, ) -> glib::ffi::gboolean1445 unsafe extern "C" fn widget_drag_motion<T: WidgetImpl>(
1446     ptr: *mut ffi::GtkWidget,
1447     ctxptr: *mut gdk::ffi::GdkDragContext,
1448     x: i32,
1449     y: i32,
1450     time: u32,
1451 ) -> glib::ffi::gboolean {
1452     let instance = &*(ptr as *mut T::Instance);
1453     let imp = instance.impl_();
1454     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1455     let context: Borrowed<gdk::DragContext> = from_glib_borrow(ctxptr);
1456 
1457     imp.drag_motion(wrap.unsafe_cast_ref(), &context, x, y, time)
1458         .into_glib()
1459 }
1460 
widget_draw<T: WidgetImpl>( ptr: *mut ffi::GtkWidget, cr_ptr: *mut cairo::ffi::cairo_t, ) -> glib::ffi::gboolean1461 unsafe extern "C" fn widget_draw<T: WidgetImpl>(
1462     ptr: *mut ffi::GtkWidget,
1463     cr_ptr: *mut cairo::ffi::cairo_t,
1464 ) -> glib::ffi::gboolean {
1465     let instance = &*(ptr as *mut T::Instance);
1466     let imp = instance.impl_();
1467     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1468     let cr: Borrowed<cairo::Context> = from_glib_borrow(cr_ptr);
1469 
1470     imp.draw(wrap.unsafe_cast_ref(), &cr).into_glib()
1471 }
1472 
widget_get_request_mode<T: WidgetImpl>( ptr: *mut ffi::GtkWidget, ) -> ffi::GtkSizeRequestMode1473 unsafe extern "C" fn widget_get_request_mode<T: WidgetImpl>(
1474     ptr: *mut ffi::GtkWidget,
1475 ) -> ffi::GtkSizeRequestMode {
1476     let instance = &*(ptr as *mut T::Instance);
1477     let imp = instance.impl_();
1478     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1479 
1480     imp.request_mode(wrap.unsafe_cast_ref()).into_glib()
1481 }
1482 
widget_get_preferred_height<T: WidgetImpl>( ptr: *mut ffi::GtkWidget, minptr: *mut c_int, natptr: *mut c_int, )1483 unsafe extern "C" fn widget_get_preferred_height<T: WidgetImpl>(
1484     ptr: *mut ffi::GtkWidget,
1485     minptr: *mut c_int,
1486     natptr: *mut c_int,
1487 ) {
1488     let instance = &*(ptr as *mut T::Instance);
1489     let imp = instance.impl_();
1490     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1491 
1492     let (min_size, nat_size) = imp.preferred_height(wrap.unsafe_cast_ref());
1493     if !minptr.is_null() {
1494         *minptr = min_size;
1495     }
1496     if !natptr.is_null() {
1497         *natptr = nat_size;
1498     }
1499 }
1500 
widget_get_preferred_width_for_height<T: WidgetImpl>( ptr: *mut ffi::GtkWidget, height: c_int, min_width_ptr: *mut c_int, nat_width_ptr: *mut c_int, )1501 unsafe extern "C" fn widget_get_preferred_width_for_height<T: WidgetImpl>(
1502     ptr: *mut ffi::GtkWidget,
1503     height: c_int,
1504     min_width_ptr: *mut c_int,
1505     nat_width_ptr: *mut c_int,
1506 ) {
1507     let instance = &*(ptr as *mut T::Instance);
1508     let imp = instance.impl_();
1509     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1510 
1511     let (min_width, nat_width) = imp.preferred_width_for_height(wrap.unsafe_cast_ref(), height);
1512     if !min_width_ptr.is_null() {
1513         *min_width_ptr = min_width;
1514     }
1515     if !nat_width_ptr.is_null() {
1516         *nat_width_ptr = nat_width;
1517     }
1518 }
1519 
widget_get_preferred_width<T: WidgetImpl>( ptr: *mut ffi::GtkWidget, minptr: *mut c_int, natptr: *mut c_int, )1520 unsafe extern "C" fn widget_get_preferred_width<T: WidgetImpl>(
1521     ptr: *mut ffi::GtkWidget,
1522     minptr: *mut c_int,
1523     natptr: *mut c_int,
1524 ) {
1525     let instance = &*(ptr as *mut T::Instance);
1526     let imp = instance.impl_();
1527     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1528     let (min_size, nat_size) = imp.preferred_width(wrap.unsafe_cast_ref());
1529     if !minptr.is_null() {
1530         *minptr = min_size;
1531     }
1532     if !natptr.is_null() {
1533         *natptr = nat_size;
1534     }
1535 }
1536 
widget_get_preferred_height_for_width<T: WidgetImpl>( ptr: *mut ffi::GtkWidget, width: c_int, min_height_ptr: *mut c_int, nat_height_ptr: *mut c_int, )1537 unsafe extern "C" fn widget_get_preferred_height_for_width<T: WidgetImpl>(
1538     ptr: *mut ffi::GtkWidget,
1539     width: c_int,
1540     min_height_ptr: *mut c_int,
1541     nat_height_ptr: *mut c_int,
1542 ) {
1543     let instance = &*(ptr as *mut T::Instance);
1544     let imp = instance.impl_();
1545     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1546 
1547     let (min_height, nat_height) = imp.preferred_height_for_width(wrap.unsafe_cast_ref(), width);
1548     if !min_height_ptr.is_null() {
1549         *min_height_ptr = min_height;
1550     }
1551     if !nat_height_ptr.is_null() {
1552         *nat_height_ptr = nat_height;
1553     }
1554 }
1555 
widget_size_allocate<T: WidgetImpl>( ptr: *mut ffi::GtkWidget, allocation: *mut ffi::GtkAllocation, )1556 unsafe extern "C" fn widget_size_allocate<T: WidgetImpl>(
1557     ptr: *mut ffi::GtkWidget,
1558     allocation: *mut ffi::GtkAllocation,
1559 ) {
1560     let instance = &*(ptr as *mut T::Instance);
1561     let imp = instance.impl_();
1562     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1563     let allocate: &Allocation = &from_glib_none(allocation);
1564 
1565     imp.size_allocate(wrap.unsafe_cast_ref(), allocate);
1566 }
1567 
widget_realize<T: WidgetImpl>(ptr: *mut ffi::GtkWidget)1568 unsafe extern "C" fn widget_realize<T: WidgetImpl>(ptr: *mut ffi::GtkWidget) {
1569     let instance = &*(ptr as *mut T::Instance);
1570     let imp = instance.impl_();
1571     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1572 
1573     imp.realize(wrap.unsafe_cast_ref());
1574 }
1575 
widget_unrealize<T: WidgetImpl>(ptr: *mut ffi::GtkWidget)1576 unsafe extern "C" fn widget_unrealize<T: WidgetImpl>(ptr: *mut ffi::GtkWidget) {
1577     let instance = &*(ptr as *mut T::Instance);
1578     let imp = instance.impl_();
1579     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1580 
1581     imp.unrealize(wrap.unsafe_cast_ref());
1582 }
1583 
widget_map<T: WidgetImpl>(ptr: *mut ffi::GtkWidget)1584 unsafe extern "C" fn widget_map<T: WidgetImpl>(ptr: *mut ffi::GtkWidget) {
1585     let instance = &*(ptr as *mut T::Instance);
1586     let imp = instance.impl_();
1587     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1588     imp.map(wrap.unsafe_cast_ref());
1589 }
1590 
widget_unmap<T: WidgetImpl>(ptr: *mut ffi::GtkWidget)1591 unsafe extern "C" fn widget_unmap<T: WidgetImpl>(ptr: *mut ffi::GtkWidget) {
1592     let instance = &*(ptr as *mut T::Instance);
1593     let imp = instance.impl_();
1594     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1595     imp.unmap(wrap.unsafe_cast_ref());
1596 }
1597 
widget_motion_notify_event<T: WidgetImpl>( ptr: *mut ffi::GtkWidget, mptr: *mut gdk::ffi::GdkEventMotion, ) -> glib::ffi::gboolean1598 unsafe extern "C" fn widget_motion_notify_event<T: WidgetImpl>(
1599     ptr: *mut ffi::GtkWidget,
1600     mptr: *mut gdk::ffi::GdkEventMotion,
1601 ) -> glib::ffi::gboolean {
1602     let instance = &*(ptr as *mut T::Instance);
1603     let imp = instance.impl_();
1604     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1605     let event: Borrowed<gdk::EventMotion> = from_glib_borrow(mptr);
1606 
1607     imp.motion_notify_event(wrap.unsafe_cast_ref(), &event)
1608         .into_glib()
1609 }
1610 
widget_scroll_event<T: WidgetImpl>( ptr: *mut ffi::GtkWidget, mptr: *mut gdk::ffi::GdkEventScroll, ) -> glib::ffi::gboolean1611 unsafe extern "C" fn widget_scroll_event<T: WidgetImpl>(
1612     ptr: *mut ffi::GtkWidget,
1613     mptr: *mut gdk::ffi::GdkEventScroll,
1614 ) -> glib::ffi::gboolean {
1615     let instance = &*(ptr as *mut T::Instance);
1616     let imp = instance.impl_();
1617     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1618     let event: Borrowed<gdk::EventScroll> = from_glib_borrow(mptr);
1619 
1620     imp.scroll_event(wrap.unsafe_cast_ref(), &event).into_glib()
1621 }
1622 
widget_enter_notify_event<T: WidgetImpl>( ptr: *mut ffi::GtkWidget, mptr: *mut gdk::ffi::GdkEventCrossing, ) -> glib::ffi::gboolean1623 unsafe extern "C" fn widget_enter_notify_event<T: WidgetImpl>(
1624     ptr: *mut ffi::GtkWidget,
1625     mptr: *mut gdk::ffi::GdkEventCrossing,
1626 ) -> glib::ffi::gboolean {
1627     let instance = &*(ptr as *mut T::Instance);
1628     let imp = instance.impl_();
1629     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1630     let event: Borrowed<gdk::EventCrossing> = from_glib_borrow(mptr);
1631 
1632     imp.enter_notify_event(wrap.unsafe_cast_ref(), &event)
1633         .into_glib()
1634 }
1635 
widget_leave_notify_event<T: WidgetImpl>( ptr: *mut ffi::GtkWidget, mptr: *mut gdk::ffi::GdkEventCrossing, ) -> glib::ffi::gboolean1636 unsafe extern "C" fn widget_leave_notify_event<T: WidgetImpl>(
1637     ptr: *mut ffi::GtkWidget,
1638     mptr: *mut gdk::ffi::GdkEventCrossing,
1639 ) -> glib::ffi::gboolean {
1640     let instance = &*(ptr as *mut T::Instance);
1641     let imp = instance.impl_();
1642     let wrap: Borrowed<Widget> = from_glib_borrow(ptr);
1643     let event: Borrowed<gdk::EventCrossing> = from_glib_borrow(mptr);
1644 
1645     imp.leave_notify_event(wrap.unsafe_cast_ref(), &event)
1646         .into_glib()
1647 }
1648 
1649 pub unsafe trait WidgetClassSubclassExt: ClassStruct {
set_template_bytes(&mut self, template: &glib::Bytes)1650     fn set_template_bytes(&mut self, template: &glib::Bytes) {
1651         unsafe {
1652             let widget_class = self as *mut _ as *mut ffi::GtkWidgetClass;
1653             ffi::gtk_widget_class_set_template(widget_class, template.to_glib_none().0);
1654         }
1655     }
1656 
set_template(&mut self, template: &[u8])1657     fn set_template(&mut self, template: &[u8]) {
1658         let template_bytes = glib::Bytes::from(template);
1659         self.set_template_bytes(&template_bytes);
1660     }
1661 
set_template_static(&mut self, template: &'static [u8])1662     fn set_template_static(&mut self, template: &'static [u8]) {
1663         let template_bytes = glib::Bytes::from_static(template);
1664         self.set_template_bytes(&template_bytes);
1665     }
1666 
set_template_from_resource(&mut self, resource_name: &str)1667     fn set_template_from_resource(&mut self, resource_name: &str) {
1668         unsafe {
1669             let widget_class = self as *mut _ as *mut ffi::GtkWidgetClass;
1670             ffi::gtk_widget_class_set_template_from_resource(
1671                 widget_class,
1672                 resource_name.to_glib_none().0,
1673             );
1674         }
1675     }
1676 
bind_template_child(&mut self, name: &str)1677     fn bind_template_child(&mut self, name: &str) {
1678         unsafe {
1679             let widget_class = self as *mut _ as *mut ffi::GtkWidgetClass;
1680             ffi::gtk_widget_class_bind_template_child_full(
1681                 widget_class,
1682                 name.to_glib_none().0,
1683                 false as glib::ffi::gboolean,
1684                 0,
1685             );
1686         }
1687     }
1688 
1689     #[allow(clippy::missing_safety_doc)]
bind_template_child_with_offset<T>( &mut self, name: &str, offset: field_offset::FieldOffset<Self::Type, TemplateChild<T>>, ) where T: ObjectType + FromGlibPtrNone<*mut <T as ObjectType>::GlibType>,1690     unsafe fn bind_template_child_with_offset<T>(
1691         &mut self,
1692         name: &str,
1693         offset: field_offset::FieldOffset<Self::Type, TemplateChild<T>>,
1694     ) where
1695         T: ObjectType + FromGlibPtrNone<*mut <T as ObjectType>::GlibType>,
1696     {
1697         let widget_class = self as *mut _ as *mut ffi::GtkWidgetClass;
1698         let private_offset = <Self::Type as ObjectSubclassType>::type_data()
1699             .as_ref()
1700             .impl_offset();
1701         ffi::gtk_widget_class_bind_template_child_full(
1702             widget_class,
1703             name.to_glib_none().0,
1704             false as glib::ffi::gboolean,
1705             private_offset + (offset.get_byte_offset() as isize),
1706         )
1707     }
1708 
1709     #[cfg(any(feature = "v3_20", feature = "dox"))]
1710     #[cfg_attr(feature = "dox", doc(cfg(feature = "v3_20")))]
1711     #[doc(alias = "gtk_widget_class_set_css_name")]
set_css_name(&mut self, name: &str)1712     fn set_css_name(&mut self, name: &str) {
1713         unsafe {
1714             let widget_class = self as *mut _ as *mut ffi::GtkWidgetClass;
1715             ffi::gtk_widget_class_set_css_name(widget_class, name.to_glib_none().0);
1716         }
1717     }
1718 
1719     #[cfg(any(feature = "v3_20", feature = "dox"))]
1720     #[cfg_attr(feature = "dox", doc(cfg(feature = "v3_20")))]
1721     #[doc(alias = "gtk_widget_class_get_css_name")]
css_name(&self) -> glib::GString1722     fn css_name(&self) -> glib::GString {
1723         unsafe {
1724             let widget_class = self as *const _ as *mut ffi::GtkWidgetClass;
1725             from_glib_none(ffi::gtk_widget_class_get_css_name(widget_class))
1726         }
1727     }
1728 }
1729 
1730 unsafe impl<T: ClassStruct> WidgetClassSubclassExt for T where T::Type: WidgetImpl {}
1731 
1732 #[derive(Debug, PartialEq, Eq)]
1733 #[repr(transparent)]
1734 pub struct TemplateChild<T>
1735 where
1736     T: ObjectType + FromGlibPtrNone<*mut <T as ObjectType>::GlibType>,
1737 {
1738     ptr: *mut <T as ObjectType>::GlibType,
1739 }
1740 
1741 impl<T> Default for TemplateChild<T>
1742 where
1743     T: ObjectType + FromGlibPtrNone<*mut <T as ObjectType>::GlibType>,
1744 {
default() -> Self1745     fn default() -> Self {
1746         Self {
1747             ptr: std::ptr::null_mut(),
1748         }
1749     }
1750 }
1751 
1752 impl<T> std::ops::Deref for TemplateChild<T>
1753 where
1754     T: ObjectType + FromGlibPtrNone<*mut <T as ObjectType>::GlibType>,
1755 {
1756     type Target = T;
1757 
1758     // rustdoc-stripper-ignore-next
1759     /// # Safety
1760     ///
1761     /// Since the template child may not be properly bound,
1762     /// this cast is potentially dangerous if, for example,
1763     /// the template child isn't bound or is of the wrong type.
1764     /// The caller is responsible for ensuring that the template
1765     /// child is bound and of the right type.
deref(&self) -> &Self::Target1766     fn deref(&self) -> &Self::Target {
1767         unsafe {
1768             assert!(!self.ptr.is_null());
1769             &*(&self.ptr as *const _ as *const T)
1770         }
1771     }
1772 }
1773 
1774 impl<T> TemplateChild<T>
1775 where
1776     T: ObjectType + FromGlibPtrNone<*mut <T as ObjectType>::GlibType>,
1777 {
1778     #[track_caller]
get(&self) -> T1779     pub fn get(&self) -> T {
1780         unsafe {
1781             Option::<T>::from_glib_none(self.ptr)
1782                 .expect("Failed to retrieve template child. Please check that it has been bound.")
1783         }
1784     }
1785 }
1786 
1787 pub trait CompositeTemplate: WidgetImpl {
bind_template(klass: &mut Self::Class)1788     fn bind_template(klass: &mut Self::Class);
1789 }
1790