Skip to main content

gtk4/auto/
popover_menu.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::{
9    AccessibleRole, Align, Buildable, ConstraintTarget, LayoutManager, Native, Overflow, Popover,
10    PopoverMenuFlags, PositionType, ShortcutManager, Widget, ffi,
11};
12use glib::{
13    prelude::*,
14    signal::{SignalHandlerId, connect_raw},
15    translate::*,
16};
17use std::boxed::Box as Box_;
18
19#[cfg(feature = "v4_10")]
20#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
21glib::wrapper! {
22    /// A subclass of [`Popover`][crate::Popover] that implements menu behavior.
23    ///
24    /// <picture>
25    ///   <source srcset="menu-dark.png" media="(prefers-color-scheme: dark)">
26    ///   <img alt="An example GtkPopoverMenu" src="menu.png">
27    /// </picture>
28    ///
29    /// [`PopoverMenu`][crate::PopoverMenu] treats its children like menus and allows switching
30    /// between them. It can open submenus as traditional, nested submenus,
31    /// or in a more touch-friendly sliding fashion.
32    /// The property [`flags`][struct@crate::PopoverMenu#flags] controls this appearance.
33    ///
34    /// [`PopoverMenu`][crate::PopoverMenu] is meant to be used primarily with menu models,
35    /// using [`from_model()`][Self::from_model()]. If you need to put
36    /// other widgets such as a [`SpinButton`][crate::SpinButton] or a [`Switch`][crate::Switch] into a popover,
37    /// you can use [`add_child()`][Self::add_child()].
38    ///
39    /// For more dialog-like behavior, use a plain [`Popover`][crate::Popover].
40    ///
41    /// ## Menu models
42    ///
43    /// The XML format understood by [`Builder`][crate::Builder] for `GMenuModel` consists
44    /// of a toplevel `<menu>` element, which contains one or more `<item>`
45    /// elements. Each `<item>` element contains `<attribute>` and `<link>`
46    /// elements with a mandatory name attribute. `<link>` elements have the
47    /// same content model as `<menu>`. Instead of `<link name="submenu">`
48    /// or `<link name="section">`, you can use `<submenu>` or `<section>`
49    /// elements.
50    ///
51    /// ```xml
52    /// <menu id='app-menu'>
53    ///   <section>
54    ///     <item>
55    ///       <attribute name='label' translatable='yes'>_New Window</attribute>
56    ///       <attribute name='action'>app.new</attribute>
57    ///     </item>
58    ///     <item>
59    ///       <attribute name='label' translatable='yes'>_About Sunny</attribute>
60    ///       <attribute name='action'>app.about</attribute>
61    ///     </item>
62    ///     <item>
63    ///       <attribute name='label' translatable='yes'>_Quit</attribute>
64    ///       <attribute name='action'>app.quit</attribute>
65    ///     </item>
66    ///   </section>
67    /// </menu>
68    /// ```
69    ///
70    /// Attribute values can be translated using gettext, like other [`Builder`][crate::Builder]
71    /// content. `<attribute>` elements can be marked for translation with a
72    /// `translatable="yes"` attribute. It is also possible to specify message
73    /// context and translator comments, using the context and comments attributes.
74    /// To make use of this, the [`Builder`][crate::Builder] must have been given the gettext
75    /// domain to use.
76    ///
77    /// The following attributes are used when constructing menu items:
78    ///
79    /// - "label": a user-visible string to display
80    /// - "use-markup": whether the text in the menu item includes [Pango markup](https://docs.gtk.org/Pango/pango_markup.html)
81    /// - "action": the prefixed name of the action to trigger
82    /// - "target": the parameter to use when activating the action
83    /// - "icon" and "verb-icon": names of icons that may be displayed
84    /// - "submenu-action": name of an action that may be used to track
85    ///      whether a submenu is open
86    /// - "hidden-when": a string used to determine when the item will be hidden.
87    ///      Possible values include "action-disabled", "action-missing", "macos-menubar".
88    ///      This is mainly useful for exported menus, see [`GtkApplicationExt::set_menubar()`][crate::prelude::GtkApplicationExt::set_menubar()].
89    /// - "custom": a string used to match against the ID of a custom child added with
90    ///      [`add_child()`][Self::add_child()], [`PopoverMenuBar::add_child()`][crate::PopoverMenuBar::add_child()],
91    ///      or in the ui file with `<child type="ID">`.
92    ///
93    /// The following attributes are used when constructing sections:
94    ///
95    /// - "label": a user-visible string to use as section heading
96    /// - "display-hint": a string used to determine special formatting for the section.
97    ///     Possible values include "horizontal-buttons", "circular-buttons" and
98    ///     "inline-buttons". They all indicate that section should be
99    ///     displayed as a horizontal row of buttons.
100    /// - "text-direction": a string used to determine the [`TextDirection`][crate::TextDirection] to use
101    ///     when "display-hint" is set to "horizontal-buttons". Possible values
102    ///     include "rtl", "ltr", and "none".
103    ///
104    /// The following attributes are used when constructing submenus:
105    ///
106    /// - "label": a user-visible string to display
107    /// - "icon": icon name to display
108    /// - "gtk-macos-special": (macOS only, ignored by others) Add special meaning to a menu
109    ///     in the macOS menu bar. See [Using GTK on Apple macOS](osx.html).
110    ///
111    /// Menu items will also show accelerators, which are usually associated
112    /// with actions via [`GtkApplicationExt::set_accels_for_action()`][crate::prelude::GtkApplicationExt::set_accels_for_action()],
113    /// [`WidgetClassExt::add_binding_action()`][crate::subclass::prelude::WidgetClassExt::add_binding_action()] or
114    /// [`ShortcutController::add_shortcut()`][crate::ShortcutController::add_shortcut()].
115    ///
116    /// # Shortcuts and Gestures
117    ///
118    /// [`PopoverMenu`][crate::PopoverMenu] supports the following keyboard shortcuts:
119    ///
120    /// - <kbd>Space</kbd> activates the default widget.
121    ///
122    /// # CSS Nodes
123    ///
124    /// [`PopoverMenu`][crate::PopoverMenu] is just a subclass of [`Popover`][crate::Popover] that adds custom content
125    /// to it, therefore it has the same CSS nodes. It is one of the cases that add
126    /// a `.menu` style class to the main `popover` node.
127    ///
128    /// Menu items have nodes with name `button` and class `.model`. If a section
129    /// display-hint is set, the section gets a node `box` with class `horizontal`
130    /// plus a class with the same text as the display hint. Note that said box may
131    /// not be the direct ancestor of the item `button`s. Thus, for example, to style
132    /// items in an `inline-buttons` section, select `.inline-buttons button.model`.
133    /// Other things that may be of interest to style in menus include `label` nodes.
134    ///
135    /// # Accessibility
136    ///
137    /// [`PopoverMenu`][crate::PopoverMenu] uses the [enum@Gtk.AccessibleRole.menu] role, and its
138    /// items use the [enum@Gtk.AccessibleRole.menu_item],
139    /// [enum@Gtk.AccessibleRole.checkbox] or [enum@Gtk.AccessibleRole.menu_item_radio]
140    /// roles, depending on the action they are connected to.
141    ///
142    /// ## Properties
143    ///
144    ///
145    /// #### `flags`
146    ///  The flags that @popover uses to create/display a menu from its model.
147    ///
148    /// If a model is set and the flags change, contents are rebuilt, so if setting
149    /// properties individually, set flags before model to avoid a redundant rebuild.
150    ///
151    /// Readable | Writable
152    ///
153    ///
154    /// #### `menu-model`
155    ///  The model from which the menu is made.
156    ///
157    /// Readable | Writable
158    ///
159    ///
160    /// #### `visible-submenu`
161    ///  The name of the visible submenu.
162    ///
163    /// Readable | Writable
164    /// <details><summary><h4>Popover</h4></summary>
165    ///
166    ///
167    /// #### `autohide`
168    ///  Whether to dismiss the popover on outside clicks.
169    ///
170    /// If false, the popover won't automatically grab the focus when shown.
171    /// This is useful for usecases like entry completion, where the focus is
172    /// expected to stay on the entry.
173    ///
174    /// Readable | Writable
175    ///
176    ///
177    /// #### `cascade-popdown`
178    ///  Whether the popover pops down after a child popover.
179    ///
180    /// This is used to implement the expected behavior of submenus.
181    ///
182    /// Readable | Writable
183    ///
184    ///
185    /// #### `child`
186    ///  The child widget.
187    ///
188    /// Readable | Writable
189    ///
190    ///
191    /// #### `default-widget`
192    ///  The default widget inside the popover.
193    ///
194    /// Readable | Writable
195    ///
196    ///
197    /// #### `has-arrow`
198    ///  Whether to draw an arrow.
199    ///
200    /// Readable | Writable
201    ///
202    ///
203    /// #### `mnemonics-visible`
204    ///  Whether mnemonics are currently visible in this popover.
205    ///
206    /// Readable | Writable
207    ///
208    ///
209    /// #### `pointing-to`
210    ///  Rectangle in the parent widget that the popover points to.
211    ///
212    /// Readable | Writable
213    ///
214    ///
215    /// #### `position`
216    ///  How to place the popover, relative to its parent.
217    ///
218    /// Readable | Writable
219    /// </details>
220    /// <details><summary><h4>Widget</h4></summary>
221    ///
222    ///
223    /// #### `can-focus`
224    ///  Whether the widget or any of its descendents can accept
225    /// the input focus.
226    ///
227    /// This property is meant to be set by widget implementations,
228    /// typically in their instance init function.
229    ///
230    /// Readable | Writable
231    ///
232    ///
233    /// #### `can-target`
234    ///  Whether the widget can receive pointer events.
235    ///
236    /// Readable | Writable
237    ///
238    ///
239    /// #### `css-classes`
240    ///  A list of css classes applied to this widget.
241    ///
242    /// Readable | Writable
243    ///
244    ///
245    /// #### `css-name`
246    ///  The name of this widget in the CSS tree.
247    ///
248    /// This property is meant to be set by widget implementations,
249    /// typically in their instance init function.
250    ///
251    /// Readable | Writable | Construct Only
252    ///
253    ///
254    /// #### `cursor`
255    ///  The cursor used by @widget.
256    ///
257    /// Readable | Writable
258    ///
259    ///
260    /// #### `focus-on-click`
261    ///  Whether the widget should grab focus when it is clicked with the mouse.
262    ///
263    /// This property is only relevant for widgets that can take focus.
264    ///
265    /// Readable | Writable
266    ///
267    ///
268    /// #### `focusable`
269    ///  Whether this widget itself will accept the input focus.
270    ///
271    /// Readable | Writable
272    ///
273    ///
274    /// #### `halign`
275    ///  How to distribute horizontal space if widget gets extra space.
276    ///
277    /// Readable | Writable
278    ///
279    ///
280    /// #### `has-default`
281    ///  Whether the widget is the default widget.
282    ///
283    /// Readable
284    ///
285    ///
286    /// #### `has-focus`
287    ///  Whether the widget has the input focus.
288    ///
289    /// Readable
290    ///
291    ///
292    /// #### `has-tooltip`
293    ///  Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
294    /// signal on @widget.
295    ///
296    /// A true value indicates that @widget can have a tooltip, in this case
297    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
298    /// determine whether it will provide a tooltip or not.
299    ///
300    /// Readable | Writable
301    ///
302    ///
303    /// #### `height-request`
304    ///  Overrides for height request of the widget.
305    ///
306    /// If this is -1, the natural request will be used.
307    ///
308    /// Readable | Writable
309    ///
310    ///
311    /// #### `hexpand`
312    ///  Whether to expand horizontally.
313    ///
314    /// Readable | Writable
315    ///
316    ///
317    /// #### `hexpand-set`
318    ///  Whether to use the `hexpand` property.
319    ///
320    /// Readable | Writable
321    ///
322    ///
323    /// #### `layout-manager`
324    ///  The [`LayoutManager`][crate::LayoutManager] instance to use to compute
325    /// the preferred size of the widget, and allocate its children.
326    ///
327    /// This property is meant to be set by widget implementations,
328    /// typically in their instance init function.
329    ///
330    /// Readable | Writable
331    ///
332    ///
333    /// #### `limit-events`
334    ///  Makes this widget act like a modal dialog, with respect to
335    /// event delivery.
336    ///
337    /// Global event controllers will not handle events with targets
338    /// inside the widget, unless they are set up to ignore propagation
339    /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
340    ///
341    /// Readable | Writable
342    ///
343    ///
344    /// #### `margin-bottom`
345    ///  Margin on bottom side of widget.
346    ///
347    /// This property adds margin outside of the widget's normal size
348    /// request, the margin will be added in addition to the size from
349    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
350    ///
351    /// Readable | Writable
352    ///
353    ///
354    /// #### `margin-end`
355    ///  Margin on end of widget, horizontally.
356    ///
357    /// This property supports left-to-right and right-to-left text
358    /// directions.
359    ///
360    /// This property adds margin outside of the widget's normal size
361    /// request, the margin will be added in addition to the size from
362    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
363    ///
364    /// Readable | Writable
365    ///
366    ///
367    /// #### `margin-start`
368    ///  Margin on start of widget, horizontally.
369    ///
370    /// This property supports left-to-right and right-to-left text
371    /// directions.
372    ///
373    /// This property adds margin outside of the widget's normal size
374    /// request, the margin will be added in addition to the size from
375    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
376    ///
377    /// Readable | Writable
378    ///
379    ///
380    /// #### `margin-top`
381    ///  Margin on top side of widget.
382    ///
383    /// This property adds margin outside of the widget's normal size
384    /// request, the margin will be added in addition to the size from
385    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
386    ///
387    /// Readable | Writable
388    ///
389    ///
390    /// #### `name`
391    ///  The name of the widget.
392    ///
393    /// Readable | Writable
394    ///
395    ///
396    /// #### `opacity`
397    ///  The requested opacity of the widget.
398    ///
399    /// Readable | Writable
400    ///
401    ///
402    /// #### `overflow`
403    ///  How content outside the widget's content area is treated.
404    ///
405    /// This property is meant to be set by widget implementations,
406    /// typically in their instance init function.
407    ///
408    /// Readable | Writable
409    ///
410    ///
411    /// #### `parent`
412    ///  The parent widget of this widget.
413    ///
414    /// Readable
415    ///
416    ///
417    /// #### `receives-default`
418    ///  Whether the widget will receive the default action when it is focused.
419    ///
420    /// Readable | Writable
421    ///
422    ///
423    /// #### `root`
424    ///  The [`Root`][crate::Root] widget of the widget tree containing this widget.
425    ///
426    /// This will be `NULL` if the widget is not contained in a root widget.
427    ///
428    /// Readable
429    ///
430    ///
431    /// #### `scale-factor`
432    ///  The scale factor of the widget.
433    ///
434    /// Readable
435    ///
436    ///
437    /// #### `sensitive`
438    ///  Whether the widget responds to input.
439    ///
440    /// Readable | Writable
441    ///
442    ///
443    /// #### `tooltip-markup`
444    ///  Sets the text of tooltip to be the given string, which is marked up
445    /// with Pango markup.
446    ///
447    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
448    ///
449    /// This is a convenience property which will take care of getting the
450    /// tooltip shown if the given string is not `NULL`:
451    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
452    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
453    /// the default signal handler.
454    ///
455    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
456    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
457    ///
458    /// Readable | Writable
459    ///
460    ///
461    /// #### `tooltip-text`
462    ///  Sets the text of tooltip to be the given string.
463    ///
464    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
465    ///
466    /// This is a convenience property which will take care of getting the
467    /// tooltip shown if the given string is not `NULL`:
468    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
469    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
470    /// the default signal handler.
471    ///
472    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
473    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
474    ///
475    /// Readable | Writable
476    ///
477    ///
478    /// #### `valign`
479    ///  How to distribute vertical space if widget gets extra space.
480    ///
481    /// Readable | Writable
482    ///
483    ///
484    /// #### `vexpand`
485    ///  Whether to expand vertically.
486    ///
487    /// Readable | Writable
488    ///
489    ///
490    /// #### `vexpand-set`
491    ///  Whether to use the `vexpand` property.
492    ///
493    /// Readable | Writable
494    ///
495    ///
496    /// #### `visible`
497    ///  Whether the widget is visible.
498    ///
499    /// Readable | Writable
500    ///
501    ///
502    /// #### `width-request`
503    ///  Overrides for width request of the widget.
504    ///
505    /// If this is -1, the natural request will be used.
506    ///
507    /// Readable | Writable
508    /// </details>
509    /// <details><summary><h4>Accessible</h4></summary>
510    ///
511    ///
512    /// #### `accessible-role`
513    ///  The accessible role of the given [`Accessible`][crate::Accessible] implementation.
514    ///
515    /// The accessible role cannot be changed once set.
516    ///
517    /// Readable | Writable
518    /// </details>
519    ///
520    /// # Implements
521    ///
522    /// [`PopoverExt`][trait@crate::prelude::PopoverExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`AccessibleExt`][trait@crate::prelude::AccessibleExt], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ConstraintTargetExt`][trait@crate::prelude::ConstraintTargetExt], [`NativeExt`][trait@crate::prelude::NativeExt], [`ShortcutManagerExt`][trait@crate::prelude::ShortcutManagerExt], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`AccessibleExtManual`][trait@crate::prelude::AccessibleExtManual]
523    #[doc(alias = "GtkPopoverMenu")]
524    pub struct PopoverMenu(Object<ffi::GtkPopoverMenu>) @extends Popover, Widget, @implements Accessible, Buildable, ConstraintTarget, Native, ShortcutManager;
525
526    match fn {
527        type_ => || ffi::gtk_popover_menu_get_type(),
528    }
529}
530
531#[cfg(not(feature = "v4_10"))]
532glib::wrapper! {
533    #[doc(alias = "GtkPopoverMenu")]
534    pub struct PopoverMenu(Object<ffi::GtkPopoverMenu>) @extends Popover, Widget, @implements Buildable, ConstraintTarget, Native, ShortcutManager;
535
536    match fn {
537        type_ => || ffi::gtk_popover_menu_get_type(),
538    }
539}
540
541impl PopoverMenu {
542    /// Creates a [`PopoverMenu`][crate::PopoverMenu] and populates it according to @model.
543    ///
544    /// The created buttons are connected to actions found in the
545    /// [`ApplicationWindow`][crate::ApplicationWindow] to which the popover belongs - typically
546    /// by means of being attached to a widget that is contained within
547    /// the [`ApplicationWindow`][crate::ApplicationWindow]s widget hierarchy.
548    ///
549    /// Actions can also be added using [`WidgetExt::insert_action_group()`][crate::prelude::WidgetExt::insert_action_group()]
550    /// on the menus attach widget or on any of its parent widgets.
551    ///
552    /// This function creates menus with sliding submenus.
553    /// See [`from_model_full()`][Self::from_model_full()] for a way
554    /// to control this.
555    /// ## `model`
556    /// a `GMenuModel`
557    ///
558    /// # Returns
559    ///
560    /// the new [`PopoverMenu`][crate::PopoverMenu]
561    #[doc(alias = "gtk_popover_menu_new_from_model")]
562    #[doc(alias = "new_from_model")]
563    pub fn from_model(model: Option<&impl IsA<gio::MenuModel>>) -> PopoverMenu {
564        assert_initialized_main_thread!();
565        unsafe {
566            Widget::from_glib_none(ffi::gtk_popover_menu_new_from_model(
567                model.map(|p| p.as_ref()).to_glib_none().0,
568            ))
569            .unsafe_cast()
570        }
571    }
572
573    /// Creates a [`PopoverMenu`][crate::PopoverMenu] and populates it according to @model.
574    ///
575    /// The created buttons are connected to actions found in the
576    /// action groups that are accessible from the parent widget.
577    /// This includes the [`ApplicationWindow`][crate::ApplicationWindow] to which the popover
578    /// belongs. Actions can also be added using [`WidgetExt::insert_action_group()`][crate::prelude::WidgetExt::insert_action_group()]
579    /// on the parent widget or on any of its parent widgets.
580    /// ## `model`
581    /// a `GMenuModel`
582    /// ## `flags`
583    /// flags that affect how the menu is created
584    ///
585    /// # Returns
586    ///
587    /// the new [`PopoverMenu`][crate::PopoverMenu]
588    #[doc(alias = "gtk_popover_menu_new_from_model_full")]
589    #[doc(alias = "new_from_model_full")]
590    pub fn from_model_full(
591        model: &impl IsA<gio::MenuModel>,
592        flags: PopoverMenuFlags,
593    ) -> PopoverMenu {
594        assert_initialized_main_thread!();
595        unsafe {
596            Widget::from_glib_none(ffi::gtk_popover_menu_new_from_model_full(
597                model.as_ref().to_glib_none().0,
598                flags.into_glib(),
599            ))
600            .unsafe_cast()
601        }
602    }
603
604    // rustdoc-stripper-ignore-next
605    /// Creates a new builder-pattern struct instance to construct [`PopoverMenu`] objects.
606    ///
607    /// This method returns an instance of [`PopoverMenuBuilder`](crate::builders::PopoverMenuBuilder) which can be used to create [`PopoverMenu`] objects.
608    pub fn builder() -> PopoverMenuBuilder {
609        PopoverMenuBuilder::new()
610    }
611
612    /// Adds a custom widget to a generated menu.
613    ///
614    /// For this to work, the menu model of @self must have
615    /// an item with a `custom` attribute that matches @id.
616    /// ## `child`
617    /// the [`Widget`][crate::Widget] to add
618    /// ## `id`
619    /// the ID to insert @child at
620    ///
621    /// # Returns
622    ///
623    /// [`true`] if @id was found and the widget added
624    #[doc(alias = "gtk_popover_menu_add_child")]
625    pub fn add_child(&self, child: &impl IsA<Widget>, id: &str) -> bool {
626        unsafe {
627            from_glib(ffi::gtk_popover_menu_add_child(
628                self.to_glib_none().0,
629                child.as_ref().to_glib_none().0,
630                id.to_glib_none().0,
631            ))
632        }
633    }
634
635    /// Returns the flags that @self uses to create/display a menu from its model.
636    ///
637    /// # Returns
638    ///
639    /// the [`PopoverMenuFlags`][crate::PopoverMenuFlags]
640    #[cfg(feature = "v4_14")]
641    #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
642    #[doc(alias = "gtk_popover_menu_get_flags")]
643    #[doc(alias = "get_flags")]
644    pub fn flags(&self) -> PopoverMenuFlags {
645        unsafe { from_glib(ffi::gtk_popover_menu_get_flags(self.to_glib_none().0)) }
646    }
647
648    /// Returns the menu model used to populate the popover.
649    ///
650    /// # Returns
651    ///
652    /// the menu model of @self
653    #[doc(alias = "gtk_popover_menu_get_menu_model")]
654    #[doc(alias = "get_menu_model")]
655    #[doc(alias = "menu-model")]
656    pub fn menu_model(&self) -> Option<gio::MenuModel> {
657        unsafe { from_glib_none(ffi::gtk_popover_menu_get_menu_model(self.to_glib_none().0)) }
658    }
659
660    /// Removes a widget that has previously been added with
661    /// [`add_child()`][Self::add_child()]
662    /// ## `child`
663    /// the [`Widget`][crate::Widget] to remove
664    ///
665    /// # Returns
666    ///
667    /// [`true`] if the widget was removed
668    #[doc(alias = "gtk_popover_menu_remove_child")]
669    pub fn remove_child(&self, child: &impl IsA<Widget>) -> bool {
670        unsafe {
671            from_glib(ffi::gtk_popover_menu_remove_child(
672                self.to_glib_none().0,
673                child.as_ref().to_glib_none().0,
674            ))
675        }
676    }
677
678    /// Sets the flags that @self uses to create/display a menu from its model.
679    ///
680    /// If a model is set and the flags change, contents are rebuilt, so if setting
681    /// properties individually, set flags before model to avoid a redundant rebuild.
682    /// ## `flags`
683    /// a set of [`PopoverMenuFlags`][crate::PopoverMenuFlags]
684    #[cfg(feature = "v4_14")]
685    #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
686    #[doc(alias = "gtk_popover_menu_set_flags")]
687    #[doc(alias = "flags")]
688    pub fn set_flags(&self, flags: PopoverMenuFlags) {
689        unsafe {
690            ffi::gtk_popover_menu_set_flags(self.to_glib_none().0, flags.into_glib());
691        }
692    }
693
694    /// Sets a new menu model on @self.
695    ///
696    /// The existing contents of @self are removed, and
697    /// the @self is populated with new contents according
698    /// to @model.
699    /// ## `model`
700    /// a `GMenuModel`
701    #[doc(alias = "gtk_popover_menu_set_menu_model")]
702    #[doc(alias = "menu-model")]
703    pub fn set_menu_model(&self, model: Option<&impl IsA<gio::MenuModel>>) {
704        unsafe {
705            ffi::gtk_popover_menu_set_menu_model(
706                self.to_glib_none().0,
707                model.map(|p| p.as_ref()).to_glib_none().0,
708            );
709        }
710    }
711
712    /// The name of the visible submenu.
713    #[doc(alias = "visible-submenu")]
714    pub fn visible_submenu(&self) -> Option<glib::GString> {
715        ObjectExt::property(self, "visible-submenu")
716    }
717
718    /// The name of the visible submenu.
719    #[doc(alias = "visible-submenu")]
720    pub fn set_visible_submenu(&self, visible_submenu: Option<&str>) {
721        ObjectExt::set_property(self, "visible-submenu", visible_submenu)
722    }
723
724    #[cfg(feature = "v4_14")]
725    #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
726    #[doc(alias = "flags")]
727    pub fn connect_flags_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
728        unsafe extern "C" fn notify_flags_trampoline<F: Fn(&PopoverMenu) + 'static>(
729            this: *mut ffi::GtkPopoverMenu,
730            _param_spec: glib::ffi::gpointer,
731            f: glib::ffi::gpointer,
732        ) {
733            unsafe {
734                let f: &F = &*(f as *const F);
735                f(&from_glib_borrow(this))
736            }
737        }
738        unsafe {
739            let f: Box_<F> = Box_::new(f);
740            connect_raw(
741                self.as_ptr() as *mut _,
742                c"notify::flags".as_ptr(),
743                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
744                    notify_flags_trampoline::<F> as *const (),
745                )),
746                Box_::into_raw(f),
747            )
748        }
749    }
750
751    #[doc(alias = "menu-model")]
752    pub fn connect_menu_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
753        unsafe extern "C" fn notify_menu_model_trampoline<F: Fn(&PopoverMenu) + 'static>(
754            this: *mut ffi::GtkPopoverMenu,
755            _param_spec: glib::ffi::gpointer,
756            f: glib::ffi::gpointer,
757        ) {
758            unsafe {
759                let f: &F = &*(f as *const F);
760                f(&from_glib_borrow(this))
761            }
762        }
763        unsafe {
764            let f: Box_<F> = Box_::new(f);
765            connect_raw(
766                self.as_ptr() as *mut _,
767                c"notify::menu-model".as_ptr(),
768                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
769                    notify_menu_model_trampoline::<F> as *const (),
770                )),
771                Box_::into_raw(f),
772            )
773        }
774    }
775
776    #[doc(alias = "visible-submenu")]
777    pub fn connect_visible_submenu_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
778        unsafe extern "C" fn notify_visible_submenu_trampoline<F: Fn(&PopoverMenu) + 'static>(
779            this: *mut ffi::GtkPopoverMenu,
780            _param_spec: glib::ffi::gpointer,
781            f: glib::ffi::gpointer,
782        ) {
783            unsafe {
784                let f: &F = &*(f as *const F);
785                f(&from_glib_borrow(this))
786            }
787        }
788        unsafe {
789            let f: Box_<F> = Box_::new(f);
790            connect_raw(
791                self.as_ptr() as *mut _,
792                c"notify::visible-submenu".as_ptr(),
793                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
794                    notify_visible_submenu_trampoline::<F> as *const (),
795                )),
796                Box_::into_raw(f),
797            )
798        }
799    }
800}
801
802// rustdoc-stripper-ignore-next
803/// A [builder-pattern] type to construct [`PopoverMenu`] objects.
804///
805/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
806#[must_use = "The builder must be built to be used"]
807pub struct PopoverMenuBuilder {
808    builder: glib::object::ObjectBuilder<'static, PopoverMenu>,
809}
810
811impl PopoverMenuBuilder {
812    fn new() -> Self {
813        Self {
814            builder: glib::object::Object::builder(),
815        }
816    }
817
818    /// The flags that @popover uses to create/display a menu from its model.
819    ///
820    /// If a model is set and the flags change, contents are rebuilt, so if setting
821    /// properties individually, set flags before model to avoid a redundant rebuild.
822    #[cfg(feature = "v4_14")]
823    #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
824    pub fn flags(self, flags: PopoverMenuFlags) -> Self {
825        Self {
826            builder: self.builder.property("flags", flags),
827        }
828    }
829
830    /// The model from which the menu is made.
831    pub fn menu_model(self, menu_model: &impl IsA<gio::MenuModel>) -> Self {
832        Self {
833            builder: self
834                .builder
835                .property("menu-model", menu_model.clone().upcast()),
836        }
837    }
838
839    /// The name of the visible submenu.
840    pub fn visible_submenu(self, visible_submenu: impl Into<glib::GString>) -> Self {
841        Self {
842            builder: self
843                .builder
844                .property("visible-submenu", visible_submenu.into()),
845        }
846    }
847
848    /// Whether to dismiss the popover on outside clicks.
849    ///
850    /// If false, the popover won't automatically grab the focus when shown.
851    /// This is useful for usecases like entry completion, where the focus is
852    /// expected to stay on the entry.
853    pub fn autohide(self, autohide: bool) -> Self {
854        Self {
855            builder: self.builder.property("autohide", autohide),
856        }
857    }
858
859    /// Whether the popover pops down after a child popover.
860    ///
861    /// This is used to implement the expected behavior of submenus.
862    pub fn cascade_popdown(self, cascade_popdown: bool) -> Self {
863        Self {
864            builder: self.builder.property("cascade-popdown", cascade_popdown),
865        }
866    }
867
868    /// The child widget.
869    pub fn child(self, child: &impl IsA<Widget>) -> Self {
870        Self {
871            builder: self.builder.property("child", child.clone().upcast()),
872        }
873    }
874
875    /// The default widget inside the popover.
876    pub fn default_widget(self, default_widget: &impl IsA<Widget>) -> Self {
877        Self {
878            builder: self
879                .builder
880                .property("default-widget", default_widget.clone().upcast()),
881        }
882    }
883
884    /// Whether to draw an arrow.
885    pub fn has_arrow(self, has_arrow: bool) -> Self {
886        Self {
887            builder: self.builder.property("has-arrow", has_arrow),
888        }
889    }
890
891    /// Whether mnemonics are currently visible in this popover.
892    pub fn mnemonics_visible(self, mnemonics_visible: bool) -> Self {
893        Self {
894            builder: self
895                .builder
896                .property("mnemonics-visible", mnemonics_visible),
897        }
898    }
899
900    /// Rectangle in the parent widget that the popover points to.
901    pub fn pointing_to(self, pointing_to: &gdk::Rectangle) -> Self {
902        Self {
903            builder: self.builder.property("pointing-to", pointing_to),
904        }
905    }
906
907    /// How to place the popover, relative to its parent.
908    pub fn position(self, position: PositionType) -> Self {
909        Self {
910            builder: self.builder.property("position", position),
911        }
912    }
913
914    /// Whether the widget or any of its descendents can accept
915    /// the input focus.
916    ///
917    /// This property is meant to be set by widget implementations,
918    /// typically in their instance init function.
919    pub fn can_focus(self, can_focus: bool) -> Self {
920        Self {
921            builder: self.builder.property("can-focus", can_focus),
922        }
923    }
924
925    /// Whether the widget can receive pointer events.
926    pub fn can_target(self, can_target: bool) -> Self {
927        Self {
928            builder: self.builder.property("can-target", can_target),
929        }
930    }
931
932    /// A list of css classes applied to this widget.
933    pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
934        Self {
935            builder: self.builder.property("css-classes", css_classes.into()),
936        }
937    }
938
939    /// The name of this widget in the CSS tree.
940    ///
941    /// This property is meant to be set by widget implementations,
942    /// typically in their instance init function.
943    pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
944        Self {
945            builder: self.builder.property("css-name", css_name.into()),
946        }
947    }
948
949    /// The cursor used by @widget.
950    pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
951        Self {
952            builder: self.builder.property("cursor", cursor.clone()),
953        }
954    }
955
956    /// Whether the widget should grab focus when it is clicked with the mouse.
957    ///
958    /// This property is only relevant for widgets that can take focus.
959    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
960        Self {
961            builder: self.builder.property("focus-on-click", focus_on_click),
962        }
963    }
964
965    /// Whether this widget itself will accept the input focus.
966    pub fn focusable(self, focusable: bool) -> Self {
967        Self {
968            builder: self.builder.property("focusable", focusable),
969        }
970    }
971
972    /// How to distribute horizontal space if widget gets extra space.
973    pub fn halign(self, halign: Align) -> Self {
974        Self {
975            builder: self.builder.property("halign", halign),
976        }
977    }
978
979    /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
980    /// signal on @widget.
981    ///
982    /// A true value indicates that @widget can have a tooltip, in this case
983    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
984    /// determine whether it will provide a tooltip or not.
985    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
986        Self {
987            builder: self.builder.property("has-tooltip", has_tooltip),
988        }
989    }
990
991    /// Overrides for height request of the widget.
992    ///
993    /// If this is -1, the natural request will be used.
994    pub fn height_request(self, height_request: i32) -> Self {
995        Self {
996            builder: self.builder.property("height-request", height_request),
997        }
998    }
999
1000    /// Whether to expand horizontally.
1001    pub fn hexpand(self, hexpand: bool) -> Self {
1002        Self {
1003            builder: self.builder.property("hexpand", hexpand),
1004        }
1005    }
1006
1007    /// Whether to use the `hexpand` property.
1008    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
1009        Self {
1010            builder: self.builder.property("hexpand-set", hexpand_set),
1011        }
1012    }
1013
1014    /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
1015    /// the preferred size of the widget, and allocate its children.
1016    ///
1017    /// This property is meant to be set by widget implementations,
1018    /// typically in their instance init function.
1019    pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
1020        Self {
1021            builder: self
1022                .builder
1023                .property("layout-manager", layout_manager.clone().upcast()),
1024        }
1025    }
1026
1027    /// Makes this widget act like a modal dialog, with respect to
1028    /// event delivery.
1029    ///
1030    /// Global event controllers will not handle events with targets
1031    /// inside the widget, unless they are set up to ignore propagation
1032    /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
1033    #[cfg(feature = "v4_18")]
1034    #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
1035    pub fn limit_events(self, limit_events: bool) -> Self {
1036        Self {
1037            builder: self.builder.property("limit-events", limit_events),
1038        }
1039    }
1040
1041    /// Margin on bottom side of widget.
1042    ///
1043    /// This property adds margin outside of the widget's normal size
1044    /// request, the margin will be added in addition to the size from
1045    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1046    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
1047        Self {
1048            builder: self.builder.property("margin-bottom", margin_bottom),
1049        }
1050    }
1051
1052    /// Margin on end of widget, horizontally.
1053    ///
1054    /// This property supports left-to-right and right-to-left text
1055    /// directions.
1056    ///
1057    /// This property adds margin outside of the widget's normal size
1058    /// request, the margin will be added in addition to the size from
1059    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1060    pub fn margin_end(self, margin_end: i32) -> Self {
1061        Self {
1062            builder: self.builder.property("margin-end", margin_end),
1063        }
1064    }
1065
1066    /// Margin on start of widget, horizontally.
1067    ///
1068    /// This property supports left-to-right and right-to-left text
1069    /// directions.
1070    ///
1071    /// This property adds margin outside of the widget's normal size
1072    /// request, the margin will be added in addition to the size from
1073    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1074    pub fn margin_start(self, margin_start: i32) -> Self {
1075        Self {
1076            builder: self.builder.property("margin-start", margin_start),
1077        }
1078    }
1079
1080    /// Margin on top side of widget.
1081    ///
1082    /// This property adds margin outside of the widget's normal size
1083    /// request, the margin will be added in addition to the size from
1084    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1085    pub fn margin_top(self, margin_top: i32) -> Self {
1086        Self {
1087            builder: self.builder.property("margin-top", margin_top),
1088        }
1089    }
1090
1091    /// The name of the widget.
1092    pub fn name(self, name: impl Into<glib::GString>) -> Self {
1093        Self {
1094            builder: self.builder.property("name", name.into()),
1095        }
1096    }
1097
1098    /// The requested opacity of the widget.
1099    pub fn opacity(self, opacity: f64) -> Self {
1100        Self {
1101            builder: self.builder.property("opacity", opacity),
1102        }
1103    }
1104
1105    /// How content outside the widget's content area is treated.
1106    ///
1107    /// This property is meant to be set by widget implementations,
1108    /// typically in their instance init function.
1109    pub fn overflow(self, overflow: Overflow) -> Self {
1110        Self {
1111            builder: self.builder.property("overflow", overflow),
1112        }
1113    }
1114
1115    /// Whether the widget will receive the default action when it is focused.
1116    pub fn receives_default(self, receives_default: bool) -> Self {
1117        Self {
1118            builder: self.builder.property("receives-default", receives_default),
1119        }
1120    }
1121
1122    /// Whether the widget responds to input.
1123    pub fn sensitive(self, sensitive: bool) -> Self {
1124        Self {
1125            builder: self.builder.property("sensitive", sensitive),
1126        }
1127    }
1128
1129    /// Sets the text of tooltip to be the given string, which is marked up
1130    /// with Pango markup.
1131    ///
1132    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
1133    ///
1134    /// This is a convenience property which will take care of getting the
1135    /// tooltip shown if the given string is not `NULL`:
1136    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1137    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1138    /// the default signal handler.
1139    ///
1140    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1141    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1142    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
1143        Self {
1144            builder: self
1145                .builder
1146                .property("tooltip-markup", tooltip_markup.into()),
1147        }
1148    }
1149
1150    /// Sets the text of tooltip to be the given string.
1151    ///
1152    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
1153    ///
1154    /// This is a convenience property which will take care of getting the
1155    /// tooltip shown if the given string is not `NULL`:
1156    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1157    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1158    /// the default signal handler.
1159    ///
1160    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1161    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1162    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
1163        Self {
1164            builder: self.builder.property("tooltip-text", tooltip_text.into()),
1165        }
1166    }
1167
1168    /// How to distribute vertical space if widget gets extra space.
1169    pub fn valign(self, valign: Align) -> Self {
1170        Self {
1171            builder: self.builder.property("valign", valign),
1172        }
1173    }
1174
1175    /// Whether to expand vertically.
1176    pub fn vexpand(self, vexpand: bool) -> Self {
1177        Self {
1178            builder: self.builder.property("vexpand", vexpand),
1179        }
1180    }
1181
1182    /// Whether to use the `vexpand` property.
1183    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
1184        Self {
1185            builder: self.builder.property("vexpand-set", vexpand_set),
1186        }
1187    }
1188
1189    /// Whether the widget is visible.
1190    pub fn visible(self, visible: bool) -> Self {
1191        Self {
1192            builder: self.builder.property("visible", visible),
1193        }
1194    }
1195
1196    /// Overrides for width request of the widget.
1197    ///
1198    /// If this is -1, the natural request will be used.
1199    pub fn width_request(self, width_request: i32) -> Self {
1200        Self {
1201            builder: self.builder.property("width-request", width_request),
1202        }
1203    }
1204
1205    /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
1206    ///
1207    /// The accessible role cannot be changed once set.
1208    pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
1209        Self {
1210            builder: self.builder.property("accessible-role", accessible_role),
1211        }
1212    }
1213
1214    // rustdoc-stripper-ignore-next
1215    /// Build the [`PopoverMenu`].
1216    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
1217    pub fn build(self) -> PopoverMenu {
1218        assert_initialized_main_thread!();
1219        self.builder.build()
1220    }
1221}