mirror of
https://gitlab.gnome.org/GNOME/glade.git
synced 2025-09-24 00:04:33 -04:00
factor out property_class_new_from_spec
and move list_properties where it belongs.
This commit is contained in:
parent
f8da4a75dd
commit
c9590d728a
@ -1,9 +1,13 @@
|
||||
2003-07-02 Paolo Borelli <pborelli@katamail.com>
|
||||
|
||||
* src/glade-property.c: move here and semplify
|
||||
* src/glade-property.[ch]: move here and semplify
|
||||
property_refresh. Move widget property list
|
||||
creation to widget.c.
|
||||
* src/glade-widget.c: see above.
|
||||
* src/glade-property-class.[ch]: factor out
|
||||
property_class_new_from_spec and move
|
||||
list_properties to widget-class.c.
|
||||
* src/glade-widget-class.c: see above.
|
||||
|
||||
2003-06-30 Paolo Borelli <pborelli@katamail.com>
|
||||
|
||||
|
@ -24,6 +24,10 @@
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmodule.h>
|
||||
|
||||
#include "glade.h"
|
||||
#include "glade-xml-utils.h"
|
||||
#include "glade-choice.h"
|
||||
@ -35,10 +39,6 @@
|
||||
#include "glade-gtk.h"
|
||||
#include "glade-debug.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmodule.h>
|
||||
|
||||
#if 0
|
||||
typedef struct GladePropertyTypeTable {
|
||||
const gchar *xml_tag;
|
||||
@ -115,7 +115,6 @@ glade_property_query_new (void)
|
||||
return query;
|
||||
}
|
||||
|
||||
|
||||
static GladePropertyQuery *
|
||||
glade_query_new_from_node (GladeXmlNode *node)
|
||||
{
|
||||
@ -165,20 +164,20 @@ glade_property_class_new (void)
|
||||
return property_class;
|
||||
}
|
||||
|
||||
#define MY_FREE(foo) if(foo) g_free(foo); foo = NULL
|
||||
static void
|
||||
glade_widget_property_class_free (GladePropertyClass *class)
|
||||
void
|
||||
glade_property_class_free (GladePropertyClass *class)
|
||||
{
|
||||
if (class == NULL)
|
||||
return;
|
||||
|
||||
g_return_if_fail (GLADE_IS_PROPERTY_CLASS (class));
|
||||
|
||||
MY_FREE (class->name);
|
||||
MY_FREE (class->tooltip);
|
||||
MY_FREE (class);
|
||||
g_free (class->name);
|
||||
g_free (class->tooltip);
|
||||
g_free (class);
|
||||
|
||||
class = NULL;
|
||||
}
|
||||
#undef MY_FREE
|
||||
|
||||
static GladePropertyType
|
||||
glade_property_class_get_type_from_spec (GParamSpec *spec)
|
||||
@ -222,6 +221,58 @@ glade_property_class_get_type_from_spec (GParamSpec *spec)
|
||||
return GLADE_PROPERTY_TYPE_ERROR;
|
||||
}
|
||||
|
||||
static GValue *
|
||||
glade_property_class_get_default_from_spec (GParamSpec *spec,
|
||||
GladePropertyClass *class,
|
||||
GladeXmlNode *node)
|
||||
{
|
||||
GValue *value;
|
||||
|
||||
value = g_new0 (GValue, 1);
|
||||
|
||||
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_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;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
static GladeChoice *
|
||||
glade_property_class_choice_new_from_value (GEnumValue value)
|
||||
{
|
||||
@ -419,58 +470,6 @@ glade_property_class_make_gvalue_from_string (GladePropertyClass *property_class
|
||||
return value;
|
||||
}
|
||||
|
||||
static GValue *
|
||||
glade_property_class_get_default_from_spec (GParamSpec *spec,
|
||||
GladePropertyClass *class,
|
||||
GladeXmlNode *node)
|
||||
{
|
||||
GValue *value;
|
||||
|
||||
value = g_new0 (GValue, 1);
|
||||
|
||||
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_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;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
static gchar *
|
||||
glade_property_get_parameter_numeric_min (GParamSpec *spec)
|
||||
{
|
||||
@ -509,7 +508,6 @@ glade_property_get_parameter_numeric_max (GParamSpec *spec)
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
static GList *
|
||||
glade_property_get_parameters_numeric (GParamSpec *spec,
|
||||
GladePropertyClass *class)
|
||||
@ -538,7 +536,66 @@ glade_property_get_parameters_numeric (GParamSpec *spec,
|
||||
return list;
|
||||
}
|
||||
|
||||
GladePropertyClass *
|
||||
glade_property_class_new_from_spec (GParamSpec *spec)
|
||||
{
|
||||
GladePropertyClass *property_class;
|
||||
|
||||
property_class = glade_property_class_new ();
|
||||
|
||||
property_class->type = glade_property_class_get_type_from_spec (spec);
|
||||
property_class->id = g_strdup (spec->name);
|
||||
property_class->name = g_strdup (g_param_spec_get_nick (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);
|
||||
|
||||
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_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;
|
||||
case GLADE_PROPERTY_TYPE_ERROR:
|
||||
break;
|
||||
}
|
||||
|
||||
return property_class;
|
||||
}
|
||||
|
||||
static GValue *
|
||||
glade_property_class_get_default (GladeXmlNode *node, GladePropertyClass *property_class)
|
||||
{
|
||||
GValue *value;
|
||||
gchar *temp;
|
||||
|
||||
temp = glade_xml_get_property_string (node, GLADE_TAG_DEFAULT);
|
||||
|
||||
if (!temp) {
|
||||
/* g_debug(("Temp is NULL, we dont' have a default\n")) */;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
value = glade_property_class_make_gvalue_from_string (property_class, temp);
|
||||
|
||||
g_free (temp);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
#if 0 // do we still need these 2 ?
|
||||
static GList *
|
||||
glade_property_class_get_parameters_from_spec (GParamSpec *spec,
|
||||
GladePropertyClass *class,
|
||||
@ -581,27 +638,6 @@ glade_property_class_get_parameters_from_spec (GParamSpec *spec,
|
||||
return parameters;
|
||||
}
|
||||
|
||||
static GValue *
|
||||
glade_property_class_get_default (GladeXmlNode *node, GladePropertyClass *property_class)
|
||||
{
|
||||
GValue *value;
|
||||
gchar *temp;
|
||||
|
||||
temp = glade_xml_get_property_string (node, GLADE_TAG_DEFAULT);
|
||||
|
||||
if (!temp) {
|
||||
/* g_debug(("Temp is NULL, we dont' have a default\n")) */;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
value = glade_property_class_make_gvalue_from_string (property_class, temp);
|
||||
|
||||
g_free (temp);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* glade_property_class_load_from_param_spec:
|
||||
* @name:
|
||||
@ -659,6 +695,7 @@ glade_property_class_load_from_param_spec (const gchar *name,
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
static gboolean
|
||||
glade_property_class_get_get_function (GladePropertyClass *class, const gchar *function_name)
|
||||
@ -738,7 +775,7 @@ glade_property_class_update_from_node (GladeXmlNode *node,
|
||||
*/
|
||||
if ( glade_xml_get_property_boolean (node, GLADE_TAG_DISABLED, FALSE)) {
|
||||
if (*property_class != NULL) {
|
||||
glade_widget_property_class_free (*property_class);
|
||||
glade_property_class_free (*property_class);
|
||||
*property_class = NULL;
|
||||
}
|
||||
|
||||
@ -771,14 +808,14 @@ glade_property_class_update_from_node (GladeXmlNode *node,
|
||||
/* Get the type */
|
||||
type = glade_xml_get_value_string_required (node, GLADE_TAG_TYPE, widget_class->name);
|
||||
if (type == NULL) {
|
||||
glade_widget_property_class_free (pproperty_class);
|
||||
glade_property_class_free (pproperty_class);
|
||||
pproperty_class = NULL;
|
||||
return;
|
||||
}
|
||||
pproperty_class->type = glade_property_type_str_to_enum (type);
|
||||
g_free (type);
|
||||
if (pproperty_class->type == GLADE_PROPERTY_TYPE_ERROR) {
|
||||
glade_widget_property_class_free (pproperty_class);
|
||||
glade_property_class_free (pproperty_class);
|
||||
pproperty_class = NULL;
|
||||
return;
|
||||
}
|
||||
@ -798,7 +835,7 @@ glade_property_class_update_from_node (GladeXmlNode *node,
|
||||
GladeXmlNode *child;
|
||||
child = glade_xml_search_child_required (node, GLADE_TAG_ENUMS);
|
||||
if (child == NULL) {
|
||||
glade_widget_property_class_free (pproperty_class);
|
||||
glade_property_class_free (pproperty_class);
|
||||
pproperty_class = NULL;
|
||||
return;
|
||||
}
|
||||
@ -806,14 +843,14 @@ glade_property_class_update_from_node (GladeXmlNode *node,
|
||||
pproperty_class->choices = glade_choice_list_new_from_node (child);
|
||||
type_name = glade_xml_get_property_string_required (child, "EnumType", NULL);
|
||||
if (type_name == NULL) {
|
||||
glade_widget_property_class_free (pproperty_class);
|
||||
glade_property_class_free (pproperty_class);
|
||||
pproperty_class = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
type = g_type_from_name (type_name);
|
||||
if (! (type != 0)) {
|
||||
glade_widget_property_class_free (pproperty_class);
|
||||
glade_property_class_free (pproperty_class);
|
||||
pproperty_class = NULL;
|
||||
return;
|
||||
}
|
||||
@ -821,15 +858,14 @@ glade_property_class_update_from_node (GladeXmlNode *node,
|
||||
g_value_init (gvalue, type);
|
||||
default_string = glade_xml_get_property_string (node, GLADE_TAG_DEFAULT);
|
||||
pproperty_class->def = gvalue;
|
||||
glade_widget_property_class_free (*property_class);
|
||||
glade_property_class_free (*property_class);
|
||||
*property_class = pproperty_class;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
/* If the property is an object Load it */
|
||||
if (pproperty_class->type == GLADE_PROPERTY_TYPE_OBJECT) {
|
||||
child = glade_xml_search_child_required (node, GLADE_TAG_GLADE_WIDGET_CLASS);
|
||||
if (child == NULL) {
|
||||
glade_widget_property_class_free (pproperty_class);
|
||||
glade_property_class_free (pproperty_class);
|
||||
pproperty_class = NULL;
|
||||
return;
|
||||
}
|
||||
@ -838,7 +874,7 @@ glade_property_class_update_from_node (GladeXmlNode *node,
|
||||
}
|
||||
|
||||
pproperty_class->def = glade_property_class_get_default (node, pproperty_class);
|
||||
glade_widget_property_class_free (*property_class);
|
||||
glade_property_class_free (*property_class);
|
||||
*property_class = pproperty_class;
|
||||
}
|
||||
|
||||
@ -891,7 +927,6 @@ glade_property_class_update_from_node (GladeXmlNode *node,
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
glade_property_class_list_add_from_node (GladeXmlNode *node,
|
||||
GladeWidgetClass *widget_class,
|
||||
@ -934,52 +969,6 @@ glade_property_class_list_add_from_node (GladeXmlNode *node,
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* glade_property_class_create_label:
|
||||
* @class: The PropertyClass to create the name from
|
||||
@ -1008,87 +997,3 @@ glade_property_class_create_label (GladePropertyClass *class)
|
||||
return label;
|
||||
}
|
||||
|
||||
GList *
|
||||
glade_property_class_list_properties (GladeWidgetClass *class)
|
||||
{
|
||||
GladePropertyClass *property_class;
|
||||
GParamSpec **specs = NULL;
|
||||
GParamSpec *spec;
|
||||
GType last;
|
||||
gint n_specs = 0;
|
||||
gint i;
|
||||
GList *list;
|
||||
|
||||
glade_widget_class_get_specs (class, &specs, &n_specs);
|
||||
|
||||
last = 0;
|
||||
list = NULL;
|
||||
for (i = 0; i < n_specs; i++) {
|
||||
|
||||
spec = specs[i];
|
||||
|
||||
/* We only use the writable properties */
|
||||
if (spec->flags & G_PARAM_WRITABLE) {
|
||||
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) {
|
||||
/* The property type is not supported. That's not an error, as there are
|
||||
* several standard properties that are not supposed to be edited through
|
||||
* the palette (as the "attributes" property of a GtkLabel) */
|
||||
glade_widget_property_class_free (property_class);
|
||||
property_class = NULL;
|
||||
continue;
|
||||
} else if (property_class->type == GLADE_PROPERTY_TYPE_OBJECT) {
|
||||
/* We don't support these properties */
|
||||
glade_widget_property_class_free (property_class);
|
||||
property_class = NULL;
|
||||
continue;
|
||||
} else if (property_class->type == GLADE_PROPERTY_TYPE_ENUM) {
|
||||
property_class->choices = glade_property_class_get_choices_from_spec (spec);
|
||||
}
|
||||
|
||||
if (!g_ascii_strcasecmp (g_type_name (spec->owner_type), "GtkWidget") &&
|
||||
g_ascii_strcasecmp (spec->name, "name")) {
|
||||
property_class->common = TRUE;
|
||||
} else {
|
||||
property_class->common = FALSE;
|
||||
}
|
||||
property_class->optional = FALSE;
|
||||
property_class->update_signals = NULL;
|
||||
property_class->id = g_strdup (spec->name);
|
||||
property_class->name = g_strdup (g_param_spec_get_nick (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);
|
||||
|
||||
switch (property_class->type) {
|
||||
case GLADE_PROPERTY_TYPE_ENUM:
|
||||
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;
|
||||
case GLADE_PROPERTY_TYPE_ERROR:
|
||||
break;
|
||||
}
|
||||
list = g_list_prepend (list, property_class);
|
||||
}
|
||||
}
|
||||
list = g_list_reverse (list);
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,10 +2,9 @@
|
||||
#ifndef __GLADE_PROPERTY_CLASS_H__
|
||||
#define __GLADE_PROPERTY_CLASS_H__
|
||||
|
||||
#include "glade-xml-utils.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
typedef enum {
|
||||
GLADE_PROPERTY_TYPE_BOOLEAN,
|
||||
GLADE_PROPERTY_TYPE_FLOAT,
|
||||
@ -102,8 +101,8 @@ typedef enum {
|
||||
#define GLADE_PROPERTY_CLASS(gpc) ((GladePropertyClass *) gpc)
|
||||
#define GLADE_IS_PROPERTY_CLASS(gpc) (gpc != NULL)
|
||||
|
||||
struct _GladePropertyClass {
|
||||
|
||||
struct _GladePropertyClass
|
||||
{
|
||||
GladePropertyType type; /* The type of property from GladePropertyType
|
||||
*/
|
||||
|
||||
@ -188,10 +187,13 @@ struct _GladePropertyClass {
|
||||
};
|
||||
|
||||
GladePropertyClass * glade_property_class_new (void);
|
||||
GladePropertyClass * glade_property_class_new_from_spec (GParamSpec *spec);
|
||||
|
||||
void glade_property_class_free (GladePropertyClass *class);
|
||||
|
||||
GtkWidget * glade_property_class_create_label (GladePropertyClass *pclass);
|
||||
GtkWidget * glade_property_class_create_input (GladePropertyClass *pclass);
|
||||
GList * glade_property_class_list_properties (GladeWidgetClass *class);
|
||||
|
||||
void glade_property_class_list_add_from_node (GladeXmlNode * node,
|
||||
GladeWidgetClass *class,
|
||||
GList **properties);
|
||||
@ -205,6 +207,7 @@ GValue * glade_property_class_make_gvalue_from_string (GladePropertyClass *prope
|
||||
gchar * glade_property_class_make_string_from_gvalue (GladePropertyClass *property_class,
|
||||
const GValue *value);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GLADE_PROPERTY_CLASS_H__ */
|
||||
|
@ -29,9 +29,6 @@
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "glade.h"
|
||||
#include "glade-xml-utils.h"
|
||||
|
||||
#include <glib/gdir.h>
|
||||
#include <gmodule.h>
|
||||
#include <ctype.h>
|
||||
@ -39,6 +36,8 @@
|
||||
#include <gtk/gtkenums.h> /* This should go away. Chema */
|
||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||
|
||||
#include "glade.h"
|
||||
#include "glade-xml-utils.h"
|
||||
#include "glade-placeholder.h"
|
||||
#include "glade-property.h"
|
||||
#include "glade-property-class.h"
|
||||
@ -83,7 +82,6 @@ glade_widget_class_compose_get_type_func (GladeWidgetClass *class)
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
static GladeWidgetClass *
|
||||
glade_widget_class_new (void)
|
||||
{
|
||||
@ -94,6 +92,7 @@ glade_widget_class_new (void)
|
||||
class->placeholder_replace = NULL;
|
||||
class->type = 0;
|
||||
class->properties = NULL;
|
||||
class->packing_properties = NULL;
|
||||
|
||||
return class;
|
||||
}
|
||||
@ -107,10 +106,10 @@ glade_widget_class_add_virtual_methods (GladeWidgetClass *class)
|
||||
glade_placeholder_add_methods_to_class (class);
|
||||
}
|
||||
|
||||
GList *
|
||||
static GList *
|
||||
glade_widget_class_list_signals (GladeWidgetClass *class)
|
||||
{
|
||||
GList *signals;
|
||||
GList *signals = NULL;
|
||||
GType type;
|
||||
guint count;
|
||||
guint *sig_ids;
|
||||
@ -119,7 +118,6 @@ glade_widget_class_list_signals (GladeWidgetClass *class)
|
||||
|
||||
g_return_val_if_fail (class->type != 0, NULL);
|
||||
|
||||
signals = NULL;
|
||||
type = class->type;
|
||||
while (g_type_is_a (type, GTK_TYPE_OBJECT)) {
|
||||
if (G_TYPE_IS_INSTANTIATABLE (type) || G_TYPE_IS_INTERFACE (type)) {
|
||||
@ -141,8 +139,67 @@ glade_widget_class_list_signals (GladeWidgetClass *class)
|
||||
return signals;
|
||||
}
|
||||
|
||||
static GList *
|
||||
glade_widget_class_list_properties (GladeWidgetClass *class)
|
||||
{
|
||||
GladePropertyClass *property_class;
|
||||
GParamSpec **specs = NULL;
|
||||
GParamSpec *spec;
|
||||
GType last;
|
||||
gint n_specs = 0;
|
||||
gint i;
|
||||
GList *list = NULL;
|
||||
|
||||
g_return_val_if_fail (GLADE_IS_WIDGET_CLASS (class), NULL);
|
||||
|
||||
glade_widget_class_get_specs (class, &specs, &n_specs);
|
||||
|
||||
last = 0;
|
||||
for (i = 0; i < n_specs; i++) {
|
||||
|
||||
spec = specs[i];
|
||||
|
||||
/* We only use the writable properties */
|
||||
if (spec->flags & G_PARAM_WRITABLE) {
|
||||
property_class = glade_property_class_new_from_spec (spec);
|
||||
|
||||
if (property_class->type == GLADE_PROPERTY_TYPE_ERROR) {
|
||||
/* The property type is not supported. That's not an error, as there are
|
||||
* several standard properties that are not supposed to be edited through
|
||||
* the palette (as the "attributes" property of a GtkLabel) */
|
||||
glade_property_class_free (property_class);
|
||||
property_class = NULL;
|
||||
continue;
|
||||
} else if (property_class->type == GLADE_PROPERTY_TYPE_OBJECT) {
|
||||
/* We don't support these properties */
|
||||
glade_property_class_free (property_class);
|
||||
property_class = NULL;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* should this if go into property_class_new_from_spec ? */
|
||||
if (!g_ascii_strcasecmp (g_type_name (spec->owner_type), "GtkWidget") &&
|
||||
g_ascii_strcasecmp (spec->name, "name")) {
|
||||
property_class->common = TRUE;
|
||||
} else {
|
||||
property_class->common = FALSE;
|
||||
}
|
||||
|
||||
property_class->optional = FALSE;
|
||||
property_class->update_signals = NULL;
|
||||
|
||||
list = g_list_prepend (list, property_class);
|
||||
}
|
||||
}
|
||||
|
||||
list = g_list_reverse (list);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
glade_widget_class_set_type (GladeWidgetClass *class, const gchar *init_function_name)
|
||||
glade_widget_class_set_type (GladeWidgetClass *class,
|
||||
const gchar *init_function_name)
|
||||
{
|
||||
GType type;
|
||||
|
||||
@ -163,7 +220,6 @@ glade_widget_class_set_type (GladeWidgetClass *class, const gchar *init_function
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
GladeWidgetClass *
|
||||
glade_widget_class_new_from_node (GladeXmlNode *node)
|
||||
{
|
||||
@ -179,12 +235,11 @@ glade_widget_class_new_from_node (GladeXmlNode *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);
|
||||
|
||||
if (!class->name ||
|
||||
!class->generic_name) {
|
||||
if (!class->name || !class->generic_name) {
|
||||
g_warning ("Invalid XML file. Widget Class %s\n", class->name);
|
||||
return 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);
|
||||
@ -196,18 +251,17 @@ glade_widget_class_new_from_node (GladeXmlNode *node)
|
||||
return NULL;
|
||||
g_free (init_function_name);
|
||||
|
||||
|
||||
/* <Properties> */
|
||||
child = glade_xml_search_child_required (node, GLADE_TAG_PROPERTIES);
|
||||
if (child == NULL)
|
||||
return FALSE;
|
||||
|
||||
class->properties = glade_property_class_list_properties (class);
|
||||
|
||||
class->properties = glade_widget_class_list_properties (class);
|
||||
glade_property_class_list_add_from_node (child, class, &class->properties);
|
||||
|
||||
/* Signals */
|
||||
class->signals = glade_widget_class_list_signals (class);
|
||||
|
||||
|
||||
/* Get the flags */
|
||||
if (glade_xml_get_boolean (node, GLADE_TAG_TOPLEVEL, FALSE))
|
||||
GLADE_WIDGET_CLASS_SET_FLAGS (class, GLADE_TOPLEVEL);
|
||||
@ -336,7 +390,9 @@ glade_widget_class_has_queries (GladeWidgetClass *class)
|
||||
|
||||
/* ParamSpec stuff */
|
||||
void
|
||||
glade_widget_class_get_specs (GladeWidgetClass *class, GParamSpec ***specs, gint *n_specs)
|
||||
glade_widget_class_get_specs (GladeWidgetClass *class,
|
||||
GParamSpec ***specs,
|
||||
gint *n_specs)
|
||||
{
|
||||
GObjectClass *object_class;
|
||||
GType type;
|
||||
@ -385,9 +441,10 @@ glade_widget_class_find_spec (GladeWidgetClass *class, const gchar *name)
|
||||
}
|
||||
|
||||
g_free (specs);
|
||||
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* glade_widget_class_dump_param_specs:
|
||||
* @class:
|
||||
@ -427,7 +484,6 @@ glade_widget_class_dump_param_specs (GladeWidgetClass *class)
|
||||
g_ok_print ("\n");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* glade_widget_class_get_by_name:
|
||||
* @name:
|
||||
@ -445,7 +501,7 @@ glade_widget_class_get_by_name (const gchar *name)
|
||||
g_return_val_if_fail (name != NULL, NULL);
|
||||
|
||||
list = glade_catalog_get_widgets ();
|
||||
for (; list != NULL; list = list->next) {
|
||||
for (; list; list = list->next) {
|
||||
class = list->data;
|
||||
g_return_val_if_fail (class->name != NULL, NULL);
|
||||
if (class->name == NULL)
|
||||
@ -459,7 +515,6 @@ glade_widget_class_get_by_name (const gchar *name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
gboolean
|
||||
glade_widget_class_is (GladeWidgetClass *class, const gchar *name)
|
||||
{
|
||||
@ -541,3 +596,4 @@ glade_widget_class_load_packing_properties (GladeWidgetClass *class)
|
||||
|
||||
g_free (file_name);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user