gtk4/subclass/
cell_renderer.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
// Take a look at the license at the top of the repository in the LICENSE file.

// rustdoc-stripper-ignore-next
//! Traits intended for subclassing [`CellRenderer`].

use std::mem;

use glib::{translate::*, GString};
use libc::{c_char, c_int};

use crate::{
    ffi, prelude::*, subclass::prelude::*, CellEditable, CellRenderer, CellRendererState,
    SizeRequestMode, Snapshot, Widget,
};

#[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
#[allow(deprecated)]
pub trait CellRendererImpl: ObjectImpl + ObjectSubclass<Type: IsA<CellRenderer>> {
    /// Passes an activate event to the cell renderer for possible processing.
    /// Some cell renderers may use events; for example, [`CellRendererToggle`][crate::CellRendererToggle]
    /// toggles when it gets a mouse click.
    ///
    /// # Deprecated since 4.10
    ///
    /// ## `event`
    /// a [`gdk::Event`][crate::gdk::Event]
    /// ## `widget`
    /// widget that received the event
    /// ## `path`
    /// widget-dependent string representation of the event location;
    ///    e.g. for [`TreeView`][crate::TreeView], a string representation of [`TreePath`][crate::TreePath]
    /// ## `background_area`
    /// background area as passed to gtk_cell_renderer_render()
    /// ## `cell_area`
    /// cell area as passed to gtk_cell_renderer_render()
    /// ## `flags`
    /// render flags
    ///
    /// # Returns
    ///
    /// [`true`] if the event was consumed/handled
    fn activate<P: IsA<Widget>>(
        &self,
        event: Option<&gdk::Event>,
        widget: &P,
        path: &str,
        background_area: &gdk::Rectangle,
        cell_area: &gdk::Rectangle,
        flags: CellRendererState,
    ) -> bool {
        self.parent_activate(event, widget, path, background_area, cell_area, flags)
    }

    /// Signal gets emitted when the user cancels the process of editing a cell.
    fn editing_canceled(&self) {
        self.parent_editing_canceled()
    }

    /// Signal gets emitted when a cell starts to be edited.
    fn editing_started(&self, editable: &CellEditable, path: &str) {
        self.parent_editing_started(editable, path)
    }

    /// Gets the aligned area used by @self inside @cell_area. Used for finding
    /// the appropriate edit and focus rectangle.
    ///
    /// # Deprecated since 4.10
    ///
    /// ## `widget`
    /// the [`Widget`][crate::Widget] this cell will be rendering to
    /// ## `flags`
    /// render flags
    /// ## `cell_area`
    /// cell area which would be passed to gtk_cell_renderer_render()
    ///
    /// # Returns
    ///
    ///
    /// ## `aligned_area`
    /// the return location for the space inside @cell_area
    ///                that would actually be used to render.
    #[doc(alias = "get_aligned_area")]
    fn aligned_area<P: IsA<Widget>>(
        &self,
        widget: &P,
        flags: CellRendererState,
        cell_area: &gdk::Rectangle,
    ) -> gdk::Rectangle {
        self.parent_aligned_area(widget, flags, cell_area)
    }

    /// Retrieves a cell renderers’s minimum and natural height if it were rendered to
    /// @widget with the specified @width.
    ///
    /// # Deprecated since 4.10
    ///
    /// ## `widget`
    /// the [`Widget`][crate::Widget] this cell will be rendering to
    /// ## `width`
    /// the size which is available for allocation
    ///
    /// # Returns
    ///
    ///
    /// ## `minimum_height`
    /// location for storing the minimum size
    ///
    /// ## `natural_height`
    /// location for storing the preferred size
    #[doc(alias = "get_preferred_height_for_width")]
    fn preferred_height_for_width<P: IsA<Widget>>(&self, widget: &P, width: i32) -> (i32, i32) {
        self.parent_preferred_height_for_width(widget, width)
    }

    /// Retrieves a renderer’s natural size when rendered to @widget.
    ///
    /// # Deprecated since 4.10
    ///
    /// ## `widget`
    /// the [`Widget`][crate::Widget] this cell will be rendering to
    ///
    /// # Returns
    ///
    ///
    /// ## `minimum_size`
    /// location to store the minimum size
    ///
    /// ## `natural_size`
    /// location to store the natural size
    #[doc(alias = "get_preferred_height")]
    fn preferred_height<P: IsA<Widget>>(&self, widget: &P) -> (i32, i32) {
        self.parent_preferred_height(widget)
    }

    /// Retrieves a cell renderers’s minimum and natural width if it were rendered to
    /// @widget with the specified @height.
    ///
    /// # Deprecated since 4.10
    ///
    /// ## `widget`
    /// the [`Widget`][crate::Widget] this cell will be rendering to
    /// ## `height`
    /// the size which is available for allocation
    ///
    /// # Returns
    ///
    ///
    /// ## `minimum_width`
    /// location for storing the minimum size
    ///
    /// ## `natural_width`
    /// location for storing the preferred size
    #[doc(alias = "get_preferred_width_for_height")]
    fn preferred_width_for_height<P: IsA<Widget>>(&self, widget: &P, height: i32) -> (i32, i32) {
        self.parent_preferred_width_for_height(widget, height)
    }

    /// Retrieves a renderer’s natural size when rendered to @widget.
    ///
    /// # Deprecated since 4.10
    ///
    /// ## `widget`
    /// the [`Widget`][crate::Widget] this cell will be rendering to
    ///
    /// # Returns
    ///
    ///
    /// ## `minimum_size`
    /// location to store the minimum size
    ///
    /// ## `natural_size`
    /// location to store the natural size
    #[doc(alias = "get_preferred_width")]
    fn preferred_width<P: IsA<Widget>>(&self, widget: &P) -> (i32, i32) {
        self.parent_preferred_width(widget)
    }

    /// Gets whether the cell renderer prefers a height-for-width layout
    /// or a width-for-height layout.
    ///
    /// # Deprecated since 4.10
    ///
    ///
    /// # Returns
    ///
    /// The [`SizeRequestMode`][crate::SizeRequestMode] preferred by this renderer.
    #[doc(alias = "get_request_mode")]
    fn request_mode(&self) -> SizeRequestMode {
        self.parent_request_mode()
    }

    /// Invokes the virtual render function of the [`CellRenderer`][crate::CellRenderer]. The three
    /// passed-in rectangles are areas in @cr. Most renderers will draw within
    /// @cell_area; the xalign, yalign, xpad, and ypad fields of the [`CellRenderer`][crate::CellRenderer]
    /// should be honored with respect to @cell_area. @background_area includes the
    /// blank space around the cell, and also the area containing the tree expander;
    /// so the @background_area rectangles for all cells tile to cover the entire
    /// @window.
    ///
    /// # Deprecated since 4.10
    ///
    /// ## `snapshot`
    /// a [`Snapshot`][crate::Snapshot] to draw to
    /// ## `widget`
    /// the widget owning @window
    /// ## `background_area`
    /// entire cell area (including tree expanders and maybe
    ///    padding on the sides)
    /// ## `cell_area`
    /// area normally rendered by a cell renderer
    /// ## `flags`
    /// flags that affect rendering
    fn snapshot<P: IsA<Widget>>(
        &self,
        snapshot: &Snapshot,
        widget: &P,
        background_area: &gdk::Rectangle,
        cell_area: &gdk::Rectangle,
        flags: CellRendererState,
    ) {
        self.parent_snapshot(snapshot, widget, background_area, cell_area, flags);
    }

    /// Starts editing the contents of this @self, through a new [`CellEditable`][crate::CellEditable]
    /// widget created by the [`CellRenderer`][crate::CellRenderer]Class.start_editing virtual function.
    ///
    /// # Deprecated since 4.10
    ///
    /// ## `event`
    /// a [`gdk::Event`][crate::gdk::Event]
    /// ## `widget`
    /// widget that received the event
    /// ## `path`
    /// widget-dependent string representation of the event location;
    ///    e.g. for [`TreeView`][crate::TreeView], a string representation of [`TreePath`][crate::TreePath]
    /// ## `background_area`
    /// background area as passed to gtk_cell_renderer_render()
    /// ## `cell_area`
    /// cell area as passed to gtk_cell_renderer_render()
    /// ## `flags`
    /// render flags
    ///
    /// # Returns
    ///
    /// A new [`CellEditable`][crate::CellEditable] for editing this
    ///   @self, or [`None`] if editing is not possible
    fn start_editing<P: IsA<Widget>>(
        &self,
        event: Option<&gdk::Event>,
        widget: &P,
        path: &str,
        background_area: &gdk::Rectangle,
        cell_area: &gdk::Rectangle,
        flags: CellRendererState,
    ) -> Option<CellEditable> {
        self.parent_start_editing(event, widget, path, background_area, cell_area, flags)
    }
}

#[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
#[allow(deprecated)]
pub trait CellRendererImplExt: CellRendererImpl {
    fn parent_request_mode(&self) -> SizeRequestMode {
        unsafe {
            let data = Self::type_data();
            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkCellRendererClass;
            let f = (*parent_class).get_request_mode.unwrap();
            from_glib(f(self
                .obj()
                .unsafe_cast_ref::<CellRenderer>()
                .to_glib_none()
                .0))
        }
    }

    fn parent_preferred_width<P: IsA<Widget>>(&self, widget: &P) -> (i32, i32) {
        unsafe {
            let data = Self::type_data();
            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkCellRendererClass;
            let f = (*parent_class).get_preferred_width.unwrap();

            let mut minimum_size = mem::MaybeUninit::uninit();
            let mut natural_size = mem::MaybeUninit::uninit();
            f(
                self.obj()
                    .unsafe_cast_ref::<CellRenderer>()
                    .to_glib_none()
                    .0,
                widget.as_ref().to_glib_none().0,
                minimum_size.as_mut_ptr(),
                natural_size.as_mut_ptr(),
            );
            (minimum_size.assume_init(), natural_size.assume_init())
        }
    }

    fn parent_preferred_width_for_height<P: IsA<Widget>>(
        &self,
        widget: &P,
        height: i32,
    ) -> (i32, i32) {
        unsafe {
            let data = Self::type_data();
            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkCellRendererClass;
            let f = (*parent_class).get_preferred_width_for_height.unwrap();

            let mut minimum_size = mem::MaybeUninit::uninit();
            let mut natural_size = mem::MaybeUninit::uninit();
            f(
                self.obj()
                    .unsafe_cast_ref::<CellRenderer>()
                    .to_glib_none()
                    .0,
                widget.as_ref().to_glib_none().0,
                height,
                minimum_size.as_mut_ptr(),
                natural_size.as_mut_ptr(),
            );
            (minimum_size.assume_init(), natural_size.assume_init())
        }
    }
    fn parent_preferred_height<P: IsA<Widget>>(&self, widget: &P) -> (i32, i32) {
        unsafe {
            let data = Self::type_data();
            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkCellRendererClass;
            let f = (*parent_class).get_preferred_height.unwrap();
            let mut minimum_size = mem::MaybeUninit::uninit();
            let mut natural_size = mem::MaybeUninit::uninit();
            f(
                self.obj()
                    .unsafe_cast_ref::<CellRenderer>()
                    .to_glib_none()
                    .0,
                widget.as_ref().to_glib_none().0,
                minimum_size.as_mut_ptr(),
                natural_size.as_mut_ptr(),
            );
            (minimum_size.assume_init(), natural_size.assume_init())
        }
    }
    fn parent_preferred_height_for_width<P: IsA<Widget>>(
        &self,
        widget: &P,
        width: i32,
    ) -> (i32, i32) {
        unsafe {
            let data = Self::type_data();
            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkCellRendererClass;
            let f = (*parent_class).get_preferred_height_for_width.unwrap();
            let mut minimum_size = mem::MaybeUninit::uninit();
            let mut natural_size = mem::MaybeUninit::uninit();
            f(
                self.obj()
                    .unsafe_cast_ref::<CellRenderer>()
                    .to_glib_none()
                    .0,
                widget.as_ref().to_glib_none().0,
                width,
                minimum_size.as_mut_ptr(),
                natural_size.as_mut_ptr(),
            );
            (minimum_size.assume_init(), natural_size.assume_init())
        }
    }

    fn parent_aligned_area<P: IsA<Widget>>(
        &self,
        widget: &P,
        flags: CellRendererState,
        cell_area: &gdk::Rectangle,
    ) -> gdk::Rectangle {
        unsafe {
            let data = Self::type_data();
            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkCellRendererClass;
            let mut aligned_area = gdk::Rectangle::uninitialized();
            let f = (*parent_class).get_aligned_area.unwrap();
            f(
                self.obj()
                    .unsafe_cast_ref::<CellRenderer>()
                    .to_glib_none()
                    .0,
                widget.as_ref().to_glib_none().0,
                flags.into_glib(),
                cell_area.to_glib_none().0,
                aligned_area.to_glib_none_mut().0,
            );
            aligned_area
        }
    }

    fn parent_snapshot<P: IsA<Widget>>(
        &self,
        snapshot: &Snapshot,
        widget: &P,
        background_area: &gdk::Rectangle,
        cell_area: &gdk::Rectangle,
        flags: CellRendererState,
    ) {
        unsafe {
            let data = Self::type_data();
            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkCellRendererClass;
            if let Some(f) = (*parent_class).snapshot {
                f(
                    self.obj()
                        .unsafe_cast_ref::<CellRenderer>()
                        .to_glib_none()
                        .0,
                    snapshot.to_glib_none().0,
                    widget.as_ref().to_glib_none().0,
                    background_area.to_glib_none().0,
                    cell_area.to_glib_none().0,
                    flags.into_glib(),
                )
            }
        }
    }

    // Returns true if the event was consumed/handled
    fn parent_activate<P: IsA<Widget>>(
        &self,
        event: Option<&gdk::Event>,
        widget: &P,
        path: &str,
        background_area: &gdk::Rectangle,
        cell_area: &gdk::Rectangle,
        flags: CellRendererState,
    ) -> bool {
        unsafe {
            let data = Self::type_data();
            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkCellRendererClass;
            if let Some(f) = (*parent_class).activate {
                from_glib(f(
                    self.obj()
                        .unsafe_cast_ref::<CellRenderer>()
                        .to_glib_none()
                        .0,
                    mut_override(event.to_glib_none().0),
                    widget.as_ref().to_glib_none().0,
                    path.to_glib_none().0,
                    background_area.to_glib_none().0,
                    cell_area.to_glib_none().0,
                    flags.into_glib(),
                ))
            } else {
                false
            }
        }
    }

    fn parent_start_editing<P: IsA<Widget>>(
        &self,
        event: Option<&gdk::Event>,
        widget: &P,
        path: &str,
        background_area: &gdk::Rectangle,
        cell_area: &gdk::Rectangle,
        flags: CellRendererState,
    ) -> Option<CellEditable> {
        unsafe {
            let data = Self::type_data();
            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkCellRendererClass;
            if let Some(f) = (*parent_class).start_editing {
                from_glib_none(f(
                    self.obj()
                        .unsafe_cast_ref::<CellRenderer>()
                        .to_glib_none()
                        .0,
                    mut_override(event.to_glib_none().0),
                    widget.as_ref().to_glib_none().0,
                    path.to_glib_none().0,
                    background_area.to_glib_none().0,
                    cell_area.to_glib_none().0,
                    flags.into_glib(),
                ))
            } else {
                None
            }
        }
    }

    fn parent_editing_canceled(&self) {
        unsafe {
            let data = Self::type_data();
            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkCellRendererClass;
            if let Some(f) = (*parent_class).editing_canceled {
                f(self
                    .obj()
                    .unsafe_cast_ref::<CellRenderer>()
                    .to_glib_none()
                    .0)
            }
        }
    }

    fn parent_editing_started(&self, editable: &CellEditable, path: &str) {
        unsafe {
            let data = Self::type_data();
            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkCellRendererClass;
            if let Some(f) = (*parent_class).editing_started {
                f(
                    self.obj()
                        .unsafe_cast_ref::<CellRenderer>()
                        .to_glib_none()
                        .0,
                    editable.to_glib_none().0,
                    path.to_glib_none().0,
                )
            }
        }
    }
}

impl<T: CellRendererImpl> CellRendererImplExt for T {}

unsafe impl<T: CellRendererImpl> IsSubclassable<T> for CellRenderer {
    fn class_init(class: &mut ::glib::Class<Self>) {
        Self::parent_class_init::<T>(class);

        assert_initialized_main_thread!();

        let klass = class.as_mut();

        klass.activate = Some(cell_renderer_activate::<T>);
        klass.editing_canceled = Some(cell_renderer_editing_canceled::<T>);
        klass.editing_started = Some(cell_renderer_editing_started::<T>);
        klass.get_aligned_area = Some(cell_renderer_get_aligned_area::<T>);
        klass.get_preferred_height_for_width =
            Some(cell_renderer_get_preferred_height_for_width::<T>);
        klass.get_preferred_height = Some(cell_renderer_get_preferred_height::<T>);
        klass.get_preferred_width_for_height =
            Some(cell_renderer_get_preferred_width_for_height::<T>);
        klass.get_preferred_width = Some(cell_renderer_get_preferred_width::<T>);
        klass.get_request_mode = Some(cell_renderer_get_request_mode::<T>);
        klass.snapshot = Some(cell_renderer_snapshot::<T>);
        klass.start_editing = Some(cell_renderer_start_editing::<T>);
    }
}

unsafe extern "C" fn cell_renderer_activate<T: CellRendererImpl>(
    ptr: *mut ffi::GtkCellRenderer,
    evtptr: *mut gdk::ffi::GdkEvent,
    wdgtptr: *mut ffi::GtkWidget,
    pathptr: *const c_char,
    bgptr: *const gdk::ffi::GdkRectangle,
    cellptr: *const gdk::ffi::GdkRectangle,
    flags: ffi::GtkCellRendererState,
) -> glib::ffi::gboolean {
    let instance = &*(ptr as *mut T::Instance);
    let imp = instance.imp();
    let widget: Borrowed<Widget> = from_glib_borrow(wdgtptr);
    let evt: Borrowed<Option<gdk::Event>> = from_glib_borrow(evtptr);

    imp.activate(
        evt.as_ref().as_ref(),
        &*widget,
        &GString::from_glib_borrow(pathptr),
        &from_glib_borrow(bgptr),
        &from_glib_borrow(cellptr),
        from_glib(flags),
    )
    .into_glib()
}

unsafe extern "C" fn cell_renderer_editing_canceled<T: CellRendererImpl>(
    ptr: *mut ffi::GtkCellRenderer,
) {
    let instance = &*(ptr as *mut T::Instance);
    let imp = instance.imp();

    imp.editing_canceled();
}

unsafe extern "C" fn cell_renderer_editing_started<T: CellRendererImpl>(
    ptr: *mut ffi::GtkCellRenderer,
    editableptr: *mut ffi::GtkCellEditable,
    pathptr: *const c_char,
) {
    let instance = &*(ptr as *mut T::Instance);
    let imp = instance.imp();
    let editable = from_glib_borrow(editableptr);

    imp.editing_started(&editable, &GString::from_glib_borrow(pathptr));
}

unsafe extern "C" fn cell_renderer_get_aligned_area<T: CellRendererImpl>(
    ptr: *mut ffi::GtkCellRenderer,
    wdgtptr: *mut ffi::GtkWidget,
    flags: ffi::GtkCellRendererState,
    cellarea: *const gdk::ffi::GdkRectangle,
    alignedptr: *mut gdk::ffi::GdkRectangle,
) {
    let instance = &*(ptr as *mut T::Instance);
    let imp = instance.imp();
    let widget: Borrowed<Widget> = from_glib_borrow(wdgtptr);

    let rectangle = imp.aligned_area(&*widget, from_glib(flags), &from_glib_borrow(cellarea));
    *alignedptr = *rectangle.to_glib_none().0;
}

unsafe extern "C" fn cell_renderer_get_preferred_height_for_width<T: CellRendererImpl>(
    ptr: *mut ffi::GtkCellRenderer,
    wdgtptr: *mut ffi::GtkWidget,
    width: c_int,
    min_height_ptr: *mut c_int,
    nat_height_ptr: *mut c_int,
) {
    let instance = &*(ptr as *mut T::Instance);
    let imp = instance.imp();
    let widget: Borrowed<Widget> = from_glib_borrow(wdgtptr);

    let (min_height, nat_height) = imp.preferred_height_for_width(&*widget, width);
    if !min_height_ptr.is_null() {
        *min_height_ptr = min_height;
    }
    if !nat_height_ptr.is_null() {
        *nat_height_ptr = nat_height;
    }
}

unsafe extern "C" fn cell_renderer_get_preferred_height<T: CellRendererImpl>(
    ptr: *mut ffi::GtkCellRenderer,
    wdgtptr: *mut ffi::GtkWidget,
    minptr: *mut c_int,
    natptr: *mut c_int,
) {
    let instance = &*(ptr as *mut T::Instance);
    let imp = instance.imp();
    let widget: Borrowed<Widget> = from_glib_borrow(wdgtptr);

    let (min_size, nat_size) = imp.preferred_height(&*widget);
    if !minptr.is_null() {
        *minptr = min_size;
    }
    if !natptr.is_null() {
        *natptr = nat_size;
    }
}

unsafe extern "C" fn cell_renderer_get_preferred_width_for_height<T: CellRendererImpl>(
    ptr: *mut ffi::GtkCellRenderer,
    wdgtptr: *mut ffi::GtkWidget,
    height: c_int,
    min_width_ptr: *mut c_int,
    nat_width_ptr: *mut c_int,
) {
    let instance = &*(ptr as *mut T::Instance);
    let imp = instance.imp();
    let widget: Borrowed<Widget> = from_glib_borrow(wdgtptr);

    let (min_width, nat_width) = imp.preferred_width_for_height(&*widget, height);
    if !min_width_ptr.is_null() {
        *min_width_ptr = min_width;
    }
    if !nat_width_ptr.is_null() {
        *nat_width_ptr = nat_width;
    }
}

unsafe extern "C" fn cell_renderer_get_preferred_width<T: CellRendererImpl>(
    ptr: *mut ffi::GtkCellRenderer,
    wdgtptr: *mut ffi::GtkWidget,
    minptr: *mut c_int,
    natptr: *mut c_int,
) {
    let instance = &*(ptr as *mut T::Instance);
    let imp = instance.imp();
    let widget: Borrowed<Widget> = from_glib_borrow(wdgtptr);

    let (min_size, nat_size) = imp.preferred_width(&*widget);
    if !minptr.is_null() {
        *minptr = min_size;
    }
    if !natptr.is_null() {
        *natptr = nat_size;
    }
}

unsafe extern "C" fn cell_renderer_get_request_mode<T: CellRendererImpl>(
    ptr: *mut ffi::GtkCellRenderer,
) -> ffi::GtkSizeRequestMode {
    let instance = &*(ptr as *mut T::Instance);
    let imp = instance.imp();

    imp.request_mode().into_glib()
}

unsafe extern "C" fn cell_renderer_snapshot<T: CellRendererImpl>(
    ptr: *mut ffi::GtkCellRenderer,
    snapshotptr: *mut ffi::GtkSnapshot,
    wdgtptr: *mut ffi::GtkWidget,
    bgptr: *const gdk::ffi::GdkRectangle,
    cellptr: *const gdk::ffi::GdkRectangle,
    flags: ffi::GtkCellRendererState,
) {
    let instance = &*(ptr as *mut T::Instance);
    let imp = instance.imp();
    let widget: Borrowed<Widget> = from_glib_borrow(wdgtptr);
    let snapshot: Borrowed<Snapshot> = from_glib_borrow(snapshotptr);

    imp.snapshot(
        &snapshot,
        &*widget,
        &from_glib_borrow(bgptr),
        &from_glib_borrow(cellptr),
        from_glib(flags),
    );
}

unsafe extern "C" fn cell_renderer_start_editing<T: CellRendererImpl>(
    ptr: *mut ffi::GtkCellRenderer,
    evtptr: *mut gdk::ffi::GdkEvent,
    wdgtptr: *mut ffi::GtkWidget,
    pathptr: *const c_char,
    bgptr: *const gdk::ffi::GdkRectangle,
    cellptr: *const gdk::ffi::GdkRectangle,
    flags: ffi::GtkCellRendererState,
) -> *mut ffi::GtkCellEditable {
    let instance = &*(ptr as *mut T::Instance);
    let imp = instance.imp();
    let widget: Borrowed<Widget> = from_glib_borrow(wdgtptr);
    let evt: Borrowed<Option<gdk::Event>> = from_glib_borrow(evtptr);

    imp.start_editing(
        evt.as_ref().as_ref(),
        &*widget,
        &GString::from_glib_borrow(pathptr),
        &from_glib_borrow(bgptr),
        &from_glib_borrow(cellptr),
        from_glib(flags),
    )
    .to_glib_none()
    .0
}