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