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::Value;
14use glib_sys;
15use gobject_sys;
16use gtk_sys;
17use libc;
18use std::boxed::Box as Box_;
19use std::fmt;
20use std::mem::transmute;
21use CellRenderer;
22use CellRendererMode;
23use TreePath;
24
25glib_wrapper! {
26 pub struct CellRendererToggle(Object<gtk_sys::GtkCellRendererToggle, gtk_sys::GtkCellRendererToggleClass, CellRendererToggleClass>) @extends CellRenderer;
27
28 match fn {
29 get_type => || gtk_sys::gtk_cell_renderer_toggle_get_type(),
30 }
31}
32
33impl CellRendererToggle {
34 pub fn new() -> CellRendererToggle {
35 assert_initialized_main_thread!();
36 unsafe {
37 CellRenderer::from_glib_none(gtk_sys::gtk_cell_renderer_toggle_new()).unsafe_cast()
38 }
39 }
40}
41
42impl Default for CellRendererToggle {
43 fn default() -> Self {
44 Self::new()
45 }
46}
47
48pub struct CellRendererToggleBuilder {
49 activatable: Option<bool>,
50 active: Option<bool>,
51 inconsistent: Option<bool>,
52 indicator_size: Option<i32>,
53 radio: Option<bool>,
54 cell_background: Option<String>,
55 cell_background_rgba: Option<gdk::RGBA>,
56 cell_background_set: Option<bool>,
57 height: Option<i32>,
58 is_expanded: Option<bool>,
59 is_expander: Option<bool>,
60 mode: Option<CellRendererMode>,
61 sensitive: Option<bool>,
62 visible: Option<bool>,
63 width: Option<i32>,
64 xalign: Option<f32>,
65 xpad: Option<u32>,
66 yalign: Option<f32>,
67 ypad: Option<u32>,
68}
69
70impl CellRendererToggleBuilder {
71 pub fn new() -> Self {
72 Self {
73 activatable: None,
74 active: None,
75 inconsistent: None,
76 indicator_size: None,
77 radio: None,
78 cell_background: None,
79 cell_background_rgba: None,
80 cell_background_set: None,
81 height: None,
82 is_expanded: None,
83 is_expander: None,
84 mode: None,
85 sensitive: None,
86 visible: None,
87 width: None,
88 xalign: None,
89 xpad: None,
90 yalign: None,
91 ypad: None,
92 }
93 }
94
95 pub fn build(self) -> CellRendererToggle {
96 let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
97 if let Some(ref activatable) = self.activatable {
98 properties.push(("activatable", activatable));
99 }
100 if let Some(ref active) = self.active {
101 properties.push(("active", active));
102 }
103 if let Some(ref inconsistent) = self.inconsistent {
104 properties.push(("inconsistent", inconsistent));
105 }
106 if let Some(ref indicator_size) = self.indicator_size {
107 properties.push(("indicator-size", indicator_size));
108 }
109 if let Some(ref radio) = self.radio {
110 properties.push(("radio", radio));
111 }
112 if let Some(ref cell_background) = self.cell_background {
113 properties.push(("cell-background", cell_background));
114 }
115 if let Some(ref cell_background_rgba) = self.cell_background_rgba {
116 properties.push(("cell-background-rgba", cell_background_rgba));
117 }
118 if let Some(ref cell_background_set) = self.cell_background_set {
119 properties.push(("cell-background-set", cell_background_set));
120 }
121 if let Some(ref height) = self.height {
122 properties.push(("height", height));
123 }
124 if let Some(ref is_expanded) = self.is_expanded {
125 properties.push(("is-expanded", is_expanded));
126 }
127 if let Some(ref is_expander) = self.is_expander {
128 properties.push(("is-expander", is_expander));
129 }
130 if let Some(ref mode) = self.mode {
131 properties.push(("mode", mode));
132 }
133 if let Some(ref sensitive) = self.sensitive {
134 properties.push(("sensitive", sensitive));
135 }
136 if let Some(ref visible) = self.visible {
137 properties.push(("visible", visible));
138 }
139 if let Some(ref width) = self.width {
140 properties.push(("width", width));
141 }
142 if let Some(ref xalign) = self.xalign {
143 properties.push(("xalign", xalign));
144 }
145 if let Some(ref xpad) = self.xpad {
146 properties.push(("xpad", xpad));
147 }
148 if let Some(ref yalign) = self.yalign {
149 properties.push(("yalign", yalign));
150 }
151 if let Some(ref ypad) = self.ypad {
152 properties.push(("ypad", ypad));
153 }
154 glib::Object::new(CellRendererToggle::static_type(), &properties)
155 .expect("object new")
156 .downcast()
157 .expect("downcast")
158 }
159
160 pub fn activatable(mut self, activatable: bool) -> Self {
161 self.activatable = Some(activatable);
162 self
163 }
164
165 pub fn active(mut self, active: bool) -> Self {
166 self.active = Some(active);
167 self
168 }
169
170 pub fn inconsistent(mut self, inconsistent: bool) -> Self {
171 self.inconsistent = Some(inconsistent);
172 self
173 }
174
175 pub fn indicator_size(mut self, indicator_size: i32) -> Self {
176 self.indicator_size = Some(indicator_size);
177 self
178 }
179
180 pub fn radio(mut self, radio: bool) -> Self {
181 self.radio = Some(radio);
182 self
183 }
184
185 pub fn cell_background(mut self, cell_background: &str) -> Self {
186 self.cell_background = Some(cell_background.to_string());
187 self
188 }
189
190 pub fn cell_background_rgba(mut self, cell_background_rgba: &gdk::RGBA) -> Self {
191 self.cell_background_rgba = Some(cell_background_rgba.clone());
192 self
193 }
194
195 pub fn cell_background_set(mut self, cell_background_set: bool) -> Self {
196 self.cell_background_set = Some(cell_background_set);
197 self
198 }
199
200 pub fn height(mut self, height: i32) -> Self {
201 self.height = Some(height);
202 self
203 }
204
205 pub fn is_expanded(mut self, is_expanded: bool) -> Self {
206 self.is_expanded = Some(is_expanded);
207 self
208 }
209
210 pub fn is_expander(mut self, is_expander: bool) -> Self {
211 self.is_expander = Some(is_expander);
212 self
213 }
214
215 pub fn mode(mut self, mode: CellRendererMode) -> Self {
216 self.mode = Some(mode);
217 self
218 }
219
220 pub fn sensitive(mut self, sensitive: bool) -> Self {
221 self.sensitive = Some(sensitive);
222 self
223 }
224
225 pub fn visible(mut self, visible: bool) -> Self {
226 self.visible = Some(visible);
227 self
228 }
229
230 pub fn width(mut self, width: i32) -> Self {
231 self.width = Some(width);
232 self
233 }
234
235 pub fn xalign(mut self, xalign: f32) -> Self {
236 self.xalign = Some(xalign);
237 self
238 }
239
240 pub fn xpad(mut self, xpad: u32) -> Self {
241 self.xpad = Some(xpad);
242 self
243 }
244
245 pub fn yalign(mut self, yalign: f32) -> Self {
246 self.yalign = Some(yalign);
247 self
248 }
249
250 pub fn ypad(mut self, ypad: u32) -> Self {
251 self.ypad = Some(ypad);
252 self
253 }
254}
255
256pub const NONE_CELL_RENDERER_TOGGLE: Option<&CellRendererToggle> = None;
257
258pub trait CellRendererToggleExt: 'static {
259 fn get_activatable(&self) -> bool;
260
261 fn get_active(&self) -> bool;
262
263 fn get_radio(&self) -> bool;
264
265 fn set_activatable(&self, setting: bool);
266
267 fn set_active(&self, setting: bool);
268
269 fn set_radio(&self, radio: bool);
270
271 fn get_property_inconsistent(&self) -> bool;
272
273 fn set_property_inconsistent(&self, inconsistent: bool);
274
275 fn get_property_indicator_size(&self) -> i32;
276
277 fn set_property_indicator_size(&self, indicator_size: i32);
278
279 fn connect_toggled<F: Fn(&Self, TreePath) + 'static>(&self, f: F) -> SignalHandlerId;
280
281 fn connect_property_activatable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
282
283 fn connect_property_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
284
285 fn connect_property_inconsistent_notify<F: Fn(&Self) + 'static>(&self, f: F)
286 -> SignalHandlerId;
287
288 fn connect_property_indicator_size_notify<F: Fn(&Self) + 'static>(
289 &self,
290 f: F,
291 ) -> SignalHandlerId;
292
293 fn connect_property_radio_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
294}
295
296impl<O: IsA<CellRendererToggle>> CellRendererToggleExt for O {
297 fn get_activatable(&self) -> bool {
298 unsafe {
299 from_glib(gtk_sys::gtk_cell_renderer_toggle_get_activatable(
300 self.as_ref().to_glib_none().0,
301 ))
302 }
303 }
304
305 fn get_active(&self) -> bool {
306 unsafe {
307 from_glib(gtk_sys::gtk_cell_renderer_toggle_get_active(
308 self.as_ref().to_glib_none().0,
309 ))
310 }
311 }
312
313 fn get_radio(&self) -> bool {
314 unsafe {
315 from_glib(gtk_sys::gtk_cell_renderer_toggle_get_radio(
316 self.as_ref().to_glib_none().0,
317 ))
318 }
319 }
320
321 fn set_activatable(&self, setting: bool) {
322 unsafe {
323 gtk_sys::gtk_cell_renderer_toggle_set_activatable(
324 self.as_ref().to_glib_none().0,
325 setting.to_glib(),
326 );
327 }
328 }
329
330 fn set_active(&self, setting: bool) {
331 unsafe {
332 gtk_sys::gtk_cell_renderer_toggle_set_active(
333 self.as_ref().to_glib_none().0,
334 setting.to_glib(),
335 );
336 }
337 }
338
339 fn set_radio(&self, radio: bool) {
340 unsafe {
341 gtk_sys::gtk_cell_renderer_toggle_set_radio(
342 self.as_ref().to_glib_none().0,
343 radio.to_glib(),
344 );
345 }
346 }
347
348 fn get_property_inconsistent(&self) -> bool {
349 unsafe {
350 let mut value = Value::from_type(<bool as StaticType>::static_type());
351 gobject_sys::g_object_get_property(
352 self.to_glib_none().0 as *mut gobject_sys::GObject,
353 b"inconsistent\0".as_ptr() as *const _,
354 value.to_glib_none_mut().0,
355 );
356 value.get().unwrap()
357 }
358 }
359
360 fn set_property_inconsistent(&self, inconsistent: bool) {
361 unsafe {
362 gobject_sys::g_object_set_property(
363 self.to_glib_none().0 as *mut gobject_sys::GObject,
364 b"inconsistent\0".as_ptr() as *const _,
365 Value::from(&inconsistent).to_glib_none().0,
366 );
367 }
368 }
369
370 fn get_property_indicator_size(&self) -> i32 {
371 unsafe {
372 let mut value = Value::from_type(<i32 as StaticType>::static_type());
373 gobject_sys::g_object_get_property(
374 self.to_glib_none().0 as *mut gobject_sys::GObject,
375 b"indicator-size\0".as_ptr() as *const _,
376 value.to_glib_none_mut().0,
377 );
378 value.get().unwrap()
379 }
380 }
381
382 fn set_property_indicator_size(&self, indicator_size: i32) {
383 unsafe {
384 gobject_sys::g_object_set_property(
385 self.to_glib_none().0 as *mut gobject_sys::GObject,
386 b"indicator-size\0".as_ptr() as *const _,
387 Value::from(&indicator_size).to_glib_none().0,
388 );
389 }
390 }
391
392 fn connect_toggled<F: Fn(&Self, TreePath) + 'static>(&self, f: F) -> SignalHandlerId {
393 unsafe extern "C" fn toggled_trampoline<P, F: Fn(&P, TreePath) + 'static>(
394 this: *mut gtk_sys::GtkCellRendererToggle,
395 path: *mut libc::c_char,
396 f: glib_sys::gpointer,
397 ) where
398 P: IsA<CellRendererToggle>,
399 {
400 let f: &F = &*(f as *const F);
401 let path = from_glib_full(gtk_sys::gtk_tree_path_new_from_string(path));
402 f(
403 &CellRendererToggle::from_glib_borrow(this).unsafe_cast(),
404 path,
405 )
406 }
407 unsafe {
408 let f: Box_<F> = Box_::new(f);
409 connect_raw(
410 self.as_ptr() as *mut _,
411 b"toggled\0".as_ptr() as *const _,
412 Some(transmute(toggled_trampoline::<Self, F> as usize)),
413 Box_::into_raw(f),
414 )
415 }
416 }
417
418 fn connect_property_activatable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
419 unsafe extern "C" fn notify_activatable_trampoline<P, F: Fn(&P) + 'static>(
420 this: *mut gtk_sys::GtkCellRendererToggle,
421 _param_spec: glib_sys::gpointer,
422 f: glib_sys::gpointer,
423 ) where
424 P: IsA<CellRendererToggle>,
425 {
426 let f: &F = &*(f as *const F);
427 f(&CellRendererToggle::from_glib_borrow(this).unsafe_cast())
428 }
429 unsafe {
430 let f: Box_<F> = Box_::new(f);
431 connect_raw(
432 self.as_ptr() as *mut _,
433 b"notify::activatable\0".as_ptr() as *const _,
434 Some(transmute(notify_activatable_trampoline::<Self, F> as usize)),
435 Box_::into_raw(f),
436 )
437 }
438 }
439
440 fn connect_property_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
441 unsafe extern "C" fn notify_active_trampoline<P, F: Fn(&P) + 'static>(
442 this: *mut gtk_sys::GtkCellRendererToggle,
443 _param_spec: glib_sys::gpointer,
444 f: glib_sys::gpointer,
445 ) where
446 P: IsA<CellRendererToggle>,
447 {
448 let f: &F = &*(f as *const F);
449 f(&CellRendererToggle::from_glib_borrow(this).unsafe_cast())
450 }
451 unsafe {
452 let f: Box_<F> = Box_::new(f);
453 connect_raw(
454 self.as_ptr() as *mut _,
455 b"notify::active\0".as_ptr() as *const _,
456 Some(transmute(notify_active_trampoline::<Self, F> as usize)),
457 Box_::into_raw(f),
458 )
459 }
460 }
461
462 fn connect_property_inconsistent_notify<F: Fn(&Self) + 'static>(
463 &self,
464 f: F,
465 ) -> SignalHandlerId {
466 unsafe extern "C" fn notify_inconsistent_trampoline<P, F: Fn(&P) + 'static>(
467 this: *mut gtk_sys::GtkCellRendererToggle,
468 _param_spec: glib_sys::gpointer,
469 f: glib_sys::gpointer,
470 ) where
471 P: IsA<CellRendererToggle>,
472 {
473 let f: &F = &*(f as *const F);
474 f(&CellRendererToggle::from_glib_borrow(this).unsafe_cast())
475 }
476 unsafe {
477 let f: Box_<F> = Box_::new(f);
478 connect_raw(
479 self.as_ptr() as *mut _,
480 b"notify::inconsistent\0".as_ptr() as *const _,
481 Some(transmute(
482 notify_inconsistent_trampoline::<Self, F> as usize,
483 )),
484 Box_::into_raw(f),
485 )
486 }
487 }
488
489 fn connect_property_indicator_size_notify<F: Fn(&Self) + 'static>(
490 &self,
491 f: F,
492 ) -> SignalHandlerId {
493 unsafe extern "C" fn notify_indicator_size_trampoline<P, F: Fn(&P) + 'static>(
494 this: *mut gtk_sys::GtkCellRendererToggle,
495 _param_spec: glib_sys::gpointer,
496 f: glib_sys::gpointer,
497 ) where
498 P: IsA<CellRendererToggle>,
499 {
500 let f: &F = &*(f as *const F);
501 f(&CellRendererToggle::from_glib_borrow(this).unsafe_cast())
502 }
503 unsafe {
504 let f: Box_<F> = Box_::new(f);
505 connect_raw(
506 self.as_ptr() as *mut _,
507 b"notify::indicator-size\0".as_ptr() as *const _,
508 Some(transmute(
509 notify_indicator_size_trampoline::<Self, F> as usize,
510 )),
511 Box_::into_raw(f),
512 )
513 }
514 }
515
516 fn connect_property_radio_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
517 unsafe extern "C" fn notify_radio_trampoline<P, F: Fn(&P) + 'static>(
518 this: *mut gtk_sys::GtkCellRendererToggle,
519 _param_spec: glib_sys::gpointer,
520 f: glib_sys::gpointer,
521 ) where
522 P: IsA<CellRendererToggle>,
523 {
524 let f: &F = &*(f as *const F);
525 f(&CellRendererToggle::from_glib_borrow(this).unsafe_cast())
526 }
527 unsafe {
528 let f: Box_<F> = Box_::new(f);
529 connect_raw(
530 self.as_ptr() as *mut _,
531 b"notify::radio\0".as_ptr() as *const _,
532 Some(transmute(notify_radio_trampoline::<Self, F> as usize)),
533 Box_::into_raw(f),
534 )
535 }
536 }
537}
538
539impl fmt::Display for CellRendererToggle {
540 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
541 write!(f, "CellRendererToggle")
542 }
543}