more work on GParamStuff,

i'll start writing ChangeLogs when it starts getting close to beeing complete
This commit is contained in:
Jose Maria Celorio 2001-06-21 03:24:48 +00:00
parent 59be078300
commit 07dee3718f
10 changed files with 226 additions and 84 deletions

View File

@ -26,7 +26,7 @@ dnl ========================================================
dnl Check for gtk-2.0
dnl ========================================================
check_module="gtk+-2.0"
check_version="1.3.6"
check_version="1.3.5"
dnl ====================
check_version_num=`echo "$check_version" | awk 'BEGIN { FS = "."; } { printf "%d", ($1 * 1000 + $2) * 1000 + $3;}'`
AC_MSG_CHECKING(for $check_module library => $check_version)
@ -47,7 +47,7 @@ dnl ========================================================
dnl Check for libxml
dnl ========================================================
check_module="libxml-2.0"
check_version="2.3.11"
check_version="2.3.10"
dnl ====================
check_version_num=`echo "$check_version" | awk 'BEGIN { FS = "."; } { printf "%d", ($1 * 1000 + $2) * 1000 + $3;}'`
AC_MSG_CHECKING(for $check_module library => $check_version)

View File

@ -231,13 +231,6 @@ glade_editor_property_changed_text (GtkWidget *entry,
glade_property_changed_text (property->property, text);
g_return_if_fail (property->property->widget != NULL);
g_return_if_fail (property->property->widget->widget != NULL);
g_return_if_fail (property->property->class->gtk_arg != NULL);
gtk_object_set (GTK_OBJECT (property->property->widget->widget),
property->property->class->gtk_arg, text, NULL);
g_free (text);
}

View File

@ -98,8 +98,7 @@ glade_parameter_get_string (GList *parameters, const gchar *key, gchar **value)
}
}
}
static GladeParameter *
GladeParameter *
glade_parameter_new (void)
{
GladeParameter *parameter;

View File

@ -30,6 +30,8 @@ struct _GladeParameter {
};
GladeParameter * glade_parameter_new (void);
void glade_parameter_get_float (GList *parameters, const gchar *key, gfloat *value);
void glade_parameter_get_integer (GList *parameters, const gchar *key, gint *value);
void glade_parameter_get_boolean (GList *parameters, const gchar *key, gboolean *value);

View File

@ -138,8 +138,12 @@ glade_property_class_get_specs (GladeWidgetClass *class, GParamSpec ***specs, gi
* touse g_type_class_ref ();
*/
object_class = g_type_class_peek (type);
if (object_class == NULL)
g_print ("error\n");
if (object_class == NULL) {
g_warning ("Class peek failed\n");
*specs = NULL;
*n_specs = 0;
return;
}
/* Use private interface for now, fix later */
*specs = object_class->property_specs;
@ -182,9 +186,9 @@ glade_property_class_get_type_from_spec (GParamSpec *spec)
#if 0
case G_TYPE_PARAM_INT:
case G_TYPE_PARAM_FLOAT:
#endif
case G_TYPE_PARAM_BOOLEAN:
break;
#endif
return GLADE_PROPERTY_TYPE_BOOLEAN;
case G_TYPE_PARAM_STRING:
return GLADE_PROPERTY_TYPE_TEXT;
case G_TYPE_PARAM_ENUM:
@ -215,7 +219,6 @@ glade_property_class_get_choices_from_spec (GParamSpec *spec)
GladeChoice *choice;
GEnumClass *class;
GEnumValue value;
GEnumValue default_value;
GList *list = NULL;
gint num;
gint i;
@ -230,12 +233,68 @@ glade_property_class_get_choices_from_spec (GParamSpec *spec)
}
list = g_list_reverse (list);
#warning How can I determine the default value ??
g_print ("NUm is %d, list size is %d\n", num, g_list_length (list));
return list;
}
static GladeParameter *
glade_property_get_parameter_default_choice (GParamSpec *spec,
GladePropertyClass *class)
{
GladeParameter *parameter;
GladeChoice *choice;
GList *list;
gint def;
def = (gint) G_PARAM_SPEC_ENUM (spec)->default_value;
list = class->choices;
for (; list != NULL; list = list->next) {
choice = list->data;
if (choice->value == def)
break;
}
if (list == NULL) {
g_warning ("Could not find the default value for %s\n", spec->nick);
if (class->choices == NULL)
return NULL;
choice = class->choices->data;
}
parameter = glade_parameter_new ();
parameter->key = g_strdup ("Default");
parameter->value = g_strdup (choice->symbol);
return parameter;
}
static GList *
glade_property_class_get_parameters_from_spec (GParamSpec *spec,
GladePropertyClass *class)
{
GladeParameter *parameter;
GList *parameters = NULL;
switch (class->type) {
case GLADE_PROPERTY_TYPE_CHOICE:
parameter = glade_property_get_parameter_default_choice (spec,
class);
parameters = g_list_prepend (parameters, parameter);
break;
case GLADE_PROPERTY_TYPE_TEXT:
break;
case GLADE_PROPERTY_TYPE_INTEGER:
break;
case GLADE_PROPERTY_TYPE_FLOAT:
break;
case GLADE_PROPERTY_TYPE_BOOLEAN:
break;
default:
}
return parameters;
}
static GladePropertyClass *
glade_property_class_new_from_param_spec (const gchar *name, GladeWidgetClass *widget_class)
{
@ -257,6 +316,8 @@ 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);
return class;
}
@ -343,10 +404,8 @@ glade_property_class_list_new_from_node (xmlNodePtr node, GladeWidgetClass *clas
if (!glade_xml_node_verify (child, GLADE_TAG_PROPERTY))
return NULL;
property_class = glade_property_class_new_from_node (child, class);
if (property_class == NULL) {
g_print ("NUll\n");
if (property_class == NULL)
return NULL;
}
list = g_list_prepend (list, property_class);
child = child->next;
}

View File

@ -115,7 +115,8 @@ struct _GladePropertyClass {
* pairs to specify aspects of this property.
* Like the number of "VisibleLines" of a text
* property. Or the range and default values of
* a spin button entry
* a spin button entry. Also the default choice
* for a type == CHOICE
*/
GList *choices; /* list of GladeChoice items. This is only used
* for propeties of type GLADE_PROPERYT_TYPE_CHOICE

View File

@ -163,6 +163,7 @@ glade_property_list_new_from_widget_class (GladeWidgetClass *class,
if (def)
g_free (def);
new_list = g_list_prepend (new_list, property);
}
@ -207,11 +208,24 @@ void
glade_property_changed_text (GladeProperty *property,
const gchar *text)
{
gchar *temp;
g_return_if_fail (property != NULL);
g_return_if_fail (property->value != NULL);
g_free (property->value);
g_return_if_fail (property->widget != NULL);
g_return_if_fail (property->widget->widget != NULL);
temp = property->value;
property->value = g_strdup (text);
g_free (temp);
if (property->class->gtk_arg == NULL) {
g_print ("I don't have a gtk arg for %s\n", property->class->name);
return;
}
gtk_object_set (GTK_OBJECT (property->widget->widget),
property->class->gtk_arg, property->value, NULL);
}
void
@ -242,6 +256,9 @@ glade_property_changed_boolean (GladeProperty *property, gboolean val)
g_free (property->value);
property->value = g_strdup_printf ("%s", val ? GLADE_TAG_TRUE : GLADE_TAG_FALSE);
gtk_object_set (GTK_OBJECT (property->widget->widget),
property->class->gtk_arg, val, NULL);
}
void
@ -249,12 +266,71 @@ glade_property_changed_choice (GladeProperty *property, GladeChoice *choice)
{
g_return_if_fail (property != NULL);
g_return_if_fail (property->value != NULL);
g_return_if_fail (choice != NULL);
g_free (property->value);
property->value = g_strdup_printf ("%s", choice->symbol);
}
const gchar *
glade_property_get_text (GladeProperty *property)
{
g_return_val_if_fail (property != NULL, NULL);
g_return_val_if_fail (property->value != NULL, NULL);
return property->value;
}
gint
glade_property_get_integer (GladeProperty *property)
{
g_return_val_if_fail (property != NULL, 0);
g_return_val_if_fail (property->value != NULL, 0);
return atoi (property->value);
}
gfloat
glade_property_get_float (GladeProperty *property)
{
g_return_val_if_fail (property != NULL, 0.0);
g_return_val_if_fail (property->value != NULL, 0.0);
return atof (property->value);
}
gboolean
glade_property_get_boolean (GladeProperty *property)
{
g_return_val_if_fail (property != NULL, FALSE);
g_return_val_if_fail (property->value != NULL, FALSE);
return (strcmp (property->value, GLADE_TAG_TRUE) == 0);
}
GladeChoice *
glade_property_get_choice (GladeProperty *property)
{
GladeChoice *choice = NULL;
GList *list;
g_return_val_if_fail (property != NULL, NULL);
g_return_val_if_fail (property->value != NULL, NULL);
list = property->class->choices;
for (; list != NULL; list = list->next) {
choice = list->data;
if (strcmp (choice->symbol, property->value) == 0)
break;
}
if (list == NULL)
g_warning ("Cant find the GladePropertyChoice selected\n");
return choice;
}
GladeProperty *
glade_property_get_from_class (GladeWidget *widget,

View File

@ -51,6 +51,13 @@ void glade_property_changed_float (GladeProperty *property, gfloat val);
void glade_property_changed_boolean (GladeProperty *property, gboolean val);
void glade_property_changed_choice (GladeProperty *property, GladeChoice *choice);
const gchar * glade_property_get_text (GladeProperty *property);
gint glade_property_get_integer (GladeProperty *property);
gfloat glade_property_get_float (GladeProperty *property);
gboolean glade_property_get_boolean (GladeProperty *property);
GladeChoice * glade_property_get_choice (GladeProperty *property);
GList * glade_property_list_new_from_widget_class (GladeWidgetClass *class,
GladeWidget *widget);

View File

@ -86,6 +86,50 @@ glade_widget_new (GladeProject *project, GladeWidgetClass *class, GtkWidget *gtk
}
/**
* glade_widget_set_default_options:
* @widget:
*
* Takes care of applying the default values to a newly created widget
**/
static void
glade_widget_set_default_options (GladeWidget *widget)
{
GladeProperty *property;
GList *list;
list = widget->properties;
for (; list != NULL; list = list->next) {
property = list->data;
switch (property->class->type) {
case GLADE_PROPERTY_TYPE_BOOLEAN:
glade_property_changed_boolean (property,
glade_property_get_boolean (property));
break;
case GLADE_PROPERTY_TYPE_FLOAT:
glade_property_changed_float (property,
glade_property_get_float (property));
break;
case GLADE_PROPERTY_TYPE_INTEGER:
glade_property_changed_integer (property,
glade_property_get_integer (property));
break;
case GLADE_PROPERTY_TYPE_TEXT:
glade_property_changed_text (property,
glade_property_get_text (property));
break;
case GLADE_PROPERTY_TYPE_CHOICE:
glade_property_changed_choice (property,
glade_property_get_choice (property));
break;
default:
g_warning ("Implement set default for this type\n");
break;
}
}
}
static GladeWidget *
glade_widget_register (GladeProject *project, GladeWidgetClass *class, GtkWidget *gtk_widget, const gchar *name, GladeWidget *parent)
{
@ -100,7 +144,8 @@ glade_widget_register (GladeProject *project, GladeWidgetClass *class, GtkWidget
if (parent)
parent->children = g_list_prepend (parent->children, glade_widget);
glade_widget_set_default_options (glade_widget);
return glade_widget;
}

View File

@ -26,59 +26,27 @@
<Name>title</Name>
<ParamSpec/>
</Property>
<!--
<Property>
<Type>Text</Type>
<Name>Title</Name>
<Tooltip>The title of the window</Tooltip>
<GtkArg>title</GtkArg>
<Parameters>
<Parameter Key="VisibleLines" Value="1"/>
<Parameter Key="Default" Value=""/>
</Parameters>
</Property>
-->
<Property>
<Name>type</Name>
<ParamSpec/>
</Property>
<Property>
<Type>Choice</Type>
<Name>Position</Name>
<Tooltip>The initial position of the window</Tooltip>
<GtkArg>fixme</GtkArg>
<Parameters>
<Parameter Key="Default" Value="GTK_WIN_POS_NONE"/>
</Parameters>
<Choices>
<Choice>
<Name>None</Name>
<Symbol>GTK_WIN_POS_NONE</Symbol>
</Choice>
<Choice>
<Name>Center</Name>
<Symbol>GTK_WIN_POS_CENTER</Symbol>
</Choice>
<Choice>
<Name>Mouse</Name>
<Symbol>GTK_WIN_POS_MOUSE</Symbol>
</Choice>
</Choices>
<Name>window-position</Name>
<ParamSpec/>
</Property>
<Property>
<Type>Boolean</Type>
<Name>Modal</Name>
<Tooltip>The window is modal</Tooltip>
<GtkArg>fixme</GtkArg>
<Name>modal</Name>
<ParamSpec/>
</Property>
<Property>
<Type>Integer</Type>
<Name>Default Width</Name>
<Tooltip>The default width of the window</Tooltip>
<GtkArg>fixme</GtkArg>
<!-- <GtkArg>fixme</GtkArg> -->
<Parameters>
<Parameter Key="Min" Value="0"/>
<Parameter Key="Max" Value="10000"/>
@ -95,7 +63,7 @@
<Type>Integer</Type>
<Name>Default Height</Name>
<Tooltip>The default height of the window</Tooltip>
<GtkArg>fixme</GtkArg>
<!-- <GtkArg>fixme</GtkArg> -->
<Parameters>
<Parameter Key="Min" Value="0"/>
<Parameter Key="Max" Value="10000"/>
@ -109,41 +77,33 @@
</Property>
<Property>
<Type>Boolean</Type>
<Name>Shrink</Name>
<Tooltip>If the window can be shrunk</Tooltip>
<GtkArg>fixme</GtkArg>
<Name>allow-shrink</Name>
<ParamSpec/>
</Property>
<Property>
<Type>Boolean</Type>
<Name>Grow</Name>
<Tooltip>If the window can be enlarged</Tooltip>
<GtkArg>fixme</GtkArg>
<Parameters>
<Parameter Key="Default" Value="True"/>
</Parameters>
<Name>allow-grow</Name>
<ParamSpec/>
</Property>
<Property>
<Type>Boolean</Type>
<Name>Auto Shrink</Name>
<Tooltip>If the window shrinks automatically</Tooltip>
<GtkArg>fixme</GtkArg>
<Name>auto-shrink</Name>
<ParamSpec/>
</Property>
<!-- Dunno what this does, dunno if we should remove it -->
<Property>
<Type>Text</Type>
<Name>WM Name</Name>
<Tooltip>The name to pass to the window manager</Tooltip>
<GtkArg>fixme</GtkArg>
<!-- <GtkArg>fixme</GtkArg> -->
</Property>
<Property>
<Type>Text</Type>
<Name>WM Class</Name>
<Tooltip>The class name to pass to the window manager</Tooltip>
<GtkArg>fixme</GtkArg>
<!-- <GtkArg>fixme</GtkArg> -->
</Property>
</Properties>