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 
5 use gdk;
6 use glib;
7 use glib::object::Cast;
8 use glib::object::IsA;
9 use glib::object::ObjectExt;
10 use glib::signal::connect_raw;
11 use glib::signal::SignalHandlerId;
12 use glib::translate::*;
13 use glib::StaticType;
14 use glib::ToValue;
15 use glib_sys;
16 use gobject_sys;
17 use gtk_sys;
18 use std::boxed::Box as Box_;
19 use std::fmt;
20 use std::mem::transmute;
21 use Actionable;
22 use Align;
23 use Buildable;
24 use Container;
25 use Widget;
26 
27 glib_wrapper! {
28     pub struct Switch(Object<gtk_sys::GtkSwitch, gtk_sys::GtkSwitchClass, SwitchClass>) @extends Widget, @implements Buildable, Actionable;
29 
30     match fn {
31         get_type => || gtk_sys::gtk_switch_get_type(),
32     }
33 }
34 
35 impl Switch {
new() -> Switch36     pub fn new() -> Switch {
37         assert_initialized_main_thread!();
38         unsafe { Widget::from_glib_none(gtk_sys::gtk_switch_new()).unsafe_cast() }
39     }
40 }
41 
42 impl Default for Switch {
default() -> Self43     fn default() -> Self {
44         Self::new()
45     }
46 }
47 
48 #[derive(Clone, Default)]
49 pub struct SwitchBuilder {
50     active: Option<bool>,
51     state: Option<bool>,
52     app_paintable: Option<bool>,
53     can_default: Option<bool>,
54     can_focus: Option<bool>,
55     events: Option<gdk::EventMask>,
56     expand: Option<bool>,
57     #[cfg(any(feature = "v3_20", feature = "dox"))]
58     focus_on_click: Option<bool>,
59     halign: Option<Align>,
60     has_default: Option<bool>,
61     has_focus: Option<bool>,
62     has_tooltip: Option<bool>,
63     height_request: Option<i32>,
64     hexpand: Option<bool>,
65     hexpand_set: Option<bool>,
66     is_focus: Option<bool>,
67     margin: Option<i32>,
68     margin_bottom: Option<i32>,
69     margin_end: Option<i32>,
70     margin_start: Option<i32>,
71     margin_top: Option<i32>,
72     name: Option<String>,
73     no_show_all: Option<bool>,
74     opacity: Option<f64>,
75     parent: Option<Container>,
76     receives_default: Option<bool>,
77     sensitive: Option<bool>,
78     tooltip_markup: Option<String>,
79     tooltip_text: Option<String>,
80     valign: Option<Align>,
81     vexpand: Option<bool>,
82     vexpand_set: Option<bool>,
83     visible: Option<bool>,
84     width_request: Option<i32>,
85     action_name: Option<String>,
86     action_target: Option<glib::Variant>,
87 }
88 
89 impl SwitchBuilder {
new() -> Self90     pub fn new() -> Self {
91         Self::default()
92     }
93 
build(self) -> Switch94     pub fn build(self) -> Switch {
95         let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
96         if let Some(ref active) = self.active {
97             properties.push(("active", active));
98         }
99         if let Some(ref state) = self.state {
100             properties.push(("state", state));
101         }
102         if let Some(ref app_paintable) = self.app_paintable {
103             properties.push(("app-paintable", app_paintable));
104         }
105         if let Some(ref can_default) = self.can_default {
106             properties.push(("can-default", can_default));
107         }
108         if let Some(ref can_focus) = self.can_focus {
109             properties.push(("can-focus", can_focus));
110         }
111         if let Some(ref events) = self.events {
112             properties.push(("events", events));
113         }
114         if let Some(ref expand) = self.expand {
115             properties.push(("expand", expand));
116         }
117         #[cfg(any(feature = "v3_20", feature = "dox"))]
118         {
119             if let Some(ref focus_on_click) = self.focus_on_click {
120                 properties.push(("focus-on-click", focus_on_click));
121             }
122         }
123         if let Some(ref halign) = self.halign {
124             properties.push(("halign", halign));
125         }
126         if let Some(ref has_default) = self.has_default {
127             properties.push(("has-default", has_default));
128         }
129         if let Some(ref has_focus) = self.has_focus {
130             properties.push(("has-focus", has_focus));
131         }
132         if let Some(ref has_tooltip) = self.has_tooltip {
133             properties.push(("has-tooltip", has_tooltip));
134         }
135         if let Some(ref height_request) = self.height_request {
136             properties.push(("height-request", height_request));
137         }
138         if let Some(ref hexpand) = self.hexpand {
139             properties.push(("hexpand", hexpand));
140         }
141         if let Some(ref hexpand_set) = self.hexpand_set {
142             properties.push(("hexpand-set", hexpand_set));
143         }
144         if let Some(ref is_focus) = self.is_focus {
145             properties.push(("is-focus", is_focus));
146         }
147         if let Some(ref margin) = self.margin {
148             properties.push(("margin", margin));
149         }
150         if let Some(ref margin_bottom) = self.margin_bottom {
151             properties.push(("margin-bottom", margin_bottom));
152         }
153         if let Some(ref margin_end) = self.margin_end {
154             properties.push(("margin-end", margin_end));
155         }
156         if let Some(ref margin_start) = self.margin_start {
157             properties.push(("margin-start", margin_start));
158         }
159         if let Some(ref margin_top) = self.margin_top {
160             properties.push(("margin-top", margin_top));
161         }
162         if let Some(ref name) = self.name {
163             properties.push(("name", name));
164         }
165         if let Some(ref no_show_all) = self.no_show_all {
166             properties.push(("no-show-all", no_show_all));
167         }
168         if let Some(ref opacity) = self.opacity {
169             properties.push(("opacity", opacity));
170         }
171         if let Some(ref parent) = self.parent {
172             properties.push(("parent", parent));
173         }
174         if let Some(ref receives_default) = self.receives_default {
175             properties.push(("receives-default", receives_default));
176         }
177         if let Some(ref sensitive) = self.sensitive {
178             properties.push(("sensitive", sensitive));
179         }
180         if let Some(ref tooltip_markup) = self.tooltip_markup {
181             properties.push(("tooltip-markup", tooltip_markup));
182         }
183         if let Some(ref tooltip_text) = self.tooltip_text {
184             properties.push(("tooltip-text", tooltip_text));
185         }
186         if let Some(ref valign) = self.valign {
187             properties.push(("valign", valign));
188         }
189         if let Some(ref vexpand) = self.vexpand {
190             properties.push(("vexpand", vexpand));
191         }
192         if let Some(ref vexpand_set) = self.vexpand_set {
193             properties.push(("vexpand-set", vexpand_set));
194         }
195         if let Some(ref visible) = self.visible {
196             properties.push(("visible", visible));
197         }
198         if let Some(ref width_request) = self.width_request {
199             properties.push(("width-request", width_request));
200         }
201         if let Some(ref action_name) = self.action_name {
202             properties.push(("action-name", action_name));
203         }
204         if let Some(ref action_target) = self.action_target {
205             properties.push(("action-target", action_target));
206         }
207         glib::Object::new(Switch::static_type(), &properties)
208             .expect("object new")
209             .downcast()
210             .expect("downcast")
211     }
212 
active(mut self, active: bool) -> Self213     pub fn active(mut self, active: bool) -> Self {
214         self.active = Some(active);
215         self
216     }
217 
state(mut self, state: bool) -> Self218     pub fn state(mut self, state: bool) -> Self {
219         self.state = Some(state);
220         self
221     }
222 
app_paintable(mut self, app_paintable: bool) -> Self223     pub fn app_paintable(mut self, app_paintable: bool) -> Self {
224         self.app_paintable = Some(app_paintable);
225         self
226     }
227 
can_default(mut self, can_default: bool) -> Self228     pub fn can_default(mut self, can_default: bool) -> Self {
229         self.can_default = Some(can_default);
230         self
231     }
232 
can_focus(mut self, can_focus: bool) -> Self233     pub fn can_focus(mut self, can_focus: bool) -> Self {
234         self.can_focus = Some(can_focus);
235         self
236     }
237 
events(mut self, events: gdk::EventMask) -> Self238     pub fn events(mut self, events: gdk::EventMask) -> Self {
239         self.events = Some(events);
240         self
241     }
242 
expand(mut self, expand: bool) -> Self243     pub fn expand(mut self, expand: bool) -> Self {
244         self.expand = Some(expand);
245         self
246     }
247 
248     #[cfg(any(feature = "v3_20", feature = "dox"))]
focus_on_click(mut self, focus_on_click: bool) -> Self249     pub fn focus_on_click(mut self, focus_on_click: bool) -> Self {
250         self.focus_on_click = Some(focus_on_click);
251         self
252     }
253 
halign(mut self, halign: Align) -> Self254     pub fn halign(mut self, halign: Align) -> Self {
255         self.halign = Some(halign);
256         self
257     }
258 
has_default(mut self, has_default: bool) -> Self259     pub fn has_default(mut self, has_default: bool) -> Self {
260         self.has_default = Some(has_default);
261         self
262     }
263 
has_focus(mut self, has_focus: bool) -> Self264     pub fn has_focus(mut self, has_focus: bool) -> Self {
265         self.has_focus = Some(has_focus);
266         self
267     }
268 
has_tooltip(mut self, has_tooltip: bool) -> Self269     pub fn has_tooltip(mut self, has_tooltip: bool) -> Self {
270         self.has_tooltip = Some(has_tooltip);
271         self
272     }
273 
height_request(mut self, height_request: i32) -> Self274     pub fn height_request(mut self, height_request: i32) -> Self {
275         self.height_request = Some(height_request);
276         self
277     }
278 
hexpand(mut self, hexpand: bool) -> Self279     pub fn hexpand(mut self, hexpand: bool) -> Self {
280         self.hexpand = Some(hexpand);
281         self
282     }
283 
hexpand_set(mut self, hexpand_set: bool) -> Self284     pub fn hexpand_set(mut self, hexpand_set: bool) -> Self {
285         self.hexpand_set = Some(hexpand_set);
286         self
287     }
288 
is_focus(mut self, is_focus: bool) -> Self289     pub fn is_focus(mut self, is_focus: bool) -> Self {
290         self.is_focus = Some(is_focus);
291         self
292     }
293 
margin(mut self, margin: i32) -> Self294     pub fn margin(mut self, margin: i32) -> Self {
295         self.margin = Some(margin);
296         self
297     }
298 
margin_bottom(mut self, margin_bottom: i32) -> Self299     pub fn margin_bottom(mut self, margin_bottom: i32) -> Self {
300         self.margin_bottom = Some(margin_bottom);
301         self
302     }
303 
margin_end(mut self, margin_end: i32) -> Self304     pub fn margin_end(mut self, margin_end: i32) -> Self {
305         self.margin_end = Some(margin_end);
306         self
307     }
308 
margin_start(mut self, margin_start: i32) -> Self309     pub fn margin_start(mut self, margin_start: i32) -> Self {
310         self.margin_start = Some(margin_start);
311         self
312     }
313 
margin_top(mut self, margin_top: i32) -> Self314     pub fn margin_top(mut self, margin_top: i32) -> Self {
315         self.margin_top = Some(margin_top);
316         self
317     }
318 
name(mut self, name: &str) -> Self319     pub fn name(mut self, name: &str) -> Self {
320         self.name = Some(name.to_string());
321         self
322     }
323 
no_show_all(mut self, no_show_all: bool) -> Self324     pub fn no_show_all(mut self, no_show_all: bool) -> Self {
325         self.no_show_all = Some(no_show_all);
326         self
327     }
328 
opacity(mut self, opacity: f64) -> Self329     pub fn opacity(mut self, opacity: f64) -> Self {
330         self.opacity = Some(opacity);
331         self
332     }
333 
parent<P: IsA<Container>>(mut self, parent: &P) -> Self334     pub fn parent<P: IsA<Container>>(mut self, parent: &P) -> Self {
335         self.parent = Some(parent.clone().upcast());
336         self
337     }
338 
receives_default(mut self, receives_default: bool) -> Self339     pub fn receives_default(mut self, receives_default: bool) -> Self {
340         self.receives_default = Some(receives_default);
341         self
342     }
343 
sensitive(mut self, sensitive: bool) -> Self344     pub fn sensitive(mut self, sensitive: bool) -> Self {
345         self.sensitive = Some(sensitive);
346         self
347     }
348 
tooltip_markup(mut self, tooltip_markup: &str) -> Self349     pub fn tooltip_markup(mut self, tooltip_markup: &str) -> Self {
350         self.tooltip_markup = Some(tooltip_markup.to_string());
351         self
352     }
353 
tooltip_text(mut self, tooltip_text: &str) -> Self354     pub fn tooltip_text(mut self, tooltip_text: &str) -> Self {
355         self.tooltip_text = Some(tooltip_text.to_string());
356         self
357     }
358 
valign(mut self, valign: Align) -> Self359     pub fn valign(mut self, valign: Align) -> Self {
360         self.valign = Some(valign);
361         self
362     }
363 
vexpand(mut self, vexpand: bool) -> Self364     pub fn vexpand(mut self, vexpand: bool) -> Self {
365         self.vexpand = Some(vexpand);
366         self
367     }
368 
vexpand_set(mut self, vexpand_set: bool) -> Self369     pub fn vexpand_set(mut self, vexpand_set: bool) -> Self {
370         self.vexpand_set = Some(vexpand_set);
371         self
372     }
373 
visible(mut self, visible: bool) -> Self374     pub fn visible(mut self, visible: bool) -> Self {
375         self.visible = Some(visible);
376         self
377     }
378 
width_request(mut self, width_request: i32) -> Self379     pub fn width_request(mut self, width_request: i32) -> Self {
380         self.width_request = Some(width_request);
381         self
382     }
383 
action_name(mut self, action_name: &str) -> Self384     pub fn action_name(mut self, action_name: &str) -> Self {
385         self.action_name = Some(action_name.to_string());
386         self
387     }
388 
action_target(mut self, action_target: &glib::Variant) -> Self389     pub fn action_target(mut self, action_target: &glib::Variant) -> Self {
390         self.action_target = Some(action_target.clone());
391         self
392     }
393 }
394 
395 pub const NONE_SWITCH: Option<&Switch> = None;
396 
397 pub trait SwitchExt: 'static {
get_active(&self) -> bool398     fn get_active(&self) -> bool;
399 
get_state(&self) -> bool400     fn get_state(&self) -> bool;
401 
set_active(&self, is_active: bool)402     fn set_active(&self, is_active: bool);
403 
set_state(&self, state: bool)404     fn set_state(&self, state: bool);
405 
connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId406     fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
407 
emit_activate(&self)408     fn emit_activate(&self);
409 
connect_state_set<F: Fn(&Self, bool) -> glib::signal::Inhibit + 'static>( &self, f: F, ) -> SignalHandlerId410     fn connect_state_set<F: Fn(&Self, bool) -> glib::signal::Inhibit + 'static>(
411         &self,
412         f: F,
413     ) -> SignalHandlerId;
414 
connect_property_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId415     fn connect_property_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
416 
connect_property_state_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId417     fn connect_property_state_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
418 }
419 
420 impl<O: IsA<Switch>> SwitchExt for O {
get_active(&self) -> bool421     fn get_active(&self) -> bool {
422         unsafe {
423             from_glib(gtk_sys::gtk_switch_get_active(
424                 self.as_ref().to_glib_none().0,
425             ))
426         }
427     }
428 
get_state(&self) -> bool429     fn get_state(&self) -> bool {
430         unsafe {
431             from_glib(gtk_sys::gtk_switch_get_state(
432                 self.as_ref().to_glib_none().0,
433             ))
434         }
435     }
436 
set_active(&self, is_active: bool)437     fn set_active(&self, is_active: bool) {
438         unsafe {
439             gtk_sys::gtk_switch_set_active(self.as_ref().to_glib_none().0, is_active.to_glib());
440         }
441     }
442 
set_state(&self, state: bool)443     fn set_state(&self, state: bool) {
444         unsafe {
445             gtk_sys::gtk_switch_set_state(self.as_ref().to_glib_none().0, state.to_glib());
446         }
447     }
448 
connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId449     fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
450         unsafe extern "C" fn activate_trampoline<P, F: Fn(&P) + 'static>(
451             this: *mut gtk_sys::GtkSwitch,
452             f: glib_sys::gpointer,
453         ) where
454             P: IsA<Switch>,
455         {
456             let f: &F = &*(f as *const F);
457             f(&Switch::from_glib_borrow(this).unsafe_cast())
458         }
459         unsafe {
460             let f: Box_<F> = Box_::new(f);
461             connect_raw(
462                 self.as_ptr() as *mut _,
463                 b"activate\0".as_ptr() as *const _,
464                 Some(transmute(activate_trampoline::<Self, F> as usize)),
465                 Box_::into_raw(f),
466             )
467         }
468     }
469 
emit_activate(&self)470     fn emit_activate(&self) {
471         let _ = unsafe {
472             glib::Object::from_glib_borrow(self.to_glib_none().0 as *mut gobject_sys::GObject)
473                 .emit("activate", &[])
474                 .unwrap()
475         };
476     }
477 
connect_state_set<F: Fn(&Self, bool) -> glib::signal::Inhibit + 'static>( &self, f: F, ) -> SignalHandlerId478     fn connect_state_set<F: Fn(&Self, bool) -> glib::signal::Inhibit + 'static>(
479         &self,
480         f: F,
481     ) -> SignalHandlerId {
482         unsafe extern "C" fn state_set_trampoline<
483             P,
484             F: Fn(&P, bool) -> glib::signal::Inhibit + 'static,
485         >(
486             this: *mut gtk_sys::GtkSwitch,
487             state: glib_sys::gboolean,
488             f: glib_sys::gpointer,
489         ) -> glib_sys::gboolean
490         where
491             P: IsA<Switch>,
492         {
493             let f: &F = &*(f as *const F);
494             f(
495                 &Switch::from_glib_borrow(this).unsafe_cast(),
496                 from_glib(state),
497             )
498             .to_glib()
499         }
500         unsafe {
501             let f: Box_<F> = Box_::new(f);
502             connect_raw(
503                 self.as_ptr() as *mut _,
504                 b"state-set\0".as_ptr() as *const _,
505                 Some(transmute(state_set_trampoline::<Self, F> as usize)),
506                 Box_::into_raw(f),
507             )
508         }
509     }
510 
connect_property_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId511     fn connect_property_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
512         unsafe extern "C" fn notify_active_trampoline<P, F: Fn(&P) + 'static>(
513             this: *mut gtk_sys::GtkSwitch,
514             _param_spec: glib_sys::gpointer,
515             f: glib_sys::gpointer,
516         ) where
517             P: IsA<Switch>,
518         {
519             let f: &F = &*(f as *const F);
520             f(&Switch::from_glib_borrow(this).unsafe_cast())
521         }
522         unsafe {
523             let f: Box_<F> = Box_::new(f);
524             connect_raw(
525                 self.as_ptr() as *mut _,
526                 b"notify::active\0".as_ptr() as *const _,
527                 Some(transmute(notify_active_trampoline::<Self, F> as usize)),
528                 Box_::into_raw(f),
529             )
530         }
531     }
532 
connect_property_state_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId533     fn connect_property_state_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
534         unsafe extern "C" fn notify_state_trampoline<P, F: Fn(&P) + 'static>(
535             this: *mut gtk_sys::GtkSwitch,
536             _param_spec: glib_sys::gpointer,
537             f: glib_sys::gpointer,
538         ) where
539             P: IsA<Switch>,
540         {
541             let f: &F = &*(f as *const F);
542             f(&Switch::from_glib_borrow(this).unsafe_cast())
543         }
544         unsafe {
545             let f: Box_<F> = Box_::new(f);
546             connect_raw(
547                 self.as_ptr() as *mut _,
548                 b"notify::state\0".as_ptr() as *const _,
549                 Some(transmute(notify_state_trampoline::<Self, F> as usize)),
550                 Box_::into_raw(f),
551             )
552         }
553     }
554 }
555 
556 impl fmt::Display for Switch {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result557     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
558         write!(f, "Switch")
559     }
560 }
561