gtk4/auto/tree_list_row.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::ffi;
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 /// The type of item used by [`TreeListModel`][crate::TreeListModel].
15 ///
16 /// It allows navigating the model as a tree and modify the state of rows.
17 ///
18 /// [`TreeListRow`][crate::TreeListRow] instances are created by a [`TreeListModel`][crate::TreeListModel] only
19 /// when the [`passthrough`][struct@crate::TreeListModel#passthrough] property is not set.
20 ///
21 /// There are various support objects that can make use of [`TreeListRow`][crate::TreeListRow]
22 /// objects, such as the [`TreeExpander`][crate::TreeExpander] widget that allows displaying
23 /// an icon to expand or collapse a row or [`TreeListRowSorter`][crate::TreeListRowSorter] that
24 /// makes it possible to sort trees properly.
25 ///
26 /// ## Properties
27 ///
28 ///
29 /// #### `children`
30 /// The model holding the row's children.
31 ///
32 /// Readable
33 ///
34 ///
35 /// #### `depth`
36 /// The depth in the tree of this row.
37 ///
38 /// Readable
39 ///
40 ///
41 /// #### `expandable`
42 /// If this row can ever be expanded.
43 ///
44 /// Readable
45 ///
46 ///
47 /// #### `expanded`
48 /// If this row is currently expanded.
49 ///
50 /// Readable | Writeable
51 ///
52 ///
53 /// #### `item`
54 /// The item held in this row.
55 ///
56 /// Readable
57 ///
58 /// # Implements
59 ///
60 /// [`trait@glib::ObjectExt`]
61 #[doc(alias = "GtkTreeListRow")]
62 pub struct TreeListRow(Object<ffi::GtkTreeListRow, ffi::GtkTreeListRowClass>);
63
64 match fn {
65 type_ => || ffi::gtk_tree_list_row_get_type(),
66 }
67}
68
69impl TreeListRow {
70 /// If @self is not expanded or @position is greater than the
71 /// number of children, [`None`] is returned.
72 /// ## `position`
73 /// position of the child to get
74 ///
75 /// # Returns
76 ///
77 /// the child in @position
78 #[doc(alias = "gtk_tree_list_row_get_child_row")]
79 #[doc(alias = "get_child_row")]
80 #[must_use]
81 pub fn child_row(&self, position: u32) -> Option<TreeListRow> {
82 unsafe {
83 from_glib_full(ffi::gtk_tree_list_row_get_child_row(
84 self.to_glib_none().0,
85 position,
86 ))
87 }
88 }
89
90 /// If the row is expanded, gets the model holding the children of @self.
91 ///
92 /// This model is the model created by the
93 /// `callback::Gtk::TreeListModelCreateModelFunc
94 /// and contains the original items, no matter what value
95 /// [`passthrough`][struct@crate::TreeListModel#passthrough] is set to.
96 ///
97 /// # Returns
98 ///
99 /// The model containing the children
100 #[doc(alias = "gtk_tree_list_row_get_children")]
101 #[doc(alias = "get_children")]
102 pub fn children(&self) -> Option<gio::ListModel> {
103 unsafe { from_glib_none(ffi::gtk_tree_list_row_get_children(self.to_glib_none().0)) }
104 }
105
106 /// Gets the depth of this row.
107 ///
108 /// Rows that correspond to items in the root model have a depth
109 /// of zero, rows corresponding to items of models of direct children
110 /// of the root model have a depth of 1 and so on.
111 ///
112 /// The depth of a row never changes until the row is removed from its model
113 /// at which point it will forever return 0.
114 ///
115 /// # Returns
116 ///
117 /// The depth of this row
118 #[doc(alias = "gtk_tree_list_row_get_depth")]
119 #[doc(alias = "get_depth")]
120 pub fn depth(&self) -> u32 {
121 unsafe { ffi::gtk_tree_list_row_get_depth(self.to_glib_none().0) }
122 }
123
124 /// Gets if a row is currently expanded.
125 ///
126 /// # Returns
127 ///
128 /// [`true`] if the row is expanded
129 #[doc(alias = "gtk_tree_list_row_get_expanded")]
130 #[doc(alias = "get_expanded")]
131 #[doc(alias = "expanded")]
132 pub fn is_expanded(&self) -> bool {
133 unsafe { from_glib(ffi::gtk_tree_list_row_get_expanded(self.to_glib_none().0)) }
134 }
135
136 /// Gets the item corresponding to this row,
137 ///
138 /// # Returns
139 ///
140 /// The item
141 /// of this row. This function is only marked as nullable for backwards
142 /// compatibility reasons.
143 #[doc(alias = "gtk_tree_list_row_get_item")]
144 #[doc(alias = "get_item")]
145 pub fn item(&self) -> Option<glib::Object> {
146 unsafe { from_glib_full(ffi::gtk_tree_list_row_get_item(self.to_glib_none().0)) }
147 }
148
149 /// Gets the row representing the parent for @self.
150 ///
151 /// That is the row that would need to be collapsed
152 /// to make this row disappear.
153 ///
154 /// If @self is a row corresponding to the root model,
155 /// [`None`] is returned.
156 ///
157 /// The value returned by this function never changes
158 /// until the row is removed from its model at which point
159 /// it will forever return [`None`].
160 ///
161 /// # Returns
162 ///
163 /// The parent of @self
164 #[doc(alias = "gtk_tree_list_row_get_parent")]
165 #[doc(alias = "get_parent")]
166 #[must_use]
167 pub fn parent(&self) -> Option<TreeListRow> {
168 unsafe { from_glib_full(ffi::gtk_tree_list_row_get_parent(self.to_glib_none().0)) }
169 }
170
171 /// Returns the position in the [`TreeListModel`][crate::TreeListModel] that @self occupies
172 /// at the moment.
173 ///
174 /// # Returns
175 ///
176 /// The position in the model
177 #[doc(alias = "gtk_tree_list_row_get_position")]
178 #[doc(alias = "get_position")]
179 pub fn position(&self) -> u32 {
180 unsafe { ffi::gtk_tree_list_row_get_position(self.to_glib_none().0) }
181 }
182
183 /// Checks if a row can be expanded.
184 ///
185 /// This does not mean that the row is actually expanded,
186 /// this can be checked with [`is_expanded()`][Self::is_expanded()].
187 ///
188 /// If a row is expandable never changes until the row is removed
189 /// from its model at which point it will forever return [`false`].
190 ///
191 /// # Returns
192 ///
193 /// [`true`] if the row is expandable
194 #[doc(alias = "gtk_tree_list_row_is_expandable")]
195 #[doc(alias = "expandable")]
196 pub fn is_expandable(&self) -> bool {
197 unsafe { from_glib(ffi::gtk_tree_list_row_is_expandable(self.to_glib_none().0)) }
198 }
199
200 /// Expands or collapses a row.
201 ///
202 /// If a row is expanded, the model of calling the
203 /// `callback::Gtk::TreeListModelCreateModelFunc for the row's
204 /// item will be inserted after this row. If a row is collapsed,
205 /// those items will be removed from the model.
206 ///
207 /// If the row is not expandable, this function does nothing.
208 /// ## `expanded`
209 /// [`true`] if the row should be expanded
210 #[doc(alias = "gtk_tree_list_row_set_expanded")]
211 #[doc(alias = "expanded")]
212 pub fn set_expanded(&self, expanded: bool) {
213 unsafe {
214 ffi::gtk_tree_list_row_set_expanded(self.to_glib_none().0, expanded.into_glib());
215 }
216 }
217
218 #[doc(alias = "children")]
219 pub fn connect_children_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
220 unsafe extern "C" fn notify_children_trampoline<F: Fn(&TreeListRow) + 'static>(
221 this: *mut ffi::GtkTreeListRow,
222 _param_spec: glib::ffi::gpointer,
223 f: glib::ffi::gpointer,
224 ) {
225 let f: &F = &*(f as *const F);
226 f(&from_glib_borrow(this))
227 }
228 unsafe {
229 let f: Box_<F> = Box_::new(f);
230 connect_raw(
231 self.as_ptr() as *mut _,
232 c"notify::children".as_ptr() as *const _,
233 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
234 notify_children_trampoline::<F> as *const (),
235 )),
236 Box_::into_raw(f),
237 )
238 }
239 }
240
241 #[doc(alias = "depth")]
242 pub fn connect_depth_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
243 unsafe extern "C" fn notify_depth_trampoline<F: Fn(&TreeListRow) + 'static>(
244 this: *mut ffi::GtkTreeListRow,
245 _param_spec: glib::ffi::gpointer,
246 f: glib::ffi::gpointer,
247 ) {
248 let f: &F = &*(f as *const F);
249 f(&from_glib_borrow(this))
250 }
251 unsafe {
252 let f: Box_<F> = Box_::new(f);
253 connect_raw(
254 self.as_ptr() as *mut _,
255 c"notify::depth".as_ptr() as *const _,
256 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
257 notify_depth_trampoline::<F> as *const (),
258 )),
259 Box_::into_raw(f),
260 )
261 }
262 }
263
264 #[doc(alias = "expandable")]
265 pub fn connect_expandable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
266 unsafe extern "C" fn notify_expandable_trampoline<F: Fn(&TreeListRow) + 'static>(
267 this: *mut ffi::GtkTreeListRow,
268 _param_spec: glib::ffi::gpointer,
269 f: glib::ffi::gpointer,
270 ) {
271 let f: &F = &*(f as *const F);
272 f(&from_glib_borrow(this))
273 }
274 unsafe {
275 let f: Box_<F> = Box_::new(f);
276 connect_raw(
277 self.as_ptr() as *mut _,
278 c"notify::expandable".as_ptr() as *const _,
279 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
280 notify_expandable_trampoline::<F> as *const (),
281 )),
282 Box_::into_raw(f),
283 )
284 }
285 }
286
287 #[doc(alias = "expanded")]
288 pub fn connect_expanded_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
289 unsafe extern "C" fn notify_expanded_trampoline<F: Fn(&TreeListRow) + 'static>(
290 this: *mut ffi::GtkTreeListRow,
291 _param_spec: glib::ffi::gpointer,
292 f: glib::ffi::gpointer,
293 ) {
294 let f: &F = &*(f as *const F);
295 f(&from_glib_borrow(this))
296 }
297 unsafe {
298 let f: Box_<F> = Box_::new(f);
299 connect_raw(
300 self.as_ptr() as *mut _,
301 c"notify::expanded".as_ptr() as *const _,
302 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
303 notify_expanded_trampoline::<F> as *const (),
304 )),
305 Box_::into_raw(f),
306 )
307 }
308 }
309
310 #[doc(alias = "item")]
311 pub fn connect_item_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
312 unsafe extern "C" fn notify_item_trampoline<F: Fn(&TreeListRow) + 'static>(
313 this: *mut ffi::GtkTreeListRow,
314 _param_spec: glib::ffi::gpointer,
315 f: glib::ffi::gpointer,
316 ) {
317 let f: &F = &*(f as *const F);
318 f(&from_glib_borrow(this))
319 }
320 unsafe {
321 let f: Box_<F> = Box_::new(f);
322 connect_raw(
323 self.as_ptr() as *mut _,
324 c"notify::item".as_ptr() as *const _,
325 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
326 notify_item_trampoline::<F> as *const (),
327 )),
328 Box_::into_raw(f),
329 )
330 }
331 }
332}