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
This commit is contained in:
Havoc Pennington 2001-01-08 18:26:05 +00:00 committed by Havoc Pennington
parent 59b6bf3863
commit 157cfa27ca
13 changed files with 423 additions and 19 deletions

View File

@ -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]:

View File

@ -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]:

View File

@ -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]:

View File

@ -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]:

View File

@ -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]:

View File

@ -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]:

View File

@ -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]:

View File

@ -22,6 +22,7 @@
#include "gtkliststore.h"
#include "gtktreedatalist.h"
#include "gtksignal.h"
#include <gobject/gvaluecollector.h>
#define G_SLIST(x) ((GSList *) x)
@ -474,6 +475,135 @@ gtk_list_store_set_cell (GtkListStore *list_store,
NULL, iter);
}
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)

View File

@ -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,

View File

@ -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);
}

View File

@ -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,

View File

@ -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

View File

@ -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 ();