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
// Take a look at the license at the top of the repository in the LICENSE file.

// rustdoc-stripper-ignore-next
//! Traits intended for subclassing [`CellAreaContext`](crate::CellAreaContext).

use crate::subclass::prelude::*;
use crate::CellAreaContext;
use glib::translate::*;
use glib::Cast;
use std::mem::MaybeUninit;

#[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
pub trait CellAreaContextImpl: CellAreaContextImplExt + ObjectImpl {
    fn reset(&self) {
        self.parent_reset()
    }

    fn preferred_height_for_width(&self, width: i32) -> (i32, i32) {
        self.parent_preferred_height_for_width(width)
    }

    fn preferred_width_for_height(&self, height: i32) -> (i32, i32) {
        self.parent_preferred_width_for_height(height)
    }

    fn allocate(&self, width: i32, height: i32) {
        self.parent_allocate(width, height)
    }
}

#[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
pub trait CellAreaContextImplExt: ObjectSubclass {
    fn parent_reset(&self);
    fn parent_preferred_height_for_width(&self, width: i32) -> (i32, i32);
    fn parent_preferred_width_for_height(&self, height: i32) -> (i32, i32);
    fn parent_allocate(&self, width: i32, height: i32);
}

impl<T: CellAreaContextImpl> CellAreaContextImplExt for T {
    fn parent_reset(&self) {
        unsafe {
            let data = T::type_data();
            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkCellAreaContextClass;
            if let Some(f) = (*parent_class).reset {
                f(self
                    .obj()
                    .unsafe_cast_ref::<CellAreaContext>()
                    .to_glib_none()
                    .0)
            }
        }
    }

    fn parent_preferred_height_for_width(&self, width: i32) -> (i32, i32) {
        unsafe {
            let data = T::type_data();
            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkCellAreaContextClass;
            if let Some(f) = (*parent_class).get_preferred_height_for_width {
                let mut minimum_size = MaybeUninit::uninit();
                let mut natural_size = MaybeUninit::uninit();
                f(
                    self.obj()
                        .unsafe_cast_ref::<CellAreaContext>()
                        .to_glib_none()
                        .0,
                    width,
                    minimum_size.as_mut_ptr(),
                    natural_size.as_mut_ptr(),
                );
                (minimum_size.assume_init(), natural_size.assume_init())
            } else {
                (-1, -1)
            }
        }
    }

    fn parent_preferred_width_for_height(&self, height: i32) -> (i32, i32) {
        unsafe {
            let data = T::type_data();
            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkCellAreaContextClass;
            if let Some(f) = (*parent_class).get_preferred_width_for_height {
                let mut minimum_size = MaybeUninit::uninit();
                let mut natural_size = MaybeUninit::uninit();
                f(
                    self.obj()
                        .unsafe_cast_ref::<CellAreaContext>()
                        .to_glib_none()
                        .0,
                    height,
                    minimum_size.as_mut_ptr(),
                    natural_size.as_mut_ptr(),
                );
                (minimum_size.assume_init(), natural_size.assume_init())
            } else {
                (-1, -1)
            }
        }
    }

    fn parent_allocate(&self, width: i32, height: i32) {
        unsafe {
            let data = T::type_data();
            let parent_class = data.as_ref().parent_class() as *mut ffi::GtkCellAreaContextClass;
            if let Some(f) = (*parent_class).allocate {
                f(
                    self.obj()
                        .unsafe_cast_ref::<CellAreaContext>()
                        .to_glib_none()
                        .0,
                    width,
                    height,
                )
            }
        }
    }
}

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

        assert!(
            crate::rt::is_initialized(),
            "GTK has to be initialized first"
        );

        let klass = class.as_mut();
        klass.reset = Some(cell_area_context_reset::<T>);
        klass.get_preferred_height_for_width =
            Some(cell_area_context_get_preferred_height_for_width::<T>);
        klass.get_preferred_width_for_height =
            Some(cell_area_context_get_preferred_width_for_height::<T>);
        klass.allocate = Some(cell_area_context_allocate::<T>);
    }
}

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

    imp.reset()
}

unsafe extern "C" fn cell_area_context_get_preferred_height_for_width<T: CellAreaContextImpl>(
    ptr: *mut ffi::GtkCellAreaContext,
    width: i32,
    minimum_height: *mut libc::c_int,
    natural_height: *mut libc::c_int,
) {
    let instance = &*(ptr as *mut T::Instance);
    let imp = instance.imp();

    let (min_height, nat_height) = imp.preferred_height_for_width(width);
    *minimum_height = min_height;
    *natural_height = nat_height;
}

unsafe extern "C" fn cell_area_context_get_preferred_width_for_height<T: CellAreaContextImpl>(
    ptr: *mut ffi::GtkCellAreaContext,
    height: i32,
    minimum_width: *mut libc::c_int,
    natural_width: *mut libc::c_int,
) {
    let instance = &*(ptr as *mut T::Instance);
    let imp = instance.imp();

    let (min_width, nat_width) = imp.preferred_width_for_height(height);
    *minimum_width = min_width;
    *natural_width = nat_width;
}

unsafe extern "C" fn cell_area_context_allocate<T: CellAreaContextImpl>(
    ptr: *mut ffi::GtkCellAreaContext,
    width: i32,
    height: i32,
) {
    let instance = &*(ptr as *mut T::Instance);
    let imp = instance.imp();

    imp.allocate(width, height)
}