gtk/auto/list_store.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{Buildable, TreeDragDest, TreeDragSource, TreeIter, TreeModel, TreeSortable, ffi};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9 /// The [`ListStore`][crate::ListStore] object is a list model for use with a [`TreeView`][crate::TreeView]
10 /// widget. It implements the [`TreeModel`][crate::TreeModel] interface, and consequentialy,
11 /// can use all of the methods available there. It also implements the
12 /// [`TreeSortable`][crate::TreeSortable] interface so it can be sorted by the view.
13 /// Finally, it also implements the tree
14 /// [drag and drop][gtk3-GtkTreeView-drag-and-drop]
15 /// interfaces.
16 ///
17 /// The [`ListStore`][crate::ListStore] can accept most GObject types as a column type, though
18 /// it can’t accept all custom types. Internally, it will keep a copy of
19 /// data passed in (such as a string or a boxed pointer). Columns that
20 /// accept `GObjects` are handled a little differently. The
21 /// [`ListStore`][crate::ListStore] will keep a reference to the object instead of copying the
22 /// value. As a result, if the object is modified, it is up to the
23 /// application writer to call [`TreeModelExt::row_changed()`][crate::prelude::TreeModelExt::row_changed()] to emit the
24 /// [`row_changed`][struct@crate::TreeModel#row_changed] signal. This most commonly affects lists with
25 /// `GdkPixbufs` stored.
26 ///
27 /// An example for creating a simple list store:
28 ///
29 ///
30 ///
31 /// **⚠️ The following code is in C ⚠️**
32 ///
33 /// ```C
34 /// enum {
35 /// COLUMN_STRING,
36 /// COLUMN_INT,
37 /// COLUMN_BOOLEAN,
38 /// N_COLUMNS
39 /// };
40 ///
41 /// {
42 /// GtkListStore *list_store;
43 /// GtkTreePath *path;
44 /// GtkTreeIter iter;
45 /// gint i;
46 ///
47 /// list_store = gtk_list_store_new (N_COLUMNS,
48 /// G_TYPE_STRING,
49 /// G_TYPE_INT,
50 /// G_TYPE_BOOLEAN);
51 ///
52 /// for (i = 0; i < 10; i++)
53 /// {
54 /// gchar *some_data;
55 ///
56 /// some_data = get_some_data (i);
57 ///
58 /// // Add a new row to the model
59 /// gtk_list_store_append (list_store, &iter);
60 /// gtk_list_store_set (list_store, &iter,
61 /// COLUMN_STRING, some_data,
62 /// COLUMN_INT, i,
63 /// COLUMN_BOOLEAN, FALSE,
64 /// -1);
65 ///
66 /// // As the store will keep a copy of the string internally,
67 /// // we free some_data.
68 /// g_free (some_data);
69 /// }
70 ///
71 /// // Modify a particular row
72 /// path = gtk_tree_path_new_from_string ("4");
73 /// gtk_tree_model_get_iter (GTK_TREE_MODEL (list_store),
74 /// &iter,
75 /// path);
76 /// gtk_tree_path_free (path);
77 /// gtk_list_store_set (list_store, &iter,
78 /// COLUMN_BOOLEAN, TRUE,
79 /// -1);
80 /// }
81 /// ```
82 ///
83 /// # Performance Considerations
84 ///
85 /// Internally, the [`ListStore`][crate::ListStore] was implemented with a linked list with
86 /// a tail pointer prior to GTK+ 2.6. As a result, it was fast at data
87 /// insertion and deletion, and not fast at random data access. The
88 /// [`ListStore`][crate::ListStore] sets the [`TreeModelFlags::ITERS_PERSIST`][crate::TreeModelFlags::ITERS_PERSIST] flag, which means
89 /// that `GtkTreeIters` can be cached while the row exists. Thus, if
90 /// access to a particular row is needed often and your code is expected to
91 /// run on older versions of GTK+, it is worth keeping the iter around.
92 ///
93 /// # Atomic Operations
94 ///
95 /// It is important to note that only the methods
96 /// `gtk_list_store_insert_with_values()` and `gtk_list_store_insert_with_valuesv()`
97 /// are atomic, in the sense that the row is being appended to the store and the
98 /// values filled in in a single operation with regard to [`TreeModel`][crate::TreeModel] signaling.
99 /// In contrast, using e.g. [`GtkListStoreExt::append()`][crate::prelude::GtkListStoreExt::append()] and then [`GtkListStoreExtManual::set()`][crate::prelude::GtkListStoreExtManual::set()]
100 /// will first create a row, which triggers the [`row-inserted`][struct@crate::TreeModel#row-inserted] signal
101 /// on [`ListStore`][crate::ListStore]. The row, however, is still empty, and any signal handler
102 /// connecting to [`row-inserted`][struct@crate::TreeModel#row-inserted] on this particular store should be prepared
103 /// for the situation that the row might be empty. This is especially important
104 /// if you are wrapping the [`ListStore`][crate::ListStore] inside a [`TreeModelFilter`][crate::TreeModelFilter] and are
105 /// using a `GtkTreeModelFilterVisibleFunc`. Using any of the non-atomic operations
106 /// to append rows to the [`ListStore`][crate::ListStore] will cause the
107 /// `GtkTreeModelFilterVisibleFunc` to be visited with an empty row first; the
108 /// function must be prepared for that.
109 ///
110 /// # GtkListStore as GtkBuildable
111 ///
112 /// The GtkListStore implementation of the GtkBuildable interface allows
113 /// to specify the model columns with a ``<columns>`` element that may contain
114 /// multiple ``<column>`` elements, each specifying one model column. The “type”
115 /// attribute specifies the data type for the column.
116 ///
117 /// Additionally, it is possible to specify content for the list store
118 /// in the UI definition, with the ``<data>`` element. It can contain multiple
119 /// ``<row>`` elements, each specifying to content for one row of the list model.
120 /// Inside a ``<row>``, the ``<col>`` elements specify the content for individual cells.
121 ///
122 /// Note that it is probably more common to define your models in the code,
123 /// and one might consider it a layering violation to specify the content of
124 /// a list store in a UI definition, data, not presentation, and common wisdom
125 /// is to separate the two, as far as possible.
126 ///
127 /// An example of a UI Definition fragment for a list store:
128 ///
129 ///
130 ///
131 /// **⚠️ The following code is in xml ⚠️**
132 ///
133 /// ```xml
134 /// <object class="GtkListStore">
135 /// <columns>
136 /// <column type="gchararray"/>
137 /// <column type="gchararray"/>
138 /// <column type="gint"/>
139 /// </columns>
140 /// <data>
141 /// <row>
142 /// <col id="0">John</col>
143 /// <col id="1">Doe</col>
144 /// <col id="2">25</col>
145 /// </row>
146 /// <row>
147 /// <col id="0">Johan</col>
148 /// <col id="1">Dahlin</col>
149 /// <col id="2">50</col>
150 /// </row>
151 /// </data>
152 /// </object>
153 /// ```
154 ///
155 /// # Implements
156 ///
157 /// [`GtkListStoreExt`][trait@crate::prelude::GtkListStoreExt], [`trait@glib::ObjectExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`TreeDragDestExt`][trait@crate::prelude::TreeDragDestExt], [`TreeDragSourceExt`][trait@crate::prelude::TreeDragSourceExt], [`TreeModelExt`][trait@crate::prelude::TreeModelExt], [`TreeSortableExt`][trait@crate::prelude::TreeSortableExt], [`GtkListStoreExtManual`][trait@crate::prelude::GtkListStoreExtManual], [`BuildableExtManual`][trait@crate::prelude::BuildableExtManual], [`TreeSortableExtManual`][trait@crate::prelude::TreeSortableExtManual]
158 #[doc(alias = "GtkListStore")]
159 pub struct ListStore(Object<ffi::GtkListStore, ffi::GtkListStoreClass>) @implements Buildable, TreeDragDest, TreeDragSource, TreeModel, TreeSortable;
160
161 match fn {
162 type_ => || ffi::gtk_list_store_get_type(),
163 }
164}
165
166impl ListStore {
167 pub const NONE: Option<&'static ListStore> = None;
168
169 //#[doc(alias = "gtk_list_store_new")]
170 //pub fn new(n_columns: i32, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) -> ListStore {
171 // unsafe { TODO: call ffi:gtk_list_store_new() }
172 //}
173
174 //#[doc(alias = "gtk_list_store_newv")]
175 //pub fn newv(types: /*Unimplemented*/&CArray TypeId { ns_id: 0, id: 30 }) -> ListStore {
176 // unsafe { TODO: call ffi:gtk_list_store_newv() }
177 //}
178}
179
180/// Trait containing all [`struct@ListStore`] methods.
181///
182/// # Implementors
183///
184/// [`ListStore`][struct@crate::ListStore]
185pub trait GtkListStoreExt: IsA<ListStore> + 'static {
186 /// Appends a new row to `self`. `iter` will be changed to point to this new
187 /// row. The row will be empty after this function is called. To fill in
188 /// values, you need to call [`GtkListStoreExtManual::set()`][crate::prelude::GtkListStoreExtManual::set()] or [`GtkListStoreExtManual::set_value()`][crate::prelude::GtkListStoreExtManual::set_value()].
189 ///
190 /// # Returns
191 ///
192 ///
193 /// ## `iter`
194 /// An unset [`TreeIter`][crate::TreeIter] to set to the appended row
195 #[doc(alias = "gtk_list_store_append")]
196 fn append(&self) -> TreeIter {
197 unsafe {
198 let mut iter = TreeIter::uninitialized();
199 ffi::gtk_list_store_append(self.as_ref().to_glib_none().0, iter.to_glib_none_mut().0);
200 iter
201 }
202 }
203
204 /// Removes all rows from the list store.
205 #[doc(alias = "gtk_list_store_clear")]
206 fn clear(&self) {
207 unsafe {
208 ffi::gtk_list_store_clear(self.as_ref().to_glib_none().0);
209 }
210 }
211
212 /// Creates a new row at `position`. `iter` will be changed to point to this new
213 /// row. If `position` is -1 or is larger than the number of rows on the list,
214 /// then the new row will be appended to the list. The row will be empty after
215 /// this function is called. To fill in values, you need to call
216 /// [`GtkListStoreExtManual::set()`][crate::prelude::GtkListStoreExtManual::set()] or [`GtkListStoreExtManual::set_value()`][crate::prelude::GtkListStoreExtManual::set_value()].
217 /// ## `position`
218 /// position to insert the new row, or -1 for last
219 ///
220 /// # Returns
221 ///
222 ///
223 /// ## `iter`
224 /// An unset [`TreeIter`][crate::TreeIter] to set to the new row
225 #[doc(alias = "gtk_list_store_insert")]
226 fn insert(&self, position: i32) -> TreeIter {
227 unsafe {
228 let mut iter = TreeIter::uninitialized();
229 ffi::gtk_list_store_insert(
230 self.as_ref().to_glib_none().0,
231 iter.to_glib_none_mut().0,
232 position,
233 );
234 iter
235 }
236 }
237
238 /// Inserts a new row after `sibling`. If `sibling` is [`None`], then the row will be
239 /// prepended to the beginning of the list. `iter` will be changed to point to
240 /// this new row. The row will be empty after this function is called. To fill
241 /// in values, you need to call [`GtkListStoreExtManual::set()`][crate::prelude::GtkListStoreExtManual::set()] or [`GtkListStoreExtManual::set_value()`][crate::prelude::GtkListStoreExtManual::set_value()].
242 /// ## `sibling`
243 /// A valid [`TreeIter`][crate::TreeIter], or [`None`]
244 ///
245 /// # Returns
246 ///
247 ///
248 /// ## `iter`
249 /// An unset [`TreeIter`][crate::TreeIter] to set to the new row
250 #[doc(alias = "gtk_list_store_insert_after")]
251 fn insert_after(&self, sibling: Option<&TreeIter>) -> TreeIter {
252 unsafe {
253 let mut iter = TreeIter::uninitialized();
254 ffi::gtk_list_store_insert_after(
255 self.as_ref().to_glib_none().0,
256 iter.to_glib_none_mut().0,
257 mut_override(sibling.to_glib_none().0),
258 );
259 iter
260 }
261 }
262
263 /// Inserts a new row before `sibling`. If `sibling` is [`None`], then the row will
264 /// be appended to the end of the list. `iter` will be changed to point to this
265 /// new row. The row will be empty after this function is called. To fill in
266 /// values, you need to call [`GtkListStoreExtManual::set()`][crate::prelude::GtkListStoreExtManual::set()] or [`GtkListStoreExtManual::set_value()`][crate::prelude::GtkListStoreExtManual::set_value()].
267 /// ## `sibling`
268 /// A valid [`TreeIter`][crate::TreeIter], or [`None`]
269 ///
270 /// # Returns
271 ///
272 ///
273 /// ## `iter`
274 /// An unset [`TreeIter`][crate::TreeIter] to set to the new row
275 #[doc(alias = "gtk_list_store_insert_before")]
276 fn insert_before(&self, sibling: Option<&TreeIter>) -> TreeIter {
277 unsafe {
278 let mut iter = TreeIter::uninitialized();
279 ffi::gtk_list_store_insert_before(
280 self.as_ref().to_glib_none().0,
281 iter.to_glib_none_mut().0,
282 mut_override(sibling.to_glib_none().0),
283 );
284 iter
285 }
286 }
287
288 //#[doc(alias = "gtk_list_store_insert_with_values")]
289 //fn insert_with_values(&self, position: i32, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) -> TreeIter {
290 // unsafe { TODO: call ffi:gtk_list_store_insert_with_values() }
291 //}
292
293 //#[doc(alias = "gtk_list_store_insert_with_valuesv")]
294 //fn insert_with_valuesv(&self, position: i32, columns: &[i32], values: &[&glib::Value]) -> TreeIter {
295 // unsafe { TODO: call ffi:gtk_list_store_insert_with_valuesv() }
296 //}
297
298 /// > This function is slow. Only use it for debugging and/or testing
299 /// > purposes.
300 ///
301 /// Checks if the given iter is a valid iter for this [`ListStore`][crate::ListStore].
302 /// ## `iter`
303 /// A [`TreeIter`][crate::TreeIter].
304 ///
305 /// # Returns
306 ///
307 /// [`true`] if the iter is valid, [`false`] if the iter is invalid.
308 #[doc(alias = "gtk_list_store_iter_is_valid")]
309 fn iter_is_valid(&self, iter: &TreeIter) -> bool {
310 unsafe {
311 from_glib(ffi::gtk_list_store_iter_is_valid(
312 self.as_ref().to_glib_none().0,
313 mut_override(iter.to_glib_none().0),
314 ))
315 }
316 }
317
318 /// Moves `iter` in `self` to the position after `position`. Note that this
319 /// function only works with unsorted stores. If `position` is [`None`], `iter`
320 /// will be moved to the start of the list.
321 /// ## `iter`
322 /// A [`TreeIter`][crate::TreeIter].
323 /// ## `position`
324 /// A [`TreeIter`][crate::TreeIter] or [`None`].
325 #[doc(alias = "gtk_list_store_move_after")]
326 fn move_after(&self, iter: &TreeIter, position: Option<&TreeIter>) {
327 unsafe {
328 ffi::gtk_list_store_move_after(
329 self.as_ref().to_glib_none().0,
330 mut_override(iter.to_glib_none().0),
331 mut_override(position.to_glib_none().0),
332 );
333 }
334 }
335
336 /// Moves `iter` in `self` to the position before `position`. Note that this
337 /// function only works with unsorted stores. If `position` is [`None`], `iter`
338 /// will be moved to the end of the list.
339 /// ## `iter`
340 /// A [`TreeIter`][crate::TreeIter].
341 /// ## `position`
342 /// A [`TreeIter`][crate::TreeIter], or [`None`].
343 #[doc(alias = "gtk_list_store_move_before")]
344 fn move_before(&self, iter: &TreeIter, position: Option<&TreeIter>) {
345 unsafe {
346 ffi::gtk_list_store_move_before(
347 self.as_ref().to_glib_none().0,
348 mut_override(iter.to_glib_none().0),
349 mut_override(position.to_glib_none().0),
350 );
351 }
352 }
353
354 /// Prepends a new row to `self`. `iter` will be changed to point to this new
355 /// row. The row will be empty after this function is called. To fill in
356 /// values, you need to call [`GtkListStoreExtManual::set()`][crate::prelude::GtkListStoreExtManual::set()] or [`GtkListStoreExtManual::set_value()`][crate::prelude::GtkListStoreExtManual::set_value()].
357 ///
358 /// # Returns
359 ///
360 ///
361 /// ## `iter`
362 /// An unset [`TreeIter`][crate::TreeIter] to set to the prepend row
363 #[doc(alias = "gtk_list_store_prepend")]
364 fn prepend(&self) -> TreeIter {
365 unsafe {
366 let mut iter = TreeIter::uninitialized();
367 ffi::gtk_list_store_prepend(self.as_ref().to_glib_none().0, iter.to_glib_none_mut().0);
368 iter
369 }
370 }
371
372 /// Removes the given row from the list store. After being removed,
373 /// `iter` is set to be the next valid row, or invalidated if it pointed
374 /// to the last row in `self`.
375 /// ## `iter`
376 /// A valid [`TreeIter`][crate::TreeIter]
377 ///
378 /// # Returns
379 ///
380 /// [`true`] if `iter` is valid, [`false`] if not.
381 #[doc(alias = "gtk_list_store_remove")]
382 fn remove(&self, iter: &TreeIter) -> bool {
383 unsafe {
384 from_glib(ffi::gtk_list_store_remove(
385 self.as_ref().to_glib_none().0,
386 mut_override(iter.to_glib_none().0),
387 ))
388 }
389 }
390
391 //#[doc(alias = "gtk_list_store_set_column_types")]
392 //fn set_column_types(&self, types: /*Unimplemented*/&CArray TypeId { ns_id: 0, id: 30 }) {
393 // unsafe { TODO: call ffi:gtk_list_store_set_column_types() }
394 //}
395
396 //#[doc(alias = "gtk_list_store_set_valist")]
397 //fn set_valist(&self, iter: &TreeIter, var_args: /*Unknown conversion*//*Unimplemented*/Unsupported) {
398 // unsafe { TODO: call ffi:gtk_list_store_set_valist() }
399 //}
400
401 //#[doc(alias = "gtk_list_store_set_valuesv")]
402 //fn set_valuesv(&self, iter: &TreeIter, columns: &[i32], values: &[&glib::Value]) {
403 // unsafe { TODO: call ffi:gtk_list_store_set_valuesv() }
404 //}
405
406 /// Swaps `a` and `b` in `self`. Note that this function only works with
407 /// unsorted stores.
408 /// ## `a`
409 /// A [`TreeIter`][crate::TreeIter].
410 /// ## `b`
411 /// Another [`TreeIter`][crate::TreeIter].
412 #[doc(alias = "gtk_list_store_swap")]
413 fn swap(&self, a: &TreeIter, b: &TreeIter) {
414 unsafe {
415 ffi::gtk_list_store_swap(
416 self.as_ref().to_glib_none().0,
417 mut_override(a.to_glib_none().0),
418 mut_override(b.to_glib_none().0),
419 );
420 }
421 }
422}
423
424impl<O: IsA<ListStore>> GtkListStoreExt for O {}