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 glib::object::Cast;
6 use glib::object::IsA;
7 use glib::signal::connect_raw;
8 use glib::signal::SignalHandlerId;
9 use glib::translate::*;
10 use std::boxed::Box as Box_;
11 use std::fmt;
12 use std::mem::transmute;
13 
14 glib::wrapper! {
15     #[doc(alias = "GtkColorChooser")]
16     pub struct ColorChooser(Interface<ffi::GtkColorChooser, ffi::GtkColorChooserInterface>);
17 
18     match fn {
19         type_ => || ffi::gtk_color_chooser_get_type(),
20     }
21 }
22 
23 pub const NONE_COLOR_CHOOSER: Option<&ColorChooser> = None;
24 
25 pub trait ColorChooserExt: 'static {
26     #[doc(alias = "gtk_color_chooser_get_rgba")]
27     #[doc(alias = "get_rgba")]
rgba(&self) -> gdk::RGBA28     fn rgba(&self) -> gdk::RGBA;
29 
30     #[doc(alias = "gtk_color_chooser_get_use_alpha")]
31     #[doc(alias = "get_use_alpha")]
uses_alpha(&self) -> bool32     fn uses_alpha(&self) -> bool;
33 
34     #[doc(alias = "gtk_color_chooser_set_rgba")]
set_rgba(&self, color: &gdk::RGBA)35     fn set_rgba(&self, color: &gdk::RGBA);
36 
37     #[doc(alias = "gtk_color_chooser_set_use_alpha")]
set_use_alpha(&self, use_alpha: bool)38     fn set_use_alpha(&self, use_alpha: bool);
39 
40     #[doc(alias = "color-activated")]
connect_color_activated<F: Fn(&Self, &gdk::RGBA) + 'static>(&self, f: F) -> SignalHandlerId41     fn connect_color_activated<F: Fn(&Self, &gdk::RGBA) + 'static>(&self, f: F) -> SignalHandlerId;
42 
43     #[doc(alias = "rgba")]
connect_rgba_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId44     fn connect_rgba_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
45 
46     #[doc(alias = "use-alpha")]
connect_use_alpha_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId47     fn connect_use_alpha_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
48 }
49 
50 impl<O: IsA<ColorChooser>> ColorChooserExt for O {
rgba(&self) -> gdk::RGBA51     fn rgba(&self) -> gdk::RGBA {
52         unsafe {
53             let mut color = gdk::RGBA::uninitialized();
54             ffi::gtk_color_chooser_get_rgba(
55                 self.as_ref().to_glib_none().0,
56                 color.to_glib_none_mut().0,
57             );
58             color
59         }
60     }
61 
uses_alpha(&self) -> bool62     fn uses_alpha(&self) -> bool {
63         unsafe {
64             from_glib(ffi::gtk_color_chooser_get_use_alpha(
65                 self.as_ref().to_glib_none().0,
66             ))
67         }
68     }
69 
set_rgba(&self, color: &gdk::RGBA)70     fn set_rgba(&self, color: &gdk::RGBA) {
71         unsafe {
72             ffi::gtk_color_chooser_set_rgba(self.as_ref().to_glib_none().0, color.to_glib_none().0);
73         }
74     }
75 
set_use_alpha(&self, use_alpha: bool)76     fn set_use_alpha(&self, use_alpha: bool) {
77         unsafe {
78             ffi::gtk_color_chooser_set_use_alpha(
79                 self.as_ref().to_glib_none().0,
80                 use_alpha.into_glib(),
81             );
82         }
83     }
84 
connect_color_activated<F: Fn(&Self, &gdk::RGBA) + 'static>(&self, f: F) -> SignalHandlerId85     fn connect_color_activated<F: Fn(&Self, &gdk::RGBA) + 'static>(&self, f: F) -> SignalHandlerId {
86         unsafe extern "C" fn color_activated_trampoline<
87             P: IsA<ColorChooser>,
88             F: Fn(&P, &gdk::RGBA) + 'static,
89         >(
90             this: *mut ffi::GtkColorChooser,
91             color: *mut gdk::ffi::GdkRGBA,
92             f: glib::ffi::gpointer,
93         ) {
94             let f: &F = &*(f as *const F);
95             f(
96                 ColorChooser::from_glib_borrow(this).unsafe_cast_ref(),
97                 &from_glib_borrow(color),
98             )
99         }
100         unsafe {
101             let f: Box_<F> = Box_::new(f);
102             connect_raw(
103                 self.as_ptr() as *mut _,
104                 b"color-activated\0".as_ptr() as *const _,
105                 Some(transmute::<_, unsafe extern "C" fn()>(
106                     color_activated_trampoline::<Self, F> as *const (),
107                 )),
108                 Box_::into_raw(f),
109             )
110         }
111     }
112 
connect_rgba_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId113     fn connect_rgba_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
114         unsafe extern "C" fn notify_rgba_trampoline<P: IsA<ColorChooser>, F: Fn(&P) + 'static>(
115             this: *mut ffi::GtkColorChooser,
116             _param_spec: glib::ffi::gpointer,
117             f: glib::ffi::gpointer,
118         ) {
119             let f: &F = &*(f as *const F);
120             f(ColorChooser::from_glib_borrow(this).unsafe_cast_ref())
121         }
122         unsafe {
123             let f: Box_<F> = Box_::new(f);
124             connect_raw(
125                 self.as_ptr() as *mut _,
126                 b"notify::rgba\0".as_ptr() as *const _,
127                 Some(transmute::<_, unsafe extern "C" fn()>(
128                     notify_rgba_trampoline::<Self, F> as *const (),
129                 )),
130                 Box_::into_raw(f),
131             )
132         }
133     }
134 
connect_use_alpha_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId135     fn connect_use_alpha_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
136         unsafe extern "C" fn notify_use_alpha_trampoline<
137             P: IsA<ColorChooser>,
138             F: Fn(&P) + 'static,
139         >(
140             this: *mut ffi::GtkColorChooser,
141             _param_spec: glib::ffi::gpointer,
142             f: glib::ffi::gpointer,
143         ) {
144             let f: &F = &*(f as *const F);
145             f(ColorChooser::from_glib_borrow(this).unsafe_cast_ref())
146         }
147         unsafe {
148             let f: Box_<F> = Box_::new(f);
149             connect_raw(
150                 self.as_ptr() as *mut _,
151                 b"notify::use-alpha\0".as_ptr() as *const _,
152                 Some(transmute::<_, unsafe extern "C" fn()>(
153                     notify_use_alpha_trampoline::<Self, F> as *const (),
154                 )),
155                 Box_::into_raw(f),
156             )
157         }
158     }
159 }
160 
161 impl fmt::Display for ColorChooser {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result162     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
163         f.write_str("ColorChooser")
164     }
165 }
166