init_function is not required in the xml files.

2001-07-15  Chema Celorio  <chema@celorio.com>

	* src/glade-widget-class.c (glade_widget_class_new_from_node): init_function is
	not required in the xml files.
	(glade_widget_class_new_from_node): make non-static cause a property can now have
	a child like a spin button has a gtk_adjustment

	* src/glade-property.h: a property can have a ->child.

	* src/glade-property.c (glade_property_new_from_string): handl type _OBJECT

	* src/glade-property-class.h: we can only have one child per property. Rename
	children to child

	* src/glade-property-class.c (glade_property_class_get_type_from_spec): handle
	_OBJECT
	(glade_property_class_new_from_node): if we have child object, load it.

	* src/glade-gtk.c (glade_gtk_option_menu_set_items): rename _append to _shell_append
	to remove warning.
	(glade_gtk_adjustment_set_max): impl.
	(glade_gtk_adjustment_set_min): impl.

	* src/glade-editor.h (struct _GladeEditorTable): add tabel->editor, this cleans
	up the fucntion prototypes cause we have one less argument to pass.

	* src/glade-editor.c (glade_editor_append_item_real): rename and change
	arguments to that we can recurse
	(glade_editor_table_append_items): ditto
	(glade_editor_property_load_object): impl.
	(glade_editor_property_load): change so that we can recurse

	* src/glade-property-class.h: add ->child for property type == OBJECT

	* src/glade-editor.c (glade_editor_create_input_object): implement

	* src/glade-widget-class.c (glade_widget_class_new_from_node): make non
	static and add to headers since we are recursing for type object
This commit is contained in:
Chema Celorio 2001-07-16 00:35:59 +00:00 committed by Jose Maria Celorio
parent c8702214d6
commit 75f81c9694
17 changed files with 380 additions and 271 deletions

View File

@ -1,3 +1,42 @@
2001-07-15 Chema Celorio <chema@celorio.com>
* src/glade-widget-class.c (glade_widget_class_new_from_node): init_function is
not required in the xml files.
(glade_widget_class_new_from_node): make non-static cause a property can now have
a child like a spin button has a gtk_adjustment
* src/glade-property.h: a property can have a ->child.
* src/glade-property.c (glade_property_new_from_string): handl type _OBJECT
* src/glade-property-class.h: we can only have one child per property. Rename
children to child
* src/glade-property-class.c (glade_property_class_get_type_from_spec): handle
_OBJECT
(glade_property_class_new_from_node): if we have child object, load it.
* src/glade-gtk.c (glade_gtk_option_menu_set_items): rename _append to _shell_append
to remove warning.
(glade_gtk_adjustment_set_max): impl.
(glade_gtk_adjustment_set_min): impl.
* src/glade-editor.h (struct _GladeEditorTable): add tabel->editor, this cleans
up the fucntion prototypes cause we have one less argument to pass.
* src/glade-editor.c (glade_editor_append_item_real): rename and change
arguments to that we can recurse
(glade_editor_table_append_items): ditto
(glade_editor_property_load_object): impl.
(glade_editor_property_load): change so that we can recurse
* src/glade-property-class.h: add ->child for property type == OBJECT
* src/glade-editor.c (glade_editor_create_input_object): implement
* src/glade-widget-class.c (glade_widget_class_new_from_node): make non
static and add to headers since we are recursing for type object
2001-07-14 Archit Baweja <bighead@crosswinds.net>
* src/glade-widget-class.c (glade_widget_class_compose_get_type_func):

View File

@ -53,6 +53,11 @@ static guint glade_editor_signals[LAST_SIGNAL] = {0};
static GtkWindowClass *parent_class = NULL;
static void glade_editor_select_item_real (GladeEditor *editor, GladeWidget *widget);
/* We use this function recursively so we need to declare it */
static gboolean glade_editor_table_append_items (GladeEditorTable *table, GladeWidgetClass *class,
GList **list);
guint
glade_editor_get_type (void)
{
@ -199,6 +204,7 @@ glade_editor_table_new (GladeWidgetClass *class)
table->glade_widget_class = class;
table->table_widget = gtk_table_new (0, 0, FALSE);
table->properties = NULL;
table->rows = 0;
gtk_table_set_row_spacings (GTK_TABLE (table->table_widget),
GLADE_PROPERY_TABLE_ROW_SPACING);
@ -408,7 +414,6 @@ glade_editor_create_input_choice_item (GladeEditorProperty *property,
static GtkWidget *
glade_editor_create_input_choice (GladeEditorProperty *property)
{
GladePropertyClass *class;
GladeChoice *choice;
GtkWidget *menu_item;
GtkWidget *menu;
@ -417,9 +422,7 @@ glade_editor_create_input_choice (GladeEditorProperty *property)
g_return_val_if_fail (property != NULL, NULL);
class = property->glade_property_class;
list = class->choices;
list = property->class->choices;
menu = gtk_menu_new ();
for (; list != NULL; list = list->next) {
choice = (GladeChoice *)list->data;
@ -442,7 +445,7 @@ glade_editor_create_input_text (GladeEditorProperty *property)
g_return_val_if_fail (property != NULL, NULL);
class = property->glade_property_class;
class = property->class;
glade_parameter_get_integer (class->parameters, GLADE_TAG_VISIBLE_LINES, &lines);
@ -515,7 +518,7 @@ glade_editor_create_input_numeric (GladeEditorProperty *property,
g_return_val_if_fail (property != NULL, NULL);
class = property->glade_property_class;
class = property->class;
adjustment = glade_parameter_adjustment_new (class->parameters);
@ -527,7 +530,6 @@ glade_editor_create_input_numeric (GladeEditorProperty *property,
GTK_SIGNAL_FUNC (glade_editor_property_changed_numeric),
property);
/* Some numeric types are optional, for example the default window size, so
* they have a toggle button right next to the spin button.
*/
@ -574,7 +576,7 @@ glade_editor_create_input_boolean (GladeEditorProperty *property)
g_return_val_if_fail (property != NULL, NULL);
class = property->glade_property_class;
class = property->class;
button = gtk_toggle_button_new_with_label (_("No"));
@ -585,16 +587,26 @@ glade_editor_create_input_boolean (GladeEditorProperty *property)
}
static GtkWidget *
glade_editor_create_input (GladeEditorProperty *property)
glade_editor_create_input_object (GladeEditorProperty *property, GladeEditorTable *table)
{
GladePropertyType type;
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);
return NULL;
}
static GtkWidget *
glade_editor_append_item_real (GladeEditorTable *table, GladeEditorProperty *property)
{
GtkWidget *label;
GtkWidget *input = NULL;
g_return_val_if_fail (property != NULL, NULL);
g_return_val_if_fail (GLADE_IS_EDITOR_TABLE (table), NULL);
g_return_val_if_fail (GLADE_IS_PROPERTY_CLASS (property->class), NULL);
type = property->glade_property_class->type;
switch (type) {
switch (property->class->type) {
case GLADE_PROPERTY_TYPE_BOOLEAN:
input = glade_editor_create_input_boolean (property);
break;
@ -614,66 +626,58 @@ glade_editor_create_input (GladeEditorProperty *property)
input = glade_editor_create_input_choice (property);
break;
case GLADE_PROPERTY_TYPE_OTHER_WIDGETS:
g_warning ("The widget type %d does not have an input implemented\n", type);
g_warning ("The widget type %s does not have an input implemented\n",
property->class->name);
break;
case GLADE_PROPERTY_TYPE_OBJECT:
return gtk_label_new ("Implement 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 !");
}
if (input == NULL) {
g_warning ("Can't create an input widget for type %i\n", type);
g_warning ("Can't create an input widget for type %s\n",
property->class->name);
return gtk_label_new ("Implement me !");
}
label = glade_property_class_create_label (property->class);
glade_editor_table_attach (table->table_widget, label, 0, table->rows);
glade_editor_table_attach (table->table_widget, input, 1, table->rows);
table->rows++;
return input;
}
static GladeEditorProperty *
glade_editor_property_new (GladeEditor *editor,
GladePropertyClass *property_class)
glade_editor_table_append_item (GladeEditorTable *table,
GladePropertyClass *class)
{
GladeEditorProperty *editor_property;
GladeEditorProperty *property;
editor_property = g_new0 (GladeEditorProperty, 1);
property = g_new0 (GladeEditorProperty, 1);
editor_property->glade_property_class = property_class;
editor_property->input = glade_editor_create_input (editor_property);
editor_property->property = NULL;
property->class = class;
property->children = NULL;
property->input = glade_editor_append_item_real (table, property);
property->property = NULL;
return editor_property;
return property;
}
static void
glade_editor_create_widget_table_from_class_common (GladeEditor *editor,
GladeEditorTable *table,
gint *row_)
glade_editor_table_append_common (GladeEditorTable *table)
{
GtkWidget *gtk_table;
GtkWidget *label;
GtkWidget *entry;
gint row = *row_;
gtk_table = table->table_widget;
@ -684,13 +688,12 @@ glade_editor_create_widget_table_from_class_common (GladeEditor *editor,
table->name_entry = entry;
gtk_signal_connect (GTK_OBJECT (entry), "changed",
GTK_SIGNAL_FUNC (glade_editor_widget_name_changed),
editor);
table->editor);
glade_editor_table_attach (gtk_table, label, 0, row);
glade_editor_table_attach (gtk_table, entry, 1, row);
glade_editor_table_attach (gtk_table, label, 0, table->rows);
glade_editor_table_attach (gtk_table, entry, 1, table->rows);
table->rows++;
row++;
/* Class */
label = gtk_label_new (_("Class :"));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
@ -698,63 +701,56 @@ glade_editor_create_widget_table_from_class_common (GladeEditor *editor,
gtk_entry_set_text (GTK_ENTRY (entry), table->glade_widget_class->name);
gtk_entry_set_editable (GTK_ENTRY (entry), FALSE);
glade_editor_table_attach (gtk_table, label, 0, row);
glade_editor_table_attach (gtk_table, entry, 1, row);
row++;
glade_editor_table_attach (gtk_table, label, 0, table->rows);
glade_editor_table_attach (gtk_table, entry, 1, table->rows);
table->rows++;
*row_ = row;
}
static gboolean
glade_editor_table_append_items (GladeEditorTable *table,
GladeWidgetClass *class,
GList **list_)
{
GladeEditorProperty *property;
GladePropertyClass *property_class;
GList *list;
GList *new_list;
new_list = *list_;
list = class->properties;
for (; list != NULL; list = list->next) {
property_class = (GladePropertyClass *) list->data;
property = glade_editor_table_append_item (table, property_class);
if (property != NULL)
new_list = g_list_prepend (new_list,
property);
}
*list_ = new_list;
return TRUE;
}
static GladeEditorTable *
glade_editor_create_table_from_class (GladeEditor *editor,
GladeWidgetClass *class)
glade_editor_table_create (GladeEditor *editor, GladeWidgetClass *class)
{
GladePropertyClass *property_class;
GladeEditorTable *table;
GtkWidget *gtk_table;
GtkWidget *label;
GList *list;
gint row = 0;
g_return_val_if_fail (GLADE_IS_EDITOR (editor), NULL);
g_return_val_if_fail (GLADE_IS_WIDGET_CLASS (class), NULL);
table = glade_editor_table_new (class);
gtk_table = table->table_widget;
/* Add the common fields. Name & Class */
glade_editor_create_widget_table_from_class_common (editor,
table,
&row);
list = class->properties;
for (; list != NULL; list = list->next) {
GladeEditorProperty *editor_property;
property_class = (GladePropertyClass *) list->data;
/* Special cases */
label = glade_property_class_create_label (property_class);
if (label == NULL)
return NULL;
editor_property = glade_editor_property_new (editor,
property_class);
if (editor_property == NULL)
return NULL;
table->properties = g_list_prepend (table->properties,
editor_property);
glade_editor_table_attach (gtk_table, label, 0, row);
glade_editor_table_attach (gtk_table, editor_property->input,
1, row);
row++;
}
gtk_widget_show_all (gtk_table);
table->editor = editor;
glade_editor_table_append_common (table);
if (!glade_editor_table_append_items (table, class, &table->properties))
return NULL;
gtk_widget_show_all (table->table_widget);
editor->widget_tables = g_list_prepend (editor->widget_tables,
table);
return table;
}
@ -783,7 +779,7 @@ glade_editor_load_widget_page (GladeEditor *editor, GladeWidgetClass *class)
table = glade_editor_get_table_from_class (editor, class);
if (table == NULL)
table = glade_editor_create_table_from_class (editor, class);
table = glade_editor_table_create (editor, class);
g_return_if_fail (table != NULL);
@ -1036,22 +1032,39 @@ glade_editor_property_load_text (GladeEditorProperty *property)
gtk_object_set_user_data (GTK_OBJECT (property->input), 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)
{
GladeEditorProperty *child;
GList *list;
list = property->children;
for (; list != NULL; list = list->next) {
child = list->data;
glade_editor_property_load (child, property->property->widget);
}
}
static void
glade_editor_property_load (GladeEditorProperty *property, GladeWidget *widget)
{
GladePropertyClass *property_class = property->glade_property_class;
GladePropertyClass *class = property->class;
g_return_if_fail (property != NULL);
g_return_if_fail (property->glade_property_class != NULL);
property->loading = TRUE;
property->property = glade_property_get_from_class (widget, property_class);
g_return_if_fail (GLADE_IS_EDITOR_PROPERTY (property));
g_return_if_fail (GLADE_IS_PROPERTY_CLASS (property->class));
property->property = glade_widget_get_property_from_class (widget, class);
g_return_if_fail (property->property != NULL);
g_return_if_fail (property->property->class == property->glade_property_class);
switch (property_class->type) {
g_return_if_fail (property->property->class == property->class);
property->loading = TRUE;
switch (class->type) {
case GLADE_PROPERTY_TYPE_TEXT:
glade_editor_property_load_text (property);
break;
@ -1074,9 +1087,11 @@ glade_editor_property_load (GladeEditorProperty *property, GladeWidget *widget)
glade_editor_property_load_other_widgets (property);
break;
case GLADE_PROPERTY_TYPE_OBJECT:
glade_editor_property_load_object (property);
break;
case GLADE_PROPERTY_TYPE_ERROR:
g_warning ("%s : type %i not implemented\n", __FUNCTION__,
property_class->type);
class->type);
}
property->loading = FALSE;
@ -1086,9 +1101,9 @@ glade_editor_property_load (GladeEditorProperty *property, GladeWidget *widget)
static void
glade_editor_load_item (GladeEditor *editor, GladeWidget *item)
{
GladeEditorTable *table;
GladeEditorProperty *property;
GladeWidgetClass *class;
GladeEditorTable *table;
GList *list;
/* Load the GladeWidgetClass */

View File

@ -4,9 +4,13 @@
G_BEGIN_DECLS
#define GLADE_EDITOR(obj) GTK_CHECK_CAST (obj, glade_editor_get_type (), GladeEditor)
#define GLADE_EDITOR_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, glade_editor_get_type (), GladeEditorClass)
#define GLADE_IS_EDITOR(obj) GTK_CHECK_TYPE (obj, glade_editor_get_type ())
#define GLADE_EDITOR(obj) GTK_CHECK_CAST (obj, glade_editor_get_type (), GladeEditor)
#define GLADE_EDITOR_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, glade_editor_get_type (), GladeEditorClass)
#define GLADE_IS_EDITOR(obj) GTK_CHECK_TYPE (obj, glade_editor_get_type ())
#define GLADE_EDITOR_TABLE(t) ((GladeEditorTable *)t)
#define GLADE_IS_EDITOR_TABLE(t) (t != NULL)
#define GLADE_EDITOR_PROPERTY(p) ((GladeEditorProperty *)p)
#define GLADE_IS_EDITOR_PROPERTY(p) (p != NULL)
typedef struct _GladeEditorClass GladeEditorClass;
typedef struct _GladeEditorTable GladeEditorTable;
@ -101,6 +105,10 @@ struct _GladeEditorClass
*/
struct _GladeEditorTable
{
GladeEditor *editor; /* Handy pointer that avoids havving to pass the
* editor arround.
*/
GladeWidgetClass *glade_widget_class; /* The GladeWidgetClass this
* table belongs to.
*/
@ -125,6 +133,8 @@ struct _GladeEditorTable
* For each row in the gtk_table, there is a
* corrsponding GladeEditorProperty struct.
*/
gint rows;
};
/* For every GladePropertyClass we have a GladeEditorProperty that is
@ -132,7 +142,7 @@ struct _GladeEditorTable
*/
struct _GladeEditorProperty
{
GladePropertyClass *glade_property_class; /* The class this property
GladePropertyClass *class; /* The class this property
* corresponds to.
*/
@ -150,6 +160,10 @@ struct _GladeEditorProperty
* when we receive a "changed" signal we know that nothing has
* really changed, we just loaded a new glade widget
*/
GList *children; /* Used for class->type = OBJECT. Where a sigle entry corresponds
* to a number of inputs
*/
};
typedef enum {

View File

@ -21,6 +21,7 @@
*/
#include <string.h>
#include <stdlib.h>
#include "glade.h"
#include "glade-property-class.h"
@ -60,7 +61,7 @@ glade_gtk_option_menu_set_items (GObject *object, const gchar *items)
menu_item = gtk_menu_item_new_with_label (pos);
gtk_widget_show (menu_item);
gtk_menu_append (GTK_MENU (menu), menu_item);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
pos = item_end + 1;
}
@ -80,9 +81,33 @@ glade_gtk_progress_bar_set_format (GObject *object, const gchar *format)
gtk_progress_set_format_string (GTK_PROGRESS (bar), format);
}
static void
glade_gtk_adjustment_set_max (GObject *object, const gchar *string)
{
GtkAdjustment *adjustment;
gfloat val;
val = atof (string);
adjustment = GTK_ADJUSTMENT (object);
adjustment->upper = val;
gtk_adjustment_changed (adjustment);
}
static void
glade_gtk_adjustment_set_min (GObject *object, const gchar *string)
{
GtkAdjustment *adjustment;
gfloat val;
val = atof (string);
adjustment = GTK_ADJUSTMENT (object);
adjustment->lower = val;
gtk_adjustment_changed (adjustment);
}
/* ================ Temp hack =================== */
@ -98,6 +123,8 @@ GladeGtkFunction functions [] = {
{"glade_gtk_entry_set_text", &glade_gtk_entry_set_text},
{"glade_gtk_option_menu_set_items", &glade_gtk_option_menu_set_items},
{"glade_gtk_progress_bar_set_format", &glade_gtk_progress_bar_set_format},
{"glade_gtk_adjustment_set_max", &glade_gtk_adjustment_set_max},
{"glade_gtk_adjustment_set_min", &glade_gtk_adjustment_set_min},
};
gboolean

View File

@ -161,9 +161,12 @@ glade_property_class_get_type_from_spec (GParamSpec *spec)
case G_TYPE_PARAM_UCHAR:
g_warning ("uchar not implemented\n");
break;
case G_TYPE_PARAM_OBJECT:
return GLADE_PROPERTY_TYPE_OBJECT;
default:
g_warning ("Could not determine GladePropertyType from spec (%d)",
G_PARAM_SPEC_TYPE (spec));
g_warning ("Could not determine GladePropertyType from spec (%d,%s)",
G_PARAM_SPEC_TYPE (spec),
G_PARAM_SPEC_TYPE_NAME (spec));
}
return GLADE_PROPERTY_TYPE_ERROR;
@ -397,7 +400,6 @@ glade_property_class_get_parameters_from_spec (GParamSpec *spec,
case GLADE_PROPERTY_TYPE_OTHER_WIDGETS:
break;
case GLADE_PROPERTY_TYPE_OBJECT:
g_print ("get parameters from spec for type object not implemented\n");
break;
case GLADE_PROPERTY_TYPE_ERROR:
break;
@ -551,6 +553,10 @@ glade_property_class_new_from_node (xmlNodePtr node, GladeWidgetClass *widget_cl
/* If the property is an object Load it */
if (property_class->type == GLADE_PROPERTY_TYPE_OBJECT) {
child = glade_xml_search_child_required (node, GLADE_TAG_GLADE_WIDGET_CLASS);
if (child == NULL)
return NULL;
property_class->child = glade_widget_class_new_from_node (child);
}
/* If this property can't be set with g_object_set, get the workarround

View File

@ -136,12 +136,13 @@ struct _GladePropertyClass {
GladePropertyQuery *query;
GList *children; /* A list of 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
*/
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.
*/
void (*set_function) (GObject *object,
const gchar *value);

View File

@ -40,13 +40,17 @@ glade_property_new (void)
property->class = NULL;
property->value = NULL;
property->enabled = TRUE;
property->child = NULL;
return property;
}
/* We are recursing so add the prototype. Don't you love C ? */
static GList * glade_property_list_new_from_list (GList *list, GladeWidget *widget);
static GladeProperty *
glade_property_new_from_string (const gchar *string, GladePropertyClass *class)
glade_property_new_from_string (const gchar *string, GladePropertyClass *class, GladeWidget *widget)
{
GladeProperty *property;
gchar *value = NULL;
@ -140,7 +144,9 @@ glade_property_new_from_string (const gchar *string, GladePropertyClass *class)
value = g_strdup ("");
break;
case GLADE_PROPERTY_TYPE_OBJECT:
g_print ("Dunno what to do with type object \n");
value = NULL;
property->child = glade_widget_new_from_class (class->child,
widget);
break;
case GLADE_PROPERTY_TYPE_ERROR:
g_warning ("Invalid Glade property type (%d)\n", class->type);
@ -152,23 +158,20 @@ glade_property_new_from_string (const gchar *string, GladePropertyClass *class)
return property;
}
GList *
glade_property_list_new_from_widget_class (GladeWidgetClass *class,
GladeWidget *widget)
static GList *
glade_property_list_new_from_list (GList *list, GladeWidget *widget)
{
GladePropertyClass *property_class;
GladeProperty *property;
GList *list = NULL;
GList *new_list = NULL;
gchar *def;
list = class->properties;
for (; list != NULL; list = list->next) {
property_class = list->data;
def = NULL;
glade_parameter_get_string (property_class->parameters,
"Default", &def);
property = glade_property_new_from_string (def, property_class);
property = glade_property_new_from_string (def, property_class, widget);
if (property == NULL)
continue;
@ -180,13 +183,24 @@ glade_property_list_new_from_widget_class (GladeWidgetClass *class,
new_list = g_list_prepend (new_list, property);
}
new_list = g_list_reverse (new_list);
return new_list;
}
GList *
glade_property_list_new_from_widget_class (GladeWidgetClass *class,
GladeWidget *widget)
{
GList *list = NULL;
list = class->properties;
return glade_property_list_new_from_list (list, widget);
}
GladeProperty *
glade_property_get_from_id (GList *settings_list, const gchar *id)
{
@ -266,15 +280,16 @@ glade_property_changed_float (GladeProperty *property, gfloat val)
g_return_if_fail (property != NULL);
g_return_if_fail (property->value != NULL);
#if 0
g_print ("Changed float\n");
#endif
g_free (property->value);
property->value = g_strdup_printf ("%g", val);
gtk_object_set (GTK_OBJECT (property->widget->widget),
property->class->id, val, NULL);
if (property->class->set_function == NULL)
gtk_object_set (GTK_OBJECT (property->widget->widget),
property->class->id, val, NULL);
else
(*property->class->set_function) (G_OBJECT (property->widget->widget),
property->value);
}
void
@ -290,13 +305,13 @@ glade_property_changed_double (GladeProperty *property, gdouble val)
g_free (property->value);
property->value = g_strdup_printf ("%g", val);
#if 0
#if 0
gvalue = g_value_init (gvalue, G_TYPE_DOUBLE);
g_value_set_double (gvalue, val);
#endif
#if 0
g_print ("Changed double to %g \"%s\" -->%s<-- but using gvalue @%d\n",
#ifdef DEBUG
g_debug ("Changed double to %g \"%s\" -->%s<-- but using gvalue @%d\n",
val,
property->value,
property->class->gtk_arg,
@ -306,10 +321,10 @@ glade_property_changed_double (GladeProperty *property, gdouble val)
g_object_set (G_OBJECT (property->widget->widget),
property->class->id, val, NULL);
#if 0
#ifdef DEBUG
if (GTK_IS_SPIN_BUTTON (property->widget->widget)) {
g_print ("It is spin button\n");
g_print ("The alignement is min :%g max:%g value%g\n",
g_debug ("It is spin button\n");
g_debug ("The alignement is min :%g max:%g value%g\n",
GTK_SPIN_BUTTON (property->widget->widget)->adjustment->lower,
GTK_SPIN_BUTTON (property->widget->widget)->adjustment->upper,
GTK_SPIN_BUTTON (property->widget->widget)->adjustment->value);
@ -318,11 +333,9 @@ glade_property_changed_double (GladeProperty *property, gdouble val)
}
#endif
#if 0
g_print ("Setting-------------------- 222222222\n");
g_object_set (G_OBJECT (property->widget->widget),
property->class->gtk_arg,
gvalue, NULL);
g_print ("DONE: Setting-------------------------\n");
#endif
}
@ -421,26 +434,6 @@ glade_property_get_choice (GladeProperty *property)
return choice;
}
GladeProperty *
glade_property_get_from_class (GladeWidget *widget,
GladePropertyClass *class)
{
GladeProperty *property;
GList *list;
list = widget->properties;
for (; list != NULL; list = list->next) {
property = list->data;
if (property->class == class)
return property;
}
g_warning ("Could not find property from class\n");
return NULL;
}
void
glade_property_query_result_set_int (GladePropertyQueryResult *result,
const gchar *key,

View File

@ -32,6 +32,8 @@ struct _GladeProperty {
*/
GList *views; /* A list of GladePropertyView items */
GladeWidget *child; /* A GladeProperty of type object has a child */
};
@ -66,10 +68,8 @@ GladeChoice * glade_property_get_choice (GladeProperty *property);
/* Get a GladeProperty */
GladeProperty * glade_property_get_from_name (GList *property_list,
const gchar *name);
GladeProperty * glade_property_get_from_class (GladeWidget *widget,
GladePropertyClass *class);
GladeProperty * glade_property_get_from_id (GList *settings_list,
const gchar *id);
GladeProperty * glade_property_get_from_id (GList *settings_list,
const gchar *id);
/* Property Queries */
GladePropertyQueryResult * glade_property_query_result_new (void);

View File

@ -102,7 +102,6 @@ glade_widget_class_add_virtual_methods (GladeWidgetClass *class)
if (GLADE_WIDGET_CLASS_ADD_PLACEHOLDER(class)) {
/* I don't love this. Make it better. Chema */
#warning FIXME
if ((strcmp (class->name, "GtkVBox") == 0) ||
(strcmp (class->name, "GtkHBox") == 0))
class->placeholder_replace = glade_placeholder_replace_box;
@ -184,19 +183,22 @@ glade_widget_class_set_type (GladeWidgetClass *class, const gchar *init_function
return FALSE;
}
/* Disabled for GtkAdjustment, but i'd like to check for this somehow */
#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 FALSE;
}
#endif
class->type = type;
return TRUE;
}
static GladeWidgetClass *
glade_widget_class_new_from_node (XmlParseContext *context, xmlNodePtr node)
GladeWidgetClass *
glade_widget_class_new_from_node (xmlNodePtr node)
{
GladeWidgetClass *class;
xmlNodePtr child;
@ -213,7 +215,7 @@ glade_widget_class_new_from_node (XmlParseContext *context, xmlNodePtr node)
class->name = glade_xml_get_value_string_required (node, GLADE_TAG_NAME, NULL);
class->generic_name = glade_xml_get_value_string_required (node, GLADE_TAG_GENERIC_NAME, NULL);
init_function_name = glade_xml_get_value_string_required (node, GLADE_TAG_GET_TYPE_FUNC, NULL);
init_function_name = glade_xml_get_value_string (node, GLADE_TAG_GET_TYPE_FUNCTION);
if (!init_function_name) {
init_function_name = glade_widget_class_compose_get_type_func (class);
@ -290,7 +292,7 @@ glade_widget_class_new_from_name (const gchar *name)
context = glade_xml_parse_context_new_from_path (file_name, NULL, GLADE_TAG_GLADE_WIDGET_CLASS);
if (context == NULL)
return NULL;
class = glade_widget_class_new_from_node (context, context->doc->children);
class = glade_widget_class_new_from_node (context->doc->children);
glade_xml_parse_context_free (context);
if (!glade_widget_class_create_pixmap (class))
@ -313,16 +315,6 @@ glade_widget_class_get_type (GladeWidgetClass *widget)
return widget->type;
}
void
glade_widget_class_create (GladeWidgetClass *glade_widget)
{
GtkWidget *widget;
widget = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_show (widget);
}
/**
* glade_widget_class_has_queries:
* @class:
@ -383,14 +375,6 @@ glade_widget_class_find_spec (GladeWidgetClass *class, const gchar *name)
glade_widget_class_get_specs (class, &specs, &n_specs);
#if 0
g_print ("Dumping specs for %s\n\n", class->name);
for (i = 0; i < n_specs; i++) {
spec = specs[i];
g_print ("%02d - %s\n", i, spec->name);
}
#endif
for (i = 0; i < n_specs; i++) {
spec = specs[i];

View File

@ -70,6 +70,7 @@ struct _GladeWidgetClassSignal {
};
GladeWidgetClass * glade_widget_class_new_from_name (const gchar *name);
GladeWidgetClass * glade_widget_class_new_from_node (xmlNodePtr node);
GladeWidgetClass * glade_widget_class_get_by_name (const gchar *name);
const gchar * glade_widget_class_get_name (GladeWidgetClass *class);

View File

@ -123,7 +123,7 @@ glade_widget_find_inside_container (GtkWidget *widget, gpointer data_in)
GladeFindInContainerData *data = data_in;
#ifdef DEBUG
g_print ("In find_child_at: %s X:%i Y:%i W:%i H:%i\n"
g_debug ("In find_child_at: %s X:%i Y:%i W:%i H:%i\n"
" so this means that if we are in the %d-%d , %d-%d range. We are ok\n",
gtk_widget_get_name (widget),
widget->allocation.x, widget->allocation.y,
@ -140,7 +140,7 @@ glade_widget_find_inside_container (GtkWidget *widget, gpointer data_in)
&& (widget->allocation.y + widget->allocation.height >= data->y))
{
#ifdef DEBUG
g_print ("Found it!\n");
g_debug ("Found it!\n");
#endif
data->found_child = widget;
}
@ -177,9 +177,9 @@ glade_widget_get_from_event_widget (GtkWidget *event_widget, GdkEventButton *eve
y = event->y;
gdk_window_get_position (event_widget->window, &win_x, &win_y);
#ifdef DEBUG
g_print ("Window [%d,%d]\n", win_x, win_y);
g_print ("\n\nWe want to find the real widget that was clicked at %d,%d\n", x, y);
g_print ("The widget that received the event was \"%s\" a \"%s\" [%d]\n",
g_debug ("Window [%d,%d]\n", win_x, win_y);
g_debug ("\n\nWe want to find the real widget that was clicked at %d,%d\n", x, y);
g_debug ("The widget that received the event was \"%s\" a \"%s\" [%d]\n",
NULL,
gtk_widget_get_name (event_widget),
GPOINTER_TO_INT (event_widget));
@ -189,7 +189,7 @@ glade_widget_get_from_event_widget (GtkWidget *event_widget, GdkEventButton *eve
while (window && window != parent_window) {
gdk_window_get_position (window, &win_x, &win_y);
#ifdef DEBUG
g_print (" adding X:%d Y:%d - We now have : %d %d\n",
g_debug (" adding X:%d Y:%d - We now have : %d %d\n",
win_x, win_y, x + win_x, y + win_y);
#endif
x += win_x;
@ -205,7 +205,7 @@ glade_widget_get_from_event_widget (GtkWidget *event_widget, GdkEventButton *eve
while (GTK_IS_CONTAINER (temp)) {
#ifdef DEBUG
g_print ("\"%s\" is a container, check inside each child\n",
g_debug ("\"%s\" is a container, check inside each child\n",
gtk_widget_get_name (temp));
#endif
data.found_child = NULL;
@ -218,7 +218,7 @@ glade_widget_get_from_event_widget (GtkWidget *event_widget, GdkEventButton *eve
g_assert (found->widget == data.found_child);
} else {
#ifdef DEBUG
g_print ("Temp was not a GladeWidget, it was a %s\n",
g_debug ("Temp was not a GladeWidget, it was a %s\n",
gtk_widget_get_name (temp));
#endif
}
@ -243,7 +243,7 @@ glade_widget_get_from_event_widget (GtkWidget *event_widget, GdkEventButton *eve
#endif
#ifdef DEBUG
g_print ("We found a \"%s\", child at %d,%d\n",
g_debug ("We found a \"%s\", child at %d,%d\n",
gtk_widget_get_name (found->widget), data.x, data.y);
#endif
return found;
@ -267,23 +267,27 @@ glade_widget_button_press (GtkWidget *event_widget, GdkEventButton *event, gpoin
glade_widget = glade_widget_get_from_event_widget (event_widget, event);
#ifdef DEBUG
g_print ("button press for a %s\n", glade_widget->class->name);
g_debug ("button press for a %s\n", glade_widget->class->name);
#endif
if (!glade_widget) {
g_warning ("Button press event but the gladewidget was not found\n");
return FALSE;
}
g_print ("Event button %d\n", event->button);
#ifdef DEBUG
g_debug ("Event button %d\n", event->button);
#endif
if (event->button == 1)
glade_project_selection_set (glade_widget, TRUE);
else if (event->button == 3)
glade_popup_pop (glade_widget, event);
#ifdef DEBUG
else
g_print ("Button press not handled yet.\n");
g_debug ("Button press not handled yet.\n");
#endif
#ifdef DEBUG
g_print ("The widget found was a %s\n", glade_widget->class->name);
g_debug ("The widget found was a %s\n", glade_widget->class->name);
#endif
return FALSE;
@ -294,13 +298,11 @@ static gboolean
glade_widget_button_release (GtkWidget *widget, GdkEventButton *event, gpointer not_used)
{
#ifdef DEBUG
g_print ("button release\n");
g_debug ("button release\n");
#endif
return FALSE;
}
#if 1
/**
* glade_widget_set_default_options:
* @widget:
@ -341,14 +343,16 @@ glade_widget_set_default_options (GladeWidget *widget)
glade_property_changed_choice (property,
glade_property_get_choice (property));
break;
case GLADE_PROPERTY_TYPE_OBJECT:
glade_widget_set_default_options (property->child);
break;
default:
g_warning ("Implement set default for this type\n");
g_warning ("Implement set default for this type [%s]\n", property->class->name);
break;
}
}
}
#endif
static GladeWidget *
glade_widget_register (GladeProject *project, GladeWidgetClass *class, GtkWidget *gtk_widget, const gchar *name, GladeWidget *parent)
@ -523,29 +527,37 @@ glade_widget_create_gtk_widget (GladeProject *project,
name = glade_widget_new_name (project, class);
type = g_type_from_name (class->name);
if (! g_type_is_a (type, GTK_TYPE_WIDGET)) {
if (! g_type_is_a (type, G_TYPE_OBJECT)) {
gchar *text;
g_warning ("Unknown type %s read from glade file.", class->name);
text = g_strdup_printf ("Error, class_new_widget not implemented [%s]\n", class->name);
widget = gtk_label_new (text);
g_free (text);
} else {
widget = gtk_widget_new (type, NULL);
if (g_type_is_a (type, GTK_TYPE_WIDGET))
widget = gtk_widget_new (type, NULL);
else
widget = g_object_new (type, NULL);
}
glade_widget = glade_widget_register (project, class, widget, name, parent);
glade_widget_set_default_options (glade_widget);
/* We need to be able to get to the GladeWidget * from a GtkWidget * */
/* We need to be able to get to the GladeWidget * from a GtkWidget so add
* the GladeWidget pointer to the GtkWidget
*/
gtk_object_set_data (GTK_OBJECT (glade_widget->widget), GLADE_WIDGET_DATA_TAG, glade_widget);
glade_project_add_widget (project, glade_widget);
g_free (name);
if (!g_type_is_a (type, GTK_TYPE_WIDGET))
return glade_widget;
glade_widget_set_contents (glade_widget);
glade_widget_connect_mouse_signals (glade_widget);
glade_widget_connect_draw_signals (glade_widget);
glade_project_add_widget (project, glade_widget);
g_free (name);
return glade_widget;
}
@ -582,7 +594,9 @@ glade_widget_new_from_class_full (GladeWidgetClass *class, GladeProject *project
if (GLADE_WIDGET_CLASS_ADD_PLACEHOLDER (class))
glade_placeholder_add (class, glade_widget, result);
gtk_widget_show (glade_widget->widget);
/* ->widget sometimes contains GtkObjects like a GtkAdjustment for example */
if (GTK_IS_WIDGET (glade_widget->widget))
gtk_widget_show (glade_widget->widget);
if (result)
glade_property_query_result_destroy (result);
@ -627,6 +641,35 @@ glade_widget_get_class (GladeWidget *widget)
}
static GladeProperty *
glade_widget_get_property_from_list (GList *list, GladePropertyClass *class)
{
GladeProperty *property = NULL;
if (list == NULL)
return NULL;
for (; list != NULL; list = list->next) {
property = list->data;
if (property->class == class)
break;
if (property->child != NULL) {
property = glade_widget_get_property_from_list (property->child->properties,
class);
if (property != NULL)
break;
}
}
if (list == NULL) {
g_warning ("Could not find the GladeProperty to load.\n");
return NULL;
}
return property;
}
/**
* glade_widget_get_property_from_class:
* @widget:
@ -640,24 +683,13 @@ GladeProperty *
glade_widget_get_property_from_class (GladeWidget *widget,
GladePropertyClass *property_class)
{
GladeProperty *property = NULL;
GList *list;
list = widget->properties;
for (; list != NULL; list = list->next) {
property = list->data;
if (property->class == property_class)
break;
}
if (list == NULL) {
g_warning ("Could not find the GladeProperty to load\n");
return NULL;
}
return property;
return glade_widget_get_property_from_list (list, property_class);
}
/**
* glade_widget_set_name:
* @widget:

View File

@ -89,6 +89,7 @@ void glade_widget_delete (GladeWidget *widget);
GladeWidget * glade_widget_get_from_gtk_widget (GtkWidget *widget);
G_END_DECLS
#endif /* __GLADE_WIDGET_H__ */

View File

@ -75,6 +75,7 @@ glade_xml_get_value (xmlNodePtr node, const char *name)
xmlFree (val);
return ret;
}
child = node->children;
while (child != NULL) {

View File

@ -6,29 +6,7 @@
<Properties>
<Property ParamSpec="TRUE" Id="label"/>
<Property Name="Stock Button" Id="stock-button">
<Type>Choice</Type>
<Name>Stock Button</Name>
<Tooltip>The GNOME stock button to use</Tooltip>
<Parameters>
<Parameter Key="Default" Value="GTK_RELIEF_NORMAL"/>
</Parameters>
<Choices>
<Choice>
<Name>Normal</Name>
<Symbol>GTK_RELIEF_NORMAL</Symbol>
</Choice>
<Choice>
<Name>Half</Name>
<Symbol>GTK_RELIEF_HALF</Symbol>
</Choice>
<Choice>
<Name>None</Name>
<Symbol>GTK_RELIEF_NONE</Symbol>
</Choice>
</Choices>
</Property>
<Property ParamSpec="TRUE" Id="relief"/>
</Properties>

View File

@ -5,11 +5,16 @@
<Properties>
<Property ParamSpec="TRUE" Id="border-width"/>
<Property ParamSpec="TRUE" Id="label"/>
<Property ParamSpec="TRUE" Id="draw-indicator">
<Parameters>
<Parameter Key="Default" Value="True"/>
</Parameters>
</Property>
<Property ParamSpec="TRUE" Id="active"/>
<Property ParamSpec="TRUE" Id="group"/>
</Properties>
</GladeWidgetClass>
</GladeWidgetClass>

View File

@ -15,19 +15,32 @@
<Property ParamSpec="TRUE" Id="value"/>
<Property Name="Adjustment" Id="adjustment">
<Property ParamSpec="FALSE" Id="adjustment" Name="Adjustment">
<Type>Object</Type>
<GladeObject>
<GladeWidgetClass>
<Name>GtkAdjustment</Name>
<GetTypeFunction>gtk_adjustment_get_type</GetTypeFunction>
<GenericName>adjustment</GenericName>
<Toplevel>False</Toplevel>
<Properties>
<Property ParamSpec="TRUE" Id="climb-rate"/>
<Property ParamSpec="TRUE" Id="digits"/>
<Property ParamSpec="TRUE" Id="numeric"/>
<Property ParamSpec="TRUE" Id="update-policy"/>
<Property ParamSpec="FALSE" Id="minimum" Name="Min">
<Type>Float</Type>
<Parameters>
<Parameter Key="Default" Value="1.23456"/>
</Parameters>
<SetFunction>glade_gtk_adjustment_set_max</SetFunction>
</Property>
<Property ParamSpec="FALSE" Id="maximum" Name="Max">
<Type>Float</Type>
<Parameters>
<Parameter Key="Default" Value="5.43210"/>
</Parameters>
<SetFunction>glade_gtk_adjustment_set_min</SetFunction>
</Property>
</Properties>
</GladeObject>
<!--
</GladeWidgetClass>
<!--
<Parameters>
<Parameter Key="Default" Value="1"/>
<Parameter Key="Min" Value="0"/>

View File

@ -13,9 +13,8 @@
</Query>
</Property>
<Property Id="rows">
<Property Id="rows" Name="Rows">
<Type>Integer</Type>
<Name>Rows</Name>
<Tooltip>The number of rows in the table</Tooltip>
<Parameters>
<Parameter Key="Min" Value="0"/>