1use gdk;
6use glib;
7use glib::object::Cast;
8use glib::object::IsA;
9use glib::object::ObjectExt;
10use glib::signal::connect_raw;
11use glib::signal::SignalHandlerId;
12use glib::translate::*;
13use glib::GString;
14use glib::StaticType;
15use glib::ToValue;
16use glib::Value;
17use glib_sys;
18use gobject_sys;
19use gtk_sys;
20use libc;
21use std::boxed::Box as Box_;
22use std::fmt;
23use std::mem::transmute;
24use Actionable;
25use Align;
26use Bin;
27use Buildable;
28use Container;
29use Menu;
30use ResizeMode;
31use Widget;
32
33glib_wrapper! {
34 pub struct MenuItem(Object<gtk_sys::GtkMenuItem, gtk_sys::GtkMenuItemClass, MenuItemClass>) @extends Bin, Container, Widget, @implements Buildable, Actionable;
35
36 match fn {
37 get_type => || gtk_sys::gtk_menu_item_get_type(),
38 }
39}
40
41impl MenuItem {
42 pub fn new() -> MenuItem {
43 assert_initialized_main_thread!();
44 unsafe { Widget::from_glib_none(gtk_sys::gtk_menu_item_new()).unsafe_cast() }
45 }
46
47 pub fn new_with_label(label: &str) -> MenuItem {
48 assert_initialized_main_thread!();
49 unsafe {
50 Widget::from_glib_none(gtk_sys::gtk_menu_item_new_with_label(
51 label.to_glib_none().0,
52 ))
53 .unsafe_cast()
54 }
55 }
56
57 pub fn new_with_mnemonic(label: &str) -> MenuItem {
58 assert_initialized_main_thread!();
59 unsafe {
60 Widget::from_glib_none(gtk_sys::gtk_menu_item_new_with_mnemonic(
61 label.to_glib_none().0,
62 ))
63 .unsafe_cast()
64 }
65 }
66}
67
68impl Default for MenuItem {
69 fn default() -> Self {
70 Self::new()
71 }
72}
73
74pub struct MenuItemBuilder {
75 accel_path: Option<String>,
76 label: Option<String>,
77 right_justified: Option<bool>,
78 submenu: Option<Menu>,
79 use_underline: Option<bool>,
80 border_width: Option<u32>,
81 child: Option<Widget>,
82 resize_mode: Option<ResizeMode>,
83 app_paintable: Option<bool>,
84 can_default: Option<bool>,
85 can_focus: Option<bool>,
86 events: Option<gdk::EventMask>,
87 expand: Option<bool>,
88 #[cfg(any(feature = "v3_20", feature = "dox"))]
89 focus_on_click: Option<bool>,
90 halign: Option<Align>,
91 has_default: Option<bool>,
92 has_focus: Option<bool>,
93 has_tooltip: Option<bool>,
94 height_request: Option<i32>,
95 hexpand: Option<bool>,
96 hexpand_set: Option<bool>,
97 is_focus: Option<bool>,
98 margin: Option<i32>,
99 margin_bottom: Option<i32>,
100 margin_end: Option<i32>,
101 margin_start: Option<i32>,
102 margin_top: Option<i32>,
103 name: Option<String>,
104 no_show_all: Option<bool>,
105 opacity: Option<f64>,
106 parent: Option<Container>,
107 receives_default: Option<bool>,
108 sensitive: Option<bool>,
109 tooltip_markup: Option<String>,
111 tooltip_text: Option<String>,
112 valign: Option<Align>,
113 vexpand: Option<bool>,
114 vexpand_set: Option<bool>,
115 visible: Option<bool>,
116 width_request: Option<i32>,
117}
118
119impl MenuItemBuilder {
120 pub fn new() -> Self {
121 Self {
122 accel_path: None,
123 label: None,
124 right_justified: None,
125 submenu: None,
126 use_underline: None,
127 border_width: None,
128 child: None,
129 resize_mode: None,
130 app_paintable: None,
131 can_default: None,
132 can_focus: None,
133 events: None,
134 expand: None,
135 #[cfg(any(feature = "v3_20", feature = "dox"))]
136 focus_on_click: None,
137 halign: None,
138 has_default: None,
139 has_focus: None,
140 has_tooltip: None,
141 height_request: None,
142 hexpand: None,
143 hexpand_set: None,
144 is_focus: None,
145 margin: None,
146 margin_bottom: None,
147 margin_end: None,
148 margin_start: None,
149 margin_top: None,
150 name: None,
151 no_show_all: None,
152 opacity: None,
153 parent: None,
154 receives_default: None,
155 sensitive: None,
156 tooltip_markup: None,
157 tooltip_text: None,
158 valign: None,
159 vexpand: None,
160 vexpand_set: None,
161 visible: None,
162 width_request: None,
163 }
164 }
165
166 pub fn build(self) -> MenuItem {
167 let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
168 if let Some(ref accel_path) = self.accel_path {
169 properties.push(("accel-path", accel_path));
170 }
171 if let Some(ref label) = self.label {
172 properties.push(("label", label));
173 }
174 if let Some(ref right_justified) = self.right_justified {
175 properties.push(("right-justified", right_justified));
176 }
177 if let Some(ref submenu) = self.submenu {
178 properties.push(("submenu", submenu));
179 }
180 if let Some(ref use_underline) = self.use_underline {
181 properties.push(("use-underline", use_underline));
182 }
183 if let Some(ref border_width) = self.border_width {
184 properties.push(("border-width", border_width));
185 }
186 if let Some(ref child) = self.child {
187 properties.push(("child", child));
188 }
189 if let Some(ref resize_mode) = self.resize_mode {
190 properties.push(("resize-mode", resize_mode));
191 }
192 if let Some(ref app_paintable) = self.app_paintable {
193 properties.push(("app-paintable", app_paintable));
194 }
195 if let Some(ref can_default) = self.can_default {
196 properties.push(("can-default", can_default));
197 }
198 if let Some(ref can_focus) = self.can_focus {
199 properties.push(("can-focus", can_focus));
200 }
201 if let Some(ref events) = self.events {
202 properties.push(("events", events));
203 }
204 if let Some(ref expand) = self.expand {
205 properties.push(("expand", expand));
206 }
207 #[cfg(any(feature = "v3_20", feature = "dox"))]
208 {
209 if let Some(ref focus_on_click) = self.focus_on_click {
210 properties.push(("focus-on-click", focus_on_click));
211 }
212 }
213 if let Some(ref halign) = self.halign {
214 properties.push(("halign", halign));
215 }
216 if let Some(ref has_default) = self.has_default {
217 properties.push(("has-default", has_default));
218 }
219 if let Some(ref has_focus) = self.has_focus {
220 properties.push(("has-focus", has_focus));
221 }
222 if let Some(ref has_tooltip) = self.has_tooltip {
223 properties.push(("has-tooltip", has_tooltip));
224 }
225 if let Some(ref height_request) = self.height_request {
226 properties.push(("height-request", height_request));
227 }
228 if let Some(ref hexpand) = self.hexpand {
229 properties.push(("hexpand", hexpand));
230 }
231 if let Some(ref hexpand_set) = self.hexpand_set {
232 properties.push(("hexpand-set", hexpand_set));
233 }
234 if let Some(ref is_focus) = self.is_focus {
235 properties.push(("is-focus", is_focus));
236 }
237 if let Some(ref margin) = self.margin {
238 properties.push(("margin", margin));
239 }
240 if let Some(ref margin_bottom) = self.margin_bottom {
241 properties.push(("margin-bottom", margin_bottom));
242 }
243 if let Some(ref margin_end) = self.margin_end {
244 properties.push(("margin-end", margin_end));
245 }
246 if let Some(ref margin_start) = self.margin_start {
247 properties.push(("margin-start", margin_start));
248 }
249 if let Some(ref margin_top) = self.margin_top {
250 properties.push(("margin-top", margin_top));
251 }
252 if let Some(ref name) = self.name {
253 properties.push(("name", name));
254 }
255 if let Some(ref no_show_all) = self.no_show_all {
256 properties.push(("no-show-all", no_show_all));
257 }
258 if let Some(ref opacity) = self.opacity {
259 properties.push(("opacity", opacity));
260 }
261 if let Some(ref parent) = self.parent {
262 properties.push(("parent", parent));
263 }
264 if let Some(ref receives_default) = self.receives_default {
265 properties.push(("receives-default", receives_default));
266 }
267 if let Some(ref sensitive) = self.sensitive {
268 properties.push(("sensitive", sensitive));
269 }
270 if let Some(ref tooltip_markup) = self.tooltip_markup {
271 properties.push(("tooltip-markup", tooltip_markup));
272 }
273 if let Some(ref tooltip_text) = self.tooltip_text {
274 properties.push(("tooltip-text", tooltip_text));
275 }
276 if let Some(ref valign) = self.valign {
277 properties.push(("valign", valign));
278 }
279 if let Some(ref vexpand) = self.vexpand {
280 properties.push(("vexpand", vexpand));
281 }
282 if let Some(ref vexpand_set) = self.vexpand_set {
283 properties.push(("vexpand-set", vexpand_set));
284 }
285 if let Some(ref visible) = self.visible {
286 properties.push(("visible", visible));
287 }
288 if let Some(ref width_request) = self.width_request {
289 properties.push(("width-request", width_request));
290 }
291 glib::Object::new(MenuItem::static_type(), &properties)
292 .expect("object new")
293 .downcast()
294 .expect("downcast")
295 }
296
297 pub fn accel_path(mut self, accel_path: &str) -> Self {
298 self.accel_path = Some(accel_path.to_string());
299 self
300 }
301
302 pub fn label(mut self, label: &str) -> Self {
303 self.label = Some(label.to_string());
304 self
305 }
306
307 pub fn right_justified(mut self, right_justified: bool) -> Self {
308 self.right_justified = Some(right_justified);
309 self
310 }
311
312 pub fn submenu(mut self, submenu: &Menu) -> Self {
313 self.submenu = Some(submenu.clone());
314 self
315 }
316
317 pub fn use_underline(mut self, use_underline: bool) -> Self {
318 self.use_underline = Some(use_underline);
319 self
320 }
321
322 pub fn border_width(mut self, border_width: u32) -> Self {
323 self.border_width = Some(border_width);
324 self
325 }
326
327 pub fn child(mut self, child: &Widget) -> Self {
328 self.child = Some(child.clone());
329 self
330 }
331
332 pub fn resize_mode(mut self, resize_mode: ResizeMode) -> Self {
333 self.resize_mode = Some(resize_mode);
334 self
335 }
336
337 pub fn app_paintable(mut self, app_paintable: bool) -> Self {
338 self.app_paintable = Some(app_paintable);
339 self
340 }
341
342 pub fn can_default(mut self, can_default: bool) -> Self {
343 self.can_default = Some(can_default);
344 self
345 }
346
347 pub fn can_focus(mut self, can_focus: bool) -> Self {
348 self.can_focus = Some(can_focus);
349 self
350 }
351
352 pub fn events(mut self, events: gdk::EventMask) -> Self {
353 self.events = Some(events);
354 self
355 }
356
357 pub fn expand(mut self, expand: bool) -> Self {
358 self.expand = Some(expand);
359 self
360 }
361
362 #[cfg(any(feature = "v3_20", feature = "dox"))]
363 pub fn focus_on_click(mut self, focus_on_click: bool) -> Self {
364 self.focus_on_click = Some(focus_on_click);
365 self
366 }
367
368 pub fn halign(mut self, halign: Align) -> Self {
369 self.halign = Some(halign);
370 self
371 }
372
373 pub fn has_default(mut self, has_default: bool) -> Self {
374 self.has_default = Some(has_default);
375 self
376 }
377
378 pub fn has_focus(mut self, has_focus: bool) -> Self {
379 self.has_focus = Some(has_focus);
380 self
381 }
382
383 pub fn has_tooltip(mut self, has_tooltip: bool) -> Self {
384 self.has_tooltip = Some(has_tooltip);
385 self
386 }
387
388 pub fn height_request(mut self, height_request: i32) -> Self {
389 self.height_request = Some(height_request);
390 self
391 }
392
393 pub fn hexpand(mut self, hexpand: bool) -> Self {
394 self.hexpand = Some(hexpand);
395 self
396 }
397
398 pub fn hexpand_set(mut self, hexpand_set: bool) -> Self {
399 self.hexpand_set = Some(hexpand_set);
400 self
401 }
402
403 pub fn is_focus(mut self, is_focus: bool) -> Self {
404 self.is_focus = Some(is_focus);
405 self
406 }
407
408 pub fn margin(mut self, margin: i32) -> Self {
409 self.margin = Some(margin);
410 self
411 }
412
413 pub fn margin_bottom(mut self, margin_bottom: i32) -> Self {
414 self.margin_bottom = Some(margin_bottom);
415 self
416 }
417
418 pub fn margin_end(mut self, margin_end: i32) -> Self {
419 self.margin_end = Some(margin_end);
420 self
421 }
422
423 pub fn margin_start(mut self, margin_start: i32) -> Self {
424 self.margin_start = Some(margin_start);
425 self
426 }
427
428 pub fn margin_top(mut self, margin_top: i32) -> Self {
429 self.margin_top = Some(margin_top);
430 self
431 }
432
433 pub fn name(mut self, name: &str) -> Self {
434 self.name = Some(name.to_string());
435 self
436 }
437
438 pub fn no_show_all(mut self, no_show_all: bool) -> Self {
439 self.no_show_all = Some(no_show_all);
440 self
441 }
442
443 pub fn opacity(mut self, opacity: f64) -> Self {
444 self.opacity = Some(opacity);
445 self
446 }
447
448 pub fn parent(mut self, parent: &Container) -> Self {
449 self.parent = Some(parent.clone());
450 self
451 }
452
453 pub fn receives_default(mut self, receives_default: bool) -> Self {
454 self.receives_default = Some(receives_default);
455 self
456 }
457
458 pub fn sensitive(mut self, sensitive: bool) -> Self {
459 self.sensitive = Some(sensitive);
460 self
461 }
462
463 pub fn tooltip_markup(mut self, tooltip_markup: &str) -> Self {
464 self.tooltip_markup = Some(tooltip_markup.to_string());
465 self
466 }
467
468 pub fn tooltip_text(mut self, tooltip_text: &str) -> Self {
469 self.tooltip_text = Some(tooltip_text.to_string());
470 self
471 }
472
473 pub fn valign(mut self, valign: Align) -> Self {
474 self.valign = Some(valign);
475 self
476 }
477
478 pub fn vexpand(mut self, vexpand: bool) -> Self {
479 self.vexpand = Some(vexpand);
480 self
481 }
482
483 pub fn vexpand_set(mut self, vexpand_set: bool) -> Self {
484 self.vexpand_set = Some(vexpand_set);
485 self
486 }
487
488 pub fn visible(mut self, visible: bool) -> Self {
489 self.visible = Some(visible);
490 self
491 }
492
493 pub fn width_request(mut self, width_request: i32) -> Self {
494 self.width_request = Some(width_request);
495 self
496 }
497}
498
499pub const NONE_MENU_ITEM: Option<&MenuItem> = None;
500
501pub trait GtkMenuItemExt: 'static {
502 fn deselect(&self);
503
504 fn get_accel_path(&self) -> Option<GString>;
505
506 fn get_label(&self) -> Option<GString>;
507
508 fn get_reserve_indicator(&self) -> bool;
509
510 fn get_submenu(&self) -> Option<Widget>;
511
512 fn get_use_underline(&self) -> bool;
513
514 fn select(&self);
515
516 fn set_accel_path(&self, accel_path: Option<&str>);
517
518 fn set_label(&self, label: &str);
519
520 fn set_reserve_indicator(&self, reserve: bool);
521
522 fn set_submenu<P: IsA<Menu>>(&self, submenu: Option<&P>);
523
524 fn set_use_underline(&self, setting: bool);
525
526 fn toggle_size_allocate(&self, allocation: i32);
527
528 fn toggle_size_request(&self, requisition: &mut i32);
529
530 fn get_property_right_justified(&self) -> bool;
531
532 fn set_property_right_justified(&self, right_justified: bool);
533
534 fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
535
536 fn emit_activate(&self);
537
538 fn connect_activate_item<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
539
540 fn connect_deselect<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
541
542 fn connect_select<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
543
544 fn connect_toggle_size_allocate<F: Fn(&Self, i32) + 'static>(&self, f: F) -> SignalHandlerId;
545
546 fn connect_property_accel_path_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
549
550 fn connect_property_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
551
552 fn connect_property_right_justified_notify<F: Fn(&Self) + 'static>(
553 &self,
554 f: F,
555 ) -> SignalHandlerId;
556
557 fn connect_property_submenu_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
558
559 fn connect_property_use_underline_notify<F: Fn(&Self) + 'static>(
560 &self,
561 f: F,
562 ) -> SignalHandlerId;
563}
564
565impl<O: IsA<MenuItem>> GtkMenuItemExt for O {
566 fn deselect(&self) {
567 unsafe {
568 gtk_sys::gtk_menu_item_deselect(self.as_ref().to_glib_none().0);
569 }
570 }
571
572 fn get_accel_path(&self) -> Option<GString> {
573 unsafe {
574 from_glib_none(gtk_sys::gtk_menu_item_get_accel_path(
575 self.as_ref().to_glib_none().0,
576 ))
577 }
578 }
579
580 fn get_label(&self) -> Option<GString> {
581 unsafe {
582 from_glib_none(gtk_sys::gtk_menu_item_get_label(
583 self.as_ref().to_glib_none().0,
584 ))
585 }
586 }
587
588 fn get_reserve_indicator(&self) -> bool {
589 unsafe {
590 from_glib(gtk_sys::gtk_menu_item_get_reserve_indicator(
591 self.as_ref().to_glib_none().0,
592 ))
593 }
594 }
595
596 fn get_submenu(&self) -> Option<Widget> {
597 unsafe {
598 from_glib_none(gtk_sys::gtk_menu_item_get_submenu(
599 self.as_ref().to_glib_none().0,
600 ))
601 }
602 }
603
604 fn get_use_underline(&self) -> bool {
605 unsafe {
606 from_glib(gtk_sys::gtk_menu_item_get_use_underline(
607 self.as_ref().to_glib_none().0,
608 ))
609 }
610 }
611
612 fn select(&self) {
613 unsafe {
614 gtk_sys::gtk_menu_item_select(self.as_ref().to_glib_none().0);
615 }
616 }
617
618 fn set_accel_path(&self, accel_path: Option<&str>) {
619 unsafe {
620 gtk_sys::gtk_menu_item_set_accel_path(
621 self.as_ref().to_glib_none().0,
622 accel_path.to_glib_none().0,
623 );
624 }
625 }
626
627 fn set_label(&self, label: &str) {
628 unsafe {
629 gtk_sys::gtk_menu_item_set_label(
630 self.as_ref().to_glib_none().0,
631 label.to_glib_none().0,
632 );
633 }
634 }
635
636 fn set_reserve_indicator(&self, reserve: bool) {
637 unsafe {
638 gtk_sys::gtk_menu_item_set_reserve_indicator(
639 self.as_ref().to_glib_none().0,
640 reserve.to_glib(),
641 );
642 }
643 }
644
645 fn set_submenu<P: IsA<Menu>>(&self, submenu: Option<&P>) {
646 unsafe {
647 gtk_sys::gtk_menu_item_set_submenu(
648 self.as_ref().to_glib_none().0,
649 submenu.map(|p| p.as_ref()).to_glib_none().0,
650 );
651 }
652 }
653
654 fn set_use_underline(&self, setting: bool) {
655 unsafe {
656 gtk_sys::gtk_menu_item_set_use_underline(
657 self.as_ref().to_glib_none().0,
658 setting.to_glib(),
659 );
660 }
661 }
662
663 fn toggle_size_allocate(&self, allocation: i32) {
664 unsafe {
665 gtk_sys::gtk_menu_item_toggle_size_allocate(self.as_ref().to_glib_none().0, allocation);
666 }
667 }
668
669 fn toggle_size_request(&self, requisition: &mut i32) {
670 unsafe {
671 gtk_sys::gtk_menu_item_toggle_size_request(self.as_ref().to_glib_none().0, requisition);
672 }
673 }
674
675 fn get_property_right_justified(&self) -> bool {
676 unsafe {
677 let mut value = Value::from_type(<bool as StaticType>::static_type());
678 gobject_sys::g_object_get_property(
679 self.to_glib_none().0 as *mut gobject_sys::GObject,
680 b"right-justified\0".as_ptr() as *const _,
681 value.to_glib_none_mut().0,
682 );
683 value.get().unwrap()
684 }
685 }
686
687 fn set_property_right_justified(&self, right_justified: bool) {
688 unsafe {
689 gobject_sys::g_object_set_property(
690 self.to_glib_none().0 as *mut gobject_sys::GObject,
691 b"right-justified\0".as_ptr() as *const _,
692 Value::from(&right_justified).to_glib_none().0,
693 );
694 }
695 }
696
697 fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
698 unsafe extern "C" fn activate_trampoline<P, F: Fn(&P) + 'static>(
699 this: *mut gtk_sys::GtkMenuItem,
700 f: glib_sys::gpointer,
701 ) where
702 P: IsA<MenuItem>,
703 {
704 let f: &F = &*(f as *const F);
705 f(&MenuItem::from_glib_borrow(this).unsafe_cast())
706 }
707 unsafe {
708 let f: Box_<F> = Box_::new(f);
709 connect_raw(
710 self.as_ptr() as *mut _,
711 b"activate\0".as_ptr() as *const _,
712 Some(transmute(activate_trampoline::<Self, F> as usize)),
713 Box_::into_raw(f),
714 )
715 }
716 }
717
718 fn emit_activate(&self) {
719 let _ = unsafe {
720 glib::Object::from_glib_borrow(self.to_glib_none().0 as *mut gobject_sys::GObject)
721 .emit("activate", &[])
722 .unwrap()
723 };
724 }
725
726 fn connect_activate_item<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
727 unsafe extern "C" fn activate_item_trampoline<P, F: Fn(&P) + 'static>(
728 this: *mut gtk_sys::GtkMenuItem,
729 f: glib_sys::gpointer,
730 ) where
731 P: IsA<MenuItem>,
732 {
733 let f: &F = &*(f as *const F);
734 f(&MenuItem::from_glib_borrow(this).unsafe_cast())
735 }
736 unsafe {
737 let f: Box_<F> = Box_::new(f);
738 connect_raw(
739 self.as_ptr() as *mut _,
740 b"activate-item\0".as_ptr() as *const _,
741 Some(transmute(activate_item_trampoline::<Self, F> as usize)),
742 Box_::into_raw(f),
743 )
744 }
745 }
746
747 fn connect_deselect<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
748 unsafe extern "C" fn deselect_trampoline<P, F: Fn(&P) + 'static>(
749 this: *mut gtk_sys::GtkMenuItem,
750 f: glib_sys::gpointer,
751 ) where
752 P: IsA<MenuItem>,
753 {
754 let f: &F = &*(f as *const F);
755 f(&MenuItem::from_glib_borrow(this).unsafe_cast())
756 }
757 unsafe {
758 let f: Box_<F> = Box_::new(f);
759 connect_raw(
760 self.as_ptr() as *mut _,
761 b"deselect\0".as_ptr() as *const _,
762 Some(transmute(deselect_trampoline::<Self, F> as usize)),
763 Box_::into_raw(f),
764 )
765 }
766 }
767
768 fn connect_select<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
769 unsafe extern "C" fn select_trampoline<P, F: Fn(&P) + 'static>(
770 this: *mut gtk_sys::GtkMenuItem,
771 f: glib_sys::gpointer,
772 ) where
773 P: IsA<MenuItem>,
774 {
775 let f: &F = &*(f as *const F);
776 f(&MenuItem::from_glib_borrow(this).unsafe_cast())
777 }
778 unsafe {
779 let f: Box_<F> = Box_::new(f);
780 connect_raw(
781 self.as_ptr() as *mut _,
782 b"select\0".as_ptr() as *const _,
783 Some(transmute(select_trampoline::<Self, F> as usize)),
784 Box_::into_raw(f),
785 )
786 }
787 }
788
789 fn connect_toggle_size_allocate<F: Fn(&Self, i32) + 'static>(&self, f: F) -> SignalHandlerId {
790 unsafe extern "C" fn toggle_size_allocate_trampoline<P, F: Fn(&P, i32) + 'static>(
791 this: *mut gtk_sys::GtkMenuItem,
792 object: libc::c_int,
793 f: glib_sys::gpointer,
794 ) where
795 P: IsA<MenuItem>,
796 {
797 let f: &F = &*(f as *const F);
798 f(&MenuItem::from_glib_borrow(this).unsafe_cast(), object)
799 }
800 unsafe {
801 let f: Box_<F> = Box_::new(f);
802 connect_raw(
803 self.as_ptr() as *mut _,
804 b"toggle-size-allocate\0".as_ptr() as *const _,
805 Some(transmute(
806 toggle_size_allocate_trampoline::<Self, F> as usize,
807 )),
808 Box_::into_raw(f),
809 )
810 }
811 }
812
813 fn connect_property_accel_path_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
818 unsafe extern "C" fn notify_accel_path_trampoline<P, F: Fn(&P) + 'static>(
819 this: *mut gtk_sys::GtkMenuItem,
820 _param_spec: glib_sys::gpointer,
821 f: glib_sys::gpointer,
822 ) where
823 P: IsA<MenuItem>,
824 {
825 let f: &F = &*(f as *const F);
826 f(&MenuItem::from_glib_borrow(this).unsafe_cast())
827 }
828 unsafe {
829 let f: Box_<F> = Box_::new(f);
830 connect_raw(
831 self.as_ptr() as *mut _,
832 b"notify::accel-path\0".as_ptr() as *const _,
833 Some(transmute(notify_accel_path_trampoline::<Self, F> as usize)),
834 Box_::into_raw(f),
835 )
836 }
837 }
838
839 fn connect_property_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
840 unsafe extern "C" fn notify_label_trampoline<P, F: Fn(&P) + 'static>(
841 this: *mut gtk_sys::GtkMenuItem,
842 _param_spec: glib_sys::gpointer,
843 f: glib_sys::gpointer,
844 ) where
845 P: IsA<MenuItem>,
846 {
847 let f: &F = &*(f as *const F);
848 f(&MenuItem::from_glib_borrow(this).unsafe_cast())
849 }
850 unsafe {
851 let f: Box_<F> = Box_::new(f);
852 connect_raw(
853 self.as_ptr() as *mut _,
854 b"notify::label\0".as_ptr() as *const _,
855 Some(transmute(notify_label_trampoline::<Self, F> as usize)),
856 Box_::into_raw(f),
857 )
858 }
859 }
860
861 fn connect_property_right_justified_notify<F: Fn(&Self) + 'static>(
862 &self,
863 f: F,
864 ) -> SignalHandlerId {
865 unsafe extern "C" fn notify_right_justified_trampoline<P, F: Fn(&P) + 'static>(
866 this: *mut gtk_sys::GtkMenuItem,
867 _param_spec: glib_sys::gpointer,
868 f: glib_sys::gpointer,
869 ) where
870 P: IsA<MenuItem>,
871 {
872 let f: &F = &*(f as *const F);
873 f(&MenuItem::from_glib_borrow(this).unsafe_cast())
874 }
875 unsafe {
876 let f: Box_<F> = Box_::new(f);
877 connect_raw(
878 self.as_ptr() as *mut _,
879 b"notify::right-justified\0".as_ptr() as *const _,
880 Some(transmute(
881 notify_right_justified_trampoline::<Self, F> as usize,
882 )),
883 Box_::into_raw(f),
884 )
885 }
886 }
887
888 fn connect_property_submenu_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
889 unsafe extern "C" fn notify_submenu_trampoline<P, F: Fn(&P) + 'static>(
890 this: *mut gtk_sys::GtkMenuItem,
891 _param_spec: glib_sys::gpointer,
892 f: glib_sys::gpointer,
893 ) where
894 P: IsA<MenuItem>,
895 {
896 let f: &F = &*(f as *const F);
897 f(&MenuItem::from_glib_borrow(this).unsafe_cast())
898 }
899 unsafe {
900 let f: Box_<F> = Box_::new(f);
901 connect_raw(
902 self.as_ptr() as *mut _,
903 b"notify::submenu\0".as_ptr() as *const _,
904 Some(transmute(notify_submenu_trampoline::<Self, F> as usize)),
905 Box_::into_raw(f),
906 )
907 }
908 }
909
910 fn connect_property_use_underline_notify<F: Fn(&Self) + 'static>(
911 &self,
912 f: F,
913 ) -> SignalHandlerId {
914 unsafe extern "C" fn notify_use_underline_trampoline<P, F: Fn(&P) + 'static>(
915 this: *mut gtk_sys::GtkMenuItem,
916 _param_spec: glib_sys::gpointer,
917 f: glib_sys::gpointer,
918 ) where
919 P: IsA<MenuItem>,
920 {
921 let f: &F = &*(f as *const F);
922 f(&MenuItem::from_glib_borrow(this).unsafe_cast())
923 }
924 unsafe {
925 let f: Box_<F> = Box_::new(f);
926 connect_raw(
927 self.as_ptr() as *mut _,
928 b"notify::use-underline\0".as_ptr() as *const _,
929 Some(transmute(
930 notify_use_underline_trampoline::<Self, F> as usize,
931 )),
932 Box_::into_raw(f),
933 )
934 }
935 }
936}
937
938impl fmt::Display for MenuItem {
939 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
940 write!(f, "MenuItem")
941 }
942}