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