Commit 151e42b3 authored by Tristan Van Berkom's avatar Tristan Van Berkom

Added GladeEPropCellAttribute


	* plugins/gtk+/glade-cell-renderer-editor.c: Added GladeEPropCellAttribute

	* plugins/gtk+/glade-gtk.c, plugins/gtk+/gtk+.xml.in: Integrated new eprop
	  for cell renderer attributes, avoid setting attributes for columns that
	  exceed model bounds (except on load).


svn path=/trunk/; revision=2038
parent c9e4cf00
......@@ -6,6 +6,12 @@
* plugins/gtk+/glade-column-types.c: Fixed to populate enums/flags only
after all catalogs parsed, now they are listed in alphabetical order too.
* plugins/gtk+/glade-cell-renderer-editor.c: Added GladeEPropCellAttribute
* plugins/gtk+/glade-gtk.c, plugins/gtk+/gtk+.xml.in: Integrated new eprop
for cell renderer attributes, avoid setting attributes for columns that
exceed model bounds (except on load).
2008-11-19 Tristan Van Berkom <tvb@gnome.org>
* plugins/gtk+/Makefile.am, plugins/gtk+/glade-cell-renderer-editor.c:
......
......@@ -49,9 +49,9 @@
#include "glade-displayable-values.h"
#include "glade-debug.h"
#define NUMERICAL_STEP_INCREMENT 1
#define NUMERICAL_PAGE_INCREMENT 10
#define NUMERICAL_PAGE_SIZE 1
#define NUMERICAL_STEP_INCREMENT 1.0F
#define NUMERICAL_PAGE_INCREMENT 10.0F
#define NUMERICAL_PAGE_SIZE 1.0F
#define FLOATING_STEP_INCREMENT 0.01F
#define FLOATING_PAGE_INCREMENT 0.1F
......
......@@ -70,7 +70,7 @@ struct _GladeButtonEditorClass
GtkVBoxClass parent;
};
GType glade_button_editor_get_type (void);
GType glade_button_editor_get_type (void) G_GNUC_CONST;
GtkWidget *glade_button_editor_new (GladeWidgetAdaptor *adaptor,
GladeEditable *editable);
......
......@@ -26,6 +26,7 @@
#include <gdk/gdkkeysyms.h>
#include "glade-cell-renderer-editor.h"
#include "glade-column-types.h"
static void glade_cell_renderer_editor_finalize (GObject *object);
......@@ -489,3 +490,180 @@ glade_cell_renderer_editor_new (GladeWidgetAdaptor *adaptor,
return GTK_WIDGET (renderer_editor);
}
/***************************************************************************
* Editor Property *
***************************************************************************/
typedef struct
{
GladeEditorProperty parent_instance;
GtkTreeModel *columns;
GtkWidget *spin;
GtkWidget *combo;
} GladeEPropCellAttribute;
GLADE_MAKE_EPROP (GladeEPropCellAttribute, glade_eprop_cell_attribute)
#define GLADE_EPROP_CELL_ATTRIBUTE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EPROP_CELL_ATTRIBUTE, GladeEPropCellAttribute))
#define GLADE_EPROP_CELL_ATTRIBUTE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EPROP_CELL_ATTRIBUTE, GladeEPropCellAttributeClass))
#define GLADE_IS_EPROP_CELL_ATTRIBUTE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_CELL_ATTRIBUTE))
#define GLADE_IS_EPROP_CELL_ATTRIBUTE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_EPROP_CELL_ATTRIBUTE))
#define GLADE_EPROP_CELL_ATTRIBUTE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GLADE_EPROP_CELL_ATTRIBUTE, GladeEPropCellAttributeClass))
static void
glade_eprop_cell_attribute_finalize (GObject *object)
{
/* Chain up */
GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (object));
//GladeEPropCellAttribute *eprop_attribute = GLADE_EPROP_CELL_ATTRIBUTE (object);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static GladeWidget *
get_model (GladeProperty *property)
{
GladeWidget *renderer = property->widget;
GladeWidget *model = NULL;
/* Keep inline with all new cell layouts !!! */
if (renderer->parent && GTK_IS_TREE_VIEW_COLUMN (renderer->parent->object))
{
GladeWidget *column = renderer->parent;
if (column->parent && GTK_IS_TREE_VIEW (column->parent->object))
{
GladeWidget *view = column->parent;
GtkTreeModel *real_model = NULL;
glade_widget_property_get (view, "model", &real_model);
if (real_model)
model = glade_widget_get_from_gobject (real_model);
}
}
return model;
}
static void
glade_eprop_cell_attribute_load (GladeEditorProperty *eprop,
GladeProperty *property)
{
GladeEditorPropertyClass *parent_class =
g_type_class_peek_parent (GLADE_EDITOR_PROPERTY_GET_CLASS (eprop));
GladeEPropCellAttribute *eprop_attribute = GLADE_EPROP_CELL_ATTRIBUTE (eprop);
/* Chain up in a clean state... */
parent_class->load (eprop, property);
if (property)
{
GladeWidget *gmodel;
GtkListStore *store = GTK_LIST_STORE (eprop_attribute->columns);
GtkTreeIter iter;
gtk_list_store_clear (store);
/* Generate model and set active iter */
if ((gmodel = get_model (property)) != NULL)
{
GList *columns = NULL, *l;
glade_widget_property_get (gmodel, "columns", &columns);
gtk_list_store_append (store, &iter);
/* translators: the adjective not the verb */
gtk_list_store_set (store, &iter, 0, _("unset"), -1);
for (l = columns; l; l = l->next)
{
GladeColumnType *column = l->data;
gchar *str = g_strdup_printf ("%s (%s)", column->column_name,
g_type_name (column->type));
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, 0, str, -1);
g_free (str);
}
gtk_combo_box_set_active (GTK_COMBO_BOX (eprop_attribute->combo),
CLAMP (g_value_get_int (property->value) + 1,
0, g_list_length (columns) + 1));
gtk_widget_set_sensitive (eprop_attribute->combo, TRUE);
}
else
{
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, 0, _("no model"), -1);
gtk_combo_box_set_active (GTK_COMBO_BOX (eprop_attribute->combo), 0);
gtk_widget_set_sensitive (eprop_attribute->combo, FALSE);
}
gtk_spin_button_set_value (GTK_SPIN_BUTTON (eprop_attribute->spin),
(gdouble)g_value_get_int (property->value));
}
}
static void
combo_changed (GtkWidget *combo,
GladeEditorProperty *eprop)
{
GValue val = { 0, };
if (eprop->loading) return;
g_value_init (&val, G_TYPE_INT);
g_value_set_int (&val, (gint)gtk_combo_box_get_active (GTK_COMBO_BOX (combo)) - 1);
glade_editor_property_commit (eprop, &val);
g_value_unset (&val);
}
static void
spin_changed (GtkWidget *spin,
GladeEditorProperty *eprop)
{
GValue val = { 0, };
if (eprop->loading) return;
g_value_init (&val, G_TYPE_INT);
g_value_set_int (&val, gtk_spin_button_get_value (GTK_SPIN_BUTTON (spin)));
glade_editor_property_commit (eprop, &val);
g_value_unset (&val);
}
static GtkWidget *
glade_eprop_cell_attribute_create_input (GladeEditorProperty *eprop)
{
GladeEPropCellAttribute *eprop_attribute = GLADE_EPROP_CELL_ATTRIBUTE (eprop);
GtkWidget *hbox;
GtkAdjustment *adjustment;
GtkCellRenderer *cell;
hbox = gtk_hbox_new (FALSE, 2);
adjustment = glade_property_class_make_adjustment (eprop->klass);
eprop_attribute->spin = gtk_spin_button_new (adjustment, 1.0, 0);
eprop_attribute->columns = (GtkTreeModel *)gtk_list_store_new (1, G_TYPE_STRING);
eprop_attribute->combo = gtk_combo_box_new_with_model (eprop_attribute->columns);
/* Add cell renderer */
cell = gtk_cell_renderer_text_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (eprop_attribute->combo), cell, TRUE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (eprop_attribute->combo), cell,
"text", 0, NULL);
gtk_box_pack_start (GTK_BOX (hbox), eprop_attribute->spin, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (hbox), eprop_attribute->combo, TRUE, TRUE, 0);
g_signal_connect (G_OBJECT (eprop_attribute->combo), "changed",
G_CALLBACK (combo_changed), eprop);
g_signal_connect (G_OBJECT (eprop_attribute->spin), "value-changed",
G_CALLBACK (spin_changed), eprop);
return hbox;
}
......@@ -34,6 +34,9 @@ G_BEGIN_DECLS
#define GLADE_IS_CELL_RENDERER_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_CELL_RENDERER_EDITOR))
#define GLADE_CELL_RENDERER_EDITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GLADE_TYPE_CELL_RENDERER_EDITOR, GladeCellRendererEditorClass))
#define GLADE_TYPE_EPROP_CELL_ATTRIBUTE (glade_eprop_cell_attribute_get_type())
typedef struct _GladeCellRendererEditor GladeCellRendererEditor;
typedef struct _GladeCellRendererEditorClass GladeCellRendererEditorClass;
......@@ -58,7 +61,8 @@ struct _GladeCellRendererEditorClass
GtkVBoxClass parent;
};
GType glade_cell_renderer_editor_get_type (void);
GType glade_eprop_cell_attribute_get_type (void) G_GNUC_CONST;
GType glade_cell_renderer_editor_get_type (void) G_GNUC_CONST;
GtkWidget *glade_cell_renderer_editor_new (GladeWidgetAdaptor *adaptor,
GladeEditorPageType type,
GladeEditable *editable);
......
......@@ -10208,6 +10208,29 @@ glade_gtk_cell_renderer_post_create (GladeWidgetAdaptor *adaptor,
}
GladeEditorProperty *
glade_gtk_cell_renderer_create_eprop (GladeWidgetAdaptor *adaptor,
GladePropertyClass *klass,
gboolean use_command)
{
GladeEditorProperty *eprop;
if (strncmp (klass->id, "attr-", strlen ("attr-")) == 0)
eprop = g_object_new (GLADE_TYPE_EPROP_CELL_ATTRIBUTE,
"property-class", klass,
"use-command", use_command,
NULL);
else
eprop = GWA_GET_CLASS
(G_TYPE_OBJECT)->create_eprop (adaptor,
klass,
use_command);
return eprop;
}
GladeEditable *
glade_gtk_cell_renderer_create_editable (GladeWidgetAdaptor *adaptor,
GladeEditorPageType type)
......@@ -10259,10 +10282,12 @@ glade_gtk_cell_renderer_set_attribute (GObject *object,
{
GtkCellLayout *layout;
GtkCellRenderer *cell;
GladeWidget *widget = glade_widget_get_from_gobject (object);
GladeWidget *widget = glade_widget_get_from_gobject (object), *glayout;
GladeWidget *gmodel = NULL;
GladeProperty *property;
gchar *attr_prop_name;
GList *l;
gint columns = 0;
static gint attr_len = 0;
if (!attr_len)
......@@ -10275,6 +10300,24 @@ glade_gtk_cell_renderer_set_attribute (GObject *object,
layout = GTK_CELL_LAYOUT (widget->parent->object);
cell = GTK_CELL_RENDERER (object);
glayout = glade_widget_get_from_gobject (layout);
if (glayout->parent && GTK_IS_TREE_VIEW (glayout->parent->object))
{
GtkTreeModel *model = NULL;
glade_widget_property_get (glayout->parent, "model", &model);
if (model)
gmodel = glade_widget_get_from_gobject (model);
}
if (gmodel)
{
GList *column_list = NULL;
glade_widget_property_get (gmodel, "columns", &column_list);
columns = g_list_length (column_list);
}
gtk_cell_layout_clear_attributes (layout, cell);
......@@ -10286,10 +10329,11 @@ glade_gtk_cell_renderer_set_attribute (GObject *object,
{
attr_prop_name = &property->klass->id[attr_len];
/* XXX TODO: Check that column doesnt exceed model bounds, and that
* cell supports the data type in the indexed column.
/* XXX TODO: Check that the cell supports the data type in the indexed column.
*/
if (g_value_get_int (property->value) >= 0)
if (g_value_get_int (property->value) >= 0 &&
/* We have to set attributes before parenting when loading */
(glade_util_object_is_loading (object) || g_value_get_int (property->value) < columns))
gtk_cell_layout_add_attribute (layout, cell,
attr_prop_name,
g_value_get_int (property->value));
......@@ -10325,29 +10369,6 @@ glade_gtk_cell_renderer_set_property (GladeWidgetAdaptor *adaptor,
value);
}
GladeEditorProperty *
glade_gtk_cell_renderer_create_eprop (GladeWidgetAdaptor *adaptor,
GladePropertyClass *klass,
gboolean use_command)
{
GladeEditorProperty *eprop;
/* chain up.. */
/* if (klass->pspec->value_type == GLADE_TYPE_CELL_ATTRIBUTE_LIST) */
/* eprop = g_object_new (GLADE_TYPE_EPROP_CELL_ATTRIBUTE_LIST, */
/* "property-class", klass, */
/* "use-command", use_command, */
/* NULL); */
/* else */
eprop = GWA_GET_CLASS
(G_TYPE_OBJECT)->create_eprop (adaptor,
klass,
use_command);
return eprop;
}
static void
glade_gtk_cell_renderer_write_properties (GladeWidget *widget,
GladeXmlContext *context,
......
......@@ -52,7 +52,7 @@ struct _GladeIconFactoryEditorClass
GtkVBoxClass parent;
};
GType glade_icon_factory_editor_get_type (void);
GType glade_icon_factory_editor_get_type (void) G_GNUC_CONST;
GtkWidget *glade_icon_factory_editor_new (GladeWidgetAdaptor *adaptor,
GladeEditable *editable);
......
......@@ -68,7 +68,7 @@ struct _GladeImageEditorClass
GtkVBoxClass parent;
};
GType glade_image_editor_get_type (void);
GType glade_image_editor_get_type (void) G_GNUC_CONST;
GtkWidget *glade_image_editor_new (GladeWidgetAdaptor *adaptor,
GladeEditable *editable);
......
......@@ -61,7 +61,7 @@ struct _GladeImageItemEditorClass
GtkVBoxClass parent;
};
GType glade_image_item_editor_get_type (void);
GType glade_image_item_editor_get_type (void) G_GNUC_CONST;
GtkWidget *glade_image_item_editor_new (GladeWidgetAdaptor *adaptor,
GladeEditable *editable);
......
......@@ -82,7 +82,7 @@ struct _GladeLabelEditorClass
GtkVBoxClass parent;
};
GType glade_label_editor_get_type (void);
GType glade_label_editor_get_type (void) G_GNUC_CONST;
GtkWidget *glade_label_editor_new (GladeWidgetAdaptor *adaptor,
GladeEditable *editable);
......
......@@ -52,7 +52,7 @@ struct _GladeStoreEditorClass
GtkVBoxClass parent;
};
GType glade_store_editor_get_type (void);
GType glade_store_editor_get_type (void) G_GNUC_CONST;
GtkWidget *glade_store_editor_new (GladeWidgetAdaptor *adaptor,
GladeEditable *editable);
......
......@@ -72,7 +72,7 @@ struct _GladeToolButtonEditorClass
GtkVBoxClass parent;
};
GType glade_tool_button_editor_get_type (void);
GType glade_tool_button_editor_get_type (void) G_GNUC_CONST;
GtkWidget *glade_tool_button_editor_new (GladeWidgetAdaptor *adaptor,
GladeEditable *editable);
......
......@@ -1922,6 +1922,7 @@ embedded in another object</_tooltip>
<glade-widget-class name="GtkCellRenderer" _title="Cell Renderer">
<post-create-function>glade_gtk_cell_renderer_post_create</post-create-function>
<create-editor-property-function>glade_gtk_cell_renderer_create_eprop</create-editor-property-function>
<create-editable-function>glade_gtk_cell_renderer_create_editable</create-editable-function>
<set-property-function>glade_gtk_cell_renderer_set_property</set-property-function>
<write-widget-function>glade_gtk_cell_renderer_write_widget</write-widget-function>
......
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