Skip to main content

gtk/subclass/
widget.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use glib::subclass::SignalId;
4use libc::c_int;
5use std::mem;
6use std::num::NonZeroU32;
7
8use glib::Propagation;
9use glib::prelude::*;
10use glib::subclass::prelude::*;
11use glib::translate::*;
12
13use crate::DirectionType;
14use crate::DragResult;
15use crate::Orientation;
16use crate::SelectionData;
17use crate::SizeRequestMode;
18use crate::StateFlags;
19use crate::TextDirection;
20use crate::Tooltip;
21use crate::Widget;
22use crate::WidgetHelpType;
23use crate::prelude::*;
24use crate::{Allocation, ffi};
25
26pub trait WidgetImpl: ObjectImpl + ObjectSubclass<Type: IsA<Widget>> {
27    // Do not provide an override for this, as widget implementors should just use
28    // WidgetClassSubclassExt::set_accessible_type().  The base gtk_widget_real_get_accessible()
29    // does caching (because this vfunc is transfer-none) and initialization, and it's probably
30    // best that we don't encourage people to take on the burden of getting that right.
31    //fn get_accessible(&self) -> atk::Accessible;
32
33    // Deprecated, use state_flags_changed instead.
34    //fn state_changed(&self, previous_state: StateType);
35
36    // Deprecated, use style_updated instead.
37    //fn style_set(&self, previous_style: Style);
38
39    fn adjust_baseline_allocation(&self, baseline: &mut i32) {
40        self.parent_adjust_baseline_allocation(baseline)
41    }
42
43    fn adjust_baseline_request(&self, minimum_baseline: &mut i32, natural_baseline: &mut i32) {
44        self.parent_adjust_baseline_request(minimum_baseline, natural_baseline)
45    }
46
47    /// Retrieves a widget’s minimum and natural height and the corresponding baselines if it would be given
48    /// the specified `width`, or the default height if `width` is -1. The baselines may be -1 which means
49    /// that no baseline is requested for this widget.
50    ///
51    /// The returned request will be modified by the
52    /// GtkWidgetClass::adjust_size_request and GtkWidgetClass::adjust_baseline_request virtual methods
53    /// and by any `GtkSizeGroups` that have been applied. That is, the returned request
54    /// is the one that should be used for layout, not necessarily the one
55    /// returned by the widget itself.
56    /// ## `width`
57    /// the width which is available for allocation, or -1 if none
58    ///
59    /// # Returns
60    ///
61    ///
62    /// ## `minimum_height`
63    /// location for storing the minimum height, or [`None`]
64    ///
65    /// ## `natural_height`
66    /// location for storing the natural height, or [`None`]
67    ///
68    /// ## `minimum_baseline`
69    /// location for storing the baseline for the minimum height, or [`None`]
70    ///
71    /// ## `natural_baseline`
72    /// location for storing the baseline for the natural height, or [`None`]
73    #[doc(alias = "get_preferred_height_and_baseline_for_width")]
74    fn preferred_height_and_baseline_for_width(&self, width: i32) -> (i32, i32, i32, i32) {
75        self.parent_preferred_height_and_baseline_for_width(width)
76    }
77
78    /// Convert an initial size allocation assigned
79    ///  by a [`Container`][crate::Container] using [`WidgetExt::size_allocate()`][crate::prelude::WidgetExt::size_allocate()], into an actual
80    ///  size allocation to be used by the widget. adjust_size_allocation
81    ///  adjusts to a child widget’s actual allocation
82    ///  from what a parent container computed for the
83    ///  child. The adjusted allocation must be entirely within the original
84    ///  allocation. In any custom implementation, chain up to the default
85    ///  [`Widget`][crate::Widget] implementation of this method, which applies the margin
86    ///  and alignment properties of [`Widget`][crate::Widget]. Chain up
87    ///  before performing your own adjustments so your
88    ///  own adjustments remove more allocation after the [`Widget`][crate::Widget] base
89    ///  class has already removed margin and alignment. The natural size
90    ///  passed in should be adjusted in the same way as the allocated size,
91    ///  which allows adjustments to perform alignments or other changes
92    ///  based on natural size.
93    fn adjust_size_allocation(
94        &self,
95
96        orientation: Orientation,
97        minimum_size: &mut i32,
98        natural_size: &mut i32,
99        allocated_pos: &mut i32,
100        allocated_size: &mut i32,
101    ) {
102        self.parent_adjust_size_allocation(
103            orientation,
104            minimum_size,
105            natural_size,
106            allocated_pos,
107            allocated_size,
108        )
109    }
110
111    /// Convert an initial size request from a widget's
112    ///  [`SizeRequestMode`][crate::SizeRequestMode] virtual method implementations into a size request to
113    ///  be used by parent containers in laying out the widget.
114    ///  adjust_size_request adjusts from a child widget's
115    ///  original request to what a parent container should
116    ///  use for layout. The `for_size` argument will be -1 if the request should
117    ///  not be for a particular size in the opposing orientation, i.e. if the
118    ///  request is not height-for-width or width-for-height. If `for_size` is
119    ///  greater than -1, it is the proposed allocation in the opposing
120    ///  orientation that we need the request for. Implementations of
121    ///  adjust_size_request should chain up to the default implementation,
122    ///  which applies [`Widget`][crate::Widget]’s margin properties and imposes any values
123    ///  from [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()]. Chaining up should be last,
124    ///  after your subclass adjusts the request, so
125    ///  [`Widget`][crate::Widget] can apply constraints and add the margin properly.
126    fn adjust_size_request(
127        &self,
128
129        orientation: Orientation,
130        minimum_size: &mut i32,
131        natural_size: &mut i32,
132    ) {
133        self.parent_adjust_size_request(orientation, minimum_size, natural_size)
134    }
135
136    /// Signal will be emitted when a button
137    ///  (typically from a mouse) is pressed.
138    fn button_press_event(&self, event: &gdk::EventButton) -> Propagation {
139        self.parent_button_press_event(event)
140    }
141
142    /// Signal will be emitted when a button
143    ///  (typically from a mouse) is released.
144    fn button_release_event(&self, event: &gdk::EventButton) -> Propagation {
145        self.parent_button_release_event(event)
146    }
147
148    /// Emits a [`child-notify`][struct@crate::Widget#child-notify] signal for the
149    /// [child property][child-properties] `child_property`
150    /// on `widget`.
151    ///
152    /// This is the analogue of [`ObjectExt::notify()`][crate::glib::prelude::ObjectExt::notify()] for child properties.
153    ///
154    /// Also see [`ContainerExt::child_notify()`][crate::prelude::ContainerExt::child_notify()].
155    /// ## `child_property`
156    /// the name of a child property installed on the
157    ///  class of `widget`’s parent
158    fn child_notify(&self, child_property: &glib::ParamSpec) {
159        self.parent_child_notify(child_property)
160    }
161
162    /// Signal emitted when the composited status of
163    ///  widgets screen changes. See [`Screen::is_composited()`][crate::gdk::Screen::is_composited()].
164    fn composited_changed(&self) {
165        self.parent_composited_changed()
166    }
167
168    /// Computes whether a container should give this
169    ///  widget extra space when possible.
170    fn compute_expand(&self, hexpand: &mut bool, vexpand: &mut bool) {
171        self.parent_compute_expand(hexpand, vexpand)
172    }
173
174    /// Signal will be emitted when the size, position or
175    ///  stacking of the widget’s window has changed.
176    fn configure_event(&self, event: &gdk::EventConfigure) -> Propagation {
177        self.parent_configure_event(event)
178    }
179
180    /// Signal emitted when the state of the toplevel
181    ///  window associated to the widget changes.
182    fn window_state_event(&self, event: &gdk::EventWindowState) -> Propagation {
183        self.parent_window_state_event(event)
184    }
185
186    /// Signal emitted when a redirected window belonging to
187    ///  widget gets drawn into.
188    fn damage_event(&self, event: &gdk::EventExpose) -> Propagation {
189        self.parent_damage_event(event)
190    }
191
192    /// Signal emitted if a user requests that a toplevel
193    ///  window is closed.
194    fn delete_event(&self, event: &gdk::Event) -> Propagation {
195        self.parent_delete_event(event)
196    }
197
198    fn destroy(&self) {
199        self.parent_destroy()
200    }
201
202    /// Signal is emitted when a [`gdk::Window`][crate::gdk::Window] is destroyed.
203    fn destroy_event(&self, event: &gdk::Event) -> Propagation {
204        self.parent_destroy_event(event)
205    }
206
207    /// Signal emitted when the text direction of a
208    ///  widget changes.
209    fn direction_changed(&self, previous_direction: TextDirection) {
210        self.parent_direction_changed(previous_direction)
211    }
212
213    /// Seldomly overidden.
214    fn dispatch_child_properties_changed(&self, pspecs: &[glib::ParamSpec]) {
215        self.parent_dispatch_child_properties_changed(pspecs)
216    }
217
218    /// Signal emitted on the drag source when a drag is
219    ///  started.
220    fn drag_begin(&self, context: &gdk::DragContext) {
221        self.parent_drag_begin(context)
222    }
223
224    /// Signal emitted on the drag source when a drag
225    ///  with the action [`gdk::DragAction::MOVE`][crate::gdk::DragAction::MOVE] is successfully completed.
226    fn drag_data_delete(&self, context: &gdk::DragContext) {
227        self.parent_drag_data_delete(context)
228    }
229
230    /// Signal emitted on the drag source when the drop
231    ///  site requests the data which is dragged.
232    fn drag_data_get(
233        &self,
234
235        context: &gdk::DragContext,
236        selection_data: &SelectionData,
237        info: u32,
238        time: u32,
239    ) {
240        self.parent_drag_data_get(context, selection_data, info, time)
241    }
242
243    /// Signal emitted on the drop site when the
244    ///  dragged data has been received.
245    fn drag_data_received(
246        &self,
247
248        context: &gdk::DragContext,
249        x: i32,
250        y: i32,
251        selection_data: &SelectionData,
252        info: u32,
253        time: u32,
254    ) {
255        self.parent_drag_data_received(context, x, y, selection_data, info, time)
256    }
257
258    /// Signal emitted on the drop site when the user drops the
259    ///  data onto the widget.
260    fn drag_drop(&self, context: &gdk::DragContext, x: i32, y: i32, time: u32) -> Propagation {
261        self.parent_drag_drop(context, x, y, time)
262    }
263
264    /// Signal emitted on the drag source when a drag is
265    ///  finished.
266    fn drag_end(&self, context: &gdk::DragContext) {
267        self.parent_drag_end(context)
268    }
269
270    /// Signal emitted on the drag source when a drag has
271    ///  failed.
272    fn drag_failed(&self, context: &gdk::DragContext, result: DragResult) -> Propagation {
273        self.parent_drag_failed(context, result)
274    }
275
276    /// Signal emitted on the drop site when the cursor leaves
277    ///  the widget.
278    fn drag_leave(&self, context: &gdk::DragContext, time: u32) {
279        self.parent_drag_leave(context, time)
280    }
281
282    /// signal emitted on the drop site when the user moves
283    ///  the cursor over the widget during a drag.
284    fn drag_motion(&self, context: &gdk::DragContext, x: i32, y: i32, time: u32) -> Propagation {
285        self.parent_drag_motion(context, x, y, time)
286    }
287
288    /// Signal emitted when a widget is supposed to render itself.
289    fn draw(&self, cr: &cairo::Context) -> Propagation {
290        self.parent_draw(cr)
291    }
292
293    /// Determines whether an accelerator that activates the signal
294    /// identified by `signal_id` can currently be activated.
295    /// This is done by emitting the [`can-activate-accel`][struct@crate::Widget#can-activate-accel]
296    /// signal on `widget`; if the signal isn’t overridden by a
297    /// handler or in a derived widget, then the default check is
298    /// that the widget must be sensitive, and the widget and all
299    /// its ancestors mapped.
300    /// ## `signal_id`
301    /// the ID of a signal installed on `widget`
302    ///
303    /// # Returns
304    ///
305    /// [`true`] if the accelerator can be activated.
306    fn can_activate_accel(&self, signal_id: SignalId) -> bool {
307        self.parent_can_activate_accel(signal_id)
308    }
309
310    /// Gets whether the widget prefers a height-for-width layout
311    /// or a width-for-height layout.
312    ///
313    /// [`Bin`][crate::Bin] widgets generally propagate the preference of
314    /// their child, container widgets need to request something either in
315    /// context of their children or in context of their allocation
316    /// capabilities.
317    ///
318    /// # Returns
319    ///
320    /// The [`SizeRequestMode`][crate::SizeRequestMode] preferred by `widget`.
321    fn request_mode(&self) -> SizeRequestMode {
322        self.parent_request_mode()
323    }
324
325    /// Retrieves a widget’s initial minimum and natural width.
326    ///
327    /// This call is specific to height-for-width requests.
328    ///
329    /// The returned request will be modified by the
330    /// GtkWidgetClass::adjust_size_request virtual method and by any
331    /// `GtkSizeGroups` that have been applied. That is, the returned request
332    /// is the one that should be used for layout, not necessarily the one
333    /// returned by the widget itself.
334    ///
335    /// # Returns
336    ///
337    ///
338    /// ## `minimum_width`
339    /// location to store the minimum width, or [`None`]
340    ///
341    /// ## `natural_width`
342    /// location to store the natural width, or [`None`]
343    fn preferred_width(&self) -> (i32, i32) {
344        self.parent_preferred_width()
345    }
346
347    /// Retrieves a widget’s minimum and natural width if it would be given
348    /// the specified `height`.
349    ///
350    /// The returned request will be modified by the
351    /// GtkWidgetClass::adjust_size_request virtual method and by any
352    /// `GtkSizeGroups` that have been applied. That is, the returned request
353    /// is the one that should be used for layout, not necessarily the one
354    /// returned by the widget itself.
355    /// ## `height`
356    /// the height which is available for allocation
357    ///
358    /// # Returns
359    ///
360    ///
361    /// ## `minimum_width`
362    /// location for storing the minimum width, or [`None`]
363    ///
364    /// ## `natural_width`
365    /// location for storing the natural width, or [`None`]
366    #[doc(alias = "get_preferred_width_for_height")]
367    fn preferred_width_for_height(&self, height: i32) -> (i32, i32) {
368        self.parent_preferred_width_for_height(height)
369    }
370
371    /// Retrieves a widget’s initial minimum and natural height.
372    ///
373    /// This call is specific to width-for-height requests.
374    ///
375    /// The returned request will be modified by the
376    /// GtkWidgetClass::adjust_size_request virtual method and by any
377    /// `GtkSizeGroups` that have been applied. That is, the returned request
378    /// is the one that should be used for layout, not necessarily the one
379    /// returned by the widget itself.
380    ///
381    /// # Returns
382    ///
383    ///
384    /// ## `minimum_height`
385    /// location to store the minimum height, or [`None`]
386    ///
387    /// ## `natural_height`
388    /// location to store the natural height, or [`None`]
389    fn preferred_height(&self) -> (i32, i32) {
390        self.parent_preferred_height()
391    }
392
393    /// Retrieves a widget’s minimum and natural height if it would be given
394    /// the specified `width`.
395    ///
396    /// The returned request will be modified by the
397    /// GtkWidgetClass::adjust_size_request virtual method and by any
398    /// `GtkSizeGroups` that have been applied. That is, the returned request
399    /// is the one that should be used for layout, not necessarily the one
400    /// returned by the widget itself.
401    /// ## `width`
402    /// the width which is available for allocation
403    ///
404    /// # Returns
405    ///
406    ///
407    /// ## `minimum_height`
408    /// location for storing the minimum height, or [`None`]
409    ///
410    /// ## `natural_height`
411    /// location for storing the natural height, or [`None`]
412    #[doc(alias = "get_preferred_height_for_width")]
413    fn preferred_height_for_width(&self, width: i32) -> (i32, i32) {
414        self.parent_preferred_height_for_width(width)
415    }
416
417    /// This function is only used by [`Container`][crate::Container] subclasses, to assign a size
418    /// and position to their child widgets.
419    ///
420    /// In this function, the allocation may be adjusted. It will be forced
421    /// to a 1x1 minimum size, and the adjust_size_allocation virtual
422    /// method on the child will be used to adjust the allocation. Standard
423    /// adjustments include removing the widget’s margins, and applying the
424    /// widget’s [`halign`][struct@crate::Widget#halign] and [`valign`][struct@crate::Widget#valign] properties.
425    ///
426    /// For baseline support in containers you need to use [`WidgetExt::size_allocate_with_baseline()`][crate::prelude::WidgetExt::size_allocate_with_baseline()]
427    /// instead.
428    /// ## `allocation`
429    /// position and size to be allocated to `widget`
430    fn size_allocate(&self, allocation: &Allocation) {
431        self.parent_size_allocate(allocation)
432    }
433
434    /// Creates the GDK (windowing system) resources associated with a
435    /// widget. For example, `widget`->window will be created when a widget
436    /// is realized. Normally realization happens implicitly; if you show
437    /// a widget and all its parent containers, then the widget will be
438    /// realized and mapped automatically.
439    ///
440    /// Realizing a widget requires all
441    /// the widget’s parent widgets to be realized; calling
442    /// [`WidgetExt::realize()`][crate::prelude::WidgetExt::realize()] realizes the widget’s parents in addition to
443    /// `widget` itself. If a widget is not yet inside a toplevel window
444    /// when you realize it, bad things will happen.
445    ///
446    /// This function is primarily used in widget implementations, and
447    /// isn’t very useful otherwise. Many times when you think you might
448    /// need it, a better approach is to connect to a signal that will be
449    /// called after the widget is realized automatically, such as
450    /// [`draw`][struct@crate::Widget#draw]. Or simply g_signal_connect () to the
451    /// [`realize`][struct@crate::Widget#realize] signal.
452    fn realize(&self) {
453        self.parent_realize();
454    }
455
456    /// This function is only useful in widget implementations.
457    /// Causes a widget to be unrealized (frees all GDK resources
458    /// associated with the widget, such as `widget`->window).
459    fn unrealize(&self) {
460        self.parent_unrealize();
461    }
462    /// This function is only for use in widget implementations. Causes
463    /// a widget to be mapped if it isn’t already.
464    fn map(&self) {
465        self.parent_map();
466    }
467
468    /// This function is only for use in widget implementations. Causes
469    /// a widget to be unmapped if it’s currently mapped.
470    fn unmap(&self) {
471        self.parent_unmap();
472    }
473
474    /// Flags a widget to be displayed. Any widget that isn’t shown will
475    /// not appear on the screen. If you want to show all the widgets in a
476    /// container, it’s easier to call [`WidgetExt::show_all()`][crate::prelude::WidgetExt::show_all()] on the
477    /// container, instead of individually showing the widgets.
478    ///
479    /// Remember that you have to show the containers containing a widget,
480    /// in addition to the widget itself, before it will appear onscreen.
481    ///
482    /// When a toplevel container is shown, it is immediately realized and
483    /// mapped; other shown widgets are realized and mapped when their
484    /// toplevel container is realized and mapped.
485    fn show(&self) {
486        self.parent_show();
487    }
488
489    /// Reverses the effects of [`WidgetExt::show()`][crate::prelude::WidgetExt::show()], causing the widget to be
490    /// hidden (invisible to the user).
491    fn hide(&self) {
492        self.parent_hide();
493    }
494
495    /// Causes `widget` to have the keyboard focus for the [`Window`][crate::Window] it's
496    /// inside. `widget` must be a focusable widget, such as a [`Entry`][crate::Entry];
497    /// something like [`Frame`][crate::Frame] won’t work.
498    ///
499    /// More precisely, it must have the `GTK_CAN_FOCUS` flag set. Use
500    /// [`WidgetExt::set_can_focus()`][crate::prelude::WidgetExt::set_can_focus()] to modify that flag.
501    ///
502    /// The widget also needs to be realized and mapped. This is indicated by the
503    /// related signals. Grabbing the focus immediately after creating the widget
504    /// will likely fail and cause critical warnings.
505    fn grab_focus(&self) {
506        self.parent_grab_focus();
507    }
508
509    fn focus(&self, direction: DirectionType) -> bool {
510        self.parent_focus(direction)
511    }
512
513    /// Signal emitted when the pointer moves over
514    ///  the widget’s [`gdk::Window`][crate::gdk::Window].
515    fn motion_notify_event(&self, event: &gdk::EventMotion) -> Propagation {
516        self.parent_motion_notify_event(event)
517    }
518
519    /// Signal emitted when a button in the 4 to 7 range is
520    ///  pressed.
521    fn scroll_event(&self, event: &gdk::EventScroll) -> Propagation {
522        self.parent_scroll_event(event)
523    }
524
525    /// Signal event will be emitted when the pointer
526    ///  enters the widget’s window.
527    fn enter_notify_event(&self, event: &gdk::EventCrossing) -> Propagation {
528        self.parent_enter_notify_event(event)
529    }
530
531    /// Will be emitted when the pointer leaves the
532    ///  widget’s window.
533    fn leave_notify_event(&self, event: &gdk::EventCrossing) -> Propagation {
534        self.parent_leave_notify_event(event)
535    }
536
537    /// Signal emitted when the keyboard focus enters the
538    /// widget’s window.
539    fn focus_in_event(&self, event: &gdk::EventFocus) -> Propagation {
540        self.parent_focus_in_event(event)
541    }
542
543    /// Signal emitted when the keyboard focus leaves the
544    /// widget’s window.
545    fn focus_out_event(&self, event: &gdk::EventFocus) -> Propagation {
546        self.parent_focus_out_event(event)
547    }
548
549    /// Signal emitted when a key is pressed.
550    fn key_press_event(&self, event: &gdk::EventKey) -> Propagation {
551        self.parent_key_press_event(event)
552    }
553
554    /// Signal is emitted when a key is released.
555    fn key_release_event(&self, event: &gdk::EventKey) -> Propagation {
556        self.parent_key_release_event(event)
557    }
558
559    /// Signal emitted when the widget’s window is mapped.
560    fn map_event(&self, event: &gdk::Event) -> Propagation {
561        self.parent_map_event(event)
562    }
563
564    /// Signal will be emitted when the widget’s window is
565    ///  unmapped.
566    fn unmap_event(&self, event: &gdk::Event) -> Propagation {
567        self.parent_unmap_event(event)
568    }
569
570    /// Recursively shows a widget, and any child widgets (if the widget is
571    /// a container).
572    fn show_all(&self) {
573        self.parent_show_all();
574    }
575
576    /// Signal emitted when the widget state changes,
577    ///  see [`WidgetExt::state_flags()`][crate::prelude::WidgetExt::state_flags()].
578    fn state_flags_changed(&self, previous_state_flags: StateFlags) {
579        self.parent_state_flags_changed(previous_state_flags);
580    }
581
582    /// Signal emitted when a new parent has been set on a
583    ///  widget.
584    fn parent_set(&self, previous_parent: Option<&Widget>) {
585        self.parent_parent_set(previous_parent);
586    }
587
588    /// Signal emitted when the anchored state of a
589    ///  widget changes.
590    fn hierarchy_changed(&self, previous_toplevel: Option<&Widget>) {
591        self.parent_hierarchy_changed(previous_toplevel);
592    }
593
594    /// Signal emitted when a widget becomes shadowed by a
595    ///  GTK+ grab (not a pointer or keyboard grab) on another widget, or
596    ///  when it becomes unshadowed due to a grab being removed.
597    fn grab_notify(&self, was_grabbed: bool) {
598        self.parent_grab_notify(was_grabbed);
599    }
600
601    /// Emits the [`mnemonic-activate`][struct@crate::Widget#mnemonic-activate] signal.
602    /// ## `group_cycling`
603    /// [`true`] if there are other widgets with the same mnemonic
604    ///
605    /// # Returns
606    ///
607    /// [`true`] if the signal has been handled
608    fn mnemonic_activate(&self, group_cycling: bool) -> bool {
609        self.parent_mnemonic_activate(group_cycling)
610    }
611
612    /// Signal emitted when a change of focus is requested
613    fn move_focus(&self, direction: DirectionType) {
614        self.parent_move_focus(direction);
615    }
616
617    /// This function should be called whenever keyboard navigation within
618    /// a single widget hits a boundary. The function emits the
619    /// [`keynav-failed`][struct@crate::Widget#keynav-failed] signal on the widget and its return
620    /// value should be interpreted in a way similar to the return value of
621    /// [`WidgetExt::child_focus()`][crate::prelude::WidgetExt::child_focus()]:
622    ///
623    /// When [`true`] is returned, stay in the widget, the failed keyboard
624    /// navigation is OK and/or there is nowhere we can/should move the
625    /// focus to.
626    ///
627    /// When [`false`] is returned, the caller should continue with keyboard
628    /// navigation outside the widget, e.g. by calling
629    /// [`WidgetExt::child_focus()`][crate::prelude::WidgetExt::child_focus()] on the widget’s toplevel.
630    ///
631    /// The default ::keynav-failed handler returns [`false`] for
632    /// [`DirectionType::TabForward`][crate::DirectionType::TabForward] and [`DirectionType::TabBackward`][crate::DirectionType::TabBackward]. For the other
633    /// values of [`DirectionType`][crate::DirectionType] it returns [`true`].
634    ///
635    /// Whenever the default handler returns [`true`], it also calls
636    /// [`WidgetExt::error_bell()`][crate::prelude::WidgetExt::error_bell()] to notify the user of the failed keyboard
637    /// navigation.
638    ///
639    /// A use case for providing an own implementation of ::keynav-failed
640    /// (either by connecting to it or by overriding it) would be a row of
641    /// [`Entry`][crate::Entry] widgets where the user should be able to navigate the
642    /// entire row with the cursor keys, as e.g. known from user interfaces
643    /// that require entering license keys.
644    /// ## `direction`
645    /// direction of focus movement
646    ///
647    /// # Returns
648    ///
649    /// [`true`] if stopping keyboard navigation is fine, [`false`]
650    ///  if the emitting widget should try to handle the keyboard
651    ///  navigation attempt in its parent container(s).
652    fn keynav_failed(&self, direction: DirectionType) -> bool {
653        self.parent_keynav_failed(direction)
654    }
655
656    /// Rarely-used function. This function is used to emit
657    /// the event signals on a widget (those signals should never
658    /// be emitted without using this function to do so).
659    /// If you want to synthesize an event though, don’t use this function;
660    /// instead, use [`main_do_event()`][crate::main_do_event()] so the event will behave as if
661    /// it were in the event queue. Don’t synthesize expose events; instead,
662    /// use [`Window::invalidate_rect()`][crate::gdk::Window::invalidate_rect()] to invalidate a region of the
663    /// window.
664    /// ## `event`
665    /// a `GdkEvent`
666    ///
667    /// # Returns
668    ///
669    /// return from the event signal emission ([`true`] if
670    ///  the event was handled)
671    fn event(&self, event: &gdk::Event) -> Propagation {
672        self.parent_event(event)
673    }
674
675    /// Signal will be emitted when a property on
676    ///  the widget’s window has been changed or deleted.
677    fn property_notify_event(&self, event: &gdk::EventProperty) -> Propagation {
678        self.parent_property_notify_event(event)
679    }
680
681    /// Signal will be emitted when the the
682    ///  widget’s window has lost ownership of a selection.
683    fn selection_clear_event(&self, event: &gdk::EventSelection) -> Propagation {
684        self.parent_selection_clear_event(event)
685    }
686
687    /// Signal will be emitted when another
688    ///  client requests ownership of the selection owned by the widget's
689    ///  window.
690    fn selection_request_event(&self, event: &gdk::EventSelection) -> Propagation {
691        self.parent_selection_request_event(event)
692    }
693
694    fn selection_notify_event(&self, event: &gdk::EventSelection) -> Propagation {
695        self.parent_selection_notify_event(event)
696    }
697
698    fn proximity_in_event(&self, event: &gdk::EventProximity) -> Propagation {
699        self.parent_proximity_in_event(event)
700    }
701
702    fn proximity_out_event(&self, event: &gdk::EventProximity) -> Propagation {
703        self.parent_proximity_out_event(event)
704    }
705
706    /// Signal emitted when the widget’s window is
707    ///  obscured or unobscured.
708    fn visibility_notify_event(&self, event: &gdk::EventVisibility) -> Propagation {
709        self.parent_visibility_notify_event(event)
710    }
711
712    /// Signal emitted when a pointer or keyboard grab
713    ///  on a window belonging to widget gets broken.
714    fn grab_broken_event(&self, event: &gdk::EventGrabBroken) -> Propagation {
715        self.parent_grab_broken_event(event)
716    }
717
718    /// Signal emitted when a touch event happens
719    fn touch_event(&self, event: &gdk::EventTouch) -> Propagation {
720        self.parent_touch_event(event)
721    }
722
723    fn selection_get(&self, selection_data: &SelectionData, info: u32, time: u32) {
724        self.parent_selection_get(selection_data, info, time);
725    }
726
727    fn selection_received(&self, selection_data: &SelectionData, time: u32) {
728        self.parent_selection_received(selection_data, time);
729    }
730
731    /// Signal emitted whenever a widget should pop up a
732    ///  context menu.
733    fn popup_menu(&self) -> bool {
734        self.parent_popup_menu()
735    }
736
737    fn show_help(&self, help_type: WidgetHelpType) -> bool {
738        self.parent_show_help(help_type)
739    }
740
741    /// Signal emitted when the screen of a widget has
742    ///  changed.
743    fn screen_changed(&self, previous_screen: Option<&gdk::Screen>) {
744        self.parent_screen_changed(previous_screen);
745    }
746
747    /// Signal emitted when “has-tooltip” is [`true`] and the
748    ///  hover timeout has expired with the cursor hovering “above”
749    ///  widget; or emitted when widget got focus in keyboard mode.
750    fn query_tooltip(&self, x: i32, y: i32, keyboard_tooltip: bool, tooltip: &Tooltip) -> bool {
751        self.parent_query_tooltip(x, y, keyboard_tooltip, tooltip)
752    }
753
754    /// Signal emitted when the GtkStyleContext of a widget
755    ///  is changed.
756    fn style_updated(&self) {
757        self.parent_style_updated();
758    }
759
760    /// Invalidates the area of `widget` defined by `region` by calling
761    /// [`Window::invalidate_region()`][crate::gdk::Window::invalidate_region()] on the widget’s window and all its
762    /// child windows. Once the main loop becomes idle (after the current
763    /// batch of events has been processed, roughly), the window will
764    /// receive expose events for the union of all regions that have been
765    /// invalidated.
766    ///
767    /// Normally you would only use this function in widget
768    /// implementations. You might also use it to schedule a redraw of a
769    /// [`DrawingArea`][crate::DrawingArea] or some portion thereof.
770    /// ## `region`
771    /// region to draw
772    fn queue_draw_region(&self, region: &cairo::Region) {
773        self.parent_queue_draw_region(region);
774    }
775}
776
777pub trait WidgetImplExt: WidgetImpl {
778    fn parent_adjust_baseline_allocation(&self, baseline: &mut i32) {
779        unsafe {
780            let data = Self::type_data();
781            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
782            let f = (*parent_class)
783                .adjust_baseline_allocation
784                .expect("No parent class impl for \"adjust_baseline_allocation\"");
785            f(
786                self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
787                baseline,
788            )
789        }
790    }
791    fn parent_adjust_baseline_request(
792        &self,
793
794        minimum_baseline: &mut i32,
795        natural_baseline: &mut i32,
796    ) {
797        unsafe {
798            let data = Self::type_data();
799            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
800            let f = (*parent_class)
801                .adjust_baseline_request
802                .expect("No parent class impl for \"adjust_baseline_request\"");
803            f(
804                self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
805                minimum_baseline,
806                natural_baseline,
807            )
808        }
809    }
810
811    fn parent_preferred_height_and_baseline_for_width(&self, width: i32) -> (i32, i32, i32, i32) {
812        unsafe {
813            let data = Self::type_data();
814            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
815            if let Some(f) = (*parent_class).get_preferred_height_and_baseline_for_width {
816                let mut minimum_height = mem::MaybeUninit::uninit();
817                let mut natural_height = mem::MaybeUninit::uninit();
818                let mut minimum_baseline = -1;
819                let mut natural_baseline = -1;
820                f(
821                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
822                    width,
823                    minimum_height.as_mut_ptr(),
824                    natural_height.as_mut_ptr(),
825                    &mut minimum_baseline,
826                    &mut natural_baseline,
827                );
828                (
829                    minimum_height.assume_init(),
830                    natural_height.assume_init(),
831                    minimum_baseline,
832                    natural_baseline,
833                )
834            } else {
835                // The parent hasn't wired up baseline support, so do the fallback calculation
836                // exactly how GTK does it when there's no baseline support. This has to go through
837                // `self` and not `parent_*`, because we installed the baseline vfunc, which makes
838                // GTK route *every* height query here instead of calling get_preferred_height or
839                // get_preferred_height_for_width on our impl, so this is the only way to get the
840                // correct result.
841                let (minimum, natural) = if width < 0 {
842                    self.preferred_height()
843                } else {
844                    self.preferred_height_for_width(width)
845                };
846                (minimum, natural, -1, -1)
847            }
848        }
849    }
850
851    fn parent_adjust_size_allocation(
852        &self,
853
854        orientation: Orientation,
855        minimum_size: &mut i32,
856        natural_size: &mut i32,
857        allocated_pos: &mut i32,
858        allocated_size: &mut i32,
859    ) {
860        unsafe {
861            let data = Self::type_data();
862            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
863            let f = (*parent_class)
864                .adjust_size_allocation
865                .expect("No parent class impl for \"adjust_size_allocation\"");
866            f(
867                self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
868                orientation.into_glib(),
869                minimum_size,
870                natural_size,
871                allocated_pos,
872                allocated_size,
873            )
874        }
875    }
876    fn parent_adjust_size_request(
877        &self,
878
879        orientation: Orientation,
880        minimum_size: &mut i32,
881        natural_size: &mut i32,
882    ) {
883        unsafe {
884            let data = Self::type_data();
885            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
886            let f = (*parent_class)
887                .adjust_size_request
888                .expect("No parent class impl for \"adjust_size_request\"");
889            f(
890                self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
891                orientation.into_glib(),
892                minimum_size as *mut i32,
893                natural_size as *mut i32,
894            )
895        }
896    }
897    fn parent_button_press_event(&self, event: &gdk::EventButton) -> Propagation {
898        unsafe {
899            let data = Self::type_data();
900            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
901            if let Some(f) = (*parent_class).button_press_event {
902                let ev_glib = glib::translate::mut_override(event.to_glib_none().0);
903                Propagation::from_glib(f(
904                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
905                    ev_glib,
906                ))
907            } else {
908                Propagation::Proceed
909            }
910        }
911    }
912    fn parent_button_release_event(&self, event: &gdk::EventButton) -> Propagation {
913        unsafe {
914            let data = Self::type_data();
915            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
916            if let Some(f) = (*parent_class).button_release_event {
917                let ev_glib = glib::translate::mut_override(event.to_glib_none().0);
918                Propagation::from_glib(f(
919                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
920                    ev_glib,
921                ))
922            } else {
923                Propagation::Proceed
924            }
925        }
926    }
927    fn parent_can_activate_accel(&self, signal_id: SignalId) -> bool {
928        unsafe {
929            let data = Self::type_data();
930            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
931            if let Some(f) = (*parent_class).can_activate_accel {
932                from_glib(f(
933                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
934                    signal_id.into_glib(),
935                ))
936            } else {
937                false
938            }
939        }
940    }
941    fn parent_child_notify(&self, child_property: &glib::ParamSpec) {
942        unsafe {
943            let data = Self::type_data();
944            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
945            if let Some(f) = (*parent_class).child_notify {
946                let pspec_glib = glib::translate::mut_override(child_property.to_glib_none().0);
947                f(
948                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
949                    pspec_glib,
950                )
951            }
952        }
953    }
954    fn parent_composited_changed(&self) {
955        unsafe {
956            let data = Self::type_data();
957            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
958            if let Some(f) = (*parent_class).composited_changed {
959                f(self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0)
960            }
961        }
962    }
963    fn parent_compute_expand(&self, hexpand: &mut bool, vexpand: &mut bool) {
964        unsafe {
965            let data = Self::type_data();
966            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
967            let widget = self.obj();
968            let widget = widget.unsafe_cast_ref::<Widget>();
969            if let Some(f) = (*parent_class).compute_expand {
970                let mut hexpand_glib = hexpand.into_glib();
971                let mut vexpand_glib = vexpand.into_glib();
972                f(
973                    widget.to_glib_none().0,
974                    &mut hexpand_glib,
975                    &mut vexpand_glib,
976                );
977                *hexpand = from_glib(hexpand_glib);
978                *vexpand = from_glib(vexpand_glib);
979            }
980        }
981    }
982    fn parent_configure_event(&self, event: &gdk::EventConfigure) -> Propagation {
983        unsafe {
984            let data = Self::type_data();
985            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
986            if let Some(f) = (*parent_class).configure_event {
987                let ev_glib = glib::translate::mut_override(event.to_glib_none().0);
988                Propagation::from_glib(f(
989                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
990                    ev_glib,
991                ))
992            } else {
993                Propagation::Proceed
994            }
995        }
996    }
997    fn parent_window_state_event(&self, event: &gdk::EventWindowState) -> Propagation {
998        unsafe {
999            let data = Self::type_data();
1000            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1001            if let Some(f) = (*parent_class).window_state_event {
1002                let ev_glib = glib::translate::mut_override(event.to_glib_none().0);
1003                Propagation::from_glib(f(
1004                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1005                    ev_glib,
1006                ))
1007            } else {
1008                Propagation::Proceed
1009            }
1010        }
1011    }
1012    fn parent_damage_event(&self, event: &gdk::EventExpose) -> Propagation {
1013        unsafe {
1014            let data = Self::type_data();
1015            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1016            if let Some(f) = (*parent_class).damage_event {
1017                let ev_glib = glib::translate::mut_override(event.to_glib_none().0);
1018                Propagation::from_glib(f(
1019                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1020                    ev_glib,
1021                ))
1022            } else {
1023                Propagation::Proceed
1024            }
1025        }
1026    }
1027    fn parent_delete_event(&self, event: &gdk::Event) -> Propagation {
1028        unsafe {
1029            let data = Self::type_data();
1030            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1031            if let Some(f) = (*parent_class).delete_event {
1032                let ev_glib = glib::translate::mut_override(event.to_glib_none().0);
1033                Propagation::from_glib(f(
1034                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1035                    ev_glib,
1036                ))
1037            } else {
1038                Propagation::Proceed
1039            }
1040        }
1041    }
1042    fn parent_destroy(&self) {
1043        unsafe {
1044            let data = Self::type_data();
1045            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1046            if let Some(f) = (*parent_class).destroy {
1047                f(self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0)
1048            }
1049        }
1050    }
1051    fn parent_destroy_event(&self, event: &gdk::Event) -> Propagation {
1052        unsafe {
1053            let data = Self::type_data();
1054            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1055            if let Some(f) = (*parent_class).destroy_event {
1056                let ev_glib = glib::translate::mut_override(event.to_glib_none().0);
1057                Propagation::from_glib(f(
1058                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1059                    ev_glib,
1060                ))
1061            } else {
1062                Propagation::Proceed
1063            }
1064        }
1065    }
1066    fn parent_direction_changed(&self, previous_direction: TextDirection) {
1067        unsafe {
1068            let data = Self::type_data();
1069            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1070            if let Some(f) = (*parent_class).direction_changed {
1071                f(
1072                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1073                    previous_direction.into_glib(),
1074                )
1075            }
1076        }
1077    }
1078    fn parent_dispatch_child_properties_changed(&self, pspecs: &[glib::ParamSpec]) {
1079        unsafe {
1080            let data = Self::type_data();
1081            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1082            if let Some(f) = (*parent_class).dispatch_child_properties_changed {
1083                let mut pspecs_array = pspecs
1084                    .iter()
1085                    .map(|p| p.to_glib_none().0)
1086                    .collect::<Vec<_>>();
1087                let pspecs_ptr = pspecs_array.as_mut_ptr();
1088                f(
1089                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1090                    pspecs.len() as u32,
1091                    pspecs_ptr,
1092                )
1093            }
1094        }
1095    }
1096    fn parent_drag_begin(&self, context: &gdk::DragContext) {
1097        unsafe {
1098            let data = Self::type_data();
1099            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1100            if let Some(f) = (*parent_class).drag_begin {
1101                f(
1102                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1103                    context.to_glib_none().0,
1104                )
1105            }
1106        }
1107    }
1108    fn parent_drag_data_delete(&self, context: &gdk::DragContext) {
1109        unsafe {
1110            let data = Self::type_data();
1111            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1112            if let Some(f) = (*parent_class).drag_data_delete {
1113                f(
1114                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1115                    context.to_glib_none().0,
1116                )
1117            }
1118        }
1119    }
1120    fn parent_drag_data_get(
1121        &self,
1122
1123        context: &gdk::DragContext,
1124        selection_data: &SelectionData,
1125        info: u32,
1126        time: u32,
1127    ) {
1128        unsafe {
1129            let data = Self::type_data();
1130            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1131            if let Some(f) = (*parent_class).drag_data_get {
1132                let selection_mut = glib::translate::mut_override(selection_data.to_glib_none().0);
1133                f(
1134                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1135                    context.to_glib_none().0,
1136                    selection_mut,
1137                    info,
1138                    time,
1139                )
1140            }
1141        }
1142    }
1143    fn parent_drag_data_received(
1144        &self,
1145
1146        context: &gdk::DragContext,
1147        x: i32,
1148        y: i32,
1149        selection_data: &SelectionData,
1150        info: u32,
1151        time: u32,
1152    ) {
1153        unsafe {
1154            let data = Self::type_data();
1155            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1156            if let Some(f) = (*parent_class).drag_data_received {
1157                let selection_mut = glib::translate::mut_override(selection_data.to_glib_none().0);
1158                f(
1159                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1160                    context.to_glib_none().0,
1161                    x,
1162                    y,
1163                    selection_mut,
1164                    info,
1165                    time,
1166                )
1167            }
1168        }
1169    }
1170    fn parent_drag_drop(
1171        &self,
1172        context: &gdk::DragContext,
1173        x: i32,
1174        y: i32,
1175        time: u32,
1176    ) -> Propagation {
1177        unsafe {
1178            let data = Self::type_data();
1179            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1180            if let Some(f) = (*parent_class).drag_drop {
1181                Propagation::from_glib(f(
1182                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1183                    context.to_glib_none().0,
1184                    x,
1185                    y,
1186                    time,
1187                ))
1188            } else {
1189                Propagation::Proceed
1190            }
1191        }
1192    }
1193    fn parent_drag_end(&self, context: &gdk::DragContext) {
1194        unsafe {
1195            let data = Self::type_data();
1196            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1197            if let Some(f) = (*parent_class).drag_end {
1198                f(
1199                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1200                    context.to_glib_none().0,
1201                )
1202            }
1203        }
1204    }
1205    fn parent_drag_failed(&self, context: &gdk::DragContext, result: DragResult) -> Propagation {
1206        unsafe {
1207            let data = Self::type_data();
1208            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1209            if let Some(f) = (*parent_class).drag_failed {
1210                Propagation::from_glib(f(
1211                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1212                    context.to_glib_none().0,
1213                    result.into_glib(),
1214                ))
1215            } else {
1216                Propagation::Proceed
1217            }
1218        }
1219    }
1220    fn parent_drag_leave(&self, context: &gdk::DragContext, time: u32) {
1221        unsafe {
1222            let data = Self::type_data();
1223            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1224            if let Some(f) = (*parent_class).drag_leave {
1225                f(
1226                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1227                    context.to_glib_none().0,
1228                    time,
1229                )
1230            }
1231        }
1232    }
1233    fn parent_drag_motion(
1234        &self,
1235        context: &gdk::DragContext,
1236        x: i32,
1237        y: i32,
1238        time: u32,
1239    ) -> Propagation {
1240        unsafe {
1241            let data = Self::type_data();
1242            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1243            if let Some(f) = (*parent_class).drag_motion {
1244                Propagation::from_glib(f(
1245                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1246                    context.to_glib_none().0,
1247                    x,
1248                    y,
1249                    time,
1250                ))
1251            } else {
1252                Propagation::Proceed
1253            }
1254        }
1255    }
1256    fn parent_draw(&self, cr: &cairo::Context) -> Propagation {
1257        unsafe {
1258            let data = Self::type_data();
1259            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1260            if let Some(f) = (*parent_class).draw {
1261                Propagation::from_glib(f(
1262                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1263                    cr.to_glib_none().0,
1264                ))
1265            } else {
1266                Propagation::Proceed
1267            }
1268        }
1269    }
1270    fn parent_request_mode(&self) -> SizeRequestMode {
1271        unsafe {
1272            let data = Self::type_data();
1273            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1274            let f = (*parent_class).get_request_mode.unwrap();
1275            from_glib(f(self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0))
1276        }
1277    }
1278    fn parent_preferred_width(&self) -> (i32, i32) {
1279        unsafe {
1280            let data = Self::type_data();
1281            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1282            let f = (*parent_class).get_preferred_width.unwrap();
1283
1284            let mut minimum_size = mem::MaybeUninit::uninit();
1285            let mut natural_size = mem::MaybeUninit::uninit();
1286            f(
1287                self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1288                minimum_size.as_mut_ptr(),
1289                natural_size.as_mut_ptr(),
1290            );
1291            (minimum_size.assume_init(), natural_size.assume_init())
1292        }
1293    }
1294    fn parent_preferred_width_for_height(&self, height: i32) -> (i32, i32) {
1295        unsafe {
1296            let data = Self::type_data();
1297            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1298            let f = (*parent_class).get_preferred_width_for_height.unwrap();
1299
1300            let mut minimum_size = mem::MaybeUninit::uninit();
1301            let mut natural_size = mem::MaybeUninit::uninit();
1302            f(
1303                self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1304                height,
1305                minimum_size.as_mut_ptr(),
1306                natural_size.as_mut_ptr(),
1307            );
1308            (minimum_size.assume_init(), natural_size.assume_init())
1309        }
1310    }
1311    fn parent_preferred_height(&self) -> (i32, i32) {
1312        unsafe {
1313            let data = Self::type_data();
1314            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1315            let f = (*parent_class).get_preferred_height.unwrap();
1316            let mut minimum_size = mem::MaybeUninit::uninit();
1317            let mut natural_size = mem::MaybeUninit::uninit();
1318            f(
1319                self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1320                minimum_size.as_mut_ptr(),
1321                natural_size.as_mut_ptr(),
1322            );
1323            (minimum_size.assume_init(), natural_size.assume_init())
1324        }
1325    }
1326    fn parent_preferred_height_for_width(&self, width: i32) -> (i32, i32) {
1327        unsafe {
1328            let data = Self::type_data();
1329            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1330            let f = (*parent_class).get_preferred_height_for_width.unwrap();
1331            let mut minimum_size = mem::MaybeUninit::uninit();
1332            let mut natural_size = mem::MaybeUninit::uninit();
1333            f(
1334                self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1335                width,
1336                minimum_size.as_mut_ptr(),
1337                natural_size.as_mut_ptr(),
1338            );
1339            (minimum_size.assume_init(), natural_size.assume_init())
1340        }
1341    }
1342    fn parent_size_allocate(&self, allocation: &Allocation) {
1343        unsafe {
1344            let data = Self::type_data();
1345            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1346            let f = (*parent_class)
1347                .size_allocate
1348                .expect("No parent class impl for \"size_allocate\"");
1349            f(
1350                self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1351                mut_override(allocation.to_glib_none().0),
1352            );
1353        }
1354    }
1355    fn parent_realize(&self) {
1356        unsafe {
1357            let data = Self::type_data();
1358            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1359            if let Some(f) = (*parent_class).realize {
1360                f(self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0);
1361            }
1362        }
1363    }
1364    fn parent_unrealize(&self) {
1365        unsafe {
1366            let data = Self::type_data();
1367            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1368            if let Some(f) = (*parent_class).unrealize {
1369                f(self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0);
1370            }
1371        }
1372    }
1373    fn parent_map(&self) {
1374        unsafe {
1375            let data = Self::type_data();
1376            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1377            if let Some(f) = (*parent_class).map {
1378                f(self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0);
1379            }
1380        }
1381    }
1382    fn parent_unmap(&self) {
1383        unsafe {
1384            let data = Self::type_data();
1385            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1386            if let Some(f) = (*parent_class).unmap {
1387                f(self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0);
1388            }
1389        }
1390    }
1391
1392    fn parent_show(&self) {
1393        unsafe {
1394            let data = Self::type_data();
1395            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1396            if let Some(f) = (*parent_class).show {
1397                f(self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0);
1398            }
1399        }
1400    }
1401
1402    fn parent_hide(&self) {
1403        unsafe {
1404            let data = Self::type_data();
1405            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1406            if let Some(f) = (*parent_class).hide {
1407                f(self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0);
1408            }
1409        }
1410    }
1411
1412    fn parent_grab_focus(&self) {
1413        unsafe {
1414            let data = Self::type_data();
1415            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1416            if let Some(f) = (*parent_class).grab_focus {
1417                f(self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0);
1418            }
1419        }
1420    }
1421
1422    fn parent_focus(&self, direction: DirectionType) -> bool {
1423        unsafe {
1424            let data = Self::type_data();
1425            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1426            if let Some(f) = (*parent_class).focus {
1427                from_glib(f(
1428                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1429                    direction.into_glib(),
1430                ))
1431            } else {
1432                false
1433            }
1434        }
1435    }
1436
1437    fn parent_motion_notify_event(&self, event: &gdk::EventMotion) -> Propagation {
1438        unsafe {
1439            let data = Self::type_data();
1440            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1441            if let Some(f) = (*parent_class).motion_notify_event {
1442                Propagation::from_glib(f(
1443                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1444                    mut_override(event.to_glib_none().0),
1445                ))
1446            } else {
1447                Propagation::Proceed
1448            }
1449        }
1450    }
1451    fn parent_scroll_event(&self, event: &gdk::EventScroll) -> Propagation {
1452        unsafe {
1453            let data = Self::type_data();
1454            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1455            if let Some(f) = (*parent_class).scroll_event {
1456                Propagation::from_glib(f(
1457                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1458                    mut_override(event.to_glib_none().0),
1459                ))
1460            } else {
1461                Propagation::Proceed
1462            }
1463        }
1464    }
1465    fn parent_enter_notify_event(&self, event: &gdk::EventCrossing) -> Propagation {
1466        unsafe {
1467            let data = Self::type_data();
1468            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1469            if let Some(f) = (*parent_class).enter_notify_event {
1470                Propagation::from_glib(f(
1471                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1472                    mut_override(event.to_glib_none().0),
1473                ))
1474            } else {
1475                Propagation::Proceed
1476            }
1477        }
1478    }
1479    fn parent_leave_notify_event(&self, event: &gdk::EventCrossing) -> Propagation {
1480        unsafe {
1481            let data = Self::type_data();
1482            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1483            if let Some(f) = (*parent_class).leave_notify_event {
1484                Propagation::from_glib(f(
1485                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1486                    mut_override(event.to_glib_none().0),
1487                ))
1488            } else {
1489                Propagation::Proceed
1490            }
1491        }
1492    }
1493
1494    fn parent_focus_in_event(&self, event: &gdk::EventFocus) -> Propagation {
1495        unsafe {
1496            let data = Self::type_data();
1497            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1498            if let Some(f) = (*parent_class).focus_in_event {
1499                Propagation::from_glib(f(
1500                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1501                    mut_override(event.to_glib_none().0),
1502                ))
1503            } else {
1504                Propagation::Proceed
1505            }
1506        }
1507    }
1508
1509    fn parent_focus_out_event(&self, event: &gdk::EventFocus) -> Propagation {
1510        unsafe {
1511            let data = Self::type_data();
1512            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1513            if let Some(f) = (*parent_class).focus_out_event {
1514                Propagation::from_glib(f(
1515                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1516                    mut_override(event.to_glib_none().0),
1517                ))
1518            } else {
1519                Propagation::Proceed
1520            }
1521        }
1522    }
1523
1524    fn parent_key_press_event(&self, event: &gdk::EventKey) -> Propagation {
1525        unsafe {
1526            let data = Self::type_data();
1527            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1528            if let Some(f) = (*parent_class).key_press_event {
1529                Propagation::from_glib(f(
1530                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1531                    mut_override(event.to_glib_none().0),
1532                ))
1533            } else {
1534                Propagation::Proceed
1535            }
1536        }
1537    }
1538
1539    fn parent_key_release_event(&self, event: &gdk::EventKey) -> Propagation {
1540        unsafe {
1541            let data = Self::type_data();
1542            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1543            if let Some(f) = (*parent_class).key_release_event {
1544                Propagation::from_glib(f(
1545                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1546                    mut_override(event.to_glib_none().0),
1547                ))
1548            } else {
1549                Propagation::Proceed
1550            }
1551        }
1552    }
1553
1554    fn parent_map_event(&self, event: &gdk::Event) -> Propagation {
1555        unsafe {
1556            let data = Self::type_data();
1557            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1558            if let Some(f) = (*parent_class).map_event {
1559                Propagation::from_glib(f(
1560                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1561                    mut_override(event.to_glib_none().0),
1562                ))
1563            } else {
1564                Propagation::Proceed
1565            }
1566        }
1567    }
1568
1569    fn parent_unmap_event(&self, event: &gdk::Event) -> Propagation {
1570        unsafe {
1571            let data = Self::type_data();
1572            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1573            if let Some(f) = (*parent_class).unmap_event {
1574                Propagation::from_glib(f(
1575                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1576                    mut_override(event.to_glib_none().0),
1577                ))
1578            } else {
1579                Propagation::Proceed
1580            }
1581        }
1582    }
1583
1584    fn parent_show_all(&self) {
1585        unsafe {
1586            let data = Self::type_data();
1587            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1588            if let Some(f) = (*parent_class).show_all {
1589                f(self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0);
1590            }
1591        }
1592    }
1593
1594    fn parent_state_flags_changed(&self, previous_state_flags: StateFlags) {
1595        unsafe {
1596            let data = Self::type_data();
1597            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1598            if let Some(f) = (*parent_class).state_flags_changed {
1599                f(
1600                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1601                    previous_state_flags.into_glib(),
1602                );
1603            }
1604        }
1605    }
1606
1607    fn parent_parent_set(&self, previous_parent: Option<&Widget>) {
1608        unsafe {
1609            let data = Self::type_data();
1610            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1611            if let Some(f) = (*parent_class).parent_set {
1612                f(
1613                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1614                    previous_parent.to_glib_none().0,
1615                );
1616            }
1617        }
1618    }
1619
1620    fn parent_hierarchy_changed(&self, previous_toplevel: Option<&Widget>) {
1621        unsafe {
1622            let data = Self::type_data();
1623            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1624            if let Some(f) = (*parent_class).hierarchy_changed {
1625                f(
1626                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1627                    previous_toplevel.to_glib_none().0,
1628                );
1629            }
1630        }
1631    }
1632
1633    fn parent_grab_notify(&self, was_grabbed: bool) {
1634        unsafe {
1635            let data = Self::type_data();
1636            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1637            if let Some(f) = (*parent_class).grab_notify {
1638                f(
1639                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1640                    was_grabbed.into_glib(),
1641                );
1642            }
1643        }
1644    }
1645
1646    fn parent_mnemonic_activate(&self, group_cycling: bool) -> bool {
1647        unsafe {
1648            let data = Self::type_data();
1649            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1650            if let Some(f) = (*parent_class).mnemonic_activate {
1651                from_glib(f(
1652                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1653                    group_cycling.into_glib(),
1654                ))
1655            } else {
1656                false
1657            }
1658        }
1659    }
1660
1661    fn parent_move_focus(&self, direction: DirectionType) {
1662        unsafe {
1663            let data = Self::type_data();
1664            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1665            if let Some(f) = (*parent_class).move_focus {
1666                f(
1667                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1668                    direction.into_glib(),
1669                );
1670            }
1671        }
1672    }
1673
1674    fn parent_keynav_failed(&self, direction: DirectionType) -> bool {
1675        unsafe {
1676            let data = Self::type_data();
1677            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1678            if let Some(f) = (*parent_class).keynav_failed {
1679                from_glib(f(
1680                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1681                    direction.into_glib(),
1682                ))
1683            } else {
1684                false
1685            }
1686        }
1687    }
1688
1689    fn parent_event(&self, event: &gdk::Event) -> Propagation {
1690        unsafe {
1691            let data = Self::type_data();
1692            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1693            if let Some(f) = (*parent_class).event {
1694                Propagation::from_glib(f(
1695                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1696                    mut_override(event.to_glib_none().0),
1697                ))
1698            } else {
1699                Propagation::Proceed
1700            }
1701        }
1702    }
1703
1704    fn parent_property_notify_event(&self, event: &gdk::EventProperty) -> Propagation {
1705        unsafe {
1706            let data = Self::type_data();
1707            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1708            if let Some(f) = (*parent_class).property_notify_event {
1709                Propagation::from_glib(f(
1710                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1711                    mut_override(event.to_glib_none().0),
1712                ))
1713            } else {
1714                Propagation::Proceed
1715            }
1716        }
1717    }
1718
1719    fn parent_selection_clear_event(&self, event: &gdk::EventSelection) -> Propagation {
1720        unsafe {
1721            let data = Self::type_data();
1722            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1723            if let Some(f) = (*parent_class).selection_clear_event {
1724                Propagation::from_glib(f(
1725                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1726                    mut_override(event.to_glib_none().0),
1727                ))
1728            } else {
1729                Propagation::Proceed
1730            }
1731        }
1732    }
1733
1734    fn parent_selection_request_event(&self, event: &gdk::EventSelection) -> Propagation {
1735        unsafe {
1736            let data = Self::type_data();
1737            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1738            if let Some(f) = (*parent_class).selection_request_event {
1739                Propagation::from_glib(f(
1740                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1741                    mut_override(event.to_glib_none().0),
1742                ))
1743            } else {
1744                Propagation::Proceed
1745            }
1746        }
1747    }
1748
1749    fn parent_selection_notify_event(&self, event: &gdk::EventSelection) -> Propagation {
1750        unsafe {
1751            let data = Self::type_data();
1752            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1753            if let Some(f) = (*parent_class).selection_notify_event {
1754                Propagation::from_glib(f(
1755                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1756                    mut_override(event.to_glib_none().0),
1757                ))
1758            } else {
1759                Propagation::Proceed
1760            }
1761        }
1762    }
1763
1764    fn parent_proximity_in_event(&self, event: &gdk::EventProximity) -> Propagation {
1765        unsafe {
1766            let data = Self::type_data();
1767            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1768            if let Some(f) = (*parent_class).proximity_in_event {
1769                Propagation::from_glib(f(
1770                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1771                    mut_override(event.to_glib_none().0),
1772                ))
1773            } else {
1774                Propagation::Proceed
1775            }
1776        }
1777    }
1778
1779    fn parent_proximity_out_event(&self, event: &gdk::EventProximity) -> Propagation {
1780        unsafe {
1781            let data = Self::type_data();
1782            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1783            if let Some(f) = (*parent_class).proximity_out_event {
1784                Propagation::from_glib(f(
1785                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1786                    mut_override(event.to_glib_none().0),
1787                ))
1788            } else {
1789                Propagation::Proceed
1790            }
1791        }
1792    }
1793
1794    fn parent_visibility_notify_event(&self, event: &gdk::EventVisibility) -> Propagation {
1795        unsafe {
1796            let data = Self::type_data();
1797            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1798            if let Some(f) = (*parent_class).visibility_notify_event {
1799                Propagation::from_glib(f(
1800                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1801                    mut_override(event.to_glib_none().0),
1802                ))
1803            } else {
1804                Propagation::Proceed
1805            }
1806        }
1807    }
1808
1809    fn parent_grab_broken_event(&self, event: &gdk::EventGrabBroken) -> Propagation {
1810        unsafe {
1811            let data = Self::type_data();
1812            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1813            if let Some(f) = (*parent_class).grab_broken_event {
1814                Propagation::from_glib(f(
1815                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1816                    mut_override(event.to_glib_none().0),
1817                ))
1818            } else {
1819                Propagation::Proceed
1820            }
1821        }
1822    }
1823
1824    fn parent_touch_event(&self, event: &gdk::EventTouch) -> Propagation {
1825        unsafe {
1826            let data = Self::type_data();
1827            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1828            if let Some(f) = (*parent_class).touch_event {
1829                Propagation::from_glib(f(
1830                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1831                    mut_override(event.to_glib_none().0),
1832                ))
1833            } else {
1834                Propagation::Proceed
1835            }
1836        }
1837    }
1838
1839    fn parent_selection_get(&self, selection_data: &SelectionData, info: u32, time: u32) {
1840        unsafe {
1841            let data = Self::type_data();
1842            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1843            if let Some(f) = (*parent_class).selection_get {
1844                f(
1845                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1846                    mut_override(selection_data.to_glib_none().0),
1847                    info,
1848                    time,
1849                );
1850            }
1851        }
1852    }
1853
1854    fn parent_selection_received(&self, selection_data: &SelectionData, time: u32) {
1855        unsafe {
1856            let data = Self::type_data();
1857            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1858            if let Some(f) = (*parent_class).selection_received {
1859                f(
1860                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1861                    mut_override(selection_data.to_glib_none().0),
1862                    time,
1863                );
1864            }
1865        }
1866    }
1867
1868    fn parent_popup_menu(&self) -> bool {
1869        unsafe {
1870            let data = Self::type_data();
1871            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1872            if let Some(f) = (*parent_class).popup_menu {
1873                from_glib(f(self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0))
1874            } else {
1875                false
1876            }
1877        }
1878    }
1879
1880    fn parent_show_help(&self, help_type: WidgetHelpType) -> bool {
1881        unsafe {
1882            let data = Self::type_data();
1883            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1884            if let Some(f) = (*parent_class).show_help {
1885                from_glib(f(
1886                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1887                    help_type.into_glib(),
1888                ))
1889            } else {
1890                false
1891            }
1892        }
1893    }
1894
1895    fn parent_screen_changed(&self, previous_screen: Option<&gdk::Screen>) {
1896        unsafe {
1897            let data = Self::type_data();
1898            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1899            if let Some(f) = (*parent_class).screen_changed {
1900                f(
1901                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1902                    previous_screen.to_glib_none().0,
1903                );
1904            }
1905        }
1906    }
1907
1908    fn parent_query_tooltip(
1909        &self,
1910        x: i32,
1911        y: i32,
1912        keyboard_tooltip: bool,
1913        tooltip: &Tooltip,
1914    ) -> bool {
1915        unsafe {
1916            let data = Self::type_data();
1917            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1918            if let Some(f) = (*parent_class).query_tooltip {
1919                from_glib(f(
1920                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1921                    x,
1922                    y,
1923                    keyboard_tooltip.into_glib(),
1924                    tooltip.to_glib_none().0,
1925                ))
1926            } else {
1927                false
1928            }
1929        }
1930    }
1931
1932    fn parent_style_updated(&self) {
1933        unsafe {
1934            let data = Self::type_data();
1935            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1936            if let Some(f) = (*parent_class).style_updated {
1937                f(self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0);
1938            }
1939        }
1940    }
1941
1942    fn parent_queue_draw_region(&self, region: &cairo::Region) {
1943        unsafe {
1944            let data = Self::type_data();
1945            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
1946            if let Some(f) = (*parent_class).queue_draw_region {
1947                f(
1948                    self.obj().unsafe_cast_ref::<Widget>().to_glib_none().0,
1949                    region.to_glib_none().0,
1950                );
1951            }
1952        }
1953    }
1954}
1955
1956impl<T: WidgetImpl> WidgetImplExt for T {}
1957
1958unsafe impl<T: WidgetImpl> IsSubclassable<T> for Widget {
1959    fn class_init(class: &mut ::glib::Class<Self>) {
1960        Self::parent_class_init::<T>(class);
1961
1962        if !crate::rt::is_initialized() {
1963            panic!("GTK has to be initialized first");
1964        }
1965
1966        let klass = class.as_mut();
1967        klass.adjust_baseline_allocation = Some(widget_adjust_baseline_allocation::<T>);
1968        klass.adjust_baseline_request = Some(widget_adjust_baseline_request::<T>);
1969        klass.adjust_size_allocation = Some(widget_adjust_size_allocation::<T>);
1970        klass.adjust_size_request = Some(widget_adjust_size_request::<T>);
1971        klass.button_press_event = Some(widget_button_press_event::<T>);
1972        klass.button_release_event = Some(widget_button_release_event::<T>);
1973        klass.can_activate_accel = Some(widget_can_activate_accel::<T>);
1974        klass.child_notify = Some(widget_child_notify::<T>);
1975        klass.composited_changed = Some(widget_composited_changed::<T>);
1976        klass.compute_expand = Some(widget_compute_expand::<T>);
1977        klass.configure_event = Some(widget_configure_event::<T>);
1978        klass.damage_event = Some(widget_damage_event::<T>);
1979        klass.delete_event = Some(widget_delete_event::<T>);
1980        klass.destroy = Some(widget_destroy::<T>);
1981        klass.destroy_event = Some(widget_destroy_event::<T>);
1982        klass.direction_changed = Some(widget_direction_changed::<T>);
1983        klass.dispatch_child_properties_changed =
1984            Some(widget_dispatch_child_properties_changed::<T>);
1985        klass.drag_begin = Some(widget_drag_begin::<T>);
1986        klass.drag_data_delete = Some(widget_drag_data_delete::<T>);
1987        klass.drag_data_get = Some(widget_drag_data_get::<T>);
1988        klass.drag_data_received = Some(widget_drag_data_received::<T>);
1989        klass.drag_drop = Some(widget_drag_drop::<T>);
1990        klass.drag_end = Some(widget_drag_end::<T>);
1991        klass.drag_failed = Some(widget_drag_failed::<T>);
1992        klass.drag_leave = Some(widget_drag_leave::<T>);
1993        klass.drag_motion = Some(widget_drag_motion::<T>);
1994        klass.draw = Some(widget_draw::<T>);
1995        klass.enter_notify_event = Some(widget_enter_notify_event::<T>);
1996        klass.event = Some(widget_event::<T>);
1997        klass.focus = Some(widget_focus::<T>);
1998        klass.focus_in_event = Some(widget_focus_in_event::<T>);
1999        klass.focus_out_event = Some(widget_focus_out_event::<T>);
2000        klass.get_preferred_height = Some(widget_get_preferred_height::<T>);
2001        klass.get_preferred_height_for_width = Some(widget_get_preferred_height_for_width::<T>);
2002        klass.get_preferred_width = Some(widget_get_preferred_width::<T>);
2003        klass.get_preferred_width_for_height = Some(widget_get_preferred_width_for_height::<T>);
2004        klass.get_request_mode = Some(widget_get_request_mode::<T>);
2005        klass.grab_broken_event = Some(widget_grab_broken_event::<T>);
2006        klass.grab_focus = Some(widget_grab_focus::<T>);
2007        klass.grab_notify = Some(widget_grab_notify::<T>);
2008        klass.hide = Some(widget_hide::<T>);
2009        klass.hierarchy_changed = Some(widget_hierarchy_changed::<T>);
2010        klass.key_press_event = Some(widget_key_press_event::<T>);
2011        klass.key_release_event = Some(widget_key_release_event::<T>);
2012        klass.keynav_failed = Some(widget_keynav_failed::<T>);
2013        klass.leave_notify_event = Some(widget_leave_notify_event::<T>);
2014        klass.map = Some(widget_map::<T>);
2015        klass.map_event = Some(widget_map_event::<T>);
2016        klass.mnemonic_activate = Some(widget_mnemonic_activate::<T>);
2017        klass.motion_notify_event = Some(widget_motion_notify_event::<T>);
2018        klass.move_focus = Some(widget_move_focus::<T>);
2019        klass.parent_set = Some(widget_parent_set::<T>);
2020        klass.popup_menu = Some(widget_popup_menu::<T>);
2021        klass.property_notify_event = Some(widget_property_notify_event::<T>);
2022        klass.proximity_in_event = Some(widget_proximity_in_event::<T>);
2023        klass.proximity_out_event = Some(widget_proximity_out_event::<T>);
2024        klass.query_tooltip = Some(widget_query_tooltip::<T>);
2025        klass.queue_draw_region = Some(widget_queue_draw_region::<T>);
2026        klass.realize = Some(widget_realize::<T>);
2027        klass.screen_changed = Some(widget_screen_changed::<T>);
2028        klass.scroll_event = Some(widget_scroll_event::<T>);
2029        klass.selection_clear_event = Some(widget_selection_clear_event::<T>);
2030        klass.selection_get = Some(widget_selection_get::<T>);
2031        klass.selection_notify_event = Some(widget_selection_notify_event::<T>);
2032        klass.selection_received = Some(widget_selection_received::<T>);
2033        klass.selection_request_event = Some(widget_selection_request_event::<T>);
2034        klass.show = Some(widget_show::<T>);
2035        klass.show_all = Some(widget_show_all::<T>);
2036        klass.show_help = Some(widget_show_help::<T>);
2037        klass.size_allocate = Some(widget_size_allocate::<T>);
2038        klass.state_flags_changed = Some(widget_state_flags_changed::<T>);
2039        klass.style_updated = Some(widget_style_updated::<T>);
2040        klass.touch_event = Some(widget_touch_event::<T>);
2041        klass.unmap = Some(widget_unmap::<T>);
2042        klass.unmap_event = Some(widget_unmap_event::<T>);
2043        klass.unrealize = Some(widget_unrealize::<T>);
2044        klass.visibility_notify_event = Some(widget_visibility_notify_event::<T>);
2045        klass.window_state_event = Some(widget_window_state_event::<T>);
2046    }
2047}
2048
2049unsafe extern "C" fn widget_adjust_baseline_allocation<T: WidgetImpl>(
2050    ptr: *mut ffi::GtkWidget,
2051    baseptr: *mut i32,
2052) {
2053    unsafe {
2054        let instance = &*(ptr as *mut T::Instance);
2055        let imp = instance.imp();
2056
2057        imp.adjust_baseline_allocation(&mut *baseptr)
2058    }
2059}
2060
2061unsafe extern "C" fn widget_adjust_baseline_request<T: WidgetImpl>(
2062    ptr: *mut ffi::GtkWidget,
2063    minptr: *mut i32,
2064    natptr: *mut i32,
2065) {
2066    unsafe {
2067        let instance = &*(ptr as *mut T::Instance);
2068        let imp = instance.imp();
2069
2070        imp.adjust_baseline_request(&mut *minptr, &mut *natptr)
2071    }
2072}
2073
2074unsafe extern "C" fn widget_adjust_size_allocation<T: WidgetImpl>(
2075    ptr: *mut ffi::GtkWidget,
2076    orientation: ffi::GtkOrientation,
2077    minptr: *mut i32,
2078    natptr: *mut i32,
2079    posptr: *mut i32,
2080    sizeptr: *mut i32,
2081) {
2082    unsafe {
2083        let instance = &*(ptr as *mut T::Instance);
2084        let imp = instance.imp();
2085        let wrap_orientation: Orientation = from_glib(orientation);
2086
2087        imp.adjust_size_allocation(
2088            wrap_orientation,
2089            &mut *minptr,
2090            &mut *natptr,
2091            &mut *posptr,
2092            &mut *sizeptr,
2093        )
2094    }
2095}
2096
2097unsafe extern "C" fn widget_adjust_size_request<T: WidgetImpl>(
2098    ptr: *mut ffi::GtkWidget,
2099    orientation: ffi::GtkOrientation,
2100    minptr: *mut i32,
2101    natptr: *mut i32,
2102) {
2103    unsafe {
2104        let instance = &*(ptr as *mut T::Instance);
2105        let imp = instance.imp();
2106        let wrap_orientation: Orientation = from_glib(orientation);
2107
2108        imp.adjust_size_request(wrap_orientation, &mut *minptr, &mut *natptr)
2109    }
2110}
2111
2112unsafe extern "C" fn widget_button_press_event<T: WidgetImpl>(
2113    ptr: *mut ffi::GtkWidget,
2114    btnptr: *mut gdk::ffi::GdkEventButton,
2115) -> glib::ffi::gboolean {
2116    unsafe {
2117        let instance = &*(ptr as *mut T::Instance);
2118        let imp = instance.imp();
2119        let evwrap: Borrowed<gdk::EventButton> = from_glib_borrow(btnptr);
2120
2121        imp.button_press_event(&evwrap).into_glib()
2122    }
2123}
2124
2125unsafe extern "C" fn widget_button_release_event<T: WidgetImpl>(
2126    ptr: *mut ffi::GtkWidget,
2127    btnptr: *mut gdk::ffi::GdkEventButton,
2128) -> glib::ffi::gboolean {
2129    unsafe {
2130        let instance = &*(ptr as *mut T::Instance);
2131        let imp = instance.imp();
2132        let evwrap: Borrowed<gdk::EventButton> = from_glib_borrow(btnptr);
2133
2134        imp.button_release_event(&evwrap).into_glib()
2135    }
2136}
2137
2138unsafe extern "C" fn widget_can_activate_accel<T: WidgetImpl>(
2139    ptr: *mut ffi::GtkWidget,
2140    signal_id: u32,
2141) -> glib::ffi::gboolean {
2142    unsafe {
2143        let instance = &*(ptr as *mut T::Instance);
2144        let imp = instance.imp();
2145
2146        if let Some(signal_id) = NonZeroU32::new(signal_id).map(|nz| SignalId::new(nz)) {
2147            imp.can_activate_accel(signal_id).into_glib()
2148        } else {
2149            // 0 is invalid, so there is nothing to hand the impl; defer to GTK, where at the
2150            // bottom of the chain `gtk_widget_real_can_activate_accel()` doesn't even look at
2151            // the signal ID at all, and instead returns something based on the widget's state.
2152            let data = T::type_data();
2153            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkWidgetClass;
2154            if let Some(f) = (*parent_class).can_activate_accel {
2155                f(ptr, signal_id)
2156            } else {
2157                false.into_glib()
2158            }
2159        }
2160    }
2161}
2162
2163unsafe extern "C" fn widget_child_notify<T: WidgetImpl>(
2164    ptr: *mut ffi::GtkWidget,
2165    paramptr: *mut glib::gobject_ffi::GParamSpec,
2166) {
2167    unsafe {
2168        let instance = &*(ptr as *mut T::Instance);
2169        let imp = instance.imp();
2170        let paramwrap: Borrowed<glib::ParamSpec> = from_glib_borrow(paramptr);
2171
2172        imp.child_notify(&paramwrap)
2173    }
2174}
2175
2176unsafe extern "C" fn widget_composited_changed<T: WidgetImpl>(ptr: *mut ffi::GtkWidget) {
2177    unsafe {
2178        let instance = &*(ptr as *mut T::Instance);
2179        let imp = instance.imp();
2180
2181        imp.composited_changed()
2182    }
2183}
2184
2185unsafe extern "C" fn widget_compute_expand<T: WidgetImpl>(
2186    ptr: *mut ffi::GtkWidget,
2187    hexpand_ptr: *mut glib::ffi::gboolean,
2188    vexpand_ptr: *mut glib::ffi::gboolean,
2189) {
2190    unsafe {
2191        let instance = &*(ptr as *mut T::Instance);
2192        let imp = instance.imp();
2193
2194        let widget = imp.obj();
2195        let widget = widget.unsafe_cast_ref::<Widget>();
2196        let mut hexpand: bool = if widget.is_hexpand_set() {
2197            widget.hexpands()
2198        } else {
2199            from_glib(*hexpand_ptr)
2200        };
2201        let mut vexpand: bool = if widget.is_vexpand_set() {
2202            widget.vexpands()
2203        } else {
2204            from_glib(*vexpand_ptr)
2205        };
2206
2207        imp.compute_expand(&mut hexpand, &mut vexpand);
2208        *hexpand_ptr = hexpand.into_glib();
2209        *vexpand_ptr = vexpand.into_glib();
2210    }
2211}
2212
2213unsafe extern "C" fn widget_configure_event<T: WidgetImpl>(
2214    ptr: *mut ffi::GtkWidget,
2215    confptr: *mut gdk::ffi::GdkEventConfigure,
2216) -> glib::ffi::gboolean {
2217    unsafe {
2218        let instance = &*(ptr as *mut T::Instance);
2219        let imp = instance.imp();
2220        let evwrap: Borrowed<gdk::EventConfigure> = from_glib_borrow(confptr);
2221
2222        imp.configure_event(&evwrap).into_glib()
2223    }
2224}
2225
2226unsafe extern "C" fn widget_window_state_event<T: WidgetImpl>(
2227    ptr: *mut ffi::GtkWidget,
2228    winstateptr: *mut gdk::ffi::GdkEventWindowState,
2229) -> glib::ffi::gboolean {
2230    unsafe {
2231        let instance = &*(ptr as *mut T::Instance);
2232        let imp = instance.imp();
2233        let evwrap: Borrowed<gdk::EventWindowState> = from_glib_borrow(winstateptr);
2234
2235        imp.window_state_event(&evwrap).into_glib()
2236    }
2237}
2238
2239unsafe extern "C" fn widget_damage_event<T: WidgetImpl>(
2240    ptr: *mut ffi::GtkWidget,
2241    exposeptr: *mut gdk::ffi::GdkEventExpose,
2242) -> glib::ffi::gboolean {
2243    unsafe {
2244        let instance = &*(ptr as *mut T::Instance);
2245        let imp = instance.imp();
2246        let evwrap: Borrowed<gdk::EventExpose> = from_glib_borrow(exposeptr);
2247
2248        imp.damage_event(&evwrap).into_glib()
2249    }
2250}
2251
2252unsafe extern "C" fn widget_delete_event<T: WidgetImpl>(
2253    ptr: *mut ffi::GtkWidget,
2254    anyptr: *mut gdk::ffi::GdkEventAny,
2255) -> glib::ffi::gboolean {
2256    unsafe {
2257        let instance = &*(ptr as *mut T::Instance);
2258        let imp = instance.imp();
2259        let evwrap: Borrowed<gdk::Event> = from_glib_borrow(anyptr);
2260
2261        imp.delete_event(&evwrap).into_glib()
2262    }
2263}
2264
2265unsafe extern "C" fn widget_destroy<T: WidgetImpl>(ptr: *mut ffi::GtkWidget) {
2266    unsafe {
2267        let instance = &*(ptr as *mut T::Instance);
2268        let imp = instance.imp();
2269
2270        imp.destroy()
2271    }
2272}
2273
2274unsafe extern "C" fn widget_destroy_event<T: WidgetImpl>(
2275    ptr: *mut ffi::GtkWidget,
2276    anyptr: *mut gdk::ffi::GdkEventAny,
2277) -> glib::ffi::gboolean {
2278    unsafe {
2279        let instance = &*(ptr as *mut T::Instance);
2280        let imp = instance.imp();
2281        let evwrap: Borrowed<gdk::Event> = from_glib_borrow(anyptr);
2282
2283        imp.destroy_event(&evwrap).into_glib()
2284    }
2285}
2286
2287unsafe extern "C" fn widget_direction_changed<T: WidgetImpl>(
2288    ptr: *mut ffi::GtkWidget,
2289    directnptr: ffi::GtkTextDirection,
2290) {
2291    unsafe {
2292        let instance = &*(ptr as *mut T::Instance);
2293        let imp = instance.imp();
2294        let dirwrap: TextDirection = from_glib(directnptr);
2295
2296        imp.direction_changed(dirwrap)
2297    }
2298}
2299
2300unsafe extern "C" fn widget_dispatch_child_properties_changed<T: WidgetImpl>(
2301    ptr: *mut ffi::GtkWidget,
2302    n_pspec_ptr: u32,
2303    pspecsptr: *mut *mut glib::gobject_ffi::GParamSpec,
2304) {
2305    unsafe {
2306        let instance = &*(ptr as *mut T::Instance);
2307        let imp = instance.imp();
2308        let pspecs: Vec<glib::ParamSpec> =
2309            FromGlibContainer::from_glib_none_num(pspecsptr, n_pspec_ptr as usize);
2310
2311        imp.dispatch_child_properties_changed(&pspecs)
2312    }
2313}
2314
2315unsafe extern "C" fn widget_drag_begin<T: WidgetImpl>(
2316    ptr: *mut ffi::GtkWidget,
2317    ctxptr: *mut gdk::ffi::GdkDragContext,
2318) {
2319    unsafe {
2320        let instance = &*(ptr as *mut T::Instance);
2321        let imp = instance.imp();
2322        let context: Borrowed<gdk::DragContext> = from_glib_borrow(ctxptr);
2323
2324        imp.drag_begin(&context)
2325    }
2326}
2327
2328unsafe extern "C" fn widget_drag_data_delete<T: WidgetImpl>(
2329    ptr: *mut ffi::GtkWidget,
2330    ctxptr: *mut gdk::ffi::GdkDragContext,
2331) {
2332    unsafe {
2333        let instance = &*(ptr as *mut T::Instance);
2334        let imp = instance.imp();
2335        let context: Borrowed<gdk::DragContext> = from_glib_borrow(ctxptr);
2336
2337        imp.drag_data_delete(&context)
2338    }
2339}
2340
2341unsafe extern "C" fn widget_drag_data_get<T: WidgetImpl>(
2342    ptr: *mut ffi::GtkWidget,
2343    ctxptr: *mut gdk::ffi::GdkDragContext,
2344    selectptr: *mut ffi::GtkSelectionData,
2345    info: u32,
2346    time: u32,
2347) {
2348    unsafe {
2349        let instance = &*(ptr as *mut T::Instance);
2350        let imp = instance.imp();
2351        let context: Borrowed<gdk::DragContext> = from_glib_borrow(ctxptr);
2352        let selection_data: Borrowed<SelectionData> = from_glib_borrow(selectptr);
2353
2354        imp.drag_data_get(&context, &selection_data, info, time)
2355    }
2356}
2357
2358unsafe extern "C" fn widget_drag_data_received<T: WidgetImpl>(
2359    ptr: *mut ffi::GtkWidget,
2360    ctxptr: *mut gdk::ffi::GdkDragContext,
2361    x: i32,
2362    y: i32,
2363    selectptr: *mut ffi::GtkSelectionData,
2364    info: u32,
2365    time: u32,
2366) {
2367    unsafe {
2368        let instance = &*(ptr as *mut T::Instance);
2369        let imp = instance.imp();
2370        let context: Borrowed<gdk::DragContext> = from_glib_borrow(ctxptr);
2371        let selection_data: Borrowed<SelectionData> = from_glib_borrow(selectptr);
2372
2373        imp.drag_data_received(&context, x, y, &selection_data, info, time)
2374    }
2375}
2376
2377unsafe extern "C" fn widget_drag_drop<T: WidgetImpl>(
2378    ptr: *mut ffi::GtkWidget,
2379    ctxptr: *mut gdk::ffi::GdkDragContext,
2380    x: i32,
2381    y: i32,
2382    time: u32,
2383) -> glib::ffi::gboolean {
2384    unsafe {
2385        let instance = &*(ptr as *mut T::Instance);
2386        let imp = instance.imp();
2387        let context: Borrowed<gdk::DragContext> = from_glib_borrow(ctxptr);
2388
2389        imp.drag_drop(&context, x, y, time).into_glib()
2390    }
2391}
2392
2393unsafe extern "C" fn widget_drag_end<T: WidgetImpl>(
2394    ptr: *mut ffi::GtkWidget,
2395    ctxptr: *mut gdk::ffi::GdkDragContext,
2396) {
2397    unsafe {
2398        let instance = &*(ptr as *mut T::Instance);
2399        let imp = instance.imp();
2400        let context: Borrowed<gdk::DragContext> = from_glib_borrow(ctxptr);
2401
2402        imp.drag_end(&context)
2403    }
2404}
2405
2406unsafe extern "C" fn widget_drag_failed<T: WidgetImpl>(
2407    ptr: *mut ffi::GtkWidget,
2408    ctxptr: *mut gdk::ffi::GdkDragContext,
2409    resultptr: ffi::GtkDragResult,
2410) -> glib::ffi::gboolean {
2411    unsafe {
2412        let instance = &*(ptr as *mut T::Instance);
2413        let imp = instance.imp();
2414        let context: Borrowed<gdk::DragContext> = from_glib_borrow(ctxptr);
2415        let result: DragResult = from_glib(resultptr);
2416
2417        imp.drag_failed(&context, result).into_glib()
2418    }
2419}
2420
2421unsafe extern "C" fn widget_drag_leave<T: WidgetImpl>(
2422    ptr: *mut ffi::GtkWidget,
2423    ctxptr: *mut gdk::ffi::GdkDragContext,
2424    time: u32,
2425) {
2426    unsafe {
2427        let instance = &*(ptr as *mut T::Instance);
2428        let imp = instance.imp();
2429        let context: Borrowed<gdk::DragContext> = from_glib_borrow(ctxptr);
2430
2431        imp.drag_leave(&context, time)
2432    }
2433}
2434
2435unsafe extern "C" fn widget_drag_motion<T: WidgetImpl>(
2436    ptr: *mut ffi::GtkWidget,
2437    ctxptr: *mut gdk::ffi::GdkDragContext,
2438    x: i32,
2439    y: i32,
2440    time: u32,
2441) -> glib::ffi::gboolean {
2442    unsafe {
2443        let instance = &*(ptr as *mut T::Instance);
2444        let imp = instance.imp();
2445        let context: Borrowed<gdk::DragContext> = from_glib_borrow(ctxptr);
2446
2447        imp.drag_motion(&context, x, y, time).into_glib()
2448    }
2449}
2450
2451unsafe extern "C" fn widget_draw<T: WidgetImpl>(
2452    ptr: *mut ffi::GtkWidget,
2453    cr_ptr: *mut cairo::ffi::cairo_t,
2454) -> glib::ffi::gboolean {
2455    unsafe {
2456        let instance = &*(ptr as *mut T::Instance);
2457        let imp = instance.imp();
2458        let cr: Borrowed<cairo::Context> = from_glib_borrow(cr_ptr);
2459
2460        imp.draw(&cr).into_glib()
2461    }
2462}
2463
2464unsafe extern "C" fn widget_get_request_mode<T: WidgetImpl>(
2465    ptr: *mut ffi::GtkWidget,
2466) -> ffi::GtkSizeRequestMode {
2467    unsafe {
2468        let instance = &*(ptr as *mut T::Instance);
2469        let imp = instance.imp();
2470
2471        imp.request_mode().into_glib()
2472    }
2473}
2474
2475unsafe extern "C" fn widget_get_preferred_height<T: WidgetImpl>(
2476    ptr: *mut ffi::GtkWidget,
2477    minptr: *mut c_int,
2478    natptr: *mut c_int,
2479) {
2480    unsafe {
2481        let instance = &*(ptr as *mut T::Instance);
2482        let imp = instance.imp();
2483
2484        let (min_size, nat_size) = imp.preferred_height();
2485        if !minptr.is_null() {
2486            *minptr = min_size;
2487        }
2488        if !natptr.is_null() {
2489            *natptr = nat_size;
2490        }
2491    }
2492}
2493
2494unsafe extern "C" fn widget_get_preferred_width_for_height<T: WidgetImpl>(
2495    ptr: *mut ffi::GtkWidget,
2496    height: c_int,
2497    min_width_ptr: *mut c_int,
2498    nat_width_ptr: *mut c_int,
2499) {
2500    unsafe {
2501        let instance = &*(ptr as *mut T::Instance);
2502        let imp = instance.imp();
2503
2504        let (min_width, nat_width) = imp.preferred_width_for_height(height);
2505        if !min_width_ptr.is_null() {
2506            *min_width_ptr = min_width;
2507        }
2508        if !nat_width_ptr.is_null() {
2509            *nat_width_ptr = nat_width;
2510        }
2511    }
2512}
2513
2514unsafe extern "C" fn widget_get_preferred_width<T: WidgetImpl>(
2515    ptr: *mut ffi::GtkWidget,
2516    minptr: *mut c_int,
2517    natptr: *mut c_int,
2518) {
2519    unsafe {
2520        let instance = &*(ptr as *mut T::Instance);
2521        let imp = instance.imp();
2522        let (min_size, nat_size) = imp.preferred_width();
2523        if !minptr.is_null() {
2524            *minptr = min_size;
2525        }
2526        if !natptr.is_null() {
2527            *natptr = nat_size;
2528        }
2529    }
2530}
2531
2532unsafe extern "C" fn widget_get_preferred_height_for_width<T: WidgetImpl>(
2533    ptr: *mut ffi::GtkWidget,
2534    width: c_int,
2535    min_height_ptr: *mut c_int,
2536    nat_height_ptr: *mut c_int,
2537) {
2538    unsafe {
2539        let instance = &*(ptr as *mut T::Instance);
2540        let imp = instance.imp();
2541
2542        let (min_height, nat_height) = imp.preferred_height_for_width(width);
2543        if !min_height_ptr.is_null() {
2544            *min_height_ptr = min_height;
2545        }
2546        if !nat_height_ptr.is_null() {
2547            *nat_height_ptr = nat_height;
2548        }
2549    }
2550}
2551
2552unsafe extern "C" fn widget_get_preferred_height_and_baseline_for_width<T: WidgetImpl>(
2553    ptr: *mut ffi::GtkWidget,
2554    width: c_int,
2555    min_height_ptr: *mut c_int,
2556    nat_height_ptr: *mut c_int,
2557    min_baseline_ptr: *mut c_int,
2558    nat_baseline_ptr: *mut c_int,
2559) {
2560    unsafe {
2561        let instance = &*(ptr as *mut T::Instance);
2562        let imp = instance.imp();
2563
2564        let (min_height, nat_height, min_baseline, nat_baseline) =
2565            imp.preferred_height_and_baseline_for_width(width);
2566        if !min_height_ptr.is_null() {
2567            *min_height_ptr = min_height;
2568        }
2569        if !nat_height_ptr.is_null() {
2570            *nat_height_ptr = nat_height;
2571        }
2572        if !min_baseline_ptr.is_null() {
2573            *min_baseline_ptr = min_baseline;
2574        }
2575        if !nat_baseline_ptr.is_null() {
2576            *nat_baseline_ptr = nat_baseline;
2577        }
2578    }
2579}
2580
2581unsafe extern "C" fn widget_size_allocate<T: WidgetImpl>(
2582    ptr: *mut ffi::GtkWidget,
2583    allocation: *mut ffi::GtkAllocation,
2584) {
2585    unsafe {
2586        let instance = &*(ptr as *mut T::Instance);
2587        let imp = instance.imp();
2588        let allocate: &Allocation = &from_glib_none(allocation);
2589
2590        imp.size_allocate(allocate);
2591    }
2592}
2593
2594unsafe extern "C" fn widget_realize<T: WidgetImpl>(ptr: *mut ffi::GtkWidget) {
2595    unsafe {
2596        let instance = &*(ptr as *mut T::Instance);
2597        let imp = instance.imp();
2598
2599        imp.realize();
2600    }
2601}
2602
2603unsafe extern "C" fn widget_unrealize<T: WidgetImpl>(ptr: *mut ffi::GtkWidget) {
2604    unsafe {
2605        let instance = &*(ptr as *mut T::Instance);
2606        let imp = instance.imp();
2607
2608        imp.unrealize();
2609    }
2610}
2611
2612unsafe extern "C" fn widget_map<T: WidgetImpl>(ptr: *mut ffi::GtkWidget) {
2613    unsafe {
2614        let instance = &*(ptr as *mut T::Instance);
2615        let imp = instance.imp();
2616        imp.map();
2617    }
2618}
2619
2620unsafe extern "C" fn widget_unmap<T: WidgetImpl>(ptr: *mut ffi::GtkWidget) {
2621    unsafe {
2622        let instance = &*(ptr as *mut T::Instance);
2623        let imp = instance.imp();
2624        imp.unmap();
2625    }
2626}
2627
2628unsafe extern "C" fn widget_show<T: WidgetImpl>(ptr: *mut ffi::GtkWidget) {
2629    unsafe {
2630        let instance = &*(ptr as *mut T::Instance);
2631        let imp = instance.imp();
2632        imp.show();
2633    }
2634}
2635
2636unsafe extern "C" fn widget_hide<T: WidgetImpl>(ptr: *mut ffi::GtkWidget) {
2637    unsafe {
2638        let instance = &*(ptr as *mut T::Instance);
2639        let imp = instance.imp();
2640        imp.hide();
2641    }
2642}
2643
2644unsafe extern "C" fn widget_grab_focus<T: WidgetImpl>(ptr: *mut ffi::GtkWidget) {
2645    unsafe {
2646        let instance = &*(ptr as *mut T::Instance);
2647        let imp = instance.imp();
2648        imp.grab_focus();
2649    }
2650}
2651
2652unsafe extern "C" fn widget_focus<T: WidgetImpl>(
2653    ptr: *mut ffi::GtkWidget,
2654    direction: ffi::GtkDirectionType,
2655) -> glib::ffi::gboolean {
2656    unsafe {
2657        let instance = &*(ptr as *mut T::Instance);
2658        let imp = instance.imp();
2659        imp.focus(from_glib(direction)).into_glib()
2660    }
2661}
2662
2663unsafe extern "C" fn widget_motion_notify_event<T: WidgetImpl>(
2664    ptr: *mut ffi::GtkWidget,
2665    mptr: *mut gdk::ffi::GdkEventMotion,
2666) -> glib::ffi::gboolean {
2667    unsafe {
2668        let instance = &*(ptr as *mut T::Instance);
2669        let imp = instance.imp();
2670        let event: Borrowed<gdk::EventMotion> = from_glib_borrow(mptr);
2671
2672        imp.motion_notify_event(&event).into_glib()
2673    }
2674}
2675
2676unsafe extern "C" fn widget_scroll_event<T: WidgetImpl>(
2677    ptr: *mut ffi::GtkWidget,
2678    mptr: *mut gdk::ffi::GdkEventScroll,
2679) -> glib::ffi::gboolean {
2680    unsafe {
2681        let instance = &*(ptr as *mut T::Instance);
2682        let imp = instance.imp();
2683        let event: Borrowed<gdk::EventScroll> = from_glib_borrow(mptr);
2684
2685        imp.scroll_event(&event).into_glib()
2686    }
2687}
2688
2689unsafe extern "C" fn widget_enter_notify_event<T: WidgetImpl>(
2690    ptr: *mut ffi::GtkWidget,
2691    mptr: *mut gdk::ffi::GdkEventCrossing,
2692) -> glib::ffi::gboolean {
2693    unsafe {
2694        let instance = &*(ptr as *mut T::Instance);
2695        let imp = instance.imp();
2696        let event: Borrowed<gdk::EventCrossing> = from_glib_borrow(mptr);
2697
2698        imp.enter_notify_event(&event).into_glib()
2699    }
2700}
2701
2702unsafe extern "C" fn widget_leave_notify_event<T: WidgetImpl>(
2703    ptr: *mut ffi::GtkWidget,
2704    mptr: *mut gdk::ffi::GdkEventCrossing,
2705) -> glib::ffi::gboolean {
2706    unsafe {
2707        let instance = &*(ptr as *mut T::Instance);
2708        let imp = instance.imp();
2709        let event: Borrowed<gdk::EventCrossing> = from_glib_borrow(mptr);
2710
2711        imp.leave_notify_event(&event).into_glib()
2712    }
2713}
2714
2715unsafe extern "C" fn widget_focus_in_event<T: WidgetImpl>(
2716    ptr: *mut ffi::GtkWidget,
2717    mptr: *mut gdk::ffi::GdkEventFocus,
2718) -> glib::ffi::gboolean {
2719    unsafe {
2720        let instance = &*(ptr as *mut T::Instance);
2721        let imp = instance.imp();
2722        let event: Borrowed<gdk::EventFocus> = from_glib_borrow(mptr);
2723
2724        imp.focus_in_event(&event).into_glib()
2725    }
2726}
2727
2728unsafe extern "C" fn widget_focus_out_event<T: WidgetImpl>(
2729    ptr: *mut ffi::GtkWidget,
2730    mptr: *mut gdk::ffi::GdkEventFocus,
2731) -> glib::ffi::gboolean {
2732    unsafe {
2733        let instance = &*(ptr as *mut T::Instance);
2734        let imp = instance.imp();
2735        let event: Borrowed<gdk::EventFocus> = from_glib_borrow(mptr);
2736
2737        imp.focus_out_event(&event).into_glib()
2738    }
2739}
2740
2741unsafe extern "C" fn widget_key_press_event<T: WidgetImpl>(
2742    ptr: *mut ffi::GtkWidget,
2743    mptr: *mut gdk::ffi::GdkEventKey,
2744) -> glib::ffi::gboolean {
2745    unsafe {
2746        let instance = &*(ptr as *mut T::Instance);
2747        let imp = instance.imp();
2748        let event: Borrowed<gdk::EventKey> = from_glib_borrow(mptr);
2749
2750        imp.key_press_event(&event).into_glib()
2751    }
2752}
2753
2754unsafe extern "C" fn widget_key_release_event<T: WidgetImpl>(
2755    ptr: *mut ffi::GtkWidget,
2756    mptr: *mut gdk::ffi::GdkEventKey,
2757) -> glib::ffi::gboolean {
2758    unsafe {
2759        let instance = &*(ptr as *mut T::Instance);
2760        let imp = instance.imp();
2761        let event: Borrowed<gdk::EventKey> = from_glib_borrow(mptr);
2762
2763        imp.key_release_event(&event).into_glib()
2764    }
2765}
2766
2767unsafe extern "C" fn widget_map_event<T: WidgetImpl>(
2768    ptr: *mut ffi::GtkWidget,
2769    anyptr: *mut gdk::ffi::GdkEventAny,
2770) -> glib::ffi::gboolean {
2771    unsafe {
2772        let instance = &*(ptr as *mut T::Instance);
2773        let imp = instance.imp();
2774        let evwrap: Borrowed<gdk::Event> = from_glib_borrow(anyptr);
2775
2776        imp.map_event(&evwrap).into_glib()
2777    }
2778}
2779
2780unsafe extern "C" fn widget_unmap_event<T: WidgetImpl>(
2781    ptr: *mut ffi::GtkWidget,
2782    anyptr: *mut gdk::ffi::GdkEventAny,
2783) -> glib::ffi::gboolean {
2784    unsafe {
2785        let instance = &*(ptr as *mut T::Instance);
2786        let imp = instance.imp();
2787        let evwrap: Borrowed<gdk::Event> = from_glib_borrow(anyptr);
2788
2789        imp.unmap_event(&evwrap).into_glib()
2790    }
2791}
2792
2793unsafe extern "C" fn widget_show_all<T: WidgetImpl>(ptr: *mut ffi::GtkWidget) {
2794    unsafe {
2795        let instance = &*(ptr as *mut T::Instance);
2796        let imp = instance.imp();
2797        imp.show_all();
2798    }
2799}
2800
2801unsafe extern "C" fn widget_style_updated<T: WidgetImpl>(ptr: *mut ffi::GtkWidget) {
2802    unsafe {
2803        let instance = &*(ptr as *mut T::Instance);
2804        let imp = instance.imp();
2805        imp.style_updated();
2806    }
2807}
2808
2809unsafe extern "C" fn widget_state_flags_changed<T: WidgetImpl>(
2810    ptr: *mut ffi::GtkWidget,
2811    flags: ffi::GtkStateFlags,
2812) {
2813    unsafe {
2814        let instance = &*(ptr as *mut T::Instance);
2815        let imp = instance.imp();
2816        imp.state_flags_changed(from_glib(flags));
2817    }
2818}
2819
2820unsafe extern "C" fn widget_parent_set<T: WidgetImpl>(
2821    ptr: *mut ffi::GtkWidget,
2822    parentptr: *mut ffi::GtkWidget,
2823) {
2824    unsafe {
2825        let instance = &*(ptr as *mut T::Instance);
2826        let imp = instance.imp();
2827        let previous_parent: Borrowed<Option<Widget>> = from_glib_borrow(parentptr);
2828
2829        imp.parent_set(previous_parent.as_ref().as_ref());
2830    }
2831}
2832
2833unsafe extern "C" fn widget_hierarchy_changed<T: WidgetImpl>(
2834    ptr: *mut ffi::GtkWidget,
2835    toplevelptr: *mut ffi::GtkWidget,
2836) {
2837    unsafe {
2838        let instance = &*(ptr as *mut T::Instance);
2839        let imp = instance.imp();
2840        let previous_toplevel: Borrowed<Option<Widget>> = from_glib_borrow(toplevelptr);
2841
2842        imp.hierarchy_changed(previous_toplevel.as_ref().as_ref());
2843    }
2844}
2845
2846unsafe extern "C" fn widget_grab_notify<T: WidgetImpl>(
2847    ptr: *mut ffi::GtkWidget,
2848    was_grabbed: glib::ffi::gboolean,
2849) {
2850    unsafe {
2851        let instance = &*(ptr as *mut T::Instance);
2852        let imp = instance.imp();
2853        imp.grab_notify(from_glib(was_grabbed));
2854    }
2855}
2856
2857unsafe extern "C" fn widget_mnemonic_activate<T: WidgetImpl>(
2858    ptr: *mut ffi::GtkWidget,
2859    group_cycling: glib::ffi::gboolean,
2860) -> glib::ffi::gboolean {
2861    unsafe {
2862        let instance = &*(ptr as *mut T::Instance);
2863        let imp = instance.imp();
2864        imp.mnemonic_activate(from_glib(group_cycling)).into_glib()
2865    }
2866}
2867
2868unsafe extern "C" fn widget_move_focus<T: WidgetImpl>(
2869    ptr: *mut ffi::GtkWidget,
2870    direction: ffi::GtkDirectionType,
2871) {
2872    unsafe {
2873        let instance = &*(ptr as *mut T::Instance);
2874        let imp = instance.imp();
2875        imp.move_focus(from_glib(direction));
2876    }
2877}
2878
2879unsafe extern "C" fn widget_keynav_failed<T: WidgetImpl>(
2880    ptr: *mut ffi::GtkWidget,
2881    direction: ffi::GtkDirectionType,
2882) -> glib::ffi::gboolean {
2883    unsafe {
2884        let instance = &*(ptr as *mut T::Instance);
2885        let imp = instance.imp();
2886        imp.keynav_failed(from_glib(direction)).into_glib()
2887    }
2888}
2889
2890unsafe extern "C" fn widget_event<T: WidgetImpl>(
2891    ptr: *mut ffi::GtkWidget,
2892    evptr: *mut gdk::ffi::GdkEvent,
2893) -> glib::ffi::gboolean {
2894    unsafe {
2895        let instance = &*(ptr as *mut T::Instance);
2896        let imp = instance.imp();
2897        let event: Borrowed<gdk::Event> = from_glib_borrow(evptr);
2898
2899        imp.event(&event).into_glib()
2900    }
2901}
2902
2903unsafe extern "C" fn widget_property_notify_event<T: WidgetImpl>(
2904    ptr: *mut ffi::GtkWidget,
2905    evptr: *mut gdk::ffi::GdkEventProperty,
2906) -> glib::ffi::gboolean {
2907    unsafe {
2908        let instance = &*(ptr as *mut T::Instance);
2909        let imp = instance.imp();
2910        let event: Borrowed<gdk::EventProperty> = from_glib_borrow(evptr);
2911
2912        imp.property_notify_event(&event).into_glib()
2913    }
2914}
2915
2916unsafe extern "C" fn widget_selection_clear_event<T: WidgetImpl>(
2917    ptr: *mut ffi::GtkWidget,
2918    evptr: *mut gdk::ffi::GdkEventSelection,
2919) -> glib::ffi::gboolean {
2920    unsafe {
2921        let instance = &*(ptr as *mut T::Instance);
2922        let imp = instance.imp();
2923        let event: Borrowed<gdk::EventSelection> = from_glib_borrow(evptr);
2924
2925        imp.selection_clear_event(&event).into_glib()
2926    }
2927}
2928
2929unsafe extern "C" fn widget_selection_request_event<T: WidgetImpl>(
2930    ptr: *mut ffi::GtkWidget,
2931    evptr: *mut gdk::ffi::GdkEventSelection,
2932) -> glib::ffi::gboolean {
2933    unsafe {
2934        let instance = &*(ptr as *mut T::Instance);
2935        let imp = instance.imp();
2936        let event: Borrowed<gdk::EventSelection> = from_glib_borrow(evptr);
2937
2938        imp.selection_request_event(&event).into_glib()
2939    }
2940}
2941
2942unsafe extern "C" fn widget_selection_notify_event<T: WidgetImpl>(
2943    ptr: *mut ffi::GtkWidget,
2944    evptr: *mut gdk::ffi::GdkEventSelection,
2945) -> glib::ffi::gboolean {
2946    unsafe {
2947        let instance = &*(ptr as *mut T::Instance);
2948        let imp = instance.imp();
2949        let event: Borrowed<gdk::EventSelection> = from_glib_borrow(evptr);
2950
2951        imp.selection_notify_event(&event).into_glib()
2952    }
2953}
2954
2955unsafe extern "C" fn widget_proximity_in_event<T: WidgetImpl>(
2956    ptr: *mut ffi::GtkWidget,
2957    evptr: *mut gdk::ffi::GdkEventProximity,
2958) -> glib::ffi::gboolean {
2959    unsafe {
2960        let instance = &*(ptr as *mut T::Instance);
2961        let imp = instance.imp();
2962        let event: Borrowed<gdk::EventProximity> = from_glib_borrow(evptr);
2963
2964        imp.proximity_in_event(&event).into_glib()
2965    }
2966}
2967
2968unsafe extern "C" fn widget_proximity_out_event<T: WidgetImpl>(
2969    ptr: *mut ffi::GtkWidget,
2970    evptr: *mut gdk::ffi::GdkEventProximity,
2971) -> glib::ffi::gboolean {
2972    unsafe {
2973        let instance = &*(ptr as *mut T::Instance);
2974        let imp = instance.imp();
2975        let event: Borrowed<gdk::EventProximity> = from_glib_borrow(evptr);
2976
2977        imp.proximity_out_event(&event).into_glib()
2978    }
2979}
2980
2981unsafe extern "C" fn widget_visibility_notify_event<T: WidgetImpl>(
2982    ptr: *mut ffi::GtkWidget,
2983    evptr: *mut gdk::ffi::GdkEventVisibility,
2984) -> glib::ffi::gboolean {
2985    unsafe {
2986        let instance = &*(ptr as *mut T::Instance);
2987        let imp = instance.imp();
2988        let event: Borrowed<gdk::EventVisibility> = from_glib_borrow(evptr);
2989
2990        imp.visibility_notify_event(&event).into_glib()
2991    }
2992}
2993
2994unsafe extern "C" fn widget_grab_broken_event<T: WidgetImpl>(
2995    ptr: *mut ffi::GtkWidget,
2996    evptr: *mut gdk::ffi::GdkEventGrabBroken,
2997) -> glib::ffi::gboolean {
2998    unsafe {
2999        let instance = &*(ptr as *mut T::Instance);
3000        let imp = instance.imp();
3001        let event: Borrowed<gdk::EventGrabBroken> = from_glib_borrow(evptr);
3002
3003        imp.grab_broken_event(&event).into_glib()
3004    }
3005}
3006
3007unsafe extern "C" fn widget_touch_event<T: WidgetImpl>(
3008    ptr: *mut ffi::GtkWidget,
3009    evptr: *mut gdk::ffi::GdkEventTouch,
3010) -> glib::ffi::gboolean {
3011    unsafe {
3012        let instance = &*(ptr as *mut T::Instance);
3013        let imp = instance.imp();
3014        let event: Borrowed<gdk::EventTouch> = from_glib_borrow(evptr);
3015
3016        imp.touch_event(&event).into_glib()
3017    }
3018}
3019
3020unsafe extern "C" fn widget_selection_get<T: WidgetImpl>(
3021    ptr: *mut ffi::GtkWidget,
3022    selectptr: *mut ffi::GtkSelectionData,
3023    info: u32,
3024    time: u32,
3025) {
3026    unsafe {
3027        let instance = &*(ptr as *mut T::Instance);
3028        let imp = instance.imp();
3029        let selection_data: Borrowed<SelectionData> = from_glib_borrow(selectptr);
3030
3031        imp.selection_get(&selection_data, info, time);
3032    }
3033}
3034
3035unsafe extern "C" fn widget_selection_received<T: WidgetImpl>(
3036    ptr: *mut ffi::GtkWidget,
3037    selectptr: *mut ffi::GtkSelectionData,
3038    time: u32,
3039) {
3040    unsafe {
3041        let instance = &*(ptr as *mut T::Instance);
3042        let imp = instance.imp();
3043        let selection_data: Borrowed<SelectionData> = from_glib_borrow(selectptr);
3044
3045        imp.selection_received(&selection_data, time);
3046    }
3047}
3048
3049unsafe extern "C" fn widget_popup_menu<T: WidgetImpl>(
3050    ptr: *mut ffi::GtkWidget,
3051) -> glib::ffi::gboolean {
3052    unsafe {
3053        let instance = &*(ptr as *mut T::Instance);
3054        let imp = instance.imp();
3055        imp.popup_menu().into_glib()
3056    }
3057}
3058
3059unsafe extern "C" fn widget_show_help<T: WidgetImpl>(
3060    ptr: *mut ffi::GtkWidget,
3061    help_type: ffi::GtkWidgetHelpType,
3062) -> glib::ffi::gboolean {
3063    unsafe {
3064        let instance = &*(ptr as *mut T::Instance);
3065        let imp = instance.imp();
3066        imp.show_help(from_glib(help_type)).into_glib()
3067    }
3068}
3069
3070unsafe extern "C" fn widget_screen_changed<T: WidgetImpl>(
3071    ptr: *mut ffi::GtkWidget,
3072    screenptr: *mut gdk::ffi::GdkScreen,
3073) {
3074    unsafe {
3075        let instance = &*(ptr as *mut T::Instance);
3076        let imp = instance.imp();
3077        let previous_screen: Borrowed<Option<gdk::Screen>> = from_glib_borrow(screenptr);
3078
3079        imp.screen_changed(previous_screen.as_ref().as_ref());
3080    }
3081}
3082
3083unsafe extern "C" fn widget_query_tooltip<T: WidgetImpl>(
3084    ptr: *mut ffi::GtkWidget,
3085    x: c_int,
3086    y: c_int,
3087    keyboard_tooltip: glib::ffi::gboolean,
3088    tooltipptr: *mut ffi::GtkTooltip,
3089) -> glib::ffi::gboolean {
3090    unsafe {
3091        let instance = &*(ptr as *mut T::Instance);
3092        let imp = instance.imp();
3093        let tooltip: Borrowed<Tooltip> = from_glib_borrow(tooltipptr);
3094
3095        imp.query_tooltip(x, y, from_glib(keyboard_tooltip), &tooltip)
3096            .into_glib()
3097    }
3098}
3099
3100unsafe extern "C" fn widget_queue_draw_region<T: WidgetImpl>(
3101    ptr: *mut ffi::GtkWidget,
3102    regionptr: *const cairo::ffi::cairo_region_t,
3103) {
3104    unsafe {
3105        let instance = &*(ptr as *mut T::Instance);
3106        let imp = instance.imp();
3107        let region: Borrowed<cairo::Region> = from_glib_borrow(mut_override(regionptr));
3108
3109        imp.queue_draw_region(&region);
3110    }
3111}
3112
3113pub unsafe trait WidgetClassSubclassExt: ClassStruct<Type: WidgetImpl> {
3114    fn set_accessible_type(&mut self, type_: glib::Type) {
3115        unsafe {
3116            let widget_class = self as *mut _ as *mut ffi::GtkWidgetClass;
3117            ffi::gtk_widget_class_set_accessible_type(widget_class, type_.into_glib());
3118        }
3119    }
3120
3121    fn set_accessible_role(&mut self, role: atk::Role) {
3122        unsafe {
3123            let widget_class = self as *mut _ as *mut ffi::GtkWidgetClass;
3124            ffi::gtk_widget_class_set_accessible_role(widget_class, role.into_glib());
3125        }
3126    }
3127
3128    fn set_template_bytes(&mut self, template: &glib::Bytes) {
3129        unsafe {
3130            let widget_class = self as *mut _ as *mut ffi::GtkWidgetClass;
3131            ffi::gtk_widget_class_set_template(widget_class, template.to_glib_none().0);
3132        }
3133    }
3134
3135    // rustdoc-stripper-ignore-next
3136    /// Enables baseline support for this widget class.
3137    ///
3138    /// You call this for two reasons:
3139    ///
3140    /// 1. You want your widget subclass to implement baseline support, in which case you must
3141    ///    implement [`WidgetImpl::preferred_height_and_baseline_for_width`].  You should *not*
3142    ///    implement [`WidgetImpl::preferred_height`] or
3143    ///    [`WidgetImpl::preferred_height_for_width`], as they will never be called.
3144    /// 2. You are subclassing a widget that implements baselines, and you want the parent's
3145    ///    baselines to continue working.  In that case you should call this function (as the
3146    ///    baseline-enabled state is *not* inherited), but do not implement the
3147    ///    height/height-for-width trait items yourself.
3148    ///
3149    /// If you want to control sizing yourself, without baseline support, do not call this, and
3150    /// just implement [`WidgetImpl::preferred_height`] and
3151    /// [`WidgetImpl::preferred_height_for_width`].
3152    fn enable_baseline_support(&mut self) {
3153        unsafe {
3154            let widget_class = self as *mut _ as *mut ffi::GtkWidgetClass;
3155            (*widget_class).get_preferred_height_and_baseline_for_width =
3156                Some(widget_get_preferred_height_and_baseline_for_width::<Self::Type>);
3157        }
3158    }
3159
3160    fn set_template(&mut self, template: &[u8]) {
3161        let template_bytes = glib::Bytes::from(template);
3162        self.set_template_bytes(&template_bytes);
3163    }
3164
3165    fn set_template_static(&mut self, template: &'static [u8]) {
3166        let template_bytes = glib::Bytes::from_static(template);
3167        self.set_template_bytes(&template_bytes);
3168    }
3169
3170    fn set_template_from_resource(&mut self, resource_name: &str) {
3171        unsafe {
3172            let widget_class = self as *mut _ as *mut ffi::GtkWidgetClass;
3173            ffi::gtk_widget_class_set_template_from_resource(
3174                widget_class,
3175                resource_name.to_glib_none().0,
3176            );
3177        }
3178    }
3179
3180    fn bind_template_child(&mut self, name: &str) {
3181        unsafe {
3182            let widget_class = self as *mut _ as *mut ffi::GtkWidgetClass;
3183            ffi::gtk_widget_class_bind_template_child_full(
3184                widget_class,
3185                name.to_glib_none().0,
3186                false as glib::ffi::gboolean,
3187                0,
3188            );
3189        }
3190    }
3191
3192    #[allow(clippy::missing_safety_doc)]
3193    unsafe fn bind_template_child_with_offset<T>(
3194        &mut self,
3195        name: &str,
3196        offset: field_offset::FieldOffset<Self::Type, TemplateChild<T>>,
3197    ) where
3198        T: ObjectType + FromGlibPtrNone<*mut <T as ObjectType>::GlibType>,
3199    {
3200        unsafe {
3201            let widget_class = self as *mut _ as *mut ffi::GtkWidgetClass;
3202            let private_offset = <Self::Type as ObjectSubclassType>::type_data()
3203                .as_ref()
3204                .impl_offset();
3205            ffi::gtk_widget_class_bind_template_child_full(
3206                widget_class,
3207                name.to_glib_none().0,
3208                false as glib::ffi::gboolean,
3209                private_offset + (offset.get_byte_offset() as isize),
3210            )
3211        }
3212    }
3213
3214    #[doc(alias = "gtk_widget_class_set_css_name")]
3215    fn set_css_name(&mut self, name: &str) {
3216        unsafe {
3217            let widget_class = self as *mut _ as *mut ffi::GtkWidgetClass;
3218            ffi::gtk_widget_class_set_css_name(widget_class, name.to_glib_none().0);
3219        }
3220    }
3221
3222    #[doc(alias = "gtk_widget_class_get_css_name")]
3223    fn css_name(&self) -> glib::GString {
3224        unsafe {
3225            let widget_class = self as *const _ as *mut ffi::GtkWidgetClass;
3226            from_glib_none(ffi::gtk_widget_class_get_css_name(widget_class))
3227        }
3228    }
3229}
3230
3231unsafe impl<T: ClassStruct> WidgetClassSubclassExt for T where T::Type: WidgetImpl {}
3232
3233#[derive(Debug, PartialEq, Eq)]
3234#[repr(transparent)]
3235pub struct TemplateChild<T>
3236where
3237    T: ObjectType + FromGlibPtrNone<*mut <T as ObjectType>::GlibType>,
3238{
3239    ptr: *mut <T as ObjectType>::GlibType,
3240}
3241
3242impl<T> Default for TemplateChild<T>
3243where
3244    T: ObjectType + FromGlibPtrNone<*mut <T as ObjectType>::GlibType>,
3245{
3246    fn default() -> Self {
3247        Self {
3248            ptr: std::ptr::null_mut(),
3249        }
3250    }
3251}
3252
3253impl<T> std::ops::Deref for TemplateChild<T>
3254where
3255    T: ObjectType + FromGlibPtrNone<*mut <T as ObjectType>::GlibType>,
3256{
3257    type Target = T;
3258
3259    // rustdoc-stripper-ignore-next
3260    /// # Safety
3261    ///
3262    /// Since the template child may not be properly bound,
3263    /// this cast is potentially dangerous if, for example,
3264    /// the template child isn't bound or is of the wrong type.
3265    /// The caller is responsible for ensuring that the template
3266    /// child is bound and of the right type.
3267    fn deref(&self) -> &Self::Target {
3268        unsafe {
3269            assert!(!self.ptr.is_null());
3270            &*(&self.ptr as *const _ as *const T)
3271        }
3272    }
3273}
3274
3275impl<T> TemplateChild<T>
3276where
3277    T: ObjectType + FromGlibPtrNone<*mut <T as ObjectType>::GlibType>,
3278{
3279    #[track_caller]
3280    pub fn get(&self) -> T {
3281        unsafe {
3282            Option::<T>::from_glib_none(self.ptr)
3283                .expect("Failed to retrieve template child. Please check that it has been bound.")
3284        }
3285    }
3286}
3287
3288pub trait CompositeTemplate: WidgetImpl {
3289    fn bind_template(klass: &mut Self::Class);
3290}