1use gdk;
6use glib::object::Cast;
7use glib::object::IsA;
8use glib::signal::connect_raw;
9use glib::signal::SignalHandlerId;
10use glib::translate::*;
11use glib::GString;
12use glib::StaticType;
13use glib::ToValue;
14use glib::Value;
15use glib_sys;
16use gobject_sys;
17use gtk_sys;
18use std::boxed::Box as Box_;
19use std::fmt;
20use std::mem::transmute;
21use Align;
22use Bin;
23use Buildable;
24use Container;
25use Popover;
26#[cfg(any(feature = "v3_20", feature = "dox"))]
27use PopoverConstraint;
28use PositionType;
29use ResizeMode;
30use Widget;
31
32glib_wrapper! {
33 pub struct PopoverMenu(Object<gtk_sys::GtkPopoverMenu, gtk_sys::GtkPopoverMenuClass, PopoverMenuClass>) @extends Popover, Bin, Container, Widget, @implements Buildable;
34
35 match fn {
36 get_type => || gtk_sys::gtk_popover_menu_get_type(),
37 }
38}
39
40impl PopoverMenu {
41 #[cfg(any(feature = "v3_16", feature = "dox"))]
42 pub fn new() -> PopoverMenu {
43 assert_initialized_main_thread!();
44 unsafe { Widget::from_glib_none(gtk_sys::gtk_popover_menu_new()).unsafe_cast() }
45 }
46}
47
48#[cfg(any(feature = "v3_16", feature = "dox"))]
49impl Default for PopoverMenu {
50 fn default() -> Self {
51 Self::new()
52 }
53}
54
55pub struct PopoverMenuBuilder {
56 visible_submenu: Option<String>,
57 #[cfg(any(feature = "v3_20", feature = "dox"))]
58 constrain_to: Option<PopoverConstraint>,
59 modal: Option<bool>,
60 pointing_to: Option<gdk::Rectangle>,
61 position: Option<PositionType>,
62 relative_to: Option<Widget>,
63 #[cfg(any(feature = "v3_16", feature = "dox"))]
64 transitions_enabled: Option<bool>,
65 border_width: Option<u32>,
66 child: Option<Widget>,
67 resize_mode: Option<ResizeMode>,
68 app_paintable: Option<bool>,
69 can_default: Option<bool>,
70 can_focus: Option<bool>,
71 events: Option<gdk::EventMask>,
72 expand: Option<bool>,
73 #[cfg(any(feature = "v3_20", feature = "dox"))]
74 focus_on_click: Option<bool>,
75 halign: Option<Align>,
76 has_default: Option<bool>,
77 has_focus: Option<bool>,
78 has_tooltip: Option<bool>,
79 height_request: Option<i32>,
80 hexpand: Option<bool>,
81 hexpand_set: Option<bool>,
82 is_focus: Option<bool>,
83 margin: Option<i32>,
84 margin_bottom: Option<i32>,
85 margin_end: Option<i32>,
86 margin_start: Option<i32>,
87 margin_top: Option<i32>,
88 name: Option<String>,
89 no_show_all: Option<bool>,
90 opacity: Option<f64>,
91 parent: Option<Container>,
92 receives_default: Option<bool>,
93 sensitive: Option<bool>,
94 tooltip_markup: Option<String>,
96 tooltip_text: Option<String>,
97 valign: Option<Align>,
98 vexpand: Option<bool>,
99 vexpand_set: Option<bool>,
100 visible: Option<bool>,
101 width_request: Option<i32>,
102}
103
104impl PopoverMenuBuilder {
105 pub fn new() -> Self {
106 Self {
107 visible_submenu: None,
108 #[cfg(any(feature = "v3_20", feature = "dox"))]
109 constrain_to: None,
110 modal: None,
111 pointing_to: None,
112 position: None,
113 relative_to: None,
114 #[cfg(any(feature = "v3_16", feature = "dox"))]
115 transitions_enabled: None,
116 border_width: None,
117 child: None,
118 resize_mode: None,
119 app_paintable: None,
120 can_default: None,
121 can_focus: None,
122 events: None,
123 expand: None,
124 #[cfg(any(feature = "v3_20", feature = "dox"))]
125 focus_on_click: None,
126 halign: None,
127 has_default: None,
128 has_focus: None,
129 has_tooltip: None,
130 height_request: None,
131 hexpand: None,
132 hexpand_set: None,
133 is_focus: None,
134 margin: None,
135 margin_bottom: None,
136 margin_end: None,
137 margin_start: None,
138 margin_top: None,
139 name: None,
140 no_show_all: None,
141 opacity: None,
142 parent: None,
143 receives_default: None,
144 sensitive: None,
145 tooltip_markup: None,
146 tooltip_text: None,
147 valign: None,
148 vexpand: None,
149 vexpand_set: None,
150 visible: None,
151 width_request: None,
152 }
153 }
154
155 pub fn build(self) -> PopoverMenu {
156 let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
157 if let Some(ref visible_submenu) = self.visible_submenu {
158 properties.push(("visible-submenu", visible_submenu));
159 }
160 #[cfg(any(feature = "v3_20", feature = "dox"))]
161 {
162 if let Some(ref constrain_to) = self.constrain_to {
163 properties.push(("constrain-to", constrain_to));
164 }
165 }
166 if let Some(ref modal) = self.modal {
167 properties.push(("modal", modal));
168 }
169 if let Some(ref pointing_to) = self.pointing_to {
170 properties.push(("pointing-to", pointing_to));
171 }
172 if let Some(ref position) = self.position {
173 properties.push(("position", position));
174 }
175 if let Some(ref relative_to) = self.relative_to {
176 properties.push(("relative-to", relative_to));
177 }
178 #[cfg(any(feature = "v3_16", feature = "dox"))]
179 {
180 if let Some(ref transitions_enabled) = self.transitions_enabled {
181 properties.push(("transitions-enabled", transitions_enabled));
182 }
183 }
184 if let Some(ref border_width) = self.border_width {
185 properties.push(("border-width", border_width));
186 }
187 if let Some(ref child) = self.child {
188 properties.push(("child", child));
189 }
190 if let Some(ref resize_mode) = self.resize_mode {
191 properties.push(("resize-mode", resize_mode));
192 }
193 if let Some(ref app_paintable) = self.app_paintable {
194 properties.push(("app-paintable", app_paintable));
195 }
196 if let Some(ref can_default) = self.can_default {
197 properties.push(("can-default", can_default));
198 }
199 if let Some(ref can_focus) = self.can_focus {
200 properties.push(("can-focus", can_focus));
201 }
202 if let Some(ref events) = self.events {
203 properties.push(("events", events));
204 }
205 if let Some(ref expand) = self.expand {
206 properties.push(("expand", expand));
207 }
208 #[cfg(any(feature = "v3_20", feature = "dox"))]
209 {
210 if let Some(ref focus_on_click) = self.focus_on_click {
211 properties.push(("focus-on-click", focus_on_click));
212 }
213 }
214 if let Some(ref halign) = self.halign {
215 properties.push(("halign", halign));
216 }
217 if let Some(ref has_default) = self.has_default {
218 properties.push(("has-default", has_default));
219 }
220 if let Some(ref has_focus) = self.has_focus {
221 properties.push(("has-focus", has_focus));
222 }
223 if let Some(ref has_tooltip) = self.has_tooltip {
224 properties.push(("has-tooltip", has_tooltip));
225 }
226 if let Some(ref height_request) = self.height_request {
227 properties.push(("height-request", height_request));
228 }
229 if let Some(ref hexpand) = self.hexpand {
230 properties.push(("hexpand", hexpand));
231 }
232 if let Some(ref hexpand_set) = self.hexpand_set {
233 properties.push(("hexpand-set", hexpand_set));
234 }
235 if let Some(ref is_focus) = self.is_focus {
236 properties.push(("is-focus", is_focus));
237 }
238 if let Some(ref margin) = self.margin {
239 properties.push(("margin", margin));
240 }
241 if let Some(ref margin_bottom) = self.margin_bottom {
242 properties.push(("margin-bottom", margin_bottom));
243 }
244 if let Some(ref margin_end) = self.margin_end {
245 properties.push(("margin-end", margin_end));
246 }
247 if let Some(ref margin_start) = self.margin_start {
248 properties.push(("margin-start", margin_start));
249 }
250 if let Some(ref margin_top) = self.margin_top {
251 properties.push(("margin-top", margin_top));
252 }
253 if let Some(ref name) = self.name {
254 properties.push(("name", name));
255 }
256 if let Some(ref no_show_all) = self.no_show_all {
257 properties.push(("no-show-all", no_show_all));
258 }
259 if let Some(ref opacity) = self.opacity {
260 properties.push(("opacity", opacity));
261 }
262 if let Some(ref parent) = self.parent {
263 properties.push(("parent", parent));
264 }
265 if let Some(ref receives_default) = self.receives_default {
266 properties.push(("receives-default", receives_default));
267 }
268 if let Some(ref sensitive) = self.sensitive {
269 properties.push(("sensitive", sensitive));
270 }
271 if let Some(ref tooltip_markup) = self.tooltip_markup {
272 properties.push(("tooltip-markup", tooltip_markup));
273 }
274 if let Some(ref tooltip_text) = self.tooltip_text {
275 properties.push(("tooltip-text", tooltip_text));
276 }
277 if let Some(ref valign) = self.valign {
278 properties.push(("valign", valign));
279 }
280 if let Some(ref vexpand) = self.vexpand {
281 properties.push(("vexpand", vexpand));
282 }
283 if let Some(ref vexpand_set) = self.vexpand_set {
284 properties.push(("vexpand-set", vexpand_set));
285 }
286 if let Some(ref visible) = self.visible {
287 properties.push(("visible", visible));
288 }
289 if let Some(ref width_request) = self.width_request {
290 properties.push(("width-request", width_request));
291 }
292 glib::Object::new(PopoverMenu::static_type(), &properties)
293 .expect("object new")
294 .downcast()
295 .expect("downcast")
296 }
297
298 pub fn visible_submenu(mut self, visible_submenu: &str) -> Self {
299 self.visible_submenu = Some(visible_submenu.to_string());
300 self
301 }
302
303 #[cfg(any(feature = "v3_20", feature = "dox"))]
304 pub fn constrain_to(mut self, constrain_to: PopoverConstraint) -> Self {
305 self.constrain_to = Some(constrain_to);
306 self
307 }
308
309 pub fn modal(mut self, modal: bool) -> Self {
310 self.modal = Some(modal);
311 self
312 }
313
314 pub fn pointing_to(mut self, pointing_to: &gdk::Rectangle) -> Self {
315 self.pointing_to = Some(pointing_to.clone());
316 self
317 }
318
319 pub fn position(mut self, position: PositionType) -> Self {
320 self.position = Some(position);
321 self
322 }
323
324 pub fn relative_to(mut self, relative_to: &Widget) -> Self {
325 self.relative_to = Some(relative_to.clone());
326 self
327 }
328
329 #[cfg(any(feature = "v3_16", feature = "dox"))]
330 pub fn transitions_enabled(mut self, transitions_enabled: bool) -> Self {
331 self.transitions_enabled = Some(transitions_enabled);
332 self
333 }
334
335 pub fn border_width(mut self, border_width: u32) -> Self {
336 self.border_width = Some(border_width);
337 self
338 }
339
340 pub fn child(mut self, child: &Widget) -> Self {
341 self.child = Some(child.clone());
342 self
343 }
344
345 pub fn resize_mode(mut self, resize_mode: ResizeMode) -> Self {
346 self.resize_mode = Some(resize_mode);
347 self
348 }
349
350 pub fn app_paintable(mut self, app_paintable: bool) -> Self {
351 self.app_paintable = Some(app_paintable);
352 self
353 }
354
355 pub fn can_default(mut self, can_default: bool) -> Self {
356 self.can_default = Some(can_default);
357 self
358 }
359
360 pub fn can_focus(mut self, can_focus: bool) -> Self {
361 self.can_focus = Some(can_focus);
362 self
363 }
364
365 pub fn events(mut self, events: gdk::EventMask) -> Self {
366 self.events = Some(events);
367 self
368 }
369
370 pub fn expand(mut self, expand: bool) -> Self {
371 self.expand = Some(expand);
372 self
373 }
374
375 #[cfg(any(feature = "v3_20", feature = "dox"))]
376 pub fn focus_on_click(mut self, focus_on_click: bool) -> Self {
377 self.focus_on_click = Some(focus_on_click);
378 self
379 }
380
381 pub fn halign(mut self, halign: Align) -> Self {
382 self.halign = Some(halign);
383 self
384 }
385
386 pub fn has_default(mut self, has_default: bool) -> Self {
387 self.has_default = Some(has_default);
388 self
389 }
390
391 pub fn has_focus(mut self, has_focus: bool) -> Self {
392 self.has_focus = Some(has_focus);
393 self
394 }
395
396 pub fn has_tooltip(mut self, has_tooltip: bool) -> Self {
397 self.has_tooltip = Some(has_tooltip);
398 self
399 }
400
401 pub fn height_request(mut self, height_request: i32) -> Self {
402 self.height_request = Some(height_request);
403 self
404 }
405
406 pub fn hexpand(mut self, hexpand: bool) -> Self {
407 self.hexpand = Some(hexpand);
408 self
409 }
410
411 pub fn hexpand_set(mut self, hexpand_set: bool) -> Self {
412 self.hexpand_set = Some(hexpand_set);
413 self
414 }
415
416 pub fn is_focus(mut self, is_focus: bool) -> Self {
417 self.is_focus = Some(is_focus);
418 self
419 }
420
421 pub fn margin(mut self, margin: i32) -> Self {
422 self.margin = Some(margin);
423 self
424 }
425
426 pub fn margin_bottom(mut self, margin_bottom: i32) -> Self {
427 self.margin_bottom = Some(margin_bottom);
428 self
429 }
430
431 pub fn margin_end(mut self, margin_end: i32) -> Self {
432 self.margin_end = Some(margin_end);
433 self
434 }
435
436 pub fn margin_start(mut self, margin_start: i32) -> Self {
437 self.margin_start = Some(margin_start);
438 self
439 }
440
441 pub fn margin_top(mut self, margin_top: i32) -> Self {
442 self.margin_top = Some(margin_top);
443 self
444 }
445
446 pub fn name(mut self, name: &str) -> Self {
447 self.name = Some(name.to_string());
448 self
449 }
450
451 pub fn no_show_all(mut self, no_show_all: bool) -> Self {
452 self.no_show_all = Some(no_show_all);
453 self
454 }
455
456 pub fn opacity(mut self, opacity: f64) -> Self {
457 self.opacity = Some(opacity);
458 self
459 }
460
461 pub fn parent(mut self, parent: &Container) -> Self {
462 self.parent = Some(parent.clone());
463 self
464 }
465
466 pub fn receives_default(mut self, receives_default: bool) -> Self {
467 self.receives_default = Some(receives_default);
468 self
469 }
470
471 pub fn sensitive(mut self, sensitive: bool) -> Self {
472 self.sensitive = Some(sensitive);
473 self
474 }
475
476 pub fn tooltip_markup(mut self, tooltip_markup: &str) -> Self {
477 self.tooltip_markup = Some(tooltip_markup.to_string());
478 self
479 }
480
481 pub fn tooltip_text(mut self, tooltip_text: &str) -> Self {
482 self.tooltip_text = Some(tooltip_text.to_string());
483 self
484 }
485
486 pub fn valign(mut self, valign: Align) -> Self {
487 self.valign = Some(valign);
488 self
489 }
490
491 pub fn vexpand(mut self, vexpand: bool) -> Self {
492 self.vexpand = Some(vexpand);
493 self
494 }
495
496 pub fn vexpand_set(mut self, vexpand_set: bool) -> Self {
497 self.vexpand_set = Some(vexpand_set);
498 self
499 }
500
501 pub fn visible(mut self, visible: bool) -> Self {
502 self.visible = Some(visible);
503 self
504 }
505
506 pub fn width_request(mut self, width_request: i32) -> Self {
507 self.width_request = Some(width_request);
508 self
509 }
510}
511
512pub const NONE_POPOVER_MENU: Option<&PopoverMenu> = None;
513
514pub trait PopoverMenuExt: 'static {
515 #[cfg(any(feature = "v3_16", feature = "dox"))]
516 fn open_submenu(&self, name: &str);
517
518 fn get_property_visible_submenu(&self) -> Option<GString>;
519
520 fn set_property_visible_submenu(&self, visible_submenu: Option<&str>);
521
522 fn get_child_position<T: IsA<Widget>>(&self, item: &T) -> i32;
523
524 fn set_child_position<T: IsA<Widget>>(&self, item: &T, position: i32);
525
526 fn get_child_submenu<T: IsA<Widget>>(&self, item: &T) -> Option<GString>;
527
528 fn set_child_submenu<T: IsA<Widget>>(&self, item: &T, submenu: Option<&str>);
529
530 fn connect_property_visible_submenu_notify<F: Fn(&Self) + 'static>(
531 &self,
532 f: F,
533 ) -> SignalHandlerId;
534}
535
536impl<O: IsA<PopoverMenu>> PopoverMenuExt for O {
537 #[cfg(any(feature = "v3_16", feature = "dox"))]
538 fn open_submenu(&self, name: &str) {
539 unsafe {
540 gtk_sys::gtk_popover_menu_open_submenu(
541 self.as_ref().to_glib_none().0,
542 name.to_glib_none().0,
543 );
544 }
545 }
546
547 fn get_property_visible_submenu(&self) -> Option<GString> {
548 unsafe {
549 let mut value = Value::from_type(<GString as StaticType>::static_type());
550 gobject_sys::g_object_get_property(
551 self.to_glib_none().0 as *mut gobject_sys::GObject,
552 b"visible-submenu\0".as_ptr() as *const _,
553 value.to_glib_none_mut().0,
554 );
555 value.get()
556 }
557 }
558
559 fn set_property_visible_submenu(&self, visible_submenu: Option<&str>) {
560 unsafe {
561 gobject_sys::g_object_set_property(
562 self.to_glib_none().0 as *mut gobject_sys::GObject,
563 b"visible-submenu\0".as_ptr() as *const _,
564 Value::from(visible_submenu).to_glib_none().0,
565 );
566 }
567 }
568
569 fn get_child_position<T: IsA<Widget>>(&self, item: &T) -> i32 {
570 unsafe {
571 let mut value = Value::from_type(<i32 as StaticType>::static_type());
572 gtk_sys::gtk_container_child_get_property(
573 self.to_glib_none().0 as *mut gtk_sys::GtkContainer,
574 item.to_glib_none().0 as *mut _,
575 b"position\0".as_ptr() as *const _,
576 value.to_glib_none_mut().0,
577 );
578 value.get().unwrap()
579 }
580 }
581
582 fn set_child_position<T: IsA<Widget>>(&self, item: &T, position: i32) {
583 unsafe {
584 gtk_sys::gtk_container_child_set_property(
585 self.to_glib_none().0 as *mut gtk_sys::GtkContainer,
586 item.to_glib_none().0 as *mut _,
587 b"position\0".as_ptr() as *const _,
588 Value::from(&position).to_glib_none().0,
589 );
590 }
591 }
592
593 fn get_child_submenu<T: IsA<Widget>>(&self, item: &T) -> Option<GString> {
594 unsafe {
595 let mut value = Value::from_type(<GString as StaticType>::static_type());
596 gtk_sys::gtk_container_child_get_property(
597 self.to_glib_none().0 as *mut gtk_sys::GtkContainer,
598 item.to_glib_none().0 as *mut _,
599 b"submenu\0".as_ptr() as *const _,
600 value.to_glib_none_mut().0,
601 );
602 value.get()
603 }
604 }
605
606 fn set_child_submenu<T: IsA<Widget>>(&self, item: &T, submenu: Option<&str>) {
607 unsafe {
608 gtk_sys::gtk_container_child_set_property(
609 self.to_glib_none().0 as *mut gtk_sys::GtkContainer,
610 item.to_glib_none().0 as *mut _,
611 b"submenu\0".as_ptr() as *const _,
612 Value::from(submenu).to_glib_none().0,
613 );
614 }
615 }
616
617 fn connect_property_visible_submenu_notify<F: Fn(&Self) + 'static>(
618 &self,
619 f: F,
620 ) -> SignalHandlerId {
621 unsafe extern "C" fn notify_visible_submenu_trampoline<P, F: Fn(&P) + 'static>(
622 this: *mut gtk_sys::GtkPopoverMenu,
623 _param_spec: glib_sys::gpointer,
624 f: glib_sys::gpointer,
625 ) where
626 P: IsA<PopoverMenu>,
627 {
628 let f: &F = &*(f as *const F);
629 f(&PopoverMenu::from_glib_borrow(this).unsafe_cast())
630 }
631 unsafe {
632 let f: Box_<F> = Box_::new(f);
633 connect_raw(
634 self.as_ptr() as *mut _,
635 b"notify::visible-submenu\0".as_ptr() as *const _,
636 Some(transmute(
637 notify_visible_submenu_trampoline::<Self, F> as usize,
638 )),
639 Box_::into_raw(f),
640 )
641 }
642 }
643}
644
645impl fmt::Display for PopoverMenu {
646 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
647 write!(f, "PopoverMenu")
648 }
649}