Commit 9051dfb9 authored by Tristan Van Berkom's avatar Tristan Van Berkom Committed by David Hoover

Removed GladePropertyType completely from the source in favor of

2004-11-02  Tristan Van Berkom  <tristan.van.berkom@gmail.com>
	* Removed GladePropertyType completely from the source in favor of
	  GParamSpec.
	* Removed GladeChoice code, and replaced all references thereof
	* Custom types must now provide a function to retrieve a GParamSpec for
	  that type (xml files and glade-gtk backend updated accordingly).
	* Removed "child" member from GladePropertyType in order to avoid
	  confusion (Note, I will add support for non-widget types + all types
	  allowed to have children, in a more flexable way, for now I got rid
	  of all mention of "child" since it wasn't implemented and mostly
	  `#if 0'd out anyway)
	* Implemented <VerifyFunction> in xml files and in the glade-gtk
	  backend.
	* Added support for numerical types long/ulong/int64/uint64 to the
	  editor.
	* src/glade-project.c: glade_project_remove_widget() Now removes nodes
	  on widget to remove, this fixes bug 156515.
	* src/glade-editor.c: Fixed popup name to
	  g_strdup_printf(_("Create a %s"), type);
parent b9a1931e
2004-11-02 Tristan Van Berkom <tristan.van.berkom@gmail.com>
* Removed GladePropertyType completely from the source in favor of
GParamSpec.
* Removed GladeChoice code, and replaced all references thereof
* Custom types must now provide a function to retrieve a GParamSpec for
that type (xml files and glade-gtk backend updated accordingly).
* Removed "child" member from GladePropertyType in order to avoid
confusion (Note, I will add support for non-widget types + all types
allowed to have children, in a more flexable way, for now I got rid
of all mention of "child" since it wasn't implemented and mostly
`#if 0'd out anyway)
* Implemented <VerifyFunction> in xml files and in the glade-gtk
backend.
* Added support for numerical types long/ulong/int64/uint64 to the
editor.
* src/glade-project.c: glade_project_remove_widget() Now removes nodes
on widget to remove, this fixes bug 156515.
* src/glade-editor.c: Fixed popup name to
g_strdup_printf(_("Create a %s"), type);
2004-11-02 David Hoover <karma@deadmoose.com>
* src/Makefile.am: fix up CLEANFILES problem
......
......@@ -59,7 +59,6 @@ glade_3_SOURCES = \
glade-popup.c \
glade-widget.c \
glade-catalog.c \
glade-choice.c \
glade-editor.c \
glade-utils.c \
glade-signal.c \
......@@ -91,7 +90,6 @@ noinst_HEADERS = \
glade-property.h \
glade-property-class.h \
glade-popup.h \
glade-choice.h \
glade-catalog.h \
glade-utils.h \
glade-signal.h \
......
/* -*- 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-xml-utils.h"
#include "glade-choice.h"
/**
* glade_choice_new:
*
* Returns: a new #GladeChoice
*/
GladeChoice *
glade_choice_new (void)
{
GladeChoice *choice;
choice = g_new0 (GladeChoice, 1);
return choice;
}
/**
* glade_choice_clone:
* @choice: a #GladeChoice
*
* Returns: a new #GladeChoice cloned from @choice
*/
GladeChoice *
glade_choice_clone (GladeChoice *choice)
{
GladeChoice *clone;
clone = glade_choice_new ();
clone->id = g_strdup (choice->id);
clone->name = g_strdup (choice->name);
clone->type = choice->type;
clone->value = choice->value;
return clone;
}
/**
* glade_choice_free:
* @choice: a #GladeChoice
*
* Frees @choice and its associated memory.
*/
void
glade_choice_free (GladeChoice *choice)
{
if (choice == NULL)
return;
g_free (choice->name);
g_free (choice->id);
g_free (choice);
}
/* This should go outside and it should be generated from ./make_enums.pl taking enums.txt
* as input. Chema */
/* I think gtk 2.0 already has a way of doing this .. Chema */
static gint
glade_enum_from_string (const gchar *string)
{
g_return_val_if_fail (string != NULL, -1);
if (strcmp (string, "-") == 0)
return 0;
if (strcmp (string, "GTK_JUSTIFY_LEFT") == 0)
return GTK_JUSTIFY_LEFT;
if (strcmp (string, "GTK_JUSTIFY_RIGHT") == 0)
return GTK_JUSTIFY_RIGHT;
if (strcmp (string, "GTK_JUSTIFY_CENTER") == 0)
return GTK_JUSTIFY_CENTER;
if (strcmp (string, "GTK_JUSTIFY_FILL") == 0)
return GTK_JUSTIFY_FILL;
if (strcmp (string, "GTK_WINDOW_TOPLEVEL") == 0)
return GTK_WINDOW_TOPLEVEL;
if (strcmp (string, "GTK_WINDOW_POPUP") == 0)
return GTK_WINDOW_POPUP;
if (strcmp (string, "GTK_WIN_POS_NONE") == 0)
return GTK_WIN_POS_NONE;
if (strcmp (string, "GTK_WIN_POS_CENTER") == 0)
return GTK_WIN_POS_CENTER;
if (strcmp (string, "GTK_WIN_POS_MOUSE") == 0)
return GTK_WIN_POS_MOUSE;
if (strcmp (string, "GTK_RELIEF_NORMAL") == 0)
return GTK_RELIEF_NORMAL;
if (strcmp (string, "GTK_RELIEF_HALF") == 0)
return GTK_RELIEF_HALF;
if (strcmp (string, "GTK_RELIEF_NONE") == 0)
return GTK_RELIEF_NONE;
return -1;
}
#if 0
static gchar *
glade_string_from_string (const gchar *string)
{
g_return_val_if_fail (string != NULL, NULL);
if (strcmp (string, "-") == 0)
return "None";
#if 1 /* Add the gtk stock buttons list here. Gtk takes care of stock
* items now
*/
if (strcmp (string, "GTK_STOCK_OK") == 0)
return GTK_STOCK_OK;
if (strcmp (string, "GTK_STOCK_CANCEL") == 0)
return GTK_STOCK_CANCEL;
#endif
#if 0
if (strcmp (string, "GNOME_STOCK_BUTTON_YES") == 0)
return GNOME_STOCK_BUTTON_YES;
if (strcmp (string, "GNOME_STOCK_BUTTON_NO") == 0)
return GNOME_STOCK_BUTTON_NO;
if (strcmp (string, "GNOME_STOCK_BUTTON_CLOSE") == 0)
return GNOME_STOCK_BUTTON_CLOSE;
if (strcmp (string, "GNOME_STOCK_BUTTON_APPLY") == 0)
return GNOME_STOCK_BUTTON_APPLY;
if (strcmp (string, "GNOME_STOCK_BUTTON_HELP") == 0)
return GNOME_STOCK_BUTTON_HELP;
if (strcmp (string, "GNOME_STOCK_BUTTON_NEXT") == 0)
return GNOME_STOCK_BUTTON_NEXT;
if (strcmp (string, "GNOME_STOCK_BUTTON_PREV") == 0)
return GNOME_STOCK_BUTTON_PREV;
if (strcmp (string, "GNOME_STOCK_BUTTON_UP") == 0)
return GNOME_STOCK_BUTTON_UP;
if (strcmp (string, "GNOME_STOCK_BUTTON_DOWN") == 0)
return GNOME_STOCK_BUTTON_DOWN;
if (strcmp (string, "GNOME_STOCK_BUTTON_FONT") == 0)
return GNOME_STOCK_BUTTON_FONT;
#endif
g_warning ("Could not determine string from string (%s)\n",
string);
return NULL;
}
#endif
static GladeChoice *
glade_choice_new_from_value (GEnumValue value)
{
GladeChoice *choice;
choice = glade_choice_new ();
choice->name = g_strdup (value.value_nick);
choice->id = g_strdup (value.value_name);
choice->value = value.value;
return choice;
}
/**
* glade_choice_list_new_from_spec:
* @spec: a #GParamSpec
*
* TODO: write me
*
* Returns:
*/
GList *
glade_choice_list_new_from_spec (GParamSpec *spec)
{
GladeChoice *choice;
GEnumClass *class;
GEnumValue value;
GList *list = NULL;
gint num;
gint i;
class = G_PARAM_SPEC_ENUM (spec)->enum_class;
num = class->n_values;
for (i = 0; i < num; i++) {
value = class->values[i];
choice = glade_choice_new_from_value (value);
if (choice)
list = g_list_prepend (list, choice);
}
list = g_list_reverse (list);
return list;
}
static GladeChoice *
glade_choice_new_from_node (GladeXmlNode *node)
{
GladeChoice *choice;
if (!glade_xml_node_verify (node, GLADE_TAG_ENUM))
return NULL;
choice = glade_choice_new ();
choice->name = glade_xml_get_property_string_required (node, GLADE_TAG_NAME, NULL);
choice->id = glade_xml_get_property_string_required (node, GLADE_TAG_ID, NULL);
#if 0
choice->symbol = glade_xml_get_property_string_required (node, GLADE_TAG_SYMBOL, NULL);
#endif
choice->value = glade_enum_from_string (choice->id);
#if 0
if (choice->value == -1)
choice->string = glade_string_from_string (choice->id);
#endif
#if 0
if ((choice->value == -1 && choice->string == NULL) || !choice->name) {
#endif
if (!choice->name) {
g_warning ("Could not create Choice from node");
return NULL;
}
return choice;
}
/**
* glade_choice_list_new_from_node:
* @node: a #GladeXmlNode
*
* TODO: write me
*
* Returns:
*/
GList *
glade_choice_list_new_from_node (GladeXmlNode *node)
{
GladeXmlNode *child;
GladeChoice *choice;
GList *list = NULL;
int def_value = 0;
g_return_val_if_fail (glade_xml_node_verify (node, GLADE_TAG_ENUMS), NULL);
child = glade_xml_node_get_children (node);
for (; child; child = glade_xml_node_next (child)) {
if (!glade_xml_node_verify (child, GLADE_TAG_ENUM))
continue;
choice = glade_choice_new_from_node (child);
if (choice == NULL)
continue;
/* if enum_from_string is not able to find a value for this enum,
we will use as value the position of the item in the enum list */
if (choice->value == -1)
choice->value = def_value;
list = g_list_prepend (list, choice);
++def_value;
}
list = g_list_reverse (list);
return list;
}
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
#ifndef __GLADE_CHOICE_H__
#define __GLADE_CHOICE_H__
G_BEGIN_DECLS
#define GLADE_CHOICE(c) ((GladeChoice *)c)
#define GLADE_IS_CHOICE(c) (c != NULL)
/* GladeChoice is used for GladeProperties of type "choice"
* each property of type choice has a list of GladeChoice objects.
* [see glade-property ]
<Property>
...
...
<Choices>
<Choice>
<Name>Top Level</Name>
<Symbol>GTK_WINDOW_TOPLEVEL</Symbol>
</Choice>
<Choice>
<Name>Dialog</Name>
...
*/
struct _GladeChoice {
GType type;
gchar *name; /* Name of the choice to be used in the gui. This
* field is translated. Like "Top Level" or "Ok"
* (for GTK_WINDOW_TOPLEVEL & GNOME_STOCK_BUTTON_OK
*/
gchar *id;
#if 0
gchar *symbol; /* Symbol for the choice. Like GTK_WINDOW_TOPLEVEL
* (which is an integer) or GNOME_STOCK_BUTTON_FOO
* (which is not an integer). For integers which are
* enum'ed values this symbol is converted to its
* value
*/
#endif
gint value; /* The enum value of the symbol. The symbol
* GTK_WINDOW_TOPLEVEL will be 0 and GTK_WINDOW_POPUP
* will be 1
*/
#if 0
const gchar *string; /* For non-integer values like
* GNOME_STOCK_BUTTON_OK it points to a string
* inside the library that contains it.
* See glade-choice.c#glade_string_from_sring
*/
#endif
};
GladeChoice *glade_choice_new (void);
GladeChoice *glade_choice_clone (GladeChoice *choice);
void glade_choice_free (GladeChoice *choice);
GList *glade_choice_list_new_from_spec (GParamSpec *spec);
GList *glade_choice_list_new_from_node (GladeXmlNode *node);
G_END_DECLS
#endif /* __GLADE_CHOICE_H__ */
This diff is collapsed.
......@@ -187,12 +187,6 @@ struct _GladeEditorProperty
*/
};
typedef enum {
GLADE_EDITOR_INTEGER,
GLADE_EDITOR_FLOAT,
GLADE_EDITOR_DOUBLE,
}GladeEditorNumericType;
GType glade_editor_get_type (void);
GladeEditor *glade_editor_new (void);
......
......@@ -63,6 +63,67 @@
#define FIXED_DEFAULT_CHILD_WIDTH 100
#define FIXED_DEFAULT_CHILD_HEIGHT 60
/* ---------------------------- Custom Property definitions ------------------------ */
static GType
glade_gtk_stock_get_type (void)
{
static GType etype = 0;
if (etype == 0) {
static const GEnumValue values[] = {
{ 0, "None", "glade-none" },
{ 1, "Ok", "gtk-ok" },
{ 2, "Cancel", "gtk-cancel" },
{ 3, "Apply", "gtk-apply" },
{ 4, "Close", "gtk-close" },
{ 0, NULL, NULL }
};
etype = g_enum_register_static ("GtkTtScrollType", values);
}
return etype;
}
GParamSpec *GLADEGTK_API
glade_gtk_stock_spec (void)
{
return g_param_spec_enum ("stock", "stock", "stock",
glade_gtk_stock_get_type (),
0, G_PARAM_READWRITE);
}
GParamSpec *GLADEGTK_API
glade_gtk_standard_int_spec (void)
{
static GParamSpec *int_spec = NULL;
if (!int_spec)
int_spec = g_param_spec_int ("int", "int", "int",
0, G_MAXINT,
0, G_PARAM_READWRITE);
return int_spec;
}
GParamSpec *GLADEGTK_API
glade_gtk_standard_string_spec (void)
{
static GParamSpec *str_spec = NULL;
if (!str_spec)
str_spec = g_param_spec_string ("string", "string", "string",
"", G_PARAM_READWRITE);
return str_spec;
}
GParamSpec *GLADEGTK_API
glade_gtk_standard_float_spec (void)
{
static GParamSpec *float_spec = NULL;
if (!float_spec)
float_spec = g_param_spec_float ("float", "float", "float",
0.0F, G_MAXFLOAT, 0.0F,
G_PARAM_READWRITE);
return float_spec;
}
/* ------------------------------------ Custom Properties ------------------------------ */
/**
* glade_gtk_option_menu_set_items:
......@@ -329,10 +390,9 @@ glade_gtk_box_set_size (GObject *object, GValue *value)
*/
for (i = 0; i < new_size; i++)
{
if (i + 1 < g_list_length(box->children))
continue;
gtk_container_add (GTK_CONTAINER (box),
GTK_WIDGET (glade_placeholder_new ()));
if (g_list_length(box->children) < (i + 1))
gtk_container_add (GTK_CONTAINER (box),
GTK_WIDGET (glade_placeholder_new ()));
}
/* The box has shrunk. Remove the widgets that are on those slots */
......@@ -343,8 +403,7 @@ glade_gtk_box_set_size (GObject *object, GValue *value)
GtkWidget *child_widget = ((GtkBoxChild *) (child->data))->widget;
GladeWidget *glade_widget;
glade_widget = glade_widget_get_from_gtk_widget (child_widget);
if (glade_widget)
if ((glade_widget = glade_widget_get_from_gtk_widget (child_widget)) != NULL)
/* In this case, refuse to shrink */
break;
......@@ -352,6 +411,26 @@ glade_gtk_box_set_size (GObject *object, GValue *value)
}
}
gboolean GLADEGTK_API
glade_gtk_box_verify_size (GObject *object, GValue *value)
{
GtkBox *box = GTK_BOX(object);
GList *child;
gint old_size = g_list_length (box->children);
gint new_size = g_value_get_int (value);
for (child = g_list_last (box->children);
child && old_size > new_size;
child = g_list_previous (child), old_size--)
{
GtkWidget *widget = ((GtkBoxChild *) (child->data))->widget;
if (glade_widget_get_from_gtk_widget (widget) != NULL)
/* In this case, refuse to shrink */
return FALSE;
}
return TRUE;
}
/**
* glade_gtk_toolbar_get_size:
* @object:
......@@ -382,47 +461,53 @@ glade_gtk_toolbar_get_size (GObject *object, GValue *value)
void GLADEGTK_API
glade_gtk_toolbar_set_size (GObject *object, GValue *value)
{
GladeWidget *widget;
GtkToolbar *toolbar;
gint new_size;
gint old_size;
g_return_if_fail (GTK_IS_TOOLBAR (object));
toolbar = GTK_TOOLBAR (object);
widget = glade_widget_get_from_gtk_widget (GTK_WIDGET (toolbar));
g_return_if_fail (widget != NULL);
GtkToolbar *toolbar = GTK_TOOLBAR (object);
gint new_size = g_value_get_int (value);
gint old_size = toolbar->num_children;
GList *child;
old_size = toolbar->num_children;
new_size = g_value_get_int (value);
if (new_size == old_size)
return;
g_print ("Toolbar (set) old size: %d, new size %d\n", old_size, new_size);
/* Ensure base size
*/
while (new_size > old_size) {
gtk_toolbar_append_widget (toolbar, glade_placeholder_new (), NULL, NULL);
old_size++;
}
if (new_size > old_size) {
while (new_size > old_size) {
GtkWidget *placeholder = glade_placeholder_new ();
gtk_toolbar_append_widget (toolbar, placeholder, NULL, NULL);
old_size++;
}
} else {
GList *child = g_list_last (toolbar->children);
for (child = g_list_last (toolbar->children);
child && old_size > new_size;
child = g_list_last (toolbar->children), old_size--)
{
GtkWidget *child_widget = ((GtkToolbarChild *) child->data)->widget;
if (glade_widget_get_from_gtk_widget (child_widget))
break;
while (child && old_size > new_size) {
GtkWidget *child_widget = ((GtkToolbarChild *) child->data)->widget;
GladeWidget *glade_widget;
gtk_container_remove (GTK_CONTAINER (toolbar), child_widget);
}
g_print ("Toolbar (set) now size %d\n", toolbar->num_children);
}
glade_widget = glade_widget_get_from_gtk_widget (child_widget);
if (glade_widget)
glade_project_remove_widget
(glade_widget->project, child_widget);
gboolean GLADEGTK_API
glade_gtk_toolbar_verify_size (GObject *object, GValue *value)
{
GtkToolbar *toolbar = GTK_TOOLBAR (object);
gint new_size = g_value_get_int (value);
gint old_size = toolbar->num_children;
GList *child;
gtk_container_remove (GTK_CONTAINER (toolbar), child_widget);
g_print ("Toolbar (verify) old size: %d, new size %d\n", old_size, new_size);
child = g_list_last (toolbar->children);
old_size--;
}
for (child = g_list_last (toolbar->children);
child && old_size > new_size;
child = g_list_previous (child), old_size--)
{
GtkWidget *child_widget = ((GtkToolbarChild *) child->data)->widget;
if (glade_widget_get_from_gtk_widget (child_widget))
return FALSE;
}
return TRUE;
}
/**
......@@ -457,7 +542,8 @@ glade_gtk_notebook_set_n_pages (GObject *object, GValue *value)
{
GladeWidget *widget;
GtkNotebook *notebook;
gint new_size;
GtkWidget *child_widget;
gint new_size, i;
gint old_size;
notebook = GTK_NOTEBOOK (object);
......@@ -466,51 +552,62 @@ glade_gtk_notebook_set_n_pages (GObject *object, GValue *value)
widget = glade_widget_get_from_gtk_widget (GTK_WIDGET (notebook));
g_return_if_fail (widget != NULL);
old_size = g_list_length (notebook->children);
new_size = g_value_get_int (value);
if (new_size == old_size)
return;
if (new_size > old_size) {
/* The notebook has grown. Add a page. */
while (new_size > old_size) {
GladePlaceholder *placeholder =
GLADE_PLACEHOLDER (glade_placeholder_new ());
gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
GTK_WIDGET (placeholder),
NULL);
old_size++;
}
} else {/* new_size < old_size */
/* The notebook has shrunk. Remove pages */
GladeWidget *child_gwidget;
GtkWidget *child_widget;
/*
* Thing to remember is that GtkNotebook starts the
* page numbers from 0, not 1 (C-style). So we need to do
* old_size-1, where we're referring to "nth" widget.
/* Ensure base size of notebook */
for (i = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook)); i < new_size; i++)
{
gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
glade_placeholder_new (),
NULL);
}
old_size = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook));
/*
* Thing to remember is that GtkNotebook starts the
* page numbers from 0, not 1 (C-style). So we need to do
* old_size-1, where we're referring to "nth" widget.
*/
while (old_size > new_size) {
/* Get the last widget. */
child_widget = gtk_notebook_get_nth_page (notebook, old_size-1);
/*
* If we got it, and its not a placeholder, remove it
* from project.
*/
while (old_size > new_size) {
/* Get the last widget. */
child_widget = gtk_notebook_get_nth_page (notebook, old_size-1);
child_gwidget = glade_widget_get_from_gtk_widget (child_widget);
/*
* If we got it, and its not a placeholder, remove it
* from project.
*/
if (child_gwidget)
glade_project_remove_widget
(child_gwidget->project, child_widget);
if (glade_widget_get_from_gtk_widget (child_widget))
break;
gtk_notebook_remove_page (notebook, old_size-1);
old_size--;
}
gtk_notebook_remove_page (notebook, old_size-1);
old_size--;
}
}
gboolean GLADEGTK_API
glade_gtk_notebook_verify_n_pages (GObject *object, GValue *value)
{
GtkNotebook *notebook = GTK_NOTEBOOK(object);
GtkWidget *child_widget;
gint old_size, new_size = g_value_get_int (value);
for (old_size = gtk_notebook_get_n_pages (notebook);
old_size > new_size; old_size--) {
/* Get the last widget. */
child_widget = gtk_notebook_get_nth_page (notebook, old_size-1);
/*
* If we got it, and its not a placeholder, remove it
* from project.
*/
if (glade_widget_get_from_gtk_widget (child_widget))
return FALSE;
}
return TRUE;
}
static gboolean
glade_gtk_table_has_child (GtkTable *table,
......@@ -561,14 +658,14 @@ glade_gtk_table_set_n_common (GObject *object, GValue *value, gboolean for_rows)
{
GladeWidget *widget;
GtkTable *table;
gint new_size;
gint old_size;
guint new_size;
guint old_size;
gint i, j;
table = GTK_TABLE (object);
g_return_if_fail (GTK_IS_TABLE (table));
new_size = g_value_get_int (value);
new_size = g_value_get_uint (value);
old_size = for_rows ? table->nrows : table->ncols;
if (new_size < 1)
......@@ -668,6 +765,34 @@ glade_gtk_table_set_n_columns (GObject *object, GValue *value)
glade_gtk_table_set_n_common (object, value, FALSE);
}
static gboolean
glade_gtk_table_verify_n_common (GObject *object, GValue *value, gboolean for_rows)
{
GtkTable *table = GTK_TABLE(object);
guint new_size = g_value_get_uint (value);
if (glade_gtk_table_widget_exceeds_bounds
(table,