gtk/auto/tree_row_reference.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::{TreeModel, TreePath};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9 /// A GtkTreeRowReference tracks model changes so that it always refers to the
10 /// same row (a [`TreePath`][crate::TreePath] refers to a position, not a fixed row). Create a
11 /// new GtkTreeRowReference with [`new()`][Self::new()].
12 #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
13 pub struct TreeRowReference(Boxed<ffi::GtkTreeRowReference>);
14
15 match fn {
16 copy => |ptr| ffi::gtk_tree_row_reference_copy(mut_override(ptr)),
17 free => |ptr| ffi::gtk_tree_row_reference_free(ptr),
18 type_ => || ffi::gtk_tree_row_reference_get_type(),
19 }
20}
21
22impl TreeRowReference {
23 /// Creates a row reference based on `path`.
24 ///
25 /// This reference will keep pointing to the node pointed to
26 /// by `path`, so long as it exists. Any changes that occur on `model` are
27 /// propagated, and the path is updated appropriately. If
28 /// `path` isn’t a valid path in `model`, then [`None`] is returned.
29 /// ## `model`
30 /// a [`TreeModel`][crate::TreeModel]
31 /// ## `path`
32 /// a valid [`TreePath`][crate::TreePath]-struct to monitor
33 ///
34 /// # Returns
35 ///
36 /// a newly allocated [`TreeRowReference`][crate::TreeRowReference], or [`None`]
37 #[doc(alias = "gtk_tree_row_reference_new")]
38 pub fn new(model: &impl IsA<TreeModel>, path: &TreePath) -> Option<TreeRowReference> {
39 skip_assert_initialized!();
40 unsafe {
41 from_glib_full(ffi::gtk_tree_row_reference_new(
42 model.as_ref().to_glib_none().0,
43 mut_override(path.to_glib_none().0),
44 ))
45 }
46 }
47
48 /// You do not need to use this function.
49 ///
50 /// Creates a row reference based on `path`.
51 ///
52 /// This reference will keep pointing to the node pointed to
53 /// by `path`, so long as it exists. If `path` isn’t a valid
54 /// path in `model`, then [`None`] is returned. However, unlike
55 /// references created with [`new()`][Self::new()], it
56 /// does not listen to the model for changes. The creator of
57 /// the row reference must do this explicitly using
58 /// [`inserted()`][Self::inserted()], [`deleted()`][Self::deleted()],
59 /// `gtk_tree_row_reference_reordered()`.
60 ///
61 /// These functions must be called exactly once per proxy when the
62 /// corresponding signal on the model is emitted. This single call
63 /// updates all row references for that proxy. Since built-in GTK+
64 /// objects like [`TreeView`][crate::TreeView] already use this mechanism internally,
65 /// using them as the proxy object will produce unpredictable results.
66 /// Further more, passing the same object as `model` and `proxy`
67 /// doesn’t work for reasons of internal implementation.
68 ///
69 /// This type of row reference is primarily meant by structures that
70 /// need to carefully monitor exactly when a row reference updates
71 /// itself, and is not generally needed by most applications.
72 /// ## `proxy`
73 /// a proxy [`glib::Object`][crate::glib::Object]
74 /// ## `model`
75 /// a [`TreeModel`][crate::TreeModel]
76 /// ## `path`
77 /// a valid [`TreePath`][crate::TreePath]-struct to monitor
78 ///
79 /// # Returns
80 ///
81 /// a newly allocated [`TreeRowReference`][crate::TreeRowReference], or [`None`]
82 #[doc(alias = "gtk_tree_row_reference_new_proxy")]
83 pub fn new_proxy(
84 proxy: &impl IsA<glib::Object>,
85 model: &impl IsA<TreeModel>,
86 path: &TreePath,
87 ) -> Option<TreeRowReference> {
88 skip_assert_initialized!();
89 unsafe {
90 from_glib_full(ffi::gtk_tree_row_reference_new_proxy(
91 proxy.as_ref().to_glib_none().0,
92 model.as_ref().to_glib_none().0,
93 mut_override(path.to_glib_none().0),
94 ))
95 }
96 }
97
98 /// Returns the model that the row reference is monitoring.
99 ///
100 /// # Returns
101 ///
102 /// the model
103 #[doc(alias = "gtk_tree_row_reference_get_model")]
104 #[doc(alias = "get_model")]
105 pub fn model(&self) -> TreeModel {
106 unsafe {
107 from_glib_none(ffi::gtk_tree_row_reference_get_model(mut_override(
108 self.to_glib_none().0,
109 )))
110 }
111 }
112
113 /// Returns a path that the row reference currently points to,
114 /// or [`None`] if the path pointed to is no longer valid.
115 ///
116 /// # Returns
117 ///
118 /// a current path, or [`None`]
119 #[doc(alias = "gtk_tree_row_reference_get_path")]
120 #[doc(alias = "get_path")]
121 pub fn path(&self) -> Option<TreePath> {
122 unsafe {
123 from_glib_full(ffi::gtk_tree_row_reference_get_path(mut_override(
124 self.to_glib_none().0,
125 )))
126 }
127 }
128
129 /// Returns [`true`] if the `self` is non-[`None`] and refers to
130 /// a current valid path.
131 ///
132 /// # Returns
133 ///
134 /// [`true`] if `self` points to a valid path
135 #[doc(alias = "gtk_tree_row_reference_valid")]
136 pub fn valid(&self) -> bool {
137 unsafe {
138 from_glib(ffi::gtk_tree_row_reference_valid(mut_override(
139 self.to_glib_none().0,
140 )))
141 }
142 }
143
144 /// Lets a set of row reference created by
145 /// [`new_proxy()`][Self::new_proxy()] know that the
146 /// model emitted the [`row-deleted`][struct@crate::TreeModel#row-deleted] signal.
147 /// ## `proxy`
148 /// a [`glib::Object`][crate::glib::Object]
149 /// ## `path`
150 /// the path position that was deleted
151 #[doc(alias = "gtk_tree_row_reference_deleted")]
152 pub fn deleted(proxy: &impl IsA<glib::Object>, path: &TreePath) {
153 assert_initialized_main_thread!();
154 unsafe {
155 ffi::gtk_tree_row_reference_deleted(
156 proxy.as_ref().to_glib_none().0,
157 mut_override(path.to_glib_none().0),
158 );
159 }
160 }
161
162 /// Lets a set of row reference created by
163 /// [`new_proxy()`][Self::new_proxy()] know that the
164 /// model emitted the [`row-inserted`][struct@crate::TreeModel#row-inserted] signal.
165 /// ## `proxy`
166 /// a [`glib::Object`][crate::glib::Object]
167 /// ## `path`
168 /// the row position that was inserted
169 #[doc(alias = "gtk_tree_row_reference_inserted")]
170 pub fn inserted(proxy: &impl IsA<glib::Object>, path: &TreePath) {
171 assert_initialized_main_thread!();
172 unsafe {
173 ffi::gtk_tree_row_reference_inserted(
174 proxy.as_ref().to_glib_none().0,
175 mut_override(path.to_glib_none().0),
176 );
177 }
178 }
179
180 //#[doc(alias = "gtk_tree_row_reference_reordered")]
181 //pub fn reordered(proxy: &impl IsA<glib::Object>, path: &mut TreePath, iter: &mut TreeIter, new_order: &[i32]) {
182 // unsafe { TODO: call ffi:gtk_tree_row_reference_reordered() }
183 //}
184}