1use gdk;
6#[cfg(any(feature = "v3_16", feature = "dox"))]
7use gio;
8use glib;
9use glib::object::Cast;
10use glib::object::IsA;
11use glib::object::ObjectExt;
12use glib::signal::connect_raw;
13use glib::signal::SignalHandlerId;
14use glib::translate::*;
15use glib::StaticType;
16use glib::ToValue;
17use glib_sys;
18use gobject_sys;
19use gtk_sys;
20use libc;
21use std::boxed::Box as Box_;
22use std::fmt;
23use std::mem::transmute;
24use Adjustment;
25use Align;
26use Buildable;
27use Container;
28use ListBoxRow;
29use MovementStep;
30use ResizeMode;
31use SelectionMode;
32use Widget;
33
34glib_wrapper! {
35 pub struct ListBox(Object<gtk_sys::GtkListBox, gtk_sys::GtkListBoxClass, ListBoxClass>) @extends Container, Widget, @implements Buildable;
36
37 match fn {
38 get_type => || gtk_sys::gtk_list_box_get_type(),
39 }
40}
41
42impl ListBox {
43 pub fn new() -> ListBox {
44 assert_initialized_main_thread!();
45 unsafe { Widget::from_glib_none(gtk_sys::gtk_list_box_new()).unsafe_cast() }
46 }
47}
48
49impl Default for ListBox {
50 fn default() -> Self {
51 Self::new()
52 }
53}
54
55pub struct ListBoxBuilder {
56 activate_on_single_click: Option<bool>,
57 selection_mode: Option<SelectionMode>,
58 border_width: Option<u32>,
59 child: Option<Widget>,
60 resize_mode: Option<ResizeMode>,
61 app_paintable: Option<bool>,
62 can_default: Option<bool>,
63 can_focus: Option<bool>,
64 events: Option<gdk::EventMask>,
65 expand: Option<bool>,
66 #[cfg(any(feature = "v3_20", feature = "dox"))]
67 focus_on_click: Option<bool>,
68 halign: Option<Align>,
69 has_default: Option<bool>,
70 has_focus: Option<bool>,
71 has_tooltip: Option<bool>,
72 height_request: Option<i32>,
73 hexpand: Option<bool>,
74 hexpand_set: Option<bool>,
75 is_focus: Option<bool>,
76 margin: Option<i32>,
77 margin_bottom: Option<i32>,
78 margin_end: Option<i32>,
79 margin_start: Option<i32>,
80 margin_top: Option<i32>,
81 name: Option<String>,
82 no_show_all: Option<bool>,
83 opacity: Option<f64>,
84 parent: Option<Container>,
85 receives_default: Option<bool>,
86 sensitive: Option<bool>,
87 tooltip_markup: Option<String>,
89 tooltip_text: Option<String>,
90 valign: Option<Align>,
91 vexpand: Option<bool>,
92 vexpand_set: Option<bool>,
93 visible: Option<bool>,
94 width_request: Option<i32>,
95}
96
97impl ListBoxBuilder {
98 pub fn new() -> Self {
99 Self {
100 activate_on_single_click: None,
101 selection_mode: None,
102 border_width: None,
103 child: None,
104 resize_mode: None,
105 app_paintable: None,
106 can_default: None,
107 can_focus: None,
108 events: None,
109 expand: None,
110 #[cfg(any(feature = "v3_20", feature = "dox"))]
111 focus_on_click: None,
112 halign: None,
113 has_default: None,
114 has_focus: None,
115 has_tooltip: None,
116 height_request: None,
117 hexpand: None,
118 hexpand_set: None,
119 is_focus: None,
120 margin: None,
121 margin_bottom: None,
122 margin_end: None,
123 margin_start: None,
124 margin_top: None,
125 name: None,
126 no_show_all: None,
127 opacity: None,
128 parent: None,
129 receives_default: None,
130 sensitive: None,
131 tooltip_markup: None,
132 tooltip_text: None,
133 valign: None,
134 vexpand: None,
135 vexpand_set: None,
136 visible: None,
137 width_request: None,
138 }
139 }
140
141 pub fn build(self) -> ListBox {
142 let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
143 if let Some(ref activate_on_single_click) = self.activate_on_single_click {
144 properties.push(("activate-on-single-click", activate_on_single_click));
145 }
146 if let Some(ref selection_mode) = self.selection_mode {
147 properties.push(("selection-mode", selection_mode));
148 }
149 if let Some(ref border_width) = self.border_width {
150 properties.push(("border-width", border_width));
151 }
152 if let Some(ref child) = self.child {
153 properties.push(("child", child));
154 }
155 if let Some(ref resize_mode) = self.resize_mode {
156 properties.push(("resize-mode", resize_mode));
157 }
158 if let Some(ref app_paintable) = self.app_paintable {
159 properties.push(("app-paintable", app_paintable));
160 }
161 if let Some(ref can_default) = self.can_default {
162 properties.push(("can-default", can_default));
163 }
164 if let Some(ref can_focus) = self.can_focus {
165 properties.push(("can-focus", can_focus));
166 }
167 if let Some(ref events) = self.events {
168 properties.push(("events", events));
169 }
170 if let Some(ref expand) = self.expand {
171 properties.push(("expand", expand));
172 }
173 #[cfg(any(feature = "v3_20", feature = "dox"))]
174 {
175 if let Some(ref focus_on_click) = self.focus_on_click {
176 properties.push(("focus-on-click", focus_on_click));
177 }
178 }
179 if let Some(ref halign) = self.halign {
180 properties.push(("halign", halign));
181 }
182 if let Some(ref has_default) = self.has_default {
183 properties.push(("has-default", has_default));
184 }
185 if let Some(ref has_focus) = self.has_focus {
186 properties.push(("has-focus", has_focus));
187 }
188 if let Some(ref has_tooltip) = self.has_tooltip {
189 properties.push(("has-tooltip", has_tooltip));
190 }
191 if let Some(ref height_request) = self.height_request {
192 properties.push(("height-request", height_request));
193 }
194 if let Some(ref hexpand) = self.hexpand {
195 properties.push(("hexpand", hexpand));
196 }
197 if let Some(ref hexpand_set) = self.hexpand_set {
198 properties.push(("hexpand-set", hexpand_set));
199 }
200 if let Some(ref is_focus) = self.is_focus {
201 properties.push(("is-focus", is_focus));
202 }
203 if let Some(ref margin) = self.margin {
204 properties.push(("margin", margin));
205 }
206 if let Some(ref margin_bottom) = self.margin_bottom {
207 properties.push(("margin-bottom", margin_bottom));
208 }
209 if let Some(ref margin_end) = self.margin_end {
210 properties.push(("margin-end", margin_end));
211 }
212 if let Some(ref margin_start) = self.margin_start {
213 properties.push(("margin-start", margin_start));
214 }
215 if let Some(ref margin_top) = self.margin_top {
216 properties.push(("margin-top", margin_top));
217 }
218 if let Some(ref name) = self.name {
219 properties.push(("name", name));
220 }
221 if let Some(ref no_show_all) = self.no_show_all {
222 properties.push(("no-show-all", no_show_all));
223 }
224 if let Some(ref opacity) = self.opacity {
225 properties.push(("opacity", opacity));
226 }
227 if let Some(ref parent) = self.parent {
228 properties.push(("parent", parent));
229 }
230 if let Some(ref receives_default) = self.receives_default {
231 properties.push(("receives-default", receives_default));
232 }
233 if let Some(ref sensitive) = self.sensitive {
234 properties.push(("sensitive", sensitive));
235 }
236 if let Some(ref tooltip_markup) = self.tooltip_markup {
237 properties.push(("tooltip-markup", tooltip_markup));
238 }
239 if let Some(ref tooltip_text) = self.tooltip_text {
240 properties.push(("tooltip-text", tooltip_text));
241 }
242 if let Some(ref valign) = self.valign {
243 properties.push(("valign", valign));
244 }
245 if let Some(ref vexpand) = self.vexpand {
246 properties.push(("vexpand", vexpand));
247 }
248 if let Some(ref vexpand_set) = self.vexpand_set {
249 properties.push(("vexpand-set", vexpand_set));
250 }
251 if let Some(ref visible) = self.visible {
252 properties.push(("visible", visible));
253 }
254 if let Some(ref width_request) = self.width_request {
255 properties.push(("width-request", width_request));
256 }
257 glib::Object::new(ListBox::static_type(), &properties)
258 .expect("object new")
259 .downcast()
260 .expect("downcast")
261 }
262
263 pub fn activate_on_single_click(mut self, activate_on_single_click: bool) -> Self {
264 self.activate_on_single_click = Some(activate_on_single_click);
265 self
266 }
267
268 pub fn selection_mode(mut self, selection_mode: SelectionMode) -> Self {
269 self.selection_mode = Some(selection_mode);
270 self
271 }
272
273 pub fn border_width(mut self, border_width: u32) -> Self {
274 self.border_width = Some(border_width);
275 self
276 }
277
278 pub fn child(mut self, child: &Widget) -> Self {
279 self.child = Some(child.clone());
280 self
281 }
282
283 pub fn resize_mode(mut self, resize_mode: ResizeMode) -> Self {
284 self.resize_mode = Some(resize_mode);
285 self
286 }
287
288 pub fn app_paintable(mut self, app_paintable: bool) -> Self {
289 self.app_paintable = Some(app_paintable);
290 self
291 }
292
293 pub fn can_default(mut self, can_default: bool) -> Self {
294 self.can_default = Some(can_default);
295 self
296 }
297
298 pub fn can_focus(mut self, can_focus: bool) -> Self {
299 self.can_focus = Some(can_focus);
300 self
301 }
302
303 pub fn events(mut self, events: gdk::EventMask) -> Self {
304 self.events = Some(events);
305 self
306 }
307
308 pub fn expand(mut self, expand: bool) -> Self {
309 self.expand = Some(expand);
310 self
311 }
312
313 #[cfg(any(feature = "v3_20", feature = "dox"))]
314 pub fn focus_on_click(mut self, focus_on_click: bool) -> Self {
315 self.focus_on_click = Some(focus_on_click);
316 self
317 }
318
319 pub fn halign(mut self, halign: Align) -> Self {
320 self.halign = Some(halign);
321 self
322 }
323
324 pub fn has_default(mut self, has_default: bool) -> Self {
325 self.has_default = Some(has_default);
326 self
327 }
328
329 pub fn has_focus(mut self, has_focus: bool) -> Self {
330 self.has_focus = Some(has_focus);
331 self
332 }
333
334 pub fn has_tooltip(mut self, has_tooltip: bool) -> Self {
335 self.has_tooltip = Some(has_tooltip);
336 self
337 }
338
339 pub fn height_request(mut self, height_request: i32) -> Self {
340 self.height_request = Some(height_request);
341 self
342 }
343
344 pub fn hexpand(mut self, hexpand: bool) -> Self {
345 self.hexpand = Some(hexpand);
346 self
347 }
348
349 pub fn hexpand_set(mut self, hexpand_set: bool) -> Self {
350 self.hexpand_set = Some(hexpand_set);
351 self
352 }
353
354 pub fn is_focus(mut self, is_focus: bool) -> Self {
355 self.is_focus = Some(is_focus);
356 self
357 }
358
359 pub fn margin(mut self, margin: i32) -> Self {
360 self.margin = Some(margin);
361 self
362 }
363
364 pub fn margin_bottom(mut self, margin_bottom: i32) -> Self {
365 self.margin_bottom = Some(margin_bottom);
366 self
367 }
368
369 pub fn margin_end(mut self, margin_end: i32) -> Self {
370 self.margin_end = Some(margin_end);
371 self
372 }
373
374 pub fn margin_start(mut self, margin_start: i32) -> Self {
375 self.margin_start = Some(margin_start);
376 self
377 }
378
379 pub fn margin_top(mut self, margin_top: i32) -> Self {
380 self.margin_top = Some(margin_top);
381 self
382 }
383
384 pub fn name(mut self, name: &str) -> Self {
385 self.name = Some(name.to_string());
386 self
387 }
388
389 pub fn no_show_all(mut self, no_show_all: bool) -> Self {
390 self.no_show_all = Some(no_show_all);
391 self
392 }
393
394 pub fn opacity(mut self, opacity: f64) -> Self {
395 self.opacity = Some(opacity);
396 self
397 }
398
399 pub fn parent(mut self, parent: &Container) -> Self {
400 self.parent = Some(parent.clone());
401 self
402 }
403
404 pub fn receives_default(mut self, receives_default: bool) -> Self {
405 self.receives_default = Some(receives_default);
406 self
407 }
408
409 pub fn sensitive(mut self, sensitive: bool) -> Self {
410 self.sensitive = Some(sensitive);
411 self
412 }
413
414 pub fn tooltip_markup(mut self, tooltip_markup: &str) -> Self {
415 self.tooltip_markup = Some(tooltip_markup.to_string());
416 self
417 }
418
419 pub fn tooltip_text(mut self, tooltip_text: &str) -> Self {
420 self.tooltip_text = Some(tooltip_text.to_string());
421 self
422 }
423
424 pub fn valign(mut self, valign: Align) -> Self {
425 self.valign = Some(valign);
426 self
427 }
428
429 pub fn vexpand(mut self, vexpand: bool) -> Self {
430 self.vexpand = Some(vexpand);
431 self
432 }
433
434 pub fn vexpand_set(mut self, vexpand_set: bool) -> Self {
435 self.vexpand_set = Some(vexpand_set);
436 self
437 }
438
439 pub fn visible(mut self, visible: bool) -> Self {
440 self.visible = Some(visible);
441 self
442 }
443
444 pub fn width_request(mut self, width_request: i32) -> Self {
445 self.width_request = Some(width_request);
446 self
447 }
448}
449
450pub const NONE_LIST_BOX: Option<&ListBox> = None;
451
452pub trait ListBoxExt: 'static {
453 #[cfg(any(feature = "v3_16", feature = "dox"))]
454 fn bind_model<P: IsA<gio::ListModel>, Q: Fn(&glib::Object) -> Widget + 'static>(
455 &self,
456 model: Option<&P>,
457 create_widget_func: Q,
458 );
459
460 fn drag_highlight_row<P: IsA<ListBoxRow>>(&self, row: &P);
461
462 fn drag_unhighlight_row(&self);
463
464 fn get_activate_on_single_click(&self) -> bool;
465
466 fn get_adjustment(&self) -> Option<Adjustment>;
467
468 fn get_row_at_index(&self, index_: i32) -> Option<ListBoxRow>;
469
470 fn get_row_at_y(&self, y: i32) -> Option<ListBoxRow>;
471
472 fn get_selected_row(&self) -> Option<ListBoxRow>;
473
474 fn get_selected_rows(&self) -> Vec<ListBoxRow>;
475
476 fn get_selection_mode(&self) -> SelectionMode;
477
478 fn insert<P: IsA<Widget>>(&self, child: &P, position: i32);
479
480 fn invalidate_filter(&self);
481
482 fn invalidate_headers(&self);
483
484 fn invalidate_sort(&self);
485
486 fn prepend<P: IsA<Widget>>(&self, child: &P);
487
488 fn select_all(&self);
489
490 fn select_row<P: IsA<ListBoxRow>>(&self, row: Option<&P>);
491
492 fn selected_foreach<P: FnMut(&ListBox, &ListBoxRow)>(&self, func: P);
493
494 fn set_activate_on_single_click(&self, single: bool);
495
496 fn set_adjustment<P: IsA<Adjustment>>(&self, adjustment: Option<&P>);
497
498 fn set_filter_func(&self, filter_func: Option<Box<dyn Fn(&ListBoxRow) -> bool + 'static>>);
499
500 fn set_header_func(
501 &self,
502 update_header: Option<Box<dyn Fn(&ListBoxRow, Option<&ListBoxRow>) + 'static>>,
503 );
504
505 fn set_placeholder<P: IsA<Widget>>(&self, placeholder: Option<&P>);
506
507 fn set_selection_mode(&self, mode: SelectionMode);
508
509 fn set_sort_func(
510 &self,
511 sort_func: Option<Box<dyn Fn(&ListBoxRow, &ListBoxRow) -> i32 + 'static>>,
512 );
513
514 fn unselect_all(&self);
515
516 fn unselect_row<P: IsA<ListBoxRow>>(&self, row: &P);
517
518 fn connect_activate_cursor_row<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
519
520 fn emit_activate_cursor_row(&self);
521
522 fn connect_move_cursor<F: Fn(&Self, MovementStep, i32) + 'static>(
523 &self,
524 f: F,
525 ) -> SignalHandlerId;
526
527 fn emit_move_cursor(&self, object: MovementStep, p0: i32);
528
529 fn connect_row_activated<F: Fn(&Self, &ListBoxRow) + 'static>(&self, f: F) -> SignalHandlerId;
530
531 fn connect_row_selected<F: Fn(&Self, Option<&ListBoxRow>) + 'static>(
532 &self,
533 f: F,
534 ) -> SignalHandlerId;
535
536 fn connect_select_all<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
537
538 fn emit_select_all(&self);
539
540 fn connect_selected_rows_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
541
542 fn connect_toggle_cursor_row<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
543
544 fn emit_toggle_cursor_row(&self);
545
546 fn connect_unselect_all<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
547
548 fn emit_unselect_all(&self);
549
550 fn connect_property_activate_on_single_click_notify<F: Fn(&Self) + 'static>(
551 &self,
552 f: F,
553 ) -> SignalHandlerId;
554
555 fn connect_property_selection_mode_notify<F: Fn(&Self) + 'static>(
556 &self,
557 f: F,
558 ) -> SignalHandlerId;
559}
560
561impl<O: IsA<ListBox>> ListBoxExt for O {
562 #[cfg(any(feature = "v3_16", feature = "dox"))]
563 fn bind_model<P: IsA<gio::ListModel>, Q: Fn(&glib::Object) -> Widget + 'static>(
564 &self,
565 model: Option<&P>,
566 create_widget_func: Q,
567 ) {
568 let create_widget_func_data: Box_<Q> = Box::new(create_widget_func);
569 unsafe extern "C" fn create_widget_func_func<
570 P: IsA<gio::ListModel>,
571 Q: Fn(&glib::Object) -> Widget + 'static,
572 >(
573 item: *mut gobject_sys::GObject,
574 user_data: glib_sys::gpointer,
575 ) -> *mut gtk_sys::GtkWidget {
576 let item = from_glib_borrow(item);
577 let callback: &Q = &*(user_data as *mut _);
578 let res = (*callback)(&item);
579 res.to_glib_full()
580 }
581 let create_widget_func = Some(create_widget_func_func::<P, Q> as _);
582 unsafe extern "C" fn user_data_free_func_func<
583 P: IsA<gio::ListModel>,
584 Q: Fn(&glib::Object) -> Widget + 'static,
585 >(
586 data: glib_sys::gpointer,
587 ) {
588 let _callback: Box_<Q> = Box_::from_raw(data as *mut _);
589 }
590 let destroy_call4 = Some(user_data_free_func_func::<P, Q> as _);
591 let super_callback0: Box_<Q> = create_widget_func_data;
592 unsafe {
593 gtk_sys::gtk_list_box_bind_model(
594 self.as_ref().to_glib_none().0,
595 model.map(|p| p.as_ref()).to_glib_none().0,
596 create_widget_func,
597 Box::into_raw(super_callback0) as *mut _,
598 destroy_call4,
599 );
600 }
601 }
602
603 fn drag_highlight_row<P: IsA<ListBoxRow>>(&self, row: &P) {
604 unsafe {
605 gtk_sys::gtk_list_box_drag_highlight_row(
606 self.as_ref().to_glib_none().0,
607 row.as_ref().to_glib_none().0,
608 );
609 }
610 }
611
612 fn drag_unhighlight_row(&self) {
613 unsafe {
614 gtk_sys::gtk_list_box_drag_unhighlight_row(self.as_ref().to_glib_none().0);
615 }
616 }
617
618 fn get_activate_on_single_click(&self) -> bool {
619 unsafe {
620 from_glib(gtk_sys::gtk_list_box_get_activate_on_single_click(
621 self.as_ref().to_glib_none().0,
622 ))
623 }
624 }
625
626 fn get_adjustment(&self) -> Option<Adjustment> {
627 unsafe {
628 from_glib_none(gtk_sys::gtk_list_box_get_adjustment(
629 self.as_ref().to_glib_none().0,
630 ))
631 }
632 }
633
634 fn get_row_at_index(&self, index_: i32) -> Option<ListBoxRow> {
635 unsafe {
636 from_glib_none(gtk_sys::gtk_list_box_get_row_at_index(
637 self.as_ref().to_glib_none().0,
638 index_,
639 ))
640 }
641 }
642
643 fn get_row_at_y(&self, y: i32) -> Option<ListBoxRow> {
644 unsafe {
645 from_glib_none(gtk_sys::gtk_list_box_get_row_at_y(
646 self.as_ref().to_glib_none().0,
647 y,
648 ))
649 }
650 }
651
652 fn get_selected_row(&self) -> Option<ListBoxRow> {
653 unsafe {
654 from_glib_none(gtk_sys::gtk_list_box_get_selected_row(
655 self.as_ref().to_glib_none().0,
656 ))
657 }
658 }
659
660 fn get_selected_rows(&self) -> Vec<ListBoxRow> {
661 unsafe {
662 FromGlibPtrContainer::from_glib_container(gtk_sys::gtk_list_box_get_selected_rows(
663 self.as_ref().to_glib_none().0,
664 ))
665 }
666 }
667
668 fn get_selection_mode(&self) -> SelectionMode {
669 unsafe {
670 from_glib(gtk_sys::gtk_list_box_get_selection_mode(
671 self.as_ref().to_glib_none().0,
672 ))
673 }
674 }
675
676 fn insert<P: IsA<Widget>>(&self, child: &P, position: i32) {
677 unsafe {
678 gtk_sys::gtk_list_box_insert(
679 self.as_ref().to_glib_none().0,
680 child.as_ref().to_glib_none().0,
681 position,
682 );
683 }
684 }
685
686 fn invalidate_filter(&self) {
687 unsafe {
688 gtk_sys::gtk_list_box_invalidate_filter(self.as_ref().to_glib_none().0);
689 }
690 }
691
692 fn invalidate_headers(&self) {
693 unsafe {
694 gtk_sys::gtk_list_box_invalidate_headers(self.as_ref().to_glib_none().0);
695 }
696 }
697
698 fn invalidate_sort(&self) {
699 unsafe {
700 gtk_sys::gtk_list_box_invalidate_sort(self.as_ref().to_glib_none().0);
701 }
702 }
703
704 fn prepend<P: IsA<Widget>>(&self, child: &P) {
705 unsafe {
706 gtk_sys::gtk_list_box_prepend(
707 self.as_ref().to_glib_none().0,
708 child.as_ref().to_glib_none().0,
709 );
710 }
711 }
712
713 fn select_all(&self) {
714 unsafe {
715 gtk_sys::gtk_list_box_select_all(self.as_ref().to_glib_none().0);
716 }
717 }
718
719 fn select_row<P: IsA<ListBoxRow>>(&self, row: Option<&P>) {
720 unsafe {
721 gtk_sys::gtk_list_box_select_row(
722 self.as_ref().to_glib_none().0,
723 row.map(|p| p.as_ref()).to_glib_none().0,
724 );
725 }
726 }
727
728 fn selected_foreach<P: FnMut(&ListBox, &ListBoxRow)>(&self, func: P) {
729 let func_data: P = func;
730 unsafe extern "C" fn func_func<P: FnMut(&ListBox, &ListBoxRow)>(
731 box_: *mut gtk_sys::GtkListBox,
732 row: *mut gtk_sys::GtkListBoxRow,
733 user_data: glib_sys::gpointer,
734 ) {
735 let box_ = from_glib_borrow(box_);
736 let row = from_glib_borrow(row);
737 let callback: *mut P = user_data as *const _ as usize as *mut P;
738 (*callback)(&box_, &row);
739 }
740 let func = Some(func_func::<P> as _);
741 let super_callback0: &P = &func_data;
742 unsafe {
743 gtk_sys::gtk_list_box_selected_foreach(
744 self.as_ref().to_glib_none().0,
745 func,
746 super_callback0 as *const _ as usize as *mut _,
747 );
748 }
749 }
750
751 fn set_activate_on_single_click(&self, single: bool) {
752 unsafe {
753 gtk_sys::gtk_list_box_set_activate_on_single_click(
754 self.as_ref().to_glib_none().0,
755 single.to_glib(),
756 );
757 }
758 }
759
760 fn set_adjustment<P: IsA<Adjustment>>(&self, adjustment: Option<&P>) {
761 unsafe {
762 gtk_sys::gtk_list_box_set_adjustment(
763 self.as_ref().to_glib_none().0,
764 adjustment.map(|p| p.as_ref()).to_glib_none().0,
765 );
766 }
767 }
768
769 fn set_filter_func(&self, filter_func: Option<Box<dyn Fn(&ListBoxRow) -> bool + 'static>>) {
770 let filter_func_data: Box_<Option<Box<dyn Fn(&ListBoxRow) -> bool + 'static>>> =
771 Box::new(filter_func);
772 unsafe extern "C" fn filter_func_func(
773 row: *mut gtk_sys::GtkListBoxRow,
774 user_data: glib_sys::gpointer,
775 ) -> glib_sys::gboolean {
776 let row = from_glib_borrow(row);
777 let callback: &Option<Box<dyn Fn(&ListBoxRow) -> bool + 'static>> =
778 &*(user_data as *mut _);
779 let res = if let Some(ref callback) = *callback {
780 callback(&row)
781 } else {
782 panic!("cannot get closure...")
783 };
784 res.to_glib()
785 }
786 let filter_func = if filter_func_data.is_some() {
787 Some(filter_func_func as _)
788 } else {
789 None
790 };
791 unsafe extern "C" fn destroy_func(data: glib_sys::gpointer) {
792 let _callback: Box_<Option<Box<dyn Fn(&ListBoxRow) -> bool + 'static>>> =
793 Box_::from_raw(data as *mut _);
794 }
795 let destroy_call3 = Some(destroy_func as _);
796 let super_callback0: Box_<Option<Box<dyn Fn(&ListBoxRow) -> bool + 'static>>> =
797 filter_func_data;
798 unsafe {
799 gtk_sys::gtk_list_box_set_filter_func(
800 self.as_ref().to_glib_none().0,
801 filter_func,
802 Box::into_raw(super_callback0) as *mut _,
803 destroy_call3,
804 );
805 }
806 }
807
808 fn set_header_func(
809 &self,
810 update_header: Option<Box<dyn Fn(&ListBoxRow, Option<&ListBoxRow>) + 'static>>,
811 ) {
812 let update_header_data: Box_<
813 Option<Box<dyn Fn(&ListBoxRow, Option<&ListBoxRow>) + 'static>>,
814 > = Box::new(update_header);
815 unsafe extern "C" fn update_header_func(
816 row: *mut gtk_sys::GtkListBoxRow,
817 before: *mut gtk_sys::GtkListBoxRow,
818 user_data: glib_sys::gpointer,
819 ) {
820 let row = from_glib_borrow(row);
821 let before: Option<ListBoxRow> = from_glib_borrow(before);
822 let callback: &Option<Box<dyn Fn(&ListBoxRow, Option<&ListBoxRow>) + 'static>> =
823 &*(user_data as *mut _);
824 if let Some(ref callback) = *callback {
825 callback(&row, before.as_ref())
826 } else {
827 panic!("cannot get closure...")
828 };
829 }
830 let update_header = if update_header_data.is_some() {
831 Some(update_header_func as _)
832 } else {
833 None
834 };
835 unsafe extern "C" fn destroy_func(data: glib_sys::gpointer) {
836 let _callback: Box_<Option<Box<dyn Fn(&ListBoxRow, Option<&ListBoxRow>) + 'static>>> =
837 Box_::from_raw(data as *mut _);
838 }
839 let destroy_call3 = Some(destroy_func as _);
840 let super_callback0: Box_<Option<Box<dyn Fn(&ListBoxRow, Option<&ListBoxRow>) + 'static>>> =
841 update_header_data;
842 unsafe {
843 gtk_sys::gtk_list_box_set_header_func(
844 self.as_ref().to_glib_none().0,
845 update_header,
846 Box::into_raw(super_callback0) as *mut _,
847 destroy_call3,
848 );
849 }
850 }
851
852 fn set_placeholder<P: IsA<Widget>>(&self, placeholder: Option<&P>) {
853 unsafe {
854 gtk_sys::gtk_list_box_set_placeholder(
855 self.as_ref().to_glib_none().0,
856 placeholder.map(|p| p.as_ref()).to_glib_none().0,
857 );
858 }
859 }
860
861 fn set_selection_mode(&self, mode: SelectionMode) {
862 unsafe {
863 gtk_sys::gtk_list_box_set_selection_mode(
864 self.as_ref().to_glib_none().0,
865 mode.to_glib(),
866 );
867 }
868 }
869
870 fn set_sort_func(
871 &self,
872 sort_func: Option<Box<dyn Fn(&ListBoxRow, &ListBoxRow) -> i32 + 'static>>,
873 ) {
874 let sort_func_data: Box_<Option<Box<dyn Fn(&ListBoxRow, &ListBoxRow) -> i32 + 'static>>> =
875 Box::new(sort_func);
876 unsafe extern "C" fn sort_func_func(
877 row1: *mut gtk_sys::GtkListBoxRow,
878 row2: *mut gtk_sys::GtkListBoxRow,
879 user_data: glib_sys::gpointer,
880 ) -> libc::c_int {
881 let row1 = from_glib_borrow(row1);
882 let row2 = from_glib_borrow(row2);
883 let callback: &Option<Box<dyn Fn(&ListBoxRow, &ListBoxRow) -> i32 + 'static>> =
884 &*(user_data as *mut _);
885 let res = if let Some(ref callback) = *callback {
886 callback(&row1, &row2)
887 } else {
888 panic!("cannot get closure...")
889 };
890 res
891 }
892 let sort_func = if sort_func_data.is_some() {
893 Some(sort_func_func as _)
894 } else {
895 None
896 };
897 unsafe extern "C" fn destroy_func(data: glib_sys::gpointer) {
898 let _callback: Box_<Option<Box<dyn Fn(&ListBoxRow, &ListBoxRow) -> i32 + 'static>>> =
899 Box_::from_raw(data as *mut _);
900 }
901 let destroy_call3 = Some(destroy_func as _);
902 let super_callback0: Box_<Option<Box<dyn Fn(&ListBoxRow, &ListBoxRow) -> i32 + 'static>>> =
903 sort_func_data;
904 unsafe {
905 gtk_sys::gtk_list_box_set_sort_func(
906 self.as_ref().to_glib_none().0,
907 sort_func,
908 Box::into_raw(super_callback0) as *mut _,
909 destroy_call3,
910 );
911 }
912 }
913
914 fn unselect_all(&self) {
915 unsafe {
916 gtk_sys::gtk_list_box_unselect_all(self.as_ref().to_glib_none().0);
917 }
918 }
919
920 fn unselect_row<P: IsA<ListBoxRow>>(&self, row: &P) {
921 unsafe {
922 gtk_sys::gtk_list_box_unselect_row(
923 self.as_ref().to_glib_none().0,
924 row.as_ref().to_glib_none().0,
925 );
926 }
927 }
928
929 fn connect_activate_cursor_row<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
930 unsafe extern "C" fn activate_cursor_row_trampoline<P, F: Fn(&P) + 'static>(
931 this: *mut gtk_sys::GtkListBox,
932 f: glib_sys::gpointer,
933 ) where
934 P: IsA<ListBox>,
935 {
936 let f: &F = &*(f as *const F);
937 f(&ListBox::from_glib_borrow(this).unsafe_cast())
938 }
939 unsafe {
940 let f: Box_<F> = Box_::new(f);
941 connect_raw(
942 self.as_ptr() as *mut _,
943 b"activate-cursor-row\0".as_ptr() as *const _,
944 Some(transmute(
945 activate_cursor_row_trampoline::<Self, F> as usize,
946 )),
947 Box_::into_raw(f),
948 )
949 }
950 }
951
952 fn emit_activate_cursor_row(&self) {
953 let _ = unsafe {
954 glib::Object::from_glib_borrow(self.to_glib_none().0 as *mut gobject_sys::GObject)
955 .emit("activate-cursor-row", &[])
956 .unwrap()
957 };
958 }
959
960 fn connect_move_cursor<F: Fn(&Self, MovementStep, i32) + 'static>(
961 &self,
962 f: F,
963 ) -> SignalHandlerId {
964 unsafe extern "C" fn move_cursor_trampoline<P, F: Fn(&P, MovementStep, i32) + 'static>(
965 this: *mut gtk_sys::GtkListBox,
966 object: gtk_sys::GtkMovementStep,
967 p0: libc::c_int,
968 f: glib_sys::gpointer,
969 ) where
970 P: IsA<ListBox>,
971 {
972 let f: &F = &*(f as *const F);
973 f(
974 &ListBox::from_glib_borrow(this).unsafe_cast(),
975 from_glib(object),
976 p0,
977 )
978 }
979 unsafe {
980 let f: Box_<F> = Box_::new(f);
981 connect_raw(
982 self.as_ptr() as *mut _,
983 b"move-cursor\0".as_ptr() as *const _,
984 Some(transmute(move_cursor_trampoline::<Self, F> as usize)),
985 Box_::into_raw(f),
986 )
987 }
988 }
989
990 fn emit_move_cursor(&self, object: MovementStep, p0: i32) {
991 let _ = unsafe {
992 glib::Object::from_glib_borrow(self.to_glib_none().0 as *mut gobject_sys::GObject)
993 .emit("move-cursor", &[&object, &p0])
994 .unwrap()
995 };
996 }
997
998 fn connect_row_activated<F: Fn(&Self, &ListBoxRow) + 'static>(&self, f: F) -> SignalHandlerId {
999 unsafe extern "C" fn row_activated_trampoline<P, F: Fn(&P, &ListBoxRow) + 'static>(
1000 this: *mut gtk_sys::GtkListBox,
1001 row: *mut gtk_sys::GtkListBoxRow,
1002 f: glib_sys::gpointer,
1003 ) where
1004 P: IsA<ListBox>,
1005 {
1006 let f: &F = &*(f as *const F);
1007 f(
1008 &ListBox::from_glib_borrow(this).unsafe_cast(),
1009 &from_glib_borrow(row),
1010 )
1011 }
1012 unsafe {
1013 let f: Box_<F> = Box_::new(f);
1014 connect_raw(
1015 self.as_ptr() as *mut _,
1016 b"row-activated\0".as_ptr() as *const _,
1017 Some(transmute(row_activated_trampoline::<Self, F> as usize)),
1018 Box_::into_raw(f),
1019 )
1020 }
1021 }
1022
1023 fn connect_row_selected<F: Fn(&Self, Option<&ListBoxRow>) + 'static>(
1024 &self,
1025 f: F,
1026 ) -> SignalHandlerId {
1027 unsafe extern "C" fn row_selected_trampoline<P, F: Fn(&P, Option<&ListBoxRow>) + 'static>(
1028 this: *mut gtk_sys::GtkListBox,
1029 row: *mut gtk_sys::GtkListBoxRow,
1030 f: glib_sys::gpointer,
1031 ) where
1032 P: IsA<ListBox>,
1033 {
1034 let f: &F = &*(f as *const F);
1035 f(
1036 &ListBox::from_glib_borrow(this).unsafe_cast(),
1037 Option::<ListBoxRow>::from_glib_borrow(row).as_ref(),
1038 )
1039 }
1040 unsafe {
1041 let f: Box_<F> = Box_::new(f);
1042 connect_raw(
1043 self.as_ptr() as *mut _,
1044 b"row-selected\0".as_ptr() as *const _,
1045 Some(transmute(row_selected_trampoline::<Self, F> as usize)),
1046 Box_::into_raw(f),
1047 )
1048 }
1049 }
1050
1051 fn connect_select_all<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1052 unsafe extern "C" fn select_all_trampoline<P, F: Fn(&P) + 'static>(
1053 this: *mut gtk_sys::GtkListBox,
1054 f: glib_sys::gpointer,
1055 ) where
1056 P: IsA<ListBox>,
1057 {
1058 let f: &F = &*(f as *const F);
1059 f(&ListBox::from_glib_borrow(this).unsafe_cast())
1060 }
1061 unsafe {
1062 let f: Box_<F> = Box_::new(f);
1063 connect_raw(
1064 self.as_ptr() as *mut _,
1065 b"select-all\0".as_ptr() as *const _,
1066 Some(transmute(select_all_trampoline::<Self, F> as usize)),
1067 Box_::into_raw(f),
1068 )
1069 }
1070 }
1071
1072 fn emit_select_all(&self) {
1073 let _ = unsafe {
1074 glib::Object::from_glib_borrow(self.to_glib_none().0 as *mut gobject_sys::GObject)
1075 .emit("select-all", &[])
1076 .unwrap()
1077 };
1078 }
1079
1080 fn connect_selected_rows_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1081 unsafe extern "C" fn selected_rows_changed_trampoline<P, F: Fn(&P) + 'static>(
1082 this: *mut gtk_sys::GtkListBox,
1083 f: glib_sys::gpointer,
1084 ) where
1085 P: IsA<ListBox>,
1086 {
1087 let f: &F = &*(f as *const F);
1088 f(&ListBox::from_glib_borrow(this).unsafe_cast())
1089 }
1090 unsafe {
1091 let f: Box_<F> = Box_::new(f);
1092 connect_raw(
1093 self.as_ptr() as *mut _,
1094 b"selected-rows-changed\0".as_ptr() as *const _,
1095 Some(transmute(
1096 selected_rows_changed_trampoline::<Self, F> as usize,
1097 )),
1098 Box_::into_raw(f),
1099 )
1100 }
1101 }
1102
1103 fn connect_toggle_cursor_row<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1104 unsafe extern "C" fn toggle_cursor_row_trampoline<P, F: Fn(&P) + 'static>(
1105 this: *mut gtk_sys::GtkListBox,
1106 f: glib_sys::gpointer,
1107 ) where
1108 P: IsA<ListBox>,
1109 {
1110 let f: &F = &*(f as *const F);
1111 f(&ListBox::from_glib_borrow(this).unsafe_cast())
1112 }
1113 unsafe {
1114 let f: Box_<F> = Box_::new(f);
1115 connect_raw(
1116 self.as_ptr() as *mut _,
1117 b"toggle-cursor-row\0".as_ptr() as *const _,
1118 Some(transmute(toggle_cursor_row_trampoline::<Self, F> as usize)),
1119 Box_::into_raw(f),
1120 )
1121 }
1122 }
1123
1124 fn emit_toggle_cursor_row(&self) {
1125 let _ = unsafe {
1126 glib::Object::from_glib_borrow(self.to_glib_none().0 as *mut gobject_sys::GObject)
1127 .emit("toggle-cursor-row", &[])
1128 .unwrap()
1129 };
1130 }
1131
1132 fn connect_unselect_all<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1133 unsafe extern "C" fn unselect_all_trampoline<P, F: Fn(&P) + 'static>(
1134 this: *mut gtk_sys::GtkListBox,
1135 f: glib_sys::gpointer,
1136 ) where
1137 P: IsA<ListBox>,
1138 {
1139 let f: &F = &*(f as *const F);
1140 f(&ListBox::from_glib_borrow(this).unsafe_cast())
1141 }
1142 unsafe {
1143 let f: Box_<F> = Box_::new(f);
1144 connect_raw(
1145 self.as_ptr() as *mut _,
1146 b"unselect-all\0".as_ptr() as *const _,
1147 Some(transmute(unselect_all_trampoline::<Self, F> as usize)),
1148 Box_::into_raw(f),
1149 )
1150 }
1151 }
1152
1153 fn emit_unselect_all(&self) {
1154 let _ = unsafe {
1155 glib::Object::from_glib_borrow(self.to_glib_none().0 as *mut gobject_sys::GObject)
1156 .emit("unselect-all", &[])
1157 .unwrap()
1158 };
1159 }
1160
1161 fn connect_property_activate_on_single_click_notify<F: Fn(&Self) + 'static>(
1162 &self,
1163 f: F,
1164 ) -> SignalHandlerId {
1165 unsafe extern "C" fn notify_activate_on_single_click_trampoline<P, F: Fn(&P) + 'static>(
1166 this: *mut gtk_sys::GtkListBox,
1167 _param_spec: glib_sys::gpointer,
1168 f: glib_sys::gpointer,
1169 ) where
1170 P: IsA<ListBox>,
1171 {
1172 let f: &F = &*(f as *const F);
1173 f(&ListBox::from_glib_borrow(this).unsafe_cast())
1174 }
1175 unsafe {
1176 let f: Box_<F> = Box_::new(f);
1177 connect_raw(
1178 self.as_ptr() as *mut _,
1179 b"notify::activate-on-single-click\0".as_ptr() as *const _,
1180 Some(transmute(
1181 notify_activate_on_single_click_trampoline::<Self, F> as usize,
1182 )),
1183 Box_::into_raw(f),
1184 )
1185 }
1186 }
1187
1188 fn connect_property_selection_mode_notify<F: Fn(&Self) + 'static>(
1189 &self,
1190 f: F,
1191 ) -> SignalHandlerId {
1192 unsafe extern "C" fn notify_selection_mode_trampoline<P, F: Fn(&P) + 'static>(
1193 this: *mut gtk_sys::GtkListBox,
1194 _param_spec: glib_sys::gpointer,
1195 f: glib_sys::gpointer,
1196 ) where
1197 P: IsA<ListBox>,
1198 {
1199 let f: &F = &*(f as *const F);
1200 f(&ListBox::from_glib_borrow(this).unsafe_cast())
1201 }
1202 unsafe {
1203 let f: Box_<F> = Box_::new(f);
1204 connect_raw(
1205 self.as_ptr() as *mut _,
1206 b"notify::selection-mode\0".as_ptr() as *const _,
1207 Some(transmute(
1208 notify_selection_mode_trampoline::<Self, F> as usize,
1209 )),
1210 Box_::into_raw(f),
1211 )
1212 }
1213 }
1214}
1215
1216impl fmt::Display for ListBox {
1217 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1218 write!(f, "ListBox")
1219 }
1220}