Commit 88bbc2a5 authored by Jonathan Blandford's avatar Jonathan Blandford Committed by Jonathan Blandford

More work on implementing sortable interface.

Tue Mar 27 20:55:29 2001  Jonathan Blandford  <jrb@redhat.com>

	* gtk/gtkliststore.c: More work on implementing sortable
	interface.
parent 2c613ffd
Tue Mar 27 20:55:29 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtkliststore.c: More work on implementing sortable
interface.
Mon Mar 26 15:48:45 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwindow.c (gtk_window_list_toplevels): Don't
......
Tue Mar 27 20:55:29 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtkliststore.c: More work on implementing sortable
interface.
Mon Mar 26 15:48:45 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwindow.c (gtk_window_list_toplevels): Don't
......
Tue Mar 27 20:55:29 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtkliststore.c: More work on implementing sortable
interface.
Mon Mar 26 15:48:45 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwindow.c (gtk_window_list_toplevels): Don't
......
Tue Mar 27 20:55:29 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtkliststore.c: More work on implementing sortable
interface.
Mon Mar 26 15:48:45 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwindow.c (gtk_window_list_toplevels): Don't
......
Tue Mar 27 20:55:29 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtkliststore.c: More work on implementing sortable
interface.
Mon Mar 26 15:48:45 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwindow.c (gtk_window_list_toplevels): Don't
......
Tue Mar 27 20:55:29 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtkliststore.c: More work on implementing sortable
interface.
Mon Mar 26 15:48:45 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwindow.c (gtk_window_list_toplevels): Don't
......
Tue Mar 27 20:55:29 2001 Jonathan Blandford <jrb@redhat.com>
* gtk/gtkliststore.c: More work on implementing sortable
interface.
Mon Mar 26 15:48:45 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkwindow.c (gtk_window_list_toplevels): Don't
......
......@@ -34,7 +34,6 @@ GtkTreeViewColumn
@alignment:
@window:
@xalign:
@id:
@width:
@min_width:
@max_width:
......@@ -46,6 +45,8 @@ GtkTreeViewColumn
@cell:
@attributes:
@column_type:
@sort_signal:
@sort_column_id:
@sort_order:
@visible:
@button_active:
......
This diff is collapsed.
......@@ -38,6 +38,7 @@ NONE:STRING,INT,POINTER
VOID:BOOLEAN
VOID:BOXED
VOID:BOXED,BOXED
VOID:BOXED,BOXED,POINTER
VOID:BOXED,POINTER
VOID:BOXED,OBJECT
VOID:BOXED,STRING,INT
......
......@@ -38,6 +38,7 @@ NONE:STRING,INT,POINTER
VOID:BOOLEAN
VOID:BOXED
VOID:BOXED,BOXED
VOID:BOXED,BOXED,POINTER
VOID:BOXED,POINTER
VOID:BOXED,OBJECT
VOID:BOXED,STRING,INT
......
......@@ -264,7 +264,8 @@ gtk_tree_data_list_compare_func (GtkTreeModel *model,
GValue a_value = {0, };
GValue b_value = {0, };
gint retval;
gchar *stra, *strb;
gtk_tree_model_get_value (model, a, column, &a_value);
gtk_tree_model_get_value (model, b, column, &b_value);
......@@ -299,7 +300,13 @@ gtk_tree_data_list_compare_func (GtkTreeModel *model,
retval = (g_value_get_double (&a_value) < g_value_get_double (&b_value));
break;
case G_TYPE_STRING:
retval = strcmp (g_value_get_string (&a_value), g_value_get_string (&b_value));
stra = g_value_get_string (&a_value);
strb = g_value_get_string (&b_value);
if (stra == NULL)
stra = "";
if (strb == NULL)
strb = "";
retval = strcmp (stra, strb);
break;
case G_TYPE_POINTER:
case G_TYPE_BOXED:
......@@ -356,3 +363,18 @@ _gtk_tree_data_list_header_free (GList *list)
}
g_list_free (list);
}
GtkTreeDataSortHeader *
_gtk_tree_data_list_get_header (GList *header_list,
gint sort_column_id)
{
GtkTreeDataSortHeader *header = NULL;
for (; header_list; header_list = header_list->next)
{
header = (GtkTreeDataSortHeader*) header_list->data;
if (header->sort_column_id == sort_column_id)
return header;
}
return NULL;
}
......@@ -63,8 +63,11 @@ GtkTreeDataList *_gtk_tree_data_list_node_copy (GtkTreeDataList *list,
GType type);
/* Header code */
GList *_gtk_tree_data_list_header_new (gint n_columns,
GType *types);
void _gtk_tree_data_list_header_free (GList *header_list);
GList * _gtk_tree_data_list_header_new (gint n_columns,
GType *types);
void _gtk_tree_data_list_header_free (GList *header_list);
GtkTreeDataSortHeader *_gtk_tree_data_list_get_header (GList *header_list,
gint sort_column_id);
#endif /* __GTK_TREE_DATA_LIST_H__ */
......@@ -112,9 +112,10 @@ gtk_tree_model_base_init (gpointer g_class)
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkTreeModelIface, reordered),
NULL, NULL,
gtk_marshal_VOID__BOXED_POINTER,
G_TYPE_NONE, 2,
gtk_marshal_VOID__BOXED_BOXED_POINTER,
G_TYPE_NONE, 3,
GTK_TYPE_TREE_PATH,
GTK_TYPE_TREE_ITER,
G_TYPE_POINTER);
initialized = TRUE;
}
......
......@@ -69,6 +69,7 @@ struct _GtkTreeModelIface
GtkTreePath *path);
void (* reordered) (GtkTreeModel *tree_model,
GtkTreePath *path,
GtkTreeIter *iter,
gint *new_order);
/* Virtual Table */
......@@ -219,6 +220,7 @@ void gtk_tree_model_deleted (GtkTreeModel *tree_model,
GtkTreePath *path);
void gtk_tree_model_reordered (GtkTreeModel *tree_model,
GtkTreePath *path,
GtkTreeIter *iter,
gint *new_order);
......
......@@ -28,7 +28,6 @@ extern "C" {
typedef enum
{
GTK_TREE_SORT_NONE,
GTK_TREE_SORT_ASCENDING,
GTK_TREE_SORT_DESCENDING
} GtkTreeSortOrder;
......@@ -71,19 +70,20 @@ struct _GtkTreeSortableIface
};
GType gtk_tree_sortable_get_type (void) G_GNUC_CONST;
GType gtk_tree_sortable_get_type (void) G_GNUC_CONST;
gboolean gtk_tree_sortable_get_sort_column_id (GtkTreeSortable *sortable,
gint *sort_column_id,
GtkTreeSortOrder *order);
void gtk_tree_sortable_set_sort_column_id (GtkTreeSortable *sortable,
gint sort_column_id,
GtkTreeSortOrder order);
void gtk_tree_sortable_sort_column_id_set_func (GtkTreeSortable *sortable,
gint sort_column_id,
GtkTreeIterCompareFunc func,
gpointer data,
GtkDestroyNotify destroy);
gboolean gtk_tree_sortable_get_sort_id (GtkTreeSortable *sortable,
gint *sort_column_id,
GtkTreeSortOrder *order);
void gtk_tree_sortable_set_sort_id (GtkTreeSortable *sortable,
gint sort_column_id,
GtkTreeSortOrder order);
void gtk_tree_sortable_sort_id_set_func (GtkTreeSortable *sortable,
gint sort_column_id,
GtkTreeIterCompareFunc func,
gpointer data,
GtkDestroyNotify destroy);
......
......@@ -3011,6 +3011,17 @@ gtk_tree_view_reordered (GtkTreeModel *model,
GtkTreePath *parent,
gint *new_order)
{
GtkTreeView *tree_view = GTK_TREE_VIEW (model);
GtkTreeIter iter;
GArray *array;
gint len;
gtk_tree_model_get_iter (model, parent, &iter);
len = gtk_tree_model_iter_n_children (model, &iter);
if (len < 2)
return;
}
......
......@@ -252,6 +252,8 @@ gtk_tree_view_column_init (GtkTreeViewColumn *tree_column)
tree_column->dirty = TRUE;
tree_column->sort_order = GTK_TREE_SORT_ASCENDING;
tree_column->show_sort_indicator = FALSE;
tree_column->sort_signal = 0;
tree_column->sort_column_id = -1;
}
static void
......@@ -1478,6 +1480,79 @@ gtk_tree_view_column_get_alignment (GtkTreeViewColumn *tree_column)
return tree_column->xalign;
}
static void
sort_clicked_func (GtkTreeViewColumn *tree_column,
gpointer data)
{
GList *list;
g_return_if_fail (tree_column->tree_view != NULL);
if (tree_column->show_sort_indicator)
{
if (tree_column->sort_order == GTK_TREE_SORT_ASCENDING)
gtk_tree_view_column_set_sort_order (tree_column, GTK_TREE_SORT_DESCENDING);
else
gtk_tree_view_column_set_sort_order (tree_column, GTK_TREE_SORT_ASCENDING);
}
else
{
gtk_tree_view_column_set_sort_order (tree_column, GTK_TREE_SORT_ASCENDING);
gtk_tree_view_column_set_sort_indicator (tree_column, TRUE);
}
list = (GTK_TREE_VIEW (tree_column->tree_view)->priv->columns);
g_assert (list);
while (list)
{
GtkTreeViewColumn *tmp_column;
tmp_column = GTK_TREE_VIEW_COLUMN (list->data);
if (tmp_column->visible && tmp_column != tree_column)
gtk_tree_view_column_set_sort_indicator (tmp_column, FALSE);
list = list->next;
}
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (GTK_TREE_VIEW (tree_column->tree_view)->priv->model),
tree_column->sort_column_id,
tree_column->sort_order);
}
/**
* gtk_tree_view_column_set_sort_column_id:
* @tree_column: a #GtkTreeViewColumn
* @sort_column_id: The sort_column_id of the model to sort on.
*
* Sets the sort_column_id that the column sorts on.
**/
void
gtk_tree_view_column_set_sort_column_id (GtkTreeViewColumn *tree_column,
gint sort_column_id)
{
g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
g_return_if_fail (sort_column_id >= 0);
if (tree_column->sort_column_id == sort_column_id)
return;
if (sort_column_id == -1)
{
if (tree_column->sort_signal)
g_signal_handler_disconnect (G_OBJECT (tree_column), tree_column->sort_signal);
return;
}
if (! tree_column->sort_signal)
tree_column->sort_signal = g_signal_connectc (G_OBJECT (tree_column),
"clicked",
G_CALLBACK (sort_clicked_func),
NULL, FALSE);
tree_column->sort_column_id = sort_column_id;
gtk_tree_view_column_set_sort_indicator (tree_column, FALSE);
gtk_tree_view_column_set_sort_order (tree_column, GTK_TREE_SORT_ASCENDING);
}
/**
* gtk_tree_view_column_set_sort_indicator:
* @tree_column: a #GtkTreeViewColumn
......@@ -1531,12 +1606,13 @@ gtk_tree_view_column_get_sort_indicator (GtkTreeViewColumn *tree_column)
* @order: sort order that the sort indicator should indicate
*
* Changes the appearance of the sort indicator. (This <emphasis>does
* not</emphasis> actually sort the model - for the models shipped
* with GTK+, use at gtk_tree_sortable_set_sort_column() to do
* that. For custom models, the mechanism will vary.) The sort
* indicator changes direction to indicate normal sort or reverse
* sort. Note that you must have the sort indicator enabled to see
* anything when calling this function; see
* not</emphasis> actually sort the model. Use
* gtk_tree_view_column_set_sort_column_id() if you want automatic sorting
* support. This function is primarily for custom sorting behavior, and should
* be used in conjunction with #gtk_tree_sortable_set_sort_column() to do
* that. For custom models, the mechanism will vary.) The sort indicator changes
* direction to indicate normal sort or reverse sort. Note that you must have
* the sort indicator enabled to see anything when calling this function; see
* gtk_tree_view_column_set_sort_indicator().
*
**/
......
......@@ -64,8 +64,6 @@ struct _GtkTreeViewColumn
GdkWindow *window;
gfloat xalign;
gint id;
gint width;
gint min_width;
gint max_width;
......@@ -78,7 +76,13 @@ struct _GtkTreeViewColumn
GtkCellRenderer *cell;
GSList *attributes;
GtkTreeViewColumnSizing column_type;
/* Sorting */
guint sort_signal;
gint sort_column_id;
GtkTreeSortOrder sort_order;
guint visible : 1;
guint button_active : 1;
guint dirty : 1;
......@@ -147,6 +151,14 @@ GtkWidget *gtk_tree_view_column_get_widget (GtkTreeViewColumn
void gtk_tree_view_column_set_alignment (GtkTreeViewColumn *tree_column,
gfloat xalign);
gfloat gtk_tree_view_column_get_alignment (GtkTreeViewColumn *tree_column);
/* You probably only want to use gtk_tree_view_column_set_sort_column_id. The
* other sorting functions exist primarily to let others do their own custom sorting.
*/
void gtk_tree_view_column_set_sort_column_id (GtkTreeViewColumn *tree_column,
gint sort_column_id);
void gtk_tree_view_column_set_sort_indicator (GtkTreeViewColumn *tree_column,
gboolean setting);
gboolean gtk_tree_view_column_get_sort_indicator (GtkTreeViewColumn *tree_column);
......
......@@ -31,21 +31,24 @@ LDADDS = @STRIP_BEGIN@ \
@STRIP_END@
noinst_PROGRAMS = \
testsocket \
testsocket_child \
## testsocket \
## testsocket_child \
testtreeview \
testtreefocus \
testtreecolumns
testtreecolumns \
testtreesort
testsocket_DEPENDENCIES = $(DEPS)
testsocket_child_DEPENDENCIES = $(DEPS)
#testsocket_DEPENDENCIES = $(DEPS)
#testsocket_child_DEPENDENCIES = $(DEPS)
testtreeview_DEPENDENCIES = $(DEPS)
testtreefocus_DEPENDENCIES = $(DEPS)
testtreecolumns_DEPENDENCIES = $(DEPS)
testtreesort_DEPENDENCIES = $(DEPS)
testsocket_LDADD = $(LDADDS)
testsocket_child_LDADD = $(LDADDS)
#testsocket_LDADD = $(LDADDS)
#testsocket_child_LDADD = $(LDADDS)
testtreeview_LDADD = $(LDADDS)
testtreefocus_LDADD = $(LDADDS)
testtreecolumns_LDADD = $(LDADDS)
testtreesort_LDADD = $(LDADDS)
#include <gtk/gtk.h>
typedef struct _ListSort ListSort;
struct _ListSort
{
const gchar *word_1;
const gchar *word_2;
const gchar *word_3;
const gchar *word_4;
};
static ListSort data[] =
{
{ "Apples", "Transmorgrify", "Exculpatory", "Gesundheit"},
{ "Oranges", "Wicker", "Adamantine", "Convivial" },
{ "Bovine Spongiform Encephilopathy", "Sleazebucket", "Mountaineer", "Pander" },
{ "Foot and Mouth", "Lampshade", "Skim Milk\nFull Milk", "Viewless" },
{ "Blood,\nsweat,\ntears", "The Man", "Horses", "Muckety-Muck" },
{ "Rare Steak", "Siam", "Watchdog", "Xantippe" },
{ "SIGINT", "Rabbit Breath", "Alligator", "Bloodstained" },
{ "Google", "Chrysanthemums", "Hobnob", "Leapfrog"},
{ "Technology fibre optic", "Turtle", "Academe", "Lonely" },
{ "Freon", "Harpes", "Quidditch", "Reagan" },
{ "Transposition", "Fruit Basket", "Monkey Wort", "Glogg" },
{ "Fern", "Glasnost and Perestroika", "Latitude", "Bomberman!!!" },
{NULL, }
};
enum
{
WORD_COLUMN = 0,
WORD_COLUMN_2,
WORD_COLUMN_3,
WORD_COLUMN_4,
NUM_COLUMNS
};
int
main (int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *scrolled_window;
GtkWidget *tree_view;
GtkTreeModel *model;
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
GtkTreeIter iter;
gint i;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_signal_connect (GTK_OBJECT (window), "destroy", gtk_main_quit, NULL);
vbox = gtk_vbox_new (FALSE, 8);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 8);
gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new ("My List of cool words"), FALSE, FALSE, 0);
gtk_container_add (GTK_CONTAINER (window), vbox);
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_ETCHED_IN);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE, 0);
model = gtk_list_store_new_with_types (NUM_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (model),
0, GTK_TREE_SORT_ASCENDING);
for (i = 0; data[i].word_1 != NULL; i++)
{
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
WORD_COLUMN, 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);
}
tree_view = gtk_tree_view_new_with_model (model);
g_object_unref (G_OBJECT (model));
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree_view), TRUE);
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes ("First Word", renderer,
"text", WORD_COLUMN,
NULL);
gtk_tree_view_column_set_sort_column_id (column, WORD_COLUMN);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
g_object_unref (column);
g_object_unref (renderer);
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_view), column);
g_object_unref (column);
g_object_unref (renderer);
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_view), column);
g_object_unref (column);
g_object_unref (renderer);
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_view), column);
g_object_unref (column);
g_object_unref (renderer);
gtk_container_add (GTK_CONTAINER (scrolled_window), tree_view);
gtk_widget_show_all (window);
gtk_main ();
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment