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