Skip to main content

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