more changes in an attempt to get it right. It's not yet ready for general

Wed Oct 24 20:29:47 2001  Kristian Rietveld  <kristian@planet.nl>

        * gtk/gtktreemodelsort.c: more changes in an attempt to get
        it right. It's not yet ready for general consumption.

        * tests/treestoretest.c: add a button and entry for the new
        iter_change function
        (iter_change): new function, to test
        the row_changed signal implementation of the GtkTreeModelSort

        * tests/testtreesort.c: cleanups, changes to test more features
        of the GtkTreeModelSort at once
This commit is contained in:
Kristian Rietveld 2001-10-24 18:36:50 +00:00 committed by Kristian Rietveld
parent 9b7d528ac2
commit beaba6a43c
10 changed files with 532 additions and 402 deletions

View File

@ -1,3 +1,16 @@
Wed Oct 24 20:29:47 2001 Kristian Rietveld <kristian@planet.nl>
* gtk/gtktreemodelsort.c: more changes in an attempt to get
it right. It's not yet ready for general consumption.
* tests/treestoretest.c: add a button and entry for the new
iter_change function
(iter_change): new function, to test
the row_changed signal implementation of the GtkTreeModelSort
* tests/testtreesort.c: cleanups, changes to test more features
of the GtkTreeModelSort at once
2001-10-24 Havoc Pennington <hp@redhat.com>
* gtk/gtktextbuffer.c (clipboard_clipboard_buffer_received):

View File

@ -1,3 +1,16 @@
Wed Oct 24 20:29:47 2001 Kristian Rietveld <kristian@planet.nl>
* gtk/gtktreemodelsort.c: more changes in an attempt to get
it right. It's not yet ready for general consumption.
* tests/treestoretest.c: add a button and entry for the new
iter_change function
(iter_change): new function, to test
the row_changed signal implementation of the GtkTreeModelSort
* tests/testtreesort.c: cleanups, changes to test more features
of the GtkTreeModelSort at once
2001-10-24 Havoc Pennington <hp@redhat.com>
* gtk/gtktextbuffer.c (clipboard_clipboard_buffer_received):

View File

@ -1,3 +1,16 @@
Wed Oct 24 20:29:47 2001 Kristian Rietveld <kristian@planet.nl>
* gtk/gtktreemodelsort.c: more changes in an attempt to get
it right. It's not yet ready for general consumption.
* tests/treestoretest.c: add a button and entry for the new
iter_change function
(iter_change): new function, to test
the row_changed signal implementation of the GtkTreeModelSort
* tests/testtreesort.c: cleanups, changes to test more features
of the GtkTreeModelSort at once
2001-10-24 Havoc Pennington <hp@redhat.com>
* gtk/gtktextbuffer.c (clipboard_clipboard_buffer_received):

View File

@ -1,3 +1,16 @@
Wed Oct 24 20:29:47 2001 Kristian Rietveld <kristian@planet.nl>
* gtk/gtktreemodelsort.c: more changes in an attempt to get
it right. It's not yet ready for general consumption.
* tests/treestoretest.c: add a button and entry for the new
iter_change function
(iter_change): new function, to test
the row_changed signal implementation of the GtkTreeModelSort
* tests/testtreesort.c: cleanups, changes to test more features
of the GtkTreeModelSort at once
2001-10-24 Havoc Pennington <hp@redhat.com>
* gtk/gtktextbuffer.c (clipboard_clipboard_buffer_received):

View File

@ -1,3 +1,16 @@
Wed Oct 24 20:29:47 2001 Kristian Rietveld <kristian@planet.nl>
* gtk/gtktreemodelsort.c: more changes in an attempt to get
it right. It's not yet ready for general consumption.
* tests/treestoretest.c: add a button and entry for the new
iter_change function
(iter_change): new function, to test
the row_changed signal implementation of the GtkTreeModelSort
* tests/testtreesort.c: cleanups, changes to test more features
of the GtkTreeModelSort at once
2001-10-24 Havoc Pennington <hp@redhat.com>
* gtk/gtktextbuffer.c (clipboard_clipboard_buffer_received):

View File

@ -1,3 +1,16 @@
Wed Oct 24 20:29:47 2001 Kristian Rietveld <kristian@planet.nl>
* gtk/gtktreemodelsort.c: more changes in an attempt to get
it right. It's not yet ready for general consumption.
* tests/treestoretest.c: add a button and entry for the new
iter_change function
(iter_change): new function, to test
the row_changed signal implementation of the GtkTreeModelSort
* tests/testtreesort.c: cleanups, changes to test more features
of the GtkTreeModelSort at once
2001-10-24 Havoc Pennington <hp@redhat.com>
* gtk/gtktextbuffer.c (clipboard_clipboard_buffer_received):

View File

@ -1,3 +1,16 @@
Wed Oct 24 20:29:47 2001 Kristian Rietveld <kristian@planet.nl>
* gtk/gtktreemodelsort.c: more changes in an attempt to get
it right. It's not yet ready for general consumption.
* tests/treestoretest.c: add a button and entry for the new
iter_change function
(iter_change): new function, to test
the row_changed signal implementation of the GtkTreeModelSort
* tests/testtreesort.c: cleanups, changes to test more features
of the GtkTreeModelSort at once
2001-10-24 Havoc Pennington <hp@redhat.com>
* gtk/gtktextbuffer.c (clipboard_clipboard_buffer_received):

View File

@ -79,8 +79,6 @@ struct _SortTuple
#define SORT_ELT(sort_elt) ((SortElt *)sort_elt)
#define SORT_LEVEL(sort_level) ((SortLevel *)sort_level)
//#define GET_CHILD_ITER(tree_model_sort,child_iter,sort_iter) ((((GtkTreeModelSort *)tree_model_sort)->child_flags&GTK_TREE_MODEL_ITERS_PERSIST)?((*child_iter)=SORT_ELT(sort_iter->user_data)->iter):gtk_tree_model_sort_convert_iter_to_child_iter (GTK_TREE_MODEL_SORT(tree_model_sort),sort_iter,child_iter))
#define GET_CHILD_ITER(tree_model_sort,child_iter,sort_iter) gtk_tree_model_sort_convert_iter_to_child_iter(GTK_TREE_MODEL_SORT (tree_model_sort), child_iter, sort_iter);
static void gtk_tree_model_sort_init (GtkTreeModelSort *tree_model_sort);
@ -167,17 +165,17 @@ static void gtk_tree_model_sort_unref_node (GtkTreeModel
GtkTreeIter *iter);
/* TreeSortable interface */
static gboolean gtk_tree_model_sort_get_sort_column_id (GtkTreeSortable *sortable,
gint *sort_column_id,
GtkSortType *order);
static void gtk_tree_model_sort_set_sort_column_id (GtkTreeSortable *sortable,
gint sort_column_id,
GtkSortType order);
static void gtk_tree_model_sort_set_sort_func (GtkTreeSortable *sortable,
gint sort_column_id,
GtkTreeIterCompareFunc func,
gpointer data,
GtkDestroyNotify destroy);
static gboolean gtk_tree_model_sort_get_sort_column_id (GtkTreeSortable *sortable,
gint *sort_column_id,
GtkSortType *order);
static void gtk_tree_model_sort_set_sort_column_id (GtkTreeSortable *sortable,
gint sort_column_id,
GtkSortType order);
static void gtk_tree_model_sort_set_sort_func (GtkTreeSortable *sortable,
gint sort_column_id,
GtkTreeIterCompareFunc func,
gpointer data,
GtkDestroyNotify destroy);
static void gtk_tree_model_sort_set_default_sort_func (GtkTreeSortable *sortable,
GtkTreeIterCompareFunc func,
gpointer data,
@ -185,37 +183,37 @@ static void gtk_tree_model_sort_set_default_sort_func (GtkTreeSortable
static gboolean gtk_tree_model_sort_has_default_sort_func (GtkTreeSortable *sortable);
/* Private functions */
static void gtk_tree_model_sort_build_level (GtkTreeModelSort *tree_model_sort,
SortLevel *parent_level,
SortElt *parent_elt);
static void gtk_tree_model_sort_free_level (GtkTreeModelSort *tree_model_sort,
SortLevel *sort_level);
static void gtk_tree_model_sort_increment_stamp (GtkTreeModelSort *tree_model_sort);
static void gtk_tree_model_sort_sort_level (GtkTreeModelSort *tree_model_sort,
SortLevel *level,
gboolean recurse,
gboolean emit_reordered);
static void gtk_tree_model_sort_sort (GtkTreeModelSort *tree_model_sort);
static void gtk_tree_model_sort_build_level (GtkTreeModelSort *tree_model_sort,
SortLevel *parent_level,
SortElt *parent_elt);
static void gtk_tree_model_sort_free_level (GtkTreeModelSort *tree_model_sort,
SortLevel *sort_level);
static void gtk_tree_model_sort_increment_stamp (GtkTreeModelSort *tree_model_sort);
static void gtk_tree_model_sort_sort_level (GtkTreeModelSort *tree_model_sort,
SortLevel *level,
gboolean recurse,
gboolean emit_reordered);
static void gtk_tree_model_sort_sort (GtkTreeModelSort *tree_model_sort);
static gint gtk_tree_model_sort_level_find_insert (GtkTreeModelSort *tree_model_sort,
SortLevel *level,
GtkTreeIter *iter,
gboolean skip_sort_elt);
static gboolean gtk_tree_model_sort_insert_value (GtkTreeModelSort *tree_model_sort,
SortLevel *level,
GtkTreePath *s_path,
GtkTreeIter *s_iter);
static GtkTreePath *gtk_tree_model_sort_elt_get_path (SortLevel *level,
SortElt *elt);
static void get_child_iter_from_elt_no_cache (GtkTreeModelSort *tree_model_sort,
GtkTreeIter *child_iter,
SortLevel *level,
SortElt *elt);
static void get_child_iter_from_elt (GtkTreeModelSort *tree_model_sort,
GtkTreeIter *child_iter,
SortLevel *level,
SortElt *elt);
static void gtk_tree_model_sort_set_model (GtkTreeModelSort *tree_model_sort,
GtkTreeModel *child_model);
static GtkTreePath *gtk_tree_model_sort_elt_get_path (SortLevel *level,
SortElt *elt);
static void get_child_iter_from_elt_no_cache (GtkTreeModelSort *tree_model_sort,
GtkTreeIter *child_iter,
SortLevel *level,
SortElt *elt);
static void get_child_iter_from_elt (GtkTreeModelSort *tree_model_sort,
GtkTreeIter *child_iter,
SortLevel *level,
SortElt *elt);
static void gtk_tree_model_sort_set_model (GtkTreeModelSort *tree_model_sort,
GtkTreeModel *child_model);
GType
@ -374,7 +372,7 @@ gtk_tree_model_sort_row_changed (GtkTreeModel *s_model,
gpointer data)
{
GtkTreeModelSort *tree_model_sort = GTK_TREE_MODEL_SORT (data);
GtkTreePath *path;
GtkTreePath *path = NULL;
GtkTreeIter iter;
GtkTreeIter tmpiter;
@ -382,10 +380,10 @@ gtk_tree_model_sort_row_changed (GtkTreeModel *s_model,
SortElt *elt;
SortLevel *level;
gboolean free_s_path;
gboolean free_s_path = FALSE;
gint offset, index = 0, i;
gint offset, index, i;
g_return_if_fail (start_s_path != NULL || start_s_iter != NULL);
if (!start_s_path)
@ -408,11 +406,11 @@ gtk_tree_model_sort_row_changed (GtkTreeModel *s_model,
level = iter.user_data;
elt = iter.user_data2;
if (level->array->len < 2)
if (level->array->len < 2 || tree_model_sort->sort_column_id == -1)
{
if (free_s_path)
gtk_tree_path_free (start_s_path);
gtk_tree_model_row_changed (GTK_TREE_MODEL (data), path, &iter);
gtk_tree_path_free (path);
@ -421,7 +419,10 @@ gtk_tree_model_sort_row_changed (GtkTreeModel *s_model,
}
if (!GTK_TREE_MODEL_SORT_CACHE_CHILD_ITERS (tree_model_sort))
get_child_iter_from_elt (tree_model_sort, &tmpiter, level, elt);
{
gtk_tree_model_get_iter (tree_model_sort->child_model,
&tmpiter, start_s_path);
}
offset = elt->offset;
@ -442,11 +443,21 @@ gtk_tree_model_sort_row_changed (GtkTreeModel *s_model,
level,
&tmpiter,
TRUE);
g_array_insert_val (level->array, index, tmp);
gtk_tree_model_row_changed (GTK_TREE_MODEL (data), path, &iter);
/* FIXME: update stamp?? */
g_array_insert_val (level->array, index, tmp);
gtk_tree_model_sort_increment_stamp (tree_model_sort);
if (path)
gtk_tree_path_free (path);
path = gtk_tree_model_sort_elt_get_path (level, &g_array_index (level->array, SortElt, index));
g_return_if_fail (path != NULL);
gtk_tree_model_get_iter (GTK_TREE_MODEL (data), &iter, path);
gtk_tree_model_row_changed (GTK_TREE_MODEL (data), path, &iter);
gtk_tree_path_free (path);
if (free_s_path)
gtk_tree_path_free (start_s_path);
@ -461,36 +472,98 @@ gtk_tree_model_sort_row_inserted (GtkTreeModel *s_model,
GtkTreeModelSort *tree_model_sort = GTK_TREE_MODEL_SORT (data);
GtkTreePath *path;
GtkTreeIter iter;
GtkTreeIter real_s_iter;
gint i = 0;
gboolean free_s_path = FALSE;
SortElt *elt;
SortLevel *level;
SortLevel *parent_level = NULL;
parent_level = level = SORT_LEVEL (tree_model_sort->root);
g_return_if_fail (s_path != NULL || s_iter != NULL);
if (!s_path)
s_path = gtk_tree_model_get_path (s_model, s_iter);
if (!GTK_TREE_MODEL_SORT_CACHE_CHILD_ITERS (tree_model_sort)
&& tree_model_sort->root)
{
gtk_tree_model_sort_free_level (tree_model_sort,
SORT_LEVEL (tree_model_sort->root));
tree_model_sort->root = NULL;
s_path = gtk_tree_model_get_path (s_model, s_iter);
free_s_path = TRUE;
}
if (!s_iter)
gtk_tree_model_get_iter (s_model, &real_s_iter, s_path);
else
{
GtkTreeIter real_s_iter;
if (!s_iter)
gtk_tree_model_get_iter (s_model, &real_s_iter, s_path);
else
real_s_iter = (* s_iter);
if (!gtk_tree_model_sort_insert_value (tree_model_sort,
s_path, &real_s_iter))
return;
}
real_s_iter = *s_iter;
if (!tree_model_sort->root)
gtk_tree_model_sort_build_level (tree_model_sort, NULL, NULL);
{
gtk_tree_model_sort_build_level (tree_model_sort, NULL, NULL);
/* the build level already put the inserted iter in the level,
so no need to handle this signal anymore */
goto done_and_submit;
}
/* find the parent level */
while (i < gtk_tree_path_get_depth (s_path) - 1)
{
if (!level)
{
/* level not yet build, we won't cover this signal */
goto done;
}
if (level->array->len < gtk_tree_path_get_indices (s_path)[i])
{
g_warning ("A node was inserted with a parent that's not in the tree.\n"
"This possibly means that a GtkTreeModel inserted a child node\n"
"before the parent was inserted.");
goto done;
}
elt = SORT_ELT (&g_array_index (level->array, SortElt, gtk_tree_path_get_indices (s_path)[i]));
if (!elt->children)
{
/* FIXME: emit has_child_toggled here? like the treeview? */
GtkTreePath *tmppath;
GtkTreeIter tmpiter;
tmppath = gtk_tree_model_sort_elt_get_path (level, elt);
if (tmppath)
{
gtk_tree_model_get_iter (GTK_TREE_MODEL (data), &tmpiter,
tmppath);
gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (data),
tmppath,
&tmpiter);
gtk_tree_path_free (tmppath);
}
/* not covering this signal */
goto done;
}
level = elt->children;
parent_level = level;
i++;
}
if (!parent_level)
{
goto done;
}
if (!gtk_tree_model_sort_insert_value (tree_model_sort,
parent_level,
s_path,
&real_s_iter))
goto done;
done_and_submit:
path = gtk_tree_model_sort_convert_child_path_to_path (tree_model_sort,
s_path);
@ -498,9 +571,17 @@ gtk_tree_model_sort_row_inserted (GtkTreeModel *s_model,
return;
gtk_tree_model_sort_increment_stamp (tree_model_sort);
gtk_tree_model_get_iter (GTK_TREE_MODEL (data), &iter, path);
gtk_tree_model_row_inserted (GTK_TREE_MODEL (data), path, &iter);
gtk_tree_path_free (path);
done:
if (free_s_path)
gtk_tree_path_free (s_path);
return;
}
static void
@ -520,13 +601,6 @@ gtk_tree_model_sort_row_has_child_toggled (GtkTreeModel *s_model,
if (!tree_model_sort->root)
return;
if (!GTK_TREE_MODEL_SORT_CACHE_CHILD_ITERS (tree_model_sort))
{
gtk_tree_model_sort_free_level (tree_model_sort,
SORT_LEVEL (tree_model_sort->root));
tree_model_sort->root = NULL;
}
if (!s_path)
{
s_path = gtk_tree_model_get_path (s_model, s_iter);
@ -542,6 +616,13 @@ gtk_tree_model_sort_row_has_child_toggled (GtkTreeModel *s_model,
gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (data), path,
&iter);
gtk_tree_path_free (path);
if (!GTK_TREE_MODEL_SORT_CACHE_CHILD_ITERS (tree_model_sort))
{
gtk_tree_model_sort_free_level (tree_model_sort,
SORT_LEVEL (tree_model_sort->root));
tree_model_sort->root = NULL;
}
if (free_s_path)
gtk_tree_path_free (s_path);
@ -553,7 +634,7 @@ gtk_tree_model_sort_row_deleted (GtkTreeModel *s_model,
gpointer data)
{
GtkTreeModelSort *tree_model_sort = GTK_TREE_MODEL_SORT (data);
GtkTreePath *path;
GtkTreePath *path = NULL;
/* we don't handle signals which we don't cover */
if (!tree_model_sort->root)
@ -562,8 +643,13 @@ gtk_tree_model_sort_row_deleted (GtkTreeModel *s_model,
g_return_if_fail (s_path != NULL);
path = gtk_tree_model_sort_convert_child_path_to_path (tree_model_sort,
s_path);
g_return_if_fail (path != NULL);
if (!path)
{
/* we don't cover this signal */
return;
}
if (!GTK_TREE_MODEL_SORT_CACHE_CHILD_ITERS (tree_model_sort))
{
gtk_tree_model_sort_free_level (tree_model_sort,
@ -578,43 +664,34 @@ gtk_tree_model_sort_row_deleted (GtkTreeModel *s_model,
gint offset;
gint i;
gtk_tree_model_get_iter (GTK_TREE_MODEL (tree_model_sort),
gtk_tree_model_get_iter (GTK_TREE_MODEL (data),
&iter, path);
g_return_if_fail (tree_model_sort->stamp == iter.stamp);
level = SORT_LEVEL (iter.user_data);
elt = SORT_ELT (iter.user_data2);
offset = elt->offset;
if (level->array->len == 1)
{
// if (SORT_ELT (level->array->data)->parent == NULL)
if (level->parent_elt == NULL)
tree_model_sort->root = NULL;
else
// (SORT_ELT (level->array->data)->parent)->children = NULL;
level->parent_level->array = NULL;
gtk_tree_model_sort_free_level (tree_model_sort, level);
}
else
{
for (i = 0; i < level->array->len; i++)
if (elt->offset == g_array_index (level->array, SortElt, i).offset)
break;
g_array_remove_index (level->array, i);
/* update all offsets */
for (i = 0; i < level->array->len; i++)
for (i = 0; i < level->array->len; i++)
if (elt->offset == g_array_index (level->array, SortElt, i).offset)
break;
g_array_remove_index (level->array, i);
level->ref_count--;
/* update all offsets */
for (i = 0; i < level->array->len; i++)
{
elt = & (g_array_index (level->array, SortElt, i));
if (elt->offset > offset)
elt->offset--;
}
}
}
gtk_tree_model_row_deleted (GTK_TREE_MODEL (data), path);
gtk_tree_model_sort_increment_stamp (tree_model_sort);
gtk_tree_path_free (path);
gtk_tree_model_row_deleted (GTK_TREE_MODEL (data), path);
if (path)
gtk_tree_path_free (path);
}
static void
@ -626,7 +703,6 @@ gtk_tree_model_sort_rows_reordered (GtkTreeModel *s_model,
{
int i;
int len;
int *my_new_order;
SortElt *elt;
SortLevel *level;
gboolean free_s_path = FALSE;
@ -711,7 +787,6 @@ gtk_tree_model_sort_rows_reordered (GtkTreeModel *s_model,
gtk_tree_path_free (s_path);
/* length mismatch, pretty bad, shouldn't happen */
g_warning ("length mismatch!");
return;
}
@ -729,18 +804,19 @@ gtk_tree_model_sort_rows_reordered (GtkTreeModel *s_model,
return;
}
for (i = 0; i < level->array->len; i++)
{
g_array_index (level->array, SortElt, i).offset = new_order[i];
if (GTK_TREE_MODEL_SORT_CACHE_CHILD_ITERS (tree_model_sort))
if (GTK_TREE_MODEL_SORT_CACHE_CHILD_ITERS (tree_model_sort)
&& tree_model_sort->sort_column_id == -1)
{
get_child_iter_from_elt_no_cache (tree_model_sort,
&(g_array_index (level->array, SortElt, i).iter), level, &g_array_index (level->array, SortElt, i));
}
}
gtk_tree_model_sort_increment_stamp (tree_model_sort);
gtk_tree_model_sort_sort_level (tree_model_sort, level,
@ -755,11 +831,13 @@ gtk_tree_model_sort_rows_reordered (GtkTreeModel *s_model,
path, &iter, new_order);
}
else
gtk_tree_model_rows_reordered (GTK_TREE_MODEL (tree_model_sort),
path, NULL, new_order);
{
gtk_tree_model_rows_reordered (GTK_TREE_MODEL (tree_model_sort),
path, NULL, new_order);
}
gtk_tree_path_free (path);
if (free_s_path)
gtk_tree_path_free (s_path);
@ -767,25 +845,10 @@ gtk_tree_model_sort_rows_reordered (GtkTreeModel *s_model,
}
/** sorted: update offsets, no emission of reordered signal **/
g_print ("B");
for (i = 0; i < level->array->len; i++)
g_print ("%3d", g_array_index (level->array, SortElt, i).offset);
g_print ("\n");
g_print ("N");
for (i = 0; i < level->array->len; i++)
g_print ("%3d", new_order[i]);
g_print ("\n");
for (i = 0; i < level->array->len; i++)
g_array_index (level->array, SortElt, i).offset =
new_order[g_array_index (level->array, SortElt, i).offset];
g_print ("A");
for (i = 0; i < level->array->len; i++)
g_print ("%3d", g_array_index (level->array, SortElt, i).offset);
g_print ("\n");
gtk_tree_model_sort_increment_stamp (tree_model_sort);
if (free_s_path)
@ -1163,7 +1226,6 @@ gtk_tree_model_sort_set_sort_column_id (GtkTreeSortable *sortable,
GtkSortType order)
{
GtkTreeModelSort *tree_model_sort = (GtkTreeModelSort *)sortable;
GList *list;
g_return_if_fail (GTK_IS_TREE_MODEL_SORT (sortable));
@ -1414,9 +1476,6 @@ gtk_tree_model_sort_sort_level (GtkTreeModelSort *tree_model_sort,
g_array_append_val (sort_array, tuple);
}
g_print ("-- sort: sort_column_id = %d // default_sort_func = %.2x\n",
tree_model_sort->sort_column_id, tree_model_sort->default_sort_func);
if (tree_model_sort->sort_column_id == GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID)
g_array_sort_with_data (sort_array,
gtk_tree_model_sort_offset_compare_func,
@ -1470,9 +1529,23 @@ gtk_tree_model_sort_sort_level (GtkTreeModelSort *tree_model_sort,
g_array_free (sort_array, TRUE);
/* recurse, if possible */
if (recurse)
{
for (i = 0; i < level->array->len; i++)
{
SortElt *elt = &g_array_index (level->array, SortElt, i);
if (elt->children)
gtk_tree_model_sort_sort_level (tree_model_sort,
elt->children,
TRUE, emit_reordered);
}
}
if (emit_reordered)
{
gtk_tree_model_sort_increment_stamp (tree_model_sort);
/* gtk_tree_model_sort_increment_stamp (tree_model_sort); */
if (level->parent_elt)
{
@ -1498,20 +1571,6 @@ gtk_tree_model_sort_sort_level (GtkTreeModelSort *tree_model_sort,
}
g_free (new_order);
/* recurse, if possible */
if (recurse)
{
for (i = 0; i < level->array->len; i++)
{
SortElt *elt = &g_array_index (level->array, SortElt, i);
if (elt->children)
gtk_tree_model_sort_sort_level (tree_model_sort,
elt->children,
TRUE, emit_reordered);
}
}
}
static void
@ -1521,7 +1580,6 @@ gtk_tree_model_sort_sort (GtkTreeModelSort *tree_model_sort)
if (!tree_model_sort->root)
{
g_print ("sort: bailing out, no level built yet\n");
return;
}
@ -1602,23 +1660,14 @@ gtk_tree_model_sort_level_find_insert (GtkTreeModelSort *tree_model_sort,
static gboolean
gtk_tree_model_sort_insert_value (GtkTreeModelSort *tree_model_sort,
SortLevel *level,
GtkTreePath *s_path,
GtkTreeIter *s_iter)
{
gint offset, index, j;
SortLevel *level;
gint offset, index, i;
SortElt elt;
SortElt *tmp_elt;
GtkTreeIter iter;
GtkTreePath *tmp_path;
return FALSE;
if (!tree_model_sort->root)
{
gtk_tree_model_sort_build_level (tree_model_sort, NULL, NULL);
return FALSE;
}
offset = gtk_tree_path_get_indices (s_path)[gtk_tree_path_get_depth (s_path) - 1];
@ -1628,46 +1677,6 @@ gtk_tree_model_sort_insert_value (GtkTreeModelSort *tree_model_sort,
elt.zero_ref_count = 0;
elt.ref_count = 0;
elt.children = NULL;
tmp_path = gtk_tree_path_copy (s_path);
if (gtk_tree_path_up (tmp_path))
{
GtkTreePath *parent_path;
parent_path = gtk_tree_model_sort_convert_child_path_to_path (tree_model_sort, tmp_path);
if (!parent_path)
{
gtk_tree_path_free (tmp_path);
return FALSE;
}
if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (tree_model_sort), &iter,
parent_path))
{
gtk_tree_path_free (parent_path);
gtk_tree_path_free (tmp_path);
return FALSE;
}
level = SORT_LEVEL (iter.user_data);
gtk_tree_path_free (parent_path);
if (!level)
{
gtk_tree_path_free (tmp_path);
return FALSE;
}
}
else
{
if (!tree_model_sort->root)
gtk_tree_model_sort_build_level (tree_model_sort, NULL, NULL);
level = SORT_LEVEL (tree_model_sort->root);
}
gtk_tree_path_free (tmp_path);
if (GTK_TREE_MODEL_SORT_CACHE_CHILD_ITERS (tree_model_sort))
index = gtk_tree_model_sort_level_find_insert (tree_model_sort,
@ -1677,9 +1686,10 @@ gtk_tree_model_sort_insert_value (GtkTreeModelSort *tree_model_sort,
else
{
GtkTreeIter tmpiter;
gtk_tree_model_sort_convert_child_iter_to_iter (tree_model_sort,
&tmpiter,
s_iter);
gtk_tree_model_get_iter (tree_model_sort->child_model,
&tmpiter, s_path);
index = gtk_tree_model_sort_level_find_insert (tree_model_sort,
level,
&tmpiter,
@ -1687,11 +1697,11 @@ gtk_tree_model_sort_insert_value (GtkTreeModelSort *tree_model_sort,
}
g_array_insert_vals (level->array, index, &elt, 1);
/* update all larger offsets */
tmp_elt = SORT_ELT (level->array->data);
for (j = 0; j < level->array->len; j++, tmp_elt++)
if ((tmp_elt->offset >= offset) && j != index)
for (i = 0; i < level->array->len; i++, tmp_elt++)
if ((tmp_elt->offset >= offset) && i != index)
tmp_elt->offset++;
return TRUE;
@ -1937,7 +1947,7 @@ gtk_tree_model_sort_convert_child_path_to_path (GtkTreeModelSort *tree_model_sor
{
if ((g_array_index (level->array, SortElt, j)).offset == child_indices[i])
{
gtk_tree_path_prepend_index (retval, j);
gtk_tree_path_append_index (retval, j);
level = g_array_index (level->array, SortElt, j).children;
found_child = TRUE;
break;
@ -2239,17 +2249,14 @@ gtk_tree_model_sort_clear_cache_helper (GtkTreeModelSort *tree_model_sort,
for (i = 0; i < level->array->len; i++)
{
if (g_array_index (level->array, SortElt, i).zero_ref_count > 0)
{
gtk_tree_model_sort_clear_cache_helper (tree_model_sort, g_array_index (level->array, SortElt, i).children);
}
gtk_tree_model_sort_clear_cache_helper (tree_model_sort, g_array_index (level->array, SortElt, i).children);
}
if (level->ref_count == 0)
if (level->ref_count == 0 && level != tree_model_sort->root)
{
gtk_tree_model_sort_free_level (tree_model_sort, level);
return;
}
}
/**
@ -2264,8 +2271,6 @@ gtk_tree_model_sort_reset_default_sort_func (GtkTreeModelSort *tree_model_sort)
{
g_return_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model_sort));
g_print ("RESET DEFAULT SORT FUNC\n");
if (tree_model_sort->default_sort_destroy)
(* tree_model_sort->default_sort_destroy) (tree_model_sort->default_sort_data);

View File

@ -57,12 +57,12 @@ main (int argc, char *argv[])
GtkWidget *scrolled_window;
GtkWidget *tree_view;
GtkTreeStore *model;
GtkTreeModel *smodel;
GtkTreeModel *smodel = NULL;
GtkTreeModel *ssmodel = NULL;
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
GtkTreeIter iter;
gint i, j;
gint i;
GtkWidget *window2, *vbox2, *scrolled_window2, *tree_view2;
GtkWidget *window3, *vbox3, *scrolled_window3, *tree_view3;
@ -87,40 +87,43 @@ main (int argc, char *argv[])
gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE, 0);
model = gtk_tree_store_new (NUM_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
smodel = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (model));
ssmodel = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (smodel));
tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
for (j = 0; j < 2; j++)
for (i = 0; data[i].word_1 != NULL; i++)
{
gint k;
gtk_tree_store_prepend (GTK_TREE_STORE (model), &iter, NULL);
gtk_tree_store_set (GTK_TREE_STORE (model), &iter,
WORD_COLUMN_1, data[i].word_1,
WORD_COLUMN_2, data[i].word_2,
WORD_COLUMN_3, data[i].word_3,
WORD_COLUMN_4, data[i].word_4,
-1);
for (k = 0; childdata[k].word_1 != NULL; k++)
{
GtkTreeIter child_iter;
gtk_tree_store_append (GTK_TREE_STORE (model), &child_iter, &iter);
gtk_tree_store_set (GTK_TREE_STORE (model), &child_iter,
WORD_COLUMN_1, childdata[k].word_1,
WORD_COLUMN_2, childdata[k].word_2,
WORD_COLUMN_3, childdata[k].word_3,
WORD_COLUMN_4, childdata[k].word_4,
-1);
}
}
/*
smodel = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (model));
ssmodel = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (smodel));
*/
tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
/* 12 iters now, 12 later... */
for (i = 0; data[i].word_1 != NULL; i++)
{
gint k;
gtk_tree_store_prepend (GTK_TREE_STORE (model), &iter, NULL);
gtk_tree_store_set (GTK_TREE_STORE (model), &iter,
WORD_COLUMN_1, data[i].word_1,
WORD_COLUMN_2, data[i].word_2,
WORD_COLUMN_3, data[i].word_3,
WORD_COLUMN_4, data[i].word_4,
-1);
for (k = 0; childdata[k].word_1 != NULL; k++)
{
GtkTreeIter child_iter;
gtk_tree_store_append (GTK_TREE_STORE (model), &child_iter, &iter);
gtk_tree_store_set (GTK_TREE_STORE (model), &child_iter,
WORD_COLUMN_1, childdata[k].word_1,
WORD_COLUMN_2, childdata[k].word_2,
WORD_COLUMN_3, childdata[k].word_3,
WORD_COLUMN_4, childdata[k].word_4,
-1);
}
}
smodel = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (model));
ssmodel = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (smodel));
g_object_unref (G_OBJECT (model));
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree_view), TRUE);
@ -152,11 +155,11 @@ main (int argc, char *argv[])
gtk_tree_view_column_set_sort_column_id (column, WORD_COLUMN_4);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
/*
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (smodel),
WORD_COLUMN_1,
GTK_SORT_ASCENDING);
*/
gtk_container_add (GTK_CONTAINER (scrolled_window), tree_view);
gtk_window_set_default_size (GTK_WINDOW (window), 400, 400);
gtk_widget_show_all (window);
@ -166,167 +169,169 @@ main (int argc, char *argv[])
* Second window - GtkTreeModelSort wrapping the GtkTreeStore
*/
window2 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window2),
"Words, words, words - window 2");
gtk_signal_connect (GTK_OBJECT (window2), "destroy", gtk_main_quit, NULL);
vbox2 = gtk_vbox_new (FALSE, 8);
gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);
gtk_box_pack_start (GTK_BOX (vbox2),
gtk_label_new ("Jonathan and Kristian's list of words.\n\nA GtkTreeModelSort wrapping the GtkTreeStore of window 1"),
FALSE, FALSE, 0);
gtk_container_add (GTK_CONTAINER (window2), vbox2);
scrolled_window2 = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window2),
GTK_SHADOW_ETCHED_IN);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window2),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_box_pack_start (GTK_BOX (vbox2), scrolled_window2, TRUE, TRUE, 0);
tree_view2 = gtk_tree_view_new_with_model (smodel);
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree_view2), TRUE);
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes ("First Word", renderer,
"text", WORD_COLUMN_1,
NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view2), column);
gtk_tree_view_column_set_sort_column_id (column, WORD_COLUMN_1);
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes ("Second Word", renderer,
"text", WORD_COLUMN_2,
NULL);
gtk_tree_view_column_set_sort_column_id (column, WORD_COLUMN_2);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view2), column);
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes ("Third Word", renderer,
"text", WORD_COLUMN_3,
NULL);
gtk_tree_view_column_set_sort_column_id (column, WORD_COLUMN_3);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view2), column);
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes ("Fourth Word", renderer,
"text", WORD_COLUMN_4,
NULL);
gtk_tree_view_column_set_sort_column_id (column, WORD_COLUMN_4);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view2), column);
gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (smodel),
(GtkTreeIterCompareFunc)gtk_tree_data_list_compare_func,
NULL, NULL);
/*
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (smodel),
WORD_COLUMN_1,
GTK_SORT_DESCENDING);
*/
gtk_container_add (GTK_CONTAINER (scrolled_window2), tree_view2);
gtk_window_set_default_size (GTK_WINDOW (window2), 400, 400);
gtk_widget_show_all (window2);
if (smodel)
{
window2 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window2),
"Words, words, words - window 2");
gtk_signal_connect (GTK_OBJECT (window2), "destroy", gtk_main_quit, NULL);
vbox2 = gtk_vbox_new (FALSE, 8);
gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);
gtk_box_pack_start (GTK_BOX (vbox2),
gtk_label_new ("Jonathan and Kristian's list of words.\n\nA GtkTreeModelSort wrapping the GtkTreeStore of window 1"),
FALSE, FALSE, 0);
gtk_container_add (GTK_CONTAINER (window2), vbox2);
scrolled_window2 = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window2),
GTK_SHADOW_ETCHED_IN);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window2),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_box_pack_start (GTK_BOX (vbox2), scrolled_window2, TRUE, TRUE, 0);
tree_view2 = gtk_tree_view_new_with_model (smodel);
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree_view2), TRUE);
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes ("First Word", renderer,
"text", WORD_COLUMN_1,
NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view2), column);
gtk_tree_view_column_set_sort_column_id (column, WORD_COLUMN_1);
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes ("Second Word", renderer,
"text", WORD_COLUMN_2,
NULL);
gtk_tree_view_column_set_sort_column_id (column, WORD_COLUMN_2);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view2), column);
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes ("Third Word", renderer,
"text", WORD_COLUMN_3,
NULL);
gtk_tree_view_column_set_sort_column_id (column, WORD_COLUMN_3);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view2), column);
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes ("Fourth Word", renderer,
"text", WORD_COLUMN_4,
NULL);
gtk_tree_view_column_set_sort_column_id (column, WORD_COLUMN_4);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view2), column);
gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (smodel),
(GtkTreeIterCompareFunc)gtk_tree_data_list_compare_func,
NULL, NULL);
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (smodel),
WORD_COLUMN_1,
GTK_SORT_DESCENDING);
gtk_container_add (GTK_CONTAINER (scrolled_window2), tree_view2);
gtk_window_set_default_size (GTK_WINDOW (window2), 400, 400);
gtk_widget_show_all (window2);
}
/**
* Third window - GtkTreeModelSort wrapping the GtkTreeModelSort which
* is wrapping the GtkTreeStore.
*/
if (ssmodel) {
window3 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window3),
"Words, words, words - Window 3");
gtk_signal_connect (GTK_OBJECT (window3), "destroy", gtk_main_quit, NULL);
vbox3 = gtk_vbox_new (FALSE, 8);
gtk_container_set_border_width (GTK_CONTAINER (vbox3), 8);
gtk_box_pack_start (GTK_BOX (vbox3),
gtk_label_new ("Jonathan and Kristian's list of words.\n\nA GtkTreeModelSort wrapping the GtkTreeModelSort of window 2"),
FALSE, FALSE, 0);
gtk_container_add (GTK_CONTAINER (window3), vbox3);
scrolled_window3 = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window3),
GTK_SHADOW_ETCHED_IN);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window3),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_box_pack_start (GTK_BOX (vbox3), scrolled_window3, TRUE, TRUE, 0);
tree_view3 = gtk_tree_view_new_with_model (ssmodel);
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree_view3), TRUE);
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes ("First Word", renderer,
"text", WORD_COLUMN_1,
NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view3), column);
gtk_tree_view_column_set_sort_column_id (column, WORD_COLUMN_1);
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes ("Second Word", renderer,
"text", WORD_COLUMN_2,
NULL);
gtk_tree_view_column_set_sort_column_id (column, WORD_COLUMN_2);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view3), column);
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes ("Third Word", renderer,
"text", WORD_COLUMN_3,
NULL);
gtk_tree_view_column_set_sort_column_id (column, WORD_COLUMN_3);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view3), column);
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes ("Fourth Word", renderer,
"text", WORD_COLUMN_4,
NULL);
gtk_tree_view_column_set_sort_column_id (column, WORD_COLUMN_4);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view3), column);
/*
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (ssmodel),
WORD_COLUMN_1,
GTK_SORT_ASCENDING);
*/
gtk_container_add (GTK_CONTAINER (scrolled_window3), tree_view3);
gtk_window_set_default_size (GTK_WINDOW (window3), 400, 400);
gtk_widget_show_all (window3);
}
/*
for (j = 0; j < 2; j++)
for (i = 0; data[i].word_1 != NULL; i++)
{
gint k;
gtk_tree_store_prepend (GTK_TREE_STORE (model), &iter, NULL);
gtk_tree_store_set (GTK_TREE_STORE (model), &iter,
WORD_COLUMN_1, data[i].word_1,
WORD_COLUMN_2, data[i].word_2,
WORD_COLUMN_3, data[i].word_3,
WORD_COLUMN_4, data[i].word_4,
-1);
for (k = 0; childdata[k].word_1 != NULL; k++)
{
GtkTreeIter child_iter;
gtk_tree_store_append (GTK_TREE_STORE (model), &child_iter, &iter);
gtk_tree_store_set (GTK_TREE_STORE (model), &child_iter,
WORD_COLUMN_1, childdata[k].word_1,
WORD_COLUMN_2, childdata[k].word_2,
WORD_COLUMN_3, childdata[k].word_3,
WORD_COLUMN_4, childdata[k].word_4,
-1);
}
}
*/
if (ssmodel)
{
window3 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window3),
"Words, words, words - Window 3");
gtk_signal_connect (GTK_OBJECT (window3), "destroy", gtk_main_quit, NULL);
vbox3 = gtk_vbox_new (FALSE, 8);
gtk_container_set_border_width (GTK_CONTAINER (vbox3), 8);
gtk_box_pack_start (GTK_BOX (vbox3),
gtk_label_new ("Jonathan and Kristian's list of words.\n\nA GtkTreeModelSort wrapping the GtkTreeModelSort of window 2"),
FALSE, FALSE, 0);
gtk_container_add (GTK_CONTAINER (window3), vbox3);
scrolled_window3 = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window3),
GTK_SHADOW_ETCHED_IN);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window3),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_box_pack_start (GTK_BOX (vbox3), scrolled_window3, TRUE, TRUE, 0);
tree_view3 = gtk_tree_view_new_with_model (ssmodel);
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree_view3), TRUE);
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes ("First Word", renderer,
"text", WORD_COLUMN_1,
NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view3), column);
gtk_tree_view_column_set_sort_column_id (column, WORD_COLUMN_1);
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes ("Second Word", renderer,
"text", WORD_COLUMN_2,
NULL);
gtk_tree_view_column_set_sort_column_id (column, WORD_COLUMN_2);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view3), column);
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes ("Third Word", renderer,
"text", WORD_COLUMN_3,
NULL);
gtk_tree_view_column_set_sort_column_id (column, WORD_COLUMN_3);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view3), column);
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes ("Fourth Word", renderer,
"text", WORD_COLUMN_4,
NULL);
gtk_tree_view_column_set_sort_column_id (column, WORD_COLUMN_4);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view3), column);
gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (ssmodel),
(GtkTreeIterCompareFunc)gtk_tree_data_list_compare_func,
NULL, NULL);
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (ssmodel),
WORD_COLUMN_1,
GTK_SORT_ASCENDING);
gtk_container_add (GTK_CONTAINER (scrolled_window3), tree_view3);
gtk_window_set_default_size (GTK_WINDOW (window3), 400, 400);
gtk_widget_show_all (window3);
}
for (i = 0; data[i].word_1 != NULL; i++)
{
gint k;
gtk_tree_store_prepend (GTK_TREE_STORE (model), &iter, NULL);
gtk_tree_store_set (GTK_TREE_STORE (model), &iter,
WORD_COLUMN_1, data[i].word_1,
WORD_COLUMN_2, data[i].word_2,
WORD_COLUMN_3, data[i].word_3,
WORD_COLUMN_4, data[i].word_4,
-1);
for (k = 0; childdata[k].word_1 != NULL; k++)
{
GtkTreeIter child_iter;
gtk_tree_store_append (GTK_TREE_STORE (model), &child_iter, &iter);
gtk_tree_store_set (GTK_TREE_STORE (model), &child_iter,
WORD_COLUMN_1, childdata[k].word_1,
WORD_COLUMN_2, childdata[k].word_2,
WORD_COLUMN_3, childdata[k].word_3,
WORD_COLUMN_4, childdata[k].word_4,
-1);
}
}
gtk_main ();
return 0;
}

View File

@ -82,6 +82,25 @@ iter_insert (GtkWidget *button, GtkTreeView *tree_view)
node_set (&iter);
}
static void
iter_change (GtkWidget *button, GtkTreeView *tree_view)
{
GtkWidget *entry;
GtkTreeIter selected;
GtkTreeModel *model = gtk_tree_view_get_model (tree_view);
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)),
NULL, &selected))
{
gtk_tree_store_set (GTK_TREE_STORE (model),
&selected,
1,
gtk_entry_get_text (GTK_ENTRY (entry)),
-1);
}
}
static void
iter_insert_before (GtkWidget *button, GtkTreeView *tree_view)
{
@ -281,7 +300,17 @@ make_window (gint view_type)
gtk_signal_connect (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC (iter_insert),
tree_view);
button = gtk_button_new_with_label ("gtk_tree_store_set");
hbox = gtk_hbox_new (FALSE, 8);
entry = gtk_entry_new ();
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (hbox), entry, FALSE, FALSE, 0);
gtk_object_set_user_data (GTK_OBJECT (button), entry);
gtk_signal_connect (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC (iter_change),
tree_view);
button = gtk_button_new_with_label ("gtk_tree_store_insert_before");
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);