Commit 740baecc authored by Paolo Borelli's avatar Paolo Borelli

Initial support for properties

of type FLAGS.
parent a5e2f508
2003-07-07 Paolo Borelli <pborelli@katamail.com>
* src/glade.h: add GLADE_PROPERTY_TYPE_FLAGS.
* src/glade-editor.c: ditto.
* src/glade-property.[ch]: ditto.
* src/glade-property-class: ditto.
* src/glade-placeholder: remove unused include.
2003-07-06 Paolo Borelli <pborelli@katamail.com>
* src/glade-widget.c: handle the delete event
......
......@@ -393,11 +393,11 @@ static void
glade_editor_property_changed_boolean (GtkWidget *button,
GladeEditorProperty *property)
{
const gchar * text [] = { GLADE_TAG_NO, GLADE_TAG_YES };
const gchar *text[] = { GLADE_TAG_NO, GLADE_TAG_YES };
GtkWidget *label;
gboolean state;
GValue *val;
g_return_if_fail (property != NULL);
if (property->property->loading)
......@@ -528,6 +528,12 @@ glade_editor_create_input_enum (GladeEditorProperty *property)
return option_menu;
}
static GtkWidget *
glade_editor_create_input_flags (GladeEditorProperty *property)
{
return gtk_label_new ("Fix Me");
}
static GtkWidget *
glade_editor_create_input_text (GladeEditorProperty *property)
{
......@@ -716,6 +722,9 @@ glade_editor_append_item_real (GladeEditorTable *table,
case GLADE_PROPERTY_TYPE_ENUM:
input = glade_editor_create_input_enum (property);
break;
case GLADE_PROPERTY_TYPE_FLAGS:
input = glade_editor_create_input_flags (property);
break;
case GLADE_PROPERTY_TYPE_UNICHAR:
input = glade_editor_create_input_unichar (property);
break;
......@@ -731,7 +740,10 @@ glade_editor_append_item_real (GladeEditorTable *table,
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) {
......@@ -741,11 +753,11 @@ glade_editor_append_item_real (GladeEditorTable *table,
}
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;
}
......@@ -756,9 +768,10 @@ glade_editor_table_append_item (GladeEditorTable *table,
GladeEditorProperty *property;
property = g_new0 (GladeEditorProperty, 1);
property->class = class;
property->children = NULL;
property->input = glade_editor_append_item_real (table, property);
property->property = NULL;
......@@ -1151,6 +1164,12 @@ glade_editor_property_load_enum (GladeEditorProperty *property)
}
}
static void
glade_editor_property_load_flags (GladeEditorProperty *property)
{
glade_implement_me ();
}
static void
glade_editor_property_load_other_widgets (GladeEditorProperty *property)
{
......@@ -1166,7 +1185,7 @@ static void
glade_editor_property_load_boolean (GladeEditorProperty *property)
{
GtkWidget *label;
const gchar * text [] = { GLADE_TAG_NO, GLADE_TAG_YES };
const gchar *text[] = { GLADE_TAG_NO, GLADE_TAG_YES };
gboolean state;
g_return_if_fail (property != NULL);
......@@ -1181,7 +1200,7 @@ glade_editor_property_load_boolean (GladeEditorProperty *property)
label = GTK_BIN (property->input)->child;
g_return_if_fail (GTK_IS_LABEL (label));
gtk_label_set_text (GTK_LABEL (label), text [state]);
g_object_set_data (G_OBJECT (property->input), "user_data", property);
}
......@@ -1279,7 +1298,7 @@ glade_editor_property_load (GladeEditorProperty *property, GladeWidget *widget)
glade_editor_property_load_object (property, widget);
return;
}
property->property = glade_widget_get_property_from_class (widget, class);
g_return_if_fail (property->property != NULL);
......@@ -1306,6 +1325,9 @@ glade_editor_property_load (GladeEditorProperty *property, GladeWidget *widget)
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:
glade_editor_property_load_unichar (property);
break;
......
......@@ -36,7 +36,6 @@
#include "glade-property-class.h"
#include "glade-project.h"
#include "glade-project-window.h"
#include "glade-packing.h"
#include "glade-popup.h"
#include "glade-command.h"
......
......@@ -64,6 +64,8 @@ glade_property_type_str_to_enum (const gchar *str)
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)
......@@ -92,6 +94,8 @@ glade_property_type_enum_to_string (GladePropertyType type)
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:
......@@ -198,6 +202,12 @@ glade_property_class_get_type_from_spec (GParamSpec *spec)
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)) {
/* FIXME: We should implement the "events" property */
if (g_ascii_strcasecmp (spec->name, "events") == 0)
return GLADE_PROPERTY_TYPE_ERROR;
else
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)) {
......@@ -211,8 +221,7 @@ glade_property_class_get_type_from_spec (GParamSpec *spec)
return GLADE_PROPERTY_TYPE_ERROR;
} else {
/* FIXME: We should implement the "events" property */
if (g_ascii_strcasecmp (spec->name, "user-data") &&
g_ascii_strcasecmp (spec->name, "events")) {
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)));
}
......@@ -235,6 +244,10 @@ glade_property_class_get_default_from_spec (GParamSpec *spec,
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);
......@@ -280,7 +293,7 @@ glade_property_class_choice_new_from_value (GEnumValue value)
choice = glade_choice_new ();
choice->name = g_strdup (value.value_nick);
choice->id = g_strdup (value.value_name);
choice->id = g_strdup (value.value_name);
/*
g_debug(("Choice Id is %s\n", choice->id));
......@@ -549,10 +562,14 @@ 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, NULL);
g_return_val_if_fail (property_class->name != NULL, NULL);
switch (property_class->type) {
case GLADE_PROPERTY_TYPE_ENUM:
property_class->choices = glade_property_class_get_choices_from_spec (spec);
break;
case GLADE_PROPERTY_TYPE_FLAGS:
break;
case GLADE_PROPERTY_TYPE_STRING:
break;
case GLADE_PROPERTY_TYPE_INTEGER:
......@@ -607,6 +624,8 @@ glade_property_class_get_parameters_from_spec (GParamSpec *spec,
switch (class->type) {
case GLADE_PROPERTY_TYPE_ENUM:
break;
case GLADE_PROPERTY_TYPE_FLAGS:
break;
case GLADE_PROPERTY_TYPE_STRING:
break;
case GLADE_PROPERTY_TYPE_INTEGER:
......
......@@ -13,6 +13,7 @@ typedef enum {
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
......
......@@ -136,6 +136,7 @@ glade_property_new_from_class (GladePropertyClass *class, GladeWidget *widget)
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:
......@@ -414,6 +415,9 @@ glade_property_set (GladeProperty *property, const GValue *value)
glade_property_set_enum (property, choice);
}
break;
case GLADE_PROPERTY_TYPE_FLAGS:
glade_implement_me ();
break;
case GLADE_PROPERTY_TYPE_OBJECT:
glade_implement_me ();
g_print ("Set adjustment ->%d<-\n", GPOINTER_TO_INT (property->child));
......@@ -434,7 +438,6 @@ glade_property_set (GladeProperty *property, const GValue *value)
g_warning ("Implement set default for this type [%s]\n", property->class->name);
break;
}
}
void
......@@ -599,7 +602,8 @@ glade_property_write (GladeXmlContext *context, GladeProperty *property)
/* convert the value of this property to a string, and put it between
* the openning and the closing of the property tag */
tmp = glade_property_class_make_string_from_gvalue (property->class,
property->value);
property->value);
if (tmp == NULL) {
glade_xml_node_delete (node);
return NULL;
......
......@@ -27,13 +27,8 @@ struct _GladeProperty
* GladeProperty is modifying
*/
GValue *value;
#if 0
gchar *value; /* A string representation of the value. Depending
* on the property->type it can contain an integer
* a "False" or "True" string or a string itself
*/
#endif
GValue *value; /* The value of the property
*/
gboolean enabled; /* Enables is a flag that is used for GladeProperties
* that have the optional flag set to let us know
......@@ -44,8 +39,6 @@ struct _GladeProperty
* widget.
*/
GList *views; /* A list of GladePropertyView items */
GladeWidget *child; /* A GladeProperty of type object has a child */
gboolean loading;
......
......@@ -65,6 +65,7 @@
#define GLADE_TAG_SYMBOL "Symbol"
#define GLADE_TAG_ENUM "Enum"
#define GLADE_TAG_ENUMS "Enums"
#define GLADE_TAG_FLAGS "Flags"
#define GLADE_TAG_FALSE "False"
#define GLADE_TAG_TRUE "True"
#define GLADE_TAG_YES "Yes"
......@@ -86,6 +87,7 @@
#define GLADE_TAG_PARAM_SPEC "ParamSpec"
#define GLADE_TAG_VISIBLE_LINES "VisibleLines"
#define GLADE_ENUM_DATA_TAG "GladeEnumDataTag"
#define GLADE_FLAGS_DATA_TAG "GladeFlagsDataTag"
#define GLADE_TAG_UPDATE_SIGNALS "UpdateSignals"
#define GLADE_TAG_SIGNAL_NAME "SignalName"
#define GLADE_TAG_DEFAULT "Default"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment