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