Skip to main content

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::{SignalHandlerId, connect_raw},
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            unsafe {
226                let f: &F = &*(f as *const F);
227                f(&from_glib_borrow(this))
228            }
229        }
230        unsafe {
231            let f: Box_<F> = Box_::new(f);
232            connect_raw(
233                self.as_ptr() as *mut _,
234                c"notify::children".as_ptr(),
235                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
236                    notify_children_trampoline::<F> as *const (),
237                )),
238                Box_::into_raw(f),
239            )
240        }
241    }
242
243    #[doc(alias = "depth")]
244    pub fn connect_depth_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
245        unsafe extern "C" fn notify_depth_trampoline<F: Fn(&TreeListRow) + 'static>(
246            this: *mut ffi::GtkTreeListRow,
247            _param_spec: glib::ffi::gpointer,
248            f: glib::ffi::gpointer,
249        ) {
250            unsafe {
251                let f: &F = &*(f as *const F);
252                f(&from_glib_borrow(this))
253            }
254        }
255        unsafe {
256            let f: Box_<F> = Box_::new(f);
257            connect_raw(
258                self.as_ptr() as *mut _,
259                c"notify::depth".as_ptr(),
260                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
261                    notify_depth_trampoline::<F> as *const (),
262                )),
263                Box_::into_raw(f),
264            )
265        }
266    }
267
268    #[doc(alias = "expandable")]
269    pub fn connect_expandable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
270        unsafe extern "C" fn notify_expandable_trampoline<F: Fn(&TreeListRow) + 'static>(
271            this: *mut ffi::GtkTreeListRow,
272            _param_spec: glib::ffi::gpointer,
273            f: glib::ffi::gpointer,
274        ) {
275            unsafe {
276                let f: &F = &*(f as *const F);
277                f(&from_glib_borrow(this))
278            }
279        }
280        unsafe {
281            let f: Box_<F> = Box_::new(f);
282            connect_raw(
283                self.as_ptr() as *mut _,
284                c"notify::expandable".as_ptr(),
285                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
286                    notify_expandable_trampoline::<F> as *const (),
287                )),
288                Box_::into_raw(f),
289            )
290        }
291    }
292
293    #[doc(alias = "expanded")]
294    pub fn connect_expanded_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
295        unsafe extern "C" fn notify_expanded_trampoline<F: Fn(&TreeListRow) + 'static>(
296            this: *mut ffi::GtkTreeListRow,
297            _param_spec: glib::ffi::gpointer,
298            f: glib::ffi::gpointer,
299        ) {
300            unsafe {
301                let f: &F = &*(f as *const F);
302                f(&from_glib_borrow(this))
303            }
304        }
305        unsafe {
306            let f: Box_<F> = Box_::new(f);
307            connect_raw(
308                self.as_ptr() as *mut _,
309                c"notify::expanded".as_ptr(),
310                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
311                    notify_expanded_trampoline::<F> as *const (),
312                )),
313                Box_::into_raw(f),
314            )
315        }
316    }
317
318    #[doc(alias = "item")]
319    pub fn connect_item_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
320        unsafe extern "C" fn notify_item_trampoline<F: Fn(&TreeListRow) + 'static>(
321            this: *mut ffi::GtkTreeListRow,
322            _param_spec: glib::ffi::gpointer,
323            f: glib::ffi::gpointer,
324        ) {
325            unsafe {
326                let f: &F = &*(f as *const F);
327                f(&from_glib_borrow(this))
328            }
329        }
330        unsafe {
331            let f: Box_<F> = Box_::new(f);
332            connect_raw(
333                self.as_ptr() as *mut _,
334                c"notify::item".as_ptr(),
335                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
336                    notify_item_trampoline::<F> as *const (),
337                )),
338                Box_::into_raw(f),
339            )
340        }
341    }
342}