Skip to main content

gtk/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::{Buildable, Widget, ffi};
6use glib::{
7    prelude::*,
8    signal::{SignalHandlerId, connect_raw},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    /// This interface provides a convenient way of associating widgets with
15    /// actions on a [`ApplicationWindow`][crate::ApplicationWindow] or [`Application`][crate::Application].
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 APIs
19    /// 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 [`ApplicationWindow`][crate::ApplicationWindow]
24    /// or [`Application`][crate::Application], but other action groups that are added with
25    /// [`WidgetExt::insert_action_group()`][crate::prelude::WidgetExt::insert_action_group()] will be consulted as well.
26    ///
27    /// ## Properties
28    ///
29    ///
30    /// #### `action-name`
31    ///  Readable | Writable
32    ///
33    ///
34    /// #### `action-target`
35    ///  Readable | Writable
36    /// <details><summary><h4>Widget</h4></summary>
37    ///
38    ///
39    /// #### `app-paintable`
40    ///  Readable | Writable
41    ///
42    ///
43    /// #### `can-default`
44    ///  Readable | Writable
45    ///
46    ///
47    /// #### `can-focus`
48    ///  Readable | Writable
49    ///
50    ///
51    /// #### `composite-child`
52    ///  Readable
53    ///
54    ///
55    /// #### `double-buffered`
56    ///  Whether the widget is double buffered.
57    ///
58    /// Readable | Writable
59    ///
60    ///
61    /// #### `events`
62    ///  Readable | Writable
63    ///
64    ///
65    /// #### `expand`
66    ///  Whether to expand in both directions. Setting this sets both [`hexpand`][struct@crate::Widget#hexpand] and [`vexpand`][struct@crate::Widget#vexpand]
67    ///
68    /// Readable | Writable
69    ///
70    ///
71    /// #### `focus-on-click`
72    ///  Whether the widget should grab focus when it is clicked with the mouse.
73    ///
74    /// This property is only relevant for widgets that can take focus.
75    ///
76    /// Before 3.20, several widgets (GtkButton, GtkFileChooserButton,
77    /// GtkComboBox) implemented this property individually.
78    ///
79    /// Readable | Writable
80    ///
81    ///
82    /// #### `halign`
83    ///  How to distribute horizontal space if widget gets extra space, see [`Align`][crate::Align]
84    ///
85    /// Readable | Writable
86    ///
87    ///
88    /// #### `has-default`
89    ///  Readable | Writable
90    ///
91    ///
92    /// #### `has-focus`
93    ///  Readable | Writable
94    ///
95    ///
96    /// #### `has-tooltip`
97    ///  Enables or disables the emission of [`query-tooltip`][struct@crate::Widget#query-tooltip] on `widget`.
98    /// A value of [`true`] indicates that `widget` can have a tooltip, in this case
99    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to determine
100    /// whether it will provide a tooltip or not.
101    ///
102    /// Note that setting this property to [`true`] for the first time will change
103    /// the event masks of the GdkWindows of this widget to include leave-notify
104    /// and motion-notify events. This cannot and will not be undone when the
105    /// property is set to [`false`] again.
106    ///
107    /// Readable | Writable
108    ///
109    ///
110    /// #### `height-request`
111    ///  Readable | Writable
112    ///
113    ///
114    /// #### `hexpand`
115    ///  Whether to expand horizontally. See [`WidgetExt::set_hexpand()`][crate::prelude::WidgetExt::set_hexpand()].
116    ///
117    /// Readable | Writable
118    ///
119    ///
120    /// #### `hexpand-set`
121    ///  Whether to use the [`hexpand`][struct@crate::Widget#hexpand] property. See [`WidgetExt::is_hexpand_set()`][crate::prelude::WidgetExt::is_hexpand_set()].
122    ///
123    /// Readable | Writable
124    ///
125    ///
126    /// #### `is-focus`
127    ///  Readable | Writable
128    ///
129    ///
130    /// #### `margin`
131    ///  Sets all four sides' margin at once. If read, returns max
132    /// margin on any side.
133    ///
134    /// Readable | Writable
135    ///
136    ///
137    /// #### `margin-bottom`
138    ///  Margin on bottom side of widget.
139    ///
140    /// This property adds margin outside of the widget's normal size
141    /// request, the margin will be added in addition to the size from
142    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
143    ///
144    /// Readable | Writable
145    ///
146    ///
147    /// #### `margin-end`
148    ///  Margin on end of widget, horizontally. This property supports
149    /// left-to-right and right-to-left text directions.
150    ///
151    /// This property adds margin outside of the widget's normal size
152    /// request, the margin will be added in addition to the size from
153    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
154    ///
155    /// Readable | Writable
156    ///
157    ///
158    /// #### `margin-left`
159    ///  Margin on left side of widget.
160    ///
161    /// This property adds margin outside of the widget's normal size
162    /// request, the margin will be added in addition to the size from
163    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
164    ///
165    /// Readable | Writable
166    ///
167    ///
168    /// #### `margin-right`
169    ///  Margin on right side of widget.
170    ///
171    /// This property adds margin outside of the widget's normal size
172    /// request, the margin will be added in addition to the size from
173    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
174    ///
175    /// Readable | Writable
176    ///
177    ///
178    /// #### `margin-start`
179    ///  Margin on start of widget, horizontally. This property supports
180    /// left-to-right and right-to-left text directions.
181    ///
182    /// This property adds margin outside of the widget's normal size
183    /// request, the margin will be added in addition to the size from
184    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
185    ///
186    /// Readable | Writable
187    ///
188    ///
189    /// #### `margin-top`
190    ///  Margin on top side of widget.
191    ///
192    /// This property adds margin outside of the widget's normal size
193    /// request, the margin will be added in addition to the size from
194    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
195    ///
196    /// Readable | Writable
197    ///
198    ///
199    /// #### `name`
200    ///  Readable | Writable
201    ///
202    ///
203    /// #### `no-show-all`
204    ///  Readable | Writable
205    ///
206    ///
207    /// #### `opacity`
208    ///  The requested opacity of the widget. See [`WidgetExt::set_opacity()`][crate::prelude::WidgetExt::set_opacity()] for
209    /// more details about window opacity.
210    ///
211    /// Before 3.8 this was only available in GtkWindow
212    ///
213    /// Readable | Writable
214    ///
215    ///
216    /// #### `parent`
217    ///  Readable | Writable
218    ///
219    ///
220    /// #### `receives-default`
221    ///  Readable | Writable
222    ///
223    ///
224    /// #### `scale-factor`
225    ///  The scale factor of the widget. See [`WidgetExt::scale_factor()`][crate::prelude::WidgetExt::scale_factor()] for
226    /// more details about widget scaling.
227    ///
228    /// Readable
229    ///
230    ///
231    /// #### `sensitive`
232    ///  Readable | Writable
233    ///
234    ///
235    /// #### `style`
236    ///  The style of the widget, which contains information about how it will look (colors, etc).
237    ///
238    /// Readable | Writable
239    ///
240    ///
241    /// #### `tooltip-markup`
242    ///  Sets the text of tooltip to be the given string, which is marked up
243    /// with the [Pango text markup language][PangoMarkupFormat].
244    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
245    ///
246    /// This is a convenience property which will take care of getting the
247    /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
248    /// will automatically be set to [`true`] and there will be taken care of
249    /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
250    ///
251    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
252    /// are set, the last one wins.
253    ///
254    /// Readable | Writable
255    ///
256    ///
257    /// #### `tooltip-text`
258    ///  Sets the text of tooltip to be the given string.
259    ///
260    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
261    ///
262    /// This is a convenience property which will take care of getting the
263    /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
264    /// will automatically be set to [`true`] and there will be taken care of
265    /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
266    ///
267    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
268    /// are set, the last one wins.
269    ///
270    /// Readable | Writable
271    ///
272    ///
273    /// #### `valign`
274    ///  How to distribute vertical space if widget gets extra space, see [`Align`][crate::Align]
275    ///
276    /// Readable | Writable
277    ///
278    ///
279    /// #### `vexpand`
280    ///  Whether to expand vertically. See [`WidgetExt::set_vexpand()`][crate::prelude::WidgetExt::set_vexpand()].
281    ///
282    /// Readable | Writable
283    ///
284    ///
285    /// #### `vexpand-set`
286    ///  Whether to use the [`vexpand`][struct@crate::Widget#vexpand] property. See [`WidgetExt::is_vexpand_set()`][crate::prelude::WidgetExt::is_vexpand_set()].
287    ///
288    /// Readable | Writable
289    ///
290    ///
291    /// #### `visible`
292    ///  Readable | Writable
293    ///
294    ///
295    /// #### `width-request`
296    ///  Readable | Writable
297    ///
298    ///
299    /// #### `window`
300    ///  The widget's window if it is realized, [`None`] otherwise.
301    ///
302    /// Readable
303    /// </details>
304    ///
305    /// # Implements
306    ///
307    /// [`ActionableExt`][trait@crate::prelude::ActionableExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`BuildableExtManual`][trait@crate::prelude::BuildableExtManual]
308    #[doc(alias = "GtkActionable")]
309    pub struct Actionable(Interface<ffi::GtkActionable, ffi::GtkActionableInterface>) @requires Widget, Buildable;
310
311    match fn {
312        type_ => || ffi::gtk_actionable_get_type(),
313    }
314}
315
316impl Actionable {
317    pub const NONE: Option<&'static Actionable> = None;
318}
319
320/// Trait containing all [`struct@Actionable`] methods.
321///
322/// # Implementors
323///
324/// [`Actionable`][struct@crate::Actionable], [`Button`][struct@crate::Button], [`CheckButton`][struct@crate::CheckButton], [`CheckMenuItem`][struct@crate::CheckMenuItem], [`ColorButton`][struct@crate::ColorButton], [`FontButton`][struct@crate::FontButton], [`LinkButton`][struct@crate::LinkButton], [`ListBoxRow`][struct@crate::ListBoxRow], [`LockButton`][struct@crate::LockButton], [`MenuButton`][struct@crate::MenuButton], [`MenuItem`][struct@crate::MenuItem], [`MenuToolButton`][struct@crate::MenuToolButton], [`ModelButton`][struct@crate::ModelButton], [`RadioButton`][struct@crate::RadioButton], [`RadioMenuItem`][struct@crate::RadioMenuItem], [`RadioToolButton`][struct@crate::RadioToolButton], [`ScaleButton`][struct@crate::ScaleButton], [`SeparatorMenuItem`][struct@crate::SeparatorMenuItem], [`Switch`][struct@crate::Switch], [`ToggleButton`][struct@crate::ToggleButton], [`ToggleToolButton`][struct@crate::ToggleToolButton], [`ToolButton`][struct@crate::ToolButton], [`VolumeButton`][struct@crate::VolumeButton]
325pub trait ActionableExt: IsA<Actionable> + 'static {
326    /// Gets the action name for `self`.
327    ///
328    /// See [`set_action_name()`][Self::set_action_name()] for more information.
329    ///
330    /// # Returns
331    ///
332    /// the action name, or [`None`] if none is set
333    #[doc(alias = "gtk_actionable_get_action_name")]
334    #[doc(alias = "get_action_name")]
335    #[doc(alias = "action-name")]
336    fn action_name(&self) -> Option<glib::GString> {
337        unsafe {
338            from_glib_none(ffi::gtk_actionable_get_action_name(
339                self.as_ref().to_glib_none().0,
340            ))
341        }
342    }
343
344    /// Gets the current target value of `self`.
345    ///
346    /// See [`set_action_target_value()`][Self::set_action_target_value()] for more information.
347    ///
348    /// # Returns
349    ///
350    /// the current target value
351    #[doc(alias = "gtk_actionable_get_action_target_value")]
352    #[doc(alias = "get_action_target_value")]
353    fn action_target_value(&self) -> Option<glib::Variant> {
354        unsafe {
355            from_glib_none(ffi::gtk_actionable_get_action_target_value(
356                self.as_ref().to_glib_none().0,
357            ))
358        }
359    }
360
361    /// Specifies the name of the action with which this widget should be
362    /// associated. If `action_name` is [`None`] then the widget will be
363    /// unassociated from any previous action.
364    ///
365    /// Usually this function is used when the widget is located (or will be
366    /// located) within the hierarchy of a [`ApplicationWindow`][crate::ApplicationWindow].
367    ///
368    /// Names are of the form “win.save” or “app.quit” for actions on the
369    /// containing [`ApplicationWindow`][crate::ApplicationWindow] or its associated [`Application`][crate::Application],
370    /// respectively. This is the same form used for actions in the [`gio::Menu`][crate::gio::Menu]
371    /// associated with the window.
372    /// ## `action_name`
373    /// an action name, or [`None`]
374    #[doc(alias = "gtk_actionable_set_action_name")]
375    #[doc(alias = "action-name")]
376    fn set_action_name(&self, action_name: Option<&str>) {
377        unsafe {
378            ffi::gtk_actionable_set_action_name(
379                self.as_ref().to_glib_none().0,
380                action_name.to_glib_none().0,
381            );
382        }
383    }
384
385    //#[doc(alias = "gtk_actionable_set_action_target")]
386    //#[doc(alias = "action-target")]
387    //fn set_action_target(&self, format_string: &str, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) {
388    //    unsafe { TODO: call ffi:gtk_actionable_set_action_target() }
389    //}
390
391    /// Sets the target value of an actionable widget.
392    ///
393    /// If `target_value` is [`None`] then the target value is unset.
394    ///
395    /// The target value has two purposes. First, it is used as the
396    /// parameter to activation of the action associated with the
397    /// [`Actionable`][crate::Actionable] widget. Second, it is used to determine if the widget
398    /// should be rendered as “active” — the widget is active if the state
399    /// is equal to the given target.
400    ///
401    /// Consider the example of associating a set of buttons with a `GAction`
402    /// with string state in a typical “radio button” situation. Each button
403    /// will be associated with the same action, but with a different target
404    /// value for that action. Clicking on a particular button will activate
405    /// the action with the target of that button, which will typically cause
406    /// the action’s state to change to that value. Since the action’s state
407    /// is now equal to the target value of the button, the button will now
408    /// be rendered as active (and the other buttons, with different targets,
409    /// rendered inactive).
410    /// ## `target_value`
411    /// a [`glib::Variant`][struct@crate::glib::Variant] to set as the target value, or [`None`]
412    #[doc(alias = "gtk_actionable_set_action_target_value")]
413    fn set_action_target_value(&self, target_value: Option<&glib::Variant>) {
414        unsafe {
415            ffi::gtk_actionable_set_action_target_value(
416                self.as_ref().to_glib_none().0,
417                target_value.to_glib_none().0,
418            );
419        }
420    }
421
422    /// Sets the action-name and associated string target value of an
423    /// actionable widget.
424    ///
425    /// `detailed_action_name` is a string in the format accepted by
426    /// `g_action_parse_detailed_name()`.
427    ///
428    /// (Note that prior to version 3.22.25,
429    /// this function is only usable for actions with a simple "s" target, and
430    /// `detailed_action_name` must be of the form `"action::target"` where
431    /// `action` is the action name and `target` is the string to use
432    /// as the target.)
433    /// ## `detailed_action_name`
434    /// the detailed action name
435    #[doc(alias = "gtk_actionable_set_detailed_action_name")]
436    fn set_detailed_action_name(&self, detailed_action_name: &str) {
437        unsafe {
438            ffi::gtk_actionable_set_detailed_action_name(
439                self.as_ref().to_glib_none().0,
440                detailed_action_name.to_glib_none().0,
441            );
442        }
443    }
444
445    #[doc(alias = "action-name")]
446    fn connect_action_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
447        unsafe extern "C" fn notify_action_name_trampoline<
448            P: IsA<Actionable>,
449            F: Fn(&P) + 'static,
450        >(
451            this: *mut ffi::GtkActionable,
452            _param_spec: glib::ffi::gpointer,
453            f: glib::ffi::gpointer,
454        ) {
455            unsafe {
456                let f: &F = &*(f as *const F);
457                f(Actionable::from_glib_borrow(this).unsafe_cast_ref())
458            }
459        }
460        unsafe {
461            let f: Box_<F> = Box_::new(f);
462            connect_raw(
463                self.as_ptr() as *mut _,
464                c"notify::action-name".as_ptr(),
465                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
466                    notify_action_name_trampoline::<Self, F> as *const (),
467                )),
468                Box_::into_raw(f),
469            )
470        }
471    }
472
473    #[doc(alias = "action-target")]
474    fn connect_action_target_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
475        unsafe extern "C" fn notify_action_target_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            unsafe {
484                let f: &F = &*(f as *const F);
485                f(Actionable::from_glib_borrow(this).unsafe_cast_ref())
486            }
487        }
488        unsafe {
489            let f: Box_<F> = Box_::new(f);
490            connect_raw(
491                self.as_ptr() as *mut _,
492                c"notify::action-target".as_ptr(),
493                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
494                    notify_action_target_trampoline::<Self, F> as *const (),
495                )),
496                Box_::into_raw(f),
497            )
498        }
499    }
500}
501
502impl<O: IsA<Actionable>> ActionableExt for O {}