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::StaticType;
14use glib::ToValue;
15use glib_sys;
16use gobject_sys;
17use gtk_sys;
18use std::boxed::Box as Box_;
19use std::fmt;
20use std::mem::transmute;
21use Actionable;
22use Align;
23use Bin;
24use Buildable;
25use Container;
26use ResizeMode;
27use Widget;
28
29glib_wrapper! {
30 pub struct ListBoxRow(Object<gtk_sys::GtkListBoxRow, gtk_sys::GtkListBoxRowClass, ListBoxRowClass>) @extends Bin, Container, Widget, @implements Buildable, Actionable;
31
32 match fn {
33 get_type => || gtk_sys::gtk_list_box_row_get_type(),
34 }
35}
36
37impl ListBoxRow {
38 pub fn new() -> ListBoxRow {
39 assert_initialized_main_thread!();
40 unsafe { Widget::from_glib_none(gtk_sys::gtk_list_box_row_new()).unsafe_cast() }
41 }
42}
43
44impl Default for ListBoxRow {
45 fn default() -> Self {
46 Self::new()
47 }
48}
49
50pub struct ListBoxRowBuilder {
51 activatable: Option<bool>,
52 selectable: Option<bool>,
53 border_width: Option<u32>,
54 child: Option<Widget>,
55 resize_mode: Option<ResizeMode>,
56 app_paintable: Option<bool>,
57 can_default: Option<bool>,
58 can_focus: Option<bool>,
59 events: Option<gdk::EventMask>,
60 expand: Option<bool>,
61 #[cfg(any(feature = "v3_20", feature = "dox"))]
62 focus_on_click: Option<bool>,
63 halign: Option<Align>,
64 has_default: Option<bool>,
65 has_focus: Option<bool>,
66 has_tooltip: Option<bool>,
67 height_request: Option<i32>,
68 hexpand: Option<bool>,
69 hexpand_set: Option<bool>,
70 is_focus: Option<bool>,
71 margin: Option<i32>,
72 margin_bottom: Option<i32>,
73 margin_end: Option<i32>,
74 margin_start: Option<i32>,
75 margin_top: Option<i32>,
76 name: Option<String>,
77 no_show_all: Option<bool>,
78 opacity: Option<f64>,
79 parent: Option<Container>,
80 receives_default: Option<bool>,
81 sensitive: Option<bool>,
82 tooltip_markup: Option<String>,
84 tooltip_text: Option<String>,
85 valign: Option<Align>,
86 vexpand: Option<bool>,
87 vexpand_set: Option<bool>,
88 visible: Option<bool>,
89 width_request: Option<i32>,
90}
91
92impl ListBoxRowBuilder {
93 pub fn new() -> Self {
94 Self {
95 activatable: None,
96 selectable: None,
97 border_width: None,
98 child: None,
99 resize_mode: None,
100 app_paintable: None,
101 can_default: None,
102 can_focus: None,
103 events: None,
104 expand: None,
105 #[cfg(any(feature = "v3_20", feature = "dox"))]
106 focus_on_click: None,
107 halign: None,
108 has_default: None,
109 has_focus: None,
110 has_tooltip: None,
111 height_request: None,
112 hexpand: None,
113 hexpand_set: None,
114 is_focus: None,
115 margin: None,
116 margin_bottom: None,
117 margin_end: None,
118 margin_start: None,
119 margin_top: None,
120 name: None,
121 no_show_all: None,
122 opacity: None,
123 parent: None,
124 receives_default: None,
125 sensitive: None,
126 tooltip_markup: None,
127 tooltip_text: None,
128 valign: None,
129 vexpand: None,
130 vexpand_set: None,
131 visible: None,
132 width_request: None,
133 }
134 }
135
136 pub fn build(self) -> ListBoxRow {
137 let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
138 if let Some(ref activatable) = self.activatable {
139 properties.push(("activatable", activatable));
140 }
141 if let Some(ref selectable) = self.selectable {
142 properties.push(("selectable", selectable));
143 }
144 if let Some(ref border_width) = self.border_width {
145 properties.push(("border-width", border_width));
146 }
147 if let Some(ref child) = self.child {
148 properties.push(("child", child));
149 }
150 if let Some(ref resize_mode) = self.resize_mode {
151 properties.push(("resize-mode", resize_mode));
152 }
153 if let Some(ref app_paintable) = self.app_paintable {
154 properties.push(("app-paintable", app_paintable));
155 }
156 if let Some(ref can_default) = self.can_default {
157 properties.push(("can-default", can_default));
158 }
159 if let Some(ref can_focus) = self.can_focus {
160 properties.push(("can-focus", can_focus));
161 }
162 if let Some(ref events) = self.events {
163 properties.push(("events", events));
164 }
165 if let Some(ref expand) = self.expand {
166 properties.push(("expand", expand));
167 }
168 #[cfg(any(feature = "v3_20", feature = "dox"))]
169 {
170 if let Some(ref focus_on_click) = self.focus_on_click {
171 properties.push(("focus-on-click", focus_on_click));
172 }
173 }
174 if let Some(ref halign) = self.halign {
175 properties.push(("halign", halign));
176 }
177 if let Some(ref has_default) = self.has_default {
178 properties.push(("has-default", has_default));
179 }
180 if let Some(ref has_focus) = self.has_focus {
181 properties.push(("has-focus", has_focus));
182 }
183 if let Some(ref has_tooltip) = self.has_tooltip {
184 properties.push(("has-tooltip", has_tooltip));
185 }
186 if let Some(ref height_request) = self.height_request {
187 properties.push(("height-request", height_request));
188 }
189 if let Some(ref hexpand) = self.hexpand {
190 properties.push(("hexpand", hexpand));
191 }
192 if let Some(ref hexpand_set) = self.hexpand_set {
193 properties.push(("hexpand-set", hexpand_set));
194 }
195 if let Some(ref is_focus) = self.is_focus {
196 properties.push(("is-focus", is_focus));
197 }
198 if let Some(ref margin) = self.margin {
199 properties.push(("margin", margin));
200 }
201 if let Some(ref margin_bottom) = self.margin_bottom {
202 properties.push(("margin-bottom", margin_bottom));
203 }
204 if let Some(ref margin_end) = self.margin_end {
205 properties.push(("margin-end", margin_end));
206 }
207 if let Some(ref margin_start) = self.margin_start {
208 properties.push(("margin-start", margin_start));
209 }
210 if let Some(ref margin_top) = self.margin_top {
211 properties.push(("margin-top", margin_top));
212 }
213 if let Some(ref name) = self.name {
214 properties.push(("name", name));
215 }
216 if let Some(ref no_show_all) = self.no_show_all {
217 properties.push(("no-show-all", no_show_all));
218 }
219 if let Some(ref opacity) = self.opacity {
220 properties.push(("opacity", opacity));
221 }
222 if let Some(ref parent) = self.parent {
223 properties.push(("parent", parent));
224 }
225 if let Some(ref receives_default) = self.receives_default {
226 properties.push(("receives-default", receives_default));
227 }
228 if let Some(ref sensitive) = self.sensitive {
229 properties.push(("sensitive", sensitive));
230 }
231 if let Some(ref tooltip_markup) = self.tooltip_markup {
232 properties.push(("tooltip-markup", tooltip_markup));
233 }
234 if let Some(ref tooltip_text) = self.tooltip_text {
235 properties.push(("tooltip-text", tooltip_text));
236 }
237 if let Some(ref valign) = self.valign {
238 properties.push(("valign", valign));
239 }
240 if let Some(ref vexpand) = self.vexpand {
241 properties.push(("vexpand", vexpand));
242 }
243 if let Some(ref vexpand_set) = self.vexpand_set {
244 properties.push(("vexpand-set", vexpand_set));
245 }
246 if let Some(ref visible) = self.visible {
247 properties.push(("visible", visible));
248 }
249 if let Some(ref width_request) = self.width_request {
250 properties.push(("width-request", width_request));
251 }
252 glib::Object::new(ListBoxRow::static_type(), &properties)
253 .expect("object new")
254 .downcast()
255 .expect("downcast")
256 }
257
258 pub fn activatable(mut self, activatable: bool) -> Self {
259 self.activatable = Some(activatable);
260 self
261 }
262
263 pub fn selectable(mut self, selectable: bool) -> Self {
264 self.selectable = Some(selectable);
265 self
266 }
267
268 pub fn border_width(mut self, border_width: u32) -> Self {
269 self.border_width = Some(border_width);
270 self
271 }
272
273 pub fn child(mut self, child: &Widget) -> Self {
274 self.child = Some(child.clone());
275 self
276 }
277
278 pub fn resize_mode(mut self, resize_mode: ResizeMode) -> Self {
279 self.resize_mode = Some(resize_mode);
280 self
281 }
282
283 pub fn app_paintable(mut self, app_paintable: bool) -> Self {
284 self.app_paintable = Some(app_paintable);
285 self
286 }
287
288 pub fn can_default(mut self, can_default: bool) -> Self {
289 self.can_default = Some(can_default);
290 self
291 }
292
293 pub fn can_focus(mut self, can_focus: bool) -> Self {
294 self.can_focus = Some(can_focus);
295 self
296 }
297
298 pub fn events(mut self, events: gdk::EventMask) -> Self {
299 self.events = Some(events);
300 self
301 }
302
303 pub fn expand(mut self, expand: bool) -> Self {
304 self.expand = Some(expand);
305 self
306 }
307
308 #[cfg(any(feature = "v3_20", feature = "dox"))]
309 pub fn focus_on_click(mut self, focus_on_click: bool) -> Self {
310 self.focus_on_click = Some(focus_on_click);
311 self
312 }
313
314 pub fn halign(mut self, halign: Align) -> Self {
315 self.halign = Some(halign);
316 self
317 }
318
319 pub fn has_default(mut self, has_default: bool) -> Self {
320 self.has_default = Some(has_default);
321 self
322 }
323
324 pub fn has_focus(mut self, has_focus: bool) -> Self {
325 self.has_focus = Some(has_focus);
326 self
327 }
328
329 pub fn has_tooltip(mut self, has_tooltip: bool) -> Self {
330 self.has_tooltip = Some(has_tooltip);
331 self
332 }
333
334 pub fn height_request(mut self, height_request: i32) -> Self {
335 self.height_request = Some(height_request);
336 self
337 }
338
339 pub fn hexpand(mut self, hexpand: bool) -> Self {
340 self.hexpand = Some(hexpand);
341 self
342 }
343
344 pub fn hexpand_set(mut self, hexpand_set: bool) -> Self {
345 self.hexpand_set = Some(hexpand_set);
346 self
347 }
348
349 pub fn is_focus(mut self, is_focus: bool) -> Self {
350 self.is_focus = Some(is_focus);
351 self
352 }
353
354 pub fn margin(mut self, margin: i32) -> Self {
355 self.margin = Some(margin);
356 self
357 }
358
359 pub fn margin_bottom(mut self, margin_bottom: i32) -> Self {
360 self.margin_bottom = Some(margin_bottom);
361 self
362 }
363
364 pub fn margin_end(mut self, margin_end: i32) -> Self {
365 self.margin_end = Some(margin_end);
366 self
367 }
368
369 pub fn margin_start(mut self, margin_start: i32) -> Self {
370 self.margin_start = Some(margin_start);
371 self
372 }
373
374 pub fn margin_top(mut self, margin_top: i32) -> Self {
375 self.margin_top = Some(margin_top);
376 self
377 }
378
379 pub fn name(mut self, name: &str) -> Self {
380 self.name = Some(name.to_string());
381 self
382 }
383
384 pub fn no_show_all(mut self, no_show_all: bool) -> Self {
385 self.no_show_all = Some(no_show_all);
386 self
387 }
388
389 pub fn opacity(mut self, opacity: f64) -> Self {
390 self.opacity = Some(opacity);
391 self
392 }
393
394 pub fn parent(mut self, parent: &Container) -> Self {
395 self.parent = Some(parent.clone());
396 self
397 }
398
399 pub fn receives_default(mut self, receives_default: bool) -> Self {
400 self.receives_default = Some(receives_default);
401 self
402 }
403
404 pub fn sensitive(mut self, sensitive: bool) -> Self {
405 self.sensitive = Some(sensitive);
406 self
407 }
408
409 pub fn tooltip_markup(mut self, tooltip_markup: &str) -> Self {
410 self.tooltip_markup = Some(tooltip_markup.to_string());
411 self
412 }
413
414 pub fn tooltip_text(mut self, tooltip_text: &str) -> Self {
415 self.tooltip_text = Some(tooltip_text.to_string());
416 self
417 }
418
419 pub fn valign(mut self, valign: Align) -> Self {
420 self.valign = Some(valign);
421 self
422 }
423
424 pub fn vexpand(mut self, vexpand: bool) -> Self {
425 self.vexpand = Some(vexpand);
426 self
427 }
428
429 pub fn vexpand_set(mut self, vexpand_set: bool) -> Self {
430 self.vexpand_set = Some(vexpand_set);
431 self
432 }
433
434 pub fn visible(mut self, visible: bool) -> Self {
435 self.visible = Some(visible);
436 self
437 }
438
439 pub fn width_request(mut self, width_request: i32) -> Self {
440 self.width_request = Some(width_request);
441 self
442 }
443}
444
445pub const NONE_LIST_BOX_ROW: Option<&ListBoxRow> = None;
446
447pub trait ListBoxRowExt: 'static {
448 fn changed(&self);
449
450 fn get_activatable(&self) -> bool;
451
452 fn get_header(&self) -> Option<Widget>;
453
454 fn get_index(&self) -> i32;
455
456 fn get_selectable(&self) -> bool;
457
458 fn is_selected(&self) -> bool;
459
460 fn set_activatable(&self, activatable: bool);
461
462 fn set_header<P: IsA<Widget>>(&self, header: Option<&P>);
463
464 fn set_selectable(&self, selectable: bool);
465
466 fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
467
468 fn emit_activate(&self);
469
470 fn connect_property_activatable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
471
472 fn connect_property_selectable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
473}
474
475impl<O: IsA<ListBoxRow>> ListBoxRowExt for O {
476 fn changed(&self) {
477 unsafe {
478 gtk_sys::gtk_list_box_row_changed(self.as_ref().to_glib_none().0);
479 }
480 }
481
482 fn get_activatable(&self) -> bool {
483 unsafe {
484 from_glib(gtk_sys::gtk_list_box_row_get_activatable(
485 self.as_ref().to_glib_none().0,
486 ))
487 }
488 }
489
490 fn get_header(&self) -> Option<Widget> {
491 unsafe {
492 from_glib_none(gtk_sys::gtk_list_box_row_get_header(
493 self.as_ref().to_glib_none().0,
494 ))
495 }
496 }
497
498 fn get_index(&self) -> i32 {
499 unsafe { gtk_sys::gtk_list_box_row_get_index(self.as_ref().to_glib_none().0) }
500 }
501
502 fn get_selectable(&self) -> bool {
503 unsafe {
504 from_glib(gtk_sys::gtk_list_box_row_get_selectable(
505 self.as_ref().to_glib_none().0,
506 ))
507 }
508 }
509
510 fn is_selected(&self) -> bool {
511 unsafe {
512 from_glib(gtk_sys::gtk_list_box_row_is_selected(
513 self.as_ref().to_glib_none().0,
514 ))
515 }
516 }
517
518 fn set_activatable(&self, activatable: bool) {
519 unsafe {
520 gtk_sys::gtk_list_box_row_set_activatable(
521 self.as_ref().to_glib_none().0,
522 activatable.to_glib(),
523 );
524 }
525 }
526
527 fn set_header<P: IsA<Widget>>(&self, header: Option<&P>) {
528 unsafe {
529 gtk_sys::gtk_list_box_row_set_header(
530 self.as_ref().to_glib_none().0,
531 header.map(|p| p.as_ref()).to_glib_none().0,
532 );
533 }
534 }
535
536 fn set_selectable(&self, selectable: bool) {
537 unsafe {
538 gtk_sys::gtk_list_box_row_set_selectable(
539 self.as_ref().to_glib_none().0,
540 selectable.to_glib(),
541 );
542 }
543 }
544
545 fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
546 unsafe extern "C" fn activate_trampoline<P, F: Fn(&P) + 'static>(
547 this: *mut gtk_sys::GtkListBoxRow,
548 f: glib_sys::gpointer,
549 ) where
550 P: IsA<ListBoxRow>,
551 {
552 let f: &F = &*(f as *const F);
553 f(&ListBoxRow::from_glib_borrow(this).unsafe_cast())
554 }
555 unsafe {
556 let f: Box_<F> = Box_::new(f);
557 connect_raw(
558 self.as_ptr() as *mut _,
559 b"activate\0".as_ptr() as *const _,
560 Some(transmute(activate_trampoline::<Self, F> as usize)),
561 Box_::into_raw(f),
562 )
563 }
564 }
565
566 fn emit_activate(&self) {
567 let _ = unsafe {
568 glib::Object::from_glib_borrow(self.to_glib_none().0 as *mut gobject_sys::GObject)
569 .emit("activate", &[])
570 .unwrap()
571 };
572 }
573
574 fn connect_property_activatable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
575 unsafe extern "C" fn notify_activatable_trampoline<P, F: Fn(&P) + 'static>(
576 this: *mut gtk_sys::GtkListBoxRow,
577 _param_spec: glib_sys::gpointer,
578 f: glib_sys::gpointer,
579 ) where
580 P: IsA<ListBoxRow>,
581 {
582 let f: &F = &*(f as *const F);
583 f(&ListBoxRow::from_glib_borrow(this).unsafe_cast())
584 }
585 unsafe {
586 let f: Box_<F> = Box_::new(f);
587 connect_raw(
588 self.as_ptr() as *mut _,
589 b"notify::activatable\0".as_ptr() as *const _,
590 Some(transmute(notify_activatable_trampoline::<Self, F> as usize)),
591 Box_::into_raw(f),
592 )
593 }
594 }
595
596 fn connect_property_selectable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
597 unsafe extern "C" fn notify_selectable_trampoline<P, F: Fn(&P) + 'static>(
598 this: *mut gtk_sys::GtkListBoxRow,
599 _param_spec: glib_sys::gpointer,
600 f: glib_sys::gpointer,
601 ) where
602 P: IsA<ListBoxRow>,
603 {
604 let f: &F = &*(f as *const F);
605 f(&ListBoxRow::from_glib_borrow(this).unsafe_cast())
606 }
607 unsafe {
608 let f: Box_<F> = Box_::new(f);
609 connect_raw(
610 self.as_ptr() as *mut _,
611 b"notify::selectable\0".as_ptr() as *const _,
612 Some(transmute(notify_selectable_trampoline::<Self, F> as usize)),
613 Box_::into_raw(f),
614 )
615 }
616 }
617}
618
619impl fmt::Display for ListBoxRow {
620 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
621 write!(f, "ListBoxRow")
622 }
623}