glade3 r1756 - in branches/builder: . gladeui plugins/gtk+
- From: tvb svn gnome org
- To: svn-commits-list gnome org
- Subject: glade3 r1756 - in branches/builder: . gladeui plugins/gtk+
- Date: Wed, 2 Apr 2008 06:17:19 +0100 (BST)
Author: tvb
Date: Wed Apr 2 06:17:18 2008
New Revision: 1756
URL: http://svn.gnome.org/viewvc/glade3?rev=1756&view=rev
Log:
* gladeui/glade-widget-adaptor.[ch]: Added new entry points
to create editor widgets for plugin provided pspecs and also
to create strings based on plugin provided pspec.
Moved all accelerater code out of the core and into the plugin,
still working on loading glade files with the new parser...
A plugins/gtk+/glade-keysyms.c
M plugins/gtk+/glade-gtk.c
M plugins/gtk+/gtk+.xml.in
A plugins/gtk+/glade-accels.c
M plugins/gtk+/Makefile.am
A plugins/gtk+/glade-accels.h
M ChangeLog
M gladeui/glade-editor.c
M gladeui/glade-editor-property.c
M gladeui/glade-editor-property.h
M gladeui/glade-widget.c
M gladeui/glade-widget.h
M gladeui/glade-widget-adaptor.c
M gladeui/glade-command.c
M gladeui/glade-widget-adaptor.h
M gladeui/glade-base-editor.c
M gladeui/glade-xml-utils.h
D gladeui/glade-keysyms.c
M gladeui/glade-property.c
M gladeui/glade-property-class.c
M gladeui/glade-builtins.c
M gladeui/glade-builtins.h
M gladeui/glade-project.c
M gladeui/Makefile.am
Added:
branches/builder/plugins/gtk+/glade-accels.c
branches/builder/plugins/gtk+/glade-accels.h
branches/builder/plugins/gtk+/glade-keysyms.c
- copied, changed from r1752, /branches/builder/gladeui/glade-keysyms.c
Removed:
branches/builder/gladeui/glade-keysyms.c
Modified:
branches/builder/ChangeLog
branches/builder/gladeui/Makefile.am
branches/builder/gladeui/glade-base-editor.c
branches/builder/gladeui/glade-builtins.c
branches/builder/gladeui/glade-builtins.h
branches/builder/gladeui/glade-command.c
branches/builder/gladeui/glade-editor-property.c
branches/builder/gladeui/glade-editor-property.h
branches/builder/gladeui/glade-editor.c
branches/builder/gladeui/glade-project.c
branches/builder/gladeui/glade-property-class.c
branches/builder/gladeui/glade-property.c
branches/builder/gladeui/glade-widget-adaptor.c
branches/builder/gladeui/glade-widget-adaptor.h
branches/builder/gladeui/glade-widget.c
branches/builder/gladeui/glade-widget.h
branches/builder/gladeui/glade-xml-utils.h
branches/builder/plugins/gtk+/Makefile.am
branches/builder/plugins/gtk+/glade-gtk.c
branches/builder/plugins/gtk+/gtk+.xml.in
Modified: branches/builder/gladeui/Makefile.am
==============================================================================
--- branches/builder/gladeui/Makefile.am (original)
+++ branches/builder/gladeui/Makefile.am Wed Apr 2 06:17:18 2008
@@ -53,7 +53,6 @@
glade-accumulators.c \
glade-builtins.c \
glade-app.c \
- glade-keysyms.c \
glade-fixed.c \
glade-base-editor.c \
glade-palette-item.h \
Modified: branches/builder/gladeui/glade-base-editor.c
==============================================================================
--- branches/builder/gladeui/glade-base-editor.c (original)
+++ branches/builder/gladeui/glade-base-editor.c Wed Apr 2 06:17:18 2008
@@ -1675,7 +1675,7 @@
while (property)
{
- eprop = glade_editor_property_new_from_widget (gchild, property, packing, TRUE);
+ eprop = glade_widget_create_editor_property (gchild, property, packing, TRUE);
if (eprop)
glade_base_editor_table_attach (editor,
GLADE_EDITOR_PROPERTY (eprop)->item_label,
Modified: branches/builder/gladeui/glade-builtins.c
==============================================================================
--- branches/builder/gladeui/glade-builtins.c (original)
+++ branches/builder/gladeui/glade-builtins.c Wed Apr 2 06:17:18 2008
@@ -41,15 +41,6 @@
*/
};
-struct _GladeParamSpecAccel {
- GParamSpec parent_instance;
-
- GType type; /* The type this accel key is for; this allows
- * us to verify the validity of any signals for
- * this type.
- */
-};
-
typedef struct _GladeStockItem {
gchar *value_name;
gchar *value_nick;
@@ -277,10 +268,9 @@
0, G_PARAM_READWRITE);
}
-
/****************************************************************
* A GList boxed type used by GladeParamSpecObjects and *
- * GladeParamSpecAccel *
+ * GladeParamSpecAccel (which is now in the glade-gtk backend) *
****************************************************************/
GType
glade_glist_get_type (void)
@@ -295,180 +285,6 @@
return type_id;
}
-GList *
-glade_accel_list_copy (GList *accels)
-{
- GList *ret = NULL, *list;
- GladeAccelInfo *info, *dup_info;
-
- for (list = accels; list; list = list->next)
- {
- info = list->data;
-
- dup_info = g_new0 (GladeAccelInfo, 1);
- dup_info->signal = g_strdup (info->signal);
- dup_info->key = info->key;
- dup_info->modifiers = info->modifiers;
-
- ret = g_list_prepend (ret, dup_info);
- }
-
- return g_list_reverse (ret);
-}
-
-void
-glade_accel_list_free (GList *accels)
-{
- GList *list;
- GladeAccelInfo *info;
-
- for (list = accels; list; list = list->next)
- {
- info = list->data;
-
- g_free (info->signal);
- g_free (info);
- }
- g_list_free (accels);
-}
-
-GType
-glade_accel_glist_get_type (void)
-{
- static GType type_id = 0;
-
- if (!type_id)
- type_id = g_boxed_type_register_static
- ("GladeAccelGList",
- (GBoxedCopyFunc) glade_accel_list_copy,
- (GBoxedFreeFunc) glade_accel_list_free);
- return type_id;
-}
-
-
-/****************************************************************
- * Built-in GladeParamSpecAccel for accelerator properties *
- ****************************************************************/
-gboolean
-glade_keyval_valid (guint val)
-{
- gint i;
-
- for (i = 0; GladeKeys[i].name != NULL; i++)
- {
- if (GladeKeys[i].value == val)
- return TRUE;
- }
- return FALSE;
-}
-
-
-static void
-param_accel_init (GParamSpec *pspec)
-{
- GladeParamSpecAccel *ospec = GLADE_PARAM_SPEC_ACCEL (pspec);
- ospec->type = G_TYPE_OBJECT;
-}
-
-static void
-param_accel_set_default (GParamSpec *pspec,
- GValue *value)
-{
- if (value->data[0].v_pointer != NULL)
- {
- g_free (value->data[0].v_pointer);
- }
- value->data[0].v_pointer = NULL;
-}
-
-static gboolean
-param_accel_validate (GParamSpec *pspec,
- GValue *value)
-{
- /* GladeParamSpecAccel *aspec = GLADE_PARAM_SPEC_ACCEL (pspec); */
- GList *accels, *list, *toremove = NULL;
- GladeAccelInfo *info;
-
- accels = value->data[0].v_pointer;
-
- for (list = accels; list; list = list->next)
- {
- info = list->data;
-
- /* Is it an invalid key ? */
- if (glade_keyval_valid (info->key) == FALSE ||
- /* Does the modifier contain any unwanted bits ? */
- info->modifiers & GDK_MODIFIER_MASK ||
- /* Do we have a signal ? */
- /* FIXME: Check if the signal is valid for 'type' */
- info->signal == NULL)
- toremove = g_list_prepend (toremove, info);
- }
-
- for (list = toremove; list; list = list->next)
- accels = g_list_remove (accels, list->data);
-
- if (toremove) g_list_free (toremove);
-
- value->data[0].v_pointer = accels;
-
- return toremove != NULL;
-}
-
-static gint
-param_accel_values_cmp (GParamSpec *pspec,
- const GValue *value1,
- const GValue *value2)
-{
- guint8 *p1 = value1->data[0].v_pointer;
- guint8 *p2 = value2->data[0].v_pointer;
-
- /* not much to compare here, try to at least provide stable lesser/greater result */
-
- return p1 < p2 ? -1 : p1 > p2;
-}
-
-GType
-glade_param_accel_get_type (void)
-{
- static GType accel_type = 0;
-
- if (accel_type == 0)
- {
- static /* const */ GParamSpecTypeInfo pspec_info = {
- sizeof (GladeParamSpecAccel), /* instance_size */
- 16, /* n_preallocs */
- param_accel_init, /* instance_init */
- 0xdeadbeef, /* value_type, assigned further down */
- NULL, /* finalize */
- param_accel_set_default, /* value_set_default */
- param_accel_validate, /* value_validate */
- param_accel_values_cmp, /* values_cmp */
- };
- pspec_info.value_type = GLADE_TYPE_ACCEL_GLIST;
-
- accel_type = g_param_type_register_static
- ("GladeParamAccel", &pspec_info);
- }
- return accel_type;
-}
-
-GParamSpec *
-glade_param_spec_accel (const gchar *name,
- const gchar *nick,
- const gchar *blurb,
- GType widget_type,
- GParamFlags flags)
-{
- GladeParamSpecAccel *pspec;
-
- pspec = g_param_spec_internal (GLADE_TYPE_PARAM_ACCEL,
- name, nick, blurb, flags);
-
- pspec->type = widget_type;
- return G_PARAM_SPEC (pspec);
-}
-
/****************************************************************
* Built-in GladeParamSpecObjects for object list properties *
* (Used as a pspec to desctibe an AtkRelationSet, but can *
@@ -628,16 +444,6 @@
G_PARAM_READWRITE);
}
-/* Accelerator spec */
-GParamSpec *
-glade_standard_accel_spec (void)
-{
- return glade_param_spec_accel ("accelerators", _("Accelerators"),
- _("A list of accelerator keys"),
- GTK_TYPE_WIDGET,
- G_PARAM_READWRITE);
-}
-
/****************************************************************
* Basic types follow *
****************************************************************/
@@ -692,31 +498,6 @@
G_PARAM_READWRITE);
}
-guint
-glade_builtin_key_from_string (const gchar *string)
-{
- gint i;
-
- g_return_val_if_fail (string != NULL, 0);
-
- for (i = 0; GladeKeys[i].name != NULL; i++)
- if (!strcmp (string, GladeKeys[i].name))
- return GladeKeys[i].value;
-
- return 0;
-}
-
-const gchar *
-glade_builtin_string_from_key (guint key)
-{
- gint i;
-
- for (i = 0; GladeKeys[i].name != NULL; i++)
- if (GladeKeys[i].value == key)
- return GladeKeys[i].name;
- return NULL;
-}
-
GType
glade_item_appearance_get_type (void)
{
Modified: branches/builder/gladeui/glade-builtins.h
==============================================================================
--- branches/builder/gladeui/glade-builtins.h (original)
+++ branches/builder/gladeui/glade-builtins.h Wed Apr 2 06:17:18 2008
@@ -8,28 +8,12 @@
G_BEGIN_DECLS
typedef struct _GladeParamSpecObjects GladeParamSpecObjects;
-typedef struct _GladeParamSpecAccel GladeParamSpecAccel;
-typedef struct _GladeKey GladeKey;
-struct _GladeKey {
- guint value;
- gchar *name;
-};
-
-extern const GladeKey GladeKeys[];
-
-#define GLADE_KEYS_LAST_ALPHANUM "9"
-#define GLADE_KEYS_LAST_EXTRA "questiondown"
-#define GLADE_KEYS_LAST_KP "KP_9"
-#define GLADE_KEYS_LAST_FKEY "F35"
-
#define GLADE_TYPE_STOCK (glade_standard_stock_get_type())
#define GLADE_TYPE_STOCK_IMAGE (glade_standard_stock_image_get_type())
#define GLADE_TYPE_GLIST (glade_glist_get_type())
-#define GLADE_TYPE_ACCEL_GLIST (glade_accel_glist_get_type())
#define GLADE_TYPE_PARAM_OBJECTS (glade_param_objects_get_type())
-#define GLADE_TYPE_PARAM_ACCEL (glade_param_accel_get_type())
#define GLADE_TYPE_ITEM_APPEARANCE (glade_item_appearance_get_type())
#define GLADE_IS_STOCK(pspec) \
@@ -45,42 +29,22 @@
(G_TYPE_CHECK_INSTANCE_CAST ((pspec), \
GLADE_TYPE_PARAM_OBJECTS, GladeParamSpecObjects))
-#define GLADE_IS_PARAM_SPEC_ACCEL(pspec) \
- (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), \
- GLADE_TYPE_PARAM_ACCEL))
-#define GLADE_PARAM_SPEC_ACCEL(pspec) \
- (G_TYPE_CHECK_INSTANCE_CAST ((pspec), \
- GLADE_TYPE_PARAM_ACCEL, GladeParamSpecAccel))
-
GType glade_standard_stock_get_type (void) G_GNUC_CONST;
GType glade_standard_stock_image_get_type (void) G_GNUC_CONST;
GType glade_glist_get_type (void) G_GNUC_CONST;
-GType glade_accel_glist_get_type (void) G_GNUC_CONST;
GType glade_param_objects_get_type (void) G_GNUC_CONST;
-GType glade_param_accel_get_type (void) G_GNUC_CONST;
GType glade_item_appearance_get_type (void) G_GNUC_CONST;
guint glade_builtin_key_from_string (const gchar *string);
const gchar *glade_builtin_string_from_key (guint key);
-GList *glade_accel_list_copy (GList *accels);
-void glade_accel_list_free (GList *accels);
-
-
-
GParamSpec *glade_param_spec_objects (const gchar *name,
const gchar *nick,
const gchar *blurb,
GType accepted_type,
GParamFlags flags);
-GParamSpec *glade_param_spec_accel (const gchar *name,
- const gchar *nick,
- const gchar *blurb,
- GType widget_type,
- GParamFlags flags);
-
void glade_param_spec_objects_set_type (GladeParamSpecObjects *pspec,
GType type);
GType glade_param_spec_objects_get_type (GladeParamSpecObjects *pspec);
@@ -90,7 +54,6 @@
GParamSpec *glade_standard_objects_spec (void);
GParamSpec *glade_standard_stock_spec (void);
GParamSpec *glade_standard_stock_image_spec (void);
-GParamSpec *glade_standard_accel_spec (void);
GParamSpec *glade_standard_int_spec (void);
GParamSpec *glade_standard_uint_spec (void);
GParamSpec *glade_standard_string_spec (void);
@@ -100,8 +63,6 @@
void glade_standard_stock_append_prefix (const gchar *prefix);
-gboolean glade_keyval_valid (guint val);
-
G_END_DECLS
#endif /* __GLADE_BUILTINS_H__ */
Modified: branches/builder/gladeui/glade-command.c
==============================================================================
--- branches/builder/gladeui/glade-command.c (original)
+++ branches/builder/gladeui/glade-command.c Wed Apr 2 06:17:18 2008
@@ -364,8 +364,9 @@
#if 0
{
gchar *str =
- glade_property_class_make_string_from_gvalue
- (sdata->property->klass, &new_value);
+ glade_widget_adaptor_string_from_value
+ (GLADE_WIDGET_ADAPTOR (sdata->property->klass->handle),
+ sdata->property->klass, &new_value);
g_print ("Setting %s property of %s to %s (sumode: %d)\n",
sdata->property->klass->id,
@@ -550,8 +551,10 @@
else
{
sdata = me->sdata->data;
- value_name = glade_property_class_make_string_from_gvalue (sdata->property->klass,
- sdata->new_value);
+ value_name = glade_widget_adaptor_string_from_value
+ (GLADE_WIDGET_ADAPTOR (sdata->property->klass->handle),
+ sdata->property->klass, sdata->new_value);
+
if (!value_name || strlen (value_name) > MAX_UNDO_MENU_ITEM_VALUE_LEN
|| strchr (value_name, '_')) {
description = g_strdup_printf (_("Setting %s of %s"),
Modified: branches/builder/gladeui/glade-editor-property.c
==============================================================================
--- branches/builder/gladeui/glade-editor-property.c (original)
+++ branches/builder/gladeui/glade-editor-property.c Wed Apr 2 06:17:18 2008
@@ -70,61 +70,6 @@
#define FLAGS_COLUMN_SETTING 0
#define FLAGS_COLUMN_SYMBOL 1
-/*******************************************************************************
- Boiler plate macros (inspired from glade-command.c)
- *******************************************************************************/
-#define MAKE_TYPE(func, type, parent) \
-GType \
-func ## _get_type (void) \
-{ \
- static GType cmd_type = 0; \
- \
- if (!cmd_type) \
- { \
- static const GTypeInfo info = \
- { \
- sizeof (type ## Class), \
- (GBaseInitFunc) NULL, \
- (GBaseFinalizeFunc) NULL, \
- (GClassInitFunc) func ## _class_init, \
- (GClassFinalizeFunc) NULL, \
- NULL, \
- sizeof (type), \
- 0, \
- (GInstanceInitFunc) NULL \
- }; \
- \
- cmd_type = g_type_register_static (parent, #type, &info, 0); \
- } \
- \
- return cmd_type; \
-} \
-
-
-#define GLADE_MAKE_EPROP(type, func) \
-static void \
-func ## _finalize (GObject *object); \
-static void \
-func ## _load (GladeEditorProperty *me, GladeProperty *property); \
-static GtkWidget * \
-func ## _create_input (GladeEditorProperty *me); \
-static void \
-func ## _class_init (gpointer parent_tmp, gpointer notused) \
-{ \
- GladeEditorPropertyClass *parent = parent_tmp; \
- GObjectClass* object_class; \
- object_class = G_OBJECT_CLASS (parent); \
- parent->load = func ## _load; \
- parent->create_input = func ## _create_input; \
- object_class->finalize = func ## _finalize; \
-} \
-typedef struct { \
- GladeEditorPropertyClass cmd; \
-} type ## Class; \
-static MAKE_TYPE(func, type, GLADE_TYPE_EDITOR_PROPERTY)
-
-
-
/*******************************************************************************
GladeEditorPropertyClass
@@ -134,9 +79,15 @@
static void glade_editor_property_load_common (GladeEditorProperty *eprop,
GladeProperty *property);
-/* For use in editor implementations
+/**
+ * glade_editor_property_commit:
+ * @eprop: A #GladeEditorProperty
+ * @value: The #GValue
+ *
+ * Commits the value onto the widget and glade-command interface
+ * (for use in GladeEditorProperty implementations)
*/
-static void
+void
glade_editor_property_commit (GladeEditorProperty *eprop,
GValue *value)
{
@@ -596,7 +547,6 @@
} GladeEPropNumeric;
GLADE_MAKE_EPROP (GladeEPropNumeric, glade_eprop_numeric)
-#define GLADE_TYPE_EPROP_NUMERIC (glade_eprop_numeric_get_type())
#define GLADE_EPROP_NUMERIC(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EPROP_NUMERIC, GladeEPropNumeric))
#define GLADE_EPROP_NUMERIC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EPROP_NUMERIC, GladeEPropNumericClass))
#define GLADE_IS_EPROP_NUMERIC(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_NUMERIC))
@@ -717,7 +667,6 @@
} GladeEPropEnum;
GLADE_MAKE_EPROP (GladeEPropEnum, glade_eprop_enum)
-#define GLADE_TYPE_EPROP_ENUM (glade_eprop_enum_get_type())
#define GLADE_EPROP_ENUM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EPROP_ENUM, GladeEPropEnum))
#define GLADE_EPROP_ENUM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EPROP_ENUM, GladeEPropEnumClass))
#define GLADE_IS_EPROP_ENUM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_ENUM))
@@ -871,7 +820,6 @@
} GladeEPropFlags;
GLADE_MAKE_EPROP (GladeEPropFlags, glade_eprop_flags)
-#define GLADE_TYPE_EPROP_FLAGS (glade_eprop_flags_get_type())
#define GLADE_EPROP_FLAGS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EPROP_FLAGS, GladeEPropFlags))
#define GLADE_EPROP_FLAGS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EPROP_FLAGS, GladeEPropFlagsClass))
#define GLADE_IS_EPROP_FLAGS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_FLAGS))
@@ -1160,7 +1108,6 @@
} GladeEPropColor;
GLADE_MAKE_EPROP (GladeEPropColor, glade_eprop_color)
-#define GLADE_TYPE_EPROP_COLOR (glade_eprop_color_get_type())
#define GLADE_EPROP_COLOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EPROP_COLOR, GladeEPropColor))
#define GLADE_EPROP_COLOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EPROP_COLOR, GladeEPropColorClass))
#define GLADE_IS_EPROP_COLOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_COLOR))
@@ -1187,8 +1134,9 @@
if (property)
{
- if ((text = glade_property_class_make_string_from_gvalue
- (eprop->klass, property->value)) != NULL)
+ if ((text = glade_widget_adaptor_string_from_value
+ (GLADE_WIDGET_ADAPTOR (eprop->klass->handle),
+ eprop->klass, property->value)) != NULL)
{
gtk_entry_set_text (GTK_ENTRY (eprop_color->entry), text);
g_free (text);
@@ -1268,7 +1216,6 @@
} GladeEPropNamedIcon;
GLADE_MAKE_EPROP (GladeEPropNamedIcon, glade_eprop_named_icon)
-#define GLADE_TYPE_EPROP_NAMED_ICON (glade_eprop_named_icon_get_type())
#define GLADE_EPROP_NAMED_ICON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EPROP_NAMED_ICON, GladeEPropNamedIcon))
#define GLADE_EPROP_NAMED_ICON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EPROP_NAMED_ICON, GladeEPropNamedIconClass))
#define GLADE_IS_EPROP_NAMED_ICON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_NAMED_ICON))
@@ -1478,7 +1425,6 @@
} GladeEPropText;
GLADE_MAKE_EPROP (GladeEPropText, glade_eprop_text)
-#define GLADE_TYPE_EPROP_TEXT (glade_eprop_text_get_type())
#define GLADE_EPROP_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EPROP_TEXT, GladeEPropText))
#define GLADE_EPROP_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EPROP_TEXT, GladeEPropTextClass))
#define GLADE_IS_EPROP_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_TEXT))
@@ -1519,8 +1465,9 @@
if (G_VALUE_HOLDS (property->value, G_TYPE_STRV) ||
G_VALUE_HOLDS (property->value, G_TYPE_VALUE_ARRAY))
{
- gchar *text = glade_property_class_make_string_from_gvalue (
- property->klass, property->value);
+ gchar *text = glade_widget_adaptor_string_from_value
+ (GLADE_WIDGET_ADAPTOR (property->klass->handle),
+ property->klass, property->value);
gtk_text_buffer_set_text (buffer, text ? text : "", -1);
g_free (text);
}
@@ -1860,7 +1807,6 @@
} GladeEPropBool;
GLADE_MAKE_EPROP (GladeEPropBool, glade_eprop_bool)
-#define GLADE_TYPE_EPROP_BOOL (glade_eprop_bool_get_type())
#define GLADE_EPROP_BOOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EPROP_BOOL, GladeEPropBool))
#define GLADE_EPROP_BOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EPROP_BOOL, GladeEPropBoolClass))
#define GLADE_IS_EPROP_BOOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_BOOL))
@@ -1942,7 +1888,6 @@
} GladeEPropUnichar;
GLADE_MAKE_EPROP (GladeEPropUnichar, glade_eprop_unichar)
-#define GLADE_TYPE_EPROP_UNICHAR (glade_eprop_unichar_get_type())
#define GLADE_EPROP_UNICHAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EPROP_UNICHAR, GladeEPropUnichar))
#define GLADE_EPROP_UNICHAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EPROP_UNICHAR, GladeEPropUnicharClass))
#define GLADE_IS_EPROP_UNICHAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_UNICHAR))
@@ -2072,7 +2017,6 @@
} GladeEPropResource;
GLADE_MAKE_EPROP (GladeEPropResource, glade_eprop_resource)
-#define GLADE_TYPE_EPROP_RESOURCE (glade_eprop_resource_get_type())
#define GLADE_EPROP_RESOURCE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EPROP_RESOURCE, GladeEPropResource))
#define GLADE_EPROP_RESOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EPROP_RESOURCE, GladeEPropResourceClass))
#define GLADE_IS_EPROP_RESOURCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_RESOURCE))
@@ -2173,8 +2117,9 @@
if (property == NULL) return;
- file = glade_property_class_make_string_from_gvalue
- (eprop->klass, property->value);
+ file = glade_widget_adaptor_string_from_value
+ (GLADE_WIDGET_ADAPTOR (eprop->klass->handle),
+ eprop->klass, property->value);
if (file)
{
gtk_entry_set_text (GTK_ENTRY (eprop_resource->entry), file);
@@ -2238,7 +2183,6 @@
} GladeEPropObject;
GLADE_MAKE_EPROP (GladeEPropObject, glade_eprop_object)
-#define GLADE_TYPE_EPROP_OBJECT (glade_eprop_object_get_type())
#define GLADE_EPROP_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EPROP_OBJECT, GladeEPropObject))
#define GLADE_EPROP_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EPROP_OBJECT, GladeEPropObjectClass))
#define GLADE_IS_EPROP_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_OBJECT))
@@ -2682,8 +2626,9 @@
if (property == NULL) return;
- if ((obj_name = glade_property_class_make_string_from_gvalue
- (eprop->klass, property->value)) != NULL)
+ if ((obj_name = glade_widget_adaptor_string_from_value
+ (GLADE_WIDGET_ADAPTOR (eprop->klass->handle),
+ eprop->klass, property->value)) != NULL)
{
gtk_entry_set_text (GTK_ENTRY (eprop_object->entry), obj_name);
g_free (obj_name);
@@ -2728,7 +2673,6 @@
} GladeEPropObjects;
GLADE_MAKE_EPROP (GladeEPropObjects, glade_eprop_objects)
-#define GLADE_TYPE_EPROP_OBJECTS (glade_eprop_objects_get_type())
#define GLADE_EPROP_OBJECTS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EPROP_OBJECTS, GladeEPropObjects))
#define GLADE_EPROP_OBJECTS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EPROP_OBJECTS, GladeEPropObjectsClass))
#define GLADE_IS_EPROP_OBJECTS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_OBJECTS))
@@ -2753,8 +2697,9 @@
if (property == NULL) return;
- if ((obj_name = glade_property_class_make_string_from_gvalue
- (eprop->klass, property->value)) != NULL)
+ if ((obj_name = glade_widget_adaptor_string_from_value
+ (GLADE_WIDGET_ADAPTOR (eprop->klass->handle),
+ eprop->klass, property->value)) != NULL)
{
gtk_entry_set_text (GTK_ENTRY (eprop_objects->entry), obj_name);
g_free (obj_name);
@@ -2913,7 +2858,6 @@
} GladeEPropAdjustment;
GLADE_MAKE_EPROP (GladeEPropAdjustment, glade_eprop_adjustment)
-#define GLADE_TYPE_EPROP_ADJUSTMENT (glade_eprop_adjustment_get_type())
#define GLADE_EPROP_ADJUSTMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EPROP_ADJUSTMENT, GladeEPropAdjustment))
#define GLADE_EPROP_ADJUSTMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EPROP_ADJUSTMENT, GladeEPropAdjustmentClass))
#define GLADE_IS_EPROP_ADJUSTMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_ADJUSTMENT))
@@ -3165,813 +3109,10 @@
/*******************************************************************************
- GladeEditorPropertyAccelClass
- *******************************************************************************/
-enum {
- ACCEL_COLUMN_SIGNAL = 0,
- ACCEL_COLUMN_REAL_SIGNAL,
- ACCEL_COLUMN_KEY,
- ACCEL_COLUMN_MOD_SHIFT,
- ACCEL_COLUMN_MOD_CNTL,
- ACCEL_COLUMN_MOD_ALT,
- ACCEL_COLUMN_IS_CLASS,
- ACCEL_COLUMN_IS_SIGNAL,
- ACCEL_COLUMN_KEY_ENTERED,
- ACCEL_COLUMN_KEY_SLOT,
- ACCEL_NUM_COLUMNS
-};
-
-enum {
- ACCEL_COMBO_COLUMN_TEXT = 0,
- ACCEL_COMBO_NUM_COLUMNS,
-};
-
-typedef struct {
- GladeEditorProperty parent_instance;
-
- GtkWidget *entry;
- GList *parent_iters;
- GtkTreeModel *model;
-} GladeEPropAccel;
-
-typedef struct {
- GtkTreeIter *iter;
- gchar *name; /* <-- dont free */
-} GladeEpropIterTab;
-
-
-static GtkTreeModel *keysyms_model = NULL;
-
-GLADE_MAKE_EPROP (GladeEPropAccel, glade_eprop_accel)
-#define GLADE_TYPE_EPROP_ACCEL (glade_eprop_accel_get_type())
-#define GLADE_EPROP_ACCEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EPROP_ACCEL, GladeEPropAccel))
-#define GLADE_EPROP_ACCEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EPROP_ACCEL, GladeEPropAccelClass))
-#define GLADE_IS_EPROP_ACCEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_ACCEL))
-#define GLADE_IS_EPROP_ACCEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_EPROP_ACCEL))
-#define GLADE_EPROP_ACCEL_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GLADE_EPROP_ACCEL, GladeEPropAccelClass))
-
-
-static GtkTreeModel *
-create_keysyms_model (void)
-{
- GtkTreeModel *model;
- GtkTreeIter iter, alphanum, fkey, keypad, other, extra;
- GtkTreeIter *parent;
- gint i;
-
- model = (GtkTreeModel *)gtk_tree_store_new
- (ACCEL_COMBO_NUM_COLUMNS,
- G_TYPE_STRING); /* The Key charachter name */
-
- gtk_tree_store_append (GTK_TREE_STORE (model), &alphanum, NULL);
- gtk_tree_store_set
- (GTK_TREE_STORE (model), &alphanum,
- ACCEL_COMBO_COLUMN_TEXT, _("Alphanumerical"), -1);
-
- gtk_tree_store_append (GTK_TREE_STORE (model), &extra, NULL);
- gtk_tree_store_set
- (GTK_TREE_STORE (model), &extra,
- ACCEL_COMBO_COLUMN_TEXT, _("Extra"), -1);
-
- gtk_tree_store_append (GTK_TREE_STORE (model), &keypad, NULL);
- gtk_tree_store_set
- (GTK_TREE_STORE (model), &keypad,
- ACCEL_COMBO_COLUMN_TEXT, _("Keypad"), -1);
-
- gtk_tree_store_append (GTK_TREE_STORE (model), &fkey, NULL);
- gtk_tree_store_set
- (GTK_TREE_STORE (model), &fkey,
- ACCEL_COMBO_COLUMN_TEXT, _("Functions"), -1);
-
- gtk_tree_store_append (GTK_TREE_STORE (model), &other, NULL);
- gtk_tree_store_set
- (GTK_TREE_STORE (model), &other,
- ACCEL_COMBO_COLUMN_TEXT, _("Other"), -1);
-
- parent = &alphanum;
-
- for (i = 0; GladeKeys[i].name != NULL; i++)
- {
- gtk_tree_store_append (GTK_TREE_STORE (model), &iter, parent);
- gtk_tree_store_set
- (GTK_TREE_STORE (model), &iter,
- ACCEL_COMBO_COLUMN_TEXT, GladeKeys[i].name, -1);
-
- if (!strcmp (GladeKeys[i].name, GLADE_KEYS_LAST_ALPHANUM))
- parent = &extra;
- else if (!strcmp (GladeKeys[i].name, GLADE_KEYS_LAST_EXTRA))
- parent = &keypad;
- else if (!strcmp (GladeKeys[i].name, GLADE_KEYS_LAST_KP))
- parent = &fkey;
- else if (!strcmp (GladeKeys[i].name, GLADE_KEYS_LAST_FKEY))
- parent = &other;
- }
- return model;
-}
-
-static void
-glade_eprop_accel_finalize (GObject *object)
-{
- /* Chain up */
- G_OBJECT_CLASS (editor_property_class)->finalize (object);
-}
-
-static void
-glade_eprop_accel_load (GladeEditorProperty *eprop,
- GladeProperty *property)
-{
- GladeEPropAccel *eprop_accel = GLADE_EPROP_ACCEL (eprop);
- gchar *accels;
-
- /* Chain up first */
- editor_property_class->load (eprop, property);
-
- if (property == NULL) return;
-
- if ((accels = glade_property_class_make_string_from_gvalue
- (eprop->klass, property->value)) != NULL)
- {
- gtk_entry_set_text (GTK_ENTRY (eprop_accel->entry), accels);
- g_free (accels);
- }
- else
- gtk_entry_set_text (GTK_ENTRY (eprop_accel->entry), "");
-
-}
-
-static gint
-eprop_find_iter (GladeEpropIterTab *iter_tab,
- gchar *name)
-{
- return strcmp (iter_tab->name, name);
-}
-
-static void
-iter_tab_free (GladeEpropIterTab *iter_tab)
-{
- gtk_tree_iter_free (iter_tab->iter);
- g_free (iter_tab);
-}
-
-static void
-glade_eprop_accel_populate_view (GladeEditorProperty *eprop,
- GtkTreeView *view)
-{
- GladeEPropAccel *eprop_accel = GLADE_EPROP_ACCEL (eprop);
- GladeSignalClass *sclass;
- GladeWidgetAdaptor *adaptor = glade_widget_adaptor_from_pclass (eprop->klass);
- GtkTreeStore *model = (GtkTreeStore *)gtk_tree_view_get_model (view);
- GtkTreeIter iter;
- GladeEpropIterTab *parent_tab;
- GladeAccelInfo *info;
- GList *list, *l, *found, *accelerators;
- gchar *name;
-
- accelerators = g_value_get_boxed (eprop->property->value);
-
- /* First make parent iters...
- */
- for (list = adaptor->signals; list; list = list->next)
- {
- sclass = list->data;
-
- /* Only action signals have accelerators. */
- if ((sclass->query.signal_flags & G_SIGNAL_ACTION) == 0)
- continue;
-
- if (g_list_find_custom (eprop_accel->parent_iters,
- sclass->type,
- (GCompareFunc)eprop_find_iter) == NULL)
- {
- gtk_tree_store_append (model, &iter, NULL);
- gtk_tree_store_set (model, &iter,
- ACCEL_COLUMN_SIGNAL, sclass->type,
- ACCEL_COLUMN_IS_CLASS, TRUE,
- ACCEL_COLUMN_IS_SIGNAL, FALSE,
- -1);
-
- parent_tab = g_new0 (GladeEpropIterTab, 1);
- parent_tab->name = sclass->type;
- parent_tab->iter = gtk_tree_iter_copy (&iter);
-
- eprop_accel->parent_iters =
- g_list_prepend (eprop_accel->parent_iters,
- parent_tab);
- }
- }
-
- /* Now we populate...
- */
- for (list = adaptor->signals; list; list = list->next)
- {
- sclass = list->data;
-
- /* Only action signals have accelerators. */
- if ((sclass->query.signal_flags & G_SIGNAL_ACTION) == 0)
- continue;
-
- if ((found = g_list_find_custom (eprop_accel->parent_iters,
- sclass->type,
- (GCompareFunc)eprop_find_iter)) != NULL)
- {
- parent_tab = found->data;
- name = g_strdup_printf (" %s", sclass->name);
-
- /* Populate from accelerator list
- */
- for (l = accelerators; l; l = l->next)
- {
- info = l->data;
-
- if (strcmp (info->signal, sclass->name))
- continue;
-
- gtk_tree_store_append (model, &iter, parent_tab->iter);
- gtk_tree_store_set
- (model, &iter,
- ACCEL_COLUMN_SIGNAL, name,
- ACCEL_COLUMN_REAL_SIGNAL, sclass->name,
- ACCEL_COLUMN_IS_CLASS, FALSE,
- ACCEL_COLUMN_IS_SIGNAL, TRUE,
- ACCEL_COLUMN_MOD_SHIFT,
- (info->modifiers & GDK_SHIFT_MASK) != 0,
- ACCEL_COLUMN_MOD_CNTL,
- (info->modifiers & GDK_CONTROL_MASK) != 0,
- ACCEL_COLUMN_MOD_ALT,
- (info->modifiers & GDK_MOD1_MASK) != 0,
- ACCEL_COLUMN_KEY,
- glade_builtin_string_from_key (info->key),
- ACCEL_COLUMN_KEY_ENTERED, TRUE,
- ACCEL_COLUMN_KEY_SLOT, FALSE,
- -1);
- }
-
- /* Append a new empty slot at the end */
- gtk_tree_store_append (model, &iter, parent_tab->iter);
- gtk_tree_store_set
- (model, &iter,
- ACCEL_COLUMN_SIGNAL, name,
- ACCEL_COLUMN_REAL_SIGNAL, sclass->name,
- ACCEL_COLUMN_IS_CLASS, FALSE,
- ACCEL_COLUMN_IS_SIGNAL, TRUE,
- ACCEL_COLUMN_MOD_SHIFT, FALSE,
- ACCEL_COLUMN_MOD_CNTL, FALSE,
- ACCEL_COLUMN_MOD_ALT, FALSE,
- ACCEL_COLUMN_KEY, _("<choose a key>"),
- ACCEL_COLUMN_KEY_ENTERED, FALSE,
- ACCEL_COLUMN_KEY_SLOT, TRUE,
- -1);
-
- g_free (name);
- }
- }
-}
-
-static void
-key_edited (GtkCellRendererText *cell,
- const gchar *path_string,
- const gchar *new_text,
- GladeEditorProperty *eprop)
-{
- GladeEPropAccel *eprop_accel = GLADE_EPROP_ACCEL (eprop);
- gboolean key_was_set;
- const gchar *text;
- GtkTreeIter iter, parent_iter, new_iter;
-
- if (!gtk_tree_model_get_iter_from_string (eprop_accel->model,
- &iter, path_string))
- return;
-
- gtk_tree_model_get (eprop_accel->model, &iter,
- ACCEL_COLUMN_KEY_ENTERED, &key_was_set,
- -1);
-
- /* If user selects "none"; remove old entry or ignore new one.
- */
- if (!new_text || new_text[0] == '\0' ||
- glade_builtin_string_from_key ((guint)new_text[0]) == NULL ||
- g_utf8_collate (new_text, _("None")) == 0 ||
- g_utf8_collate (new_text, _("<choose a key>")) == 0)
- {
- if (key_was_set)
- gtk_tree_store_remove
- (GTK_TREE_STORE (eprop_accel->model), &iter);
-
- return;
- }
-
- if (glade_builtin_key_from_string (new_text) != 0)
- text = new_text;
- else
- text = glade_builtin_string_from_key ((guint)new_text[0]);
-
- gtk_tree_store_set
- (GTK_TREE_STORE (eprop_accel->model), &iter,
- ACCEL_COLUMN_KEY, text,
- ACCEL_COLUMN_KEY_ENTERED, TRUE,
- ACCEL_COLUMN_KEY_SLOT, FALSE,
- -1);
-
- /* Append a new one if needed
- */
- if (key_was_set == FALSE &&
- gtk_tree_model_iter_parent (eprop_accel->model,
- &parent_iter, &iter))
- {
- gchar *signal, *real_signal;
-
- gtk_tree_model_get (eprop_accel->model, &iter,
- ACCEL_COLUMN_SIGNAL, &signal,
- ACCEL_COLUMN_REAL_SIGNAL, &real_signal,
- -1);
-
- /* Append a new empty slot at the end */
- gtk_tree_store_insert_after (GTK_TREE_STORE (eprop_accel->model),
- &new_iter, &parent_iter, &iter);
- gtk_tree_store_set (GTK_TREE_STORE (eprop_accel->model), &new_iter,
- ACCEL_COLUMN_SIGNAL, signal,
- ACCEL_COLUMN_REAL_SIGNAL, real_signal,
- ACCEL_COLUMN_IS_CLASS, FALSE,
- ACCEL_COLUMN_IS_SIGNAL, TRUE,
- ACCEL_COLUMN_MOD_SHIFT, FALSE,
- ACCEL_COLUMN_MOD_CNTL, FALSE,
- ACCEL_COLUMN_MOD_ALT, FALSE,
- ACCEL_COLUMN_KEY, _("<choose a key>"),
- ACCEL_COLUMN_KEY_ENTERED, FALSE,
- ACCEL_COLUMN_KEY_SLOT, TRUE,
- -1);
- g_free (signal);
- g_free (real_signal);
- }
-}
-
-static void
-modifier_toggled (GtkCellRendererToggle *cell,
- gchar *path_string,
- GladeEditorProperty *eprop)
-{
- GladeEPropAccel *eprop_accel = GLADE_EPROP_ACCEL (eprop);
- GtkTreeIter iter;
- gint column;
- gboolean active, key_entered;
-
- if (!gtk_tree_model_get_iter_from_string (eprop_accel->model,
- &iter, path_string))
- return;
-
- column = GPOINTER_TO_INT (g_object_get_data
- (G_OBJECT (cell), "model-column"));
-
- gtk_tree_model_get
- (eprop_accel->model, &iter,
- ACCEL_COLUMN_KEY_ENTERED, &key_entered,
- column, &active, -1);
-
- if (key_entered)
- gtk_tree_store_set
- (GTK_TREE_STORE (eprop_accel->model), &iter,
- column, !active, -1);
-}
-
-
-static GtkWidget *
-glade_eprop_accel_view (GladeEditorProperty *eprop)
-{
- GladeEPropAccel *eprop_accel = GLADE_EPROP_ACCEL (eprop);
- GtkWidget *view_widget;
- GtkCellRenderer *renderer;
- GtkTreeViewColumn *column;
-
- eprop_accel->model = (GtkTreeModel *)gtk_tree_store_new
- (ACCEL_NUM_COLUMNS,
- G_TYPE_STRING, /* The GSignal name formatted for display */
- G_TYPE_STRING, /* The GSignal name */
- G_TYPE_STRING, /* The Gdk keycode */
- G_TYPE_BOOLEAN, /* The shift modifier */
- G_TYPE_BOOLEAN, /* The cntl modifier */
- G_TYPE_BOOLEAN, /* The alt modifier */
- G_TYPE_BOOLEAN, /* Whether this is a class entry */
- G_TYPE_BOOLEAN, /* Whether this is a signal entry (oposite of above) */
- G_TYPE_BOOLEAN, /* Whether the key has been entered for this row */
- G_TYPE_BOOLEAN); /* Oposite of above */
-
- view_widget = gtk_tree_view_new_with_model (eprop_accel->model);
- g_object_set (G_OBJECT (view_widget), "enable-search", FALSE, NULL);
-
- /********************* fake invisible column *********************/
- renderer = gtk_cell_renderer_text_new ();
- g_object_set (G_OBJECT (renderer), "editable", FALSE, "visible", FALSE, NULL);
-
- column = gtk_tree_view_column_new_with_attributes (NULL, renderer, NULL);
- gtk_tree_view_append_column (GTK_TREE_VIEW (view_widget), column);
-
- gtk_tree_view_column_set_visible (column, FALSE);
- gtk_tree_view_set_expander_column (GTK_TREE_VIEW (view_widget), column);
-
- /********************* signal name column *********************/
- renderer = gtk_cell_renderer_text_new ();
- g_object_set (G_OBJECT (renderer),
- "editable", FALSE,
- "weight", PANGO_WEIGHT_BOLD,
- NULL);
-
- column = gtk_tree_view_column_new_with_attributes
- (_("Signal"), renderer,
- "text", ACCEL_COLUMN_SIGNAL,
- "weight-set", ACCEL_COLUMN_IS_CLASS,
- NULL);
-
- g_object_set (G_OBJECT (column), "expand", TRUE, NULL);
-
- gtk_tree_view_append_column (GTK_TREE_VIEW (view_widget), column);
-
- /********************* key name column *********************/
- if (keysyms_model == NULL)
- keysyms_model = create_keysyms_model ();
-
- renderer = gtk_cell_renderer_combo_new ();
- g_object_set (G_OBJECT (renderer),
- "editable", TRUE,
- "model", keysyms_model,
- "text-column", ACCEL_COMBO_COLUMN_TEXT,
- "has-entry", TRUE,
- "style", PANGO_STYLE_ITALIC,
- "foreground", "Gray",
- NULL);
-
- g_signal_connect (renderer, "edited",
- G_CALLBACK (key_edited), eprop);
-
- column = gtk_tree_view_column_new_with_attributes
- (_("Key"), renderer,
- "text", ACCEL_COLUMN_KEY,
- "style-set", ACCEL_COLUMN_KEY_SLOT,
- "foreground-set", ACCEL_COLUMN_KEY_SLOT,
- "visible", ACCEL_COLUMN_IS_SIGNAL,
- NULL);
-
- g_object_set (G_OBJECT (column), "expand", TRUE, NULL);
-
- gtk_tree_view_append_column (GTK_TREE_VIEW (view_widget), column);
-
- /********************* shift modifier column *********************/
- renderer = gtk_cell_renderer_toggle_new ();
- column = gtk_tree_view_column_new_with_attributes
- (_("Shift"), renderer,
- "visible", ACCEL_COLUMN_IS_SIGNAL,
- "sensitive", ACCEL_COLUMN_KEY_ENTERED,
- "active", ACCEL_COLUMN_MOD_SHIFT,
- NULL);
-
- g_object_set_data (G_OBJECT (renderer), "model-column",
- GINT_TO_POINTER (ACCEL_COLUMN_MOD_SHIFT));
- g_signal_connect (G_OBJECT (renderer), "toggled",
- G_CALLBACK (modifier_toggled), eprop);
-
- gtk_tree_view_append_column (GTK_TREE_VIEW (view_widget), column);
-
- /********************* control modifier column *********************/
- renderer = gtk_cell_renderer_toggle_new ();
- column = gtk_tree_view_column_new_with_attributes
- (_("Control"), renderer,
- "visible", ACCEL_COLUMN_IS_SIGNAL,
- "sensitive", ACCEL_COLUMN_KEY_ENTERED,
- "active", ACCEL_COLUMN_MOD_CNTL,
- NULL);
-
- g_object_set_data (G_OBJECT (renderer), "model-column",
- GINT_TO_POINTER (ACCEL_COLUMN_MOD_CNTL));
- g_signal_connect (G_OBJECT (renderer), "toggled",
- G_CALLBACK (modifier_toggled), eprop);
-
- gtk_tree_view_append_column (GTK_TREE_VIEW (view_widget), column);
-
- /********************* alt modifier column *********************/
- renderer = gtk_cell_renderer_toggle_new ();
- column = gtk_tree_view_column_new_with_attributes
- (_("Alt"), renderer,
- "visible", ACCEL_COLUMN_IS_SIGNAL,
- "sensitive", ACCEL_COLUMN_KEY_ENTERED,
- "active", ACCEL_COLUMN_MOD_ALT,
- NULL);
-
- g_object_set_data (G_OBJECT (renderer), "model-column",
- GINT_TO_POINTER (ACCEL_COLUMN_MOD_ALT));
- g_signal_connect (G_OBJECT (renderer), "toggled",
- G_CALLBACK (modifier_toggled), eprop);
-
- gtk_tree_view_append_column (GTK_TREE_VIEW (view_widget), column);
-
- return view_widget;
-}
-
-static gboolean
-glade_eprop_accel_accum_accelerators (GtkTreeModel *model,
- GtkTreePath *path,
- GtkTreeIter *iter,
- GList **ret)
-{
- GladeAccelInfo *info;
- gchar *signal, *key_str;
- gboolean shift, cntl, alt, entered;
-
- gtk_tree_model_get (model, iter, ACCEL_COLUMN_KEY_ENTERED, &entered, -1);
- if (entered == FALSE) return FALSE;
-
- gtk_tree_model_get (model, iter,
- ACCEL_COLUMN_REAL_SIGNAL, &signal,
- ACCEL_COLUMN_KEY, &key_str,
- ACCEL_COLUMN_MOD_SHIFT, &shift,
- ACCEL_COLUMN_MOD_CNTL, &cntl,
- ACCEL_COLUMN_MOD_ALT, &alt,
- -1);
-
- info = g_new0 (GladeAccelInfo, 1);
- info->signal = signal;
- info->key = glade_builtin_key_from_string (key_str);
- info->modifiers = (shift ? GDK_SHIFT_MASK : 0) |
- (cntl ? GDK_CONTROL_MASK : 0) |
- (alt ? GDK_MOD1_MASK : 0);
-
- *ret = g_list_prepend (*ret, info);
-
- g_free (key_str);
-
- return FALSE;
-}
-
-
-static void
-glade_eprop_accel_show_dialog (GtkWidget *dialog_button,
- GladeEditorProperty *eprop)
-{
- GladeEPropAccel *eprop_accel = GLADE_EPROP_ACCEL (eprop);
- GtkWidget *dialog, *parent, *vbox, *sw, *tree_view;
- GladeProject *project;
- GValue *value;
- GList *accelerators = NULL;
- gint res;
-
- project = glade_widget_get_project (eprop->property->widget);
- parent = gtk_widget_get_toplevel (GTK_WIDGET (eprop));
-
- dialog = gtk_dialog_new_with_buttons (_("Choose accelerator keys..."),
- GTK_WINDOW (parent),
- GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_STOCK_CLEAR, GLADE_RESPONSE_CLEAR,
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- GTK_STOCK_OK, GTK_RESPONSE_OK,
- NULL);
-
- gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
-
- vbox = gtk_vbox_new (FALSE, 6);
- gtk_widget_show (vbox);
-
- gtk_container_set_border_width (GTK_CONTAINER (vbox), 6);
-
- gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), vbox, TRUE, TRUE, 0);
-
- sw = gtk_scrolled_window_new (NULL, NULL);
- gtk_widget_show (sw);
- gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0);
- gtk_widget_set_size_request (sw, 400, 200);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
- GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
- gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN);
-
- tree_view = glade_eprop_accel_view (eprop);
- glade_eprop_accel_populate_view (eprop, GTK_TREE_VIEW (tree_view));
-
- gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
-
- gtk_widget_show (tree_view);
- gtk_container_add (GTK_CONTAINER (sw), tree_view);
-
- /* Run the dialog */
- res = gtk_dialog_run (GTK_DIALOG (dialog));
- if (res == GTK_RESPONSE_OK)
- {
- gtk_tree_model_foreach
- (gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view)),
- (GtkTreeModelForeachFunc)
- glade_eprop_accel_accum_accelerators, &accelerators);
-
- value = g_new0 (GValue, 1);
- g_value_init (value, GLADE_TYPE_ACCEL_GLIST);
- g_value_take_boxed (value, accelerators);
-
- glade_editor_property_commit (eprop, value);
-
- g_value_unset (value);
- g_free (value);
- }
- else if (res == GLADE_RESPONSE_CLEAR)
- {
- value = g_new0 (GValue, 1);
- g_value_init (value, GLADE_TYPE_ACCEL_GLIST);
- g_value_set_boxed (value, NULL);
-
- glade_editor_property_commit (eprop, value);
-
- g_value_unset (value);
- g_free (value);
- }
-
- /* Clean up ...
- */
- gtk_widget_destroy (dialog);
-
- g_object_unref (G_OBJECT (eprop_accel->model));
- eprop_accel->model = NULL;
-
- if (eprop_accel->parent_iters)
- {
- g_list_foreach (eprop_accel->parent_iters, (GFunc)iter_tab_free, NULL);
- g_list_free (eprop_accel->parent_iters);
- eprop_accel->parent_iters = NULL;
- }
-
-}
-
-static GtkWidget *
-glade_eprop_accel_create_input (GladeEditorProperty *eprop)
-{
- GladeEPropAccel *eprop_accel = GLADE_EPROP_ACCEL (eprop);
- GtkWidget *hbox;
- GtkWidget *button;
-
- hbox = gtk_hbox_new (FALSE, 0);
- eprop_accel->entry = gtk_entry_new ();
- gtk_entry_set_editable (GTK_ENTRY (eprop_accel->entry), FALSE);
- gtk_widget_show (eprop_accel->entry);
- gtk_box_pack_start (GTK_BOX (hbox), eprop_accel->entry, TRUE, TRUE, 0);
-
- button = gtk_button_new_with_label ("...");
- gtk_widget_show (button);
- gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
-
- g_signal_connect (G_OBJECT (button), "clicked",
- G_CALLBACK (glade_eprop_accel_show_dialog),
- eprop);
-
- return hbox;
-}
-
-
-
-/*******************************************************************************
- Misc static stuff
- *******************************************************************************/
-static GType
-glade_editor_property_type (GParamSpec *pspec)
-{
- GType type = 0;
-
- if (pspec->value_type == GLADE_TYPE_STOCK ||
- G_IS_PARAM_SPEC_ENUM(pspec))
- type = GLADE_TYPE_EPROP_ENUM;
- else if (G_IS_PARAM_SPEC_FLAGS(pspec))
- type = GLADE_TYPE_EPROP_FLAGS;
- else if (G_IS_PARAM_SPEC_VALUE_ARRAY (pspec))
- {
- if (pspec->value_type == G_TYPE_VALUE_ARRAY)
- type = GLADE_TYPE_EPROP_TEXT;
- }
- else if (G_IS_PARAM_SPEC_BOXED(pspec))
- {
- if (pspec->value_type == GDK_TYPE_COLOR)
- type = GLADE_TYPE_EPROP_COLOR;
- else if (pspec->value_type == G_TYPE_STRV)
- type = GLADE_TYPE_EPROP_TEXT;
- }
- else if (G_IS_PARAM_SPEC_STRING(pspec))
- type = GLADE_TYPE_EPROP_TEXT;
- else if (G_IS_PARAM_SPEC_BOOLEAN(pspec))
- type = GLADE_TYPE_EPROP_BOOL;
- else if (G_IS_PARAM_SPEC_FLOAT(pspec) ||
- G_IS_PARAM_SPEC_DOUBLE(pspec) ||
- G_IS_PARAM_SPEC_INT(pspec) ||
- G_IS_PARAM_SPEC_UINT(pspec) ||
- G_IS_PARAM_SPEC_LONG(pspec) ||
- G_IS_PARAM_SPEC_ULONG(pspec) ||
- G_IS_PARAM_SPEC_INT64(pspec) ||
- G_IS_PARAM_SPEC_UINT64(pspec))
- type = GLADE_TYPE_EPROP_NUMERIC;
- else if (G_IS_PARAM_SPEC_UNICHAR(pspec))
- type = GLADE_TYPE_EPROP_UNICHAR;
- else if (G_IS_PARAM_SPEC_OBJECT(pspec))
- {
- if (pspec->value_type == GDK_TYPE_PIXBUF)
- type = GLADE_TYPE_EPROP_RESOURCE;
- else if (pspec->value_type == GTK_TYPE_ADJUSTMENT)
- type = GLADE_TYPE_EPROP_ADJUSTMENT;
- else
- type = GLADE_TYPE_EPROP_OBJECT;
- }
- else if (GLADE_IS_PARAM_SPEC_OBJECTS(pspec))
- type = GLADE_TYPE_EPROP_OBJECTS;
- else if (GLADE_IS_PARAM_SPEC_ACCEL(pspec))
- type = GLADE_TYPE_EPROP_ACCEL;
-
- return type;
-}
-
-/*******************************************************************************
API
*******************************************************************************/
/**
- * glade_editor_property_new:
- * @klass: A #GladePropertyClass
- * @use_command: Whether the undo/redo stack applies here.
- *
- * This is a factory function to create the correct type of
- * editor property that can edit the said type of #GladePropertyClass
- *
- * Returns: A newly created GladeEditorProperty of the correct type
- */
-GladeEditorProperty *
-glade_editor_property_new (GladePropertyClass *klass,
- gboolean use_command)
-{
- GladeEditorProperty *eprop;
- GType type = 0;
-
- /* Find the right type of GladeEditorProperty for this
- * GladePropertyClass.
- */
- if ((type = glade_editor_property_type (klass->pspec)) == 0)
- g_error ("%s : pspec '%s' type '%s' not implemented (%s)\n",
- G_GNUC_PRETTY_FUNCTION,
- klass->name,
- g_type_name (G_PARAM_SPEC_TYPE (klass->pspec)),
- g_type_name (klass->pspec->value_type));
-
- /* special case for resource specs which are hand specified in the catalog. */
- if (klass->resource)
- type = GLADE_TYPE_EPROP_RESOURCE;
-
- /* special case for string specs that denote themed application icons. */
- if (klass->themed_icon)
- type = GLADE_TYPE_EPROP_NAMED_ICON;
-
- /* Create and return the correct type of GladeEditorProperty */
- eprop = g_object_new (type,
- "property-class", klass,
- "use-command", use_command,
- NULL);
-
- return eprop;
-}
-
-/**
- * glade_editor_property_new_from_widget:
- * @widget: A #GladeWidget
- * @property: The widget's property
- * @packing: whether @property indicates a packing property or not.
- * @use_command: Whether the undo/redo stack applies here.
- *
- * This is a convenience function to create a GladeEditorProperty corresponding
- * to @property
- *
- * Returns: A newly created and connected GladeEditorProperty
- */
-GladeEditorProperty *
-glade_editor_property_new_from_widget (GladeWidget *widget,
- const gchar *property,
- gboolean packing,
- gboolean use_command)
-{
- GladeEditorProperty *eprop;
- GladeProperty *p;
-
- if (packing)
- p = glade_widget_get_pack_property (widget, property);
- else
- p = glade_widget_get_property (widget, property);
- g_return_val_if_fail (GLADE_IS_PROPERTY (p), NULL);
-
- eprop = glade_editor_property_new (p->klass, use_command);
- glade_editor_property_load (eprop, p);
-
- return eprop;
-}
-
-/**
- * glade_editor_property_supported:
- * @pspec: A #GParamSpec
- *
- * Returns: whether this pspec is supported by GladeEditorProperties.
- */
-gboolean
-glade_editor_property_supported (GParamSpec *pspec)
-{
- return glade_editor_property_type (pspec) != 0;
-}
-
-
-/**
* glade_editor_property_load:
* @eprop: A #GladeEditorProperty
* @property: A #GladeProperty
@@ -4009,10 +3150,12 @@
g_return_if_fail (widget == NULL || GLADE_IS_WIDGET (widget));
if (widget)
+ {
/* properties are allowed to be missing on some internal widgets */
property = glade_widget_get_property (widget, eprop->klass->id);
- glade_editor_property_load (eprop, property);
+ glade_editor_property_load (eprop, property);
+ }
}
/**
Modified: branches/builder/gladeui/glade-editor-property.h
==============================================================================
--- branches/builder/gladeui/glade-editor-property.h (original)
+++ branches/builder/gladeui/glade-editor-property.h Wed Apr 2 06:17:18 2008
@@ -2,8 +2,69 @@
#ifndef __GLADE_EDITOR_PROPERTY_H__
#define __GLADE_EDITOR_PROPERTY_H__
+#include <gtk/gtk.h>
+
G_BEGIN_DECLS
+
+
+/*******************************************************************************
+ Boiler plate macros (inspired from glade-command.c)
+ *******************************************************************************/
+/* XXX document me ! */
+
+#define GLADE_MAKE_EPROP_TYPE(func, type, parent) \
+GType \
+func ## _get_type (void) \
+{ \
+ static GType cmd_type = 0; \
+ \
+ if (!cmd_type) \
+ { \
+ static const GTypeInfo info = \
+ { \
+ sizeof (type ## Class), \
+ (GBaseInitFunc) NULL, \
+ (GBaseFinalizeFunc) NULL, \
+ (GClassInitFunc) func ## _class_init, \
+ (GClassFinalizeFunc) NULL, \
+ NULL, \
+ sizeof (type), \
+ 0, \
+ (GInstanceInitFunc) NULL \
+ }; \
+ \
+ cmd_type = g_type_register_static (parent, #type, &info, 0); \
+ } \
+ \
+ return cmd_type; \
+} \
+
+
+#define GLADE_MAKE_EPROP(type, func) \
+static void \
+func ## _finalize (GObject *object); \
+static void \
+func ## _load (GladeEditorProperty *me, GladeProperty *property); \
+static GtkWidget * \
+func ## _create_input (GladeEditorProperty *me); \
+static void \
+func ## _class_init (gpointer parent_tmp, gpointer notused) \
+{ \
+ GladeEditorPropertyClass *parent = parent_tmp; \
+ GObjectClass* object_class; \
+ object_class = G_OBJECT_CLASS (parent); \
+ parent->load = func ## _load; \
+ parent->create_input = func ## _create_input; \
+ object_class->finalize = func ## _finalize; \
+} \
+typedef struct { \
+ GladeEditorPropertyClass cmd; \
+} type ## Class; \
+GLADE_MAKE_EPROP_TYPE(func, type, GLADE_TYPE_EDITOR_PROPERTY)
+
+
+
#define GLADE_TYPE_EDITOR_PROPERTY (glade_editor_property_get_type())
#define GLADE_EDITOR_PROPERTY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EDITOR_PROPERTY, GladeEditorProperty))
#define GLADE_EDITOR_PROPERTY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EDITOR_PROPERTY, GladeEditorPropertyClass))
@@ -59,7 +120,6 @@
void (* load) (GladeEditorProperty *, GladeProperty *);
- /* private */
GtkWidget *(* create_input) (GladeEditorProperty *);
void (* gtk_doc_search)(GladeEditorProperty *,
@@ -71,15 +131,7 @@
-GType glade_editor_property_get_type (void);
-
-GladeEditorProperty *glade_editor_property_new (GladePropertyClass *klass,
- gboolean use_command);
-
-GladeEditorProperty *glade_editor_property_new_from_widget (GladeWidget *widget,
- const gchar *property,
- gboolean packing,
- gboolean use_command);
+GType glade_editor_property_get_type (void) G_GNUC_CONST;
void glade_editor_property_load (GladeEditorProperty *eprop,
GladeProperty *property);
@@ -87,12 +139,40 @@
void glade_editor_property_load_by_widget (GladeEditorProperty *eprop,
GladeWidget *widget);
-gboolean glade_editor_property_supported (GParamSpec *pspec);
-
void glade_editor_property_show_info (GladeEditorProperty *eprop);
void glade_editor_property_hide_info (GladeEditorProperty *eprop);
+void glade_editor_property_commit (GladeEditorProperty *eprop,
+ GValue *value);
+
+
+/* Generic eprops */
+#define GLADE_TYPE_EPROP_NUMERIC (glade_eprop_numeric_get_type())
+#define GLADE_TYPE_EPROP_ENUM (glade_eprop_enum_get_type())
+#define GLADE_TYPE_EPROP_FLAGS (glade_eprop_flags_get_type())
+#define GLADE_TYPE_EPROP_COLOR (glade_eprop_color_get_type())
+#define GLADE_TYPE_EPROP_NAMED_ICON (glade_eprop_named_icon_get_type())
+#define GLADE_TYPE_EPROP_TEXT (glade_eprop_text_get_type())
+#define GLADE_TYPE_EPROP_BOOL (glade_eprop_bool_get_type())
+#define GLADE_TYPE_EPROP_UNICHAR (glade_eprop_unichar_get_type())
+#define GLADE_TYPE_EPROP_RESOURCE (glade_eprop_resource_get_type())
+#define GLADE_TYPE_EPROP_OBJECT (glade_eprop_object_get_type())
+#define GLADE_TYPE_EPROP_OBJECTS (glade_eprop_objects_get_type())
+#define GLADE_TYPE_EPROP_ADJUSTMENT (glade_eprop_adjustment_get_type())
+GType glade_eprop_numeric_get_type (void) G_GNUC_CONST;
+GType glade_eprop_enum_get_type (void) G_GNUC_CONST;
+GType glade_eprop_flags_get_type (void) G_GNUC_CONST;
+GType glade_eprop_color_get_type (void) G_GNUC_CONST;
+GType glade_eprop_named_icon_get_type (void) G_GNUC_CONST;
+GType glade_eprop_text_get_type (void) G_GNUC_CONST;
+GType glade_eprop_bool_get_type (void) G_GNUC_CONST;
+GType glade_eprop_unichar_get_type (void) G_GNUC_CONST;
+GType glade_eprop_resource_get_type (void) G_GNUC_CONST;
+GType glade_eprop_object_get_type (void) G_GNUC_CONST;
+GType glade_eprop_objects_get_type (void) G_GNUC_CONST;
+GType glade_eprop_adjustment_get_type (void) G_GNUC_CONST;
+
G_END_DECLS
Modified: branches/builder/gladeui/glade-editor.c
==============================================================================
--- branches/builder/gladeui/glade-editor.c (original)
+++ branches/builder/gladeui/glade-editor.c Wed Apr 2 06:17:18 2008
@@ -434,7 +434,10 @@
{
GladeEditorProperty *property;
- property = glade_editor_property_new (klass, from_query_dialog == FALSE);
+ property = glade_widget_adaptor_create_eprop
+ (GLADE_WIDGET_ADAPTOR (klass->handle),
+ klass, from_query_dialog == FALSE);
+
gtk_widget_show (GTK_WIDGET (property));
gtk_widget_show_all (property->item_label);
Modified: branches/builder/gladeui/glade-project.c
==============================================================================
--- branches/builder/gladeui/glade-project.c (original)
+++ branches/builder/gladeui/glade-project.c Wed Apr 2 06:17:18 2008
@@ -972,8 +972,9 @@
glade_property_get_value (property, &value);
- if ((resource = glade_property_class_make_string_from_gvalue
- (property->klass, &value)) != NULL)
+ if ((resource = glade_widget_adaptor_string_from_value
+ (GLADE_WIDGET_ADAPTOR (property->klass->handle),
+ property->klass, &value)) != NULL)
{
full_resource = glade_project_resource_fullpath
(prev_project ? prev_project : project, resource);
Modified: branches/builder/gladeui/glade-property-class.c
==============================================================================
--- branches/builder/gladeui/glade-property-class.c (original)
+++ branches/builder/gladeui/glade-property-class.c Wed Apr 2 06:17:18 2008
@@ -474,41 +474,6 @@
return string;
}
-/* This is not used to save in the glade file... and its a one-way conversion.
- * its only usefull to show the values in the UI.
- */
-static gchar *
-glade_property_class_make_string_from_accels (GladePropertyClass *property_class,
- GList *accels)
-{
- GladeAccelInfo *info;
- GString *string;
- GList *list;
-
- string = g_string_new ("");
-
- for (list = accels; list; list = list->next)
- {
- info = list->data;
-
- if (info->modifiers & GDK_SHIFT_MASK)
- g_string_append (string, "SHIFT-");
-
- if (info->modifiers & GDK_CONTROL_MASK)
- g_string_append (string, "CNTL-");
-
- if (info->modifiers & GDK_MOD1_MASK)
- g_string_append (string, "ALT-");
-
- g_string_append (string, glade_builtin_string_from_key (info->key));
-
- if (list->next)
- g_string_append (string, ", ");
- }
-
- return g_string_free (string, FALSE);
-}
-
/**
* glade_property_class_make_string_from_gvalue:
* @property_class: A #GladePropertyClass
@@ -523,7 +488,7 @@
gchar *string = NULL, **strv, str[G_ASCII_DTOSTR_BUF_SIZE];
GObject *object;
GdkColor *color;
- GList *objects, *accels;
+ GList *objects;
if (G_IS_PARAM_SPEC_ENUM(property_class->pspec))
{
@@ -629,14 +594,8 @@
string = glade_property_class_make_string_from_objects
(property_class, objects);
}
- else if (GLADE_IS_PARAM_SPEC_ACCEL (property_class->pspec))
- {
- accels = g_value_get_boxed (value);
- string = glade_property_class_make_string_from_accels
- (property_class, accels);
- }
else
- g_critical ("Unsupported pspec type %s",
+ g_critical ("Unsupported pspec type %s (value -> string)",
g_type_name(G_PARAM_SPEC_TYPE (property_class->pspec)));
return string;
@@ -961,7 +920,7 @@
g_value_set_boxed (value, objects);
}
else
- g_critical ("Unsupported pspec type %s",
+ g_critical ("Unsupported pspec type %s (string -> value)",
g_type_name(G_PARAM_SPEC_TYPE (property_class->pspec)));
return value;
@@ -1024,7 +983,7 @@
else if (GLADE_IS_PARAM_SPEC_OBJECTS(klass->pspec))
g_value_set_boxed (value, va_arg (vl, gpointer));
else
- g_critical ("Unsupported pspec type %s",
+ g_critical ("Unsupported pspec type %s (vl -> string)",
g_type_name(G_PARAM_SPEC_TYPE (klass->pspec)));
return value;
@@ -1113,7 +1072,7 @@
else if (GLADE_IS_PARAM_SPEC_OBJECTS(klass->pspec))
*(gpointer *)(va_arg (vl, gpointer *)) = g_value_get_boxed (value);
else
- g_critical ("Unsupported pspec type %s",
+ g_critical ("Unsupported pspec type %s (string -> vl)",
g_type_name(G_PARAM_SPEC_TYPE (klass->pspec)));
}
@@ -1192,57 +1151,6 @@
}
/**
- * glade_property_class_accel_property:
- * @handle: A generic pointer (i.e. a #GladeWidgetClass)
- * @owner_type: The #GType of the owning widget class.
- *
- * Returns: a newly created #GladePropertyClass for accelerators
- * of the prescribed @owner_type.
- */
-GladePropertyClass *
-glade_property_class_accel_property (gpointer handle,
- GType owner_type)
-{
- GladePropertyClass *property_class;
- GValue *def_value;
-
- property_class = glade_property_class_new (handle);
- property_class->pspec =
- glade_param_spec_accel ("accelerators", _("Accelerators"),
- _("A list of accelerator keys"),
- owner_type,
- G_PARAM_READWRITE);
-
-
- property_class->pspec->owner_type = owner_type;
- property_class->id = g_strdup (g_param_spec_get_name
- (property_class->pspec));
- property_class->name = g_strdup (g_param_spec_get_nick
- (property_class->pspec));
- property_class->tooltip = g_strdup (g_param_spec_get_blurb
- (property_class->pspec));
-
- property_class->type = GPC_ACCEL_PROPERTY;
- property_class->ignore = TRUE;
- property_class->common = TRUE;
-
- /* Setup default */
- def_value = g_new0 (GValue, 1);
- g_value_init (def_value, GLADE_TYPE_ACCEL_GLIST);
- g_value_set_boxed (def_value, NULL);
- property_class->def = def_value;
-
- /* Setup original default */
- def_value = g_new0 (GValue, 1);
- g_value_init (def_value, GLADE_TYPE_ACCEL_GLIST);
- g_value_set_boxed (def_value, NULL);
- property_class->orig_def = def_value;
-
- return property_class;
-}
-
-
-/**
* glade_property_class_new_from_spec:
* @handle: A generic pointer (i.e. a #GladeWidgetClass)
* @spec: A #GParamSpec
@@ -1254,8 +1162,9 @@
glade_property_class_new_from_spec (gpointer handle,
GParamSpec *spec)
{
- GObjectClass *gtk_widget_class;
- GladePropertyClass *property_class;
+ GObjectClass *gtk_widget_class;
+ GladePropertyClass *property_class;
+ GladeEditorProperty *eprop;
g_return_val_if_fail (spec != NULL, NULL);
gtk_widget_class = g_type_class_ref (GTK_TYPE_WIDGET);
@@ -1271,13 +1180,17 @@
if ((spec->flags & G_PARAM_WRITABLE) == 0)
goto failed;
+ property_class->id = g_strdup (spec->name);
+ property_class->name = g_strdup (g_param_spec_get_nick (spec));
+
/* Register only editable properties.
*/
- if (!glade_editor_property_supported (property_class->pspec))
+ if (!(eprop = glade_widget_adaptor_create_eprop
+ (GLADE_WIDGET_ADAPTOR (handle), property_class, FALSE)))
goto failed;
-
- property_class->id = g_strdup (spec->name);
- property_class->name = g_strdup (g_param_spec_get_nick (spec));
+
+ /* Just created it to see if it was supported.... destroy now... */
+ gtk_widget_destroy (GTK_WIDGET (eprop));
/* If its on the GtkWidgetClass, it goes in "common"
* (unless stipulated otherwise in the xml file)
@@ -1747,11 +1660,6 @@
klass->type = GPC_ATK_PROPERTY;
}
- /* Special case accelerators here.
- */
- if (GLADE_IS_PARAM_SPEC_ACCEL (klass->pspec))
- klass->type = GPC_ACCEL_PROPERTY;
-
/* Special case pixbuf here.
*/
if (klass->pspec->value_type == GDK_TYPE_PIXBUF)
Modified: branches/builder/gladeui/glade-property.c
==============================================================================
--- branches/builder/gladeui/glade-property.c (original)
+++ branches/builder/gladeui/glade-property.c Wed Apr 2 06:17:18 2008
@@ -220,8 +220,9 @@
#if 0
{
- gchar *str = glade_property_class_make_string_from_gvalue
- (property->klass, value);
+ gchar *str = glade_widget_adaptor_string_from_value
+ (GLADE_WIDGET_ADAPTOR (property->klass->handle),
+ property->klass, value);
g_print ("Setting property %s on %s to %s\n",
property->klass->id,
property->widget ? property->widget->name : "unknown", str);
@@ -394,8 +395,9 @@
/* convert the value of this property to a string */
if (property->klass->type == GPC_ACCEL_PROPERTY ||
- (value = glade_property_class_make_string_from_gvalue
- (property->klass, property->value)) == NULL)
+ (value = glade_widget_adaptor_string_from_value
+ (GLADE_WIDGET_ADAPTOR (property->klass->handle),
+ property->klass, property->value)) == NULL)
/* make sure we keep the empty string, also... upcomming
* funcs that may not like NULL.
*/
@@ -695,15 +697,6 @@
GladeInterface Parsing code
*******************************************************************************/
-static GValue *
-glade_property_real_read (GladeProperty *property,
- GladePropertyClass *pclass,
- GladeProject *project,
- GladeXmlNode *node,
- gboolean free_value)
-{
-}
-
#if LOADING_WAS_IMPLEMENTED
static GValue *
Modified: branches/builder/gladeui/glade-widget-adaptor.c
==============================================================================
--- branches/builder/gladeui/glade-widget-adaptor.c (original)
+++ branches/builder/gladeui/glade-widget-adaptor.c Wed Apr 2 06:17:18 2008
@@ -786,6 +786,97 @@
}
+static GType
+glade_widget_adaptor_get_eprop_type (GParamSpec *pspec)
+{
+ GType type = 0;
+
+ if (pspec->value_type == GLADE_TYPE_STOCK ||
+ G_IS_PARAM_SPEC_ENUM(pspec))
+ type = GLADE_TYPE_EPROP_ENUM;
+ else if (G_IS_PARAM_SPEC_FLAGS(pspec))
+ type = GLADE_TYPE_EPROP_FLAGS;
+ else if (G_IS_PARAM_SPEC_VALUE_ARRAY (pspec))
+ {
+ if (pspec->value_type == G_TYPE_VALUE_ARRAY)
+ type = GLADE_TYPE_EPROP_TEXT;
+ }
+ else if (G_IS_PARAM_SPEC_BOXED(pspec))
+ {
+ if (pspec->value_type == GDK_TYPE_COLOR)
+ type = GLADE_TYPE_EPROP_COLOR;
+ else if (pspec->value_type == G_TYPE_STRV)
+ type = GLADE_TYPE_EPROP_TEXT;
+ }
+ else if (G_IS_PARAM_SPEC_STRING(pspec))
+ type = GLADE_TYPE_EPROP_TEXT;
+ else if (G_IS_PARAM_SPEC_BOOLEAN(pspec))
+ type = GLADE_TYPE_EPROP_BOOL;
+ else if (G_IS_PARAM_SPEC_FLOAT(pspec) ||
+ G_IS_PARAM_SPEC_DOUBLE(pspec) ||
+ G_IS_PARAM_SPEC_INT(pspec) ||
+ G_IS_PARAM_SPEC_UINT(pspec) ||
+ G_IS_PARAM_SPEC_LONG(pspec) ||
+ G_IS_PARAM_SPEC_ULONG(pspec) ||
+ G_IS_PARAM_SPEC_INT64(pspec) ||
+ G_IS_PARAM_SPEC_UINT64(pspec))
+ type = GLADE_TYPE_EPROP_NUMERIC;
+ else if (G_IS_PARAM_SPEC_UNICHAR(pspec))
+ type = GLADE_TYPE_EPROP_UNICHAR;
+ else if (G_IS_PARAM_SPEC_OBJECT(pspec))
+ {
+ if (pspec->value_type == GDK_TYPE_PIXBUF)
+ type = GLADE_TYPE_EPROP_RESOURCE;
+ else if (pspec->value_type == GTK_TYPE_ADJUSTMENT)
+ type = GLADE_TYPE_EPROP_ADJUSTMENT;
+ else
+ type = GLADE_TYPE_EPROP_OBJECT;
+ }
+ else if (GLADE_IS_PARAM_SPEC_OBJECTS(pspec))
+ type = GLADE_TYPE_EPROP_OBJECTS;
+
+ return type;
+}
+
+static GladeEditorProperty *
+glade_widget_adaptor_object_create_eprop (GladeWidgetAdaptor *adaptor,
+ GladePropertyClass *klass,
+ gboolean use_command)
+{
+ GladeEditorProperty *eprop;
+ GType type = 0;
+
+ /* Find the right type of GladeEditorProperty for this
+ * GladePropertyClass.
+ */
+ if ((type = glade_widget_adaptor_get_eprop_type (klass->pspec)) == 0)
+ return NULL;
+
+ /* special case for resource specs which are hand specified in the catalog. */
+ if (klass->resource)
+ type = GLADE_TYPE_EPROP_RESOURCE;
+
+ /* special case for string specs that denote themed application icons. */
+ if (klass->themed_icon)
+ type = GLADE_TYPE_EPROP_NAMED_ICON;
+
+ /* Create and return the correct type of GladeEditorProperty */
+ eprop = g_object_new (type,
+ "property-class", klass,
+ "use-command", use_command,
+ NULL);
+
+ return eprop;
+}
+
+static gchar *
+glade_widget_adaptor_object_string_from_value (GladeWidgetAdaptor *adaptor,
+ GladePropertyClass *klass,
+ const GValue *value)
+{
+ return glade_property_class_make_string_from_gvalue (klass, value);
+}
+
/*******************************************************************************
GladeWidgetAdaptor type registration and class initializer
*******************************************************************************/
@@ -826,6 +917,10 @@
adaptor_class->action_activate = glade_widget_adaptor_object_action_activate;
adaptor_class->child_action_activate= glade_widget_adaptor_object_child_action_activate;
adaptor_class->read_widget = glade_widget_adaptor_object_read_widget;
+ adaptor_class->create_eprop = glade_widget_adaptor_object_create_eprop;
+ adaptor_class->string_from_value = glade_widget_adaptor_object_string_from_value;
+
+
/* Base defaults here */
adaptor_class->fixed = FALSE;
@@ -1071,6 +1166,17 @@
GLADE_TAG_READ_WIDGET_FUNCTION,
&symbol))
klass->read_widget = symbol;
+
+ if (glade_xml_load_sym_from_node (node, module,
+ GLADE_TAG_CREATE_EPROP_FUNCTION,
+ &symbol))
+ klass->create_eprop = symbol;
+
+ if (glade_xml_load_sym_from_node (node, module,
+ GLADE_TAG_STRING_FROM_VALUE_FUNCTION,
+ &symbol))
+ klass->string_from_value = symbol;
+
}
static void
@@ -2842,3 +2948,60 @@
GLADE_WIDGET_ADAPTOR_GET_CLASS (adaptor)->read_widget (adaptor, widget, node);
}
+
+
+/**
+ * glade_widget_adaptor_create_eprop:
+ * @adaptor: A #GladeWidgetAdaptor
+ * @klass: The #GladePropertyClass to be edited
+ * @use_command: whether to use the GladeCommand interface
+ * to commit property changes
+ *
+ * Creates a GladeEditorProperty to edit @klass
+ *
+ * Returns: A newly created #GladeEditorProperty
+ */
+GladeEditorProperty *
+glade_widget_adaptor_create_eprop (GladeWidgetAdaptor *adaptor,
+ GladePropertyClass *klass,
+ gboolean use_command)
+{
+ GladeEditorProperty *eprop;
+ g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL);
+ g_return_val_if_fail (GLADE_IS_PROPERTY_CLASS (klass), NULL);
+
+ eprop = GLADE_WIDGET_ADAPTOR_GET_CLASS
+ (adaptor)->create_eprop (adaptor, klass, use_command);
+
+ /* XXX we really need to print a g_error() here, exept we are
+ * now using this func to test for unsupported properties
+ * at init time from glade-property-class */
+
+ return eprop;
+}
+
+
+/**
+ * glade_widget_adaptor_string_from_value:
+ * @adaptor: A #GladeWidgetAdaptor
+ * @klass: The #GladePropertyClass
+ * @value: The #GValue to convert to a string
+ *
+ * For normal properties this is used to serialize
+ * property values, for custom properties its still
+ * needed to update the UI for undo/redo items etc.
+ *
+ * Returns: A newly allocated string representation of @value
+ */
+gchar *
+glade_widget_adaptor_string_from_value (GladeWidgetAdaptor *adaptor,
+ GladePropertyClass *klass,
+ const GValue *value)
+{
+ g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL);
+ g_return_val_if_fail (GLADE_IS_PROPERTY_CLASS (klass), NULL);
+ g_return_val_if_fail (value != NULL, NULL);
+
+ return GLADE_WIDGET_ADAPTOR_GET_CLASS
+ (adaptor)->string_from_value (adaptor, klass, value);
+}
Modified: branches/builder/gladeui/glade-widget-adaptor.h
==============================================================================
--- branches/builder/gladeui/glade-widget-adaptor.h (original)
+++ branches/builder/gladeui/glade-widget-adaptor.h Wed Apr 2 06:17:18 2008
@@ -4,6 +4,7 @@
#include <gladeui/glade-xml-utils.h>
#include <gladeui/glade-property-class.h>
+#include <gladeui/glade-editor-property.h>
#include <glib-object.h>
#include <gmodule.h>
#include <gtk/gtk.h>
@@ -237,9 +238,10 @@
/**
* GladeGetChildrenFunc:
* @container: A #GObject container
- * @Returns: A #GList of #GObject children.
*
* A function called to get @containers children.
+ *
+ * Returns: A #GList of #GObject children.
*/
typedef GList *(* GladeGetChildrenFunc) (GladeWidgetAdaptor *adaptor,
GObject *container);
@@ -297,6 +299,8 @@
* @name: A string identifier
*
* Called to lookup @child in composite object @parent by @name.
+ *
+ * Returns: The specified internal widget.
*/
typedef GObject *(* GladeGetInternalFunc) (GladeWidgetAdaptor *adaptor,
GObject *parent,
@@ -330,10 +334,6 @@
GObject *object,
const gchar *action_path);
-
-
-
-
/**
* GladeReadWidgetFunc:
* @adaptor: A #GladeWidgetAdaptor
@@ -347,6 +347,36 @@
GladeWidget *widget,
GladeXmlNode *node);
+/**
+ * GladeCreateEPropFunc:
+ * @adaptor: A #GladeWidgetAdaptor
+ * @klass: The #GladePropertyClass to be edited
+ * @use_command: whether to use the GladeCommand interface
+ * to commit property changes
+ *
+ * Creates a GladeEditorProperty to edit @klass
+ *
+ * Returns: A newly created #GladeEditorProperty
+ */
+typedef GladeEditorProperty *(* GladeCreateEPropFunc) (GladeWidgetAdaptor *adaptor,
+ GladePropertyClass *klass,
+ gboolean use_command);
+
+/**
+ * GladeStringFromValueFunc:
+ * @adaptor: A #GladeWidgetAdaptor
+ * @klass: The #GladePropertyClass
+ * @value: The #GValue to convert to a string
+ *
+ * For normal properties this is used to serialize
+ * property values, for custom properties its still
+ * needed to update the UI for undo/redo items etc.
+ *
+ * Returns: A newly allocated string representation of @value
+ */
+typedef gchar *(* GladeStringFromValueFunc) (GladeWidgetAdaptor *adaptor,
+ GladePropertyClass *klass,
+ const GValue *value);
/* GladeSignalClass contains all the info we need for a given signal, such as
@@ -494,6 +524,11 @@
GladeReadWidgetFunc read_widget; /* Reads widget attributes from xml */
+
+
+ GladeCreateEPropFunc create_eprop; /* Creates a GladeEditorProperty */
+
+ GladeStringFromValueFunc string_from_value; /* Creates a string for a value */
};
#define glade_widget_adaptor_create_widget(adaptor, query, ...) \
@@ -649,6 +684,14 @@
GladeWidget *widget,
GladeXmlNode *node);
+GladeEditorProperty *glade_widget_adaptor_create_eprop (GladeWidgetAdaptor *adaptor,
+ GladePropertyClass *klass,
+ gboolean use_command);
+
+gchar *glade_widget_adaptor_string_from_value (GladeWidgetAdaptor *adaptor,
+ GladePropertyClass *klass,
+ const GValue *value);
+
G_END_DECLS
#endif /* __GLADE_WIDGET_ADAPTOR_H__ */
Modified: branches/builder/gladeui/glade-widget.c
==============================================================================
--- branches/builder/gladeui/glade-widget.c (original)
+++ branches/builder/gladeui/glade-widget.c Wed Apr 2 06:17:18 2008
@@ -3104,9 +3104,9 @@
g_return_val_if_fail (id_property != NULL, NULL);
if ((property = glade_widget_get_property (widget, id_property)) != NULL)
- ret_string =
- glade_property_class_make_string_from_gvalue (property->klass,
- value ? value : property->value);
+ ret_string = glade_widget_adaptor_string_from_value
+ (GLADE_WIDGET_ADAPTOR (property->klass->handle),
+ property->klass, value ? value : property->value);
return ret_string;
}
@@ -3134,9 +3134,9 @@
g_return_val_if_fail (id_property != NULL, NULL);
if ((property = glade_widget_get_pack_property (widget, id_property)) != NULL)
- ret_string =
- glade_property_class_make_string_from_gvalue (property->klass,
- value ? value : property->value);
+ ret_string = glade_widget_adaptor_string_from_value
+ (GLADE_WIDGET_ADAPTOR (property->klass->handle),
+ property->klass, value ? value : property->value);
return ret_string;
}
@@ -4423,3 +4423,40 @@
return TRUE;
}
+
+
+/**
+ * glade_widget_create_editor_property:
+ * @widget: A #GladeWidget
+ * @property: The widget's property
+ * @packing: whether @property indicates a packing property or not.
+ * @use_command: Whether the undo/redo stack applies here.
+ *
+ * This is a convenience function to create a GladeEditorProperty corresponding
+ * to @property
+ *
+ * Returns: A newly created and connected GladeEditorProperty
+ */
+GladeEditorProperty *
+glade_widget_create_editor_property (GladeWidget *widget,
+ const gchar *property,
+ gboolean packing,
+ gboolean use_command)
+{
+ GladeEditorProperty *eprop;
+ GladeProperty *p;
+
+ if (packing)
+ p = glade_widget_get_pack_property (widget, property);
+ else
+ p = glade_widget_get_property (widget, property);
+
+ g_return_val_if_fail (GLADE_IS_PROPERTY (p), NULL);
+
+ eprop = glade_widget_adaptor_create_eprop (widget->adaptor,
+ p->klass,
+ use_command);
+ glade_editor_property_load (eprop, p);
+
+ return eprop;
+}
Modified: branches/builder/gladeui/glade-widget.h
==============================================================================
--- branches/builder/gladeui/glade-widget.h (original)
+++ branches/builder/gladeui/glade-widget.h Wed Apr 2 06:17:18 2008
@@ -135,14 +135,6 @@
void glade_widget_remove_child (GladeWidget *parent,
GladeWidget *child);
-
-/* XXX GladeWidgetInfo *glade_widget_write (GladeWidget *widget, */
-/* GladeInterface *interface); */
-
-GladeWidget *glade_widget_read (GladeProject *project,
- GladeWidget *parent,
- GladeXmlNode *node,
- const gchar *internal);
void glade_widget_replace (GladeWidget *parent,
GObject *old_object,
@@ -221,6 +213,19 @@
GtkWidget * glade_widget_create_action_menu (GladeWidget *widget,
const gchar *action_path);
+/* XXX GladeWidgetInfo *glade_widget_write (GladeWidget *widget, */
+/* GladeInterface *interface); */
+
+GladeWidget *glade_widget_read (GladeProject *project,
+ GladeWidget *parent,
+ GladeXmlNode *node,
+ const gchar *internal);
+
+GladeEditorProperty *glade_widget_create_editor_property (GladeWidget *widget,
+ const gchar *property,
+ gboolean packing,
+ gboolean use_command);
+
/*******************************************************************************
Project, object property references
*******************************************************************************/
Modified: branches/builder/gladeui/glade-xml-utils.h
==============================================================================
--- branches/builder/gladeui/glade-xml-utils.h (original)
+++ branches/builder/gladeui/glade-xml-utils.h Wed Apr 2 06:17:18 2008
@@ -64,6 +64,8 @@
#define GLADE_TAG_ACTION_ACTIVATE_FUNCTION "action-activate-function"
#define GLADE_TAG_CHILD_ACTION_ACTIVATE_FUNCTION "child-action-activate-function"
#define GLADE_TAG_READ_WIDGET_FUNCTION "read-widget-function"
+#define GLADE_TAG_CREATE_EPROP_FUNCTION "create-editor-property-function"
+#define GLADE_TAG_STRING_FROM_VALUE_FUNCTION "string-from-value-function"
#define GLADE_TAG_PROPERTIES "properties"
#define GLADE_TAG_PACKING_PROPERTIES "packing-properties"
#define GLADE_TAG_PROPERTY "property"
Modified: branches/builder/plugins/gtk+/Makefile.am
==============================================================================
--- branches/builder/plugins/gtk+/Makefile.am (original)
+++ branches/builder/plugins/gtk+/Makefile.am Wed Apr 2 06:17:18 2008
@@ -23,7 +23,7 @@
$(PLUGINS_WARN_CFLAGS) \
$(AM_CFLAGS)
-libgladegtk_la_SOURCES = glade-gtk.c fixed-bg.xpm
+libgladegtk_la_SOURCES = glade-gtk.c glade-accels.c glade-keysyms.c fixed-bg.xpm
libgladegtk_la_LDFLAGS = -module -avoid-version $(AM_LDFLAGS)
libgladegtk_la_LIBADD = $(libgladeui) $(GTK_LIBS)
Added: branches/builder/plugins/gtk+/glade-accels.c
==============================================================================
--- (empty file)
+++ branches/builder/plugins/gtk+/glade-accels.c Wed Apr 2 06:17:18 2008
@@ -0,0 +1,943 @@
+/* -*- 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>
+ */
+
+#include <config.h>
+
+#include <gladeui/glade.h>
+#include <gtk/gtk.h>
+#include <glib/gi18n-lib.h>
+#include <string.h>
+
+#include "glade-accels.h"
+
+#define GLADE_RESPONSE_CLEAR 42
+
+/**************************************************************
+ * GParamSpec stuff here
+ **************************************************************/
+struct _GladeParamSpecAccel {
+ GParamSpec parent_instance;
+
+ GType type; /* The type this accel key is for; this allows
+ * us to verify the validity of any signals for
+ * this type.
+ */
+};
+
+GList *
+glade_accel_list_copy (GList *accels)
+{
+ GList *ret = NULL, *list;
+ GladeAccelInfo *info, *dup_info;
+
+ for (list = accels; list; list = list->next)
+ {
+ info = list->data;
+
+ dup_info = g_new0 (GladeAccelInfo, 1);
+ dup_info->signal = g_strdup (info->signal);
+ dup_info->key = info->key;
+ dup_info->modifiers = info->modifiers;
+
+ ret = g_list_prepend (ret, dup_info);
+ }
+
+ return g_list_reverse (ret);
+}
+
+void
+glade_accel_list_free (GList *accels)
+{
+ GList *list;
+ GladeAccelInfo *info;
+
+ for (list = accels; list; list = list->next)
+ {
+ info = list->data;
+
+ g_free (info->signal);
+ g_free (info);
+ }
+ g_list_free (accels);
+}
+
+GType
+glade_accel_glist_get_type (void)
+{
+ static GType type_id = 0;
+
+ if (!type_id)
+ type_id = g_boxed_type_register_static
+ ("GladeAccelGList",
+ (GBoxedCopyFunc) glade_accel_list_copy,
+ (GBoxedFreeFunc) glade_accel_list_free);
+ return type_id;
+}
+
+gboolean
+glade_keyval_valid (guint val)
+{
+ gint i;
+
+ for (i = 0; GladeKeys[i].name != NULL; i++)
+ {
+ if (GladeKeys[i].value == val)
+ return TRUE;
+ }
+ return FALSE;
+}
+
+
+static void
+param_accel_init (GParamSpec *pspec)
+{
+ GladeParamSpecAccel *ospec = GLADE_PARAM_SPEC_ACCEL (pspec);
+ ospec->type = G_TYPE_OBJECT;
+}
+
+static void
+param_accel_set_default (GParamSpec *pspec,
+ GValue *value)
+{
+ if (value->data[0].v_pointer != NULL)
+ {
+ g_free (value->data[0].v_pointer);
+ }
+ value->data[0].v_pointer = NULL;
+}
+
+static gboolean
+param_accel_validate (GParamSpec *pspec,
+ GValue *value)
+{
+ /* GladeParamSpecAccel *aspec = GLADE_PARAM_SPEC_ACCEL (pspec); */
+ GList *accels, *list, *toremove = NULL;
+ GladeAccelInfo *info;
+
+ accels = value->data[0].v_pointer;
+
+ for (list = accels; list; list = list->next)
+ {
+ info = list->data;
+
+ /* Is it an invalid key ? */
+ if (glade_keyval_valid (info->key) == FALSE ||
+ /* Does the modifier contain any unwanted bits ? */
+ info->modifiers & GDK_MODIFIER_MASK ||
+ /* Do we have a signal ? */
+ /* FIXME: Check if the signal is valid for 'type' */
+ info->signal == NULL)
+ toremove = g_list_prepend (toremove, info);
+ }
+
+ for (list = toremove; list; list = list->next)
+ accels = g_list_remove (accels, list->data);
+
+ if (toremove) g_list_free (toremove);
+
+ value->data[0].v_pointer = accels;
+
+ return toremove != NULL;
+}
+
+static gint
+param_accel_values_cmp (GParamSpec *pspec,
+ const GValue *value1,
+ const GValue *value2)
+{
+ guint8 *p1 = value1->data[0].v_pointer;
+ guint8 *p2 = value2->data[0].v_pointer;
+
+ /* not much to compare here, try to at least provide stable lesser/greater result */
+
+ return p1 < p2 ? -1 : p1 > p2;
+}
+
+GType
+glade_param_accel_get_type (void)
+{
+ static GType accel_type = 0;
+
+ if (accel_type == 0)
+ {
+ static /* const */ GParamSpecTypeInfo pspec_info = {
+ sizeof (GladeParamSpecAccel), /* instance_size */
+ 16, /* n_preallocs */
+ param_accel_init, /* instance_init */
+ 0xdeadbeef, /* value_type, assigned further down */
+ NULL, /* finalize */
+ param_accel_set_default, /* value_set_default */
+ param_accel_validate, /* value_validate */
+ param_accel_values_cmp, /* values_cmp */
+ };
+ pspec_info.value_type = GLADE_TYPE_ACCEL_GLIST;
+
+ accel_type = g_param_type_register_static
+ ("GladeParamAccel", &pspec_info);
+ }
+ return accel_type;
+}
+
+GParamSpec *
+glade_param_spec_accel (const gchar *name,
+ const gchar *nick,
+ const gchar *blurb,
+ GType widget_type,
+ GParamFlags flags)
+{
+ GladeParamSpecAccel *pspec;
+
+ pspec = g_param_spec_internal (GLADE_TYPE_PARAM_ACCEL,
+ name, nick, blurb, flags);
+
+ pspec->type = widget_type;
+ return G_PARAM_SPEC (pspec);
+}
+
+/* Accelerator spec */
+GParamSpec *
+glade_standard_accel_spec (void)
+{
+ return glade_param_spec_accel ("accelerators", _("Accelerators"),
+ _("A list of accelerator keys"),
+ GTK_TYPE_WIDGET,
+ G_PARAM_READWRITE);
+}
+
+guint
+glade_key_from_string (const gchar *string)
+{
+ gint i;
+
+ g_return_val_if_fail (string != NULL, 0);
+
+ for (i = 0; GladeKeys[i].name != NULL; i++)
+ if (!strcmp (string, GladeKeys[i].name))
+ return GladeKeys[i].value;
+
+ return 0;
+}
+
+const gchar *
+glade_string_from_key (guint key)
+{
+ gint i;
+
+ for (i = 0; GladeKeys[i].name != NULL; i++)
+ if (GladeKeys[i].value == key)
+ return GladeKeys[i].name;
+ return NULL;
+}
+
+
+/* This is not used to save in the glade file... and its a one-way conversion.
+ * its only usefull to show the values in the UI.
+ */
+gchar *
+glade_accels_make_string (GList *accels)
+{
+ GladeAccelInfo *info;
+ GString *string;
+ GList *list;
+
+ string = g_string_new ("");
+
+ for (list = accels; list; list = list->next)
+ {
+ info = list->data;
+
+ if (info->modifiers & GDK_SHIFT_MASK)
+ g_string_append (string, "SHIFT-");
+
+ if (info->modifiers & GDK_CONTROL_MASK)
+ g_string_append (string, "CNTL-");
+
+ if (info->modifiers & GDK_MOD1_MASK)
+ g_string_append (string, "ALT-");
+
+ g_string_append (string, glade_string_from_key (info->key));
+
+ if (list->next)
+ g_string_append (string, ", ");
+ }
+
+ return g_string_free (string, FALSE);
+}
+
+
+/**************************************************************
+ * GladeEditorProperty stuff here
+ **************************************************************/
+
+enum {
+ ACCEL_COLUMN_SIGNAL = 0,
+ ACCEL_COLUMN_REAL_SIGNAL,
+ ACCEL_COLUMN_KEY,
+ ACCEL_COLUMN_MOD_SHIFT,
+ ACCEL_COLUMN_MOD_CNTL,
+ ACCEL_COLUMN_MOD_ALT,
+ ACCEL_COLUMN_IS_CLASS,
+ ACCEL_COLUMN_IS_SIGNAL,
+ ACCEL_COLUMN_KEY_ENTERED,
+ ACCEL_COLUMN_KEY_SLOT,
+ ACCEL_NUM_COLUMNS
+};
+
+enum {
+ ACCEL_COMBO_COLUMN_TEXT = 0,
+ ACCEL_COMBO_NUM_COLUMNS,
+};
+
+typedef struct {
+ GladeEditorProperty parent_instance;
+
+ GtkWidget *entry;
+ GList *parent_iters;
+ GtkTreeModel *model;
+} GladeEPropAccel;
+
+typedef struct {
+ GtkTreeIter *iter;
+ gchar *name; /* <-- dont free */
+} GladeEpropIterTab;
+
+
+static GtkTreeModel *keysyms_model = NULL;
+
+GLADE_MAKE_EPROP (GladeEPropAccel, glade_eprop_accel)
+#define GLADE_EPROP_ACCEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EPROP_ACCEL, GladeEPropAccel))
+#define GLADE_EPROP_ACCEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EPROP_ACCEL, GladeEPropAccelClass))
+#define GLADE_IS_EPROP_ACCEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_ACCEL))
+#define GLADE_IS_EPROP_ACCEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_EPROP_ACCEL))
+#define GLADE_EPROP_ACCEL_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GLADE_EPROP_ACCEL, GladeEPropAccelClass))
+
+
+static GtkTreeModel *
+create_keysyms_model (void)
+{
+ GtkTreeModel *model;
+ GtkTreeIter iter, alphanum, fkey, keypad, other, extra;
+ GtkTreeIter *parent;
+ gint i;
+
+ model = (GtkTreeModel *)gtk_tree_store_new
+ (ACCEL_COMBO_NUM_COLUMNS,
+ G_TYPE_STRING); /* The Key charachter name */
+
+ gtk_tree_store_append (GTK_TREE_STORE (model), &alphanum, NULL);
+ gtk_tree_store_set
+ (GTK_TREE_STORE (model), &alphanum,
+ ACCEL_COMBO_COLUMN_TEXT, _("Alphanumerical"), -1);
+
+ gtk_tree_store_append (GTK_TREE_STORE (model), &extra, NULL);
+ gtk_tree_store_set
+ (GTK_TREE_STORE (model), &extra,
+ ACCEL_COMBO_COLUMN_TEXT, _("Extra"), -1);
+
+ gtk_tree_store_append (GTK_TREE_STORE (model), &keypad, NULL);
+ gtk_tree_store_set
+ (GTK_TREE_STORE (model), &keypad,
+ ACCEL_COMBO_COLUMN_TEXT, _("Keypad"), -1);
+
+ gtk_tree_store_append (GTK_TREE_STORE (model), &fkey, NULL);
+ gtk_tree_store_set
+ (GTK_TREE_STORE (model), &fkey,
+ ACCEL_COMBO_COLUMN_TEXT, _("Functions"), -1);
+
+ gtk_tree_store_append (GTK_TREE_STORE (model), &other, NULL);
+ gtk_tree_store_set
+ (GTK_TREE_STORE (model), &other,
+ ACCEL_COMBO_COLUMN_TEXT, _("Other"), -1);
+
+ parent = &alphanum;
+
+ for (i = 0; GladeKeys[i].name != NULL; i++)
+ {
+ gtk_tree_store_append (GTK_TREE_STORE (model), &iter, parent);
+ gtk_tree_store_set
+ (GTK_TREE_STORE (model), &iter,
+ ACCEL_COMBO_COLUMN_TEXT, GladeKeys[i].name, -1);
+
+ if (!strcmp (GladeKeys[i].name, GLADE_KEYS_LAST_ALPHANUM))
+ parent = &extra;
+ else if (!strcmp (GladeKeys[i].name, GLADE_KEYS_LAST_EXTRA))
+ parent = &keypad;
+ else if (!strcmp (GladeKeys[i].name, GLADE_KEYS_LAST_KP))
+ parent = &fkey;
+ else if (!strcmp (GladeKeys[i].name, GLADE_KEYS_LAST_FKEY))
+ parent = &other;
+ }
+ return model;
+}
+
+static void
+glade_eprop_accel_finalize (GObject *object)
+{
+ /* Chain up */
+ GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (object));
+
+ G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
+glade_eprop_accel_load (GladeEditorProperty *eprop,
+ GladeProperty *property)
+{
+ GladeEditorPropertyClass *parent_class =
+ g_type_class_peek_parent (GLADE_EDITOR_PROPERTY_GET_CLASS (eprop));
+ GladeEPropAccel *eprop_accel = GLADE_EPROP_ACCEL (eprop);
+ gchar *accels;
+
+ /* Chain up first */
+ parent_class->load (eprop, property);
+
+ if (property == NULL) return;
+
+ if ((accels =
+ glade_accels_make_string (g_value_get_boxed (property->value))) != NULL)
+ {
+ gtk_entry_set_text (GTK_ENTRY (eprop_accel->entry), accels);
+ g_free (accels);
+ }
+ else
+ gtk_entry_set_text (GTK_ENTRY (eprop_accel->entry), "");
+
+}
+
+static gint
+eprop_find_iter (GladeEpropIterTab *iter_tab,
+ gchar *name)
+{
+ return strcmp (iter_tab->name, name);
+}
+
+static void
+iter_tab_free (GladeEpropIterTab *iter_tab)
+{
+ gtk_tree_iter_free (iter_tab->iter);
+ g_free (iter_tab);
+}
+
+static void
+glade_eprop_accel_populate_view (GladeEditorProperty *eprop,
+ GtkTreeView *view)
+{
+ GladeEPropAccel *eprop_accel = GLADE_EPROP_ACCEL (eprop);
+ GladeSignalClass *sclass;
+ GladeWidgetAdaptor *adaptor = glade_widget_adaptor_from_pclass (eprop->klass);
+ GtkTreeStore *model = (GtkTreeStore *)gtk_tree_view_get_model (view);
+ GtkTreeIter iter;
+ GladeEpropIterTab *parent_tab;
+ GladeAccelInfo *info;
+ GList *list, *l, *found, *accelerators;
+ gchar *name;
+
+ accelerators = g_value_get_boxed (eprop->property->value);
+
+ /* First make parent iters...
+ */
+ for (list = adaptor->signals; list; list = list->next)
+ {
+ sclass = list->data;
+
+ /* Only action signals have accelerators. */
+ if ((sclass->query.signal_flags & G_SIGNAL_ACTION) == 0)
+ continue;
+
+ if (g_list_find_custom (eprop_accel->parent_iters,
+ sclass->type,
+ (GCompareFunc)eprop_find_iter) == NULL)
+ {
+ gtk_tree_store_append (model, &iter, NULL);
+ gtk_tree_store_set (model, &iter,
+ ACCEL_COLUMN_SIGNAL, sclass->type,
+ ACCEL_COLUMN_IS_CLASS, TRUE,
+ ACCEL_COLUMN_IS_SIGNAL, FALSE,
+ -1);
+
+ parent_tab = g_new0 (GladeEpropIterTab, 1);
+ parent_tab->name = sclass->type;
+ parent_tab->iter = gtk_tree_iter_copy (&iter);
+
+ eprop_accel->parent_iters =
+ g_list_prepend (eprop_accel->parent_iters,
+ parent_tab);
+ }
+ }
+
+ /* Now we populate...
+ */
+ for (list = adaptor->signals; list; list = list->next)
+ {
+ sclass = list->data;
+
+ /* Only action signals have accelerators. */
+ if ((sclass->query.signal_flags & G_SIGNAL_ACTION) == 0)
+ continue;
+
+ if ((found = g_list_find_custom (eprop_accel->parent_iters,
+ sclass->type,
+ (GCompareFunc)eprop_find_iter)) != NULL)
+ {
+ parent_tab = found->data;
+ name = g_strdup_printf (" %s", sclass->name);
+
+ /* Populate from accelerator list
+ */
+ for (l = accelerators; l; l = l->next)
+ {
+ info = l->data;
+
+ if (strcmp (info->signal, sclass->name))
+ continue;
+
+ gtk_tree_store_append (model, &iter, parent_tab->iter);
+ gtk_tree_store_set
+ (model, &iter,
+ ACCEL_COLUMN_SIGNAL, name,
+ ACCEL_COLUMN_REAL_SIGNAL, sclass->name,
+ ACCEL_COLUMN_IS_CLASS, FALSE,
+ ACCEL_COLUMN_IS_SIGNAL, TRUE,
+ ACCEL_COLUMN_MOD_SHIFT,
+ (info->modifiers & GDK_SHIFT_MASK) != 0,
+ ACCEL_COLUMN_MOD_CNTL,
+ (info->modifiers & GDK_CONTROL_MASK) != 0,
+ ACCEL_COLUMN_MOD_ALT,
+ (info->modifiers & GDK_MOD1_MASK) != 0,
+ ACCEL_COLUMN_KEY,
+ glade_string_from_key (info->key),
+ ACCEL_COLUMN_KEY_ENTERED, TRUE,
+ ACCEL_COLUMN_KEY_SLOT, FALSE,
+ -1);
+ }
+
+ /* Append a new empty slot at the end */
+ gtk_tree_store_append (model, &iter, parent_tab->iter);
+ gtk_tree_store_set
+ (model, &iter,
+ ACCEL_COLUMN_SIGNAL, name,
+ ACCEL_COLUMN_REAL_SIGNAL, sclass->name,
+ ACCEL_COLUMN_IS_CLASS, FALSE,
+ ACCEL_COLUMN_IS_SIGNAL, TRUE,
+ ACCEL_COLUMN_MOD_SHIFT, FALSE,
+ ACCEL_COLUMN_MOD_CNTL, FALSE,
+ ACCEL_COLUMN_MOD_ALT, FALSE,
+ ACCEL_COLUMN_KEY, _("<choose a key>"),
+ ACCEL_COLUMN_KEY_ENTERED, FALSE,
+ ACCEL_COLUMN_KEY_SLOT, TRUE,
+ -1);
+
+ g_free (name);
+ }
+ }
+}
+
+static void
+key_edited (GtkCellRendererText *cell,
+ const gchar *path_string,
+ const gchar *new_text,
+ GladeEditorProperty *eprop)
+{
+ GladeEPropAccel *eprop_accel = GLADE_EPROP_ACCEL (eprop);
+ gboolean key_was_set;
+ const gchar *text;
+ GtkTreeIter iter, parent_iter, new_iter;
+
+ if (!gtk_tree_model_get_iter_from_string (eprop_accel->model,
+ &iter, path_string))
+ return;
+
+ gtk_tree_model_get (eprop_accel->model, &iter,
+ ACCEL_COLUMN_KEY_ENTERED, &key_was_set,
+ -1);
+
+ /* If user selects "none"; remove old entry or ignore new one.
+ */
+ if (!new_text || new_text[0] == '\0' ||
+ glade_string_from_key ((guint)new_text[0]) == NULL ||
+ g_utf8_collate (new_text, _("None")) == 0 ||
+ g_utf8_collate (new_text, _("<choose a key>")) == 0)
+ {
+ if (key_was_set)
+ gtk_tree_store_remove
+ (GTK_TREE_STORE (eprop_accel->model), &iter);
+
+ return;
+ }
+
+ if (glade_key_from_string (new_text) != 0)
+ text = new_text;
+ else
+ text = glade_string_from_key ((guint)new_text[0]);
+
+ gtk_tree_store_set
+ (GTK_TREE_STORE (eprop_accel->model), &iter,
+ ACCEL_COLUMN_KEY, text,
+ ACCEL_COLUMN_KEY_ENTERED, TRUE,
+ ACCEL_COLUMN_KEY_SLOT, FALSE,
+ -1);
+
+ /* Append a new one if needed
+ */
+ if (key_was_set == FALSE &&
+ gtk_tree_model_iter_parent (eprop_accel->model,
+ &parent_iter, &iter))
+ {
+ gchar *signal, *real_signal;
+
+ gtk_tree_model_get (eprop_accel->model, &iter,
+ ACCEL_COLUMN_SIGNAL, &signal,
+ ACCEL_COLUMN_REAL_SIGNAL, &real_signal,
+ -1);
+
+ /* Append a new empty slot at the end */
+ gtk_tree_store_insert_after (GTK_TREE_STORE (eprop_accel->model),
+ &new_iter, &parent_iter, &iter);
+ gtk_tree_store_set (GTK_TREE_STORE (eprop_accel->model), &new_iter,
+ ACCEL_COLUMN_SIGNAL, signal,
+ ACCEL_COLUMN_REAL_SIGNAL, real_signal,
+ ACCEL_COLUMN_IS_CLASS, FALSE,
+ ACCEL_COLUMN_IS_SIGNAL, TRUE,
+ ACCEL_COLUMN_MOD_SHIFT, FALSE,
+ ACCEL_COLUMN_MOD_CNTL, FALSE,
+ ACCEL_COLUMN_MOD_ALT, FALSE,
+ ACCEL_COLUMN_KEY, _("<choose a key>"),
+ ACCEL_COLUMN_KEY_ENTERED, FALSE,
+ ACCEL_COLUMN_KEY_SLOT, TRUE,
+ -1);
+ g_free (signal);
+ g_free (real_signal);
+ }
+}
+
+static void
+modifier_toggled (GtkCellRendererToggle *cell,
+ gchar *path_string,
+ GladeEditorProperty *eprop)
+{
+ GladeEPropAccel *eprop_accel = GLADE_EPROP_ACCEL (eprop);
+ GtkTreeIter iter;
+ gint column;
+ gboolean active, key_entered;
+
+ if (!gtk_tree_model_get_iter_from_string (eprop_accel->model,
+ &iter, path_string))
+ return;
+
+ column = GPOINTER_TO_INT (g_object_get_data
+ (G_OBJECT (cell), "model-column"));
+
+ gtk_tree_model_get
+ (eprop_accel->model, &iter,
+ ACCEL_COLUMN_KEY_ENTERED, &key_entered,
+ column, &active, -1);
+
+ if (key_entered)
+ gtk_tree_store_set
+ (GTK_TREE_STORE (eprop_accel->model), &iter,
+ column, !active, -1);
+}
+
+
+static GtkWidget *
+glade_eprop_accel_view (GladeEditorProperty *eprop)
+{
+ GladeEPropAccel *eprop_accel = GLADE_EPROP_ACCEL (eprop);
+ GtkWidget *view_widget;
+ GtkCellRenderer *renderer;
+ GtkTreeViewColumn *column;
+
+ eprop_accel->model = (GtkTreeModel *)gtk_tree_store_new
+ (ACCEL_NUM_COLUMNS,
+ G_TYPE_STRING, /* The GSignal name formatted for display */
+ G_TYPE_STRING, /* The GSignal name */
+ G_TYPE_STRING, /* The Gdk keycode */
+ G_TYPE_BOOLEAN, /* The shift modifier */
+ G_TYPE_BOOLEAN, /* The cntl modifier */
+ G_TYPE_BOOLEAN, /* The alt modifier */
+ G_TYPE_BOOLEAN, /* Whether this is a class entry */
+ G_TYPE_BOOLEAN, /* Whether this is a signal entry (oposite of above) */
+ G_TYPE_BOOLEAN, /* Whether the key has been entered for this row */
+ G_TYPE_BOOLEAN); /* Oposite of above */
+
+ view_widget = gtk_tree_view_new_with_model (eprop_accel->model);
+ g_object_set (G_OBJECT (view_widget), "enable-search", FALSE, NULL);
+
+ /********************* fake invisible column *********************/
+ renderer = gtk_cell_renderer_text_new ();
+ g_object_set (G_OBJECT (renderer), "editable", FALSE, "visible", FALSE, NULL);
+
+ column = gtk_tree_view_column_new_with_attributes (NULL, renderer, NULL);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (view_widget), column);
+
+ gtk_tree_view_column_set_visible (column, FALSE);
+ gtk_tree_view_set_expander_column (GTK_TREE_VIEW (view_widget), column);
+
+ /********************* signal name column *********************/
+ renderer = gtk_cell_renderer_text_new ();
+ g_object_set (G_OBJECT (renderer),
+ "editable", FALSE,
+ "weight", PANGO_WEIGHT_BOLD,
+ NULL);
+
+ column = gtk_tree_view_column_new_with_attributes
+ (_("Signal"), renderer,
+ "text", ACCEL_COLUMN_SIGNAL,
+ "weight-set", ACCEL_COLUMN_IS_CLASS,
+ NULL);
+
+ g_object_set (G_OBJECT (column), "expand", TRUE, NULL);
+
+ gtk_tree_view_append_column (GTK_TREE_VIEW (view_widget), column);
+
+ /********************* key name column *********************/
+ if (keysyms_model == NULL)
+ keysyms_model = create_keysyms_model ();
+
+ renderer = gtk_cell_renderer_combo_new ();
+ g_object_set (G_OBJECT (renderer),
+ "editable", TRUE,
+ "model", keysyms_model,
+ "text-column", ACCEL_COMBO_COLUMN_TEXT,
+ "has-entry", TRUE,
+ "style", PANGO_STYLE_ITALIC,
+ "foreground", "Gray",
+ NULL);
+
+ g_signal_connect (renderer, "edited",
+ G_CALLBACK (key_edited), eprop);
+
+ column = gtk_tree_view_column_new_with_attributes
+ (_("Key"), renderer,
+ "text", ACCEL_COLUMN_KEY,
+ "style-set", ACCEL_COLUMN_KEY_SLOT,
+ "foreground-set", ACCEL_COLUMN_KEY_SLOT,
+ "visible", ACCEL_COLUMN_IS_SIGNAL,
+ NULL);
+
+ g_object_set (G_OBJECT (column), "expand", TRUE, NULL);
+
+ gtk_tree_view_append_column (GTK_TREE_VIEW (view_widget), column);
+
+ /********************* shift modifier column *********************/
+ renderer = gtk_cell_renderer_toggle_new ();
+ column = gtk_tree_view_column_new_with_attributes
+ (_("Shift"), renderer,
+ "visible", ACCEL_COLUMN_IS_SIGNAL,
+ "sensitive", ACCEL_COLUMN_KEY_ENTERED,
+ "active", ACCEL_COLUMN_MOD_SHIFT,
+ NULL);
+
+ g_object_set_data (G_OBJECT (renderer), "model-column",
+ GINT_TO_POINTER (ACCEL_COLUMN_MOD_SHIFT));
+ g_signal_connect (G_OBJECT (renderer), "toggled",
+ G_CALLBACK (modifier_toggled), eprop);
+
+ gtk_tree_view_append_column (GTK_TREE_VIEW (view_widget), column);
+
+ /********************* control modifier column *********************/
+ renderer = gtk_cell_renderer_toggle_new ();
+ column = gtk_tree_view_column_new_with_attributes
+ (_("Control"), renderer,
+ "visible", ACCEL_COLUMN_IS_SIGNAL,
+ "sensitive", ACCEL_COLUMN_KEY_ENTERED,
+ "active", ACCEL_COLUMN_MOD_CNTL,
+ NULL);
+
+ g_object_set_data (G_OBJECT (renderer), "model-column",
+ GINT_TO_POINTER (ACCEL_COLUMN_MOD_CNTL));
+ g_signal_connect (G_OBJECT (renderer), "toggled",
+ G_CALLBACK (modifier_toggled), eprop);
+
+ gtk_tree_view_append_column (GTK_TREE_VIEW (view_widget), column);
+
+ /********************* alt modifier column *********************/
+ renderer = gtk_cell_renderer_toggle_new ();
+ column = gtk_tree_view_column_new_with_attributes
+ (_("Alt"), renderer,
+ "visible", ACCEL_COLUMN_IS_SIGNAL,
+ "sensitive", ACCEL_COLUMN_KEY_ENTERED,
+ "active", ACCEL_COLUMN_MOD_ALT,
+ NULL);
+
+ g_object_set_data (G_OBJECT (renderer), "model-column",
+ GINT_TO_POINTER (ACCEL_COLUMN_MOD_ALT));
+ g_signal_connect (G_OBJECT (renderer), "toggled",
+ G_CALLBACK (modifier_toggled), eprop);
+
+ gtk_tree_view_append_column (GTK_TREE_VIEW (view_widget), column);
+
+ return view_widget;
+}
+
+static gboolean
+glade_eprop_accel_accum_accelerators (GtkTreeModel *model,
+ GtkTreePath *path,
+ GtkTreeIter *iter,
+ GList **ret)
+{
+ GladeAccelInfo *info;
+ gchar *signal, *key_str;
+ gboolean shift, cntl, alt, entered;
+
+ gtk_tree_model_get (model, iter, ACCEL_COLUMN_KEY_ENTERED, &entered, -1);
+ if (entered == FALSE) return FALSE;
+
+ gtk_tree_model_get (model, iter,
+ ACCEL_COLUMN_REAL_SIGNAL, &signal,
+ ACCEL_COLUMN_KEY, &key_str,
+ ACCEL_COLUMN_MOD_SHIFT, &shift,
+ ACCEL_COLUMN_MOD_CNTL, &cntl,
+ ACCEL_COLUMN_MOD_ALT, &alt,
+ -1);
+
+ info = g_new0 (GladeAccelInfo, 1);
+ info->signal = signal;
+ info->key = glade_key_from_string (key_str);
+ info->modifiers = (shift ? GDK_SHIFT_MASK : 0) |
+ (cntl ? GDK_CONTROL_MASK : 0) |
+ (alt ? GDK_MOD1_MASK : 0);
+
+ *ret = g_list_prepend (*ret, info);
+
+ g_free (key_str);
+
+ return FALSE;
+}
+
+
+static void
+glade_eprop_accel_show_dialog (GtkWidget *dialog_button,
+ GladeEditorProperty *eprop)
+{
+ GladeEPropAccel *eprop_accel = GLADE_EPROP_ACCEL (eprop);
+ GtkWidget *dialog, *parent, *vbox, *sw, *tree_view;
+ GladeProject *project;
+ GValue *value;
+ GList *accelerators = NULL;
+ gint res;
+
+ project = glade_widget_get_project (eprop->property->widget);
+ parent = gtk_widget_get_toplevel (GTK_WIDGET (eprop));
+
+ dialog = gtk_dialog_new_with_buttons (_("Choose accelerator keys..."),
+ GTK_WINDOW (parent),
+ GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_STOCK_CLEAR, GLADE_RESPONSE_CLEAR,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OK, GTK_RESPONSE_OK,
+ NULL);
+
+ gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
+
+ vbox = gtk_vbox_new (FALSE, 6);
+ gtk_widget_show (vbox);
+
+ gtk_container_set_border_width (GTK_CONTAINER (vbox), 6);
+
+ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), vbox, TRUE, TRUE, 0);
+
+ sw = gtk_scrolled_window_new (NULL, NULL);
+ gtk_widget_show (sw);
+ gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0);
+ gtk_widget_set_size_request (sw, 400, 200);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
+ GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN);
+
+ tree_view = glade_eprop_accel_view (eprop);
+ glade_eprop_accel_populate_view (eprop, GTK_TREE_VIEW (tree_view));
+
+ gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));
+
+ gtk_widget_show (tree_view);
+ gtk_container_add (GTK_CONTAINER (sw), tree_view);
+
+ /* Run the dialog */
+ res = gtk_dialog_run (GTK_DIALOG (dialog));
+ if (res == GTK_RESPONSE_OK)
+ {
+ gtk_tree_model_foreach
+ (gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view)),
+ (GtkTreeModelForeachFunc)
+ glade_eprop_accel_accum_accelerators, &accelerators);
+
+ value = g_new0 (GValue, 1);
+ g_value_init (value, GLADE_TYPE_ACCEL_GLIST);
+ g_value_take_boxed (value, accelerators);
+
+ glade_editor_property_commit (eprop, value);
+
+ g_value_unset (value);
+ g_free (value);
+ }
+ else if (res == GLADE_RESPONSE_CLEAR)
+ {
+ value = g_new0 (GValue, 1);
+ g_value_init (value, GLADE_TYPE_ACCEL_GLIST);
+ g_value_set_boxed (value, NULL);
+
+ glade_editor_property_commit (eprop, value);
+
+ g_value_unset (value);
+ g_free (value);
+ }
+
+ /* Clean up ...
+ */
+ gtk_widget_destroy (dialog);
+
+ g_object_unref (G_OBJECT (eprop_accel->model));
+ eprop_accel->model = NULL;
+
+ if (eprop_accel->parent_iters)
+ {
+ g_list_foreach (eprop_accel->parent_iters, (GFunc)iter_tab_free, NULL);
+ g_list_free (eprop_accel->parent_iters);
+ eprop_accel->parent_iters = NULL;
+ }
+
+}
+
+static GtkWidget *
+glade_eprop_accel_create_input (GladeEditorProperty *eprop)
+{
+ GladeEPropAccel *eprop_accel = GLADE_EPROP_ACCEL (eprop);
+ GtkWidget *hbox;
+ GtkWidget *button;
+
+ hbox = gtk_hbox_new (FALSE, 0);
+ eprop_accel->entry = gtk_entry_new ();
+ gtk_entry_set_editable (GTK_ENTRY (eprop_accel->entry), FALSE);
+ gtk_widget_show (eprop_accel->entry);
+ gtk_box_pack_start (GTK_BOX (hbox), eprop_accel->entry, TRUE, TRUE, 0);
+
+ button = gtk_button_new_with_label ("...");
+ gtk_widget_show (button);
+ gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
+
+ g_signal_connect (G_OBJECT (button), "clicked",
+ G_CALLBACK (glade_eprop_accel_show_dialog),
+ eprop);
+
+ return hbox;
+}
Added: branches/builder/plugins/gtk+/glade-accels.h
==============================================================================
--- (empty file)
+++ branches/builder/plugins/gtk+/glade-accels.h Wed Apr 2 06:17:18 2008
@@ -0,0 +1,50 @@
+#include <gladeui/glade.h>
+#include <gtk/gtk.h>
+
+
+#define GLADE_TYPE_PARAM_ACCEL (glade_param_accel_get_type())
+#define GLADE_TYPE_ACCEL_GLIST (glade_accel_glist_get_type())
+#define GLADE_TYPE_EPROP_ACCEL (glade_eprop_accel_get_type())
+
+#define GLADE_IS_PARAM_SPEC_ACCEL(pspec) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), \
+ GLADE_TYPE_PARAM_ACCEL))
+#define GLADE_PARAM_SPEC_ACCEL(pspec) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((pspec), \
+ GLADE_TYPE_PARAM_ACCEL, GladeParamSpecAccel))
+
+typedef struct _GladeKey GladeKey;
+typedef struct _GladeParamSpecAccel GladeParamSpecAccel;
+
+
+struct _GladeKey {
+ guint value;
+ gchar *name;
+};
+
+extern const GladeKey GladeKeys[];
+
+#define GLADE_KEYS_LAST_ALPHANUM "9"
+#define GLADE_KEYS_LAST_EXTRA "questiondown"
+#define GLADE_KEYS_LAST_KP "KP_9"
+#define GLADE_KEYS_LAST_FKEY "F35"
+
+GType glade_param_accel_get_type (void) G_GNUC_CONST;
+GType glade_accel_glist_get_type (void) G_GNUC_CONST;
+GType glade_eprop_accel_get_type (void) G_GNUC_CONST;
+
+GList *glade_accel_list_copy (GList *accels);
+void glade_accel_list_free (GList *accels);
+
+
+GParamSpec *glade_param_spec_accel (const gchar *name,
+ const gchar *nick,
+ const gchar *blurb,
+ GType widget_type,
+ GParamFlags flags);
+
+GParamSpec *glade_standard_accel_spec (void);
+
+gboolean glade_keyval_valid (guint val);
+
+gchar *glade_accels_make_string (GList *accels);
Modified: branches/builder/plugins/gtk+/glade-gtk.c
==============================================================================
--- branches/builder/plugins/gtk+/glade-gtk.c (original)
+++ branches/builder/plugins/gtk+/glade-gtk.c Wed Apr 2 06:17:18 2008
@@ -26,6 +26,7 @@
#include "glade-gtk.h"
#include "fixed-bg.xpm"
+#include "glade-accels.h"
#include <gladeui/glade-editor-property.h>
#include <gladeui/glade-base-editor.h>
@@ -242,6 +243,58 @@
}
/* ----------------------------- GtkWidget ------------------------------ */
+void
+glade_gtk_widget_read_widget (GladeWidgetAdaptor *adaptor,
+ GladeWidget *widget,
+ GladeXmlNode *node)
+{
+ /* This code should work the same for <packing> and <widget> */
+ if (!glade_xml_node_verify_silent (node, GLADE_XML_TAG_WIDGET))
+ return;
+
+ /* First chain up.. */
+ GWA_GET_CLASS (G_TYPE_OBJECT)->read_widget (adaptor, widget, node);
+
+
+ /* Read in atk properties and accelerators */
+
+}
+
+GladeEditorProperty *
+glade_gtk_widget_create_eprop (GladeWidgetAdaptor *adaptor,
+ GladePropertyClass *klass,
+ gboolean use_command)
+{
+ GladeEditorProperty *eprop;
+
+ /* chain up.. */
+ if (GLADE_IS_PARAM_SPEC_ACCEL (klass->pspec))
+ eprop = g_object_new (GLADE_TYPE_EPROP_ACCEL,
+ "property-class", klass,
+ "use-command", use_command,
+ NULL);
+ else
+ eprop = GWA_GET_CLASS
+ (G_TYPE_OBJECT)->create_eprop (adaptor,
+ klass,
+ use_command);
+ return eprop;
+}
+
+gchar *
+glade_gtk_widget_string_from_value (GladeWidgetAdaptor *adaptor,
+ GladePropertyClass *klass,
+ const GValue *value)
+{
+ if (GLADE_IS_PARAM_SPEC_ACCEL (klass->pspec))
+ return glade_accels_make_string (g_value_get_boxed (value));
+ else
+ return GWA_GET_CLASS
+ (G_TYPE_OBJECT)->string_from_value (adaptor,
+ klass,
+ value);
+}
+
static void
widget_parent_changed (GtkWidget *widget,
GParamSpec *pspec,
Copied: branches/builder/plugins/gtk+/glade-keysyms.c (from r1752, /branches/builder/gladeui/glade-keysyms.c)
==============================================================================
--- /branches/builder/gladeui/glade-keysyms.c (original)
+++ branches/builder/plugins/gtk+/glade-keysyms.c Wed Apr 2 06:17:18 2008
@@ -1,6 +1,6 @@
#include <gdk/gdkkeysyms.h>
-#include "glade-builtins.h"
+#include "glade-accels.h"
/*
* This is automatically generated by ${glade-2 cvs}/tools/getkeys.pl
Modified: branches/builder/plugins/gtk+/gtk+.xml.in
==============================================================================
--- branches/builder/plugins/gtk+/gtk+.xml.in (original)
+++ branches/builder/plugins/gtk+/gtk+.xml.in Wed Apr 2 06:17:18 2008
@@ -11,6 +11,9 @@
<set-property-function>glade_gtk_widget_set_property</set-property-function>
<get-property-function>glade_gtk_widget_get_property</get-property-function>
<action-activate-function>glade_gtk_widget_action_activate</action-activate-function>
+ <read-widget-function>glade_gtk_widget_read_widget</read-widget-function>
+ <create-editor-property-function>glade_gtk_widget_create_eprop</create-editor-property-function>
+ <string-from-value-function>glade_gtk_widget_string_from_value</string-from-value-function>
<actions>
<action id="remove_parent" _name="Remove Parent" stock="gtk-remove"/>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]