1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
use crate::subclass::prelude::*;
use crate::{TreeIter, TreeModel, TreeModelFilter};
use glib::translate::*;
use glib::{Cast, IsA, Value};
pub trait TreeModelFilterImpl: TreeModelFilterImplExt + ObjectImpl {
fn visible<M: IsA<TreeModel>>(
&self,
tree_model_filter: &Self::Type,
child_model: &M,
iter: &TreeIter,
) -> bool {
self.parent_visible(tree_model_filter, child_model, iter)
}
fn modify<M: IsA<TreeModel>>(
&self,
tree_model_filter: &Self::Type,
child_model: &M,
iter: &TreeIter,
value: Value,
column: i32,
) {
self.parent_modify(tree_model_filter, child_model, iter, value, column)
}
}
pub trait TreeModelFilterImplExt: ObjectSubclass {
fn parent_visible<M: IsA<TreeModel>>(
&self,
tree_model_filter: &Self::Type,
child_model: &M,
iter: &TreeIter,
) -> bool;
fn parent_modify<M: IsA<TreeModel>>(
&self,
tree_model_filter: &Self::Type,
child_model: &M,
iter: &TreeIter,
value: Value,
index: i32,
);
}
impl<T: TreeModelFilterImpl> TreeModelFilterImplExt for T {
fn parent_visible<M: IsA<TreeModel>>(
&self,
tree_model_filter: &Self::Type,
child_model: &M,
iter: &TreeIter,
) -> bool {
unsafe {
let data = T::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GtkTreeModelFilterClass;
if let Some(f) = (*parent_class).visible {
from_glib(f(
tree_model_filter
.unsafe_cast_ref::<TreeModelFilter>()
.to_glib_none()
.0,
child_model.as_ref().to_glib_none().0,
iter.to_glib_none().0 as *mut _,
))
} else {
true }
}
}
fn parent_modify<M: IsA<TreeModel>>(
&self,
tree_model_filter: &Self::Type,
child_model: &M,
iter: &TreeIter,
value: Value,
index: i32,
) {
unsafe {
let data = T::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GtkTreeModelFilterClass;
if let Some(f) = (*parent_class).modify {
f(
tree_model_filter
.unsafe_cast_ref::<TreeModelFilter>()
.to_glib_none()
.0,
child_model.as_ref().to_glib_none().0,
iter.to_glib_none().0 as *mut _,
value.to_glib_none().0 as *mut _,
index,
)
}
}
}
}
unsafe impl<T: TreeModelFilterImpl> IsSubclassable<T> for TreeModelFilter {
fn class_init(class: &mut glib::Class<Self>) {
Self::parent_class_init::<T>(class);
assert!(
crate::rt::is_initialized(),
"GTK has to be initialized first"
);
let klass = class.as_mut();
klass.visible = Some(tree_model_filter_visible::<T>);
klass.modify = Some(tree_model_filter_modify::<T>);
}
}
unsafe extern "C" fn tree_model_filter_visible<T: TreeModelFilterImpl>(
ptr: *mut ffi::GtkTreeModelFilter,
child_modelptr: *mut ffi::GtkTreeModel,
iterptr: *mut ffi::GtkTreeIter,
) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp();
let wrap: Borrowed<TreeModelFilter> = from_glib_borrow(ptr);
let child_model: Borrowed<TreeModel> = from_glib_borrow(child_modelptr);
let iter: Borrowed<TreeIter> = from_glib_borrow(iterptr);
imp.visible(wrap.unsafe_cast_ref(), &*child_model, &iter)
.into_glib()
}
unsafe extern "C" fn tree_model_filter_modify<T: TreeModelFilterImpl>(
ptr: *mut ffi::GtkTreeModelFilter,
child_modelptr: *mut ffi::GtkTreeModel,
iterptr: *mut ffi::GtkTreeIter,
valueptr: *mut glib::gobject_ffi::GValue,
column: i32,
) {
let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp();
let wrap: Borrowed<TreeModelFilter> = from_glib_borrow(ptr);
let child_model: Borrowed<TreeModel> = from_glib_borrow(child_modelptr);
let iter: Borrowed<TreeIter> = from_glib_borrow(iterptr);
let value: Value = from_glib_full(valueptr);
imp.modify(wrap.unsafe_cast_ref(), &*child_model, &iter, value, column)
}