Commit 109cda6b authored by Kristian Rietveld's avatar Kristian Rietveld Committed by Kristian Rietveld

much changes in an attempt to make it working. It mostly works now,

Sun Sep  2 23:27:16 2001  Kristian Rietveld  <kristian@planet.nl>

        * gtk/gtktreemodelsort.[ch]: much changes in an attempt to make
        it working. It mostly works now, although there're still a few issues
        to be worked out.

        * tests/testtreesort.c (main): changes to have a better test
        application for the GtkTreeModelSort.
parent 9a4b995b
Sun Sep 2 23:27:16 2001 Kristian Rietveld <kristian@planet.nl>
* gtk/gtktreemodelsort.[ch]: much changes in an attempt to make
it working. It mostly works now, although there're still a few issues
to be worked out.
* tests/testtreesort.c (main): changes to have a better test
application for the GtkTreeModelSort.
Sun Sep 2 23:19:07 2001 Kristian Rietveld <kristian@planet.nl>
* gtk/gtktreeview.c (gtk_tree_view_search_iter): code cleaup,
......
Sun Sep 2 23:27:16 2001 Kristian Rietveld <kristian@planet.nl>
* gtk/gtktreemodelsort.[ch]: much changes in an attempt to make
it working. It mostly works now, although there're still a few issues
to be worked out.
* tests/testtreesort.c (main): changes to have a better test
application for the GtkTreeModelSort.
Sun Sep 2 23:19:07 2001 Kristian Rietveld <kristian@planet.nl>
* gtk/gtktreeview.c (gtk_tree_view_search_iter): code cleaup,
......
Sun Sep 2 23:27:16 2001 Kristian Rietveld <kristian@planet.nl>
* gtk/gtktreemodelsort.[ch]: much changes in an attempt to make
it working. It mostly works now, although there're still a few issues
to be worked out.
* tests/testtreesort.c (main): changes to have a better test
application for the GtkTreeModelSort.
Sun Sep 2 23:19:07 2001 Kristian Rietveld <kristian@planet.nl>
* gtk/gtktreeview.c (gtk_tree_view_search_iter): code cleaup,
......
Sun Sep 2 23:27:16 2001 Kristian Rietveld <kristian@planet.nl>
* gtk/gtktreemodelsort.[ch]: much changes in an attempt to make
it working. It mostly works now, although there're still a few issues
to be worked out.
* tests/testtreesort.c (main): changes to have a better test
application for the GtkTreeModelSort.
Sun Sep 2 23:19:07 2001 Kristian Rietveld <kristian@planet.nl>
* gtk/gtktreeview.c (gtk_tree_view_search_iter): code cleaup,
......
Sun Sep 2 23:27:16 2001 Kristian Rietveld <kristian@planet.nl>
* gtk/gtktreemodelsort.[ch]: much changes in an attempt to make
it working. It mostly works now, although there're still a few issues
to be worked out.
* tests/testtreesort.c (main): changes to have a better test
application for the GtkTreeModelSort.
Sun Sep 2 23:19:07 2001 Kristian Rietveld <kristian@planet.nl>
* gtk/gtktreeview.c (gtk_tree_view_search_iter): code cleaup,
......
Sun Sep 2 23:27:16 2001 Kristian Rietveld <kristian@planet.nl>
* gtk/gtktreemodelsort.[ch]: much changes in an attempt to make
it working. It mostly works now, although there're still a few issues
to be worked out.
* tests/testtreesort.c (main): changes to have a better test
application for the GtkTreeModelSort.
Sun Sep 2 23:19:07 2001 Kristian Rietveld <kristian@planet.nl>
* gtk/gtktreeview.c (gtk_tree_view_search_iter): code cleaup,
......
Sun Sep 2 23:27:16 2001 Kristian Rietveld <kristian@planet.nl>
* gtk/gtktreemodelsort.[ch]: much changes in an attempt to make
it working. It mostly works now, although there're still a few issues
to be worked out.
* tests/testtreesort.c (main): changes to have a better test
application for the GtkTreeModelSort.
Sun Sep 2 23:19:07 2001 Kristian Rietveld <kristian@planet.nl>
* gtk/gtktreeview.c (gtk_tree_view_search_iter): code cleaup,
......
......@@ -17,7 +17,6 @@
* Boston, MA 02111-1307, USA.
*/
/* 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 child model being
* sorted. As a convention, variables referencing the child model will have an
......@@ -26,113 +25,154 @@
#include "gtktreemodelsort.h"
#include "gtktreesortable.h"
#include "gtktreestore.h"
#include "gtksignal.h"
#include "gtktreedatalist.h"
#include <string.h>
typedef struct _SortElt SortElt;
struct _SortElt
{
GtkTreeIter iter;
SortElt *parent;
GArray *children;
gint ref;
gint offset;
GtkTreeIter iter;
SortElt *parent;
GArray *children;
gint offset;
gint ref;
};
typedef struct _SortData SortData;
struct _SortData
{
GtkTreeModel *model;
gint sort_col;
GValueCompareFunc func;
GtkTreeModelSort *tree_model_sort;
GtkTreePath *parent_a;
GtkTreePath *parent_b;
};
typedef struct _SortTuple SortTuple;
struct _SortTuple
{
SortElt *elt;
GArray *children;
gint offset;
};
#define get_array(e,t) ((GArray *)((e)->parent?(e)->parent->children:GTK_TREE_MODEL_SORT(t)->root))
static void gtk_tree_model_sort_init (GtkTreeModelSort *tree_model_sort);
static void gtk_tree_model_sort_class_init (GtkTreeModelSortClass *tree_model_sort_class);
static void gtk_tree_model_sort_tree_model_init (GtkTreeModelIface *iface);
/* object init and signal handlers */
static void gtk_tree_model_sort_init (GtkTreeModelSort *tree_model_sort);
static void gtk_tree_model_sort_class_init (GtkTreeModelSortClass *tree_model_sort_class);
static void gtk_tree_model_sort_tree_model_init (GtkTreeModelIface *iface);
static void gtk_tree_model_sort_tree_sortable_init (GtkTreeSortableIface *iface);
static void gtk_tree_model_sort_finalize (GObject *object);
static void gtk_tree_model_sort_range_changed (GtkTreeModel *model,
GtkTreePath *start_path,
GtkTreeIter *start_iter,
GtkTreePath *end_path,
GtkTreeIter *end_iter,
gpointer data);
static void gtk_tree_model_sort_inserted (GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
gpointer data);
static void gtk_tree_model_sort_has_child_toggled (GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
gpointer data);
static void gtk_tree_model_sort_deleted (GtkTreeModel *model,
GtkTreePath *path,
gpointer data);
static gint gtk_tree_model_sort_get_n_columns (GtkTreeModel *tree_model);
static GType gtk_tree_model_sort_get_column_type (GtkTreeModel *tree_model,
gint index);
static gboolean gtk_tree_model_sort_get_iter (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreePath *path);
static GtkTreePath *gtk_tree_model_sort_get_path (GtkTreeModel *tree_model,
GtkTreeIter *iter);
static void gtk_tree_model_sort_get_value (GtkTreeModel *tree_model,
GtkTreeIter *iter,
gint column,
GValue *value);
static gboolean gtk_tree_model_sort_iter_next (GtkTreeModel *tree_model,
GtkTreeIter *iter);
static gboolean gtk_tree_model_sort_iter_children (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreeIter *parent);
static gboolean gtk_tree_model_sort_iter_has_child (GtkTreeModel *tree_model,
GtkTreeIter *iter);
static gint gtk_tree_model_sort_iter_n_children (GtkTreeModel *tree_model,
GtkTreeIter *iter);
static gboolean gtk_tree_model_sort_iter_nth_child (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreeIter *parent,
gint n);
static gboolean gtk_tree_model_sort_iter_parent (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreeIter *child);
static void gtk_tree_model_sort_ref_node (GtkTreeModel *tree_model,
GtkTreeIter *iter);
static void gtk_tree_model_sort_unref_node (GtkTreeModel *tree_model,
GtkTreeIter *iter);
/* sortable */
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);
/* Internal functions */
static gint gtk_tree_model_sort_array_find_insert (GtkTreeModelSort *tree_model_sort,
GArray *array,
GtkTreeIter *iter,
gboolean skip_sort_elt);
static GtkTreePath *gtk_tree_model_sort_convert_path_real (GtkTreeModelSort *tree_model_sort,
GtkTreePath *child_path,
gboolean build_children);
static void gtk_tree_model_sort_build_level (GtkTreeModelSort *tree_model_sort,
SortElt *place);
static void gtk_tree_model_sort_free_level (GArray *array);
static void gtk_tree_model_sort_finalize (GObject *object);
static void gtk_tree_model_sort_range_changed (GtkTreeModel *model,
GtkTreePath *start_path,
GtkTreeIter *start_iter,
GtkTreePath *end_path,
GtkTreeIter *end_iter,
gpointer data);
static void gtk_tree_model_sort_inserted (GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
gpointer data);
static void gtk_tree_model_sort_has_child_toggled (GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
gpointer data);
static void gtk_tree_model_sort_deleted (GtkTreeModel *model,
GtkTreePath *path,
gpointer data);
static void gtk_tree_model_sort_reordered (GtkTreeModel *s_model,
GtkTreePath *s_path,
GtkTreeIter *s_iter,
gint *new_order,
gpointer data);
/* TreeModel interface */
static gint gtk_tree_model_sort_get_n_columns (GtkTreeModel *tree_model);
static GType gtk_tree_model_sort_get_column_type (GtkTreeModel *tree_model,
gint index);
static gboolean gtk_tree_model_sort_get_iter (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreePath *path);
static GtkTreePath *gtk_tree_model_sort_get_path (GtkTreeModel *tree_model,
GtkTreeIter *iter);
static void gtk_tree_model_sort_get_value (GtkTreeModel *tree_model,
GtkTreeIter *iter,
gint column,
GValue *value);
static gboolean gtk_tree_model_sort_iter_next (GtkTreeModel *tree_model,
GtkTreeIter *iter);
static gboolean gtk_tree_model_sort_iter_children (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreeIter *parent);
static gboolean gtk_tree_model_sort_iter_has_child (GtkTreeModel *tree_model,
GtkTreeIter *iter);
static gint gtk_tree_model_sort_iter_n_children (GtkTreeModel *tree_model,
GtkTreeIter *iter);
static gboolean gtk_tree_model_sort_iter_nth_child (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreeIter *parent,
gint n);
static gboolean gtk_tree_model_sort_iter_parent (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreeIter *child);
static void gtk_tree_model_sort_ref_node (GtkTreeModel *tree_model,
GtkTreeIter *iter);
static void gtk_tree_model_sort_unref_node (GtkTreeModel *tree_model,
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);
/* internal functions */
static gboolean gtk_tree_model_sort_get_iter_helper (GtkTreeModelSort *tree_model_sort,
GArray *array,
GtkTreeIter *iter,
gint depth,
GtkTreePath *path);
static gint gtk_tree_model_sort_compare_func (gconstpointer a,
gconstpointer b,
gpointer user_data);
static void gtk_tree_model_sort_sort_helper (GtkTreeModelSort *tree_model_sort,
GArray *parent,
gboolean recurse,
gboolean emit_reordered);
static void gtk_tree_model_sort_sort (GtkTreeModelSort *tree_model_sort);
static gint gtk_tree_model_sort_array_find_insert (GtkTreeModelSort *tree_model_sort,
GArray *array,
GtkTreeIter *iter,
gboolean skip_sort_elt);
static GtkTreePath *gtk_tree_model_sort_generate_path_index(SortElt *item,
GtkTreeModelSort *tree_model_sort);
static GtkTreePath *gtk_tree_model_sort_generate_path (SortElt *item);
static GtkTreePath *gtk_tree_model_sort_convert_path_real (GtkTreeModelSort *tree_model_sort,
GtkTreePath *child_path,
gboolean build_children);
static void gtk_tree_model_sort_convert_iter_real (GtkTreeModelSort *tree_model_sort,
GtkTreeIter *sort_iter,
GtkTreeIter *child_iter,
gboolean build_children);
static void gtk_tree_model_sort_build_level (GtkTreeModelSort *tree_model_sort,
SortElt *place);
static void gtk_tree_model_sort_free_level (GArray *array);
static void sort_elt_get_iter (GtkTreeModelSort *tree_model_sort,
SortElt *elt,
GtkTreeIter *child_iter);
......@@ -140,44 +180,46 @@ GType
gtk_tree_model_sort_get_type (void)
{
static GType tree_model_sort_type = 0;
if (!tree_model_sort_type)
{
static const GTypeInfo tree_model_sort_info =
{
sizeof (GtkTreeModelSortClass),
NULL, /* base_init */
NULL, /* base_finalize */
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gtk_tree_model_sort_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GtkTreeModelSort),
0, /* n_preallocs */
0, /* n_preallocs */
(GInstanceInitFunc) gtk_tree_model_sort_init
};
static const GInterfaceInfo tree_model_info =
{
(GInterfaceInitFunc) gtk_tree_model_sort_tree_model_init,
NULL,
NULL
(GInterfaceInitFunc) gtk_tree_model_sort_tree_model_init,
NULL,
NULL
};
static const GInterfaceInfo sortable_info =
{
(GInterfaceInitFunc) gtk_tree_model_sort_tree_sortable_init,
NULL,
NULL
(GInterfaceInitFunc) gtk_tree_model_sort_tree_sortable_init,
NULL,
NULL
};
tree_model_sort_type = g_type_register_static (G_TYPE_OBJECT, "GtkTreeModelSort", &tree_model_sort_info, 0);
tree_model_sort_type = g_type_register_static (G_TYPE_OBJECT,
"GtkTreeModelSort",
&tree_model_sort_info, 0);
g_type_add_interface_static (tree_model_sort_type,
GTK_TYPE_TREE_MODEL,
&tree_model_info);
GTK_TYPE_TREE_MODEL,
&tree_model_info);
g_type_add_interface_static (tree_model_sort_type,
GTK_TYPE_TREE_SORTABLE,
&sortable_info);
GTK_TYPE_TREE_SORTABLE,
&sortable_info);
}
return tree_model_sort_type;
......@@ -224,14 +266,33 @@ gtk_tree_model_sort_init (GtkTreeModelSort *tree_model_sort)
{
tree_model_sort->sort_column_id = -1;
tree_model_sort->stamp = g_random_int ();
tree_model_sort->cache_child_iters = FALSE;
tree_model_sort->root = NULL;
tree_model_sort->sort_list = NULL;
}
/**
* gtk_tree_model_sort_new:
*
* Creates a new #GtkTreeModel without child_model.
*
* Returns: A new #GtkTreeModel.
*/
GtkTreeModel *
gtk_tree_model_sort_new (void)
{
return GTK_TREE_MODEL (g_object_new (gtk_tree_model_sort_get_type (), NULL));
}
/**
* gtk_tree_model_sort_new_with_model:
* @child_model: A #GtkTreeModel
*
* Creates a new #GtkTreeModel, with @child_model as the child_model.
*
* Return value: A new #GtkTreeModel.
*/
GtkTreeModel *
gtk_tree_model_sort_new_with_model (GtkTreeModel *child_model)
{
......@@ -248,12 +309,11 @@ gtk_tree_model_sort_new_with_model (GtkTreeModel *child_model)
* @tree_model_sort: The #GtkTreeModelSort.
* @child_model: A #GtkTreeModel, or NULL.
*
* Sets the model of @tree_model_sort to be @model. If @model is NULL, then the
* old model is unset.
* Sets the model of @tree_model_sort to be @model. If @model is NULL, then the * old model is unset.
**/
void
gtk_tree_model_sort_set_model (GtkTreeModelSort *tree_model_sort,
GtkTreeModel *child_model)
GtkTreeModel *child_model)
{
g_return_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model_sort));
......@@ -263,14 +323,17 @@ gtk_tree_model_sort_set_model (GtkTreeModelSort *tree_model_sort,
if (tree_model_sort->child_model)
{
g_signal_handler_disconnect (G_OBJECT (tree_model_sort->child_model),
tree_model_sort->changed_id);
tree_model_sort->changed_id);
g_signal_handler_disconnect (G_OBJECT (tree_model_sort->child_model),
tree_model_sort->inserted_id);
g_signal_handler_disconnect (G_OBJECT (tree_model_sort->child_model),
tree_model_sort->inserted_id);
tree_model_sort->has_child_toggled_id);
g_signal_handler_disconnect (G_OBJECT (tree_model_sort->child_model),
tree_model_sort->has_child_toggled_id);
tree_model_sort->deleted_id);
g_signal_handler_disconnect (G_OBJECT (tree_model_sort->child_model),
tree_model_sort->deleted_id);
tree_model_sort->reordered_id);
gtk_tree_model_sort_free_level (tree_model_sort->root);
g_object_unref (G_OBJECT (tree_model_sort->child_model));
}
......@@ -293,33 +356,46 @@ gtk_tree_model_sort_set_model (GtkTreeModelSort *tree_model_sort,
gint i, n_columns;
tree_model_sort->changed_id =
g_signal_connect (child_model,
g_signal_connect (child_model,
"range_changed",
G_CALLBACK (gtk_tree_model_sort_range_changed),
tree_model_sort);
tree_model_sort->inserted_id =
g_signal_connect (child_model,
g_signal_connect (child_model,
"inserted",
G_CALLBACK (gtk_tree_model_sort_inserted),
tree_model_sort);
tree_model_sort->has_child_toggled_id =
g_signal_connect (child_model,
g_signal_connect (child_model,
"has_child_toggled",
G_CALLBACK (gtk_tree_model_sort_has_child_toggled),
tree_model_sort);
tree_model_sort->deleted_id =
g_signal_connect (child_model,
g_signal_connect (child_model,
"deleted",
G_CALLBACK (gtk_tree_model_sort_deleted),
tree_model_sort);
tree_model_sort->reordered_id =
g_signal_connect (child_model,
"reordered",
G_CALLBACK (gtk_tree_model_sort_reordered),
tree_model_sort);
tree_model_sort->flags = gtk_tree_model_get_flags (child_model);
n_columns = gtk_tree_model_get_n_columns (child_model);
types = g_new (GType, n_columns);
for (i = 0; i < n_columns; i++)
types[i] = gtk_tree_model_get_column_type (child_model, i);
tree_model_sort->sort_list = _gtk_tree_data_list_header_new (n_columns, types);
types[i] = gtk_tree_model_get_column_type (child_model, i);
tree_model_sort->sort_list = _gtk_tree_data_list_header_new (n_columns,
types);
g_free (types);
if (tree_model_sort->flags & GTK_TREE_MODEL_ITERS_PERSIST)
tree_model_sort->cache_child_iters = TRUE;
else
tree_model_sort->cache_child_iters = FALSE;
}
}
......@@ -353,7 +429,7 @@ gtk_tree_model_sort_get_model (GtkTreeModelSort *tree_model)
**/
GtkTreePath *
gtk_tree_model_sort_convert_path (GtkTreeModelSort *tree_model_sort,
GtkTreePath *child_path)
GtkTreePath *child_path)
{
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model_sort), NULL);
g_return_val_if_fail (child_path != NULL, NULL);
......@@ -361,6 +437,32 @@ gtk_tree_model_sort_convert_path (GtkTreeModelSort *tree_model_sort,
return gtk_tree_model_sort_convert_path_real (tree_model_sort, child_path, TRUE);
}
/**
* gtk_tree_model_sort_convert_iter:
* @tree_model_sort: The #GtkTreeModelSort
* @sort_iter: A pointer to a #GtkTreeIter
* @child_iter: A #GtkTreeIter, relative to the child model
*
* Converts the @child_iter to a new iter, relative to the sorted position. In other
* words, the value found in the @tree_model_sort ->child_model at the @child_iter, is
* identical to that found in @tree_model_sort at the @sort_iter. The @sort_iter will be
* set.
*/
void
gtk_tree_model_sort_convert_iter (GtkTreeModelSort *tree_model_sort,
GtkTreeIter *sort_iter,
GtkTreeIter *child_iter)
{
g_return_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model_sort));
g_return_if_fail (sort_iter != NULL);
g_return_if_fail (child_iter != NULL);
gtk_tree_model_sort_convert_iter_real (tree_model_sort,
sort_iter,
child_iter,
TRUE);
}
static void
gtk_tree_model_sort_finalize (GObject *object)
{
......@@ -383,19 +485,23 @@ gtk_tree_model_sort_finalize (GObject *object)
static void
gtk_tree_model_sort_range_changed (GtkTreeModel *s_model,
GtkTreePath *s_start_path,
GtkTreeIter *s_start_iter,
GtkTreePath *s_end_path,
GtkTreeIter *s_end_iter,
gpointer data)
GtkTreePath *s_start_path,
GtkTreeIter *s_start_iter,
GtkTreePath *s_end_path,
GtkTreeIter *s_end_iter,
gpointer data)
{
GtkTreeModelSort *tree_model_sort = GTK_TREE_MODEL_SORT (data);
GtkTreePath *path;
GtkTreeIter iter;
GtkTreeIter tmpiter;
SortElt *elt;
GArray *array;
gboolean free_s_path = FALSE;
gint i;
gint offset;
gint index;
SortElt tmp;
g_return_if_fail (s_start_path != NULL || s_start_iter != NULL);
......@@ -409,52 +515,87 @@ gtk_tree_model_sort_range_changed (GtkTreeModel *s_model,
if (path == NULL)
{
if (free_s_path)
gtk_tree_path_free (s_start_path);
gtk_tree_path_free (s_start_path);
return;
}
gtk_tree_model_get_iter (GTK_TREE_MODEL (data), &iter, path);
elt = (SortElt *) iter.user_data;
elt = iter.user_data;
array = get_array (elt, tree_model_sort);
/* FIXME: as an optimization for when the column other then the one we're
if (array->len < 2)
{
/* we're not going to care about this */
if (free_s_path)
gtk_tree_path_free (s_start_path);
gtk_tree_path_free (path);
return;
}
if (tree_model_sort->cache_child_iters)
sort_elt_get_iter (tree_model_sort, elt, &tmpiter);
offset = elt->offset;
for (i = 0; i < array->len; i++)
if (elt->offset == g_array_index (array, SortElt, i).offset)
{
index = i;
}
memcpy (&tmp, elt, sizeof (SortElt));
g_array_remove_index (array, index);
/* _kris_: don't know if this FIXME was originally at this position...
* FIXME: as an optimization for when the column other then the one we're
* sorting is changed, we can check the prev and next element to see if
* they're different.
*/
/* Now we need to resort things. */
index = gtk_tree_model_sort_array_find_insert (tree_model_sort,
array,
(GtkTreeIter *) elt,
TRUE);
gtk_tree_model_range_changed (GTK_TREE_MODEL (data), path, &iter, path, &iter);
/* now we need to resort things */
if (tree_model_sort->cache_child_iters)
index = gtk_tree_model_sort_array_find_insert (tree_model_sort,
array,
&tmp.iter,
TRUE);
else
index = gtk_tree_model_sort_array_find_insert (tree_model_sort,
array,
&tmpiter,
TRUE);
g_array_insert_val (array, index, tmp);
gtk_tree_model_range_changed (GTK_TREE_MODEL (data), path, &iter,
path, &iter);
gtk_tree_path_free (path);
if (free_s_path)
gtk_tree_path_free (s_start_path);
}
/* FALSE if the value was inserted, TRUE otherwise */
/* Returns FALSE if the value was inserted, TRUE otherwise */
static gboolean
gtk_tree_model_sort_insert_value (GtkTreeModelSort *sort,
gtk_tree_model_sort_insert_value (GtkTreeModelSort *tree_model_sort,
GtkTreePath *s_path,
GtkTreeIter *s_iter)
{
GtkTreePath *tmp_path;
GArray *array;
GArray *array = NULL;
gint index;
GtkTreeIter iter;
SortElt elt;
gint offset;
gint j;
SortElt *tmp_elt;
offset = gtk_tree_path_get_indices (s_path)[gtk_tree_path_get_depth (s_path) - 1];
elt.iter = *s_iter;
elt.ref = 0;
offset = gtk_tree_path_get_indices (s_path)[gtk_tree_path_get_depth (s_path) - 1];
if (tree_model_sort->cache_child_iters)
elt.iter = *s_iter;
elt.children = NULL;
elt.offset = offset;
elt.ref = 0;
tmp_path = gtk_tree_path_copy (s_path);
......@@ -462,17 +603,28 @@ gtk_tree_model_sort_insert_value (GtkTreeModelSort *sort,
{
GtkTreePath *parent_path;
parent_path = gtk_tree_model_sort_convert_path_real (sort, tmp_path, FALSE);
if (parent_path == NULL)
parent_path = gtk_tree_model_sort_convert_path_real (tree_model_sort,
tmp_path,
FALSE);
if (!parent_path)
{
gtk_tree_path_free (tmp_path);
return FALSE;
}
gtk_tree_model_get_iter (GTK_TREE_MODEL (sort), &iter, parent_path);
elt.parent = ((SortElt *) iter.user_data);
array = ((SortElt *) iter.user_data)->children;
if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (tree_model_sort), &iter,
parent_path))
{
gtk_tree_path_free (tmp_path);
return FALSE;
}
elt.parent = iter.user_data;
array = elt.parent->children;
gtk_tree_path_free (parent_path);
if (array == NULL)
if (!array)
{
gtk_tree_path_free (tmp_path);
return FALSE;
......@@ -480,34 +632,47 @@ gtk_tree_model_sort_insert_value (GtkTreeModelSort *sort,
}
else
{
if (sort->root == NULL)