GTK+ Reference Manual | ||||
---|---|---|---|---|
Top | Description | Object Hierarchy | Prerequisites | Known Implementations | Signals |
#include <gtk/gtk.h> GtkTreeSortable; GtkTreeSortableIface; gint (*GtkTreeIterCompareFunc) (GtkTreeModel *model
,GtkTreeIter *a
,GtkTreeIter *b
,gpointer user_data
); void gtk_tree_sortable_sort_column_changed (GtkTreeSortable *sortable
); gboolean gtk_tree_sortable_get_sort_column_id (GtkTreeSortable *sortable
,gint *sort_column_id
,GtkSortType *order
); void gtk_tree_sortable_set_sort_column_id (GtkTreeSortable *sortable
,gint sort_column_id
,GtkSortType order
); void gtk_tree_sortable_set_sort_func (GtkTreeSortable *sortable
,gint sort_column_id
,GtkTreeIterCompareFunc sort_func
,gpointer user_data
,GDestroyNotify destroy
); void gtk_tree_sortable_set_default_sort_func (GtkTreeSortable *sortable
,GtkTreeIterCompareFunc sort_func
,gpointer user_data
,GDestroyNotify destroy
); gboolean gtk_tree_sortable_has_default_sort_func (GtkTreeSortable *sortable
);
GtkTreeSortable is implemented by GtkListStore, GtkTreeModelSort and GtkTreeStore.
GtkTreeSortable is an interface to be implemented by tree models which support sorting. The GtkTreeView uses the methods provided by this interface to sort the model.
typedef struct { GTypeInterface g_iface; /* signals */ void (* sort_column_changed) (GtkTreeSortable *sortable); /* virtual table */ gboolean (* get_sort_column_id) (GtkTreeSortable *sortable, gint *sort_column_id, GtkSortType *order); void (* set_sort_column_id) (GtkTreeSortable *sortable, gint sort_column_id, GtkSortType order); void (* set_sort_func) (GtkTreeSortable *sortable, gint sort_column_id, GtkTreeIterCompareFunc func, gpointer data, GDestroyNotify destroy); void (* set_default_sort_func) (GtkTreeSortable *sortable, GtkTreeIterCompareFunc func, gpointer data, GDestroyNotify destroy); gboolean (* has_default_sort_func) (GtkTreeSortable *sortable); } GtkTreeSortableIface;
gint (*GtkTreeIterCompareFunc) (GtkTreeModel *model
,GtkTreeIter *a
,GtkTreeIter *b
,gpointer user_data
);
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
|
|
Data passed when the compare func is assigned e.g. by
gtk_tree_sortable_set_sort_func()
|
Returns : |
a negative integer, zero or a positive integer depending on whether
a sorts before, with or after b
|
void gtk_tree_sortable_sort_column_changed
(GtkTreeSortable *sortable
);
Emits a "sort-column-changed" signal on sortable
.
|
A GtkTreeSortable |
gboolean gtk_tree_sortable_get_sort_column_id (GtkTreeSortable *sortable
,gint *sort_column_id
,GtkSortType *order
);
Fills in sort_column_id
and order
with the current sort column and the
order. It returns TRUE
unless the sort_column_id
is
GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID
or
GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID
.
|
A GtkTreeSortable |
|
The sort column id to be filled in |
|
The GtkSortType to be filled in |
Returns : |
TRUE if the sort column is not one of the special sort
column ids.
|
void gtk_tree_sortable_set_sort_column_id (GtkTreeSortable *sortable
,gint sort_column_id
,GtkSortType order
);
Sets the current sort column to be sort_column_id
. The sortable
will
resort itself to reflect this change, after emitting a
"sort-column-changed" signal. sort_column_id
may either be
a regular column id, or one of the following special values:
|
the default sort function will be used, if it is set |
|
no sorting will occur |
|
A GtkTreeSortable |
|
the sort column id to set |
|
The sort order of the column |
void gtk_tree_sortable_set_sort_func (GtkTreeSortable *sortable
,gint sort_column_id
,GtkTreeIterCompareFunc sort_func
,gpointer user_data
,GDestroyNotify destroy
);
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.
|
A GtkTreeSortable |
|
the sort column id to set the function for |
|
The comparison function |
|
User data to pass to sort_func , or NULL . [allow-none]
|
|
Destroy notifier of user_data , or NULL . [allow-none]
|
void gtk_tree_sortable_set_default_sort_func (GtkTreeSortable *sortable
,GtkTreeIterCompareFunc sort_func
,gpointer user_data
,GDestroyNotify destroy
);
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.
|
A GtkTreeSortable |
|
The comparison function |
|
User data to pass to sort_func , or NULL . [allow-none]
|
|
Destroy notifier of user_data , or NULL . [allow-none]
|
gboolean gtk_tree_sortable_has_default_sort_func
(GtkTreeSortable *sortable
);
Returns TRUE
if the model has a default sort function. This is used
primarily by GtkTreeViewColumns in order to determine if a model can
go back to the default state, or not.
|
A GtkTreeSortable |
Returns : |
TRUE , if the model has a default sort function
|
"sort-column-changed"
signalvoid user_function (GtkTreeSortable *sortable, gpointer user_data) : Run Last
The ::sort-column-changed signal is emitted when the sort column
or sort order of sortable
is changed. The signal is emitted before
the contents of sortable
are resorted.
|
the object on which the signal is emitted |
|
user data set when the signal handler was connected. |