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

add a packing argument. (glade_widget_set_default_options): we now set the

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

	* src/glade-widget.c (glade_widget_set_default_options_real): add a packing
	argument.
	(glade_widget_set_default_options): we now set the default options in two
	steps. Firts the object properties and
	(glade_widget_set_default_packing_options): secondly the packing properties.
	The packing properties are applied after the widget is appended to the container

	* src/glade-property-class.c (glade_property_class_get_default_from_spec):
	default is now a member of GladePropertyClass not a GladeParameter.

	* src/glade-parameter.c (glade_parameter_adjustment_new): get the default
	from the parameters only if def was not specified. Added a default variable
	to the function.

	* src/glade-packing.c: add file. Takes care of container packing related
	stuff.

	* src/glade-gtk.c (glade_gtk_vbox_get_size): add the prototype, still
	no content
	(glade_gtk_vbox_set_size): ditto.

	* src/glade-editor.c (glade_editor_load_packing_page): impl. Adds
	the packing page.

	* src/Makefile.am: add packging.[ch]

	* src/glade-popup.c (glade_popup_create_menu): make the popup-menu
	work. Select now works.

	* src/glade-widget.h: remove ->popup. destroy it right away.

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

	* src/glade-widget-class.c (glade_widget_class_list_signals): plug a memleak
	(glade_widget_class_compose_get_type_func): plug a memleak
parent e0f3bbf8
......@@ -40,6 +40,7 @@ glade2_SOURCES = \
glade-gtk.c \
glade-utils.c \
glade-signal.c \
glade-packing.c \
glade-signal-editor.c
noinst_HEADERS = \
......@@ -65,4 +66,5 @@ noinst_HEADERS = \
glade-catalog.h \
glade-utils.h \
glade-signal.h \
glade-packing.h \
glade-xml-utils.h
......@@ -473,38 +473,7 @@ glade_editor_create_input_text (GladeEditorProperty *property)
GTK_SIGNAL_FUNC (glade_editor_property_changed_text_view),
property, NULL, 0);
return view;
#if 0
/* This code worked with the old gtk, but the GtkText widget was
* deprecated for VERY good reasons. Chema
*/
GtkWidget *text;
GtkWidget *scrolled_window;
gint line_height;
gint height;
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
text = gtk_text_new (NULL, NULL);
gtk_text_set_editable ((GtkText *)text, TRUE);
gtk_container_add (GTK_CONTAINER (scrolled_window), text);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
line_height = text->style->font->ascent + text->style->font->descent;
/* We add 8 for the text's border height etc. */
height = lines * line_height;
height -= 20;
/* This is not working */
gtk_widget_set_usize (text, -1, height);
gtk_signal_connect (GTK_OBJECT (text), "changed",
GTK_SIGNAL_FUNC (glade_editor_property_changed_text), property);
property->input = text;
return scrolled_window;
#endif
return NULL;
}
return NULL;
......@@ -522,7 +491,7 @@ glade_editor_create_input_numeric (GladeEditorProperty *property,
class = property->class;
adjustment = glade_parameter_adjustment_new (class->parameters);
adjustment = glade_parameter_adjustment_new (class->parameters, class->def);
spin = gtk_spin_button_new (adjustment, 10,
numeric_type == GLADE_EDITOR_INTEGER ? 0 : 2);
......@@ -849,9 +818,9 @@ glade_editor_load_signal_page (GladeEditor *editor, GladeWidgetClass *class)
static void
glade_editor_load_class (GladeEditor *editor, GladeWidgetClass *class)
{
glade_editor_load_widget_page (editor, class);
glade_editor_load_common_page (editor, class);
glade_editor_load_signal_page (editor, class);
glade_editor_load_widget_page (editor, class);
glade_editor_load_common_page (editor, class);
glade_editor_load_signal_page (editor, class);
editor->loaded_class = class;
}
......@@ -1019,6 +988,7 @@ glade_editor_property_load_boolean (GladeEditorProperty *property)
g_return_if_fail (property->property != NULL);
g_return_if_fail (property->property->value != NULL);
g_return_if_fail (property->input != NULL);
g_return_if_fail (GTK_IS_TOGGLE_BUTTON (property->input));
if (strcmp (property->property->value, GLADE_TAG_TRUE) == 0)
state = TRUE;
......@@ -1135,6 +1105,62 @@ glade_editor_property_load (GladeEditorProperty *property, GladeWidget *widget)
property->loading = FALSE;
}
static void
glade_editor_table_free (GladeEditorTable *me)
{
if (me)
g_free (me);
}
static void
glade_editor_load_packing_page (GladeEditor *editor, GladeWidget *widget)
{
static GladeEditorTable *old = NULL;
static GList *old_props = NULL;
GladeEditorProperty *editor_property;
GladeEditorTable *table;
GladeProperty *property;
GtkContainer *container;
GList *list;
/* Remove the old properties */
container = GTK_CONTAINER (editor->vbox_packing);
list = gtk_container_children (container);
for (; list; list = list->next) {
GtkWidget *widget = list->data;
g_return_if_fail (GTK_IS_WIDGET (widget));
gtk_container_remove (container, widget);
}
/* Free the old structs */
if (old)
glade_editor_table_free (old);
list = old_props;
for (; list; list = list->next)
g_free (list->data);
old_props = NULL;
/* Now add the new properties */
table = glade_editor_table_new (widget->class);
table->editor = editor;
table->common = FALSE;
table->packing = TRUE;
list = widget->properties;
for (; list; list = list->next) {
property = list->data;
if (property->class->packing) {
editor_property = glade_editor_table_append_item (table, property->class);
old_props = g_list_prepend (old_props, editor_property);
glade_editor_property_load (editor_property, widget);
}
}
gtk_widget_show_all (table->table_widget);
gtk_container_add (container, table->table_widget);
old = table;
}
static void
glade_editor_load_item (GladeEditor *editor, GladeWidget *item)
......@@ -1167,6 +1193,9 @@ 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);
}
......
......@@ -137,6 +137,8 @@ struct _GladeEditorTable
gboolean common; /* Is this table to be used in the common tab ?
* or the general tab ?
*/
gboolean packing;
gint rows;
};
......
......@@ -141,6 +141,7 @@ glade_gtk_adjustment_set_page_increment (GObject *object, const gchar *string)
adjustment->page_increment = val;
gtk_adjustment_changed (adjustment);
}
static void
glade_gtk_adjustment_set_page_size (GObject *object, const gchar *string)
{
......@@ -156,6 +157,18 @@ 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");
}
static void
glade_gtk_vbox_set_size (GObject *object, const gchar *string)
{
g_print ("Set size\n");
}
/* ================ Temp hack =================== */
typedef struct _GladeGtkFunction GladeGtkFunction;
......@@ -174,6 +187,8 @@ GladeGtkFunction functions [] = {
{"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
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2001 Ximian, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* Authors:
* Chema Celorio <chema@celorio.com>
*/
#include <string.h>
#include "glade.h"
#include "glade-packing.h"
#include "glade-property-class.h"
#include "glade-property.h"
#include "glade-widget-class.h"
#include "glade-widget.h"
GList *table_properties = NULL;
GList *box_properties = NULL;
static void
glade_packing_x_expand_set (GObject *object, const gchar *value)
{
g_print ("X expand set %s\n", value);
}
static void
glade_packing_y_expand_set (GObject *object, const gchar *value)
{
g_print ("Y expand set %s\n", value);
}
static void
glade_packing_x_shrink_set (GObject *object, const gchar *value)
{
g_print ("X shrink set %s\n", value);
}
static void
glade_packing_y_shrink_set (GObject *object, const gchar *value)
{
g_print ("Y shrink set %s\n", value);
}
static void
glade_packing_x_fill_set (GObject *object, const gchar *value)
{
g_print ("X fill set %s\n", value);
}
static void
glade_packing_y_fill_set (GObject *object, const gchar *value)
{
g_print ("Y fill set %s\n", value);
}
static void
glade_packing_expand_set (GObject *object, const gchar *value)
{
GladeWidget *glade_widget;
GtkBox *box;
GtkWidget *widget;
gboolean expand, fill;
gint padding;
GtkPackType pack_type;
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));
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);
expand = (strcmp (value, GLADE_TAG_TRUE) == 0);
gtk_box_set_child_packing (box, widget,
expand, fill, padding, pack_type);
}
static void
glade_packing_fill_set (GObject *object, const gchar *value)
{
GladeWidget *glade_widget;
GtkBox *box;
GtkWidget *widget;
gboolean expand, fill;
gint padding;
GtkPackType pack_type;
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));
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);
fill = (strcmp (value, GLADE_TAG_TRUE) == 0);
gtk_box_set_child_packing (box, widget,
expand, fill, padding, pack_type);
}
static void
glade_packing_pack_start_set (GObject *object, const gchar *value)
{
GladeWidget *glade_widget;
GtkBox *box;
GtkWidget *widget;
gboolean expand, fill;
gint padding;
GtkPackType pack_type;
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));
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);
}
typedef struct _GladePackingProperty GladePackingProperty;
struct _GladePackingProperty
{
const gchar *name;
const gchar *id;
void (*set_function) (GObject *object, const gchar *value);
GladePropertyType type;
const gchar *def;
};
static void
glade_packing_add_property (GList **list, GladePackingProperty prop)
{
GladePropertyClass *class;
class = glade_property_class_new ();
class->packing = TRUE;
class->name = g_strdup (prop.name);
class->id = g_strdup (prop.id);
class->tooltip = g_strdup ("Implement me");
class->type = prop.type;
class->set_function = prop.set_function;
if (prop.def)
class->def = g_strdup (prop.def);
*list = g_list_prepend (*list, class);
}
GladePackingProperty table_props[] =
{
{"X Expand", "xexpand", glade_packing_x_expand_set, GLADE_PROPERTY_TYPE_BOOLEAN, NULL},
{"Y Expand", "yexpand", glade_packing_y_expand_set, GLADE_PROPERTY_TYPE_BOOLEAN, NULL},
{"X Shrink", "xshrink", glade_packing_x_shrink_set, GLADE_PROPERTY_TYPE_BOOLEAN, NULL},
{"Y Shrink", "yshrink", glade_packing_y_shrink_set, GLADE_PROPERTY_TYPE_BOOLEAN, NULL},
{"X Fill", "xfill", glade_packing_x_fill_set, GLADE_PROPERTY_TYPE_BOOLEAN, NULL},
{"Y Fill", "yfill", glade_packing_y_fill_set, GLADE_PROPERTY_TYPE_BOOLEAN, NULL},
};
GladePackingProperty box_props[] =
{
{"Expand", "expand", glade_packing_expand_set, GLADE_PROPERTY_TYPE_BOOLEAN, GLADE_TAG_FALSE},
{"Fill", "fill", glade_packing_fill_set, GLADE_PROPERTY_TYPE_BOOLEAN, GLADE_TAG_FALSE},
{"Pack Start", "packstart", glade_packing_pack_start_set, GLADE_PROPERTY_TYPE_BOOLEAN, GLADE_TAG_TRUE},
};
void
glade_packing_init (void)
{
gint num;
gint i;
num = sizeof (table_props) / sizeof (GladePackingProperty);
for (i = 0; i < num; i++)
glade_packing_add_property (&table_properties, table_props[i]);
table_properties = g_list_reverse (table_properties);
num = sizeof (box_props) / sizeof (GladePackingProperty);
for (i = 0; i < num; i++)
glade_packing_add_property (&box_properties, box_props[i]);
box_properties = g_list_reverse (box_properties);
}
static void
glade_packing_add_properties_from_list (GladeWidget *widget,
GList *list)
{
GladePropertyClass *class;
GladeProperty *property;
for (; list != NULL; list = list->next) {
class = list->data;
property = glade_property_new_from_class (class, widget);
property->widget = widget;
widget->properties = g_list_append (widget->properties, property);
}
}
void
glade_packing_add_properties (GladeWidget *widget)
{
gchar *class;
if (widget->parent == NULL)
return;
class = widget->parent->class->name;
if (strcmp (class, "GtkTable") == 0)
glade_packing_add_properties_from_list (widget, table_properties);
if ((strcmp (class, "GtkHBox") == 0) ||
(strcmp (class, "GtkVBox") == 0))
glade_packing_add_properties_from_list (widget, box_properties);
}
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
#ifndef __GLADE_PACKING_H__
#define __GLADE_PACKING_H__
G_BEGIN_DECLS
void glade_packing_init (void);
void glade_packing_add_properties (GladeWidget *widget);
G_END_DECLS
#endif /* __GLADE_PACKING_H__ */
......@@ -208,7 +208,7 @@ glade_parameter_list_new_from_node (GList *list, GladeXmlNode *node)
* Return Value: A newly created GtkAdjustment
**/
GtkAdjustment *
glade_parameter_adjustment_new (GList *parameters)
glade_parameter_adjustment_new (GList *parameters, const gchar *def)
{
GtkAdjustment *adjustment;
gfloat value = 1;
......@@ -219,7 +219,11 @@ glade_parameter_adjustment_new (GList *parameters)
gfloat page_increment = 265;
gfloat climb_rate = 1;
glade_parameter_get_float (parameters, "Default", &value);
if (def)
value = atof (def);
else
glade_parameter_get_float (parameters, "Default", &value);
glade_parameter_get_float (parameters, "Min", &lower);
glade_parameter_get_float (parameters, "Max", &upper);
glade_parameter_get_float (parameters, "StepIncrement", &step_increment);
......
......@@ -42,7 +42,7 @@ void glade_parameter_get_string (GList *parameters, const gchar *key, gchar **v
GList * glade_parameter_list_new_from_node (GList *list, GladeXmlNode *node);
/* Convenience functions */
GtkAdjustment * glade_parameter_adjustment_new (GList *parameters);
GtkAdjustment * glade_parameter_adjustment_new (GList *parameters, const gchar *def);
G_END_DECLS
......
......@@ -179,6 +179,8 @@ glade_placeholder_replace_widget (GladePlaceholder *placeholder, GladeWidgetClas
"function has not been implemented for this class (%s)\n",
class->name);
glade_widget_set_default_packing_options (widget);
glade_project_selection_set (widget, TRUE);
}
......
......@@ -30,10 +30,17 @@ static void
glade_popup_menu_detach (GtkWidget *attach_widget,
GtkMenu *menu)
{
#if 0
GladeWidget *widget;
#endif
/* Dunno what this is for */
g_print ("Detaching ************************************\n");
#if 0
gtk_widget_destroy (GTK_WIDGET (menu));
widget = glade_widget_get_from_gtk_widget (attach_widget);
widget->popup_menu = NULL;
#endif
}
static void
......@@ -51,7 +58,8 @@ glade_popup_item_activate_cb (GtkWidget *menu_item,
}
static void
glade_popup_append_item (GladeWidget *widget,
glade_popup_append_item (GtkWidget *popup_menu,
GladeWidget *widget,
const gchar *label,
GladeWidgetFunction function,
gboolean sensitive)
......@@ -67,15 +75,56 @@ glade_popup_append_item (GladeWidget *widget,
gtk_widget_set_sensitive (menu_item, sensitive);
gtk_widget_show (menu_item);
gtk_menu_shell_append (GTK_MENU_SHELL (widget->popup_menu),
gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu),
menu_item);
}
static void
glade_popup_append_items (GladeWidget *widget)
static GtkWidget *
glade_popup_create_menu (GladeWidget *widget, gboolean add_childs)
{
glade_popup_append_item (widget, _("Delete"),
GtkWidget *popup_menu;
popup_menu = gtk_menu_new ();
glade_popup_append_item (popup_menu, widget, _("Select"),
glade_widget_select, TRUE);
glade_popup_append_item (popup_menu, widget, _("Cut"),
glade_widget_cut, TRUE);
glade_popup_append_item (popup_menu, widget, _("Copy"),
glade_widget_copy, TRUE);
glade_popup_append_item (popup_menu, widget, _("Paste"),
glade_widget_paste, TRUE);
glade_popup_append_item (popup_menu, widget, _("Delete"),
glade_widget_delete, TRUE);
if (add_childs && widget->parent) {
GladeWidget *parent = widget->parent;
while (parent) {
GtkWidget *child;
GtkWidget *child_menu;
GtkWidget *separator;
separator = gtk_menu_item_new ();
gtk_widget_show (separator);
gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu),
separator);
child = gtk_menu_item_new_with_label (parent->name);
child_menu = glade_popup_create_menu (parent, FALSE);
gtk_menu_item_set_submenu (GTK_MENU_ITEM (child),
child_menu);
gtk_widget_show (child);
gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu),
child);
parent = parent->parent;
}
}
return popup_menu;
}
void
......@@ -83,18 +132,12 @@ glade_popup_pop (GladeWidget *widget, GdkEventButton *event)
{
GtkWidget *popup_menu;
if (widget->popup_menu)
gtk_widget_destroy (widget->popup_menu);
popup_menu = gtk_menu_new ();
widget->popup_menu = popup_menu;
popup_menu = glade_popup_create_menu (widget, TRUE);
gtk_menu_attach_to_widget (GTK_MENU (popup_menu),
GTK_WIDGET (widget->widget),
glade_popup_menu_detach);
glade_popup_append_items (widget);
gtk_menu_popup (GTK_MENU (popup_menu), NULL, NULL,
NULL, NULL,
event->button, event->time);
......
......@@ -478,7 +478,7 @@ glade_project_append_query (GtkWidget *table, GladePropertyClass *property_class
0, 1, row, row +1);
/* Spin/Entry */
adjustment = glade_parameter_adjustment_new (property_class->parameters);
adjustment = glade_parameter_adjustment_new (property_class->parameters, property_class->def);
spin = gtk_spin_button_new (adjustment, 1, 0);
gtk_widget_show (spin);
gtk_table_attach_defaults (GTK_TABLE (table), spin,
......
......@@ -263,7 +263,7 @@ glade_project_selection_clear (GladeProject *project, gboolean emit_signal)
list = project->selection;
for (; list != NULL; list =