Skip to main content

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