gtk4/subclass/style_context.rs
1// Take a look at the license at the top of the repository in the LICENSE file.
2
3// rustdoc-stripper-ignore-next
4//! Traits intended for subclassing [`StyleContext`].
5
6use glib::translate::*;
7
8use crate::{ffi, prelude::*, subclass::prelude::*, StyleContext};
9
10#[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
11#[allow(deprecated)]
12pub trait StyleContextImpl: ObjectImpl + ObjectSubclass<Type: IsA<StyleContext>> {
13 fn changed(&self) {
14 self.parent_changed()
15 }
16}
17
18#[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
19#[allow(deprecated)]
20pub trait StyleContextImplExt: StyleContextImpl {
21 fn parent_changed(&self) {
22 unsafe {
23 let data = Self::type_data();
24 let parent_class = data.as_ref().parent_class() as *mut ffi::GtkStyleContextClass;
25 if let Some(f) = (*parent_class).changed {
26 f(self
27 .obj()
28 .unsafe_cast_ref::<StyleContext>()
29 .to_glib_none()
30 .0)
31 }
32 }
33 }
34}
35
36impl<T: StyleContextImpl> StyleContextImplExt for T {}
37
38unsafe impl<T: StyleContextImpl> IsSubclassable<T> for StyleContext {
39 fn class_init(class: &mut glib::Class<Self>) {
40 Self::parent_class_init::<T>(class);
41
42 assert_initialized_main_thread!();
43 let klass = class.as_mut();
44 klass.changed = Some(style_context_changed::<T>);
45 }
46}
47
48unsafe extern "C" fn style_context_changed<T: StyleContextImpl>(ptr: *mut ffi::GtkStyleContext) {
49 let instance = &*(ptr as *mut T::Instance);
50 let imp = instance.imp();
51
52 imp.changed()
53}