diff options
author | Havoc Pennington <hp@redhat.com> | 2001-01-08 18:26:05 +0000 |
---|---|---|
committer | Havoc Pennington <hp@src.gnome.org> | 2001-01-08 18:26:05 +0000 |
commit | 157cfa27ca530a8b896f89a11962ebde4ebec005 (patch) | |
tree | 6966ff287976fbc93307ad890aefd0a7f899ec05 | |
parent | 59b6bf38632d443532987e80429dcd5528fe74e6 (diff) | |
download | gtk+-157cfa27ca530a8b896f89a11962ebde4ebec005.tar.gz |
hack on this some
2001-01-08 Havoc Pennington <hp@redhat.com>
* tests/testtreeview.c: hack on this some
* gtk/gtktreestore.c (gtk_tree_store_setv): rename
gtk_tree_store_set_valist, v is for arrays, valist for varargs
list
(gtk_tree_store_getv): rename gtk_tree_store_get_valist
* gtk/gtkliststore.h: Add varargs set() and get() convenience
functions
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | ChangeLog.pre-2-0 | 12 | ||||
-rw-r--r-- | ChangeLog.pre-2-10 | 12 | ||||
-rw-r--r-- | ChangeLog.pre-2-2 | 12 | ||||
-rw-r--r-- | ChangeLog.pre-2-4 | 12 | ||||
-rw-r--r-- | ChangeLog.pre-2-6 | 12 | ||||
-rw-r--r-- | ChangeLog.pre-2-8 | 12 | ||||
-rw-r--r-- | gtk/gtkliststore.c | 130 | ||||
-rw-r--r-- | gtk/gtkliststore.h | 12 | ||||
-rw-r--r-- | gtk/gtktreestore.c | 37 | ||||
-rw-r--r-- | gtk/gtktreestore.h | 4 | ||||
-rw-r--r-- | tests/testtreeview-plan.txt | 7 | ||||
-rw-r--r-- | tests/testtreeview.c | 168 |
13 files changed, 423 insertions, 19 deletions
@@ -1,3 +1,15 @@ +2001-01-08 Havoc Pennington <hp@redhat.com> + + * tests/testtreeview.c: hack on this some + + * gtk/gtktreestore.c (gtk_tree_store_setv): rename + gtk_tree_store_set_valist, v is for arrays, valist for varargs + list + (gtk_tree_store_getv): rename gtk_tree_store_get_valist + + * gtk/gtkliststore.h: Add varargs set() and get() convenience + functions + 2001-01-08 Alexander Larsson <alexl@redhat.com> * gtk/gtkwindow-decorate.[hc]: diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index df7121f59d..69f51cb9e5 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,15 @@ +2001-01-08 Havoc Pennington <hp@redhat.com> + + * tests/testtreeview.c: hack on this some + + * gtk/gtktreestore.c (gtk_tree_store_setv): rename + gtk_tree_store_set_valist, v is for arrays, valist for varargs + list + (gtk_tree_store_getv): rename gtk_tree_store_get_valist + + * gtk/gtkliststore.h: Add varargs set() and get() convenience + functions + 2001-01-08 Alexander Larsson <alexl@redhat.com> * gtk/gtkwindow-decorate.[hc]: diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index df7121f59d..69f51cb9e5 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,15 @@ +2001-01-08 Havoc Pennington <hp@redhat.com> + + * tests/testtreeview.c: hack on this some + + * gtk/gtktreestore.c (gtk_tree_store_setv): rename + gtk_tree_store_set_valist, v is for arrays, valist for varargs + list + (gtk_tree_store_getv): rename gtk_tree_store_get_valist + + * gtk/gtkliststore.h: Add varargs set() and get() convenience + functions + 2001-01-08 Alexander Larsson <alexl@redhat.com> * gtk/gtkwindow-decorate.[hc]: diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index df7121f59d..69f51cb9e5 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,15 @@ +2001-01-08 Havoc Pennington <hp@redhat.com> + + * tests/testtreeview.c: hack on this some + + * gtk/gtktreestore.c (gtk_tree_store_setv): rename + gtk_tree_store_set_valist, v is for arrays, valist for varargs + list + (gtk_tree_store_getv): rename gtk_tree_store_get_valist + + * gtk/gtkliststore.h: Add varargs set() and get() convenience + functions + 2001-01-08 Alexander Larsson <alexl@redhat.com> * gtk/gtkwindow-decorate.[hc]: diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index df7121f59d..69f51cb9e5 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,15 @@ +2001-01-08 Havoc Pennington <hp@redhat.com> + + * tests/testtreeview.c: hack on this some + + * gtk/gtktreestore.c (gtk_tree_store_setv): rename + gtk_tree_store_set_valist, v is for arrays, valist for varargs + list + (gtk_tree_store_getv): rename gtk_tree_store_get_valist + + * gtk/gtkliststore.h: Add varargs set() and get() convenience + functions + 2001-01-08 Alexander Larsson <alexl@redhat.com> * gtk/gtkwindow-decorate.[hc]: diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index df7121f59d..69f51cb9e5 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,15 @@ +2001-01-08 Havoc Pennington <hp@redhat.com> + + * tests/testtreeview.c: hack on this some + + * gtk/gtktreestore.c (gtk_tree_store_setv): rename + gtk_tree_store_set_valist, v is for arrays, valist for varargs + list + (gtk_tree_store_getv): rename gtk_tree_store_get_valist + + * gtk/gtkliststore.h: Add varargs set() and get() convenience + functions + 2001-01-08 Alexander Larsson <alexl@redhat.com> * gtk/gtkwindow-decorate.[hc]: diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index df7121f59d..69f51cb9e5 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,15 @@ +2001-01-08 Havoc Pennington <hp@redhat.com> + + * tests/testtreeview.c: hack on this some + + * gtk/gtktreestore.c (gtk_tree_store_setv): rename + gtk_tree_store_set_valist, v is for arrays, valist for varargs + list + (gtk_tree_store_getv): rename gtk_tree_store_get_valist + + * gtk/gtkliststore.h: Add varargs set() and get() convenience + functions + 2001-01-08 Alexander Larsson <alexl@redhat.com> * gtk/gtkwindow-decorate.[hc]: diff --git a/gtk/gtkliststore.c b/gtk/gtkliststore.c index 6597abb026..88d3c6fd53 100644 --- a/gtk/gtkliststore.c +++ b/gtk/gtkliststore.c @@ -22,6 +22,7 @@ #include "gtkliststore.h" #include "gtktreedatalist.h" #include "gtksignal.h" +#include <gobject/gvaluecollector.h> #define G_SLIST(x) ((GSList *) x) @@ -475,6 +476,135 @@ gtk_list_store_set_cell (GtkListStore *list_store, } void +gtk_list_store_set_valist (GtkListStore *list_store, + GtkTreeIter *iter, + va_list var_args) +{ + gint column; + + g_return_if_fail (GTK_IS_LIST_STORE (list_store)); + + column = va_arg (var_args, gint); + + while (column != -1) + { + GValue value = { 0, }; + gchar *error = NULL; + + if (column >= list_store->n_columns) + { + g_warning ("%s: Invalid column number %d added to iter (remember to end your list of columns with a -1)", G_STRLOC, column); + break; + } + g_value_init (&value, list_store->column_headers[column]); + + G_VALUE_COLLECT (&value, var_args, &error); + if (error) + { + g_warning ("%s: %s", G_STRLOC, error); + g_free (error); + + /* we purposely leak the value here, it might not be + * in a sane state if an error condition occoured + */ + break; + } + + gtk_list_store_set_cell (list_store, + iter, + column, + &value); + + g_value_unset (&value); + + column = va_arg (var_args, gint); + } +} + +/** + * gtk_list_store_set: + * @list_store: a #GtkListStore + * @iter: row iterator + * @Varargs: pairs of column number and value, terminated with -1 + * + * Sets the value of one or more cells in the row referenced by @iter. + * The variable argument list should contain integer column numbers, + * each column number followed by the value to be set. For example, + * The list is terminated by a -1. For example, to set column 0 with type + * %G_TYPE_STRING to "Foo", you would write gtk_list_store_set (store, iter, + * 0, "Foo", -1). + **/ +void +gtk_list_store_set (GtkListStore *list_store, + GtkTreeIter *iter, + ...) +{ + va_list var_args; + + g_return_if_fail (GTK_IS_LIST_STORE (list_store)); + + va_start (var_args, iter); + gtk_list_store_set_valist (list_store, iter, var_args); + va_end (var_args); +} + +void +gtk_list_store_get_valist (GtkListStore *list_store, + GtkTreeIter *iter, + va_list var_args) +{ + gint column; + + g_return_if_fail (GTK_IS_LIST_STORE (list_store)); + + column = va_arg (var_args, gint); + + while (column != -1) + { + GValue value = { 0, }; + gchar *error = NULL; + + if (column >= list_store->n_columns) + { + g_warning ("%s: Invalid column number %d accessed (remember to end your list of columns with a -1)", G_STRLOC, column); + break; + } + + gtk_list_store_get_value (GTK_TREE_MODEL (list_store), iter, column, &value); + + G_VALUE_LCOPY (&value, var_args, &error); + if (error) + { + g_warning ("%s: %s", G_STRLOC, error); + g_free (error); + + /* we purposely leak the value here, it might not be + * in a sane state if an error condition occoured + */ + break; + } + + g_value_unset (&value); + + column = va_arg (var_args, gint); + } +} + +void +gtk_list_store_get (GtkListStore *list_store, + GtkTreeIter *iter, + ...) +{ + va_list var_args; + + g_return_if_fail (GTK_IS_LIST_STORE (list_store)); + + va_start (var_args, iter); + gtk_list_store_get_valist (list_store, iter, var_args); + va_end (var_args); +} + +void gtk_list_store_remove (GtkListStore *list_store, GtkTreeIter *iter) { diff --git a/gtk/gtkliststore.h b/gtk/gtkliststore.h index dc91fa5672..ff01ea37fc 100644 --- a/gtk/gtkliststore.h +++ b/gtk/gtkliststore.h @@ -79,6 +79,18 @@ void gtk_list_store_set_cell (GtkListStore *store, GtkTreeIter *iter, gint column, GValue *value); +void gtk_list_store_set (GtkListStore *list_store, + GtkTreeIter *iter, + ...); +void gtk_list_store_set_valist (GtkListStore *list_store, + GtkTreeIter *iter, + va_list var_args); +void gtk_list_store_get (GtkListStore *list_store, + GtkTreeIter *iter, + ...); +void gtk_list_store_get_valist (GtkListStore *list_store, + GtkTreeIter *iter, + va_list var_args); void gtk_list_store_remove (GtkListStore *store, GtkTreeIter *iter); void gtk_list_store_insert (GtkListStore *store, diff --git a/gtk/gtktreestore.c b/gtk/gtktreestore.c index 071a117a7b..0c4bc516df 100644 --- a/gtk/gtktreestore.c +++ b/gtk/gtktreestore.c @@ -536,9 +536,9 @@ gtk_tree_store_set_cell (GtkTreeStore *tree_store, } void -gtk_tree_store_setv (GtkTreeStore *tree_store, - GtkTreeIter *iter, - va_list var_args) +gtk_tree_store_set_valist (GtkTreeStore *tree_store, + GtkTreeIter *iter, + va_list var_args) { gint column; @@ -546,14 +546,14 @@ gtk_tree_store_setv (GtkTreeStore *tree_store, column = va_arg (var_args, gint); - while (column >= 0) + while (column != -1) { GValue value = { 0, }; gchar *error = NULL; if (column >= tree_store->n_columns) { - g_warning ("Invalid column number %d added to iter", column); + g_warning ("%s: Invalid column number %d added to iter (remember to end your list of columns with a -1)", G_STRLOC, column); break; } g_value_init (&value, tree_store->column_headers[column]); @@ -581,6 +581,19 @@ gtk_tree_store_setv (GtkTreeStore *tree_store, } } +/** + * gtk_tree_store_set: + * @tree_store: a #GtkTreeStore + * @iter: row iterator + * @Varargs: pairs of column number and value, terminated with -1 + * + * Sets the value of one or more cells in the row referenced by @iter. + * The variable argument list should contain integer column numbers, + * each column number followed by the value to be set. For example, + * The list is terminated by a -1. For example, to set column 0 with type + * %G_TYPE_STRING to "Foo", you would write gtk_tree_store_set (store, iter, + * 0, "Foo", -1). + **/ void gtk_tree_store_set (GtkTreeStore *tree_store, GtkTreeIter *iter, @@ -591,14 +604,14 @@ gtk_tree_store_set (GtkTreeStore *tree_store, g_return_if_fail (GTK_IS_TREE_STORE (tree_store)); va_start (var_args, iter); - gtk_tree_store_setv (tree_store, iter, var_args); + gtk_tree_store_set_valist (tree_store, iter, var_args); va_end (var_args); } void -gtk_tree_store_getv (GtkTreeStore *tree_store, - GtkTreeIter *iter, - va_list var_args) +gtk_tree_store_get_valist (GtkTreeStore *tree_store, + GtkTreeIter *iter, + va_list var_args) { gint column; @@ -606,14 +619,14 @@ gtk_tree_store_getv (GtkTreeStore *tree_store, column = va_arg (var_args, gint); - while (column >= 0) + while (column != -1) { GValue value = { 0, }; gchar *error = NULL; if (column >= tree_store->n_columns) { - g_warning ("Invalid column number %d accessed", column); + g_warning ("%s: Invalid column number %d accessed (remember to end your list of columns with a -1)", G_STRLOC, column); break; } @@ -647,7 +660,7 @@ gtk_tree_store_get (GtkTreeStore *tree_store, g_return_if_fail (GTK_IS_TREE_STORE (tree_store)); va_start (var_args, iter); - gtk_tree_store_getv (tree_store, iter, var_args); + gtk_tree_store_get_valist (tree_store, iter, var_args); va_end (var_args); } diff --git a/gtk/gtktreestore.h b/gtk/gtktreestore.h index 373c117927..ab6abefa1d 100644 --- a/gtk/gtktreestore.h +++ b/gtk/gtktreestore.h @@ -84,13 +84,13 @@ void gtk_tree_store_set_cell (GtkTreeStore *tree_store, void gtk_tree_store_set (GtkTreeStore *tree_store, GtkTreeIter *iter, ...); -void gtk_tree_store_setv (GtkTreeStore *tree_store, +void gtk_tree_store_set_valist (GtkTreeStore *tree_store, GtkTreeIter *iter, va_list var_args); void gtk_tree_store_get (GtkTreeStore *tree_store, GtkTreeIter *iter, ...); -void gtk_tree_store_getv (GtkTreeStore *tree_store, +void gtk_tree_store_get_valist (GtkTreeStore *tree_store, GtkTreeIter *iter, va_list var_args); void gtk_tree_store_remove (GtkTreeStore *tree_store, diff --git a/tests/testtreeview-plan.txt b/tests/testtreeview-plan.txt index 9662d699d6..20753f124e 100644 --- a/tests/testtreeview-plan.txt +++ b/tests/testtreeview-plan.txt @@ -1,4 +1,11 @@ This document is a laundry list of stuff to check if you want to verify that GtkTreeView and associated objects are working properly. +TreeModel testing: + + - all the TreeView/TreeModel tests in this document should be run + with each of the different models testtreeview supports + + - ensure that swapping in a new model for the tree view when there + was a preexisting one exists already diff --git a/tests/testtreeview.c b/tests/testtreeview.c index 0b38023ce6..509356c9da 100644 --- a/tests/testtreeview.c +++ b/tests/testtreeview.c @@ -79,11 +79,115 @@ GtkTreeModelTypes *gtk_tree_model_types_new (void); typedef enum { - MODEL_TYPES, - MODEL_LAST + /* MODEL_TYPES, */ + MODEL_TREE, + MODEL_LIST, + MODEL_SORTED_TREE, + MODEL_SORTED_LIST, + MODEL_NULL, + MODEL_LAST } ModelType; +/* FIXME add a custom model to test */ static GtkTreeModel *models[MODEL_LAST]; +static const char *model_names[MODEL_LAST] = { + "GtkTreeStore", + "GtkListStore", + "GtkTreeModelSort wrapping GtkTreeStore", + "GtkTreeModelSort wrapping GtkListStore", + "NULL (no model)" +}; + +static GtkTreeModel* +create_list_model (void) +{ + GtkListStore *store; + GtkTreeIter iter; + gint i; + + store = gtk_list_store_new_with_types (2, G_TYPE_STRING, G_TYPE_STRING); + + i = 0; + while (i < 200) + { + char *msg; + + gtk_list_store_append (store, &iter); + + msg = g_strdup_printf ("%d", i); + + gtk_list_store_set (store, &iter, 0, msg, 1, "Foo! Foo! Foo!", -1); + + g_free (msg); + + ++i; + } + + return GTK_TREE_MODEL (store); +} + +static void +typesystem_recurse (GType type, + GtkTreeIter *parent_iter, + GtkTreeStore *store) +{ + GType* children; + guint n_children = 0; + gint i; + GtkTreeIter iter; + gchar *str; + + gtk_tree_store_append (store, &iter, parent_iter); + + str = g_strdup_printf ("%d", type); + gtk_tree_store_set (store, &iter, 0, str, 1, g_type_name (type), -1); + g_free (str); + + children = g_type_children (type, &n_children); + + i = 0; + while (i < n_children) + { + typesystem_recurse (children[i], &iter, store); + + ++i; + } + + g_free (children); +} + +static GtkTreeModel* +create_tree_model (void) +{ + GtkTreeStore *store; + gint i; + + store = gtk_tree_store_new_with_types (2, G_TYPE_STRING, G_TYPE_STRING); + + i = 0; + while (i < G_TYPE_LAST_RESERVED_FUNDAMENTAL) + { + typesystem_recurse (i, NULL, store); + + ++i; + } + + return GTK_TREE_MODEL (store); +} + +static void +model_selected (GtkOptionMenu *om, gpointer data) +{ + GtkTreeView *tree_view = GTK_TREE_VIEW (data); + gint hist; + + hist = gtk_option_menu_get_history (om); + + if (models[hist] != gtk_tree_view_get_model (tree_view)) + { + gtk_tree_view_set_model (tree_view, models[hist]); + } +} int main (int argc, @@ -92,20 +196,52 @@ main (int argc, GtkWidget *window; GtkWidget *sw; GtkWidget *tv; + GtkWidget *table; + GtkWidget *om; + GtkWidget *menu; GtkTreeViewColumn *col; GtkCellRenderer *rend; + GtkTreeModel *model; gint i; gtk_init (&argc, &argv); +#if 0 models[MODEL_TYPES] = GTK_TREE_MODEL (gtk_tree_model_types_new ()); +#endif + models[MODEL_LIST] = create_list_model (); + models[MODEL_TREE] = create_tree_model (); + + model = create_list_model (); + models[MODEL_SORTED_LIST] = gtk_tree_model_sort_new_with_model (model, NULL, 0); + g_object_unref (G_OBJECT (model)); + + model = create_tree_model (); + models[MODEL_SORTED_TREE] = gtk_tree_model_sort_new_with_model (model, NULL, 0); + g_object_unref (G_OBJECT (model)); + + models[MODEL_NULL] = NULL; + + menu = gtk_menu_new (); i = 0; while (i < MODEL_LAST) { + GtkWidget *mi; + const char *name; + + name = model_names[i]; + + mi = gtk_menu_item_new_with_label (name); + + gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi); + +#if 0 window = create_prop_editor (G_OBJECT (models[i])); - gtk_window_set_title (GTK_WINDOW (window), g_type_name (G_TYPE_FROM_INSTANCE (models[i]))); + gtk_window_set_title (GTK_WINDOW (window), + name); +#endif ++i; } @@ -113,16 +249,38 @@ main (int argc, window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size (GTK_WINDOW (window), 400, 400); + + table = gtk_table_new (2, 1, FALSE); + + gtk_container_add (GTK_CONTAINER (window), table); + + om = gtk_option_menu_new (); + gtk_option_menu_set_menu (GTK_OPTION_MENU (om), menu); + + gtk_table_attach (GTK_TABLE (table), om, + 0, 1, 0, 1, + 0, 0, + 0, 0); sw = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_container_add (GTK_CONTAINER (window), sw); + + gtk_table_attach (GTK_TABLE (table), sw, + 0, 1, 1, 2, + GTK_EXPAND | GTK_FILL, + GTK_EXPAND | GTK_FILL, + 0, 0); tv = gtk_tree_view_new_with_model (models[0]); + gtk_signal_connect (GTK_OBJECT (om), + "changed", + GTK_SIGNAL_FUNC (model_selected), + tv); + gtk_container_add (GTK_CONTAINER (sw), tv); rend = gtk_cell_renderer_text_new (); @@ -148,7 +306,7 @@ main (int argc, g_object_unref (G_OBJECT (rend)); g_object_unref (G_OBJECT (col)); - + gtk_widget_show_all (window); gtk_main (); |