Commit 58a16f54 authored by Tristan Van Berkom's avatar Tristan Van Berkom

new pspec and eprop for GtkIconSources in GtkIconFactories.


	* plugins/gtk+/Makefile.am, plugins/gtk+/glade-icon-sources.[ch]:
	new pspec and eprop for GtkIconSources in GtkIconFactories.

	* plugins/gtk+/glade-gtk.c, plugins/gtk+/gtk+.xml.in: Added load/save/set_property/string_from_value
	support for icon sources in icon factories.


svn path=/trunk/; revision=1987
parent c5619eb4
2008-10-22 Tristan Van Berkom <tvb@gnome.org>
* plugins/gtk+/Makefile.am, plugins/gtk+/glade-icon-sources.[ch]:
new pspec and eprop for GtkIconSources in GtkIconFactories.
* plugins/gtk+/glade-gtk.c, plugins/gtk+/gtk+.xml.in: Added load/save/set_property/string_from_value
support for icon sources in icon factories.
2008-10-21 Tristan Van Berkom <tvb@gnome.org>
* src/glade-window.c, gladeui/glade-editor.c, gladeui/glade-editor-property.[ch],
......
......@@ -290,7 +290,6 @@ glade_editor_property_constructor (GType type,
guint n_construct_properties,
GObjectConstructParam *construct_properties)
{
GtkRequisition req = { -1, -1 };
GObject *obj;
GladeEditorProperty *eprop;
GtkWidget *hbox;
......@@ -324,17 +323,13 @@ glade_editor_property_constructor (GType type,
/* Create & setup label */
eprop->item_label = gtk_event_box_new ();
eprop->label = gtk_label_new (NULL);
gtk_event_box_set_visible_window (GTK_EVENT_BOX (eprop->item_label), FALSE);
hbox = gtk_hbox_new (FALSE, 4);
gtk_label_set_line_wrap (GTK_LABEL(eprop->label), TRUE);
gtk_label_set_line_wrap_mode (GTK_LABEL(eprop->label), PANGO_WRAP_WORD_CHAR);
/* gtk_label_set_width_chars() was not working well :( */
gtk_label_set_text (GTK_LABEL (eprop->label), "xxxxxxxxxxxxxxx");
gtk_widget_size_request (eprop->label, &req);
gtk_widget_set_size_request(GTK_WIDGET(eprop->label), req.width, -1);
/* A Hack to that PANGO_WRAP_WORD_CHAR works nicely */
g_signal_connect (G_OBJECT (eprop->item_label), "size-request",
G_CALLBACK (eprop_item_label_size_request), eprop);
......
......@@ -24,14 +24,15 @@ libgladegtk_la_CFLAGS = \
$(AM_CFLAGS)
libgladegtk_la_SOURCES = glade-gtk.c glade-accels.c glade-attributes.c glade-convert.c fixed-bg.xpm \
glade-column-types.c glade-model-data.c glade-text-button.c glade-cell-renderer-button.c
glade-column-types.c glade-model-data.c glade-text-button.c glade-cell-renderer-button.c \
glade-icon-sources.c
libgladegtk_la_LDFLAGS = -module -avoid-version $(AM_LDFLAGS)
libgladegtk_la_LIBADD = $(libgladeui) $(GTK_LIBS)
libgladegtkincludedir= $(includedir)/libgladeui-1.0/gladeui
libgladegtkinclude_HEADERS = glade-gtk.h glade-accels.h glade-attributes.h glade-column-types.h glade-model-data.h \
glade-text-button.h glade-cell-renderer-button.h
glade-text-button.h glade-cell-renderer-button.h glade-icon-sources.h
if PLATFORM_WIN32
libgladegtk_la_LDFLAGS += -no-undefined
......
......@@ -1012,7 +1012,6 @@ glade_eprop_attrs_view (GladeEditorProperty *eprop)
column = gtk_tree_view_column_new ();
gtk_tree_view_column_set_title (column, _("Value"));
/* Toggle renderer */
renderer = gtk_cell_renderer_toggle_new ();
g_object_set (G_OBJECT (renderer), "activatable", TRUE, NULL);
......@@ -1024,7 +1023,8 @@ glade_eprop_attrs_view (GladeEditorProperty *eprop)
g_signal_connect (G_OBJECT (renderer), "toggled",
G_CALLBACK (value_toggled), eprop);
/* Text renderer */
/* Button renderer */
renderer = glade_cell_renderer_button_new ();
g_object_set (G_OBJECT (renderer),
"editable", TRUE,
......
......@@ -30,6 +30,7 @@
#include "glade-attributes.h"
#include "glade-column-types.h"
#include "glade-model-data.h"
#include "glade-icon-sources.h"
#include <gladeui/glade-editor-property.h>
#include <gladeui/glade-base-editor.h>
......@@ -8979,6 +8980,7 @@ glade_gtk_store_read_columns (GladeWidget *widget, GladeXmlNode *node)
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
......@@ -9053,7 +9055,7 @@ glade_gtk_store_read_data (GladeWidget *widget, GladeXmlNode *node)
}
}
if (data_tree->children && data_tree->children)
if (data_tree->children)
glade_widget_property_set (widget, "data", data_tree);
glade_model_data_tree_free (data_tree);
......@@ -9076,7 +9078,6 @@ glade_gtk_store_read_widget (GladeWidgetAdaptor *adaptor,
}
/*--------------------------- GtkTreeView ---------------------------------*/
static void
......@@ -9322,3 +9323,377 @@ glade_gtk_treeview_remove_child (GladeWidgetAdaptor *adaptor,
column = GTK_TREE_VIEW_COLUMN (child);
gtk_tree_view_remove_column (view, column);
}
/*--------------------------- 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, "%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, "%s ", str);
g_free (str);
}
if (!gtk_icon_source_get_state_wildcarded (source))
{
GtkStateType state = gtk_icon_source_get_size (source);
str = glade_utils_enum_string_from_value (GTK_TYPE_STATE_TYPE, state);
g_string_append_printf (string, "%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 (GLADE_IS_PARAM_SPEC_ICON_SOURCES (klass->pspec))
{
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;
/* chain up.. */
if (GLADE_IS_PARAM_SPEC_ICON_SOURCES (klass->pspec))
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;
}
This diff is collapsed.
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2008 Tristan Van Berkom.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Authors:
* Tristan Van Berkom <tvb@gnome.org>
*/
#ifndef _GLADE_ICON_SOURCES_H_
#define _STV_CAP_H_
#include <glib.h>
G_BEGIN_DECLS
struct _GladeIconSources
{
GHashTable *sources;
};
typedef struct _GladeIconSources GladeIconSources;
typedef struct _GladeParamIconSources GladeParamIconSources;
#define GLADE_TYPE_ICON_SOURCES (glade_icon_sources_get_type())
#define GLADE_TYPE_PARAM_ICON_SOURCES (glade_param_icon_sources_get_type())
#define GLADE_TYPE_EPROP_ICON_SOURCES (glade_eprop_icon_sources_get_type())
#define GLADE_IS_PARAM_SPEC_ICON_SOURCES(pspec) \
(G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GLADE_TYPE_PARAM_ICON_SOURCES))
#define GLADE_PARAM_SPEC_ICON_SOURCES(pspec) \
(G_TYPE_CHECK_INSTANCE_CAST ((pspec), GLADE_TYPE_PARAM_ICON_SOURCES, GladeParamSpecIconSources))
GType glade_icon_sources_get_type (void) G_GNUC_CONST;
GType glade_param_icon_sources_get_type (void) G_GNUC_CONST;
GType glade_eprop_icon_sources_get_type (void) G_GNUC_CONST;
GParamSpec *glade_standard_icon_sources_spec (void);
GladeIconSources *glade_icon_sources_new (void);
GladeIconSources *glade_icon_sources_copy (GladeIconSources *sources);
void glade_icon_sources_free (GladeIconSources *sources);
G_END_DECLS
#endif /* _GLADE_ICON_SOURCE_H_ */
......@@ -502,10 +502,7 @@ glade_eprop_model_data_finalize (GObject *object)
{
/* Chain up */
GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (object));
GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (object);
if (eprop_data->store)
g_object_unref (G_OBJECT (eprop_data->store));
//GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (object);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
......
......@@ -1743,11 +1743,25 @@ embedded in another object</_tooltip>
libglade-unsupported="True" toplevel="True"/>
<glade-widget-class name="GtkEntryCompletion" generic-name="entrycompletion" _title="Entry Completion"
libglade-unsupported="True" toplevel="True"/>
<glade-widget-class name="GtkIconFactory" generic-name="iconfactory" _title="Icon Factory"
libglade-unsupported="True" toplevel="True"/>
<glade-widget-class name="GtkUIManager" generic-name="uimanager" _title="UI Manager"
libglade-unsupported="True" toplevel="True"/>
<glade-widget-class name="GtkIconFactory" generic-name="iconfactory" _title="Icon Factory"
libglade-unsupported="True" toplevel="True">
<post-create-function>glade_gtk_icon_factory_post_create</post-create-function>
<read-widget-function>glade_gtk_icon_factory_read_widget</read-widget-function>
<write-widget-function>glade_gtk_icon_factory_write_widget</write-widget-function>
<set-property-function>glade_gtk_icon_factory_set_property</set-property-function>
<string-from-value-function>glade_gtk_icon_factory_string_from_value</string-from-value-function>
<create-editor-property-function>glade_gtk_icon_factory_create_eprop</create-editor-property-function>
<properties>
<property id="sources" _name="Icon Sources" save="False">
<_tooltip>A list of sources for this icon factory</_tooltip>
<spec>glade_standard_icon_sources_spec</spec>
</property>
</properties>
</glade-widget-class>
<glade-widget-class name="GtkTreeView" generic-name="treeview" _title="Tree View">
<post-create-function>empty</post-create-function>
<child-set-property-function>glade_gtk_treeview_set_child_property</child-set-property-function>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment