Commit 426ac9c6 authored by Jonathan Blandford's avatar Jonathan Blandford Committed by Jonathan Blandford

Whoops. Forgot this a couple months ago. Now GtkTreeStore sort of sorts.

Thu Jun 14 19:21:27 2001  Jonathan Blandford  <jrb@redhat.com>

	* gtk/gtktreestore.c (gtk_tree_store_sort_helper): Whoops.  Forgot
	this a couple months ago.  Now GtkTreeStore sort of sorts.  I'll
	finish it off tonight, though it basically works now when it's a
	list.  Also, I have a sinking feeling neither GtkTreeStore or
	GtkListStore actually resort when adding a new item.  I'll look
	into it.
parent c6046481
Thu Jun 14 19:21:27 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtktreestore.c (gtk_tree_store_sort_helper): Whoops. Forgot
this a couple months ago. Now GtkTreeStore sort of sorts. I'll
finish it off tonight, though it basically works now when it's a
list. Also, I have a sinking feeling neither GtkTreeStore or
GtkListStore actually resort when adding a new item. I'll look
into it.
2001-06-14 Havoc Pennington <hp@redhat.com> 2001-06-14 Havoc Pennington <hp@redhat.com>
* demos/gtk-demo/main.c (load_file): fix bug identified by * demos/gtk-demo/main.c (load_file): fix bug identified by
......
Thu Jun 14 19:21:27 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtktreestore.c (gtk_tree_store_sort_helper): Whoops. Forgot
this a couple months ago. Now GtkTreeStore sort of sorts. I'll
finish it off tonight, though it basically works now when it's a
list. Also, I have a sinking feeling neither GtkTreeStore or
GtkListStore actually resort when adding a new item. I'll look
into it.
2001-06-14 Havoc Pennington <hp@redhat.com> 2001-06-14 Havoc Pennington <hp@redhat.com>
* demos/gtk-demo/main.c (load_file): fix bug identified by * demos/gtk-demo/main.c (load_file): fix bug identified by
......
Thu Jun 14 19:21:27 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtktreestore.c (gtk_tree_store_sort_helper): Whoops. Forgot
this a couple months ago. Now GtkTreeStore sort of sorts. I'll
finish it off tonight, though it basically works now when it's a
list. Also, I have a sinking feeling neither GtkTreeStore or
GtkListStore actually resort when adding a new item. I'll look
into it.
2001-06-14 Havoc Pennington <hp@redhat.com> 2001-06-14 Havoc Pennington <hp@redhat.com>
* demos/gtk-demo/main.c (load_file): fix bug identified by * demos/gtk-demo/main.c (load_file): fix bug identified by
......
Thu Jun 14 19:21:27 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtktreestore.c (gtk_tree_store_sort_helper): Whoops. Forgot
this a couple months ago. Now GtkTreeStore sort of sorts. I'll
finish it off tonight, though it basically works now when it's a
list. Also, I have a sinking feeling neither GtkTreeStore or
GtkListStore actually resort when adding a new item. I'll look
into it.
2001-06-14 Havoc Pennington <hp@redhat.com> 2001-06-14 Havoc Pennington <hp@redhat.com>
* demos/gtk-demo/main.c (load_file): fix bug identified by * demos/gtk-demo/main.c (load_file): fix bug identified by
......
Thu Jun 14 19:21:27 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtktreestore.c (gtk_tree_store_sort_helper): Whoops. Forgot
this a couple months ago. Now GtkTreeStore sort of sorts. I'll
finish it off tonight, though it basically works now when it's a
list. Also, I have a sinking feeling neither GtkTreeStore or
GtkListStore actually resort when adding a new item. I'll look
into it.
2001-06-14 Havoc Pennington <hp@redhat.com> 2001-06-14 Havoc Pennington <hp@redhat.com>
* demos/gtk-demo/main.c (load_file): fix bug identified by * demos/gtk-demo/main.c (load_file): fix bug identified by
......
Thu Jun 14 19:21:27 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtktreestore.c (gtk_tree_store_sort_helper): Whoops. Forgot
this a couple months ago. Now GtkTreeStore sort of sorts. I'll
finish it off tonight, though it basically works now when it's a
list. Also, I have a sinking feeling neither GtkTreeStore or
GtkListStore actually resort when adding a new item. I'll look
into it.
2001-06-14 Havoc Pennington <hp@redhat.com> 2001-06-14 Havoc Pennington <hp@redhat.com>
* demos/gtk-demo/main.c (load_file): fix bug identified by * demos/gtk-demo/main.c (load_file): fix bug identified by
......
Thu Jun 14 19:21:27 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtktreestore.c (gtk_tree_store_sort_helper): Whoops. Forgot
this a couple months ago. Now GtkTreeStore sort of sorts. I'll
finish it off tonight, though it basically works now when it's a
list. Also, I have a sinking feeling neither GtkTreeStore or
GtkListStore actually resort when adding a new item. I'll look
into it.
2001-06-14 Havoc Pennington <hp@redhat.com> 2001-06-14 Havoc Pennington <hp@redhat.com>
* demos/gtk-demo/main.c (load_file): fix bug identified by * demos/gtk-demo/main.c (load_file): fix bug identified by
......
...@@ -1347,9 +1347,9 @@ typedef struct _SortTuple ...@@ -1347,9 +1347,9 @@ typedef struct _SortTuple
} SortTuple; } SortTuple;
static gint static gint
_gtk_list_store_compare_func (gconstpointer a, gtk_list_store_compare_func (gconstpointer a,
gconstpointer b, gconstpointer b,
gpointer user_data) gpointer user_data)
{ {
GtkListStore *list_store = user_data; GtkListStore *list_store = user_data;
GtkTreeDataSortHeader *header = NULL; GtkTreeDataSortHeader *header = NULL;
...@@ -1394,7 +1394,6 @@ gtk_list_store_sort (GtkListStore *list_store) ...@@ -1394,7 +1394,6 @@ gtk_list_store_sort (GtkListStore *list_store)
GtkTreeIter iter; GtkTreeIter iter;
GArray *sort_array; GArray *sort_array;
gint i; gint i;
GList *header_list;
gint *new_order; gint *new_order;
GSList *list; GSList *list;
GtkTreePath *path; GtkTreePath *path;
...@@ -1404,12 +1403,7 @@ gtk_list_store_sort (GtkListStore *list_store) ...@@ -1404,12 +1403,7 @@ gtk_list_store_sort (GtkListStore *list_store)
g_assert (GTK_LIST_STORE_IS_SORTED (list_store)); g_assert (GTK_LIST_STORE_IS_SORTED (list_store));
for (header_list = list_store->sort_list; header_list; header_list = header_list->next) header = _gtk_tree_data_list_get_header (list_store->sort_list, list_store->sort_column_id);
{
header = (GtkTreeDataSortHeader*) header_list->data;
if (header->sort_column_id == list_store->sort_column_id)
break;
}
/* We want to make sure that we have a function */ /* We want to make sure that we have a function */
g_return_if_fail (header != NULL); g_return_if_fail (header != NULL);
...@@ -1435,7 +1429,7 @@ gtk_list_store_sort (GtkListStore *list_store) ...@@ -1435,7 +1429,7 @@ gtk_list_store_sort (GtkListStore *list_store)
list = list->next; list = list->next;
} }
g_array_sort_with_data (sort_array, _gtk_list_store_compare_func, list_store); g_array_sort_with_data (sort_array, gtk_list_store_compare_func, list_store);
for (i = 0; i < list_store->length - 1; i++) for (i = 0; i < list_store->length - 1; i++)
g_array_index (sort_array, SortTuple, i).el->next = g_array_index (sort_array, SortTuple, i).el->next =
......
...@@ -576,8 +576,8 @@ gtk_tree_iter_free (GtkTreeIter *iter) ...@@ -576,8 +576,8 @@ gtk_tree_iter_free (GtkTreeIter *iter)
* @tree_model: A #GtkTreeModel. * @tree_model: A #GtkTreeModel.
* *
* Returns a set of flags supported by this interface. The flags are a bitwise * Returns a set of flags supported by this interface. The flags are a bitwise
* combination of #GtkTreeModelFlags. It is expected that the flags supported * combination of #GtkTreeModelFlags. The flags supported should not change
* do not change for an interface. * during the lifecycle of the tree_model.
* *
* Return value: The flags supported by this interface. * Return value: The flags supported by this interface.
**/ **/
......
...@@ -25,9 +25,13 @@ ...@@ -25,9 +25,13 @@
*/ */
#include "gtktreemodelsort.h" #include "gtktreemodelsort.h"
#include "gtktreesortable.h"
#include "gtksignal.h" #include "gtksignal.h"
#include "gtktreedatalist.h"
#include <string.h> #include <string.h>
typedef struct _SortElt SortElt; typedef struct _SortElt SortElt;
struct _SortElt struct _SortElt
{ {
...@@ -53,6 +57,7 @@ struct _SortData ...@@ -53,6 +57,7 @@ struct _SortData
static void gtk_tree_model_sort_init (GtkTreeModelSort *tree_model_sort); 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_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_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_finalize (GObject *object);
static void gtk_tree_model_sort_range_changed (GtkTreeModel *model, static void gtk_tree_model_sort_range_changed (GtkTreeModel *model,
GtkTreePath *start_path, GtkTreePath *start_path,
...@@ -104,6 +109,19 @@ static void gtk_tree_model_sort_ref_node (GtkTreeModel * ...@@ -104,6 +109,19 @@ static void gtk_tree_model_sort_ref_node (GtkTreeModel *
static void gtk_tree_model_sort_unref_node (GtkTreeModel *tree_model, static void gtk_tree_model_sort_unref_node (GtkTreeModel *tree_model,
GtkTreeIter *iter); GtkTreeIter *iter);
/* sortable */
static gboolean gtk_tree_model_sort_get_sort_column_id (GtkTreeSortable *sortable,
gint *sort_column_id,
GtkTreeSortOrder *order);
static void gtk_tree_model_sort_set_sort_column_id (GtkTreeSortable *sortable,
gint sort_column_id,
GtkTreeSortOrder order);
static void gtk_tree_model_sort_sort_column_id_set_func (GtkTreeSortable *sortable,
gint sort_column_id,
GtkTreeIterCompareFunc func,
gpointer data,
GtkDestroyNotify destroy);
/* Internal functions */ /* Internal functions */
static gint gtk_tree_model_sort_array_find_insert (GtkTreeModelSort *tree_model_sort, static gint gtk_tree_model_sort_array_find_insert (GtkTreeModelSort *tree_model_sort,
GArray *array, GArray *array,
...@@ -115,14 +133,6 @@ static GtkTreePath *gtk_tree_model_sort_convert_path_real (GtkTreeModelSort *tre ...@@ -115,14 +133,6 @@ static GtkTreePath *gtk_tree_model_sort_convert_path_real (GtkTreeModelSort *tre
static void gtk_tree_model_sort_build_level (GtkTreeModelSort *tree_model_sort, static void gtk_tree_model_sort_build_level (GtkTreeModelSort *tree_model_sort,
SortElt *place); SortElt *place);
static void gtk_tree_model_sort_free_level (GArray *array); static void gtk_tree_model_sort_free_level (GArray *array);
static GFunc gtk_tree_model_sort_get_func (GtkTreeModelSort *tree_model_sort);
static gint gtk_tree_model_sort_func (gconstpointer a,
gconstpointer b,
gpointer user_data);
static gint g_value_string_compare_func (const GValue *a,
const GValue *b);
static gint g_value_int_compare_func (const GValue *a,
const GValue *b);
...@@ -153,10 +163,21 @@ gtk_tree_model_sort_get_type (void) ...@@ -153,10 +163,21 @@ gtk_tree_model_sort_get_type (void)
NULL NULL
}; };
static const GInterfaceInfo sortable_info =
{
(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, g_type_add_interface_static (tree_model_sort_type,
GTK_TYPE_TREE_MODEL, GTK_TYPE_TREE_MODEL,
&tree_model_info); &tree_model_info);
g_type_add_interface_static (tree_model_sort_type,
GTK_TYPE_TREE_SORTABLE,
&sortable_info);
} }
return tree_model_sort_type; return tree_model_sort_type;
...@@ -190,9 +211,18 @@ gtk_tree_model_sort_tree_model_init (GtkTreeModelIface *iface) ...@@ -190,9 +211,18 @@ gtk_tree_model_sort_tree_model_init (GtkTreeModelIface *iface)
iface->unref_node = gtk_tree_model_sort_unref_node; iface->unref_node = gtk_tree_model_sort_unref_node;
} }
static void
gtk_tree_model_sort_tree_sortable_init (GtkTreeSortableIface *iface)
{
iface->get_sort_column_id = gtk_tree_model_sort_get_sort_column_id;
iface->set_sort_column_id = gtk_tree_model_sort_set_sort_column_id;
iface->sort_column_id_set_func = gtk_tree_model_sort_sort_column_id_set_func;
}
static void static void
gtk_tree_model_sort_init (GtkTreeModelSort *tree_model_sort) 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->stamp = g_random_int ();
} }
...@@ -203,17 +233,13 @@ gtk_tree_model_sort_new (void) ...@@ -203,17 +233,13 @@ gtk_tree_model_sort_new (void)
} }
GtkTreeModel * GtkTreeModel *
gtk_tree_model_sort_new_with_model (GtkTreeModel *child_model, gtk_tree_model_sort_new_with_model (GtkTreeModel *child_model)
GValueCompareFunc func,
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), child_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)->sort_col = sort_col;
return retval; return retval;
} }
...@@ -249,35 +275,56 @@ gtk_tree_model_sort_set_model (GtkTreeModelSort *tree_model_sort, ...@@ -249,35 +275,56 @@ gtk_tree_model_sort_set_model (GtkTreeModelSort *tree_model_sort,
g_object_unref (G_OBJECT (tree_model_sort->child_model)); g_object_unref (G_OBJECT (tree_model_sort->child_model));
} }
tree_model_sort->child_model = child_model; if (tree_model_sort->root)
{
gtk_tree_model_sort_free_level (tree_model_sort->root);
tree_model_sort->root;
}
if (tree_model_sort->sort_list)
{
_gtk_tree_data_list_header_free (tree_model_sort->sort_list);
tree_model_sort->sort_list = NULL;
}
tree_model_sort->child_model = child_model;
if (child_model) if (child_model)
{ {
GType *types;
gint i, n_columns;
tree_model_sort->changed_id = tree_model_sort->changed_id =
g_signal_connectc (child_model, g_signal_connectc (child_model,
"range_changed", "range_changed",
gtk_tree_model_sort_range_changed, G_CALLBACK (gtk_tree_model_sort_range_changed),
tree_model_sort, tree_model_sort,
FALSE); FALSE);
tree_model_sort->inserted_id = tree_model_sort->inserted_id =
g_signal_connectc (child_model, g_signal_connectc (child_model,
"inserted", "inserted",
gtk_tree_model_sort_inserted, G_CALLBACK (gtk_tree_model_sort_inserted),
tree_model_sort, tree_model_sort,
FALSE); FALSE);
tree_model_sort->has_child_toggled_id = tree_model_sort->has_child_toggled_id =
g_signal_connectc (child_model, g_signal_connectc (child_model,
"has_child_toggled", "has_child_toggled",
gtk_tree_model_sort_has_child_toggled, G_CALLBACK (gtk_tree_model_sort_has_child_toggled),
tree_model_sort, tree_model_sort,
FALSE); FALSE);
tree_model_sort->deleted_id = tree_model_sort->deleted_id =
g_signal_connectc (child_model, g_signal_connectc (child_model,
"deleted", "deleted",
gtk_tree_model_sort_deleted, G_CALLBACK (gtk_tree_model_sort_deleted),
tree_model_sort, tree_model_sort,
FALSE); FALSE);
tree_model_sort->flags = gtk_tree_model_get_flags (child_model); 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);
g_free (types);
} }
} }
...@@ -333,6 +380,11 @@ gtk_tree_model_sort_finalize (GObject *object) ...@@ -333,6 +380,11 @@ gtk_tree_model_sort_finalize (GObject *object)
g_object_unref (G_OBJECT (tree_model_sort->child_model)); g_object_unref (G_OBJECT (tree_model_sort->child_model));
tree_model_sort->child_model = NULL; tree_model_sort->child_model = NULL;
} }
if (tree_model_sort->sort_list)
{
_gtk_tree_data_list_header_free (tree_model_sort->sort_list);
tree_model_sort->sort_list = NULL;
}
} }
static void static void
...@@ -594,8 +646,12 @@ gtk_tree_model_sort_deleted (GtkTreeModel *s_model, ...@@ -594,8 +646,12 @@ gtk_tree_model_sort_deleted (GtkTreeModel *s_model,
static gint static gint
gtk_tree_model_sort_get_n_columns (GtkTreeModel *tree_model) gtk_tree_model_sort_get_n_columns (GtkTreeModel *tree_model)
{ {
GtkTreeModelSort *tree_model_sort = (GtkTreeModelSort *) 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)->child_model != NULL, 0);
if (tree_model_sort->child_model == 0)
return 0;
return gtk_tree_model_get_n_columns (GTK_TREE_MODEL_SORT (tree_model)->child_model); return gtk_tree_model_get_n_columns (GTK_TREE_MODEL_SORT (tree_model)->child_model);
} }
...@@ -857,6 +913,98 @@ gtk_tree_model_sort_unref_node (GtkTreeModel *tree_model, ...@@ -857,6 +913,98 @@ gtk_tree_model_sort_unref_node (GtkTreeModel *tree_model,
GtkTreeIter *iter) GtkTreeIter *iter)
{ {
}
static gboolean
gtk_tree_model_sort_get_sort_column_id (GtkTreeSortable *sortable,
gint *sort_column_id,
GtkTreeSortOrder *order)
{
GtkTreeModelSort *tree_model_sort = (GtkTreeModelSort *) sortable;
g_return_val_if_fail (sortable != NULL, FALSE);
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (sortable), FALSE);
if (tree_model_sort->sort_column_id == -1)
return FALSE;
if (sort_column_id)
*sort_column_id = tree_model_sort->sort_column_id;
if (order)
*order = tree_model_sort->order;
return TRUE;
}
static void
gtk_tree_model_sort_set_sort_column_id (GtkTreeSortable *sortable,
gint sort_column_id,
GtkTreeSortOrder order)
{
GtkTreeModelSort *tree_model_sort = (GtkTreeModelSort *) sortable;
GList *list;
g_return_if_fail (sortable != NULL);
g_return_if_fail (GTK_IS_TREE_MODEL_SORT (sortable));
for (list = tree_model_sort->sort_list; list; list = list->next)
{
GtkTreeDataSortHeader *header = (GtkTreeDataSortHeader*) list->data;
if (header->sort_column_id == sort_column_id)
break;
}
g_return_if_fail (list != NULL);
if ((tree_model_sort->sort_column_id == sort_column_id) &&
(tree_model_sort->order == order))
return;
tree_model_sort->sort_column_id = sort_column_id;
tree_model_sort->order = order;
/* if (tree_model_sort->sort_column_id >= 0)
gtk_list_store_sort (tree_model_sort);*/
gtk_tree_sortable_sort_column_changed (sortable);
}
static void
gtk_tree_model_sort_sort_column_id_set_func (GtkTreeSortable *sortable,
gint sort_column_id,
GtkTreeIterCompareFunc func,
gpointer data,
GtkDestroyNotify destroy)
{
GtkTreeModelSort *tree_model_sort = (GtkTreeModelSort *) sortable;
GtkTreeDataSortHeader *header = NULL;
GList *list;
g_return_if_fail (sortable != NULL);
g_return_if_fail (GTK_IS_TREE_MODEL_SORT (sortable));
g_return_if_fail (func != NULL);
for (list = tree_model_sort->sort_list; list; list = list->next)
{
header = (GtkTreeDataSortHeader*) list->data;
if (header->sort_column_id == sort_column_id)
break;
}
if (header == NULL)
{
header = g_new0 (GtkTreeDataSortHeader, 1);
header->sort_column_id = sort_column_id;
tree_model_sort->sort_list = g_list_append (tree_model_sort->sort_list, header);
}
if (header->destroy)
(* header->destroy) (header->data);
header->func = func;
header->data = data;
header->destroy = destroy;
} }
/* Internal functions */ /* Internal functions */
...@@ -874,11 +1022,11 @@ gtk_tree_model_sort_array_find_insert (GtkTreeModelSort *tree_model_sort, ...@@ -874,11 +1022,11 @@ gtk_tree_model_sort_array_find_insert (GtkTreeModelSort *tree_model_sort,
GValue tmp_value = {0, }; GValue tmp_value = {0, };
SortElt *tmp_elt; SortElt *tmp_elt;
func = (GValueCompareFunc) gtk_tree_model_sort_get_func (tree_model_sort); func = NULL; //(GValueCompareFunc) gtk_tree_model_sort_get_func (tree_model_sort);
g_return_val_if_fail (func != NULL, 0); g_return_val_if_fail (func != NULL, 0);
gtk_tree_model_get_value (tree_model_sort->child_model, iter, tree_model_sort->sort_col, &value); gtk_tree_model_get_value (tree_model_sort->child_model, iter, tree_model_sort->sort_column_id, &value);
for (middle = 0; middle < array->len; middle++) for (middle = 0; middle < array->len; middle++)
{ {
...@@ -888,7 +1036,7 @@ gtk_tree_model_sort_array_find_insert (GtkTreeModelSort *tree_model_sort, ...@@ -888,7 +1036,7 @@ gtk_tree_model_sort_array_find_insert (GtkTreeModelSort *tree_model_sort,
continue; continue;
gtk_tree_model_get_value (tree_model_sort->child_model, gtk_tree_model_get_value (tree_model_sort->child_model,
(GtkTreeIter *) tmp_elt, (GtkTreeIter *) tmp_elt,
tree_model_sort->sort_col, tree_model_sort->sort_column_id,
&tmp_value); &tmp_value);
cmp = ((func) (&value, &tmp_value)); cmp = ((func) (&value, &tmp_value));
...@@ -1019,12 +1167,6 @@ gtk_tree_model_sort_build_level (GtkTreeModelSort *tree_model_sort, ...@@ -1019,12 +1167,6 @@ gtk_tree_model_sort_build_level (GtkTreeModelSort *tree_model_sort,
i++; i++;
} }
while (gtk_tree_model_iter_next (tree_model_sort->child_model, &iter)); while (gtk_tree_model_iter_next (tree_model_sort->child_model, &iter));
sort_data.func = (GValueCompareFunc) gtk_tree_model_sort_get_func (tree_model_sort);
sort_data.model = tree_model_sort->child_model;
sort_data.sort_col = tree_model_sort->sort_col;
g_array_sort_with_data (children, gtk_tree_model_sort_func, &sort_data);
} }
static void static void
...@@ -1047,88 +1189,6 @@ gtk_tree_model_sort_free_level (GArray *array) ...@@ -1047,88 +1189,6 @@ gtk_tree_model_sort_free_level (GArray *array)
g_array_free (array, TRUE); g_array_free (array, TRUE);
} }
static GFunc
gtk_tree_model_sort_get_func (GtkTreeModelSort *tree_model_sort)
{
GValueCompareFunc func;
if (tree_model_sort->func)
func = tree_model_sort->func;
else
{
switch (gtk_tree_model_get_column_type (tree_model_sort->child_model,
tree_model_sort->sort_col))
{
case G_TYPE_STRING:
func = &g_value_string_compare_func;
break;
case G_TYPE_INT:
func = &g_value_int_compare_func;
break;
default:
g_warning ("No comparison function for row %d (Type %s)\n",
tree_model_sort->sort_col,
g_type_name (gtk_tree_model_get_column_type (tree_model_sort->child_model,
tree_model_sort->sort_col)));
return NULL;
}
}
return (GFunc) func;
}
static gint
gtk_tree_model_sort_func (gconstpointer a,
gconstpointer b,
gpointer user_data)
{
GValue value_a = {0, };
GValue value_b = {0, };
SortData *sort_data = user_data;
gboolean retval;
gtk_tree_model_get_value (sort_data->model, (GtkTreeIter *) a, sort_data->sort_col, &value_a);
gtk_tree_model_get_value (sort_data->model, (GtkTreeIter *) b, sort_data->sort_col, &value_b);
retval = (sort_data->func) (&value_a, &value_b);
g_value_unset (&value_a);
g_value_unset (&value_b);
return retval;
}
static gint
g_value_string_compare_func (const GValue *a,
const GValue *b)
{
gchar *a_str = g_value_get_string (a);
gchar *b_str = g_value_get_string (b);
if (b_str == NULL)
return a_str == NULL;
if (a_str == NULL)
return -1;
return strcmp (a_str, b_str);
}
static gint
g_value_int_compare_func (const GValue *a,
const GValue *b)
{
gint a_int = g_value_get_int (a);
gint b_int = g_value_get_int (b);
if (a_int < b_int)
return -1;
else if (a_int > b_int)
return 1;
else
return 0;
}
/* DEAD CODE */ /* DEAD CODE */
#if 0 #if 0
...@@ -1147,7 +1207,7 @@ g_value_int_compare_func (const GValue *a, ...@@ -1147,7 +1207,7 @@ g_value_int_compare_func (const GValue *a,
tmp_elt = &(g_array_index (array, SortElt, middle)); tmp_elt = &(g_array_index (array, SortElt, middle));
gtk_tree_model_get_value (sort->child_model, gtk_tree_model_get_value (sort->child_model,
(GtkTreeIter *) tmp_elt, (GtkTreeIter *) tmp_elt,
sort->sort_col, sort->sort_column_id,
&tmp_value); &tmp_value);
cmp = ((func) (&tmp_value, &s_value)); cmp = ((func) (&tmp_value, &s_value));
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#define __GTK_TREE_MODEL_SORT_H__ #define __GTK_TREE_MODEL_SORT_H__
#include <gtk/gtktreemodel.h> #include <gtk/gtktreemodel.h>
#include <gtk/gtktreesortable.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -48,9 +49,13 @@ struct _GtkTreeModelSort ...@@ -48,9 +49,13 @@ struct _GtkTreeModelSort
gint stamp; gint stamp;
guint flags; guint flags;
GtkTreeModel *child_model; GtkTreeModel *child_model;
gint sort_col;
GValueCompareFunc func;
/* sort information */
GList *sort_list;
gint sort_column_id;
GtkTreeSortOrder order;