1use glib::object::Cast;
6use glib::object::IsA;
7use glib::signal::connect_raw;
8use glib::signal::SignalHandlerId;
9use glib::translate::*;
10use glib::StaticType;
11use glib::Value;
12use glib_sys;
13use gobject_sys;
14use gtk_sys;
15use std::boxed::Box as Box_;
16use std::fmt;
17use std::mem;
18use std::mem::transmute;
19use CellArea;
20
21glib_wrapper! {
22 pub struct CellAreaContext(Object<gtk_sys::GtkCellAreaContext, gtk_sys::GtkCellAreaContextClass, CellAreaContextClass>);
23
24 match fn {
25 get_type => || gtk_sys::gtk_cell_area_context_get_type(),
26 }
27}
28
29pub const NONE_CELL_AREA_CONTEXT: Option<&CellAreaContext> = None;
30
31pub trait CellAreaContextExt: 'static {
32 fn allocate(&self, width: i32, height: i32);
33
34 fn get_allocation(&self) -> (i32, i32);
35
36 fn get_area(&self) -> Option<CellArea>;
37
38 fn get_preferred_height(&self) -> (i32, i32);
39
40 fn get_preferred_height_for_width(&self, width: i32) -> (i32, i32);
41
42 fn get_preferred_width(&self) -> (i32, i32);
43
44 fn get_preferred_width_for_height(&self, height: i32) -> (i32, i32);
45
46 fn push_preferred_height(&self, minimum_height: i32, natural_height: i32);
47
48 fn push_preferred_width(&self, minimum_width: i32, natural_width: i32);
49
50 fn reset(&self);
51
52 fn get_property_minimum_height(&self) -> i32;
53
54 fn get_property_minimum_width(&self) -> i32;
55
56 fn get_property_natural_height(&self) -> i32;
57
58 fn get_property_natural_width(&self) -> i32;
59
60 fn connect_property_minimum_height_notify<F: Fn(&Self) + 'static>(
61 &self,
62 f: F,
63 ) -> SignalHandlerId;
64
65 fn connect_property_minimum_width_notify<F: Fn(&Self) + 'static>(
66 &self,
67 f: F,
68 ) -> SignalHandlerId;
69
70 fn connect_property_natural_height_notify<F: Fn(&Self) + 'static>(
71 &self,
72 f: F,
73 ) -> SignalHandlerId;
74
75 fn connect_property_natural_width_notify<F: Fn(&Self) + 'static>(
76 &self,
77 f: F,
78 ) -> SignalHandlerId;
79}
80
81impl<O: IsA<CellAreaContext>> CellAreaContextExt for O {
82 fn allocate(&self, width: i32, height: i32) {
83 unsafe {
84 gtk_sys::gtk_cell_area_context_allocate(self.as_ref().to_glib_none().0, width, height);
85 }
86 }
87
88 fn get_allocation(&self) -> (i32, i32) {
89 unsafe {
90 let mut width = mem::uninitialized();
91 let mut height = mem::uninitialized();
92 gtk_sys::gtk_cell_area_context_get_allocation(
93 self.as_ref().to_glib_none().0,
94 &mut width,
95 &mut height,
96 );
97 (width, height)
98 }
99 }
100
101 fn get_area(&self) -> Option<CellArea> {
102 unsafe {
103 from_glib_none(gtk_sys::gtk_cell_area_context_get_area(
104 self.as_ref().to_glib_none().0,
105 ))
106 }
107 }
108
109 fn get_preferred_height(&self) -> (i32, i32) {
110 unsafe {
111 let mut minimum_height = mem::uninitialized();
112 let mut natural_height = mem::uninitialized();
113 gtk_sys::gtk_cell_area_context_get_preferred_height(
114 self.as_ref().to_glib_none().0,
115 &mut minimum_height,
116 &mut natural_height,
117 );
118 (minimum_height, natural_height)
119 }
120 }
121
122 fn get_preferred_height_for_width(&self, width: i32) -> (i32, i32) {
123 unsafe {
124 let mut minimum_height = mem::uninitialized();
125 let mut natural_height = mem::uninitialized();
126 gtk_sys::gtk_cell_area_context_get_preferred_height_for_width(
127 self.as_ref().to_glib_none().0,
128 width,
129 &mut minimum_height,
130 &mut natural_height,
131 );
132 (minimum_height, natural_height)
133 }
134 }
135
136 fn get_preferred_width(&self) -> (i32, i32) {
137 unsafe {
138 let mut minimum_width = mem::uninitialized();
139 let mut natural_width = mem::uninitialized();
140 gtk_sys::gtk_cell_area_context_get_preferred_width(
141 self.as_ref().to_glib_none().0,
142 &mut minimum_width,
143 &mut natural_width,
144 );
145 (minimum_width, natural_width)
146 }
147 }
148
149 fn get_preferred_width_for_height(&self, height: i32) -> (i32, i32) {
150 unsafe {
151 let mut minimum_width = mem::uninitialized();
152 let mut natural_width = mem::uninitialized();
153 gtk_sys::gtk_cell_area_context_get_preferred_width_for_height(
154 self.as_ref().to_glib_none().0,
155 height,
156 &mut minimum_width,
157 &mut natural_width,
158 );
159 (minimum_width, natural_width)
160 }
161 }
162
163 fn push_preferred_height(&self, minimum_height: i32, natural_height: i32) {
164 unsafe {
165 gtk_sys::gtk_cell_area_context_push_preferred_height(
166 self.as_ref().to_glib_none().0,
167 minimum_height,
168 natural_height,
169 );
170 }
171 }
172
173 fn push_preferred_width(&self, minimum_width: i32, natural_width: i32) {
174 unsafe {
175 gtk_sys::gtk_cell_area_context_push_preferred_width(
176 self.as_ref().to_glib_none().0,
177 minimum_width,
178 natural_width,
179 );
180 }
181 }
182
183 fn reset(&self) {
184 unsafe {
185 gtk_sys::gtk_cell_area_context_reset(self.as_ref().to_glib_none().0);
186 }
187 }
188
189 fn get_property_minimum_height(&self) -> i32 {
190 unsafe {
191 let mut value = Value::from_type(<i32 as StaticType>::static_type());
192 gobject_sys::g_object_get_property(
193 self.to_glib_none().0 as *mut gobject_sys::GObject,
194 b"minimum-height\0".as_ptr() as *const _,
195 value.to_glib_none_mut().0,
196 );
197 value.get().unwrap()
198 }
199 }
200
201 fn get_property_minimum_width(&self) -> i32 {
202 unsafe {
203 let mut value = Value::from_type(<i32 as StaticType>::static_type());
204 gobject_sys::g_object_get_property(
205 self.to_glib_none().0 as *mut gobject_sys::GObject,
206 b"minimum-width\0".as_ptr() as *const _,
207 value.to_glib_none_mut().0,
208 );
209 value.get().unwrap()
210 }
211 }
212
213 fn get_property_natural_height(&self) -> i32 {
214 unsafe {
215 let mut value = Value::from_type(<i32 as StaticType>::static_type());
216 gobject_sys::g_object_get_property(
217 self.to_glib_none().0 as *mut gobject_sys::GObject,
218 b"natural-height\0".as_ptr() as *const _,
219 value.to_glib_none_mut().0,
220 );
221 value.get().unwrap()
222 }
223 }
224
225 fn get_property_natural_width(&self) -> i32 {
226 unsafe {
227 let mut value = Value::from_type(<i32 as StaticType>::static_type());
228 gobject_sys::g_object_get_property(
229 self.to_glib_none().0 as *mut gobject_sys::GObject,
230 b"natural-width\0".as_ptr() as *const _,
231 value.to_glib_none_mut().0,
232 );
233 value.get().unwrap()
234 }
235 }
236
237 fn connect_property_minimum_height_notify<F: Fn(&Self) + 'static>(
238 &self,
239 f: F,
240 ) -> SignalHandlerId {
241 unsafe extern "C" fn notify_minimum_height_trampoline<P, F: Fn(&P) + 'static>(
242 this: *mut gtk_sys::GtkCellAreaContext,
243 _param_spec: glib_sys::gpointer,
244 f: glib_sys::gpointer,
245 ) where
246 P: IsA<CellAreaContext>,
247 {
248 let f: &F = &*(f as *const F);
249 f(&CellAreaContext::from_glib_borrow(this).unsafe_cast())
250 }
251 unsafe {
252 let f: Box_<F> = Box_::new(f);
253 connect_raw(
254 self.as_ptr() as *mut _,
255 b"notify::minimum-height\0".as_ptr() as *const _,
256 Some(transmute(
257 notify_minimum_height_trampoline::<Self, F> as usize,
258 )),
259 Box_::into_raw(f),
260 )
261 }
262 }
263
264 fn connect_property_minimum_width_notify<F: Fn(&Self) + 'static>(
265 &self,
266 f: F,
267 ) -> SignalHandlerId {
268 unsafe extern "C" fn notify_minimum_width_trampoline<P, F: Fn(&P) + 'static>(
269 this: *mut gtk_sys::GtkCellAreaContext,
270 _param_spec: glib_sys::gpointer,
271 f: glib_sys::gpointer,
272 ) where
273 P: IsA<CellAreaContext>,
274 {
275 let f: &F = &*(f as *const F);
276 f(&CellAreaContext::from_glib_borrow(this).unsafe_cast())
277 }
278 unsafe {
279 let f: Box_<F> = Box_::new(f);
280 connect_raw(
281 self.as_ptr() as *mut _,
282 b"notify::minimum-width\0".as_ptr() as *const _,
283 Some(transmute(
284 notify_minimum_width_trampoline::<Self, F> as usize,
285 )),
286 Box_::into_raw(f),
287 )
288 }
289 }
290
291 fn connect_property_natural_height_notify<F: Fn(&Self) + 'static>(
292 &self,
293 f: F,
294 ) -> SignalHandlerId {
295 unsafe extern "C" fn notify_natural_height_trampoline<P, F: Fn(&P) + 'static>(
296 this: *mut gtk_sys::GtkCellAreaContext,
297 _param_spec: glib_sys::gpointer,
298 f: glib_sys::gpointer,
299 ) where
300 P: IsA<CellAreaContext>,
301 {
302 let f: &F = &*(f as *const F);
303 f(&CellAreaContext::from_glib_borrow(this).unsafe_cast())
304 }
305 unsafe {
306 let f: Box_<F> = Box_::new(f);
307 connect_raw(
308 self.as_ptr() as *mut _,
309 b"notify::natural-height\0".as_ptr() as *const _,
310 Some(transmute(
311 notify_natural_height_trampoline::<Self, F> as usize,
312 )),
313 Box_::into_raw(f),
314 )
315 }
316 }
317
318 fn connect_property_natural_width_notify<F: Fn(&Self) + 'static>(
319 &self,
320 f: F,
321 ) -> SignalHandlerId {
322 unsafe extern "C" fn notify_natural_width_trampoline<P, F: Fn(&P) + 'static>(
323 this: *mut gtk_sys::GtkCellAreaContext,
324 _param_spec: glib_sys::gpointer,
325 f: glib_sys::gpointer,
326 ) where
327 P: IsA<CellAreaContext>,
328 {
329 let f: &F = &*(f as *const F);
330 f(&CellAreaContext::from_glib_borrow(this).unsafe_cast())
331 }
332 unsafe {
333 let f: Box_<F> = Box_::new(f);
334 connect_raw(
335 self.as_ptr() as *mut _,
336 b"notify::natural-width\0".as_ptr() as *const _,
337 Some(transmute(
338 notify_natural_width_trampoline::<Self, F> as usize,
339 )),
340 Box_::into_raw(f),
341 )
342 }
343 }
344}
345
346impl fmt::Display for CellAreaContext {
347 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
348 write!(f, "CellAreaContext")
349 }
350}