gtk4/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#![allow(deprecated)]
5
6use crate::{ffi, TreeIter, TreeModelFlags, TreePath};
7use glib::{
8 object::ObjectType as _,
9 prelude::*,
10 signal::{connect_raw, SignalHandlerId},
11 translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16 /// Use [`gio::ListModel`][crate::gio::ListModel] instead
17 /// The tree interface used by GtkTreeView
18 ///
19 /// The [`TreeModel`][crate::TreeModel] interface defines a generic tree interface for
20 /// use by the [`TreeView`][crate::TreeView] widget. It is an abstract interface, and
21 /// is designed to be usable with any appropriate data structure. The
22 /// programmer just has to implement this interface on their own data
23 /// type for it to be viewable by a [`TreeView`][crate::TreeView] widget.
24 ///
25 /// The model is represented as a hierarchical tree of strongly-typed,
26 /// columned data. In other words, the model can be seen as a tree where
27 /// every node has different values depending on which column is being
28 /// queried. The type of data found in a column is determined by using
29 /// the GType system (ie. `G_TYPE_INT`, `GTK_TYPE_BUTTON`, `G_TYPE_POINTER`,
30 /// etc). The types are homogeneous per column across all nodes. It is
31 /// important to note that this interface only provides a way of examining
32 /// a model and observing changes. The implementation of each individual
33 /// model decides how and if changes are made.
34 ///
35 /// In order to make life simpler for programmers who do not need to
36 /// write their own specialized model, two generic models are provided
37 /// — the [`TreeStore`][crate::TreeStore] and the [`ListStore`][crate::ListStore]. To use these, the
38 /// developer simply pushes data into these models as necessary. These
39 /// models provide the data structure as well as all appropriate tree
40 /// interfaces. As a result, implementing drag and drop, sorting, and
41 /// storing data is trivial. For the vast majority of trees and lists,
42 /// these two models are sufficient.
43 ///
44 /// Models are accessed on a node/column level of granularity. One can
45 /// query for the value of a model at a certain node and a certain
46 /// column on that node. There are two structures used to reference a
47 /// particular node in a model. They are the [`TreePath`][crate::TreePath] and
48 /// the [`TreeIter`][crate::TreeIter] (“iter” is short for iterator). Most of the
49 /// interface consists of operations on a [`TreeIter`][crate::TreeIter].
50 ///
51 /// A path is essentially a potential node. It is a location on a model
52 /// that may or may not actually correspond to a node on a specific
53 /// model. A [`TreePath`][crate::TreePath] can be converted into either an
54 /// array of unsigned integers or a string. The string form is a list
55 /// of numbers separated by a colon. Each number refers to the offset
56 /// at that level. Thus, the path `0` refers to the root
57 /// node and the path `2:4` refers to the fifth child of
58 /// the third node.
59 ///
60 /// By contrast, a [`TreeIter`][crate::TreeIter] is a reference to a specific node on
61 /// a specific model. It is a generic struct with an integer and three
62 /// generic pointers. These are filled in by the model in a model-specific
63 /// way. One can convert a path to an iterator by calling
64 /// gtk_tree_model_get_iter(). These iterators are the primary way
65 /// of accessing a model and are similar to the iterators used by
66 /// [`TextBuffer`][crate::TextBuffer]. They are generally statically allocated on the
67 /// stack and only used for a short time. The model interface defines
68 /// a set of operations using them for navigating the model.
69 ///
70 /// It is expected that models fill in the iterator with private data.
71 /// For example, the [`ListStore`][crate::ListStore] model, which is internally a simple
72 /// linked list, stores a list node in one of the pointers. The
73 /// [`TreeModel`][crate::TreeModel]Sort stores an array and an offset in two of the
74 /// pointers. Additionally, there is an integer field. This field is
75 /// generally filled with a unique stamp per model. This stamp is for
76 /// catching errors resulting from using invalid iterators with a model.
77 ///
78 /// The lifecycle of an iterator can be a little confusing at first.
79 /// Iterators are expected to always be valid for as long as the model
80 /// is unchanged (and doesn’t emit a signal). The model is considered
81 /// to own all outstanding iterators and nothing needs to be done to
82 /// free them from the user’s point of view. Additionally, some models
83 /// guarantee that an iterator is valid for as long as the node it refers
84 /// to is valid (most notably the [`TreeStore`][crate::TreeStore] and [`ListStore`][crate::ListStore]).
85 /// Although generally uninteresting, as one always has to allow for
86 /// the case where iterators do not persist beyond a signal, some very
87 /// important performance enhancements were made in the sort model.
88 /// As a result, the [`TreeModelFlags::ITERS_PERSIST`][crate::TreeModelFlags::ITERS_PERSIST] flag was added to
89 /// indicate this behavior.
90 ///
91 /// To help show some common operation of a model, some examples are
92 /// provided. The first example shows three ways of getting the iter at
93 /// the location `3:2:5`. While the first method shown is
94 /// easier, the second is much more common, as you often get paths from
95 /// callbacks.
96 ///
97 /// ## Acquiring a [`TreeIter`][crate::TreeIter]
98 ///
99 /// **⚠️ The following code is in c ⚠️**
100 ///
101 /// ```c
102 /// // Three ways of getting the iter pointing to the location
103 /// GtkTreePath *path;
104 /// GtkTreeIter iter;
105 /// GtkTreeIter parent_iter;
106 ///
107 /// // get the iterator from a string
108 /// gtk_tree_model_get_iter_from_string (model,
109 /// &iter,
110 /// "3:2:5");
111 ///
112 /// // get the iterator from a path
113 /// path = gtk_tree_path_new_from_string ("3:2:5");
114 /// gtk_tree_model_get_iter (model, &iter, path);
115 /// gtk_tree_path_free (path);
116 ///
117 /// // walk the tree to find the iterator
118 /// gtk_tree_model_iter_nth_child (model, &iter,
119 /// NULL, 3);
120 /// parent_iter = iter;
121 /// gtk_tree_model_iter_nth_child (model, &iter,
122 /// &parent_iter, 2);
123 /// parent_iter = iter;
124 /// gtk_tree_model_iter_nth_child (model, &iter,
125 /// &parent_iter, 5);
126 /// ```
127 ///
128 /// This second example shows a quick way of iterating through a list
129 /// and getting a string and an integer from each row. The
130 /// populate_model() function used below is not
131 /// shown, as it is specific to the [`ListStore`][crate::ListStore]. For information on
132 /// how to write such a function, see the [`ListStore`][crate::ListStore] documentation.
133 ///
134 /// ## Reading data from a [`TreeModel`][crate::TreeModel]
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 /// int 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 /// char *str_data;
169 /// int 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], [`TreeModelExtManual`][trait@crate::prelude::TreeModelExtManual]
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 gtk_tree_model_foreach() returns.
293 ///
294 /// # Deprecated since 4.10
295 ///
296 /// ## `func`
297 /// a function to be called on each row
298 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
299 #[allow(deprecated)]
300 #[doc(alias = "gtk_tree_model_foreach")]
301 fn foreach<P: FnMut(&TreeModel, &TreePath, &TreeIter) -> bool>(&self, func: P) {
302 let mut func_data: P = func;
303 unsafe extern "C" fn func_func<P: FnMut(&TreeModel, &TreePath, &TreeIter) -> bool>(
304 model: *mut ffi::GtkTreeModel,
305 path: *mut ffi::GtkTreePath,
306 iter: *mut ffi::GtkTreeIter,
307 data: glib::ffi::gpointer,
308 ) -> glib::ffi::gboolean {
309 let model = from_glib_borrow(model);
310 let path = from_glib_borrow(path);
311 let iter = from_glib_borrow(iter);
312 let callback = data as *mut P;
313 (*callback)(&model, &path, &iter).into_glib()
314 }
315 let func = Some(func_func::<P> as _);
316 let super_callback0: &mut P = &mut func_data;
317 unsafe {
318 ffi::gtk_tree_model_foreach(
319 self.as_ref().to_glib_none().0,
320 func,
321 super_callback0 as *mut _ as *mut _,
322 );
323 }
324 }
325
326 /// Returns the type of the column.
327 ///
328 /// # Deprecated since 4.10
329 ///
330 /// ## `index_`
331 /// the column index
332 ///
333 /// # Returns
334 ///
335 /// the type of the column
336 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
337 #[allow(deprecated)]
338 #[doc(alias = "gtk_tree_model_get_column_type")]
339 #[doc(alias = "get_column_type")]
340 fn column_type(&self, index_: i32) -> glib::types::Type {
341 unsafe {
342 from_glib(ffi::gtk_tree_model_get_column_type(
343 self.as_ref().to_glib_none().0,
344 index_,
345 ))
346 }
347 }
348
349 /// Returns a set of flags supported by this interface.
350 ///
351 /// The flags are a bitwise combination of [`TreeModel`][crate::TreeModel]Flags.
352 /// The flags supported should not change during the lifetime
353 /// of the @self.
354 ///
355 /// # Deprecated since 4.10
356 ///
357 ///
358 /// # Returns
359 ///
360 /// the flags supported by this interface
361 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
362 #[allow(deprecated)]
363 #[doc(alias = "gtk_tree_model_get_flags")]
364 #[doc(alias = "get_flags")]
365 fn flags(&self) -> TreeModelFlags {
366 unsafe {
367 from_glib(ffi::gtk_tree_model_get_flags(
368 self.as_ref().to_glib_none().0,
369 ))
370 }
371 }
372
373 /// Sets @iter to a valid iterator pointing to @path.
374 ///
375 /// If @path does not exist, @iter is set to an invalid
376 /// iterator and [`false`] is returned.
377 ///
378 /// # Deprecated since 4.10
379 ///
380 /// ## `path`
381 /// the [`TreePath`][crate::TreePath]
382 ///
383 /// # Returns
384 ///
385 /// [`true`], if @iter was set
386 ///
387 /// ## `iter`
388 /// the uninitialized [`TreeIter`][crate::TreeIter]
389 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
390 #[allow(deprecated)]
391 #[doc(alias = "gtk_tree_model_get_iter")]
392 #[doc(alias = "get_iter")]
393 fn iter(&self, path: &TreePath) -> Option<TreeIter> {
394 unsafe {
395 let mut iter = TreeIter::uninitialized();
396 let ret = from_glib(ffi::gtk_tree_model_get_iter(
397 self.as_ref().to_glib_none().0,
398 iter.to_glib_none_mut().0,
399 mut_override(path.to_glib_none().0),
400 ));
401 if ret {
402 Some(iter)
403 } else {
404 None
405 }
406 }
407 }
408
409 /// Initializes @iter with the first iterator in the tree
410 /// (the one at the path "0").
411 ///
412 /// Returns [`false`] if the tree is empty, [`true`] otherwise.
413 ///
414 /// # Deprecated since 4.10
415 ///
416 ///
417 /// # Returns
418 ///
419 /// [`true`], if @iter was set
420 ///
421 /// ## `iter`
422 /// the uninitialized [`TreeIter`][crate::TreeIter]
423 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
424 #[allow(deprecated)]
425 #[doc(alias = "gtk_tree_model_get_iter_first")]
426 #[doc(alias = "get_iter_first")]
427 fn iter_first(&self) -> Option<TreeIter> {
428 unsafe {
429 let mut iter = TreeIter::uninitialized();
430 let ret = from_glib(ffi::gtk_tree_model_get_iter_first(
431 self.as_ref().to_glib_none().0,
432 iter.to_glib_none_mut().0,
433 ));
434 if ret {
435 Some(iter)
436 } else {
437 None
438 }
439 }
440 }
441
442 /// Sets @iter to a valid iterator pointing to @path_string, if it
443 /// exists.
444 ///
445 /// Otherwise, @iter is left invalid and [`false`] is returned.
446 ///
447 /// # Deprecated since 4.10
448 ///
449 /// ## `path_string`
450 /// a string representation of a [`TreePath`][crate::TreePath]
451 ///
452 /// # Returns
453 ///
454 /// [`true`], if @iter was set
455 ///
456 /// ## `iter`
457 /// an uninitialized [`TreeIter`][crate::TreeIter]
458 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
459 #[allow(deprecated)]
460 #[doc(alias = "gtk_tree_model_get_iter_from_string")]
461 #[doc(alias = "get_iter_from_string")]
462 fn iter_from_string(&self, path_string: &str) -> Option<TreeIter> {
463 unsafe {
464 let mut iter = TreeIter::uninitialized();
465 let ret = from_glib(ffi::gtk_tree_model_get_iter_from_string(
466 self.as_ref().to_glib_none().0,
467 iter.to_glib_none_mut().0,
468 path_string.to_glib_none().0,
469 ));
470 if ret {
471 Some(iter)
472 } else {
473 None
474 }
475 }
476 }
477
478 /// Returns the number of columns supported by @self.
479 ///
480 /// # Deprecated since 4.10
481 ///
482 ///
483 /// # Returns
484 ///
485 /// the number of columns
486 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
487 #[allow(deprecated)]
488 #[doc(alias = "gtk_tree_model_get_n_columns")]
489 #[doc(alias = "get_n_columns")]
490 fn n_columns(&self) -> i32 {
491 unsafe { ffi::gtk_tree_model_get_n_columns(self.as_ref().to_glib_none().0) }
492 }
493
494 /// Returns a newly-created [`TreePath`][crate::TreePath] referenced by @iter.
495 ///
496 /// This path should be freed with gtk_tree_path_free().
497 ///
498 /// # Deprecated since 4.10
499 ///
500 /// ## `iter`
501 /// the [`TreeIter`][crate::TreeIter]
502 ///
503 /// # Returns
504 ///
505 /// a newly-created [`TreePath`][crate::TreePath]
506 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
507 #[allow(deprecated)]
508 #[doc(alias = "gtk_tree_model_get_path")]
509 #[doc(alias = "get_path")]
510 fn path(&self, iter: &TreeIter) -> TreePath {
511 unsafe {
512 from_glib_full(ffi::gtk_tree_model_get_path(
513 self.as_ref().to_glib_none().0,
514 mut_override(iter.to_glib_none().0),
515 ))
516 }
517 }
518
519 /// Generates a string representation of the iter.
520 ///
521 /// This string is a “:” separated list of numbers.
522 /// For example, “4:10:0:3” would be an acceptable
523 /// return value for this string.
524 ///
525 /// # Deprecated since 4.10
526 ///
527 /// ## `iter`
528 /// a [`TreeIter`][crate::TreeIter]
529 ///
530 /// # Returns
531 ///
532 /// a newly-allocated string
533 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
534 #[allow(deprecated)]
535 #[doc(alias = "gtk_tree_model_get_string_from_iter")]
536 #[doc(alias = "get_string_from_iter")]
537 fn string_from_iter(&self, iter: &TreeIter) -> Option<glib::GString> {
538 unsafe {
539 from_glib_full(ffi::gtk_tree_model_get_string_from_iter(
540 self.as_ref().to_glib_none().0,
541 mut_override(iter.to_glib_none().0),
542 ))
543 }
544 }
545
546 /// Sets @iter to point to the first child of @parent.
547 ///
548 /// If @parent has no children, [`false`] is returned and @iter is
549 /// set to be invalid. @parent will remain a valid node after this
550 /// function has been called.
551 ///
552 /// If @parent is [`None`] returns the first node, equivalent to
553 /// `gtk_tree_model_get_iter_first (tree_model, iter);`
554 ///
555 /// # Deprecated since 4.10
556 ///
557 /// ## `parent`
558 /// the [`TreeIter`][crate::TreeIter]
559 ///
560 /// # Returns
561 ///
562 /// [`true`], if @iter has been set to the first child
563 ///
564 /// ## `iter`
565 /// the new [`TreeIter`][crate::TreeIter] to be set to the child
566 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
567 #[allow(deprecated)]
568 #[doc(alias = "gtk_tree_model_iter_children")]
569 fn iter_children(&self, parent: Option<&TreeIter>) -> Option<TreeIter> {
570 unsafe {
571 let mut iter = TreeIter::uninitialized();
572 let ret = from_glib(ffi::gtk_tree_model_iter_children(
573 self.as_ref().to_glib_none().0,
574 iter.to_glib_none_mut().0,
575 mut_override(parent.to_glib_none().0),
576 ));
577 if ret {
578 Some(iter)
579 } else {
580 None
581 }
582 }
583 }
584
585 /// Returns [`true`] if @iter has children, [`false`] otherwise.
586 ///
587 /// # Deprecated since 4.10
588 ///
589 /// ## `iter`
590 /// the [`TreeIter`][crate::TreeIter] to test for children
591 ///
592 /// # Returns
593 ///
594 /// [`true`] if @iter has children
595 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
596 #[allow(deprecated)]
597 #[doc(alias = "gtk_tree_model_iter_has_child")]
598 fn iter_has_child(&self, iter: &TreeIter) -> bool {
599 unsafe {
600 from_glib(ffi::gtk_tree_model_iter_has_child(
601 self.as_ref().to_glib_none().0,
602 mut_override(iter.to_glib_none().0),
603 ))
604 }
605 }
606
607 /// Returns the number of children that @iter has.
608 ///
609 /// As a special case, if @iter is [`None`], then the number
610 /// of toplevel nodes is returned.
611 ///
612 /// # Deprecated since 4.10
613 ///
614 /// ## `iter`
615 /// the [`TreeIter`][crate::TreeIter]
616 ///
617 /// # Returns
618 ///
619 /// the number of children of @iter
620 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
621 #[allow(deprecated)]
622 #[doc(alias = "gtk_tree_model_iter_n_children")]
623 fn iter_n_children(&self, iter: Option<&TreeIter>) -> i32 {
624 unsafe {
625 ffi::gtk_tree_model_iter_n_children(
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 ///
640 /// # Deprecated since 4.10
641 ///
642 /// ## `parent`
643 /// the [`TreeIter`][crate::TreeIter] to get the child from
644 /// ## `n`
645 /// the index of the desired child
646 ///
647 /// # Returns
648 ///
649 /// [`true`], if @parent has an @n-th child
650 ///
651 /// ## `iter`
652 /// the [`TreeIter`][crate::TreeIter] to set to the nth child
653 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
654 #[allow(deprecated)]
655 #[doc(alias = "gtk_tree_model_iter_nth_child")]
656 fn iter_nth_child(&self, parent: Option<&TreeIter>, n: i32) -> Option<TreeIter> {
657 unsafe {
658 let mut iter = TreeIter::uninitialized();
659 let ret = from_glib(ffi::gtk_tree_model_iter_nth_child(
660 self.as_ref().to_glib_none().0,
661 iter.to_glib_none_mut().0,
662 mut_override(parent.to_glib_none().0),
663 n,
664 ));
665 if ret {
666 Some(iter)
667 } else {
668 None
669 }
670 }
671 }
672
673 /// Sets @iter to be the parent of @child.
674 ///
675 /// If @child is at the toplevel, and doesn’t have a parent, then
676 /// @iter is set to an invalid iterator and [`false`] is returned.
677 /// @child will remain a valid node after this function has been
678 /// called.
679 ///
680 /// @iter will be initialized before the lookup is performed, so @child
681 /// and @iter cannot point to the same memory location.
682 ///
683 /// # Deprecated since 4.10
684 ///
685 /// ## `child`
686 /// the [`TreeIter`][crate::TreeIter]
687 ///
688 /// # Returns
689 ///
690 /// [`true`], if @iter is set to the parent of @child
691 ///
692 /// ## `iter`
693 /// the new [`TreeIter`][crate::TreeIter] to set to the parent
694 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
695 #[allow(deprecated)]
696 #[doc(alias = "gtk_tree_model_iter_parent")]
697 fn iter_parent(&self, child: &TreeIter) -> Option<TreeIter> {
698 unsafe {
699 let mut iter = TreeIter::uninitialized();
700 let ret = from_glib(ffi::gtk_tree_model_iter_parent(
701 self.as_ref().to_glib_none().0,
702 iter.to_glib_none_mut().0,
703 mut_override(child.to_glib_none().0),
704 ));
705 if ret {
706 Some(iter)
707 } else {
708 None
709 }
710 }
711 }
712
713 /// Sets @iter to point to the previous node at the current level.
714 ///
715 /// If there is no previous @iter, [`false`] is returned and @iter is
716 /// set to be invalid.
717 ///
718 /// # Deprecated since 4.10
719 ///
720 /// ## `iter`
721 /// the [`TreeIter`][crate::TreeIter]
722 ///
723 /// # Returns
724 ///
725 /// [`true`] if @iter has been changed to the previous node
726 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
727 #[allow(deprecated)]
728 #[doc(alias = "gtk_tree_model_iter_previous")]
729 fn iter_previous(&self, iter: &TreeIter) -> bool {
730 unsafe {
731 from_glib(ffi::gtk_tree_model_iter_previous(
732 self.as_ref().to_glib_none().0,
733 mut_override(iter.to_glib_none().0),
734 ))
735 }
736 }
737
738 /// Emits the ::row-changed signal on @self.
739 ///
740 /// See [`row-changed`][struct@crate::TreeModel#row-changed].
741 ///
742 /// # Deprecated since 4.10
743 ///
744 /// ## `path`
745 /// a [`TreePath`][crate::TreePath] pointing to the changed row
746 /// ## `iter`
747 /// a valid [`TreeIter`][crate::TreeIter] pointing to the changed row
748 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
749 #[allow(deprecated)]
750 #[doc(alias = "gtk_tree_model_row_changed")]
751 fn row_changed(&self, path: &TreePath, iter: &TreeIter) {
752 unsafe {
753 ffi::gtk_tree_model_row_changed(
754 self.as_ref().to_glib_none().0,
755 mut_override(path.to_glib_none().0),
756 mut_override(iter.to_glib_none().0),
757 );
758 }
759 }
760
761 /// Emits the ::row-deleted signal on @self.
762 ///
763 /// See [`row-deleted`][struct@crate::TreeModel#row-deleted].
764 ///
765 /// This should be called by models after a row has been removed.
766 /// The location pointed to by @path should be the location that
767 /// the row previously was at. It may not be a valid location anymore.
768 ///
769 /// Nodes that are deleted are not unreffed, this means that any
770 /// outstanding references on the deleted node should not be released.
771 ///
772 /// # Deprecated since 4.10
773 ///
774 /// ## `path`
775 /// a [`TreePath`][crate::TreePath] pointing to the previous location of
776 /// the deleted row
777 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
778 #[allow(deprecated)]
779 #[doc(alias = "gtk_tree_model_row_deleted")]
780 fn row_deleted(&self, path: &TreePath) {
781 unsafe {
782 ffi::gtk_tree_model_row_deleted(
783 self.as_ref().to_glib_none().0,
784 mut_override(path.to_glib_none().0),
785 );
786 }
787 }
788
789 /// Emits the ::row-has-child-toggled signal on @self.
790 ///
791 /// See [`row-has-child-toggled`][struct@crate::TreeModel#row-has-child-toggled].
792 ///
793 /// This should be called by models after the child
794 /// state of a node changes.
795 ///
796 /// # Deprecated since 4.10
797 ///
798 /// ## `path`
799 /// a [`TreePath`][crate::TreePath] pointing to the changed row
800 /// ## `iter`
801 /// a valid [`TreeIter`][crate::TreeIter] pointing to the changed row
802 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
803 #[allow(deprecated)]
804 #[doc(alias = "gtk_tree_model_row_has_child_toggled")]
805 fn row_has_child_toggled(&self, path: &TreePath, iter: &TreeIter) {
806 unsafe {
807 ffi::gtk_tree_model_row_has_child_toggled(
808 self.as_ref().to_glib_none().0,
809 mut_override(path.to_glib_none().0),
810 mut_override(iter.to_glib_none().0),
811 );
812 }
813 }
814
815 /// Emits the ::row-inserted signal on @self.
816 ///
817 /// See [`row-inserted`][struct@crate::TreeModel#row-inserted].
818 ///
819 /// # Deprecated since 4.10
820 ///
821 /// ## `path`
822 /// a [`TreePath`][crate::TreePath] pointing to the inserted row
823 /// ## `iter`
824 /// a valid [`TreeIter`][crate::TreeIter] pointing to the inserted row
825 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
826 #[allow(deprecated)]
827 #[doc(alias = "gtk_tree_model_row_inserted")]
828 fn row_inserted(&self, path: &TreePath, iter: &TreeIter) {
829 unsafe {
830 ffi::gtk_tree_model_row_inserted(
831 self.as_ref().to_glib_none().0,
832 mut_override(path.to_glib_none().0),
833 mut_override(iter.to_glib_none().0),
834 );
835 }
836 }
837
838 /// This signal is emitted when a row in the model has changed.
839 /// ## `path`
840 /// a [`TreePath`][crate::TreePath] identifying the changed row
841 /// ## `iter`
842 /// a valid [`TreeIter`][crate::TreeIter] pointing to the changed row
843 #[doc(alias = "row-changed")]
844 fn connect_row_changed<F: Fn(&Self, &TreePath, &TreeIter) + 'static>(
845 &self,
846 f: F,
847 ) -> SignalHandlerId {
848 unsafe extern "C" fn row_changed_trampoline<
849 P: IsA<TreeModel>,
850 F: Fn(&P, &TreePath, &TreeIter) + 'static,
851 >(
852 this: *mut ffi::GtkTreeModel,
853 path: *mut ffi::GtkTreePath,
854 iter: *mut ffi::GtkTreeIter,
855 f: glib::ffi::gpointer,
856 ) {
857 let f: &F = &*(f as *const F);
858 f(
859 TreeModel::from_glib_borrow(this).unsafe_cast_ref(),
860 &from_glib_borrow(path),
861 &from_glib_borrow(iter),
862 )
863 }
864 unsafe {
865 let f: Box_<F> = Box_::new(f);
866 connect_raw(
867 self.as_ptr() as *mut _,
868 c"row-changed".as_ptr() as *const _,
869 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
870 row_changed_trampoline::<Self, F> as *const (),
871 )),
872 Box_::into_raw(f),
873 )
874 }
875 }
876
877 /// This signal is emitted when a row has been deleted.
878 ///
879 /// Note that no iterator is passed to the signal handler,
880 /// since the row is already deleted.
881 ///
882 /// This should be called by models after a row has been removed.
883 /// The location pointed to by @path should be the location that
884 /// the row previously was at. It may not be a valid location anymore.
885 /// ## `path`
886 /// a [`TreePath`][crate::TreePath] identifying the row
887 #[doc(alias = "row-deleted")]
888 fn connect_row_deleted<F: Fn(&Self, &TreePath) + 'static>(&self, f: F) -> SignalHandlerId {
889 unsafe extern "C" fn row_deleted_trampoline<
890 P: IsA<TreeModel>,
891 F: Fn(&P, &TreePath) + 'static,
892 >(
893 this: *mut ffi::GtkTreeModel,
894 path: *mut ffi::GtkTreePath,
895 f: glib::ffi::gpointer,
896 ) {
897 let f: &F = &*(f as *const F);
898 f(
899 TreeModel::from_glib_borrow(this).unsafe_cast_ref(),
900 &from_glib_borrow(path),
901 )
902 }
903 unsafe {
904 let f: Box_<F> = Box_::new(f);
905 connect_raw(
906 self.as_ptr() as *mut _,
907 c"row-deleted".as_ptr() as *const _,
908 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
909 row_deleted_trampoline::<Self, F> as *const (),
910 )),
911 Box_::into_raw(f),
912 )
913 }
914 }
915
916 /// This signal is emitted when a row has gotten the first child
917 /// row or lost its last child row.
918 /// ## `path`
919 /// a [`TreePath`][crate::TreePath] identifying the row
920 /// ## `iter`
921 /// a valid [`TreeIter`][crate::TreeIter] pointing to the row
922 #[doc(alias = "row-has-child-toggled")]
923 fn connect_row_has_child_toggled<F: Fn(&Self, &TreePath, &TreeIter) + 'static>(
924 &self,
925 f: F,
926 ) -> SignalHandlerId {
927 unsafe extern "C" fn row_has_child_toggled_trampoline<
928 P: IsA<TreeModel>,
929 F: Fn(&P, &TreePath, &TreeIter) + 'static,
930 >(
931 this: *mut ffi::GtkTreeModel,
932 path: *mut ffi::GtkTreePath,
933 iter: *mut ffi::GtkTreeIter,
934 f: glib::ffi::gpointer,
935 ) {
936 let f: &F = &*(f as *const F);
937 f(
938 TreeModel::from_glib_borrow(this).unsafe_cast_ref(),
939 &from_glib_borrow(path),
940 &from_glib_borrow(iter),
941 )
942 }
943 unsafe {
944 let f: Box_<F> = Box_::new(f);
945 connect_raw(
946 self.as_ptr() as *mut _,
947 c"row-has-child-toggled".as_ptr() as *const _,
948 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
949 row_has_child_toggled_trampoline::<Self, F> as *const (),
950 )),
951 Box_::into_raw(f),
952 )
953 }
954 }
955
956 /// This signal is emitted when a new row has been inserted in
957 /// the model.
958 ///
959 /// Note that the row may still be empty at this point, since
960 /// it is a common pattern to first insert an empty row, and
961 /// then fill it with the desired values.
962 /// ## `path`
963 /// a [`TreePath`][crate::TreePath] identifying the new row
964 /// ## `iter`
965 /// a valid [`TreeIter`][crate::TreeIter] pointing to the new row
966 #[doc(alias = "row-inserted")]
967 fn connect_row_inserted<F: Fn(&Self, &TreePath, &TreeIter) + 'static>(
968 &self,
969 f: F,
970 ) -> SignalHandlerId {
971 unsafe extern "C" fn row_inserted_trampoline<
972 P: IsA<TreeModel>,
973 F: Fn(&P, &TreePath, &TreeIter) + 'static,
974 >(
975 this: *mut ffi::GtkTreeModel,
976 path: *mut ffi::GtkTreePath,
977 iter: *mut ffi::GtkTreeIter,
978 f: glib::ffi::gpointer,
979 ) {
980 let f: &F = &*(f as *const F);
981 f(
982 TreeModel::from_glib_borrow(this).unsafe_cast_ref(),
983 &from_glib_borrow(path),
984 &from_glib_borrow(iter),
985 )
986 }
987 unsafe {
988 let f: Box_<F> = Box_::new(f);
989 connect_raw(
990 self.as_ptr() as *mut _,
991 c"row-inserted".as_ptr() as *const _,
992 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
993 row_inserted_trampoline::<Self, F> as *const (),
994 )),
995 Box_::into_raw(f),
996 )
997 }
998 }
999
1000 //#[doc(alias = "rows-reordered")]
1001 //fn connect_rows_reordered<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId {
1002 // Unimplemented new_order: *.Pointer
1003 //}
1004}
1005
1006impl<O: IsA<TreeModel>> TreeModelExt for O {}