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`](crate::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: StyleContextImplExt + ObjectImpl {
13 fn changed(&self) {
14 self.parent_changed()
15 }
16}
17
18mod sealed {
19 pub trait Sealed {}
20 impl<T: super::StyleContextImplExt> Sealed for T {}
21}
22
23#[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
24#[allow(deprecated)]
25pub trait StyleContextImplExt: sealed::Sealed + ObjectSubclass {
26 fn parent_changed(&self) {
27 unsafe {
28 let data = Self::type_data();
29 let parent_class = data.as_ref().parent_class() as *mut ffi::GtkStyleContextClass;
30 if let Some(f) = (*parent_class).changed {
31 f(self
32 .obj()
33 .unsafe_cast_ref::<StyleContext>()
34 .to_glib_none()
35 .0)
36 }
37 }
38 }
39}
40
41impl<T: StyleContextImpl> StyleContextImplExt for T {}
42
43unsafe impl<T: StyleContextImpl> IsSubclassable<T> for StyleContext {
44 fn class_init(class: &mut glib::Class<Self>) {
45 Self::parent_class_init::<T>(class);
46
47 assert_initialized_main_thread!();
48 let klass = class.as_mut();
49 klass.changed = Some(style_context_changed::<T>);
50 }
51}
52
53unsafe extern "C" fn style_context_changed<T: StyleContextImpl>(ptr: *mut ffi::GtkStyleContext) {
54 let instance = &*(ptr as *mut T::Instance);
55 let imp = instance.imp();
56
57 imp.changed()
58}