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};
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::{boxed::Box as Box_, fmt, mem::transmute};
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 | Writeable
32 ///
33 ///
34 /// #### `action-target`
35 /// Readable | Writeable
36 /// <details><summary><h4>Widget</h4></summary>
37 ///
38 ///
39 /// #### `app-paintable`
40 /// Readable | Writeable
41 ///
42 ///
43 /// #### `can-default`
44 /// Readable | Writeable
45 ///
46 ///
47 /// #### `can-focus`
48 /// Readable | Writeable
49 ///
50 ///
51 /// #### `composite-child`
52 /// Readable
53 ///
54 ///
55 /// #### `double-buffered`
56 /// Whether the widget is double buffered.
57 ///
58 /// Readable | Writeable
59 ///
60 ///
61 /// #### `events`
62 /// Readable | Writeable
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 | Writeable
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 | Writeable
80 ///
81 ///
82 /// #### `halign`
83 /// How to distribute horizontal space if widget gets extra space, see [`Align`][crate::Align]
84 ///
85 /// Readable | Writeable
86 ///
87 ///
88 /// #### `has-default`
89 /// Readable | Writeable
90 ///
91 ///
92 /// #### `has-focus`
93 /// Readable | Writeable
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 | Writeable
108 ///
109 ///
110 /// #### `height-request`
111 /// Readable | Writeable
112 ///
113 ///
114 /// #### `hexpand`
115 /// Whether to expand horizontally. See [`WidgetExt::set_hexpand()`][crate::prelude::WidgetExt::set_hexpand()].
116 ///
117 /// Readable | Writeable
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 | Writeable
124 ///
125 ///
126 /// #### `is-focus`
127 /// Readable | Writeable
128 ///
129 ///
130 /// #### `margin`
131 /// Sets all four sides' margin at once. If read, returns max
132 /// margin on any side.
133 ///
134 /// Readable | Writeable
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 | Writeable
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 | Writeable
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 | Writeable
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 | Writeable
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 | Writeable
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 | Writeable
197 ///
198 ///
199 /// #### `name`
200 /// Readable | Writeable
201 ///
202 ///
203 /// #### `no-show-all`
204 /// Readable | Writeable
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 | Writeable
214 ///
215 ///
216 /// #### `parent`
217 /// Readable | Writeable
218 ///
219 ///
220 /// #### `receives-default`
221 /// Readable | Writeable
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 | Writeable
233 ///
234 ///
235 /// #### `style`
236 /// The style of the widget, which contains information about how it will look (colors, etc).
237 ///
238 /// Readable | Writeable
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 | Writeable
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 | Writeable
271 ///
272 ///
273 /// #### `valign`
274 /// How to distribute vertical space if widget gets extra space, see [`Align`][crate::Align]
275 ///
276 /// Readable | Writeable
277 ///
278 ///
279 /// #### `vexpand`
280 /// Whether to expand vertically. See [`WidgetExt::set_vexpand()`][crate::prelude::WidgetExt::set_vexpand()].
281 ///
282 /// Readable | Writeable
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 | Writeable
289 ///
290 ///
291 /// #### `visible`
292 /// Readable | Writeable
293 ///
294 ///
295 /// #### `width-request`
296 /// Readable | Writeable
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
320mod sealed {
321 pub trait Sealed {}
322 impl<T: super::IsA<super::Actionable>> Sealed for T {}
323}
324
325/// Trait containing all [`struct@Actionable`] methods.
326///
327/// # Implementors
328///
329/// [`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]
330pub trait ActionableExt: IsA<Actionable> + sealed::Sealed + 'static {
331 /// Gets the action name for `self`.
332 ///
333 /// See [`set_action_name()`][Self::set_action_name()] for more information.
334 ///
335 /// # Returns
336 ///
337 /// the action name, or [`None`] if none is set
338 #[doc(alias = "gtk_actionable_get_action_name")]
339 #[doc(alias = "get_action_name")]
340 fn action_name(&self) -> Option<glib::GString> {
341 unsafe {
342 from_glib_none(ffi::gtk_actionable_get_action_name(
343 self.as_ref().to_glib_none().0,
344 ))
345 }
346 }
347
348 /// Gets the current target value of `self`.
349 ///
350 /// See [`set_action_target_value()`][Self::set_action_target_value()] for more information.
351 ///
352 /// # Returns
353 ///
354 /// the current target value
355 #[doc(alias = "gtk_actionable_get_action_target_value")]
356 #[doc(alias = "get_action_target_value")]
357 fn action_target_value(&self) -> Option<glib::Variant> {
358 unsafe {
359 from_glib_none(ffi::gtk_actionable_get_action_target_value(
360 self.as_ref().to_glib_none().0,
361 ))
362 }
363 }
364
365 /// Specifies the name of the action with which this widget should be
366 /// associated. If `action_name` is [`None`] then the widget will be
367 /// unassociated from any previous action.
368 ///
369 /// Usually this function is used when the widget is located (or will be
370 /// located) within the hierarchy of a [`ApplicationWindow`][crate::ApplicationWindow].
371 ///
372 /// Names are of the form “win.save” or “app.quit” for actions on the
373 /// containing [`ApplicationWindow`][crate::ApplicationWindow] or its associated [`Application`][crate::Application],
374 /// respectively. This is the same form used for actions in the [`gio::Menu`][crate::gio::Menu]
375 /// associated with the window.
376 /// ## `action_name`
377 /// an action name, or [`None`]
378 #[doc(alias = "gtk_actionable_set_action_name")]
379 fn set_action_name(&self, action_name: Option<&str>) {
380 unsafe {
381 ffi::gtk_actionable_set_action_name(
382 self.as_ref().to_glib_none().0,
383 action_name.to_glib_none().0,
384 );
385 }
386 }
387
388 //#[doc(alias = "gtk_actionable_set_action_target")]
389 //fn set_action_target(&self, format_string: &str, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) {
390 // unsafe { TODO: call ffi:gtk_actionable_set_action_target() }
391 //}
392
393 /// Sets the target value of an actionable widget.
394 ///
395 /// If `target_value` is [`None`] then the target value is unset.
396 ///
397 /// The target value has two purposes. First, it is used as the
398 /// parameter to activation of the action associated with the
399 /// [`Actionable`][crate::Actionable] widget. Second, it is used to determine if the widget
400 /// should be rendered as “active” — the widget is active if the state
401 /// is equal to the given target.
402 ///
403 /// Consider the example of associating a set of buttons with a `GAction`
404 /// with string state in a typical “radio button” situation. Each button
405 /// will be associated with the same action, but with a different target
406 /// value for that action. Clicking on a particular button will activate
407 /// the action with the target of that button, which will typically cause
408 /// the action’s state to change to that value. Since the action’s state
409 /// is now equal to the target value of the button, the button will now
410 /// be rendered as active (and the other buttons, with different targets,
411 /// rendered inactive).
412 /// ## `target_value`
413 /// a [`glib::Variant`][struct@crate::glib::Variant] to set as the target value, or [`None`]
414 #[doc(alias = "gtk_actionable_set_action_target_value")]
415 fn set_action_target_value(&self, target_value: Option<&glib::Variant>) {
416 unsafe {
417 ffi::gtk_actionable_set_action_target_value(
418 self.as_ref().to_glib_none().0,
419 target_value.to_glib_none().0,
420 );
421 }
422 }
423
424 /// Sets the action-name and associated string target value of an
425 /// actionable widget.
426 ///
427 /// `detailed_action_name` is a string in the format accepted by
428 /// `g_action_parse_detailed_name()`.
429 ///
430 /// (Note that prior to version 3.22.25,
431 /// this function is only usable for actions with a simple "s" target, and
432 /// `detailed_action_name` must be of the form `"action::target"` where
433 /// `action` is the action name and `target` is the string to use
434 /// as the target.)
435 /// ## `detailed_action_name`
436 /// the detailed action name
437 #[doc(alias = "gtk_actionable_set_detailed_action_name")]
438 fn set_detailed_action_name(&self, detailed_action_name: &str) {
439 unsafe {
440 ffi::gtk_actionable_set_detailed_action_name(
441 self.as_ref().to_glib_none().0,
442 detailed_action_name.to_glib_none().0,
443 );
444 }
445 }
446
447 #[doc(alias = "action-name")]
448 fn connect_action_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
449 unsafe extern "C" fn notify_action_name_trampoline<
450 P: IsA<Actionable>,
451 F: Fn(&P) + 'static,
452 >(
453 this: *mut ffi::GtkActionable,
454 _param_spec: glib::ffi::gpointer,
455 f: glib::ffi::gpointer,
456 ) {
457 let f: &F = &*(f as *const F);
458 f(Actionable::from_glib_borrow(this).unsafe_cast_ref())
459 }
460 unsafe {
461 let f: Box_<F> = Box_::new(f);
462 connect_raw(
463 self.as_ptr() as *mut _,
464 b"notify::action-name\0".as_ptr() as *const _,
465 Some(transmute::<_, 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 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-target\0".as_ptr() as *const _,
491 Some(transmute::<_, unsafe extern "C" fn()>(
492 notify_action_target_trampoline::<Self, F> as *const (),
493 )),
494 Box_::into_raw(f),
495 )
496 }
497 }
498}
499
500impl<O: IsA<Actionable>> ActionableExt for O {}
501
502impl fmt::Display for Actionable {
503 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
504 f.write_str("Actionable")
505 }
506}