Commit f8da4a75 authored by Paolo Borelli's avatar Paolo Borelli

Move a couple of functions where

they belong.
parent 9bfb390e
2003-07-02 Paolo Borelli <pborelli@katamail.com>
* src/glade-property.c: move here and semplify
property_refresh. Move widget property list
creation to widget.c.
* src/glade-widget.c: see above.
2003-06-30 Paolo Borelli <pborelli@katamail.com>
* src/glade-project-window.c: on close, hide the
......
......@@ -92,7 +92,6 @@ glade_property_object_class_init (GladePropertyObjectClass *class)
static void
glade_property_init (GladeProperty *property)
{
property->class = NULL;
property->value = g_new0 (GValue, 1);
property->enabled = TRUE;
......@@ -109,9 +108,6 @@ glade_property_new (void)
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);
GladeProperty *
glade_property_new_from_class (GladePropertyClass *class, GladeWidget *widget)
{
......@@ -161,40 +157,6 @@ glade_property_new_from_class (GladePropertyClass *class, GladeWidget *widget)
return property;
}
static GList *
glade_property_list_new_from_list (GList *list, GladeWidget *widget)
{
GladePropertyClass *property_class;
GladeProperty *property;
GList *new_list = NULL;
for (; list != NULL; list = list->next) {
property_class = list->data;
property = glade_property_new_from_class (property_class, widget);
if (property == NULL)
continue;
property->widget = widget;
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)
{
......@@ -202,9 +164,8 @@ glade_property_get_from_id (GList *settings_list, const gchar *id)
GladeProperty *property;
g_return_val_if_fail (id != NULL, NULL);
list = settings_list;
for (; list != NULL; list = list->next) {
for (list = settings_list; list; list = list->next) {
property = list->data;
g_return_val_if_fail (property, NULL);
g_return_val_if_fail (property->class, NULL);
......@@ -390,7 +351,6 @@ glade_property_set_enum (GladeProperty *property, GladeChoice *choice)
g_return_if_fail (property->value != NULL);
g_return_if_fail (choice != NULL);
g_value_set_enum (property->value, choice->value);
property->loading = TRUE;
......@@ -405,10 +365,12 @@ glade_property_set_enum (GladeProperty *property, GladeChoice *choice)
glade_property_emit_changed (property);
}
void
glade_property_set (GladeProperty *property, const GValue *value)
{
g_return_if_fail (GLADE_IS_PROPERTY (property));
switch (property->class->type) {
case GLADE_PROPERTY_TYPE_BOOLEAN:
glade_property_set_boolean (property,
......@@ -440,7 +402,7 @@ glade_property_set (GladeProperty *property, const GValue *value)
GList * list = NULL;
list = property->class->choices;
for (; list != NULL; list = list->next) {
for (; list; list = list->next) {
choice = list->data;
if (choice->value == g_value_get_enum (value))
break;
......@@ -475,6 +437,12 @@ glade_property_set (GladeProperty *property, const GValue *value)
}
void
glade_property_refresh (GladeProperty *property)
{
glade_property_set (property, property->value);
}
const gchar *
glade_property_get_string (GladeProperty *property)
{
......@@ -544,7 +512,7 @@ glade_property_get_enum (GladeProperty *property)
value = g_value_get_enum (property->value);
list = property->class->choices;
for (; list != NULL; list = list->next) {
for (; list; list = list->next) {
choice = list->data;
if (choice->value == value)
break;
......@@ -565,7 +533,6 @@ glade_property_query_result_set_int (GladePropertyQueryResult *result,
g_hash_table_insert (result->hash, (gchar *)key,
GINT_TO_POINTER (value));
}
void
......@@ -633,8 +600,7 @@ glade_property_write (GladeXmlContext *context, GladeProperty *property)
* the openning and the closing of the property tag */
tmp = glade_property_class_make_string_from_gvalue (property->class,
property->value);
if (tmp == NULL)
{
if (tmp == NULL) {
glade_xml_node_delete (node);
return NULL;
}
......
......@@ -86,6 +86,7 @@ void glade_property_set_double (GladeProperty *property, gdouble val);
void glade_property_set_boolean (GladeProperty *property, gboolean val);
void glade_property_set_unichar (GladeProperty *property, gunichar val);
void glade_property_set_enum (GladeProperty *property, GladeChoice *choice);
void glade_property_refresh (GladeProperty *property);
const gchar * glade_property_get_string (GladeProperty *property);
gint glade_property_get_integer (GladeProperty *property);
......
......@@ -56,6 +56,31 @@ glade_widget_new_name (GladeProject *project, GladeWidgetClass *class)
return glade_project_new_widget_name (project, class->generic_name);
}
static GList *
glade_widget_property_list_from_class (GladeWidgetClass *class,
GladeWidget *widget)
{
GList *list = NULL;
GladePropertyClass *property_class;
GladeProperty *property;
GList *new_list = NULL;
for (list = class->properties; list; list = list->next) {
property_class = list->data;
property = glade_property_new_from_class (property_class, widget);
if (property == NULL)
continue;
property->widget = widget;
new_list = g_list_prepend (new_list, property);
}
new_list = g_list_reverse (new_list);
return new_list;
}
/**
* glade_widget_new:
* @class: The GladeWidgeClass of the GladeWidget
......@@ -74,7 +99,7 @@ glade_widget_new (GladeWidgetClass *class)
widget->widget = NULL;
widget->project = NULL;
widget->class = class;
widget->properties = glade_property_list_new_from_widget_class (class, widget);
widget->properties = glade_widget_property_list_from_class (class, widget);
widget->parent = NULL;
widget->children = NULL;
......@@ -317,61 +342,6 @@ glade_widget_button_release (GtkWidget *widget, GdkEventButton *event, gpointer
return FALSE;
}
static void
glade_property_refresh (GladeProperty *property)
{
switch (property->class->type) {
case GLADE_PROPERTY_TYPE_BOOLEAN:
glade_property_set_boolean (property,
glade_property_get_boolean (property));
break;
case GLADE_PROPERTY_TYPE_UNICHAR:
glade_property_set_unichar (property,
glade_property_get_unichar (property));
break;
case GLADE_PROPERTY_TYPE_FLOAT:
glade_property_set_float (property,
glade_property_get_float (property));
break;
case GLADE_PROPERTY_TYPE_INTEGER:
glade_property_set_integer (property,
glade_property_get_integer (property));
break;
case GLADE_PROPERTY_TYPE_DOUBLE:
glade_property_set_double (property,
glade_property_get_double (property));
break;
case GLADE_PROPERTY_TYPE_STRING:
glade_property_set_string (property,
glade_property_get_string (property));
break;
case GLADE_PROPERTY_TYPE_ENUM:
glade_property_set_enum (property,
glade_property_get_enum (property));
break;
case GLADE_PROPERTY_TYPE_OBJECT:
g_debug(("Set adjustment (refresh) %d\n", GPOINTER_TO_INT (property->child)));
#if 1
#if 0
glade_widget_set_default_options_real (property->child, packing);
#endif
g_debug(("Set directly \n"));
gtk_spin_button_set_adjustment (GTK_SPIN_BUTTON (property->widget->widget),
GTK_ADJUSTMENT (property->child));
g_debug(("DONE : Set directly\n"));
#else
gtk_object_set (GTK_OBJECT (property->widget->widget),
property->class->id,
property->child, NULL);
#endif
g_debug(("Adjustment has been set\n"));
break;
default:
g_warning ("Implement set default for this type [%s]\n", property->class->name);
break;
}
}
/**
* glade_widget_set_default_options:
* @widget:
......@@ -384,8 +354,7 @@ glade_widget_set_default_options_real (GladeWidget *widget, gboolean packing)
GladeProperty *property;
GList *list;
list = widget->properties;
for (; list != NULL; list = list->next) {
for (list = widget->properties; list; list = list->next) {
property = list->data;
if (property->class->packing != packing)
......@@ -402,9 +371,7 @@ glade_widget_set_default_options_real (GladeWidget *widget, gboolean packing)
property->loading = TRUE;
glade_property_refresh (property);
property->loading = FALSE;
}
}
static void
......@@ -551,7 +518,6 @@ glade_widget_connect_edit_signals_with_class (GladeWidget *widget,
}
}
static void
glade_widget_connect_edit_signals (GladeWidget *widget)
{
......@@ -613,7 +579,7 @@ glade_widget_create_gtk_widget (GladeWidget *glade_widget)
class = glade_widget->class;
type = g_type_from_name (class->name);
if (!g_type_is_a (type, G_TYPE_OBJECT)) {
gchar *text;
g_warning ("Unknown type %s read from glade file.", class->name);
......@@ -627,7 +593,7 @@ glade_widget_create_gtk_widget (GladeWidget *glade_widget)
else
widget = g_object_new (type, NULL);
}
glade_widget->widget = widget;
g_signal_connect_swapped (G_OBJECT (widget), "destroy", G_CALLBACK (glade_widget_free), G_OBJECT (glade_widget));
g_object_set_data (G_OBJECT (glade_widget->widget), GLADE_WIDGET_DATA_TAG, glade_widget);
......@@ -821,16 +787,14 @@ glade_widget_query_properties (GladeWidgetClass *class,
hash = g_hash_table_new (g_str_hash, g_str_equal);
list = class->properties;
for (; list != NULL; list = list->next) {
for (list = class->properties; list; list = list->next) {
property_class = list->data;
if (property_class->query) {
spin = glade_widget_append_query (table, property_class, row++);
g_hash_table_insert (hash, property_class->id, spin);
}
}
if (spin == NULL)
{
if (spin == NULL) {
g_hash_table_destroy (hash);
gtk_widget_destroy (GTK_WIDGET (dialog));
return TRUE;
......@@ -925,7 +889,6 @@ glade_widget_new_from_class (GladeWidgetClass *class,
return widget;
}
const gchar *
glade_widget_get_name (GladeWidget *widget)
{
......@@ -957,7 +920,7 @@ glade_widget_get_property_from_list (GList *list, GladePropertyClass *class, gbo
if (list == NULL)
return NULL;
for (; list != NULL; list = list->next) {
for (; list; list = list->next) {
property = list->data;
if (property->class == class)
break;
......@@ -1174,7 +1137,7 @@ glade_widget_write (GladeXmlContext *context, GladeWidget *widget)
/* Write the properties */
list = widget->properties;
for (; list != NULL; list = list->next) {
for (; list; list = list->next) {
property = list->data;
if (property->class->packing)
continue;
......@@ -1186,7 +1149,7 @@ glade_widget_write (GladeXmlContext *context, GladeWidget *widget)
/* Signals */
list = widget->signals;
for (; list != NULL; list = list->next) {
for (; list; list = list->next) {
signal = list->data;
child = glade_signal_write (context, signal);
if (child == NULL)
......@@ -1200,7 +1163,7 @@ glade_widget_write (GladeXmlContext *context, GladeWidget *widget)
else
list = NULL;
for (; list != NULL; list = list->next) {
for (; list; list = list->next) {
gtk_widget = GTK_WIDGET (list->data);
child_widget = glade_widget_get_from_gtk_widget (gtk_widget);
if (!child_widget && !GLADE_IS_PLACEHOLDER (gtk_widget))
......@@ -1209,8 +1172,7 @@ glade_widget_write (GladeXmlContext *context, GladeWidget *widget)
child_tag = glade_xml_node_new (context, GLADE_XML_TAG_CHILD);
glade_xml_node_append_child (node, child_tag);
if (child_widget)
{
if (child_widget) {
/* write the widget */
child = glade_widget_write (context, child_widget);
if (child == NULL)
......@@ -1221,7 +1183,7 @@ glade_widget_write (GladeXmlContext *context, GladeWidget *widget)
/* Append the packing properties */
packing = glade_xml_node_new (context, GLADE_XML_TAG_PACKING);
list2 = child_widget->properties;
for (; list2 != NULL; list2 = list2->next) {
for (; list2; list2 = list2->next) {
GladeXmlNode *packing_property;
property = list2->data;
if (!property->class->packing)
......@@ -1232,13 +1194,10 @@ glade_widget_write (GladeXmlContext *context, GladeWidget *widget)
glade_xml_node_append_child (packing, packing_property);
glade_xml_node_append_child (child_tag, packing);
}
}
else
{
} else {
/* a placeholder */
child = glade_xml_node_new (context, GLADE_XML_TAG_PLACEHOLDER);
glade_xml_node_append_child (child_tag, child);
/* TODO: write the placeholder packing properties */
}
}
......@@ -1433,8 +1392,7 @@ glade_widget_new_child_from_node (GladeXmlNode *node,
child_node = glade_xml_search_child (node, GLADE_XML_TAG_PLACEHOLDER);
if (child_node)
child_widget = glade_placeholder_new (parent);
else
{
else {
/* Get and create the widget */
child_node = glade_xml_search_child_required (node, GLADE_XML_TAG_WIDGET);
if (!child_node)
......@@ -1492,8 +1450,7 @@ glade_widget_new_child_from_node (GladeXmlNode *node,
g_value_set_string_take_ownership (&string_value, value);
g_value_init (&gvalue, G_PARAM_SPEC_VALUE_TYPE (param_spec));
if (g_value_transform (&string_value, &gvalue))
{
if (g_value_transform (&string_value, &gvalue)) {
gtk_container_child_set_property (GTK_CONTAINER (parent->widget), child_widget, id, &gvalue);
g_value_unset (&gvalue);
}
......@@ -1514,3 +1471,4 @@ glade_widget_new_from_node (GladeXmlNode *node, GladeProject *project)
{
return glade_widget_new_from_node_real (node, project, NULL);
}
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