gtk/auto/
color_chooser.rs1use gdk;
6use gdk_sys;
7use glib::object::Cast;
8use glib::object::IsA;
9use glib::signal::connect_raw;
10use glib::signal::SignalHandlerId;
11use glib::translate::*;
12use glib_sys;
13use gtk_sys;
14use std::boxed::Box as Box_;
15use std::fmt;
16use std::mem::transmute;
17
18glib_wrapper! {
19 pub struct ColorChooser(Interface<gtk_sys::GtkColorChooser>);
20
21 match fn {
22 get_type => || gtk_sys::gtk_color_chooser_get_type(),
23 }
24}
25
26pub const NONE_COLOR_CHOOSER: Option<&ColorChooser> = None;
27
28pub trait ColorChooserExt: 'static {
29 fn get_rgba(&self) -> gdk::RGBA;
30
31 fn get_use_alpha(&self) -> bool;
32
33 fn set_rgba(&self, color: &gdk::RGBA);
34
35 fn set_use_alpha(&self, use_alpha: bool);
36
37 fn connect_color_activated<F: Fn(&Self, &gdk::RGBA) + 'static>(&self, f: F) -> SignalHandlerId;
38
39 fn connect_property_rgba_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
40
41 fn connect_property_use_alpha_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
42}
43
44impl<O: IsA<ColorChooser>> ColorChooserExt for O {
45 fn get_rgba(&self) -> gdk::RGBA {
46 unsafe {
47 let mut color = gdk::RGBA::uninitialized();
48 gtk_sys::gtk_color_chooser_get_rgba(
49 self.as_ref().to_glib_none().0,
50 color.to_glib_none_mut().0,
51 );
52 color
53 }
54 }
55
56 fn get_use_alpha(&self) -> bool {
57 unsafe {
58 from_glib(gtk_sys::gtk_color_chooser_get_use_alpha(
59 self.as_ref().to_glib_none().0,
60 ))
61 }
62 }
63
64 fn set_rgba(&self, color: &gdk::RGBA) {
65 unsafe {
66 gtk_sys::gtk_color_chooser_set_rgba(
67 self.as_ref().to_glib_none().0,
68 color.to_glib_none().0,
69 );
70 }
71 }
72
73 fn set_use_alpha(&self, use_alpha: bool) {
74 unsafe {
75 gtk_sys::gtk_color_chooser_set_use_alpha(
76 self.as_ref().to_glib_none().0,
77 use_alpha.to_glib(),
78 );
79 }
80 }
81
82 fn connect_color_activated<F: Fn(&Self, &gdk::RGBA) + 'static>(&self, f: F) -> SignalHandlerId {
83 unsafe extern "C" fn color_activated_trampoline<P, F: Fn(&P, &gdk::RGBA) + 'static>(
84 this: *mut gtk_sys::GtkColorChooser,
85 color: *mut gdk_sys::GdkRGBA,
86 f: glib_sys::gpointer,
87 ) where
88 P: IsA<ColorChooser>,
89 {
90 let f: &F = &*(f as *const F);
91 f(
92 &ColorChooser::from_glib_borrow(this).unsafe_cast(),
93 &from_glib_borrow(color),
94 )
95 }
96 unsafe {
97 let f: Box_<F> = Box_::new(f);
98 connect_raw(
99 self.as_ptr() as *mut _,
100 b"color-activated\0".as_ptr() as *const _,
101 Some(transmute(color_activated_trampoline::<Self, F> as usize)),
102 Box_::into_raw(f),
103 )
104 }
105 }
106
107 fn connect_property_rgba_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
108 unsafe extern "C" fn notify_rgba_trampoline<P, F: Fn(&P) + 'static>(
109 this: *mut gtk_sys::GtkColorChooser,
110 _param_spec: glib_sys::gpointer,
111 f: glib_sys::gpointer,
112 ) where
113 P: IsA<ColorChooser>,
114 {
115 let f: &F = &*(f as *const F);
116 f(&ColorChooser::from_glib_borrow(this).unsafe_cast())
117 }
118 unsafe {
119 let f: Box_<F> = Box_::new(f);
120 connect_raw(
121 self.as_ptr() as *mut _,
122 b"notify::rgba\0".as_ptr() as *const _,
123 Some(transmute(notify_rgba_trampoline::<Self, F> as usize)),
124 Box_::into_raw(f),
125 )
126 }
127 }
128
129 fn connect_property_use_alpha_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
130 unsafe extern "C" fn notify_use_alpha_trampoline<P, F: Fn(&P) + 'static>(
131 this: *mut gtk_sys::GtkColorChooser,
132 _param_spec: glib_sys::gpointer,
133 f: glib_sys::gpointer,
134 ) where
135 P: IsA<ColorChooser>,
136 {
137 let f: &F = &*(f as *const F);
138 f(&ColorChooser::from_glib_borrow(this).unsafe_cast())
139 }
140 unsafe {
141 let f: Box_<F> = Box_::new(f);
142 connect_raw(
143 self.as_ptr() as *mut _,
144 b"notify::use-alpha\0".as_ptr() as *const _,
145 Some(transmute(notify_use_alpha_trampoline::<Self, F> as usize)),
146 Box_::into_raw(f),
147 )
148 }
149 }
150}
151
152impl fmt::Display for ColorChooser {
153 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
154 write!(f, "ColorChooser")
155 }
156}