1use crate::ffi;
6use glib::translate::*;
7
8glib::wrapper! {
9 #[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 #[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 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
50 #[allow(deprecated)]
51 #[doc(alias = "gtk_tree_path_new_first")]
52 pub fn new_first() -> TreePath {
53 assert_initialized_main_thread!();
54 unsafe { from_glib_full(ffi::gtk_tree_path_new_first()) }
55 }
56
57 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
68 #[allow(deprecated)]
69 #[doc(alias = "gtk_tree_path_new_from_indicesv")]
70 #[doc(alias = "new_from_indicesv")]
71 pub fn from_indices(indices: &[i32]) -> TreePath {
72 assert_initialized_main_thread!();
73 let length = indices.len() as _;
74 unsafe {
75 from_glib_full(ffi::gtk_tree_path_new_from_indicesv(
76 indices.to_glib_none().0,
77 length,
78 ))
79 }
80 }
81
82 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
96 #[allow(deprecated)]
97 #[doc(alias = "gtk_tree_path_new_from_string")]
98 #[doc(alias = "new_from_string")]
99 pub fn from_string(path: &str) -> Option<TreePath> {
100 assert_initialized_main_thread!();
101 unsafe { from_glib_full(ffi::gtk_tree_path_new_from_string(path.to_glib_none().0)) }
102 }
103
104 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
113 #[allow(deprecated)]
114 #[doc(alias = "gtk_tree_path_append_index")]
115 pub fn append_index(&mut self, index_: i32) {
116 unsafe {
117 ffi::gtk_tree_path_append_index(self.to_glib_none_mut().0, index_);
118 }
119 }
120
121 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
122 #[allow(deprecated)]
123 #[doc(alias = "gtk_tree_path_compare")]
124 fn compare(&self, b: &TreePath) -> i32 {
125 unsafe { ffi::gtk_tree_path_compare(self.to_glib_none().0, b.to_glib_none().0) }
126 }
127
128 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
133 #[allow(deprecated)]
134 #[doc(alias = "gtk_tree_path_down")]
135 pub fn down(&mut self) {
136 unsafe {
137 ffi::gtk_tree_path_down(self.to_glib_none_mut().0);
138 }
139 }
140
141 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
150 #[allow(deprecated)]
151 #[doc(alias = "gtk_tree_path_get_depth")]
152 #[doc(alias = "get_depth")]
153 pub fn depth(&self) -> i32 {
154 unsafe { ffi::gtk_tree_path_get_depth(mut_override(self.to_glib_none().0)) }
155 }
156
157 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
168 #[allow(deprecated)]
169 #[doc(alias = "gtk_tree_path_is_ancestor")]
170 pub fn is_ancestor(&self, descendant: &TreePath) -> bool {
171 unsafe {
172 from_glib(ffi::gtk_tree_path_is_ancestor(
173 mut_override(self.to_glib_none().0),
174 mut_override(descendant.to_glib_none().0),
175 ))
176 }
177 }
178
179 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
190 #[allow(deprecated)]
191 #[doc(alias = "gtk_tree_path_is_descendant")]
192 pub fn is_descendant(&self, ancestor: &TreePath) -> bool {
193 unsafe {
194 from_glib(ffi::gtk_tree_path_is_descendant(
195 mut_override(self.to_glib_none().0),
196 mut_override(ancestor.to_glib_none().0),
197 ))
198 }
199 }
200
201 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
206 #[allow(deprecated)]
207 #[doc(alias = "gtk_tree_path_next")]
208 pub fn next(&mut self) {
209 unsafe {
210 ffi::gtk_tree_path_next(self.to_glib_none_mut().0);
211 }
212 }
213
214 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
223 #[allow(deprecated)]
224 #[doc(alias = "gtk_tree_path_prepend_index")]
225 pub fn prepend_index(&mut self, index_: i32) {
226 unsafe {
227 ffi::gtk_tree_path_prepend_index(self.to_glib_none_mut().0, index_);
228 }
229 }
230
231 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
242 #[allow(deprecated)]
243 #[doc(alias = "gtk_tree_path_prev")]
244 pub fn prev(&mut self) -> bool {
245 unsafe { from_glib(ffi::gtk_tree_path_prev(self.to_glib_none_mut().0)) }
246 }
247
248 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
259 #[allow(deprecated)]
260 #[doc(alias = "gtk_tree_path_to_string")]
261 #[doc(alias = "to_string")]
262 pub fn to_str(&self) -> Option<glib::GString> {
263 unsafe {
264 from_glib_full(ffi::gtk_tree_path_to_string(mut_override(
265 self.to_glib_none().0,
266 )))
267 }
268 }
269
270 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
279 #[allow(deprecated)]
280 #[doc(alias = "gtk_tree_path_up")]
281 pub fn up(&mut self) -> bool {
282 unsafe { from_glib(ffi::gtk_tree_path_up(self.to_glib_none_mut().0)) }
283 }
284}
285
286impl Default for TreePath {
287 fn default() -> Self {
288 Self::new()
289 }
290}
291
292impl PartialEq for TreePath {
293 #[inline]
294 fn eq(&self, other: &Self) -> bool {
295 self.compare(other) == 0
296 }
297}
298
299impl Eq for TreePath {}
300
301impl PartialOrd for TreePath {
302 #[inline]
303 fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
304 Some(self.cmp(other))
305 }
306}
307
308impl Ord for TreePath {
309 #[inline]
310 fn cmp(&self, other: &Self) -> std::cmp::Ordering {
311 self.compare(other).cmp(&0)
312 }
313}