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