gtk/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 glib::translate::*;
6use glib::GString;
7use gtk_sys;
8use std::cmp;
9use std::fmt;
10use std::mem;
11
12glib_wrapper! {
13    #[derive(Debug, Hash)]
14    pub struct TreePath(Boxed<gtk_sys::GtkTreePath>);
15
16    match fn {
17        copy => |ptr| gtk_sys::gtk_tree_path_copy(mut_override(ptr)),
18        free => |ptr| gtk_sys::gtk_tree_path_free(ptr),
19        get_type => || gtk_sys::gtk_tree_path_get_type(),
20    }
21}
22
23impl TreePath {
24    pub fn new() -> TreePath {
25        assert_initialized_main_thread!();
26        unsafe { from_glib_full(gtk_sys::gtk_tree_path_new()) }
27    }
28
29    pub fn new_first() -> TreePath {
30        assert_initialized_main_thread!();
31        unsafe { from_glib_full(gtk_sys::gtk_tree_path_new_first()) }
32    }
33
34    //pub fn new_from_indices(first_index: i32, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> TreePath {
35    //    unsafe { TODO: call gtk_sys:gtk_tree_path_new_from_indices() }
36    //}
37
38    pub fn new_from_indicesv(indices: &[i32]) -> TreePath {
39        assert_initialized_main_thread!();
40        let length = indices.len() as usize;
41        unsafe {
42            from_glib_full(gtk_sys::gtk_tree_path_new_from_indicesv(
43                indices.to_glib_none().0,
44                length,
45            ))
46        }
47    }
48
49    pub fn new_from_string(path: &str) -> TreePath {
50        assert_initialized_main_thread!();
51        unsafe {
52            from_glib_full(gtk_sys::gtk_tree_path_new_from_string(
53                path.to_glib_none().0,
54            ))
55        }
56    }
57
58    pub fn append_index(&mut self, index_: i32) {
59        unsafe {
60            gtk_sys::gtk_tree_path_append_index(self.to_glib_none_mut().0, index_);
61        }
62    }
63
64    fn compare(&self, b: &TreePath) -> i32 {
65        unsafe { gtk_sys::gtk_tree_path_compare(self.to_glib_none().0, b.to_glib_none().0) }
66    }
67
68    pub fn down(&mut self) {
69        unsafe {
70            gtk_sys::gtk_tree_path_down(self.to_glib_none_mut().0);
71        }
72    }
73
74    pub fn get_depth(&self) -> i32 {
75        unsafe { gtk_sys::gtk_tree_path_get_depth(mut_override(self.to_glib_none().0)) }
76    }
77
78    pub fn get_indices_with_depth(&mut self) -> Vec<i32> {
79        unsafe {
80            let mut depth = mem::uninitialized();
81            let ret = FromGlibContainer::from_glib_none_num(
82                gtk_sys::gtk_tree_path_get_indices_with_depth(
83                    self.to_glib_none_mut().0,
84                    &mut depth,
85                ),
86                depth as usize,
87            );
88            ret
89        }
90    }
91
92    pub fn is_ancestor(&self, descendant: &TreePath) -> bool {
93        unsafe {
94            from_glib(gtk_sys::gtk_tree_path_is_ancestor(
95                mut_override(self.to_glib_none().0),
96                mut_override(descendant.to_glib_none().0),
97            ))
98        }
99    }
100
101    pub fn is_descendant(&self, ancestor: &TreePath) -> bool {
102        unsafe {
103            from_glib(gtk_sys::gtk_tree_path_is_descendant(
104                mut_override(self.to_glib_none().0),
105                mut_override(ancestor.to_glib_none().0),
106            ))
107        }
108    }
109
110    pub fn next(&mut self) {
111        unsafe {
112            gtk_sys::gtk_tree_path_next(self.to_glib_none_mut().0);
113        }
114    }
115
116    pub fn prepend_index(&mut self, index_: i32) {
117        unsafe {
118            gtk_sys::gtk_tree_path_prepend_index(self.to_glib_none_mut().0, index_);
119        }
120    }
121
122    pub fn prev(&mut self) -> bool {
123        unsafe { from_glib(gtk_sys::gtk_tree_path_prev(self.to_glib_none_mut().0)) }
124    }
125
126    fn to_string(&self) -> GString {
127        unsafe {
128            from_glib_full(gtk_sys::gtk_tree_path_to_string(mut_override(
129                self.to_glib_none().0,
130            )))
131        }
132    }
133
134    pub fn up(&mut self) -> bool {
135        unsafe { from_glib(gtk_sys::gtk_tree_path_up(self.to_glib_none_mut().0)) }
136    }
137}
138
139impl Default for TreePath {
140    fn default() -> Self {
141        Self::new()
142    }
143}
144
145impl PartialEq for TreePath {
146    #[inline]
147    fn eq(&self, other: &Self) -> bool {
148        self.compare(other) == 0
149    }
150}
151
152impl Eq for TreePath {}
153
154impl PartialOrd for TreePath {
155    #[inline]
156    fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
157        self.compare(other).partial_cmp(&0)
158    }
159}
160
161impl Ord for TreePath {
162    #[inline]
163    fn cmp(&self, other: &Self) -> cmp::Ordering {
164        self.compare(other).cmp(&0)
165    }
166}
167
168impl fmt::Display for TreePath {
169    #[inline]
170    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
171        write!(f, "{}", self.to_string())
172    }
173}