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
This commit is contained in:
Chema Celorio 2001-08-04 19:01:06 +00:00 committed by Jose Maria Celorio
parent e0f3bbf8c0
commit 4aec257b61
21 changed files with 690 additions and 190 deletions

View File

@ -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

View File

@ -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);
}

View File

@ -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;
};

View File

@ -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

247
src/glade-packing.c Normal file
View File

@ -0,0 +1,247 @@
/* -*- 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);
}

14
src/glade-packing.h Normal file
View File

@ -0,0 +1,14 @@
/* -*- 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__ */

View File

@ -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);

View File

@ -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

View File

@ -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);
}

View File

@ -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);

View File

@ -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,

View File

@ -263,7 +263,7 @@ glade_project_selection_clear (GladeProject *project, gboolean emit_signal)
list = project->selection;
for (; list != NULL; list = list->next) {
widget = list->data;
glade_widget_unselect (widget);
glade_widget_flag_unselected (widget);
}
g_list_free (project->selection);
@ -286,7 +286,7 @@ glade_project_selection_remove (GladeWidget *widget,
if (!widget->selected)
return;
glade_widget_unselect (widget);
glade_widget_flag_unselected (widget);
project->selection = g_list_remove (project->selection, widget);
@ -308,7 +308,7 @@ glade_project_selection_add (GladeWidget *widget,
return;
project->selection = g_list_prepend (project->selection, widget);
glade_widget_select (widget);
glade_widget_flag_selected (widget);
if (emit_signal)
glade_project_selection_changed (project);

View File

@ -117,7 +117,7 @@ glade_query_new_from_node (GladeXmlNode *node)
return query;
}
static GladePropertyClass *
GladePropertyClass *
glade_property_class_new (void)
{
GladePropertyClass *property_class;
@ -131,6 +131,7 @@ glade_property_class_new (void)
property_class->choices = NULL;
property_class->optional = FALSE;
property_class->common = FALSE;
property_class->packing = FALSE;
property_class->query = NULL;
property_class->set_function = NULL;
@ -221,22 +222,17 @@ glade_property_class_get_choices_from_spec (GParamSpec *spec)
return list;
}
static GList *
glade_property_get_parameters_boolean (GParamSpec *spec,
GladePropertyClass *class)
static gchar *
glade_property_get_default_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);
return g_list_prepend (NULL, parameter);
return def ? g_strdup (GLADE_TAG_TRUE) : g_strdup (GLADE_TAG_FALSE);
}
static gchar *
@ -258,6 +254,92 @@ glade_property_get_parameter_numeric_default (GParamSpec *spec)
return value;
}
static gchar *
glade_property_get_default_text (GParamSpec *spec,
GladePropertyClass *class)
{
g_return_val_if_fail (G_IS_PARAM_SPEC_STRING (spec), NULL);
if (G_PARAM_SPEC_STRING (spec)->default_value != NULL)
return g_strdup (G_PARAM_SPEC_STRING (spec)->default_value);
return NULL;
}
static gchar *
glade_property_get_default_choice (GParamSpec *spec,
GladePropertyClass *class)
{
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;
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;
}
return g_strdup (choice->symbol);
}
static gchar *
glade_property_get_default_numeric (GParamSpec *spec,
GladePropertyClass *class)
{
g_return_val_if_fail (G_IS_PARAM_SPEC_INT (spec) |
G_IS_PARAM_SPEC_UINT (spec) |
G_IS_PARAM_SPEC_FLOAT (spec) |
G_IS_PARAM_SPEC_DOUBLE (spec), NULL);
return glade_property_get_parameter_numeric_default (spec);
}
static gchar *
glade_property_class_get_default_from_spec (GParamSpec *spec,
GladePropertyClass *class,
GladeXmlNode *node)
{
gchar *def = NULL;
switch (class->type) {
case GLADE_PROPERTY_TYPE_CHOICE:
def = glade_property_get_default_choice (spec, class);
break;
case GLADE_PROPERTY_TYPE_TEXT:
def = glade_property_get_default_text (spec, class);
break;
case GLADE_PROPERTY_TYPE_INTEGER:
case GLADE_PROPERTY_TYPE_FLOAT:
case GLADE_PROPERTY_TYPE_DOUBLE:
def = glade_property_get_default_numeric (spec, class);
break;
case GLADE_PROPERTY_TYPE_BOOLEAN:
def = glade_property_get_default_boolean (spec, class);
break;
case GLADE_PROPERTY_TYPE_OTHER_WIDGETS:
break;
case GLADE_PROPERTY_TYPE_OBJECT:
break;
case GLADE_PROPERTY_TYPE_ERROR:
break;
}
return def;
}
static gchar *
glade_property_get_parameter_numeric_min (GParamSpec *spec)
{
@ -296,6 +378,7 @@ glade_property_get_parameter_numeric_max (GParamSpec *spec)
return value;
}
static GList *
glade_property_get_parameters_numeric (GParamSpec *spec,
GladePropertyClass *class)
@ -308,12 +391,6 @@ glade_property_get_parameters_numeric (GParamSpec *spec,
G_IS_PARAM_SPEC_FLOAT (spec) |
G_IS_PARAM_SPEC_DOUBLE (spec), NULL);
/* Get the default value */
parameter = glade_parameter_new ();
parameter->key = g_strdup ("Default");
parameter->value = glade_property_get_parameter_numeric_default (spec);
list = g_list_prepend (list, parameter);
/* Get the min value */
parameter = glade_parameter_new ();
parameter->key = g_strdup ("Min");
@ -330,63 +407,7 @@ glade_property_get_parameters_numeric (GParamSpec *spec,
return list;
}
static GList *
glade_property_get_parameters_text (GParamSpec *spec,
GladePropertyClass *class)
{
GladeParameter *parameter;
GList *list = NULL;
g_return_val_if_fail (G_IS_PARAM_SPEC_STRING (spec), NULL);
if (G_PARAM_SPEC_STRING (spec)->default_value != NULL) {
/* Get the default value */
parameter = glade_parameter_new ();
parameter->key = g_strdup ("Default");
parameter->value = g_strdup (G_PARAM_SPEC_STRING (spec)->default_value);
list = g_list_prepend (list, parameter);
}
return list;
}
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;
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);
/* 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,
@ -397,10 +418,8 @@ glade_property_class_get_parameters_from_spec (GParamSpec *spec,
switch (class->type) {
case GLADE_PROPERTY_TYPE_CHOICE:
parameters = glade_property_get_parameters_choice (spec, class);
break;
case GLADE_PROPERTY_TYPE_TEXT:
parameters = glade_property_get_parameters_text (spec, class);
break;
case GLADE_PROPERTY_TYPE_INTEGER:
case GLADE_PROPERTY_TYPE_FLOAT:
@ -408,7 +427,6 @@ glade_property_class_get_parameters_from_spec (GParamSpec *spec,
parameters = glade_property_get_parameters_numeric (spec, class);
break;
case GLADE_PROPERTY_TYPE_BOOLEAN:
parameters = glade_property_get_parameters_boolean (spec, class);
break;
case GLADE_PROPERTY_TYPE_OTHER_WIDGETS:
break;
@ -472,6 +490,11 @@ glade_property_class_load_from_param_spec (const gchar *name,
if (class->type == GLADE_PROPERTY_TYPE_CHOICE)
class->choices = glade_property_class_get_choices_from_spec (spec);
/* We want to use the parm spec default only when the xml files do not provide a
* default value
*/
if (class->def == NULL)
class->def = glade_property_class_get_default_from_spec (spec, class, node);
class->parameters = glade_property_class_get_parameters_from_spec (spec, class, node);
return TRUE;
@ -561,9 +584,11 @@ glade_property_class_new_from_node (GladeXmlNode *node, GladeWidgetClass *widget
child = glade_xml_search_child (node, GLADE_TAG_QUERY);
if (child != NULL)
property_class->query = glade_query_new_from_node (child);
/* Will this property go in the common tab ? */
property_class->common = glade_xml_property_get_boolean (node, GLADE_TAG_COMMON, FALSE);
property_class->common = glade_xml_property_get_boolean (node, GLADE_TAG_COMMON, FALSE);
property_class->def = glade_xml_get_property_string (node, GLADE_TAG_DEFAULT);
/* Should we load this property from the ParamSpec ?
* We can have a property like ... ParamSpec="TRUE">
@ -579,7 +604,7 @@ glade_property_class_new_from_node (GladeXmlNode *node, GladeWidgetClass *widget
glade_widget_property_class_free (property_class);
property_class = NULL;
}
return property_class;
}
@ -718,9 +743,6 @@ glade_property_class_list_new_from_node (GladeXmlNode *node, GladeWidgetClass *c
@ -749,7 +771,3 @@ glade_property_class_create_label (GladePropertyClass *class)
return label;
}

View File

@ -113,6 +113,7 @@ struct _GladePropertyClass {
gchar *tooltip; /* The tooltip. Currently unimplemented. Not sure if
* it should go here
*/
gchar *def; /* The default value for this property */
GList *parameters; /* list of GladeParameter objects. This list
* provides with an extra set of key-value
@ -134,7 +135,10 @@ struct _GladePropertyClass {
* left that enables/disables de input
*/
GladePropertyQuery *query;
GladePropertyQuery *query; /* Some widgets require us to query the user
* before creating the widget. Like a vbox will
* want to know the number of columns.
*/
GladeWidgetClass *child; /* A GladeWidgetClass pointer of objects
* that we need to set for this widget
@ -154,6 +158,7 @@ struct _GladePropertyClass {
*/
gboolean common; /* Common properties go in the common tab */
gboolean packing; /* Packing properties go in the packing tab */
void (*set_function) (GObject *object,
const gchar *value);
@ -170,6 +175,8 @@ struct _GladePropertyClass {
*/
};
GladePropertyClass * glade_property_class_new (void);
GtkWidget * glade_property_class_create_label (GladePropertyClass *pclass);
GtkWidget * glade_property_class_create_input (GladePropertyClass *pclass);
GList * glade_property_class_list_new_from_node (GladeXmlNode * node, GladeWidgetClass *class);

View File

@ -49,13 +49,14 @@ glade_property_new (void)
/* We are recursing so add the prototype. Don't you love C ? */
static GList * glade_property_list_new_from_list (GList *list, GladeWidget *widget);
static GladeProperty *
glade_property_new_from_string (const gchar *string, GladePropertyClass *class, GladeWidget *widget)
GladeProperty *
glade_property_new_from_class (GladePropertyClass *class, GladeWidget *widget)
{
GladeProperty *property;
gchar *value = NULL;
gfloat float_val;
gint int_val;
gchar *string = class->def;
/* move somewhere else */
GladeChoice *choice;
@ -164,22 +165,15 @@ glade_property_list_new_from_list (GList *list, GladeWidget *widget)
GladePropertyClass *property_class;
GladeProperty *property;
GList *new_list = NULL;
gchar *def;
for (; list != NULL; list = list->next) {
property_class = list->data;
def = NULL;
glade_parameter_get_string (property_class->parameters,
"Default", &def);
property = glade_property_new_from_string (def, property_class, widget);
property = glade_property_new_from_class (property_class, widget);
if (property == NULL)
continue;
property->widget = widget;
if (def)
g_free (def);
new_list = g_list_prepend (new_list, property);
}
@ -270,8 +264,13 @@ glade_property_changed_integer (GladeProperty *property, gint val)
g_free (property->value);
property->value = g_strdup_printf ("%i", val);
gtk_object_set (GTK_OBJECT (property->widget->widget),
property->class->id, val, NULL);
if (property->class->set_function == NULL)
gtk_object_set (GTK_OBJECT (property->widget->widget),
property->class->id, val, NULL);
else
(*property->class->set_function) (G_OBJECT (property->widget->widget),
property->value);
}
void
@ -344,12 +343,21 @@ glade_property_changed_boolean (GladeProperty *property, gboolean val)
{
g_return_if_fail (property != NULL);
g_return_if_fail (property->value != NULL);
g_return_if_fail (property->widget != NULL);
g_return_if_fail (property->widget->widget != NULL);
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->id, val, NULL);
if (property->class->set_function == NULL)
gtk_object_set (GTK_OBJECT (property->widget->widget),
property->class->id,
val,
NULL);
else
(*property->class->set_function) (G_OBJECT (property->widget->widget),
property->value);
}
void
@ -362,8 +370,12 @@ glade_property_changed_choice (GladeProperty *property, GladeChoice *choice)
g_free (property->value);
property->value = g_strdup_printf ("%s", choice->symbol);
gtk_object_set (GTK_OBJECT (property->widget->widget),
property->class->id, choice->value, NULL);
if (property->class->set_function == NULL)
gtk_object_set (GTK_OBJECT (property->widget->widget),
property->class->id, choice->value, NULL);
else
(*property->class->set_function) (G_OBJECT (property->widget->widget),
property->value);
}

View File

@ -53,6 +53,7 @@ struct _GladePropertyQueryResult {
GList * glade_property_list_new_from_widget_class (GladeWidgetClass *class,
GladeWidget *widget);
GladeProperty * glade_property_new_from_class (GladePropertyClass *class, GladeWidget *widget);
void glade_property_changed_text (GladeProperty *property, const gchar *text);
void glade_property_changed_integer (GladeProperty *property, gint val);

View File

@ -74,7 +74,7 @@ glade_widget_class_compose_get_type_func (GladeWidgetClass *class)
i++;
}
retval = g_strconcat (g_strdup (tmp->str), "_get_type", NULL);
retval = g_strconcat (tmp->str, "_get_type", NULL);
g_strdown (retval);
g_string_free (tmp, TRUE);
@ -146,6 +146,7 @@ glade_widget_class_list_signals (GladeWidgetClass *class)
signals = g_list_append (signals, (GladeWidgetClassSignal *) cur);
}
g_free (sig_ids);
}
type = g_type_parent (type);
@ -386,13 +387,20 @@ glade_widget_class_find_spec (GladeWidgetClass *class, const gchar *name)
if (!spec || !spec->name) {
g_warning ("Spec does not have a valid name, or invalid spec");
g_free (specs);
return NULL;
}
if (strcmp (spec->name, name) == 0)
return spec;
if (strcmp (spec->name, name) == 0) {
GParamSpec *return_me;
return_me = g_param_spec_ref (spec);
g_free (specs);
return return_me;
}
}
g_free (specs);
return NULL;
}
/**

View File

@ -33,7 +33,7 @@
#include "glade-popup.h"
#include "glade-placeholder.h"
#include "glade-signal.h"
#include "glade-packing.h"
#define GLADE_WIDGET_SELECTION_NODE_SIZE 7
@ -103,7 +103,11 @@ glade_widget_new (GladeProject *project, GladeWidgetClass *class, GtkWidget *gtk
GladeWidget *
glade_widget_get_from_gtk_widget (GtkWidget *widget)
{
return gtk_object_get_data (GTK_OBJECT (widget), GLADE_WIDGET_DATA_TAG);
GladeWidget *glade_widget;
glade_widget = gtk_object_get_data (GTK_OBJECT (widget), GLADE_WIDGET_DATA_TAG);
return glade_widget;
}
/* A temp data struct that we use when looking for a widget inside a container
@ -304,6 +308,7 @@ glade_widget_button_release (GtkWidget *widget, GdkEventButton *event, gpointer
return FALSE;
}
/**
* glade_widget_set_default_options:
* @widget:
@ -311,7 +316,7 @@ glade_widget_button_release (GtkWidget *widget, GdkEventButton *event, gpointer
* Takes care of applying the default values to a newly created widget
**/
static void
glade_widget_set_default_options (GladeWidget *widget)
glade_widget_set_default_options_real (GladeWidget *widget, gboolean packing)
{
GladeProperty *property;
GList *list;
@ -319,6 +324,10 @@ glade_widget_set_default_options (GladeWidget *widget)
list = widget->properties;
for (; list != NULL; list = list->next) {
property = list->data;
if (property->class->packing != packing)
continue;
switch (property->class->type) {
case GLADE_PROPERTY_TYPE_BOOLEAN:
glade_property_changed_boolean (property,
@ -348,7 +357,7 @@ glade_widget_set_default_options (GladeWidget *widget)
g_print ("Set adjustment\n");
#if 1
g_print ("Set directly \n");
glade_widget_set_default_options (property->child);
glade_widget_set_default_options_real (property->child, packing);
gtk_spin_button_set_adjustment (GTK_SPIN_BUTTON (property->widget->widget),
GTK_ADJUSTMENT (property->child));
#else
@ -366,6 +375,27 @@ glade_widget_set_default_options (GladeWidget *widget)
}
static void
glade_widget_set_default_options (GladeWidget *widget)
{
glade_widget_set_default_options_real (widget, FALSE);
}
/**
* glade_widget_set_default_packing_options:
* @widget:
*
* We need to have a different funcition for setting packing options
* because we weed to add the widget to the container before we
* apply the packing options
*
**/
void
glade_widget_set_default_packing_options (GladeWidget *widget)
{
glade_widget_set_default_options_real (widget, TRUE);
}
static GladeWidget *
glade_widget_register (GladeProject *project, GladeWidgetClass *class, GtkWidget *gtk_widget, const gchar *name, GladeWidget *parent)
{
@ -375,8 +405,10 @@ glade_widget_register (GladeProject *project, GladeWidgetClass *class, GtkWidget
g_return_val_if_fail (GLADE_IS_PROJECT (project), NULL);
glade_widget = glade_widget_new (project, class, gtk_widget, name);
glade_widget->parent = parent;
glade_packing_add_properties (glade_widget);
if (parent)
parent->children = g_list_prepend (parent->children, glade_widget);
@ -518,7 +550,7 @@ glade_widget_set_contents (GladeWidget *widget)
if (glade_widget_class_find_spec (class, "label") != NULL)
property = glade_property_get_from_id (widget->properties,
"label");
"label");
if (glade_widget_class_find_spec (class, "title") != NULL)
property = glade_property_get_from_id (widget->properties,
"title");
@ -592,11 +624,7 @@ 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 so add
* the GladeWidget pointer to the GtkWidget
*/
gtk_object_set_data (GTK_OBJECT (glade_widget->widget), GLADE_WIDGET_DATA_TAG, glade_widget);
glade_project_add_widget (project, glade_widget);
@ -653,6 +681,11 @@ glade_widget_new_from_class_full (GladeWidgetClass *class, GladeProject *project
if (result)
glade_property_query_result_destroy (result);
/* We need to set the default options after adding it to the placeholder cause
* there are packing options too
*/
glade_widget_set_default_options (glade_widget);
return glade_widget;
}
@ -762,7 +795,23 @@ glade_widget_set_name (GladeWidget *widget, const gchar *name)
void
glade_widget_unselect (GladeWidget *widget)
glade_widget_select (GladeWidget *widget)
{
glade_project_selection_set (widget, TRUE);
}
/* I don't think this flag is beeing used at all, but for now it is queueing
* redraws. Chema.
*/
/**
* glade_widget_flag_unselected:
* @widget:
*
* Flag the widget as unselected
**/
void
glade_widget_flag_unselected (GladeWidget *widget)
{
g_return_if_fail (widget->selected);
@ -770,8 +819,14 @@ glade_widget_unselect (GladeWidget *widget)
gtk_widget_queue_draw (widget->widget);
}
/**
* glade_widget_flag_selected:
* @widget:
*
* Flags the widget as selected
**/
void
glade_widget_select (GladeWidget *widget)
glade_widget_flag_selected (GladeWidget *widget)
{
g_return_if_fail (!widget->selected);
@ -786,6 +841,27 @@ glade_widget_delete (GladeWidget *widget)
glade_widget_get_name (widget));
}
void
glade_widget_cut (GladeWidget *widget)
{
g_print ("Implement cut. Widget : %s\n",
glade_widget_get_name (widget));
}
void
glade_widget_copy (GladeWidget *widget)
{
g_print ("Implement copy. Widget : %s\n",
glade_widget_get_name (widget));
}
void
glade_widget_paste (GladeWidget *widget)
{
g_print ("Implement paste. Widget : %s\n",
glade_widget_get_name (widget));
}
/**
* glade_widget_new_from_class_name:
* @class_name:

View File

@ -34,11 +34,11 @@ struct _GladeWidget {
* just hide them
*/
GList * properties; /* A list of GladeProperty. A GladeProperty is an
* instance of a GladePropertyClass. If a
* GladePropertyClass for a gtkbutton is label, its
* property is "Ok".
*/
GList *properties; /* A list of GladeProperty. A GladeProperty is an
* instance of a GladePropertyClass. If a
* GladePropertyClass for a gtkbutton is label, its
* property is "Ok".
*/
GList *signals; /* A list of GladeWidgetSignals */
@ -51,7 +51,21 @@ struct _GladeWidget {
gboolean selected;
GtkWidget *popup_menu;
/* Packing */
gint attach_left;
gint attach_right;
gint attach_top;
gint attach_bottom;
gint padding_horizontal;
gint padding_vertical;
gboolean expand_x : 1;
gboolean expand_y : 1;
gboolean shrink_x : 1;
gboolean shrink_y : 1;
gboolean fill_x : 1;
gboolean fill_y : 1;
};
/* GladeWidgetSignal is a structure that holds information about a signal a
@ -70,6 +84,7 @@ GladeWidget * glade_widget_new_from_class (GladeWidgetClass *class,
GladeWidget *widget);
GladeWidget * glade_widget_new_from_class_name (const gchar *class_name,
GladeWidget *parent);
void glade_widget_set_default_packing_options (GladeWidget *widget);
const gchar * glade_widget_get_name (GladeWidget *widget);
@ -83,9 +98,14 @@ void glade_widget_set_name (GladeWidget *widget, const gchar *name);
/* Widget functions */
typedef void (*GladeWidgetFunction) (GladeWidget *widget);
void glade_widget_unselect (GladeWidget *widget);
void glade_widget_flag_selected (GladeWidget *widget);
void glade_widget_flag_unselected (GladeWidget *widget);
void glade_widget_select (GladeWidget *widget);
void glade_widget_delete (GladeWidget *widget);
void glade_widget_cut (GladeWidget *widget);
void glade_widget_copy (GladeWidget *widget);
void glade_widget_paste (GladeWidget *widget);
GladeWidget * glade_widget_get_from_gtk_widget (GtkWidget *widget);

View File

@ -54,6 +54,7 @@ gchar * _ (gchar * name);
#define GLADE_CHOICE_DATA_TAG "GladeChoiceDataTag"
#define GLADE_TAG_UPDATE_SIGNALS "UpdateSignals"
#define GLADE_TAG_SIGNAL_NAME "SignalName"
#define GLADE_TAG_DEFAULT "Default"
#define GLADE_TAG_CATALOG "GladeCatalog"
#define GLADE_TAG_GLADE_WIDGET "GladeWidget"

View File

@ -27,6 +27,7 @@
#include "glade-editor.h"
#include "glade-cursor.h"
#include "glade-catalog.h"
#include "glade-packing.h"
#include "glade-palette.h"
#include "glade-project.h"
#include "glade-project-view.h"
@ -35,8 +36,6 @@
#include <gmodule.h>
#include <popt.h>
#define FIX_POPT
#ifdef FIX_POPT
static void parse_command_line (poptContext);
gchar * widget_name = NULL;
@ -48,7 +47,7 @@ static struct poptOption options[] = {
POPT_ARG_STRING,
&widget_name,
0,
"Dump a widget",
"Dump the properties of a widget. --dump [gtk type] where type can be GtkWindow, GtkLabel etc.",
NULL
},
{
@ -61,7 +60,6 @@ static struct poptOption options[] = {
NULL
}
};
#endif
static gint
glade_init ()
@ -83,6 +81,7 @@ glade_init ()
* 4. Create the project window
*/
glade_cursor_init ();
glade_packing_init ();
catalog = glade_catalog_load ();
if (catalog == NULL)
@ -99,9 +98,7 @@ glade_init ()
int
main (int argc, char *argv[])
{
#ifdef FIX_POPT
poptContext pctx = poptGetContext ("Glade2", argc, (const char **) argv, options, 0);
#endif
#if 0
#if 1
@ -124,10 +121,7 @@ main (int argc, char *argv[])
if (!glade_init ())
return -1;
#ifdef FIX_POPT
parse_command_line (pctx);
#endif
poptFreeContext (pctx);
if (widget_name == NULL) {
@ -146,7 +140,6 @@ main (int argc, char *argv[])
}
#ifdef FIX_POPT
static void
parse_command_line (poptContext pctx)
{
@ -165,7 +158,13 @@ parse_command_line (poptContext pctx)
files = g_list_reverse (files);
}
#endif
void
g_scanner_stat_mode (void)
{
g_print ("foo\n");
}
gchar * _ (gchar * name) { return name;};