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;
15use std::mem::transmute;
16use CoordType;
17use Layer;
18use Object;
19use Rectangle;
20#[cfg(any(feature = "v2_30", feature = "dox"))]
21use ScrollType;
22
23glib_wrapper! {
24 pub struct Component(Interface<atk_sys::AtkComponent>);
25
26 match fn {
27 get_type => || atk_sys::atk_component_get_type(),
28 }
29}
30
31pub const NONE_COMPONENT: Option<&Component> = None;
32
33pub trait ComponentExt: 'static {
34 fn contains(&self, x: i32, y: i32, coord_type: CoordType) -> bool;
35
36 fn get_alpha(&self) -> f64;
37
38 fn get_extents(&self, coord_type: CoordType) -> (i32, i32, i32, i32);
39
40 fn get_layer(&self) -> Layer;
41
42 fn get_mdi_zorder(&self) -> i32;
43
44 fn get_position(&self, coord_type: CoordType) -> (i32, i32);
45
46 fn get_size(&self) -> (i32, i32);
47
48 fn grab_focus(&self) -> bool;
49
50 fn ref_accessible_at_point(&self, x: i32, y: i32, coord_type: CoordType) -> Option<Object>;
51
52 #[cfg(any(feature = "v2_30", feature = "dox"))]
53 fn scroll_to(&self, type_: ScrollType) -> bool;
54
55 #[cfg(any(feature = "v2_30", feature = "dox"))]
56 fn scroll_to_point(&self, coords: CoordType, x: i32, y: i32) -> bool;
57
58 fn set_extents(&self, x: i32, y: i32, width: i32, height: i32, coord_type: CoordType) -> bool;
59
60 fn set_position(&self, x: i32, y: i32, coord_type: CoordType) -> bool;
61
62 fn set_size(&self, width: i32, height: i32) -> bool;
63
64 fn connect_bounds_changed<F: Fn(&Self, &Rectangle) + 'static>(&self, f: F) -> SignalHandlerId;
65}
66
67impl<O: IsA<Component>> ComponentExt for O {
68 fn contains(&self, x: i32, y: i32, coord_type: CoordType) -> bool {
69 unsafe {
70 from_glib(atk_sys::atk_component_contains(
71 self.as_ref().to_glib_none().0,
72 x,
73 y,
74 coord_type.to_glib(),
75 ))
76 }
77 }
78
79 fn get_alpha(&self) -> f64 {
80 unsafe { atk_sys::atk_component_get_alpha(self.as_ref().to_glib_none().0) }
81 }
82
83 fn get_extents(&self, coord_type: CoordType) -> (i32, i32, i32, i32) {
84 unsafe {
85 let mut x = mem::uninitialized();
86 let mut y = mem::uninitialized();
87 let mut width = mem::uninitialized();
88 let mut height = mem::uninitialized();
89 atk_sys::atk_component_get_extents(
90 self.as_ref().to_glib_none().0,
91 &mut x,
92 &mut y,
93 &mut width,
94 &mut height,
95 coord_type.to_glib(),
96 );
97 (x, y, width, height)
98 }
99 }
100
101 fn get_layer(&self) -> Layer {
102 unsafe {
103 from_glib(atk_sys::atk_component_get_layer(
104 self.as_ref().to_glib_none().0,
105 ))
106 }
107 }
108
109 fn get_mdi_zorder(&self) -> i32 {
110 unsafe { atk_sys::atk_component_get_mdi_zorder(self.as_ref().to_glib_none().0) }
111 }
112
113 fn get_position(&self, coord_type: CoordType) -> (i32, i32) {
114 unsafe {
115 let mut x = mem::uninitialized();
116 let mut y = mem::uninitialized();
117 atk_sys::atk_component_get_position(
118 self.as_ref().to_glib_none().0,
119 &mut x,
120 &mut y,
121 coord_type.to_glib(),
122 );
123 (x, y)
124 }
125 }
126
127 fn get_size(&self) -> (i32, i32) {
128 unsafe {
129 let mut width = mem::uninitialized();
130 let mut height = mem::uninitialized();
131 atk_sys::atk_component_get_size(
132 self.as_ref().to_glib_none().0,
133 &mut width,
134 &mut height,
135 );
136 (width, height)
137 }
138 }
139
140 fn grab_focus(&self) -> bool {
141 unsafe {
142 from_glib(atk_sys::atk_component_grab_focus(
143 self.as_ref().to_glib_none().0,
144 ))
145 }
146 }
147
148 fn ref_accessible_at_point(&self, x: i32, y: i32, coord_type: CoordType) -> Option<Object> {
149 unsafe {
150 from_glib_full(atk_sys::atk_component_ref_accessible_at_point(
151 self.as_ref().to_glib_none().0,
152 x,
153 y,
154 coord_type.to_glib(),
155 ))
156 }
157 }
158
159 #[cfg(any(feature = "v2_30", feature = "dox"))]
160 fn scroll_to(&self, type_: ScrollType) -> bool {
161 unsafe {
162 from_glib(atk_sys::atk_component_scroll_to(
163 self.as_ref().to_glib_none().0,
164 type_.to_glib(),
165 ))
166 }
167 }
168
169 #[cfg(any(feature = "v2_30", feature = "dox"))]
170 fn scroll_to_point(&self, coords: CoordType, x: i32, y: i32) -> bool {
171 unsafe {
172 from_glib(atk_sys::atk_component_scroll_to_point(
173 self.as_ref().to_glib_none().0,
174 coords.to_glib(),
175 x,
176 y,
177 ))
178 }
179 }
180
181 fn set_extents(&self, x: i32, y: i32, width: i32, height: i32, coord_type: CoordType) -> bool {
182 unsafe {
183 from_glib(atk_sys::atk_component_set_extents(
184 self.as_ref().to_glib_none().0,
185 x,
186 y,
187 width,
188 height,
189 coord_type.to_glib(),
190 ))
191 }
192 }
193
194 fn set_position(&self, x: i32, y: i32, coord_type: CoordType) -> bool {
195 unsafe {
196 from_glib(atk_sys::atk_component_set_position(
197 self.as_ref().to_glib_none().0,
198 x,
199 y,
200 coord_type.to_glib(),
201 ))
202 }
203 }
204
205 fn set_size(&self, width: i32, height: i32) -> bool {
206 unsafe {
207 from_glib(atk_sys::atk_component_set_size(
208 self.as_ref().to_glib_none().0,
209 width,
210 height,
211 ))
212 }
213 }
214
215 fn connect_bounds_changed<F: Fn(&Self, &Rectangle) + 'static>(&self, f: F) -> SignalHandlerId {
216 unsafe extern "C" fn bounds_changed_trampoline<P, F: Fn(&P, &Rectangle) + 'static>(
217 this: *mut atk_sys::AtkComponent,
218 arg1: *mut atk_sys::AtkRectangle,
219 f: glib_sys::gpointer,
220 ) where
221 P: IsA<Component>,
222 {
223 let f: &F = &*(f as *const F);
224 f(
225 &Component::from_glib_borrow(this).unsafe_cast(),
226 &from_glib_borrow(arg1),
227 )
228 }
229 unsafe {
230 let f: Box_<F> = Box_::new(f);
231 connect_raw(
232 self.as_ptr() as *mut _,
233 b"bounds-changed\0".as_ptr() as *const _,
234 Some(transmute(bounds_changed_trampoline::<Self, F> as usize)),
235 Box_::into_raw(f),
236 )
237 }
238 }
239}
240
241impl fmt::Display for Component {
242 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
243 write!(f, "Component")
244 }
245}