gtk4/subclass/
combo_box.rs
1use glib::{translate::*, GString};
7
8use crate::{ffi, prelude::*, subclass::prelude::*, CellEditable, CellLayout, ComboBox};
9
10#[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
11#[allow(deprecated)]
12pub trait ComboBoxImpl:
13 WidgetImpl + ObjectSubclass<Type: IsA<ComboBox> + IsA<CellEditable> + IsA<CellLayout>>
14{
15 #[cfg(feature = "v4_6")]
16 #[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
17 fn activate(&self) {
18 self.parent_activate()
19 }
20 fn changed(&self) {
22 self.parent_changed()
23 }
24 fn format_entry_text(&self, path: &str) -> Option<GString> {
27 self.parent_format_entry_text(path)
28 }
29}
30
31#[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
32#[allow(deprecated)]
33pub trait ComboBoxImplExt: ComboBoxImpl {
34 #[cfg(feature = "v4_6")]
35 #[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
36 fn parent_activate(&self) {
37 unsafe {
38 let data = Self::type_data();
39 let parent_class = data.as_ref().parent_class() as *mut ffi::GtkComboBoxClass;
40 if let Some(f) = (*parent_class).activate {
41 f(self.obj().unsafe_cast_ref::<ComboBox>().to_glib_none().0)
42 }
43 }
44 }
45 fn parent_changed(&self) {
46 unsafe {
47 let data = Self::type_data();
48 let parent_class = data.as_ref().parent_class() as *mut ffi::GtkComboBoxClass;
49 if let Some(f) = (*parent_class).changed {
50 f(self.obj().unsafe_cast_ref::<ComboBox>().to_glib_none().0)
51 }
52 }
53 }
54 fn parent_format_entry_text(&self, path: &str) -> Option<GString> {
55 unsafe {
56 let data = Self::type_data();
57 let parent_class = data.as_ref().parent_class() as *mut ffi::GtkComboBoxClass;
58 if let Some(f) = (*parent_class).format_entry_text {
59 return Some(from_glib_full(f(
60 self.obj().unsafe_cast_ref::<ComboBox>().to_glib_none().0,
61 path.to_glib_none().0,
62 )));
63 }
64 None
65 }
66 }
67}
68
69impl<T: ComboBoxImpl> ComboBoxImplExt for T {}
70
71unsafe impl<T: ComboBoxImpl> IsSubclassable<T> for ComboBox {
72 fn class_init(class: &mut glib::Class<Self>) {
73 Self::parent_class_init::<T>(class);
74
75 let klass = class.as_mut();
76 klass.changed = Some(combo_box_changed::<T>);
77 klass.format_entry_text = Some(combo_box_format_entry_text::<T>);
78 #[cfg(feature = "v4_6")]
79 #[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
80 {
81 klass.activate = Some(combo_box_activate::<T>);
82 };
83 }
84}
85
86unsafe extern "C" fn combo_box_changed<T: ComboBoxImpl>(ptr: *mut ffi::GtkComboBox) {
87 let instance = &*(ptr as *mut T::Instance);
88 let imp = instance.imp();
89
90 imp.changed()
91}
92
93unsafe extern "C" fn combo_box_format_entry_text<T: ComboBoxImpl>(
94 ptr: *mut ffi::GtkComboBox,
95 pathptr: *const libc::c_char,
96) -> *mut libc::c_char {
97 let instance = &*(ptr as *mut T::Instance);
98 let imp = instance.imp();
99 let path: Borrowed<GString> = from_glib_borrow(pathptr);
100
101 imp.format_entry_text(path.as_str()).into_glib_ptr()
102}
103
104#[cfg(feature = "v4_6")]
105#[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
106unsafe extern "C" fn combo_box_activate<T: ComboBoxImpl>(ptr: *mut ffi::GtkComboBox) {
107 let instance = &*(ptr as *mut T::Instance);
108 let imp = instance.imp();
109
110 imp.activate()
111}