gtk/auto/tree_store.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::{Buildable, TreeDragDest, TreeDragSource, TreeIter, TreeModel, TreeSortable};
6use glib::{prelude::*, translate::*};
7use std::fmt;
8
9glib::wrapper! {
10 /// The [`TreeStore`][crate::TreeStore] object is a list model for use with a [`TreeView`][crate::TreeView]
11 /// widget. It implements the [`TreeModel`][crate::TreeModel] interface, and consequentially,
12 /// can use all of the methods available there. It also implements the
13 /// [`TreeSortable`][crate::TreeSortable] interface so it can be sorted by the view. Finally,
14 /// it also implements the tree
15 /// [drag and drop][gtk3-GtkTreeView-drag-and-drop]
16 /// interfaces.
17 ///
18 /// # GtkTreeStore as GtkBuildable
19 ///
20 /// The GtkTreeStore implementation of the [`Buildable`][crate::Buildable] interface allows
21 /// to specify the model columns with a ``<columns>`` element that may contain
22 /// multiple ``<column>`` elements, each specifying one model column. The “type”
23 /// attribute specifies the data type for the column.
24 ///
25 /// An example of a UI Definition fragment for a tree store:
26 ///
27 ///
28 ///
29 /// **⚠️ The following code is in xml ⚠️**
30 ///
31 /// ```xml
32 /// <object class="GtkTreeStore">
33 /// <columns>
34 /// <column type="gchararray"/>
35 /// <column type="gchararray"/>
36 /// <column type="gint"/>
37 /// </columns>
38 /// </object>
39 /// ```
40 ///
41 /// # Implements
42 ///
43 /// [`TreeStoreExt`][trait@crate::prelude::TreeStoreExt], [`trait@glib::ObjectExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`TreeDragDestExt`][trait@crate::prelude::TreeDragDestExt], [`TreeDragSourceExt`][trait@crate::prelude::TreeDragSourceExt], [`TreeModelExt`][trait@crate::prelude::TreeModelExt], [`TreeSortableExt`][trait@crate::prelude::TreeSortableExt], [`TreeStoreExtManual`][trait@crate::prelude::TreeStoreExtManual], [`BuildableExtManual`][trait@crate::prelude::BuildableExtManual], [`TreeSortableExtManual`][trait@crate::prelude::TreeSortableExtManual]
44 #[doc(alias = "GtkTreeStore")]
45 pub struct TreeStore(Object<ffi::GtkTreeStore, ffi::GtkTreeStoreClass>) @implements Buildable, TreeDragDest, TreeDragSource, TreeModel, TreeSortable;
46
47 match fn {
48 type_ => || ffi::gtk_tree_store_get_type(),
49 }
50}
51
52impl TreeStore {
53 pub const NONE: Option<&'static TreeStore> = None;
54
55 //#[doc(alias = "gtk_tree_store_new")]
56 //pub fn new(n_columns: i32, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) -> TreeStore {
57 // unsafe { TODO: call ffi:gtk_tree_store_new() }
58 //}
59
60 //#[doc(alias = "gtk_tree_store_newv")]
61 //pub fn newv(types: /*Unimplemented*/&CArray TypeId { ns_id: 0, id: 30 }) -> TreeStore {
62 // unsafe { TODO: call ffi:gtk_tree_store_newv() }
63 //}
64}
65
66mod sealed {
67 pub trait Sealed {}
68 impl<T: super::IsA<super::TreeStore>> Sealed for T {}
69}
70
71/// Trait containing all [`struct@TreeStore`] methods.
72///
73/// # Implementors
74///
75/// [`TreeStore`][struct@crate::TreeStore]
76pub trait TreeStoreExt: IsA<TreeStore> + sealed::Sealed + 'static {
77 /// Appends a new row to `self`. If `parent` is non-[`None`], then it will append the
78 /// new row after the last child of `parent`, otherwise it will append a row to
79 /// the top level. `iter` will be changed to point to this new row. The row will
80 /// be empty after this function is called. To fill in values, you need to call
81 /// [`TreeStoreExtManual::set()`][crate::prelude::TreeStoreExtManual::set()] or [`TreeStoreExtManual::set_value()`][crate::prelude::TreeStoreExtManual::set_value()].
82 /// ## `parent`
83 /// A valid [`TreeIter`][crate::TreeIter], or [`None`]
84 ///
85 /// # Returns
86 ///
87 ///
88 /// ## `iter`
89 /// An unset [`TreeIter`][crate::TreeIter] to set to the appended row
90 #[doc(alias = "gtk_tree_store_append")]
91 fn append(&self, parent: Option<&TreeIter>) -> TreeIter {
92 unsafe {
93 let mut iter = TreeIter::uninitialized();
94 ffi::gtk_tree_store_append(
95 self.as_ref().to_glib_none().0,
96 iter.to_glib_none_mut().0,
97 mut_override(parent.to_glib_none().0),
98 );
99 iter
100 }
101 }
102
103 /// Removes all rows from `self`
104 #[doc(alias = "gtk_tree_store_clear")]
105 fn clear(&self) {
106 unsafe {
107 ffi::gtk_tree_store_clear(self.as_ref().to_glib_none().0);
108 }
109 }
110
111 /// Creates a new row at `position`. If parent is non-[`None`], then the row will be
112 /// made a child of `parent`. Otherwise, the row will be created at the toplevel.
113 /// If `position` is -1 or is larger than the number of rows at that level, then
114 /// the new row will be inserted to the end of the list. `iter` will be changed
115 /// to point to this new row. The row will be empty after this function is
116 /// called. To fill in values, you need to call [`TreeStoreExtManual::set()`][crate::prelude::TreeStoreExtManual::set()] or
117 /// [`TreeStoreExtManual::set_value()`][crate::prelude::TreeStoreExtManual::set_value()].
118 /// ## `parent`
119 /// A valid [`TreeIter`][crate::TreeIter], or [`None`]
120 /// ## `position`
121 /// position to insert the new row, or -1 for last
122 ///
123 /// # Returns
124 ///
125 ///
126 /// ## `iter`
127 /// An unset [`TreeIter`][crate::TreeIter] to set to the new row
128 #[doc(alias = "gtk_tree_store_insert")]
129 fn insert(&self, parent: Option<&TreeIter>, position: i32) -> TreeIter {
130 unsafe {
131 let mut iter = TreeIter::uninitialized();
132 ffi::gtk_tree_store_insert(
133 self.as_ref().to_glib_none().0,
134 iter.to_glib_none_mut().0,
135 mut_override(parent.to_glib_none().0),
136 position,
137 );
138 iter
139 }
140 }
141
142 /// Inserts a new row after `sibling`. If `sibling` is [`None`], then the row will be
143 /// prepended to `parent` ’s children. If `parent` and `sibling` are [`None`], then
144 /// the row will be prepended to the toplevel. If both `sibling` and `parent` are
145 /// set, then `parent` must be the parent of `sibling`. When `sibling` is set,
146 /// `parent` is optional.
147 ///
148 /// `iter` will be changed to point to this new row. The row will be empty after
149 /// this function is called. To fill in values, you need to call
150 /// [`TreeStoreExtManual::set()`][crate::prelude::TreeStoreExtManual::set()] or [`TreeStoreExtManual::set_value()`][crate::prelude::TreeStoreExtManual::set_value()].
151 /// ## `parent`
152 /// A valid [`TreeIter`][crate::TreeIter], or [`None`]
153 /// ## `sibling`
154 /// A valid [`TreeIter`][crate::TreeIter], or [`None`]
155 ///
156 /// # Returns
157 ///
158 ///
159 /// ## `iter`
160 /// An unset [`TreeIter`][crate::TreeIter] to set to the new row
161 #[doc(alias = "gtk_tree_store_insert_after")]
162 fn insert_after(&self, parent: Option<&TreeIter>, sibling: Option<&TreeIter>) -> TreeIter {
163 unsafe {
164 let mut iter = TreeIter::uninitialized();
165 ffi::gtk_tree_store_insert_after(
166 self.as_ref().to_glib_none().0,
167 iter.to_glib_none_mut().0,
168 mut_override(parent.to_glib_none().0),
169 mut_override(sibling.to_glib_none().0),
170 );
171 iter
172 }
173 }
174
175 /// Inserts a new row before `sibling`. If `sibling` is [`None`], then the row will
176 /// be appended to `parent` ’s children. If `parent` and `sibling` are [`None`], then
177 /// the row will be appended to the toplevel. If both `sibling` and `parent` are
178 /// set, then `parent` must be the parent of `sibling`. When `sibling` is set,
179 /// `parent` is optional.
180 ///
181 /// `iter` will be changed to point to this new row. The row will be empty after
182 /// this function is called. To fill in values, you need to call
183 /// [`TreeStoreExtManual::set()`][crate::prelude::TreeStoreExtManual::set()] or [`TreeStoreExtManual::set_value()`][crate::prelude::TreeStoreExtManual::set_value()].
184 /// ## `parent`
185 /// A valid [`TreeIter`][crate::TreeIter], or [`None`]
186 /// ## `sibling`
187 /// A valid [`TreeIter`][crate::TreeIter], or [`None`]
188 ///
189 /// # Returns
190 ///
191 ///
192 /// ## `iter`
193 /// An unset [`TreeIter`][crate::TreeIter] to set to the new row
194 #[doc(alias = "gtk_tree_store_insert_before")]
195 fn insert_before(&self, parent: Option<&TreeIter>, sibling: Option<&TreeIter>) -> TreeIter {
196 unsafe {
197 let mut iter = TreeIter::uninitialized();
198 ffi::gtk_tree_store_insert_before(
199 self.as_ref().to_glib_none().0,
200 iter.to_glib_none_mut().0,
201 mut_override(parent.to_glib_none().0),
202 mut_override(sibling.to_glib_none().0),
203 );
204 iter
205 }
206 }
207
208 //#[doc(alias = "gtk_tree_store_insert_with_values")]
209 //fn insert_with_values(&self, parent: Option<&TreeIter>, position: i32, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) -> TreeIter {
210 // unsafe { TODO: call ffi:gtk_tree_store_insert_with_values() }
211 //}
212
213 //#[doc(alias = "gtk_tree_store_insert_with_valuesv")]
214 //fn insert_with_valuesv(&self, parent: Option<&TreeIter>, position: i32, columns: &[i32], values: &[&glib::Value]) -> TreeIter {
215 // unsafe { TODO: call ffi:gtk_tree_store_insert_with_valuesv() }
216 //}
217
218 /// Returns [`true`] if `iter` is an ancestor of `descendant`. That is, `iter` is the
219 /// parent (or grandparent or great-grandparent) of `descendant`.
220 /// ## `iter`
221 /// A valid [`TreeIter`][crate::TreeIter]
222 /// ## `descendant`
223 /// A valid [`TreeIter`][crate::TreeIter]
224 ///
225 /// # Returns
226 ///
227 /// [`true`], if `iter` is an ancestor of `descendant`
228 #[doc(alias = "gtk_tree_store_is_ancestor")]
229 fn is_ancestor(&self, iter: &TreeIter, descendant: &TreeIter) -> bool {
230 unsafe {
231 from_glib(ffi::gtk_tree_store_is_ancestor(
232 self.as_ref().to_glib_none().0,
233 mut_override(iter.to_glib_none().0),
234 mut_override(descendant.to_glib_none().0),
235 ))
236 }
237 }
238
239 /// Returns the depth of `iter`. This will be 0 for anything on the root level, 1
240 /// for anything down a level, etc.
241 /// ## `iter`
242 /// A valid [`TreeIter`][crate::TreeIter]
243 ///
244 /// # Returns
245 ///
246 /// The depth of `iter`
247 #[doc(alias = "gtk_tree_store_iter_depth")]
248 fn iter_depth(&self, iter: &TreeIter) -> i32 {
249 unsafe {
250 ffi::gtk_tree_store_iter_depth(
251 self.as_ref().to_glib_none().0,
252 mut_override(iter.to_glib_none().0),
253 )
254 }
255 }
256
257 /// WARNING: This function is slow. Only use it for debugging and/or testing
258 /// purposes.
259 ///
260 /// Checks if the given iter is a valid iter for this [`TreeStore`][crate::TreeStore].
261 /// ## `iter`
262 /// A [`TreeIter`][crate::TreeIter].
263 ///
264 /// # Returns
265 ///
266 /// [`true`] if the iter is valid, [`false`] if the iter is invalid.
267 #[doc(alias = "gtk_tree_store_iter_is_valid")]
268 fn iter_is_valid(&self, iter: &TreeIter) -> bool {
269 unsafe {
270 from_glib(ffi::gtk_tree_store_iter_is_valid(
271 self.as_ref().to_glib_none().0,
272 mut_override(iter.to_glib_none().0),
273 ))
274 }
275 }
276
277 /// Moves `iter` in `self` to the position after `position`. `iter` and
278 /// `position` should be in the same level. Note that this function only
279 /// works with unsorted stores. If `position` is [`None`], `iter` will be moved
280 /// to the start of the level.
281 /// ## `iter`
282 /// A [`TreeIter`][crate::TreeIter].
283 /// ## `position`
284 /// A [`TreeIter`][crate::TreeIter].
285 #[doc(alias = "gtk_tree_store_move_after")]
286 fn move_after(&self, iter: &TreeIter, position: Option<&TreeIter>) {
287 unsafe {
288 ffi::gtk_tree_store_move_after(
289 self.as_ref().to_glib_none().0,
290 mut_override(iter.to_glib_none().0),
291 mut_override(position.to_glib_none().0),
292 );
293 }
294 }
295
296 /// Moves `iter` in `self` to the position before `position`. `iter` and
297 /// `position` should be in the same level. Note that this function only
298 /// works with unsorted stores. If `position` is [`None`], `iter` will be
299 /// moved to the end of the level.
300 /// ## `iter`
301 /// A [`TreeIter`][crate::TreeIter].
302 /// ## `position`
303 /// A [`TreeIter`][crate::TreeIter] or [`None`].
304 #[doc(alias = "gtk_tree_store_move_before")]
305 fn move_before(&self, iter: &TreeIter, position: Option<&TreeIter>) {
306 unsafe {
307 ffi::gtk_tree_store_move_before(
308 self.as_ref().to_glib_none().0,
309 mut_override(iter.to_glib_none().0),
310 mut_override(position.to_glib_none().0),
311 );
312 }
313 }
314
315 /// Prepends a new row to `self`. If `parent` is non-[`None`], then it will prepend
316 /// the new row before the first child of `parent`, otherwise it will prepend a row
317 /// to the top level. `iter` will be changed to point to this new row. The row
318 /// will be empty after this function is called. To fill in values, you need to
319 /// call [`TreeStoreExtManual::set()`][crate::prelude::TreeStoreExtManual::set()] or [`TreeStoreExtManual::set_value()`][crate::prelude::TreeStoreExtManual::set_value()].
320 /// ## `parent`
321 /// A valid [`TreeIter`][crate::TreeIter], or [`None`]
322 ///
323 /// # Returns
324 ///
325 ///
326 /// ## `iter`
327 /// An unset [`TreeIter`][crate::TreeIter] to set to the prepended row
328 #[doc(alias = "gtk_tree_store_prepend")]
329 fn prepend(&self, parent: Option<&TreeIter>) -> TreeIter {
330 unsafe {
331 let mut iter = TreeIter::uninitialized();
332 ffi::gtk_tree_store_prepend(
333 self.as_ref().to_glib_none().0,
334 iter.to_glib_none_mut().0,
335 mut_override(parent.to_glib_none().0),
336 );
337 iter
338 }
339 }
340
341 /// Removes `iter` from `self`. After being removed, `iter` is set to the
342 /// next valid row at that level, or invalidated if it previously pointed to the
343 /// last one.
344 /// ## `iter`
345 /// A valid [`TreeIter`][crate::TreeIter]
346 ///
347 /// # Returns
348 ///
349 /// [`true`] if `iter` is still valid, [`false`] if not.
350 #[doc(alias = "gtk_tree_store_remove")]
351 fn remove(&self, iter: &TreeIter) -> bool {
352 unsafe {
353 from_glib(ffi::gtk_tree_store_remove(
354 self.as_ref().to_glib_none().0,
355 mut_override(iter.to_glib_none().0),
356 ))
357 }
358 }
359
360 //#[doc(alias = "gtk_tree_store_set_column_types")]
361 //fn set_column_types(&self, types: /*Unimplemented*/&CArray TypeId { ns_id: 0, id: 30 }) {
362 // unsafe { TODO: call ffi:gtk_tree_store_set_column_types() }
363 //}
364
365 //#[doc(alias = "gtk_tree_store_set_valist")]
366 //fn set_valist(&self, iter: &TreeIter, var_args: /*Unknown conversion*//*Unimplemented*/Unsupported) {
367 // unsafe { TODO: call ffi:gtk_tree_store_set_valist() }
368 //}
369
370 //#[doc(alias = "gtk_tree_store_set_valuesv")]
371 //fn set_valuesv(&self, iter: &TreeIter, columns: &[i32], values: &[&glib::Value]) {
372 // unsafe { TODO: call ffi:gtk_tree_store_set_valuesv() }
373 //}
374
375 /// Swaps `a` and `b` in the same level of `self`. Note that this function
376 /// only works with unsorted stores.
377 /// ## `a`
378 /// A [`TreeIter`][crate::TreeIter].
379 /// ## `b`
380 /// Another [`TreeIter`][crate::TreeIter].
381 #[doc(alias = "gtk_tree_store_swap")]
382 fn swap(&self, a: &TreeIter, b: &TreeIter) {
383 unsafe {
384 ffi::gtk_tree_store_swap(
385 self.as_ref().to_glib_none().0,
386 mut_override(a.to_glib_none().0),
387 mut_override(b.to_glib_none().0),
388 );
389 }
390 }
391}
392
393impl<O: IsA<TreeStore>> TreeStoreExt for O {}
394
395impl fmt::Display for TreeStore {
396 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
397 f.write_str("TreeStore")
398 }
399}