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