1use 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 ResizeMode;
24use ToolButton;
25use ToolItem;
26use Widget;
27
28glib_wrapper! {
29 pub struct ToggleToolButton(Object<gtk_sys::GtkToggleToolButton, gtk_sys::GtkToggleToolButtonClass, ToggleToolButtonClass>) @extends ToolButton, ToolItem, Bin, Container, Widget, @implements Buildable, Actionable;
30
31 match fn {
32 get_type => || gtk_sys::gtk_toggle_tool_button_get_type(),
33 }
34}
35
36impl ToggleToolButton {
37 pub fn new() -> ToggleToolButton {
38 assert_initialized_main_thread!();
39 unsafe { ToolItem::from_glib_none(gtk_sys::gtk_toggle_tool_button_new()).unsafe_cast() }
40 }
41}
42
43impl Default for ToggleToolButton {
44 fn default() -> Self {
45 Self::new()
46 }
47}
48
49pub struct ToggleToolButtonBuilder {
50 active: Option<bool>,
51 icon_name: Option<String>,
52 icon_widget: Option<Widget>,
53 label: Option<String>,
54 label_widget: Option<Widget>,
55 use_underline: Option<bool>,
56 is_important: Option<bool>,
57 visible_horizontal: Option<bool>,
58 visible_vertical: Option<bool>,
59 border_width: Option<u32>,
60 child: Option<Widget>,
61 resize_mode: Option<ResizeMode>,
62 app_paintable: Option<bool>,
63 can_default: Option<bool>,
64 can_focus: Option<bool>,
65 events: Option<gdk::EventMask>,
66 expand: Option<bool>,
67 #[cfg(any(feature = "v3_20", feature = "dox"))]
68 focus_on_click: Option<bool>,
69 halign: Option<Align>,
70 has_default: Option<bool>,
71 has_focus: Option<bool>,
72 has_tooltip: Option<bool>,
73 height_request: Option<i32>,
74 hexpand: Option<bool>,
75 hexpand_set: Option<bool>,
76 is_focus: Option<bool>,
77 margin: Option<i32>,
78 margin_bottom: Option<i32>,
79 margin_end: Option<i32>,
80 margin_start: Option<i32>,
81 margin_top: Option<i32>,
82 name: Option<String>,
83 no_show_all: Option<bool>,
84 opacity: Option<f64>,
85 parent: Option<Container>,
86 receives_default: Option<bool>,
87 sensitive: Option<bool>,
88 tooltip_markup: Option<String>,
90 tooltip_text: Option<String>,
91 valign: Option<Align>,
92 vexpand: Option<bool>,
93 vexpand_set: Option<bool>,
94 visible: Option<bool>,
95 width_request: Option<i32>,
96}
97
98impl ToggleToolButtonBuilder {
99 pub fn new() -> Self {
100 Self {
101 active: None,
102 icon_name: None,
103 icon_widget: None,
104 label: None,
105 label_widget: None,
106 use_underline: None,
107 is_important: None,
108 visible_horizontal: None,
109 visible_vertical: None,
110 border_width: None,
111 child: None,
112 resize_mode: None,
113 app_paintable: None,
114 can_default: None,
115 can_focus: None,
116 events: None,
117 expand: None,
118 #[cfg(any(feature = "v3_20", feature = "dox"))]
119 focus_on_click: None,
120 halign: None,
121 has_default: None,
122 has_focus: None,
123 has_tooltip: None,
124 height_request: None,
125 hexpand: None,
126 hexpand_set: None,
127 is_focus: None,
128 margin: None,
129 margin_bottom: None,
130 margin_end: None,
131 margin_start: None,
132 margin_top: None,
133 name: None,
134 no_show_all: None,
135 opacity: None,
136 parent: None,
137 receives_default: None,
138 sensitive: None,
139 tooltip_markup: None,
140 tooltip_text: None,
141 valign: None,
142 vexpand: None,
143 vexpand_set: None,
144 visible: None,
145 width_request: None,
146 }
147 }
148
149 pub fn build(self) -> ToggleToolButton {
150 let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
151 if let Some(ref active) = self.active {
152 properties.push(("active", active));
153 }
154 if let Some(ref icon_name) = self.icon_name {
155 properties.push(("icon-name", icon_name));
156 }
157 if let Some(ref icon_widget) = self.icon_widget {
158 properties.push(("icon-widget", icon_widget));
159 }
160 if let Some(ref label) = self.label {
161 properties.push(("label", label));
162 }
163 if let Some(ref label_widget) = self.label_widget {
164 properties.push(("label-widget", label_widget));
165 }
166 if let Some(ref use_underline) = self.use_underline {
167 properties.push(("use-underline", use_underline));
168 }
169 if let Some(ref is_important) = self.is_important {
170 properties.push(("is-important", is_important));
171 }
172 if let Some(ref visible_horizontal) = self.visible_horizontal {
173 properties.push(("visible-horizontal", visible_horizontal));
174 }
175 if let Some(ref visible_vertical) = self.visible_vertical {
176 properties.push(("visible-vertical", visible_vertical));
177 }
178 if let Some(ref border_width) = self.border_width {
179 properties.push(("border-width", border_width));
180 }
181 if let Some(ref child) = self.child {
182 properties.push(("child", child));
183 }
184 if let Some(ref resize_mode) = self.resize_mode {
185 properties.push(("resize-mode", resize_mode));
186 }
187 if let Some(ref app_paintable) = self.app_paintable {
188 properties.push(("app-paintable", app_paintable));
189 }
190 if let Some(ref can_default) = self.can_default {
191 properties.push(("can-default", can_default));
192 }
193 if let Some(ref can_focus) = self.can_focus {
194 properties.push(("can-focus", can_focus));
195 }
196 if let Some(ref events) = self.events {
197 properties.push(("events", events));
198 }
199 if let Some(ref expand) = self.expand {
200 properties.push(("expand", expand));
201 }
202 #[cfg(any(feature = "v3_20", feature = "dox"))]
203 {
204 if let Some(ref focus_on_click) = self.focus_on_click {
205 properties.push(("focus-on-click", focus_on_click));
206 }
207 }
208 if let Some(ref halign) = self.halign {
209 properties.push(("halign", halign));
210 }
211 if let Some(ref has_default) = self.has_default {
212 properties.push(("has-default", has_default));
213 }
214 if let Some(ref has_focus) = self.has_focus {
215 properties.push(("has-focus", has_focus));
216 }
217 if let Some(ref has_tooltip) = self.has_tooltip {
218 properties.push(("has-tooltip", has_tooltip));
219 }
220 if let Some(ref height_request) = self.height_request {
221 properties.push(("height-request", height_request));
222 }
223 if let Some(ref hexpand) = self.hexpand {
224 properties.push(("hexpand", hexpand));
225 }
226 if let Some(ref hexpand_set) = self.hexpand_set {
227 properties.push(("hexpand-set", hexpand_set));
228 }
229 if let Some(ref is_focus) = self.is_focus {
230 properties.push(("is-focus", is_focus));
231 }
232 if let Some(ref margin) = self.margin {
233 properties.push(("margin", margin));
234 }
235 if let Some(ref margin_bottom) = self.margin_bottom {
236 properties.push(("margin-bottom", margin_bottom));
237 }
238 if let Some(ref margin_end) = self.margin_end {
239 properties.push(("margin-end", margin_end));
240 }
241 if let Some(ref margin_start) = self.margin_start {
242 properties.push(("margin-start", margin_start));
243 }
244 if let Some(ref margin_top) = self.margin_top {
245 properties.push(("margin-top", margin_top));
246 }
247 if let Some(ref name) = self.name {
248 properties.push(("name", name));
249 }
250 if let Some(ref no_show_all) = self.no_show_all {
251 properties.push(("no-show-all", no_show_all));
252 }
253 if let Some(ref opacity) = self.opacity {
254 properties.push(("opacity", opacity));
255 }
256 if let Some(ref parent) = self.parent {
257 properties.push(("parent", parent));
258 }
259 if let Some(ref receives_default) = self.receives_default {
260 properties.push(("receives-default", receives_default));
261 }
262 if let Some(ref sensitive) = self.sensitive {
263 properties.push(("sensitive", sensitive));
264 }
265 if let Some(ref tooltip_markup) = self.tooltip_markup {
266 properties.push(("tooltip-markup", tooltip_markup));
267 }
268 if let Some(ref tooltip_text) = self.tooltip_text {
269 properties.push(("tooltip-text", tooltip_text));
270 }
271 if let Some(ref valign) = self.valign {
272 properties.push(("valign", valign));
273 }
274 if let Some(ref vexpand) = self.vexpand {
275 properties.push(("vexpand", vexpand));
276 }
277 if let Some(ref vexpand_set) = self.vexpand_set {
278 properties.push(("vexpand-set", vexpand_set));
279 }
280 if let Some(ref visible) = self.visible {
281 properties.push(("visible", visible));
282 }
283 if let Some(ref width_request) = self.width_request {
284 properties.push(("width-request", width_request));
285 }
286 glib::Object::new(ToggleToolButton::static_type(), &properties)
287 .expect("object new")
288 .downcast()
289 .expect("downcast")
290 }
291
292 pub fn active(mut self, active: bool) -> Self {
293 self.active = Some(active);
294 self
295 }
296
297 pub fn icon_name(mut self, icon_name: &str) -> Self {
298 self.icon_name = Some(icon_name.to_string());
299 self
300 }
301
302 pub fn icon_widget(mut self, icon_widget: &Widget) -> Self {
303 self.icon_widget = Some(icon_widget.clone());
304 self
305 }
306
307 pub fn label(mut self, label: &str) -> Self {
308 self.label = Some(label.to_string());
309 self
310 }
311
312 pub fn label_widget(mut self, label_widget: &Widget) -> Self {
313 self.label_widget = Some(label_widget.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 is_important(mut self, is_important: bool) -> Self {
323 self.is_important = Some(is_important);
324 self
325 }
326
327 pub fn visible_horizontal(mut self, visible_horizontal: bool) -> Self {
328 self.visible_horizontal = Some(visible_horizontal);
329 self
330 }
331
332 pub fn visible_vertical(mut self, visible_vertical: bool) -> Self {
333 self.visible_vertical = Some(visible_vertical);
334 self
335 }
336
337 pub fn border_width(mut self, border_width: u32) -> Self {
338 self.border_width = Some(border_width);
339 self
340 }
341
342 pub fn child(mut self, child: &Widget) -> Self {
343 self.child = Some(child.clone());
344 self
345 }
346
347 pub fn resize_mode(mut self, resize_mode: ResizeMode) -> Self {
348 self.resize_mode = Some(resize_mode);
349 self
350 }
351
352 pub fn app_paintable(mut self, app_paintable: bool) -> Self {
353 self.app_paintable = Some(app_paintable);
354 self
355 }
356
357 pub fn can_default(mut self, can_default: bool) -> Self {
358 self.can_default = Some(can_default);
359 self
360 }
361
362 pub fn can_focus(mut self, can_focus: bool) -> Self {
363 self.can_focus = Some(can_focus);
364 self
365 }
366
367 pub fn events(mut self, events: gdk::EventMask) -> Self {
368 self.events = Some(events);
369 self
370 }
371
372 pub fn expand(mut self, expand: bool) -> Self {
373 self.expand = Some(expand);
374 self
375 }
376
377 #[cfg(any(feature = "v3_20", feature = "dox"))]
378 pub fn focus_on_click(mut self, focus_on_click: bool) -> Self {
379 self.focus_on_click = Some(focus_on_click);
380 self
381 }
382
383 pub fn halign(mut self, halign: Align) -> Self {
384 self.halign = Some(halign);
385 self
386 }
387
388 pub fn has_default(mut self, has_default: bool) -> Self {
389 self.has_default = Some(has_default);
390 self
391 }
392
393 pub fn has_focus(mut self, has_focus: bool) -> Self {
394 self.has_focus = Some(has_focus);
395 self
396 }
397
398 pub fn has_tooltip(mut self, has_tooltip: bool) -> Self {
399 self.has_tooltip = Some(has_tooltip);
400 self
401 }
402
403 pub fn height_request(mut self, height_request: i32) -> Self {
404 self.height_request = Some(height_request);
405 self
406 }
407
408 pub fn hexpand(mut self, hexpand: bool) -> Self {
409 self.hexpand = Some(hexpand);
410 self
411 }
412
413 pub fn hexpand_set(mut self, hexpand_set: bool) -> Self {
414 self.hexpand_set = Some(hexpand_set);
415 self
416 }
417
418 pub fn is_focus(mut self, is_focus: bool) -> Self {
419 self.is_focus = Some(is_focus);
420 self
421 }
422
423 pub fn margin(mut self, margin: i32) -> Self {
424 self.margin = Some(margin);
425 self
426 }
427
428 pub fn margin_bottom(mut self, margin_bottom: i32) -> Self {
429 self.margin_bottom = Some(margin_bottom);
430 self
431 }
432
433 pub fn margin_end(mut self, margin_end: i32) -> Self {
434 self.margin_end = Some(margin_end);
435 self
436 }
437
438 pub fn margin_start(mut self, margin_start: i32) -> Self {
439 self.margin_start = Some(margin_start);
440 self
441 }
442
443 pub fn margin_top(mut self, margin_top: i32) -> Self {
444 self.margin_top = Some(margin_top);
445 self
446 }
447
448 pub fn name(mut self, name: &str) -> Self {
449 self.name = Some(name.to_string());
450 self
451 }
452
453 pub fn no_show_all(mut self, no_show_all: bool) -> Self {
454 self.no_show_all = Some(no_show_all);
455 self
456 }
457
458 pub fn opacity(mut self, opacity: f64) -> Self {
459 self.opacity = Some(opacity);
460 self
461 }
462
463 pub fn parent(mut self, parent: &Container) -> Self {
464 self.parent = Some(parent.clone());
465 self
466 }
467
468 pub fn receives_default(mut self, receives_default: bool) -> Self {
469 self.receives_default = Some(receives_default);
470 self
471 }
472
473 pub fn sensitive(mut self, sensitive: bool) -> Self {
474 self.sensitive = Some(sensitive);
475 self
476 }
477
478 pub fn tooltip_markup(mut self, tooltip_markup: &str) -> Self {
479 self.tooltip_markup = Some(tooltip_markup.to_string());
480 self
481 }
482
483 pub fn tooltip_text(mut self, tooltip_text: &str) -> Self {
484 self.tooltip_text = Some(tooltip_text.to_string());
485 self
486 }
487
488 pub fn valign(mut self, valign: Align) -> Self {
489 self.valign = Some(valign);
490 self
491 }
492
493 pub fn vexpand(mut self, vexpand: bool) -> Self {
494 self.vexpand = Some(vexpand);
495 self
496 }
497
498 pub fn vexpand_set(mut self, vexpand_set: bool) -> Self {
499 self.vexpand_set = Some(vexpand_set);
500 self
501 }
502
503 pub fn visible(mut self, visible: bool) -> Self {
504 self.visible = Some(visible);
505 self
506 }
507
508 pub fn width_request(mut self, width_request: i32) -> Self {
509 self.width_request = Some(width_request);
510 self
511 }
512}
513
514pub const NONE_TOGGLE_TOOL_BUTTON: Option<&ToggleToolButton> = None;
515
516pub trait ToggleToolButtonExt: 'static {
517 fn get_active(&self) -> bool;
518
519 fn set_active(&self, is_active: bool);
520
521 fn connect_toggled<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
522
523 fn connect_property_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
524}
525
526impl<O: IsA<ToggleToolButton>> ToggleToolButtonExt for O {
527 fn get_active(&self) -> bool {
528 unsafe {
529 from_glib(gtk_sys::gtk_toggle_tool_button_get_active(
530 self.as_ref().to_glib_none().0,
531 ))
532 }
533 }
534
535 fn set_active(&self, is_active: bool) {
536 unsafe {
537 gtk_sys::gtk_toggle_tool_button_set_active(
538 self.as_ref().to_glib_none().0,
539 is_active.to_glib(),
540 );
541 }
542 }
543
544 fn connect_toggled<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
545 unsafe extern "C" fn toggled_trampoline<P, F: Fn(&P) + 'static>(
546 this: *mut gtk_sys::GtkToggleToolButton,
547 f: glib_sys::gpointer,
548 ) where
549 P: IsA<ToggleToolButton>,
550 {
551 let f: &F = &*(f as *const F);
552 f(&ToggleToolButton::from_glib_borrow(this).unsafe_cast())
553 }
554 unsafe {
555 let f: Box_<F> = Box_::new(f);
556 connect_raw(
557 self.as_ptr() as *mut _,
558 b"toggled\0".as_ptr() as *const _,
559 Some(transmute(toggled_trampoline::<Self, F> as usize)),
560 Box_::into_raw(f),
561 )
562 }
563 }
564
565 fn connect_property_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
566 unsafe extern "C" fn notify_active_trampoline<P, F: Fn(&P) + 'static>(
567 this: *mut gtk_sys::GtkToggleToolButton,
568 _param_spec: glib_sys::gpointer,
569 f: glib_sys::gpointer,
570 ) where
571 P: IsA<ToggleToolButton>,
572 {
573 let f: &F = &*(f as *const F);
574 f(&ToggleToolButton::from_glib_borrow(this).unsafe_cast())
575 }
576 unsafe {
577 let f: Box_<F> = Box_::new(f);
578 connect_raw(
579 self.as_ptr() as *mut _,
580 b"notify::active\0".as_ptr() as *const _,
581 Some(transmute(notify_active_trampoline::<Self, F> as usize)),
582 Box_::into_raw(f),
583 )
584 }
585 }
586}
587
588impl fmt::Display for ToggleToolButton {
589 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
590 write!(f, "ToggleToolButton")
591 }
592}