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