summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tvb@src.gnome.org>2008-11-23 20:24:27 +0000
committerTristan Van Berkom <tvb@src.gnome.org>2008-11-23 20:24:27 +0000
commit82c2cad3827b069eb9da6f6cd4fd5d4e7077c276 (patch)
tree80a245e483c39fbc72efabd6de153e7cfe2507a1
parent93bf0105b2a730aca7ef2f39ea4a1628bf88a00e (diff)
downloadglade-82c2cad3827b069eb9da6f6cd4fd5d4e7077c276.tar.gz
glade_widget_build_object() now calls glade_widget_set_object() internally
* gladeui/glade-widget.c: glade_widget_build_object() now calls glade_widget_set_object() internally and then uses glade_widget_adaptor_set_property() for non construct properties. * plugins/gtk+/glade-gtk.c, plugins/gtk+/gtk+.xml.in: - Made GtkTreeView:model property query user at create time. - Fixed to never sync properties when in attribute mode, to sync attributes after adding cells to cell layouts, and to not set attributes to orphan cells (net result: copy/paste of treeviews now result in a nice runtime replica). - Did some reordering in glade-gtk.c svn path=/trunk/; revision=2044
-rw-r--r--ChangeLog12
-rw-r--r--gladeui/glade-widget.c38
-rw-r--r--plugins/gtk+/glade-gtk.c1504
-rw-r--r--plugins/gtk+/gtk+.xml.in2
4 files changed, 816 insertions, 740 deletions
diff --git a/ChangeLog b/ChangeLog
index d6db0fd6..a09edeca 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2008-11-23 Tristan Van Berkom <tvb@gnome.org>
+
+ * gladeui/glade-widget.c: glade_widget_build_object() now calls glade_widget_set_object()
+ internally and then uses glade_widget_adaptor_set_property() for non construct properties.
+
+ * plugins/gtk+/glade-gtk.c, plugins/gtk+/gtk+.xml.in:
+ - Made GtkTreeView:model property query user at create time.
+ - Fixed to never sync properties when in attribute mode, to sync attributes
+ after adding cells to cell layouts, and to not set attributes to orphan cells
+ (net result: copy/paste of treeviews now result in a nice runtime replica).
+ - Did some reordering in glade-gtk.c
+
2008-11-22 Tristan Van Berkom <tvb@gnome.org>
* gladeui/glade-base-editor.c:
diff --git a/gladeui/glade-widget.c b/gladeui/glade-widget.c
index a41c4a3f..1fa06e6f 100644
--- a/gladeui/glade-widget.c
+++ b/gladeui/glade-widget.c
@@ -503,8 +503,8 @@ free_params (GParameter *params, guint n_params)
}
static GObject *
-glade_widget_build_object (GladeWidgetAdaptor *adaptor,
- GladeWidget *widget,
+glade_widget_build_object (GladeWidget *widget,
+ GladeWidget *template,
GladeCreateReason reason)
{
GParameter *params;
@@ -512,26 +512,32 @@ glade_widget_build_object (GladeWidgetAdaptor *adaptor,
guint n_params, i;
if (reason == GLADE_CREATE_LOAD)
- return glade_widget_adaptor_construct_object (adaptor, 0, NULL);
+ {
+ object = glade_widget_adaptor_construct_object (widget->adaptor, 0, NULL);
+ glade_widget_set_object (widget, object);
+ return object;
+ }
- if (widget)
- params = glade_widget_template_params (widget, TRUE, &n_params);
+ if (template)
+ params = glade_widget_template_params (template, TRUE, &n_params);
else
- params = glade_widget_adaptor_default_params (adaptor, TRUE, &n_params);
+ params = glade_widget_adaptor_default_params (widget->adaptor, TRUE, &n_params);
/* Create the new object with the correct parameters.
*/
- object = glade_widget_adaptor_construct_object (adaptor, n_params, params);
+ object = glade_widget_adaptor_construct_object (widget->adaptor, n_params, params);
free_params (params, n_params);
- if (widget)
- params = glade_widget_template_params (widget, FALSE, &n_params);
+ glade_widget_set_object (widget, object);
+
+ if (template)
+ params = glade_widget_template_params (template, FALSE, &n_params);
else
- params = glade_widget_adaptor_default_params (adaptor, FALSE, &n_params);
+ params = glade_widget_adaptor_default_params (widget->adaptor, FALSE, &n_params);
for (i = 0; i < n_params; i++)
- g_object_set_property (object, params[i].name, &(params[i].value));
+ glade_widget_adaptor_set_property (widget->adaptor, object, params[i].name, &(params[i].value));
free_params (params, n_params);
@@ -689,10 +695,9 @@ glade_widget_constructor (GType type,
if (gwidget->object == NULL)
{
- object = glade_widget_build_object(gwidget->adaptor,
+ object = glade_widget_build_object(gwidget,
gwidget->construct_template,
gwidget->construct_reason);
- glade_widget_set_object (gwidget, object);
}
/* Setup width/height */
@@ -1407,6 +1412,7 @@ glade_widget_dup_internal (GladeWidget *parent,
glade_widget_copy_packing_props (gwidget,
child_dup,
child_gwidget);
+
}
}
g_list_free (children);
@@ -1422,7 +1428,7 @@ glade_widget_dup_internal (GladeWidget *parent,
* default value, they need to be synced.
*/
glade_widget_sync_custom_props (gwidget);
-
+
/* Some properties may not be synced so we reload them */
for (l = gwidget->properties; l; l = l->next)
glade_property_load (GLADE_PROPERTY (l->data));
@@ -2262,10 +2268,8 @@ glade_widget_rebuild (GladeWidget *gwidget)
/* Hold a reference to the old widget while we transport properties
* and children from it
*/
- new_object = glade_widget_build_object(adaptor, gwidget, GLADE_CREATE_REBUILD);
old_object = g_object_ref(glade_widget_get_object (gwidget));
-
- glade_widget_set_object (gwidget, new_object);
+ new_object = glade_widget_build_object(gwidget, gwidget, GLADE_CREATE_REBUILD);
/* Only call this once the object has a proper GladeWidget */
glade_widget_adaptor_post_create (adaptor, new_object, GLADE_CREATE_REBUILD);
diff --git a/plugins/gtk+/glade-gtk.c b/plugins/gtk+/glade-gtk.c
index 4c9d5af9..255bb0e2 100644
--- a/plugins/gtk+/glade-gtk.c
+++ b/plugins/gtk+/glade-gtk.c
@@ -8874,6 +8874,395 @@ glade_gtk_size_group_set_property (GladeWidgetAdaptor *adaptor,
property_name, value);
}
+/*--------------------------- GtkIconFactory ---------------------------------*/
+#define GLADE_TAG_SOURCES "sources"
+#define GLADE_TAG_SOURCE "source"
+
+#define GLADE_TAG_STOCK_ID "stock-id"
+#define GLADE_TAG_FILENAME "filename"
+#define GLADE_TAG_DIRECTION "direction"
+#define GLADE_TAG_STATE "state"
+#define GLADE_TAG_SIZE "size"
+
+void
+glade_gtk_icon_factory_post_create (GladeWidgetAdaptor *adaptor,
+ GObject *object,
+ GladeCreateReason reason)
+{
+ gtk_icon_factory_add_default (GTK_ICON_FACTORY (object));
+}
+
+static void
+glade_gtk_icon_factory_read_sources (GladeWidget *widget,
+ GladeXmlNode *node)
+{
+ GladeIconSources *sources;
+ GtkIconSource *source;
+ GladeXmlNode *sources_node, *source_node;
+ GValue *value;
+ GList *list;
+ gchar *current_icon_name = NULL;
+ GdkPixbuf *pixbuf;
+
+ if ((sources_node = glade_xml_search_child (node, GLADE_TAG_SOURCES)) == NULL)
+ return;
+
+ sources = glade_icon_sources_new ();
+
+ /* Here we expect all icon sets to remain together in the list. */
+ for (source_node = glade_xml_node_get_children (sources_node); source_node;
+ source_node = glade_xml_node_next (source_node))
+ {
+ gchar *icon_name;
+ gchar *str;
+
+ if (!glade_xml_node_verify (source_node, GLADE_TAG_SOURCE))
+ continue;
+
+ if (!(icon_name =
+ glade_xml_get_property_string_required (source_node, GLADE_TAG_STOCK_ID, NULL)))
+ continue;
+
+ if (!(str = glade_xml_get_property_string_required (source_node, GLADE_TAG_FILENAME, NULL)))
+ {
+ g_free (icon_name);
+ continue;
+ }
+
+ if (!current_icon_name || strcmp (current_icon_name, icon_name) != 0)
+ current_icon_name = (g_free (current_icon_name), g_strdup (icon_name));
+
+ source = gtk_icon_source_new ();
+
+ /* Deal with the filename... */
+ value = glade_utils_value_from_string (GDK_TYPE_PIXBUF, str,
+ widget->project, widget);
+ pixbuf = g_value_dup_object (value);
+ g_value_unset (value);
+ g_free (value);
+
+ gtk_icon_source_set_pixbuf (source, pixbuf);
+ g_object_unref (G_OBJECT (pixbuf));
+ g_free (str);
+
+ /* Now the attributes... */
+ if ((str = glade_xml_get_property_string (source_node, GLADE_TAG_DIRECTION)) != NULL)
+ {
+ GtkTextDirection direction =
+ glade_utils_enum_value_from_string (GTK_TYPE_TEXT_DIRECTION, str);
+ gtk_icon_source_set_direction_wildcarded (source, FALSE);
+ gtk_icon_source_set_direction (source, direction);
+ g_free (str);
+ }
+
+ if ((str = glade_xml_get_property_string (source_node, GLADE_TAG_SIZE)) != NULL)
+ {
+ GtkIconSize size =
+ glade_utils_enum_value_from_string (GTK_TYPE_ICON_SIZE, str);
+ gtk_icon_source_set_size_wildcarded (source, FALSE);
+ gtk_icon_source_set_size (source, size);
+ g_free (str);
+ }
+
+ if ((str = glade_xml_get_property_string (source_node, GLADE_TAG_STATE)) != NULL)
+ {
+ GtkStateType state =
+ glade_utils_enum_value_from_string (GTK_TYPE_STATE_TYPE, str);
+ gtk_icon_source_set_state_wildcarded (source, FALSE);
+ gtk_icon_source_set_state (source, state);
+ g_free (str);
+ }
+
+ if ((list = g_hash_table_lookup (sources->sources, g_strdup (current_icon_name))) != NULL)
+ list = g_list_prepend (list, source);
+ else
+ {
+ list = g_list_append (NULL, source);
+ g_hash_table_insert (sources->sources, g_strdup (current_icon_name), list);
+ }
+ }
+
+ if (g_hash_table_size (sources->sources) > 0)
+ glade_widget_property_set (widget, "sources", sources);
+
+ glade_icon_sources_free (sources);
+}
+
+void
+glade_gtk_icon_factory_read_widget (GladeWidgetAdaptor *adaptor,
+ GladeWidget *widget,
+ GladeXmlNode *node)
+{
+ if (!glade_xml_node_verify
+ (node, GLADE_XML_TAG_WIDGET (glade_project_get_format (widget->project))))
+ return;
+
+ /* First chain up and read in any normal properties.. */
+ GWA_GET_CLASS (G_TYPE_OBJECT)->read_widget (adaptor, widget, node);
+
+ glade_gtk_icon_factory_read_sources (widget, node);
+}
+
+typedef struct {
+ GladeXmlContext *context;
+ GladeXmlNode *node;
+} SourceWriteTab;
+
+static void
+write_icon_sources (gchar *icon_name,
+ GList *sources,
+ SourceWriteTab *tab)
+{
+ GladeXmlNode *source_node;
+ GtkIconSource *source;
+ GList *l;
+ gchar *string;
+
+ GdkPixbuf *pixbuf;
+
+ for (l = sources; l; l = l->next)
+ {
+ source = l->data;
+
+ source_node = glade_xml_node_new (tab->context, GLADE_TAG_SOURCE);
+ glade_xml_node_append_child (tab->node, source_node);
+
+ glade_xml_node_set_property_string (source_node, GLADE_TAG_STOCK_ID, icon_name);
+
+ if (!gtk_icon_source_get_direction_wildcarded (source))
+ {
+ GtkTextDirection direction = gtk_icon_source_get_direction (source);
+ string = glade_utils_enum_string_from_value (GTK_TYPE_TEXT_DIRECTION, direction);
+ glade_xml_node_set_property_string (source_node, GLADE_TAG_DIRECTION, string);
+ g_free (string);
+ }
+
+ if (!gtk_icon_source_get_size_wildcarded (source))
+ {
+ GtkIconSize size = gtk_icon_source_get_size (source);
+ string = glade_utils_enum_string_from_value (GTK_TYPE_ICON_SIZE, size);
+ glade_xml_node_set_property_string (source_node, GLADE_TAG_SIZE, string);
+ g_free (string);
+ }
+
+ if (!gtk_icon_source_get_state_wildcarded (source))
+ {
+ GtkStateType state = gtk_icon_source_get_size (source);
+ string = glade_utils_enum_string_from_value (GTK_TYPE_STATE_TYPE, state);
+ glade_xml_node_set_property_string (source_node, GLADE_TAG_STATE, string);
+ g_free (string);
+ }
+
+ pixbuf = gtk_icon_source_get_pixbuf (source);
+ string = g_object_get_data (G_OBJECT (pixbuf), "GladeFileName");
+
+ glade_xml_node_set_property_string (source_node,
+ GLADE_TAG_FILENAME,
+ string);
+ }
+}
+
+
+static void
+glade_gtk_icon_factory_write_sources (GladeWidget *widget,
+ GladeXmlContext *context,
+ GladeXmlNode *node)
+{
+ GladeXmlNode *sources_node;
+ GladeIconSources *sources = NULL;
+ SourceWriteTab tab;
+
+ glade_widget_property_get (widget, "sources", &sources);
+ if (!sources)
+ return;
+
+ sources_node = glade_xml_node_new (context, GLADE_TAG_SOURCES);
+
+ tab.context = context;
+ tab.node = sources_node;
+ g_hash_table_foreach (sources->sources, (GHFunc)write_icon_sources, &tab);
+
+ if (!glade_xml_node_get_children (sources_node))
+ glade_xml_node_delete (sources_node);
+ else
+ glade_xml_node_append_child (node, sources_node);
+
+}
+
+
+void
+glade_gtk_icon_factory_write_widget (GladeWidgetAdaptor *adaptor,
+ GladeWidget *widget,
+ GladeXmlContext *context,
+ GladeXmlNode *node)
+{
+ if (!glade_xml_node_verify
+ (node, GLADE_XML_TAG_WIDGET (glade_project_get_format (widget->project))))
+ return;
+
+ /* First chain up and write all the normal properties.. */
+ GWA_GET_CLASS (G_TYPE_OBJECT)->write_widget (adaptor, widget, context, node);
+
+ glade_gtk_icon_factory_write_sources (widget, context, node);
+}
+
+static void
+apply_icon_sources (gchar *icon_name,
+ GList *sources,
+ GtkIconFactory *factory)
+{
+ GtkIconSource *source;
+ GtkIconSet *set;
+ GList *l;
+
+ set = gtk_icon_set_new ();
+
+ for (l = sources; l; l = l->next)
+ {
+ source = gtk_icon_source_copy ((GtkIconSource *)l->data);
+ gtk_icon_set_add_source (set, source);
+ }
+
+ gtk_icon_factory_add (factory, icon_name, set);
+}
+
+static void
+glade_gtk_icon_factory_set_sources (GObject *object, const GValue *value)
+{
+ GladeIconSources *sources = g_value_get_boxed (value);
+ if (sources)
+ g_hash_table_foreach (sources->sources, (GHFunc)apply_icon_sources, object);
+}
+
+
+void
+glade_gtk_icon_factory_set_property (GladeWidgetAdaptor *adaptor,
+ GObject *object,
+ const gchar *property_name,
+ const GValue *value)
+{
+ if (strcmp (property_name, "sources") == 0)
+ {
+ glade_gtk_icon_factory_set_sources (object, value);
+ }
+ else
+ /* Chain Up */
+ GWA_GET_CLASS (G_TYPE_OBJECT)->set_property (adaptor,
+ object,
+ property_name,
+ value);
+}
+
+static void
+serialize_icon_sources (gchar *icon_name,
+ GList *sources,
+ GString *string)
+{
+ GList *l;
+
+ for (l = sources; l; l = g_list_next (l))
+ {
+ GtkIconSource *source = l->data;
+ GdkPixbuf *pixbuf;
+ gchar *str;
+
+ pixbuf = gtk_icon_source_get_pixbuf (source);
+ str = g_object_get_data (G_OBJECT (pixbuf), "GladeFileName");
+
+ g_string_append_printf (string, "%s[%s] ", icon_name, str);
+
+ if (!gtk_icon_source_get_direction_wildcarded (source))
+ {
+ GtkTextDirection direction = gtk_icon_source_get_direction (source);
+ str = glade_utils_enum_string_from_value (GTK_TYPE_TEXT_DIRECTION, direction);
+ g_string_append_printf (string, "dir-%s ", str);
+ g_free (str);
+ }
+
+ if (!gtk_icon_source_get_size_wildcarded (source))
+ {
+ GtkIconSize size = gtk_icon_source_get_size (source);
+ str = glade_utils_enum_string_from_value (GTK_TYPE_ICON_SIZE, size);
+ g_string_append_printf (string, "size-%s ", str);
+ g_free (str);
+ }
+
+ if (!gtk_icon_source_get_state_wildcarded (source))
+ {
+ GtkStateType state = gtk_icon_source_get_state (source);
+ str = glade_utils_enum_string_from_value (GTK_TYPE_STATE_TYPE, state);
+ g_string_append_printf (string, "state-%s ", str);
+ g_free (str);
+ }
+
+ g_string_append_printf (string, "| ");
+ }
+}
+
+gchar *
+glade_gtk_icon_factory_string_from_value (GladeWidgetAdaptor *adaptor,
+ GladePropertyClass *klass,
+ const GValue *value,
+ GladeProjectFormat fmt)
+{
+ GString *string;
+
+ if (klass->pspec->value_type == GLADE_TYPE_ICON_SOURCES)
+ {
+ GladeIconSources *sources = g_value_get_boxed (value);
+ if (!sources)
+ return g_strdup ("");
+
+ string = g_string_new ("");
+ g_hash_table_foreach (sources->sources, (GHFunc)serialize_icon_sources, string);
+
+ return g_string_free (string, FALSE);
+ }
+ else
+ return GWA_GET_CLASS
+ (G_TYPE_OBJECT)->string_from_value (adaptor,
+ klass,
+ value,
+ fmt);
+}
+
+
+GladeEditorProperty *
+glade_gtk_icon_factory_create_eprop (GladeWidgetAdaptor *adaptor,
+ GladePropertyClass *klass,
+ gboolean use_command)
+{
+ GladeEditorProperty *eprop;
+
+ if (klass->pspec->value_type == GLADE_TYPE_ICON_SOURCES)
+ eprop = g_object_new (GLADE_TYPE_EPROP_ICON_SOURCES,
+ "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_icon_factory_create_editable (GladeWidgetAdaptor *adaptor,
+ GladeEditorPageType type)
+{
+ GladeEditable *editable;
+
+ /* Get base editable */
+ editable = GWA_GET_CLASS (G_TYPE_OBJECT)->create_editable (adaptor, type);
+
+ if (type == GLADE_PAGE_GENERAL)
+ return (GladeEditable *)glade_icon_factory_editor_new (adaptor, editable);
+
+ return editable;
+}
+
+
/*--------------------------- GtkListStore/GtkTreeStore ---------------------------------*/
#define GLADE_TAG_COLUMNS "columns"
@@ -9383,503 +9772,243 @@ glade_gtk_store_read_widget (GladeWidgetAdaptor *adaptor,
glade_gtk_store_read_data (widget, node);
}
+/*--------------------------- GtkCellRenderer ---------------------------------*/
+static void glade_gtk_treeview_launch_editor (GObject *treeview);
-/*--------------------------- GtkTreeView ---------------------------------*/
-static gchar *
-glade_gtk_treeview_get_display_name (GladeBaseEditor *editor,
- GladeWidget *gchild,
- gpointer user_data)
+void
+glade_gtk_cell_renderer_action_activate (GladeWidgetAdaptor *adaptor,
+ GObject *object,
+ const gchar *action_path)
{
- GObject *child = glade_widget_get_object (gchild);
- gchar *name;
-
- if (GTK_IS_TREE_VIEW_COLUMN (child))
- glade_widget_property_get (gchild, "title", &name);
+ if (strcmp (action_path, "launch_editor") == 0)
+ {
+ GladeWidget *w = glade_widget_get_from_gobject (object);
+
+ while ((w = glade_widget_get_parent (w)))
+ {
+ if (GTK_IS_TREE_VIEW (w->object))
+ {
+ glade_gtk_treeview_launch_editor (w->object);
+ break;
+ }
+ }
+ }
else
- name = gchild->name;
-
- return g_strdup (name);
+ GWA_GET_CLASS (G_TYPE_OBJECT)->action_activate (adaptor,
+ object,
+ action_path);
}
-static void
-glade_gtk_treeview_child_selected (GladeBaseEditor *editor,
- GladeWidget *gchild,
- gpointer data)
+void
+glade_gtk_cell_renderer_post_create (GladeWidgetAdaptor *adaptor,
+ GObject *object,
+ GladeCreateReason reason)
{
- GObject *child = glade_widget_get_object (gchild);
-
- glade_base_editor_add_label (editor, GTK_IS_TREE_VIEW_COLUMN (child) ?
- _("Tree View Column") : _("Cell Renderer"));
-
- glade_base_editor_add_default_properties (editor, gchild);
+ GladePropertyClass *pclass;
+ GladeProperty *property;
+ GladeWidget *widget;
+ GList *l;
- glade_base_editor_add_label (editor, GTK_IS_TREE_VIEW_COLUMN (child) ?
- _("Properties") : _("Properties and Attributes"));
- glade_base_editor_add_editable (editor, gchild, GLADE_PAGE_GENERAL);
+ widget = glade_widget_get_from_gobject (object);
- if (GTK_IS_CELL_RENDERER (child))
+ for (l = adaptor->properties; l; l = l->next)
{
- glade_base_editor_add_label (editor, _("Common Properties and Attributes"));
- glade_base_editor_add_editable (editor, gchild, GLADE_PAGE_COMMON);
- }
-}
-
-static gboolean
-glade_gtk_treeview_move_child (GladeBaseEditor *editor,
- GladeWidget *gparent,
- GladeWidget *gchild,
- gpointer data)
-{
- GObject *parent = glade_widget_get_object (gparent);
- GObject *child = glade_widget_get_object (gchild);
- GList list = { 0, };
+ pclass = l->data;
- if (GTK_IS_TREE_VIEW (parent) && !GTK_IS_TREE_VIEW_COLUMN (child))
- return FALSE;
- if (GTK_IS_TREE_VIEW_COLUMN (parent) && !GTK_IS_CELL_RENDERER (child))
- return FALSE;
- if (GTK_IS_CELL_RENDERER (parent))
- return FALSE;
-
- if (gparent != glade_widget_get_parent (gchild))
- {
- list.data = gchild;
- glade_command_dnd (&list, gparent, NULL);
+ if (strncmp (pclass->id, "use-attr-", strlen ("use-attr-")) == 0)
+ {
+ property = glade_widget_get_property (widget, pclass->id);
+ glade_property_sync (property);
+ }
}
-
- return TRUE;
}
-static void
-glade_gtk_treeview_launch_editor (GObject *treeview)
+GladeEditorProperty *
+glade_gtk_cell_renderer_create_eprop (GladeWidgetAdaptor *adaptor,
+ GladePropertyClass *klass,
+ gboolean use_command)
{
- GladeWidget *widget = glade_widget_get_from_gobject (treeview);
- GladeBaseEditor *editor;
- GladeEditable *treeview_editor;
- GtkWidget *window;
-
-
- treeview_editor = glade_widget_adaptor_create_editable (widget->adaptor, GLADE_PAGE_GENERAL);
- treeview_editor = (GladeEditable *)glade_tree_view_editor_new (widget->adaptor, treeview_editor);
-
- /* Editor */
- editor = glade_base_editor_new (treeview, treeview_editor,
- _("Column"), GTK_TYPE_TREE_VIEW_COLUMN,
- NULL);
-
- glade_base_editor_append_types (editor, GTK_TYPE_TREE_VIEW_COLUMN,
- _("Text"), GTK_TYPE_CELL_RENDERER_TEXT,
- _("Accelerator"), GTK_TYPE_CELL_RENDERER_ACCEL,
- _("Combo"), GTK_TYPE_CELL_RENDERER_COMBO,
- _("Spin"), GTK_TYPE_CELL_RENDERER_SPIN,
- _("Pixbuf"), GTK_TYPE_CELL_RENDERER_PIXBUF,
- _("Progress"), GTK_TYPE_CELL_RENDERER_PROGRESS,
- _("Toggle"), GTK_TYPE_CELL_RENDERER_TOGGLE,
- NULL);
-
- g_signal_connect (editor, "get-display-name", G_CALLBACK (glade_gtk_treeview_get_display_name), NULL);
- g_signal_connect (editor, "child-selected", G_CALLBACK (glade_gtk_treeview_child_selected), NULL);
- g_signal_connect (editor, "move-child", G_CALLBACK (glade_gtk_treeview_move_child), NULL);
-
- gtk_widget_show (GTK_WIDGET (editor));
-
- window = glade_base_editor_pack_new_window (editor, _("Tree View Editor"), NULL);
- gtk_widget_show (window);
-}
+ GladeEditorProperty *eprop;
-void
-glade_gtk_treeview_action_activate (GladeWidgetAdaptor *adaptor,
- GObject *object,
- const gchar *action_path)
-{
- if (strcmp (action_path, "launch_editor") == 0)
- {
- glade_gtk_treeview_launch_editor (object);
- }
+ 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
- GWA_GET_CLASS (GTK_TYPE_CONTAINER)->action_activate (adaptor,
- object,
- action_path);
-}
-
-static gint
-glade_gtk_treeview_get_column_index (GtkTreeView *view,
- GtkTreeViewColumn *column)
-{
- GtkTreeViewColumn *iter;
- gint i;
-
- for (i = 0; (iter = gtk_tree_view_get_column (view, i)) != NULL; i++)
- if (iter == column)
- return i;
-
- return -1;
+ eprop = GWA_GET_CLASS
+ (G_TYPE_OBJECT)->create_eprop (adaptor,
+ klass,
+ use_command);
+ return eprop;
}
-void
-glade_gtk_treeview_get_child_property (GladeWidgetAdaptor *adaptor,
- GObject *container,
- GObject *child,
- const gchar *property_name,
- GValue *value)
-{
- if (strcmp (property_name, "position") == 0)
- g_value_set_int (value,
- glade_gtk_treeview_get_column_index (GTK_TREE_VIEW (container),
- GTK_TREE_VIEW_COLUMN (child)));
- else
- /* Chain Up */
- GWA_GET_CLASS
- (GTK_TYPE_CONTAINER)->child_get_property (adaptor,
- container, child,
- property_name, value);
-}
-void
-glade_gtk_treeview_set_child_property (GladeWidgetAdaptor *adaptor,
- GObject *container,
- GObject *child,
- const gchar *property_name,
- const GValue *value)
+GladeEditable *
+glade_gtk_cell_renderer_create_editable (GladeWidgetAdaptor *adaptor,
+ GladeEditorPageType type)
{
- if (strcmp (property_name, "position") == 0)
- {
+ GladeEditable *editable;
- gtk_tree_view_remove_column (GTK_TREE_VIEW (container),
- GTK_TREE_VIEW_COLUMN (child));
- gtk_tree_view_insert_column (GTK_TREE_VIEW (container),
- GTK_TREE_VIEW_COLUMN (child),
- g_value_get_int (value));
- }
- else
- /* Chain Up */
- GWA_GET_CLASS
- (GTK_TYPE_CONTAINER)->child_set_property (adaptor,
- container, child,
- property_name, value);
-}
+ /* Get base editable */
+ editable = GWA_GET_CLASS (G_TYPE_OBJECT)->create_editable (adaptor, type);
-GList *
-glade_gtk_treeview_get_children (GladeWidgetAdaptor *adaptor,
- GtkTreeView *view)
-{
- return gtk_tree_view_get_columns (view);
+ if (type == GLADE_PAGE_GENERAL || type == GLADE_PAGE_COMMON)
+ return (GladeEditable *)glade_cell_renderer_editor_new (adaptor, type, editable);
+
+ return editable;
}
-void
-glade_gtk_treeview_add_child (GladeWidgetAdaptor *adaptor,
- GObject *container,
- GObject *child)
+static void
+glade_gtk_cell_renderer_set_use_attribute (GObject *object,
+ const gchar *property_name,
+ const GValue *value)
{
- GtkTreeView *view = GTK_TREE_VIEW (container);
- GtkTreeViewColumn *column;
+ GladeWidget *widget = glade_widget_get_from_gobject (object);
+ gchar *attr_prop_name, *prop_msg, *attr_msg;
- if (!GTK_IS_TREE_VIEW_COLUMN (child))
- return;
+ attr_prop_name = g_strdup_printf ("attr-%s", property_name);
- column = GTK_TREE_VIEW_COLUMN (child);
- gtk_tree_view_append_column (view, column);
-}
+ prop_msg = g_strdup_printf (_("%s is set to load %s from the model"),
+ widget->name, property_name);
+ attr_msg = g_strdup_printf (_("%s is set to manipulate %s directly"),
+ widget->name, attr_prop_name);
-void
-glade_gtk_treeview_remove_child (GladeWidgetAdaptor *adaptor,
- GObject *container,
- GObject *child)
-{
- GtkTreeView *view = GTK_TREE_VIEW (container);
- GtkTreeViewColumn *column;
+ glade_widget_property_set_sensitive (widget, property_name, FALSE, prop_msg);
+ glade_widget_property_set_sensitive (widget, attr_prop_name, FALSE, attr_msg);
- if (!GTK_IS_TREE_VIEW_COLUMN (child))
- return;
+ if (g_value_get_boolean (value))
+ glade_widget_property_set_sensitive (widget, attr_prop_name, TRUE, NULL);
+ else
+ glade_widget_property_set_sensitive (widget, property_name, TRUE, NULL);
- column = GTK_TREE_VIEW_COLUMN (child);
- gtk_tree_view_remove_column (view, column);
+ g_free (prop_msg);
+ g_free (attr_msg);
+ g_free (attr_prop_name);
}
-gboolean
-glade_gtk_treeview_depends (GladeWidgetAdaptor *adaptor,
- GladeWidget *widget,
- GladeWidget *another)
+static gboolean
+glade_gtk_cell_layout_has_renderer (GtkCellLayout *layout,
+ GtkCellRenderer *renderer)
{
- if (GTK_IS_TREE_MODEL (another->object))
- return TRUE;
+ GList *cells = gtk_cell_layout_get_cells (layout);
+ gboolean has_renderer;
- return GWA_GET_CLASS (GTK_TYPE_CONTAINER)->depends (adaptor, widget, another);
-}
-
-
-/*--------------------------- GtkIconFactory ---------------------------------*/
-#define GLADE_TAG_SOURCES "sources"
-#define GLADE_TAG_SOURCE "source"
+ has_renderer = (g_list_find (cells, renderer) != NULL);
-#define GLADE_TAG_STOCK_ID "stock-id"
-#define GLADE_TAG_FILENAME "filename"
-#define GLADE_TAG_DIRECTION "direction"
-#define GLADE_TAG_STATE "state"
-#define GLADE_TAG_SIZE "size"
+ g_list_free (cells);
-void
-glade_gtk_icon_factory_post_create (GladeWidgetAdaptor *adaptor,
- GObject *object,
- GladeCreateReason reason)
-{
- gtk_icon_factory_add_default (GTK_ICON_FACTORY (object));
+ return has_renderer;
}
static void
-glade_gtk_icon_factory_read_sources (GladeWidget *widget,
- GladeXmlNode *node)
+glade_gtk_cell_renderer_sync_attributes (GObject *object)
{
- GladeIconSources *sources;
- GtkIconSource *source;
- GladeXmlNode *sources_node, *source_node;
- GValue *value;
- GList *list;
- gchar *current_icon_name = NULL;
- GdkPixbuf *pixbuf;
- if ((sources_node = glade_xml_search_child (node, GLADE_TAG_SOURCES)) == NULL)
- return;
-
- sources = glade_icon_sources_new ();
-
- /* Here we expect all icon sets to remain together in the list. */
- for (source_node = glade_xml_node_get_children (sources_node); source_node;
- source_node = glade_xml_node_next (source_node))
- {
- gchar *icon_name;
- gchar *str;
-
- if (!glade_xml_node_verify (source_node, GLADE_TAG_SOURCE))
- continue;
-
- if (!(icon_name =
- glade_xml_get_property_string_required (source_node, GLADE_TAG_STOCK_ID, NULL)))
- continue;
-
- if (!(str = glade_xml_get_property_string_required (source_node, GLADE_TAG_FILENAME, NULL)))
- {
- g_free (icon_name);
- continue;
- }
+ GtkCellLayout *layout;
+ GtkCellRenderer *cell;
+ 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 (!current_icon_name || strcmp (current_icon_name, icon_name) != 0)
- current_icon_name = (g_free (current_icon_name), g_strdup (icon_name));
+ if (!attr_len)
+ attr_len = strlen ("attr-");
- source = gtk_icon_source_new ();
+ /* Apply attributes to renderer when bound to a model in runtime */
+ widget = glade_widget_get_from_gobject (object);
- /* Deal with the filename... */
- value = glade_utils_value_from_string (GDK_TYPE_PIXBUF, str,
- widget->project, widget);
- pixbuf = g_value_dup_object (value);
- g_value_unset (value);
- g_free (value);
-
- gtk_icon_source_set_pixbuf (source, pixbuf);
- g_object_unref (G_OBJECT (pixbuf));
- g_free (str);
-
- /* Now the attributes... */
- if ((str = glade_xml_get_property_string (source_node, GLADE_TAG_DIRECTION)) != NULL)
- {
- GtkTextDirection direction =
- glade_utils_enum_value_from_string (GTK_TYPE_TEXT_DIRECTION, str);
- gtk_icon_source_set_direction_wildcarded (source, FALSE);
- gtk_icon_source_set_direction (source, direction);
- g_free (str);
- }
-
- if ((str = glade_xml_get_property_string (source_node, GLADE_TAG_SIZE)) != NULL)
- {
- GtkIconSize size =
- glade_utils_enum_value_from_string (GTK_TYPE_ICON_SIZE, str);
- gtk_icon_source_set_size_wildcarded (source, FALSE);
- gtk_icon_source_set_size (source, size);
- g_free (str);
- }
-
- if ((str = glade_xml_get_property_string (source_node, GLADE_TAG_STATE)) != NULL)
- {
- GtkStateType state =
- glade_utils_enum_value_from_string (GTK_TYPE_STATE_TYPE, str);
- gtk_icon_source_set_state_wildcarded (source, FALSE);
- gtk_icon_source_set_state (source, state);
- g_free (str);
- }
-
- if ((list = g_hash_table_lookup (sources->sources, g_strdup (current_icon_name))) != NULL)
- list = g_list_prepend (list, source);
- else
- {
- list = g_list_append (NULL, source);
- g_hash_table_insert (sources->sources, g_strdup (current_icon_name), list);
- }
- }
-
- if (g_hash_table_size (sources->sources) > 0)
- glade_widget_property_set (widget, "sources", sources);
+ if (widget->parent == NULL) return;
- glade_icon_sources_free (sources);
-}
+ /* When creating widgets, sometimes the parent is set before parenting happens,
+ * here we have to be careful for that..
+ */
+ layout = GTK_CELL_LAYOUT (widget->parent->object);
+ cell = GTK_CELL_RENDERER (object);
+ glayout = glade_widget_get_from_gobject (layout);
-void
-glade_gtk_icon_factory_read_widget (GladeWidgetAdaptor *adaptor,
- GladeWidget *widget,
- GladeXmlNode *node)
-{
- if (!glade_xml_node_verify
- (node, GLADE_XML_TAG_WIDGET (glade_project_get_format (widget->project))))
+ if (!glade_gtk_cell_layout_has_renderer (layout, cell))
return;
- /* First chain up and read in any normal properties.. */
- GWA_GET_CLASS (G_TYPE_OBJECT)->read_widget (adaptor, widget, node);
-
- glade_gtk_icon_factory_read_sources (widget, node);
-}
-
-typedef struct {
- GladeXmlContext *context;
- GladeXmlNode *node;
-} SourceWriteTab;
-
-static void
-write_icon_sources (gchar *icon_name,
- GList *sources,
- SourceWriteTab *tab)
-{
- GladeXmlNode *source_node;
- GtkIconSource *source;
- GList *l;
- gchar *string;
+ if (glayout->parent && GTK_IS_TREE_VIEW (glayout->parent->object))
+ {
+ GtkTreeModel *model = NULL;
- GdkPixbuf *pixbuf;
+ glade_widget_property_get (glayout->parent, "model", &model);
+ if (model)
+ gmodel = glade_widget_get_from_gobject (model);
+ }
- for (l = sources; l; l = l->next)
+ if (gmodel)
{
- source = l->data;
+ GList *column_list = NULL;
+ glade_widget_property_get (gmodel, "columns", &column_list);
+ columns = g_list_length (column_list);
- source_node = glade_xml_node_new (tab->context, GLADE_TAG_SOURCE);
- glade_xml_node_append_child (tab->node, source_node);
+ }
- glade_xml_node_set_property_string (source_node, GLADE_TAG_STOCK_ID, icon_name);
+ gtk_cell_layout_clear_attributes (layout, cell);
- if (!gtk_icon_source_get_direction_wildcarded (source))
- {
- GtkTextDirection direction = gtk_icon_source_get_direction (source);
- string = glade_utils_enum_string_from_value (GTK_TYPE_TEXT_DIRECTION, direction);
- glade_xml_node_set_property_string (source_node, GLADE_TAG_DIRECTION, string);
- g_free (string);
- }
+ for (l = widget->properties; l; l = l->next)
+ {
+ property = l->data;
- if (!gtk_icon_source_get_size_wildcarded (source))
+ if (strncmp (property->klass->id, "attr-", attr_len) == 0)
{
- GtkIconSize size = gtk_icon_source_get_size (source);
- string = glade_utils_enum_string_from_value (GTK_TYPE_ICON_SIZE, size);
- glade_xml_node_set_property_string (source_node, GLADE_TAG_SIZE, string);
- g_free (string);
- }
+ attr_prop_name = &property->klass->id[attr_len];
- if (!gtk_icon_source_get_state_wildcarded (source))
- {
- GtkStateType state = gtk_icon_source_get_size (source);
- string = glade_utils_enum_string_from_value (GTK_TYPE_STATE_TYPE, state);
- glade_xml_node_set_property_string (source_node, GLADE_TAG_STATE, string);
- g_free (string);
+ /* XXX TODO: Check that the cell supports the data type in the indexed column.
+ */
+ if (g_value_get_int (property->value) >= 0 &&
+ /* We have to set attributes before parenting when loading */
+ (glade_widget_superuser () || g_value_get_int (property->value) < columns))
+ gtk_cell_layout_add_attribute (layout, cell,
+ attr_prop_name,
+ g_value_get_int (property->value));
}
-
- pixbuf = gtk_icon_source_get_pixbuf (source);
- string = g_object_get_data (G_OBJECT (pixbuf), "GladeFileName");
-
- glade_xml_node_set_property_string (source_node,
- GLADE_TAG_FILENAME,
- string);
}
}
-
-static void
-glade_gtk_icon_factory_write_sources (GladeWidget *widget,
- GladeXmlContext *context,
- GladeXmlNode *node)
+static gboolean
+glade_gtk_cell_renderer_property_enabled (GObject *object,
+ const gchar *property_name)
{
- GladeXmlNode *sources_node;
- GladeIconSources *sources = NULL;
- SourceWriteTab tab;
-
- glade_widget_property_get (widget, "sources", &sources);
- if (!sources)
- return;
-
- sources_node = glade_xml_node_new (context, GLADE_TAG_SOURCES);
+ GladeWidget *gwidget = glade_widget_get_from_gobject (object);
+ gchar *use_attr_name = g_strdup_printf ("use-attr-%s", property_name);
+ GladeProperty *property;
+ gboolean use_attr = TRUE;
- tab.context = context;
- tab.node = sources_node;
- g_hash_table_foreach (sources->sources, (GHFunc)write_icon_sources, &tab);
+ if ((property = glade_widget_get_property (gwidget, use_attr_name)) != NULL)
+ glade_property_get (property, &use_attr);
- if (!glade_xml_node_get_children (sources_node))
- glade_xml_node_delete (sources_node);
- else
- glade_xml_node_append_child (node, sources_node);
+ g_free (use_attr_name);
+ return !use_attr;
}
-
void
-glade_gtk_icon_factory_write_widget (GladeWidgetAdaptor *adaptor,
- GladeWidget *widget,
- GladeXmlContext *context,
- GladeXmlNode *node)
-{
- if (!glade_xml_node_verify
- (node, GLADE_XML_TAG_WIDGET (glade_project_get_format (widget->project))))
- return;
-
- /* First chain up and write all the normal properties.. */
- GWA_GET_CLASS (G_TYPE_OBJECT)->write_widget (adaptor, widget, context, node);
-
- glade_gtk_icon_factory_write_sources (widget, context, node);
-}
-
-static void
-apply_icon_sources (gchar *icon_name,
- GList *sources,
- GtkIconFactory *factory)
+glade_gtk_cell_renderer_set_property (GladeWidgetAdaptor *adaptor,
+ GObject *object,
+ const gchar *property_name,
+ const GValue *value)
{
- GtkIconSource *source;
- GtkIconSet *set;
- GList *l;
-
- set = gtk_icon_set_new ();
+ static gint use_attr_len = 0;
+ static gint attr_len = 0;
- for (l = sources; l; l = l->next)
+ if (!attr_len)
{
- source = gtk_icon_source_copy ((GtkIconSource *)l->data);
- gtk_icon_set_add_source (set, source);
+ use_attr_len = strlen ("use-attr-");
+ attr_len = strlen ("attr-");
}
- gtk_icon_factory_add (factory, icon_name, set);
-}
-
-static void
-glade_gtk_icon_factory_set_sources (GObject *object, const GValue *value)
-{
- GladeIconSources *sources = g_value_get_boxed (value);
- if (sources)
- g_hash_table_foreach (sources->sources, (GHFunc)apply_icon_sources, object);
-}
-
-
-void
-glade_gtk_icon_factory_set_property (GladeWidgetAdaptor *adaptor,
- GObject *object,
- const gchar *property_name,
- const GValue *value)
-{
- if (strcmp (property_name, "sources") == 0)
- {
- glade_gtk_icon_factory_set_sources (object, value);
- }
- else
+ if (strncmp (property_name, "use-attr-", use_attr_len) == 0)
+ glade_gtk_cell_renderer_set_use_attribute (object, &property_name[use_attr_len], value);
+ else if (strncmp (property_name, "attr-", attr_len) == 0)
+ glade_gtk_cell_renderer_sync_attributes (object);
+ else if (glade_gtk_cell_renderer_property_enabled (object, property_name))
/* Chain Up */
GWA_GET_CLASS (G_TYPE_OBJECT)->set_property (adaptor,
object,
@@ -9888,112 +10017,57 @@ glade_gtk_icon_factory_set_property (GladeWidgetAdaptor *adaptor,
}
static void
-serialize_icon_sources (gchar *icon_name,
- GList *sources,
- GString *string)
-{
+glade_gtk_cell_renderer_write_properties (GladeWidget *widget,
+ GladeXmlContext *context,
+ GladeXmlNode *node)
+{
+ GladeProperty *property, *prop;
+ gchar *attr_name;
GList *l;
-
- for (l = sources; l; l = g_list_next (l))
- {
- GtkIconSource *source = l->data;
- GdkPixbuf *pixbuf;
- gchar *str;
-
- pixbuf = gtk_icon_source_get_pixbuf (source);
- str = g_object_get_data (G_OBJECT (pixbuf), "GladeFileName");
-
- g_string_append_printf (string, "%s[%s] ", icon_name, str);
+ static gint attr_len = 0;
- if (!gtk_icon_source_get_direction_wildcarded (source))
- {
- GtkTextDirection direction = gtk_icon_source_get_direction (source);
- str = glade_utils_enum_string_from_value (GTK_TYPE_TEXT_DIRECTION, direction);
- g_string_append_printf (string, "dir-%s ", str);
- g_free (str);
- }
+ if (!attr_len)
+ attr_len = strlen ("attr-");
- if (!gtk_icon_source_get_size_wildcarded (source))
- {
- GtkIconSize size = gtk_icon_source_get_size (source);
- str = glade_utils_enum_string_from_value (GTK_TYPE_ICON_SIZE, size);
- g_string_append_printf (string, "size-%s ", str);
- g_free (str);
- }
+ for (l = widget->properties; l; l = l->next)
+ {
+ property = l->data;
- if (!gtk_icon_source_get_state_wildcarded (source))
+ if (strncmp (property->klass->id, "attr-", attr_len) == 0)
{
- GtkStateType state = gtk_icon_source_get_state (source);
- str = glade_utils_enum_string_from_value (GTK_TYPE_STATE_TYPE, state);
- g_string_append_printf (string, "state-%s ", str);
- g_free (str);
- }
-
- g_string_append_printf (string, "| ");
- }
-}
+ gchar *use_attr_str;
+ gboolean use_attr = FALSE;
-gchar *
-glade_gtk_icon_factory_string_from_value (GladeWidgetAdaptor *adaptor,
- GladePropertyClass *klass,
- const GValue *value,
- GladeProjectFormat fmt)
-{
- GString *string;
+ use_attr_str = g_strdup_printf ("use-%s", property->klass->id);
+ glade_widget_property_get (widget, use_attr_str, &use_attr);
- if (klass->pspec->value_type == GLADE_TYPE_ICON_SOURCES)
- {
- GladeIconSources *sources = g_value_get_boxed (value);
- if (!sources)
- return g_strdup ("");
+ attr_name = &property->klass->id[attr_len];
+ prop = glade_widget_get_property (widget, attr_name);
- string = g_string_new ("");
- g_hash_table_foreach (sources->sources, (GHFunc)serialize_icon_sources, string);
+ if (!use_attr && prop)
+ glade_property_write (prop, context, node);
- return g_string_free (string, FALSE);
+ g_free (use_attr_str);
+ }
}
- else
- return GWA_GET_CLASS
- (G_TYPE_OBJECT)->string_from_value (adaptor,
- klass,
- value,
- fmt);
}
-
-GladeEditorProperty *
-glade_gtk_icon_factory_create_eprop (GladeWidgetAdaptor *adaptor,
- GladePropertyClass *klass,
- gboolean use_command)
-{
- GladeEditorProperty *eprop;
-
- if (klass->pspec->value_type == GLADE_TYPE_ICON_SOURCES)
- eprop = g_object_new (GLADE_TYPE_EPROP_ICON_SOURCES,
- "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_icon_factory_create_editable (GladeWidgetAdaptor *adaptor,
- GladeEditorPageType type)
+void
+glade_gtk_cell_renderer_write_widget (GladeWidgetAdaptor *adaptor,
+ GladeWidget *widget,
+ GladeXmlContext *context,
+ GladeXmlNode *node)
{
- GladeEditable *editable;
-
- /* Get base editable */
- editable = GWA_GET_CLASS (G_TYPE_OBJECT)->create_editable (adaptor, type);
+ if (!glade_xml_node_verify
+ (node, GLADE_XML_TAG_WIDGET (glade_project_get_format (widget->project))))
+ return;
- if (type == GLADE_PAGE_GENERAL)
- return (GladeEditable *)glade_icon_factory_editor_new (adaptor, editable);
+ /* Write our normal properties, then chain up to write any other normal properties,
+ * then attributes
+ */
+ glade_gtk_cell_renderer_write_properties (widget, context, node);
- return editable;
+ GWA_GET_CLASS (G_TYPE_OBJECT)->write_widget (adaptor, widget, context, node);
}
/*--------------------------- GtkCellLayout ---------------------------------*/
@@ -10003,6 +10077,8 @@ glade_gtk_cell_layout_add_child (GladeWidgetAdaptor *adaptor,
GObject *child)
{
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (container), GTK_CELL_RENDERER (child), TRUE);
+
+ glade_gtk_cell_renderer_sync_attributes (child);
}
void
@@ -10224,6 +10300,24 @@ glade_gtk_cell_layout_write_child (GladeWidgetAdaptor *adaptor,
glade_gtk_cell_renderer_write_attributes (widget, context, child_node);
}
+static void
+glade_gtk_cell_layout_sync_attributes (GObject *layout)
+{
+ GladeWidget *gwidget = glade_widget_get_from_gobject (layout);
+ GObject *cell;
+ GList *children, *l;
+
+ children = glade_widget_adaptor_get_children (gwidget->adaptor, layout);
+ for (l = children; l; l = l->next)
+ {
+ cell = l->data;
+ if (!GTK_IS_CELL_RENDERER (cell))
+ continue;
+
+ glade_gtk_cell_renderer_sync_attributes (cell);
+ }
+ g_list_free (children);
+}
/*--------------------------- GtkTreeViewColumn ---------------------------------*/
void
@@ -10250,264 +10344,230 @@ glade_gtk_treeview_column_action_activate (GladeWidgetAdaptor *adaptor,
action_path);
}
-/*--------------------------- GtkCellRenderer ---------------------------------*/
-void
-glade_gtk_cell_renderer_action_activate (GladeWidgetAdaptor *adaptor,
- GObject *object,
- const gchar *action_path)
+
+
+/*--------------------------- GtkTreeView ---------------------------------*/
+static gchar *
+glade_gtk_treeview_get_display_name (GladeBaseEditor *editor,
+ GladeWidget *gchild,
+ gpointer user_data)
{
- if (strcmp (action_path, "launch_editor") == 0)
- {
- GladeWidget *w = glade_widget_get_from_gobject (object);
-
- while ((w = glade_widget_get_parent (w)))
- {
- if (GTK_IS_TREE_VIEW (w->object))
- {
- glade_gtk_treeview_launch_editor (w->object);
- break;
- }
- }
- }
+ GObject *child = glade_widget_get_object (gchild);
+ gchar *name;
+
+ if (GTK_IS_TREE_VIEW_COLUMN (child))
+ glade_widget_property_get (gchild, "title", &name);
else
- GWA_GET_CLASS (G_TYPE_OBJECT)->action_activate (adaptor,
- object,
- action_path);
+ name = gchild->name;
+
+ return g_strdup (name);
}
-void
-glade_gtk_cell_renderer_post_create (GladeWidgetAdaptor *adaptor,
- GObject *object,
- GladeCreateReason reason)
+static void
+glade_gtk_treeview_child_selected (GladeBaseEditor *editor,
+ GladeWidget *gchild,
+ gpointer data)
{
- GladePropertyClass *pclass;
- GladeProperty *property;
- GladeWidget *widget;
- GList *l;
+ GObject *child = glade_widget_get_object (gchild);
- widget = glade_widget_get_from_gobject (object);
+ glade_base_editor_add_label (editor, GTK_IS_TREE_VIEW_COLUMN (child) ?
+ _("Tree View Column") : _("Cell Renderer"));
+
+ glade_base_editor_add_default_properties (editor, gchild);
+
+ glade_base_editor_add_label (editor, GTK_IS_TREE_VIEW_COLUMN (child) ?
+ _("Properties") : _("Properties and Attributes"));
+ glade_base_editor_add_editable (editor, gchild, GLADE_PAGE_GENERAL);
- for (l = adaptor->properties; l; l = l->next)
+ if (GTK_IS_CELL_RENDERER (child))
{
- pclass = l->data;
-
- if (strncmp (pclass->id, "use-attr-", strlen ("use-attr-")) == 0)
- {
- property = glade_widget_get_property (widget, pclass->id);
- glade_property_sync (property);
- }
+ glade_base_editor_add_label (editor, _("Common Properties and Attributes"));
+ glade_base_editor_add_editable (editor, gchild, GLADE_PAGE_COMMON);
}
}
-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)
-{
- GladeEditable *editable;
-
- /* Get base editable */
- editable = GWA_GET_CLASS (G_TYPE_OBJECT)->create_editable (adaptor, type);
+static gboolean
+glade_gtk_treeview_move_child (GladeBaseEditor *editor,
+ GladeWidget *gparent,
+ GladeWidget *gchild,
+ gpointer data)
+{
+ GObject *parent = glade_widget_get_object (gparent);
+ GObject *child = glade_widget_get_object (gchild);
+ GList list = { 0, };
- if (type == GLADE_PAGE_GENERAL || type == GLADE_PAGE_COMMON)
- return (GladeEditable *)glade_cell_renderer_editor_new (adaptor, type, editable);
+ if (GTK_IS_TREE_VIEW (parent) && !GTK_IS_TREE_VIEW_COLUMN (child))
+ return FALSE;
+ if (GTK_IS_TREE_VIEW_COLUMN (parent) && !GTK_IS_CELL_RENDERER (child))
+ return FALSE;
+ if (GTK_IS_CELL_RENDERER (parent))
+ return FALSE;
+
+ if (gparent != glade_widget_get_parent (gchild))
+ {
+ list.data = gchild;
+ glade_command_dnd (&list, gparent, NULL);
+ }
- return editable;
+ return TRUE;
}
static void
-glade_gtk_cell_renderer_set_use_attribute (GObject *object,
- const gchar *property_name,
- const GValue *value)
+glade_gtk_treeview_launch_editor (GObject *treeview)
{
- GladeWidget *widget = glade_widget_get_from_gobject (object);
- gchar *attr_prop_name, *prop_msg, *attr_msg;
+ GladeWidget *widget = glade_widget_get_from_gobject (treeview);
+ GladeBaseEditor *editor;
+ GladeEditable *treeview_editor;
+ GtkWidget *window;
- attr_prop_name = g_strdup_printf ("attr-%s", property_name);
- prop_msg = g_strdup_printf (_("%s is set to load %s from the model"),
- widget->name, property_name);
- attr_msg = g_strdup_printf (_("%s is set to manipulate %s directly"),
- widget->name, attr_prop_name);
+ treeview_editor = glade_widget_adaptor_create_editable (widget->adaptor, GLADE_PAGE_GENERAL);
+ treeview_editor = (GladeEditable *)glade_tree_view_editor_new (widget->adaptor, treeview_editor);
- glade_widget_property_set_sensitive (widget, property_name, FALSE, prop_msg);
- glade_widget_property_set_sensitive (widget, attr_prop_name, FALSE, attr_msg);
+ /* Editor */
+ editor = glade_base_editor_new (treeview, treeview_editor,
+ _("Column"), GTK_TYPE_TREE_VIEW_COLUMN,
+ NULL);
- if (g_value_get_boolean (value))
- glade_widget_property_set_sensitive (widget, attr_prop_name, TRUE, NULL);
- else
- glade_widget_property_set_sensitive (widget, property_name, TRUE, NULL);
+ glade_base_editor_append_types (editor, GTK_TYPE_TREE_VIEW_COLUMN,
+ _("Text"), GTK_TYPE_CELL_RENDERER_TEXT,
+ _("Accelerator"), GTK_TYPE_CELL_RENDERER_ACCEL,
+ _("Combo"), GTK_TYPE_CELL_RENDERER_COMBO,
+ _("Spin"), GTK_TYPE_CELL_RENDERER_SPIN,
+ _("Pixbuf"), GTK_TYPE_CELL_RENDERER_PIXBUF,
+ _("Progress"), GTK_TYPE_CELL_RENDERER_PROGRESS,
+ _("Toggle"), GTK_TYPE_CELL_RENDERER_TOGGLE,
+ NULL);
- g_free (prop_msg);
- g_free (attr_msg);
- g_free (attr_prop_name);
-}
+ g_signal_connect (editor, "get-display-name", G_CALLBACK (glade_gtk_treeview_get_display_name), NULL);
+ g_signal_connect (editor, "child-selected", G_CALLBACK (glade_gtk_treeview_child_selected), NULL);
+ g_signal_connect (editor, "move-child", G_CALLBACK (glade_gtk_treeview_move_child), NULL);
+ gtk_widget_show (GTK_WIDGET (editor));
+
+ window = glade_base_editor_pack_new_window (editor, _("Tree View Editor"), NULL);
+ gtk_widget_show (window);
+}
-static void
-glade_gtk_cell_renderer_set_attribute (GObject *object,
- const gchar *property_name,
- const GValue *value)
+void
+glade_gtk_treeview_action_activate (GladeWidgetAdaptor *adaptor,
+ GObject *object,
+ const gchar *action_path)
{
- GtkCellLayout *layout;
- GtkCellRenderer *cell;
- 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)
- attr_len = strlen ("attr-");
-
- /* Apply attributes to renderer when bound to a model in runtime */
- widget = glade_widget_get_from_gobject (object);
-
- if (widget->parent == NULL) return;
-
- 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)
+ if (strcmp (action_path, "launch_editor") == 0)
{
- GList *column_list = NULL;
- glade_widget_property_get (gmodel, "columns", &column_list);
- columns = g_list_length (column_list);
-
+ glade_gtk_treeview_launch_editor (object);
}
+ else
+ GWA_GET_CLASS (GTK_TYPE_CONTAINER)->action_activate (adaptor,
+ object,
+ action_path);
+}
- gtk_cell_layout_clear_attributes (layout, cell);
-
- for (l = widget->properties; l; l = l->next)
- {
- property = l->data;
+static gint
+glade_gtk_treeview_get_column_index (GtkTreeView *view,
+ GtkTreeViewColumn *column)
+{
+ GtkTreeViewColumn *iter;
+ gint i;
- if (strncmp (property->klass->id, "attr-", attr_len) == 0)
- {
- attr_prop_name = &property->klass->id[attr_len];
+ for (i = 0; (iter = gtk_tree_view_get_column (view, i)) != NULL; i++)
+ if (iter == column)
+ return i;
- /* XXX TODO: Check that the cell supports the data type in the indexed column.
- */
- 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));
- }
- }
+ return -1;
}
+void
+glade_gtk_treeview_get_child_property (GladeWidgetAdaptor *adaptor,
+ GObject *container,
+ GObject *child,
+ const gchar *property_name,
+ GValue *value)
+{
+ if (strcmp (property_name, "position") == 0)
+ g_value_set_int (value,
+ glade_gtk_treeview_get_column_index (GTK_TREE_VIEW (container),
+ GTK_TREE_VIEW_COLUMN (child)));
+ else
+ /* Chain Up */
+ GWA_GET_CLASS
+ (GTK_TYPE_CONTAINER)->child_get_property (adaptor,
+ container, child,
+ property_name, value);
+}
void
-glade_gtk_cell_renderer_set_property (GladeWidgetAdaptor *adaptor,
- GObject *object,
- const gchar *property_name,
- const GValue *value)
+glade_gtk_treeview_set_child_property (GladeWidgetAdaptor *adaptor,
+ GObject *container,
+ GObject *child,
+ const gchar *property_name,
+ const GValue *value)
{
- static gint use_attr_len = 0;
- static gint attr_len = 0;
-
- if (!attr_len)
+ if (strcmp (property_name, "position") == 0)
{
- use_attr_len = strlen ("use-attr-");
- attr_len = strlen ("attr-");
- }
- if (strncmp (property_name, "use-attr-", use_attr_len) == 0)
- glade_gtk_cell_renderer_set_use_attribute (object, &property_name[use_attr_len], value);
- else if (strncmp (property_name, "attr-", attr_len) == 0)
- glade_gtk_cell_renderer_set_attribute (object, &property_name[attr_len], value);
+ gtk_tree_view_remove_column (GTK_TREE_VIEW (container),
+ GTK_TREE_VIEW_COLUMN (child));
+ gtk_tree_view_insert_column (GTK_TREE_VIEW (container),
+ GTK_TREE_VIEW_COLUMN (child),
+ g_value_get_int (value));
+ }
else
/* Chain Up */
- GWA_GET_CLASS (G_TYPE_OBJECT)->set_property (adaptor,
- object,
- property_name,
- value);
+ GWA_GET_CLASS
+ (GTK_TYPE_CONTAINER)->child_set_property (adaptor,
+ container, child,
+ property_name, value);
}
-static void
-glade_gtk_cell_renderer_write_properties (GladeWidget *widget,
- GladeXmlContext *context,
- GladeXmlNode *node)
+GList *
+glade_gtk_treeview_get_children (GladeWidgetAdaptor *adaptor,
+ GtkTreeView *view)
{
- GladeProperty *property, *prop;
- gchar *attr_name;
- GList *l;
- static gint attr_len = 0;
-
- if (!attr_len)
- attr_len = strlen ("attr-");
-
- for (l = widget->properties; l; l = l->next)
- {
- property = l->data;
-
- if (strncmp (property->klass->id, "attr-", attr_len) == 0)
- {
- gchar *use_attr_str;
- gboolean use_attr = FALSE;
+ return gtk_tree_view_get_columns (view);
+}
- use_attr_str = g_strdup_printf ("use-%s", property->klass->id);
- glade_widget_property_get (widget, use_attr_str, &use_attr);
+void
+glade_gtk_treeview_add_child (GladeWidgetAdaptor *adaptor,
+ GObject *container,
+ GObject *child)
+{
+ GtkTreeView *view = GTK_TREE_VIEW (container);
+ GtkTreeViewColumn *column;
- attr_name = &property->klass->id[attr_len];
- prop = glade_widget_get_property (widget, attr_name);
+ if (!GTK_IS_TREE_VIEW_COLUMN (child))
+ return;
- if (!use_attr && prop)
- glade_property_write (prop, context, node);
+ column = GTK_TREE_VIEW_COLUMN (child);
+ gtk_tree_view_append_column (view, column);
- g_free (use_attr_str);
- }
- }
+ glade_gtk_cell_layout_sync_attributes (G_OBJECT (column));
}
void
-glade_gtk_cell_renderer_write_widget (GladeWidgetAdaptor *adaptor,
- GladeWidget *widget,
- GladeXmlContext *context,
- GladeXmlNode *node)
+glade_gtk_treeview_remove_child (GladeWidgetAdaptor *adaptor,
+ GObject *container,
+ GObject *child)
{
- if (!glade_xml_node_verify
- (node, GLADE_XML_TAG_WIDGET (glade_project_get_format (widget->project))))
+ GtkTreeView *view = GTK_TREE_VIEW (container);
+ GtkTreeViewColumn *column;
+
+ if (!GTK_IS_TREE_VIEW_COLUMN (child))
return;
- /* Write our normal properties, then chain up to write any other normal properties,
- * then attributes
- */
- glade_gtk_cell_renderer_write_properties (widget, context, node);
+ column = GTK_TREE_VIEW_COLUMN (child);
+ gtk_tree_view_remove_column (view, column);
+}
- GWA_GET_CLASS (G_TYPE_OBJECT)->write_widget (adaptor, widget, context, node);
+gboolean
+glade_gtk_treeview_depends (GladeWidgetAdaptor *adaptor,
+ GladeWidget *widget,
+ GladeWidget *another)
+{
+ if (GTK_IS_TREE_MODEL (another->object))
+ return TRUE;
+
+ return GWA_GET_CLASS (GTK_TYPE_CONTAINER)->depends (adaptor, widget, another);
}
+
diff --git a/plugins/gtk+/gtk+.xml.in b/plugins/gtk+/gtk+.xml.in
index d4d27486..491fce0e 100644
--- a/plugins/gtk+/gtk+.xml.in
+++ b/plugins/gtk+/gtk+.xml.in
@@ -1814,7 +1814,7 @@ embedded in another object</_tooltip>
</property>
<property id="hadjustment" libglade-unsupported="True"/>
<property id="vadjustment" libglade-unsupported="True"/>
- <property id="model" create-type="GtkListStore" libglade-unsupported="True"/>
+ <property id="model" create-type="GtkListStore" query="True" libglade-unsupported="True"/>
</properties>
<packing-properties>