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