1use 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 #[doc(alias = "GtkPopoverMenu")]
18 pub struct PopoverMenu(Object<ffi::GtkPopoverMenu>) @extends Popover, Widget, @implements Accessible, Buildable, ConstraintTarget, Native, ShortcutManager;
19
20 match fn {
21 type_ => || ffi::gtk_popover_menu_get_type(),
22 }
23}
24
25impl PopoverMenu {
26 #[doc(alias = "gtk_popover_menu_new_from_model")]
27 #[doc(alias = "new_from_model")]
28 pub fn from_model(model: Option<&impl IsA<gio::MenuModel>>) -> PopoverMenu {
29 assert_initialized_main_thread!();
30 unsafe {
31 Widget::from_glib_none(ffi::gtk_popover_menu_new_from_model(
32 model.map(|p| p.as_ref()).to_glib_none().0,
33 ))
34 .unsafe_cast()
35 }
36 }
37
38 #[doc(alias = "gtk_popover_menu_new_from_model_full")]
39 #[doc(alias = "new_from_model_full")]
40 pub fn from_model_full(
41 model: &impl IsA<gio::MenuModel>,
42 flags: PopoverMenuFlags,
43 ) -> PopoverMenu {
44 assert_initialized_main_thread!();
45 unsafe {
46 Widget::from_glib_none(ffi::gtk_popover_menu_new_from_model_full(
47 model.as_ref().to_glib_none().0,
48 flags.into_glib(),
49 ))
50 .unsafe_cast()
51 }
52 }
53
54 pub fn builder() -> PopoverMenuBuilder {
59 PopoverMenuBuilder::new()
60 }
61
62 #[doc(alias = "gtk_popover_menu_add_child")]
63 pub fn add_child(&self, child: &impl IsA<Widget>, id: &str) -> bool {
64 unsafe {
65 from_glib(ffi::gtk_popover_menu_add_child(
66 self.to_glib_none().0,
67 child.as_ref().to_glib_none().0,
68 id.to_glib_none().0,
69 ))
70 }
71 }
72
73 #[cfg(feature = "v4_14")]
74 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
75 #[doc(alias = "gtk_popover_menu_get_flags")]
76 #[doc(alias = "get_flags")]
77 pub fn flags(&self) -> PopoverMenuFlags {
78 unsafe { from_glib(ffi::gtk_popover_menu_get_flags(self.to_glib_none().0)) }
79 }
80
81 #[doc(alias = "gtk_popover_menu_get_menu_model")]
82 #[doc(alias = "get_menu_model")]
83 #[doc(alias = "menu-model")]
84 pub fn menu_model(&self) -> Option<gio::MenuModel> {
85 unsafe { from_glib_none(ffi::gtk_popover_menu_get_menu_model(self.to_glib_none().0)) }
86 }
87
88 #[doc(alias = "gtk_popover_menu_remove_child")]
89 pub fn remove_child(&self, child: &impl IsA<Widget>) -> bool {
90 unsafe {
91 from_glib(ffi::gtk_popover_menu_remove_child(
92 self.to_glib_none().0,
93 child.as_ref().to_glib_none().0,
94 ))
95 }
96 }
97
98 #[cfg(feature = "v4_14")]
99 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
100 #[doc(alias = "gtk_popover_menu_set_flags")]
101 #[doc(alias = "flags")]
102 pub fn set_flags(&self, flags: PopoverMenuFlags) {
103 unsafe {
104 ffi::gtk_popover_menu_set_flags(self.to_glib_none().0, flags.into_glib());
105 }
106 }
107
108 #[doc(alias = "gtk_popover_menu_set_menu_model")]
109 #[doc(alias = "menu-model")]
110 pub fn set_menu_model(&self, model: Option<&impl IsA<gio::MenuModel>>) {
111 unsafe {
112 ffi::gtk_popover_menu_set_menu_model(
113 self.to_glib_none().0,
114 model.map(|p| p.as_ref()).to_glib_none().0,
115 );
116 }
117 }
118
119 #[doc(alias = "visible-submenu")]
120 pub fn visible_submenu(&self) -> Option<glib::GString> {
121 ObjectExt::property(self, "visible-submenu")
122 }
123
124 #[doc(alias = "visible-submenu")]
125 pub fn set_visible_submenu(&self, visible_submenu: Option<&str>) {
126 ObjectExt::set_property(self, "visible-submenu", visible_submenu)
127 }
128
129 #[cfg(feature = "v4_14")]
130 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
131 #[doc(alias = "flags")]
132 pub fn connect_flags_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
133 unsafe extern "C" fn notify_flags_trampoline<F: Fn(&PopoverMenu) + 'static>(
134 this: *mut ffi::GtkPopoverMenu,
135 _param_spec: glib::ffi::gpointer,
136 f: glib::ffi::gpointer,
137 ) {
138 let f: &F = &*(f as *const F);
139 f(&from_glib_borrow(this))
140 }
141 unsafe {
142 let f: Box_<F> = Box_::new(f);
143 connect_raw(
144 self.as_ptr() as *mut _,
145 c"notify::flags".as_ptr() as *const _,
146 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
147 notify_flags_trampoline::<F> as *const (),
148 )),
149 Box_::into_raw(f),
150 )
151 }
152 }
153
154 #[doc(alias = "menu-model")]
155 pub fn connect_menu_model_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
156 unsafe extern "C" fn notify_menu_model_trampoline<F: Fn(&PopoverMenu) + 'static>(
157 this: *mut ffi::GtkPopoverMenu,
158 _param_spec: glib::ffi::gpointer,
159 f: glib::ffi::gpointer,
160 ) {
161 let f: &F = &*(f as *const F);
162 f(&from_glib_borrow(this))
163 }
164 unsafe {
165 let f: Box_<F> = Box_::new(f);
166 connect_raw(
167 self.as_ptr() as *mut _,
168 c"notify::menu-model".as_ptr() as *const _,
169 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
170 notify_menu_model_trampoline::<F> as *const (),
171 )),
172 Box_::into_raw(f),
173 )
174 }
175 }
176
177 #[doc(alias = "visible-submenu")]
178 pub fn connect_visible_submenu_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
179 unsafe extern "C" fn notify_visible_submenu_trampoline<F: Fn(&PopoverMenu) + 'static>(
180 this: *mut ffi::GtkPopoverMenu,
181 _param_spec: glib::ffi::gpointer,
182 f: glib::ffi::gpointer,
183 ) {
184 let f: &F = &*(f as *const F);
185 f(&from_glib_borrow(this))
186 }
187 unsafe {
188 let f: Box_<F> = Box_::new(f);
189 connect_raw(
190 self.as_ptr() as *mut _,
191 c"notify::visible-submenu".as_ptr() as *const _,
192 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
193 notify_visible_submenu_trampoline::<F> as *const (),
194 )),
195 Box_::into_raw(f),
196 )
197 }
198 }
199}
200
201#[must_use = "The builder must be built to be used"]
206pub struct PopoverMenuBuilder {
207 builder: glib::object::ObjectBuilder<'static, PopoverMenu>,
208}
209
210impl PopoverMenuBuilder {
211 fn new() -> Self {
212 Self {
213 builder: glib::object::Object::builder(),
214 }
215 }
216
217 #[cfg(feature = "v4_14")]
218 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
219 pub fn flags(self, flags: PopoverMenuFlags) -> Self {
220 Self {
221 builder: self.builder.property("flags", flags),
222 }
223 }
224
225 pub fn menu_model(self, menu_model: &impl IsA<gio::MenuModel>) -> Self {
226 Self {
227 builder: self
228 .builder
229 .property("menu-model", menu_model.clone().upcast()),
230 }
231 }
232
233 pub fn visible_submenu(self, visible_submenu: impl Into<glib::GString>) -> Self {
234 Self {
235 builder: self
236 .builder
237 .property("visible-submenu", visible_submenu.into()),
238 }
239 }
240
241 pub fn autohide(self, autohide: bool) -> Self {
242 Self {
243 builder: self.builder.property("autohide", autohide),
244 }
245 }
246
247 pub fn cascade_popdown(self, cascade_popdown: bool) -> Self {
248 Self {
249 builder: self.builder.property("cascade-popdown", cascade_popdown),
250 }
251 }
252
253 pub fn child(self, child: &impl IsA<Widget>) -> Self {
254 Self {
255 builder: self.builder.property("child", child.clone().upcast()),
256 }
257 }
258
259 pub fn default_widget(self, default_widget: &impl IsA<Widget>) -> Self {
260 Self {
261 builder: self
262 .builder
263 .property("default-widget", default_widget.clone().upcast()),
264 }
265 }
266
267 pub fn has_arrow(self, has_arrow: bool) -> Self {
268 Self {
269 builder: self.builder.property("has-arrow", has_arrow),
270 }
271 }
272
273 pub fn mnemonics_visible(self, mnemonics_visible: bool) -> Self {
274 Self {
275 builder: self
276 .builder
277 .property("mnemonics-visible", mnemonics_visible),
278 }
279 }
280
281 pub fn pointing_to(self, pointing_to: &gdk::Rectangle) -> Self {
282 Self {
283 builder: self.builder.property("pointing-to", pointing_to),
284 }
285 }
286
287 pub fn position(self, position: PositionType) -> Self {
288 Self {
289 builder: self.builder.property("position", position),
290 }
291 }
292
293 pub fn can_focus(self, can_focus: bool) -> Self {
294 Self {
295 builder: self.builder.property("can-focus", can_focus),
296 }
297 }
298
299 pub fn can_target(self, can_target: bool) -> Self {
300 Self {
301 builder: self.builder.property("can-target", can_target),
302 }
303 }
304
305 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
306 Self {
307 builder: self.builder.property("css-classes", css_classes.into()),
308 }
309 }
310
311 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
312 Self {
313 builder: self.builder.property("css-name", css_name.into()),
314 }
315 }
316
317 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
318 Self {
319 builder: self.builder.property("cursor", cursor.clone()),
320 }
321 }
322
323 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
324 Self {
325 builder: self.builder.property("focus-on-click", focus_on_click),
326 }
327 }
328
329 pub fn focusable(self, focusable: bool) -> Self {
330 Self {
331 builder: self.builder.property("focusable", focusable),
332 }
333 }
334
335 pub fn halign(self, halign: Align) -> Self {
336 Self {
337 builder: self.builder.property("halign", halign),
338 }
339 }
340
341 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
342 Self {
343 builder: self.builder.property("has-tooltip", has_tooltip),
344 }
345 }
346
347 pub fn height_request(self, height_request: i32) -> Self {
348 Self {
349 builder: self.builder.property("height-request", height_request),
350 }
351 }
352
353 pub fn hexpand(self, hexpand: bool) -> Self {
354 Self {
355 builder: self.builder.property("hexpand", hexpand),
356 }
357 }
358
359 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
360 Self {
361 builder: self.builder.property("hexpand-set", hexpand_set),
362 }
363 }
364
365 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
366 Self {
367 builder: self
368 .builder
369 .property("layout-manager", layout_manager.clone().upcast()),
370 }
371 }
372
373 #[cfg(feature = "v4_18")]
374 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
375 pub fn limit_events(self, limit_events: bool) -> Self {
376 Self {
377 builder: self.builder.property("limit-events", limit_events),
378 }
379 }
380
381 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
382 Self {
383 builder: self.builder.property("margin-bottom", margin_bottom),
384 }
385 }
386
387 pub fn margin_end(self, margin_end: i32) -> Self {
388 Self {
389 builder: self.builder.property("margin-end", margin_end),
390 }
391 }
392
393 pub fn margin_start(self, margin_start: i32) -> Self {
394 Self {
395 builder: self.builder.property("margin-start", margin_start),
396 }
397 }
398
399 pub fn margin_top(self, margin_top: i32) -> Self {
400 Self {
401 builder: self.builder.property("margin-top", margin_top),
402 }
403 }
404
405 pub fn name(self, name: impl Into<glib::GString>) -> Self {
406 Self {
407 builder: self.builder.property("name", name.into()),
408 }
409 }
410
411 pub fn opacity(self, opacity: f64) -> Self {
412 Self {
413 builder: self.builder.property("opacity", opacity),
414 }
415 }
416
417 pub fn overflow(self, overflow: Overflow) -> Self {
418 Self {
419 builder: self.builder.property("overflow", overflow),
420 }
421 }
422
423 pub fn receives_default(self, receives_default: bool) -> Self {
424 Self {
425 builder: self.builder.property("receives-default", receives_default),
426 }
427 }
428
429 pub fn sensitive(self, sensitive: bool) -> Self {
430 Self {
431 builder: self.builder.property("sensitive", sensitive),
432 }
433 }
434
435 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
436 Self {
437 builder: self
438 .builder
439 .property("tooltip-markup", tooltip_markup.into()),
440 }
441 }
442
443 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
444 Self {
445 builder: self.builder.property("tooltip-text", tooltip_text.into()),
446 }
447 }
448
449 pub fn valign(self, valign: Align) -> Self {
450 Self {
451 builder: self.builder.property("valign", valign),
452 }
453 }
454
455 pub fn vexpand(self, vexpand: bool) -> Self {
456 Self {
457 builder: self.builder.property("vexpand", vexpand),
458 }
459 }
460
461 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
462 Self {
463 builder: self.builder.property("vexpand-set", vexpand_set),
464 }
465 }
466
467 pub fn visible(self, visible: bool) -> Self {
468 Self {
469 builder: self.builder.property("visible", visible),
470 }
471 }
472
473 pub fn width_request(self, width_request: i32) -> Self {
474 Self {
475 builder: self.builder.property("width-request", width_request),
476 }
477 }
478
479 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
480 Self {
481 builder: self.builder.property("accessible-role", accessible_role),
482 }
483 }
484
485 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
488 pub fn build(self) -> PopoverMenu {
489 assert_initialized_main_thread!();
490 self.builder.build()
491 }
492}