A list-like data structure that can be used with the [classGtk.TreeView].
The GtkListStore object is a list model for use with a GtkTreeView widget. It implements the GtkTreeModel interface, and consequentialy, can use all of the methods available there. It also implements the GtkTreeSortable interface so it can be sorted by the view. Finally, it also implements the tree drag and drop interfaces.
The GtkListStore can accept most GTypes as a column type, though it can't accept all custom types. Internally, it will keep a copy of data passed in (such as a string or a boxed pointer). Columns that accept GObjects are handled a little differently. The GtkListStore will keep a reference to the object instead of copying the value. As a result, if the object is modified, it is up to the application writer to call [methodGtk.TreeModel.row_changed] to emit the [signalGtk.TreeModel::row_changed] signal. This most commonly affects lists with [classGdk.Texture]s stored.
An example for creating a simple list store:
{ GtkListStore *list_store; GtkTreePath *path; GtkTreeIter iter; int i;
list_store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_INT,
G_TYPE_BOOLEAN);
for (i = 0; i < 10; i++) { char *some_data;
some_data = get_some_data (i);
// Add a new row to the model gtk_list_store_append (list_store, &iter);
gtk_list_store_set (list_store, &iter, COLUMN_STRING, some_data,
COLUMN_INT, i, COLUMN_BOOLEAN, FALSE, -1);
// As the store will keep a copy of the string internally, // we free
some_data. g_free (some_data); }
// Modify a particular row path = gtk_tree_path_new_from_string ("4");
gtk_tree_model_get_iter (GTK_TREE_MODEL (list_store), &iter, path);
gtk_tree_path_free (path); gtk_list_store_set (list_store, &iter,
COLUMN_BOOLEAN, TRUE, -1); } ```
`GtkListStore` is deprecated since GTK 4.10, and should not be used in
newly written code. You should use [classGio.ListStore] instead, and the
various list models provided by GTK.
## Performance Considerations
Internally, the `GtkListStore` was originally implemented with a linked
list with a tail pointer. As a result, it was fast at data insertion and
deletion, and not fast at random data access. The `GtkListStore` sets the
`GTK_TREE_MODEL_ITERS_PERSIST` flag, which means that `GtkTreeIter`s can be
cached while the row exists. Thus, if access to a particular row is needed
often and your code is expected to run on older versions of GTK, it is
worth keeping the iter around.
## Atomic Operations
It is important to note that only the methods
gtk_list_store_insert_with_values and gtk_list_store_insert_with_valuesv
are atomic, in the sense that the row is being appended to the store and
the values filled in in a single operation with regard to `GtkTreeModel`
signaling. In contrast, using e.g. Gtk.List_Store.Append and then
gtk_list_store_set will first create a row, which triggers the
`GtkTreeModel::row-inserted` signal on `GtkListStore`. The row, however, is
still empty, and any signal handler connecting to
`GtkTreeModel::row-inserted` on this particular store should be prepared
for the situation that the row might be empty. This is especially important
if you are wrapping the `GtkListStore` inside a `GtkTreeModel`Filter and
are using a `GtkTreeModel`FilterVisibleFunc. Using any of the non-atomic
operations to append rows to the `GtkListStore` will cause the
`GtkTreeModel`FilterVisibleFunc to be visited with an empty row first; the
function must be prepared for that.
## GtkListStore as GtkBuildable
The GtkListStore implementation of the [ifaceGtk.Buildable] interface
allows to specify the model columns with a `<columns>` element that may
contain multiple `<column>` elements, each specifying one model column. The
"type" attribute specifies the data type for the column.
Additionally, it is possible to specify content for the list store in the
UI definition, with the `<data>` element. It can contain multiple `<row>`
elements, each specifying to content for one row of the list model. Inside
a `<row>`, the `<col>` elements specify the content for individual cells.
Note that it is probably more common to define your models in the code,
and one might consider it a layering violation to specify the content of a
list store in a UI definition, data, not presentation, and common wisdom is
to separate the two, as far as possible.
An example of a UI Definition fragment for a list store:
```xml <object class="GtkListStore"> <columns> <column type="gchararray"/>
<column type="gchararray"/> <column type="gint"/> </columns> <data> <row>
<col id="0">John</col> <col id="1">Doe</col> <col id="2">25</col> </row>
<row> <col id="0">Johan</col> <col id="1">Dahlin</col> <col id="2">50</col>
</row> </data> </object> ```
function "+"
(Widget : access Gtk_List_Store_Record'Class)
return Gtk.Buildable.Gtk_Buildable
function "+"
(Widget : access Gtk_List_Store_Record'Class)
return Gtk.Tree_Drag_Dest.Gtk_Tree_Drag_Dest
function "+"
(Widget : access Gtk_List_Store_Record'Class)
return Gtk.Tree_Drag_Source.Gtk_Tree_Drag_Source
function "+"
(Widget : access Gtk_List_Store_Record'Class)
return Gtk.Tree_Model.Gtk_Tree_Model
function "+"
(Widget : access Gtk_List_Store_Record'Class)
return Gtk.Tree_Sortable.Gtk_Tree_Sortable
function "-"
(Interf : Gtk.Buildable.Gtk_Buildable)
return Gtk_List_Store
function "-"
(Interf : Gtk.Tree_Drag_Dest.Gtk_Tree_Drag_Dest)
return Gtk_List_Store
function "-"
(Interf : Gtk.Tree_Drag_Source.Gtk_Tree_Drag_Source)
return Gtk_List_Store
function "-"
(Interf : Gtk.Tree_Model.Gtk_Tree_Model)
return Gtk_List_Store
function "-"
(Interf : Gtk.Tree_Sortable.Gtk_Tree_Sortable)
return Gtk_List_Store
procedure Append
(Self : not null access Gtk_List_Store_Record;
Iter : out Gtk.Tree_Model.Gtk_Tree_Iter)
Appends a new row to List_Store. Iter will be changed to point to this new row. The row will be empty after this function is called. To fill in values, you need to call gtk_list_store_set or Gtk.List_Store.Set_Value. Deprecated since 4.10, 1
An unset GtkTreeIter to set to the appended row
function Children
(Tree_Model : not null access Gtk_List_Store_Record;
Parent : Gtk.Tree_Model.Gtk_Tree_Iter)
return Gtk.Tree_Model.Gtk_Tree_Iter
procedure Clear (Self : not null access Gtk_List_Store_Record)
Removes all rows from the list store. Deprecated since 4.10, 1
function Drag_Data_Delete
(Self : not null access Gtk_List_Store_Record;
Path : Gtk.Tree_Model.Gtk_Tree_Path) return Boolean
function Drag_Data_Get
(Self : not null access Gtk_List_Store_Record;
Path : Gtk.Tree_Model.Gtk_Tree_Path)
return Gdk.Content_Provider.Gdk_Content_Provider
function Drag_Data_Received
(Self : not null access Gtk_List_Store_Record;
Dest : Gtk.Tree_Model.Gtk_Tree_Path;
Value : in out Glib.Values.GValue) return Boolean
procedure Foreach
(Tree_Model : not null access Gtk_List_Store_Record;
Func : Gtk_Tree_Model_Foreach_Func)
Calls Func on each node in model in a depth-first fashion. If Func returns True, then the tree ceases to be walked, and Gtk.Tree_Model.Foreach returns. Deprecated since 4.10, 1
a function to be called on each row
function Get_Column_Type
(Tree_Model : not null access Gtk_List_Store_Record;
Index : Glib.Gint) return GType
function Get_Flags
(Tree_Model : not null access Gtk_List_Store_Record)
return Gtk.Tree_Model.Tree_Model_Flags
function Get_Iter
(Tree_Model : not null access Gtk_List_Store_Record;
Path : Gtk.Tree_Model.Gtk_Tree_Path)
return Gtk.Tree_Model.Gtk_Tree_Iter
function Get_Iter_First
(Tree_Model : not null access Gtk_List_Store_Record)
return Gtk.Tree_Model.Gtk_Tree_Iter
function Get_Iter_From_String
(Tree_Model : not null access Gtk_List_Store_Record;
Path_String : UTF8_String) return Gtk.Tree_Model.Gtk_Tree_Iter
function Get_N_Columns
(Tree_Model : not null access Gtk_List_Store_Record) return Glib.Gint
function Get_Path
(Tree_Model : not null access Gtk_List_Store_Record;
Iter : Gtk.Tree_Model.Gtk_Tree_Iter)
return Gtk.Tree_Model.Gtk_Tree_Path
function Get_Sort_Column_Id
(Self : not null access Gtk_List_Store_Record;
Sort_Column_Id : out Glib.Gint;
Order : out Gtk.Enums.Gtk_Sort_Type) return Boolean
function Get_String_From_Iter
(Tree_Model : not null access Gtk_List_Store_Record;
Iter : Gtk.Tree_Model.Gtk_Tree_Iter) return UTF8_String
function Get_Type return Glib.GType
procedure Get_Value
(Tree_Model : not null access Gtk_List_Store_Record;
Iter : Gtk.Tree_Model.Gtk_Tree_Iter;
Column : Glib.Gint;
Value : out Glib.Values.GValue)
type Gtk_List_Store is access all Gtk_List_Store_Record'Class;
function Gtk_List_Store_Newv (Types : GType_Array) return Gtk_List_Store
Creates a new GtkListStore. This function is meant to be used by language bindings.
an array of GType types for the columns, from first to last
type Gtk_List_Store_Record is new Gtk_Root_Tree_Model_Record with null record;
procedure Gtk_New (Self : out Gtk_List_Store; Types : GType_Array)
Creates a new GtkListStore. This function is meant to be used by language bindings. Initialize does nothing if the object was already created with another call to Initialize* or G_New.
an array of GType types for the columns, from first to last
type Gtk_Tree_Iter_Compare_Func is access function
(Model : Gtk.Tree_Model.Gtk_Tree_Model;
A : Gtk.Tree_Model.Gtk_Tree_Iter;
B : Gtk.Tree_Model.Gtk_Tree_Iter) return Glib.Gint;
A GtkTreeIterCompareFunc should return a negative integer, zero, or a positive integer if A sorts before B, A sorts with B, or A sorts after B respectively. If two iters compare as equal, their order in the sorted model is undefined. In order to ensure that the GtkTreeSortable behaves as expected, the GtkTreeIterCompareFunc must define a partial order on the model, i.e. it must be reflexive, antisymmetric and transitive. For example, if Model is a product catalogue, then a compare function for the "price" column could be one which returns price_of(A) - price_of(B).
The GtkTreeModel the comparison is within
A GtkTreeIter in Model
Another GtkTreeIter in Model
a negative integer, zero or a positive integer depending on whether A sorts before, with or after B
type Gtk_Tree_Model_Foreach_Func is access function
(Model : Gtk.Tree_Model.Gtk_Tree_Model;
Path : Gtk.Tree_Model.Gtk_Tree_Path;
Iter : Gtk.Tree_Model.Gtk_Tree_Iter) return Boolean;
Type of the callback passed to Gtk.Tree_Model.Foreach to iterate over the rows in a tree model.
the GtkTreeModel being iterated
the current GtkTreePath
the current GtkTreeIter
True to stop iterating, False to continue
function Has_Child
(Tree_Model : not null access Gtk_List_Store_Record;
Iter : Gtk.Tree_Model.Gtk_Tree_Iter) return Boolean
function Has_Default_Sort_Func
(Self : not null access Gtk_List_Store_Record) return Boolean
package Implements_Gtk_Buildable is new Glib.Types.Implements
(Gtk.Buildable.Gtk_Buildable, Gtk_List_Store_Record, Gtk_List_Store);
package Implements_Gtk_Tree_Drag_Dest is new Glib.Types.Implements
(Gtk.Tree_Drag_Dest.Gtk_Tree_Drag_Dest, Gtk_List_Store_Record, Gtk_List_Store);
package Implements_Gtk_Tree_Drag_Source is new Glib.Types.Implements
(Gtk.Tree_Drag_Source.Gtk_Tree_Drag_Source, Gtk_List_Store_Record, Gtk_List_Store);
package Implements_Gtk_Tree_Model is new Glib.Types.Implements
(Gtk.Tree_Model.Gtk_Tree_Model, Gtk_List_Store_Record, Gtk_List_Store);
package Implements_Gtk_Tree_Sortable is new Glib.Types.Implements
(Gtk.Tree_Sortable.Gtk_Tree_Sortable, Gtk_List_Store_Record, Gtk_List_Store);
procedure Initialize
(Self : not null access Gtk_List_Store_Record'Class;
Types : GType_Array)
Creates a new GtkListStore. This function is meant to be used by language bindings. Initialize does nothing if the object was already created with another call to Initialize* or G_New.
an array of GType types for the columns, from first to last
procedure Insert
(Self : not null access Gtk_List_Store_Record;
Iter : out Gtk.Tree_Model.Gtk_Tree_Iter;
Position : Glib.Gint)
Creates a new row at Position. Iter will be changed to point to this new row. If Position is -1 or is larger than the number of rows on the list, then the new row will be appended to the list. The row will be empty after this function is called. To fill in values, you need to call gtk_list_store_set or Gtk.List_Store.Set_Value. Deprecated since 4.10, 1
An unset GtkTreeIter to set to the new row
position to insert the new row, or -1 for last
procedure Insert_After
(Self : not null access Gtk_List_Store_Record;
Iter : out Gtk.Tree_Model.Gtk_Tree_Iter;
Sibling : Gtk.Tree_Model.Gtk_Tree_Iter)
Inserts a new row after Sibling. If Sibling is null, then the row will be prepended to the beginning of the list. Iter will be changed to point to this new row. The row will be empty after this function is called. To fill in values, you need to call gtk_list_store_set or Gtk.List_Store.Set_Value. Deprecated since 4.10, 1
An unset GtkTreeIter to set to the new row
A valid GtkTreeIter
procedure Insert_Before
(Self : not null access Gtk_List_Store_Record;
Iter : out Gtk.Tree_Model.Gtk_Tree_Iter;
Sibling : Gtk.Tree_Model.Gtk_Tree_Iter)
Inserts a new row before Sibling. If Sibling is null, then the row will be appended to the end of the list. Iter will be changed to point to this new row. The row will be empty after this function is called. To fill in values, you need to call gtk_list_store_set or Gtk.List_Store.Set_Value. Deprecated since 4.10, 1
An unset GtkTreeIter to set to the new row
A valid GtkTreeIter
function Iter_Is_Valid
(Self : not null access Gtk_List_Store_Record;
Iter : Gtk.Tree_Model.Gtk_Tree_Iter) return Boolean
Checks if the given iter is a valid iter for this GtkListStore. This function is slow. Only use it for debugging and/or testing purposes. Deprecated since 4.10, 1
the iterator to check
True if the iter is valid, False if the iter is invalid.
procedure Move_After
(Self : not null access Gtk_List_Store_Record;
Iter : Gtk.Tree_Model.Gtk_Tree_Iter;
Position : Gtk.Tree_Model.Gtk_Tree_Iter)
Moves Iter in Store to the position after Position. Note that this function only works with unsorted stores. If Position is null, Iter will be moved to the start of the list. Deprecated since 4.10, 1
A GtkTreeIter
A GtkTreeIter
procedure Move_Before
(Self : not null access Gtk_List_Store_Record;
Iter : Gtk.Tree_Model.Gtk_Tree_Iter;
Position : Gtk.Tree_Model.Gtk_Tree_Iter)
Moves Iter in Store to the position before Position. Note that this function only works with unsorted stores. If Position is null, Iter will be moved to the end of the list. Deprecated since 4.10, 1
A GtkTreeIter
A GtkTreeIter
function N_Children
(Tree_Model : not null access Gtk_List_Store_Record;
Iter : Gtk.Tree_Model.Gtk_Tree_Iter := Gtk.Tree_Model.Null_Iter)
return Glib.Gint
procedure Next
(Tree_Model : not null access Gtk_List_Store_Record;
Iter : in out Gtk.Tree_Model.Gtk_Tree_Iter)
function Nth_Child
(Tree_Model : not null access Gtk_List_Store_Record;
Parent : Gtk.Tree_Model.Gtk_Tree_Iter;
N : Glib.Gint) return Gtk.Tree_Model.Gtk_Tree_Iter
function Parent
(Tree_Model : not null access Gtk_List_Store_Record;
Child : Gtk.Tree_Model.Gtk_Tree_Iter)
return Gtk.Tree_Model.Gtk_Tree_Iter
procedure Prepend
(Self : not null access Gtk_List_Store_Record;
Iter : out Gtk.Tree_Model.Gtk_Tree_Iter)
Prepends a new row to List_Store. Iter will be changed to point to this new row. The row will be empty after this function is called. To fill in values, you need to call gtk_list_store_set or Gtk.List_Store.Set_Value. Deprecated since 4.10, 1
An unset GtkTreeIter to set to the prepend row
procedure Previous
(Tree_Model : not null access Gtk_List_Store_Record;
Iter : in out Gtk.Tree_Model.Gtk_Tree_Iter)
procedure Ref_Node
(Tree_Model : not null access Gtk_List_Store_Record;
Iter : Gtk.Tree_Model.Gtk_Tree_Iter)
procedure Remove
(Self : not null access Gtk_List_Store_Record;
Iter : in out Gtk.Tree_Model.Gtk_Tree_Iter)
Removes the given row from the list store. After being removed, Iter is set to be the next valid row, or invalidated if it pointed to the last row in List_Store. Deprecated since 4.10, 1
A valid GtkTreeIter
procedure Reorder
(Self : not null access Gtk_List_Store_Record;
New_Order : Gint_Array)
Reorders Store to follow the order indicated by New_Order. Note that this function only works with unsorted stores. Deprecated since 4.10, 1
an array of integers mapping the new position of each child to its old position before the re-ordering, i.e. New_Order[newpos] = oldpos. It must have exactly as many items as the list store's length.
procedure Row_Changed
(Tree_Model : not null access Gtk_List_Store_Record;
Path : Gtk.Tree_Model.Gtk_Tree_Path;
Iter : Gtk.Tree_Model.Gtk_Tree_Iter)
procedure Row_Deleted
(Tree_Model : not null access Gtk_List_Store_Record;
Path : Gtk.Tree_Model.Gtk_Tree_Path)
function Row_Draggable
(Self : not null access Gtk_List_Store_Record;
Path : Gtk.Tree_Model.Gtk_Tree_Path) return Boolean
function Row_Drop_Possible
(Self : not null access Gtk_List_Store_Record;
Dest_Path : Gtk.Tree_Model.Gtk_Tree_Path;
Value : in out Glib.Values.GValue) return Boolean
procedure Row_Has_Child_Toggled
(Tree_Model : not null access Gtk_List_Store_Record;
Path : Gtk.Tree_Model.Gtk_Tree_Path;
Iter : Gtk.Tree_Model.Gtk_Tree_Iter)
procedure Row_Inserted
(Tree_Model : not null access Gtk_List_Store_Record;
Path : Gtk.Tree_Model.Gtk_Tree_Path;
Iter : Gtk.Tree_Model.Gtk_Tree_Iter)
procedure Rows_Reordered
(Tree_Model : not null access Gtk_List_Store_Record;
Path : Gtk.Tree_Model.Gtk_Tree_Path;
Iter : Gtk.Tree_Model.Gtk_Tree_Iter;
New_Order : Gint_Array)
procedure Rows_Reordered_With_Length
(Tree_Model : not null access Gtk_List_Store_Record;
Path : Gtk.Tree_Model.Gtk_Tree_Path;
Iter : Gtk.Tree_Model.Gtk_Tree_Iter;
New_Order : Gint_Array;
Length : Glib.Gint)
procedure Set
(Self : access Gtk_List_Store_Record;
Iter : Gtk.Tree_Model.Gtk_Tree_Iter;
Column : Gint;
Value : Gint)
procedure Set (Self : access Gtk_List_Store_Record; Iter : Gtk.Tree_Model.Gtk_Tree_Iter; Column : Gint; Value : Gdk.Pixbuf.Gdk_Pixbuf);
procedure Set
(Self : access Gtk_List_Store_Record;
Iter : Gtk.Tree_Model.Gtk_Tree_Iter;
Column : Gint;
Value : UTF8_String)
procedure Set (Self : access Gtk_List_Store_Record; Iter : Gtk.Tree_Model.Gtk_Tree_Iter; Column : Gint; Value : Gdk.Pixbuf.Gdk_Pixbuf);
procedure Set
(Self : access Gtk_List_Store_Record;
Iter : Gtk.Tree_Model.Gtk_Tree_Iter;
Column : Gint;
Value : Boolean)
procedure Set (Self : access Gtk_List_Store_Record; Iter : Gtk.Tree_Model.Gtk_Tree_Iter; Column : Gint; Value : Gdk.Pixbuf.Gdk_Pixbuf);
procedure Set
(Self : not null access Gtk_List_Store_Record;
Iter : Gtk.Tree_Model.Gtk_Tree_Iter;
Columns : Glib.Gint_Array;
Values : Glib.Values.GValue_Array)
A variant of Set which takes the columns and valus as two arrays. This is more efficient when changing multiple values than calling one of the Set procedures above multiple times.
procedure Set
(Self : not null access Gtk_List_Store_Record;
Iter : Gtk.Tree_Model.Gtk_Tree_Iter;
Values : Glib.Values.GValue_Array)
A variant of the above that is used to set all the columns.
procedure Set_Column_Types
(Self : not null access Gtk_List_Store_Record;
Types : GType_Array)
Sets the types of the columns of a list store. This function is meant primarily for objects that inherit from GtkListStore, and should only be used when constructing a new instance. This function cannot be called after a row has been added, or a method on the GtkTreeModel interface is called. Deprecated since 4.10, 1
An array length n of GTypes
procedure Set_Default_Sort_Func
(Self : not null access Gtk_List_Store_Record;
Sort_Func : Gtk_Tree_Iter_Compare_Func)
Sets the default comparison function used when sorting to be Sort_Func. If the current sort column id of Sortable is GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, then the model will sort using this function. If Sort_Func is null, then there will be no default comparison function. This means that once the model has been sorted, it can't go back to the default state. In this case, when the current sort column id of Sortable is GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, the model will be unsorted. Deprecated since 4.10, 1
The comparison function
procedure Set_Sort_Column_Id
(Self : not null access Gtk_List_Store_Record;
Sort_Column_Id : Glib.Gint;
Order : Gtk.Enums.Gtk_Sort_Type)
procedure Set_Sort_Func
(Self : not null access Gtk_List_Store_Record;
Sort_Column_Id : Glib.Gint;
Sort_Func : Gtk_Tree_Iter_Compare_Func)
Sets the comparison function used when sorting to be Sort_Func. If the current sort column id of Sortable is the same as Sort_Column_Id, then the model will sort using this function. Deprecated since 4.10, 1
the sort column id to set the function for
The comparison function
procedure Set_Value
(Self : not null access Gtk_List_Store_Record;
Iter : Gtk.Tree_Model.Gtk_Tree_Iter;
Column : Glib.Gint;
Value : Glib.Values.GValue)
Sets the data in the cell specified by Iter and Column. The type of Value must be convertible to the type of the column. Deprecated since 4.10, 1
A valid GtkTreeIter for the row being modified
column number to modify
new value for the cell
procedure Sort_Column_Changed
(Self : not null access Gtk_List_Store_Record)
procedure Swap
(Self : not null access Gtk_List_Store_Record;
A : Gtk.Tree_Model.Gtk_Tree_Iter;
B : Gtk.Tree_Model.Gtk_Tree_Iter)
Swaps A and B in Store. Note that this function only works with unsorted stores. Deprecated since 4.10, 1
A GtkTreeIter
Another GtkTreeIter
procedure Unref_Node
(Tree_Model : not null access Gtk_List_Store_Record;
Iter : Gtk.Tree_Model.Gtk_Tree_Iter)