glade3 r2044 - in trunk: . gladeui plugins/gtk+
- From: tvb svn gnome org
- To: svn-commits-list gnome org
- Subject: glade3 r2044 - in trunk: . gladeui plugins/gtk+
- Date: Sun, 23 Nov 2008 20:24:27 +0000 (UTC)
Author: tvb
Date: Sun Nov 23 20:24:27 2008
New Revision: 2044
URL: http://svn.gnome.org/viewvc/glade3?rev=2044&view=rev
Log:
* 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
Modified:
trunk/ChangeLog
trunk/gladeui/glade-widget.c
trunk/plugins/gtk+/glade-gtk.c
trunk/plugins/gtk+/gtk+.xml.in
Modified: trunk/gladeui/glade-widget.c
==============================================================================
--- trunk/gladeui/glade-widget.c (original)
+++ trunk/gladeui/glade-widget.c Sun Nov 23 20:24:27 2008
@@ -503,8 +503,8 @@
}
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 @@
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 @@
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_copy_packing_props (gwidget,
child_dup,
child_gwidget);
+
}
}
g_list_free (children);
@@ -1422,7 +1428,7 @@
* 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 @@
/* 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);
Modified: trunk/plugins/gtk+/glade-gtk.c
==============================================================================
--- trunk/plugins/gtk+/glade-gtk.c (original)
+++ trunk/plugins/gtk+/glade-gtk.c Sun Nov 23 20:24:27 2008
@@ -8874,346 +8874,227 @@
property_name, value);
}
-/*--------------------------- GtkListStore/GtkTreeStore ---------------------------------*/
-
-#define GLADE_TAG_COLUMNS "columns"
-#define GLADE_TAG_COLUMN "column"
-#define GLADE_TAG_TYPE "type"
+/*--------------------------- GtkIconFactory ---------------------------------*/
+#define GLADE_TAG_SOURCES "sources"
+#define GLADE_TAG_SOURCE "source"
-#define GLADE_TAG_ROW "row"
-#define GLADE_TAG_DATA "data"
-#define GLADE_TAG_COL "col"
+#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"
-static void
-glade_gtk_store_set_columns (GObject *object,
- const GValue *value)
+void
+glade_gtk_icon_factory_post_create (GladeWidgetAdaptor *adaptor,
+ GObject *object,
+ GladeCreateReason reason)
{
- GList *l = g_value_get_boxed (value);
- gint i, n = g_list_length (l);
- GType *types = g_new (GType, n);
-
- for (i = 0; l; l = g_list_next (l), i++)
- {
- GladeColumnType *data = l->data;
- types[i] = data->type;
- }
-
- if (GTK_IS_LIST_STORE (object))
- gtk_list_store_set_column_types (GTK_LIST_STORE (object), n, types);
- else
- gtk_tree_store_set_column_types (GTK_TREE_STORE (object), n, types);
+ gtk_icon_factory_add_default (GTK_ICON_FACTORY (object));
}
static void
-glade_gtk_store_set_data (GObject *object,
- const GValue *value)
+glade_gtk_icon_factory_read_sources (GladeWidget *widget,
+ GladeXmlNode *node)
{
- GladeWidget *gwidget = glade_widget_get_from_gobject (object);
- GList *columns = NULL;
- GNode *data_tree, *row, *iter;
- gint colnum;
- GtkTreeIter row_iter;
- GladeModelData *data;
- GType column_type;
-
- if (GTK_IS_LIST_STORE (object))
- gtk_list_store_clear (GTK_LIST_STORE (object));
- else
- gtk_tree_store_clear (GTK_TREE_STORE (object));
-
- glade_widget_property_get (gwidget, "columns", &columns);
- data_tree = g_value_get_boxed (value);
-
- /* Nothing to enter without columns defined */
- if (!data_tree || !columns)
+ 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;
- for (row = data_tree->children; row; row = row->next)
+ 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))
{
- if (GTK_IS_LIST_STORE (object))
- gtk_list_store_append (GTK_LIST_STORE (object), &row_iter);
- else
- /* (for now no child data... ) */
- gtk_tree_store_append (GTK_TREE_STORE (object), &row_iter, NULL);
+ 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 ();
- for (colnum = 0, iter = row->children; iter;
- colnum++, iter = iter->next)
+ /* 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)
{
- data = iter->data;
+ 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 (!g_list_nth (columns, colnum))
- break;
+ 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);
+ }
- /* Abort if theres a type mismatch, the widget's being rebuilt
- * and a sync will come soon with the right values
- */
- column_type = gtk_tree_model_get_column_type (GTK_TREE_MODEL (object), colnum);
- if (!g_type_is_a (G_VALUE_TYPE (&data->value), column_type))
- break;
+ 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 (GTK_IS_LIST_STORE (object))
- gtk_list_store_set_value (GTK_LIST_STORE (object),
- &row_iter,
- colnum, &data->value);
- else
- gtk_tree_store_set_value (GTK_TREE_STORE (object),
- &row_iter,
- colnum, &data->value);
+ 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_store_set_property (GladeWidgetAdaptor *adaptor,
- GObject *object,
- const gchar *property_name,
- const GValue *value)
+glade_gtk_icon_factory_read_widget (GladeWidgetAdaptor *adaptor,
+ GladeWidget *widget,
+ GladeXmlNode *node)
{
- if (strcmp (property_name, "columns") == 0)
- {
- glade_gtk_store_set_columns (object, value);
- }
- else if (strcmp (property_name, "data") == 0)
- {
- glade_gtk_store_set_data (object, value);
- }
- else
- /* Chain Up */
- GWA_GET_CLASS (G_TYPE_OBJECT)->set_property (adaptor,
- object,
- property_name,
- value);
-}
+ if (!glade_xml_node_verify
+ (node, GLADE_XML_TAG_WIDGET (glade_project_get_format (widget->project))))
+ return;
-GladeEditorProperty *
-glade_gtk_store_create_eprop (GladeWidgetAdaptor *adaptor,
- GladePropertyClass *klass,
- gboolean use_command)
-{
- GladeEditorProperty *eprop;
+ /* First chain up and read in any normal properties.. */
+ GWA_GET_CLASS (G_TYPE_OBJECT)->read_widget (adaptor, widget, node);
- /* chain up.. */
- if (klass->pspec->value_type == GLADE_TYPE_COLUMN_TYPE_LIST)
- eprop = g_object_new (GLADE_TYPE_EPROP_COLUMN_TYPES,
- "property-class", klass,
- "use-command", use_command,
- NULL);
- else if (klass->pspec->value_type == GLADE_TYPE_MODEL_DATA_TREE)
- eprop = g_object_new (GLADE_TYPE_EPROP_MODEL_DATA,
- "property-class", klass,
- "use-command", use_command,
- NULL);
- else
- eprop = GWA_GET_CLASS
- (G_TYPE_OBJECT)->create_eprop (adaptor,
- klass,
- use_command);
- return eprop;
+ glade_gtk_icon_factory_read_sources (widget, node);
}
-GladeEditable *
-glade_gtk_store_create_editable (GladeWidgetAdaptor *adaptor,
- GladeEditorPageType type)
+typedef struct {
+ GladeXmlContext *context;
+ GladeXmlNode *node;
+} SourceWriteTab;
+
+static void
+write_icon_sources (gchar *icon_name,
+ GList *sources,
+ SourceWriteTab *tab)
{
- GladeEditable *editable;
+ GladeXmlNode *source_node;
+ GtkIconSource *source;
+ GList *l;
+ gchar *string;
- /* Get base editable */
- editable = GWA_GET_CLASS (G_TYPE_OBJECT)->create_editable (adaptor, type);
+ GdkPixbuf *pixbuf;
- if (type == GLADE_PAGE_GENERAL)
- return (GladeEditable *)glade_store_editor_new (adaptor, editable);
+ for (l = sources; l; l = l->next)
+ {
+ source = l->data;
- return editable;
-}
+ source_node = glade_xml_node_new (tab->context, GLADE_TAG_SOURCE);
+ glade_xml_node_append_child (tab->node, source_node);
-gchar *
-glade_gtk_store_string_from_value (GladeWidgetAdaptor *adaptor,
- GladePropertyClass *klass,
- const GValue *value,
- GladeProjectFormat fmt)
-{
- GString *string;
+ glade_xml_node_set_property_string (source_node, GLADE_TAG_STOCK_ID, icon_name);
- if (klass->pspec->value_type == GLADE_TYPE_COLUMN_TYPE_LIST)
- {
- GList *l;
- string = g_string_new ("");
- for (l = g_value_get_boxed (value); l; l = g_list_next (l))
+ if (!gtk_icon_source_get_direction_wildcarded (source))
{
- GladeColumnType *data = l->data;
- g_string_append_printf (string, (g_list_next (l)) ? "%s:%s|" : "%s:%s",
- g_type_name (data->type), data->column_name);
+ 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);
}
- return g_string_free (string, FALSE);
- }
- else if (klass->pspec->value_type == GLADE_TYPE_MODEL_DATA_TREE)
- {
- GladeModelData *data;
- GNode *data_tree, *row, *iter;
- gint rownum;
- gchar *str;
- gboolean is_last;
-
- /* Return a unique string for the backend to compare */
- data_tree = g_value_get_boxed (value);
-
- if (!data_tree || !data_tree->children)
- return g_strdup ("");
- string = g_string_new ("");
- for (rownum = 0, row = data_tree->children; row;
- rownum++, row = row->next)
+ if (!gtk_icon_source_get_size_wildcarded (source))
{
- for (iter = row->children; iter; iter = iter->next)
- {
- data = iter->data;
-
- str = glade_utils_string_from_value (&data->value, fmt);
-
- is_last = !row->next && !iter->next;
- g_string_append_printf (string, "%s[%d]:%s",
- data->name, rownum, str);
-
- if (data->i18n_translatable)
- g_string_append_printf (string, " translatable");
- if (data->i18n_context)
- g_string_append_printf (string, " i18n-context:%s", data->i18n_context);
- if (data->i18n_comment)
- g_string_append_printf (string, " i18n-comment:%s", data->i18n_comment);
-
- if (!is_last)
- g_string_append_printf (string, "|");
-
- g_free (str);
- }
+ 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);
}
- return g_string_free (string, FALSE);
- }
- else
- return GWA_GET_CLASS
- (G_TYPE_OBJECT)->string_from_value (adaptor,
- klass,
- value,
- fmt);
-}
-static void
-glade_gtk_store_write_columns (GladeWidget *widget,
- GladeXmlContext *context,
- GladeXmlNode *node)
-{
- GladeXmlNode *columns_node;
- GladeProperty *prop;
- GList *l;
+ 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);
+ }
- prop = glade_widget_get_property (widget, "columns");
+ pixbuf = gtk_icon_source_get_pixbuf (source);
+ string = g_object_get_data (G_OBJECT (pixbuf), "GladeFileName");
- columns_node = glade_xml_node_new (context, GLADE_TAG_COLUMNS);
-
- for (l = g_value_get_boxed (prop->value); l; l = g_list_next (l))
- {
- GladeColumnType *data = l->data;
- GladeXmlNode *column_node, *comment_node;
-
- /* Write column names in comments... */
- gchar *comment = g_strdup_printf (" column-name %s ", data->column_name);
- comment_node = glade_xml_node_new_comment (context, comment);
- glade_xml_node_append_child (columns_node, comment_node);
- g_free (comment);
-
- column_node = glade_xml_node_new (context, GLADE_TAG_COLUMN);
- glade_xml_node_append_child (columns_node, column_node);
- glade_xml_node_set_property_string (column_node, GLADE_TAG_TYPE,
- g_type_name (data->type));
+ glade_xml_node_set_property_string (source_node,
+ GLADE_TAG_FILENAME,
+ string);
}
-
- if (!glade_xml_node_get_children (columns_node))
- glade_xml_node_delete (columns_node);
- else
- glade_xml_node_append_child (node, columns_node);
-
}
+
static void
-glade_gtk_store_write_data (GladeWidget *widget,
- GladeXmlContext *context,
- GladeXmlNode *node)
+glade_gtk_icon_factory_write_sources (GladeWidget *widget,
+ GladeXmlContext *context,
+ GladeXmlNode *node)
{
- GladeXmlNode *data_node, *col_node, *row_node;
- GList *columns = NULL;
- GladeModelData *data;
- GNode *data_tree = NULL, *row, *iter;
- gint colnum;
-
- glade_widget_property_get (widget, "data", &data_tree);
- glade_widget_property_get (widget, "columns", &columns);
+ GladeXmlNode *sources_node;
+ GladeIconSources *sources = NULL;
+ SourceWriteTab tab;
- /* XXX log errors about data not fitting columns here when
- * loggin is available
- */
- if (!data_tree || !columns)
+ glade_widget_property_get (widget, "sources", &sources);
+ if (!sources)
return;
- data_node = glade_xml_node_new (context, GLADE_TAG_DATA);
-
- for (row = data_tree->children; row; row = row->next)
- {
- row_node = glade_xml_node_new (context, GLADE_TAG_ROW);
- glade_xml_node_append_child (data_node, row_node);
-
- for (colnum = 0, iter = row->children; iter;
- colnum++, iter = iter->next)
- {
- gchar *string, *column_number;
-
- data = iter->data;
-
- string = glade_utils_string_from_value (&data->value,
- glade_project_get_format (widget->project));
-
- /* XXX Log error: data col j exceeds columns on row i */
- if (!g_list_nth (columns, colnum))
- break;
-
- column_number = g_strdup_printf ("%d", colnum);
-
- col_node = glade_xml_node_new (context, GLADE_TAG_COL);
- glade_xml_node_append_child (row_node, col_node);
- glade_xml_node_set_property_string (col_node, GLADE_TAG_ID,
- column_number);
- glade_xml_set_content (col_node, string);
-
- if (data->i18n_translatable)
- glade_xml_node_set_property_string (col_node,
- GLADE_TAG_TRANSLATABLE,
- GLADE_XML_TAG_I18N_TRUE);
- if (data->i18n_context)
- glade_xml_node_set_property_string (col_node,
- GLADE_TAG_CONTEXT,
- data->i18n_context);
- if (data->i18n_comment)
- glade_xml_node_set_property_string (col_node,
- GLADE_TAG_COMMENT,
- data->i18n_comment);
+ sources_node = glade_xml_node_new (context, GLADE_TAG_SOURCES);
-
- g_free (column_number);
- g_free (string);
- }
- }
+ tab.context = context;
+ tab.node = sources_node;
+ g_hash_table_foreach (sources->sources, (GHFunc)write_icon_sources, &tab);
- if (!glade_xml_node_get_children (data_node))
- glade_xml_node_delete (data_node);
+ if (!glade_xml_node_get_children (sources_node))
+ glade_xml_node_delete (sources_node);
else
- glade_xml_node_append_child (node, data_node);
+ glade_xml_node_append_child (node, sources_node);
+
}
void
-glade_gtk_store_write_widget (GladeWidgetAdaptor *adaptor,
- GladeWidget *widget,
- GladeXmlContext *context,
- GladeXmlNode *node)
+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))))
@@ -9222,664 +9103,912 @@
/* First chain up and write all the normal properties.. */
GWA_GET_CLASS (G_TYPE_OBJECT)->write_widget (adaptor, widget, context, node);
- glade_gtk_store_write_columns (widget, context, node);
- glade_gtk_store_write_data (widget, context, node);
+ glade_gtk_icon_factory_write_sources (widget, context, node);
}
static void
-glade_gtk_store_read_columns (GladeWidget *widget, GladeXmlNode *node)
+apply_icon_sources (gchar *icon_name,
+ GList *sources,
+ GtkIconFactory *factory)
{
- GladeNameContext *context;
- GladeXmlNode *columns_node;
- GladeProperty *property;
- GladeXmlNode *prop;
- GList *types = NULL;
- GValue value = {0,};
- gchar column_name[256];
-
- column_name[0] = '\0';
- column_name[255] = '\0';
-
- if ((columns_node = glade_xml_search_child (node, GLADE_TAG_COLUMNS)) == NULL)
- return;
+ GtkIconSource *source;
+ GtkIconSet *set;
+ GList *l;
- context = glade_name_context_new ();
+ set = gtk_icon_set_new ();
- for (prop = glade_xml_node_get_children_with_comments (columns_node); prop;
- prop = glade_xml_node_next_with_comments (prop))
+ for (l = sources; l; l = l->next)
{
- GladeColumnType *data = g_new0 (GladeColumnType, 1);
- gchar *type, *comment_str, buffer[256];
-
- if (!glade_xml_node_verify_silent (prop, GLADE_TAG_COLUMN) &&
- !glade_xml_node_is_comment (prop)) continue;
+ source = gtk_icon_source_copy ((GtkIconSource *)l->data);
+ gtk_icon_set_add_source (set, source);
+ }
- if (glade_xml_node_is_comment (prop))
- {
- comment_str = glade_xml_get_content (prop);
- if (sscanf (comment_str, " column-name %s", buffer) == 1)
- strncpy (column_name, buffer, 255);
+ gtk_icon_factory_add (factory, icon_name, set);
+}
- g_free (comment_str);
- continue;
- }
+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);
+}
- type = glade_xml_get_property_string_required (prop, GLADE_TAG_TYPE, NULL);
- data->type = g_type_from_name (type);
- data->column_name = column_name[0] ? g_strdup (column_name) : g_ascii_strdown (type, -1);
- if (glade_name_context_has_name (context, data->column_name))
- {
- gchar *name = glade_name_context_new_name (context, data->column_name);
- g_free (data->column_name);
- data->column_name = name;
+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);
}
- glade_name_context_add_name (context, data->column_name);
- types = g_list_prepend (types, data);
- g_free (type);
+ g_string_append_printf (string, "| ");
+ }
+}
- column_name[0] = '\0';
+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);
}
-
- property = glade_widget_get_property (widget, "columns");
- g_value_init (&value, GLADE_TYPE_COLUMN_TYPE_LIST);
- g_value_take_boxed (&value, g_list_reverse (types));
- glade_property_set_value (property, &value);
- g_value_unset (&value);
+ else
+ return GWA_GET_CLASS
+ (G_TYPE_OBJECT)->string_from_value (adaptor,
+ klass,
+ value,
+ fmt);
}
-static void
-glade_gtk_store_read_data (GladeWidget *widget, GladeXmlNode *node)
+
+GladeEditorProperty *
+glade_gtk_icon_factory_create_eprop (GladeWidgetAdaptor *adaptor,
+ GladePropertyClass *klass,
+ gboolean use_command)
{
- GladeXmlNode *data_node, *row_node, *col_node;
- GNode *data_tree, *row, *item;
- GladeModelData *data;
- GValue *value;
- GList *column_types = NULL, *list;
- GladeColumnType *column_type;
- gint colnum;
+ GladeEditorProperty *eprop;
- if ((data_node = glade_xml_search_child (node, GLADE_TAG_DATA)) == NULL)
- return;
+ 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;
+}
- /* XXX FIXME: Warn that columns werent there when parsing */
- if (!glade_widget_property_get (widget, "columns", &column_types) || !column_types)
- return;
+GladeEditable *
+glade_gtk_icon_factory_create_editable (GladeWidgetAdaptor *adaptor,
+ GladeEditorPageType type)
+{
+ GladeEditable *editable;
- /* Create root... */
- data_tree = g_node_new (NULL);
-
- for (row_node = glade_xml_node_get_children (data_node); row_node;
- row_node = glade_xml_node_next (row_node))
- {
- gchar *value_str;
+ /* Get base editable */
+ editable = GWA_GET_CLASS (G_TYPE_OBJECT)->create_editable (adaptor, type);
- if (!glade_xml_node_verify (row_node, GLADE_TAG_ROW))
- continue;
+ if (type == GLADE_PAGE_GENERAL)
+ return (GladeEditable *)glade_icon_factory_editor_new (adaptor, editable);
- row = g_node_new (NULL);
- g_node_append (data_tree, row);
+ return editable;
+}
- /* XXX FIXME: we are assuming that the columns are listed in order */
- for (colnum = 0, col_node = glade_xml_node_get_children (row_node); col_node;
- col_node = glade_xml_node_next (col_node))
- {
- if (!glade_xml_node_verify (col_node, GLADE_TAG_COL))
- continue;
+/*--------------------------- GtkListStore/GtkTreeStore ---------------------------------*/
- if (!(list = g_list_nth (column_types, colnum)))
- /* XXX Log this too... */
- continue;
+#define GLADE_TAG_COLUMNS "columns"
+#define GLADE_TAG_COLUMN "column"
+#define GLADE_TAG_TYPE "type"
- column_type = list->data;
+#define GLADE_TAG_ROW "row"
+#define GLADE_TAG_DATA "data"
+#define GLADE_TAG_COL "col"
- /* XXX Do we need object properties to somehow work at load time here ??
- * should we be doing this part in "finished" ? ... todo thinkso...
- */
- value_str = glade_xml_get_content (col_node);
- value = glade_utils_value_from_string (column_type->type, value_str, widget->project, widget);
- g_free (value_str);
+static void
+glade_gtk_store_set_columns (GObject *object,
+ const GValue *value)
+{
+ GList *l = g_value_get_boxed (value);
+ gint i, n = g_list_length (l);
+ GType *types = g_new (GType, n);
- data = glade_model_data_new (column_type->type, column_type->column_name);
+ for (i = 0; l; l = g_list_next (l), i++)
+ {
+ GladeColumnType *data = l->data;
+ types[i] = data->type;
+ }
- g_value_copy (value, &data->value);
- g_value_unset (value);
- g_free (value);
+ if (GTK_IS_LIST_STORE (object))
+ gtk_list_store_set_column_types (GTK_LIST_STORE (object), n, types);
+ else
+ gtk_tree_store_set_column_types (GTK_TREE_STORE (object), n, types);
+}
- data->name = g_strdup (column_type->column_name);
- data->i18n_translatable = glade_xml_get_property_boolean (col_node, GLADE_TAG_TRANSLATABLE, FALSE);
- data->i18n_context = glade_xml_get_property_string (col_node, GLADE_TAG_CONTEXT);
- data->i18n_comment = glade_xml_get_property_string (col_node, GLADE_TAG_COMMENT);
+static void
+glade_gtk_store_set_data (GObject *object,
+ const GValue *value)
+{
+ GladeWidget *gwidget = glade_widget_get_from_gobject (object);
+ GList *columns = NULL;
+ GNode *data_tree, *row, *iter;
+ gint colnum;
+ GtkTreeIter row_iter;
+ GladeModelData *data;
+ GType column_type;
+
+ if (GTK_IS_LIST_STORE (object))
+ gtk_list_store_clear (GTK_LIST_STORE (object));
+ else
+ gtk_tree_store_clear (GTK_TREE_STORE (object));
+
+ glade_widget_property_get (gwidget, "columns", &columns);
+ data_tree = g_value_get_boxed (value);
+
+ /* Nothing to enter without columns defined */
+ if (!data_tree || !columns)
+ return;
- item = g_node_new (data);
- g_node_append (row, item);
+ for (row = data_tree->children; row; row = row->next)
+ {
+ if (GTK_IS_LIST_STORE (object))
+ gtk_list_store_append (GTK_LIST_STORE (object), &row_iter);
+ else
+ /* (for now no child data... ) */
+ gtk_tree_store_append (GTK_TREE_STORE (object), &row_iter, NULL);
+
+ for (colnum = 0, iter = row->children; iter;
+ colnum++, iter = iter->next)
+ {
+ data = iter->data;
- /* dont increment colnum on invalid xml tags... */
- colnum++;
+ if (!g_list_nth (columns, colnum))
+ break;
+
+ /* Abort if theres a type mismatch, the widget's being rebuilt
+ * and a sync will come soon with the right values
+ */
+ column_type = gtk_tree_model_get_column_type (GTK_TREE_MODEL (object), colnum);
+ if (!g_type_is_a (G_VALUE_TYPE (&data->value), column_type))
+ break;
+
+ if (GTK_IS_LIST_STORE (object))
+ gtk_list_store_set_value (GTK_LIST_STORE (object),
+ &row_iter,
+ colnum, &data->value);
+ else
+ gtk_tree_store_set_value (GTK_TREE_STORE (object),
+ &row_iter,
+ colnum, &data->value);
}
}
+}
- if (data_tree->children)
- glade_widget_property_set (widget, "data", data_tree);
+void
+glade_gtk_store_set_property (GladeWidgetAdaptor *adaptor,
+ GObject *object,
+ const gchar *property_name,
+ const GValue *value)
+{
+ if (strcmp (property_name, "columns") == 0)
+ {
+ glade_gtk_store_set_columns (object, value);
+ }
+ else if (strcmp (property_name, "data") == 0)
+ {
+ glade_gtk_store_set_data (object, value);
+ }
+ else
+ /* Chain Up */
+ GWA_GET_CLASS (G_TYPE_OBJECT)->set_property (adaptor,
+ object,
+ property_name,
+ value);
+}
- glade_model_data_tree_free (data_tree);
+GladeEditorProperty *
+glade_gtk_store_create_eprop (GladeWidgetAdaptor *adaptor,
+ GladePropertyClass *klass,
+ gboolean use_command)
+{
+ GladeEditorProperty *eprop;
+
+ /* chain up.. */
+ if (klass->pspec->value_type == GLADE_TYPE_COLUMN_TYPE_LIST)
+ eprop = g_object_new (GLADE_TYPE_EPROP_COLUMN_TYPES,
+ "property-class", klass,
+ "use-command", use_command,
+ NULL);
+ else if (klass->pspec->value_type == GLADE_TYPE_MODEL_DATA_TREE)
+ eprop = g_object_new (GLADE_TYPE_EPROP_MODEL_DATA,
+ "property-class", klass,
+ "use-command", use_command,
+ NULL);
+ else
+ eprop = GWA_GET_CLASS
+ (G_TYPE_OBJECT)->create_eprop (adaptor,
+ klass,
+ use_command);
+ return eprop;
}
-void
-glade_gtk_store_read_widget (GladeWidgetAdaptor *adaptor,
- GladeWidget *widget,
- GladeXmlNode *node)
+GladeEditable *
+glade_gtk_store_create_editable (GladeWidgetAdaptor *adaptor,
+ GladeEditorPageType type)
{
- if (!glade_xml_node_verify
- (node, GLADE_XML_TAG_WIDGET (glade_project_get_format (widget->project))))
- return;
+ GladeEditable *editable;
- /* First chain up and read in all the normal properties.. */
- GWA_GET_CLASS (G_TYPE_OBJECT)->read_widget (adaptor, widget, node);
+ /* Get base editable */
+ editable = GWA_GET_CLASS (G_TYPE_OBJECT)->create_editable (adaptor, type);
- glade_gtk_store_read_columns (widget, node);
- glade_gtk_store_read_data (widget, node);
+ if (type == GLADE_PAGE_GENERAL)
+ return (GladeEditable *)glade_store_editor_new (adaptor, editable);
+
+ return editable;
}
+gchar *
+glade_gtk_store_string_from_value (GladeWidgetAdaptor *adaptor,
+ GladePropertyClass *klass,
+ const GValue *value,
+ GladeProjectFormat fmt)
+{
+ GString *string;
+
+ if (klass->pspec->value_type == GLADE_TYPE_COLUMN_TYPE_LIST)
+ {
+ GList *l;
+ string = g_string_new ("");
+ for (l = g_value_get_boxed (value); l; l = g_list_next (l))
+ {
+ GladeColumnType *data = l->data;
+ g_string_append_printf (string, (g_list_next (l)) ? "%s:%s|" : "%s:%s",
+ g_type_name (data->type), data->column_name);
+ }
+ return g_string_free (string, FALSE);
+ }
+ else if (klass->pspec->value_type == GLADE_TYPE_MODEL_DATA_TREE)
+ {
+ GladeModelData *data;
+ GNode *data_tree, *row, *iter;
+ gint rownum;
+ gchar *str;
+ gboolean is_last;
+
+ /* Return a unique string for the backend to compare */
+ data_tree = g_value_get_boxed (value);
+
+ if (!data_tree || !data_tree->children)
+ return g_strdup ("");
+
+ string = g_string_new ("");
+ for (rownum = 0, row = data_tree->children; row;
+ rownum++, row = row->next)
+ {
+ for (iter = row->children; iter; iter = iter->next)
+ {
+ data = iter->data;
+
+ str = glade_utils_string_from_value (&data->value, fmt);
+
+ is_last = !row->next && !iter->next;
+ g_string_append_printf (string, "%s[%d]:%s",
+ data->name, rownum, str);
+
+ if (data->i18n_translatable)
+ g_string_append_printf (string, " translatable");
+ if (data->i18n_context)
+ g_string_append_printf (string, " i18n-context:%s", data->i18n_context);
+ if (data->i18n_comment)
+ g_string_append_printf (string, " i18n-comment:%s", data->i18n_comment);
+
+ if (!is_last)
+ g_string_append_printf (string, "|");
-/*--------------------------- GtkTreeView ---------------------------------*/
-static gchar *
-glade_gtk_treeview_get_display_name (GladeBaseEditor *editor,
- GladeWidget *gchild,
- gpointer user_data)
-{
- GObject *child = glade_widget_get_object (gchild);
- gchar *name;
-
- if (GTK_IS_TREE_VIEW_COLUMN (child))
- glade_widget_property_get (gchild, "title", &name);
+ g_free (str);
+ }
+ }
+ return g_string_free (string, FALSE);
+ }
else
- name = gchild->name;
-
- return g_strdup (name);
+ return GWA_GET_CLASS
+ (G_TYPE_OBJECT)->string_from_value (adaptor,
+ klass,
+ value,
+ fmt);
}
static void
-glade_gtk_treeview_child_selected (GladeBaseEditor *editor,
- GladeWidget *gchild,
- gpointer data)
+glade_gtk_store_write_columns (GladeWidget *widget,
+ GladeXmlContext *context,
+ GladeXmlNode *node)
{
- 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);
-
- 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);
-
- if (GTK_IS_CELL_RENDERER (child))
- {
- glade_base_editor_add_label (editor, _("Common Properties and Attributes"));
- glade_base_editor_add_editable (editor, gchild, GLADE_PAGE_COMMON);
- }
-}
+ GladeXmlNode *columns_node;
+ GladeProperty *prop;
+ GList *l;
-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, };
+ prop = glade_widget_get_property (widget, "columns");
- 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;
+ columns_node = glade_xml_node_new (context, GLADE_TAG_COLUMNS);
- if (gparent != glade_widget_get_parent (gchild))
+ for (l = g_value_get_boxed (prop->value); l; l = g_list_next (l))
{
- list.data = gchild;
- glade_command_dnd (&list, gparent, NULL);
+ GladeColumnType *data = l->data;
+ GladeXmlNode *column_node, *comment_node;
+
+ /* Write column names in comments... */
+ gchar *comment = g_strdup_printf (" column-name %s ", data->column_name);
+ comment_node = glade_xml_node_new_comment (context, comment);
+ glade_xml_node_append_child (columns_node, comment_node);
+ g_free (comment);
+
+ column_node = glade_xml_node_new (context, GLADE_TAG_COLUMN);
+ glade_xml_node_append_child (columns_node, column_node);
+ glade_xml_node_set_property_string (column_node, GLADE_TAG_TYPE,
+ g_type_name (data->type));
}
- return TRUE;
+ if (!glade_xml_node_get_children (columns_node))
+ glade_xml_node_delete (columns_node);
+ else
+ glade_xml_node_append_child (node, columns_node);
+
}
static void
-glade_gtk_treeview_launch_editor (GObject *treeview)
+glade_gtk_store_write_data (GladeWidget *widget,
+ GladeXmlContext *context,
+ GladeXmlNode *node)
{
- 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);
+ GladeXmlNode *data_node, *col_node, *row_node;
+ GList *columns = NULL;
+ GladeModelData *data;
+ GNode *data_tree = NULL, *row, *iter;
+ gint colnum;
- 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);
+ glade_widget_property_get (widget, "data", &data_tree);
+ glade_widget_property_get (widget, "columns", &columns);
- 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);
+ /* XXX log errors about data not fitting columns here when
+ * loggin is available
+ */
+ if (!data_tree || !columns)
+ return;
- gtk_widget_show (GTK_WIDGET (editor));
-
- window = glade_base_editor_pack_new_window (editor, _("Tree View Editor"), NULL);
- gtk_widget_show (window);
-}
+ data_node = glade_xml_node_new (context, GLADE_TAG_DATA);
-void
-glade_gtk_treeview_action_activate (GladeWidgetAdaptor *adaptor,
- GObject *object,
- const gchar *action_path)
-{
- if (strcmp (action_path, "launch_editor") == 0)
+ for (row = data_tree->children; row; row = row->next)
{
- glade_gtk_treeview_launch_editor (object);
- }
- else
- GWA_GET_CLASS (GTK_TYPE_CONTAINER)->action_activate (adaptor,
- object,
- action_path);
-}
+ row_node = glade_xml_node_new (context, GLADE_TAG_ROW);
+ glade_xml_node_append_child (data_node, row_node);
-static gint
-glade_gtk_treeview_get_column_index (GtkTreeView *view,
- GtkTreeViewColumn *column)
-{
- GtkTreeViewColumn *iter;
- gint i;
+ for (colnum = 0, iter = row->children; iter;
+ colnum++, iter = iter->next)
+ {
+ gchar *string, *column_number;
- for (i = 0; (iter = gtk_tree_view_get_column (view, i)) != NULL; i++)
- if (iter == column)
- return i;
+ data = iter->data;
- return -1;
-}
+ string = glade_utils_string_from_value (&data->value,
+ glade_project_get_format (widget->project));
-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);
-}
+ /* XXX Log error: data col j exceeds columns on row i */
+ if (!g_list_nth (columns, colnum))
+ break;
+
+ column_number = g_strdup_printf ("%d", colnum);
+
+ col_node = glade_xml_node_new (context, GLADE_TAG_COL);
+ glade_xml_node_append_child (row_node, col_node);
+ glade_xml_node_set_property_string (col_node, GLADE_TAG_ID,
+ column_number);
+ glade_xml_set_content (col_node, string);
-void
-glade_gtk_treeview_set_child_property (GladeWidgetAdaptor *adaptor,
- GObject *container,
- GObject *child,
- const gchar *property_name,
- const GValue *value)
-{
- if (strcmp (property_name, "position") == 0)
- {
+ if (data->i18n_translatable)
+ glade_xml_node_set_property_string (col_node,
+ GLADE_TAG_TRANSLATABLE,
+ GLADE_XML_TAG_I18N_TRUE);
+ if (data->i18n_context)
+ glade_xml_node_set_property_string (col_node,
+ GLADE_TAG_CONTEXT,
+ data->i18n_context);
+ if (data->i18n_comment)
+ glade_xml_node_set_property_string (col_node,
+ GLADE_TAG_COMMENT,
+ data->i18n_comment);
- 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));
+
+ g_free (column_number);
+ g_free (string);
+ }
}
+
+ if (!glade_xml_node_get_children (data_node))
+ glade_xml_node_delete (data_node);
else
- /* Chain Up */
- GWA_GET_CLASS
- (GTK_TYPE_CONTAINER)->child_set_property (adaptor,
- container, child,
- property_name, value);
+ glade_xml_node_append_child (node, data_node);
}
-GList *
-glade_gtk_treeview_get_children (GladeWidgetAdaptor *adaptor,
- GtkTreeView *view)
-{
- return gtk_tree_view_get_columns (view);
-}
void
-glade_gtk_treeview_add_child (GladeWidgetAdaptor *adaptor,
- GObject *container,
- GObject *child)
+glade_gtk_store_write_widget (GladeWidgetAdaptor *adaptor,
+ GladeWidget *widget,
+ GladeXmlContext *context,
+ GladeXmlNode *node)
{
- GtkTreeView *view = GTK_TREE_VIEW (container);
- GtkTreeViewColumn *column;
-
- if (!GTK_IS_TREE_VIEW_COLUMN (child))
+ if (!glade_xml_node_verify
+ (node, GLADE_XML_TAG_WIDGET (glade_project_get_format (widget->project))))
return;
- column = GTK_TREE_VIEW_COLUMN (child);
- gtk_tree_view_append_column (view, column);
+ /* First chain up and write all the normal properties.. */
+ GWA_GET_CLASS (G_TYPE_OBJECT)->write_widget (adaptor, widget, context, node);
+
+ glade_gtk_store_write_columns (widget, context, node);
+ glade_gtk_store_write_data (widget, context, node);
}
-void
-glade_gtk_treeview_remove_child (GladeWidgetAdaptor *adaptor,
- GObject *container,
- GObject *child)
+static void
+glade_gtk_store_read_columns (GladeWidget *widget, GladeXmlNode *node)
{
- GtkTreeView *view = GTK_TREE_VIEW (container);
- GtkTreeViewColumn *column;
+ GladeNameContext *context;
+ GladeXmlNode *columns_node;
+ GladeProperty *property;
+ GladeXmlNode *prop;
+ GList *types = NULL;
+ GValue value = {0,};
+ gchar column_name[256];
- if (!GTK_IS_TREE_VIEW_COLUMN (child))
+ column_name[0] = '\0';
+ column_name[255] = '\0';
+
+ if ((columns_node = glade_xml_search_child (node, GLADE_TAG_COLUMNS)) == NULL)
return;
- column = GTK_TREE_VIEW_COLUMN (child);
- gtk_tree_view_remove_column (view, column);
-}
+ context = glade_name_context_new ();
-gboolean
-glade_gtk_treeview_depends (GladeWidgetAdaptor *adaptor,
- GladeWidget *widget,
- GladeWidget *another)
-{
- if (GTK_IS_TREE_MODEL (another->object))
- return TRUE;
+ for (prop = glade_xml_node_get_children_with_comments (columns_node); prop;
+ prop = glade_xml_node_next_with_comments (prop))
+ {
+ GladeColumnType *data = g_new0 (GladeColumnType, 1);
+ gchar *type, *comment_str, buffer[256];
- return GWA_GET_CLASS (GTK_TYPE_CONTAINER)->depends (adaptor, widget, another);
-}
+ if (!glade_xml_node_verify_silent (prop, GLADE_TAG_COLUMN) &&
+ !glade_xml_node_is_comment (prop)) continue;
+ if (glade_xml_node_is_comment (prop))
+ {
+ comment_str = glade_xml_get_content (prop);
+ if (sscanf (comment_str, " column-name %s", buffer) == 1)
+ strncpy (column_name, buffer, 255);
-/*--------------------------- GtkIconFactory ---------------------------------*/
-#define GLADE_TAG_SOURCES "sources"
-#define GLADE_TAG_SOURCE "source"
+ g_free (comment_str);
+ continue;
+ }
-#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"
+ type = glade_xml_get_property_string_required (prop, GLADE_TAG_TYPE, NULL);
+ data->type = g_type_from_name (type);
+ data->column_name = column_name[0] ? g_strdup (column_name) : g_ascii_strdown (type, -1);
-void
-glade_gtk_icon_factory_post_create (GladeWidgetAdaptor *adaptor,
- GObject *object,
- GladeCreateReason reason)
-{
- gtk_icon_factory_add_default (GTK_ICON_FACTORY (object));
+ if (glade_name_context_has_name (context, data->column_name))
+ {
+ gchar *name = glade_name_context_new_name (context, data->column_name);
+ g_free (data->column_name);
+ data->column_name = name;
+ }
+ glade_name_context_add_name (context, data->column_name);
+
+ types = g_list_prepend (types, data);
+ g_free (type);
+
+ column_name[0] = '\0';
+ }
+
+ property = glade_widget_get_property (widget, "columns");
+ g_value_init (&value, GLADE_TYPE_COLUMN_TYPE_LIST);
+ g_value_take_boxed (&value, g_list_reverse (types));
+ glade_property_set_value (property, &value);
+ g_value_unset (&value);
}
static void
-glade_gtk_icon_factory_read_sources (GladeWidget *widget,
- GladeXmlNode *node)
+glade_gtk_store_read_data (GladeWidget *widget, GladeXmlNode *node)
{
- GladeIconSources *sources;
- GtkIconSource *source;
- GladeXmlNode *sources_node, *source_node;
- GValue *value;
- GList *list;
- gchar *current_icon_name = NULL;
- GdkPixbuf *pixbuf;
+ GladeXmlNode *data_node, *row_node, *col_node;
+ GNode *data_tree, *row, *item;
+ GladeModelData *data;
+ GValue *value;
+ GList *column_types = NULL, *list;
+ GladeColumnType *column_type;
+ gint colnum;
- if ((sources_node = glade_xml_search_child (node, GLADE_TAG_SOURCES)) == NULL)
+ if ((data_node = glade_xml_search_child (node, GLADE_TAG_DATA)) == NULL)
return;
- sources = glade_icon_sources_new ();
+ /* XXX FIXME: Warn that columns werent there when parsing */
+ if (!glade_widget_property_get (widget, "columns", &column_types) || !column_types)
+ return;
- /* 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))
+ /* Create root... */
+ data_tree = g_node_new (NULL);
+
+ for (row_node = glade_xml_node_get_children (data_node); row_node;
+ row_node = glade_xml_node_next (row_node))
{
- gchar *icon_name;
- gchar *str;
+ gchar *value_str;
- if (!glade_xml_node_verify (source_node, GLADE_TAG_SOURCE))
+ if (!glade_xml_node_verify (row_node, GLADE_TAG_ROW))
continue;
- if (!(icon_name =
- glade_xml_get_property_string_required (source_node, GLADE_TAG_STOCK_ID, NULL)))
- continue;
+ row = g_node_new (NULL);
+ g_node_append (data_tree, row);
- if (!(str = glade_xml_get_property_string_required (source_node, GLADE_TAG_FILENAME, NULL)))
+ /* XXX FIXME: we are assuming that the columns are listed in order */
+ for (colnum = 0, col_node = glade_xml_node_get_children (row_node); col_node;
+ col_node = glade_xml_node_next (col_node))
{
- 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));
+ if (!glade_xml_node_verify (col_node, GLADE_TAG_COL))
+ continue;
- 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);
+ if (!(list = g_list_nth (column_types, colnum)))
+ /* XXX Log this too... */
+ continue;
- gtk_icon_source_set_pixbuf (source, pixbuf);
- g_object_unref (G_OBJECT (pixbuf));
- g_free (str);
+ column_type = list->data;
- /* 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);
- }
+ /* XXX Do we need object properties to somehow work at load time here ??
+ * should we be doing this part in "finished" ? ... todo thinkso...
+ */
+ value_str = glade_xml_get_content (col_node);
+ value = glade_utils_value_from_string (column_type->type, value_str, widget->project, widget);
+ g_free (value_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);
+ data = glade_model_data_new (column_type->type, column_type->column_name);
+
+ g_value_copy (value, &data->value);
+ g_value_unset (value);
+ g_free (value);
+
+ data->name = g_strdup (column_type->column_name);
+ data->i18n_translatable = glade_xml_get_property_boolean (col_node, GLADE_TAG_TRANSLATABLE, FALSE);
+ data->i18n_context = glade_xml_get_property_string (col_node, GLADE_TAG_CONTEXT);
+ data->i18n_comment = glade_xml_get_property_string (col_node, GLADE_TAG_COMMENT);
+
+ item = g_node_new (data);
+ g_node_append (row, item);
+
+ /* dont increment colnum on invalid xml tags... */
+ colnum++;
}
+ }
- if ((str = glade_xml_get_property_string (source_node, GLADE_TAG_STATE)) != NULL)
+ if (data_tree->children)
+ glade_widget_property_set (widget, "data", data_tree);
+
+ glade_model_data_tree_free (data_tree);
+}
+
+void
+glade_gtk_store_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 all the normal properties.. */
+ GWA_GET_CLASS (G_TYPE_OBJECT)->read_widget (adaptor, widget, node);
+
+ glade_gtk_store_read_columns (widget, node);
+ glade_gtk_store_read_data (widget, node);
+}
+
+/*--------------------------- GtkCellRenderer ---------------------------------*/
+static void glade_gtk_treeview_launch_editor (GObject *treeview);
+
+void
+glade_gtk_cell_renderer_action_activate (GladeWidgetAdaptor *adaptor,
+ GObject *object,
+ const gchar *action_path)
+{
+ if (strcmp (action_path, "launch_editor") == 0)
+ {
+ GladeWidget *w = glade_widget_get_from_gobject (object);
+
+ while ((w = glade_widget_get_parent (w)))
{
- 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 (GTK_IS_TREE_VIEW (w->object))
+ {
+ glade_gtk_treeview_launch_editor (w->object);
+ break;
+ }
}
+ }
+ else
+ GWA_GET_CLASS (G_TYPE_OBJECT)->action_activate (adaptor,
+ object,
+ action_path);
+}
+
+void
+glade_gtk_cell_renderer_post_create (GladeWidgetAdaptor *adaptor,
+ GObject *object,
+ GladeCreateReason reason)
+{
+ GladePropertyClass *pclass;
+ GladeProperty *property;
+ GladeWidget *widget;
+ GList *l;
+
+ widget = glade_widget_get_from_gobject (object);
- if ((list = g_hash_table_lookup (sources->sources, g_strdup (current_icon_name))) != NULL)
- list = g_list_prepend (list, source);
- else
+ for (l = adaptor->properties; l; l = l->next)
+ {
+ pclass = l->data;
+
+ if (strncmp (pclass->id, "use-attr-", strlen ("use-attr-")) == 0)
{
- list = g_list_append (NULL, source);
- g_hash_table_insert (sources->sources, g_strdup (current_icon_name), list);
+ property = glade_widget_get_property (widget, pclass->id);
+ glade_property_sync (property);
}
}
+}
- if (g_hash_table_size (sources->sources) > 0)
- glade_widget_property_set (widget, "sources", sources);
+GladeEditorProperty *
+glade_gtk_cell_renderer_create_eprop (GladeWidgetAdaptor *adaptor,
+ GladePropertyClass *klass,
+ gboolean use_command)
+{
+ GladeEditorProperty *eprop;
- glade_icon_sources_free (sources);
+ 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;
}
-void
-glade_gtk_icon_factory_read_widget (GladeWidgetAdaptor *adaptor,
- GladeWidget *widget,
- GladeXmlNode *node)
+
+GladeEditable *
+glade_gtk_cell_renderer_create_editable (GladeWidgetAdaptor *adaptor,
+ GladeEditorPageType type)
{
- if (!glade_xml_node_verify
- (node, GLADE_XML_TAG_WIDGET (glade_project_get_format (widget->project))))
- return;
+ GladeEditable *editable;
- /* First chain up and read in any normal properties.. */
- GWA_GET_CLASS (G_TYPE_OBJECT)->read_widget (adaptor, widget, node);
+ /* Get base editable */
+ editable = GWA_GET_CLASS (G_TYPE_OBJECT)->create_editable (adaptor, type);
- glade_gtk_icon_factory_read_sources (widget, node);
-}
+ if (type == GLADE_PAGE_GENERAL || type == GLADE_PAGE_COMMON)
+ return (GladeEditable *)glade_cell_renderer_editor_new (adaptor, type, editable);
-typedef struct {
- GladeXmlContext *context;
- GladeXmlNode *node;
-} SourceWriteTab;
+ return editable;
+}
static void
-write_icon_sources (gchar *icon_name,
- GList *sources,
- SourceWriteTab *tab)
+glade_gtk_cell_renderer_set_use_attribute (GObject *object,
+ const gchar *property_name,
+ const GValue *value)
{
- GladeXmlNode *source_node;
- GtkIconSource *source;
- GList *l;
- gchar *string;
+ GladeWidget *widget = glade_widget_get_from_gobject (object);
+ gchar *attr_prop_name, *prop_msg, *attr_msg;
- GdkPixbuf *pixbuf;
+ attr_prop_name = g_strdup_printf ("attr-%s", property_name);
- for (l = sources; l; l = l->next)
- {
- source = l->data;
+ 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);
- source_node = glade_xml_node_new (tab->context, GLADE_TAG_SOURCE);
- glade_xml_node_append_child (tab->node, source_node);
+ glade_widget_property_set_sensitive (widget, property_name, FALSE, prop_msg);
+ glade_widget_property_set_sensitive (widget, attr_prop_name, FALSE, attr_msg);
- glade_xml_node_set_property_string (source_node, GLADE_TAG_STOCK_ID, icon_name);
+ 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);
- 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);
- }
+ g_free (prop_msg);
+ g_free (attr_msg);
+ g_free (attr_prop_name);
+}
- 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);
- }
+static gboolean
+glade_gtk_cell_layout_has_renderer (GtkCellLayout *layout,
+ GtkCellRenderer *renderer)
+{
+ GList *cells = gtk_cell_layout_get_cells (layout);
+ gboolean has_renderer;
- 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);
- }
+ has_renderer = (g_list_find (cells, renderer) != NULL);
- pixbuf = gtk_icon_source_get_pixbuf (source);
- string = g_object_get_data (G_OBJECT (pixbuf), "GladeFileName");
+ g_list_free (cells);
- glade_xml_node_set_property_string (source_node,
- GLADE_TAG_FILENAME,
- string);
- }
+ return has_renderer;
}
-
static void
-glade_gtk_icon_factory_write_sources (GladeWidget *widget,
- GladeXmlContext *context,
- GladeXmlNode *node)
+glade_gtk_cell_renderer_sync_attributes (GObject *object)
{
- 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);
+ 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 (!glade_xml_node_get_children (sources_node))
- glade_xml_node_delete (sources_node);
- else
- glade_xml_node_append_child (node, sources_node);
+ 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;
+ /* 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_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))))
+ if (!glade_gtk_cell_layout_has_renderer (layout, cell))
return;
- /* First chain up and write all the normal properties.. */
- GWA_GET_CLASS (G_TYPE_OBJECT)->write_widget (adaptor, widget, context, node);
+ if (glayout->parent && GTK_IS_TREE_VIEW (glayout->parent->object))
+ {
+ GtkTreeModel *model = NULL;
- glade_gtk_icon_factory_write_sources (widget, context, node);
-}
+ glade_widget_property_get (glayout->parent, "model", &model);
+ if (model)
+ gmodel = glade_widget_get_from_gobject (model);
+ }
-static void
-apply_icon_sources (gchar *icon_name,
- GList *sources,
- GtkIconFactory *factory)
-{
- GtkIconSource *source;
- GtkIconSet *set;
- GList *l;
+ if (gmodel)
+ {
+ GList *column_list = NULL;
+ glade_widget_property_get (gmodel, "columns", &column_list);
+ columns = g_list_length (column_list);
- set = gtk_icon_set_new ();
+ }
- for (l = sources; l; l = l->next)
+ gtk_cell_layout_clear_attributes (layout, cell);
+
+ for (l = widget->properties; l; l = l->next)
{
- source = gtk_icon_source_copy ((GtkIconSource *)l->data);
- gtk_icon_set_add_source (set, source);
- }
+ property = l->data;
- gtk_icon_factory_add (factory, icon_name, set);
+ if (strncmp (property->klass->id, "attr-", attr_len) == 0)
+ {
+ attr_prop_name = &property->klass->id[attr_len];
+
+ /* 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));
+ }
+ }
}
-static void
-glade_gtk_icon_factory_set_sources (GObject *object, const GValue *value)
+static gboolean
+glade_gtk_cell_renderer_property_enabled (GObject *object,
+ const gchar *property_name)
{
- GladeIconSources *sources = g_value_get_boxed (value);
- if (sources)
- g_hash_table_foreach (sources->sources, (GHFunc)apply_icon_sources, object);
-}
+ 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;
+
+ if ((property = glade_widget_get_property (gwidget, use_attr_name)) != NULL)
+ glade_property_get (property, &use_attr);
+ g_free (use_attr_name);
+
+ return !use_attr;
+}
void
-glade_gtk_icon_factory_set_property (GladeWidgetAdaptor *adaptor,
- GObject *object,
- const gchar *property_name,
- const GValue *value)
+glade_gtk_cell_renderer_set_property (GladeWidgetAdaptor *adaptor,
+ GObject *object,
+ const gchar *property_name,
+ const GValue *value)
{
- if (strcmp (property_name, "sources") == 0)
+ static gint use_attr_len = 0;
+ static gint attr_len = 0;
+
+ if (!attr_len)
{
- glade_gtk_icon_factory_set_sources (object, value);
- }
- else
+ 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_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 @@
}
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 @@
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_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 @@
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);
}
+
Modified: trunk/plugins/gtk+/gtk+.xml.in
==============================================================================
--- trunk/plugins/gtk+/gtk+.xml.in (original)
+++ trunk/plugins/gtk+/gtk+.xml.in Sun Nov 23 20:24:27 2008
@@ -1814,7 +1814,7 @@
</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>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]