gtk4/auto/
actionable.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::{ffi, Accessible, Buildable, ConstraintTarget, Widget};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    /// The [`Actionable`][crate::Actionable] interface provides a convenient way of associating
15    /// widgets with actions.
16    ///
17    /// It primarily consists of two properties: [`action-name`][struct@crate::Actionable#action-name]
18    /// and [`action-target`][struct@crate::Actionable#action-target]. There are also some convenience
19    /// APIs for setting these properties.
20    ///
21    /// The action will be looked up in action groups that are found among
22    /// the widgets ancestors. Most commonly, these will be the actions with
23    /// the “win.” or “app.” prefix that are associated with the
24    /// [`ApplicationWindow`][crate::ApplicationWindow] or [`Application`][crate::Application], but other action groups that
25    /// are added with [`WidgetExt::insert_action_group()`][crate::prelude::WidgetExt::insert_action_group()] will be consulted
26    /// as well.
27    ///
28    /// ## Properties
29    ///
30    ///
31    /// #### `action-name`
32    ///  The name of the action with which this widget should be associated.
33    ///
34    /// Readable | Writeable
35    ///
36    ///
37    /// #### `action-target`
38    ///  The target value of the actionable widget's action.
39    ///
40    /// Readable | Writeable
41    /// <details><summary><h4>Widget</h4></summary>
42    ///
43    ///
44    /// #### `can-focus`
45    ///  Whether the widget or any of its descendents can accept
46    /// the input focus.
47    ///
48    /// This property is meant to be set by widget implementations,
49    /// typically in their instance init function.
50    ///
51    /// Readable | Writeable
52    ///
53    ///
54    /// #### `can-target`
55    ///  Whether the widget can receive pointer events.
56    ///
57    /// Readable | Writeable
58    ///
59    ///
60    /// #### `css-classes`
61    ///  A list of css classes applied to this widget.
62    ///
63    /// Readable | Writeable
64    ///
65    ///
66    /// #### `css-name`
67    ///  The name of this widget in the CSS tree.
68    ///
69    /// This property is meant to be set by widget implementations,
70    /// typically in their instance init function.
71    ///
72    /// Readable | Writeable | Construct Only
73    ///
74    ///
75    /// #### `cursor`
76    ///  The cursor used by @widget.
77    ///
78    /// Readable | Writeable
79    ///
80    ///
81    /// #### `focus-on-click`
82    ///  Whether the widget should grab focus when it is clicked with the mouse.
83    ///
84    /// This property is only relevant for widgets that can take focus.
85    ///
86    /// Readable | Writeable
87    ///
88    ///
89    /// #### `focusable`
90    ///  Whether this widget itself will accept the input focus.
91    ///
92    /// Readable | Writeable
93    ///
94    ///
95    /// #### `halign`
96    ///  How to distribute horizontal space if widget gets extra space.
97    ///
98    /// Readable | Writeable
99    ///
100    ///
101    /// #### `has-default`
102    ///  Whether the widget is the default widget.
103    ///
104    /// Readable
105    ///
106    ///
107    /// #### `has-focus`
108    ///  Whether the widget has the input focus.
109    ///
110    /// Readable
111    ///
112    ///
113    /// #### `has-tooltip`
114    ///  Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
115    /// signal on @widget.
116    ///
117    /// A true value indicates that @widget can have a tooltip, in this case
118    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
119    /// determine whether it will provide a tooltip or not.
120    ///
121    /// Readable | Writeable
122    ///
123    ///
124    /// #### `height-request`
125    ///  Overrides for height request of the widget.
126    ///
127    /// If this is -1, the natural request will be used.
128    ///
129    /// Readable | Writeable
130    ///
131    ///
132    /// #### `hexpand`
133    ///  Whether to expand horizontally.
134    ///
135    /// Readable | Writeable
136    ///
137    ///
138    /// #### `hexpand-set`
139    ///  Whether to use the `hexpand` property.
140    ///
141    /// Readable | Writeable
142    ///
143    ///
144    /// #### `layout-manager`
145    ///  The [`LayoutManager`][crate::LayoutManager] instance to use to compute
146    /// the preferred size of the widget, and allocate its children.
147    ///
148    /// This property is meant to be set by widget implementations,
149    /// typically in their instance init function.
150    ///
151    /// Readable | Writeable
152    ///
153    ///
154    /// #### `limit-events`
155    ///  Makes this widget act like a modal dialog, with respect to
156    /// event delivery.
157    ///
158    /// Global event controllers will not handle events with targets
159    /// inside the widget, unless they are set up to ignore propagation
160    /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
161    ///
162    /// Readable | Writeable
163    ///
164    ///
165    /// #### `margin-bottom`
166    ///  Margin on bottom side of widget.
167    ///
168    /// This property adds margin outside of the widget's normal size
169    /// request, the margin will be added in addition to the size from
170    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
171    ///
172    /// Readable | Writeable
173    ///
174    ///
175    /// #### `margin-end`
176    ///  Margin on end of widget, horizontally.
177    ///
178    /// This property supports left-to-right and right-to-left text
179    /// directions.
180    ///
181    /// This property adds margin outside of the widget's normal size
182    /// request, the margin will be added in addition to the size from
183    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
184    ///
185    /// Readable | Writeable
186    ///
187    ///
188    /// #### `margin-start`
189    ///  Margin on start of widget, horizontally.
190    ///
191    /// This property supports left-to-right and right-to-left text
192    /// directions.
193    ///
194    /// This property adds margin outside of the widget's normal size
195    /// request, the margin will be added in addition to the size from
196    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
197    ///
198    /// Readable | Writeable
199    ///
200    ///
201    /// #### `margin-top`
202    ///  Margin on top side of widget.
203    ///
204    /// This property adds margin outside of the widget's normal size
205    /// request, the margin will be added in addition to the size from
206    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
207    ///
208    /// Readable | Writeable
209    ///
210    ///
211    /// #### `name`
212    ///  The name of the widget.
213    ///
214    /// Readable | Writeable
215    ///
216    ///
217    /// #### `opacity`
218    ///  The requested opacity of the widget.
219    ///
220    /// Readable | Writeable
221    ///
222    ///
223    /// #### `overflow`
224    ///  How content outside the widget's content area is treated.
225    ///
226    /// This property is meant to be set by widget implementations,
227    /// typically in their instance init function.
228    ///
229    /// Readable | Writeable
230    ///
231    ///
232    /// #### `parent`
233    ///  The parent widget of this widget.
234    ///
235    /// Readable
236    ///
237    ///
238    /// #### `receives-default`
239    ///  Whether the widget will receive the default action when it is focused.
240    ///
241    /// Readable | Writeable
242    ///
243    ///
244    /// #### `root`
245    ///  The [`Root`][crate::Root] widget of the widget tree containing this widget.
246    ///
247    /// This will be `NULL` if the widget is not contained in a root widget.
248    ///
249    /// Readable
250    ///
251    ///
252    /// #### `scale-factor`
253    ///  The scale factor of the widget.
254    ///
255    /// Readable
256    ///
257    ///
258    /// #### `sensitive`
259    ///  Whether the widget responds to input.
260    ///
261    /// Readable | Writeable
262    ///
263    ///
264    /// #### `tooltip-markup`
265    ///  Sets the text of tooltip to be the given string, which is marked up
266    /// with Pango markup.
267    ///
268    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
269    ///
270    /// This is a convenience property which will take care of getting the
271    /// tooltip shown if the given string is not `NULL`:
272    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
273    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
274    /// the default signal handler.
275    ///
276    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
277    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
278    ///
279    /// Readable | Writeable
280    ///
281    ///
282    /// #### `tooltip-text`
283    ///  Sets the text of tooltip to be the given string.
284    ///
285    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
286    ///
287    /// This is a convenience property which will take care of getting the
288    /// tooltip shown if the given string is not `NULL`:
289    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
290    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
291    /// the default signal handler.
292    ///
293    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
294    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
295    ///
296    /// Readable | Writeable
297    ///
298    ///
299    /// #### `valign`
300    ///  How to distribute vertical space if widget gets extra space.
301    ///
302    /// Readable | Writeable
303    ///
304    ///
305    /// #### `vexpand`
306    ///  Whether to expand vertically.
307    ///
308    /// Readable | Writeable
309    ///
310    ///
311    /// #### `vexpand-set`
312    ///  Whether to use the `vexpand` property.
313    ///
314    /// Readable | Writeable
315    ///
316    ///
317    /// #### `visible`
318    ///  Whether the widget is visible.
319    ///
320    /// Readable | Writeable
321    ///
322    ///
323    /// #### `width-request`
324    ///  Overrides for width request of the widget.
325    ///
326    /// If this is -1, the natural request will be used.
327    ///
328    /// Readable | Writeable
329    /// </details>
330    /// <details><summary><h4>Accessible</h4></summary>
331    ///
332    ///
333    /// #### `accessible-role`
334    ///  The accessible role of the given [`Accessible`][crate::Accessible] implementation.
335    ///
336    /// The accessible role cannot be changed once set.
337    ///
338    /// Readable | Writeable
339    /// </details>
340    ///
341    /// # Implements
342    ///
343    /// [`ActionableExt`][trait@crate::prelude::ActionableExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`AccessibleExt`][trait@crate::prelude::AccessibleExt], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ConstraintTargetExt`][trait@crate::prelude::ConstraintTargetExt], [`ActionableExtManual`][trait@crate::prelude::ActionableExtManual], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`AccessibleExtManual`][trait@crate::prelude::AccessibleExtManual]
344    #[doc(alias = "GtkActionable")]
345    pub struct Actionable(Interface<ffi::GtkActionable, ffi::GtkActionableInterface>) @requires Widget, Accessible, Buildable, ConstraintTarget;
346
347    match fn {
348        type_ => || ffi::gtk_actionable_get_type(),
349    }
350}
351
352impl Actionable {
353    pub const NONE: Option<&'static Actionable> = None;
354}
355
356mod sealed {
357    pub trait Sealed {}
358    impl<T: super::IsA<super::Actionable>> Sealed for T {}
359}
360
361/// Trait containing all [`struct@Actionable`] methods.
362///
363/// # Implementors
364///
365/// [`Actionable`][struct@crate::Actionable], [`Button`][struct@crate::Button], [`CheckButton`][struct@crate::CheckButton], [`LinkButton`][struct@crate::LinkButton], [`ListBoxRow`][struct@crate::ListBoxRow], [`LockButton`][struct@crate::LockButton], [`Switch`][struct@crate::Switch], [`ToggleButton`][struct@crate::ToggleButton]
366pub trait ActionableExt: IsA<Actionable> + sealed::Sealed + 'static {
367    /// Gets the action name for @self.
368    ///
369    /// # Returns
370    ///
371    /// the action name
372    #[doc(alias = "gtk_actionable_get_action_name")]
373    #[doc(alias = "get_action_name")]
374    #[doc(alias = "action-name")]
375    fn action_name(&self) -> Option<glib::GString> {
376        unsafe {
377            from_glib_none(ffi::gtk_actionable_get_action_name(
378                self.as_ref().to_glib_none().0,
379            ))
380        }
381    }
382
383    /// Gets the current target value of @self.
384    ///
385    /// # Returns
386    ///
387    /// the current target value
388    #[doc(alias = "gtk_actionable_get_action_target_value")]
389    #[doc(alias = "get_action_target_value")]
390    #[doc(alias = "action-target")]
391    fn action_target_value(&self) -> Option<glib::Variant> {
392        unsafe {
393            from_glib_none(ffi::gtk_actionable_get_action_target_value(
394                self.as_ref().to_glib_none().0,
395            ))
396        }
397    }
398
399    /// Specifies the name of the action with which this widget should be
400    /// associated.
401    ///
402    /// If @action_name is [`None`] then the widget will be unassociated from
403    /// any previous action.
404    ///
405    /// Usually this function is used when the widget is located (or will be
406    /// located) within the hierarchy of a [`ApplicationWindow`][crate::ApplicationWindow].
407    ///
408    /// Names are of the form “win.save” or “app.quit” for actions on the
409    /// containing [`ApplicationWindow`][crate::ApplicationWindow] or its associated [`Application`][crate::Application],
410    /// respectively. This is the same form used for actions in the [`gio::Menu`][crate::gio::Menu]
411    /// associated with the window.
412    /// ## `action_name`
413    /// an action name
414    #[doc(alias = "gtk_actionable_set_action_name")]
415    #[doc(alias = "action-name")]
416    fn set_action_name(&self, action_name: Option<&str>) {
417        unsafe {
418            ffi::gtk_actionable_set_action_name(
419                self.as_ref().to_glib_none().0,
420                action_name.to_glib_none().0,
421            );
422        }
423    }
424
425    /// Sets the target value of an actionable widget.
426    ///
427    /// If @target_value is [`None`] then the target value is unset.
428    ///
429    /// The target value has two purposes. First, it is used as the parameter
430    /// to activation of the action associated with the [`Actionable`][crate::Actionable] widget.
431    /// Second, it is used to determine if the widget should be rendered as
432    /// “active” — the widget is active if the state is equal to the given target.
433    ///
434    /// Consider the example of associating a set of buttons with a [`gio::Action`][crate::gio::Action]
435    /// with string state in a typical “radio button” situation. Each button
436    /// will be associated with the same action, but with a different target
437    /// value for that action. Clicking on a particular button will activate
438    /// the action with the target of that button, which will typically cause
439    /// the action’s state to change to that value. Since the action’s state
440    /// is now equal to the target value of the button, the button will now
441    /// be rendered as active (and the other buttons, with different targets,
442    /// rendered inactive).
443    /// ## `target_value`
444    /// a [`glib::Variant`][struct@crate::glib::Variant] to set as the target value
445    #[doc(alias = "gtk_actionable_set_action_target_value")]
446    #[doc(alias = "action-target")]
447    fn set_action_target_value(&self, target_value: Option<&glib::Variant>) {
448        unsafe {
449            ffi::gtk_actionable_set_action_target_value(
450                self.as_ref().to_glib_none().0,
451                target_value.to_glib_none().0,
452            );
453        }
454    }
455
456    /// Sets the action-name and associated string target value of an
457    /// actionable widget.
458    ///
459    /// @detailed_action_name is a string in the format accepted by
460    /// [`gio::Action::parse_detailed_name()`][crate::gio::Action::parse_detailed_name()].
461    /// ## `detailed_action_name`
462    /// the detailed action name
463    #[doc(alias = "gtk_actionable_set_detailed_action_name")]
464    fn set_detailed_action_name(&self, detailed_action_name: &str) {
465        unsafe {
466            ffi::gtk_actionable_set_detailed_action_name(
467                self.as_ref().to_glib_none().0,
468                detailed_action_name.to_glib_none().0,
469            );
470        }
471    }
472
473    #[doc(alias = "action-name")]
474    fn connect_action_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
475        unsafe extern "C" fn notify_action_name_trampoline<
476            P: IsA<Actionable>,
477            F: Fn(&P) + 'static,
478        >(
479            this: *mut ffi::GtkActionable,
480            _param_spec: glib::ffi::gpointer,
481            f: glib::ffi::gpointer,
482        ) {
483            let f: &F = &*(f as *const F);
484            f(Actionable::from_glib_borrow(this).unsafe_cast_ref())
485        }
486        unsafe {
487            let f: Box_<F> = Box_::new(f);
488            connect_raw(
489                self.as_ptr() as *mut _,
490                b"notify::action-name\0".as_ptr() as *const _,
491                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
492                    notify_action_name_trampoline::<Self, F> as *const (),
493                )),
494                Box_::into_raw(f),
495            )
496        }
497    }
498
499    #[doc(alias = "action-target")]
500    fn connect_action_target_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
501        unsafe extern "C" fn notify_action_target_trampoline<
502            P: IsA<Actionable>,
503            F: Fn(&P) + 'static,
504        >(
505            this: *mut ffi::GtkActionable,
506            _param_spec: glib::ffi::gpointer,
507            f: glib::ffi::gpointer,
508        ) {
509            let f: &F = &*(f as *const F);
510            f(Actionable::from_glib_borrow(this).unsafe_cast_ref())
511        }
512        unsafe {
513            let f: Box_<F> = Box_::new(f);
514            connect_raw(
515                self.as_ptr() as *mut _,
516                b"notify::action-target\0".as_ptr() as *const _,
517                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
518                    notify_action_target_trampoline::<Self, F> as *const (),
519                )),
520                Box_::into_raw(f),
521            )
522        }
523    }
524}
525
526impl<O: IsA<Actionable>> ActionableExt for O {}