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 crate::Actionable;
6 use crate::Align;
7 use crate::Bin;
8 use crate::Buildable;
9 use crate::Container;
10 use crate::ResizeMode;
11 use crate::ToolButton;
12 use crate::ToolItem;
13 use crate::Widget;
14 use glib::object::Cast;
15 use glib::object::IsA;
16 use glib::signal::connect_raw;
17 use glib::signal::SignalHandlerId;
18 use glib::translate::*;
19 use glib::StaticType;
20 use glib::ToValue;
21 use std::boxed::Box as Box_;
22 use std::fmt;
23 use std::mem::transmute;
24 
25 glib::wrapper! {
26     #[doc(alias = "GtkToggleToolButton")]
27     pub struct ToggleToolButton(Object<ffi::GtkToggleToolButton, ffi::GtkToggleToolButtonClass>) @extends ToolButton, ToolItem, Bin, Container, Widget, @implements Buildable, Actionable;
28 
29     match fn {
30         type_ => || ffi::gtk_toggle_tool_button_get_type(),
31     }
32 }
33 
34 impl ToggleToolButton {
35     #[doc(alias = "gtk_toggle_tool_button_new")]
new() -> ToggleToolButton36     pub fn new() -> ToggleToolButton {
37         assert_initialized_main_thread!();
38         unsafe { ToolItem::from_glib_none(ffi::gtk_toggle_tool_button_new()).unsafe_cast() }
39     }
40 
41     // rustdoc-stripper-ignore-next
42     /// Creates a new builder-pattern struct instance to construct [`ToggleToolButton`] objects.
43     ///
44     /// This method returns an instance of [`ToggleToolButtonBuilder`] which can be used to create [`ToggleToolButton`] objects.
builder() -> ToggleToolButtonBuilder45     pub fn builder() -> ToggleToolButtonBuilder {
46         ToggleToolButtonBuilder::default()
47     }
48 }
49 
50 impl Default for ToggleToolButton {
default() -> Self51     fn default() -> Self {
52         Self::new()
53     }
54 }
55 
56 #[derive(Clone, Default)]
57 // rustdoc-stripper-ignore-next
58 /// A [builder-pattern] type to construct [`ToggleToolButton`] objects.
59 ///
60 /// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
61 pub struct ToggleToolButtonBuilder {
62     active: Option<bool>,
63     icon_name: Option<String>,
64     icon_widget: Option<Widget>,
65     label: Option<String>,
66     label_widget: Option<Widget>,
67     use_underline: Option<bool>,
68     is_important: Option<bool>,
69     visible_horizontal: Option<bool>,
70     visible_vertical: Option<bool>,
71     border_width: Option<u32>,
72     child: Option<Widget>,
73     resize_mode: Option<ResizeMode>,
74     app_paintable: Option<bool>,
75     can_default: Option<bool>,
76     can_focus: Option<bool>,
77     events: Option<gdk::EventMask>,
78     expand: Option<bool>,
79     #[cfg(any(feature = "v3_20", feature = "dox"))]
80     #[cfg_attr(feature = "dox", doc(cfg(feature = "v3_20")))]
81     focus_on_click: Option<bool>,
82     halign: Option<Align>,
83     has_default: Option<bool>,
84     has_focus: Option<bool>,
85     has_tooltip: Option<bool>,
86     height_request: Option<i32>,
87     hexpand: Option<bool>,
88     hexpand_set: Option<bool>,
89     is_focus: Option<bool>,
90     margin: Option<i32>,
91     margin_bottom: Option<i32>,
92     margin_end: Option<i32>,
93     margin_start: Option<i32>,
94     margin_top: Option<i32>,
95     name: Option<String>,
96     no_show_all: Option<bool>,
97     opacity: Option<f64>,
98     parent: Option<Container>,
99     receives_default: Option<bool>,
100     sensitive: Option<bool>,
101     tooltip_markup: Option<String>,
102     tooltip_text: Option<String>,
103     valign: Option<Align>,
104     vexpand: Option<bool>,
105     vexpand_set: Option<bool>,
106     visible: Option<bool>,
107     width_request: Option<i32>,
108     action_name: Option<String>,
109     action_target: Option<glib::Variant>,
110 }
111 
112 impl ToggleToolButtonBuilder {
113     // rustdoc-stripper-ignore-next
114     /// Create a new [`ToggleToolButtonBuilder`].
new() -> Self115     pub fn new() -> Self {
116         Self::default()
117     }
118 
119     // rustdoc-stripper-ignore-next
120     /// Build the [`ToggleToolButton`].
build(self) -> ToggleToolButton121     pub fn build(self) -> ToggleToolButton {
122         let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
123         if let Some(ref active) = self.active {
124             properties.push(("active", active));
125         }
126         if let Some(ref icon_name) = self.icon_name {
127             properties.push(("icon-name", icon_name));
128         }
129         if let Some(ref icon_widget) = self.icon_widget {
130             properties.push(("icon-widget", icon_widget));
131         }
132         if let Some(ref label) = self.label {
133             properties.push(("label", label));
134         }
135         if let Some(ref label_widget) = self.label_widget {
136             properties.push(("label-widget", label_widget));
137         }
138         if let Some(ref use_underline) = self.use_underline {
139             properties.push(("use-underline", use_underline));
140         }
141         if let Some(ref is_important) = self.is_important {
142             properties.push(("is-important", is_important));
143         }
144         if let Some(ref visible_horizontal) = self.visible_horizontal {
145             properties.push(("visible-horizontal", visible_horizontal));
146         }
147         if let Some(ref visible_vertical) = self.visible_vertical {
148             properties.push(("visible-vertical", visible_vertical));
149         }
150         if let Some(ref border_width) = self.border_width {
151             properties.push(("border-width", border_width));
152         }
153         if let Some(ref child) = self.child {
154             properties.push(("child", child));
155         }
156         if let Some(ref resize_mode) = self.resize_mode {
157             properties.push(("resize-mode", resize_mode));
158         }
159         if let Some(ref app_paintable) = self.app_paintable {
160             properties.push(("app-paintable", app_paintable));
161         }
162         if let Some(ref can_default) = self.can_default {
163             properties.push(("can-default", can_default));
164         }
165         if let Some(ref can_focus) = self.can_focus {
166             properties.push(("can-focus", can_focus));
167         }
168         if let Some(ref events) = self.events {
169             properties.push(("events", events));
170         }
171         if let Some(ref expand) = self.expand {
172             properties.push(("expand", expand));
173         }
174         #[cfg(any(feature = "v3_20", feature = "dox"))]
175         if let Some(ref focus_on_click) = self.focus_on_click {
176             properties.push(("focus-on-click", focus_on_click));
177         }
178         if let Some(ref halign) = self.halign {
179             properties.push(("halign", halign));
180         }
181         if let Some(ref has_default) = self.has_default {
182             properties.push(("has-default", has_default));
183         }
184         if let Some(ref has_focus) = self.has_focus {
185             properties.push(("has-focus", has_focus));
186         }
187         if let Some(ref has_tooltip) = self.has_tooltip {
188             properties.push(("has-tooltip", has_tooltip));
189         }
190         if let Some(ref height_request) = self.height_request {
191             properties.push(("height-request", height_request));
192         }
193         if let Some(ref hexpand) = self.hexpand {
194             properties.push(("hexpand", hexpand));
195         }
196         if let Some(ref hexpand_set) = self.hexpand_set {
197             properties.push(("hexpand-set", hexpand_set));
198         }
199         if let Some(ref is_focus) = self.is_focus {
200             properties.push(("is-focus", is_focus));
201         }
202         if let Some(ref margin) = self.margin {
203             properties.push(("margin", margin));
204         }
205         if let Some(ref margin_bottom) = self.margin_bottom {
206             properties.push(("margin-bottom", margin_bottom));
207         }
208         if let Some(ref margin_end) = self.margin_end {
209             properties.push(("margin-end", margin_end));
210         }
211         if let Some(ref margin_start) = self.margin_start {
212             properties.push(("margin-start", margin_start));
213         }
214         if let Some(ref margin_top) = self.margin_top {
215             properties.push(("margin-top", margin_top));
216         }
217         if let Some(ref name) = self.name {
218             properties.push(("name", name));
219         }
220         if let Some(ref no_show_all) = self.no_show_all {
221             properties.push(("no-show-all", no_show_all));
222         }
223         if let Some(ref opacity) = self.opacity {
224             properties.push(("opacity", opacity));
225         }
226         if let Some(ref parent) = self.parent {
227             properties.push(("parent", parent));
228         }
229         if let Some(ref receives_default) = self.receives_default {
230             properties.push(("receives-default", receives_default));
231         }
232         if let Some(ref sensitive) = self.sensitive {
233             properties.push(("sensitive", sensitive));
234         }
235         if let Some(ref tooltip_markup) = self.tooltip_markup {
236             properties.push(("tooltip-markup", tooltip_markup));
237         }
238         if let Some(ref tooltip_text) = self.tooltip_text {
239             properties.push(("tooltip-text", tooltip_text));
240         }
241         if let Some(ref valign) = self.valign {
242             properties.push(("valign", valign));
243         }
244         if let Some(ref vexpand) = self.vexpand {
245             properties.push(("vexpand", vexpand));
246         }
247         if let Some(ref vexpand_set) = self.vexpand_set {
248             properties.push(("vexpand-set", vexpand_set));
249         }
250         if let Some(ref visible) = self.visible {
251             properties.push(("visible", visible));
252         }
253         if let Some(ref width_request) = self.width_request {
254             properties.push(("width-request", width_request));
255         }
256         if let Some(ref action_name) = self.action_name {
257             properties.push(("action-name", action_name));
258         }
259         if let Some(ref action_target) = self.action_target {
260             properties.push(("action-target", action_target));
261         }
262         glib::Object::new::<ToggleToolButton>(&properties)
263             .expect("Failed to create an instance of ToggleToolButton")
264     }
265 
active(mut self, active: bool) -> Self266     pub fn active(mut self, active: bool) -> Self {
267         self.active = Some(active);
268         self
269     }
270 
icon_name(mut self, icon_name: &str) -> Self271     pub fn icon_name(mut self, icon_name: &str) -> Self {
272         self.icon_name = Some(icon_name.to_string());
273         self
274     }
275 
icon_widget<P: IsA<Widget>>(mut self, icon_widget: &P) -> Self276     pub fn icon_widget<P: IsA<Widget>>(mut self, icon_widget: &P) -> Self {
277         self.icon_widget = Some(icon_widget.clone().upcast());
278         self
279     }
280 
label(mut self, label: &str) -> Self281     pub fn label(mut self, label: &str) -> Self {
282         self.label = Some(label.to_string());
283         self
284     }
285 
label_widget<P: IsA<Widget>>(mut self, label_widget: &P) -> Self286     pub fn label_widget<P: IsA<Widget>>(mut self, label_widget: &P) -> Self {
287         self.label_widget = Some(label_widget.clone().upcast());
288         self
289     }
290 
use_underline(mut self, use_underline: bool) -> Self291     pub fn use_underline(mut self, use_underline: bool) -> Self {
292         self.use_underline = Some(use_underline);
293         self
294     }
295 
is_important(mut self, is_important: bool) -> Self296     pub fn is_important(mut self, is_important: bool) -> Self {
297         self.is_important = Some(is_important);
298         self
299     }
300 
visible_horizontal(mut self, visible_horizontal: bool) -> Self301     pub fn visible_horizontal(mut self, visible_horizontal: bool) -> Self {
302         self.visible_horizontal = Some(visible_horizontal);
303         self
304     }
305 
visible_vertical(mut self, visible_vertical: bool) -> Self306     pub fn visible_vertical(mut self, visible_vertical: bool) -> Self {
307         self.visible_vertical = Some(visible_vertical);
308         self
309     }
310 
border_width(mut self, border_width: u32) -> Self311     pub fn border_width(mut self, border_width: u32) -> Self {
312         self.border_width = Some(border_width);
313         self
314     }
315 
child<P: IsA<Widget>>(mut self, child: &P) -> Self316     pub fn child<P: IsA<Widget>>(mut self, child: &P) -> Self {
317         self.child = Some(child.clone().upcast());
318         self
319     }
320 
resize_mode(mut self, resize_mode: ResizeMode) -> Self321     pub fn resize_mode(mut self, resize_mode: ResizeMode) -> Self {
322         self.resize_mode = Some(resize_mode);
323         self
324     }
325 
app_paintable(mut self, app_paintable: bool) -> Self326     pub fn app_paintable(mut self, app_paintable: bool) -> Self {
327         self.app_paintable = Some(app_paintable);
328         self
329     }
330 
can_default(mut self, can_default: bool) -> Self331     pub fn can_default(mut self, can_default: bool) -> Self {
332         self.can_default = Some(can_default);
333         self
334     }
335 
can_focus(mut self, can_focus: bool) -> Self336     pub fn can_focus(mut self, can_focus: bool) -> Self {
337         self.can_focus = Some(can_focus);
338         self
339     }
340 
events(mut self, events: gdk::EventMask) -> Self341     pub fn events(mut self, events: gdk::EventMask) -> Self {
342         self.events = Some(events);
343         self
344     }
345 
expand(mut self, expand: bool) -> Self346     pub fn expand(mut self, expand: bool) -> Self {
347         self.expand = Some(expand);
348         self
349     }
350 
351     #[cfg(any(feature = "v3_20", feature = "dox"))]
352     #[cfg_attr(feature = "dox", doc(cfg(feature = "v3_20")))]
focus_on_click(mut self, focus_on_click: bool) -> Self353     pub fn focus_on_click(mut self, focus_on_click: bool) -> Self {
354         self.focus_on_click = Some(focus_on_click);
355         self
356     }
357 
halign(mut self, halign: Align) -> Self358     pub fn halign(mut self, halign: Align) -> Self {
359         self.halign = Some(halign);
360         self
361     }
362 
has_default(mut self, has_default: bool) -> Self363     pub fn has_default(mut self, has_default: bool) -> Self {
364         self.has_default = Some(has_default);
365         self
366     }
367 
has_focus(mut self, has_focus: bool) -> Self368     pub fn has_focus(mut self, has_focus: bool) -> Self {
369         self.has_focus = Some(has_focus);
370         self
371     }
372 
has_tooltip(mut self, has_tooltip: bool) -> Self373     pub fn has_tooltip(mut self, has_tooltip: bool) -> Self {
374         self.has_tooltip = Some(has_tooltip);
375         self
376     }
377 
height_request(mut self, height_request: i32) -> Self378     pub fn height_request(mut self, height_request: i32) -> Self {
379         self.height_request = Some(height_request);
380         self
381     }
382 
hexpand(mut self, hexpand: bool) -> Self383     pub fn hexpand(mut self, hexpand: bool) -> Self {
384         self.hexpand = Some(hexpand);
385         self
386     }
387 
hexpand_set(mut self, hexpand_set: bool) -> Self388     pub fn hexpand_set(mut self, hexpand_set: bool) -> Self {
389         self.hexpand_set = Some(hexpand_set);
390         self
391     }
392 
is_focus(mut self, is_focus: bool) -> Self393     pub fn is_focus(mut self, is_focus: bool) -> Self {
394         self.is_focus = Some(is_focus);
395         self
396     }
397 
margin(mut self, margin: i32) -> Self398     pub fn margin(mut self, margin: i32) -> Self {
399         self.margin = Some(margin);
400         self
401     }
402 
margin_bottom(mut self, margin_bottom: i32) -> Self403     pub fn margin_bottom(mut self, margin_bottom: i32) -> Self {
404         self.margin_bottom = Some(margin_bottom);
405         self
406     }
407 
margin_end(mut self, margin_end: i32) -> Self408     pub fn margin_end(mut self, margin_end: i32) -> Self {
409         self.margin_end = Some(margin_end);
410         self
411     }
412 
margin_start(mut self, margin_start: i32) -> Self413     pub fn margin_start(mut self, margin_start: i32) -> Self {
414         self.margin_start = Some(margin_start);
415         self
416     }
417 
margin_top(mut self, margin_top: i32) -> Self418     pub fn margin_top(mut self, margin_top: i32) -> Self {
419         self.margin_top = Some(margin_top);
420         self
421     }
422 
name(mut self, name: &str) -> Self423     pub fn name(mut self, name: &str) -> Self {
424         self.name = Some(name.to_string());
425         self
426     }
427 
no_show_all(mut self, no_show_all: bool) -> Self428     pub fn no_show_all(mut self, no_show_all: bool) -> Self {
429         self.no_show_all = Some(no_show_all);
430         self
431     }
432 
opacity(mut self, opacity: f64) -> Self433     pub fn opacity(mut self, opacity: f64) -> Self {
434         self.opacity = Some(opacity);
435         self
436     }
437 
parent<P: IsA<Container>>(mut self, parent: &P) -> Self438     pub fn parent<P: IsA<Container>>(mut self, parent: &P) -> Self {
439         self.parent = Some(parent.clone().upcast());
440         self
441     }
442 
receives_default(mut self, receives_default: bool) -> Self443     pub fn receives_default(mut self, receives_default: bool) -> Self {
444         self.receives_default = Some(receives_default);
445         self
446     }
447 
sensitive(mut self, sensitive: bool) -> Self448     pub fn sensitive(mut self, sensitive: bool) -> Self {
449         self.sensitive = Some(sensitive);
450         self
451     }
452 
tooltip_markup(mut self, tooltip_markup: &str) -> Self453     pub fn tooltip_markup(mut self, tooltip_markup: &str) -> Self {
454         self.tooltip_markup = Some(tooltip_markup.to_string());
455         self
456     }
457 
tooltip_text(mut self, tooltip_text: &str) -> Self458     pub fn tooltip_text(mut self, tooltip_text: &str) -> Self {
459         self.tooltip_text = Some(tooltip_text.to_string());
460         self
461     }
462 
valign(mut self, valign: Align) -> Self463     pub fn valign(mut self, valign: Align) -> Self {
464         self.valign = Some(valign);
465         self
466     }
467 
vexpand(mut self, vexpand: bool) -> Self468     pub fn vexpand(mut self, vexpand: bool) -> Self {
469         self.vexpand = Some(vexpand);
470         self
471     }
472 
vexpand_set(mut self, vexpand_set: bool) -> Self473     pub fn vexpand_set(mut self, vexpand_set: bool) -> Self {
474         self.vexpand_set = Some(vexpand_set);
475         self
476     }
477 
visible(mut self, visible: bool) -> Self478     pub fn visible(mut self, visible: bool) -> Self {
479         self.visible = Some(visible);
480         self
481     }
482 
width_request(mut self, width_request: i32) -> Self483     pub fn width_request(mut self, width_request: i32) -> Self {
484         self.width_request = Some(width_request);
485         self
486     }
487 
action_name(mut self, action_name: &str) -> Self488     pub fn action_name(mut self, action_name: &str) -> Self {
489         self.action_name = Some(action_name.to_string());
490         self
491     }
492 
action_target(mut self, action_target: &glib::Variant) -> Self493     pub fn action_target(mut self, action_target: &glib::Variant) -> Self {
494         self.action_target = Some(action_target.clone());
495         self
496     }
497 }
498 
499 pub const NONE_TOGGLE_TOOL_BUTTON: Option<&ToggleToolButton> = None;
500 
501 pub trait ToggleToolButtonExt: 'static {
502     #[doc(alias = "gtk_toggle_tool_button_get_active")]
503     #[doc(alias = "get_active")]
is_active(&self) -> bool504     fn is_active(&self) -> bool;
505 
506     #[doc(alias = "gtk_toggle_tool_button_set_active")]
set_active(&self, is_active: bool)507     fn set_active(&self, is_active: bool);
508 
509     #[doc(alias = "toggled")]
connect_toggled<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId510     fn connect_toggled<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
511 
512     #[doc(alias = "active")]
connect_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId513     fn connect_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
514 }
515 
516 impl<O: IsA<ToggleToolButton>> ToggleToolButtonExt for O {
is_active(&self) -> bool517     fn is_active(&self) -> bool {
518         unsafe {
519             from_glib(ffi::gtk_toggle_tool_button_get_active(
520                 self.as_ref().to_glib_none().0,
521             ))
522         }
523     }
524 
set_active(&self, is_active: bool)525     fn set_active(&self, is_active: bool) {
526         unsafe {
527             ffi::gtk_toggle_tool_button_set_active(
528                 self.as_ref().to_glib_none().0,
529                 is_active.into_glib(),
530             );
531         }
532     }
533 
connect_toggled<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId534     fn connect_toggled<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
535         unsafe extern "C" fn toggled_trampoline<P: IsA<ToggleToolButton>, F: Fn(&P) + 'static>(
536             this: *mut ffi::GtkToggleToolButton,
537             f: glib::ffi::gpointer,
538         ) {
539             let f: &F = &*(f as *const F);
540             f(ToggleToolButton::from_glib_borrow(this).unsafe_cast_ref())
541         }
542         unsafe {
543             let f: Box_<F> = Box_::new(f);
544             connect_raw(
545                 self.as_ptr() as *mut _,
546                 b"toggled\0".as_ptr() as *const _,
547                 Some(transmute::<_, unsafe extern "C" fn()>(
548                     toggled_trampoline::<Self, F> as *const (),
549                 )),
550                 Box_::into_raw(f),
551             )
552         }
553     }
554 
connect_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId555     fn connect_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
556         unsafe extern "C" fn notify_active_trampoline<
557             P: IsA<ToggleToolButton>,
558             F: Fn(&P) + 'static,
559         >(
560             this: *mut ffi::GtkToggleToolButton,
561             _param_spec: glib::ffi::gpointer,
562             f: glib::ffi::gpointer,
563         ) {
564             let f: &F = &*(f as *const F);
565             f(ToggleToolButton::from_glib_borrow(this).unsafe_cast_ref())
566         }
567         unsafe {
568             let f: Box_<F> = Box_::new(f);
569             connect_raw(
570                 self.as_ptr() as *mut _,
571                 b"notify::active\0".as_ptr() as *const _,
572                 Some(transmute::<_, unsafe extern "C" fn()>(
573                     notify_active_trampoline::<Self, F> as *const (),
574                 )),
575                 Box_::into_raw(f),
576             )
577         }
578     }
579 }
580 
581 impl fmt::Display for ToggleToolButton {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result582     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
583         f.write_str("ToggleToolButton")
584     }
585 }
586