Commit ca932a90 authored by Chema Celorio's avatar Chema Celorio Committed by Jose Maria Celorio
Browse files

handle the case where the property is queried from the gtkwidget v.s.

2001-08-06  Chema Celorio  <chema@celorio.com>

	* src/glade-widget.c (glade_widget_set_default_options_real): handle the case
	where the property is queried from the gtkwidget v.s. setting a default one.
	(glade_widget_free): implement.
	(glade_widget_delete): add content.
	(glade_widget_write): when saving a widget, add the packing properties too.

	* src/glade-signal.c (glade_signal_free): impl.

	* src/glade-signal-editor.c (glade_signal_editor_load_widget): handle a
	widget->class = NULL for clearing the signal editor.

	* src/glade-property.c (glade_property_new_from_class): handle properties
	that the default is fetched from the gtkwidget itself, not set.
	(glade_property_free): implement.

	* src/glade-project.c (glade_project_selection_changed): implement.
	(glade_project_remove_widget_real): impl.
	(glade_project_remove_widget): impl.

	* src/glade-project-window.c (gpw_delete_cb): implement.

	* src/glade-project-view.h (struct _GladeProjectView): add the remove
	signal id to the struct.

	* src/glade-project-view.c (glade_project_view_remove_item): implement
	for "Delete"
	(glade_project_view_remove_widget_cb): ditto
	(glade_project_view_set_project): connect and disconnect ->remove_item

	* src/glade-placeholder.c (glade_placeholder_replace_$x): where
	x are all the containers. Modify this functions so that we can
	use them to replace a placeholder with a widget and the other
	way arround. We need this when we delete a widget and want to
	put a placeholder where the widget was.

	* src/glade-packing.c (glade_packing_container_set_flag): impl.
	(glade_packing_container_set_integer): impl.
	(glade_packing_container_set_boolean): impl.
	(glade_packing_table_set_flag): impl.
	(glade_packing_table_set_integer): impl.
	(glade_packing_box_set_boolean): impl.
	(glade_packing_box_set_integer): impl.
	(glade_packing_box_position_get): impl.
	(glade_packing_box_position_set): when setting the pos of a child update the
	property->value of the rest, cause it has (most likely) changed.
	(table_props): add the rest of the properties
	(box_props): ditto

	* src/glade-editor.c (glade_editor_load_widget_page): handle a NULL class to
	clear the page
	(glade_editor_load_common_page): ditto
	(glade_editor_load_item): ditto
	(glade_editor_select_item_real): ditto
parent 37e38612
## Process this file with automake to produce Makefile.in
SUBDIRS=tests
bin_PROGRAMS = glade2
......
......@@ -372,7 +372,7 @@ glade_editor_property_changed_boolean (GtkWidget *button,
gboolean state;
g_return_if_fail (property != NULL);
if (property->loading)
return;
......@@ -755,12 +755,6 @@ glade_editor_load_widget_page (GladeEditor *editor, GladeWidgetClass *class)
GtkContainer *container;
GList *list;
table = glade_editor_get_table_from_class (editor, class, FALSE);
if (table == NULL)
table = glade_editor_table_create (editor, class, FALSE);
g_return_if_fail (table != NULL);
/* Remove the old table that was in this container */
container = GTK_CONTAINER (editor->vbox_widget);
list = gtk_container_children (container);
......@@ -771,6 +765,15 @@ glade_editor_load_widget_page (GladeEditor *editor, GladeWidgetClass *class)
gtk_container_remove (container, widget);
}
if (!class)
return;
table = glade_editor_get_table_from_class (editor, class, FALSE);
if (table == NULL)
table = glade_editor_table_create (editor, class, FALSE);
g_return_if_fail (table != NULL);
/* Attach the new table */
gtk_box_pack_start (GTK_BOX (editor->vbox_widget), table->table_widget,
TRUE, TRUE, 0);
......@@ -783,12 +786,6 @@ glade_editor_load_common_page (GladeEditor *editor, GladeWidgetClass *class)
GtkContainer *container;
GList *list;
table = glade_editor_get_table_from_class (editor, class, TRUE);
if (table == NULL)
table = glade_editor_table_create (editor, class, TRUE);
g_return_if_fail (table != NULL);
/* Remove the old table that was in this container */
container = GTK_CONTAINER (editor->vbox_common);
list = gtk_container_children (container);
......@@ -799,6 +796,16 @@ glade_editor_load_common_page (GladeEditor *editor, GladeWidgetClass *class)
gtk_container_remove (container, widget);
}
if (!class)
return;
table = glade_editor_get_table_from_class (editor, class, TRUE);
if (table == NULL)
table = glade_editor_table_create (editor, class, TRUE);
g_return_if_fail (table != NULL);
/* Attach the new table */
gtk_box_pack_start (GTK_BOX (editor->vbox_common), table->table_widget,
TRUE, TRUE, 0);
......@@ -1139,6 +1146,10 @@ glade_editor_load_packing_page (GladeEditor *editor, GladeWidget *widget)
for (; list; list = list->next)
g_free (list->data);
old_props = NULL;
old = NULL;
if (!widget)
return;
/* Now add the new properties */
table = glade_editor_table_new (widget->class);
......@@ -1171,12 +1182,19 @@ glade_editor_load_item (GladeEditor *editor, GladeWidget *item)
GList *list;
/* Load the GladeWidgetClass */
class = item->class;
class = item ? item->class : NULL;
if (editor->loaded_class != class)
glade_editor_load_class (editor, class);
editor->loaded_widget = item;
glade_editor_load_packing_page (editor, item);
glade_signal_editor_load_widget (editor->signal_editor, item);
if (!item)
return;
/* Load each GladeEditorProperty */
table = glade_editor_get_table_from_class (editor, class, FALSE);
list = table->properties;
......@@ -1184,7 +1202,7 @@ glade_editor_load_item (GladeEditor *editor, GladeWidget *item)
property = list->data;
glade_editor_property_load (property, item);
}
/* Load each GladeEditorProperty for the common tab*/
table = glade_editor_get_table_from_class (editor, class, TRUE);
list = table->properties;
......@@ -1193,10 +1211,6 @@ glade_editor_load_item (GladeEditor *editor, GladeWidget *item)
glade_editor_property_load (property, item);
}
/* Load the Packin tab */
glade_editor_load_packing_page (editor, item);
glade_signal_editor_load_widget (editor->signal_editor, item);
}
......@@ -1212,6 +1226,14 @@ glade_editor_load_item (GladeEditor *editor, GladeWidget *item)
/**
* glade_editor_select_item_real:
* @editor:
* @widget: the widget to load into the editor. Can be NULL if we want
* to clear the editor.
*
* Select an item and load it into the editor
**/
static void
glade_editor_select_item_real (GladeEditor *editor, GladeWidget *widget)
{
......@@ -1222,6 +1244,9 @@ glade_editor_select_item_real (GladeEditor *editor, GladeWidget *widget)
glade_editor_load_item (editor, widget);
if (!widget)
return;
editor->loading = TRUE;
table = glade_editor_get_table_from_class (editor, widget->class, FALSE);
g_return_if_fail (table != NULL);
......@@ -1233,9 +1258,7 @@ void
glade_editor_select_widget (GladeEditor *editor, GladeWidget *widget)
{
g_return_if_fail (GLADE_IS_EDITOR (editor));
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_WIDGET (widget->widget));
gtk_signal_emit (GTK_OBJECT (editor),
glade_editor_signals [SELECT_ITEM], widget);
}
......
......@@ -39,7 +39,7 @@ glade_gtk_entry_set_text (GObject *object, const gchar *text)
static void
glade_gtk_entry_get_text (GObject *object)
{
g_print ("IMplement get text functikon\n");
glade_implement_me ();
}
static void
......@@ -160,16 +160,20 @@ glade_gtk_adjustment_set_page_size (GObject *object, const gchar *string)
static void
glade_gtk_vbox_get_size (GObject *object, const gchar *string)
{
g_print ("Get size\n");
glade_implement_me ();
}
static void
glade_gtk_vbox_set_size (GObject *object, const gchar *string)
{
g_print ("Set size\n");
glade_implement_me ();
}
/* ================ Temp hack =================== */
/* We have this table, but what we should do is use gmodule for this,
* however this requires that we link with libtool cause right now
* we are loosing the symbols. Chema
*/
typedef struct _GladeGtkFunction GladeGtkFunction;
struct _GladeGtkFunction {
......@@ -182,13 +186,14 @@ GladeGtkFunction functions [] = {
{"glade_gtk_entry_get_text", &glade_gtk_entry_get_text},
{"glade_gtk_option_menu_set_items", &glade_gtk_option_menu_set_items},
{"glade_gtk_progress_bar_set_format", &glade_gtk_progress_bar_set_format},
{"glade_gtk_vbox_set_size", &glade_gtk_vbox_set_size},
{"glade_gtk_vbox_get_size", &glade_gtk_vbox_get_size},
{"glade_gtk_adjustment_set_max", &glade_gtk_adjustment_set_max},
{"glade_gtk_adjustment_set_min", &glade_gtk_adjustment_set_min},
{"glade_gtk_adjustment_set_step_increment", &glade_gtk_adjustment_set_step_increment},
{"glade_gtk_adjustment_set_page_increment", &glade_gtk_adjustment_set_page_increment},
{"glade_gtk_adjustment_set_page_size", &glade_gtk_adjustment_set_page_size},
{"glade_gtk_vbox_set_size", &glade_gtk_vbox_set_size},
{"glade_gtk_vbox_get_size", &glade_gtk_vbox_get_size},
};
static gpointer
......
......@@ -7,6 +7,9 @@ G_BEGIN_DECLS
gboolean glade_gtk_get_set_function_hack (GladePropertyClass *class, const gchar *name);
gboolean glade_gtk_get_get_function_hack (GladePropertyClass *class, const gchar *name);
/* Remove !! */
gpointer glade_gtk_get_function (const gchar *name);
G_END_DECLS
#endif /* __GLADE_GTK_H__ */
......@@ -21,6 +21,7 @@
*/
#include <string.h>
#include <stdlib.h>
#include "glade.h"
#include "glade-packing.h"
......@@ -32,52 +33,199 @@
GList *table_properties = NULL;
GList *box_properties = NULL;
/* ---------------------------------- container child properties ------------------------------ */
static void
glade_packing_x_expand_set (GObject *object, const gchar *value)
glade_packing_container_set_flag (GtkContainer *container,
GtkWidget *widget,
gboolean value,
const gchar *prop,
guint flag)
{
g_print ("X expand set %s\n", value);
GValue gvalue = { 0, };
guint old;
guint new;
g_value_init (&gvalue, G_TYPE_UINT);
gtk_container_child_get_property (container,
widget,
prop,
&gvalue);
old = g_value_get_uint (&gvalue);
/* Clear the old flag */
new = old & (~flag);
/* Set it */
new |= (value ? flag : 0);
g_value_set_uint (&gvalue, new);
gtk_container_child_set_property (container,
widget,
prop,
&gvalue);
}
static void
glade_packing_container_set_integer (GtkContainer *container,
GtkWidget *widget,
gboolean value,
const gchar *property)
{
GValue gvalue = { 0, };
g_value_init (&gvalue, G_TYPE_UINT);
g_value_set_uint (&gvalue, value);
gtk_container_child_set_property (container,
widget,
property,
&gvalue);
}
static void
glade_packing_container_set_boolean (GtkContainer *container,
GtkWidget *widget,
gboolean value,
const gchar *property)
{
GValue gvalue = { 0, };
g_value_init (&gvalue, G_TYPE_BOOLEAN);
g_value_set_boolean (&gvalue, value);
gtk_container_child_set_property (container,
widget,
property,
&gvalue);
}
/* ---------------------------------------- Table ---------------------------*/
static void
glade_packing_table_set_flag (GObject *object, const gchar *value, const gchar *prop, guint flag)
{
GladeWidget *glade_widget;
GtkWidget *widget;
GtkTable *table;
gboolean val;
g_return_if_fail (value != NULL);
widget = GTK_WIDGET (object);
g_return_if_fail (GTK_IS_WIDGET (widget));
glade_widget = glade_widget_get_from_gtk_widget (widget);
g_return_if_fail (GLADE_IS_WIDGET (glade_widget));
table = GTK_TABLE (glade_widget->parent->widget);
g_return_if_fail (GTK_IS_TABLE (table));
val = (strcmp (value, GLADE_TAG_TRUE) == 0) ? TRUE : FALSE;
glade_packing_container_set_flag (GTK_CONTAINER (table), widget,
val, prop, flag);
}
static void
glade_packing_table_set_integer (GObject *object, const gchar *value, const gchar *prop)
{
GladeWidget *glade_widget;
GtkWidget *widget;
GtkTable *table;
gboolean val;
g_return_if_fail (value != NULL);
widget = GTK_WIDGET (object);
g_return_if_fail (GTK_IS_WIDGET (widget));
glade_widget = glade_widget_get_from_gtk_widget (widget);
g_return_if_fail (GLADE_IS_WIDGET (glade_widget));
table = GTK_TABLE (glade_widget->parent->widget);
g_return_if_fail (GTK_IS_TABLE (table));
val = atoi (value);
glade_packing_container_set_integer (GTK_CONTAINER (table), widget,
val, prop);
}
static void
glade_packing_table_x_expand_set (GObject *object, const gchar *value)
{
glade_packing_table_set_flag (object, value, "x_options", GTK_EXPAND);
}
static void
glade_packing_y_expand_set (GObject *object, const gchar *value)
glade_packing_table_y_expand_set (GObject *object, const gchar *value)
{
g_print ("Y expand set %s\n", value);
glade_packing_table_set_flag (object, value, "y_options", GTK_EXPAND);
}
static void
glade_packing_x_shrink_set (GObject *object, const gchar *value)
glade_packing_table_x_shrink_set (GObject *object, const gchar *value)
{
g_print ("X shrink set %s\n", value);
glade_packing_table_set_flag (object, value, "x_options", GTK_SHRINK);
}
static void
glade_packing_y_shrink_set (GObject *object, const gchar *value)
glade_packing_table_y_shrink_set (GObject *object, const gchar *value)
{
g_print ("Y shrink set %s\n", value);
glade_packing_table_set_flag (object, value, "y_options", GTK_SHRINK);
}
static void
glade_packing_x_fill_set (GObject *object, const gchar *value)
glade_packing_table_x_fill_set (GObject *object, const gchar *value)
{
glade_packing_table_set_flag (object, value, "x_options", GTK_FILL);
}
static void
glade_packing_table_y_fill_set (GObject *object, const gchar *value)
{
g_print ("X fill set %s\n", value);
glade_packing_table_set_flag (object, value, "y_options", GTK_FILL);
}
static void
glade_packing_y_fill_set (GObject *object, const gchar *value)
glade_packing_table_padding_h_set (GObject *object, const gchar *value)
{
g_print ("Y fill set %s\n", value);
glade_packing_table_set_integer (object, value, "x_padding");
}
static void
glade_packing_expand_set (GObject *object, const gchar *value)
glade_packing_table_padding_v_set (GObject *object, const gchar *value)
{
glade_packing_table_set_integer (object, value, "y_padding");
}
static void
glade_packing_table_cell_x_set (GObject *object, const gchar *value)
{
glade_implement_me ();
}
static void
glade_packing_table_cell_y_set (GObject *object, const gchar *value)
{
glade_implement_me ();
}
static void
glade_packing_table_span_x_set (GObject *object, const gchar *value)
{
glade_implement_me ();
}
static void
glade_packing_table_span_y_set (GObject *object, const gchar *value)
{
glade_implement_me ();
}
/* --------------------- box ----------------------------------- */
static void
glade_packing_box_set_boolean (GObject *object, const gchar *value, const gchar *property)
{
GladeWidget *glade_widget;
GtkBox *box;
GtkWidget *widget;
gboolean expand, fill;
gint padding;
GtkPackType pack_type;
GtkBox *box;
gboolean val;
widget = GTK_WIDGET (object);
g_return_if_fail (GTK_IS_WIDGET (widget));
glade_widget = glade_widget_get_from_gtk_widget (widget);
......@@ -86,24 +234,22 @@ glade_packing_expand_set (GObject *object, const gchar *value)
g_return_if_fail (GTK_IS_BOX (box));
gtk_box_query_child_packing (box, widget,
&expand, &fill, &padding, &pack_type);
expand = (strcmp (value, GLADE_TAG_TRUE) == 0);
val = (strcmp (value, GLADE_TAG_TRUE) == 0) ? TRUE : FALSE;
gtk_box_set_child_packing (box, widget,
expand, fill, padding, pack_type);
glade_packing_container_set_boolean (GTK_CONTAINER (box),
widget,
val,
property);
}
static void
glade_packing_fill_set (GObject *object, const gchar *value)
glade_packing_box_set_integer (GObject *object, const gchar *value,
const gchar *property)
{
GladeWidget *glade_widget;
GtkBox *box;
GtkWidget *widget;
gboolean expand, fill;
gint padding;
GtkPackType pack_type;
gint val;
widget = GTK_WIDGET (object);
g_return_if_fail (GTK_IS_WIDGET (widget));
......@@ -113,24 +259,119 @@ glade_packing_fill_set (GObject *object, const gchar *value)
g_return_if_fail (GTK_IS_BOX (box));
gtk_box_query_child_packing (box, widget,
&expand, &fill, &padding, &pack_type);
val = atoi (value);
glade_packing_container_set_integer (GTK_CONTAINER (box),
widget,
val,
property);
}
/**
* glade_packing_expand_set:
* @object:
* @value:
*
* Sets the expand property of a widget inside a Gtk[HV]Box
**/
static void
glade_packing_box_expand_set (GObject *object, const gchar *value)
{
glade_packing_box_set_boolean (object, value, "expand");
}
/**
* glade_packing_fill_set:
* @object:
* @value:
*
* Sets the fill property of a widget inside a Gtk[VH]Box
**/
static void
glade_packing_box_fill_set (GObject *object, const gchar *value)
{
glade_packing_box_set_boolean (object, value, "fill");
}
fill = (strcmp (value, GLADE_TAG_TRUE) == 0);
/**
* glade_packing_pack_start_set:
* @object:
* @value:
*
* Sets the pack_start property for a widget inside a Gtk[HV]Box
**/
static void
glade_packing_box_pack_start_set (GObject *object, const gchar *value)
{
gchar *temp;
/* Reverse value, because pack start is an enum, not a boolean.
* Chema
*/
if (strcmp (value, GLADE_TAG_TRUE) == 0)
temp = g_strdup (GLADE_TAG_FALSE);
else
temp = g_strdup (GLADE_TAG_TRUE);
glade_packing_box_set_boolean (object, temp, "pack_type");
gtk_box_set_child_packing (box, widget,
expand, fill, padding, pack_type);
g_free (temp);
}
/**
* glade_packing_padding_set:
* @object:
* @value:
*
* Sets the padding for widgets inside a GtkVBox or GtkHBox
**/
static void
glade_packing_pack_start_set (GObject *object, const gchar *value)
glade_packing_box_padding_set (GObject *object, const gchar *value)
{
glade_packing_box_set_integer (object, value, "padding");
}
static gchar *
glade_packing_box_position_get (GObject *object)
{
GladeWidget *glade_widget;
GtkBoxChild *box_child = NULL;
GtkWidget *widget;
GtkBox *box;
GList *list;
gint i;
widget = GTK_WIDGET (object);
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
glade_widget = glade_widget_get_from_gtk_widget (widget);
g_return_val_if_fail (GLADE_IS_WIDGET (glade_widget), NULL);
box = GTK_BOX (glade_widget->parent->widget);
g_return_val_if_fail (GTK_IS_BOX (box), NULL);
list = box->children;
for (; list; list = list->next) {
box_child = list->data;
if (box_child->widget == widget)
break;
}
if (list == NULL) {
g_warning ("Could not find the position in the GtkBox");
return g_strdup ("Error");
}
i = g_list_index (box->children, box_child);
return g_strdup_printf ("%d", i);
}
static void
glade_packing_box_position_set (GObject *object, const gchar *value)
{
GladeWidget *glade_widget;
GladeWidget *glade_widget_child;
GtkWidget *widget;
gboolean expand, fill;
gint padding;
GtkPackType pack_type;
GList *list;
GtkBox *box;
widget = GTK_WIDGET (object);
g_return_if_fail (GTK_IS_WIDGET (widget));
......@@ -138,28 +379,87 @@ glade_packing_pack_start_set (GObject *object, const gchar *value)
g_return_if_fail (GLADE_IS_WIDGET (glade_widget));
box = GTK_BOX (glade_widget->parent->widget);
g_return_if_fail (GTK_IS_BOX (box));
gtk_box_query_child_packing (box, widget,
&expand, &fill, &padding, &pack_type);
pack_type = (strcmp (value, GLADE_TAG_TRUE) == 0) ? GTK_PACK_START : GTK_PACK_END;
gtk_box_set_child_packing (box, widget,
expand, fill, padding, pack_type);
gtk_box_reorder_child (box, widget, atoi (value));
/* This all works fine, but we need to update the position property
* of the other children in this box since it has changed.
*/
list = box->children;
for (; list; list = list->next) {
GladeProperty *property;