gtk4/subclass/
actionable.rs
1use glib::{translate::*, GString, Variant};
8
9use crate::{ffi, prelude::*, subclass::prelude::*, Actionable};
10
11pub trait ActionableImpl: WidgetImpl {
12 #[doc(alias = "get_action_name")]
13 fn action_name(&self) -> Option<GString>;
14 #[doc(alias = "get_action_target_value")]
15 fn action_target_value(&self) -> Option<Variant>;
16 fn set_action_name(&self, name: Option<&str>);
17 fn set_action_target_value(&self, value: Option<&Variant>);
18}
19
20mod sealed {
21 pub trait Sealed {}
22 impl<T: super::ActionableImplExt> Sealed for T {}
23}
24
25pub trait ActionableImplExt: sealed::Sealed + ObjectSubclass {
26 fn parent_action_name(&self) -> Option<GString> {
27 unsafe {
28 let type_data = Self::type_data();
29 let parent_iface = type_data.as_ref().parent_interface::<Actionable>()
30 as *const ffi::GtkActionableInterface;
31
32 let func = (*parent_iface)
33 .get_action_name
34 .expect("no parent \"get_action_name\" implementation");
35
36 from_glib_none(func(
37 self.obj().unsafe_cast_ref::<Actionable>().to_glib_none().0,
38 ))
39 }
40 }
41
42 fn parent_action_target_value(&self) -> Option<Variant> {
43 unsafe {
44 let type_data = Self::type_data();
45 let parent_iface = type_data.as_ref().parent_interface::<Actionable>()
46 as *const ffi::GtkActionableInterface;
47
48 let func = (*parent_iface)
49 .get_action_target_value
50 .expect("no parent \"get_action_target_value\" implementation");
51
52 from_glib_none(func(
53 self.obj().unsafe_cast_ref::<Actionable>().to_glib_none().0,
54 ))
55 }
56 }
57
58 fn parent_set_action_name(&self, name: Option<&str>) {
59 unsafe {
60 let type_data = Self::type_data();
61 let parent_iface = type_data.as_ref().parent_interface::<Actionable>()
62 as *const ffi::GtkActionableInterface;
63
64 let func = (*parent_iface)
65 .set_action_name
66 .expect("no parent \"set_action_name\" implementation");
67
68 func(
69 self.obj().unsafe_cast_ref::<Actionable>().to_glib_none().0,
70 name.to_glib_none().0,
71 );
72 }
73 }
74
75 fn parent_set_action_target_value(&self, value: Option<&Variant>) {
76 unsafe {
77 let type_data = Self::type_data();
78 let parent_iface = type_data.as_ref().parent_interface::<Actionable>()
79 as *const ffi::GtkActionableInterface;
80
81 let func = (*parent_iface)
82 .set_action_target_value
83 .expect("no parent \"set_action_target_value\" implementation");
84
85 func(
86 self.obj().unsafe_cast_ref::<Actionable>().to_glib_none().0,
87 value.to_glib_none().0,
88 );
89 }
90 }
91}
92
93impl<T: ActionableImpl> ActionableImplExt for T {}
94
95unsafe impl<T: ActionableImpl> IsImplementable<T> for Actionable {
96 fn interface_init(iface: &mut glib::Interface<Self>) {
97 let iface = iface.as_mut();
98
99 iface.get_action_name = Some(actionable_get_action_name::<T>);
100 iface.get_action_target_value = Some(actionable_get_action_target_value::<T>);
101 iface.set_action_name = Some(actionable_set_action_name::<T>);
102 iface.set_action_target_value = Some(actionable_set_action_target_value::<T>);
103 }
104}
105
106unsafe extern "C" fn actionable_get_action_name<T: ActionableImpl>(
107 actionable: *mut ffi::GtkActionable,
108) -> *const libc::c_char {
109 let instance = &*(actionable as *mut T::Instance);
110 let imp = instance.imp();
111
112 imp.action_name().into_glib_ptr()
113}
114
115unsafe extern "C" fn actionable_get_action_target_value<T: ActionableImpl>(
116 actionable: *mut ffi::GtkActionable,
117) -> *mut glib::ffi::GVariant {
118 let instance = &*(actionable as *mut T::Instance);
119 let imp = instance.imp();
120
121 imp.action_target_value().into_glib_ptr()
122}
123
124unsafe extern "C" fn actionable_set_action_name<T: ActionableImpl>(
125 actionable: *mut ffi::GtkActionable,
126 name: *const libc::c_char,
127) {
128 let instance = &*(actionable as *mut T::Instance);
129 let imp = instance.imp();
130 let name: Borrowed<Option<GString>> = from_glib_borrow(name);
131 imp.set_action_name(name.as_ref().as_ref().map(|s| s.as_str()))
132}
133
134unsafe extern "C" fn actionable_set_action_target_value<T: ActionableImpl>(
135 actionable: *mut ffi::GtkActionable,
136 value: *mut glib::ffi::GVariant,
137) {
138 let instance = &*(actionable as *mut T::Instance);
139 let imp = instance.imp();
140 let val: Borrowed<Option<Variant>> = from_glib_borrow(value);
141
142 imp.set_action_target_value(val.as_ref().as_ref())
143}