This commit is contained in:
Jose Maria Celorio 2001-06-29 05:52:09 +00:00
parent d79f12694d
commit cc9dfb4d7c
14 changed files with 129 additions and 19 deletions

View File

@ -1,3 +1,12 @@
2001-06-28 Archit Baweja <bighead@crosswinds.net>
* src/glade.h (GLADE_TAB_GET_TYPE_FUNCTION): new #define.
* src/glade-widget-class.c (glade_widget_class_new_from_node): added
code to search for _get_type () function and initialize the GType.
(glade_widget_class_compose_get_type_func): new function.
(glade_widget_class_get_type): new function.
2001-06-27 Chema Celorio <chema@celorio.com>
* src/glade-widget-class.[ch], src/glade-widget.[ch]: Store signals
@ -16,7 +25,7 @@
* missing, mkinstalldirs: Removed, are generated files.
* ChangeLog: Changed the previous date entry to the Gnome's standar one.
2001-06-21 Jonathan Blandford <jrb@webwynk.net>
* src/glade-property-class.c (glade_property_class_get_specs):

View File

@ -185,7 +185,6 @@ glade_parameter_list_new_from_node (GList *list, xmlNodePtr node)
findme = glade_parameter_list_find_by_key (list,
parameter->key);
if (findme) {
g_print ("We foind one, replace it\n");
glade_parameter_free (findme->data);
findme->data = parameter;
child = child->next;

View File

@ -21,6 +21,7 @@
*/
#include <config.h>
#include <string.h>
#include "glade.h"
#include "glade-placeholder.h"

View File

@ -131,8 +131,8 @@ glade_property_class_get_specs (GladeWidgetClass *class, GParamSpec ***specs, gi
{
GObjectClass *object_class;
GType type;
type = gtk_window_get_type ();
type = glade_widget_class_get_type (class);
g_type_class_ref (type); /* hmm */
/* We count on the fact we have an instance, or else we'd have
* touse g_type_class_ref ();
@ -250,8 +250,6 @@ glade_property_get_parameters_boolean (GParamSpec *spec,
parameter->key = g_strdup ("Default");
parameter->value = def ? g_strdup (GLADE_TAG_TRUE) : g_strdup (GLADE_TAG_FALSE);
g_print ("Para %s\n", parameter->value);
return g_list_prepend (NULL, parameter);
}
@ -317,7 +315,6 @@ glade_property_class_get_parameters_from_spec (GParamSpec *spec,
GList *parameters = NULL;
xmlNodePtr child;
g_print ("Go %s\n", class->name);
switch (class->type) {
case GLADE_PROPERTY_TYPE_CHOICE:
parameters = glade_property_get_parameters_choice (spec,
@ -336,7 +333,6 @@ glade_property_class_get_parameters_from_spec (GParamSpec *spec,
class);
break;
default:
g_print ("No parameters for %s\n", class->name);
}
/* Get the parameters that are specified on the glade file,

View File

@ -32,6 +32,8 @@
#include "glade-xml-utils.h"
#include <dirent.h>
#include <gmodule.h>
#include <ctype.h>
#include <gtk/gtkenums.h> /* This should go away. Chema */
#include <gdk-pixbuf/gdk-pixbuf.h>
@ -43,6 +45,32 @@
#include "glade-parameter.h"
#include "glade-widget-class.h"
#if 0 /* Keep arround */
static gchar *
glade_widget_class_compose_get_type_func (GladeWidgetClass *class)
{
gchar *retval;
GString *tmp;
gint i = 1;
tmp = g_string_new (class->name);
while (tmp->str[i]) {
if (isupper (tmp->str[i])) {
tmp = g_string_insert_c (tmp, i, '_');
i+=2;
continue;
}
i++;
}
retval = g_strconcat (g_strdup (tmp->str), "_get_type", NULL);
g_strdown (retval);
g_string_free (tmp, TRUE);
return retval;
}
#endif
static GladeWidgetClass *
glade_widget_class_new (void)
@ -52,6 +80,7 @@ glade_widget_class_new (void)
widget = g_new0 (GladeWidgetClass, 1);
widget->flags = 0;
widget->placeholder_replace = NULL;
widget->type = 0;
return widget;
}
@ -111,12 +140,60 @@ glade_widget_class_list_signals (GladeWidgetClass *class)
return signals;
}
static gboolean
glade_widget_class_set_type (GladeWidgetClass *class, const gchar *init_function_name)
{
static GModule *allsymbols;
guint (*get_type) ();
GType type;
class->type = 0;
g_return_val_if_fail (GLADE_IS_WIDGET_CLASS (class), FALSE);
g_return_val_if_fail (init_function_name != NULL, FALSE);
if (!g_module_supported ()) {
g_warning (_("gmodule support not found. gmodule support is requiered "
"for glade to work"));
return FALSE;
}
if (!allsymbols)
allsymbols = g_module_open (NULL, 0);
if (!g_module_symbol (allsymbols, init_function_name,
(gpointer) &get_type)) {
g_warning (_("We could not find the symbol \"%s\" while trying to load \"%s\""),
init_function_name, class->name);
return FALSE;
}
g_assert (get_type);
type = get_type ();
if (type == 0) {
g_warning(_("Could not get the type from \"%s\" while trying to load \"%s\""), class->name);
return FALSE;
}
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;
}
class->type = type;
return TRUE;
}
static GladeWidgetClass *
glade_widget_class_new_from_node (XmlParseContext *context, xmlNodePtr node)
{
GladeWidgetClass *class;
xmlNodePtr child;
gchar *init_function_name;
if (!glade_xml_node_verify (node, GLADE_TAG_GLADE_WIDGET_CLASS))
return NULL;
@ -129,6 +206,14 @@ 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);
class->icon = glade_xml_get_value_string_required (node, GLADE_TAG_ICON, NULL);
init_function_name = glade_xml_get_value_string_required (node, GLADE_TAG_GET_TYPE_FUNCTION, NULL);
if (!init_function_name)
return FALSE;
if (!glade_widget_class_set_type (class, init_function_name))
return NULL;
g_free (init_function_name);
class->properties = glade_property_class_list_new_from_node (child, class);
class->signals = glade_widget_class_list_signals (class);
@ -160,6 +245,8 @@ glade_widget_class_create_pixmap (GladeWidgetClass *class)
struct stat s;
GtkWidget *widget;
gchar *full_path;
g_return_val_if_fail (GLADE_IS_WIDGET_CLASS (class), FALSE);
widget = gtk_button_new ();
@ -185,7 +272,7 @@ GladeWidgetClass *
glade_widget_class_new_from_name (const gchar *name)
{
XmlParseContext *context;
GladeWidgetClass *widget;
GladeWidgetClass *class;
gchar *file_name;
file_name = g_strconcat (WIDGETS_DIR, "/", name, ".xml", NULL);
@ -193,15 +280,15 @@ 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;
widget = glade_widget_class_new_from_node (context, context->doc->children);
class = glade_widget_class_new_from_node (context, context->doc->children);
glade_xml_parse_context_free (context);
if (!glade_widget_class_create_pixmap (widget))
if (!glade_widget_class_create_pixmap (class))
return NULL;
g_free (file_name);
return widget;
return class;
}
const gchar *
@ -210,6 +297,12 @@ glade_widget_class_get_name (GladeWidgetClass *widget)
return widget->name;
}
GType
glade_widget_class_get_type (GladeWidgetClass *widget)
{
return widget->type;
}
void
glade_widget_class_create (GladeWidgetClass *glade_widget)
{

View File

@ -10,6 +10,7 @@ typedef enum {
} GladeWidgetClassFlags;
#define GLADE_WIDGET_CLASS(gwc) ((GladeWidgetClass *) gwc)
#define GLADE_IS_WIDGET_CLASS(gwc) (gwc != NULL)
#define GLADE_WIDGET_FLAGS(gw) ((GLADE_WIDGET(gw)->class)->flags)
#define GLADE_WIDGET_TOPLEVEL(gw) ((GLADE_WIDGET_FLAGS(gw) & GLADE_TOPLEVEL) != 0)
@ -28,6 +29,8 @@ typedef enum {
*/
struct _GladeWidgetClass {
GType type; /* GType of the widget */
gchar *name; /* Name of the widget, for example GtkButton */
gchar *icon; /* Name of the icon without the prefix, for example
"button" */
@ -70,6 +73,7 @@ struct _GladeWidgetClassSignal {
GladeWidgetClass * glade_widget_class_new_from_name (const gchar *name);
const gchar * glade_widget_class_get_name (GladeWidgetClass *class);
GType glade_widget_class_get_type (GladeWidgetClass *class);
gboolean glade_widget_class_has_queries (GladeWidgetClass *class);
G_END_DECLS

View File

@ -11,6 +11,7 @@ gchar * _ (gchar * name);
#define GLADE_PATH_SEP_STR "/"
#define GLADE_TAG_GLADE_WIDGET_CLASS "GladeWidgetClass"
#define GLADE_TAG_GET_TYPE_FUNCTION "GetTypeFunction"
#define GLADE_TAG_GENERIC_NAME "GenericName"
#define GLADE_TAG_NAME "Name"
#define GLADE_TAG_KEY "Key"

View File

@ -1,5 +1,6 @@
<GladeWidgetClass>
<Name>GtkButton</Name>
<GetTypeFunction>gtk_button_get_type</GetTypeFunction>
<GenericName>button</GenericName>
<Toplevel>False</Toplevel>
<Icon>button</Icon>
@ -59,4 +60,4 @@
</GladeWidgetClass>

View File

@ -1,5 +1,6 @@
<GladeWidgetClass>
<Name>GtkCheckButton</Name>
<GetTypeFunction>gtk_check_button_get_type</GetTypeFunction>
<GenericName>checkbutton</GenericName>
<Toplevel>False</Toplevel>
<Icon>checkbutton</Icon>

View File

@ -1,5 +1,6 @@
<GladeWidgetClass>
<Name>GtkHBox</Name>
<GetTypeFunction>gtk_hbox_get_type</GetTypeFunction>
<GenericName>hbox</GenericName>
<Toplevel>False</Toplevel>
<Placeholder>True</Placeholder>
@ -56,4 +57,4 @@
</Property>
</Properties>
</GladeWidgetClass>
</GladeWidgetClass>

View File

@ -1,5 +1,6 @@
<GladeWidgetClass>
<Name>GtkLabel</Name>
<GetTypeFunction>gtk_label_get_type</GetTypeFunction>
<GenericName>label</GenericName>
<Toplevel>False</Toplevel>
<Icon>label</Icon>
@ -14,4 +15,4 @@
<GtkArg>label</GtkArg>
</Property>
</Properties>
</GladeWidgetClass>
</GladeWidgetClass>

View File

@ -1,5 +1,6 @@
<GladeWidgetClass>
<Name>GtkTable</Name>
<GetTypeFunction>gtk_table_get_type</GetTypeFunction>
<GenericName>table</GenericName>
<Toplevel>False</Toplevel>
<Icon>table</Icon>
@ -97,4 +98,4 @@
</Property>
</Properties>
</GladeWidgetClass>
</GladeWidgetClass>

View File

@ -1,5 +1,6 @@
<GladeWidgetClass>
<Name>GtkVBox</Name>
<GetTypeFunction>gtk_vbox_get_type</GetTypeFunction>
<GenericName>vbox</GenericName>
<Toplevel>False</Toplevel>
<Icon>vbox</Icon>
@ -56,4 +57,4 @@
</Property>
</Properties>
</GladeWidgetClass>
</GladeWidgetClass>

View File

@ -1,5 +1,6 @@
<GladeWidgetClass>
<Name>GtkWindow</Name>
<GetTypeFunction>gtk_window_get_type</GetTypeFunction>
<GenericName>window</GenericName>
<Toplevel>True</Toplevel>
<Icon>window</Icon>
@ -79,4 +80,4 @@
</GladeWidgetClass>