1use atk_sys;
6use glib::object::Cast;
7use glib::object::IsA;
8use glib::signal::connect_raw;
9use glib::signal::SignalHandlerId;
10use glib::translate::*;
11use glib_sys;
12use std::boxed::Box as Box_;
13use std::fmt;
14use std::mem::transmute;
15use Object;
16
17glib_wrapper! {
18 pub struct Selection(Interface<atk_sys::AtkSelection>);
19
20 match fn {
21 get_type => || atk_sys::atk_selection_get_type(),
22 }
23}
24
25pub const NONE_SELECTION: Option<&Selection> = None;
26
27pub trait SelectionExt: 'static {
28 fn add_selection(&self, i: i32) -> bool;
29
30 fn clear_selection(&self) -> bool;
31
32 fn get_selection_count(&self) -> i32;
33
34 fn is_child_selected(&self, i: i32) -> bool;
35
36 fn ref_selection(&self, i: i32) -> Option<Object>;
37
38 fn remove_selection(&self, i: i32) -> bool;
39
40 fn select_all_selection(&self) -> bool;
41
42 fn connect_selection_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
43}
44
45impl<O: IsA<Selection>> SelectionExt for O {
46 fn add_selection(&self, i: i32) -> bool {
47 unsafe {
48 from_glib(atk_sys::atk_selection_add_selection(
49 self.as_ref().to_glib_none().0,
50 i,
51 ))
52 }
53 }
54
55 fn clear_selection(&self) -> bool {
56 unsafe {
57 from_glib(atk_sys::atk_selection_clear_selection(
58 self.as_ref().to_glib_none().0,
59 ))
60 }
61 }
62
63 fn get_selection_count(&self) -> i32 {
64 unsafe { atk_sys::atk_selection_get_selection_count(self.as_ref().to_glib_none().0) }
65 }
66
67 fn is_child_selected(&self, i: i32) -> bool {
68 unsafe {
69 from_glib(atk_sys::atk_selection_is_child_selected(
70 self.as_ref().to_glib_none().0,
71 i,
72 ))
73 }
74 }
75
76 fn ref_selection(&self, i: i32) -> Option<Object> {
77 unsafe {
78 from_glib_full(atk_sys::atk_selection_ref_selection(
79 self.as_ref().to_glib_none().0,
80 i,
81 ))
82 }
83 }
84
85 fn remove_selection(&self, i: i32) -> bool {
86 unsafe {
87 from_glib(atk_sys::atk_selection_remove_selection(
88 self.as_ref().to_glib_none().0,
89 i,
90 ))
91 }
92 }
93
94 fn select_all_selection(&self) -> bool {
95 unsafe {
96 from_glib(atk_sys::atk_selection_select_all_selection(
97 self.as_ref().to_glib_none().0,
98 ))
99 }
100 }
101
102 fn connect_selection_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
103 unsafe extern "C" fn selection_changed_trampoline<P, F: Fn(&P) + 'static>(
104 this: *mut atk_sys::AtkSelection,
105 f: glib_sys::gpointer,
106 ) where
107 P: IsA<Selection>,
108 {
109 let f: &F = &*(f as *const F);
110 f(&Selection::from_glib_borrow(this).unsafe_cast())
111 }
112 unsafe {
113 let f: Box_<F> = Box_::new(f);
114 connect_raw(
115 self.as_ptr() as *mut _,
116 b"selection-changed\0".as_ptr() as *const _,
117 Some(transmute(selection_changed_trampoline::<Self, F> as usize)),
118 Box_::into_raw(f),
119 )
120 }
121 }
122}
123
124impl fmt::Display for Selection {
125 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
126 write!(f, "Selection")
127 }
128}