1use std::mem;
7
8use glib::{translate::*, ParamSpec, Value};
9
10use crate::{
11 ffi, prelude::*, subclass::prelude::*, Buildable, CellArea, CellAreaContext, CellLayout,
12 CellRenderer, CellRendererState, DirectionType, SizeRequestMode, Snapshot, TreeIter, TreeModel,
13 Widget,
14};
15
16#[derive(Debug)]
17pub struct CellCallback {
18 callback: ffi::GtkCellCallback,
19 user_data: glib::ffi::gpointer,
20}
21
22impl CellCallback {
23 pub fn call<R: IsA<CellRenderer>>(&self, cell_renderer: &R) -> glib::ControlFlow {
24 unsafe {
25 if let Some(callback) = self.callback {
26 from_glib(callback(
27 cell_renderer.as_ref().to_glib_none().0,
28 self.user_data,
29 ))
30 } else {
31 glib::ControlFlow::Break
32 }
33 }
34 }
35}
36
37#[derive(Debug)]
38pub struct CellCallbackAllocate {
39 callback: ffi::GtkCellAllocCallback,
40 user_data: glib::ffi::gpointer,
41}
42
43impl CellCallbackAllocate {
44 pub fn call<R: IsA<CellRenderer>>(
45 &self,
46 cell_renderer: &R,
47 cell_area: &gdk::Rectangle,
48 cell_background: &gdk::Rectangle,
49 ) -> glib::ControlFlow {
50 unsafe {
51 if let Some(callback) = self.callback {
52 from_glib(callback(
53 cell_renderer.as_ref().to_glib_none().0,
54 cell_area.to_glib_none().0,
55 cell_background.to_glib_none().0,
56 self.user_data,
57 ))
58 } else {
59 glib::ControlFlow::Break
60 }
61 }
62 }
63}
64
65#[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
66#[allow(deprecated)]
67pub trait CellAreaImpl:
68 ObjectImpl + ObjectSubclass<Type: IsA<CellArea> + IsA<Buildable> + IsA<CellLayout>>
69{
70 fn cell_properties() -> &'static [ParamSpec] {
71 &[]
72 }
73
74 fn set_cell_property<R: IsA<CellRenderer>>(
75 &self,
76 _renderer: &R,
77 _id: usize,
78 _value: &Value,
79 _pspec: &ParamSpec,
80 ) {
81 unimplemented!()
82 }
83
84 fn cell_property<R: IsA<CellRenderer>>(
85 &self,
86 _renderer: &R,
87 _id: usize,
88 _pspec: &ParamSpec,
89 ) -> Value {
90 unimplemented!()
91 }
92
93 fn activate<P: IsA<CellAreaContext>, W: IsA<Widget>>(
94 &self,
95 context: &P,
96 widget: &W,
97 area: &gdk::Rectangle,
98 flags: CellRendererState,
99 edit_only: bool,
100 ) -> bool {
101 self.parent_activate(context, widget, area, flags, edit_only)
102 }
103
104 fn add<R: IsA<CellRenderer>>(&self, renderer: &R) {
105 self.parent_add(renderer)
106 }
107
108 fn apply_attributes<M: IsA<TreeModel>>(
109 &self,
110 tree_model: &M,
111 iter: &TreeIter,
112 is_expander: bool,
113 is_expanded: bool,
114 ) {
115 self.parent_apply_attributes(tree_model, iter, is_expander, is_expanded)
116 }
117
118 fn create_context(&self) -> Option<CellAreaContext> {
119 self.parent_create_context()
120 }
121
122 fn copy_context<P: IsA<CellAreaContext>>(&self, context: &P) -> Option<CellAreaContext> {
123 self.parent_copy_context(context)
124 }
125
126 fn event<W: IsA<Widget>, P: IsA<CellAreaContext>>(
127 &self,
128 context: &P,
129 widget: &W,
130 event: &gdk::Event,
131 area: &gdk::Rectangle,
132 flags: CellRendererState,
133 ) -> bool {
134 self.parent_event(context, widget, event, area, flags)
135 }
136
137 fn foreach(&self, callback: &CellCallback) {
138 self.parent_foreach(callback);
139 }
140
141 fn foreach_alloc<P: IsA<CellAreaContext>, W: IsA<Widget>>(
142 &self,
143 context: &P,
144 widget: &W,
145 area: &gdk::Rectangle,
146 bg_area: &gdk::Rectangle,
147 callback: &CellCallbackAllocate,
148 ) {
149 self.parent_foreach_alloc(context, widget, area, bg_area, callback)
150 }
151
152 fn remove<R: IsA<CellRenderer>>(&self, renderer: &R) {
153 self.parent_remove(renderer)
154 }
155
156 fn is_activatable(&self) -> bool {
157 self.parent_is_activatable()
158 }
159
160 fn focus(&self, direction_type: DirectionType) -> bool {
161 self.parent_focus(direction_type)
162 }
163
164 fn request_mode(&self) -> SizeRequestMode {
165 self.parent_request_mode()
166 }
167
168 fn preferred_width<P: IsA<CellAreaContext>, W: IsA<Widget>>(
169 &self,
170 context: &P,
171 widget: &W,
172 ) -> (i32, i32) {
173 self.parent_preferred_width(context, widget)
174 }
175
176 fn preferred_width_for_height<P: IsA<CellAreaContext>, W: IsA<Widget>>(
177 &self,
178 context: &P,
179 widget: &W,
180 height: i32,
181 ) -> (i32, i32) {
182 self.parent_preferred_width_for_height(context, widget, height)
183 }
184
185 fn preferred_height<P: IsA<CellAreaContext>, W: IsA<Widget>>(
186 &self,
187 context: &P,
188 widget: &W,
189 ) -> (i32, i32) {
190 self.parent_preferred_height(context, widget)
191 }
192
193 fn preferred_height_for_width<P: IsA<CellAreaContext>, W: IsA<Widget>>(
194 &self,
195 context: &P,
196 widget: &W,
197 width: i32,
198 ) -> (i32, i32) {
199 self.parent_preferred_height_for_width(context, widget, width)
200 }
201
202 #[allow(clippy::too_many_arguments)]
203 fn snapshot<P: IsA<CellAreaContext>, W: IsA<Widget>>(
204 &self,
205 context: &P,
206 snapshot: &Snapshot,
207 widget: &W,
208 background_area: &gdk::Rectangle,
209 cellarea: &gdk::Rectangle,
210 flags: CellRendererState,
211 paint_focus: bool,
212 ) {
213 self.parent_snapshot(
214 context,
215 snapshot,
216 widget,
217 background_area,
218 cellarea,
219 flags,
220 paint_focus,
221 );
222 }
223}
224
225#[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
226#[allow(deprecated)]
227pub trait CellAreaImplExt: CellAreaImpl {
228 fn parent_activate<P: IsA<CellAreaContext>, W: IsA<Widget>>(
230 &self,
231 context: &P,
232 widget: &W,
233 area: &gdk::Rectangle,
234 flags: CellRendererState,
235 edit_only: bool,
236 ) -> bool {
237 unsafe {
238 let data = Self::type_data();
239 let parent_class = data.as_ref().parent_class() as *mut ffi::GtkCellAreaClass;
240 if let Some(f) = (*parent_class).activate {
241 from_glib(f(
242 self.obj().unsafe_cast_ref::<CellArea>().to_glib_none().0,
243 context.as_ref().to_glib_none().0,
244 widget.as_ref().to_glib_none().0,
245 area.to_glib_none().0,
246 flags.into_glib(),
247 edit_only.into_glib(),
248 ))
249 } else {
250 false
251 }
252 }
253 }
254
255 fn parent_add<R: IsA<CellRenderer>>(&self, renderer: &R) {
256 unsafe {
257 let data = Self::type_data();
258 let parent_class = data.as_ref().parent_class() as *mut ffi::GtkCellAreaClass;
259 if let Some(f) = (*parent_class).add {
260 f(
261 self.obj().unsafe_cast_ref::<CellArea>().to_glib_none().0,
262 renderer.as_ref().to_glib_none().0,
263 )
264 }
265 }
266 }
267
268 fn parent_apply_attributes<M: IsA<TreeModel>>(
269 &self,
270 tree_model: &M,
271 iter: &TreeIter,
272 is_expander: bool,
273 is_expanded: bool,
274 ) {
275 unsafe {
276 let data = Self::type_data();
277 let parent_class = data.as_ref().parent_class() as *mut ffi::GtkCellAreaClass;
278 if let Some(f) = (*parent_class).apply_attributes {
279 f(
280 self.obj().unsafe_cast_ref::<CellArea>().to_glib_none().0,
281 tree_model.as_ref().to_glib_none().0,
282 iter.to_glib_none().0 as *mut _,
283 is_expander.into_glib(),
284 is_expanded.into_glib(),
285 )
286 }
287 }
288 }
289
290 fn parent_create_context(&self) -> Option<CellAreaContext> {
291 unsafe {
292 let data = Self::type_data();
293 let parent_class = data.as_ref().parent_class() as *mut ffi::GtkCellAreaClass;
294 let f = (*parent_class)
295 .create_context
296 .expect("No parent class impl for \"create_context\"");
297
298 let ret = f(self.obj().unsafe_cast_ref::<CellArea>().to_glib_none().0);
299 Some(from_glib_full(ret))
300 }
301 }
302
303 fn parent_copy_context<P: IsA<CellAreaContext>>(&self, context: &P) -> Option<CellAreaContext> {
304 unsafe {
305 let data = Self::type_data();
306 let parent_class = data.as_ref().parent_class() as *mut ffi::GtkCellAreaClass;
307 let f = (*parent_class)
308 .copy_context
309 .expect("No parent class impl for \"copy_context\"");
310
311 let ret = f(
312 self.obj().unsafe_cast_ref::<CellArea>().to_glib_none().0,
313 context.as_ref().to_glib_none().0,
314 );
315 Some(from_glib_full(ret))
316 }
317 }
318
319 fn parent_event<W: IsA<Widget>, P: IsA<CellAreaContext>>(
321 &self,
322 context: &P,
323 widget: &W,
324 event: &gdk::Event,
325 area: &gdk::Rectangle,
326 flags: CellRendererState,
327 ) -> bool {
328 unsafe {
329 let data = Self::type_data();
330 let parent_class = data.as_ref().parent_class() as *mut ffi::GtkCellAreaClass;
331 if let Some(f) = (*parent_class).event {
332 from_glib(f(
333 self.obj().unsafe_cast_ref::<CellArea>().to_glib_none().0,
334 context.as_ref().to_glib_none().0,
335 widget.as_ref().to_glib_none().0,
336 event.to_glib_none().0,
337 area.to_glib_none().0,
338 flags.into_glib(),
339 ))
340 } else {
341 false
342 }
343 }
344 }
345
346 fn parent_foreach(&self, callback: &CellCallback) {
347 unsafe {
348 let data = Self::type_data();
349 let parent_class = data.as_ref().parent_class() as *mut ffi::GtkCellAreaClass;
350 if let Some(f) = (*parent_class).foreach {
351 f(
352 self.obj().unsafe_cast_ref::<CellArea>().to_glib_none().0,
353 callback.callback,
354 callback.user_data,
355 )
356 }
357 }
358 }
359
360 fn parent_foreach_alloc<P: IsA<CellAreaContext>, W: IsA<Widget>>(
361 &self,
362 context: &P,
363 widget: &W,
364 area: &gdk::Rectangle,
365 bg_area: &gdk::Rectangle,
366 callback: &CellCallbackAllocate,
367 ) {
368 unsafe {
369 let data = Self::type_data();
370 let parent_class = data.as_ref().parent_class() as *mut ffi::GtkCellAreaClass;
371 if let Some(f) = (*parent_class).foreach_alloc {
372 f(
373 self.obj().unsafe_cast_ref::<CellArea>().to_glib_none().0,
374 context.as_ref().to_glib_none().0,
375 widget.as_ref().to_glib_none().0,
376 area.to_glib_none().0,
377 bg_area.to_glib_none().0,
378 callback.callback,
379 callback.user_data,
380 )
381 }
382 }
383 }
384
385 fn parent_remove<R: IsA<CellRenderer>>(&self, renderer: &R) {
386 unsafe {
387 let data = Self::type_data();
388 let parent_class = data.as_ref().parent_class() as *mut ffi::GtkCellAreaClass;
389 if let Some(f) = (*parent_class).remove {
390 f(
391 self.obj().unsafe_cast_ref::<CellArea>().to_glib_none().0,
392 renderer.as_ref().to_glib_none().0,
393 )
394 }
395 }
396 }
397
398 fn parent_is_activatable(&self) -> bool {
400 unsafe {
401 let data = Self::type_data();
402 let parent_class = data.as_ref().parent_class() as *mut ffi::GtkCellAreaClass;
403 if let Some(f) = (*parent_class).is_activatable {
404 from_glib(f(self.obj().unsafe_cast_ref::<CellArea>().to_glib_none().0))
405 } else {
406 false
407 }
408 }
409 }
410
411 fn parent_focus(&self, direction_type: DirectionType) -> bool {
413 unsafe {
414 let data = Self::type_data();
415 let parent_class = data.as_ref().parent_class() as *mut ffi::GtkCellAreaClass;
416 if let Some(f) = (*parent_class).focus {
417 from_glib(f(
418 self.obj().unsafe_cast_ref::<CellArea>().to_glib_none().0,
419 direction_type.into_glib(),
420 ))
421 } else {
422 false
423 }
424 }
425 }
426
427 fn parent_request_mode(&self) -> SizeRequestMode {
428 unsafe {
429 let data = Self::type_data();
430 let parent_class = data.as_ref().parent_class() as *mut ffi::GtkCellAreaClass;
431 let f = (*parent_class)
432 .get_request_mode
433 .expect("No parent class impl for \"get_request_mode\"");
434 from_glib(f(self.obj().unsafe_cast_ref::<CellArea>().to_glib_none().0))
435 }
436 }
437
438 fn parent_preferred_width<P: IsA<CellAreaContext>, W: IsA<Widget>>(
439 &self,
440 cell_area_context: &P,
441 widget: &W,
442 ) -> (i32, i32) {
443 unsafe {
444 let data = Self::type_data();
445 let parent_class = data.as_ref().parent_class() as *mut ffi::GtkCellAreaClass;
446 let f = (*parent_class).get_preferred_width.unwrap();
447
448 let mut minimum_size = mem::MaybeUninit::uninit();
449 let mut natural_size = mem::MaybeUninit::uninit();
450 f(
451 self.obj().unsafe_cast_ref::<CellArea>().to_glib_none().0,
452 cell_area_context.as_ref().to_glib_none().0,
453 widget.as_ref().to_glib_none().0,
454 minimum_size.as_mut_ptr(),
455 natural_size.as_mut_ptr(),
456 );
457 (minimum_size.assume_init(), natural_size.assume_init())
458 }
459 }
460
461 fn parent_preferred_height<P: IsA<CellAreaContext>, W: IsA<Widget>>(
462 &self,
463 cell_area_context: &P,
464 widget: &W,
465 ) -> (i32, i32) {
466 unsafe {
467 let data = Self::type_data();
468 let parent_class = data.as_ref().parent_class() as *mut ffi::GtkCellAreaClass;
469 let f = (*parent_class).get_preferred_height.unwrap();
470
471 let mut minimum_size = mem::MaybeUninit::uninit();
472 let mut natural_size = mem::MaybeUninit::uninit();
473 f(
474 self.obj().unsafe_cast_ref::<CellArea>().to_glib_none().0,
475 cell_area_context.as_ref().to_glib_none().0,
476 widget.as_ref().to_glib_none().0,
477 minimum_size.as_mut_ptr(),
478 natural_size.as_mut_ptr(),
479 );
480 (minimum_size.assume_init(), natural_size.assume_init())
481 }
482 }
483
484 fn parent_preferred_width_for_height<P: IsA<CellAreaContext>, W: IsA<Widget>>(
485 &self,
486 cell_area_context: &P,
487 widget: &W,
488 height: i32,
489 ) -> (i32, i32) {
490 unsafe {
491 let data = Self::type_data();
492 let parent_class = data.as_ref().parent_class() as *mut ffi::GtkCellAreaClass;
493 let f = (*parent_class).get_preferred_width_for_height.unwrap();
494
495 let mut minimum_size = mem::MaybeUninit::uninit();
496 let mut natural_size = mem::MaybeUninit::uninit();
497 f(
498 self.obj().unsafe_cast_ref::<CellArea>().to_glib_none().0,
499 cell_area_context.as_ref().to_glib_none().0,
500 widget.as_ref().to_glib_none().0,
501 height,
502 minimum_size.as_mut_ptr(),
503 natural_size.as_mut_ptr(),
504 );
505 (minimum_size.assume_init(), natural_size.assume_init())
506 }
507 }
508
509 fn parent_preferred_height_for_width<P: IsA<CellAreaContext>, W: IsA<Widget>>(
510 &self,
511 cell_area_context: &P,
512 widget: &W,
513 width: i32,
514 ) -> (i32, i32) {
515 unsafe {
516 let data = Self::type_data();
517 let parent_class = data.as_ref().parent_class() as *mut ffi::GtkCellAreaClass;
518 let f = (*parent_class).get_preferred_height_for_width.unwrap();
519 let mut minimum_size = mem::MaybeUninit::uninit();
520 let mut natural_size = mem::MaybeUninit::uninit();
521 f(
522 self.obj().unsafe_cast_ref::<CellArea>().to_glib_none().0,
523 cell_area_context.as_ref().to_glib_none().0,
524 widget.as_ref().to_glib_none().0,
525 width,
526 minimum_size.as_mut_ptr(),
527 natural_size.as_mut_ptr(),
528 );
529 (minimum_size.assume_init(), natural_size.assume_init())
530 }
531 }
532
533 #[allow(clippy::too_many_arguments)]
534 fn parent_snapshot<P: IsA<CellAreaContext>, W: IsA<Widget>>(
535 &self,
536 context: &P,
537 snapshot: &Snapshot,
538 widget: &W,
539 background_area: &gdk::Rectangle,
540 cellarea: &gdk::Rectangle,
541 flags: CellRendererState,
542 paint_focus: bool,
543 ) {
544 unsafe {
545 let data = Self::type_data();
546 let parent_class = data.as_ref().parent_class() as *mut ffi::GtkCellAreaClass;
547 if let Some(f) = (*parent_class).snapshot {
548 f(
549 self.obj().unsafe_cast_ref::<CellArea>().to_glib_none().0,
550 context.as_ref().to_glib_none().0,
551 widget.as_ref().to_glib_none().0,
552 snapshot.to_glib_none().0,
553 background_area.to_glib_none().0,
554 cellarea.to_glib_none().0,
555 flags.into_glib(),
556 paint_focus.into_glib(),
557 )
558 }
559 }
560 }
561}
562
563impl<T: CellAreaImpl> CellAreaImplExt for T {}
564
565unsafe impl<T: CellAreaImpl> IsSubclassable<T> for CellArea {
566 fn class_init(class: &mut glib::Class<Self>) {
567 Self::parent_class_init::<T>(class);
568 let klass = class.as_mut();
569
570 assert_initialized_main_thread!();
571
572 let pspecs = <T as CellAreaImpl>::cell_properties();
573 if !pspecs.is_empty() {
574 unsafe {
575 for (prop_id, pspec) in pspecs.iter().enumerate() {
576 ffi::gtk_cell_area_class_install_cell_property(
577 klass,
578 prop_id as u32,
579 pspec.to_glib_none().0,
580 );
581 }
582 }
583 }
584 klass.activate = Some(cell_area_activate::<T>);
585 klass.add = Some(cell_area_add::<T>);
586 klass.apply_attributes = Some(cell_area_apply_attributes::<T>);
587 klass.create_context = Some(cell_area_create_context::<T>);
588 klass.copy_context = Some(cell_area_copy_context::<T>);
589 klass.event = Some(cell_area_event::<T>);
590 klass.foreach = Some(cell_area_foreach::<T>);
591 klass.foreach_alloc = Some(cell_area_foreach_alloc::<T>);
592 klass.remove = Some(cell_area_remove::<T>);
593 klass.is_activatable = Some(cell_area_is_activatable::<T>);
594 klass.focus = Some(cell_area_focus::<T>);
595 klass.get_request_mode = Some(cell_area_get_request_mode::<T>);
596 klass.get_preferred_width = Some(cell_area_get_preferred_width::<T>);
597 klass.get_preferred_width_for_height = Some(cell_area_get_preferred_width_for_height::<T>);
598 klass.get_preferred_height = Some(cell_area_get_preferred_height::<T>);
599 klass.get_preferred_height_for_width = Some(cell_area_get_preferred_height_for_width::<T>);
600 klass.snapshot = Some(cell_area_snapshot::<T>);
601 klass.set_cell_property = Some(cell_area_set_cell_property::<T>);
602 klass.get_cell_property = Some(cell_area_get_cell_property::<T>);
603 }
604}
605
606unsafe extern "C" fn cell_area_set_cell_property<T: CellAreaImpl>(
607 ptr: *mut ffi::GtkCellArea,
608 rendererptr: *mut ffi::GtkCellRenderer,
609 id: u32,
610 valueptr: *mut glib::gobject_ffi::GValue,
611 pspecptr: *mut glib::gobject_ffi::GParamSpec,
612) {
613 let instance = &*(ptr as *mut T::Instance);
614 let imp = instance.imp();
615 imp.set_cell_property(
616 &*from_glib_borrow::<_, CellRenderer>(rendererptr),
617 id as usize,
618 &*(valueptr as *mut Value),
619 &from_glib_borrow(pspecptr),
620 );
621}
622
623unsafe extern "C" fn cell_area_get_cell_property<T: CellAreaImpl>(
624 ptr: *mut ffi::GtkCellArea,
625 rendererptr: *mut ffi::GtkCellRenderer,
626 id: u32,
627 valueptr: *mut glib::gobject_ffi::GValue,
628 pspecptr: *mut glib::gobject_ffi::GParamSpec,
629) {
630 let instance = &*(ptr as *mut T::Instance);
631 let imp = instance.imp();
632
633 let value = imp.cell_property(
634 &*from_glib_borrow::<_, CellRenderer>(rendererptr),
635 id as usize,
636 &from_glib_borrow(pspecptr),
637 );
638
639 glib::gobject_ffi::g_value_unset(valueptr);
641 let value = mem::ManuallyDrop::new(value);
642 std::ptr::write(valueptr, std::ptr::read(value.to_glib_none().0));
643}
644
645unsafe extern "C" fn cell_area_add<T: CellAreaImpl>(
646 ptr: *mut ffi::GtkCellArea,
647 rendererptr: *mut ffi::GtkCellRenderer,
648) {
649 let instance = &*(ptr as *mut T::Instance);
650 let imp = instance.imp();
651 let renderer: Borrowed<CellRenderer> = from_glib_borrow(rendererptr);
652
653 imp.add(&*renderer)
654}
655
656unsafe extern "C" fn cell_area_apply_attributes<T: CellAreaImpl>(
657 ptr: *mut ffi::GtkCellArea,
658 modelptr: *mut ffi::GtkTreeModel,
659 iterptr: *mut ffi::GtkTreeIter,
660 is_expander: glib::ffi::gboolean,
661 is_expanded: glib::ffi::gboolean,
662) {
663 let instance = &*(ptr as *mut T::Instance);
664 let imp = instance.imp();
665 let model: Borrowed<TreeModel> = from_glib_borrow(modelptr);
666 let iter: Borrowed<TreeIter> = from_glib_borrow(iterptr);
667
668 imp.apply_attributes(
669 &*model,
670 &iter,
671 from_glib(is_expander),
672 from_glib(is_expanded),
673 )
674}
675
676unsafe extern "C" fn cell_area_remove<T: CellAreaImpl>(
677 ptr: *mut ffi::GtkCellArea,
678 rendererptr: *mut ffi::GtkCellRenderer,
679) {
680 let instance = &*(ptr as *mut T::Instance);
681 let imp = instance.imp();
682 let renderer: Borrowed<CellRenderer> = from_glib_borrow(rendererptr);
683
684 imp.remove(&*renderer)
685}
686
687unsafe extern "C" fn cell_area_is_activatable<T: CellAreaImpl>(
688 ptr: *mut ffi::GtkCellArea,
689) -> glib::ffi::gboolean {
690 let instance = &*(ptr as *mut T::Instance);
691 let imp = instance.imp();
692
693 imp.is_activatable().into_glib()
694}
695
696unsafe extern "C" fn cell_area_focus<T: CellAreaImpl>(
697 ptr: *mut ffi::GtkCellArea,
698 directionptr: ffi::GtkDirectionType,
699) -> glib::ffi::gboolean {
700 let instance = &*(ptr as *mut T::Instance);
701 let imp = instance.imp();
702
703 imp.focus(from_glib(directionptr)).into_glib()
704}
705
706unsafe extern "C" fn cell_area_get_request_mode<T: CellAreaImpl>(
707 ptr: *mut ffi::GtkCellArea,
708) -> ffi::GtkSizeRequestMode {
709 let instance = &*(ptr as *mut T::Instance);
710 let imp = instance.imp();
711
712 imp.request_mode().into_glib()
713}
714
715unsafe extern "C" fn cell_area_get_preferred_height<T: CellAreaImpl>(
716 ptr: *mut ffi::GtkCellArea,
717 contextptr: *mut ffi::GtkCellAreaContext,
718 wdgtptr: *mut ffi::GtkWidget,
719 minptr: *mut libc::c_int,
720 natptr: *mut libc::c_int,
721) {
722 let instance = &*(ptr as *mut T::Instance);
723 let imp = instance.imp();
724 let context: Borrowed<CellAreaContext> = from_glib_borrow(contextptr);
725 let widget: Borrowed<Widget> = from_glib_borrow(wdgtptr);
726
727 let (min_size, nat_size) = imp.preferred_height(&*context, &*widget);
728 if !minptr.is_null() {
729 *minptr = min_size;
730 }
731 if !natptr.is_null() {
732 *natptr = nat_size;
733 }
734}
735
736unsafe extern "C" fn cell_area_get_preferred_width<T: CellAreaImpl>(
737 ptr: *mut ffi::GtkCellArea,
738 contextptr: *mut ffi::GtkCellAreaContext,
739 wdgtptr: *mut ffi::GtkWidget,
740 minptr: *mut libc::c_int,
741 natptr: *mut libc::c_int,
742) {
743 let instance = &*(ptr as *mut T::Instance);
744 let imp = instance.imp();
745 let context: Borrowed<CellAreaContext> = from_glib_borrow(contextptr);
746 let widget: Borrowed<Widget> = from_glib_borrow(wdgtptr);
747
748 let (min_size, nat_size) = imp.preferred_width(&*context, &*widget);
749 if !minptr.is_null() {
750 *minptr = min_size;
751 }
752 if !natptr.is_null() {
753 *natptr = nat_size;
754 }
755}
756
757unsafe extern "C" fn cell_area_get_preferred_width_for_height<T: CellAreaImpl>(
758 ptr: *mut ffi::GtkCellArea,
759 contextptr: *mut ffi::GtkCellAreaContext,
760 wdgtptr: *mut ffi::GtkWidget,
761 height: i32,
762 min_width_ptr: *mut libc::c_int,
763 nat_width_ptr: *mut libc::c_int,
764) {
765 let instance = &*(ptr as *mut T::Instance);
766 let imp = instance.imp();
767 let context: Borrowed<CellAreaContext> = from_glib_borrow(contextptr);
768 let widget: Borrowed<Widget> = from_glib_borrow(wdgtptr);
769
770 let (min_width, nat_width) = imp.preferred_width_for_height(&*context, &*widget, height);
771 if !min_width_ptr.is_null() {
772 *min_width_ptr = min_width;
773 }
774 if !nat_width_ptr.is_null() {
775 *nat_width_ptr = nat_width;
776 }
777}
778
779unsafe extern "C" fn cell_area_get_preferred_height_for_width<T: CellAreaImpl>(
780 ptr: *mut ffi::GtkCellArea,
781 contextptr: *mut ffi::GtkCellAreaContext,
782 wdgtptr: *mut ffi::GtkWidget,
783 width: i32,
784 min_height_ptr: *mut libc::c_int,
785 nat_height_ptr: *mut libc::c_int,
786) {
787 let instance = &*(ptr as *mut T::Instance);
788 let imp = instance.imp();
789 let context: Borrowed<CellAreaContext> = from_glib_borrow(contextptr);
790 let widget: Borrowed<Widget> = from_glib_borrow(wdgtptr);
791
792 let (min_height, nat_height) = imp.preferred_height_for_width(&*context, &*widget, width);
793 if !min_height_ptr.is_null() {
794 *min_height_ptr = min_height;
795 }
796 if !nat_height_ptr.is_null() {
797 *nat_height_ptr = nat_height;
798 }
799}
800
801unsafe extern "C" fn cell_area_activate<T: CellAreaImpl>(
802 ptr: *mut ffi::GtkCellArea,
803 contextptr: *mut ffi::GtkCellAreaContext,
804 wdgtptr: *mut ffi::GtkWidget,
805 cellptr: *const gdk::ffi::GdkRectangle,
806 flags: ffi::GtkCellRendererState,
807 edit_only: glib::ffi::gboolean,
808) -> glib::ffi::gboolean {
809 let instance = &*(ptr as *mut T::Instance);
810 let imp = instance.imp();
811 let context: Borrowed<CellAreaContext> = from_glib_borrow(contextptr);
812 let widget: Borrowed<Widget> = from_glib_borrow(wdgtptr);
813
814 imp.activate(
815 &*context,
816 &*widget,
817 &from_glib_borrow(cellptr),
818 from_glib(flags),
819 from_glib(edit_only),
820 )
821 .into_glib()
822}
823
824unsafe extern "C" fn cell_area_snapshot<T: CellAreaImpl>(
825 ptr: *mut ffi::GtkCellArea,
826 contextptr: *mut ffi::GtkCellAreaContext,
827 wdgtptr: *mut ffi::GtkWidget,
828 snapshotptr: *mut ffi::GtkSnapshot,
829 bgptr: *const gdk::ffi::GdkRectangle,
830 cellptr: *const gdk::ffi::GdkRectangle,
831 flags: ffi::GtkCellRendererState,
832 paint_focus: glib::ffi::gboolean,
833) {
834 let instance = &*(ptr as *mut T::Instance);
835 let imp = instance.imp();
836 let context: Borrowed<CellAreaContext> = from_glib_borrow(contextptr);
837 let widget: Borrowed<Widget> = from_glib_borrow(wdgtptr);
838 let snapshot: Borrowed<Snapshot> = from_glib_borrow(snapshotptr);
839
840 imp.snapshot(
841 &*context,
842 &snapshot,
843 &*widget,
844 &from_glib_borrow(bgptr),
845 &from_glib_borrow(cellptr),
846 from_glib(flags),
847 from_glib(paint_focus),
848 )
849}
850
851unsafe extern "C" fn cell_area_create_context<T: CellAreaImpl>(
852 ptr: *mut ffi::GtkCellArea,
853) -> *mut ffi::GtkCellAreaContext {
854 let instance = &*(ptr as *mut T::Instance);
855 let imp = instance.imp();
856
857 imp.create_context().into_glib_ptr()
858}
859
860unsafe extern "C" fn cell_area_copy_context<T: CellAreaImpl>(
861 ptr: *mut ffi::GtkCellArea,
862 contextptr: *mut ffi::GtkCellAreaContext,
863) -> *mut ffi::GtkCellAreaContext {
864 let instance = &*(ptr as *mut T::Instance);
865 let imp = instance.imp();
866 let context: Borrowed<CellAreaContext> = from_glib_borrow(contextptr);
867
868 imp.copy_context(&*context).into_glib_ptr()
869}
870
871unsafe extern "C" fn cell_area_event<T: CellAreaImpl>(
872 ptr: *mut ffi::GtkCellArea,
873 contextptr: *mut ffi::GtkCellAreaContext,
874 widgetptr: *mut ffi::GtkWidget,
875 eventptr: *mut gdk::ffi::GdkEvent,
876 rectangleptr: *const gdk::ffi::GdkRectangle,
877 flags: ffi::GtkCellRendererState,
878) -> glib::ffi::gboolean {
879 let instance = &*(ptr as *mut T::Instance);
880 let imp = instance.imp();
881 let context: Borrowed<CellAreaContext> = from_glib_borrow(contextptr);
882 let widget: Borrowed<Widget> = from_glib_borrow(widgetptr);
883 let event: Borrowed<gdk::Event> = from_glib_borrow(eventptr);
884 let rectangle: Borrowed<gdk::Rectangle> = from_glib_borrow(rectangleptr);
885
886 imp.event(&*context, &*widget, &event, &rectangle, from_glib(flags))
887 .into_glib()
888}
889
890unsafe extern "C" fn cell_area_foreach<T: CellAreaImpl>(
891 ptr: *mut ffi::GtkCellArea,
892 callback: ffi::GtkCellCallback,
893 user_data: glib::ffi::gpointer,
894) {
895 let instance = &*(ptr as *mut T::Instance);
896 let imp = instance.imp();
897
898 let callback = CellCallback {
899 callback,
900 user_data,
901 };
902
903 imp.foreach(&callback)
904}
905
906unsafe extern "C" fn cell_area_foreach_alloc<T: CellAreaImpl>(
907 ptr: *mut ffi::GtkCellArea,
908 contextptr: *mut ffi::GtkCellAreaContext,
909 widgetptr: *mut ffi::GtkWidget,
910 areaptr: *const gdk::ffi::GdkRectangle,
911 rectangleptr: *const gdk::ffi::GdkRectangle,
912 callback: ffi::GtkCellAllocCallback,
913 user_data: glib::ffi::gpointer,
914) {
915 let instance = &*(ptr as *mut T::Instance);
916 let imp = instance.imp();
917 let context: Borrowed<CellAreaContext> = from_glib_borrow(contextptr);
918 let widget: Borrowed<Widget> = from_glib_borrow(widgetptr);
919 let rectangle: Borrowed<gdk::Rectangle> = from_glib_borrow(rectangleptr);
920 let area: Borrowed<gdk::Rectangle> = from_glib_borrow(areaptr);
921
922 let callback = CellCallbackAllocate {
923 callback,
924 user_data,
925 };
926
927 imp.foreach_alloc(&*context, &*widget, &area, &rectangle, &callback)
928}
929
930#[allow(clippy::missing_safety_doc)]
931pub unsafe trait CellAreaClassExt: ClassStruct {
932 #[doc(alias = "gtk_cell_area_class_find_cell_property")]
933 fn find_cell_property(&self, property_name: &str) -> Option<ParamSpec> {
934 unsafe {
935 let cell_area_class = self as *const _ as *mut ffi::GtkCellAreaClass;
936 from_glib_none(ffi::gtk_cell_area_class_find_cell_property(
937 cell_area_class,
938 property_name.to_glib_none().0,
939 ))
940 }
941 }
942
943 #[doc(alias = "gtk_cell_area_class_list_cell_properties")]
944 fn list_cell_properties(&self) -> Vec<ParamSpec> {
945 unsafe {
946 let cell_area_class = self as *const _ as *mut ffi::GtkCellAreaClass;
947 let mut n_properties = std::mem::MaybeUninit::uninit();
948 let props = ffi::gtk_cell_area_class_list_cell_properties(
949 cell_area_class,
950 n_properties.as_mut_ptr(),
951 );
952 FromGlibContainer::from_glib_none_num(props, n_properties.assume_init() as usize)
953 }
954 }
955}
956
957unsafe impl<T: ClassStruct> CellAreaClassExt for T {}