gtk4/auto/
tree_path.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::translate::*;
7
8glib::wrapper! {
9    /// An opaque structure representing a path to a row in a model.
10    ///
11    /// # Deprecated since 4.10
12    ///
13    #[derive(Debug, Hash)]
14    pub struct TreePath(Boxed<ffi::GtkTreePath>);
15
16    match fn {
17        copy => |ptr| ffi::gtk_tree_path_copy(ptr),
18        free => |ptr| ffi::gtk_tree_path_free(ptr),
19        type_ => || ffi::gtk_tree_path_get_type(),
20    }
21}
22
23impl TreePath {
24    /// Creates a new [`TreePath`][crate::TreePath]
25    /// This refers to a row.
26    ///
27    /// # Deprecated since 4.10
28    ///
29    ///
30    /// # Returns
31    ///
32    /// A newly created [`TreePath`][crate::TreePath].
33    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
34    #[allow(deprecated)]
35    #[doc(alias = "gtk_tree_path_new")]
36    pub fn new() -> TreePath {
37        assert_initialized_main_thread!();
38        unsafe { from_glib_full(ffi::gtk_tree_path_new()) }
39    }
40
41    /// Creates a new [`TreePath`][crate::TreePath].
42    ///
43    /// The string representation of this path is “0”.
44    ///
45    /// # Deprecated since 4.10
46    ///
47    ///
48    /// # Returns
49    ///
50    /// A new [`TreePath`][crate::TreePath]
51    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
52    #[allow(deprecated)]
53    #[doc(alias = "gtk_tree_path_new_first")]
54    pub fn new_first() -> TreePath {
55        assert_initialized_main_thread!();
56        unsafe { from_glib_full(ffi::gtk_tree_path_new_first()) }
57    }
58
59    /// Creates a new path with the given @indices array of @length.
60    ///
61    /// # Deprecated since 4.10
62    ///
63    /// ## `indices`
64    /// array of indices
65    ///
66    /// # Returns
67    ///
68    /// A newly created [`TreePath`][crate::TreePath]
69    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
70    #[allow(deprecated)]
71    #[doc(alias = "gtk_tree_path_new_from_indicesv")]
72    #[doc(alias = "new_from_indicesv")]
73    pub fn from_indices(indices: &[i32]) -> TreePath {
74        assert_initialized_main_thread!();
75        let length = indices.len() as _;
76        unsafe {
77            from_glib_full(ffi::gtk_tree_path_new_from_indicesv(
78                indices.to_glib_none().0,
79                length,
80            ))
81        }
82    }
83
84    /// Creates a new [`TreePath`][crate::TreePath] initialized to @path.
85    ///
86    /// @path is expected to be a colon separated list of numbers.
87    /// For example, the string “10:4:0” would create a path of depth
88    /// 3 pointing to the 11th child of the root node, the 5th
89    /// child of that 11th child, and the 1st child of that 5th child.
90    /// If an invalid path string is passed in, [`None`] is returned.
91    ///
92    /// # Deprecated since 4.10
93    ///
94    /// ## `path`
95    /// The string representation of a path
96    ///
97    /// # Returns
98    ///
99    /// A newly-created [`TreePath`][crate::TreePath]
100    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
101    #[allow(deprecated)]
102    #[doc(alias = "gtk_tree_path_new_from_string")]
103    #[doc(alias = "new_from_string")]
104    pub fn from_string(path: &str) -> Option<TreePath> {
105        assert_initialized_main_thread!();
106        unsafe { from_glib_full(ffi::gtk_tree_path_new_from_string(path.to_glib_none().0)) }
107    }
108
109    /// Appends a new index to a path.
110    ///
111    /// As a result, the depth of the path is increased.
112    ///
113    /// # Deprecated since 4.10
114    ///
115    /// ## `index_`
116    /// the index
117    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
118    #[allow(deprecated)]
119    #[doc(alias = "gtk_tree_path_append_index")]
120    pub fn append_index(&mut self, index_: i32) {
121        unsafe {
122            ffi::gtk_tree_path_append_index(self.to_glib_none_mut().0, index_);
123        }
124    }
125
126    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
127    #[allow(deprecated)]
128    #[doc(alias = "gtk_tree_path_compare")]
129    fn compare(&self, b: &TreePath) -> i32 {
130        unsafe { ffi::gtk_tree_path_compare(self.to_glib_none().0, b.to_glib_none().0) }
131    }
132
133    /// Moves @self to point to the first child of the current path.
134    ///
135    /// # Deprecated since 4.10
136    ///
137    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
138    #[allow(deprecated)]
139    #[doc(alias = "gtk_tree_path_down")]
140    pub fn down(&mut self) {
141        unsafe {
142            ffi::gtk_tree_path_down(self.to_glib_none_mut().0);
143        }
144    }
145
146    /// Returns the current depth of @self.
147    ///
148    /// # Deprecated since 4.10
149    ///
150    ///
151    /// # Returns
152    ///
153    /// The depth of @self
154    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
155    #[allow(deprecated)]
156    #[doc(alias = "gtk_tree_path_get_depth")]
157    #[doc(alias = "get_depth")]
158    pub fn depth(&self) -> i32 {
159        unsafe { ffi::gtk_tree_path_get_depth(mut_override(self.to_glib_none().0)) }
160    }
161
162    /// Returns [`true`] if @descendant is a descendant of @self.
163    ///
164    /// # Deprecated since 4.10
165    ///
166    /// ## `descendant`
167    /// another [`TreePath`][crate::TreePath]
168    ///
169    /// # Returns
170    ///
171    /// [`true`] if @descendant is contained inside @self
172    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
173    #[allow(deprecated)]
174    #[doc(alias = "gtk_tree_path_is_ancestor")]
175    pub fn is_ancestor(&self, descendant: &TreePath) -> bool {
176        unsafe {
177            from_glib(ffi::gtk_tree_path_is_ancestor(
178                mut_override(self.to_glib_none().0),
179                mut_override(descendant.to_glib_none().0),
180            ))
181        }
182    }
183
184    /// Returns [`true`] if @self is a descendant of @ancestor.
185    ///
186    /// # Deprecated since 4.10
187    ///
188    /// ## `ancestor`
189    /// another [`TreePath`][crate::TreePath]
190    ///
191    /// # Returns
192    ///
193    /// [`true`] if @ancestor contains @self somewhere below it
194    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
195    #[allow(deprecated)]
196    #[doc(alias = "gtk_tree_path_is_descendant")]
197    pub fn is_descendant(&self, ancestor: &TreePath) -> bool {
198        unsafe {
199            from_glib(ffi::gtk_tree_path_is_descendant(
200                mut_override(self.to_glib_none().0),
201                mut_override(ancestor.to_glib_none().0),
202            ))
203        }
204    }
205
206    /// Moves the @self to point to the next node at the current depth.
207    ///
208    /// # Deprecated since 4.10
209    ///
210    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
211    #[allow(deprecated)]
212    #[doc(alias = "gtk_tree_path_next")]
213    pub fn next(&mut self) {
214        unsafe {
215            ffi::gtk_tree_path_next(self.to_glib_none_mut().0);
216        }
217    }
218
219    /// Prepends a new index to a path.
220    ///
221    /// As a result, the depth of the path is increased.
222    ///
223    /// # Deprecated since 4.10
224    ///
225    /// ## `index_`
226    /// the index
227    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
228    #[allow(deprecated)]
229    #[doc(alias = "gtk_tree_path_prepend_index")]
230    pub fn prepend_index(&mut self, index_: i32) {
231        unsafe {
232            ffi::gtk_tree_path_prepend_index(self.to_glib_none_mut().0, index_);
233        }
234    }
235
236    /// Moves the @self to point to the previous node at the
237    /// current depth, if it exists.
238    ///
239    /// # Deprecated since 4.10
240    ///
241    ///
242    /// # Returns
243    ///
244    /// [`true`] if @self has a previous node, and
245    ///   the move was made
246    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
247    #[allow(deprecated)]
248    #[doc(alias = "gtk_tree_path_prev")]
249    pub fn prev(&mut self) -> bool {
250        unsafe { from_glib(ffi::gtk_tree_path_prev(self.to_glib_none_mut().0)) }
251    }
252
253    /// Generates a string representation of the path.
254    ///
255    /// This string is a “:” separated list of numbers.
256    /// For example, “4:10:0:3” would be an acceptable
257    /// return value for this string. If the path has
258    /// depth 0, [`None`] is returned.
259    ///
260    /// # Deprecated since 4.10
261    ///
262    ///
263    /// # Returns
264    ///
265    /// A newly-allocated string
266    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
267    #[allow(deprecated)]
268    #[doc(alias = "gtk_tree_path_to_string")]
269    #[doc(alias = "to_string")]
270    pub fn to_str(&self) -> Option<glib::GString> {
271        unsafe {
272            from_glib_full(ffi::gtk_tree_path_to_string(mut_override(
273                self.to_glib_none().0,
274            )))
275        }
276    }
277
278    /// Moves the @self to point to its parent node, if it has a parent.
279    ///
280    /// # Deprecated since 4.10
281    ///
282    ///
283    /// # Returns
284    ///
285    /// [`true`] if @self has a parent, and the move was made
286    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
287    #[allow(deprecated)]
288    #[doc(alias = "gtk_tree_path_up")]
289    pub fn up(&mut self) -> bool {
290        unsafe { from_glib(ffi::gtk_tree_path_up(self.to_glib_none_mut().0)) }
291    }
292}
293
294impl Default for TreePath {
295    fn default() -> Self {
296        Self::new()
297    }
298}
299
300impl PartialEq for TreePath {
301    #[inline]
302    fn eq(&self, other: &Self) -> bool {
303        self.compare(other) == 0
304    }
305}
306
307impl Eq for TreePath {}
308
309impl PartialOrd for TreePath {
310    #[inline]
311    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
312        Some(self.cmp(other))
313    }
314}
315
316impl Ord for TreePath {
317    #[inline]
318    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
319        self.compare(other).cmp(&0)
320    }
321}