Skip to main content

gtk/auto/
switch.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{Actionable, Align, Buildable, Container, Widget, ffi};
6use glib::{
7    object::ObjectType as _,
8    prelude::*,
9    signal::{SignalHandlerId, connect_raw},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    /// [`Switch`][crate::Switch] is a widget that has two states: on or off. The user can control
16    /// which state should be active by clicking the empty area, or by dragging the
17    /// handle.
18    ///
19    /// GtkSwitch can also handle situations where the underlying state changes with
20    /// a delay. See [`state-set`][struct@crate::Switch#state-set] for details.
21    ///
22    /// # CSS nodes
23    ///
24    ///
25    ///
26    /// **⚠️ The following code is in plain ⚠️**
27    ///
28    /// ```plain
29    /// switch
30    /// ╰── slider
31    /// ```
32    ///
33    /// GtkSwitch has two css nodes, the main node with the name switch and a subnode
34    /// named slider. Neither of them is using any style classes.
35    ///
36    /// ## Properties
37    ///
38    ///
39    /// #### `active`
40    ///  Whether the [`Switch`][crate::Switch] widget is in its on or off state.
41    ///
42    /// Readable | Writable
43    ///
44    ///
45    /// #### `state`
46    ///  The backend state that is controlled by the switch.
47    /// See [`state-set`][struct@crate::Switch#state-set] for details.
48    ///
49    /// Readable | Writable
50    /// <details><summary><h4>Widget</h4></summary>
51    ///
52    ///
53    /// #### `app-paintable`
54    ///  Readable | Writable
55    ///
56    ///
57    /// #### `can-default`
58    ///  Readable | Writable
59    ///
60    ///
61    /// #### `can-focus`
62    ///  Readable | Writable
63    ///
64    ///
65    /// #### `composite-child`
66    ///  Readable
67    ///
68    ///
69    /// #### `double-buffered`
70    ///  Whether the widget is double buffered.
71    ///
72    /// Readable | Writable
73    ///
74    ///
75    /// #### `events`
76    ///  Readable | Writable
77    ///
78    ///
79    /// #### `expand`
80    ///  Whether to expand in both directions. Setting this sets both [`hexpand`][struct@crate::Widget#hexpand] and [`vexpand`][struct@crate::Widget#vexpand]
81    ///
82    /// Readable | Writable
83    ///
84    ///
85    /// #### `focus-on-click`
86    ///  Whether the widget should grab focus when it is clicked with the mouse.
87    ///
88    /// This property is only relevant for widgets that can take focus.
89    ///
90    /// Before 3.20, several widgets (GtkButton, GtkFileChooserButton,
91    /// GtkComboBox) implemented this property individually.
92    ///
93    /// Readable | Writable
94    ///
95    ///
96    /// #### `halign`
97    ///  How to distribute horizontal space if widget gets extra space, see [`Align`][crate::Align]
98    ///
99    /// Readable | Writable
100    ///
101    ///
102    /// #### `has-default`
103    ///  Readable | Writable
104    ///
105    ///
106    /// #### `has-focus`
107    ///  Readable | Writable
108    ///
109    ///
110    /// #### `has-tooltip`
111    ///  Enables or disables the emission of [`query-tooltip`][struct@crate::Widget#query-tooltip] on `widget`.
112    /// A value of [`true`] indicates that `widget` can have a tooltip, in this case
113    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to determine
114    /// whether it will provide a tooltip or not.
115    ///
116    /// Note that setting this property to [`true`] for the first time will change
117    /// the event masks of the GdkWindows of this widget to include leave-notify
118    /// and motion-notify events. This cannot and will not be undone when the
119    /// property is set to [`false`] again.
120    ///
121    /// Readable | Writable
122    ///
123    ///
124    /// #### `height-request`
125    ///  Readable | Writable
126    ///
127    ///
128    /// #### `hexpand`
129    ///  Whether to expand horizontally. See [`WidgetExt::set_hexpand()`][crate::prelude::WidgetExt::set_hexpand()].
130    ///
131    /// Readable | Writable
132    ///
133    ///
134    /// #### `hexpand-set`
135    ///  Whether to use the [`hexpand`][struct@crate::Widget#hexpand] property. See [`WidgetExt::is_hexpand_set()`][crate::prelude::WidgetExt::is_hexpand_set()].
136    ///
137    /// Readable | Writable
138    ///
139    ///
140    /// #### `is-focus`
141    ///  Readable | Writable
142    ///
143    ///
144    /// #### `margin`
145    ///  Sets all four sides' margin at once. If read, returns max
146    /// margin on any side.
147    ///
148    /// Readable | Writable
149    ///
150    ///
151    /// #### `margin-bottom`
152    ///  Margin on bottom side of widget.
153    ///
154    /// This property adds margin outside of the widget's normal size
155    /// request, the margin will be added in addition to the size from
156    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
157    ///
158    /// Readable | Writable
159    ///
160    ///
161    /// #### `margin-end`
162    ///  Margin on end of widget, horizontally. This property supports
163    /// left-to-right and right-to-left text directions.
164    ///
165    /// This property adds margin outside of the widget's normal size
166    /// request, the margin will be added in addition to the size from
167    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
168    ///
169    /// Readable | Writable
170    ///
171    ///
172    /// #### `margin-left`
173    ///  Margin on left side of widget.
174    ///
175    /// This property adds margin outside of the widget's normal size
176    /// request, the margin will be added in addition to the size from
177    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
178    ///
179    /// Readable | Writable
180    ///
181    ///
182    /// #### `margin-right`
183    ///  Margin on right side of widget.
184    ///
185    /// This property adds margin outside of the widget's normal size
186    /// request, the margin will be added in addition to the size from
187    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
188    ///
189    /// Readable | Writable
190    ///
191    ///
192    /// #### `margin-start`
193    ///  Margin on start of widget, horizontally. This property supports
194    /// left-to-right and right-to-left text directions.
195    ///
196    /// This property adds margin outside of the widget's normal size
197    /// request, the margin will be added in addition to the size from
198    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
199    ///
200    /// Readable | Writable
201    ///
202    ///
203    /// #### `margin-top`
204    ///  Margin on top side of widget.
205    ///
206    /// This property adds margin outside of the widget's normal size
207    /// request, the margin will be added in addition to the size from
208    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
209    ///
210    /// Readable | Writable
211    ///
212    ///
213    /// #### `name`
214    ///  Readable | Writable
215    ///
216    ///
217    /// #### `no-show-all`
218    ///  Readable | Writable
219    ///
220    ///
221    /// #### `opacity`
222    ///  The requested opacity of the widget. See [`WidgetExt::set_opacity()`][crate::prelude::WidgetExt::set_opacity()] for
223    /// more details about window opacity.
224    ///
225    /// Before 3.8 this was only available in GtkWindow
226    ///
227    /// Readable | Writable
228    ///
229    ///
230    /// #### `parent`
231    ///  Readable | Writable
232    ///
233    ///
234    /// #### `receives-default`
235    ///  Readable | Writable
236    ///
237    ///
238    /// #### `scale-factor`
239    ///  The scale factor of the widget. See [`WidgetExt::scale_factor()`][crate::prelude::WidgetExt::scale_factor()] for
240    /// more details about widget scaling.
241    ///
242    /// Readable
243    ///
244    ///
245    /// #### `sensitive`
246    ///  Readable | Writable
247    ///
248    ///
249    /// #### `style`
250    ///  The style of the widget, which contains information about how it will look (colors, etc).
251    ///
252    /// Readable | Writable
253    ///
254    ///
255    /// #### `tooltip-markup`
256    ///  Sets the text of tooltip to be the given string, which is marked up
257    /// with the [Pango text markup language][PangoMarkupFormat].
258    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
259    ///
260    /// This is a convenience property which will take care of getting the
261    /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
262    /// will automatically be set to [`true`] and there will be taken care of
263    /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
264    ///
265    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
266    /// are set, the last one wins.
267    ///
268    /// Readable | Writable
269    ///
270    ///
271    /// #### `tooltip-text`
272    ///  Sets the text of tooltip to be the given string.
273    ///
274    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
275    ///
276    /// This is a convenience property which will take care of getting the
277    /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
278    /// will automatically be set to [`true`] and there will be taken care of
279    /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
280    ///
281    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
282    /// are set, the last one wins.
283    ///
284    /// Readable | Writable
285    ///
286    ///
287    /// #### `valign`
288    ///  How to distribute vertical space if widget gets extra space, see [`Align`][crate::Align]
289    ///
290    /// Readable | Writable
291    ///
292    ///
293    /// #### `vexpand`
294    ///  Whether to expand vertically. See [`WidgetExt::set_vexpand()`][crate::prelude::WidgetExt::set_vexpand()].
295    ///
296    /// Readable | Writable
297    ///
298    ///
299    /// #### `vexpand-set`
300    ///  Whether to use the [`vexpand`][struct@crate::Widget#vexpand] property. See [`WidgetExt::is_vexpand_set()`][crate::prelude::WidgetExt::is_vexpand_set()].
301    ///
302    /// Readable | Writable
303    ///
304    ///
305    /// #### `visible`
306    ///  Readable | Writable
307    ///
308    ///
309    /// #### `width-request`
310    ///  Readable | Writable
311    ///
312    ///
313    /// #### `window`
314    ///  The widget's window if it is realized, [`None`] otherwise.
315    ///
316    /// Readable
317    /// </details>
318    /// <details><summary><h4>Actionable</h4></summary>
319    ///
320    ///
321    /// #### `action-name`
322    ///  Readable | Writable
323    ///
324    ///
325    /// #### `action-target`
326    ///  Readable | Writable
327    /// </details>
328    /// <details><summary><h4>Activatable</h4></summary>
329    ///
330    ///
331    /// #### `related-action`
332    ///  The action that this activatable will activate and receive
333    /// updates from for various states and possibly appearance.
334    ///
335    /// > `GtkActivatable` implementors need to handle the this property and
336    /// > call `gtk_activatable_do_set_related_action()` when it changes.
337    ///
338    /// Readable | Writable
339    ///
340    ///
341    /// #### `use-action-appearance`
342    ///  Whether this activatable should reset its layout
343    /// and appearance when setting the related action or when
344    /// the action changes appearance.
345    ///
346    /// See the `GtkAction` documentation directly to find which properties
347    /// should be ignored by the `GtkActivatable` when this property is [`false`].
348    ///
349    /// > `GtkActivatable` implementors need to handle this property
350    /// > and call `gtk_activatable_sync_action_properties()` on the activatable
351    /// > widget when it changes.
352    ///
353    /// Readable | Writable
354    /// </details>
355    ///
356    /// ## Signals
357    ///
358    ///
359    /// #### `activate`
360    ///  The ::activate signal on GtkSwitch is an action signal and
361    /// emitting it causes the switch to animate.
362    /// Applications should never connect to this signal, but use the
363    /// notify::active signal.
364    ///
365    /// Action
366    ///
367    ///
368    /// #### `state-set`
369    ///  The ::state-set signal on GtkSwitch is emitted to change the underlying
370    /// state. It is emitted when the user changes the switch position. The
371    /// default handler keeps the state in sync with the [`active`][struct@crate::Switch#active]
372    /// property.
373    ///
374    /// To implement delayed state change, applications can connect to this signal,
375    /// initiate the change of the underlying state, and call [`SwitchExt::set_state()`][crate::prelude::SwitchExt::set_state()]
376    /// when the underlying state change is complete. The signal handler should
377    /// return [`true`] to prevent the default handler from running.
378    ///
379    /// Visually, the underlying state is represented by the trough color of
380    /// the switch, while the [`active`][struct@crate::Switch#active] property is represented by the
381    /// position of the switch.
382    ///
383    ///
384    /// <details><summary><h4>Widget</h4></summary>
385    ///
386    ///
387    /// #### `accel-closures-changed`
388    ///
389    ///
390    ///
391    /// #### `button-press-event`
392    ///  The ::button-press-event signal will be emitted when a button
393    /// (typically from a mouse) is pressed.
394    ///
395    /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the
396    /// widget needs to enable the [`gdk::EventMask::BUTTON_PRESS_MASK`][crate::gdk::EventMask::BUTTON_PRESS_MASK] mask.
397    ///
398    /// This signal will be sent to the grab widget if there is one.
399    ///
400    ///
401    ///
402    ///
403    /// #### `button-release-event`
404    ///  The ::button-release-event signal will be emitted when a button
405    /// (typically from a mouse) is released.
406    ///
407    /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the
408    /// widget needs to enable the [`gdk::EventMask::BUTTON_RELEASE_MASK`][crate::gdk::EventMask::BUTTON_RELEASE_MASK] mask.
409    ///
410    /// This signal will be sent to the grab widget if there is one.
411    ///
412    ///
413    ///
414    ///
415    /// #### `can-activate-accel`
416    ///  Determines whether an accelerator that activates the signal
417    /// identified by `signal_id` can currently be activated.
418    /// This signal is present to allow applications and derived
419    /// widgets to override the default [`Widget`][crate::Widget] handling
420    /// for determining whether an accelerator can be activated.
421    ///
422    ///
423    ///
424    ///
425    /// #### `child-notify`
426    ///  The ::child-notify signal is emitted for each
427    /// [child property][child-properties] that has
428    /// changed on an object. The signal's detail holds the property name.
429    ///
430    /// Detailed
431    ///
432    ///
433    /// #### `composited-changed`
434    ///  The ::composited-changed signal is emitted when the composited
435    /// status of `widgets` screen changes.
436    /// See [`Screen::is_composited()`][crate::gdk::Screen::is_composited()].
437    ///
438    /// Action
439    ///
440    ///
441    /// #### `configure-event`
442    ///  The ::configure-event signal will be emitted when the size, position or
443    /// stacking of the `widget`'s window has changed.
444    ///
445    /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
446    /// to enable the [`gdk::EventMask::STRUCTURE_MASK`][crate::gdk::EventMask::STRUCTURE_MASK] mask. GDK will enable this mask
447    /// automatically for all new windows.
448    ///
449    ///
450    ///
451    ///
452    /// #### `damage-event`
453    ///  Emitted when a redirected window belonging to `widget` gets drawn into.
454    /// The region/area members of the event shows what area of the redirected
455    /// drawable was drawn into.
456    ///
457    ///
458    ///
459    ///
460    /// #### `delete-event`
461    ///  The ::delete-event signal is emitted if a user requests that
462    /// a toplevel window is closed. The default handler for this signal
463    /// destroys the window. Connecting [`WidgetExtManual::hide_on_delete()`][crate::prelude::WidgetExtManual::hide_on_delete()] to
464    /// this signal will cause the window to be hidden instead, so that
465    /// it can later be shown again without reconstructing it.
466    ///
467    ///
468    ///
469    ///
470    /// #### `destroy`
471    ///  Signals that all holders of a reference to the widget should release
472    /// the reference that they hold. May result in finalization of the widget
473    /// if all references are released.
474    ///
475    /// This signal is not suitable for saving widget state.
476    ///
477    ///
478    ///
479    ///
480    /// #### `destroy-event`
481    ///  The ::destroy-event signal is emitted when a [`gdk::Window`][crate::gdk::Window] is destroyed.
482    /// You rarely get this signal, because most widgets disconnect themselves
483    /// from their window before they destroy it, so no widget owns the
484    /// window at destroy time.
485    ///
486    /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
487    /// to enable the [`gdk::EventMask::STRUCTURE_MASK`][crate::gdk::EventMask::STRUCTURE_MASK] mask. GDK will enable this mask
488    /// automatically for all new windows.
489    ///
490    ///
491    ///
492    ///
493    /// #### `direction-changed`
494    ///  The ::direction-changed signal is emitted when the text direction
495    /// of a widget changes.
496    ///
497    ///
498    ///
499    ///
500    /// #### `drag-begin`
501    ///  The ::drag-begin signal is emitted on the drag source when a drag is
502    /// started. A typical reason to connect to this signal is to set up a
503    /// custom drag icon with e.g. [`WidgetExt::drag_source_set_icon_pixbuf()`][crate::prelude::WidgetExt::drag_source_set_icon_pixbuf()].
504    ///
505    /// Note that some widgets set up a drag icon in the default handler of
506    /// this signal, so you may have to use `g_signal_connect_after()` to
507    /// override what the default handler did.
508    ///
509    ///
510    ///
511    ///
512    /// #### `drag-data-delete`
513    ///  The ::drag-data-delete signal is emitted on the drag source when a drag
514    /// with the action [`gdk::DragAction::MOVE`][crate::gdk::DragAction::MOVE] is successfully completed. The signal
515    /// handler is responsible for deleting the data that has been dropped. What
516    /// "delete" means depends on the context of the drag operation.
517    ///
518    ///
519    ///
520    ///
521    /// #### `drag-data-get`
522    ///  The ::drag-data-get signal is emitted on the drag source when the drop
523    /// site requests the data which is dragged. It is the responsibility of
524    /// the signal handler to fill `data` with the data in the format which
525    /// is indicated by `info`. See [`SelectionData::set()`][crate::SelectionData::set()] and
526    /// [`SelectionData::set_text()`][crate::SelectionData::set_text()].
527    ///
528    ///
529    ///
530    ///
531    /// #### `drag-data-received`
532    ///  The ::drag-data-received signal is emitted on the drop site when the
533    /// dragged data has been received. If the data was received in order to
534    /// determine whether the drop will be accepted, the handler is expected
535    /// to call `gdk_drag_status()` and not finish the drag.
536    /// If the data was received in response to a [`drag-drop`][struct@crate::Widget#drag-drop] signal
537    /// (and this is the last target to be received), the handler for this
538    /// signal is expected to process the received data and then call
539    /// `gtk_drag_finish()`, setting the `success` parameter depending on
540    /// whether the data was processed successfully.
541    ///
542    /// Applications must create some means to determine why the signal was emitted
543    /// and therefore whether to call `gdk_drag_status()` or `gtk_drag_finish()`.
544    ///
545    /// The handler may inspect the selected action with
546    /// [`DragContext::selected_action()`][crate::gdk::DragContext::selected_action()] before calling
547    /// `gtk_drag_finish()`, e.g. to implement [`gdk::DragAction::ASK`][crate::gdk::DragAction::ASK] as
548    /// shown in the following example:
549    ///
550    ///
551    /// **⚠️ The following code is in C ⚠️**
552    ///
553    /// ```C
554    /// void
555    /// drag_data_received (GtkWidget          *widget,
556    ///                     GdkDragContext     *context,
557    ///                     gint                x,
558    ///                     gint                y,
559    ///                     GtkSelectionData   *data,
560    ///                     guint               info,
561    ///                     guint               time)
562    /// {
563    ///   if ((data->length >= 0) && (data->format == 8))
564    ///     {
565    ///       GdkDragAction action;
566    ///
567    ///       // handle data here
568    ///
569    ///       action = gdk_drag_context_get_selected_action (context);
570    ///       if (action == GDK_ACTION_ASK)
571    ///         {
572    ///           GtkWidget *dialog;
573    ///           gint response;
574    ///
575    ///           dialog = gtk_message_dialog_new (NULL,
576    ///                                            GTK_DIALOG_MODAL |
577    ///                                            GTK_DIALOG_DESTROY_WITH_PARENT,
578    ///                                            GTK_MESSAGE_INFO,
579    ///                                            GTK_BUTTONS_YES_NO,
580    ///                                            "Move the data ?\n");
581    ///           response = gtk_dialog_run (GTK_DIALOG (dialog));
582    ///           gtk_widget_destroy (dialog);
583    ///
584    ///           if (response == GTK_RESPONSE_YES)
585    ///             action = GDK_ACTION_MOVE;
586    ///           else
587    ///             action = GDK_ACTION_COPY;
588    ///          }
589    ///
590    ///       gtk_drag_finish (context, TRUE, action == GDK_ACTION_MOVE, time);
591    ///     }
592    ///   else
593    ///     gtk_drag_finish (context, FALSE, FALSE, time);
594    ///  }
595    /// ```
596    ///
597    ///
598    ///
599    ///
600    /// #### `drag-drop`
601    ///  The ::drag-drop signal is emitted on the drop site when the user drops
602    /// the data onto the widget. The signal handler must determine whether
603    /// the cursor position is in a drop zone or not. If it is not in a drop
604    /// zone, it returns [`false`] and no further processing is necessary.
605    /// Otherwise, the handler returns [`true`]. In this case, the handler must
606    /// ensure that `gtk_drag_finish()` is called to let the source know that
607    /// the drop is done. The call to `gtk_drag_finish()` can be done either
608    /// directly or in a [`drag-data-received`][struct@crate::Widget#drag-data-received] handler which gets
609    /// triggered by calling [`WidgetExt::drag_get_data()`][crate::prelude::WidgetExt::drag_get_data()] to receive the data for one
610    /// or more of the supported targets.
611    ///
612    ///
613    ///
614    ///
615    /// #### `drag-end`
616    ///  The ::drag-end signal is emitted on the drag source when a drag is
617    /// finished. A typical reason to connect to this signal is to undo
618    /// things done in [`drag-begin`][struct@crate::Widget#drag-begin].
619    ///
620    ///
621    ///
622    ///
623    /// #### `drag-failed`
624    ///  The ::drag-failed signal is emitted on the drag source when a drag has
625    /// failed. The signal handler may hook custom code to handle a failed DnD
626    /// operation based on the type of error, it returns [`true`] is the failure has
627    /// been already handled (not showing the default "drag operation failed"
628    /// animation), otherwise it returns [`false`].
629    ///
630    ///
631    ///
632    ///
633    /// #### `drag-leave`
634    ///  The ::drag-leave signal is emitted on the drop site when the cursor
635    /// leaves the widget. A typical reason to connect to this signal is to
636    /// undo things done in [`drag-motion`][struct@crate::Widget#drag-motion], e.g. undo highlighting
637    /// with [`WidgetExt::drag_unhighlight()`][crate::prelude::WidgetExt::drag_unhighlight()].
638    ///
639    ///
640    /// Likewise, the [`drag-leave`][struct@crate::Widget#drag-leave] signal is also emitted before the
641    /// ::drag-drop signal, for instance to allow cleaning up of a preview item
642    /// created in the [`drag-motion`][struct@crate::Widget#drag-motion] signal handler.
643    ///
644    ///
645    ///
646    ///
647    /// #### `drag-motion`
648    ///  The ::drag-motion signal is emitted on the drop site when the user
649    /// moves the cursor over the widget during a drag. The signal handler
650    /// must determine whether the cursor position is in a drop zone or not.
651    /// If it is not in a drop zone, it returns [`false`] and no further processing
652    /// is necessary. Otherwise, the handler returns [`true`]. In this case, the
653    /// handler is responsible for providing the necessary information for
654    /// displaying feedback to the user, by calling `gdk_drag_status()`.
655    ///
656    /// If the decision whether the drop will be accepted or rejected can't be
657    /// made based solely on the cursor position and the type of the data, the
658    /// handler may inspect the dragged data by calling [`WidgetExt::drag_get_data()`][crate::prelude::WidgetExt::drag_get_data()] and
659    /// defer the `gdk_drag_status()` call to the [`drag-data-received`][struct@crate::Widget#drag-data-received]
660    /// handler. Note that you must pass [`DestDefaults::DROP`][crate::DestDefaults::DROP],
661    /// [`DestDefaults::MOTION`][crate::DestDefaults::MOTION] or [`DestDefaults::ALL`][crate::DestDefaults::ALL] to [`WidgetExtManual::drag_dest_set()`][crate::prelude::WidgetExtManual::drag_dest_set()]
662    /// when using the drag-motion signal that way.
663    ///
664    /// Also note that there is no drag-enter signal. The drag receiver has to
665    /// keep track of whether he has received any drag-motion signals since the
666    /// last [`drag-leave`][struct@crate::Widget#drag-leave] and if not, treat the drag-motion signal as
667    /// an "enter" signal. Upon an "enter", the handler will typically highlight
668    /// the drop site with [`WidgetExt::drag_highlight()`][crate::prelude::WidgetExt::drag_highlight()].
669    ///
670    ///
671    /// **⚠️ The following code is in C ⚠️**
672    ///
673    /// ```C
674    /// static void
675    /// drag_motion (GtkWidget      *widget,
676    ///              GdkDragContext *context,
677    ///              gint            x,
678    ///              gint            y,
679    ///              guint           time)
680    /// {
681    ///   GdkAtom target;
682    ///
683    ///   PrivateData *private_data = GET_PRIVATE_DATA (widget);
684    ///
685    ///   if (!private_data->drag_highlight)
686    ///    {
687    ///      private_data->drag_highlight = 1;
688    ///      gtk_drag_highlight (widget);
689    ///    }
690    ///
691    ///   target = gtk_drag_dest_find_target (widget, context, NULL);
692    ///   if (target == GDK_NONE)
693    ///     gdk_drag_status (context, 0, time);
694    ///   else
695    ///    {
696    ///      private_data->pending_status
697    ///         = gdk_drag_context_get_suggested_action (context);
698    ///      gtk_drag_get_data (widget, context, target, time);
699    ///    }
700    ///
701    ///   return TRUE;
702    /// }
703    ///
704    /// static void
705    /// drag_data_received (GtkWidget        *widget,
706    ///                     GdkDragContext   *context,
707    ///                     gint              x,
708    ///                     gint              y,
709    ///                     GtkSelectionData *selection_data,
710    ///                     guint             info,
711    ///                     guint             time)
712    /// {
713    ///   PrivateData *private_data = GET_PRIVATE_DATA (widget);
714    ///
715    ///   if (private_data->suggested_action)
716    ///    {
717    ///      private_data->suggested_action = 0;
718    ///
719    ///      // We are getting this data due to a request in drag_motion,
720    ///      // rather than due to a request in drag_drop, so we are just
721    ///      // supposed to call gdk_drag_status(), not actually paste in
722    ///      // the data.
723    ///
724    ///      str = gtk_selection_data_get_text (selection_data);
725    ///      if (!data_is_acceptable (str))
726    ///        gdk_drag_status (context, 0, time);
727    ///      else
728    ///        gdk_drag_status (context,
729    ///                         private_data->suggested_action,
730    ///                         time);
731    ///    }
732    ///   else
733    ///    {
734    ///      // accept the drop
735    ///    }
736    /// }
737    /// ```
738    ///
739    ///
740    ///
741    ///
742    /// #### `draw`
743    ///  This signal is emitted when a widget is supposed to render itself.
744    /// The `widget`'s top left corner must be painted at the origin of
745    /// the passed in context and be sized to the values returned by
746    /// [`WidgetExt::allocated_width()`][crate::prelude::WidgetExt::allocated_width()] and
747    /// [`WidgetExt::allocated_height()`][crate::prelude::WidgetExt::allocated_height()].
748    ///
749    /// Signal handlers connected to this signal can modify the cairo
750    /// context passed as `cr` in any way they like and don't need to
751    /// restore it. The signal emission takes care of calling `cairo_save()`
752    /// before and `cairo_restore()` after invoking the handler.
753    ///
754    /// The signal handler will get a `cr` with a clip region already set to the
755    /// widget's dirty region, i.e. to the area that needs repainting. Complicated
756    /// widgets that want to avoid redrawing themselves completely can get the full
757    /// extents of the clip region with `gdk_cairo_get_clip_rectangle()`, or they can
758    /// get a finer-grained representation of the dirty region with
759    /// `cairo_copy_clip_rectangle_list()`.
760    ///
761    ///
762    ///
763    ///
764    /// #### `enter-notify-event`
765    ///  The ::enter-notify-event will be emitted when the pointer enters
766    /// the `widget`'s window.
767    ///
768    /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
769    /// to enable the [`gdk::EventMask::ENTER_NOTIFY_MASK`][crate::gdk::EventMask::ENTER_NOTIFY_MASK] mask.
770    ///
771    /// This signal will be sent to the grab widget if there is one.
772    ///
773    ///
774    ///
775    ///
776    /// #### `event`
777    ///  The GTK+ main loop will emit three signals for each GDK event delivered
778    /// to a widget: one generic ::event signal, another, more specific,
779    /// signal that matches the type of event delivered (e.g.
780    /// [`key-press-event`][struct@crate::Widget#key-press-event]) and finally a generic
781    /// [`event-after`][struct@crate::Widget#event-after] signal.
782    ///
783    ///
784    ///
785    ///
786    /// #### `event-after`
787    ///  After the emission of the [`event`][struct@crate::Widget#event] signal and (optionally)
788    /// the second more specific signal, ::event-after will be emitted
789    /// regardless of the previous two signals handlers return values.
790    ///
791    ///
792    ///
793    ///
794    /// #### `focus`
795    ///
796    ///
797    ///
798    /// #### `focus-in-event`
799    ///  The ::focus-in-event signal will be emitted when the keyboard focus
800    /// enters the `widget`'s window.
801    ///
802    /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
803    /// to enable the [`gdk::EventMask::FOCUS_CHANGE_MASK`][crate::gdk::EventMask::FOCUS_CHANGE_MASK] mask.
804    ///
805    ///
806    ///
807    ///
808    /// #### `focus-out-event`
809    ///  The ::focus-out-event signal will be emitted when the keyboard focus
810    /// leaves the `widget`'s window.
811    ///
812    /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
813    /// to enable the [`gdk::EventMask::FOCUS_CHANGE_MASK`][crate::gdk::EventMask::FOCUS_CHANGE_MASK] mask.
814    ///
815    ///
816    ///
817    ///
818    /// #### `grab-broken-event`
819    ///  Emitted when a pointer or keyboard grab on a window belonging
820    /// to `widget` gets broken.
821    ///
822    /// On X11, this happens when the grab window becomes unviewable
823    /// (i.e. it or one of its ancestors is unmapped), or if the same
824    /// application grabs the pointer or keyboard again.
825    ///
826    ///
827    ///
828    ///
829    /// #### `grab-focus`
830    ///  Action
831    ///
832    ///
833    /// #### `grab-notify`
834    ///  The ::grab-notify signal is emitted when a widget becomes
835    /// shadowed by a GTK+ grab (not a pointer or keyboard grab) on
836    /// another widget, or when it becomes unshadowed due to a grab
837    /// being removed.
838    ///
839    /// A widget is shadowed by a [`WidgetExt::grab_add()`][crate::prelude::WidgetExt::grab_add()] when the topmost
840    /// grab widget in the grab stack of its window group is not
841    /// its ancestor.
842    ///
843    ///
844    ///
845    ///
846    /// #### `hide`
847    ///  The ::hide signal is emitted when `widget` is hidden, for example with
848    /// [`WidgetExt::hide()`][crate::prelude::WidgetExt::hide()].
849    ///
850    ///
851    ///
852    ///
853    /// #### `hierarchy-changed`
854    ///  The ::hierarchy-changed signal is emitted when the
855    /// anchored state of a widget changes. A widget is
856    /// “anchored” when its toplevel
857    /// ancestor is a [`Window`][crate::Window]. This signal is emitted when
858    /// a widget changes from un-anchored to anchored or vice-versa.
859    ///
860    ///
861    ///
862    ///
863    /// #### `key-press-event`
864    ///  The ::key-press-event signal is emitted when a key is pressed. The signal
865    /// emission will reoccur at the key-repeat rate when the key is kept pressed.
866    ///
867    /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
868    /// to enable the [`gdk::EventMask::KEY_PRESS_MASK`][crate::gdk::EventMask::KEY_PRESS_MASK] mask.
869    ///
870    /// This signal will be sent to the grab widget if there is one.
871    ///
872    ///
873    ///
874    ///
875    /// #### `key-release-event`
876    ///  The ::key-release-event signal is emitted when a key is released.
877    ///
878    /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
879    /// to enable the [`gdk::EventMask::KEY_RELEASE_MASK`][crate::gdk::EventMask::KEY_RELEASE_MASK] mask.
880    ///
881    /// This signal will be sent to the grab widget if there is one.
882    ///
883    ///
884    ///
885    ///
886    /// #### `keynav-failed`
887    ///  Gets emitted if keyboard navigation fails.
888    /// See [`WidgetExt::keynav_failed()`][crate::prelude::WidgetExt::keynav_failed()] for details.
889    ///
890    ///
891    ///
892    ///
893    /// #### `leave-notify-event`
894    ///  The ::leave-notify-event will be emitted when the pointer leaves
895    /// the `widget`'s window.
896    ///
897    /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
898    /// to enable the [`gdk::EventMask::LEAVE_NOTIFY_MASK`][crate::gdk::EventMask::LEAVE_NOTIFY_MASK] mask.
899    ///
900    /// This signal will be sent to the grab widget if there is one.
901    ///
902    ///
903    ///
904    ///
905    /// #### `map`
906    ///  The ::map signal is emitted when `widget` is going to be mapped, that is
907    /// when the widget is visible (which is controlled with
908    /// [`WidgetExt::set_visible()`][crate::prelude::WidgetExt::set_visible()]) and all its parents up to the toplevel widget
909    /// are also visible. Once the map has occurred, [`map-event`][struct@crate::Widget#map-event] will
910    /// be emitted.
911    ///
912    /// The ::map signal can be used to determine whether a widget will be drawn,
913    /// for instance it can resume an animation that was stopped during the
914    /// emission of [`unmap`][struct@crate::Widget#unmap].
915    ///
916    ///
917    ///
918    ///
919    /// #### `map-event`
920    ///  The ::map-event signal will be emitted when the `widget`'s window is
921    /// mapped. A window is mapped when it becomes visible on the screen.
922    ///
923    /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
924    /// to enable the [`gdk::EventMask::STRUCTURE_MASK`][crate::gdk::EventMask::STRUCTURE_MASK] mask. GDK will enable this mask
925    /// automatically for all new windows.
926    ///
927    ///
928    ///
929    ///
930    /// #### `mnemonic-activate`
931    ///  The default handler for this signal activates `widget` if `group_cycling`
932    /// is [`false`], or just makes `widget` grab focus if `group_cycling` is [`true`].
933    ///
934    ///
935    ///
936    ///
937    /// #### `motion-notify-event`
938    ///  The ::motion-notify-event signal is emitted when the pointer moves
939    /// over the widget's [`gdk::Window`][crate::gdk::Window].
940    ///
941    /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget
942    /// needs to enable the [`gdk::EventMask::POINTER_MOTION_MASK`][crate::gdk::EventMask::POINTER_MOTION_MASK] mask.
943    ///
944    /// This signal will be sent to the grab widget if there is one.
945    ///
946    ///
947    ///
948    ///
949    /// #### `move-focus`
950    ///  Action
951    ///
952    ///
953    /// #### `parent-set`
954    ///  The ::parent-set signal is emitted when a new parent
955    /// has been set on a widget.
956    ///
957    ///
958    ///
959    ///
960    /// #### `popup-menu`
961    ///  This signal gets emitted whenever a widget should pop up a context
962    /// menu. This usually happens through the standard key binding mechanism;
963    /// by pressing a certain key while a widget is focused, the user can cause
964    /// the widget to pop up a menu. For example, the [`Entry`][crate::Entry] widget creates
965    /// a menu with clipboard commands. See the
966    /// [Popup Menu Migration Checklist][checklist-popup-menu]
967    /// for an example of how to use this signal.
968    ///
969    /// Action
970    ///
971    ///
972    /// #### `property-notify-event`
973    ///  The ::property-notify-event signal will be emitted when a property on
974    /// the `widget`'s window has been changed or deleted.
975    ///
976    /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
977    /// to enable the [`gdk::EventMask::PROPERTY_CHANGE_MASK`][crate::gdk::EventMask::PROPERTY_CHANGE_MASK] mask.
978    ///
979    ///
980    ///
981    ///
982    /// #### `proximity-in-event`
983    ///  To receive this signal the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
984    /// to enable the [`gdk::EventMask::PROXIMITY_IN_MASK`][crate::gdk::EventMask::PROXIMITY_IN_MASK] mask.
985    ///
986    /// This signal will be sent to the grab widget if there is one.
987    ///
988    ///
989    ///
990    ///
991    /// #### `proximity-out-event`
992    ///  To receive this signal the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
993    /// to enable the [`gdk::EventMask::PROXIMITY_OUT_MASK`][crate::gdk::EventMask::PROXIMITY_OUT_MASK] mask.
994    ///
995    /// This signal will be sent to the grab widget if there is one.
996    ///
997    ///
998    ///
999    ///
1000    /// #### `query-tooltip`
1001    ///  Emitted when [`has-tooltip`][struct@crate::Widget#has-tooltip] is [`true`] and the hover timeout
1002    /// has expired with the cursor hovering "above" `widget`; or emitted when `widget` got
1003    /// focus in keyboard mode.
1004    ///
1005    /// Using the given coordinates, the signal handler should determine
1006    /// whether a tooltip should be shown for `widget`. If this is the case
1007    /// [`true`] should be returned, [`false`] otherwise. Note that if
1008    /// `keyboard_mode` is [`true`], the values of `x` and `y` are undefined and
1009    /// should not be used.
1010    ///
1011    /// The signal handler is free to manipulate `tooltip` with the therefore
1012    /// destined function calls.
1013    ///
1014    ///
1015    ///
1016    ///
1017    /// #### `realize`
1018    ///  The ::realize signal is emitted when `widget` is associated with a
1019    /// [`gdk::Window`][crate::gdk::Window], which means that [`WidgetExt::realize()`][crate::prelude::WidgetExt::realize()] has been called or the
1020    /// widget has been mapped (that is, it is going to be drawn).
1021    ///
1022    ///
1023    ///
1024    ///
1025    /// #### `screen-changed`
1026    ///  The ::screen-changed signal gets emitted when the
1027    /// screen of a widget has changed.
1028    ///
1029    ///
1030    ///
1031    ///
1032    /// #### `scroll-event`
1033    ///  The ::scroll-event signal is emitted when a button in the 4 to 7
1034    /// range is pressed. Wheel mice are usually configured to generate
1035    /// button press events for buttons 4 and 5 when the wheel is turned.
1036    ///
1037    /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
1038    /// to enable the [`gdk::EventMask::SCROLL_MASK`][crate::gdk::EventMask::SCROLL_MASK] mask.
1039    ///
1040    /// This signal will be sent to the grab widget if there is one.
1041    ///
1042    ///
1043    ///
1044    ///
1045    /// #### `selection-clear-event`
1046    ///  The ::selection-clear-event signal will be emitted when the
1047    /// the `widget`'s window has lost ownership of a selection.
1048    ///
1049    ///
1050    ///
1051    ///
1052    /// #### `selection-get`
1053    ///
1054    ///
1055    ///
1056    /// #### `selection-notify-event`
1057    ///
1058    ///
1059    ///
1060    /// #### `selection-received`
1061    ///
1062    ///
1063    ///
1064    /// #### `selection-request-event`
1065    ///  The ::selection-request-event signal will be emitted when
1066    /// another client requests ownership of the selection owned by
1067    /// the `widget`'s window.
1068    ///
1069    ///
1070    ///
1071    ///
1072    /// #### `show`
1073    ///  The ::show signal is emitted when `widget` is shown, for example with
1074    /// [`WidgetExt::show()`][crate::prelude::WidgetExt::show()].
1075    ///
1076    ///
1077    ///
1078    ///
1079    /// #### `show-help`
1080    ///  Action
1081    ///
1082    ///
1083    /// #### `size-allocate`
1084    ///
1085    ///
1086    ///
1087    /// #### `state-changed`
1088    ///  The ::state-changed signal is emitted when the widget state changes.
1089    /// See `gtk_widget_get_state()`.
1090    ///
1091    ///
1092    ///
1093    ///
1094    /// #### `state-flags-changed`
1095    ///  The ::state-flags-changed signal is emitted when the widget state
1096    /// changes, see [`WidgetExt::state_flags()`][crate::prelude::WidgetExt::state_flags()].
1097    ///
1098    ///
1099    ///
1100    ///
1101    /// #### `style-set`
1102    ///  The ::style-set signal is emitted when a new style has been set
1103    /// on a widget. Note that style-modifying functions like
1104    /// `gtk_widget_modify_base()` also cause this signal to be emitted.
1105    ///
1106    /// Note that this signal is emitted for changes to the deprecated
1107    /// `GtkStyle`. To track changes to the [`StyleContext`][crate::StyleContext] associated
1108    /// with a widget, use the [`style-updated`][struct@crate::Widget#style-updated] signal.
1109    ///
1110    ///
1111    ///
1112    ///
1113    /// #### `style-updated`
1114    ///  The ::style-updated signal is a convenience signal that is emitted when the
1115    /// [`changed`][struct@crate::StyleContext#changed] signal is emitted on the `widget`'s associated
1116    /// [`StyleContext`][crate::StyleContext] as returned by [`WidgetExt::style_context()`][crate::prelude::WidgetExt::style_context()].
1117    ///
1118    /// Note that style-modifying functions like `gtk_widget_override_color()` also
1119    /// cause this signal to be emitted.
1120    ///
1121    ///
1122    ///
1123    ///
1124    /// #### `touch-event`
1125    ///
1126    ///
1127    ///
1128    /// #### `unmap`
1129    ///  The ::unmap signal is emitted when `widget` is going to be unmapped, which
1130    /// means that either it or any of its parents up to the toplevel widget have
1131    /// been set as hidden.
1132    ///
1133    /// As ::unmap indicates that a widget will not be shown any longer, it can be
1134    /// used to, for example, stop an animation on the widget.
1135    ///
1136    ///
1137    ///
1138    ///
1139    /// #### `unmap-event`
1140    ///  The ::unmap-event signal will be emitted when the `widget`'s window is
1141    /// unmapped. A window is unmapped when it becomes invisible on the screen.
1142    ///
1143    /// To receive this signal, the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
1144    /// to enable the [`gdk::EventMask::STRUCTURE_MASK`][crate::gdk::EventMask::STRUCTURE_MASK] mask. GDK will enable this mask
1145    /// automatically for all new windows.
1146    ///
1147    ///
1148    ///
1149    ///
1150    /// #### `unrealize`
1151    ///  The ::unrealize signal is emitted when the [`gdk::Window`][crate::gdk::Window] associated with
1152    /// `widget` is destroyed, which means that [`WidgetExt::unrealize()`][crate::prelude::WidgetExt::unrealize()] has been
1153    /// called or the widget has been unmapped (that is, it is going to be
1154    /// hidden).
1155    ///
1156    ///
1157    ///
1158    ///
1159    /// #### `visibility-notify-event`
1160    ///  The ::visibility-notify-event will be emitted when the `widget`'s
1161    /// window is obscured or unobscured.
1162    ///
1163    /// To receive this signal the [`gdk::Window`][crate::gdk::Window] associated to the widget needs
1164    /// to enable the [`gdk::EventMask::VISIBILITY_NOTIFY_MASK`][crate::gdk::EventMask::VISIBILITY_NOTIFY_MASK] mask.
1165    ///
1166    ///
1167    ///
1168    ///
1169    /// #### `window-state-event`
1170    ///  The ::window-state-event will be emitted when the state of the
1171    /// toplevel window associated to the `widget` changes.
1172    ///
1173    /// To receive this signal the [`gdk::Window`][crate::gdk::Window] associated to the widget
1174    /// needs to enable the [`gdk::EventMask::STRUCTURE_MASK`][crate::gdk::EventMask::STRUCTURE_MASK] mask. GDK will enable
1175    /// this mask automatically for all new windows.
1176    ///
1177    ///
1178    /// </details>
1179    ///
1180    /// # Implements
1181    ///
1182    /// [`SwitchExt`][trait@crate::prelude::SwitchExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ActionableExt`][trait@crate::prelude::ActionableExt], [`SwitchExtManual`][trait@crate::prelude::SwitchExtManual], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`BuildableExtManual`][trait@crate::prelude::BuildableExtManual]
1183    #[doc(alias = "GtkSwitch")]
1184    pub struct Switch(Object<ffi::GtkSwitch, ffi::GtkSwitchClass>) @extends Widget, @implements Buildable, Actionable;
1185
1186    match fn {
1187        type_ => || ffi::gtk_switch_get_type(),
1188    }
1189}
1190
1191impl Switch {
1192    pub const NONE: Option<&'static Switch> = None;
1193
1194    /// Creates a new [`Switch`][crate::Switch] widget.
1195    ///
1196    /// # Returns
1197    ///
1198    /// the newly created [`Switch`][crate::Switch] instance
1199    #[doc(alias = "gtk_switch_new")]
1200    pub fn new() -> Switch {
1201        assert_initialized_main_thread!();
1202        unsafe { Widget::from_glib_none(ffi::gtk_switch_new()).unsafe_cast() }
1203    }
1204
1205    // rustdoc-stripper-ignore-next
1206    /// Creates a new builder-pattern struct instance to construct [`Switch`] objects.
1207    ///
1208    /// This method returns an instance of [`SwitchBuilder`](crate::builders::SwitchBuilder) which can be used to create [`Switch`] objects.
1209    pub fn builder() -> SwitchBuilder {
1210        SwitchBuilder::new()
1211    }
1212}
1213
1214impl Default for Switch {
1215    fn default() -> Self {
1216        Self::new()
1217    }
1218}
1219
1220// rustdoc-stripper-ignore-next
1221/// A [builder-pattern] type to construct [`Switch`] objects.
1222///
1223/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
1224#[must_use = "The builder must be built to be used"]
1225pub struct SwitchBuilder {
1226    builder: glib::object::ObjectBuilder<'static, Switch>,
1227}
1228
1229impl SwitchBuilder {
1230    fn new() -> Self {
1231        Self {
1232            builder: glib::object::Object::builder(),
1233        }
1234    }
1235
1236    /// Whether the [`Switch`][crate::Switch] widget is in its on or off state.
1237    pub fn active(self, active: bool) -> Self {
1238        Self {
1239            builder: self.builder.property("active", active),
1240        }
1241    }
1242
1243    /// The backend state that is controlled by the switch.
1244    /// See [`state-set`][struct@crate::Switch#state-set] for details.
1245    pub fn state(self, state: bool) -> Self {
1246        Self {
1247            builder: self.builder.property("state", state),
1248        }
1249    }
1250
1251    pub fn app_paintable(self, app_paintable: bool) -> Self {
1252        Self {
1253            builder: self.builder.property("app-paintable", app_paintable),
1254        }
1255    }
1256
1257    pub fn can_default(self, can_default: bool) -> Self {
1258        Self {
1259            builder: self.builder.property("can-default", can_default),
1260        }
1261    }
1262
1263    pub fn can_focus(self, can_focus: bool) -> Self {
1264        Self {
1265            builder: self.builder.property("can-focus", can_focus),
1266        }
1267    }
1268
1269    pub fn events(self, events: gdk::EventMask) -> Self {
1270        Self {
1271            builder: self.builder.property("events", events),
1272        }
1273    }
1274
1275    /// Whether to expand in both directions. Setting this sets both [`hexpand`][struct@crate::Widget#hexpand] and [`vexpand`][struct@crate::Widget#vexpand]
1276    pub fn expand(self, expand: bool) -> Self {
1277        Self {
1278            builder: self.builder.property("expand", expand),
1279        }
1280    }
1281
1282    /// Whether the widget should grab focus when it is clicked with the mouse.
1283    ///
1284    /// This property is only relevant for widgets that can take focus.
1285    ///
1286    /// Before 3.20, several widgets (GtkButton, GtkFileChooserButton,
1287    /// GtkComboBox) implemented this property individually.
1288    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
1289        Self {
1290            builder: self.builder.property("focus-on-click", focus_on_click),
1291        }
1292    }
1293
1294    /// How to distribute horizontal space if widget gets extra space, see [`Align`][crate::Align]
1295    pub fn halign(self, halign: Align) -> Self {
1296        Self {
1297            builder: self.builder.property("halign", halign),
1298        }
1299    }
1300
1301    pub fn has_default(self, has_default: bool) -> Self {
1302        Self {
1303            builder: self.builder.property("has-default", has_default),
1304        }
1305    }
1306
1307    pub fn has_focus(self, has_focus: bool) -> Self {
1308        Self {
1309            builder: self.builder.property("has-focus", has_focus),
1310        }
1311    }
1312
1313    /// Enables or disables the emission of [`query-tooltip`][struct@crate::Widget#query-tooltip] on `widget`.
1314    /// A value of [`true`] indicates that `widget` can have a tooltip, in this case
1315    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to determine
1316    /// whether it will provide a tooltip or not.
1317    ///
1318    /// Note that setting this property to [`true`] for the first time will change
1319    /// the event masks of the GdkWindows of this widget to include leave-notify
1320    /// and motion-notify events. This cannot and will not be undone when the
1321    /// property is set to [`false`] again.
1322    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
1323        Self {
1324            builder: self.builder.property("has-tooltip", has_tooltip),
1325        }
1326    }
1327
1328    pub fn height_request(self, height_request: i32) -> Self {
1329        Self {
1330            builder: self.builder.property("height-request", height_request),
1331        }
1332    }
1333
1334    /// Whether to expand horizontally. See [`WidgetExt::set_hexpand()`][crate::prelude::WidgetExt::set_hexpand()].
1335    pub fn hexpand(self, hexpand: bool) -> Self {
1336        Self {
1337            builder: self.builder.property("hexpand", hexpand),
1338        }
1339    }
1340
1341    /// Whether to use the [`hexpand`][struct@crate::Widget#hexpand] property. See [`WidgetExt::is_hexpand_set()`][crate::prelude::WidgetExt::is_hexpand_set()].
1342    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
1343        Self {
1344            builder: self.builder.property("hexpand-set", hexpand_set),
1345        }
1346    }
1347
1348    pub fn is_focus(self, is_focus: bool) -> Self {
1349        Self {
1350            builder: self.builder.property("is-focus", is_focus),
1351        }
1352    }
1353
1354    /// Sets all four sides' margin at once. If read, returns max
1355    /// margin on any side.
1356    pub fn margin(self, margin: i32) -> Self {
1357        Self {
1358            builder: self.builder.property("margin", margin),
1359        }
1360    }
1361
1362    /// Margin on bottom side of widget.
1363    ///
1364    /// This property adds margin outside of the widget's normal size
1365    /// request, the margin will be added in addition to the size from
1366    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1367    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
1368        Self {
1369            builder: self.builder.property("margin-bottom", margin_bottom),
1370        }
1371    }
1372
1373    /// Margin on end of widget, horizontally. This property supports
1374    /// left-to-right and right-to-left text directions.
1375    ///
1376    /// This property adds margin outside of the widget's normal size
1377    /// request, the margin will be added in addition to the size from
1378    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1379    pub fn margin_end(self, margin_end: i32) -> Self {
1380        Self {
1381            builder: self.builder.property("margin-end", margin_end),
1382        }
1383    }
1384
1385    /// Margin on start of widget, horizontally. This property supports
1386    /// left-to-right and right-to-left text directions.
1387    ///
1388    /// This property adds margin outside of the widget's normal size
1389    /// request, the margin will be added in addition to the size from
1390    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1391    pub fn margin_start(self, margin_start: i32) -> Self {
1392        Self {
1393            builder: self.builder.property("margin-start", margin_start),
1394        }
1395    }
1396
1397    /// Margin on top side of widget.
1398    ///
1399    /// This property adds margin outside of the widget's normal size
1400    /// request, the margin will be added in addition to the size from
1401    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1402    pub fn margin_top(self, margin_top: i32) -> Self {
1403        Self {
1404            builder: self.builder.property("margin-top", margin_top),
1405        }
1406    }
1407
1408    pub fn name(self, name: impl Into<glib::GString>) -> Self {
1409        Self {
1410            builder: self.builder.property("name", name.into()),
1411        }
1412    }
1413
1414    pub fn no_show_all(self, no_show_all: bool) -> Self {
1415        Self {
1416            builder: self.builder.property("no-show-all", no_show_all),
1417        }
1418    }
1419
1420    /// The requested opacity of the widget. See [`WidgetExt::set_opacity()`][crate::prelude::WidgetExt::set_opacity()] for
1421    /// more details about window opacity.
1422    ///
1423    /// Before 3.8 this was only available in GtkWindow
1424    pub fn opacity(self, opacity: f64) -> Self {
1425        Self {
1426            builder: self.builder.property("opacity", opacity),
1427        }
1428    }
1429
1430    pub fn parent(self, parent: &impl IsA<Container>) -> Self {
1431        Self {
1432            builder: self.builder.property("parent", parent.clone().upcast()),
1433        }
1434    }
1435
1436    pub fn receives_default(self, receives_default: bool) -> Self {
1437        Self {
1438            builder: self.builder.property("receives-default", receives_default),
1439        }
1440    }
1441
1442    pub fn sensitive(self, sensitive: bool) -> Self {
1443        Self {
1444            builder: self.builder.property("sensitive", sensitive),
1445        }
1446    }
1447
1448    /// Sets the text of tooltip to be the given string, which is marked up
1449    /// with the [Pango text markup language][PangoMarkupFormat].
1450    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
1451    ///
1452    /// This is a convenience property which will take care of getting the
1453    /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
1454    /// will automatically be set to [`true`] and there will be taken care of
1455    /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
1456    ///
1457    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
1458    /// are set, the last one wins.
1459    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
1460        Self {
1461            builder: self
1462                .builder
1463                .property("tooltip-markup", tooltip_markup.into()),
1464        }
1465    }
1466
1467    /// Sets the text of tooltip to be the given string.
1468    ///
1469    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
1470    ///
1471    /// This is a convenience property which will take care of getting the
1472    /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
1473    /// will automatically be set to [`true`] and there will be taken care of
1474    /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
1475    ///
1476    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
1477    /// are set, the last one wins.
1478    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
1479        Self {
1480            builder: self.builder.property("tooltip-text", tooltip_text.into()),
1481        }
1482    }
1483
1484    /// How to distribute vertical space if widget gets extra space, see [`Align`][crate::Align]
1485    pub fn valign(self, valign: Align) -> Self {
1486        Self {
1487            builder: self.builder.property("valign", valign),
1488        }
1489    }
1490
1491    /// Whether to expand vertically. See [`WidgetExt::set_vexpand()`][crate::prelude::WidgetExt::set_vexpand()].
1492    pub fn vexpand(self, vexpand: bool) -> Self {
1493        Self {
1494            builder: self.builder.property("vexpand", vexpand),
1495        }
1496    }
1497
1498    /// Whether to use the [`vexpand`][struct@crate::Widget#vexpand] property. See [`WidgetExt::is_vexpand_set()`][crate::prelude::WidgetExt::is_vexpand_set()].
1499    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
1500        Self {
1501            builder: self.builder.property("vexpand-set", vexpand_set),
1502        }
1503    }
1504
1505    pub fn visible(self, visible: bool) -> Self {
1506        Self {
1507            builder: self.builder.property("visible", visible),
1508        }
1509    }
1510
1511    pub fn width_request(self, width_request: i32) -> Self {
1512        Self {
1513            builder: self.builder.property("width-request", width_request),
1514        }
1515    }
1516
1517    pub fn action_name(self, action_name: impl Into<glib::GString>) -> Self {
1518        Self {
1519            builder: self.builder.property("action-name", action_name.into()),
1520        }
1521    }
1522
1523    pub fn action_target(self, action_target: &glib::Variant) -> Self {
1524        Self {
1525            builder: self
1526                .builder
1527                .property("action-target", action_target.clone()),
1528        }
1529    }
1530
1531    // rustdoc-stripper-ignore-next
1532    /// Build the [`Switch`].
1533    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
1534    pub fn build(self) -> Switch {
1535        assert_initialized_main_thread!();
1536        self.builder.build()
1537    }
1538}
1539
1540/// Trait containing all [`struct@Switch`] methods.
1541///
1542/// # Implementors
1543///
1544/// [`Switch`][struct@crate::Switch]
1545pub trait SwitchExt: IsA<Switch> + 'static {
1546    /// Gets whether the [`Switch`][crate::Switch] is in its “on” or “off” state.
1547    ///
1548    /// # Returns
1549    ///
1550    /// [`true`] if the [`Switch`][crate::Switch] is active, and [`false`] otherwise
1551    #[doc(alias = "gtk_switch_get_active")]
1552    #[doc(alias = "get_active")]
1553    #[doc(alias = "active")]
1554    fn is_active(&self) -> bool {
1555        unsafe { from_glib(ffi::gtk_switch_get_active(self.as_ref().to_glib_none().0)) }
1556    }
1557
1558    /// Gets the underlying state of the [`Switch`][crate::Switch].
1559    ///
1560    /// # Returns
1561    ///
1562    /// the underlying state
1563    #[doc(alias = "gtk_switch_get_state")]
1564    #[doc(alias = "get_state")]
1565    fn state(&self) -> bool {
1566        unsafe { from_glib(ffi::gtk_switch_get_state(self.as_ref().to_glib_none().0)) }
1567    }
1568
1569    /// Changes the state of `self` to the desired one.
1570    /// ## `is_active`
1571    /// [`true`] if `self` should be active, and [`false`] otherwise
1572    #[doc(alias = "gtk_switch_set_active")]
1573    #[doc(alias = "active")]
1574    fn set_active(&self, is_active: bool) {
1575        unsafe {
1576            ffi::gtk_switch_set_active(self.as_ref().to_glib_none().0, is_active.into_glib());
1577        }
1578    }
1579
1580    /// Sets the underlying state of the [`Switch`][crate::Switch].
1581    ///
1582    /// Normally, this is the same as [`active`][struct@crate::Switch#active], unless the switch
1583    /// is set up for delayed state changes. This function is typically
1584    /// called from a [`state-set`][struct@crate::Switch#state-set] signal handler.
1585    ///
1586    /// See [`state-set`][struct@crate::Switch#state-set] for details.
1587    /// ## `state`
1588    /// the new state
1589    #[doc(alias = "gtk_switch_set_state")]
1590    #[doc(alias = "state")]
1591    fn set_state(&self, state: bool) {
1592        unsafe {
1593            ffi::gtk_switch_set_state(self.as_ref().to_glib_none().0, state.into_glib());
1594        }
1595    }
1596
1597    /// The ::activate signal on GtkSwitch is an action signal and
1598    /// emitting it causes the switch to animate.
1599    /// Applications should never connect to this signal, but use the
1600    /// notify::active signal.
1601    #[doc(alias = "activate")]
1602    fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1603        unsafe extern "C" fn activate_trampoline<P: IsA<Switch>, F: Fn(&P) + 'static>(
1604            this: *mut ffi::GtkSwitch,
1605            f: glib::ffi::gpointer,
1606        ) {
1607            unsafe {
1608                let f: &F = &*(f as *const F);
1609                f(Switch::from_glib_borrow(this).unsafe_cast_ref())
1610            }
1611        }
1612        unsafe {
1613            let f: Box_<F> = Box_::new(f);
1614            connect_raw(
1615                self.as_ptr() as *mut _,
1616                c"activate".as_ptr(),
1617                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1618                    activate_trampoline::<Self, F> as *const (),
1619                )),
1620                Box_::into_raw(f),
1621            )
1622        }
1623    }
1624
1625    fn emit_activate(&self) {
1626        self.emit_by_name::<()>("activate", &[]);
1627    }
1628
1629    /// The ::state-set signal on GtkSwitch is emitted to change the underlying
1630    /// state. It is emitted when the user changes the switch position. The
1631    /// default handler keeps the state in sync with the [`active`][struct@crate::Switch#active]
1632    /// property.
1633    ///
1634    /// To implement delayed state change, applications can connect to this signal,
1635    /// initiate the change of the underlying state, and call [`set_state()`][Self::set_state()]
1636    /// when the underlying state change is complete. The signal handler should
1637    /// return [`true`] to prevent the default handler from running.
1638    ///
1639    /// Visually, the underlying state is represented by the trough color of
1640    /// the switch, while the [`active`][struct@crate::Switch#active] property is represented by the
1641    /// position of the switch.
1642    /// ## `state`
1643    /// the new state of the switch
1644    ///
1645    /// # Returns
1646    ///
1647    /// [`true`] to stop the signal emission
1648    #[doc(alias = "state-set")]
1649    fn connect_state_set<F: Fn(&Self, bool) -> glib::Propagation + 'static>(
1650        &self,
1651        f: F,
1652    ) -> SignalHandlerId {
1653        unsafe extern "C" fn state_set_trampoline<
1654            P: IsA<Switch>,
1655            F: Fn(&P, bool) -> glib::Propagation + 'static,
1656        >(
1657            this: *mut ffi::GtkSwitch,
1658            state: glib::ffi::gboolean,
1659            f: glib::ffi::gpointer,
1660        ) -> glib::ffi::gboolean {
1661            unsafe {
1662                let f: &F = &*(f as *const F);
1663                f(
1664                    Switch::from_glib_borrow(this).unsafe_cast_ref(),
1665                    from_glib(state),
1666                )
1667                .into_glib()
1668            }
1669        }
1670        unsafe {
1671            let f: Box_<F> = Box_::new(f);
1672            connect_raw(
1673                self.as_ptr() as *mut _,
1674                c"state-set".as_ptr(),
1675                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1676                    state_set_trampoline::<Self, F> as *const (),
1677                )),
1678                Box_::into_raw(f),
1679            )
1680        }
1681    }
1682
1683    #[doc(alias = "active")]
1684    fn connect_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1685        unsafe extern "C" fn notify_active_trampoline<P: IsA<Switch>, F: Fn(&P) + 'static>(
1686            this: *mut ffi::GtkSwitch,
1687            _param_spec: glib::ffi::gpointer,
1688            f: glib::ffi::gpointer,
1689        ) {
1690            unsafe {
1691                let f: &F = &*(f as *const F);
1692                f(Switch::from_glib_borrow(this).unsafe_cast_ref())
1693            }
1694        }
1695        unsafe {
1696            let f: Box_<F> = Box_::new(f);
1697            connect_raw(
1698                self.as_ptr() as *mut _,
1699                c"notify::active".as_ptr(),
1700                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1701                    notify_active_trampoline::<Self, F> as *const (),
1702                )),
1703                Box_::into_raw(f),
1704            )
1705        }
1706    }
1707
1708    #[doc(alias = "state")]
1709    fn connect_state_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1710        unsafe extern "C" fn notify_state_trampoline<P: IsA<Switch>, F: Fn(&P) + 'static>(
1711            this: *mut ffi::GtkSwitch,
1712            _param_spec: glib::ffi::gpointer,
1713            f: glib::ffi::gpointer,
1714        ) {
1715            unsafe {
1716                let f: &F = &*(f as *const F);
1717                f(Switch::from_glib_borrow(this).unsafe_cast_ref())
1718            }
1719        }
1720        unsafe {
1721            let f: Box_<F> = Box_::new(f);
1722            connect_raw(
1723                self.as_ptr() as *mut _,
1724                c"notify::state".as_ptr(),
1725                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1726                    notify_state_trampoline::<Self, F> as *const (),
1727                )),
1728                Box_::into_raw(f),
1729            )
1730        }
1731    }
1732}
1733
1734impl<O: IsA<Switch>> SwitchExt for O {}