gtk/auto/tree_model.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::{TreeIter, TreeModelFlags, TreePath, ffi};
6use glib::{
7 object::ObjectType as _,
8 prelude::*,
9 signal::{SignalHandlerId, connect_raw},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 /// The [`TreeModel`][crate::TreeModel] interface defines a generic tree interface for
16 /// use by the [`TreeView`][crate::TreeView] widget. It is an abstract interface, and
17 /// is designed to be usable with any appropriate data structure. The
18 /// programmer just has to implement this interface on their own data
19 /// type for it to be viewable by a [`TreeView`][crate::TreeView] widget.
20 ///
21 /// The model is represented as a hierarchical tree of strongly-typed,
22 /// columned data. In other words, the model can be seen as a tree where
23 /// every node has different values depending on which column is being
24 /// queried. The type of data found in a column is determined by using
25 /// the GType system (ie. `G_TYPE_INT`, `GTK_TYPE_BUTTON`, `G_TYPE_POINTER`,
26 /// etc). The types are homogeneous per column across all nodes. It is
27 /// important to note that this interface only provides a way of examining
28 /// a model and observing changes. The implementation of each individual
29 /// model decides how and if changes are made.
30 ///
31 /// In order to make life simpler for programmers who do not need to
32 /// write their own specialized model, two generic models are provided
33 /// — the [`TreeStore`][crate::TreeStore] and the [`ListStore`][crate::ListStore]. To use these, the
34 /// developer simply pushes data into these models as necessary. These
35 /// models provide the data structure as well as all appropriate tree
36 /// interfaces. As a result, implementing drag and drop, sorting, and
37 /// storing data is trivial. For the vast majority of trees and lists,
38 /// these two models are sufficient.
39 ///
40 /// Models are accessed on a node/column level of granularity. One can
41 /// query for the value of a model at a certain node and a certain
42 /// column on that node. There are two structures used to reference a
43 /// particular node in a model. They are the [`TreePath`][crate::TreePath]-struct and
44 /// the [`TreeIter`][crate::TreeIter]-struct (“iter” is short for iterator). Most of the
45 /// interface consists of operations on a [`TreeIter`][crate::TreeIter]-struct.
46 ///
47 /// A path is essentially a potential node. It is a location on a model
48 /// that may or may not actually correspond to a node on a specific
49 /// model. The [`TreePath`][crate::TreePath]-struct can be converted into either an
50 /// array of unsigned integers or a string. The string form is a list
51 /// of numbers separated by a colon. Each number refers to the offset
52 /// at that level. Thus, the path `0` refers to the root
53 /// node and the path `2:4` refers to the fifth child of
54 /// the third node.
55 ///
56 /// By contrast, a [`TreeIter`][crate::TreeIter]-struct is a reference to a specific node on
57 /// a specific model. It is a generic struct with an integer and three
58 /// generic pointers. These are filled in by the model in a model-specific
59 /// way. One can convert a path to an iterator by calling
60 /// [`TreeModelExt::iter()`][crate::prelude::TreeModelExt::iter()]. These iterators are the primary way
61 /// of accessing a model and are similar to the iterators used by
62 /// [`TextBuffer`][crate::TextBuffer]. They are generally statically allocated on the
63 /// stack and only used for a short time. The model interface defines
64 /// a set of operations using them for navigating the model.
65 ///
66 /// It is expected that models fill in the iterator with private data.
67 /// For example, the [`ListStore`][crate::ListStore] model, which is internally a simple
68 /// linked list, stores a list node in one of the pointers. The
69 /// [`TreeModelSort`][crate::TreeModelSort] stores an array and an offset in two of the
70 /// pointers. Additionally, there is an integer field. This field is
71 /// generally filled with a unique stamp per model. This stamp is for
72 /// catching errors resulting from using invalid iterators with a model.
73 ///
74 /// The lifecycle of an iterator can be a little confusing at first.
75 /// Iterators are expected to always be valid for as long as the model
76 /// is unchanged (and doesn’t emit a signal). The model is considered
77 /// to own all outstanding iterators and nothing needs to be done to
78 /// free them from the user’s point of view. Additionally, some models
79 /// guarantee that an iterator is valid for as long as the node it refers
80 /// to is valid (most notably the [`TreeStore`][crate::TreeStore] and [`ListStore`][crate::ListStore]).
81 /// Although generally uninteresting, as one always has to allow for
82 /// the case where iterators do not persist beyond a signal, some very
83 /// important performance enhancements were made in the sort model.
84 /// As a result, the [`TreeModelFlags::ITERS_PERSIST`][crate::TreeModelFlags::ITERS_PERSIST] flag was added to
85 /// indicate this behavior.
86 ///
87 /// To help show some common operation of a model, some examples are
88 /// provided. The first example shows three ways of getting the iter at
89 /// the location `3:2:5`. While the first method shown is
90 /// easier, the second is much more common, as you often get paths from
91 /// callbacks.
92 ///
93 /// ## Acquiring a [`TreeIter`][crate::TreeIter]-struct
94 ///
95 ///
96 ///
97 /// **⚠️ The following code is in C ⚠️**
98 ///
99 /// ```C
100 /// // Three ways of getting the iter pointing to the location
101 /// GtkTreePath *path;
102 /// GtkTreeIter iter;
103 /// GtkTreeIter parent_iter;
104 ///
105 /// // get the iterator from a string
106 /// gtk_tree_model_get_iter_from_string (model,
107 /// &iter,
108 /// "3:2:5");
109 ///
110 /// // get the iterator from a path
111 /// path = gtk_tree_path_new_from_string ("3:2:5");
112 /// gtk_tree_model_get_iter (model, &iter, path);
113 /// gtk_tree_path_free (path);
114 ///
115 /// // walk the tree to find the iterator
116 /// gtk_tree_model_iter_nth_child (model, &iter,
117 /// NULL, 3);
118 /// parent_iter = iter;
119 /// gtk_tree_model_iter_nth_child (model, &iter,
120 /// &parent_iter, 2);
121 /// parent_iter = iter;
122 /// gtk_tree_model_iter_nth_child (model, &iter,
123 /// &parent_iter, 5);
124 /// ```
125 ///
126 /// This second example shows a quick way of iterating through a list
127 /// and getting a string and an integer from each row. The
128 /// `populate_model()` function used below is not
129 /// shown, as it is specific to the [`ListStore`][crate::ListStore]. For information on
130 /// how to write such a function, see the [`ListStore`][crate::ListStore] documentation.
131 ///
132 /// ## Reading data from a [`TreeModel`][crate::TreeModel]
133 ///
134 ///
135 ///
136 /// **⚠️ The following code is in C ⚠️**
137 ///
138 /// ```C
139 /// enum
140 /// {
141 /// STRING_COLUMN,
142 /// INT_COLUMN,
143 /// N_COLUMNS
144 /// };
145 ///
146 /// ...
147 ///
148 /// GtkTreeModel *list_store;
149 /// GtkTreeIter iter;
150 /// gboolean valid;
151 /// gint row_count = 0;
152 ///
153 /// // make a new list_store
154 /// list_store = gtk_list_store_new (N_COLUMNS,
155 /// G_TYPE_STRING,
156 /// G_TYPE_INT);
157 ///
158 /// // Fill the list store with data
159 /// populate_model (list_store);
160 ///
161 /// // Get the first iter in the list, check it is valid and walk
162 /// // through the list, reading each row.
163 ///
164 /// valid = gtk_tree_model_get_iter_first (list_store,
165 /// &iter);
166 /// while (valid)
167 /// {
168 /// gchar *str_data;
169 /// gint int_data;
170 ///
171 /// // Make sure you terminate calls to gtk_tree_model_get() with a “-1” value
172 /// gtk_tree_model_get (list_store, &iter,
173 /// STRING_COLUMN, &str_data,
174 /// INT_COLUMN, &int_data,
175 /// -1);
176 ///
177 /// // Do something with the data
178 /// g_print ("Row %d: (%s,%d)\n",
179 /// row_count, str_data, int_data);
180 /// g_free (str_data);
181 ///
182 /// valid = gtk_tree_model_iter_next (list_store,
183 /// &iter);
184 /// row_count++;
185 /// }
186 /// ```
187 ///
188 /// The [`TreeModel`][crate::TreeModel] interface contains two methods for reference
189 /// counting: `gtk_tree_model_ref_node()` and `gtk_tree_model_unref_node()`.
190 /// These two methods are optional to implement. The reference counting
191 /// is meant as a way for views to let models know when nodes are being
192 /// displayed. [`TreeView`][crate::TreeView] will take a reference on a node when it is
193 /// visible, which means the node is either in the toplevel or expanded.
194 /// Being displayed does not mean that the node is currently directly
195 /// visible to the user in the viewport. Based on this reference counting
196 /// scheme a caching model, for example, can decide whether or not to cache
197 /// a node based on the reference count. A file-system based model would
198 /// not want to keep the entire file hierarchy in memory, but just the
199 /// folders that are currently expanded in every current view.
200 ///
201 /// When working with reference counting, the following rules must be taken
202 /// into account:
203 ///
204 /// - Never take a reference on a node without owning a reference on its parent.
205 /// This means that all parent nodes of a referenced node must be referenced
206 /// as well.
207 ///
208 /// - Outstanding references on a deleted node are not released. This is not
209 /// possible because the node has already been deleted by the time the
210 /// row-deleted signal is received.
211 ///
212 /// - Models are not obligated to emit a signal on rows of which none of its
213 /// siblings are referenced. To phrase this differently, signals are only
214 /// required for levels in which nodes are referenced. For the root level
215 /// however, signals must be emitted at all times (however the root level
216 /// is always referenced when any view is attached).
217 ///
218 /// ## Signals
219 ///
220 ///
221 /// #### `row-changed`
222 /// This signal is emitted when a row in the model has changed.
223 ///
224 ///
225 ///
226 ///
227 /// #### `row-deleted`
228 /// This signal is emitted when a row has been deleted.
229 ///
230 /// Note that no iterator is passed to the signal handler,
231 /// since the row is already deleted.
232 ///
233 /// This should be called by models after a row has been removed.
234 /// The location pointed to by `path` should be the location that
235 /// the row previously was at. It may not be a valid location anymore.
236 ///
237 ///
238 ///
239 ///
240 /// #### `row-has-child-toggled`
241 /// This signal is emitted when a row has gotten the first child
242 /// row or lost its last child row.
243 ///
244 ///
245 ///
246 ///
247 /// #### `row-inserted`
248 /// This signal is emitted when a new row has been inserted in
249 /// the model.
250 ///
251 /// Note that the row may still be empty at this point, since
252 /// it is a common pattern to first insert an empty row, and
253 /// then fill it with the desired values.
254 ///
255 ///
256 ///
257 ///
258 /// #### `rows-reordered`
259 /// This signal is emitted when the children of a node in the
260 /// [`TreeModel`][crate::TreeModel] have been reordered.
261 ///
262 /// Note that this signal is not emitted
263 /// when rows are reordered by DND, since this is implemented
264 /// by removing and then reinserting the row.
265 ///
266 ///
267 ///
268 /// # Implements
269 ///
270 /// [`TreeModelExt`][trait@crate::prelude::TreeModelExt]
271 #[doc(alias = "GtkTreeModel")]
272 pub struct TreeModel(Interface<ffi::GtkTreeModel, ffi::GtkTreeModelIface>);
273
274 match fn {
275 type_ => || ffi::gtk_tree_model_get_type(),
276 }
277}
278
279impl TreeModel {
280 pub const NONE: Option<&'static TreeModel> = None;
281}
282
283/// Trait containing all [`struct@TreeModel`] methods.
284///
285/// # Implementors
286///
287/// [`ListStore`][struct@crate::ListStore], [`TreeModelFilter`][struct@crate::TreeModelFilter], [`TreeModelSort`][struct@crate::TreeModelSort], [`TreeModel`][struct@crate::TreeModel], [`TreeSortable`][struct@crate::TreeSortable], [`TreeStore`][struct@crate::TreeStore]
288pub trait TreeModelExt: IsA<TreeModel> + 'static {
289 /// Calls func on each node in model in a depth-first fashion.
290 ///
291 /// If `func` returns [`true`], then the tree ceases to be walked,
292 /// and [`foreach()`][Self::foreach()] returns.
293 /// ## `func`
294 /// a function to be called on each row
295 #[doc(alias = "gtk_tree_model_foreach")]
296 fn foreach<P: FnMut(&TreeModel, &TreePath, &TreeIter) -> bool>(&self, func: P) {
297 let mut func_data: P = func;
298 unsafe extern "C" fn func_func<P: FnMut(&TreeModel, &TreePath, &TreeIter) -> bool>(
299 model: *mut ffi::GtkTreeModel,
300 path: *mut ffi::GtkTreePath,
301 iter: *mut ffi::GtkTreeIter,
302 data: glib::ffi::gpointer,
303 ) -> glib::ffi::gboolean {
304 unsafe {
305 let model = from_glib_borrow(model);
306 let path = from_glib_borrow(path);
307 let iter = from_glib_borrow(iter);
308 let callback = data as *mut P;
309 (*callback)(&model, &path, &iter).into_glib()
310 }
311 }
312 let func = Some(func_func::<P> as _);
313 let super_callback0: &mut P = &mut func_data;
314 unsafe {
315 ffi::gtk_tree_model_foreach(
316 self.as_ref().to_glib_none().0,
317 func,
318 super_callback0 as *mut _ as *mut _,
319 );
320 }
321 }
322
323 //#[doc(alias = "gtk_tree_model_get")]
324 //fn get(&self, iter: &TreeIter, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) {
325 // unsafe { TODO: call ffi:gtk_tree_model_get() }
326 //}
327
328 /// Returns the type of the column.
329 /// ## `index_`
330 /// the column index
331 ///
332 /// # Returns
333 ///
334 /// the type of the column
335 #[doc(alias = "gtk_tree_model_get_column_type")]
336 #[doc(alias = "get_column_type")]
337 fn column_type(&self, index_: i32) -> glib::types::Type {
338 unsafe {
339 from_glib(ffi::gtk_tree_model_get_column_type(
340 self.as_ref().to_glib_none().0,
341 index_,
342 ))
343 }
344 }
345
346 /// Returns a set of flags supported by this interface.
347 ///
348 /// The flags are a bitwise combination of [`TreeModelFlags`][crate::TreeModelFlags].
349 /// The flags supported should not change during the lifetime
350 /// of the `self`.
351 ///
352 /// # Returns
353 ///
354 /// the flags supported by this interface
355 #[doc(alias = "gtk_tree_model_get_flags")]
356 #[doc(alias = "get_flags")]
357 fn flags(&self) -> TreeModelFlags {
358 unsafe {
359 from_glib(ffi::gtk_tree_model_get_flags(
360 self.as_ref().to_glib_none().0,
361 ))
362 }
363 }
364
365 /// Sets `iter` to a valid iterator pointing to `path`. If `path` does
366 /// not exist, `iter` is set to an invalid iterator and [`false`] is returned.
367 /// ## `path`
368 /// the [`TreePath`][crate::TreePath]-struct
369 ///
370 /// # Returns
371 ///
372 /// [`true`], if `iter` was set
373 ///
374 /// ## `iter`
375 /// the uninitialized [`TreeIter`][crate::TreeIter]-struct
376 #[doc(alias = "gtk_tree_model_get_iter")]
377 #[doc(alias = "get_iter")]
378 fn iter(&self, path: &TreePath) -> Option<TreeIter> {
379 unsafe {
380 let mut iter = TreeIter::uninitialized();
381 let ret = from_glib(ffi::gtk_tree_model_get_iter(
382 self.as_ref().to_glib_none().0,
383 iter.to_glib_none_mut().0,
384 mut_override(path.to_glib_none().0),
385 ));
386 if ret { Some(iter) } else { None }
387 }
388 }
389
390 /// Initializes `iter` with the first iterator in the tree
391 /// (the one at the path "0") and returns [`true`]. Returns
392 /// [`false`] if the tree is empty.
393 ///
394 /// # Returns
395 ///
396 /// [`true`], if `iter` was set
397 ///
398 /// ## `iter`
399 /// the uninitialized [`TreeIter`][crate::TreeIter]-struct
400 #[doc(alias = "gtk_tree_model_get_iter_first")]
401 #[doc(alias = "get_iter_first")]
402 fn iter_first(&self) -> Option<TreeIter> {
403 unsafe {
404 let mut iter = TreeIter::uninitialized();
405 let ret = from_glib(ffi::gtk_tree_model_get_iter_first(
406 self.as_ref().to_glib_none().0,
407 iter.to_glib_none_mut().0,
408 ));
409 if ret { Some(iter) } else { None }
410 }
411 }
412
413 /// Sets `iter` to a valid iterator pointing to `path_string`, if it
414 /// exists. Otherwise, `iter` is left invalid and [`false`] is returned.
415 /// ## `path_string`
416 /// a string representation of a [`TreePath`][crate::TreePath]-struct
417 ///
418 /// # Returns
419 ///
420 /// [`true`], if `iter` was set
421 ///
422 /// ## `iter`
423 /// an uninitialized [`TreeIter`][crate::TreeIter]-struct
424 #[doc(alias = "gtk_tree_model_get_iter_from_string")]
425 #[doc(alias = "get_iter_from_string")]
426 fn iter_from_string(&self, path_string: &str) -> Option<TreeIter> {
427 unsafe {
428 let mut iter = TreeIter::uninitialized();
429 let ret = from_glib(ffi::gtk_tree_model_get_iter_from_string(
430 self.as_ref().to_glib_none().0,
431 iter.to_glib_none_mut().0,
432 path_string.to_glib_none().0,
433 ));
434 if ret { Some(iter) } else { None }
435 }
436 }
437
438 /// Returns the number of columns supported by `self`.
439 ///
440 /// # Returns
441 ///
442 /// the number of columns
443 #[doc(alias = "gtk_tree_model_get_n_columns")]
444 #[doc(alias = "get_n_columns")]
445 fn n_columns(&self) -> i32 {
446 unsafe { ffi::gtk_tree_model_get_n_columns(self.as_ref().to_glib_none().0) }
447 }
448
449 /// Returns a newly-created [`TreePath`][crate::TreePath]-struct referenced by `iter`.
450 ///
451 /// This path should be freed with `gtk_tree_path_free()`.
452 /// ## `iter`
453 /// the [`TreeIter`][crate::TreeIter]-struct
454 ///
455 /// # Returns
456 ///
457 /// a newly-created [`TreePath`][crate::TreePath]-struct
458 #[doc(alias = "gtk_tree_model_get_path")]
459 #[doc(alias = "get_path")]
460 fn path(&self, iter: &TreeIter) -> Option<TreePath> {
461 unsafe {
462 from_glib_full(ffi::gtk_tree_model_get_path(
463 self.as_ref().to_glib_none().0,
464 mut_override(iter.to_glib_none().0),
465 ))
466 }
467 }
468
469 /// Generates a string representation of the iter.
470 ///
471 /// This string is a “:” separated list of numbers.
472 /// For example, “4:10:0:3” would be an acceptable
473 /// return value for this string.
474 /// ## `iter`
475 /// a [`TreeIter`][crate::TreeIter]-struct
476 ///
477 /// # Returns
478 ///
479 /// a newly-allocated string.
480 /// Must be freed with `g_free()`.
481 #[doc(alias = "gtk_tree_model_get_string_from_iter")]
482 #[doc(alias = "get_string_from_iter")]
483 fn string_from_iter(&self, iter: &TreeIter) -> Option<glib::GString> {
484 unsafe {
485 from_glib_full(ffi::gtk_tree_model_get_string_from_iter(
486 self.as_ref().to_glib_none().0,
487 mut_override(iter.to_glib_none().0),
488 ))
489 }
490 }
491
492 //#[doc(alias = "gtk_tree_model_get_valist")]
493 //#[doc(alias = "get_valist")]
494 //fn valist(&self, iter: &TreeIter, var_args: /*Unknown conversion*//*Unimplemented*/Unsupported) {
495 // unsafe { TODO: call ffi:gtk_tree_model_get_valist() }
496 //}
497
498 /// Initializes and sets `value` to that at `column`.
499 ///
500 /// When done with `value`, [`glib::Value::unset()`][crate::glib::Value::unset()] needs to be called
501 /// to free any allocated memory.
502 /// ## `iter`
503 /// the [`TreeIter`][crate::TreeIter]-struct
504 /// ## `column`
505 /// the column to lookup the value at
506 ///
507 /// # Returns
508 ///
509 ///
510 /// ## `value`
511 /// an empty [`glib::Value`][crate::glib::Value] to set
512 #[doc(alias = "gtk_tree_model_get_value")]
513 #[doc(alias = "get_value")]
514 fn value(&self, iter: &TreeIter, column: i32) -> glib::Value {
515 unsafe {
516 let mut value = glib::Value::uninitialized();
517 ffi::gtk_tree_model_get_value(
518 self.as_ref().to_glib_none().0,
519 mut_override(iter.to_glib_none().0),
520 column,
521 value.to_glib_none_mut().0,
522 );
523 value
524 }
525 }
526
527 /// Sets `iter` to point to the first child of `parent`.
528 ///
529 /// If `parent` has no children, [`false`] is returned and `iter` is
530 /// set to be invalid. `parent` will remain a valid node after this
531 /// function has been called.
532 ///
533 /// If `parent` is [`None`] returns the first node, equivalent to
534 /// `gtk_tree_model_get_iter_first (tree_model, iter);`
535 /// ## `parent`
536 /// the [`TreeIter`][crate::TreeIter]-struct, or [`None`]
537 ///
538 /// # Returns
539 ///
540 /// [`true`], if `iter` has been set to the first child
541 ///
542 /// ## `iter`
543 /// the new [`TreeIter`][crate::TreeIter]-struct to be set to the child
544 #[doc(alias = "gtk_tree_model_iter_children")]
545 fn iter_children(&self, parent: Option<&TreeIter>) -> Option<TreeIter> {
546 unsafe {
547 let mut iter = TreeIter::uninitialized();
548 let ret = from_glib(ffi::gtk_tree_model_iter_children(
549 self.as_ref().to_glib_none().0,
550 iter.to_glib_none_mut().0,
551 mut_override(parent.to_glib_none().0),
552 ));
553 if ret { Some(iter) } else { None }
554 }
555 }
556
557 /// Returns [`true`] if `iter` has children, [`false`] otherwise.
558 /// ## `iter`
559 /// the [`TreeIter`][crate::TreeIter]-struct to test for children
560 ///
561 /// # Returns
562 ///
563 /// [`true`] if `iter` has children
564 #[doc(alias = "gtk_tree_model_iter_has_child")]
565 fn iter_has_child(&self, iter: &TreeIter) -> bool {
566 unsafe {
567 from_glib(ffi::gtk_tree_model_iter_has_child(
568 self.as_ref().to_glib_none().0,
569 mut_override(iter.to_glib_none().0),
570 ))
571 }
572 }
573
574 /// Returns the number of children that `iter` has.
575 ///
576 /// As a special case, if `iter` is [`None`], then the number
577 /// of toplevel nodes is returned.
578 /// ## `iter`
579 /// the [`TreeIter`][crate::TreeIter]-struct, or [`None`]
580 ///
581 /// # Returns
582 ///
583 /// the number of children of `iter`
584 #[doc(alias = "gtk_tree_model_iter_n_children")]
585 fn iter_n_children(&self, iter: Option<&TreeIter>) -> i32 {
586 unsafe {
587 ffi::gtk_tree_model_iter_n_children(
588 self.as_ref().to_glib_none().0,
589 mut_override(iter.to_glib_none().0),
590 )
591 }
592 }
593
594 /// Sets `iter` to point to the node following it at the current level.
595 ///
596 /// If there is no next `iter`, [`false`] is returned and `iter` is set
597 /// to be invalid.
598 /// ## `iter`
599 /// the [`TreeIter`][crate::TreeIter]-struct
600 ///
601 /// # Returns
602 ///
603 /// [`true`] if `iter` has been changed to the next node
604 #[doc(alias = "gtk_tree_model_iter_next")]
605 fn iter_next(&self, iter: &TreeIter) -> bool {
606 unsafe {
607 from_glib(ffi::gtk_tree_model_iter_next(
608 self.as_ref().to_glib_none().0,
609 mut_override(iter.to_glib_none().0),
610 ))
611 }
612 }
613
614 /// Sets `iter` to be the child of `parent`, using the given index.
615 ///
616 /// The first index is 0. If `n` is too big, or `parent` has no children,
617 /// `iter` is set to an invalid iterator and [`false`] is returned. `parent`
618 /// will remain a valid node after this function has been called. As a
619 /// special case, if `parent` is [`None`], then the `n`-th root node
620 /// is set.
621 /// ## `parent`
622 /// the [`TreeIter`][crate::TreeIter]-struct to get the child from, or [`None`].
623 /// ## `n`
624 /// the index of the desired child
625 ///
626 /// # Returns
627 ///
628 /// [`true`], if `parent` has an `n`-th child
629 ///
630 /// ## `iter`
631 /// the [`TreeIter`][crate::TreeIter]-struct to set to the nth child
632 #[doc(alias = "gtk_tree_model_iter_nth_child")]
633 fn iter_nth_child(&self, parent: Option<&TreeIter>, n: i32) -> Option<TreeIter> {
634 unsafe {
635 let mut iter = TreeIter::uninitialized();
636 let ret = from_glib(ffi::gtk_tree_model_iter_nth_child(
637 self.as_ref().to_glib_none().0,
638 iter.to_glib_none_mut().0,
639 mut_override(parent.to_glib_none().0),
640 n,
641 ));
642 if ret { Some(iter) } else { None }
643 }
644 }
645
646 /// Sets `iter` to be the parent of `child`.
647 ///
648 /// If `child` is at the toplevel, and doesn’t have a parent, then
649 /// `iter` is set to an invalid iterator and [`false`] is returned.
650 /// `child` will remain a valid node after this function has been
651 /// called.
652 ///
653 /// `iter` will be initialized before the lookup is performed, so `child`
654 /// and `iter` cannot point to the same memory location.
655 /// ## `child`
656 /// the [`TreeIter`][crate::TreeIter]-struct
657 ///
658 /// # Returns
659 ///
660 /// [`true`], if `iter` is set to the parent of `child`
661 ///
662 /// ## `iter`
663 /// the new [`TreeIter`][crate::TreeIter]-struct to set to the parent
664 #[doc(alias = "gtk_tree_model_iter_parent")]
665 fn iter_parent(&self, child: &TreeIter) -> Option<TreeIter> {
666 unsafe {
667 let mut iter = TreeIter::uninitialized();
668 let ret = from_glib(ffi::gtk_tree_model_iter_parent(
669 self.as_ref().to_glib_none().0,
670 iter.to_glib_none_mut().0,
671 mut_override(child.to_glib_none().0),
672 ));
673 if ret { Some(iter) } else { None }
674 }
675 }
676
677 /// Sets `iter` to point to the previous node at the current level.
678 ///
679 /// If there is no previous `iter`, [`false`] is returned and `iter` is
680 /// set to be invalid.
681 /// ## `iter`
682 /// the [`TreeIter`][crate::TreeIter]-struct
683 ///
684 /// # Returns
685 ///
686 /// [`true`] if `iter` has been changed to the previous node
687 #[doc(alias = "gtk_tree_model_iter_previous")]
688 fn iter_previous(&self, iter: &TreeIter) -> bool {
689 unsafe {
690 from_glib(ffi::gtk_tree_model_iter_previous(
691 self.as_ref().to_glib_none().0,
692 mut_override(iter.to_glib_none().0),
693 ))
694 }
695 }
696
697 /// Emits the [`row-changed`][struct@crate::TreeModel#row-changed] signal on `self`.
698 /// ## `path`
699 /// a [`TreePath`][crate::TreePath]-struct pointing to the changed row
700 /// ## `iter`
701 /// a valid [`TreeIter`][crate::TreeIter]-struct pointing to the changed row
702 #[doc(alias = "gtk_tree_model_row_changed")]
703 fn row_changed(&self, path: &TreePath, iter: &TreeIter) {
704 unsafe {
705 ffi::gtk_tree_model_row_changed(
706 self.as_ref().to_glib_none().0,
707 mut_override(path.to_glib_none().0),
708 mut_override(iter.to_glib_none().0),
709 );
710 }
711 }
712
713 /// Emits the [`row-deleted`][struct@crate::TreeModel#row-deleted] signal on `self`.
714 ///
715 /// This should be called by models after a row has been removed.
716 /// The location pointed to by `path` should be the location that
717 /// the row previously was at. It may not be a valid location anymore.
718 ///
719 /// Nodes that are deleted are not unreffed, this means that any
720 /// outstanding references on the deleted node should not be released.
721 /// ## `path`
722 /// a [`TreePath`][crate::TreePath]-struct pointing to the previous location of
723 /// the deleted row
724 #[doc(alias = "gtk_tree_model_row_deleted")]
725 fn row_deleted(&self, path: &TreePath) {
726 unsafe {
727 ffi::gtk_tree_model_row_deleted(
728 self.as_ref().to_glib_none().0,
729 mut_override(path.to_glib_none().0),
730 );
731 }
732 }
733
734 /// Emits the [`row-has-child-toggled`][struct@crate::TreeModel#row-has-child-toggled] signal on
735 /// `self`. This should be called by models after the child
736 /// state of a node changes.
737 /// ## `path`
738 /// a [`TreePath`][crate::TreePath]-struct pointing to the changed row
739 /// ## `iter`
740 /// a valid [`TreeIter`][crate::TreeIter]-struct pointing to the changed row
741 #[doc(alias = "gtk_tree_model_row_has_child_toggled")]
742 fn row_has_child_toggled(&self, path: &TreePath, iter: &TreeIter) {
743 unsafe {
744 ffi::gtk_tree_model_row_has_child_toggled(
745 self.as_ref().to_glib_none().0,
746 mut_override(path.to_glib_none().0),
747 mut_override(iter.to_glib_none().0),
748 );
749 }
750 }
751
752 /// Emits the [`row-inserted`][struct@crate::TreeModel#row-inserted] signal on `self`.
753 /// ## `path`
754 /// a [`TreePath`][crate::TreePath]-struct pointing to the inserted row
755 /// ## `iter`
756 /// a valid [`TreeIter`][crate::TreeIter]-struct pointing to the inserted row
757 #[doc(alias = "gtk_tree_model_row_inserted")]
758 fn row_inserted(&self, path: &TreePath, iter: &TreeIter) {
759 unsafe {
760 ffi::gtk_tree_model_row_inserted(
761 self.as_ref().to_glib_none().0,
762 mut_override(path.to_glib_none().0),
763 mut_override(iter.to_glib_none().0),
764 );
765 }
766 }
767
768 /// Emits the [`rows-reordered`][struct@crate::TreeModel#rows-reordered] signal on `self`.
769 ///
770 /// This should be called by models when their rows have been
771 /// reordered.
772 /// ## `path`
773 /// a [`TreePath`][crate::TreePath]-struct pointing to the tree node whose children
774 /// have been reordered
775 /// ## `iter`
776 /// a valid [`TreeIter`][crate::TreeIter]-struct pointing to the node
777 /// whose children have been reordered, or [`None`] if the depth
778 /// of `path` is 0
779 /// ## `new_order`
780 /// an array of integers
781 /// mapping the current position of each child to its old
782 /// position before the re-ordering,
783 /// i.e. `new_order``[newpos] = oldpos`
784 #[doc(alias = "gtk_tree_model_rows_reordered_with_length")]
785 fn rows_reordered_with_length(
786 &self,
787 path: &TreePath,
788 iter: Option<&TreeIter>,
789 new_order: &[i32],
790 ) {
791 let length = new_order.len() as _;
792 unsafe {
793 ffi::gtk_tree_model_rows_reordered_with_length(
794 self.as_ref().to_glib_none().0,
795 mut_override(path.to_glib_none().0),
796 mut_override(iter.to_glib_none().0),
797 new_order.to_glib_none().0,
798 length,
799 );
800 }
801 }
802
803 /// This signal is emitted when a row in the model has changed.
804 /// ## `path`
805 /// a [`TreePath`][crate::TreePath]-struct identifying the changed row
806 /// ## `iter`
807 /// a valid [`TreeIter`][crate::TreeIter]-struct pointing to the changed row
808 #[doc(alias = "row-changed")]
809 fn connect_row_changed<F: Fn(&Self, &TreePath, &TreeIter) + 'static>(
810 &self,
811 f: F,
812 ) -> SignalHandlerId {
813 unsafe extern "C" fn row_changed_trampoline<
814 P: IsA<TreeModel>,
815 F: Fn(&P, &TreePath, &TreeIter) + 'static,
816 >(
817 this: *mut ffi::GtkTreeModel,
818 path: *mut ffi::GtkTreePath,
819 iter: *mut ffi::GtkTreeIter,
820 f: glib::ffi::gpointer,
821 ) {
822 unsafe {
823 let f: &F = &*(f as *const F);
824 f(
825 TreeModel::from_glib_borrow(this).unsafe_cast_ref(),
826 &from_glib_borrow(path),
827 &from_glib_borrow(iter),
828 )
829 }
830 }
831 unsafe {
832 let f: Box_<F> = Box_::new(f);
833 connect_raw(
834 self.as_ptr() as *mut _,
835 c"row-changed".as_ptr(),
836 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
837 row_changed_trampoline::<Self, F> as *const (),
838 )),
839 Box_::into_raw(f),
840 )
841 }
842 }
843
844 /// This signal is emitted when a row has been deleted.
845 ///
846 /// Note that no iterator is passed to the signal handler,
847 /// since the row is already deleted.
848 ///
849 /// This should be called by models after a row has been removed.
850 /// The location pointed to by `path` should be the location that
851 /// the row previously was at. It may not be a valid location anymore.
852 /// ## `path`
853 /// a [`TreePath`][crate::TreePath]-struct identifying the row
854 #[doc(alias = "row-deleted")]
855 fn connect_row_deleted<F: Fn(&Self, &TreePath) + 'static>(&self, f: F) -> SignalHandlerId {
856 unsafe extern "C" fn row_deleted_trampoline<
857 P: IsA<TreeModel>,
858 F: Fn(&P, &TreePath) + 'static,
859 >(
860 this: *mut ffi::GtkTreeModel,
861 path: *mut ffi::GtkTreePath,
862 f: glib::ffi::gpointer,
863 ) {
864 unsafe {
865 let f: &F = &*(f as *const F);
866 f(
867 TreeModel::from_glib_borrow(this).unsafe_cast_ref(),
868 &from_glib_borrow(path),
869 )
870 }
871 }
872 unsafe {
873 let f: Box_<F> = Box_::new(f);
874 connect_raw(
875 self.as_ptr() as *mut _,
876 c"row-deleted".as_ptr(),
877 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
878 row_deleted_trampoline::<Self, F> as *const (),
879 )),
880 Box_::into_raw(f),
881 )
882 }
883 }
884
885 /// This signal is emitted when a row has gotten the first child
886 /// row or lost its last child row.
887 /// ## `path`
888 /// a [`TreePath`][crate::TreePath]-struct identifying the row
889 /// ## `iter`
890 /// a valid [`TreeIter`][crate::TreeIter]-struct pointing to the row
891 #[doc(alias = "row-has-child-toggled")]
892 fn connect_row_has_child_toggled<F: Fn(&Self, &TreePath, &TreeIter) + 'static>(
893 &self,
894 f: F,
895 ) -> SignalHandlerId {
896 unsafe extern "C" fn row_has_child_toggled_trampoline<
897 P: IsA<TreeModel>,
898 F: Fn(&P, &TreePath, &TreeIter) + 'static,
899 >(
900 this: *mut ffi::GtkTreeModel,
901 path: *mut ffi::GtkTreePath,
902 iter: *mut ffi::GtkTreeIter,
903 f: glib::ffi::gpointer,
904 ) {
905 unsafe {
906 let f: &F = &*(f as *const F);
907 f(
908 TreeModel::from_glib_borrow(this).unsafe_cast_ref(),
909 &from_glib_borrow(path),
910 &from_glib_borrow(iter),
911 )
912 }
913 }
914 unsafe {
915 let f: Box_<F> = Box_::new(f);
916 connect_raw(
917 self.as_ptr() as *mut _,
918 c"row-has-child-toggled".as_ptr(),
919 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
920 row_has_child_toggled_trampoline::<Self, F> as *const (),
921 )),
922 Box_::into_raw(f),
923 )
924 }
925 }
926
927 /// This signal is emitted when a new row has been inserted in
928 /// the model.
929 ///
930 /// Note that the row may still be empty at this point, since
931 /// it is a common pattern to first insert an empty row, and
932 /// then fill it with the desired values.
933 /// ## `path`
934 /// a [`TreePath`][crate::TreePath]-struct identifying the new row
935 /// ## `iter`
936 /// a valid [`TreeIter`][crate::TreeIter]-struct pointing to the new row
937 #[doc(alias = "row-inserted")]
938 fn connect_row_inserted<F: Fn(&Self, &TreePath, &TreeIter) + 'static>(
939 &self,
940 f: F,
941 ) -> SignalHandlerId {
942 unsafe extern "C" fn row_inserted_trampoline<
943 P: IsA<TreeModel>,
944 F: Fn(&P, &TreePath, &TreeIter) + 'static,
945 >(
946 this: *mut ffi::GtkTreeModel,
947 path: *mut ffi::GtkTreePath,
948 iter: *mut ffi::GtkTreeIter,
949 f: glib::ffi::gpointer,
950 ) {
951 unsafe {
952 let f: &F = &*(f as *const F);
953 f(
954 TreeModel::from_glib_borrow(this).unsafe_cast_ref(),
955 &from_glib_borrow(path),
956 &from_glib_borrow(iter),
957 )
958 }
959 }
960 unsafe {
961 let f: Box_<F> = Box_::new(f);
962 connect_raw(
963 self.as_ptr() as *mut _,
964 c"row-inserted".as_ptr(),
965 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
966 row_inserted_trampoline::<Self, F> as *const (),
967 )),
968 Box_::into_raw(f),
969 )
970 }
971 }
972
973 //#[doc(alias = "rows-reordered")]
974 //fn connect_rows_reordered<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId {
975 // Unimplemented new_order: *.Pointer
976 //}
977}
978
979impl<O: IsA<TreeModel>> TreeModelExt for O {}