Commit 2ddbeeb9 authored by Jose Maria Celorio's avatar Jose Maria Celorio
Browse files

add patches from SHANE BUTLER that implement the signal editor.

other Fixety fixes
parent 1780b6f6
2001-06-27 Chema Celorio <chema@celorio.com>
* src/glade-widget-class.[ch], src/glade-widget.[ch]: Store signals
available to a widget in the GladeWidgetClass and instances and their
handlers in GladeWidget.
* src/glade-editor.[ch], src/glade-signal-editor.[ch]: Add new signal editor
and add provsions for GladeEditor to use.
* src/glade-types.h: Add typedefs for GladeSignalEditor, GladeWidgetSignal
and GladeWidgetClassSignal.
2001-06-27 Chema Celorio <chema@celorio.com>
* src/glade-property-class.c (glade_property_class_get_specs):
......
pixmaps_DATA = \
window.xpm \
button.xpm \
checkbutton.xpm \
vbox.xpm \
hbox.xpm \
label.xpm \
......
......@@ -36,7 +36,8 @@ glade2_SOURCES = \
glade-widget.c \
glade-catalog.c \
glade-choice.c \
glade-editor.c
glade-editor.c \
glade-signal-editor.c
noinst_HEADERS = \
glade.h \
......@@ -45,6 +46,7 @@ noinst_HEADERS = \
glade-parameter.h \
glade-placeholder.h \
glade-editor.h \
glade-signal-editor.h \
glade-palette.h \
glade-cursor.h \
glade-project-window.h \
......
......@@ -24,6 +24,7 @@
#define GLADE_PROPERY_TABLE_ROW_SPACING 2
#include <stdlib.h> /* for atoi and atof */
#include <string.h>
#include "glade.h"
......@@ -31,6 +32,7 @@
#include "glade-widget-class.h"
#include "glade-choice.h"
#include "glade-editor.h"
#include "glade-signal-editor.h"
#include "glade-parameter.h"
#include "glade-project-window.h"
#include "glade-property.h"
......@@ -733,10 +735,22 @@ glade_editor_load_widget_page (GladeEditor *editor, GladeWidgetClass *class)
TRUE, TRUE, 0);
}
static void
glade_editor_load_signal_page (GladeEditor *editor, GladeWidgetClass *class)
{
if (editor->signal_editor == NULL) {
editor->signal_editor = glade_signal_editor_new ();
gtk_box_pack_start (GTK_BOX (editor->vbox_signals), glade_signal_editor_get_widget (editor->signal_editor),
TRUE, TRUE, 0);
}
}
static void
glade_editor_load_class (GladeEditor *editor, GladeWidgetClass *class)
{
glade_editor_load_widget_page (editor, class);
glade_editor_load_signal_page (editor, class);
editor->loaded_class = class;
}
......@@ -997,6 +1011,8 @@ glade_editor_load_item (GladeEditor *editor, GladeWidget *item)
property = list->data;
glade_editor_property_load (property, item);
}
glade_signal_editor_load_widget (editor->signal_editor, item);
}
......
......@@ -64,9 +64,10 @@ struct _GladeEditor
GtkWidget *vbox_common; /* We might not need this pointer. Not yet
* implemented
*/
GtkWidget *vbox_signals; /* We might not need this pointer. Not yet
* implemented.
*/
GtkWidget *vbox_signals; /* Widget from the GladeSignalEditor is placed
* here
*/
GladeSignalEditor *signal_editor;
GList * widget_tables; /* A list of GladeEditorTable. We have a table
* (gtktable) for each GladeWidgetClass, if
......
......@@ -21,6 +21,7 @@
*/
#include <stdlib.h> /* for atoi and atof */
#include <string.h>
#include "glade.h"
#include "glade-xml-utils.h"
......@@ -98,6 +99,20 @@ glade_parameter_get_string (GList *parameters, const gchar *key, gchar **value)
}
}
}
static void
glade_parameter_free (GladeParameter *parameter)
{
g_return_if_fail (parameter->key);
g_return_if_fail (parameter->value);
g_free (parameter->key);
g_free (parameter->value);
parameter->key = NULL;
parameter->value = NULL;
g_free (parameter);
}
GladeParameter *
glade_parameter_new (void)
{
......@@ -127,11 +142,27 @@ glade_parameter_new_from_node (xmlNodePtr node)
}
GList *
glade_parameter_list_new_from_node (xmlNodePtr node)
glade_parameter_list_find_by_key (GList *list, const gchar *key)
{
GladeParameter *parameter;
for (; list != NULL; list = list->next) {
parameter = list->data;
g_return_val_if_fail (parameter->key != NULL, NULL);
if (strcmp (parameter->key, key) == 0)
return list;
}
return NULL;
}
GList *
glade_parameter_list_new_from_node (GList *list, xmlNodePtr node)
{
GladeParameter *parameter;
xmlNodePtr child;
GList *list;
GList *findme;
if (!glade_xml_node_verify (node, GLADE_TAG_PARAMETERS))
return NULL;
......@@ -139,7 +170,6 @@ glade_parameter_list_new_from_node (xmlNodePtr node)
if (child == NULL)
return NULL;
list = NULL;
child = node->children;
while (child != NULL) {
......@@ -149,6 +179,18 @@ glade_parameter_list_new_from_node (xmlNodePtr node)
parameter = glade_parameter_new_from_node (child);
if (parameter == NULL)
return NULL;
/* Is this parameter already there ? just replace
* the pointer and free the old one
*/
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;
}
list = g_list_prepend (list, parameter);
child = child->next;
}
......
......@@ -39,7 +39,7 @@ void glade_parameter_get_boolean (GList *parameters, const gchar *key, gboolean
void glade_parameter_get_string (GList *parameters, const gchar *key, gchar **value);
GList * glade_parameter_list_new_from_node (xmlNodePtr node);
GList * glade_parameter_list_new_from_node (GList *list, xmlNodePtr node);
/* Convenience functions */
GtkAdjustment * glade_parameter_adjustment_new (GList *parameters);
......
......@@ -88,10 +88,10 @@ glade_project_view_find_iter (GtkTreeModel *model,
return gtk_tree_iter_copy (next);
/* Me ? leaking ? nah .... */
#if 1
if (gtk_tree_model_iter_has_child (model, iter)) {
if (gtk_tree_model_iter_has_child (model, next)) {
GtkTreeIter *child = g_new0 (GtkTreeIter, 1);
GtkTreeIter *retval = g_new0 (GtkTreeIter, 1);
gtk_tree_model_iter_children (model, child, iter);
GtkTreeIter *retval = NULL;
gtk_tree_model_iter_children (model, child, next);
retval = glade_project_view_find_iter (model,
child,
findme);
......
......@@ -181,10 +181,11 @@ glade_property_class_get_type_from_spec (GParamSpec *spec)
{
switch (G_PARAM_SPEC_TYPE (spec))
{
#if 0
case G_TYPE_PARAM_INT:
return GLADE_PROPERTY_TYPE_INTEGER;
case G_TYPE_PARAM_FLOAT:
#endif
g_warning ("Float not yet implemented\n");
break;
case G_TYPE_PARAM_BOOLEAN:
return GLADE_PROPERTY_TYPE_BOOLEAN;
case G_TYPE_PARAM_STRING:
......@@ -193,9 +194,9 @@ glade_property_class_get_type_from_spec (GParamSpec *spec)
return GLADE_PROPERTY_TYPE_CHOICE;
default:
g_warning ("Could not determine GladePropertyType from spec");
return GLADE_PROPERTY_TYPE_ERROR;
}
return GLADE_PROPERTY_TYPE_ERROR;
}
static GladeChoice *
......@@ -234,15 +235,55 @@ glade_property_class_get_choices_from_spec (GParamSpec *spec)
return list;
}
static GladeParameter *
glade_property_get_parameter_default_choice (GParamSpec *spec,
GladePropertyClass *class)
static GList *
glade_property_get_parameters_boolean (GParamSpec *spec,
GladePropertyClass *class)
{
GladeParameter *parameter;
gint def;
g_return_val_if_fail (G_IS_PARAM_SPEC_BOOLEAN (spec), NULL);
def = (gint) G_PARAM_SPEC_BOOLEAN (spec)->default_value;
parameter = glade_parameter_new ();
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);
}
static GList *
glade_property_get_parameters_integer (GParamSpec *spec,
GladePropertyClass *class)
{
GladeParameter *parameter;
gint def;
g_return_val_if_fail (G_IS_PARAM_SPEC_INT (spec), NULL);
def = (gint) G_PARAM_SPEC_INT (spec)->default_value;
parameter = glade_parameter_new ();
parameter->key = g_strdup ("Default");
parameter->value = g_strdup_printf ("%i", def);
return g_list_prepend (NULL, parameter);
}
static GList *
glade_property_get_parameters_choice (GParamSpec *spec,
GladePropertyClass *class)
{
GladeParameter *parameter;
GladeChoice *choice = NULL;
GList *list;
gint def;
g_return_val_if_fail (G_IS_PARAM_SPEC_ENUM (spec), NULL);
def = (gint) G_PARAM_SPEC_ENUM (spec)->default_value;
list = class->choices;
......@@ -257,44 +298,64 @@ glade_property_get_parameter_default_choice (GParamSpec *spec,
return NULL;
choice = class->choices->data;
}
parameter = glade_parameter_new ();
parameter->key = g_strdup ("Default");
parameter->value = g_strdup (choice->symbol);
return parameter;
/* The "list" pointer is now used for something else */
list = g_list_prepend (NULL, parameter);
return list;
}
static GList *
glade_property_class_get_parameters_from_spec (GParamSpec *spec,
GladePropertyClass *class)
GladePropertyClass *class,
xmlNodePtr node)
{
GladeParameter *parameter;
GList *parameters = NULL;
xmlNodePtr child;
g_print ("Go %s\n", class->name);
switch (class->type) {
case GLADE_PROPERTY_TYPE_CHOICE:
parameter = glade_property_get_parameter_default_choice (spec,
class);
parameters = g_list_prepend (parameters, parameter);
parameters = glade_property_get_parameters_choice (spec,
class);
break;
case GLADE_PROPERTY_TYPE_TEXT:
break;
case GLADE_PROPERTY_TYPE_INTEGER:
parameters = glade_property_get_parameters_integer (spec,
class);
break;
case GLADE_PROPERTY_TYPE_FLOAT:
break;
case GLADE_PROPERTY_TYPE_BOOLEAN:
parameters = glade_property_get_parameters_boolean (spec,
class);
break;
default:
g_print ("No parameters for %s\n", class->name);
}
/* Get the parameters that are specified on the glade file,
* they can overwrite gtk+ settings. For example the default
* size of a GtkWindow is 0,0 which we need to overwrite.
*/
child = glade_xml_search_child (node, GLADE_TAG_PARAMETERS);
if (child != NULL)
parameters = glade_parameter_list_new_from_node (parameters,
child);
return parameters;
}
static GladePropertyClass *
glade_property_class_new_from_param_spec (const gchar *name, GladeWidgetClass *widget_class)
glade_property_class_new_from_param_spec (const gchar *name,
GladeWidgetClass *widget_class,
xmlNodePtr node)
{
GladePropertyClass *class;
GParamSpec *spec;
......@@ -315,7 +376,7 @@ glade_property_class_new_from_param_spec (const gchar *name, GladeWidgetClass *w
if (class->type == GLADE_PROPERTY_TYPE_CHOICE)
class->choices = glade_property_class_get_choices_from_spec (spec);
class->parameters = glade_property_class_get_parameters_from_spec (spec, class);
class->parameters = glade_property_class_get_parameters_from_spec (spec, class, node);
return class;
}
......@@ -337,10 +398,10 @@ glade_property_class_new_from_node (xmlNodePtr node, GladeWidgetClass *widget_cl
if (name == NULL)
return NULL;
/* Can we load this property from the ParamSpec ? */
/* Should we load this property from the ParamSpec ? */
child = glade_xml_search_child (node, GLADE_TAG_PARAM_SPEC);
if (child) {
property_class = glade_property_class_new_from_param_spec (name, widget_class);
property_class = glade_property_class_new_from_param_spec (name, widget_class, node);
g_free (name);
return property_class;
}
......@@ -363,7 +424,7 @@ glade_property_class_new_from_node (xmlNodePtr node, GladeWidgetClass *widget_cl
/* Get the Parameters */
child = glade_xml_search_child (node, GLADE_TAG_PARAMETERS);
if (child != NULL)
property_class->parameters = glade_parameter_list_new_from_node (child);
property_class->parameters = glade_parameter_list_new_from_node (NULL, child);
glade_parameter_get_boolean (property_class->parameters, "Optional", &property_class->optional);
/* Get the Query */
......
......@@ -21,6 +21,7 @@
*/
#include <stdlib.h> /* for atoi and atof */
#include <string.h>
#include "glade.h"
#include "glade-choice.h"
......
......@@ -2,10 +2,13 @@ typedef struct _GladePaletteSection GladePaletteSection;
typedef struct _GladePalette GladePalette;
typedef struct _GladeEditor GladeEditor;
typedef struct _GladeSignalEditor GladeSignalEditor;
typedef struct _GladeProject GladeProject;
typedef struct _GladeWidget GladeWidget;
typedef struct _GladeWidgetSignal GladeWidgetSignal;
typedef struct _GladeWidgetClass GladeWidgetClass;
typedef struct _GladeWidgetClassSignal GladeWidgetClassSignal;
typedef struct _GladeProperty GladeProperty;
typedef struct _GladePropertyClass GladePropertyClass;
......
......@@ -24,6 +24,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <config.h>
......@@ -72,6 +73,44 @@ glade_widget_class_add_virtual_methods (GladeWidgetClass *class)
}
GList *
glade_widget_class_list_signals (GladeWidgetClass *class)
{
GList *signals;
GType type;
guint count;
guint *sig_ids;
guint num_signals;
GladeWidgetClassSignal *cur;
signals = NULL;
/* FIXME: This should work. Apparently this is because you need to have an
* instance of an object before you can get its type?!? need to fix this
* to use class->type when bighead applys his patch. - shane
*/
type = g_type_from_name (class->name);
g_return_val_if_fail (type != 0, NULL);
while (g_type_is_a (type, GTK_TYPE_OBJECT)) {
if (G_TYPE_IS_INSTANTIATABLE (type) || G_TYPE_IS_INTERFACE (type)) {
sig_ids = g_signal_list_ids (type, &num_signals);
for (count = 0; count < num_signals; count++) {
cur = g_new0 (GladeWidgetClassSignal, 1);
cur->name = (gchar *) g_signal_name (sig_ids[count]);
cur->type = (gchar *) g_type_name (type);
signals = g_list_append (signals, (GladeWidgetClassSignal *) cur);
}
}
type = g_type_parent (type);
}
return signals;
}
static GladeWidgetClass *
glade_widget_class_new_from_node (XmlParseContext *context, xmlNodePtr node)
{
......@@ -91,6 +130,7 @@ glade_widget_class_new_from_node (XmlParseContext *context, xmlNodePtr node)
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);
class->properties = glade_property_class_list_new_from_node (child, class);
class->signals = glade_widget_class_list_signals (class);
if (!class->name ||
!class->icon ||
......
......@@ -50,11 +50,23 @@ struct _GladeWidgetClass {
* editor.
*/
GList *signals; /* List of GladeWidgetClassSignal objects */
void (*placeholder_replace) (GladePlaceholder *placeholder,
GladeWidget *widget,
GladeWidget *parent);
};
/* GladeWidgetClassSignal contains all the info we need for a given signal, such as
* the signal name, and maybe more in the future
*/
struct _GladeWidgetClassSignal {
gchar *name; /* Name of the signal, eg clicked */
gchar *type; /* Name of the object class that this signal belongs to
* eg GtkButton */
};
GladeWidgetClass * glade_widget_class_new_from_name (const gchar *name);
const gchar * glade_widget_class_get_name (GladeWidgetClass *class);
......
......@@ -284,7 +284,7 @@ glade_widget_button_release (GtkWidget *widget, GdkEventButton *event, GladeWidg
}
#if 0
#if 1
/**
* glade_widget_set_default_options:
* @widget:
......@@ -344,21 +344,6 @@ glade_widget_register (GladeProject *project, GladeWidgetClass *class, GtkWidget
if (parent)
parent->children = g_list_prepend (parent->children, glade_widget);
#if 0
glade_widget_set_default_options (glade_widget);
#else
{
static gboolean warned = FALSE;
if (!warned) {
g_print ("Not setting the default options yet\n");
warned = TRUE;
}
}
#endif
/* Add a pointer to the GladeWidget in the GtkWidget */
gtk_object_set_data (GTK_OBJECT (gtk_widget), GLADE_WIDGET_DATA_TAG, glade_widget);
return glade_widget;
}
......@@ -502,7 +487,12 @@ glade_widget_create_gtk_widget (GladeProject *project,
}
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 * */
gtk_object_set_data (GTK_OBJECT (glade_widget->widget), GLADE_WIDGET_DATA_TAG, glade_widget);
/* FIXME */
if ((strcmp (class->name, "GtkLabel") == 0) ||
(strcmp (class->name, "GtkButton") == 0)) {
......@@ -592,7 +582,7 @@ GladeProperty *
glade_widget_get_property_from_class (GladeWidget *widget,
GladePropertyClass *property_class)
{
GladeProperty *property;
GladeProperty *property = NULL;
GList *list;
list = widget->properties;
......
......@@ -40,6 +40,8 @@ struct _GladeWidget {
* property is "Ok".
*/
GList *signals; /* A list of GladeWidgetSignals */
/* Tree Structure */
GladeWidget *parent; /* The parent of this widget, NULL if this is a
* toplevel widget.
......@@ -50,6 +52,14 @@ struct _GladeWidget {
gboolean selected;
};
/* GladeWidgetSignal is a structure that holds information about a signal a
* widget wants for handle / listen for.
*/
struct _GladeWidgetSignal {
gchar *name; /* Signal name eg "clicked" */
gchar *handler; /* Handler function eg "gtk_main_quit" */
gboolean after; /* Connect after TRUE or FALSE */
};
GladeWidget * glade_widget_new_from_class (GladeProject *project,
......
......@@ -2,6 +2,7 @@ widgets_DATA = \
catalog.xml \
gtkwindow.xml \
gtkbutton.xml \
gtkcheckbutton.xml \
gtklabel.xml \
gtkvbox.xml \
gtkhbox.xml \
......
<GladeCatalog>
<GladeWidget>gtkwindow</GladeWidget>
<GladeWidget>gtkbutton</GladeWidget>
<GladeWidget>gtkcheckbutton</GladeWidget>
<GladeWidget>gtklabel</GladeWidget>
<GladeWidget>gtkhbox</GladeWidget>
<GladeWidget>gtkvbox</GladeWidget>
......
......@@ -7,28 +7,6 @@
<Properties>
<Property>
<Type>Integer</Type>
<Name>Border Width</Name>
<Tooltip>The width of the border arround the container</Tooltip>
<GtkArg>border-width</GtkArg>
<Parameters>
<Parameter Key="Min" Value="0"/>
<Parameter Key="Max" Value="10000"/>
<Parameter Key="Default" Value="31"/>
<Parameter Key="StepIncrement" Value="1"/>
<Parameter Key="PageIncrement" Value="10"/>
<Parameter Key="ClibmRate" Value="1"/>
</Parameters>
</Property>
<!--
<Property>
<Name>border-width</Name>
<ParamSpec/>
</Property>
-->
<Property>
<Name>title</Name>
<ParamSpec/>
......@@ -48,41 +26,23 @@
<Name>modal</Name>
<ParamSpec/>
</Property>