package Tree_Model_Flags_Properties is new Generic_Internal_Discrete_Property (Tree_Model_Flags);
package Implements_Gtk_Tree_Model is new Glib.Types.Implements (Gtk_Tree_Model, Gtk_Root_Tree_Model_Record, Gtk_Root_Tree_Model);
package Gtk_Tree_Path_List is new Generic_List (Gtk.Tree_Model.Gtk_Tree_Path);
type Gtk_Tree_Path is new Glib.C_Boxed with null record;
type Gtk_Root_Tree_Model_Record is new Glib.Object.GObject_Record with null record;
type Gtk_Tree_Model is new Glib.Types.GType_Interface;
type Gtk_Tree_Model_Foreach_Func is access function (Model : Gtk_Tree_Model; Path : Gtk_Tree_Path; Iter : Gtk_Tree_Iter) return Boolean;
type Property_Tree_Model_Flags is new Tree_Model_Flags_Properties.Property;
type Gtk_Root_Tree_Model is access all Gtk_Root_Tree_Model_Record'Class;
type Cb_Gtk_Tree_Model_Gtk_Tree_Path_Gtk_Tree_Iter_Void is not null access procedure (Self : Gtk_Tree_Model; Path : Gtk_Tree_Path; Iter : Gtk_Tree_Iter);
type Cb_GObject_Gtk_Tree_Path_Gtk_Tree_Iter_Void is not null access procedure (Self : access Glib.Object.GObject_Record'Class; Path : Gtk_Tree_Path; Iter : Gtk_Tree_Iter);
type Cb_Gtk_Tree_Model_Gtk_Tree_Path_Void is not null access procedure (Self : Gtk_Tree_Model; Path : Gtk_Tree_Path);
type Cb_GObject_Gtk_Tree_Path_Void is not null access procedure (Self : access Glib.Object.GObject_Record'Class; Path : Gtk_Tree_Path);
type Cb_Gtk_Tree_Model_Gtk_Tree_Path_Gtk_Tree_Iter_Address_Void is not null access procedure (Self : Gtk_Tree_Model; Path : Gtk_Tree_Path; Iter : Gtk_Tree_Iter; New_Order : System.Address);
type Cb_GObject_Gtk_Tree_Path_Gtk_Tree_Iter_Address_Void is not null access procedure (Self : access Glib.Object.GObject_Record'Class; Path : Gtk_Tree_Path; Iter : Gtk_Tree_Iter; New_Order : System.Address);
Null_Gtk_Tree_Model : constant Gtk_Tree_Model;
Tree_Model_Iters_Persist : constant Tree_Model_Flags := 1;
Tree_Model_List_Only : constant Tree_Model_Flags := 2;
Null_Iter : constant Gtk_Tree_Iter;
Null_Gtk_Tree_Path : constant Gtk_Tree_Path;
Signal_Row_Changed : constant Glib.Signal_Name := "row-changed";
Signal_Row_Deleted : constant Glib.Signal_Name := "row-deleted";
Signal_Row_Has_Child_Toggled : constant Glib.Signal_Name := "row-has-child-toggled";
Signal_Row_Inserted : constant Glib.Signal_Name := "row-inserted";
Signal_Rows_Reordered : constant Glib.Signal_Name := "rows-reordered";
function From_Object_Free
( | B | : access Gtk_Tree_Iter) return Gtk_Tree_Iter; |
function From_Object
( | Object | : System.Address) return Gtk_Tree_Path; |
function From_Object_Free
( | B | : access Gtk_Tree_Path'Class) return Gtk_Tree_Path; |
function Get_Type return Glib.GType;
function Iter_Get_Type return Glib.GType;
procedure Gtk_New
( | Path | : out Gtk_Tree_Path); |
function Gtk_Tree_Path_New return Gtk_Tree_Path;
procedure Gtk_New_First
( | Path | : out Gtk_Tree_Path); |
function Gtk_Tree_Path_New_First return Gtk_Tree_Path;
procedure Gtk_New
( | Self | : out Gtk_Tree_Path; |
Path | : UTF8_String); |
function Gtk_Tree_Path_New_From_String
( | Path | : UTF8_String) return Gtk_Tree_Path; |
function Path_Get_Type return Glib.GType;
procedure Foreach
( | Tree_Model | : Gtk_Tree_Model; |
Func | : Gtk_Tree_Model_Foreach_Func); |
function Get_Column_Type
( | Tree_Model | : Gtk_Tree_Model; |
Index | : Gint) return GType; |
function Get_Flags
( | Tree_Model | : Gtk_Tree_Model) return Tree_Model_Flags; |
function Get_Iter
( | Tree_Model | : Gtk_Tree_Model; |
Path | : Gtk_Tree_Path) return Gtk_Tree_Iter; |
function Get_Iter_First
( | Tree_Model | : Gtk_Tree_Model) return Gtk_Tree_Iter; |
function Get_Iter_From_String
( | Tree_Model | : Gtk_Tree_Model; |
Path_String | : UTF8_String) return Gtk_Tree_Iter; |
function Get_N_Columns
( | Tree_Model | : Gtk_Tree_Model) return Gint; |
function Get_Path
( | Tree_Model | : Gtk_Tree_Model; |
Iter | : Gtk_Tree_Iter) return Gtk_Tree_Path; |
function Get_String_From_Iter
( | Tree_Model | : Gtk_Tree_Model; |
Iter | : Gtk_Tree_Iter) return UTF8_String; |
procedure Get_Value
( | Tree_Model | : Gtk_Tree_Model; |
Iter | : Gtk_Tree_Iter; | |
Column | : Gint; | |
Value | : out Glib.Values.GValue); |
function Children
( | Tree_Model | : Gtk_Tree_Model; |
Parent | : Gtk_Tree_Iter) return Gtk_Tree_Iter; |
function Has_Child
( | Tree_Model | : Gtk_Tree_Model; |
Iter | : Gtk_Tree_Iter) return Boolean; |
function N_Children
( | Tree_Model | : Gtk_Tree_Model; |
Iter | : Gtk_Tree_Iter := Gtk.Tree_Model.Null_Iter) return Gint; |
procedure Next
( | Tree_Model | : Gtk_Tree_Model; |
Iter | : in out Gtk_Tree_Iter); |
procedure Next
( | Path | : Gtk_Tree_Path); |
function Nth_Child
( | Tree_Model | : Gtk_Tree_Model; |
Parent | : Gtk_Tree_Iter; | |
N | : Gint) return Gtk_Tree_Iter; |
function Parent
( | Tree_Model | : Gtk_Tree_Model; |
Child | : Gtk_Tree_Iter) return Gtk_Tree_Iter; |
procedure Previous
( | Tree_Model | : Gtk_Tree_Model; |
Iter | : in out Gtk_Tree_Iter); |
procedure Ref_Node
( | Tree_Model | : Gtk_Tree_Model; |
Iter | : Gtk_Tree_Iter); |
procedure Row_Changed
( | Tree_Model | : Gtk_Tree_Model; |
Path | : Gtk_Tree_Path; | |
Iter | : Gtk_Tree_Iter); |
procedure Row_Deleted
( | Tree_Model | : Gtk_Tree_Model; |
Path | : Gtk_Tree_Path); |
procedure Row_Has_Child_Toggled
( | Tree_Model | : Gtk_Tree_Model; |
Path | : Gtk_Tree_Path; | |
Iter | : Gtk_Tree_Iter); |
procedure Row_Inserted
( | Tree_Model | : Gtk_Tree_Model; |
Path | : Gtk_Tree_Path; | |
Iter | : Gtk_Tree_Iter); |
procedure Rows_Reordered
( | Tree_Model | : Gtk_Tree_Model; |
Path | : Gtk_Tree_Path; | |
Iter | : Gtk_Tree_Iter; | |
New_Order | : Gint_Array); |
procedure Unref_Node
( | Tree_Model | : Gtk_Tree_Model; |
Iter | : Gtk_Tree_Iter); |
function Iter_Copy
( | Self | : Gtk_Tree_Iter) return Gtk_Tree_Iter; |
procedure Free
( | Self | : Gtk_Tree_Iter); |
procedure Append_Index
( | Path | : Gtk_Tree_Path; |
Index | : Gint); |
function Compare
( | Path | : Gtk_Tree_Path; |
B | : Gtk_Tree_Path) return Gint; |
function Copy
( | Path | : Gtk_Tree_Path) return Gtk_Tree_Path; |
procedure Down
( | Path | : Gtk_Tree_Path); |
procedure Path_Free
( | Path | : Gtk_Tree_Path); |
function Get_Indices
( | Path | : Gtk_Tree_Path) return Glib.Gint_Array; |
function Is_Ancestor
( | Path | : Gtk_Tree_Path; |
Descendant | : Gtk_Tree_Path) return Boolean; |
function Is_Descendant
( | Path | : Gtk_Tree_Path; |
Ancestor | : Gtk_Tree_Path) return Boolean; |
procedure Prepend_Index
( | Path | : Gtk_Tree_Path; |
Index | : Gint); |
function Prev
( | Path | : Gtk_Tree_Path) return Boolean; |
function To_String
( | Path | : Gtk_Tree_Path) return UTF8_String; |
function Up
( | Path | : Gtk_Tree_Path) return Boolean; |
function Get_Int
( | Tree_Model | : access Gtk_Root_Tree_Model_Record; |
Iter | : Gtk_Tree_Iter; | |
Column | : Gint) return Gint; |
function Get_Boolean
( | Tree_Model | : access Gtk_Root_Tree_Model_Record; |
Iter | : Gtk_Tree_Iter; | |
Column | : Gint) return Boolean; |
function Get_Object
( | Tree_Model | : access Gtk_Root_Tree_Model_Record; |
Iter | : Gtk_Tree_Iter; | |
Column | : Gint) return Glib.Object.GObject; |
function Get_C_Proxy
( | Tree_Model | : access Gtk_Root_Tree_Model_Record; |
Iter | : Gtk_Tree_Iter; | |
Column | : Gint) return Glib.C_Proxy; |
function Get_String
( | Tree_Model | : access Gtk_Root_Tree_Model_Record; |
Iter | : Gtk_Tree_Iter; | |
Column | : Gint) return UTF8_String; |
function Get_Address
( | Tree_Model | : access Gtk_Root_Tree_Model_Record; |
Iter | : Gtk_Tree_Iter; | |
Column | : Gint) return System.Address; |
function Get_Int
( | Tree_Model | : Gtk_Tree_Model; |
Iter | : Gtk_Tree_Iter; | |
Column | : Gint) return Gint; |
function Get_Boolean
( | Tree_Model | : Gtk_Tree_Model; |
Iter | : Gtk_Tree_Iter; | |
Column | : Gint) return Boolean; |
function Get_Object
( | Tree_Model | : Gtk_Tree_Model; |
Iter | : Gtk_Tree_Iter; | |
Column | : Gint) return Glib.Object.GObject; |
function Get_C_Proxy
( | Tree_Model | : Gtk_Tree_Model; |
Iter | : Gtk_Tree_Iter; | |
Column | : Gint) return Glib.C_Proxy; |
function Get_String
( | Tree_Model | : Gtk_Tree_Model; |
Iter | : Gtk_Tree_Iter; | |
Column | : Gint) return UTF8_String; |
function Get_Address
( | Tree_Model | : Gtk_Tree_Model; |
Iter | : Gtk_Tree_Iter; | |
Column | : Gint) return System.Address; |
function To_Interface
( | Widget | : access Gtk_Root_Tree_Model_Record'Class) return Gtk_Tree_Model renames Implements_Gtk_Tree_Model.To_Interface; |
function "-"
( | Interf | : Gtk_Tree_Model) return Gtk_Root_Tree_Model renames Implements_Gtk_Tree_Model.To_Object; |
function "="
( | Left | : Gtk_Tree_Iter; |
Right | : Gtk_Tree_Iter) return Boolean; |
procedure Set_Tree_Iter
( | Val | : in out Glib.Values.GValue; |
Iter | : Gtk_Tree_Iter); |
procedure Get_Tree_Iter
( | Val | : Glib.Values.GValue; |
Iter | : out Gtk_Tree_Iter); |
function Get_Tree_Iter
( | Val | : Glib.Values.GValue) return Gtk_Tree_Iter; |
function To_Address
( | Iter | : Gtk_Tree_Iter) return System.Address; |
function Get_Tree_Path
( | Val | : Glib.Values.GValue) return Gtk_Tree_Path; |
function Convert
( | R | : Gtk.Tree_Model.Gtk_Tree_Path) return System.Address; |
function Convert
( | R | : System.Address) return Gtk.Tree_Model.Gtk_Tree_Path; |
procedure On_Row_Changed
( | Self | : Gtk_Tree_Model; |
Call | : Cb_Gtk_Tree_Model_Gtk_Tree_Path_Gtk_Tree_Iter_Void; | |
After | : Boolean := False); |
procedure On_Row_Changed
( | Self | : Gtk_Tree_Model; |
Call | : Cb_GObject_Gtk_Tree_Path_Gtk_Tree_Iter_Void; | |
Slot | : not null access Glib.Object.GObject_Record'Class; | |
After | : Boolean := False); |
procedure On_Row_Deleted
( | Self | : Gtk_Tree_Model; |
Call | : Cb_Gtk_Tree_Model_Gtk_Tree_Path_Void; | |
After | : Boolean := False); |
procedure On_Row_Deleted
( | Self | : Gtk_Tree_Model; |
Call | : Cb_GObject_Gtk_Tree_Path_Void; | |
Slot | : not null access Glib.Object.GObject_Record'Class; | |
After | : Boolean := False); |
procedure On_Row_Has_Child_Toggled
( | Self | : Gtk_Tree_Model; |
Call | : Cb_Gtk_Tree_Model_Gtk_Tree_Path_Gtk_Tree_Iter_Void; | |
After | : Boolean := False); |
procedure On_Row_Has_Child_Toggled
( | Self | : Gtk_Tree_Model; |
Call | : Cb_GObject_Gtk_Tree_Path_Gtk_Tree_Iter_Void; | |
Slot | : not null access Glib.Object.GObject_Record'Class; | |
After | : Boolean := False); |
procedure On_Row_Inserted
( | Self | : Gtk_Tree_Model; |
Call | : Cb_Gtk_Tree_Model_Gtk_Tree_Path_Gtk_Tree_Iter_Void; | |
After | : Boolean := False); |
procedure On_Row_Inserted
( | Self | : Gtk_Tree_Model; |
Call | : Cb_GObject_Gtk_Tree_Path_Gtk_Tree_Iter_Void; | |
Slot | : not null access Glib.Object.GObject_Record'Class; | |
After | : Boolean := False); |
procedure On_Rows_Reordered
( | Self | : Gtk_Tree_Model; |
Call | : Cb_Gtk_Tree_Model_Gtk_Tree_Path_Gtk_Tree_Iter_Address_Void; | |
After | : Boolean := False); |
procedure On_Rows_Reordered
( | Self | : Gtk_Tree_Model; |
Call | : Cb_GObject_Gtk_Tree_Path_Gtk_Tree_Iter_Address_Void; | |
Slot | : not null access Glib.Object.GObject_Record'Class; | |
After | : Boolean := False); |
function "+"
( | W | : Gtk_Tree_Model) return Gtk_Tree_Model; |
The Gtk.Tree_Model.Gtk_Tree_Model interface defines a generic tree interface for use by the Gtk.Tree_View.Gtk_Tree_View widget. It is an abstract interface, and is designed to be usable with any appropriate data structure. The programmer just has to implement this interface on their own data type for it to be viewable by a Gtk.Tree_View.Gtk_Tree_View widget.
The model is represented as a hierarchical tree of strongly-typed, columned data. In other words, the model can be seen as a tree where every node has different values depending on which column is being queried. The type of data found in a column is determined by using the GType system (ie.
G_TYPE_INT, GTK_TYPE_BUTTON, G_TYPE_POINTER, etc). The types are homogeneous per column across all nodes. It is important to note that this interface only provides a way of examining a model and observing changes.
The implementation of each individual model decides how and if changes are made.
In order to make life simpler for programmers who do not need to write their own specialized model, two generic models are provided — the Gtk.Tree_Store.Gtk_Tree_Store and the Gtk.List_Store.Gtk_List_Store. To use these, the developer simply pushes data into these models as necessary.
These models provide the data structure as well as all appropriate tree interfaces. As a result, implementing drag and drop, sorting, and storing data is trivial. For the vast majority of trees and lists, these two models are sufficient.
Models are accessed on a node/column level of granularity. One can query for the value of a model at a certain node and a certain column on that node. There are two structures used to reference a particular node in a model. They are the Gtk.Tree_Model.Gtk_Tree_Path and the Gtk.Tree_Model.Gtk_Tree_Iter[ Here, <abbrev>iter</abbrev> is short for <quote>iterator</quote>]. Most of the interface consists of operations on a Gtk.Tree_Model.Gtk_Tree_Iter.
A path is essentially a potential node. It is a location on a model that may or may not actually correspond to a node on a specific model. The Gtk.Tree_Model.Gtk_Tree_Path struct can be converted into either an array of unsigned integers or a string. The string form is a list of numbers separated by a colon. Each number refers to the offset at that level. Thus, the path <quote>0</quote> refers to the root node and the path <quote>2:4</quote> refers to the fifth child of the third node.
By contrast, a Gtk.Tree_Model.Gtk_Tree_Iter is a reference to a specific node on a specific model. It is a generic struct with an integer and three generic pointers. These are filled in by the model in a model-specific way.
One can convert a path to an iterator by calling Gtk.Tree_Model.Get_Iter.
These iterators are the primary way of accessing a model and are similar to the iterators used by Gtk.Text_Buffer.Gtk_Text_Buffer. They are generally statically allocated on the stack and only used for a short time. The model interface defines a set of operations using them for navigating the model.
It is expected that models fill in the iterator with private data. For example, the Gtk.List_Store.Gtk_List_Store model, which is internally a simple linked list, stores a list node in one of the pointers. The Gtk.Tree_Model_Sort.Gtk_Tree_Model_Sort stores an array and an offset in two of the pointers. Additionally, there is an integer field. This field is generally filled with a unique stamp per model. This stamp is for catching errors resulting from using invalid iterators with a model.
The lifecycle of an iterator can be a little confusing at first. Iterators are expected to always be valid for as long as the model is unchanged (and doesn't emit a signal). The model is considered to own all outstanding iterators and nothing needs to be done to free them from the user's point of view. Additionally, some models guarantee that an iterator is valid for as long as the node it refers to is valid (most notably the Gtk.Tree_Store.Gtk_Tree_Store and Gtk.List_Store.Gtk_List_Store). Although generally uninteresting, as one always has to allow for the case where iterators do not persist beyond a signal, some very important performance enhancements were made in the sort model. As a result, the GTK_TREE_MODEL_ITERS_PERSIST flag was added to indicate this behavior.
To help show some common operation of a model, some examples are provided.
The first example shows three ways of getting the iter at the location <quote>3:2:5</quote>. While the first method shown is easier, the second is much more common, as you often get paths from callbacks. == Acquiring a <structname>GtkTreeIter</structname> == /* Three ways of getting the iter pointing to the location */ GtkTreePath *path; GtkTreeIter iter; GtkTreeIter parent_iter; /* get the iterator from a string */ gtk_tree_model_get_iter_from_string (model, &iter, "3:2:5"); /* get the iterator from a path */ path = gtk_tree_path_new_from_string ("3:2:5"); gtk_tree_model_get_iter (model, &iter, path); gtk_tree_path_free (path); /* walk the tree to find the iterator */ gtk_tree_model_iter_nth_child (model, &iter, NULL, 3); parent_iter = iter; gtk_tree_model_iter_nth_child (model, &iter, &parent_iter, 2); parent_iter = iter; gtk_tree_model_iter_nth_child (model, &iter, &parent_iter, 5); This second example shows a quick way of iterating through a list and getting a string and an integer from each row. The <function>populate_model</function> function used below is not shown, as it is specific to the Gtk.List_Store.Gtk_List_Store. For information on how to write such a function, see the Gtk.List_Store.Gtk_List_Store documentation. == Reading data from a <structname>GtkTreeModel</structname> == enum { STRING_COLUMN, INT_COLUMN, N_COLUMNS }; ... GtkTreeModel *list_store; GtkTreeIter iter; gboolean valid; gint row_count = 0; /* make a new list_store */ list_store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_INT); /* Fill the list store with data */ populate_model (list_store); /* Get the first iter in the list, check it is valid and walk * through the list, reading each row. */ for (valid = gtk_tree_model_get_iter_first (list_store, &iter); valid; valid = gtk_tree_model_iter_next (list_store, &iter)) { gchar *str_data; gint int_data; /* Make sure you terminate calls to gtk_tree_model_get * with a '-1' value */ gtk_tree_model_get (list_store, &iter, STRING_COLUMN, &str_data, INT_COLUMN, &int_data, -1); /* Do something with the data */ g_print ("Row %d: (%s,%d)\n", row_count, str_data, int_data); g_free (str_data); row_count++; } The Gtk.Tree_Model.Gtk_Tree_Model interface contains two methods for reference counting: Gtk.Tree_Model.Ref_Node and Gtk.Tree_Model.Unref_Node.
These two methods are optional to implement. The reference counting is meant as a way for views to let models know when nodes are being displayed.
Gtk.Tree_View.Gtk_Tree_View will take a reference on a node when it is visible, which means the node is either in the toplevel or expanded. Being displayed does not mean that the node is currently directly visible to the user in the viewport. Based on this reference counting scheme a caching model, for example, can decide whether or not to cache a node based on the reference count. A file-system based model would not want to keep the entire file hierarchy in memory, but just the folders that are currently expanded in every current view.
When working with reference counting, the following rules must be taken into account: * Never take a reference on a node without owning a reference on its parent. This means that all parent nodes of a referenced node must be referenced as well. * Outstanding references on a deleted node are not released. This is not possible because the node has already been deleted by the time the row-deleted signal is received. * Models are not obligated to emit a signal on rows of which none of its siblings are referenced. To phrase this differently, signals are only required for levels in which nodes are referenced. For the root level however, signals must be emitted at all times (however the root level is always referenced when any view is attached).