forked from AuroraMiddleware/gtk
Add convertion functions to let you convert to and from relative path's
2000-11-20 Jonathan Blandford <jrb@redhat.com> * gtk/gtktreemodelsort.h: Add convertion functions to let you convert to and from relative path's and iters. * gtk/treestoretest.c: move to having a sorted/unsorted view. Start testing sorting functions a bit better. Currently broken -- will fix in morning.
This commit is contained in:
parent
18dd625fa3
commit
7a2e1974f0
@ -1,3 +1,11 @@
|
|||||||
|
2000-11-20 Jonathan Blandford <jrb@redhat.com>
|
||||||
|
* gtk/gtktreemodelsort.h: Add convertion functions to let you
|
||||||
|
convert to and from relative path's and iters.
|
||||||
|
|
||||||
|
* gtk/treestoretest.c: move to having a sorted/unsorted view. Start
|
||||||
|
testing sorting functions a bit better. Currently broken -- will
|
||||||
|
fix in morning.
|
||||||
|
|
||||||
2000-11-20 Havoc Pennington <hp@redhat.com>
|
2000-11-20 Havoc Pennington <hp@redhat.com>
|
||||||
|
|
||||||
* gtk/gtkwidget.c: Documented a bunch of functions in here
|
* gtk/gtkwidget.c: Documented a bunch of functions in here
|
||||||
|
@ -1,3 +1,11 @@
|
|||||||
|
2000-11-20 Jonathan Blandford <jrb@redhat.com>
|
||||||
|
* gtk/gtktreemodelsort.h: Add convertion functions to let you
|
||||||
|
convert to and from relative path's and iters.
|
||||||
|
|
||||||
|
* gtk/treestoretest.c: move to having a sorted/unsorted view. Start
|
||||||
|
testing sorting functions a bit better. Currently broken -- will
|
||||||
|
fix in morning.
|
||||||
|
|
||||||
2000-11-20 Havoc Pennington <hp@redhat.com>
|
2000-11-20 Havoc Pennington <hp@redhat.com>
|
||||||
|
|
||||||
* gtk/gtkwidget.c: Documented a bunch of functions in here
|
* gtk/gtkwidget.c: Documented a bunch of functions in here
|
||||||
|
@ -1,3 +1,11 @@
|
|||||||
|
2000-11-20 Jonathan Blandford <jrb@redhat.com>
|
||||||
|
* gtk/gtktreemodelsort.h: Add convertion functions to let you
|
||||||
|
convert to and from relative path's and iters.
|
||||||
|
|
||||||
|
* gtk/treestoretest.c: move to having a sorted/unsorted view. Start
|
||||||
|
testing sorting functions a bit better. Currently broken -- will
|
||||||
|
fix in morning.
|
||||||
|
|
||||||
2000-11-20 Havoc Pennington <hp@redhat.com>
|
2000-11-20 Havoc Pennington <hp@redhat.com>
|
||||||
|
|
||||||
* gtk/gtkwidget.c: Documented a bunch of functions in here
|
* gtk/gtkwidget.c: Documented a bunch of functions in here
|
||||||
|
@ -1,3 +1,11 @@
|
|||||||
|
2000-11-20 Jonathan Blandford <jrb@redhat.com>
|
||||||
|
* gtk/gtktreemodelsort.h: Add convertion functions to let you
|
||||||
|
convert to and from relative path's and iters.
|
||||||
|
|
||||||
|
* gtk/treestoretest.c: move to having a sorted/unsorted view. Start
|
||||||
|
testing sorting functions a bit better. Currently broken -- will
|
||||||
|
fix in morning.
|
||||||
|
|
||||||
2000-11-20 Havoc Pennington <hp@redhat.com>
|
2000-11-20 Havoc Pennington <hp@redhat.com>
|
||||||
|
|
||||||
* gtk/gtkwidget.c: Documented a bunch of functions in here
|
* gtk/gtkwidget.c: Documented a bunch of functions in here
|
||||||
|
@ -1,3 +1,11 @@
|
|||||||
|
2000-11-20 Jonathan Blandford <jrb@redhat.com>
|
||||||
|
* gtk/gtktreemodelsort.h: Add convertion functions to let you
|
||||||
|
convert to and from relative path's and iters.
|
||||||
|
|
||||||
|
* gtk/treestoretest.c: move to having a sorted/unsorted view. Start
|
||||||
|
testing sorting functions a bit better. Currently broken -- will
|
||||||
|
fix in morning.
|
||||||
|
|
||||||
2000-11-20 Havoc Pennington <hp@redhat.com>
|
2000-11-20 Havoc Pennington <hp@redhat.com>
|
||||||
|
|
||||||
* gtk/gtkwidget.c: Documented a bunch of functions in here
|
* gtk/gtkwidget.c: Documented a bunch of functions in here
|
||||||
|
@ -1,3 +1,11 @@
|
|||||||
|
2000-11-20 Jonathan Blandford <jrb@redhat.com>
|
||||||
|
* gtk/gtktreemodelsort.h: Add convertion functions to let you
|
||||||
|
convert to and from relative path's and iters.
|
||||||
|
|
||||||
|
* gtk/treestoretest.c: move to having a sorted/unsorted view. Start
|
||||||
|
testing sorting functions a bit better. Currently broken -- will
|
||||||
|
fix in morning.
|
||||||
|
|
||||||
2000-11-20 Havoc Pennington <hp@redhat.com>
|
2000-11-20 Havoc Pennington <hp@redhat.com>
|
||||||
|
|
||||||
* gtk/gtkwidget.c: Documented a bunch of functions in here
|
* gtk/gtkwidget.c: Documented a bunch of functions in here
|
||||||
|
@ -1,3 +1,11 @@
|
|||||||
|
2000-11-20 Jonathan Blandford <jrb@redhat.com>
|
||||||
|
* gtk/gtktreemodelsort.h: Add convertion functions to let you
|
||||||
|
convert to and from relative path's and iters.
|
||||||
|
|
||||||
|
* gtk/treestoretest.c: move to having a sorted/unsorted view. Start
|
||||||
|
testing sorting functions a bit better. Currently broken -- will
|
||||||
|
fix in morning.
|
||||||
|
|
||||||
2000-11-20 Havoc Pennington <hp@redhat.com>
|
2000-11-20 Havoc Pennington <hp@redhat.com>
|
||||||
|
|
||||||
* gtk/gtkwidget.c: Documented a bunch of functions in here
|
* gtk/gtkwidget.c: Documented a bunch of functions in here
|
||||||
|
@ -19,8 +19,8 @@
|
|||||||
|
|
||||||
|
|
||||||
/* NOTE: There is a potential for confusion in this code as to whether an iter,
|
/* NOTE: There is a potential for confusion in this code as to whether an iter,
|
||||||
* path or value refers to the GtkTreeModelSort model, or the model being
|
* path or value refers to the GtkTreeModelSort model, or the child model being
|
||||||
* sorted. As a convention, variables referencing the sorted model will have an
|
* sorted. As a convention, variables referencing the child model will have an
|
||||||
* s_ prefix before them (ie. s_iter, s_value, s_path);
|
* s_ prefix before them (ie. s_iter, s_value, s_path);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -228,14 +228,14 @@ gtk_tree_model_sort_new (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
GtkTreeModel *
|
GtkTreeModel *
|
||||||
gtk_tree_model_sort_new_with_model (GtkTreeModel *model,
|
gtk_tree_model_sort_new_with_model (GtkTreeModel *child_model,
|
||||||
GValueCompareFunc func,
|
GValueCompareFunc func,
|
||||||
gint sort_col)
|
gint sort_col)
|
||||||
{
|
{
|
||||||
GtkTreeModel *retval;
|
GtkTreeModel *retval;
|
||||||
|
|
||||||
retval = gtk_tree_model_sort_new ();
|
retval = gtk_tree_model_sort_new ();
|
||||||
gtk_tree_model_sort_set_model (GTK_TREE_MODEL_SORT (retval), model);
|
gtk_tree_model_sort_set_model (GTK_TREE_MODEL_SORT (retval), child_model);
|
||||||
|
|
||||||
GTK_TREE_MODEL_SORT (retval)->func = func;
|
GTK_TREE_MODEL_SORT (retval)->func = func;
|
||||||
GTK_TREE_MODEL_SORT (retval)->sort_col = sort_col;
|
GTK_TREE_MODEL_SORT (retval)->sort_col = sort_col;
|
||||||
@ -245,79 +245,78 @@ gtk_tree_model_sort_new_with_model (GtkTreeModel *model,
|
|||||||
/**
|
/**
|
||||||
* gtk_tree_model_sort_set_model:
|
* gtk_tree_model_sort_set_model:
|
||||||
* @tree_model_sort: The #GtkTreeModelSort.
|
* @tree_model_sort: The #GtkTreeModelSort.
|
||||||
* @model: A #GtkTreeModel, or NULL.
|
* @child_model: A #GtkTreeModel, or NULL.
|
||||||
*
|
*
|
||||||
* Sets the model of @tree_model_sort to be @model. If @model is NULL, then the
|
* Sets the model of @tree_model_sort to be @model. If @model is NULL, then the
|
||||||
* old model is unset.
|
* old model is unset.
|
||||||
**/
|
**/
|
||||||
void
|
void
|
||||||
gtk_tree_model_sort_set_model (GtkTreeModelSort *tree_model_sort,
|
gtk_tree_model_sort_set_model (GtkTreeModelSort *tree_model_sort,
|
||||||
GtkTreeModel *model)
|
GtkTreeModel *child_model)
|
||||||
{
|
{
|
||||||
g_return_if_fail (tree_model_sort != NULL);
|
g_return_if_fail (tree_model_sort != NULL);
|
||||||
g_return_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model_sort));
|
g_return_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model_sort));
|
||||||
|
|
||||||
if (model)
|
if (child_model)
|
||||||
g_object_ref (G_OBJECT (model));
|
g_object_ref (G_OBJECT (child_model));
|
||||||
|
|
||||||
if (tree_model_sort->model)
|
if (tree_model_sort->child_model)
|
||||||
{
|
{
|
||||||
gtk_signal_disconnect_by_func (GTK_OBJECT (tree_model_sort->model),
|
gtk_signal_disconnect_by_func (GTK_OBJECT (tree_model_sort->child_model),
|
||||||
gtk_tree_model_sort_changed,
|
gtk_tree_model_sort_changed,
|
||||||
tree_model_sort);
|
tree_model_sort);
|
||||||
gtk_signal_disconnect_by_func (GTK_OBJECT (tree_model_sort->model),
|
gtk_signal_disconnect_by_func (GTK_OBJECT (tree_model_sort->child_model),
|
||||||
gtk_tree_model_sort_inserted,
|
gtk_tree_model_sort_inserted,
|
||||||
tree_model_sort);
|
tree_model_sort);
|
||||||
gtk_signal_disconnect_by_func (GTK_OBJECT (tree_model_sort->model),
|
gtk_signal_disconnect_by_func (GTK_OBJECT (tree_model_sort->child_model),
|
||||||
gtk_tree_model_sort_child_toggled,
|
gtk_tree_model_sort_child_toggled,
|
||||||
tree_model_sort);
|
tree_model_sort);
|
||||||
gtk_signal_disconnect_by_func (GTK_OBJECT (tree_model_sort->model),
|
gtk_signal_disconnect_by_func (GTK_OBJECT (tree_model_sort->child_model),
|
||||||
gtk_tree_model_sort_deleted,
|
gtk_tree_model_sort_deleted,
|
||||||
tree_model_sort);
|
tree_model_sort);
|
||||||
|
|
||||||
g_object_unref (G_OBJECT (tree_model_sort->model));
|
g_object_unref (G_OBJECT (tree_model_sort->child_model));
|
||||||
}
|
}
|
||||||
|
|
||||||
tree_model_sort->model = model;
|
tree_model_sort->child_model = child_model;
|
||||||
|
|
||||||
if (model)
|
if (child_model)
|
||||||
{
|
{
|
||||||
gtk_signal_connect (GTK_OBJECT (model),
|
gtk_signal_connect (GTK_OBJECT (child_model),
|
||||||
"changed",
|
"changed",
|
||||||
gtk_tree_model_sort_changed,
|
gtk_tree_model_sort_changed,
|
||||||
tree_model_sort);
|
tree_model_sort);
|
||||||
gtk_signal_connect (GTK_OBJECT (model),
|
gtk_signal_connect (GTK_OBJECT (child_model),
|
||||||
"inserted",
|
"inserted",
|
||||||
gtk_tree_model_sort_inserted,
|
gtk_tree_model_sort_inserted,
|
||||||
tree_model_sort);
|
tree_model_sort);
|
||||||
gtk_signal_connect (GTK_OBJECT (model),
|
gtk_signal_connect (GTK_OBJECT (child_model),
|
||||||
"child_toggled",
|
"child_toggled",
|
||||||
gtk_tree_model_sort_child_toggled,
|
gtk_tree_model_sort_child_toggled,
|
||||||
tree_model_sort);
|
tree_model_sort);
|
||||||
gtk_signal_connect (GTK_OBJECT (model),
|
gtk_signal_connect (GTK_OBJECT (child_model),
|
||||||
"deleted",
|
"deleted",
|
||||||
gtk_tree_model_sort_deleted,
|
gtk_tree_model_sort_deleted,
|
||||||
tree_model_sort);
|
tree_model_sort);
|
||||||
|
tree_model_sort->flags = gtk_tree_model_get_flags (child_model);
|
||||||
tree_model_sort->flags = gtk_tree_model_get_flags (model);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gtk_tree_model_sort_convert_path:
|
* gtk_tree_model_sort_convert_path:
|
||||||
* @tree_model_sort: The #GtkTreeModelSort.
|
* @tree_model_sort: The #GtkTreeModelSort.
|
||||||
* @path: A #GtkTreePath, relative to the @tree_model_sort 's model.
|
* @path: A #GtkTreePath, relative to the child model.
|
||||||
*
|
*
|
||||||
* Converts the @path to a new path, relative to the sorted position. In other
|
* Converts the @path to a new path, relative to the sorted position. In other
|
||||||
* words, the value found in the @tree_model_sort ->model at the @path, is
|
* words, the value found in the @tree_model_sort ->child_model at the @path, is
|
||||||
* identical to that found in the @tree_model_sort and the return value.
|
* identical to that found in the @tree_model_sort and the return value.
|
||||||
*
|
*
|
||||||
* Return value: A new path, or NULL if @path does not exist in @tree_model_sort
|
* Return value: A new path, or NULL if @path does not exist in @tree_model_sort
|
||||||
* ->model.
|
* ->child_model.
|
||||||
**/
|
**/
|
||||||
GtkTreePath *
|
GtkTreePath *
|
||||||
gtk_tree_model_sort_convert_path (GtkTreeModelSort *tree_model_sort,
|
gtk_tree_model_sort_convert_path (GtkTreeModelSort *tree_model_sort,
|
||||||
GtkTreePath *path)
|
GtkTreePath *child_path)
|
||||||
{
|
{
|
||||||
GtkTreePath *retval;
|
GtkTreePath *retval;
|
||||||
GArray *array;
|
GArray *array;
|
||||||
@ -329,7 +328,7 @@ gtk_tree_model_sort_convert_path (GtkTreeModelSort *tree_model_sort,
|
|||||||
|
|
||||||
retval = gtk_tree_path_new ();
|
retval = gtk_tree_path_new ();
|
||||||
array = (GArray *) tree_model_sort->root;
|
array = (GArray *) tree_model_sort->root;
|
||||||
indices = gtk_tree_path_get_indices (path);
|
indices = gtk_tree_path_get_indices (child_path);
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@ -339,7 +338,7 @@ gtk_tree_model_sort_convert_path (GtkTreeModelSort *tree_model_sort,
|
|||||||
|
|
||||||
if ((array->len < indices[i]) || (array == NULL))
|
if ((array->len < indices[i]) || (array == NULL))
|
||||||
{
|
{
|
||||||
gtk_tree_path_free (path);
|
gtk_tree_path_free (retval);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -354,7 +353,7 @@ gtk_tree_model_sort_convert_path (GtkTreeModelSort *tree_model_sort,
|
|||||||
}
|
}
|
||||||
if (! found)
|
if (! found)
|
||||||
{
|
{
|
||||||
gtk_tree_path_free (path);
|
gtk_tree_path_free (retval);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -363,7 +362,7 @@ gtk_tree_model_sort_convert_path (GtkTreeModelSort *tree_model_sort,
|
|||||||
gtk_tree_model_sort_build_level (tree_model_sort, elt);
|
gtk_tree_model_sort_build_level (tree_model_sort, elt);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
while (i < gtk_tree_path_get_depth (path));
|
while (i < gtk_tree_path_get_depth (child_path));
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
@ -376,7 +375,7 @@ gtk_tree_model_sort_finalize (GObject *object)
|
|||||||
if (tree_model_sort->root)
|
if (tree_model_sort->root)
|
||||||
gtk_tree_model_sort_free_level (tree_model_sort->root);
|
gtk_tree_model_sort_free_level (tree_model_sort->root);
|
||||||
|
|
||||||
g_object_unref (G_OBJECT (tree_model_sort->model));
|
g_object_unref (G_OBJECT (tree_model_sort->child_model));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -458,7 +457,7 @@ gtk_tree_model_sort_insert_value (GtkTreeModelSort *sort,
|
|||||||
func = sort->func;
|
func = sort->func;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
switch (gtk_tree_model_get_column_type (sort->model, sort->sort_col))
|
switch (gtk_tree_model_get_column_type (sort->child_model, sort->sort_col))
|
||||||
{
|
{
|
||||||
case G_TYPE_STRING:
|
case G_TYPE_STRING:
|
||||||
func = &g_value_string_compare_func;
|
func = &g_value_string_compare_func;
|
||||||
@ -469,12 +468,12 @@ gtk_tree_model_sort_insert_value (GtkTreeModelSort *sort,
|
|||||||
default:
|
default:
|
||||||
g_warning ("No comparison function for row %d (Type %s)\n",
|
g_warning ("No comparison function for row %d (Type %s)\n",
|
||||||
sort->sort_col,
|
sort->sort_col,
|
||||||
g_type_name (gtk_tree_model_get_column_type (sort->model, sort->sort_col)));
|
g_type_name (gtk_tree_model_get_column_type (sort->child_model, sort->sort_col)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_tree_model_get_value (sort->model, s_iter, sort->sort_col, &s_value);
|
gtk_tree_model_get_value (sort->child_model, s_iter, sort->sort_col, &s_value);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/* FIXME: we can, as we are an array, do binary search to find the correct
|
/* FIXME: we can, as we are an array, do binary search to find the correct
|
||||||
@ -490,7 +489,7 @@ gtk_tree_model_sort_insert_value (GtkTreeModelSort *sort,
|
|||||||
{
|
{
|
||||||
gint cmp;
|
gint cmp;
|
||||||
tmp_elt = &(g_array_index (array, SortElt, middle));
|
tmp_elt = &(g_array_index (array, SortElt, middle));
|
||||||
gtk_tree_model_get_value (sort->model,
|
gtk_tree_model_get_value (sort->child_model,
|
||||||
(GtkTreeIter *) tmp_elt,
|
(GtkTreeIter *) tmp_elt,
|
||||||
sort->sort_col,
|
sort->sort_col,
|
||||||
&tmp_value);
|
&tmp_value);
|
||||||
@ -512,7 +511,7 @@ gtk_tree_model_sort_insert_value (GtkTreeModelSort *sort,
|
|||||||
gint cmp;
|
gint cmp;
|
||||||
|
|
||||||
tmp_elt = &(g_array_index (array, SortElt, middle));
|
tmp_elt = &(g_array_index (array, SortElt, middle));
|
||||||
gtk_tree_model_get_value (sort->model,
|
gtk_tree_model_get_value (sort->child_model,
|
||||||
(GtkTreeIter *) tmp_elt,
|
(GtkTreeIter *) tmp_elt,
|
||||||
sort->sort_col,
|
sort->sort_col,
|
||||||
&tmp_value);
|
&tmp_value);
|
||||||
@ -673,9 +672,9 @@ static gint
|
|||||||
gtk_tree_model_sort_get_n_columns (GtkTreeModel *tree_model)
|
gtk_tree_model_sort_get_n_columns (GtkTreeModel *tree_model)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model), 0);
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model), 0);
|
||||||
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->model != NULL, 0);
|
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->child_model != NULL, 0);
|
||||||
|
|
||||||
return gtk_tree_model_get_n_columns (GTK_TREE_MODEL_SORT (tree_model)->model);
|
return gtk_tree_model_get_n_columns (GTK_TREE_MODEL_SORT (tree_model)->child_model);
|
||||||
}
|
}
|
||||||
|
|
||||||
static GType
|
static GType
|
||||||
@ -683,9 +682,9 @@ gtk_tree_model_sort_get_column_type (GtkTreeModel *tree_model,
|
|||||||
gint index)
|
gint index)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model), G_TYPE_INVALID);
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model), G_TYPE_INVALID);
|
||||||
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->model != NULL, G_TYPE_INVALID);
|
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->child_model != NULL, G_TYPE_INVALID);
|
||||||
|
|
||||||
return gtk_tree_model_get_column_type (GTK_TREE_MODEL_SORT (tree_model)->model, index);
|
return gtk_tree_model_get_column_type (GTK_TREE_MODEL_SORT (tree_model)->child_model, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -719,7 +718,7 @@ gtk_tree_model_sort_get_iter_helper (GtkTreeModelSort *tree_model_sort,
|
|||||||
depth + 1,
|
depth + 1,
|
||||||
path);
|
path);
|
||||||
|
|
||||||
if (gtk_tree_model_iter_has_child (tree_model_sort->model,
|
if (gtk_tree_model_iter_has_child (tree_model_sort->child_model,
|
||||||
&(elt->iter)))
|
&(elt->iter)))
|
||||||
|
|
||||||
gtk_tree_model_sort_build_level (tree_model_sort, elt);
|
gtk_tree_model_sort_build_level (tree_model_sort, elt);
|
||||||
@ -737,7 +736,7 @@ gtk_tree_model_sort_get_iter (GtkTreeModel *tree_model,
|
|||||||
GtkTreePath *path)
|
GtkTreePath *path)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model), FALSE);
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model), FALSE);
|
||||||
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->model != NULL, FALSE);
|
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->child_model != NULL, FALSE);
|
||||||
|
|
||||||
if (GTK_TREE_MODEL_SORT (tree_model)->root == NULL)
|
if (GTK_TREE_MODEL_SORT (tree_model)->root == NULL)
|
||||||
gtk_tree_model_sort_build_level (GTK_TREE_MODEL_SORT (tree_model), NULL);
|
gtk_tree_model_sort_build_level (GTK_TREE_MODEL_SORT (tree_model), NULL);
|
||||||
@ -752,9 +751,9 @@ gtk_tree_model_sort_get_path (GtkTreeModel *tree_model,
|
|||||||
GtkTreeIter *iter)
|
GtkTreeIter *iter)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model), NULL);
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model), NULL);
|
||||||
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->model != NULL, NULL);
|
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->child_model != NULL, NULL);
|
||||||
|
|
||||||
return gtk_tree_model_get_path (GTK_TREE_MODEL_SORT (tree_model)->model, iter);
|
return gtk_tree_model_get_path (GTK_TREE_MODEL_SORT (tree_model)->child_model, iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -766,12 +765,12 @@ gtk_tree_model_sort_get_value (GtkTreeModel *tree_model,
|
|||||||
SortElt *elt;
|
SortElt *elt;
|
||||||
|
|
||||||
g_return_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model));
|
g_return_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model));
|
||||||
g_return_if_fail (GTK_TREE_MODEL_SORT (tree_model)->model != NULL);
|
g_return_if_fail (GTK_TREE_MODEL_SORT (tree_model)->child_model != NULL);
|
||||||
g_return_if_fail (GTK_TREE_MODEL_SORT (tree_model)->stamp == iter->stamp);
|
g_return_if_fail (GTK_TREE_MODEL_SORT (tree_model)->stamp == iter->stamp);
|
||||||
|
|
||||||
elt = iter->tree_node;
|
elt = iter->tree_node;
|
||||||
|
|
||||||
gtk_tree_model_get_value (GTK_TREE_MODEL_SORT (tree_model)->model, (GtkTreeIter *)elt, column, value);
|
gtk_tree_model_get_value (GTK_TREE_MODEL_SORT (tree_model)->child_model, (GtkTreeIter *)elt, column, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -782,7 +781,7 @@ gtk_tree_model_sort_iter_next (GtkTreeModel *tree_model,
|
|||||||
SortElt *elt;
|
SortElt *elt;
|
||||||
|
|
||||||
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model), FALSE);
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model), FALSE);
|
||||||
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->model != NULL, FALSE);
|
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->child_model != NULL, FALSE);
|
||||||
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->stamp == iter->stamp, FALSE);
|
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->stamp == iter->stamp, FALSE);
|
||||||
|
|
||||||
elt = iter->tree_node;
|
elt = iter->tree_node;
|
||||||
@ -805,7 +804,7 @@ gtk_tree_model_sort_iter_children (GtkTreeModel *tree_model,
|
|||||||
SortElt *elt;
|
SortElt *elt;
|
||||||
|
|
||||||
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model), FALSE);
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model), FALSE);
|
||||||
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->model != NULL, FALSE);
|
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->child_model != NULL, FALSE);
|
||||||
if (parent)
|
if (parent)
|
||||||
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->stamp == parent->stamp, FALSE);
|
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->stamp == parent->stamp, FALSE);
|
||||||
|
|
||||||
@ -818,7 +817,7 @@ gtk_tree_model_sort_iter_children (GtkTreeModel *tree_model,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (elt->children == NULL &&
|
if (elt->children == NULL &&
|
||||||
gtk_tree_model_iter_has_child (GTK_TREE_MODEL_SORT (tree_model)->model, (GtkTreeIter *)elt))
|
gtk_tree_model_iter_has_child (GTK_TREE_MODEL_SORT (tree_model)->child_model, (GtkTreeIter *)elt))
|
||||||
gtk_tree_model_sort_build_level (GTK_TREE_MODEL_SORT (tree_model), elt);
|
gtk_tree_model_sort_build_level (GTK_TREE_MODEL_SORT (tree_model), elt);
|
||||||
|
|
||||||
if (elt->children == NULL)
|
if (elt->children == NULL)
|
||||||
@ -837,14 +836,14 @@ gtk_tree_model_sort_iter_has_child (GtkTreeModel *tree_model,
|
|||||||
SortElt *elt;
|
SortElt *elt;
|
||||||
|
|
||||||
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model), FALSE);
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model), FALSE);
|
||||||
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->model != NULL, FALSE);
|
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->child_model != NULL, FALSE);
|
||||||
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->stamp == iter->stamp, FALSE);
|
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->stamp == iter->stamp, FALSE);
|
||||||
|
|
||||||
elt = iter->tree_node;
|
elt = iter->tree_node;
|
||||||
if (elt->children)
|
if (elt->children)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
return gtk_tree_model_iter_has_child (GTK_TREE_MODEL_SORT (tree_model)->model, (GtkTreeIter *) elt);
|
return gtk_tree_model_iter_has_child (GTK_TREE_MODEL_SORT (tree_model)->child_model, (GtkTreeIter *) elt);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gint
|
static gint
|
||||||
@ -854,14 +853,14 @@ gtk_tree_model_sort_iter_n_children (GtkTreeModel *tree_model,
|
|||||||
SortElt *elt;
|
SortElt *elt;
|
||||||
|
|
||||||
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model), 0);
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model), 0);
|
||||||
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->model != NULL, 0);
|
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->child_model != NULL, 0);
|
||||||
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->stamp == iter->stamp, 0);
|
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->stamp == iter->stamp, 0);
|
||||||
|
|
||||||
elt = iter->tree_node;
|
elt = iter->tree_node;
|
||||||
if (elt->children)
|
if (elt->children)
|
||||||
return elt->children->len;
|
return elt->children->len;
|
||||||
|
|
||||||
return gtk_tree_model_iter_n_children (GTK_TREE_MODEL_SORT (tree_model)->model, (GtkTreeIter *) elt);
|
return gtk_tree_model_iter_n_children (GTK_TREE_MODEL_SORT (tree_model)->child_model, (GtkTreeIter *) elt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -874,7 +873,7 @@ gtk_tree_model_sort_iter_nth_child (GtkTreeModel *tree_model,
|
|||||||
SortElt *elt;
|
SortElt *elt;
|
||||||
|
|
||||||
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model), FALSE);
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model), FALSE);
|
||||||
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->model != NULL, FALSE);
|
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->child_model != NULL, FALSE);
|
||||||
if (parent)
|
if (parent)
|
||||||
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->stamp == parent->stamp, FALSE);
|
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->stamp == parent->stamp, FALSE);
|
||||||
|
|
||||||
@ -883,7 +882,7 @@ gtk_tree_model_sort_iter_nth_child (GtkTreeModel *tree_model,
|
|||||||
|
|
||||||
if (elt->children == NULL)
|
if (elt->children == NULL)
|
||||||
{
|
{
|
||||||
if (gtk_tree_model_iter_has_child (GTK_TREE_MODEL_SORT (tree_model)->model, (GtkTreeIter *)elt))
|
if (gtk_tree_model_iter_has_child (GTK_TREE_MODEL_SORT (tree_model)->child_model, (GtkTreeIter *)elt))
|
||||||
gtk_tree_model_sort_build_level (GTK_TREE_MODEL_SORT (tree_model), elt);
|
gtk_tree_model_sort_build_level (GTK_TREE_MODEL_SORT (tree_model), elt);
|
||||||
else
|
else
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -909,7 +908,7 @@ gtk_tree_model_sort_iter_parent (GtkTreeModel *tree_model,
|
|||||||
SortElt *elt;
|
SortElt *elt;
|
||||||
|
|
||||||
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model), FALSE);
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model), FALSE);
|
||||||
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->model != NULL, FALSE);
|
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->child_model != NULL, FALSE);
|
||||||
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->stamp == child->stamp, FALSE);
|
g_return_val_if_fail (GTK_TREE_MODEL_SORT (tree_model)->stamp == child->stamp, FALSE);
|
||||||
|
|
||||||
elt = iter->tree_node;
|
elt = iter->tree_node;
|
||||||
@ -951,7 +950,7 @@ gtk_tree_model_sort_build_level (GtkTreeModelSort *tree_model_sort,
|
|||||||
parent_iter = & (place->iter);
|
parent_iter = & (place->iter);
|
||||||
|
|
||||||
|
|
||||||
n = gtk_tree_model_iter_n_children (tree_model_sort->model, parent_iter);
|
n = gtk_tree_model_iter_n_children (tree_model_sort->child_model, parent_iter);
|
||||||
|
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
return;
|
return;
|
||||||
@ -963,7 +962,7 @@ gtk_tree_model_sort_build_level (GtkTreeModelSort *tree_model_sort,
|
|||||||
else
|
else
|
||||||
tree_model_sort->root = children;
|
tree_model_sort->root = children;
|
||||||
|
|
||||||
gtk_tree_model_iter_children (tree_model_sort->model,
|
gtk_tree_model_iter_children (tree_model_sort->child_model,
|
||||||
&iter,
|
&iter,
|
||||||
parent_iter);
|
parent_iter);
|
||||||
|
|
||||||
@ -978,7 +977,7 @@ gtk_tree_model_sort_build_level (GtkTreeModelSort *tree_model_sort,
|
|||||||
g_array_append_vals (children, &elt, 1);
|
g_array_append_vals (children, &elt, 1);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
while (gtk_tree_model_iter_next (tree_model_sort->model, &iter));
|
while (gtk_tree_model_iter_next (tree_model_sort->child_model, &iter));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ struct _GtkTreeModelSort
|
|||||||
gpointer root;
|
gpointer root;
|
||||||
gint stamp;
|
gint stamp;
|
||||||
guint flags;
|
guint flags;
|
||||||
GtkTreeModel *model;
|
GtkTreeModel *child_model;
|
||||||
gint sort_col;
|
gint sort_col;
|
||||||
GValueCompareFunc func;
|
GValueCompareFunc func;
|
||||||
};
|
};
|
||||||
@ -73,7 +73,7 @@ struct _GtkTreeModelSortClass
|
|||||||
|
|
||||||
GtkType gtk_tree_model_sort_get_type (void);
|
GtkType gtk_tree_model_sort_get_type (void);
|
||||||
GtkTreeModel *gtk_tree_model_sort_new (void);
|
GtkTreeModel *gtk_tree_model_sort_new (void);
|
||||||
GtkTreeModel *gtk_tree_model_sort_new_with_model (GtkTreeModel *model,
|
GtkTreeModel *gtk_tree_model_sort_new_with_model (GtkTreeModel *child_model,
|
||||||
GValueCompareFunc func,
|
GValueCompareFunc func,
|
||||||
gint sort_col);
|
gint sort_col);
|
||||||
void gtk_tree_model_sort_set_model (GtkTreeModelSort *tree_model_sort,
|
void gtk_tree_model_sort_set_model (GtkTreeModelSort *tree_model_sort,
|
||||||
@ -84,7 +84,10 @@ void gtk_tree_model_sort_set_compare (GtkTreeModelSort *tree_model_
|
|||||||
GValueCompareFunc *func);
|
GValueCompareFunc *func);
|
||||||
void gtk_tree_model_sort_resort (GtkTreeModelSort *tree_model_sort);
|
void gtk_tree_model_sort_resort (GtkTreeModelSort *tree_model_sort);
|
||||||
GtkTreePath *gtk_tree_model_sort_convert_path (GtkTreeModelSort *tree_model_sort,
|
GtkTreePath *gtk_tree_model_sort_convert_path (GtkTreeModelSort *tree_model_sort,
|
||||||
GtkTreePath *path);
|
GtkTreePath *child_path);
|
||||||
|
void gtk_tree_model_sort_convert_iter (GtkTreeModelSort *tree_model_sort,
|
||||||
|
GtkTreeIter *sort_iter,
|
||||||
|
GtkTreeIter *child_iter);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
GtkTreeStore *model;
|
GtkTreeStore *base_model;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
selection_changed (GtkTreeSelection *selection,
|
selection_changed (GtkTreeSelection *selection,
|
||||||
@ -17,23 +18,35 @@ static void
|
|||||||
node_set (GtkTreeIter *iter)
|
node_set (GtkTreeIter *iter)
|
||||||
{
|
{
|
||||||
static gint i = 0;
|
static gint i = 0;
|
||||||
|
|
||||||
gchar *str;
|
gchar *str;
|
||||||
|
|
||||||
str = g_strdup_printf ("FOO: %d", i++);
|
str = g_strdup_printf ("FOO: %d", i++);
|
||||||
gtk_tree_store_set (model, iter, 0, str, -1);
|
gtk_tree_store_set (base_model, iter, 0, str, -1);
|
||||||
g_free (str);
|
g_free (str);
|
||||||
|
|
||||||
|
str = g_strdup_printf ("%d", g_random_int ());
|
||||||
|
gtk_tree_store_set (base_model, iter, 1, str, -1);
|
||||||
|
g_free (str);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
iter_remove (GtkWidget *button, GtkTreeView *tree_view)
|
iter_remove (GtkWidget *button, GtkTreeView *tree_view)
|
||||||
{
|
{
|
||||||
GtkTreeIter selected;
|
GtkTreeIter selected;
|
||||||
if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
|
GtkTreeIter s_selected;
|
||||||
|
GtkTreeModel *model;
|
||||||
|
|
||||||
|
model = gtk_tree_view_get_model (tree_view);
|
||||||
|
|
||||||
|
if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (tree_view),
|
||||||
NULL,
|
NULL,
|
||||||
&selected))
|
&selected))
|
||||||
{
|
{
|
||||||
gtk_tree_store_remove (model, &selected);
|
if (GTK_IS_TREE_STORE (model))
|
||||||
|
{
|
||||||
|
gtk_tree_store_remove (GTK_TREE_STORE (model), &selected);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,6 +56,7 @@ iter_insert (GtkWidget *button, GtkTreeView *tree_view)
|
|||||||
GtkWidget *entry;
|
GtkWidget *entry;
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
GtkTreeIter selected;
|
GtkTreeIter selected;
|
||||||
|
GtkTreeStore *model = gtk_tree_view_get_model (tree_view);
|
||||||
|
|
||||||
entry = gtk_object_get_user_data (GTK_OBJECT (button));
|
entry = gtk_object_get_user_data (GTK_OBJECT (button));
|
||||||
if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
|
if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
|
||||||
@ -70,6 +84,7 @@ iter_insert_before (GtkWidget *button, GtkTreeView *tree_view)
|
|||||||
{
|
{
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
GtkTreeIter selected;
|
GtkTreeIter selected;
|
||||||
|
GtkTreeStore *model = gtk_tree_view_get_model (tree_view);
|
||||||
|
|
||||||
if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
|
if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
|
||||||
NULL,
|
NULL,
|
||||||
@ -96,6 +111,7 @@ iter_insert_after (GtkWidget *button, GtkTreeView *tree_view)
|
|||||||
{
|
{
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
GtkTreeIter selected;
|
GtkTreeIter selected;
|
||||||
|
GtkTreeStore *model = gtk_tree_view_get_model (tree_view);
|
||||||
|
|
||||||
if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
|
if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
|
||||||
NULL,
|
NULL,
|
||||||
@ -122,23 +138,29 @@ iter_prepend (GtkWidget *button, GtkTreeView *tree_view)
|
|||||||
{
|
{
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
GtkTreeIter selected;
|
GtkTreeIter selected;
|
||||||
|
GtkTreeModel *model = gtk_tree_view_get_model (tree_view);
|
||||||
|
GtkTreeSelection *selection = gtk_tree_view_get_selection (tree_view);
|
||||||
|
|
||||||
if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
|
if (gtk_tree_selection_get_selected (selection, NULL, &selected))
|
||||||
NULL,
|
|
||||||
&selected))
|
|
||||||
{
|
{
|
||||||
gtk_tree_store_prepend (model,
|
if (GTK_IS_TREE_STORE (model))
|
||||||
|
{
|
||||||
|
gtk_tree_store_prepend (GTK_TREE_STORE (model),
|
||||||
&iter,
|
&iter,
|
||||||
&selected);
|
&selected);
|
||||||
|
node_set (&iter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gtk_tree_store_prepend (model,
|
if (GTK_IS_TREE_STORE (model))
|
||||||
|
{
|
||||||
|
gtk_tree_store_prepend (GTK_TREE_STORE (model),
|
||||||
&iter,
|
&iter,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
|
||||||
|
|
||||||
node_set (&iter);
|
node_set (&iter);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -146,25 +168,31 @@ iter_append (GtkWidget *button, GtkTreeView *tree_view)
|
|||||||
{
|
{
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
GtkTreeIter selected;
|
GtkTreeIter selected;
|
||||||
|
GtkTreeStore *model = gtk_tree_view_get_model (tree_view);
|
||||||
|
|
||||||
if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
|
if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
|
||||||
NULL,
|
NULL,
|
||||||
&selected))
|
&selected))
|
||||||
|
{
|
||||||
|
if (GTK_IS_TREE_STORE (model))
|
||||||
{
|
{
|
||||||
gtk_tree_store_append (model, &iter, &selected);
|
gtk_tree_store_append (model, &iter, &selected);
|
||||||
|
node_set (&iter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
if (GTK_IS_TREE_STORE (model))
|
||||||
{
|
{
|
||||||
gtk_tree_store_append (model, &iter, NULL);
|
gtk_tree_store_append (model, &iter, NULL);
|
||||||
}
|
|
||||||
|
|
||||||
node_set (&iter);
|
node_set (&iter);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
make_window ()
|
make_window (gboolean use_sort)
|
||||||
{
|
{
|
||||||
GtkTreeModel *sort_model;
|
|
||||||
GtkWidget *window;
|
GtkWidget *window;
|
||||||
GtkWidget *vbox;
|
GtkWidget *vbox;
|
||||||
GtkWidget *hbox, *entry;
|
GtkWidget *hbox, *entry;
|
||||||
@ -177,13 +205,28 @@ make_window ()
|
|||||||
|
|
||||||
/* Make the Widgets/Objects */
|
/* Make the Widgets/Objects */
|
||||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||||
|
if (use_sort)
|
||||||
|
gtk_window_set_title (GTK_WINDOW (window), "Sorted list");
|
||||||
|
else
|
||||||
|
gtk_window_set_title (GTK_WINDOW (window), "Unsorted list");
|
||||||
|
|
||||||
vbox = gtk_vbox_new (FALSE, 8);
|
vbox = gtk_vbox_new (FALSE, 8);
|
||||||
gtk_container_set_border_width (GTK_CONTAINER (vbox), 8);
|
gtk_container_set_border_width (GTK_CONTAINER (vbox), 8);
|
||||||
gtk_window_set_default_size (GTK_WINDOW (window), 300, 350);
|
gtk_window_set_default_size (GTK_WINDOW (window), 300, 350);
|
||||||
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
|
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
|
||||||
sort_model = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (model),
|
if (use_sort)
|
||||||
|
{
|
||||||
|
GtkTreeModel *sort_model;
|
||||||
|
|
||||||
|
sort_model = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (base_model),
|
||||||
NULL, 0);
|
NULL, 0);
|
||||||
tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (sort_model));
|
tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (sort_model));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (base_model));
|
||||||
|
}
|
||||||
|
|
||||||
selection = GTK_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)));
|
selection = GTK_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)));
|
||||||
gtk_tree_selection_set_type (GTK_TREE_SELECTION (selection), GTK_TREE_SELECTION_SINGLE);
|
gtk_tree_selection_set_type (GTK_TREE_SELECTION (selection), GTK_TREE_SELECTION_SINGLE);
|
||||||
|
|
||||||
@ -244,14 +287,20 @@ make_window ()
|
|||||||
|
|
||||||
/* The selected column */
|
/* The selected column */
|
||||||
cell = gtk_cell_renderer_text_new ();
|
cell = gtk_cell_renderer_text_new ();
|
||||||
column = gtk_tree_view_column_new_with_attributes ("nodes", cell, "text", 0, NULL);
|
column = gtk_tree_view_column_new_with_attributes ("Node ID", cell, "text", 0, NULL);
|
||||||
|
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
|
||||||
|
|
||||||
|
cell = gtk_cell_renderer_text_new ();
|
||||||
|
column = gtk_tree_view_column_new_with_attributes ("Random Number", cell, "text", 1, NULL);
|
||||||
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
|
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
|
||||||
|
|
||||||
/* A few to start */
|
/* A few to start */
|
||||||
|
if (!use_sort)
|
||||||
|
{
|
||||||
iter_prepend (NULL, GTK_TREE_VIEW (tree_view));
|
iter_prepend (NULL, GTK_TREE_VIEW (tree_view));
|
||||||
iter_prepend (NULL, GTK_TREE_VIEW (tree_view));
|
iter_prepend (NULL, GTK_TREE_VIEW (tree_view));
|
||||||
iter_prepend (NULL, GTK_TREE_VIEW (tree_view));
|
iter_prepend (NULL, GTK_TREE_VIEW (tree_view));
|
||||||
|
}
|
||||||
/* Show it all */
|
/* Show it all */
|
||||||
gtk_widget_show_all (window);
|
gtk_widget_show_all (window);
|
||||||
}
|
}
|
||||||
@ -261,10 +310,11 @@ main (int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
gtk_init (&argc, &argv);
|
gtk_init (&argc, &argv);
|
||||||
|
|
||||||
model = gtk_tree_store_new_with_types (2, G_TYPE_STRING, G_TYPE_STRING);
|
base_model = gtk_tree_store_new_with_types (2, G_TYPE_STRING, G_TYPE_STRING);
|
||||||
|
|
||||||
make_window ();
|
/* FIXME: reverse this */
|
||||||
make_window ();
|
make_window (FALSE);
|
||||||
|
make_window (TRUE);
|
||||||
|
|
||||||
gtk_main ();
|
gtk_main ();
|
||||||
|
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
GtkTreeStore *model;
|
GtkTreeStore *base_model;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
selection_changed (GtkTreeSelection *selection,
|
selection_changed (GtkTreeSelection *selection,
|
||||||
@ -17,23 +18,35 @@ static void
|
|||||||
node_set (GtkTreeIter *iter)
|
node_set (GtkTreeIter *iter)
|
||||||
{
|
{
|
||||||
static gint i = 0;
|
static gint i = 0;
|
||||||
|
|
||||||
gchar *str;
|
gchar *str;
|
||||||
|
|
||||||
str = g_strdup_printf ("FOO: %d", i++);
|
str = g_strdup_printf ("FOO: %d", i++);
|
||||||
gtk_tree_store_set (model, iter, 0, str, -1);
|
gtk_tree_store_set (base_model, iter, 0, str, -1);
|
||||||
g_free (str);
|
g_free (str);
|
||||||
|
|
||||||
|
str = g_strdup_printf ("%d", g_random_int ());
|
||||||
|
gtk_tree_store_set (base_model, iter, 1, str, -1);
|
||||||
|
g_free (str);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
iter_remove (GtkWidget *button, GtkTreeView *tree_view)
|
iter_remove (GtkWidget *button, GtkTreeView *tree_view)
|
||||||
{
|
{
|
||||||
GtkTreeIter selected;
|
GtkTreeIter selected;
|
||||||
if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
|
GtkTreeIter s_selected;
|
||||||
|
GtkTreeModel *model;
|
||||||
|
|
||||||
|
model = gtk_tree_view_get_model (tree_view);
|
||||||
|
|
||||||
|
if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (tree_view),
|
||||||
NULL,
|
NULL,
|
||||||
&selected))
|
&selected))
|
||||||
{
|
{
|
||||||
gtk_tree_store_remove (model, &selected);
|
if (GTK_IS_TREE_STORE (model))
|
||||||
|
{
|
||||||
|
gtk_tree_store_remove (GTK_TREE_STORE (model), &selected);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,6 +56,7 @@ iter_insert (GtkWidget *button, GtkTreeView *tree_view)
|
|||||||
GtkWidget *entry;
|
GtkWidget *entry;
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
GtkTreeIter selected;
|
GtkTreeIter selected;
|
||||||
|
GtkTreeStore *model = gtk_tree_view_get_model (tree_view);
|
||||||
|
|
||||||
entry = gtk_object_get_user_data (GTK_OBJECT (button));
|
entry = gtk_object_get_user_data (GTK_OBJECT (button));
|
||||||
if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
|
if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
|
||||||
@ -70,6 +84,7 @@ iter_insert_before (GtkWidget *button, GtkTreeView *tree_view)
|
|||||||
{
|
{
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
GtkTreeIter selected;
|
GtkTreeIter selected;
|
||||||
|
GtkTreeStore *model = gtk_tree_view_get_model (tree_view);
|
||||||
|
|
||||||
if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
|
if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
|
||||||
NULL,
|
NULL,
|
||||||
@ -96,6 +111,7 @@ iter_insert_after (GtkWidget *button, GtkTreeView *tree_view)
|
|||||||
{
|
{
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
GtkTreeIter selected;
|
GtkTreeIter selected;
|
||||||
|
GtkTreeStore *model = gtk_tree_view_get_model (tree_view);
|
||||||
|
|
||||||
if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
|
if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
|
||||||
NULL,
|
NULL,
|
||||||
@ -122,23 +138,29 @@ iter_prepend (GtkWidget *button, GtkTreeView *tree_view)
|
|||||||
{
|
{
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
GtkTreeIter selected;
|
GtkTreeIter selected;
|
||||||
|
GtkTreeModel *model = gtk_tree_view_get_model (tree_view);
|
||||||
|
GtkTreeSelection *selection = gtk_tree_view_get_selection (tree_view);
|
||||||
|
|
||||||
if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
|
if (gtk_tree_selection_get_selected (selection, NULL, &selected))
|
||||||
NULL,
|
|
||||||
&selected))
|
|
||||||
{
|
{
|
||||||
gtk_tree_store_prepend (model,
|
if (GTK_IS_TREE_STORE (model))
|
||||||
|
{
|
||||||
|
gtk_tree_store_prepend (GTK_TREE_STORE (model),
|
||||||
&iter,
|
&iter,
|
||||||
&selected);
|
&selected);
|
||||||
|
node_set (&iter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gtk_tree_store_prepend (model,
|
if (GTK_IS_TREE_STORE (model))
|
||||||
|
{
|
||||||
|
gtk_tree_store_prepend (GTK_TREE_STORE (model),
|
||||||
&iter,
|
&iter,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
|
||||||
|
|
||||||
node_set (&iter);
|
node_set (&iter);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -146,25 +168,31 @@ iter_append (GtkWidget *button, GtkTreeView *tree_view)
|
|||||||
{
|
{
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
GtkTreeIter selected;
|
GtkTreeIter selected;
|
||||||
|
GtkTreeStore *model = gtk_tree_view_get_model (tree_view);
|
||||||
|
|
||||||
if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
|
if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
|
||||||
NULL,
|
NULL,
|
||||||
&selected))
|
&selected))
|
||||||
|
{
|
||||||
|
if (GTK_IS_TREE_STORE (model))
|
||||||
{
|
{
|
||||||
gtk_tree_store_append (model, &iter, &selected);
|
gtk_tree_store_append (model, &iter, &selected);
|
||||||
|
node_set (&iter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
if (GTK_IS_TREE_STORE (model))
|
||||||
{
|
{
|
||||||
gtk_tree_store_append (model, &iter, NULL);
|
gtk_tree_store_append (model, &iter, NULL);
|
||||||
}
|
|
||||||
|
|
||||||
node_set (&iter);
|
node_set (&iter);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
make_window ()
|
make_window (gboolean use_sort)
|
||||||
{
|
{
|
||||||
GtkTreeModel *sort_model;
|
|
||||||
GtkWidget *window;
|
GtkWidget *window;
|
||||||
GtkWidget *vbox;
|
GtkWidget *vbox;
|
||||||
GtkWidget *hbox, *entry;
|
GtkWidget *hbox, *entry;
|
||||||
@ -177,13 +205,28 @@ make_window ()
|
|||||||
|
|
||||||
/* Make the Widgets/Objects */
|
/* Make the Widgets/Objects */
|
||||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||||
|
if (use_sort)
|
||||||
|
gtk_window_set_title (GTK_WINDOW (window), "Sorted list");
|
||||||
|
else
|
||||||
|
gtk_window_set_title (GTK_WINDOW (window), "Unsorted list");
|
||||||
|
|
||||||
vbox = gtk_vbox_new (FALSE, 8);
|
vbox = gtk_vbox_new (FALSE, 8);
|
||||||
gtk_container_set_border_width (GTK_CONTAINER (vbox), 8);
|
gtk_container_set_border_width (GTK_CONTAINER (vbox), 8);
|
||||||
gtk_window_set_default_size (GTK_WINDOW (window), 300, 350);
|
gtk_window_set_default_size (GTK_WINDOW (window), 300, 350);
|
||||||
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
|
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
|
||||||
sort_model = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (model),
|
if (use_sort)
|
||||||
|
{
|
||||||
|
GtkTreeModel *sort_model;
|
||||||
|
|
||||||
|
sort_model = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (base_model),
|
||||||
NULL, 0);
|
NULL, 0);
|
||||||
tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (sort_model));
|
tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (sort_model));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (base_model));
|
||||||
|
}
|
||||||
|
|
||||||
selection = GTK_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)));
|
selection = GTK_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)));
|
||||||
gtk_tree_selection_set_type (GTK_TREE_SELECTION (selection), GTK_TREE_SELECTION_SINGLE);
|
gtk_tree_selection_set_type (GTK_TREE_SELECTION (selection), GTK_TREE_SELECTION_SINGLE);
|
||||||
|
|
||||||
@ -244,14 +287,20 @@ make_window ()
|
|||||||
|
|
||||||
/* The selected column */
|
/* The selected column */
|
||||||
cell = gtk_cell_renderer_text_new ();
|
cell = gtk_cell_renderer_text_new ();
|
||||||
column = gtk_tree_view_column_new_with_attributes ("nodes", cell, "text", 0, NULL);
|
column = gtk_tree_view_column_new_with_attributes ("Node ID", cell, "text", 0, NULL);
|
||||||
|
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
|
||||||
|
|
||||||
|
cell = gtk_cell_renderer_text_new ();
|
||||||
|
column = gtk_tree_view_column_new_with_attributes ("Random Number", cell, "text", 1, NULL);
|
||||||
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
|
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
|
||||||
|
|
||||||
/* A few to start */
|
/* A few to start */
|
||||||
|
if (!use_sort)
|
||||||
|
{
|
||||||
iter_prepend (NULL, GTK_TREE_VIEW (tree_view));
|
iter_prepend (NULL, GTK_TREE_VIEW (tree_view));
|
||||||
iter_prepend (NULL, GTK_TREE_VIEW (tree_view));
|
iter_prepend (NULL, GTK_TREE_VIEW (tree_view));
|
||||||
iter_prepend (NULL, GTK_TREE_VIEW (tree_view));
|
iter_prepend (NULL, GTK_TREE_VIEW (tree_view));
|
||||||
|
}
|
||||||
/* Show it all */
|
/* Show it all */
|
||||||
gtk_widget_show_all (window);
|
gtk_widget_show_all (window);
|
||||||
}
|
}
|
||||||
@ -261,10 +310,11 @@ main (int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
gtk_init (&argc, &argv);
|
gtk_init (&argc, &argv);
|
||||||
|
|
||||||
model = gtk_tree_store_new_with_types (2, G_TYPE_STRING, G_TYPE_STRING);
|
base_model = gtk_tree_store_new_with_types (2, G_TYPE_STRING, G_TYPE_STRING);
|
||||||
|
|
||||||
make_window ();
|
/* FIXME: reverse this */
|
||||||
make_window ();
|
make_window (FALSE);
|
||||||
|
make_window (TRUE);
|
||||||
|
|
||||||
gtk_main ();
|
gtk_main ();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user