GTK+ 2 Reference Manual | ||||
---|---|---|---|---|
Top | Description | Object Hierarchy | Implemented Interfaces |
#include <gtk/gtk.h> struct GtkTreeStore; GtkTreeStore * gtk_tree_store_new (gint n_columns
,...
); GtkTreeStore * gtk_tree_store_newv (gint n_columns
,GType *types
); void gtk_tree_store_set_column_types (GtkTreeStore *tree_store
,gint n_columns
,GType *types
); void gtk_tree_store_set_value (GtkTreeStore *tree_store
,GtkTreeIter *iter
,gint column
,GValue *value
); void gtk_tree_store_set (GtkTreeStore *tree_store
,GtkTreeIter *iter
,...
); void gtk_tree_store_set_valist (GtkTreeStore *tree_store
,GtkTreeIter *iter
,va_list var_args
); void gtk_tree_store_set_valuesv (GtkTreeStore *tree_store
,GtkTreeIter *iter
,gint *columns
,GValue *values
,gint n_values
); gboolean gtk_tree_store_remove (GtkTreeStore *tree_store
,GtkTreeIter *iter
); void gtk_tree_store_insert (GtkTreeStore *tree_store
,GtkTreeIter *iter
,GtkTreeIter *parent
,gint position
); void gtk_tree_store_insert_before (GtkTreeStore *tree_store
,GtkTreeIter *iter
,GtkTreeIter *parent
,GtkTreeIter *sibling
); void gtk_tree_store_insert_after (GtkTreeStore *tree_store
,GtkTreeIter *iter
,GtkTreeIter *parent
,GtkTreeIter *sibling
); void gtk_tree_store_insert_with_values (GtkTreeStore *tree_store
,GtkTreeIter *iter
,GtkTreeIter *parent
,gint position
,...
); void gtk_tree_store_insert_with_valuesv (GtkTreeStore *tree_store
,GtkTreeIter *iter
,GtkTreeIter *parent
,gint position
,gint *columns
,GValue *values
,gint n_values
); void gtk_tree_store_prepend (GtkTreeStore *tree_store
,GtkTreeIter *iter
,GtkTreeIter *parent
); void gtk_tree_store_append (GtkTreeStore *tree_store
,GtkTreeIter *iter
,GtkTreeIter *parent
); gboolean gtk_tree_store_is_ancestor (GtkTreeStore *tree_store
,GtkTreeIter *iter
,GtkTreeIter *descendant
); gint gtk_tree_store_iter_depth (GtkTreeStore *tree_store
,GtkTreeIter *iter
); void gtk_tree_store_clear (GtkTreeStore *tree_store
); gboolean gtk_tree_store_iter_is_valid (GtkTreeStore *tree_store
,GtkTreeIter *iter
); void gtk_tree_store_reorder (GtkTreeStore *tree_store
,GtkTreeIter *parent
,gint *new_order
); void gtk_tree_store_swap (GtkTreeStore *tree_store
,GtkTreeIter *a
,GtkTreeIter *b
); void gtk_tree_store_move_before (GtkTreeStore *tree_store
,GtkTreeIter *iter
,GtkTreeIter *position
); void gtk_tree_store_move_after (GtkTreeStore *tree_store
,GtkTreeIter *iter
,GtkTreeIter *position
);
GtkTreeStore implements GtkTreeModel, GtkTreeDragSource, GtkTreeDragDest, GtkTreeSortable and GtkBuildable.
The GtkTreeStore 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
The GtkTreeStore implementation of the GtkBuildable 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.
Example 29. A UI Definition fragment for a tree store
1 2 3 4 5 6 7 |
<object class="GtkTreeStore"> <columns> <column type="gchararray"/> <column type="gchararray"/> <column type="gint"/> </columns> </object> |
GtkTreeStore * gtk_tree_store_new (gint n_columns
,...
);
Creates a new tree store as with n_columns
columns each of the types passed
in. Note that only types derived from standard GObject fundamental types
are supported.
As an example, gtk_tree_store_new (3, G_TYPE_INT, G_TYPE_STRING,
GDK_TYPE_PIXBUF);
will create a new GtkTreeStore with three columns, of type
int, string and GdkPixbuf respectively.
|
number of columns in the tree store |
Returns : |
a new GtkTreeStore |
GtkTreeStore * gtk_tree_store_newv (gint n_columns
,GType *types
);
Non vararg creation function. Used primarily by language bindings.
|
number of columns in the tree store |
|
an array of GType types for the columns, from first to last. [array length=n_columns] |
Returns : |
a new GtkTreeStore. [transfer full] |
void gtk_tree_store_set_column_types (GtkTreeStore *tree_store
,gint n_columns
,GType *types
);
This function is meant primarily for GObjects that inherit from GtkTreeStore, and should only be used when constructing a new GtkTreeStore. It will not function after a row has been added, or a method on the GtkTreeModel interface is called.
|
A GtkTreeStore |
|
Number of columns for the tree store |
|
An array of GType types, one for each column. [array length=n_columns] |
void gtk_tree_store_set_value (GtkTreeStore *tree_store
,GtkTreeIter *iter
,gint column
,GValue *value
);
Sets the data in the cell specified by iter
and column
.
The type of value
must be convertible to the type of the
column.
|
a GtkTreeStore |
|
A valid GtkTreeIter for the row being modified |
|
column number to modify |
|
new value for the cell |
void gtk_tree_store_set (GtkTreeStore *tree_store
,GtkTreeIter *iter
,...
);
Sets the value of one or more cells in the row referenced by iter
.
The variable argument list should contain integer column numbers,
each column number followed by the value to be set.
The list is terminated by a -1. For example, to set column 0 with type
G_TYPE_STRING
to "Foo", you would write
gtk_tree_store_set (store, iter, 0, "Foo", -1)
.
The value will be referenced by the store if it is a G_TYPE_OBJECT
, and it
will be copied if it is a G_TYPE_STRING
or G_TYPE_BOXED
.
|
A GtkTreeStore |
|
A valid GtkTreeIter for the row being modified |
void gtk_tree_store_set_valist (GtkTreeStore *tree_store
,GtkTreeIter *iter
,va_list var_args
);
See gtk_tree_store_set()
; this version takes a va_list for
use by language bindings.
|
A GtkTreeStore |
|
A valid GtkTreeIter for the row being modified |
|
va_list of column/value pairs |
void gtk_tree_store_set_valuesv (GtkTreeStore *tree_store
,GtkTreeIter *iter
,gint *columns
,GValue *values
,gint n_values
);
A variant of gtk_tree_store_set_valist()
which takes
the columns and values as two arrays, instead of varargs. This
function is mainly intended for language bindings or in case
the number of columns to change is not known until run-time.
|
A GtkTreeStore |
|
A valid GtkTreeIter for the row being modified |
|
an array of column numbers. [array length=n_values] |
|
an array of GValues. [array length=n_values] |
|
the length of the columns and values arrays |
Since 2.12
gboolean gtk_tree_store_remove (GtkTreeStore *tree_store
,GtkTreeIter *iter
);
Removes iter
from tree_store
. After being removed, iter
is set to the
next valid row at that level, or invalidated if it previously pointed to the
last one.
|
A GtkTreeStore |
|
A valid GtkTreeIter |
Returns : |
TRUE if iter is still valid, FALSE if not. |
void gtk_tree_store_insert (GtkTreeStore *tree_store
,GtkTreeIter *iter
,GtkTreeIter *parent
,gint position
);
Creates a new row at position
. If parent is non-NULL
, then the row will be
made a child of parent
. Otherwise, the row will be created at the toplevel.
If position
is larger than the number of rows at that level, then the new
row will be inserted 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_tree_store_set()
or
gtk_tree_store_set_value()
.
|
A GtkTreeStore |
|
An unset GtkTreeIter to set to the new row. [out] |
|
A valid GtkTreeIter, or NULL . [allow-none]
|
|
position to insert the new row |
void gtk_tree_store_insert_before (GtkTreeStore *tree_store
,GtkTreeIter *iter
,GtkTreeIter *parent
,GtkTreeIter *sibling
);
Inserts a new row before sibling
. If sibling
is NULL
, then the row will
be appended to parent
's children. If parent
and sibling
are NULL
, then
the row will be appended to the toplevel. If both sibling
and parent
are
set, then parent
must be the parent of sibling
. When sibling
is set,
parent
is optional.
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_tree_store_set()
or gtk_tree_store_set_value()
.
|
A GtkTreeStore |
|
An unset GtkTreeIter to set to the new row. [out] |
|
A valid GtkTreeIter, or NULL . [allow-none]
|
|
A valid GtkTreeIter, or NULL . [allow-none]
|
void gtk_tree_store_insert_after (GtkTreeStore *tree_store
,GtkTreeIter *iter
,GtkTreeIter *parent
,GtkTreeIter *sibling
);
Inserts a new row after sibling
. If sibling
is NULL
, then the row will be
prepended to parent
's children. If parent
and sibling
are NULL
, then
the row will be prepended to the toplevel. If both sibling
and parent
are
set, then parent
must be the parent of sibling
. When sibling
is set,
parent
is optional.
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_tree_store_set()
or gtk_tree_store_set_value()
.
|
A GtkTreeStore |
|
An unset GtkTreeIter to set to the new row. [out] |
|
A valid GtkTreeIter, or NULL . [allow-none]
|
|
A valid GtkTreeIter, or NULL . [allow-none]
|
void gtk_tree_store_insert_with_values (GtkTreeStore *tree_store
,GtkTreeIter *iter
,GtkTreeIter *parent
,gint position
,...
);
Creates a new row at position
. iter
will be changed to point to this
new row. If position
is larger than the number of rows on the list, then
the new row will be appended to the list. The row will be filled with
the values given to this function.
Calling
gtk_tree_store_insert_with_values (tree_store, iter, position, ...)
has the same effect as calling
1 2 |
gtk_tree_store_insert (tree_store, iter, position); gtk_tree_store_set (tree_store, iter, ...); |
with the different that the former will only emit a row_inserted signal,
while the latter will emit row_inserted, row_changed and if the tree store
is sorted, rows_reordered. Since emitting the rows_reordered signal
repeatedly can affect the performance of the program,
gtk_tree_store_insert_with_values()
should generally be preferred when
inserting rows in a sorted tree store.
|
A GtkTreeStore |
|
An unset GtkTreeIter to set the new row, or NULL . [out][allow-none]
|
|
A valid GtkTreeIter, or NULL . [allow-none]
|
|
position to insert the new row |
Since 2.10
void gtk_tree_store_insert_with_valuesv (GtkTreeStore *tree_store
,GtkTreeIter *iter
,GtkTreeIter *parent
,gint position
,gint *columns
,GValue *values
,gint n_values
);
A variant of gtk_tree_store_insert_with_values()
which takes
the columns and values as two arrays, instead of varargs. This
function is mainly intended for language bindings.
|
A GtkTreeStore |
|
An unset GtkTreeIter to set the new row, or NULL . [out][allow-none]
|
|
A valid GtkTreeIter, or NULL . [allow-none]
|
|
position to insert the new row |
|
an array of column numbers. [array length=n_values] |
|
an array of GValues. [array length=n_values] |
|
the length of the columns and values arrays |
Since 2.10
void gtk_tree_store_prepend (GtkTreeStore *tree_store
,GtkTreeIter *iter
,GtkTreeIter *parent
);
Prepends a new row to tree_store
. If parent
is non-NULL
, then it will prepend
the new row before the first child of parent
, otherwise it will prepend a row
to the top level. 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_tree_store_set()
or gtk_tree_store_set_value()
.
|
A GtkTreeStore |
|
An unset GtkTreeIter to set to the prepended row. [out] |
|
A valid GtkTreeIter, or NULL . [allow-none]
|
void gtk_tree_store_append (GtkTreeStore *tree_store
,GtkTreeIter *iter
,GtkTreeIter *parent
);
Appends a new row to tree_store
. If parent
is non-NULL
, then it will append the
new row after the last child of parent
, otherwise it will append a row to
the top level. 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_tree_store_set()
or gtk_tree_store_set_value()
.
|
A GtkTreeStore |
|
An unset GtkTreeIter to set to the appended row. [out] |
|
A valid GtkTreeIter, or NULL . [allow-none]
|
gboolean gtk_tree_store_is_ancestor (GtkTreeStore *tree_store
,GtkTreeIter *iter
,GtkTreeIter *descendant
);
Returns TRUE
if iter
is an ancestor of descendant
. That is, iter
is the
parent (or grandparent or great-grandparent) of descendant
.
|
A GtkTreeStore |
|
A valid GtkTreeIter |
|
A valid GtkTreeIter |
Returns : |
TRUE , if iter is an ancestor of descendant
|
gint gtk_tree_store_iter_depth (GtkTreeStore *tree_store
,GtkTreeIter *iter
);
Returns the depth of iter
. This will be 0 for anything on the root level, 1
for anything down a level, etc.
|
A GtkTreeStore |
|
A valid GtkTreeIter |
Returns : |
The depth of iter
|
void gtk_tree_store_clear (GtkTreeStore *tree_store
);
Removes all rows from tree_store
|
a GtkTreeStore |
gboolean gtk_tree_store_iter_is_valid (GtkTreeStore *tree_store
,GtkTreeIter *iter
);
WARNING: This function is slow. Only use it for debugging and/or testing purposes.
Checks if the given iter is a valid iter for this GtkTreeStore.
|
A GtkTreeStore. |
|
A GtkTreeIter. |
Returns : |
TRUE if the iter is valid, FALSE if the iter is invalid. |
Since 2.2
void gtk_tree_store_reorder (GtkTreeStore *tree_store
,GtkTreeIter *parent
,gint *new_order
);
Reorders the children of parent
in tree_store
to follow the order
indicated by new_order
. Note that this function only works with
unsorted stores.
|
A GtkTreeStore. |
|
A GtkTreeIter. |
|
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 . [array]
|
Since 2.2
void gtk_tree_store_swap (GtkTreeStore *tree_store
,GtkTreeIter *a
,GtkTreeIter *b
);
Swaps a
and b
in the same level of tree_store
. Note that this function
only works with unsorted stores.
|
A GtkTreeStore. |
|
A GtkTreeIter. |
|
Another GtkTreeIter. |
Since 2.2
void gtk_tree_store_move_before (GtkTreeStore *tree_store
,GtkTreeIter *iter
,GtkTreeIter *position
);
Moves iter
in tree_store
to the position before position
. iter
and
position
should be in the same level. Note that this function only
works with unsorted stores. If position
is NULL
, iter
will be
moved to the end of the level.
|
A GtkTreeStore. |
|
A GtkTreeIter. |
|
A GtkTreeIter or NULL . [allow-none]
|
Since 2.2
void gtk_tree_store_move_after (GtkTreeStore *tree_store
,GtkTreeIter *iter
,GtkTreeIter *position
);
Moves iter
in tree_store
to the position after position
. iter
and
position
should be in the same level. Note that this function only
works with unsorted stores. If position
is NULL
, iter
will be moved
to the start of the level.
|
A GtkTreeStore. |
|
A GtkTreeIter. |
|
A GtkTreeIter. [allow-none] |
Since 2.2