Retrieve from gtk the value of packing properties: we now write a correct .glade

file, before all the children of a vbox had position=0.
This commit is contained in:
Paolo Borelli 2003-11-07 16:20:17 +00:00
parent e6462dfd37
commit 583cfcafc2
9 changed files with 90 additions and 133 deletions

View File

@ -1,3 +1,13 @@
2003-11-07 Paolo Borelli <pborelli@katamail.com>
* src/glade-widget.c: when adding the packing properties get their
value from gtk. Remove two unused functions.
* src/glade-command.c: set the packing properties after having
container_add'ed the widget.
* src/glade-property.[ch]: remove get_from_widget, no more needed.
* src/galde-property-class.[ch]: remove class->get_default.
* src/glade-project.c: check the parameters of some functions.
2003-11-06 Joaquin Cuenca Abela <e98cuenc@yahoo.com>
* glade-3.png: restore the good png.

View File

@ -575,8 +575,15 @@ glade_command_create_execute (GladeCommandCreateDelete *me)
glade_widget_set_contents (widget);
if (!GLADE_WIDGET_IS_TOPLEVEL (widget)) {
if (!GTK_WIDGET_TOPLEVEL (widget->widget))
{
GladeWidget *parent;
glade_util_replace_placeholder (placeholder, widget);
/* we can now add the packing properties */
parent = glade_widget_get_parent (widget);
glade_widget_set_packing_properties (widget, parent);
}
glade_project_add_widget (widget->project, widget->widget);
@ -723,7 +730,7 @@ glade_command_create (GladeWidgetClass *class,
if (!project)
project = parent->project;
widget = glade_widget_new_from_class (class, project, parent);
widget = glade_widget_new_from_class (class, project);
/* widget may be null, e.g. the user clicked cancel on a query */
if (widget == NULL)
@ -779,12 +786,14 @@ glade_command_paste_execute (GladeCommandCutPaste *me)
glade_widget_set_contents (widget);
glade_widget_connect_signals (widget);
if (!GLADE_WIDGET_IS_TOPLEVEL (widget)) {
if (!GTK_WIDGET_TOPLEVEL (widget->widget))
{
gtk_widget_ref (GTK_WIDGET (placeholder));
/* we may have changed the parent, regenerate packing properties */
glade_widget_set_packing_properties (widget, parent->class);
glade_util_replace_placeholder (placeholder, widget);
/* we may have changed the parent, regenerate packing properties */
glade_widget_set_packing_properties (widget, parent);
}
glade_project_add_widget (project, widget->widget);
@ -820,6 +829,7 @@ glade_command_cut_execute (GladeCommandCutPaste *me)
gtk_widget_hide (widget->widget);
glade_project_selection_remove (widget->project, widget->widget, TRUE);
glade_project_remove_widget (widget->project, widget->widget);
return TRUE;

View File

@ -357,7 +357,8 @@ glade_project_selection_clear (GladeProject *project, gboolean emit_signal)
if (project->selection == NULL)
return;
for (list = project->selection; list; list = list->next) {
for (list = project->selection; list; list = list->next)
{
widget = list->data;
glade_util_remove_nodes (widget);
}
@ -375,15 +376,16 @@ glade_project_selection_remove (GladeProject *project,
gboolean emit_signal)
{
g_return_if_fail (GLADE_IS_PROJECT (project));
g_return_if_fail (GTK_IS_WIDGET (widget));
if (!glade_util_has_nodes (widget))
return;
glade_util_remove_nodes (widget);
if (project) {
if (project)
{
project->selection = g_list_remove (project->selection, widget);
if (emit_signal)
glade_project_selection_changed (project);
}
@ -395,15 +397,16 @@ glade_project_selection_add (GladeProject *project,
gboolean emit_signal)
{
g_return_if_fail (GLADE_IS_PROJECT (project));
g_return_if_fail (GTK_IS_WIDGET (widget));
if (glade_util_has_nodes (widget))
return;
glade_util_add_nodes (widget);
if (project) {
if (project)
{
project->selection = g_list_prepend (project->selection, widget);
if (emit_signal)
glade_project_selection_changed (project);
}
@ -415,6 +418,7 @@ glade_project_selection_set (GladeProject *project,
gboolean emit_signal)
{
g_return_if_fail (GLADE_IS_PROJECT (project));
g_return_if_fail (GTK_IS_WIDGET (widget));
if (glade_util_has_nodes (widget))
return;
@ -426,6 +430,8 @@ glade_project_selection_set (GladeProject *project,
GList *
glade_project_selection_get (GladeProject *project)
{
g_return_val_if_fail (GLADE_IS_PROJECT (project), NULL);
return project->selection;
}

View File

@ -165,7 +165,6 @@ glade_property_class_new (void)
property_class->optional_default = TRUE;
property_class->common = FALSE;
property_class->packing = FALSE;
property_class->get_default = FALSE;
property_class->is_modified = FALSE;
property_class->query = NULL;
property_class->set_function = NULL;

View File

@ -158,12 +158,7 @@ struct _GladePropertyClass
gboolean common; /* Common properties go in the common tab */
gboolean packing; /* Packing properties go in the packing tab */
gboolean get_default; /* If true, when the default property is applied it is queried
* from the GtkWidget rather than setting it to some value. We need
* this for example for the packing position in a gtkbox, we container
* add the widget, then we query the property to get the position it
* was added into.
*/
gboolean is_modified; /* If true, this property_class has been "modified" from the
* the standard property by a xml file. */

View File

@ -49,8 +49,10 @@ glade_property_get_type (void)
{
static GType type = 0;
if (!type) {
static const GTypeInfo info = {
if (!type)
{
static const GTypeInfo info =
{
sizeof (GladePropertyObjectClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
@ -120,7 +122,8 @@ glade_property_new (GladePropertyClass *class, GladeWidget *widget)
#endif
/* Create an empty default if the class does not specify a default value */
if (!class->def) {
if (!class->def)
{
property->value = glade_property_class_make_gvalue_from_string (class, "");
return property;
}
@ -167,12 +170,15 @@ glade_property_emit_changed (GladeProperty *property)
static void
glade_property_set_property (GladeProperty *property, const GValue *value)
{
if (property->class->packing) {
if (property->class->packing)
{
GladeWidget *parent = glade_widget_get_parent (property->widget);
GtkContainer *container = GTK_CONTAINER (parent->widget);
GtkWidget *child = property->widget->widget;
gtk_container_child_set_property (container, child, property->class->id, value);
} else {
}
else
{
GObject *gobject = G_OBJECT (property->widget->widget);
g_object_set_property (gobject, property->class->id, value);
}
@ -184,8 +190,8 @@ glade_property_set (GladeProperty *property, const GValue *value)
g_return_if_fail (GLADE_IS_PROPERTY (property));
g_return_if_fail (value != NULL);
if (!g_value_type_compatible (G_VALUE_TYPE (property->value),
G_VALUE_TYPE (value))) {
if (!g_value_type_compatible (G_VALUE_TYPE (property->value), G_VALUE_TYPE (value)))
{
g_warning ("Trying to assing an incompatible value to property %s\n",
property->class->id);
return;
@ -200,10 +206,13 @@ glade_property_set (GladeProperty *property, const GValue *value)
property->loading = TRUE;
/* if there is a custom set_property use it*/
if (property->class->set_function) {
if (property->class->set_function)
{
(*property->class->set_function) (G_OBJECT (property->widget->widget),
value);
} else {
}
else
{
glade_property_set_property (property, value);
}
@ -215,12 +224,6 @@ glade_property_set (GladeProperty *property, const GValue *value)
glade_property_emit_changed (property);
}
void
glade_property_refresh (GladeProperty *property)
{
glade_property_set (property, property->value);
}
GladeXmlNode *
glade_property_write (GladeXmlContext *context, GladeProperty *property)
{
@ -237,7 +240,8 @@ glade_property_write (GladeXmlContext *context, GladeProperty *property)
/* we should change each '-' by '_' on the name of the property (<property name="...">) */
tmp = g_strdup (property->class->id);
if (!tmp) {
if (!tmp)
{
glade_xml_node_delete (node);
return NULL;
}
@ -253,7 +257,8 @@ glade_property_write (GladeXmlContext *context, GladeProperty *property)
tmp = glade_property_class_make_string_from_gvalue (property->class,
property->value);
if (!tmp) {
if (!tmp)
{
glade_xml_node_delete (node);
return NULL;
}
@ -282,26 +287,3 @@ glade_property_free (GladeProperty *property)
g_free (property);
}
void
glade_property_get_from_widget (GladeProperty *property)
{
gboolean bool = FALSE;
g_value_reset (property->value);
if (property->class->get_function)
(*property->class->get_function) (G_OBJECT (property->widget->widget), property->value);
else {
switch (property->class->type) {
case GLADE_PROPERTY_TYPE_BOOLEAN:
g_object_get (G_OBJECT (property->widget->widget),
property->class->id, &bool, NULL);
g_value_set_boolean (property->value, bool);
break;
default:
glade_implement_me ();
break;
}
}
}

View File

@ -57,10 +57,7 @@ GladeProperty *glade_property_new (GladePropertyClass *class, GladeWidget *widge
void glade_property_free (GladeProperty *property);
void glade_property_set (GladeProperty *property, const GValue *value);
void glade_property_refresh (GladeProperty *property);
void glade_property_get_from_widget (GladeProperty *property);
void glade_property_set (GladeProperty *property, const GValue *value);
/* XML i/o */
GladeXmlNode *glade_property_write (GladeXmlContext *context, GladeProperty *property);

View File

@ -342,55 +342,6 @@ glade_widget_button_release (GtkWidget *widget, GdkEventButton *event, gpointer
return FALSE;
}
/**
* Set the deafault value to the given list of properties.
*/
static void
glade_widget_set_default_options_real (GList *properties)
{
GladeProperty *property;
GList *list;
for (list = properties; list; list = list->next) {
property = list->data;
/* For some properties, we get the value from the GtkWidget, for example the
* "position" packing property. See g-p-class.h ->get_default. Chema
*/
if (property->class->get_default) {
glade_property_get_from_widget (property);
continue;
}
property->loading = TRUE;
glade_property_refresh (property);
property->loading = FALSE;
}
}
static void
glade_widget_set_default_options (GladeWidget *widget)
{
glade_widget_set_default_options_real (widget->properties);
}
/**
* glade_widget_set_default_packing_options:
* @widget:
*
* We need to have a different function for setting packing options
* because we need to add the widget to the container before we
* apply the packing options.
*
**/
void
glade_widget_set_default_packing_options (GladeWidget *widget)
{
g_return_if_fail (GLADE_IS_WIDGET (widget));
glade_widget_set_default_options_real (widget->packing_properties);
}
static void
glade_widget_connect_mouse_signals (GladeWidget *glade_widget)
{
@ -569,19 +520,33 @@ glade_widget_connect_signals (GladeWidget *widget)
*/
void
glade_widget_set_packing_properties (GladeWidget *widget,
GladeWidgetClass *container_class)
GladeWidget *container)
{
g_return_if_fail (GLADE_IS_WIDGET (widget));
g_return_if_fail (GLADE_IS_WIDGET_CLASS (container_class));
GList *list;
/*
* toplevls do not have packing properties, so should not be
g_return_if_fail (GLADE_IS_WIDGET (widget));
g_return_if_fail (GLADE_IS_WIDGET (container));
/* toplevels do not have packing properties, so should not be
* passed to this function.
*/
g_return_if_fail (!GTK_WIDGET_TOPLEVEL (widget->widget));
g_list_foreach(widget->packing_properties, (GFunc) glade_property_free, NULL);
g_list_free (widget->packing_properties);
widget->packing_properties = glade_widget_properties_from_list (container_class->child_properties, widget);
widget->packing_properties = glade_widget_properties_from_list (container->class->child_properties, widget);
/* update the values of the properties to the ones we get from gtk */
for (list = widget->packing_properties; list; list = list->next)
{
GladeProperty *property = list->data;
g_value_reset (property->value);
gtk_container_child_get_property (GTK_CONTAINER (container->widget),
widget->widget,
property->class->id,
property->value);
}
}
static void
@ -657,7 +622,7 @@ glade_widget_new_for_internal_child (GladeWidgetClass *class,
return NULL;
glade_widget_associate_with_gtk_widget (glade_widget, widget);
glade_widget_set_packing_properties (glade_widget, parent->class);
glade_widget_set_packing_properties (glade_widget, parent);
glade_widget->internal = g_strdup (internal);
return glade_widget;
@ -879,8 +844,7 @@ glade_widget_apply_queried_properties (GladeWidget *widget,
**/
GladeWidget *
glade_widget_new_from_class (GladeWidgetClass *class,
GladeProject *project,
GladeWidget *parent)
GladeProject *project)
{
GladePropertyQueryResult *result = NULL;
GladeWidget *widget;
@ -888,7 +852,8 @@ glade_widget_new_from_class (GladeWidgetClass *class,
g_return_val_if_fail (GLADE_IS_WIDGET_CLASS (class), NULL);
g_return_val_if_fail (GLADE_IS_PROJECT (project), NULL);
if (glade_widget_class_has_queries (class)) {
if (glade_widget_class_has_queries (class))
{
result = glade_property_query_result_new ();
if (!glade_widget_query_properties (class, result))
return NULL;
@ -896,17 +861,12 @@ glade_widget_new_from_class (GladeWidgetClass *class,
widget = glade_widget_new_full (class, project);
/* We know the parent (if we have one), we can add the packing properties */
if (parent)
glade_widget_set_packing_properties (widget, parent->class);
/* If we are a container, add the placeholders */
if (widget->class->fill_empty)
widget->class->fill_empty (widget->widget);
glade_widget_set_default_options (widget);
if (result) {
if (result)
{
glade_widget_apply_queried_properties (widget, result);
glade_property_query_result_destroy (result);
}
@ -1357,8 +1317,9 @@ glade_widget_new_from_node_real (GladeXmlNode *node,
if (!widget)
return NULL;
/* create the packing_properties list, without setting them */
if (parent)
glade_widget_set_packing_properties (widget, parent->class);
widget->packing_properties = glade_widget_properties_from_list (parent->class->child_properties, widget);
glade_widget_fill_from_node (node, widget);

View File

@ -67,19 +67,16 @@ void glade_widget_set_contents (GladeWidget *widget);
void glade_widget_connect_signals (GladeWidget *widget);
void glade_widget_set_packing_properties (GladeWidget *widget,
GladeWidgetClass *container_class);
GladeWidget *container);
GladeWidget *glade_widget_new_from_class (GladeWidgetClass *class,
GladeProject *project,
GladeWidget *parent);
GladeProject *project);
GladeWidget *glade_widget_new_for_internal_child (GladeWidgetClass *class,
GladeWidget *parent,
GtkWidget *widget,
const gchar *internal);
void glade_widget_set_default_packing_options (GladeWidget *widget);
const gchar *glade_widget_get_name (GladeWidget *widget);
GladeWidgetClass *glade_widget_get_class (GladeWidget *widget);