gdk4/subclass/
paintable.rs1use glib::translate::*;
8
9use crate::{ffi, prelude::*, subclass::prelude::*, Paintable, PaintableFlags, Snapshot};
10
11pub trait PaintableImpl: PaintableImplExt + ObjectImpl {
12 #[doc(alias = "get_current_image")]
13 fn current_image(&self) -> Paintable {
14 self.parent_current_image()
15 }
16
17 #[doc(alias = "get_flags")]
18 fn flags(&self) -> PaintableFlags {
19 self.parent_flags()
20 }
21
22 #[doc(alias = "get_intrinsic_width")]
23 fn intrinsic_width(&self) -> i32 {
24 self.parent_intrinsic_width()
25 }
26
27 #[doc(alias = "get_intrinsic_height")]
28 fn intrinsic_height(&self) -> i32 {
29 self.parent_intrinsic_height()
30 }
31
32 #[doc(alias = "get_intrinsic_aspect_ratio")]
33 fn intrinsic_aspect_ratio(&self) -> f64 {
34 self.parent_intrinsic_aspect_ratio()
35 }
36
37 fn snapshot(&self, snapshot: &Snapshot, width: f64, height: f64);
38}
39
40mod sealed {
41 pub trait Sealed {}
42 impl<T: super::PaintableImplExt> Sealed for T {}
43}
44
45pub trait PaintableImplExt: sealed::Sealed + ObjectSubclass {
46 fn parent_current_image(&self) -> Paintable {
47 unsafe {
48 let type_data = Self::type_data();
49 let parent_iface = type_data.as_ref().parent_interface::<Paintable>()
50 as *const ffi::GdkPaintableInterface;
51 let func = (*parent_iface)
52 .get_current_image
53 .expect("no parent \"get_current_image\" implementation");
54
55 let ret = func(self.obj().unsafe_cast_ref::<Paintable>().to_glib_none().0);
56
57 from_glib_full(ret)
58 }
59 }
60
61 fn parent_flags(&self) -> PaintableFlags {
62 unsafe {
63 let type_data = Self::type_data();
64 let parent_iface = type_data.as_ref().parent_interface::<Paintable>()
65 as *const ffi::GdkPaintableInterface;
66 let func = (*parent_iface)
67 .get_flags
68 .expect("no parent \"get_flags\" implementation");
69
70 from_glib(func(
71 self.obj().unsafe_cast_ref::<Paintable>().to_glib_none().0,
72 ))
73 }
74 }
75
76 fn parent_intrinsic_width(&self) -> i32 {
77 unsafe {
78 let type_data = Self::type_data();
79 let parent_iface = type_data.as_ref().parent_interface::<Paintable>()
80 as *const ffi::GdkPaintableInterface;
81 let func = (*parent_iface)
82 .get_intrinsic_width
83 .expect("no parent \"get_intrinsic_width\" implementation");
84
85 func(self.obj().unsafe_cast_ref::<Paintable>().to_glib_none().0)
86 }
87 }
88
89 fn parent_intrinsic_height(&self) -> i32 {
90 unsafe {
91 let type_data = Self::type_data();
92 let parent_iface = type_data.as_ref().parent_interface::<Paintable>()
93 as *const ffi::GdkPaintableInterface;
94 let func = (*parent_iface)
95 .get_intrinsic_height
96 .expect("no parent \"get_intrinsic_height\" implementation");
97
98 func(self.obj().unsafe_cast_ref::<Paintable>().to_glib_none().0)
99 }
100 }
101
102 fn parent_intrinsic_aspect_ratio(&self) -> f64 {
103 unsafe {
104 let type_data = Self::type_data();
105 let parent_iface = type_data.as_ref().parent_interface::<Paintable>()
106 as *const ffi::GdkPaintableInterface;
107 let func = (*parent_iface)
108 .get_intrinsic_aspect_ratio
109 .expect("no parent \"get_intrinsic_aspect_ratio\" implementation");
110
111 func(self.obj().unsafe_cast_ref::<Paintable>().to_glib_none().0)
112 }
113 }
114
115 fn parent_snapshot(&self, snapshot: &Snapshot, width: f64, height: f64) {
116 unsafe {
117 let type_data = Self::type_data();
118 let parent_iface = type_data.as_ref().parent_interface::<Paintable>()
119 as *const ffi::GdkPaintableInterface;
120 let func = (*parent_iface)
121 .snapshot
122 .expect("no parent \"snapshot\" implementation");
123
124 func(
125 self.obj().unsafe_cast_ref::<Paintable>().to_glib_none().0,
126 snapshot.to_glib_none().0,
127 width,
128 height,
129 )
130 }
131 }
132}
133
134impl<T: PaintableImpl> PaintableImplExt for T {}
135
136unsafe impl<T: PaintableImpl> IsImplementable<T> for Paintable {
137 fn interface_init(iface: &mut glib::Interface<Self>) {
138 let iface = iface.as_mut();
139
140 iface.get_current_image = Some(paintable_get_current_image::<T>);
141 iface.get_flags = Some(paintable_get_flags::<T>);
142 iface.get_intrinsic_width = Some(paintable_get_intrinsic_width::<T>);
143 iface.get_intrinsic_height = Some(paintable_get_intrinsic_height::<T>);
144 iface.get_intrinsic_aspect_ratio = Some(paintable_get_intrinsic_aspect_ratio::<T>);
145 iface.snapshot = Some(paintable_snapshot::<T>);
146 }
147}
148
149unsafe extern "C" fn paintable_get_current_image<T: PaintableImpl>(
150 paintable: *mut ffi::GdkPaintable,
151) -> *mut ffi::GdkPaintable {
152 let instance = &*(paintable as *mut T::Instance);
153 let imp = instance.imp();
154
155 imp.current_image().into_glib_ptr()
156}
157
158unsafe extern "C" fn paintable_get_flags<T: PaintableImpl>(
159 paintable: *mut ffi::GdkPaintable,
160) -> ffi::GdkPaintableFlags {
161 let instance = &*(paintable as *mut T::Instance);
162 let imp = instance.imp();
163
164 imp.flags().into_glib()
165}
166
167unsafe extern "C" fn paintable_get_intrinsic_width<T: PaintableImpl>(
168 paintable: *mut ffi::GdkPaintable,
169) -> i32 {
170 let instance = &*(paintable as *mut T::Instance);
171 let imp = instance.imp();
172
173 imp.intrinsic_width()
174}
175
176unsafe extern "C" fn paintable_get_intrinsic_height<T: PaintableImpl>(
177 paintable: *mut ffi::GdkPaintable,
178) -> i32 {
179 let instance = &*(paintable as *mut T::Instance);
180 let imp = instance.imp();
181
182 imp.intrinsic_height()
183}
184
185unsafe extern "C" fn paintable_get_intrinsic_aspect_ratio<T: PaintableImpl>(
186 paintable: *mut ffi::GdkPaintable,
187) -> f64 {
188 let instance = &*(paintable as *mut T::Instance);
189 let imp = instance.imp();
190
191 imp.intrinsic_aspect_ratio()
192}
193
194unsafe extern "C" fn paintable_snapshot<T: PaintableImpl>(
195 paintable: *mut ffi::GdkPaintable,
196 snapshotptr: *mut ffi::GdkSnapshot,
197 width: f64,
198 height: f64,
199) {
200 let instance = &*(paintable as *mut T::Instance);
201 let imp = instance.imp();
202
203 imp.snapshot(&Snapshot::from_glib_borrow(snapshotptr), width, height)
204}