summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.van.berkom@gmail.com>2004-11-03 05:53:05 +0000
committerDavid Hoover <dhoover@src.gnome.org>2004-11-03 05:53:05 +0000
commit9051dfb92a56467cae5a0783fac58963c9b8b7b4 (patch)
tree407d61573ef25c618714c706019333fb4462695f
parentb9a1931ed5275262304b07d0d7c8551ca10e9aa6 (diff)
downloadglade-9051dfb92a56467cae5a0783fac58963c9b8b7b4.tar.gz
Removed GladePropertyType completely from the source in favor of
2004-11-02 Tristan Van Berkom <tristan.van.berkom@gmail.com> * Removed GladePropertyType completely from the source in favor of GParamSpec. * Removed GladeChoice code, and replaced all references thereof * Custom types must now provide a function to retrieve a GParamSpec for that type (xml files and glade-gtk backend updated accordingly). * Removed "child" member from GladePropertyType in order to avoid confusion (Note, I will add support for non-widget types + all types allowed to have children, in a more flexable way, for now I got rid of all mention of "child" since it wasn't implemented and mostly `#if 0'd out anyway) * Implemented <VerifyFunction> in xml files and in the glade-gtk backend. * Added support for numerical types long/ulong/int64/uint64 to the editor. * src/glade-project.c: glade_project_remove_widget() Now removes nodes on widget to remove, this fixes bug 156515. * src/glade-editor.c: Fixed popup name to g_strdup_printf(_("Create a %s"), type);
-rw-r--r--ChangeLog21
-rw-r--r--src/Makefile.am2
-rw-r--r--src/glade-choice.c277
-rw-r--r--src/glade-choice.h71
-rw-r--r--src/glade-editor.c371
-rw-r--r--src/glade-editor.h6
-rw-r--r--src/glade-gtk.c309
-rw-r--r--src/glade-plugin.h1
-rw-r--r--src/glade-project.c6
-rw-r--r--src/glade-property-class.c672
-rw-r--r--src/glade-property-class.h49
-rw-r--r--src/glade-property.c63
-rw-r--r--src/glade-utils.c81
-rw-r--r--src/glade-utils.h2
-rw-r--r--src/glade-widget-class.c36
-rw-r--r--src/glade.h2
-rw-r--r--widgets/gtkbox.xml3
-rw-r--r--widgets/gtkbutton.xml11
-rw-r--r--widgets/gtkdialog.xml2
-rw-r--r--widgets/gtknotebook.xml5
-rw-r--r--widgets/gtkoptionmenu.xml4
-rw-r--r--widgets/gtkradiobutton.xml2
-rw-r--r--widgets/gtkspinbutton.xml10
-rw-r--r--widgets/gtktable.xml5
-rw-r--r--widgets/gtktoolbar.xml10
-rw-r--r--widgets/gtkwidget.xml2
26 files changed, 746 insertions, 1277 deletions
diff --git a/ChangeLog b/ChangeLog
index 65e1bcac..d843fda5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2004-11-02 Tristan Van Berkom <tristan.van.berkom@gmail.com>
+
+ * Removed GladePropertyType completely from the source in favor of
+ GParamSpec.
+ * Removed GladeChoice code, and replaced all references thereof
+ * Custom types must now provide a function to retrieve a GParamSpec for
+ that type (xml files and glade-gtk backend updated accordingly).
+ * Removed "child" member from GladePropertyType in order to avoid
+ confusion (Note, I will add support for non-widget types + all types
+ allowed to have children, in a more flexable way, for now I got rid
+ of all mention of "child" since it wasn't implemented and mostly
+ `#if 0'd out anyway)
+ * Implemented <VerifyFunction> in xml files and in the glade-gtk
+ backend.
+ * Added support for numerical types long/ulong/int64/uint64 to the
+ editor.
+ * src/glade-project.c: glade_project_remove_widget() Now removes nodes
+ on widget to remove, this fixes bug 156515.
+ * src/glade-editor.c: Fixed popup name to
+ g_strdup_printf(_("Create a %s"), type);
+
2004-11-02 David Hoover <karma@deadmoose.com>
* src/Makefile.am: fix up CLEANFILES problem
diff --git a/src/Makefile.am b/src/Makefile.am
index a7c816e3..b74c70cc 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -59,7 +59,6 @@ glade_3_SOURCES = \
glade-popup.c \
glade-widget.c \
glade-catalog.c \
- glade-choice.c \
glade-editor.c \
glade-utils.c \
glade-signal.c \
@@ -91,7 +90,6 @@ noinst_HEADERS = \
glade-property.h \
glade-property-class.h \
glade-popup.h \
- glade-choice.h \
glade-catalog.h \
glade-utils.h \
glade-signal.h \
diff --git a/src/glade-choice.c b/src/glade-choice.c
deleted file mode 100644
index 262d7dd8..00000000
--- a/src/glade-choice.c
+++ /dev/null
@@ -1,277 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/*
- * Copyright (C) 2001 Ximian, Inc.
- *
- * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
- *
- * Authors:
- * Chema Celorio <chema@celorio.com>
- */
-
-#include <string.h>
-
-#include "glade.h"
-#include "glade-xml-utils.h"
-#include "glade-choice.h"
-
-/**
- * glade_choice_new:
- *
- * Returns: a new #GladeChoice
- */
-GladeChoice *
-glade_choice_new (void)
-{
- GladeChoice *choice;
-
- choice = g_new0 (GladeChoice, 1);
-
- return choice;
-}
-
-/**
- * glade_choice_clone:
- * @choice: a #GladeChoice
- *
- * Returns: a new #GladeChoice cloned from @choice
- */
-GladeChoice *
-glade_choice_clone (GladeChoice *choice)
-{
- GladeChoice *clone;
-
- clone = glade_choice_new ();
- clone->id = g_strdup (choice->id);
- clone->name = g_strdup (choice->name);
- clone->type = choice->type;
- clone->value = choice->value;
-
- return clone;
-}
-
-/**
- * glade_choice_free:
- * @choice: a #GladeChoice
- *
- * Frees @choice and its associated memory.
- */
-void
-glade_choice_free (GladeChoice *choice)
-{
- if (choice == NULL)
- return;
-
- g_free (choice->name);
- g_free (choice->id);
- g_free (choice);
-}
-
-/* This should go outside and it should be generated from ./make_enums.pl taking enums.txt
- * as input. Chema */
-/* I think gtk 2.0 already has a way of doing this .. Chema */
-static gint
-glade_enum_from_string (const gchar *string)
-{
- g_return_val_if_fail (string != NULL, -1);
-
- if (strcmp (string, "-") == 0)
- return 0;
- if (strcmp (string, "GTK_JUSTIFY_LEFT") == 0)
- return GTK_JUSTIFY_LEFT;
- if (strcmp (string, "GTK_JUSTIFY_RIGHT") == 0)
- return GTK_JUSTIFY_RIGHT;
- if (strcmp (string, "GTK_JUSTIFY_CENTER") == 0)
- return GTK_JUSTIFY_CENTER;
- if (strcmp (string, "GTK_JUSTIFY_FILL") == 0)
- return GTK_JUSTIFY_FILL;
- if (strcmp (string, "GTK_WINDOW_TOPLEVEL") == 0)
- return GTK_WINDOW_TOPLEVEL;
- if (strcmp (string, "GTK_WINDOW_POPUP") == 0)
- return GTK_WINDOW_POPUP;
- if (strcmp (string, "GTK_WIN_POS_NONE") == 0)
- return GTK_WIN_POS_NONE;
- if (strcmp (string, "GTK_WIN_POS_CENTER") == 0)
- return GTK_WIN_POS_CENTER;
- if (strcmp (string, "GTK_WIN_POS_MOUSE") == 0)
- return GTK_WIN_POS_MOUSE;
- if (strcmp (string, "GTK_RELIEF_NORMAL") == 0)
- return GTK_RELIEF_NORMAL;
- if (strcmp (string, "GTK_RELIEF_HALF") == 0)
- return GTK_RELIEF_HALF;
- if (strcmp (string, "GTK_RELIEF_NONE") == 0)
- return GTK_RELIEF_NONE;
-
- return -1;
-}
-
-#if 0
-static gchar *
-glade_string_from_string (const gchar *string)
-{
- g_return_val_if_fail (string != NULL, NULL);
-
- if (strcmp (string, "-") == 0)
- return "None";
-#if 1 /* Add the gtk stock buttons list here. Gtk takes care of stock
- * items now
- */
- if (strcmp (string, "GTK_STOCK_OK") == 0)
- return GTK_STOCK_OK;
- if (strcmp (string, "GTK_STOCK_CANCEL") == 0)
- return GTK_STOCK_CANCEL;
-#endif
-#if 0
-
- if (strcmp (string, "GNOME_STOCK_BUTTON_YES") == 0)
- return GNOME_STOCK_BUTTON_YES;
- if (strcmp (string, "GNOME_STOCK_BUTTON_NO") == 0)
- return GNOME_STOCK_BUTTON_NO;
- if (strcmp (string, "GNOME_STOCK_BUTTON_CLOSE") == 0)
- return GNOME_STOCK_BUTTON_CLOSE;
- if (strcmp (string, "GNOME_STOCK_BUTTON_APPLY") == 0)
- return GNOME_STOCK_BUTTON_APPLY;
- if (strcmp (string, "GNOME_STOCK_BUTTON_HELP") == 0)
- return GNOME_STOCK_BUTTON_HELP;
- if (strcmp (string, "GNOME_STOCK_BUTTON_NEXT") == 0)
- return GNOME_STOCK_BUTTON_NEXT;
- if (strcmp (string, "GNOME_STOCK_BUTTON_PREV") == 0)
- return GNOME_STOCK_BUTTON_PREV;
- if (strcmp (string, "GNOME_STOCK_BUTTON_UP") == 0)
- return GNOME_STOCK_BUTTON_UP;
- if (strcmp (string, "GNOME_STOCK_BUTTON_DOWN") == 0)
- return GNOME_STOCK_BUTTON_DOWN;
- if (strcmp (string, "GNOME_STOCK_BUTTON_FONT") == 0)
- return GNOME_STOCK_BUTTON_FONT;
-#endif
-
- g_warning ("Could not determine string from string (%s)\n",
- string);
-
- return NULL;
-}
-#endif
-
-static GladeChoice *
-glade_choice_new_from_value (GEnumValue value)
-{
- GladeChoice *choice;
-
- choice = glade_choice_new ();
- choice->name = g_strdup (value.value_nick);
- choice->id = g_strdup (value.value_name);
- choice->value = value.value;
-
- return choice;
-}
-
-/**
- * glade_choice_list_new_from_spec:
- * @spec: a #GParamSpec
- *
- * TODO: write me
- *
- * Returns:
- */
-GList *
-glade_choice_list_new_from_spec (GParamSpec *spec)
-{
- GladeChoice *choice;
- GEnumClass *class;
- GEnumValue value;
- GList *list = NULL;
- gint num;
- gint i;
-
- class = G_PARAM_SPEC_ENUM (spec)->enum_class;
- num = class->n_values;
- for (i = 0; i < num; i++) {
- value = class->values[i];
- choice = glade_choice_new_from_value (value);
- if (choice)
- list = g_list_prepend (list, choice);
- }
- list = g_list_reverse (list);
-
- return list;
-}
-
-static GladeChoice *
-glade_choice_new_from_node (GladeXmlNode *node)
-{
- GladeChoice *choice;
-
- if (!glade_xml_node_verify (node, GLADE_TAG_ENUM))
- return NULL;
-
- choice = glade_choice_new ();
- choice->name = glade_xml_get_property_string_required (node, GLADE_TAG_NAME, NULL);
- choice->id = glade_xml_get_property_string_required (node, GLADE_TAG_ID, NULL);
-#if 0
- choice->symbol = glade_xml_get_property_string_required (node, GLADE_TAG_SYMBOL, NULL);
-#endif
- choice->value = glade_enum_from_string (choice->id);
-#if 0
- if (choice->value == -1)
- choice->string = glade_string_from_string (choice->id);
-#endif
-
-#if 0
- if ((choice->value == -1 && choice->string == NULL) || !choice->name) {
-#endif
- if (!choice->name) {
- g_warning ("Could not create Choice from node");
- return NULL;
- }
-
- return choice;
-}
-
-/**
- * glade_choice_list_new_from_node:
- * @node: a #GladeXmlNode
- *
- * TODO: write me
- *
- * Returns:
- */
-GList *
-glade_choice_list_new_from_node (GladeXmlNode *node)
-{
- GladeXmlNode *child;
- GladeChoice *choice;
- GList *list = NULL;
- int def_value = 0;
-
- g_return_val_if_fail (glade_xml_node_verify (node, GLADE_TAG_ENUMS), NULL);
-
- child = glade_xml_node_get_children (node);
- for (; child; child = glade_xml_node_next (child)) {
- if (!glade_xml_node_verify (child, GLADE_TAG_ENUM))
- continue;
- choice = glade_choice_new_from_node (child);
- if (choice == NULL)
- continue;
- /* if enum_from_string is not able to find a value for this enum,
- we will use as value the position of the item in the enum list */
- if (choice->value == -1)
- choice->value = def_value;
- list = g_list_prepend (list, choice);
- ++def_value;
- }
-
- list = g_list_reverse (list);
-
- return list;
-}
diff --git a/src/glade-choice.h b/src/glade-choice.h
deleted file mode 100644
index dad17914..00000000
--- a/src/glade-choice.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-#ifndef __GLADE_CHOICE_H__
-#define __GLADE_CHOICE_H__
-
-G_BEGIN_DECLS
-
-#define GLADE_CHOICE(c) ((GladeChoice *)c)
-#define GLADE_IS_CHOICE(c) (c != NULL)
-
-
-/* GladeChoice is used for GladeProperties of type "choice"
- * each property of type choice has a list of GladeChoice objects.
- * [see glade-property ]
-
- <Property>
- ...
- ...
- <Choices>
- <Choice>
- <Name>Top Level</Name>
- <Symbol>GTK_WINDOW_TOPLEVEL</Symbol>
- </Choice>
- <Choice>
- <Name>Dialog</Name>
- ...
-
- */
-struct _GladeChoice {
- GType type;
-
- gchar *name; /* Name of the choice to be used in the gui. This
- * field is translated. Like "Top Level" or "Ok"
- * (for GTK_WINDOW_TOPLEVEL & GNOME_STOCK_BUTTON_OK
- */
- gchar *id;
-#if 0
- gchar *symbol; /* Symbol for the choice. Like GTK_WINDOW_TOPLEVEL
- * (which is an integer) or GNOME_STOCK_BUTTON_FOO
- * (which is not an integer). For integers which are
- * enum'ed values this symbol is converted to its
- * value
- */
-#endif
-
- gint value; /* The enum value of the symbol. The symbol
- * GTK_WINDOW_TOPLEVEL will be 0 and GTK_WINDOW_POPUP
- * will be 1
- */
-
-#if 0
- const gchar *string; /* For non-integer values like
- * GNOME_STOCK_BUTTON_OK it points to a string
- * inside the library that contains it.
- * See glade-choice.c#glade_string_from_sring
- */
-#endif
-};
-
-GladeChoice *glade_choice_new (void);
-
-GladeChoice *glade_choice_clone (GladeChoice *choice);
-
-void glade_choice_free (GladeChoice *choice);
-
-GList *glade_choice_list_new_from_spec (GParamSpec *spec);
-
-GList *glade_choice_list_new_from_node (GladeXmlNode *node);
-
-G_END_DECLS
-
-#endif /* __GLADE_CHOICE_H__ */
diff --git a/src/glade-editor.c b/src/glade-editor.c
index c67a48de..cc6a4a6b 100644
--- a/src/glade-editor.c
+++ b/src/glade-editor.c
@@ -32,7 +32,6 @@
#include "glade.h"
#include "glade-widget.h"
#include "glade-widget-class.h"
-#include "glade-choice.h"
#include "glade-editor.h"
#include "glade-signal-editor.h"
#include "glade-parameter.h"
@@ -65,6 +64,7 @@ static gboolean glade_editor_table_append_items (GladeEditorTable *table,
GList **list,
GladeEditorTableType type);
+static void glade_editor_property_load (GladeEditorProperty *property, GladeWidget *widget);
static void glade_editor_property_load_flags (GladeEditorProperty *property);
@@ -242,6 +242,8 @@ glade_editor_property_changed_text (GtkWidget *entry,
glade_editor_property_changed_text_common (property->property, text);
g_free (text);
+
+ glade_editor_property_load (property, property->property->widget);
}
static void
@@ -266,13 +268,15 @@ glade_editor_property_changed_text_view (GtkTextBuffer *buffer,
glade_editor_property_changed_text_common (property->property, text);
g_free (text);
+
+ glade_editor_property_load (property, property->property->widget);
}
static void
glade_editor_property_changed_enum (GtkWidget *menu_item,
GladeEditorProperty *property)
{
- GladeChoice *choice;
+ gint ival;
GValue val = { 0, };
GladeProperty *gproperty;
@@ -282,16 +286,17 @@ glade_editor_property_changed_enum (GtkWidget *menu_item,
if (property->property->loading)
return;
- choice = g_object_get_data (G_OBJECT (menu_item), GLADE_ENUM_DATA_TAG);
- g_return_if_fail (choice != NULL);
+ ival = GPOINTER_TO_INT(g_object_get_data (G_OBJECT (menu_item), GLADE_ENUM_DATA_TAG));
gproperty = property->property;
- g_value_init (&val, gproperty->class->def->g_type);
- g_value_set_enum (&val, choice->value);
+ g_value_init (&val, gproperty->class->pspec->value_type);
+ g_value_set_enum (&val, ival);
glade_command_set_property (gproperty, &val);
g_value_unset (&val);
+
+ glade_editor_property_load (property, property->property->widget);
}
static void
@@ -336,7 +341,6 @@ static void
glade_editor_property_changed_numeric (GtkWidget *spin,
GladeEditorProperty *property)
{
- GladeEditorNumericType numeric_type;
GValue val = { 0, };
g_return_if_fail (property != NULL);
@@ -345,30 +349,41 @@ glade_editor_property_changed_numeric (GtkWidget *spin,
if (property->property->loading)
return;
- numeric_type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (spin), "NumericType"));
-
- switch (numeric_type)
- {
- case GLADE_EDITOR_INTEGER:
- g_value_init (&val, G_TYPE_INT);
- g_value_set_int (&val, gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spin)));
- break;
- case GLADE_EDITOR_FLOAT:
- g_value_init (&val, G_TYPE_FLOAT);
- g_value_set_float (&val, (gfloat) gtk_spin_button_get_value (GTK_SPIN_BUTTON (spin)));
- break;
- case GLADE_EDITOR_DOUBLE:
- g_value_init (&val, G_TYPE_DOUBLE);
- g_value_set_double (&val, gtk_spin_button_get_value (GTK_SPIN_BUTTON (spin)));
- break;
- default:
- g_warning ("Invalid numeric_type %i\n", numeric_type);
- return;
- }
+ g_value_init (&val, property->class->pspec->value_type);
+
+ if (G_IS_PARAM_SPEC_INT(property->class->pspec))
+ g_value_set_int (&val, gtk_spin_button_get_value_as_int
+ (GTK_SPIN_BUTTON (spin)));
+ else if (G_IS_PARAM_SPEC_UINT(property->class->pspec))
+ g_value_set_uint (&val, gtk_spin_button_get_value_as_int
+ (GTK_SPIN_BUTTON (spin)));
+ else if (G_IS_PARAM_SPEC_LONG(property->class->pspec))
+ g_value_set_long (&val, (glong)gtk_spin_button_get_value_as_int
+ (GTK_SPIN_BUTTON (spin)));
+ else if (G_IS_PARAM_SPEC_ULONG(property->class->pspec))
+ g_value_set_ulong (&val, (gulong)gtk_spin_button_get_value_as_int
+ (GTK_SPIN_BUTTON (spin)));
+ else if (G_IS_PARAM_SPEC_INT64(property->class->pspec))
+ g_value_set_int64 (&val, (gint64)gtk_spin_button_get_value_as_int
+ (GTK_SPIN_BUTTON (spin)));
+ else if (G_IS_PARAM_SPEC_UINT64(property->class->pspec))
+ g_value_set_uint64 (&val, (guint64)gtk_spin_button_get_value_as_int
+ (GTK_SPIN_BUTTON (spin)));
+ else if (G_IS_PARAM_SPEC_FLOAT(property->class->pspec))
+ g_value_set_float (&val, (gfloat) gtk_spin_button_get_value
+ (GTK_SPIN_BUTTON (spin)));
+ else if (G_IS_PARAM_SPEC_DOUBLE(property->class->pspec))
+ g_value_set_double (&val, gtk_spin_button_get_value
+ (GTK_SPIN_BUTTON (spin)));
+ else
+ g_warning ("Unsupported type %s\n",
+ g_type_name(property->class->pspec->value_type));
glade_command_set_property (property->property, &val);
g_value_unset (&val);
+
+ glade_editor_property_load (property, property->property->widget);
}
static void
@@ -394,6 +409,8 @@ glade_editor_property_changed_boolean (GtkWidget *button,
glade_command_set_property (property->property, &val);
g_value_unset (&val);
+
+ glade_editor_property_load (property, property->property->widget);
}
static void
@@ -421,6 +438,8 @@ glade_editor_property_changed_unichar (GtkWidget *entry,
g_value_unset (&val);
g_free (text);
+
+ glade_editor_property_load (property, property->property->widget);
}
static void glade_editor_property_delete_unichar (GtkEditable *editable,
@@ -625,19 +644,18 @@ glade_editor_property_show_flags_dialog (GtkWidget *entry,
/* ============================= Create inputs ============================= */
static GtkWidget *
glade_editor_create_input_enum_item (GladeEditorProperty *property,
- GladeChoice *choice)
+ const gchar *name,
+ gint value)
{
GtkWidget *menu_item;
- const gchar *name;
- name = choice->name;
menu_item = gtk_menu_item_new_with_label (name);
g_signal_connect (G_OBJECT (menu_item), "activate",
G_CALLBACK (glade_editor_property_changed_enum),
property);
- g_object_set_data (G_OBJECT (menu_item), GLADE_ENUM_DATA_TAG, choice);
+ g_object_set_data (G_OBJECT (menu_item), GLADE_ENUM_DATA_TAG, GINT_TO_POINTER(value));
return menu_item;
}
@@ -645,19 +663,23 @@ glade_editor_create_input_enum_item (GladeEditorProperty *property,
static GtkWidget *
glade_editor_create_input_enum (GladeEditorProperty *property)
{
- GladeChoice *choice;
- GtkWidget *menu_item;
- GtkWidget *menu;
- GtkWidget *option_menu;
- GList *list;
-
+ GtkWidget *menu_item;
+ GtkWidget *menu;
+ GtkWidget *option_menu;
+ GEnumClass *eclass;
+ gint i;
+
g_return_val_if_fail (property != NULL, NULL);
+ g_return_val_if_fail ((eclass = g_type_class_ref
+ (property->class->pspec->value_type)) != NULL, NULL);
menu = gtk_menu_new ();
- for (list = property->class->choices; list; list = list->next)
+
+ for (i = 0; i < eclass->n_values; i++)
{
- choice = (GladeChoice *)list->data;
- menu_item = glade_editor_create_input_enum_item (property, choice);
+ menu_item = glade_editor_create_input_enum_item (property,
+ eclass->values[i].value_name,
+ eclass->values[i].value);
gtk_widget_show (menu_item);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
}
@@ -665,6 +687,8 @@ glade_editor_create_input_enum (GladeEditorProperty *property)
option_menu = gtk_option_menu_new ();
gtk_option_menu_set_menu (GTK_OPTION_MENU (option_menu), menu);
+ g_type_class_unref (eclass);
+
return option_menu;
}
@@ -735,8 +759,7 @@ glade_editor_create_input_text (GladeEditorProperty *property)
}
static GtkWidget *
-glade_editor_create_input_numeric (GladeEditorProperty *property,
- GladeEditorNumericType numeric_type)
+glade_editor_create_input_numeric (GladeEditorProperty *property)
{
GladePropertyClass *property_class;
GtkAdjustment *adjustment;
@@ -749,9 +772,10 @@ glade_editor_create_input_numeric (GladeEditorProperty *property,
adjustment = glade_parameter_adjustment_new (property_class);
spin = gtk_spin_button_new (adjustment, 4,
- numeric_type == GLADE_EDITOR_INTEGER ? 0 : 2);
+ G_IS_PARAM_SPEC_FLOAT(property->class->pspec) ||
+ G_IS_PARAM_SPEC_DOUBLE(property->class->pspec)
+ ? 2 : 0);
- g_object_set_data (G_OBJECT (spin), "NumericType", GINT_TO_POINTER (numeric_type));
g_signal_connect (G_OBJECT (spin), "value_changed",
G_CALLBACK (glade_editor_property_changed_numeric),
property);
@@ -777,24 +801,6 @@ glade_editor_create_input_numeric (GladeEditorProperty *property,
}
static GtkWidget *
-glade_editor_create_input_integer (GladeEditorProperty *property)
-{
- return glade_editor_create_input_numeric (property, GLADE_EDITOR_INTEGER);
-}
-
-static GtkWidget *
-glade_editor_create_input_float (GladeEditorProperty *property)
-{
- return glade_editor_create_input_numeric (property, GLADE_EDITOR_FLOAT);
-}
-
-static GtkWidget *
-glade_editor_create_input_double (GladeEditorProperty *property)
-{
- return glade_editor_create_input_numeric (property, GLADE_EDITOR_DOUBLE);
-}
-
-static GtkWidget *
glade_editor_create_input_boolean (GladeEditorProperty *property)
{
GtkWidget *button;
@@ -831,21 +837,8 @@ glade_editor_create_input_unichar (GladeEditorProperty *property)
return entry;
}
-static GtkWidget *
-glade_editor_create_input_object (GladeEditorProperty *property,
- GladeEditorTable *table)
-{
- g_return_val_if_fail (GLADE_IS_EDITOR_TABLE (table), NULL);
- g_return_val_if_fail (GLADE_IS_EDITOR_PROPERTY (property), NULL);
-
- glade_editor_table_append_items (table, property->class->child,
- &property->children, TABLE_TYPE_GENERAL);
-
- return NULL;
-}
-
/**
- * glade_editor_create_item_labe:
+ * glade_editor_create_item_label:
* @class:
*
* TODO: write me
@@ -891,49 +884,26 @@ glade_editor_append_item_real (GladeEditorTable *table,
g_return_val_if_fail (GLADE_IS_EDITOR_TABLE (table), NULL);
g_return_val_if_fail (GLADE_IS_PROPERTY_CLASS (property->class), NULL);
- switch (property->class->type) {
- case GLADE_PROPERTY_TYPE_BOOLEAN:
- input = glade_editor_create_input_boolean (property);
- break;
- case GLADE_PROPERTY_TYPE_FLOAT:
- input = glade_editor_create_input_float (property);
- break;
- case GLADE_PROPERTY_TYPE_INTEGER:
- input = glade_editor_create_input_integer (property);
- break;
- case GLADE_PROPERTY_TYPE_DOUBLE:
- input = glade_editor_create_input_double (property);
- break;
- case GLADE_PROPERTY_TYPE_STRING:
- input = glade_editor_create_input_text (property);
- break;
- case GLADE_PROPERTY_TYPE_ENUM:
+ if (G_IS_PARAM_SPEC_ENUM(property->class->pspec))
input = glade_editor_create_input_enum (property);
- break;
- case GLADE_PROPERTY_TYPE_FLAGS:
+ else if (G_IS_PARAM_SPEC_FLAGS(property->class->pspec))
input = glade_editor_create_input_flags (property);
- break;
- case GLADE_PROPERTY_TYPE_UNICHAR:
+ else if (G_IS_PARAM_SPEC_BOOLEAN(property->class->pspec))
+ input = glade_editor_create_input_boolean (property);
+ else if (G_IS_PARAM_SPEC_INT(property->class->pspec) ||
+ G_IS_PARAM_SPEC_UINT(property->class->pspec) ||
+ G_IS_PARAM_SPEC_LONG(property->class->pspec) ||
+ G_IS_PARAM_SPEC_ULONG(property->class->pspec) ||
+ G_IS_PARAM_SPEC_INT64(property->class->pspec) ||
+ G_IS_PARAM_SPEC_UINT64(property->class->pspec) ||
+ G_IS_PARAM_SPEC_FLOAT(property->class->pspec) ||
+ G_IS_PARAM_SPEC_DOUBLE(property->class->pspec))
+ input = glade_editor_create_input_numeric (property);
+ else if (G_IS_PARAM_SPEC_STRING(property->class->pspec))
+ input = glade_editor_create_input_text (property);
+ else if (G_IS_PARAM_SPEC_UNICHAR(property->class->pspec))
input = glade_editor_create_input_unichar (property);
- break;
- case GLADE_PROPERTY_TYPE_OTHER_WIDGETS:
- g_warning ("The widget type %s does not have an input implemented\n",
- property->class->name);
- break;
- case GLADE_PROPERTY_TYPE_OBJECT:
- glade_editor_create_input_object (property, table);
- /* We don't need to add an input for the object, the object
- * has added its childs already
- */
- return NULL;
- case GLADE_PROPERTY_TYPE_ERROR:
- return gtk_label_new ("Error !");
- default:
- g_warning ("This type %s does not have an input implemented\n",
- property->class->name);
- return gtk_label_new ("Fix me !");
- }
-
+
if (input == NULL) {
g_warning ("Can't create an input widget for type %s\n",
property->class->name);
@@ -1055,7 +1025,7 @@ glade_editor_on_edit_menu_click (GtkButton *button, GladeEditor *editor)
gtk_widget_show (GTK_WIDGET (menu_editor));
}
-#define GLADE_PROPERY_TABLE_ROW_SPACING 2
+#define GLADE_PROPERTY_TABLE_ROW_SPACING 2
static GladeEditorTable *
glade_editor_table_new (void)
@@ -1069,7 +1039,7 @@ glade_editor_table_new (void)
table->rows = 0;
gtk_table_set_row_spacings (GTK_TABLE (table->table_widget),
- GLADE_PROPERY_TABLE_ROW_SPACING);
+ GLADE_PROPERTY_TABLE_ROW_SPACING);
g_object_ref (G_OBJECT(table->table_widget));
@@ -1249,15 +1219,12 @@ static void
glade_editor_property_load_integer (GladeEditorProperty *property)
{
GtkWidget *spin = NULL;
- GList *parameters;
gfloat val;
g_return_if_fail (property != NULL);
g_return_if_fail (property->property != NULL);
g_return_if_fail (property->property->value != NULL);
g_return_if_fail (property->input != NULL);
-
- parameters = property->property->class->parameters;
if (property->property->class->optional) {
GtkBoxChild *child;
@@ -1289,74 +1256,67 @@ glade_editor_property_load_integer (GladeEditorProperty *property)
spin = property->input;
}
-
- if (G_VALUE_TYPE (property->property->value) == G_TYPE_INT)
+ if (G_IS_PARAM_SPEC_INT(property->class->pspec))
val = (gfloat) g_value_get_int (property->property->value);
- else if (G_VALUE_TYPE (property->property->value) == G_TYPE_DOUBLE)
+ else if (G_IS_PARAM_SPEC_UINT(property->class->pspec))
+ val = (gfloat) g_value_get_uint (property->property->value);
+ else if (G_IS_PARAM_SPEC_LONG(property->class->pspec))
+ val = (gfloat) g_value_get_long (property->property->value);
+ else if (G_IS_PARAM_SPEC_ULONG(property->class->pspec))
+ val = (gfloat) g_value_get_ulong (property->property->value);
+ else if (G_IS_PARAM_SPEC_INT64(property->class->pspec))
+ val = (gfloat) g_value_get_int64 (property->property->value);
+ else if (G_IS_PARAM_SPEC_UINT64(property->class->pspec))
+ val = (gfloat) g_value_get_uint64 (property->property->value);
+ else if (G_IS_PARAM_SPEC_DOUBLE(property->class->pspec))
val = (gfloat) g_value_get_double (property->property->value);
- else
+ else if (G_IS_PARAM_SPEC_FLOAT(property->class->pspec))
val = g_value_get_float (property->property->value);
+ else
+ g_warning ("Unsupported type %s\n",
+ g_type_name(property->class->pspec->value_type));
gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin), val);
- g_object_set_data (G_OBJECT (spin), "user_data", property);
-}
-
-static void
-glade_editor_property_load_float (GladeEditorProperty *property)
-{
- g_return_if_fail (property != NULL);
- g_return_if_fail (property->property != NULL);
- g_return_if_fail (property->property->value != NULL);
- g_return_if_fail (property->input != NULL);
-
- glade_editor_property_load_integer (property);
-}
-static void
-glade_editor_property_load_double (GladeEditorProperty *property)
-{
- g_return_if_fail (property != NULL);
- g_return_if_fail (property->property != NULL);
- g_return_if_fail (property->property->value != NULL);
- g_return_if_fail (property->input != NULL);
-
- glade_editor_property_load_integer (property);
+ g_object_set_data (G_OBJECT (spin), "user_data", property);
}
static void
glade_editor_property_load_enum (GladeEditorProperty *property)
{
GladePropertyClass *pclass;
- GladeChoice *choice;
- GList *list;
- gint idx = 0;
+ GEnumClass *eclass;
+ gint i, value;
+ GList *list;
+
g_return_if_fail (property != NULL);
g_return_if_fail (property->property != NULL);
g_return_if_fail (property->property->value != NULL);
g_return_if_fail (property->input != NULL);
+ g_return_if_fail ((eclass = g_type_class_ref
+ (property->class->pspec->value_type)) != NULL);
pclass = property->property->class;
- list = pclass->choices;
- for (; list != NULL; list = list->next) {
- gint value = g_value_get_enum (property->property->value);
- choice = (GladeChoice *)list->data;
- if (choice->value == value)
+ value = g_value_get_enum (property->property->value);
+
+ for (i = 0; i < eclass->n_values; i++)
+ {
+ if (eclass->values[i].value == value)
break;
- idx ++;
}
-
- if (list == NULL)
- idx = 0;
-
- gtk_option_menu_set_history (GTK_OPTION_MENU (property->input), idx);
+
+ gtk_option_menu_set_history (GTK_OPTION_MENU (property->input),
+ i < eclass->n_values ? i : 0);
list = GTK_MENU_SHELL (GTK_OPTION_MENU (property->input)->menu)->children;
for (; list != NULL; list = list->next) {
GtkMenuItem *menu_item = list->data;
g_object_set_data (G_OBJECT (menu_item), "user_data", property);
}
+
+ g_type_class_unref (eclass);
}
static void
@@ -1389,17 +1349,6 @@ glade_editor_property_load_flags (GladeEditorProperty *property)
}
static void
-glade_editor_property_load_other_widgets (GladeEditorProperty *property)
-{
- g_return_if_fail (property != NULL);
- g_return_if_fail (property->property != NULL);
- g_return_if_fail (property->property->value != NULL);
- g_return_if_fail (property->input != NULL);
-
- g_warning ("Implement me (%s)!\n", G_GNUC_FUNCTION);
-}
-
-static void
glade_editor_property_load_boolean (GladeEditorProperty *property)
{
GtkWidget *label;
@@ -1484,26 +1433,6 @@ glade_editor_property_load_unichar (GladeEditorProperty *property)
g_object_set_data (G_OBJECT (property->input), "user_data", property);
}
-/* We are recursing so we need the prototype beforehand. Don't you love C ? */
-static void glade_editor_property_load (GladeEditorProperty *property, GladeWidget *widget);
-
-static void
-glade_editor_property_load_object (GladeEditorProperty *property,
- GladeWidget *widget)
-{
- GladeEditorProperty *child;
- GList *list;
-
- g_return_if_fail (property != NULL);
-
- list = property->children;
- for (; list != NULL; list = list->next) {
- child = list->data;
- glade_editor_property_load (child, widget);
- }
-
-}
-
static void
glade_editor_property_load (GladeEditorProperty *property, GladeWidget *widget)
{
@@ -1512,11 +1441,6 @@ glade_editor_property_load (GladeEditorProperty *property, GladeWidget *widget)
g_return_if_fail (GLADE_IS_EDITOR_PROPERTY (property));
g_return_if_fail (GLADE_IS_PROPERTY_CLASS (property->class));
- if (class->type == GLADE_PROPERTY_TYPE_OBJECT) {
- glade_editor_property_load_object (property, widget);
- return;
- }
-
property->property = glade_widget_get_property (widget, class->id);
g_return_if_fail (property->property != NULL);
@@ -1524,42 +1448,29 @@ glade_editor_property_load (GladeEditorProperty *property, GladeWidget *widget)
property->property->loading = TRUE;
- switch (class->type) {
- case GLADE_PROPERTY_TYPE_STRING:
+
+ if (G_IS_PARAM_SPEC_ENUM(class->pspec))
+ glade_editor_property_load_enum (property);
+ else if (G_IS_PARAM_SPEC_FLAGS(class->pspec))
+ glade_editor_property_load_flags (property);
+ else if (G_IS_PARAM_SPEC_STRING(class->pspec))
glade_editor_property_load_text (property);
- break;
- case GLADE_PROPERTY_TYPE_BOOLEAN:
+ else if (G_IS_PARAM_SPEC_BOOLEAN(class->pspec))
glade_editor_property_load_boolean (property);
- break;
- case GLADE_PROPERTY_TYPE_FLOAT:
- glade_editor_property_load_float (property);
- break;
- case GLADE_PROPERTY_TYPE_DOUBLE:
- glade_editor_property_load_double (property);
- break;
- case GLADE_PROPERTY_TYPE_INTEGER:
+ else if (G_IS_PARAM_SPEC_FLOAT(class->pspec) ||
+ G_IS_PARAM_SPEC_DOUBLE(class->pspec) ||
+ G_IS_PARAM_SPEC_INT(class->pspec) ||
+ G_IS_PARAM_SPEC_UINT(class->pspec) ||
+ G_IS_PARAM_SPEC_LONG(class->pspec) ||
+ G_IS_PARAM_SPEC_ULONG(class->pspec) ||
+ G_IS_PARAM_SPEC_INT64(class->pspec) ||
+ G_IS_PARAM_SPEC_UINT64(class->pspec))
glade_editor_property_load_integer (property);
- break;
- case GLADE_PROPERTY_TYPE_ENUM:
- glade_editor_property_load_enum (property);
- break;
- case GLADE_PROPERTY_TYPE_FLAGS:
- glade_editor_property_load_flags (property);
- break;
- case GLADE_PROPERTY_TYPE_UNICHAR:
+ else if (G_IS_PARAM_SPEC_UNICHAR(class->pspec))
glade_editor_property_load_unichar (property);
- break;
- case GLADE_PROPERTY_TYPE_OTHER_WIDGETS:
- glade_editor_property_load_other_widgets (property);
- break;
- case GLADE_PROPERTY_TYPE_ERROR:
- g_warning ("%s : type %i not implemented\n", G_GNUC_FUNCTION,
- class->type);
- break;
- default:
- g_assert_not_reached ();
- break;
- }
+ else
+ g_warning ("%s : type %s not implemented (%s)\n", __FUNCTION__,
+ class->name, g_type_name (class->pspec->value_type));
glade_editor_property_set_tooltips (property);
@@ -1733,7 +1644,7 @@ glade_editor_query_popup (GladeEditor *editor, GladeWidget *widget)
GList *list;
GladeEditorProperty *property;
- title = g_strdup_printf ("%s %s", _("Create a"), widget->widget_class->name);
+ title = g_strdup_printf (_("Create a %s"), widget->widget_class->name);
dialog = gtk_dialog_new_with_buttons
(title, NULL,
diff --git a/src/glade-editor.h b/src/glade-editor.h
index 1cc3a527..886deed0 100644
--- a/src/glade-editor.h
+++ b/src/glade-editor.h
@@ -187,12 +187,6 @@ struct _GladeEditorProperty
*/
};
-typedef enum {
- GLADE_EDITOR_INTEGER,
- GLADE_EDITOR_FLOAT,
- GLADE_EDITOR_DOUBLE,
-}GladeEditorNumericType;
-
GType glade_editor_get_type (void);
GladeEditor *glade_editor_new (void);
diff --git a/src/glade-gtk.c b/src/glade-gtk.c
index 9292424d..3e0dd4f1 100644
--- a/src/glade-gtk.c
+++ b/src/glade-gtk.c
@@ -63,6 +63,67 @@
#define FIXED_DEFAULT_CHILD_WIDTH 100
#define FIXED_DEFAULT_CHILD_HEIGHT 60
+
+
+/* ---------------------------- Custom Property definitions ------------------------ */
+static GType
+glade_gtk_stock_get_type (void)
+{
+ static GType etype = 0;
+ if (etype == 0) {
+ static const GEnumValue values[] = {
+ { 0, "None", "glade-none" },
+ { 1, "Ok", "gtk-ok" },
+ { 2, "Cancel", "gtk-cancel" },
+ { 3, "Apply", "gtk-apply" },
+ { 4, "Close", "gtk-close" },
+ { 0, NULL, NULL }
+ };
+ etype = g_enum_register_static ("GtkTtScrollType", values);
+ }
+ return etype;
+}
+
+GParamSpec *GLADEGTK_API
+glade_gtk_stock_spec (void)
+{
+ return g_param_spec_enum ("stock", "stock", "stock",
+ glade_gtk_stock_get_type (),
+ 0, G_PARAM_READWRITE);
+}
+
+GParamSpec *GLADEGTK_API
+glade_gtk_standard_int_spec (void)
+{
+ static GParamSpec *int_spec = NULL;
+ if (!int_spec)
+ int_spec = g_param_spec_int ("int", "int", "int",
+ 0, G_MAXINT,
+ 0, G_PARAM_READWRITE);
+ return int_spec;
+}
+
+GParamSpec *GLADEGTK_API
+glade_gtk_standard_string_spec (void)
+{
+ static GParamSpec *str_spec = NULL;
+ if (!str_spec)
+ str_spec = g_param_spec_string ("string", "string", "string",
+ "", G_PARAM_READWRITE);
+ return str_spec;
+}
+
+GParamSpec *GLADEGTK_API
+glade_gtk_standard_float_spec (void)
+{
+ static GParamSpec *float_spec = NULL;
+ if (!float_spec)
+ float_spec = g_param_spec_float ("float", "float", "float",
+ 0.0F, G_MAXFLOAT, 0.0F,
+ G_PARAM_READWRITE);
+ return float_spec;
+}
+
/* ------------------------------------ Custom Properties ------------------------------ */
/**
* glade_gtk_option_menu_set_items:
@@ -329,10 +390,9 @@ glade_gtk_box_set_size (GObject *object, GValue *value)
*/
for (i = 0; i < new_size; i++)
{
- if (i + 1 < g_list_length(box->children))
- continue;
- gtk_container_add (GTK_CONTAINER (box),
- GTK_WIDGET (glade_placeholder_new ()));
+ if (g_list_length(box->children) < (i + 1))
+ gtk_container_add (GTK_CONTAINER (box),
+ GTK_WIDGET (glade_placeholder_new ()));
}
/* The box has shrunk. Remove the widgets that are on those slots */
@@ -343,8 +403,7 @@ glade_gtk_box_set_size (GObject *object, GValue *value)
GtkWidget *child_widget = ((GtkBoxChild *) (child->data))->widget;
GladeWidget *glade_widget;
- glade_widget = glade_widget_get_from_gtk_widget (child_widget);
- if (glade_widget)
+ if ((glade_widget = glade_widget_get_from_gtk_widget (child_widget)) != NULL)
/* In this case, refuse to shrink */
break;
@@ -352,6 +411,26 @@ glade_gtk_box_set_size (GObject *object, GValue *value)
}
}
+gboolean GLADEGTK_API
+glade_gtk_box_verify_size (GObject *object, GValue *value)
+{
+ GtkBox *box = GTK_BOX(object);
+ GList *child;
+ gint old_size = g_list_length (box->children);
+ gint new_size = g_value_get_int (value);
+
+ for (child = g_list_last (box->children);
+ child && old_size > new_size;
+ child = g_list_previous (child), old_size--)
+ {
+ GtkWidget *widget = ((GtkBoxChild *) (child->data))->widget;
+ if (glade_widget_get_from_gtk_widget (widget) != NULL)
+ /* In this case, refuse to shrink */
+ return FALSE;
+ }
+ return TRUE;
+}
+
/**
* glade_gtk_toolbar_get_size:
* @object:
@@ -382,47 +461,53 @@ glade_gtk_toolbar_get_size (GObject *object, GValue *value)
void GLADEGTK_API
glade_gtk_toolbar_set_size (GObject *object, GValue *value)
{
- GladeWidget *widget;
- GtkToolbar *toolbar;
- gint new_size;
- gint old_size;
-
- g_return_if_fail (GTK_IS_TOOLBAR (object));
-
- toolbar = GTK_TOOLBAR (object);
- widget = glade_widget_get_from_gtk_widget (GTK_WIDGET (toolbar));
- g_return_if_fail (widget != NULL);
+ GtkToolbar *toolbar = GTK_TOOLBAR (object);
+ gint new_size = g_value_get_int (value);
+ gint old_size = toolbar->num_children;
+ GList *child;
- old_size = toolbar->num_children;
- new_size = g_value_get_int (value);
-
- if (new_size == old_size)
- return;
+ g_print ("Toolbar (set) old size: %d, new size %d\n", old_size, new_size);
+ /* Ensure base size
+ */
+ while (new_size > old_size) {
+ gtk_toolbar_append_widget (toolbar, glade_placeholder_new (), NULL, NULL);
+ old_size++;
+ }
- if (new_size > old_size) {
- while (new_size > old_size) {
- GtkWidget *placeholder = glade_placeholder_new ();
- gtk_toolbar_append_widget (toolbar, placeholder, NULL, NULL);
- old_size++;
- }
- } else {
- GList *child = g_list_last (toolbar->children);
+ for (child = g_list_last (toolbar->children);
+ child && old_size > new_size;
+ child = g_list_last (toolbar->children), old_size--)
+ {
+ GtkWidget *child_widget = ((GtkToolbarChild *) child->data)->widget;
+
+ if (glade_widget_get_from_gtk_widget (child_widget))
+ break;
- while (child && old_size > new_size) {
- GtkWidget *child_widget = ((GtkToolbarChild *) child->data)->widget;
- GladeWidget *glade_widget;
+ gtk_container_remove (GTK_CONTAINER (toolbar), child_widget);
+ }
+ g_print ("Toolbar (set) now size %d\n", toolbar->num_children);
+}
- glade_widget = glade_widget_get_from_gtk_widget (child_widget);
- if (glade_widget)
- glade_project_remove_widget
- (glade_widget->project, child_widget);
+gboolean GLADEGTK_API
+glade_gtk_toolbar_verify_size (GObject *object, GValue *value)
+{
+ GtkToolbar *toolbar = GTK_TOOLBAR (object);
+ gint new_size = g_value_get_int (value);
+ gint old_size = toolbar->num_children;
+ GList *child;
- gtk_container_remove (GTK_CONTAINER (toolbar), child_widget);
+ g_print ("Toolbar (verify) old size: %d, new size %d\n", old_size, new_size);
- child = g_list_last (toolbar->children);
- old_size--;
- }
+ for (child = g_list_last (toolbar->children);
+ child && old_size > new_size;
+ child = g_list_previous (child), old_size--)
+ {
+ GtkWidget *child_widget = ((GtkToolbarChild *) child->data)->widget;
+
+ if (glade_widget_get_from_gtk_widget (child_widget))
+ return FALSE;
}
+ return TRUE;
}
/**
@@ -457,7 +542,8 @@ glade_gtk_notebook_set_n_pages (GObject *object, GValue *value)
{
GladeWidget *widget;
GtkNotebook *notebook;
- gint new_size;
+ GtkWidget *child_widget;
+ gint new_size, i;
gint old_size;
notebook = GTK_NOTEBOOK (object);
@@ -466,51 +552,62 @@ glade_gtk_notebook_set_n_pages (GObject *object, GValue *value)
widget = glade_widget_get_from_gtk_widget (GTK_WIDGET (notebook));
g_return_if_fail (widget != NULL);
- old_size = g_list_length (notebook->children);
new_size = g_value_get_int (value);
- if (new_size == old_size)
- return;
- if (new_size > old_size) {
- /* The notebook has grown. Add a page. */
- while (new_size > old_size) {
- GladePlaceholder *placeholder =
- GLADE_PLACEHOLDER (glade_placeholder_new ());
- gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
- GTK_WIDGET (placeholder),
- NULL);
- old_size++;
- }
- } else {/* new_size < old_size */
- /* The notebook has shrunk. Remove pages */
- GladeWidget *child_gwidget;
- GtkWidget *child_widget;
-
- /*
- * Thing to remember is that GtkNotebook starts the
- * page numbers from 0, not 1 (C-style). So we need to do
- * old_size-1, where we're referring to "nth" widget.
+ /* Ensure base size of notebook */
+ for (i = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook)); i < new_size; i++)
+ {
+ gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
+ glade_placeholder_new (),
+ NULL);
+ }
+
+ old_size = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook));
+
+
+ /*
+ * Thing to remember is that GtkNotebook starts the
+ * page numbers from 0, not 1 (C-style). So we need to do
+ * old_size-1, where we're referring to "nth" widget.
+ */
+ while (old_size > new_size) {
+ /* Get the last widget. */
+ child_widget = gtk_notebook_get_nth_page (notebook, old_size-1);
+
+ /*
+ * If we got it, and its not a placeholder, remove it
+ * from project.
*/
- while (old_size > new_size) {
- /* Get the last widget. */
- child_widget = gtk_notebook_get_nth_page (notebook, old_size-1);
- child_gwidget = glade_widget_get_from_gtk_widget (child_widget);
-
- /*
- * If we got it, and its not a placeholder, remove it
- * from project.
- */
- if (child_gwidget)
- glade_project_remove_widget
- (child_gwidget->project, child_widget);
+ if (glade_widget_get_from_gtk_widget (child_widget))
+ break;
- gtk_notebook_remove_page (notebook, old_size-1);
- old_size--;
- }
+ gtk_notebook_remove_page (notebook, old_size-1);
+ old_size--;
}
}
+gboolean GLADEGTK_API
+glade_gtk_notebook_verify_n_pages (GObject *object, GValue *value)
+{
+ GtkNotebook *notebook = GTK_NOTEBOOK(object);
+ GtkWidget *child_widget;
+ gint old_size, new_size = g_value_get_int (value);
+
+ for (old_size = gtk_notebook_get_n_pages (notebook);
+ old_size > new_size; old_size--) {
+ /* Get the last widget. */
+ child_widget = gtk_notebook_get_nth_page (notebook, old_size-1);
+
+ /*
+ * If we got it, and its not a placeholder, remove it
+ * from project.
+ */
+ if (glade_widget_get_from_gtk_widget (child_widget))
+ return FALSE;
+ }
+ return TRUE;
+}
static gboolean
glade_gtk_table_has_child (GtkTable *table,
@@ -561,14 +658,14 @@ glade_gtk_table_set_n_common (GObject *object, GValue *value, gboolean for_rows)
{
GladeWidget *widget;
GtkTable *table;
- gint new_size;
- gint old_size;
+ guint new_size;
+ guint old_size;
gint i, j;
table = GTK_TABLE (object);
g_return_if_fail (GTK_IS_TABLE (table));
- new_size = g_value_get_int (value);
+ new_size = g_value_get_uint (value);
old_size = for_rows ? table->nrows : table->ncols;
if (new_size < 1)
@@ -668,6 +765,34 @@ glade_gtk_table_set_n_columns (GObject *object, GValue *value)
glade_gtk_table_set_n_common (object, value, FALSE);
}
+static gboolean
+glade_gtk_table_verify_n_common (GObject *object, GValue *value, gboolean for_rows)
+{
+ GtkTable *table = GTK_TABLE(object);
+ guint new_size = g_value_get_uint (value);
+
+ if (glade_gtk_table_widget_exceeds_bounds
+ (table,
+ for_rows ? new_size : table->nrows,
+ for_rows ? table->ncols : new_size))
+ /* Refuse to shrink if it means orphaning widgets */
+ return FALSE;
+
+ return TRUE;
+}
+
+gboolean GLADEGTK_API
+glade_gtk_table_verify_n_rows (GObject *object, GValue *value)
+{
+ return glade_gtk_table_verify_n_common (object, value, TRUE);
+}
+
+gboolean GLADEGTK_API
+glade_gtk_table_verify_n_columns (GObject *object, GValue *value)
+{
+ return glade_gtk_table_verify_n_common (object, value, FALSE);
+}
+
/**
* glade_gtk_button_set_stock:
* @object:
@@ -681,11 +806,10 @@ glade_gtk_button_set_stock (GObject *object, GValue *value)
GladeWidget *glade_widget;
GtkWidget *button;
GtkStockItem item;
- GladeChoice *choice = NULL;
GladeProperty *property;
GladeProperty *text;
- GList *list;
- gint val;
+ GEnumClass *eclass;
+ gint val, i;
val = g_value_get_enum (value);
@@ -696,23 +820,24 @@ glade_gtk_button_set_stock (GObject *object, GValue *value)
property = glade_widget_get_property (glade_widget, "stock");
text = glade_widget_get_property (glade_widget, "label");
+
+ eclass = g_type_class_ref (property->class->pspec->value_type);
g_return_if_fail (property != NULL);
g_return_if_fail (text != NULL);
- list = property->class->choices;
- for (; list; list = list->next)
+ for (i = 0; i < eclass->n_values; i++)
{
- choice = list->data;
- if (val == choice->value)
+ if (val == eclass->values[i].value)
break;
}
- g_return_if_fail (list != NULL);
+
+ g_return_if_fail (i < eclass->n_values);
if (GTK_BIN (button)->child)
gtk_container_remove (GTK_CONTAINER (button),
GTK_BIN (button)->child);
- if (!gtk_stock_lookup (choice->id, &item))
+ if (!gtk_stock_lookup (eclass->values[i].value_nick, &item))
{
GtkWidget *label;
@@ -728,7 +853,7 @@ glade_gtk_button_set_stock (GObject *object, GValue *value)
hbox = gtk_hbox_new (FALSE, 1);
label = gtk_label_new_with_mnemonic (item.label);
- image = gtk_image_new_from_stock (choice->id,
+ image = gtk_image_new_from_stock (eclass->values[i].value_nick,
GTK_ICON_SIZE_BUTTON);
gtk_label_set_mnemonic_widget (GTK_LABEL (label),
@@ -740,6 +865,8 @@ glade_gtk_button_set_stock (GObject *object, GValue *value)
gtk_widget_show_all (button);
}
+
+ g_type_class_unref (eclass);
}
/**
diff --git a/src/glade-plugin.h b/src/glade-plugin.h
index 45772a88..8dc03751 100644
--- a/src/glade-plugin.h
+++ b/src/glade-plugin.h
@@ -10,7 +10,6 @@
#include "glade-editor.h"
#include "glade-property.h"
#include "glade-property-class.h"
-#include "glade-choice.h"
#include "glade-types.h"
#endif
diff --git a/src/glade-project.c b/src/glade-project.c
index 661f5a80..b1366860 100644
--- a/src/glade-project.c
+++ b/src/glade-project.c
@@ -420,6 +420,9 @@ glade_project_remove_widget (GladeProject *project, GtkWidget *widget)
g_list_free (children);
}
+ if (glade_util_has_nodes (widget))
+ glade_util_remove_nodes (widget);
+
gwidget = glade_widget_get_from_gtk_widget (widget);
if (!gwidget)
return;
@@ -431,7 +434,8 @@ glade_project_remove_widget (GladeProject *project, GtkWidget *widget)
if (widget_l != NULL)
{
g_object_unref (widget);
- glade_project_release_widget_name (project, gwidget, glade_widget_get_name (gwidget));
+ glade_project_release_widget_name (project, gwidget,
+ glade_widget_get_name (gwidget));
project->widgets = g_list_delete_link (project->widgets, widget_l);
}
diff --git a/src/glade-property-class.c b/src/glade-property-class.c
index 40a99aa7..39a7ab93 100644
--- a/src/glade-property-class.c
+++ b/src/glade-property-class.c
@@ -29,7 +29,6 @@
#include <gmodule.h>
#include "glade.h"
-#include "glade-choice.h"
#include "glade-widget.h"
#include "glade-widget-class.h"
#include "glade-parameter.h"
@@ -38,79 +37,6 @@
#include "glade-debug.h"
/**
- * glade_property_type_str_to_enum:
- * @str: a string representation of a property type
- *
- * Returns: the #GladePropertyType described by @str, or
- * %GLADE_PROPERTY_TYPE_ERROR if we do not recognize @str
- */
-GladePropertyType
-glade_property_type_str_to_enum (const gchar *str)
-{
- if (strcmp (str, GLADE_TAG_STRING) == 0)
- return GLADE_PROPERTY_TYPE_STRING;
- if (strcmp (str, GLADE_TAG_BOOLEAN) == 0)
- return GLADE_PROPERTY_TYPE_BOOLEAN;
- if (strcmp (str, GLADE_TAG_UNICHAR) == 0)
- return GLADE_PROPERTY_TYPE_UNICHAR;
- if (strcmp (str, GLADE_TAG_FLOAT) == 0)
- return GLADE_PROPERTY_TYPE_FLOAT;
- if (strcmp (str, GLADE_TAG_INTEGER) == 0)
- return GLADE_PROPERTY_TYPE_INTEGER;
- if (strcmp (str, GLADE_TAG_ENUM) == 0)
- return GLADE_PROPERTY_TYPE_ENUM;
- if (strcmp (str, GLADE_TAG_FLAGS) == 0)
- return GLADE_PROPERTY_TYPE_FLAGS;
- if (strcmp (str, GLADE_TAG_OTHER_WIDGETS) == 0)
- return GLADE_PROPERTY_TYPE_OTHER_WIDGETS;
- if (strcmp (str, GLADE_TAG_OBJECT) == 0)
- return GLADE_PROPERTY_TYPE_OBJECT;
-
- g_warning ("Could not determine the property type from *%s*\n", str);
-
- return GLADE_PROPERTY_TYPE_ERROR;
-}
-
-/**
- * glade_property_type_enum_to_string:
- * @type: a #GladePropertyType
- *
- * Returns: a string representing @type, or %NULL if @type is
- * either not recognized or is %GLADE_PROPERTY_TYPE_ERROR
- */
-gchar *
-glade_property_type_enum_to_string (GladePropertyType type)
-{
- switch (type)
- {
- case GLADE_PROPERTY_TYPE_STRING:
- return GLADE_TAG_STRING;
- case GLADE_PROPERTY_TYPE_BOOLEAN:
- return GLADE_TAG_BOOLEAN;
- case GLADE_PROPERTY_TYPE_UNICHAR:
- return GLADE_TAG_UNICHAR;
- case GLADE_PROPERTY_TYPE_FLOAT:
- return GLADE_TAG_FLOAT;
- case GLADE_PROPERTY_TYPE_INTEGER:
- return GLADE_TAG_INTEGER;
- case GLADE_PROPERTY_TYPE_DOUBLE:
- return GLADE_TAG_DOUBLE;
- case GLADE_PROPERTY_TYPE_ENUM:
- return GLADE_TAG_ENUM;
- case GLADE_PROPERTY_TYPE_FLAGS:
- return GLADE_TAG_FLAGS;
- case GLADE_PROPERTY_TYPE_OTHER_WIDGETS:
- return GLADE_TAG_OTHER_WIDGETS;
- case GLADE_PROPERTY_TYPE_OBJECT:
- return GLADE_TAG_OBJECT;
- case GLADE_PROPERTY_TYPE_ERROR:
- return NULL;
- }
-
- return NULL;
-}
-
-/**
* glade_property_class_new:
*
* Returns: a new #GladePropertyClass
@@ -121,13 +47,11 @@ glade_property_class_new (void)
GladePropertyClass *property_class;
property_class = g_new0 (GladePropertyClass, 1);
- property_class->type = GLADE_PROPERTY_TYPE_ERROR;
+ property_class->pspec = NULL;
property_class->id = NULL;
property_class->name = NULL;
property_class->tooltip = NULL;
property_class->parameters = NULL;
- property_class->choices = NULL;
- property_class->enum_type = 0;
property_class->optional = FALSE;
property_class->optional_default = TRUE;
property_class->common = FALSE;
@@ -155,6 +79,8 @@ glade_property_class_clone (GladePropertyClass *property_class)
clone = g_new0 (GladePropertyClass, 1);
memcpy (clone, property_class, sizeof(GladePropertyClass));
+
+ clone->pspec = property_class->pspec;
clone->id = g_strdup (clone->id);
clone->name = g_strdup (clone->name);
clone->tooltip = g_strdup (clone->tooltip);
@@ -162,7 +88,7 @@ glade_property_class_clone (GladePropertyClass *property_class)
if (G_IS_VALUE (property_class->def))
{
clone->def = g_new0 (GValue, 1);
- g_value_init (clone->def, G_VALUE_TYPE (property_class->def));
+ g_value_init (clone->def, property_class->pspec->value_type);
g_value_copy (property_class->def, clone->def);
}
@@ -172,24 +98,13 @@ glade_property_class_clone (GladePropertyClass *property_class)
clone->parameters = g_list_copy (clone->parameters);
- for (parameter = clone->parameters; parameter != NULL; parameter = parameter->next)
- parameter->data = glade_parameter_clone ((GladeParameter*) parameter->data);
+ for (parameter = clone->parameters;
+ parameter != NULL;
+ parameter = parameter->next)
+ parameter->data =
+ glade_parameter_clone ((GladeParameter*) parameter->data);
}
- if (clone->choices)
- {
- GList *choice;
-
- clone->choices = g_list_copy (clone->choices);
-
- for (choice = clone->choices; choice != NULL; choice = choice->next)
- choice->data = glade_choice_clone ((GladeChoice*) choice->data);
- }
-
- /* ok, wtf? what is the child member for? */
- /* if (clone->child)
- clone->child = glade_widget_class_clone (clone->child); */
-
return clone;
}
@@ -218,108 +133,68 @@ glade_property_class_free (GladePropertyClass *class)
}
g_list_foreach (class->parameters, (GFunc) glade_parameter_free, NULL);
g_list_free (class->parameters);
- g_list_foreach (class->choices, (GFunc) glade_choice_free, NULL);
- g_list_free (class->choices);
- glade_widget_class_free (class->child);
g_free (class);
}
-static GladePropertyType
-glade_property_class_get_type_from_spec (GParamSpec *spec)
-{
- if (G_IS_PARAM_SPEC_INT (spec) || G_IS_PARAM_SPEC_UINT (spec)) {
- return GLADE_PROPERTY_TYPE_INTEGER;
- } else if (G_IS_PARAM_SPEC_FLOAT (spec)) {
- return GLADE_PROPERTY_TYPE_FLOAT;
- } else if (G_IS_PARAM_SPEC_BOOLEAN (spec)) {
- return GLADE_PROPERTY_TYPE_BOOLEAN;
- } else if (G_IS_PARAM_SPEC_UNICHAR (spec)) {
- return GLADE_PROPERTY_TYPE_UNICHAR;
- } else if (G_IS_PARAM_SPEC_STRING (spec)) {
- /* FIXME: We should solve the "name" conflict with a better solution */
- if (!g_ascii_strcasecmp ( spec->name, "name"))
- return GLADE_PROPERTY_TYPE_ERROR;
- else
- return GLADE_PROPERTY_TYPE_STRING;
- } else if (G_IS_PARAM_SPEC_ENUM (spec)) {
- return GLADE_PROPERTY_TYPE_ENUM;
- } else if (G_IS_PARAM_SPEC_FLAGS (spec)) {
- return GLADE_PROPERTY_TYPE_FLAGS;
- } else if (G_IS_PARAM_SPEC_DOUBLE (spec)) {
- return GLADE_PROPERTY_TYPE_DOUBLE;
- } else if (G_IS_PARAM_SPEC_LONG (spec)) {
- g_warning ("Long not implemented\n");
- } else if (G_IS_PARAM_SPEC_UCHAR (spec)) {
- g_warning ("uchar not implemented\n");
- } else if (G_IS_PARAM_SPEC_OBJECT (spec)) {
- return GLADE_PROPERTY_TYPE_OBJECT;
- } else if (G_IS_PARAM_SPEC_BOXED (spec)) {
- /* FIXME: Implement at least the special case of when the boxed type is GdkColor */
- return GLADE_PROPERTY_TYPE_ERROR;
- } else {
- /* FIXME: We should implement the "events" property */
- if (g_ascii_strcasecmp (spec->name, "user-data")) {
- g_warning ("Could not determine GladePropertyType from spec (%s) (%s)",
- G_PARAM_SPEC_TYPE_NAME (spec), g_type_name (G_PARAM_SPEC_VALUE_TYPE (spec)));
- }
- }
-
- return GLADE_PROPERTY_TYPE_ERROR;
-}
static GValue *
glade_property_class_get_default_from_spec (GParamSpec *spec,
GladePropertyClass *class)
{
GValue *value;
-
value = g_new0 (GValue, 1);
+ g_value_init (value, spec->value_type);
+ g_param_value_set_default (spec, value);
+ return value;
+}
- switch (class->type) {
- case GLADE_PROPERTY_TYPE_ENUM:
- g_value_init (value, spec->value_type);
- g_value_set_enum (value, G_PARAM_SPEC_ENUM (spec)->default_value);
- break;
- case GLADE_PROPERTY_TYPE_FLAGS:
- g_value_init (value, spec->value_type);
- g_value_set_flags (value, G_PARAM_SPEC_FLAGS (spec)->default_value);
- break;
- case GLADE_PROPERTY_TYPE_STRING:
- g_value_init (value, G_TYPE_STRING);
- g_value_set_string (value, G_PARAM_SPEC_STRING (spec)->default_value);
- break;
- case GLADE_PROPERTY_TYPE_INTEGER:
- g_value_init (value, G_TYPE_INT);
- if (G_IS_PARAM_SPEC_INT (spec))
- g_value_set_int (value, G_PARAM_SPEC_INT (spec)->default_value);
- else
- g_value_set_int (value, G_PARAM_SPEC_UINT (spec)->default_value);
- break;
- case GLADE_PROPERTY_TYPE_FLOAT:
- g_value_init (value, G_TYPE_FLOAT);
- g_value_set_float (value, G_PARAM_SPEC_FLOAT (spec)->default_value);
- break;
- case GLADE_PROPERTY_TYPE_DOUBLE:
- g_value_init (value, G_TYPE_DOUBLE);
- g_value_set_double (value, G_PARAM_SPEC_DOUBLE (spec)->default_value);
- break;
- case GLADE_PROPERTY_TYPE_BOOLEAN:
- g_value_init (value, G_TYPE_BOOLEAN);
- g_value_set_boolean (value, G_PARAM_SPEC_BOOLEAN (spec)->default_value);
- break;
- case GLADE_PROPERTY_TYPE_UNICHAR:
- g_value_init (value, G_TYPE_UINT);
- g_value_set_uint (value, G_PARAM_SPEC_UNICHAR (spec)->default_value);
- break;
- case GLADE_PROPERTY_TYPE_OTHER_WIDGETS:
- break;
- case GLADE_PROPERTY_TYPE_OBJECT:
- break;
- case GLADE_PROPERTY_TYPE_ERROR:
- break;
+
+static gchar *
+glade_property_class_make_string_from_enum (GType etype, gint eval)
+{
+ GEnumClass *eclass;
+ gchar *string = NULL;
+ gint i;
+
+ g_return_val_if_fail ((eclass = g_type_class_ref (etype)) != NULL, NULL);
+ for (i = 0; i < eclass->n_values; i++)
+ {
+ if (eval == eclass->values[i].value)
+ {
+ string = g_strdup (eclass->values[i].value_name);
+ break;
+ }
}
+ g_type_class_unref (eclass);
+ return string;
+}
- return value;
+static gchar *
+glade_property_class_make_string_from_flags (GType ftype, guint fval)
+{
+ GFlagsClass *fclass;
+ gchar *string = NULL;
+ gint i;
+ g_return_val_if_fail ((fclass = g_type_class_ref (ftype)) != NULL, NULL);
+
+ for (i = 0; i < fclass->n_values; i++)
+ {
+ if (fval & fclass->values[i].value)
+ {
+ if (!string)
+ string = g_strdup (fclass->values[i].value_name);
+ else
+ {
+ gchar *newstr =
+ g_strconcat (string, "|",
+ fclass->values[i].value_name,
+ NULL);
+ string = (g_free (string), newstr);
+ }
+ }
+ }
+ g_type_class_unref (fclass);
+ return string;
}
/**
@@ -336,64 +211,62 @@ glade_property_class_make_string_from_gvalue (GladePropertyClass *property_class
const GValue *value)
{
gchar *string = NULL;
- GladePropertyType type = property_class->type;
- switch (type) {
- case GLADE_PROPERTY_TYPE_INTEGER:
+ if (G_IS_PARAM_SPEC_ENUM(property_class->pspec))
+ {
+ gint eval = g_value_get_enum (value);
+ string = glade_property_class_make_string_from_enum
+ (property_class->pspec->value_type, eval);
+ }
+ else if (G_IS_PARAM_SPEC_FLAGS(property_class->pspec))
+ {
+ guint flags = g_value_get_flags (value);
+ string = glade_property_class_make_string_from_flags
+ (property_class->pspec->value_type, flags);
+ }
+ else if (G_IS_PARAM_SPEC_INT(property_class->pspec))
string = g_strdup_printf ("%d", g_value_get_int (value));
- break;
- case GLADE_PROPERTY_TYPE_FLOAT:
+ else if (G_IS_PARAM_SPEC_UINT(property_class->pspec))
+ string = g_strdup_printf ("%u", g_value_get_uint (value));
+ else if (G_IS_PARAM_SPEC_LONG(property_class->pspec))
+ string = g_strdup_printf ("%ld", g_value_get_long (value));
+ else if (G_IS_PARAM_SPEC_ULONG(property_class->pspec))
+ string = g_strdup_printf ("%lu", g_value_get_ulong (value));
+ else if (G_IS_PARAM_SPEC_INT64(property_class->pspec))
+ string = g_strdup_printf ("%lld", g_value_get_int64 (value));
+ else if (G_IS_PARAM_SPEC_UINT64(property_class->pspec))
+ string = g_strdup_printf ("%llu", g_value_get_uint64 (value));
+ else if (G_IS_PARAM_SPEC_FLOAT(property_class->pspec))
string = g_strdup_printf ("%f", g_value_get_float (value));
- break;
- case GLADE_PROPERTY_TYPE_DOUBLE:
+ else if (G_IS_PARAM_SPEC_DOUBLE(property_class->pspec))
string = g_strdup_printf ("%g", g_value_get_double (value));
- break;
- case GLADE_PROPERTY_TYPE_BOOLEAN:
- string = g_strdup_printf ("%s", g_value_get_boolean (value) ?
- GLADE_TAG_TRUE : GLADE_TAG_FALSE);
- break;
- case GLADE_PROPERTY_TYPE_UNICHAR:
+ else if (G_IS_PARAM_SPEC_STRING(property_class->pspec))
+ string = g_value_dup_string (value);
+ else if (G_IS_PARAM_SPEC_CHAR(property_class->pspec))
+ string = g_strdup_printf ("%c", g_value_get_char (value));
+ else if (G_IS_PARAM_SPEC_UCHAR(property_class->pspec))
+ string = g_strdup_printf ("%c", g_value_get_uchar (value));
+ else if (G_IS_PARAM_SPEC_UNICHAR(property_class->pspec))
+ {
string = g_malloc (7);
g_unichar_to_utf8 (g_value_get_uint (value), string);
*g_utf8_next_char(string) = '\0';
- break;
- case GLADE_PROPERTY_TYPE_STRING:
- string = g_strdup (g_value_get_string (value));
- break;
- case GLADE_PROPERTY_TYPE_ENUM:
- {
- GList *list;
- GladeChoice *choice;
-
- list = g_list_nth (property_class->choices, g_value_get_enum (value));
- if (list != NULL) {
- choice = (GladeChoice *) list->data;
- string = g_strdup (choice->id);
- } else {
- g_warning ("Could not found choice #%d\n", g_value_get_enum (value));
- }
- }
- break;
- case GLADE_PROPERTY_TYPE_FLAGS:
- {
- GValue tmp_value = { 0, };
-
- g_value_init (&tmp_value, G_TYPE_STRING);
- g_value_transform (value, &tmp_value);
- string = g_strescape (g_value_get_string (&tmp_value),
- NULL);
- g_value_unset (&tmp_value);
- }
- break;
- default:
- g_warning ("Could not make string from gvalue for type %s\n",
- glade_property_type_enum_to_string (type));
}
+ else if (G_IS_PARAM_SPEC_BOOLEAN(property_class->pspec))
+ string = g_strdup_printf ("%s", g_value_get_boolean (value) ?
+ GLADE_TAG_TRUE : GLADE_TAG_FALSE);
+ else
+ g_critical ("Unsupported pspec type %s",
+ g_type_name(property_class->pspec->value_type));
return string;
}
-/* This is copied exactly from libglade. I've just renamed the function. */
+/* This is copied exactly from libglade. I've just renamed the function.
+ *
+ * TODO: Expose function from libglade and use the one in libglade (once
+ * Ivan Wongs libglade patch gets in...).
+ */
static guint
glade_property_class_make_flags_from_string (GType type, const char *string)
{
@@ -472,6 +345,34 @@ glade_property_class_make_flags_from_string (GType type, const char *string)
return ret;
}
+/* This is copied exactly from libglade. I've just renamed the function.
+ *
+ * TODO: Expose function from libglade and use the one in libglade (once
+ * Ivan Wongs libglade patch gets in...).
+ */
+static gint
+glade_property_class_make_enum_from_string (GType type, const char *string)
+{
+ GEnumClass *eclass;
+ GEnumValue *ev;
+ gchar *endptr;
+ gint ret = 0;
+
+ ret = strtoul(string, &endptr, 0);
+ if (endptr != string) /* parsed a number */
+ return ret;
+
+ eclass = g_type_class_ref(type);
+ ev = g_enum_get_value_by_name(eclass, string);
+ if (!ev) ev = g_enum_get_value_by_nick(eclass, string);
+ if (ev) ret = ev->value;
+
+ g_type_class_unref(eclass);
+
+ return ret;
+}
+
+
/**
* glade_property_class_make_gvalue_from_string:
* @property_class:
@@ -486,150 +387,58 @@ glade_property_class_make_gvalue_from_string (GladePropertyClass *property_class
const gchar *string)
{
GValue *value = g_new0 (GValue, 1);
- GladePropertyType type = property_class->type;
-
- switch (type) {
- case GLADE_PROPERTY_TYPE_INTEGER:
- g_value_init (value, G_TYPE_INT);
+
+ g_value_init (value, property_class->pspec->value_type);
+
+ if (G_IS_PARAM_SPEC_ENUM(property_class->pspec))
+ {
+ gint eval = glade_property_class_make_enum_from_string
+ (property_class->pspec->value_type, string);
+ g_value_set_enum (value, eval);
+ }
+ else if (G_IS_PARAM_SPEC_FLAGS(property_class->pspec))
+ {
+ guint flags = glade_property_class_make_flags_from_string
+ (property_class->pspec->value_type, string);
+ g_value_set_flags (value, flags);
+ }
+ else if (G_IS_PARAM_SPEC_INT(property_class->pspec))
g_value_set_int (value, atoi (string));
- break;
- case GLADE_PROPERTY_TYPE_FLOAT:
- g_value_init (value, G_TYPE_FLOAT);
+ else if (G_IS_PARAM_SPEC_UINT(property_class->pspec))
+ g_value_set_uint (value, atoi (string));
+ else if (G_IS_PARAM_SPEC_LONG(property_class->pspec))
+ g_value_set_long (value, strtol (string, NULL, 10));
+ else if (G_IS_PARAM_SPEC_ULONG(property_class->pspec))
+ g_value_set_ulong (value, strtoul (string, NULL, 10));
+ else if (G_IS_PARAM_SPEC_INT64(property_class->pspec))
+ g_value_set_int64 (value, strtoll (string, NULL, 10));
+ else if (G_IS_PARAM_SPEC_UINT64(property_class->pspec))
+ g_value_set_uint64 (value, strtoull (string, NULL, 10));
+ else if (G_IS_PARAM_SPEC_FLOAT(property_class->pspec))
g_value_set_float (value, (float) atof (string));
- break;
- case GLADE_PROPERTY_TYPE_BOOLEAN:
- g_value_init (value, G_TYPE_BOOLEAN);
+ else if (G_IS_PARAM_SPEC_DOUBLE(property_class->pspec))
+ g_value_set_double (value, (float) atof (string));
+ else if (G_IS_PARAM_SPEC_STRING(property_class->pspec))
+ g_value_set_string (value, string);
+ else if (G_IS_PARAM_SPEC_CHAR(property_class->pspec))
+ g_value_set_char (value, string[0]);
+ else if (G_IS_PARAM_SPEC_UCHAR(property_class->pspec))
+ g_value_set_uchar (value, string[0]);
+ else if (G_IS_PARAM_SPEC_UNICHAR(property_class->pspec))
+ g_value_set_uint (value, g_utf8_get_char (string));
+ else if (G_IS_PARAM_SPEC_BOOLEAN(property_class->pspec))
+ {
if (strcmp (string, GLADE_TAG_TRUE) == 0)
g_value_set_boolean (value, TRUE);
else
g_value_set_boolean (value, FALSE);
- break;
- case GLADE_PROPERTY_TYPE_UNICHAR:
- g_value_init (value, G_TYPE_UINT);
- g_value_set_uint (value, g_utf8_get_char (string));
- break;
- case GLADE_PROPERTY_TYPE_DOUBLE:
- g_value_init (value, G_TYPE_DOUBLE);
- g_value_set_double (value, atof (string));
- break;
- case GLADE_PROPERTY_TYPE_STRING:
- g_value_init (value, G_TYPE_STRING);
- g_value_set_string (value, string);
- break;
- case GLADE_PROPERTY_TYPE_ENUM:
- {
- GList *list;
- GladeChoice *choice;
- gint i = 0;
- gboolean found = FALSE;
-
- list = g_list_first (property_class->choices);
- while (list != NULL && !found) {
- choice = (GladeChoice *) list->data;
- if (!g_ascii_strcasecmp (string, choice->id)) {
- g_value_init (value, property_class->enum_type);
- g_value_set_enum (value, i);
- found = TRUE;
- }
-
- list = g_list_next (list);
- i++;
- }
- if (!found) {
- g_warning ("Could not found choice for %s\n", string);
- g_free (value);
- value = NULL;
- }
- }
- break;
- case GLADE_PROPERTY_TYPE_FLAGS:
- {
- guint flags;
-
- g_value_init (value, property_class->enum_type);
- flags = glade_property_class_make_flags_from_string (property_class->enum_type, string);
- g_value_set_flags (value, flags);
- }
- case GLADE_PROPERTY_TYPE_OBJECT:
- break;
- default: {
- const char *typestr = glade_property_type_enum_to_string (type);
- g_warning ("Could not make gvalue from string ->%s<- and type %s\n",
- string ? string : "(null)",
- typestr ? typestr : "(null)");
- g_free (value);
- value = NULL;
- }
}
-
- return value;
-}
-
-static gchar *
-glade_property_get_parameter_numeric_min (GParamSpec *spec)
-{
- gchar *value = NULL;
-
- if (G_IS_PARAM_SPEC_INT (spec))
- value = g_strdup_printf ("%d", G_PARAM_SPEC_INT (spec)->minimum);
- else if (G_IS_PARAM_SPEC_UINT (spec))
- value = g_strdup_printf ("%u", G_PARAM_SPEC_UINT (spec)->minimum);
- else if (G_IS_PARAM_SPEC_FLOAT (spec))
- value = g_strdup_printf ("%g", G_PARAM_SPEC_FLOAT (spec)->minimum);
- else if (G_IS_PARAM_SPEC_DOUBLE (spec))
- value = g_strdup_printf ("%g", G_PARAM_SPEC_DOUBLE (spec)->minimum);
else
- g_warning ("glade_propery_get_parameter_numeric_item invalid ParamSpec (min)\n");
-
+ g_critical ("Unsupported pspec type %s",
+ g_type_name(property_class->pspec->value_type));
return value;
}
-static gchar *
-glade_property_get_parameter_numeric_max (GParamSpec *spec)
-{
- gchar *value = NULL;
-
- if (G_IS_PARAM_SPEC_INT (spec))
- value = g_strdup_printf ("%d", G_PARAM_SPEC_INT (spec)->maximum);
- else if (G_IS_PARAM_SPEC_UINT (spec))
- value = g_strdup_printf ("%u", G_PARAM_SPEC_UINT (spec)->maximum);
- else if (G_IS_PARAM_SPEC_FLOAT (spec))
- value = g_strdup_printf ("%g", G_PARAM_SPEC_FLOAT (spec)->maximum);
- else if (G_IS_PARAM_SPEC_DOUBLE (spec))
- value = g_strdup_printf ("%g", G_PARAM_SPEC_DOUBLE (spec)->maximum);
- else
- g_warning ("glade_propery_get_parameter_numeric_item invalid ParamSpec (max)\n");
-
- return value;
-}
-
-static GList *
-glade_property_get_parameters_numeric (GParamSpec *spec,
- GladePropertyClass *class)
-{
- GladeParameter *parameter;
- GList *list = NULL;
-
- g_return_val_if_fail (G_IS_PARAM_SPEC_INT (spec) |
- G_IS_PARAM_SPEC_UINT (spec) |
- G_IS_PARAM_SPEC_FLOAT (spec) |
- G_IS_PARAM_SPEC_DOUBLE (spec), NULL);
-
- /* Get the min value */
- parameter = glade_parameter_new ();
- parameter->key = g_strdup ("Min");
- parameter->value = glade_property_get_parameter_numeric_min (spec);
- list = g_list_prepend (list, parameter);
-
- /* Get the max value */
- parameter = glade_parameter_new ();
- parameter->key = g_strdup ("Max");
- parameter->value = glade_property_get_parameter_numeric_max (spec);
- list = g_list_prepend (list, parameter);
-
- return list;
-}
-
/**
* glade_property_class_new_from_spec:
* @spec:
@@ -645,11 +454,14 @@ glade_property_class_new_from_spec (GParamSpec *spec)
property_class = glade_property_class_new ();
- property_class->type = glade_property_class_get_type_from_spec (spec);
- if (property_class->type == GLADE_PROPERTY_TYPE_ERROR)
- /* no warnings, there are properties that we don't edit */
- goto lblError;
+ property_class->pspec = spec;
+ /* We dont edit objects or pointers as properties.
+ */
+ if (G_IS_PARAM_SPEC_OBJECT(property_class->pspec) ||
+ G_IS_PARAM_SPEC_POINTER(property_class->pspec))
+ goto lblError;
+
property_class->id = g_strdup (spec->name);
property_class->name = g_strdup (g_param_spec_get_nick (spec));
if (!property_class->id || !property_class->name)
@@ -661,38 +473,9 @@ glade_property_class_new_from_spec (GParamSpec *spec)
property_class->tooltip = g_strdup (g_param_spec_get_blurb (spec));
property_class->def = glade_property_class_get_default_from_spec (spec, property_class);
- switch (property_class->type)
- {
- case GLADE_PROPERTY_TYPE_ENUM:
- property_class->choices = glade_choice_list_new_from_spec (spec);
- property_class->enum_type = spec->value_type;
- break;
- case GLADE_PROPERTY_TYPE_FLAGS:
- property_class->enum_type = spec->value_type;
- break;
- case GLADE_PROPERTY_TYPE_STRING:
- break;
- case GLADE_PROPERTY_TYPE_INTEGER:
- case GLADE_PROPERTY_TYPE_FLOAT:
- case GLADE_PROPERTY_TYPE_DOUBLE:
- property_class->parameters = glade_property_get_parameters_numeric (spec, property_class);
- break;
- case GLADE_PROPERTY_TYPE_BOOLEAN:
- break;
- case GLADE_PROPERTY_TYPE_UNICHAR:
- break;
- case GLADE_PROPERTY_TYPE_OTHER_WIDGETS:
- break;
- case GLADE_PROPERTY_TYPE_OBJECT:
-// break;
- goto lblError; /* we don't support this */
- case GLADE_PROPERTY_TYPE_ERROR:
- break;
- }
-
return property_class;
-lblError:
+ lblError:
glade_property_class_free (property_class);
return NULL;
}
@@ -715,6 +498,7 @@ glade_property_class_is_visible (GladePropertyClass *property_class, GladeWidget
return TRUE;
}
+
/**
* glade_property_class_update_from_node:
* @node: the <property> node
@@ -778,16 +562,12 @@ glade_property_class_update_from_node (GladeXmlNode *node,
class->name = buff;
}
- /* ...the type... */
- buff = glade_xml_get_value_string (node, GLADE_TAG_TYPE);
+ /* ...the spec... */
+ buff = glade_xml_get_value_string (node, GLADE_TAG_SPEC);
if (buff)
{
- GladePropertyType type;
- type = glade_property_type_str_to_enum (buff);
- g_free (buff);
- if (type == GLADE_PROPERTY_TYPE_ERROR)
- return FALSE;
- class->type = type;
+ class->pspec = glade_utils_get_pspec_from_funcname (buff);
+ g_free (buff);
}
/* ...and the tooltip */
@@ -803,39 +583,7 @@ glade_property_class_update_from_node (GladeXmlNode *node,
if (child)
class->parameters = glade_parameter_list_new_from_node (class->parameters, child);
glade_parameter_get_boolean (class->parameters, "Optional", &class->optional);
-
- /* Get the choices */
- do
- {
- if (class->type == GLADE_PROPERTY_TYPE_ENUM)
- {
- gchar *type_name;
- GType type;
-
- child = glade_xml_search_child (node, GLADE_TAG_ENUMS);
- if (!child)
- break;
- class->choices = glade_choice_list_new_from_node (child);
- type_name = glade_xml_get_property_string (child, "EnumType");
- if (!type_name)
- break;
- type = g_type_from_name (type_name);
- g_free (type_name);
- if (!(type != 0))
- break;
- class->enum_type = type;
- }
- }
- while (FALSE);
-#if 0
- /* If the property is an object load it */
- if (class->type == GLADE_PROPERTY_TYPE_OBJECT) {
- child = glade_xml_search_child (node, GLADE_TAG_GLADE_WIDGET_CLASS);
- if (child)
- class->child = glade_widget_class_new_from_node (child);
- }
-#endif
/* Get the default */
buff = glade_xml_get_property_string (node, GLADE_TAG_DEFAULT);
if (buff)
@@ -858,7 +606,8 @@ glade_property_class_update_from_node (GladeXmlNode *node,
class->query = glade_xml_get_property_boolean (node, GLADE_TAG_QUERY, FALSE);
if (class->optional)
- class->optional_default = glade_xml_get_property_boolean (node, GLADE_TAG_OPTIONAL_DEFAULT, FALSE);
+ class->optional_default =
+ glade_xml_get_property_boolean (node, GLADE_TAG_OPTIONAL_DEFAULT, FALSE);
/* If this property can't be set with g_object_set, get the work around
* function
@@ -875,13 +624,18 @@ glade_property_class_update_from_node (GladeXmlNode *node,
gchar *symbol_name = glade_xml_get_content (child);
if (!widget_class->module)
- g_warning (_("The property [%s] of the widget's class [%s] needs a special \"set\" function, but there is no library associated to this widget's class."),
+ g_warning (_("The property [%s] of the widget's class [%s] "
+ "needs a special \"set\" function, but there is "
+ "no library associated to this widget's class."),
class->name, widget_class->name);
- if (!g_module_symbol (widget_class->module, symbol_name, (gpointer *) &class->set_function))
- g_warning (_("Unable to get the \"set\" function [%s] of the property [%s] of the widget's class [%s] from the module [%s]: %s"),
- symbol_name, class->name, widget_class->name, g_module_name (widget_class->module), g_module_error ());
-
+ if (!g_module_symbol (widget_class->module, symbol_name, (gpointer *)
+ &class->set_function))
+ g_warning (_("Unable to get the \"set\" function [%s] of the "
+ "property [%s] of the widget's class [%s] from "
+ "the module [%s]: %s"),
+ symbol_name, class->name, widget_class->name,
+ g_module_name (widget_class->module), g_module_error ());
g_free (symbol_name);
}
@@ -894,13 +648,39 @@ glade_property_class_update_from_node (GladeXmlNode *node,
gchar *symbol_name = glade_xml_get_content (child);
if (!widget_class->module)
- g_warning (_("The property [%s] of the widget's class [%s] needs a special \"get\" function, but there is no library associated to this widget's class."),
+ g_warning (_("The property [%s] of the widget's class [%s] needs a "
+ "special \"get\" function, but there is no library "
+ "associated to this widget's class."),
class->name, widget_class->name);
- if (!g_module_symbol(widget_class->module, symbol_name, (gpointer *) &class->get_function))
- g_warning (_("Unable to get the \"get\" function [%s] of the property [%s] of the widget's class [%s] from the module [%s]: %s"),
- symbol_name, class->name, widget_class->name, g_module_name (widget_class->module), g_module_error ());
+ if (!g_module_symbol(widget_class->module, symbol_name,
+ (gpointer *) &class->get_function))
+ g_warning (_("Unable to get the \"get\" function [%s] of the "
+ "property [%s] of the widget's class [%s] from the "
+ "module [%s]: %s"),
+ symbol_name, class->name, widget_class->name,
+ g_module_name (widget_class->module), g_module_error ());
+ g_free (symbol_name);
+ }
+
+ child = glade_xml_search_child (node, GLADE_TAG_VERIFY_FUNCTION);
+ if (child)
+ {
+ gchar *symbol_name = glade_xml_get_content (child);
+
+ if (!widget_class->module)
+ g_warning (_("The property [%s] of the widget's class [%s] needs a "
+ "special \"get\" function, but there is no library "
+ "associated to this widget's class."),
+ class->name, widget_class->name);
+ if (!g_module_symbol(widget_class->module, symbol_name,
+ (gpointer *) &class->verify_function))
+ g_warning (_("Unable to get the \"verify\" function [%s] of the "
+ "property [%s] of the widget's class [%s] from the "
+ "module [%s]: %s"),
+ symbol_name, class->name, widget_class->name,
+ g_module_name (widget_class->module), g_module_error ());
g_free (symbol_name);
}
diff --git a/src/glade-property-class.h b/src/glade-property-class.h
index ce9d58f3..a5014d30 100644
--- a/src/glade-property-class.h
+++ b/src/glade-property-class.h
@@ -4,21 +4,6 @@
G_BEGIN_DECLS
-
-typedef enum {
- GLADE_PROPERTY_TYPE_BOOLEAN,
- GLADE_PROPERTY_TYPE_FLOAT,
- GLADE_PROPERTY_TYPE_INTEGER,
- GLADE_PROPERTY_TYPE_DOUBLE,
- GLADE_PROPERTY_TYPE_STRING,
- GLADE_PROPERTY_TYPE_UNICHAR,
- GLADE_PROPERTY_TYPE_ENUM,
- GLADE_PROPERTY_TYPE_FLAGS,
- GLADE_PROPERTY_TYPE_OTHER_WIDGETS,
- GLADE_PROPERTY_TYPE_OBJECT,
- GLADE_PROPERTY_TYPE_ERROR
-} GladePropertyType;
-
/* The GladeProperty object describes a settable parameter of a widget.
* All entries that the user can change in the first page of the GladeEditor
* make are a GladeProperty (except for the widget name)
@@ -104,8 +89,8 @@ typedef enum {
struct _GladePropertyClass
{
- GladePropertyType type; /* The type of property from GladePropertyType
- */
+ GParamSpec *pspec; /* The Parameter Specification for this property.
+ */
gchar *id; /* The id of the property. Like "label" or "xpad"
* this is a non-translatable string
@@ -128,16 +113,6 @@ struct _GladePropertyClass
* for a type == CHOICE
*/
- GList *choices; /* list of GladeChoice items. This is only used
- * for propeties of type GLADE_PROPERTY_TYPE_CHOICE
- * and is NULL for other poperties.
- * [See glade-choice.h]
- */
-
- GType enum_type; /* If it is GLADE_PROPERTY_TYPE_ENUM or
- * GLADE_PROPERTY_TYPE_FLAGS, this holds
- * the GType of the enum or flags, otherwise it's 0.
- */
gboolean query; /* Whether we should explicitly ask the user about this property
* when instantiating a widget with this property (through a popup
* dialog).
@@ -152,24 +127,22 @@ struct _GladePropertyClass
gboolean optional_default; /* For optional values, what the default is */
gboolean construct_only; /* Whether this property is G_PARAM_CONSTRUCT_ONLY or not */
-
- GladeWidgetClass *child; /* A GladeWidgetClass pointer of objects
- * that we need to set for this widget
- * for example : GtkSpinButton has a Adjustment inside
- * a GtkCombo has an entry inside and a GtkClist which
- * makes a drop dowm menu. This is only valid with
- * the type is object.
- */
-
gboolean common; /* Common properties go in the common tab */
gboolean packing; /* Packing properties go in the packing tab */
gboolean is_modified; /* If true, this property_class has been "modified" from the
* the standard property by a xml file. */
+ gboolean (*verify_function) (GObject *object,
+ const GValue *value);
+ /* Delagate to verify if this is a valid value for this property,
+ * if this function exists and returns FALSE, then glade_property_set
+ * will abort before making any changes
+ */
+
void (*set_function) (GObject *object,
const GValue *value);
- /* If this property can't be set with g_object_set then
+ /* If this property can't be set with g_object_set then
* we need to implement it inside glade. This is a pointer
* to the function that can set this property. The functions
* to work arround these problems are inside glade-gtk.c
@@ -192,8 +165,6 @@ void glade_property_class_free (GladePropertyClass *property_class);
gboolean glade_property_class_is_visible (GladePropertyClass *property_class, GladeWidgetClass *widget_class);
-gchar * glade_property_type_enum_to_string (GladePropertyType type);
-
GValue * glade_property_class_make_gvalue_from_string (GladePropertyClass *property_class,
const gchar *string);
gchar * glade_property_class_make_string_from_gvalue (GladePropertyClass *property_class,
diff --git a/src/glade-property.c b/src/glade-property.c
index 948c351a..43941b5d 100644
--- a/src/glade-property.c
+++ b/src/glade-property.c
@@ -25,7 +25,6 @@
#include <string.h>
#include "glade.h"
-#include "glade-choice.h"
#include "glade-widget.h"
#include "glade-property.h"
#include "glade-property-class.h"
@@ -56,16 +55,6 @@ glade_property_new (GladePropertyClass *class, GladeWidget *widget)
property->widget = widget;
property->value = g_new0 (GValue, 1);
property->enabled = TRUE;
-#if 0
- property->child = NULL;
-
- if (class->type == GLADE_PROPERTY_TYPE_OBJECT) {
- property->child = glade_widget_new_from_class (class->child,
- widget->project,
- widget);
- return property;
- }
-#endif
/* Create an empty default if the class does not specify a default
* value */
@@ -75,31 +64,14 @@ glade_property_new (GladePropertyClass *class, GladeWidget *widget)
return property;
}
- switch (class->type) {
- case GLADE_PROPERTY_TYPE_DOUBLE:
- case GLADE_PROPERTY_TYPE_INTEGER:
- case GLADE_PROPERTY_TYPE_FLOAT:
+ if (G_IS_PARAM_SPEC_DOUBLE (class->pspec) ||
+ G_IS_PARAM_SPEC_FLOAT (class->pspec) ||
+ G_IS_PARAM_SPEC_INT (class->pspec) ||
+ G_IS_PARAM_SPEC_UINT (class->pspec))
property->enabled = class->optional_default;
- /* Fall thru */
- case GLADE_PROPERTY_TYPE_ENUM:
- case GLADE_PROPERTY_TYPE_FLAGS:
- case GLADE_PROPERTY_TYPE_BOOLEAN:
- case GLADE_PROPERTY_TYPE_STRING:
- case GLADE_PROPERTY_TYPE_UNICHAR:
- g_value_init (property->value, class->def->g_type);
- g_value_copy (class->def, property->value); // glade_property_set (property, class->def);
- break;
- case GLADE_PROPERTY_TYPE_OTHER_WIDGETS:
-#if 0
- value = g_strdup ("");
-#endif
- break;
- case GLADE_PROPERTY_TYPE_OBJECT:
- break;
- case GLADE_PROPERTY_TYPE_ERROR:
- g_warning ("Invalid Glade property type (%d)\n", class->type);
- break;
- }
+
+ g_value_init (property->value, class->def->g_type);
+ g_value_copy (class->def, property->value);
return property;
}
@@ -122,11 +94,6 @@ glade_property_free (GladeProperty *property)
property->value = NULL;
}
-#if 0
- if (property->child)
- g_warning ("Implemenet free property->child\n");
-#endif
-
g_free (property);
}
@@ -171,6 +138,14 @@ glade_property_set (GladeProperty *property, const GValue *value)
return;
}
+ if (property->class->verify_function)
+ {
+ GObject *object =
+ G_OBJECT(glade_widget_get_widget (property->widget));
+ if (property->class->verify_function (object, value) == FALSE)
+ return;
+ }
+
/* Assign property first so that; if the object need be
* rebuilt, it will reflect the new value
*/
@@ -263,7 +238,8 @@ glade_property_write (GladeXmlContext *context, GladeProperty *property)
if (!property->enabled)
return NULL;
- if (!glade_property_class_is_visible (property->class, glade_widget_get_class (property->widget)))
+ if (!glade_property_class_is_visible (property->class,
+ glade_widget_get_class (property->widget)))
return NULL;
node = glade_xml_node_new (context, GLADE_XML_TAG_PROPERTY);
@@ -297,8 +273,9 @@ glade_property_write (GladeXmlContext *context, GladeProperty *property)
if (property->class->def)
{
- default_str = glade_property_class_make_string_from_gvalue (property->class,
- property->class->def);
+ default_str =
+ glade_property_class_make_string_from_gvalue (property->class,
+ property->class->def);
if (default_str && strcmp (tmp, default_str) == 0)
{
g_free (tmp);
diff --git a/src/glade-utils.c b/src/glade-utils.c
index 328cda17..c5d986fe 100644
--- a/src/glade-utils.c
+++ b/src/glade-utils.c
@@ -60,6 +60,48 @@ glade_util_widget_set_tooltip (GtkWidget *widget, const gchar *str)
}
/**
+ * glade_util_compose_get_type_func:
+ * @name:
+ *
+ * TODO: write me
+ *
+ * Returns:
+ */
+gchar *
+glade_util_compose_get_type_func (gchar *name)
+{
+ gchar *retval;
+ GString *tmp;
+ gint i = 1, j;
+
+ tmp = g_string_new (name);
+
+ while (tmp->str[i])
+ {
+ if (g_ascii_isupper (tmp->str[i]))
+ {
+ tmp = g_string_insert_c (tmp, i++, '_');
+
+ j = 0;
+ while (g_ascii_isupper (tmp->str[i++]))
+ j++;
+
+ if (j > 2)
+ g_string_insert_c (tmp, i-2, '_');
+
+ continue;
+ }
+ i++;
+ }
+
+ tmp = g_string_append (tmp, "_get_type");
+ retval = g_ascii_strdown (tmp->str, tmp->len);
+ g_string_free (tmp, TRUE);
+
+ return retval;
+}
+
+/**
* glade_util_get_type_from_name:
* @name:
*
@@ -70,7 +112,7 @@ glade_util_widget_set_tooltip (GtkWidget *widget, const gchar *str)
GType
glade_util_get_type_from_name (const gchar *name)
{
- static GModule *allsymbols;
+ static GModule *allsymbols = NULL;
GType (*get_type) ();
GType type;
@@ -93,16 +135,38 @@ glade_util_get_type_from_name (const gchar *name)
return 0;
}
-/* Disabled for GtkAdjustment, but i'd like to check for this somehow. Chema */
-#if 0
- if (!g_type_is_a (type, gtk_widget_get_type ())) {
- g_warning (_("The loaded type is not a GtkWidget, while trying to load \"%s\""),
- class->name);
+ return type;
+}
+
+/**
+ * glade_utils_get_pspec_from_funcname:
+ * @name:
+ *
+ * TODO: write me
+ *
+ * Returns:
+ */
+GParamSpec *
+glade_utils_get_pspec_from_funcname (const gchar *funcname)
+{
+ static GModule *allsymbols = NULL;
+ GParamSpec *pspec = NULL;
+ GParamSpec *(*get_pspec)() = NULL;
+
+ if (!allsymbols)
+ allsymbols = g_module_open (NULL, 0);
+
+ if (!g_module_symbol (allsymbols, funcname,
+ (gpointer) &get_pspec)) {
+ g_warning (_("We could not find the symbol \"%s\""),
+ funcname);
return FALSE;
}
-#endif
- return type;
+ g_assert (get_pspec);
+ pspec = get_pspec ();
+
+ return pspec;
}
/**
@@ -921,3 +985,4 @@ glade_util_object_set_property (GObject *object, GladeProperty *property)
else
g_object_set_property (object, property->class->id, value);
}
+
diff --git a/src/glade-utils.h b/src/glade-utils.h
index 1aaeb7d6..02078fc3 100644
--- a/src/glade-utils.h
+++ b/src/glade-utils.h
@@ -9,7 +9,9 @@ G_BEGIN_DECLS
void glade_util_widget_set_tooltip (GtkWidget *widget, const gchar *str);
+gchar *glade_util_compose_get_type_func (gchar *name);
GType glade_util_get_type_from_name (const gchar *name);
+GParamSpec *glade_utils_get_pspec_from_funcname (const gchar *funcname);
void glade_util_ui_warn (GtkWidget *parent, const gchar *warning);
void glade_util_flash_message (GtkWidget *statusbar,
guint context_id,
diff --git a/src/glade-widget-class.c b/src/glade-widget-class.c
index 7fad2a95..c8347e3f 100644
--- a/src/glade-widget-class.c
+++ b/src/glade-widget-class.c
@@ -47,40 +47,6 @@
static GHashTable *widget_classes = NULL;
-static gchar *
-glade_widget_class_compose_get_type_func (GladeWidgetClass *class)
-{
- gchar *retval;
- GString *tmp;
- gint i = 1, j;
-
- tmp = g_string_new (class->name);
-
- while (tmp->str[i])
- {
- if (g_ascii_isupper (tmp->str[i]))
- {
- tmp = g_string_insert_c (tmp, i++, '_');
-
- j = 0;
- while (g_ascii_isupper (tmp->str[i++]))
- j++;
-
- if (j > 2)
- g_string_insert_c (tmp, i-2, '_');
-
- continue;
- }
- i++;
- }
-
- tmp = g_string_append (tmp, "_get_type");
- retval = g_ascii_strdown (tmp->str, tmp->len);
- g_string_free (tmp, TRUE);
-
- return retval;
-}
-
/**
* glade_widget_class_free:
* @widget_class: a #GladeWidgetClass
@@ -702,7 +668,7 @@ glade_widget_class_new (const char *name,
/* we can't just call g_type_from_name (name) to get the type, because
* that only works for registered types, and the only way to register the
* type is to call foo_bar_get_type() */
- init_function_name = glade_widget_class_compose_get_type_func (widget_class);
+ init_function_name = glade_util_compose_get_type_func (widget_class->name);
if (!init_function_name)
{
g_warning (_("Not enough memory."));
diff --git a/src/glade.h b/src/glade.h
index 25da3d67..7d4245e0 100644
--- a/src/glade.h
+++ b/src/glade.h
@@ -58,6 +58,7 @@
#define GLADE_TAG_OPTIONAL "Optional"
#define GLADE_TAG_OPTIONAL_DEFAULT "OptionalDefault"
#define GLADE_TAG_TYPE "Type"
+#define GLADE_TAG_SPEC "Spec"
#define GLADE_TAG_TOOLTIP "Tooltip"
#define GLADE_TAG_GTKARG "GtkArg"
#define GLADE_TAG_PARAMETERS "Parameters"
@@ -81,6 +82,7 @@
#define GLADE_TAG_OBJECT "Object"
#define GLADE_TAG_SET_FUNCTION "SetFunction"
#define GLADE_TAG_GET_FUNCTION "GetFunction"
+#define GLADE_TAG_VERIFY_FUNCTION "VerifyFunction"
#define GLADE_TAG_QUERY "Query"
#define GLADE_TAG_QUESTION "Question"
#define GLADE_TAG_VISIBLE_LINES "VisibleLines"
diff --git a/widgets/gtkbox.xml b/widgets/gtkbox.xml
index b687a76c..7c7dc3f8 100644
--- a/widgets/gtkbox.xml
+++ b/widgets/gtkbox.xml
@@ -5,7 +5,7 @@
<Properties>
<Property Id="size" Name="Number of items" Query="TRUE" Default="3">
- <Type>Integer</Type>
+ <Spec>glade_gtk_standard_int_spec</Spec>
<Tooltip>The number of items in the box</Tooltip>
<Parameters>
<Parameter Key="Min" Value="2"/>
@@ -16,6 +16,7 @@
</Parameters>
<SetFunction>glade_gtk_box_set_size</SetFunction>
<GetFunction>glade_gtk_box_get_size</GetFunction>
+ <VerifyFunction>glade_gtk_box_verify_size</VerifyFunction>
</Property>
</Properties>
diff --git a/widgets/gtkbutton.xml b/widgets/gtkbutton.xml
index 82e7dc17..e4a4169d 100644
--- a/widgets/gtkbutton.xml
+++ b/widgets/gtkbutton.xml
@@ -5,19 +5,12 @@
<Properties>
<Property Id="stock" Name="Stock Button" Default="glade-none">
- <Type>Enum</Type>
- <Enums EnumType="GtkReliefStyle">
- <Enum Id="glade-none" Name="None"/>
- <Enum Id="gtk-ok" Name="Ok"/>
- <Enum Id="gtk-cancel" Name="Cancel"/>
- <Enum Id="gtk-apply" Name="Apply"/>
- <Enum Id="gtk-close" Name="Close"/>
- </Enums>
+ <Spec>glade_gtk_stock_spec</Spec>
<SetFunction>glade_gtk_button_set_stock</SetFunction>
</Property>
<Property Id="response-id" Name="Response ID" Default="0" Common="False">
- <Type>Integer</Type>
+ <Spec>glade_gtk_standard_int_spec</Spec>
<Tooltip>The response ID of this button in a dialog (it's NOT useful if this button is not in a GtkDialog)</Tooltip>
<SetFunction>ignore</SetFunction>
<GetFunction>ignore</GetFunction>
diff --git a/widgets/gtkdialog.xml b/widgets/gtkdialog.xml
index 6fb53c90..33ed6fcd 100644
--- a/widgets/gtkdialog.xml
+++ b/widgets/gtkdialog.xml
@@ -18,7 +18,7 @@
So by now we will just add a fake response-id property to buttons
<ChildProperties>
<Property Id="response-id" Name="Response ID" Default="0" Common="False">
- <Type>Integer</Type>
+ <Spec>glade_gtk_standard_int_spec</Spec>
<Tooltip>The response ID of this button in the dialog</Tooltip>
<SetFunction>ignore</SetFunction>
<GetFunction>ignore</GetFunction>
diff --git a/widgets/gtknotebook.xml b/widgets/gtknotebook.xml
index 3c3f1bed..be047e94 100644
--- a/widgets/gtknotebook.xml
+++ b/widgets/gtknotebook.xml
@@ -1,11 +1,13 @@
<GladeWidgetClass>
+ <FillEmptyFunction>empty</FillEmptyFunction>
+
<ReplaceChildFunction>glade_gtk_notebook_replace_child</ReplaceChildFunction>
<Properties>
<Property Id="pages" Name="Number of pages" Default="3" Query="TRUE">
- <Type>Integer</Type>
+ <Spec>glade_gtk_standard_int_spec</Spec>
<Tooltip>The number of pages in the notebook</Tooltip>
<Parameters>
<Parameter Key="Min" Value="1"/>
@@ -16,6 +18,7 @@
</Parameters>
<SetFunction>glade_gtk_notebook_set_n_pages</SetFunction>
<GetFunction>glade_gtk_notebook_get_n_pages</GetFunction>
+ <VerifyFunction>glade_gtk_notebook_verify_n_pages</VerifyFunction>
</Property>
</Properties>
diff --git a/widgets/gtkoptionmenu.xml b/widgets/gtkoptionmenu.xml
index c3271d84..9125d9ca 100644
--- a/widgets/gtkoptionmenu.xml
+++ b/widgets/gtkoptionmenu.xml
@@ -7,7 +7,7 @@
<Property Id="border-width"/>
<Property Id="items" Name="Items">
- <Type>String</Type>
+ <Spec>glade_gtk_standard_string_spec</Spec>
<SetFunction>glade_gtk_option_menu_set_items</SetFunction>
<Parameters>
<Parameter Key="VisibleLines" Value="2"/>
@@ -15,7 +15,7 @@
</Property>
<!--
<Property ParamSpec="FALSE" Id="initial-choice" Name="Inital Choice">
- <Type>Integer</Type>
+ <Spec>glade_gtk_standard_int_spec</Spec>
<SetFunction>glade_gtk_option_menu_set_initial_choice</SetFunction>
</Property>
-->
diff --git a/widgets/gtkradiobutton.xml b/widgets/gtkradiobutton.xml
index 1b2a7f59..52cce432 100644
--- a/widgets/gtkradiobutton.xml
+++ b/widgets/gtkradiobutton.xml
@@ -4,7 +4,7 @@
<Property Id="label" Default="radio button"/>
<Property Id="draw-indicator" Default="True"/>
<Property Id="group" Name="Group" Default="True">
- <Type>String</Type>
+ <Spec>glade_gtk_standard_string_spec</Spec>
<SetFunction>glade_gtk_radio_button_set_group</SetFunction>
<GetFunction>glade_gtk_radio_button_get_group</GetFunction>
</Property>
diff --git a/widgets/gtkspinbutton.xml b/widgets/gtkspinbutton.xml
index 16c51f06..a5df2993 100644
--- a/widgets/gtkspinbutton.xml
+++ b/widgets/gtkspinbutton.xml
@@ -3,23 +3,23 @@
<Properties>
<Property Id="minimum" Name="Min" Default="0">
- <Type>Float</Type>
+ <Spec>glade_gtk_standard_float_spec</Spec>
<SetFunction>glade_gtk_spin_button_set_min</SetFunction>
</Property>
<Property Id="maximum" Name="Max" Default="100">
- <Type>Float</Type>
+ <Spec>glade_gtk_standard_float_spec</Spec>
<SetFunction>glade_gtk_spin_button_set_max</SetFunction>
</Property>
<Property Id="step-increment" Name="Step Inc." Default="1">
- <Type>Float</Type>
+ <Spec>glade_gtk_standard_float_spec</Spec>
<SetFunction>glade_gtk_spin_button_set_step_increment</SetFunction>
</Property>
<Property Id="page-increment" Name="Page Inc." Default="10">
- <Type>Float</Type>
+ <Spec>glade_gtk_standard_float_spec</Spec>
<SetFunction>glade_gtk_spin_button_set_step_increment</SetFunction>
</Property>
<Property Id="page-size" Name="Page Size" Default="10">
- <Type>Float</Type>
+ <Spec>glade_gtk_standard_float_spec</Spec>
<SetFunction>glade_gtk_spin_button_set_step_increment</SetFunction>
</Property>
diff --git a/widgets/gtktable.xml b/widgets/gtktable.xml
index 0f00461b..6b982543 100644
--- a/widgets/gtktable.xml
+++ b/widgets/gtktable.xml
@@ -1,5 +1,6 @@
<GladeWidgetClass>
- <FillEmptyFunction>ignore</FillEmptyFunction>
+
+ <FillEmptyFunction>empty</FillEmptyFunction>
<Properties>
@@ -12,6 +13,7 @@
<Parameter Key="ClimbRate" Value="1"/>
</Parameters>
<SetFunction>glade_gtk_table_set_n_rows</SetFunction>
+ <VerifyFunction>glade_gtk_table_verify_n_rows</VerifyFunction>
</Property>
<Property Id="n-columns" Default="3" Query="TRUE">
@@ -23,6 +25,7 @@
<Parameter Key="ClibmRate" Value="1"/>
</Parameters>
<SetFunction>glade_gtk_table_set_n_columns</SetFunction>
+ <VerifyFunction>glade_gtk_table_verify_n_columns</VerifyFunction>
</Property>
</Properties>
diff --git a/widgets/gtktoolbar.xml b/widgets/gtktoolbar.xml
index 93aa4e6f..2679c315 100644
--- a/widgets/gtktoolbar.xml
+++ b/widgets/gtktoolbar.xml
@@ -1,9 +1,11 @@
<GladeWidgetClass>
+ <FillEmptyFunction>empty</FillEmptyFunction>
+
<Properties>
- <Property Id="size" Name="Size" Default="3">
- <Type>Integer</Type>
+ <Property Id="size" Name="Size" Default="3" Query="TRUE">
+ <Spec>glade_gtk_standard_int_spec</Spec>
<Tooltip>The number of items in the toolbar</Tooltip>
<Parameters>
<Parameter Key="Min" Value="0"/>
@@ -12,11 +14,9 @@
<Parameter Key="PageIncrement" Value="10"/>
<Parameter Key="ClimbRate" Value="1"/>
</Parameters>
- <Query>
- <Question>Number of items</Question>
- </Query>
<SetFunction>glade_gtk_toolbar_set_size</SetFunction>
<GetFunction>glade_gtk_toolbar_get_size</GetFunction>
+ <VerifyFunction>glade_gtk_toolbar_verify_size</VerifyFunction>
</Property>
</Properties>
diff --git a/widgets/gtkwidget.xml b/widgets/gtkwidget.xml
index 8de74ecd..f198461f 100644
--- a/widgets/gtkwidget.xml
+++ b/widgets/gtkwidget.xml
@@ -11,7 +11,7 @@
<Property Common="True" Optional="True" OptionalDefault="False" Default="0" Id="height-request"/>
<Property Common="True" Id="tooltip" Name="Tooltip" Visible="glade_gtk_widget_condition">
- <Type>String</Type>
+ <Spec>glade_gtk_standard_string_spec</Spec>
<SetFunction>glade_gtk_widget_set_tooltip</SetFunction>
<GetFunction>glade_gtk_widget_get_tooltip</GetFunction>
</Property>