Commit 05a78c9b authored by Tristan Van Berkom's avatar Tristan Van Berkom

New internal pspec type for attributes and new editor widget for them.


	* plugins/gtk+/Makefile.am, plugins/gtk+/glade-attributes.[ch]: 
	  New internal pspec type for attributes and new editor widget for them.

	* plugins/gtk+/glade-gtk.c, plugins/gtk+/gtk+.xml.in: 
	  Load/Save/Edit pango attributes on GtkLabel

	* gladeui/glade-utils.[ch]: Added enum value <--> string converters.


svn path=/trunk/; revision=1852
parent 820a8ddc
2008-08-06 Tristan Van Berkom <tvb@gnome.org>
* plugins/gtk+/Makefile.am, plugins/gtk+/glade-attributes.[ch]:
New internal pspec type for attributes and new editor widget for them.
* plugins/gtk+/glade-gtk.c, plugins/gtk+/gtk+.xml.in:
Load/Save/Edit pango attributes on GtkLabel
* gladeui/glade-utils.[ch]: Added enum value <--> string converters.
2008-08-02 Tristan Van Berkom <tvb@gnome.org>
* doc/widgetclasses.sgml, doc/catalogintro.sgml: Ammended docs regarding
......
......@@ -156,10 +156,20 @@ if test x"$check_python" = x"yes"; then
PYGTK_REQUIRED_MAJOR=2
PYGTK_REQUIRED_MINOR=10
PYGTK_REQUIRED_MICRO=0
AM_CHECK_PYTHON_HEADERS(, [AC_MSG_ERROR(could not find Python headers)])
AM_CHECK_PYTHON_LIBS(, [AC_MSG_ERROR(could not find Python lib)])
PKG_CHECK_MODULES(PYGTK, [pygtk-2.0 >= 2.10.0], [have_python=yes],[have_python=no])
AM_CHECK_PYTHON_HEADERS(, [have_python_headers=no])
AM_CHECK_PYTHON_LIBS(, [have_python_lib=no])
if test x"$have_python_headers" = x"no"; then
have_python=no
fi
if test x"$have_python_lib" = x"no"; then
have_python=no
fi
AC_DEFINE_UNQUOTED(PYGTK_REQUIRED_MAJOR, $PYGTK_REQUIRED_MAJOR, Pygtk mayor version required)
AC_DEFINE_UNQUOTED(PYGTK_REQUIRED_MINOR, $PYGTK_REQUIRED_MINOR, Pygtk minor version required)
AC_DEFINE_UNQUOTED(PYGTK_REQUIRED_MICRO, $PYGTK_REQUIRED_MICRO, Pygtk micro version required)
......
......@@ -401,13 +401,13 @@ glade_property_class_make_string_from_gvalue (GladePropertyClass *property_class
GdkColor *color;
GList *objects;
if (G_IS_PARAM_SPEC_ENUM(property_class->pspec))
if (G_IS_PARAM_SPEC_ENUM (property_class->pspec))
{
gint eval = g_value_get_enum (value);
string = glade_property_class_make_string_from_enum
(property_class->pspec->value_type, eval);
}
else if (G_IS_PARAM_SPEC_FLAGS(property_class->pspec))
else if (G_IS_PARAM_SPEC_FLAGS (property_class->pspec))
{
guint flags = g_value_get_flags (value);
string = glade_property_class_make_string_from_flags
......@@ -432,7 +432,7 @@ glade_property_class_make_string_from_gvalue (GladePropertyClass *property_class
g_string_free (gstring, FALSE);
}
}
else if (G_IS_PARAM_SPEC_BOXED(property_class->pspec))
else if (G_IS_PARAM_SPEC_BOXED (property_class->pspec))
{
if (property_class->pspec->value_type == GDK_TYPE_COLOR)
{
......@@ -507,7 +507,7 @@ glade_property_class_make_string_from_gvalue (GladePropertyClass *property_class
}
else
g_critical ("Unsupported pspec type %s (value -> string)",
g_type_name(G_PARAM_SPEC_TYPE (property_class->pspec)));
g_type_name (G_PARAM_SPEC_TYPE (property_class->pspec)));
return string;
}
......@@ -889,10 +889,14 @@ glade_property_class_make_gvalue_from_vl (GladePropertyClass *klass,
g_value_set_boolean (value, va_arg (vl, gboolean));
else if (G_IS_PARAM_SPEC_OBJECT(klass->pspec))
g_value_set_object (value, va_arg (vl, gpointer));
else if (G_VALUE_HOLDS_BOXED (value))
g_value_set_boxed (value, va_arg (vl, gpointer));
#if THIS_STUFF_SHOULD_BE_COVERED_BY_HOLDS_BOXED
else if (G_IS_PARAM_SPEC_BOXED(klass->pspec))
g_value_set_boxed (value, va_arg (vl, gpointer));
else if (GLADE_IS_PARAM_SPEC_OBJECTS(klass->pspec))
g_value_set_boxed (value, va_arg (vl, gpointer));
#endif
else
g_critical ("Unsupported pspec type %s (vl -> string)",
g_type_name(G_PARAM_SPEC_TYPE (klass->pspec)));
......@@ -978,10 +982,14 @@ glade_property_class_set_vl_from_gvalue (GladePropertyClass *klass,
*(gboolean *)(va_arg (vl, gboolean *)) = g_value_get_boolean (value);
else if (G_IS_PARAM_SPEC_OBJECT(klass->pspec))
*(gpointer *)(va_arg (vl, gpointer *)) = g_value_get_object (value);
else if (G_VALUE_HOLDS_BOXED (value))
*(gpointer *)(va_arg (vl, gpointer *)) = g_value_get_boxed (value);
#if THIS_STUFF_SHOULD_BE_COVERED_BY_HOLDS_BOXED
else if (G_IS_PARAM_SPEC_BOXED(klass->pspec))
*(gpointer *)(va_arg (vl, gpointer *)) = g_value_get_boxed (value);
else if (GLADE_IS_PARAM_SPEC_OBJECTS(klass->pspec))
*(gpointer *)(va_arg (vl, gpointer *)) = g_value_get_boxed (value);
#endif
else
g_critical ("Unsupported pspec type %s (string -> vl)",
g_type_name(G_PARAM_SPEC_TYPE (klass->pspec)));
......
......@@ -1937,3 +1937,41 @@ glade_util_icon_name_to_filename (const gchar *value)
return g_strdup (filename);
}
gint
glade_utils_enum_value_from_string (GType enum_type, const gchar *strval)
{
GEnumClass *enum_class;
GEnumValue *enum_value;
gint value = 0;
enum_class = g_type_class_ref (enum_type);
if ((enum_value = g_enum_get_value_by_nick (enum_class, strval)) != NULL)
value = enum_value->value;
else
g_critical ("Couldnt find enum value for %s, type %s",
strval, g_type_name (enum_type));
g_type_class_unref (enum_class);
return value;
}
gchar *
glade_utils_enum_string_from_value (GType enum_type, gint value)
{
GEnumClass *enum_class;
GEnumValue *enum_value;
gchar *ret = NULL;
enum_class = g_type_class_ref (enum_type);
if ((enum_value = g_enum_get_value (enum_class, value)) != NULL)
ret = g_strdup (enum_value->value_nick);
else
g_critical ("Couldnt find enum value for %d, type %s",
value, g_type_name (enum_type));
g_type_class_unref (enum_class);
return ret;
}
......@@ -133,6 +133,10 @@ gchar *glade_util_filename_to_icon_name (const gchar *value);
gchar *glade_util_icon_name_to_filename (const gchar *value);
gint glade_utils_enum_value_from_string (GType enum_type, const gchar *strval);
gchar *glade_utils_enum_string_from_value (GType enum_type, gint value);
G_END_DECLS
......
......@@ -34,7 +34,10 @@ typedef struct _GladeProject GladeProject;
#include <gladeui/glade-property.h>
#include <gladeui/glade-project.h>
#include <gladeui/glade-app.h>
#include <gladeui/glade-base-editor.h>
#include <gladeui/glade-command.h>
#include <gladeui/glade-design-layout.h>
#include <gladeui/glade-design-view.h>
#include <gladeui/glade-editor.h>
#include <gladeui/glade-editor-property.h>
#include <gladeui/glade-palette.h>
......
......@@ -23,12 +23,12 @@ libgladegtk_la_CFLAGS = \
$(PLUGINS_WARN_CFLAGS) \
$(AM_CFLAGS)
libgladegtk_la_SOURCES = glade-gtk.c glade-accels.c fixed-bg.xpm
libgladegtk_la_SOURCES = glade-gtk.c glade-accels.c glade-attributes.c fixed-bg.xpm
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
libgladegtkinclude_HEADERS = glade-gtk.h glade-accels.h glade-attributes.h
if PLATFORM_WIN32
libgladegtk_la_LDFLAGS += -no-undefined
......
......@@ -106,6 +106,7 @@ param_accel_set_default (GParamSpec *pspec,
{
if (value->data[0].v_pointer != NULL)
{
/* XXX FIXME ?? */
g_free (value->data[0].v_pointer);
}
value->data[0].v_pointer = NULL;
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
#ifndef __GLADE_ACCELS_H__
#define __GLADE_ACCELS_H__
#include <gladeui/glade.h>
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define GLADE_TYPE_PARAM_ACCEL (glade_param_accel_get_type())
#define GLADE_TYPE_ACCEL_GLIST (glade_accel_glist_get_type())
......@@ -51,6 +56,8 @@ GParamSpec *glade_param_spec_accel (const gchar *name,
GParamSpec *glade_standard_accel_spec (void);
gboolean glade_keyval_valid (guint val);
gchar *glade_accels_make_string (GList *accels);
G_END_DECLS
#endif /* __GLADE_ACCELS_H__ */
......@@ -27,6 +27,7 @@
#include "glade-gtk.h"
#include "fixed-bg.xpm"
#include "glade-accels.h"
#include "glade-attributes.h"
#include <gladeui/glade-editor-property.h>
#include <gladeui/glade-base-editor.h>
......@@ -256,6 +257,9 @@ glade_gtk_stop_emission_POINTER (gpointer instance, gpointer dummy, gpointer dat
#define GLADE_TAG_A11Y_INTERNAL_NAME "accessible"
#define GLADE_TAG_ATTRIBUTES "attributes"
#define GLADE_TAG_ATTRIBUTE "attribute"
#define GLADE_TAG_A11Y_LIBGLADE_RELATION "atkrelation"
#define GLADE_TAG_A11Y_LIBGLADE_ACTION "atkaction"
#define GLADE_TAG_A11Y_LIBGLADE_PROPERTY "atkproperty"
......@@ -6799,6 +6803,146 @@ glade_gtk_label_post_create (GladeWidgetAdaptor *adaptor,
G_CALLBACK (ensure_label_props), adaptor);
}
GladeEditorProperty *
glade_gtk_label_create_eprop (GladeWidgetAdaptor *adaptor,
GladePropertyClass *klass,
gboolean use_command)
{
GladeEditorProperty *eprop;
/* chain up.. */
if (GLADE_IS_PARAM_SPEC_ATTRIBUTES (klass->pspec))
{
eprop = g_object_new (GLADE_TYPE_EPROP_ATTRS,
"property-class", klass,
"use-command", use_command,
NULL);
}
else
eprop = GWA_GET_CLASS
(GTK_TYPE_WIDGET)->create_eprop (adaptor,
klass,
use_command);
return eprop;
}
static void
glade_gtk_label_set_attributes (GObject *object, const GValue *value)
{
GladeAttribute *gattr;
PangoAttribute *attribute;
PangoLanguage *language;
PangoAttrList *attrs = NULL;
GdkColor *color;
GList *list;
g_print ("Setting attributes !!!\n");
for (list = g_value_get_boxed (value); list; list = list->next)
{
gattr = list->data;
attribute = NULL;
g_print ("Setting an attribute...\n");
switch (gattr->type)
{
/* PangoAttrLanguage */
case PANGO_ATTR_LANGUAGE:
if ((language = pango_language_from_string (g_value_get_string (&gattr->value))))
attribute = pango_attr_language_new (language);
break;
/* PangoAttrInt */
case PANGO_ATTR_STYLE:
attribute = pango_attr_style_new (g_value_get_enum (&(gattr->value)));
break;
case PANGO_ATTR_WEIGHT:
g_print ("XX Setting weight\n");
attribute = pango_attr_weight_new (g_value_get_enum (&(gattr->value)));
break;
case PANGO_ATTR_VARIANT:
attribute = pango_attr_variant_new (g_value_get_enum (&(gattr->value)));
break;
case PANGO_ATTR_STRETCH:
attribute = pango_attr_stretch_new (g_value_get_enum (&(gattr->value)));
break;
case PANGO_ATTR_UNDERLINE:
attribute = pango_attr_underline_new (g_value_get_boolean (&(gattr->value)));
break;
case PANGO_ATTR_STRIKETHROUGH:
attribute = pango_attr_strikethrough_new (g_value_get_boolean (&(gattr->value)));
break;
case PANGO_ATTR_GRAVITY:
attribute = pango_attr_gravity_new (g_value_get_enum (&(gattr->value)));
break;
case PANGO_ATTR_GRAVITY_HINT:
attribute = pango_attr_gravity_hint_new (g_value_get_enum (&(gattr->value)));
break;
/* PangoAttrString */
case PANGO_ATTR_FAMILY:
attribute = pango_attr_family_new (g_value_get_string (&(gattr->value)));
break;
/* PangoAttrSize */
case PANGO_ATTR_SIZE:
attribute = pango_attr_size_new (g_value_get_int (&(gattr->value)));
break;
case PANGO_ATTR_ABSOLUTE_SIZE:
attribute = pango_attr_size_new_absolute (g_value_get_int (&(gattr->value)));
break;
/* PangoAttrColor */
case PANGO_ATTR_FOREGROUND:
color = g_value_get_boxed (&(gattr->value));
attribute = pango_attr_foreground_new (color->red, color->green, color->blue);
break;
case PANGO_ATTR_BACKGROUND:
color = g_value_get_boxed (&(gattr->value));
attribute = pango_attr_background_new (color->red, color->green, color->blue);
break;
case PANGO_ATTR_UNDERLINE_COLOR:
color = g_value_get_boxed (&(gattr->value));
attribute = pango_attr_underline_color_new (color->red, color->green, color->blue);
break;
case PANGO_ATTR_STRIKETHROUGH_COLOR:
color = g_value_get_boxed (&(gattr->value));
attribute = pango_attr_strikethrough_color_new (color->red, color->green, color->blue);
break;
/* PangoAttrShape */
case PANGO_ATTR_SHAPE:
/* Unsupported for now */
break;
/* PangoAttrFloat */
case PANGO_ATTR_SCALE:
attribute = pango_attr_scale_new (g_value_get_double (&(gattr->value)));
break;
case PANGO_ATTR_INVALID:
case PANGO_ATTR_LETTER_SPACING:
case PANGO_ATTR_RISE:
case PANGO_ATTR_FALLBACK:
case PANGO_ATTR_FONT_DESC:
default:
break;
}
if (attribute)
{
if (!attrs)
attrs = pango_attr_list_new ();
pango_attr_list_insert (attrs, attribute);
}
}
gtk_label_set_attributes (GTK_LABEL (object), attrs);
}
void
glade_gtk_label_set_property (GladeWidgetAdaptor *adaptor,
GObject *object,
......@@ -6807,12 +6951,149 @@ glade_gtk_label_set_property (GladeWidgetAdaptor *adaptor,
{
if (!strcmp (id, "label"))
glade_gtk_label_set_label (object, value);
else if (!strcmp (id, "glade-attributes"))
glade_gtk_label_set_attributes (object, value);
else
GWA_GET_CLASS (GTK_TYPE_WIDGET)->set_property (adaptor,
object,
id, value);
}
static void
glade_gtk_parse_attributes (GladeWidget *widget,
GladeXmlNode *node)
{
PangoAttrType attr_type;
GladeXmlNode *prop;
GladeAttribute *attr;
GList *attrs = NULL;
gchar *name, *value;
for (prop = glade_xml_node_get_children (node);
prop; prop = glade_xml_node_next (prop))
{
if (!glade_xml_node_verify (prop, GLADE_TAG_ATTRIBUTE))
continue;
if (!(name = glade_xml_get_property_string_required
(prop, GLADE_XML_TAG_NAME, NULL)))
continue;
if (!(value = glade_xml_get_content (prop)))
{
g_free (name);
continue;
}
if ((attr_type =
glade_utils_enum_value_from_string (PANGO_TYPE_ATTR_TYPE, name)) == 0)
continue;
/* Parse attribute and add to list */
if ((attr = glade_gtk_attribute_from_string (attr_type, value)) != NULL)
attrs = g_list_prepend (attrs, attr);
/* XXX deal with start/end here ... */
g_free (name);
g_free (value);
}
glade_widget_property_set (widget, "glade-attributes", g_list_reverse (attrs));
glade_attr_list_free (attrs);
}
static void
glade_gtk_label_read_attributes (GladeWidget *widget,
GladeXmlNode *node)
{
GladeXmlNode *attrs_node;
if ((attrs_node =
glade_xml_search_child (node, GLADE_TAG_ATTRIBUTES)) != NULL)
{
g_print ("got attributes node...\n");
/* Generic attributes parsing */
glade_gtk_parse_attributes (widget, attrs_node);
}
}
void
glade_gtk_label_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 (GTK_TYPE_WIDGET)->read_widget (adaptor, widget, node);
glade_gtk_label_read_attributes (widget, node);
}
static void
glade_gtk_write_attributes (GladeWidget *widget,
GladeXmlContext *context,
GladeXmlNode *node)
{
GladeXmlNode *attr_node;
GList *attrs = NULL, *l;
GladeAttribute *gattr;
gchar *attr_type;
gchar *attr_value;
if (!glade_widget_property_get (widget, "glade-attributes", &attrs) || !attrs)
return;
for (l = attrs; l; l = l->next)
{
gattr = l->data;
attr_type = glade_utils_enum_string_from_value (PANGO_TYPE_ATTR_TYPE, gattr->type);
attr_value = glade_gtk_string_from_attr (gattr);
attr_node = glade_xml_node_new (context, GLADE_TAG_ATTRIBUTE);
glade_xml_node_append_child (node, attr_node);
glade_xml_set_content (attr_node, attr_value);
glade_xml_node_set_property_string (attr_node, GLADE_TAG_NAME, attr_type);
}
}
void
glade_gtk_label_write_widget (GladeWidgetAdaptor *adaptor,
GladeWidget *widget,
GladeXmlContext *context,
GladeXmlNode *node)
{
GladeXmlNode *attrs_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)->write_widget (adaptor, widget, context, node);
attrs_node = glade_xml_node_new (context, GLADE_TAG_ATTRIBUTES);
glade_xml_node_append_child (node, attrs_node);
glade_gtk_write_attributes (widget, context, attrs_node);
if (!glade_xml_node_get_children (attrs_node))
{
glade_xml_node_remove (attrs_node);
glade_xml_node_delete (attrs_node);
}
}
/* ----------------------------- GtkTextView ------------------------------ */
static void
glade_gtk_text_view_changed (GtkTextBuffer *buffer, GladeWidget *gtext)
......
......@@ -580,9 +580,17 @@ embedded in another object</_tooltip>
<glade-widget-class name="GtkLabel" generic-name="label" _title="Label">
<post-create-function>glade_gtk_label_post_create</post-create-function>
<create-editor-property-function>glade_gtk_label_create_eprop</create-editor-property-function>
<set-property-function>glade_gtk_label_set_property</set-property-function>
<read-widget-function>glade_gtk_label_read_widget</read-widget-function>
<write-widget-function>glade_gtk_label_write_widget</write-widget-function>
<properties>
<property id="glade-attributes" _name="Attributes" save="False">
<spec>glade_gtk_attributes_spec</spec>
<_tooltip>The pango attributes for this label</_tooltip>
</property>
<property id="selectable" ignore="True"/>
<property id="pattern" default=""/>
<property id="max-width-chars" _name="Maximum Width"/>
......
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