PATCH: GtkTreeStore (and friends) construct-time properties
- From: murrayc t-online de (Murray Cumming)
- To: gtk-devel-list <gtk-devel-list gnome org>
- Subject: PATCH: GtkTreeStore (and friends) construct-time properties
- Date: 05 Nov 2001 23:58:59 +0100
As discussed with Jonathon Blandford on irc, here's a patch that adds
necessary properties to GtkTreeStore, GtkListStore and GtkTreeModelSort,
allowing them to be instantiated by language bindings.
May I commit this?
--
Murray Cumming
murrayc usa net
www.murrayc.com
? treeview_properties.patch
? docs/reference/gtk/tmpl/gtkaccessible.sgml
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gtk+/ChangeLog,v
retrieving revision 1.2541
diff -u -u -p -r1.2541 ChangeLog
--- ChangeLog 2001/11/05 17:48:57 1.2541
+++ ChangeLog 2001/11/05 22:40:05
@@ -1,3 +1,10 @@
+2001-11-05 Murray Cumming <murrayc usa net>
+
+ * gtk/gtktreestore.c/gtkliststore.c: Added "n_columns" and
+ "types" construct-time properties, for use with g_object_new().
+ * gtk/gtktreemodelsort.c: Added "model" property, for same
+ reason.
+
Mon Nov 5 12:46:44 2001 Owen Taylor <otaylor redhat com>
* gdk/x11/gdkdrawable-x11.[ch] gdk/x11/gdkgc-x11.c
Index: gtk/gtkliststore.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkliststore.c,v
retrieving revision 1.57
diff -u -u -p -r1.57 gtkliststore.c
--- gtk/gtkliststore.c 2001/10/31 21:55:55 1.57
+++ gtk/gtkliststore.c 2001/11/05 22:40:06
@@ -23,12 +23,21 @@
#include "gtktreedatalist.h"
#include "gtksignal.h"
#include "gtktreednd.h"
+#include "gtkintl.h"
#include <gobject/gvaluecollector.h>
#define G_SLIST(x) ((GSList *) x)
#define GTK_LIST_STORE_IS_SORTED(list) (GTK_LIST_STORE (list)->sort_column_id != -2)
#define VALID_ITER(iter, list_store) (iter!= NULL && iter->user_data != NULL && list_store->stamp == iter->stamp)
+/* Properties */
+enum {
+ PROP_0,
+ /* Construct args */
+ PROP_N_COLUMNS,
+ PROP_COLUMN_TYPES
+};
+
static void gtk_list_store_init (GtkListStore *list_store);
static void gtk_list_store_class_init (GtkListStoreClass *class);
static void gtk_list_store_tree_model_init (GtkTreeModelIface *iface);
@@ -36,6 +45,14 @@ static void gtk_list_store_drag_
static void gtk_list_store_drag_dest_init (GtkTreeDragDestIface *iface);
static void gtk_list_store_sortable_init (GtkTreeSortableIface *iface);
static void gtk_list_store_finalize (GObject *object);
+static void gtk_list_store_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void gtk_list_store_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
static guint gtk_list_store_get_flags (GtkTreeModel *tree_model);
static gint gtk_list_store_get_n_columns (GtkTreeModel *tree_model);
static GType gtk_list_store_get_column_type (GtkTreeModel *tree_model,
@@ -65,13 +82,14 @@ static gboolean gtk_list_store_iter_
static gboolean gtk_list_store_iter_parent (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreeIter *child);
-
-static void gtk_list_store_set_n_columns (GtkListStore *list_store,
- gint n_columns);
-static void gtk_list_store_set_column_type (GtkListStore *list_store,
- gint column,
- GType type);
+static void gtk_list_store_set_n_columns (GtkListStore *list_store,
+ gint n_columns);
+static GtkListStore *gtk_list_store_set_column_types (GtkListStore *list_store,
+ GType *types);
+static void gtk_list_store_set_column_type (GtkListStore *list_store,
+ gint column,
+ GType type);
/* Drag and Drop */
@@ -200,7 +218,27 @@ gtk_list_store_class_init (GtkListStoreC
parent_class = g_type_class_peek_parent (class);
object_class = (GObjectClass*) class;
+ object_class->set_property = gtk_list_store_set_property;
+ object_class->get_property = gtk_list_store_get_property;
+
object_class->finalize = gtk_list_store_finalize;
+
+ /* Construct */
+ g_object_class_install_property (object_class,
+ PROP_N_COLUMNS,
+ g_param_spec_int("n_columns",
+ _("Number of columns"),
+ _("The number of columns"),
+ 0,
+ G_MAXINT,
+ 0,
+ G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
+ g_object_class_install_property (object_class,
+ PROP_COLUMN_TYPES,
+ g_param_spec_pointer("types",
+ _("Column Types"),
+ _("Array of GType column types"),
+ G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
}
static void
@@ -261,7 +299,7 @@ gtk_list_store_init (GtkListStore *list_
* @Varargs: all #GType types for the columns, from first to last
*
* Creates a new list store as with @n_columns columns each of the types passed
- * in. As an example, gtk_tree_store_new (3, G_TYPE_INT, G_TYPE_STRING,
+ * in. As an example, gtk_list_store_new (3, G_TYPE_INT, G_TYPE_STRING,
* GDK_TYPE_PIXBUF); will create a new GtkListStore with three columns, of type
* int, string and GDkPixbuf respectively.
*
@@ -315,24 +353,13 @@ gtk_list_store_newv (gint n_columns,
GType *types)
{
GtkListStore *retval;
- gint i;
g_return_val_if_fail (n_columns > 0, NULL);
- retval = GTK_LIST_STORE (g_object_new (gtk_list_store_get_type (), NULL));
+ retval = GTK_LIST_STORE (g_object_new (gtk_list_store_get_type(), NULL));
gtk_list_store_set_n_columns (retval, n_columns);
-
- for (i = 0; i < n_columns; i++)
- {
- if (! _gtk_tree_data_list_check_type (types[i]))
- {
- g_warning ("%s: Invalid type %s passed to gtk_list_store_newv\n", G_STRLOC, g_type_name (types[i]));
- g_object_unref (G_OBJECT (retval));
- return NULL;
- }
- gtk_list_store_set_column_type (retval, i, types[i]);
- }
+ retval = gtk_list_store_set_column_types(retval, types);
return retval;
}
@@ -370,6 +397,27 @@ gtk_list_store_set_n_columns (GtkListSto
list_store->n_columns = n_columns;
}
+static GtkListStore*
+gtk_list_store_set_column_types (GtkListStore *list_store,
+ GType *types)
+{
+ gint i;
+ gint n_columns = gtk_list_store_get_n_columns(GTK_TREE_MODEL(list_store));
+
+ for (i = 0; i < n_columns; i++)
+ {
+ if (! _gtk_tree_data_list_check_type (types[i]))
+ {
+ g_warning ("%s: Invalid type %s passed to gtk_list_store_new_with_types\n", G_STRLOC, g_type_name (types[i]));
+ g_object_unref (G_OBJECT (list_store));
+ return NULL;
+ }
+ gtk_list_store_set_column_type (list_store, i, types[i]);
+ }
+
+ return list_store;
+}
+
static void
gtk_list_store_set_column_type (GtkListStore *list_store,
gint column,
@@ -403,6 +451,50 @@ gtk_list_store_finalize (GObject *object
}
(* parent_class->finalize) (object);
+}
+
+static void
+gtk_list_store_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GtkListStore *list_store = GTK_LIST_STORE (object);
+
+ switch (prop_id)
+ {
+ case PROP_N_COLUMNS:
+ gtk_list_store_set_n_columns (list_store, g_value_get_int(value));
+ break;
+ case PROP_COLUMN_TYPES:
+ gtk_list_store_set_column_types (list_store, (GType*)g_value_get_pointer(value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gtk_list_store_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GtkListStore *list_store = GTK_LIST_STORE (object);
+
+ switch (prop_id)
+ {
+ case PROP_N_COLUMNS:
+ g_value_set_int(value, gtk_list_store_get_n_columns (GTK_TREE_MODEL(list_store)));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+
}
/* Fulfill the GtkTreeModel requirements */
Index: gtk/gtktreemodelsort.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktreemodelsort.c,v
retrieving revision 1.43
diff -u -u -p -r1.43 gtktreemodelsort.c
--- gtk/gtktreemodelsort.c 2001/11/03 20:47:50 1.43
+++ gtk/gtktreemodelsort.c 2001/11/05 22:40:07
@@ -35,6 +35,7 @@
#include "gtktreestore.h"
#include "gtksignal.h"
#include "gtktreedatalist.h"
+#include "gtkintl.h"
#include <string.h>
typedef struct _SortElt SortElt;
@@ -42,6 +43,13 @@ typedef struct _SortLevel SortLevel;
typedef struct _SortData SortData;
typedef struct _SortTuple SortTuple;
+/* Properties */
+enum {
+ PROP_0,
+ /* Construct args */
+ PROP_MODEL
+};
+
struct _SortElt
{
GtkTreeIter iter;
@@ -87,6 +95,14 @@ static void gtk_tree_model_sort_class_in
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_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void gtk_tree_model_sort_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
static void gtk_tree_model_sort_row_changed (GtkTreeModel *model,
GtkTreePath *start_path,
GtkTreeIter *start_iter,
@@ -283,7 +299,20 @@ gtk_tree_model_sort_class_init (GtkTreeM
object_class = (GObjectClass *) class;
parent_class = g_type_class_peek_parent (class);
+ object_class->set_property = gtk_tree_model_sort_set_property;
+ object_class->get_property = gtk_tree_model_sort_get_property;
+
object_class->finalize = gtk_tree_model_sort_finalize;
+
+ /* Properties */
+
+ g_object_class_install_property (object_class,
+ PROP_MODEL,
+ g_param_spec_object ("model",
+ _("TreeModelSort Model"),
+ _("The model for the TreeModelSort"),
+ GTK_TYPE_TREE_MODEL,
+ G_PARAM_READWRITE));
}
static void
@@ -356,6 +385,46 @@ gtk_tree_model_sort_finalize (GObject *o
/* must chain up */
parent_class->finalize (object);
+}
+
+static void
+gtk_tree_model_sort_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GtkTreeModelSort *tree_model_sort = GTK_TREE_MODEL_SORT (object);
+
+ switch (prop_id)
+ {
+
+ case PROP_MODEL:
+ gtk_tree_model_sort_set_model (tree_model_sort, g_value_get_object (value));
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gtk_tree_model_sort_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GtkTreeModelSort *tree_model_sort = GTK_TREE_MODEL_SORT (object);
+
+ switch (prop_id)
+ {
+ case PROP_MODEL:
+ g_value_set_object (value, gtk_tree_model_sort_get_model(tree_model_sort));
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+
}
static void
Index: gtk/gtktreestore.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktreestore.c,v
retrieving revision 1.64
diff -u -u -p -r1.64 gtktreestore.c
--- gtk/gtktreestore.c 2001/10/31 21:55:55 1.64
+++ gtk/gtktreestore.c 2001/11/05 22:40:08
@@ -21,6 +21,7 @@
#include "gtktreestore.h"
#include "gtktreedatalist.h"
#include "gtktreednd.h"
+#include "gtkintl.h"
#include <string.h>
#include <gobject/gvaluecollector.h>
@@ -28,6 +29,14 @@
#define GTK_TREE_STORE_IS_SORTED(tree) (GTK_TREE_STORE (tree)->sort_column_id != -2)
#define VALID_ITER(iter, tree_store) (iter!= NULL && iter->user_data != NULL && tree_store->stamp == iter->stamp)
+/* Properties */
+enum {
+ PROP_0,
+ /* Construct args */
+ PROP_N_COLUMNS,
+ PROP_COLUMN_TYPES
+};
+
static void gtk_tree_store_init (GtkTreeStore *tree_store);
static void gtk_tree_store_class_init (GtkTreeStoreClass *tree_store_class);
static void gtk_tree_store_tree_model_init (GtkTreeModelIface *iface);
@@ -35,6 +44,14 @@ static void gtk_tree_store_drag_
static void gtk_tree_store_drag_dest_init (GtkTreeDragDestIface *iface);
static void gtk_tree_store_sortable_init (GtkTreeSortableIface *iface);
static void gtk_tree_store_finalize (GObject *object);
+static void gtk_tree_store_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void gtk_tree_store_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
static guint gtk_tree_store_get_flags (GtkTreeModel *tree_model);
static gint gtk_tree_store_get_n_columns (GtkTreeModel *tree_model);
static GType gtk_tree_store_get_column_type (GtkTreeModel *tree_model,
@@ -64,13 +81,14 @@ static gboolean gtk_tree_store_iter_
static gboolean gtk_tree_store_iter_parent (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreeIter *child);
-
-static void gtk_tree_store_set_n_columns (GtkTreeStore *tree_store,
- gint n_columns);
-static void gtk_tree_store_set_column_type (GtkTreeStore *tree_store,
- gint column,
- GType type);
+static void gtk_tree_store_set_n_columns (GtkTreeStore *tree_store,
+ gint n_columns);
+static GtkTreeStore *gtk_tree_store_set_column_types (GtkTreeStore *tree_store,
+ GType *types);
+static void gtk_tree_store_set_column_type (GtkTreeStore *tree_store,
+ gint column,
+ GType type);
/* DND interfaces */
@@ -203,7 +221,27 @@ gtk_tree_store_class_init (GtkTreeStoreC
parent_class = g_type_class_peek_parent (class);
object_class = (GObjectClass *) class;
+ object_class->set_property = gtk_tree_store_set_property;
+ object_class->get_property = gtk_tree_store_get_property;
+
object_class->finalize = gtk_tree_store_finalize;
+
+ /* Construct */
+ g_object_class_install_property (object_class,
+ PROP_N_COLUMNS,
+ g_param_spec_int("n_columns",
+ _("Number of columns"),
+ _("The number of columns"),
+ 0,
+ G_MAXINT,
+ 0,
+ G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
+ g_object_class_install_property (object_class,
+ PROP_COLUMN_TYPES,
+ g_param_spec_pointer("types",
+ _("Column Types"),
+ _("Array of GType column types"),
+ G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
}
static void
@@ -316,27 +354,18 @@ gtk_tree_store_newv (gint n_columns,
GType *types)
{
GtkTreeStore *retval;
- gint i;
g_return_val_if_fail (n_columns > 0, NULL);
retval = GTK_TREE_STORE (g_object_new (GTK_TYPE_TREE_STORE, NULL));
gtk_tree_store_set_n_columns (retval, n_columns);
- for (i = 0; i < n_columns; i++)
- {
- if (! _gtk_tree_data_list_check_type (types[i]))
- {
- g_warning ("%s: Invalid type %s passed to gtk_tree_store_new_with_types\n", G_STRLOC, g_type_name (types[i]));
- g_object_unref (G_OBJECT (retval));
- return NULL;
- }
- gtk_tree_store_set_column_type (retval, i, types[i]);
- }
+ retval = gtk_tree_store_set_column_types(retval, types);
return retval;
}
+
static void
gtk_tree_store_set_n_columns (GtkTreeStore *tree_store,
gint n_columns)
@@ -369,6 +398,27 @@ gtk_tree_store_set_n_columns (GtkTreeSto
tree_store->n_columns = n_columns;
}
+static GtkTreeStore*
+gtk_tree_store_set_column_types (GtkTreeStore *tree_store,
+ GType *types)
+{
+ gint i;
+ gint n_columns = gtk_tree_store_get_n_columns(GTK_TREE_MODEL(tree_store));
+
+ for (i = 0; i < n_columns; i++)
+ {
+ if (! _gtk_tree_data_list_check_type (types[i]))
+ {
+ g_warning ("%s: Invalid type %s passed to gtk_tree_store_new_with_types\n", G_STRLOC, g_type_name (types[i]));
+ g_object_unref (G_OBJECT (tree_store));
+ return NULL;
+ }
+ gtk_tree_store_set_column_type (tree_store, i, types[i]);
+ }
+
+ return tree_store;
+}
+
/**
* gtk_tree_store_set_column_type:
* @tree_store: a #GtkTreeStore
@@ -419,6 +469,50 @@ gtk_tree_store_finalize (GObject *object
}
(* parent_class->finalize) (object);
+}
+
+static void
+gtk_tree_store_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GtkTreeStore *tree_store = GTK_TREE_STORE (object);
+
+ switch (prop_id)
+ {
+ case PROP_N_COLUMNS:
+ gtk_tree_store_set_n_columns (tree_store, g_value_get_int(value));
+ break;
+ case PROP_COLUMN_TYPES:
+ gtk_tree_store_set_column_types (tree_store, (GType*)g_value_get_pointer(value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gtk_tree_store_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GtkTreeStore *tree_store = GTK_TREE_STORE (object);
+
+ switch (prop_id)
+ {
+ case PROP_N_COLUMNS:
+ g_value_set_int(value, gtk_tree_store_get_n_columns(GTK_TREE_MODEL(tree_store)));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+
}
/* fulfill the GtkTreeModel requirements */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]