summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Blandford <jrb@redhat.com>2001-09-03 23:37:39 +0000
committerJonathan Blandford <jrb@src.gnome.org>2001-09-03 23:37:39 +0000
commit43405a3d77249aed3357af092225dc74ff73aff5 (patch)
treee40f4d3afd45277f81770829c172fffbef5e03c3
parent8249e6275a27f6084eceafa93153b9ccb7d330e2 (diff)
downloadgtk+-43405a3d77249aed3357af092225dc74ff73aff5.tar.gz
handle default sort feature
Mon Sep 3 18:03:56 2001 Jonathan Blandford <jrb@redhat.com> * gtk/gtktreestore.c (gtk_tree_store_set_default_sort_func): handle default sort feature * gtk/gtktreesortable.c (gtk_tree_sortable_set_default_sort_func): new function to handle default sort. (gtk_tree_sortable_has_default_sort_func): check if default sort is set. * gtk/gtkliststore.c (gtk_list_store_set_default_sort_func): handle default sort feature
-rw-r--r--ChangeLog13
-rw-r--r--ChangeLog.pre-2-013
-rw-r--r--ChangeLog.pre-2-1013
-rw-r--r--ChangeLog.pre-2-213
-rw-r--r--ChangeLog.pre-2-413
-rw-r--r--ChangeLog.pre-2-613
-rw-r--r--ChangeLog.pre-2-813
-rw-r--r--gtk/gtkliststore.c177
-rw-r--r--gtk/gtkliststore.h3
-rw-r--r--gtk/gtktreesortable.c31
-rw-r--r--gtk/gtktreesortable.h79
-rw-r--r--gtk/gtktreestore.c163
-rw-r--r--gtk/gtktreestore.h3
13 files changed, 401 insertions, 146 deletions
diff --git a/ChangeLog b/ChangeLog
index e087da5853..accc02c058 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+Mon Sep 3 18:03:56 2001 Jonathan Blandford <jrb@redhat.com>
+
+ * gtk/gtktreestore.c (gtk_tree_store_set_default_sort_func):
+ handle default sort feature
+
+ * gtk/gtktreesortable.c (gtk_tree_sortable_set_default_sort_func):
+ new function to handle default sort.
+ (gtk_tree_sortable_has_default_sort_func): check if default sort
+ is set.
+
+ * gtk/gtkliststore.c (gtk_list_store_set_default_sort_func):
+ handle default sort feature
+
Sun Sep 2 20:32:36 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtktreeview.c (gtk_tree_view_scroll_to_cell): patch from
diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0
index e087da5853..accc02c058 100644
--- a/ChangeLog.pre-2-0
+++ b/ChangeLog.pre-2-0
@@ -1,3 +1,16 @@
+Mon Sep 3 18:03:56 2001 Jonathan Blandford <jrb@redhat.com>
+
+ * gtk/gtktreestore.c (gtk_tree_store_set_default_sort_func):
+ handle default sort feature
+
+ * gtk/gtktreesortable.c (gtk_tree_sortable_set_default_sort_func):
+ new function to handle default sort.
+ (gtk_tree_sortable_has_default_sort_func): check if default sort
+ is set.
+
+ * gtk/gtkliststore.c (gtk_list_store_set_default_sort_func):
+ handle default sort feature
+
Sun Sep 2 20:32:36 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtktreeview.c (gtk_tree_view_scroll_to_cell): patch from
diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10
index e087da5853..accc02c058 100644
--- a/ChangeLog.pre-2-10
+++ b/ChangeLog.pre-2-10
@@ -1,3 +1,16 @@
+Mon Sep 3 18:03:56 2001 Jonathan Blandford <jrb@redhat.com>
+
+ * gtk/gtktreestore.c (gtk_tree_store_set_default_sort_func):
+ handle default sort feature
+
+ * gtk/gtktreesortable.c (gtk_tree_sortable_set_default_sort_func):
+ new function to handle default sort.
+ (gtk_tree_sortable_has_default_sort_func): check if default sort
+ is set.
+
+ * gtk/gtkliststore.c (gtk_list_store_set_default_sort_func):
+ handle default sort feature
+
Sun Sep 2 20:32:36 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtktreeview.c (gtk_tree_view_scroll_to_cell): patch from
diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2
index e087da5853..accc02c058 100644
--- a/ChangeLog.pre-2-2
+++ b/ChangeLog.pre-2-2
@@ -1,3 +1,16 @@
+Mon Sep 3 18:03:56 2001 Jonathan Blandford <jrb@redhat.com>
+
+ * gtk/gtktreestore.c (gtk_tree_store_set_default_sort_func):
+ handle default sort feature
+
+ * gtk/gtktreesortable.c (gtk_tree_sortable_set_default_sort_func):
+ new function to handle default sort.
+ (gtk_tree_sortable_has_default_sort_func): check if default sort
+ is set.
+
+ * gtk/gtkliststore.c (gtk_list_store_set_default_sort_func):
+ handle default sort feature
+
Sun Sep 2 20:32:36 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtktreeview.c (gtk_tree_view_scroll_to_cell): patch from
diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4
index e087da5853..accc02c058 100644
--- a/ChangeLog.pre-2-4
+++ b/ChangeLog.pre-2-4
@@ -1,3 +1,16 @@
+Mon Sep 3 18:03:56 2001 Jonathan Blandford <jrb@redhat.com>
+
+ * gtk/gtktreestore.c (gtk_tree_store_set_default_sort_func):
+ handle default sort feature
+
+ * gtk/gtktreesortable.c (gtk_tree_sortable_set_default_sort_func):
+ new function to handle default sort.
+ (gtk_tree_sortable_has_default_sort_func): check if default sort
+ is set.
+
+ * gtk/gtkliststore.c (gtk_list_store_set_default_sort_func):
+ handle default sort feature
+
Sun Sep 2 20:32:36 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtktreeview.c (gtk_tree_view_scroll_to_cell): patch from
diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6
index e087da5853..accc02c058 100644
--- a/ChangeLog.pre-2-6
+++ b/ChangeLog.pre-2-6
@@ -1,3 +1,16 @@
+Mon Sep 3 18:03:56 2001 Jonathan Blandford <jrb@redhat.com>
+
+ * gtk/gtktreestore.c (gtk_tree_store_set_default_sort_func):
+ handle default sort feature
+
+ * gtk/gtktreesortable.c (gtk_tree_sortable_set_default_sort_func):
+ new function to handle default sort.
+ (gtk_tree_sortable_has_default_sort_func): check if default sort
+ is set.
+
+ * gtk/gtkliststore.c (gtk_list_store_set_default_sort_func):
+ handle default sort feature
+
Sun Sep 2 20:32:36 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtktreeview.c (gtk_tree_view_scroll_to_cell): patch from
diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8
index e087da5853..accc02c058 100644
--- a/ChangeLog.pre-2-8
+++ b/ChangeLog.pre-2-8
@@ -1,3 +1,16 @@
+Mon Sep 3 18:03:56 2001 Jonathan Blandford <jrb@redhat.com>
+
+ * gtk/gtktreestore.c (gtk_tree_store_set_default_sort_func):
+ handle default sort feature
+
+ * gtk/gtktreesortable.c (gtk_tree_sortable_set_default_sort_func):
+ new function to handle default sort.
+ (gtk_tree_sortable_has_default_sort_func): check if default sort
+ is set.
+
+ * gtk/gtkliststore.c (gtk_list_store_set_default_sort_func):
+ handle default sort feature
+
Sun Sep 2 20:32:36 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtktreeview.c (gtk_tree_view_scroll_to_cell): patch from
diff --git a/gtk/gtkliststore.c b/gtk/gtkliststore.c
index 8fba27a26f..0c3f06b197 100644
--- a/gtk/gtkliststore.c
+++ b/gtk/gtkliststore.c
@@ -89,21 +89,27 @@ static gboolean gtk_list_store_row_drop_possible (GtkTreeDragDest *drag_dest,
/* sortable */
-static void gtk_list_store_sort (GtkListStore *list_store);
-static void gtk_list_store_sort_iter_changed (GtkListStore *list_store,
- GtkTreeIter *iter,
- gint column);
-static gboolean gtk_list_store_get_sort_column_id (GtkTreeSortable *sortable,
- gint *sort_column_id,
- GtkSortType *order);
-static void gtk_list_store_set_sort_column_id (GtkTreeSortable *sortable,
- gint sort_column_id,
- GtkSortType order);
-static void gtk_list_store_set_sort_func (GtkTreeSortable *sortable,
- gint sort_column_id,
- GtkTreeIterCompareFunc func,
- gpointer data,
- GtkDestroyNotify destroy);
+static void gtk_list_store_sort (GtkListStore *list_store);
+static void gtk_list_store_sort_iter_changed (GtkListStore *list_store,
+ GtkTreeIter *iter,
+ gint column);
+static gboolean gtk_list_store_get_sort_column_id (GtkTreeSortable *sortable,
+ gint *sort_column_id,
+ GtkSortType *order);
+static void gtk_list_store_set_sort_column_id (GtkTreeSortable *sortable,
+ gint sort_column_id,
+ GtkSortType order);
+static void gtk_list_store_set_sort_func (GtkTreeSortable *sortable,
+ gint sort_column_id,
+ GtkTreeIterCompareFunc func,
+ gpointer data,
+ GtkDestroyNotify destroy);
+static void gtk_list_store_set_default_sort_func (GtkTreeSortable *sortable,
+ GtkTreeIterCompareFunc func,
+ gpointer data,
+ GtkDestroyNotify destroy);
+static gboolean gtk_list_store_has_default_sort_func (GtkTreeSortable *sortable);
+
static void
@@ -228,6 +234,8 @@ gtk_list_store_sortable_init (GtkTreeSortableIface *iface)
iface->get_sort_column_id = gtk_list_store_get_sort_column_id;
iface->set_sort_column_id = gtk_list_store_set_sort_column_id;
iface->set_sort_func = gtk_list_store_set_sort_func;
+ iface->set_default_sort_func = gtk_list_store_set_default_sort_func;
+ iface->has_default_sort_func = gtk_list_store_has_default_sort_func;
}
static void
@@ -1366,18 +1374,33 @@ gtk_list_store_compare_func (gconstpointer a,
gpointer user_data)
{
GtkListStore *list_store = user_data;
- GtkTreeDataSortHeader *header = NULL;
GSList *el_a; /* Los Angeles? */
GSList *el_b;
GtkTreeIter iter_a;
GtkTreeIter iter_b;
gint retval;
+ GtkTreeIterCompareFunc func;
+ gpointer data;
- header = _gtk_tree_data_list_get_header (list_store->sort_list,
- list_store->sort_column_id);
- g_return_val_if_fail (header != NULL, 0);
- g_return_val_if_fail (header->func != NULL, 0);
+ if (list_store->sort_column_id != -1)
+ {
+ GtkTreeDataSortHeader *header;
+
+ header = _gtk_tree_data_list_get_header (list_store->sort_list,
+ list_store->sort_column_id);
+ g_return_val_if_fail (header != NULL, 0);
+ g_return_val_if_fail (header->func != NULL, 0);
+
+ func = header->func;
+ data = header->data;
+ }
+ else
+ {
+ g_return_val_if_fail (list_store->default_sort_func != NULL, 0);
+ func = list_store->default_sort_func;
+ data = list_store->default_sort_data;
+ }
el_a = ((SortTuple *) a)->el;
el_b = ((SortTuple *) b)->el;
@@ -1387,9 +1410,7 @@ gtk_list_store_compare_func (gconstpointer a,
iter_b.stamp = list_store->stamp;
iter_b.user_data = el_b;
- retval = (* header->func) (GTK_TREE_MODEL (list_store),
- &iter_a, &iter_b,
- header->data);
+ retval = (* func) (GTK_TREE_MODEL (list_store), &iter_a, &iter_b, data);
if (list_store->order == GTK_SORT_DESCENDING)
{
@@ -1404,7 +1425,6 @@ gtk_list_store_compare_func (gconstpointer a,
static void
gtk_list_store_sort (GtkListStore *list_store)
{
- GtkTreeDataSortHeader *header = NULL;
GtkTreeIter iter;
GArray *sort_array;
gint i;
@@ -1417,12 +1437,6 @@ gtk_list_store_sort (GtkListStore *list_store)
g_assert (GTK_LIST_STORE_IS_SORTED (list_store));
- header = _gtk_tree_data_list_get_header (list_store->sort_list, list_store->sort_column_id);
-
- /* We want to make sure that we have a function */
- g_return_if_fail (header != NULL);
- g_return_if_fail (header->func != NULL);
-
list = G_SLIST (list_store->root);
sort_array = g_array_sized_new (FALSE, FALSE,
@@ -1471,7 +1485,6 @@ gtk_list_store_sort_iter_changed (GtkListStore *list_store,
gint column)
{
- GtkTreeDataSortHeader *header;
GSList *prev = NULL;
GSList *next = NULL;
GSList *list = G_SLIST (list_store->root);
@@ -1483,18 +1496,33 @@ gtk_list_store_sort_iter_changed (GtkListStore *list_store,
gint old_location;
gint new_location;
gint *new_order;
+ GtkTreeIterCompareFunc func;
+ gpointer data;
if (list_store->length < 2)
return;
tmp_iter.stamp = list_store->stamp;
- header = _gtk_tree_data_list_get_header (list_store->sort_list,
- list_store->sort_column_id);
- g_return_if_fail (header != NULL);
- g_return_if_fail (header->func != NULL);
+
+ if (list_store->sort_column_id != -1)
+ {
+ GtkTreeDataSortHeader *header;
+ header = _gtk_tree_data_list_get_header (list_store->sort_list,
+ list_store->sort_column_id);
+ g_return_if_fail (header != NULL);
+ g_return_if_fail (header->func != NULL);
+ func = header->func;
+ data = header->data;
+ }
+ else
+ {
+ g_return_if_fail (list_store->default_sort_func != NULL);
+ func = list_store->default_sort_func;
+ data = list_store->default_sort_data;
+ }
/* If it's the built in function, we don't sort. */
- if (header->func == gtk_tree_data_list_compare_func &&
+ if (func == gtk_tree_data_list_compare_func &&
list_store->sort_column_id != column)
return;
@@ -1516,17 +1544,13 @@ gtk_list_store_sort_iter_changed (GtkListStore *list_store,
if (prev != NULL)
{
tmp_iter.user_data = prev;
- cmp_a = (* header->func) (GTK_TREE_MODEL (list_store),
- &tmp_iter, iter,
- header->data);
+ cmp_a = (* func) (GTK_TREE_MODEL (list_store), &tmp_iter, iter, data);
}
if (next != NULL)
{
tmp_iter.user_data = next;
- cmp_b = (* header->func) (GTK_TREE_MODEL (list_store),
- iter, &tmp_iter,
- header->data);
+ cmp_b = (* func) (GTK_TREE_MODEL (list_store), iter, &tmp_iter, data);
}
@@ -1568,11 +1592,9 @@ gtk_list_store_sort_iter_changed (GtkListStore *list_store,
new_location = 0;
tmp_iter.user_data = list;
if (list_store->order == GTK_SORT_DESCENDING)
- cmp_a = (* header->func) (GTK_TREE_MODEL (list_store),
- &tmp_iter, iter, header->data);
+ cmp_a = (* func) (GTK_TREE_MODEL (list_store), &tmp_iter, iter, data);
else
- cmp_a = (* header->func) (GTK_TREE_MODEL (list_store),
- iter, &tmp_iter, header->data);
+ cmp_a = (* func) (GTK_TREE_MODEL (list_store), iter, &tmp_iter, data);
while ((list->next) && (cmp_a > 0))
{
@@ -1581,11 +1603,9 @@ gtk_list_store_sort_iter_changed (GtkListStore *list_store,
new_location++;
tmp_iter.user_data = list;
if (list_store->order == GTK_SORT_DESCENDING)
- cmp_a = (* header->func) (GTK_TREE_MODEL (list_store),
- &tmp_iter, iter, header->data);
+ cmp_a = (* func) (GTK_TREE_MODEL (list_store), &tmp_iter, iter, data);
else
- cmp_a = (* header->func) (GTK_TREE_MODEL (list_store),
- iter, &tmp_iter, header->data);
+ cmp_a = (* func) (GTK_TREE_MODEL (list_store), iter, &tmp_iter, data);
}
if ((!list->next) && (cmp_a > 0))
@@ -1667,27 +1687,33 @@ gtk_list_store_set_sort_column_id (GtkTreeSortable *sortable,
GtkSortType order)
{
GtkListStore *list_store = (GtkListStore *) sortable;
- GList *list;
g_return_if_fail (GTK_IS_LIST_STORE (sortable));
- for (list = list_store->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 ((list_store->sort_column_id == sort_column_id) &&
(list_store->order == order))
return;
+ if (sort_column_id != -1)
+ {
+ GtkTreeDataSortHeader *header = NULL;
+
+ header = _gtk_tree_data_list_get_header (list_store->sort_list, sort_column_id);
+
+ /* We want to make sure that we have a function */
+ g_return_if_fail (header != NULL);
+ g_return_if_fail (header->func != NULL);
+ }
+ else
+ {
+ g_return_if_fail (list_store->default_sort_func != NULL);
+ }
+
+
list_store->sort_column_id = sort_column_id;
list_store->order = order;
- if (list_store->sort_column_id >= 0)
- gtk_list_store_sort (list_store);
+ gtk_list_store_sort (list_store);
gtk_tree_sortable_sort_column_changed (sortable);
}
@@ -1727,3 +1753,32 @@ gtk_list_store_set_sort_func (GtkTreeSortable *sortable,
header->data = data;
header->destroy = destroy;
}
+
+
+static void
+gtk_list_store_set_default_sort_func (GtkTreeSortable *sortable,
+ GtkTreeIterCompareFunc func,
+ gpointer data,
+ GtkDestroyNotify destroy)
+{
+ GtkListStore *list_store = (GtkListStore *) sortable;
+
+ g_return_if_fail (GTK_IS_LIST_STORE (sortable));
+
+ if (list_store->default_sort_destroy)
+ (* list_store->default_sort_destroy) (list_store->default_sort_data);
+
+ list_store->default_sort_func = func;
+ list_store->default_sort_data = data;
+ list_store->default_sort_destroy = destroy;
+}
+
+static gboolean
+gtk_list_store_has_default_sort_func (GtkTreeSortable *sortable)
+{
+ GtkListStore *list_store = (GtkListStore *) sortable;
+
+ g_return_val_if_fail (GTK_IS_LIST_STORE (sortable), FALSE);
+
+ return (list_store->default_sort_func != NULL);
+}
diff --git a/gtk/gtkliststore.h b/gtk/gtkliststore.h
index b3c550857c..6549087c89 100644
--- a/gtk/gtkliststore.h
+++ b/gtk/gtkliststore.h
@@ -51,6 +51,9 @@ struct _GtkListStore
GtkSortType order;
GType *column_headers;
gint length;
+ GtkTreeIterCompareFunc default_sort_func;
+ gpointer default_sort_data;
+ GtkDestroyNotify default_sort_destroy;
};
struct _GtkListStoreClass
diff --git a/gtk/gtktreesortable.c b/gtk/gtktreesortable.c
index e5cf6f088e..97a52c10e9 100644
--- a/gtk/gtktreesortable.c
+++ b/gtk/gtktreesortable.c
@@ -130,4 +130,35 @@ gtk_tree_sortable_set_sort_func (GtkTreeSortable *sortable,
(* iface->set_sort_func) (sortable, sort_column_id, func, data, destroy);
}
+void
+gtk_tree_sortable_set_default_sort_func (GtkTreeSortable *sortable,
+ GtkTreeIterCompareFunc func,
+ gpointer data,
+ GtkDestroyNotify destroy)
+{
+ GtkTreeSortableIface *iface;
+
+ g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
+
+ iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
+
+ g_return_if_fail (iface != NULL);
+ g_return_if_fail (iface->set_default_sort_func != NULL);
+
+ (* iface->set_default_sort_func) (sortable, func, data, destroy);
+}
+gboolean
+gtk_tree_sortable_has_default_sort_func (GtkTreeSortable *sortable)
+{
+ GtkTreeSortableIface *iface;
+
+ g_return_if_fail (GTK_IS_TREE_SORTABLE (sortable));
+
+ iface = GTK_TREE_SORTABLE_GET_IFACE (sortable);
+
+ g_return_if_fail (iface != NULL);
+ g_return_if_fail (iface->has_default_sort_func != NULL);
+
+ (* iface->has_default_sort_func) (sortable);
+}
diff --git a/gtk/gtktreesortable.h b/gtk/gtktreesortable.h
index 6c94f1cadd..d41c7f957f 100644
--- a/gtk/gtktreesortable.h
+++ b/gtk/gtktreesortable.h
@@ -22,9 +22,7 @@
#include <gtk/gtktreemodel.h>
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
+G_BEGIN_DECLS
#define GTK_TYPE_TREE_SORTABLE (gtk_tree_sortable_get_type ())
#define GTK_TREE_SORTABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_TREE_SORTABLE, GtkTreeSortable))
@@ -32,6 +30,9 @@ extern "C" {
#define GTK_IS_TREE_SORTABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_TREE_SORTABLE))
#define GTK_TREE_SORTABLE_GET_IFACE(obj) ((GtkTreeSortableIface *)g_type_interface_peek (((GTypeInstance *)GTK_TREE_SORTABLE (obj))->g_class, GTK_TYPE_TREE_SORTABLE))
+enum {
+ GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID = -1,
+};
typedef struct _GtkTreeSortable GtkTreeSortable; /* Dummy typedef */
typedef struct _GtkTreeSortableIface GtkTreeSortableIface;
@@ -47,43 +48,49 @@ struct _GtkTreeSortableIface
GTypeInterface g_iface;
/* signals */
- void (* sort_column_changed) (GtkTreeSortable *sortable);
+ void (* sort_column_changed) (GtkTreeSortable *sortable);
/* virtual table */
- gboolean (* get_sort_column_id) (GtkTreeSortable *sortable,
- gint *sort_column_id,
- GtkSortType *order);
- void (* set_sort_column_id) (GtkTreeSortable *sortable,
- gint sort_column_id,
- GtkSortType order);
- void (* set_sort_func) (GtkTreeSortable *sortable,
- gint sort_column_id,
- GtkTreeIterCompareFunc func,
- gpointer data,
- GtkDestroyNotify destroy);
+ gboolean (* get_sort_column_id) (GtkTreeSortable *sortable,
+ gint *sort_column_id,
+ GtkSortType *order);
+ void (* set_sort_column_id) (GtkTreeSortable *sortable,
+ gint sort_column_id,
+ GtkSortType order);
+ void (* set_sort_func) (GtkTreeSortable *sortable,
+ gint sort_column_id,
+ GtkTreeIterCompareFunc func,
+ gpointer data,
+ GtkDestroyNotify destroy);
+ void (* set_default_sort_func) (GtkTreeSortable *sortable,
+ GtkTreeIterCompareFunc func,
+ gpointer data,
+ GtkDestroyNotify destroy);
+ gboolean (* has_default_sort_func) (GtkTreeSortable *sortable);
};
-GType gtk_tree_sortable_get_type (void) G_GNUC_CONST;
-
-void gtk_tree_sortable_sort_column_changed (GtkTreeSortable *sortable);
-gboolean gtk_tree_sortable_get_sort_column_id (GtkTreeSortable *sortable,
- gint *sort_column_id,
- GtkSortType *order);
-void gtk_tree_sortable_set_sort_column_id (GtkTreeSortable *sortable,
- gint sort_column_id,
- GtkSortType order);
-void gtk_tree_sortable_set_sort_func (GtkTreeSortable *sortable,
- gint sort_column_id,
- GtkTreeIterCompareFunc func,
- gpointer data,
- GtkDestroyNotify destroy);
-
-
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
+GType gtk_tree_sortable_get_type (void) G_GNUC_CONST;
+
+void gtk_tree_sortable_sort_column_changed (GtkTreeSortable *sortable);
+gboolean gtk_tree_sortable_get_sort_column_id (GtkTreeSortable *sortable,
+ gint *sort_column_id,
+ GtkSortType *order);
+void gtk_tree_sortable_set_sort_column_id (GtkTreeSortable *sortable,
+ gint sort_column_id,
+ GtkSortType order);
+void gtk_tree_sortable_set_sort_func (GtkTreeSortable *sortable,
+ gint sort_column_id,
+ GtkTreeIterCompareFunc func,
+ gpointer data,
+ GtkDestroyNotify destroy);
+void gtk_tree_sortable_set_default_sort_func (GtkTreeSortable *sortable,
+ GtkTreeIterCompareFunc func,
+ gpointer data,
+ GtkDestroyNotify destroy);
+gboolean gtk_tree_sortable_has_default_sort_func (GtkTreeSortable *sortable);
+
+
+G_END_DECLS
#endif /* __GTK_TREE_SORTABLE_H__ */
diff --git a/gtk/gtktreestore.c b/gtk/gtktreestore.c
index 1f678d659f..cd56957e28 100644
--- a/gtk/gtktreestore.c
+++ b/gtk/gtktreestore.c
@@ -98,12 +98,16 @@ static gboolean gtk_tree_store_get_sort_column_id (GtkTreeSortable *
static void gtk_tree_store_set_sort_column_id (GtkTreeSortable *sortable,
gint sort_column_id,
GtkSortType order);
-static void gtk_tree_store_set_sort_func (GtkTreeSortable *sortable,
+static void gtk_tree_store_set_sort_func (GtkTreeSortable *sortable,
gint sort_column_id,
GtkTreeIterCompareFunc func,
gpointer data,
GtkDestroyNotify destroy);
-
+static void gtk_tree_store_set_default_sort_func (GtkTreeSortable *sortable,
+ GtkTreeIterCompareFunc func,
+ gpointer data,
+ GtkDestroyNotify destroy);
+static gboolean gtk_tree_store_has_default_sort_func (GtkTreeSortable *sortable);
static void validate_gnode (GNode *node);
@@ -232,6 +236,8 @@ gtk_tree_store_sortable_init (GtkTreeSortableIface *iface)
iface->get_sort_column_id = gtk_tree_store_get_sort_column_id;
iface->set_sort_column_id = gtk_tree_store_set_sort_column_id;
iface->set_sort_func = gtk_tree_store_set_sort_func;
+ iface->set_default_sort_func = gtk_tree_store_set_default_sort_func;
+ iface->has_default_sort_func = gtk_tree_store_has_default_sort_func;
}
static void
@@ -1465,18 +1471,33 @@ gtk_tree_store_compare_func (gconstpointer a,
gpointer user_data)
{
GtkTreeStore *tree_store = user_data;
- GtkTreeDataSortHeader *header = NULL;
GNode *node_a;
GNode *node_b;
+ GtkTreeIterCompareFunc func;
+ gpointer data;
+
GtkTreeIter iter_a;
GtkTreeIter iter_b;
gint retval;
- header = _gtk_tree_data_list_get_header (tree_store->sort_list,
- tree_store->sort_column_id);
+ if (tree_store->sort_column_id != -1)
+ {
+ GtkTreeDataSortHeader *header;
+
+ header = _gtk_tree_data_list_get_header (tree_store->sort_list,
+ tree_store->sort_column_id);
+ g_return_val_if_fail (header != NULL, 0);
+ g_return_val_if_fail (header->func != NULL, 0);
- g_return_val_if_fail (header != NULL, 0);
- g_return_val_if_fail (header->func != NULL, 0);
+ func = header->func;
+ data = header->data;
+ }
+ else
+ {
+ g_return_val_if_fail (tree_store->default_sort_func != NULL, 0);
+ func = tree_store->default_sort_func;
+ data = tree_store->default_sort_data;
+ }
node_a = ((SortTuple *) a)->node;
node_b = ((SortTuple *) b)->node;
@@ -1486,9 +1507,7 @@ gtk_tree_store_compare_func (gconstpointer a,
iter_b.stamp = tree_store->stamp;
iter_b.user_data = node_b;
- retval = (* header->func) (GTK_TREE_MODEL (user_data),
- &iter_a, &iter_b,
- header->data);
+ retval = (* func) (GTK_TREE_MODEL (user_data), &iter_a, &iter_b, data);
if (tree_store->order == GTK_SORT_DESCENDING)
{
@@ -1505,7 +1524,6 @@ gtk_tree_store_sort_helper (GtkTreeStore *tree_store,
GNode *parent,
gboolean recurse)
{
- GtkTreeDataSortHeader *header = NULL;
GtkTreeIter iter;
GArray *sort_array;
GNode *node;
@@ -1521,12 +1539,6 @@ gtk_tree_store_sort_helper (GtkTreeStore *tree_store,
g_assert (GTK_TREE_STORE_IS_SORTED (tree_store));
- header = _gtk_tree_data_list_get_header (tree_store->sort_list, tree_store->sort_column_id);
-
- /* We want to make sure that we have a function */
- g_return_if_fail (header != NULL);
- g_return_if_fail (header->func != NULL);
-
list_length = 0;
for (tmp_node = node; tmp_node; tmp_node = tmp_node->next)
list_length++;
@@ -1584,6 +1596,21 @@ gtk_tree_store_sort_helper (GtkTreeStore *tree_store,
static void
gtk_tree_store_sort (GtkTreeStore *tree_store)
{
+ if (tree_store->sort_column_id != -1)
+ {
+ GtkTreeDataSortHeader *header = NULL;
+
+ header = _gtk_tree_data_list_get_header (tree_store->sort_list, tree_store->sort_column_id);
+
+ /* We want to make sure that we have a function */
+ g_return_if_fail (header != NULL);
+ g_return_if_fail (header->func != NULL);
+ }
+ else
+ {
+ g_return_if_fail (tree_store->default_sort_func != NULL);
+ }
+
gtk_tree_store_sort_helper (tree_store, G_NODE (tree_store->root), TRUE);
}
@@ -1592,7 +1619,6 @@ gtk_tree_store_sort_iter_changed (GtkTreeStore *tree_store,
GtkTreeIter *iter,
gint column)
{
- GtkTreeDataSortHeader *header;
GNode *prev = NULL;
GNode *next = NULL;
GNode *node;
@@ -1605,18 +1631,31 @@ gtk_tree_store_sort_iter_changed (GtkTreeStore *tree_store,
gint new_location;
gint *new_order;
gint length;
+ GtkTreeIterCompareFunc func;
+ gpointer data;
g_return_if_fail (G_NODE (iter->user_data)->parent != NULL);
-
tmp_iter.stamp = tree_store->stamp;
- header = _gtk_tree_data_list_get_header (tree_store->sort_list,
- tree_store->sort_column_id);
- g_return_if_fail (header != NULL);
- g_return_if_fail (header->func != NULL);
+ if (tree_store->sort_column_id != -1)
+ {
+ GtkTreeDataSortHeader *header;
+ header = _gtk_tree_data_list_get_header (tree_store->sort_list,
+ tree_store->sort_column_id);
+ g_return_if_fail (header != NULL);
+ g_return_if_fail (header->func != NULL);
+ func = header->func;
+ data = header->data;
+ }
+ else
+ {
+ g_return_if_fail (tree_store->default_sort_func != NULL);
+ func = tree_store->default_sort_func;
+ data = tree_store->default_sort_data;
+ }
/* If it's the built in function, we don't sort. */
- if (header->func == gtk_tree_data_list_compare_func &&
+ if (func == gtk_tree_data_list_compare_func &&
tree_store->sort_column_id != column)
return;
@@ -1639,17 +1678,13 @@ gtk_tree_store_sort_iter_changed (GtkTreeStore *tree_store,
if (prev != NULL)
{
tmp_iter.user_data = prev;
- cmp_a = (* header->func) (GTK_TREE_MODEL (tree_store),
- &tmp_iter, iter,
- header->data);
+ cmp_a = (* func) (GTK_TREE_MODEL (tree_store), &tmp_iter, iter, data);
}
if (next != NULL)
{
tmp_iter.user_data = next;
- cmp_b = (* header->func) (GTK_TREE_MODEL (tree_store),
- iter, &tmp_iter,
- header->data);
+ cmp_b = (* func) (GTK_TREE_MODEL (tree_store), iter, &tmp_iter, data);
}
@@ -1693,11 +1728,9 @@ gtk_tree_store_sort_iter_changed (GtkTreeStore *tree_store,
new_location = 0;
tmp_iter.user_data = node;
if (tree_store->order == GTK_SORT_DESCENDING)
- cmp_a = (* header->func) (GTK_TREE_MODEL (tree_store),
- &tmp_iter, iter, header->data);
+ cmp_a = (* func) (GTK_TREE_MODEL (tree_store), &tmp_iter, iter, data);
else
- cmp_a = (* header->func) (GTK_TREE_MODEL (tree_store),
- iter, &tmp_iter, header->data);
+ cmp_a = (* func) (GTK_TREE_MODEL (tree_store), iter, &tmp_iter, data);
while ((node->next) && (cmp_a > 0))
{
@@ -1706,11 +1739,9 @@ gtk_tree_store_sort_iter_changed (GtkTreeStore *tree_store,
new_location++;
tmp_iter.user_data = node;
if (tree_store->order == GTK_SORT_DESCENDING)
- cmp_a = (* header->func) (GTK_TREE_MODEL (tree_store),
- &tmp_iter, iter, header->data);
+ cmp_a = (* func) (GTK_TREE_MODEL (tree_store), &tmp_iter, iter, data);
else
- cmp_a = (* header->func) (GTK_TREE_MODEL (tree_store),
- iter, &tmp_iter, header->data);
+ cmp_a = (* func) (GTK_TREE_MODEL (tree_store), iter, &tmp_iter, data);
}
if ((!node->next) && (cmp_a > 0))
@@ -1797,27 +1828,33 @@ gtk_tree_store_set_sort_column_id (GtkTreeSortable *sortable,
GtkSortType order)
{
GtkTreeStore *tree_store = (GtkTreeStore *) sortable;
- GList *list;
g_return_if_fail (GTK_IS_TREE_STORE (sortable));
- for (list = tree_store->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_store->sort_column_id == sort_column_id) &&
(tree_store->order == order))
return;
+ if (sort_column_id != -1)
+ {
+ GtkTreeDataSortHeader *header = NULL;
+
+ header = _gtk_tree_data_list_get_header (tree_store->sort_list, sort_column_id);
+
+ /* We want to make sure that we have a function */
+ g_return_if_fail (header != NULL);
+ g_return_if_fail (header->func != NULL);
+ }
+ else
+ {
+ g_return_if_fail (tree_store->default_sort_func != NULL);
+ }
+
tree_store->sort_column_id = sort_column_id;
tree_store->order = order;
- if (tree_store->sort_column_id >= 0)
- gtk_tree_store_sort (tree_store);
+ gtk_tree_store_sort (tree_store);
gtk_tree_sortable_sort_column_changed (sortable);
}
@@ -1860,6 +1897,34 @@ gtk_tree_store_set_sort_func (GtkTreeSortable *sortable,
}
static void
+gtk_tree_store_set_default_sort_func (GtkTreeSortable *sortable,
+ GtkTreeIterCompareFunc func,
+ gpointer data,
+ GtkDestroyNotify destroy)
+{
+ GtkTreeStore *tree_store = (GtkTreeStore *) sortable;
+
+ g_return_if_fail (GTK_IS_TREE_STORE (sortable));
+
+ if (tree_store->default_sort_destroy)
+ (* tree_store->default_sort_destroy) (tree_store->default_sort_data);
+
+ tree_store->default_sort_func = func;
+ tree_store->default_sort_data = data;
+ tree_store->default_sort_destroy = destroy;
+}
+
+static gboolean
+gtk_tree_store_has_default_sort_func (GtkTreeSortable *sortable)
+{
+ GtkTreeStore *tree_store = (GtkTreeStore *) sortable;
+
+ g_return_val_if_fail (GTK_IS_TREE_STORE (sortable), FALSE);
+
+ return (tree_store->default_sort_func != NULL);
+}
+
+static void
validate_gnode (GNode* node)
{
GNode *iter;
diff --git a/gtk/gtktreestore.h b/gtk/gtktreestore.h
index fd2d8da742..508a4c2867 100644
--- a/gtk/gtktreestore.h
+++ b/gtk/gtktreestore.h
@@ -50,6 +50,9 @@ struct _GtkTreeStore
GList *sort_list;
GtkSortType order;
GType *column_headers;
+ GtkTreeIterCompareFunc default_sort_func;
+ gpointer default_sort_data;
+ GtkDestroyNotify default_sort_destroy;
};
struct _GtkTreeStoreClass