diff options
Diffstat (limited to 'gladeui')
78 files changed, 0 insertions, 44552 deletions
diff --git a/gladeui/Makefile.am b/gladeui/Makefile.am deleted file mode 100644 index db99010b..00000000 --- a/gladeui/Makefile.am +++ /dev/null @@ -1,161 +0,0 @@ - -common_defines = \ - -DG_LOG_DOMAIN=\"GladeUI\" \ - -DGLADE_DATADIR="\"$(pkgdatadir)\"" \ - -DGLADE_LIBDIR="\"$(pkglibdir)\"" \ - -DGLADE_CATALOGSDIR="\"$(pkgdatadir)/catalogs\""\ - -DGLADE_MODULESDIR="\"$(pkglibdir)/modules\"" \ - -DGLADE_PLUGINSDIR="\"$(pkglibdir)/plugins\"" \ - -DGLADE_PIXMAPSDIR="\"$(pkgdatadir)/pixmaps\"" \ - -DGLADE_LOCALEDIR="\"$(datadir)/locale\"" - -lib_LTLIBRARIES = libgladeui-1.la - -BUILT_SOURCES = glade-marshallers.c glade-marshallers.h - -EXTRA_DIST = glade-marshallers.list gladeui.rc.in - -# The glade-3 core library -libgladeui_1_la_SOURCES = \ - glade-widget-adaptor.c \ - glade-debug.c \ - glade-project.c \ - glade-parameter.c \ - glade-placeholder.c \ - glade-custom.c \ - glade-inspector.c \ - glade-xml-utils.c \ - glade-palette.c \ - glade-palette-item.c \ - glade-palette-box.c \ - glade-palette-expander.c \ - glade-design-layout.c \ - glade-design-view.c \ - glade-cursor.c \ - glade-catalog.c \ - glade-property.c \ - glade-property-class.c \ - glade-popup.c \ - glade-widget.c \ - glade-editor-property.c \ - glade-editor.c \ - glade-utils.c \ - glade-signal.c \ - glade-signal-editor.c \ - glade-clipboard.c \ - glade-clipboard-view.c \ - glade-command.c \ - glade-id-allocator.c \ - glade-id-allocator.h \ - glade-marshallers.c \ - glade-accumulators.c \ - glade-parser.c \ - glade-builtins.c \ - glade-app.c \ - glade-keysyms.c \ - glade-fixed.c \ - glade-base-editor.c \ - glade-palette-item.h \ - glade-palette-box.h \ - glade-palette-expander.h \ - glade-popup.h \ - glade-catalog.h \ - glade-marshallers.h \ - glade-accumulators.h \ - glade-widget-action.c - -libgladeui_1_la_CPPFLAGS = \ - $(common_defines) \ - -I$(top_srcdir) \ - -I$(top_builddir) \ - $(AM_CPPFLAGS) - -libgladeui_1_la_CFLAGS = \ - $(GTK_CFLAGS) \ - $(WARN_CFLAGS) \ - $(AM_CFLAGS) - -libgladeui_1_la_LDFLAGS = -version-info $(GLADE_CURRENT):$(GLADE_REVISION):$(GLADE_AGE) $(AM_LDFLAGS) -libgladeui_1_la_LIBADD = $(GTK_LIBS) - - -libgladeuiincludedir=$(includedir)/libgladeui-1.0/gladeui -libgladeuiinclude_HEADERS = \ - glade.h \ - glade-debug.h \ - glade-project.h \ - glade-inspector.h \ - glade-parameter.h \ - glade-placeholder.h \ - glade-custom.h \ - glade-editor.h \ - glade-editor-property.h \ - glade-signal-editor.h \ - glade-palette.h \ - glade-palette-item.h \ - glade-design-layout.h \ - glade-design-view.h \ - glade-widget.h \ - glade-widget-adaptor.h \ - glade-property.h \ - glade-property-class.h \ - glade-utils.h \ - glade-clipboard.h \ - glade-clipboard-view.h \ - glade-command.h \ - glade-app.h \ - glade-builtins.h \ - glade-fixed.h \ - glade-base-editor.h \ - glade-xml-utils.h \ - glade-parser.h \ - glade-signal.h \ - glade-cursor.h \ - glade-widget-action.h - - -if PLATFORM_WIN32 -libgladeui_1_la_LDFLAGS += -no-undefined -endif - -if NATIVE_WIN32 -libgladeui_1_la_LDFLAGS += -Wl,gladeui-win32-res.o -export-symbols gladeui.def -libgladeui_1_la_DEPENDENCIES = gladeui-win32-res.o gladeui.def -endif - -gladeui-win32-res.o: gladeui.rc - $(WINDRES) $< $@ - -# gladeui.def: auto-generated DEF file for linker input -# The routines below will scan the header files and extracts symbol declarations. -# The symbol 'custom_get_type' is added manually. It's naming deviates from -# the pattern set by all other public symbols in the glade namespace. -# -gladeui.def: $(libgladeuiinclude_HEADERS) - @echo Generating $@ - @(echo EXPORTS; \ - echo 'custom_get_type'; \ - (cd $(srcdir); cat $(libgladeuiinclude_HEADERS) || echo 'glade_ERROR ()' ) | \ - grep -v -E '^# *include' | \ - grep -v -E '^# *define' | \ - grep -E '[^\(]glade_.*[[:space:]]+\(.*' | \ - sed -e 's/[ ]*(.*//' | \ - sed -e 's/.*glade_/glade_/' | \ - sort; \ - ) >$@ - @ ! grep -q glade_ERROR $@ || ($(RM) $@; false) - -# -# Marshaller generation -# -glade-marshallers.h: glade-marshallers.list $(GLIB_GENMARSHAL) - $(GLIB_GENMARSHAL) --prefix=glade_marshal $(srcdir)/glade-marshallers.list --header > glade-marshallers-h.tmp \ - && mv glade-marshallers-h.tmp glade-marshallers.h \ - || ( rm -f glade-marshallers-h.tmp && exit 1) -glade-marshallers.c: glade-marshallers.list $(GLIB_GENMARSHAL) - $(GLIB_GENMARSHAL) --prefix=glade_marshal $(srcdir)/glade-marshallers.list --body --header > glade-marshallers-c.tmp \ - && mv glade-marshallers-c.tmp glade-marshallers.c \ - || ( rm -f glade-marshallers-c.tmp && exit 1 ) - - -CLEANFILES = $(BUILT_SOURCES) gladeui.def diff --git a/gladeui/glade-accumulators.c b/gladeui/glade-accumulators.c deleted file mode 100644 index 023d022b..00000000 --- a/gladeui/glade-accumulators.c +++ /dev/null @@ -1,87 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * glade-clipboard.c - An object for handling Cut/Copy/Paste. - * - * Copyright (C) 2005 The GNOME Foundation. - * - * Author(s): - * Tristan Van Berkom <tvb@gnome.org> - * - * 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. - */ - -#include "config.h" - -#include "glade-accumulators.h" - -#include <glib-object.h> - - -gboolean -glade_single_object_accumulator (GSignalInvocationHint *ihint, - GValue *return_accu, - const GValue *handler_return, - gpointer dummy) -{ - GObject *object = g_value_get_object (handler_return); - g_value_set_object (return_accu, object); - - return (object == NULL); -} - -/* From gtkmain.c */ -gboolean -glade_boolean_handled_accumulator (GSignalInvocationHint *ihint, - GValue *return_accu, - const GValue *handler_return, - gpointer dummy) -{ - gboolean continue_emission; - gboolean signal_handled; - - signal_handled = g_value_get_boolean (handler_return); - g_value_set_boolean (return_accu, signal_handled); - continue_emission = !signal_handled; - - return continue_emission; -} - -gboolean -glade_string_accumulator (GSignalInvocationHint *ihint, - GValue *return_accu, - const GValue *handler_return, - gpointer dummy) -{ - const gchar *handler_str; - - g_free ((void *)g_value_get_string (return_accu)); - - handler_str = g_value_get_string (handler_return); - g_value_set_string (return_accu, handler_str); - - return (handler_str == NULL); -} - -gboolean -glade_stop_emission_accumulator (GSignalInvocationHint *ihint, - GValue *return_accu, - const GValue *handler_return, - gpointer dummy) -{ - g_value_copy (handler_return, return_accu); - - return FALSE; -} diff --git a/gladeui/glade-accumulators.h b/gladeui/glade-accumulators.h deleted file mode 100644 index 7b5e090d..00000000 --- a/gladeui/glade-accumulators.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef __GLADE_ACCUMULATORS_H__ -#define __GLADE_ACCUMULATORS_H__ - -#include <glib-object.h> - -G_BEGIN_DECLS - -gboolean glade_single_object_accumulator (GSignalInvocationHint *ihint, - GValue *return_accu, - const GValue *handler_return, - gpointer dummy); - -gboolean glade_boolean_handled_accumulator (GSignalInvocationHint *ihint, - GValue *return_accu, - const GValue *handler_return, - gpointer dummy); - -gboolean glade_string_accumulator (GSignalInvocationHint *ihint, - GValue *return_accu, - const GValue *handler_return, - gpointer dummy); - -gboolean glade_stop_emission_accumulator (GSignalInvocationHint *ihint, - GValue *return_accu, - const GValue *handler_return, - gpointer dummy); -G_END_DECLS - -#endif /* __GLADE_ACCUMULATORS_H__ */ diff --git a/gladeui/glade-app.c b/gladeui/glade-app.c deleted file mode 100644 index 9d813215..00000000 --- a/gladeui/glade-app.c +++ /dev/null @@ -1,1668 +0,0 @@ -/* -*- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Authors: - * Naba Kumar <naba@gnome.org> - */ - -#include <config.h> - -#include "glade.h" -#include "glade-clipboard-view.h" -#include "glade-debug.h" -#include "glade-cursor.h" -#include "glade-catalog.h" -#include "glade-fixed.h" -#include "glade-marshallers.h" -#include "glade-accumulators.h" - -#include <string.h> -#include <glib.h> -#include <glib/gstdio.h> -#include <glib/gi18n-lib.h> -#include <gdk/gdkkeysyms.h> -#include <gtk/gtkstock.h> - -#define GLADE_CONFIG_FILENAME "glade-3.conf" - -#define GLADE_APP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GLADE_TYPE_APP, GladeAppPrivate)) - -enum -{ - WIDGET_EVENT, - UPDATE_UI, - LAST_SIGNAL -}; - -enum -{ - PROP_0, - PROP_ACTIVE_PROJECT, - PROP_POINTER_MODE -}; - -struct _GladeAppPrivate -{ - GtkWidget *window; - - GladePalette *palette; /* See glade-palette */ - GladeProject *active_project; /* Currently active project (if there is at least one - * project; then this is always valid) */ - GladeEditor *editor; /* See glade-editor */ - GladeClipboard *clipboard; /* See glade-clipboard */ - GList *catalogs; /* See glade-catalog */ - - GList *projects; /* The list of Projects */ - - GKeyFile *config;/* The configuration file */ - - GtkWindow *transient_parent; /* If set by glade_app_set_transient_parent(); this - * will be used as the transient parent of all toplevel - * GladeWidgets. - */ - GtkAccelGroup *accel_group; /* Default acceleration group for this app */ - GList *undo_list, *redo_list; /* Lists of buttons to refresh in update-ui signal */ - - GladePointerMode pointer_mode; /* Current mode for the pointer in the workspace */ -}; - -static guint glade_app_signals[LAST_SIGNAL] = { 0 }; - -/* installation paths */ -static gchar *catalogs_dir = NULL; -static gchar *modules_dir = NULL; -static gchar *plugins_dir = NULL; -static gchar *pixmaps_dir = NULL; -static gchar *locale_dir = NULL; - -static GladeApp *singleton_app = NULL; - -static void glade_init_check (void); - -G_DEFINE_TYPE (GladeApp, glade_app, G_TYPE_OBJECT); - - -GType -glade_pointer_mode_get_type (void) -{ - static GType etype = 0; - - if (etype == 0) - { - static const GEnumValue values[] = - { - { GLADE_POINTER_SELECT, "select", "Select widgets" }, - { GLADE_POINTER_ADD_WIDGET, "add", "Add widgets" }, - { GLADE_POINTER_DRAG_RESIZE, "drag-resize", "Drag and resize widgets" }, - { 0, NULL, NULL } - }; - etype = g_enum_register_static ("GladePointerMode", - values); - } - return etype; -} - - -/***************************************************************** - * GObjectClass * - *****************************************************************/ -static GObject * -glade_app_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties) -{ - GObject *object; - - /* singleton */ - if (!singleton_app) - { - object = G_OBJECT_CLASS (glade_app_parent_class)->constructor (type, - n_construct_properties, - construct_properties); - singleton_app = GLADE_APP (object); - } - else - { - g_object_ref (singleton_app); - } - - return G_OBJECT (singleton_app); -} - - - -static void -glade_app_dispose (GObject *app) -{ - GladeAppPrivate *priv = GLADE_APP_GET_PRIVATE (app); - - if (priv->editor) - { - g_object_unref (priv->editor); - priv->editor = NULL; - } - if (priv->palette) - { - g_object_unref (priv->palette); - priv->palette = NULL; - } - if (priv->clipboard) - { - gtk_widget_destroy (GTK_WIDGET (priv->clipboard->view)); - priv->clipboard = NULL; - } - /* FIXME: Remove projects */ - - if (priv->config) - { - g_key_file_free (priv->config); - priv->config = NULL; - } - - G_OBJECT_CLASS (glade_app_parent_class)->dispose (app); -} - -static void -glade_app_finalize (GObject *app) -{ - g_free (catalogs_dir); - g_free (modules_dir); - g_free (pixmaps_dir); - g_free (locale_dir); - - glade_catalog_destroy_all (); - - G_OBJECT_CLASS (glade_app_parent_class)->finalize (app); -} - -static void -glade_app_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - switch (property_id) - { - case PROP_ACTIVE_PROJECT: - glade_app_set_project (g_value_get_object (value)); - break; - case PROP_POINTER_MODE: - glade_app_set_pointer_mode (g_value_get_enum (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID - (object, property_id, pspec); - break; - } -} - -static void -glade_app_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - GladeApp *app = GLADE_APP (object); - - - switch (property_id) - { - case PROP_ACTIVE_PROJECT: - g_value_set_object (value, app->priv->active_project); - break; - case PROP_POINTER_MODE: - g_value_set_enum (value, app->priv->pointer_mode); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object,property_id,pspec); - break; - } -} - -/***************************************************************** - * GladeAppClass * - *****************************************************************/ -static void -glade_app_refresh_undo_redo_button (GladeApp *app, - GtkWidget *button, - gboolean undo) -{ - GladeCommand *command = NULL; - static GtkTooltips *button_tips = NULL; - GladeProject *project; - gchar *desc; - - if (button_tips == NULL) - button_tips = gtk_tooltips_new (); - - if ((project = glade_app_get_project ()) != NULL) - { - if (undo) - command = glade_project_next_undo_item (project); - else - command = glade_project_next_redo_item (project); - } - - /* Change tooltips */ - desc = g_strdup_printf ((undo) ? _("Undo: %s") : _("Redo: %s"), - command ? command->description : _("the last action")); - gtk_tooltips_set_tip (GTK_TOOLTIPS (button_tips), button, desc, NULL); - g_free (desc); - - /* Set sensitivity on the button */ - gtk_widget_set_sensitive (button, command != NULL); -} - -static void -glade_app_update_ui_default (GladeApp *app) -{ - GList *list; - - for (list = app->priv->undo_list; list; list = list->next) - if (list->data) - glade_app_refresh_undo_redo_button (app, list->data, TRUE); - - for (list = app->priv->redo_list; list; list = list->next) - if (list->data) - glade_app_refresh_undo_redo_button (app, list->data, FALSE); -} - -static void -on_palette_button_clicked (GladePalette *palette, GladeApp *app) -{ - GladeWidgetAdaptor *adaptor; - GladeWidget *widget; - - g_return_if_fail (GLADE_IS_PALETTE (palette)); - adaptor = glade_palette_get_current_item (palette); - - /* class may be NULL if the selector was pressed */ - if (adaptor && GWA_IS_TOPLEVEL (adaptor)) - { - widget = glade_command_create (adaptor, NULL, NULL, app->priv->active_project); - - /* if this is a top level widget set the accel group */ - if (widget && app->priv->accel_group && GTK_IS_WINDOW (widget->object)) - { - gtk_window_add_accel_group (GTK_WINDOW (widget->object), - app->priv->accel_group); - } - - glade_palette_deselect_current_item (palette, FALSE); - } -} - -static gboolean -clipboard_view_on_delete_cb (GtkWidget *clipboard_view, GdkEvent *e, GladeApp *app) -{ - glade_util_hide_window (GTK_WINDOW (clipboard_view)); - return TRUE; -} - -static GKeyFile * -glade_app_config_load (GladeApp *app) -{ - GKeyFile *config = g_key_file_new (); - gchar *filename; - - filename = g_build_filename (g_get_user_config_dir (), GLADE_CONFIG_FILENAME, NULL); - - g_key_file_load_from_file (config, filename, G_KEY_FILE_NONE, NULL); - - g_free (filename); - - return config; -} - -const gchar * -glade_app_get_catalogs_dir (void) -{ - glade_init_check (); - - return catalogs_dir; -} - -const gchar * -glade_app_get_modules_dir (void) -{ - glade_init_check (); - - return modules_dir; -} - -const gchar * -glade_app_get_plugins_dir (void) -{ - glade_init_check (); - - return plugins_dir; -} - - -const gchar * -glade_app_get_pixmaps_dir (void) -{ - glade_init_check (); - - return pixmaps_dir; -} - -const gchar * -glade_app_get_locale_dir (void) -{ - glade_init_check (); - - return locale_dir; -} - -/* build package paths at runtime */ -static void -build_package_paths (void) -{ -#ifdef G_OS_WIN32 - gchar *prefix; - - prefix = g_win32_get_package_installation_directory (NULL, NULL); - pixmaps_dir = g_build_filename (prefix, "share", PACKAGE, "pixmaps", NULL); - catalogs_dir = g_build_filename (prefix, "share", PACKAGE, "catalogs", NULL); - modules_dir = g_build_filename (prefix, "lib", PACKAGE, "modules", NULL); - locale_dir = g_build_filename (prefix, "share", "locale", NULL); - g_free (prefix); -#else - catalogs_dir = g_strdup (GLADE_CATALOGSDIR); - modules_dir = g_strdup (GLADE_MODULESDIR); - plugins_dir = g_strdup (GLADE_PLUGINSDIR); - pixmaps_dir = g_strdup (GLADE_PIXMAPSDIR); - locale_dir = g_strdup (GLADE_LOCALEDIR); -#endif -} - -/* initialization function for libgladeui (not GladeApp) */ -static void -glade_init_check (void) -{ - static gboolean initialised = FALSE; - - if (initialised) - return; - - build_package_paths (); - - bindtextdomain (GETTEXT_PACKAGE, locale_dir); - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); - - initialised = TRUE; -} - -static void -glade_app_init (GladeApp *app) -{ - static gboolean initialized = FALSE; - - app->priv = GLADE_APP_GET_PRIVATE (app); - - glade_init_check (); - - if (!initialized) - { - gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), - GLADE_DATADIR G_DIR_SEPARATOR_S "pixmaps"); - - glade_cursor_init (); - - initialized = TRUE; - } - - app->priv->accel_group = NULL; - - /* Initialize app objects */ - app->priv->catalogs = (GList *) glade_catalog_load_all (); - - /* Create palette */ - app->priv->palette = (GladePalette *) glade_palette_new (app->priv->catalogs); - g_object_ref_sink (app->priv->palette); - - g_signal_connect (G_OBJECT (app->priv->palette), "toggled", - G_CALLBACK (on_palette_button_clicked), app); - - /* Create Editor */ - app->priv->editor = GLADE_EDITOR (glade_editor_new ()); - g_object_ref_sink (GTK_OBJECT (app->priv->editor)); - - glade_editor_refresh (app->priv->editor); - - /* Create clipboard */ - app->priv->clipboard = glade_clipboard_new (); - app->priv->clipboard->view = glade_clipboard_view_new (app->priv->clipboard); - gtk_window_set_title (GTK_WINDOW (app->priv->clipboard->view), _("Clipboard")); - g_signal_connect_after (G_OBJECT (app->priv->clipboard->view), "delete_event", - G_CALLBACK (clipboard_view_on_delete_cb), - app); - - /* Load the configuration file */ - app->priv->config = glade_app_config_load (app); - - /* Undo/Redo button list */ - app->priv->undo_list = app->priv->redo_list = NULL; -} - -static void -glade_app_class_init (GladeAppClass * klass) -{ - GObjectClass *object_class; - - object_class = G_OBJECT_CLASS (klass); - - object_class->constructor = glade_app_constructor; - object_class->dispose = glade_app_dispose; - object_class->finalize = glade_app_finalize; - object_class->get_property = glade_app_get_property; - object_class->set_property = glade_app_set_property; - - klass->update_ui_signal = glade_app_update_ui_default; - klass->show_properties = NULL; - klass->hide_properties = NULL; - - /** - * GladeApp::update-ui: - * @gladeapp: the #GladeApp which received the signal. - * - * Emitted when a project name changes or a cut/copy/paste/delete occurred. - */ - glade_app_signals[UPDATE_UI] = - g_signal_new ("update-ui", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (GladeAppClass, - update_ui_signal), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - - /** - * GladeApp::widget-event: - * @gladeapp: the #GladeApp which received the signal. - * @arg1: The toplevel #GladeWidget who's hierarchy recieved an event - * @arg2: The #GdkEvent - * - * Emitted when a #GladeWidget or one of its children is a GtkWidget derivative - * and is about to recieve an event from gdk. - * - * Returns: whether the event was handled or not - */ - glade_app_signals[WIDGET_EVENT] = - g_signal_new ("widget-event", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GladeAppClass, - widget_event), - glade_boolean_handled_accumulator, NULL, - glade_marshal_BOOLEAN__OBJECT_BOXED, - G_TYPE_BOOLEAN, 2, - GLADE_TYPE_WIDGET, - GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); - - g_object_class_install_property - (object_class, PROP_ACTIVE_PROJECT, - g_param_spec_object - ("active-project", _("Active Project"), - _("The active project"), - GLADE_TYPE_PROJECT, G_PARAM_READWRITE)); - - g_object_class_install_property - (object_class, PROP_POINTER_MODE, - g_param_spec_enum - ("pointer-mode", _("Pointer Mode"), - _("Current mode for the pointer in the workspace"), - GLADE_TYPE_POINTER_MODE, - GLADE_POINTER_SELECT, - G_PARAM_READWRITE)); - - g_type_class_add_private (klass, sizeof (GladeAppPrivate)); -} - -/***************************************************************** - * Public API * - *****************************************************************/ -static void -on_widget_name_changed_cb (GladeProject *project, - GladeWidget *widget, - GladeEditor *editor) -{ - glade_editor_update_widget_name (editor); -} - -static void -on_project_selection_changed_cb (GladeProject *project, GladeApp *app) -{ - GList *list; - gint num; - - g_return_if_fail (GLADE_IS_PROJECT (project)); - g_return_if_fail (GLADE_IS_APP (app)); - - /* Only update the editor if the selection has changed on - * the currently active project. - */ - if (app->priv->editor && - (project == glade_app_get_project ())) - { - list = glade_project_selection_get (project); - num = g_list_length (list); - if (num == 1 && !GLADE_IS_PLACEHOLDER (list->data)) - glade_editor_load_widget (app->priv->editor, - glade_widget_get_from_gobject - (G_OBJECT (list->data))); - else - glade_editor_load_widget (app->priv->editor, NULL); - } -} - -/** - * glade_app_config_save - * - * Saves the GKeyFile to "g_get_user_config_dir()/GLADE_CONFIG_FILENAME" - * - * Return 0 on success. - */ -gint -glade_app_config_save () -{ - GIOChannel *channel; - GIOStatus status; - gchar *data=NULL, *filename; - const gchar *config_dir = g_get_user_config_dir (); - GError *error = NULL; - gsize size, written, bytes_written = 0; - static gboolean error_shown = FALSE; - GladeApp *app; - - /* If we had any errors; wait untill next session to retry. - */ - if (error_shown) return -1; - - app = glade_app_get (); - - /* Just in case... try to create the config directory */ - if (g_file_test (config_dir, G_FILE_TEST_IS_DIR) == FALSE) - { - if (g_file_test (config_dir, G_FILE_TEST_EXISTS)) - { - /* Config dir exists but is not a directory */ - glade_util_ui_message - (glade_app_get_window(), - GLADE_UI_ERROR, - _("Trying to save private data to %s directory " - "but it is a regular file.\n" - "No private data will be saved in this session"), - config_dir); - error_shown = TRUE; - return -1; - } - else if (g_mkdir (config_dir, S_IRWXU) != 0) - { - /* Doesnt exist; failed to create */ - glade_util_ui_message - (glade_app_get_window(), - GLADE_UI_ERROR, - _("Failed to create directory %s to save private data.\n" - "No private data will be saved in this session"), config_dir); - error_shown = TRUE; - return -1; - } - } - - filename = g_build_filename (config_dir, GLADE_CONFIG_FILENAME, NULL); - - if ((channel = g_io_channel_new_file (filename, "w", &error)) != NULL) - { - if ((data = g_key_file_to_data (app->priv->config, &size, &error)) != NULL) - { - - /* Implement loop here */ - while ((status = g_io_channel_write_chars - (channel, - data + bytes_written, /* Offset of write */ - size - bytes_written, /* Size left to write */ - &written, &error)) != G_IO_STATUS_ERROR && - (bytes_written + written) < size) - bytes_written += written; - - if (status == G_IO_STATUS_ERROR) - { - glade_util_ui_message - (glade_app_get_window(), - GLADE_UI_ERROR, - _("Error writing private data to %s (%s).\n" - "No private data will be saved in this session"), - filename, error->message); - error_shown = TRUE; - } - g_free (data); - } - else - { - glade_util_ui_message - (glade_app_get_window(), - GLADE_UI_ERROR, - _("Error serializing configuration data to save (%s).\n" - "No private data will be saved in this session"), - error->message); - error_shown = TRUE; - } - g_io_channel_shutdown(channel, TRUE, NULL); - g_io_channel_unref (channel); - } - else - { - glade_util_ui_message - (glade_app_get_window(), - GLADE_UI_ERROR, - _("Error opening %s to write private data (%s).\n" - "No private data will be saved in this session"), - filename, error->message); - error_shown = TRUE; - } - g_free (filename); - - if (error) - { - g_error_free (error); - return -1; - } - return 0; -} - -void -glade_app_set_transient_parent (GtkWindow *parent) -{ - GList *projects, *objects; - GladeApp *app; - - g_return_if_fail (GTK_IS_WINDOW (parent)); - - app = glade_app_get (); - app->priv->transient_parent = parent; - - /* Loop over all projects/widgets and set_transient_for the toplevels. - */ - for (projects = glade_app_get_projects (); /* projects */ - projects; projects = projects->next) - for (objects = (GList *) glade_project_get_objects (GLADE_PROJECT (projects->data)); /* widgets */ - objects; objects = objects->next) - if (GTK_IS_WINDOW (objects->data)) - gtk_window_set_transient_for - (GTK_WINDOW (objects->data), parent); -} - -GtkWindow * -glade_app_get_transient_parent (void) -{ - GtkWindow *parent; - GladeApp *app = glade_app_get (); - - parent = app->priv->transient_parent; - - return parent; -} - -GladeApp * -glade_app_get (void) -{ - if (!singleton_app) - g_critical ("No available GladeApp"); - return singleton_app; -} - -void -glade_app_update_ui (void) -{ - GladeApp *app = glade_app_get (); - - g_signal_emit (G_OBJECT (app), - glade_app_signals[UPDATE_UI], 0); -} - -/** - * glade_app_widget_event: - * @widget: the #GladeWidget that recieved the event - * @event: the #GdkEvent - * - * Notifies the core that a widget recieved an event, - * the core will then take responsability of sending - * the right event to the right widget. - * - * Returns whether the event was handled by glade. - */ -gboolean -glade_app_widget_event (GladeWidget *widget, - GdkEvent *event) -{ - GladeApp *app = glade_app_get (); - GladeWidget *toplevel = widget; - gboolean retval = FALSE; - - g_return_val_if_fail (GLADE_IS_WIDGET (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - while (toplevel->parent) - toplevel = toplevel->parent; - - g_signal_emit (G_OBJECT (app), - glade_app_signals[WIDGET_EVENT], 0, widget, event, &retval); - - return retval; -} - - -void -glade_app_set_window (GtkWidget *window) -{ - GladeApp *app = glade_app_get (); - - app->priv->window = window; -} - -GtkWidget * -glade_app_get_window (void) -{ - GladeApp *app = glade_app_get (); - return app->priv->window; -} - -GladeEditor * -glade_app_get_editor (void) -{ - GladeApp *app = glade_app_get (); - return app->priv->editor; -} - -GladePalette * -glade_app_get_palette (void) -{ - GladeApp *app = glade_app_get (); - return app->priv->palette; -} - -GladeClipboard * -glade_app_get_clipboard (void) -{ - GladeApp *app = glade_app_get (); - return app->priv->clipboard; -} - -GtkWidget * -glade_app_get_clipboard_view (void) -{ - GladeApp *app = glade_app_get (); - return app->priv->clipboard->view; -} - -GladeProject * -glade_app_get_project (void) -{ - GladeApp *app = glade_app_get (); - return app->priv->active_project; -} - -GList * -glade_app_get_projects (void) -{ - GladeApp *app = glade_app_get (); - return app->priv->projects; -} - -GKeyFile * -glade_app_get_config (void) -{ - GladeApp *app = glade_app_get (); - return app->priv->config; -} - -gboolean -glade_app_is_project_loaded (const gchar *project_path) -{ - GladeApp *app; - GList *list; - gboolean loaded = FALSE; - - if (project_path == NULL) - return FALSE; - - app = glade_app_get (); - - for (list = app->priv->projects; list; list = list->next) - { - GladeProject *cur_project = GLADE_PROJECT (list->data); - - if ((loaded = glade_project_get_path (cur_project) && - (strcmp (glade_project_get_path (cur_project), project_path) == 0))) - break; - } - - return loaded; -} - -/** - * glade_app_get_project_by_path: - * @project_path: The path of an open project - * - * Finds an open project with @path - * - * Returns: A #GladeProject, or NULL if no such open project was found - */ -GladeProject* -glade_app_get_project_by_path (const gchar *project_path) -{ - GladeApp *app; - GList *l; - gchar *canonical_path; - - if (project_path == NULL) - return NULL; - - app = glade_app_get (); - - canonical_path = glade_util_canonical_path (project_path); - - for (l = app->priv->projects; l; l = l->next) - { - GladeProject *project = (GladeProject *) l->data; - - if (glade_project_get_path (project) && strcmp (canonical_path, glade_project_get_path (project)) == 0) { - g_free (canonical_path); - return project; - } - } - - g_free (canonical_path); - - return NULL; -} - -void -glade_app_show_properties (gboolean raise) -{ - GladeApp *app = glade_app_get (); - - if (GLADE_APP_GET_CLASS (app)->show_properties) - GLADE_APP_GET_CLASS (app)->show_properties (app, raise); - else - g_critical ("%s not implemented\n", G_GNUC_FUNCTION); -} - -void -glade_app_hide_properties (void) -{ - GladeApp *app = glade_app_get (); - - if (GLADE_APP_GET_CLASS (app)->hide_properties) - GLADE_APP_GET_CLASS (app)->hide_properties (app); - else - g_critical ("%s not implemented\n", G_GNUC_FUNCTION); - -} - -void -glade_app_update_instance_count (GladeProject *project) -{ - GladeApp *app; - GList *l; - gint temp, max = 0, i = 0, uncounted_projects = 0; - gchar *project_name; - - g_return_if_fail (GLADE_IS_PROJECT (project)); - - if (glade_project_get_instance_count (project) > 0) - return; - - project_name = glade_project_get_name (project); - - app = glade_app_get (); - - for (l = app->priv->projects; l; l = l->next) - { - GladeProject *prj = GLADE_PROJECT (l->data); - gchar *name = glade_project_get_name (project); - - if (prj != project && !g_utf8_collate (name, project_name)) - { - i++; - temp = MAX (glade_project_get_instance_count (prj) + 1, i); - max = MAX (temp, max); - - if (glade_project_get_instance_count (prj) < 1) - uncounted_projects++; - } - - g_free (name); - } - - g_free (project_name); - - /* Dont reset the initially opened project */ - if (uncounted_projects > 1 || g_list_find (app->priv->projects, project) == NULL) - { - glade_project_set_instance_count (project, MAX (max, i)); - } -} - -void -glade_app_add_project (GladeProject *project) -{ - GladeApp *app; - g_return_if_fail (GLADE_IS_PROJECT (project)); - - /* If the project was previously loaded, don't re-load */ - if (glade_app_is_project_loaded (glade_project_get_path (project))) - { - glade_app_set_project (project); - return; - } - glade_app_update_instance_count (project); - - app = glade_app_get (); - - g_object_ref (project); - - app->priv->projects = g_list_append (app->priv->projects, project); - - /* connect to the project signals so that the editor can be updated */ - g_signal_connect (G_OBJECT (project), "widget_name_changed", - G_CALLBACK (on_widget_name_changed_cb), app->priv->editor); - g_signal_connect (G_OBJECT (project), "selection_changed", - G_CALLBACK (on_project_selection_changed_cb), app); - - /* add acceleration groups to every top level widget */ - if (app->priv->accel_group) - glade_project_set_accel_group (project, app->priv->accel_group); - - glade_app_set_project (project); - - /* XXX I think the palette should detect this by itself */ - gtk_widget_set_sensitive (GTK_WIDGET (app->priv->palette), TRUE); - -} - -void -glade_app_remove_project (GladeProject *project) -{ - GladeApp *app; - g_return_if_fail (GLADE_IS_PROJECT (project)); - - app = glade_app_get (); - - app->priv->projects = g_list_remove (app->priv->projects, project); - - /* this is needed to prevent clearing the selection of a closed project - */ - app->priv->active_project = NULL; - - /* If no more projects */ - if (app->priv->projects == NULL) - { - /* XXX I think the palette should detect this. */ - gtk_widget_set_sensitive (GTK_WIDGET (app->priv->palette), FALSE); - } - else - glade_app_set_project (g_list_last (app->priv->projects)->data); - - /* Its safe to just release the project as the project emits a - * "close" signal and everyone is responsable for cleaning up at - * that point. - */ - g_object_unref (project); - -} - - -/** - * glade_app_set_project: - * @project: A #GladeProject - * - * Sets the active project in the #GladeApp to @project. - */ -void -glade_app_set_project (GladeProject *project) -{ - GladeApp *app = glade_app_get(); - - g_return_if_fail (GLADE_IS_PROJECT (project)); - - if (app->priv->active_project == project) - return; - - if (!g_list_find (app->priv->projects, project)) - { - g_warning ("Could not set project because it could not " - " be found in the app->priv->project list\n"); - return; - } - - /* clear the selection in the previous project */ - if (app->priv->active_project) - glade_project_selection_clear (app->priv->active_project, FALSE); - - app->priv->active_project = project; - - /* (XXX really ?) trigger the selection changed signal to update the editor */ - glade_project_selection_changed (project); - - /* Update UI */ - glade_app_update_ui (); - - g_object_notify (G_OBJECT (app), "active-project"); -} - - -/** - * glade_app_set_pointer_mode: - * @mode: A #GladePointerMode - * - * Sets the #GladePointerMode - */ -void -glade_app_set_pointer_mode (GladePointerMode mode) -{ - GladeApp *app = glade_app_get(); - - app->priv->pointer_mode = mode; - - g_object_notify (G_OBJECT (app), "pointer-mode"); -} - - -/** - * glade_app_get_pointer_mode: - * - * Gets the current #GladePointerMode - * - * Returns: The #GladePointerMode - */ -GladePointerMode -glade_app_get_pointer_mode (void) -{ - GladeApp *app = glade_app_get(); - - return app->priv->pointer_mode; -} - -/** - * glade_app_command_copy: - * @app: A #GladeApp - * - * Copy the active project's selection (the new copies - * will end up on the clipboard and will be set as - * the clipboards selection). - */ -void -glade_app_command_copy (void) -{ - GladeApp *app; - GList *widgets = NULL, *list; - GladeWidget *widget; - gboolean failed = FALSE; - - app = glade_app_get(); - if (app->priv->active_project == NULL) - { - return; - } - - for (list = glade_app_get_selection (); - list && list->data; list = list->next) - { - widget = glade_widget_get_from_gobject (GTK_WIDGET (list->data)); - widgets = g_list_prepend (widgets, widget); - - g_assert (widget); - if (widget->internal) - { - glade_util_ui_message - (glade_app_get_window(), - GLADE_UI_WARN, - _("You cannot copy a widget " - "internal to a composite widget.")); - failed = TRUE; - break; - } - } - - if (failed == FALSE && widgets != NULL) - { - glade_command_copy (widgets); - glade_app_update_ui (); - } - else if (widgets == NULL) - glade_util_ui_message (glade_app_get_window(), - GLADE_UI_INFO, - _("No widget selected.")); - - if (widgets) g_list_free (widgets); - -} - -/** - * glade_app_command_cut: - * @app: A #GladeApp - * - * Cut the active project's selection (the cut objects - * will end up on the clipboard and will be set as - * the clipboards selection). - */ -void -glade_app_command_cut (void) -{ - GladeApp *app; - GList *widgets = NULL, *list; - GladeWidget *widget; - gboolean failed = FALSE; - - app = glade_app_get(); - if (app->priv->active_project == NULL) - return; - - for (list = glade_app_get_selection (); - list && list->data; list = list->next) - { - widget = glade_widget_get_from_gobject (GTK_WIDGET (list->data)); - widgets = g_list_prepend (widgets, widget); - - g_assert (widget); - if (widget->internal) - { - glade_util_ui_message - (glade_app_get_window(), - GLADE_UI_WARN, - _("You cannot cut a widget " - "internal to a composite widget.")); - failed = TRUE; - break; - } - } - - if (failed == FALSE && widgets != NULL) - { - glade_command_cut (widgets); - glade_app_update_ui (); - } - else if (widgets == NULL) - glade_util_ui_message (glade_app_get_window(), - GLADE_UI_INFO, - _("No widget selected.")); - - if (widgets) g_list_free (widgets); - -} - -/** - * glade_app_command_paste: - * @placeholder: A #GladePlaceholder - * - * Paste the clipboard selection to the active project's - * selection (the project must have only one object selected). - */ -void -glade_app_command_paste (GladePlaceholder *placeholder) -{ - GladeApp *app; - GladeClipboard *clipboard; - GList *list; - GladeWidget *widget = NULL, *parent; - gint placeholder_relations = 0; - GladeFixed *fixed = NULL; - - app = glade_app_get(); - if (app->priv->active_project == NULL) - return; - - list = glade_project_selection_get (app->priv->active_project); - clipboard = glade_app_get_clipboard (); - - /* If there is a selection, paste in to the selected widget, otherwise - * paste into the placeholder's parent. - */ - parent = list ? glade_widget_get_from_gobject (list->data) : - (placeholder) ? glade_placeholder_get_parent (placeholder) : NULL; - - if (parent && GLADE_IS_FIXED (parent)) fixed = GLADE_FIXED (parent); - - /* Check if parent is actually a container of any sort */ - if (parent && - !glade_widget_adaptor_is_container (parent->adaptor)) - { - glade_util_ui_message (glade_app_get_window(), - GLADE_UI_INFO, - _("Unable to paste to the selected parent")); - return; - } - - /* Check if selection is good */ - if ((list = glade_app_get_selection ()) != NULL) - { - if (g_list_length (list) != 1) - { - glade_util_ui_message (glade_app_get_window(), - GLADE_UI_INFO, - _("Unable to paste to multiple widgets")); - - return; - } - } - - /* Check if we have anything to paste */ - if (g_list_length (clipboard->selection) == 0) - { - glade_util_ui_message (glade_app_get_window (), GLADE_UI_INFO, - _("No widget selected on the clipboard")); - - return; - } - - /* Check that we have compatible heirarchies */ - for (list = clipboard->selection; - list && list->data; list = list->next) - { - widget = list->data; - - if (!GWA_IS_TOPLEVEL (widget->adaptor) && parent) - { - /* Count placeholder relations - */ - if (glade_widget_placeholder_relation (parent, widget)) - placeholder_relations++; - } - - /* Check if there is no parent and at least on of the pasted - * widgets is not a toplevel - */ - else if (!GWA_IS_TOPLEVEL (widget->adaptor) && !parent) - { - glade_util_ui_message (glade_app_get_window (), - GLADE_UI_INFO, - _("Unable to paste widget %s without a parent"), - widget->name); - return; - } - } - - g_assert (widget); - - /* A GladeFixed that doesnt use placeholders can only paste one - * at a time - */ - if (GTK_WIDGET_TOPLEVEL (widget->object) == FALSE && - parent && fixed && !GWA_USE_PLACEHOLDERS (parent->adaptor) && - g_list_length (clipboard->selection) != 1) - { - glade_util_ui_message (glade_app_get_window (), - GLADE_UI_INFO, - _("Only one widget can be pasted at a " - "time to this container")); - return; - } - - /* Check that enough placeholders are available */ - if (parent && - GWA_USE_PLACEHOLDERS (parent->adaptor) && - glade_util_count_placeholders (parent) < placeholder_relations) - { - glade_util_ui_message (glade_app_get_window (), - GLADE_UI_INFO, - _("Insufficient amount of placeholders in " - "target container")); - return; - } - - glade_command_paste (clipboard->selection, parent, placeholder); - glade_app_update_ui (); -} - - -/** - * glade_app_command_delete: - * - * Delete the active project's selection. - */ -void -glade_app_command_delete (void) -{ - GladeApp *app; - GList *widgets = NULL, *list; - GladeWidget *widget; - gboolean failed = FALSE; - - app = glade_app_get(); - if (app->priv->active_project == NULL) - return; - - for (list = glade_app_get_selection (); - list && list->data; list = list->next) - { - widget = glade_widget_get_from_gobject (GTK_WIDGET (list->data)); - widgets = g_list_prepend (widgets, widget); - - g_assert (widget); - if (widget->internal) - { - glade_util_ui_message - (glade_app_get_window(), - GLADE_UI_WARN, - _("You cannot delete a widget " - "internal to a composite widget.")); - failed = TRUE; - break; - } - } - - if (failed == FALSE && widgets != NULL) - { - glade_command_delete (widgets); - glade_app_update_ui (); - } - else if (widgets == NULL) - glade_util_ui_message (glade_app_get_window(), - GLADE_UI_INFO, - _("No widget selected.")); - - if (widgets) g_list_free (widgets); -} - -/** - * glade_app_command_delete_clipboard: - * - * Delete the clipboard's selection. - */ -void -glade_app_command_delete_clipboard (void) -{ - GladeClipboard *clipboard; - GladeWidget *gwidget; - GList *list; - - clipboard = glade_app_get_clipboard (); - - if (clipboard->selection == NULL) - glade_util_ui_message (glade_app_get_window (), GLADE_UI_INFO, - _("No widget selected on the clipboard")); - - for (list = clipboard->selection; list; list = list->next) - { - gwidget = list->data; - if (gwidget->internal) - { - glade_util_ui_message - (glade_app_get_window(), - GLADE_UI_WARN, - _("You cannot delete a widget " - "internal to a composite widget.")); - return; - } - } - - glade_command_delete (clipboard->selection); - glade_app_update_ui (); -} - - -void -glade_app_command_undo (void) -{ - GladeApp *app = glade_app_get(); - if (app->priv->active_project) - { - glade_project_undo (app->priv->active_project); - glade_editor_refresh (app->priv->editor); - /* Update UI. */ - glade_app_update_ui (); - } -} - -void -glade_app_command_redo (void) -{ - GladeApp *app = glade_app_get(); - if (app->priv->active_project) - { - glade_project_redo (app->priv->active_project); - glade_editor_refresh (app->priv->editor); - /* Update UI. */ - glade_app_update_ui (); - } -} - -/* - * glade_app_set_accel_group: - * - * Sets @accel_group to app. - * The acceleration group will be attached to every toplevel widget in this application. - */ -void -glade_app_set_accel_group (GtkAccelGroup *accel_group) -{ - GladeApp *app; - GList *l; - GladeProject *project; - g_return_if_fail(GTK_IS_ACCEL_GROUP (accel_group)); - - app = glade_app_get (); - - for (l = app->priv->projects; l; l = l->next) - { - project = l->data; - glade_project_set_accel_group (project, accel_group); - } - - app->priv->accel_group = accel_group; -} - -static gboolean -glade_app_undo_button_destroyed (GtkWidget *button, GladeApp *app) -{ - app->priv->undo_list = g_list_remove (app->priv->undo_list, button); - return FALSE; -} - -static gboolean -glade_app_redo_button_destroyed (GtkWidget *button, GladeApp *app) -{ - app->priv->redo_list = g_list_remove (app->priv->redo_list, button); - return FALSE; -} - -static GtkWidget * -glade_app_undo_redo_button_new (GladeApp *app, gboolean undo) -{ - GtkWidget *button; - - button = gtk_button_new_from_stock ((undo) ? - GTK_STOCK_UNDO : - GTK_STOCK_REDO); - - g_signal_connect_swapped (button, "clicked", - (undo) ? G_CALLBACK (glade_app_command_undo) : - G_CALLBACK (glade_app_command_redo), - app); - - if (undo) - { - app->priv->undo_list = g_list_prepend (app->priv->undo_list, button); - g_signal_connect (button, "destroy", - G_CALLBACK (glade_app_undo_button_destroyed), - app); - } - else - { - app->priv->redo_list = g_list_prepend (app->priv->redo_list, button); - g_signal_connect (button, "destroy", - G_CALLBACK (glade_app_redo_button_destroyed), - app); - } - - glade_app_refresh_undo_redo_button (app, button, undo); - - return button; -} - -/* - * glade_app_undo_button_new: - * - * Creates a new GtkButton undo widget. - * The button will be automatically updated with @app's undo stack. - */ -GtkWidget * -glade_app_undo_button_new (void) -{ - GladeApp *app = glade_app_get(); - return glade_app_undo_redo_button_new (app, TRUE); -} - -/* - * glade_app_redo_button_new: - * - * Creates a new GtkButton redo widget. - * The button will be automatically updated with @app's redo stack. - */ -GtkWidget * -glade_app_redo_button_new (void) -{ - GladeApp *app = glade_app_get(); - return glade_app_undo_redo_button_new (app, FALSE); -} - -GList* -glade_app_get_selection (void) -{ - GList *selection = NULL, *list; - GladeProject *project; - - for (list = glade_app_get_projects (); - list && list->data; list = list->next) - { - /* Only one project may have selection at a time - */ - project = list->data; - if (glade_project_selection_get (project)) - { - selection = glade_project_selection_get (project); - break; - } - } - return selection; -} - - -gboolean -glade_app_is_selected (GObject *object) -{ - return (g_list_find (glade_app_get_selection (), object) != NULL); -} - -void -glade_app_selection_set (GObject *object, - gboolean emit_signal) -{ - GList *list; - GladeProject *project; - - for (list = glade_app_get_projects (); - list && list->data; list = list->next) - { - project = list->data; - if (glade_project_has_object (project, object)) - glade_project_selection_set (project, - object, - emit_signal); - else - glade_project_selection_clear (project, emit_signal); - } - - /* Instead of calling selection_set after all - * the selection_clear calls (lazy). - */ - if (GTK_IS_WIDGET (object)) - glade_util_add_selection (GTK_WIDGET (object)); -} - -void -glade_app_selection_add (GObject *object, - gboolean emit_signal) -{ - GList *list; - GladeWidget *widget = glade_widget_get_from_gobject (object), - *selected; - GladeProject *project = glade_widget_get_project (widget); - - /* Ignore request if the there is a selection - * from another project. - */ - if ((list = glade_app_get_selection ()) != NULL) - { - selected = glade_widget_get_from_gobject (list->data); - if (glade_widget_get_project (selected) != project) - return; - } - glade_project_selection_add (project, object, emit_signal); -} - -void -glade_app_selection_remove (GObject *object, - gboolean emit_signal) -{ - GladeWidget *widget = glade_widget_get_from_gobject (object); - GladeProject *project = glade_widget_get_project (widget);; - - glade_project_selection_remove (project, object, emit_signal); -} - -void -glade_app_selection_clear (gboolean emit_signal) -{ - GList *list; - GladeProject *project; - - glade_util_clear_selection (); - for (list = glade_app_get_projects (); - list && list->data; list = list->next) - { - project = list->data; - glade_project_selection_clear (project, emit_signal); - } -} - -void -glade_app_selection_changed (void) -{ - GList *list; - GladeProject *project; - - for (list = glade_app_get_projects (); - list && list->data; list = list->next) - { - project = list->data; - glade_project_selection_changed (project); - } -} - -GladeApp* -glade_app_new (void) -{ - return g_object_new (GLADE_TYPE_APP, NULL); -} - diff --git a/gladeui/glade-app.h b/gladeui/glade-app.h deleted file mode 100644 index 14815c4c..00000000 --- a/gladeui/glade-app.h +++ /dev/null @@ -1,205 +0,0 @@ -/* -*- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Authors: - * Naba Kumar <naba@gnome.org> - */ - -#ifndef __GLADE_APP_H__ -#define __GLADE_APP_H__ - -#include <gladeui/glade-editor.h> -#include <gladeui/glade-palette.h> -#include <gladeui/glade-clipboard.h> - -G_BEGIN_DECLS - -#define GLADE_TYPE_APP (glade_app_get_type()) -#define GLADE_APP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_APP, GladeApp)) -#define GLADE_APP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_APP, GladeAppClass)) -#define GLADE_IS_APP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_APP)) -#define GLADE_IS_APP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_APP)) -#define GLADE_APP_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GLADE_APP, GladeAppClass)) - -#define GLADE_TYPE_POINTER_MODE (glade_pointer_mode_get_type()) - -typedef struct _GladeApp GladeApp; -typedef struct _GladeAppPrivate GladeAppPrivate; -typedef struct _GladeAppClass GladeAppClass; -typedef enum _GladePointerMode GladePointerMode; - - -/** - * GladePointerMode: - * @GLADE_POINTER_SELECT: Mouse pointer used for selecting widgets - * @GLADE_POINTER_ADD_WIDGET: Mouse pointer used for adding widgets - * @GLADE_POINTER_DRAG_RESIZE: Mouse pointer used for dragging and - * resizing widgets in containers - * - * Indicates what the pointer is used for in the workspace. - */ -enum _GladePointerMode -{ - GLADE_POINTER_SELECT = 0, - GLADE_POINTER_ADD_WIDGET, - GLADE_POINTER_DRAG_RESIZE -}; - -struct _GladeApp -{ - GObject parent_instance; - - GladeAppPrivate *priv; -}; - -struct _GladeAppClass -{ - GObjectClass parent_class; - - /* class methods */ - void (* show_properties) (GladeApp* app, - gboolean raise); - void (* hide_properties) (GladeApp* app); - - /* signals */ - void (* widget_event) (GladeApp *app, - GladeWidget *toplevel, - GdkEvent *event); - void (* update_ui_signal) (GladeApp *app); -}; - - -GType glade_app_get_type (void) G_GNUC_CONST; - -GladeApp* glade_app_new (void); - -GType glade_pointer_mode_get_type (void) G_GNUC_CONST; - -GladeApp* glade_app_get (void); - -void glade_app_update_ui (void); - -gboolean glade_app_widget_event (GladeWidget *widget, - GdkEvent *event); - -void glade_app_set_window (GtkWidget *window); - -GtkWidget* glade_app_get_window (void); - - -GladeEditor* glade_app_get_editor (void); - -GladePalette* glade_app_get_palette (void); - -GladeClipboard* glade_app_get_clipboard (void); - -GtkWidget* glade_app_get_clipboard_view (void); - -GladeProject* glade_app_get_project (void); - -void glade_app_set_project (GladeProject *project); - -GladePointerMode glade_app_get_pointer_mode (void); - -void glade_app_set_pointer_mode (GladePointerMode mode); - -void glade_app_add_project (GladeProject *project); - -void glade_app_remove_project (GladeProject *project); - -GList* glade_app_get_projects (void); - -GKeyFile* glade_app_get_config (void); - -gboolean glade_app_is_project_loaded (const gchar *project_path); - -GladeProject* glade_app_get_project_by_path (const gchar *project_path); - -void glade_app_show_properties (gboolean raise); - -void glade_app_hide_properties (void); - - -void glade_app_command_copy (void); - -void glade_app_command_cut (void); - -void glade_app_command_paste (GladePlaceholder *placeholder); - -void glade_app_command_delete (void); - -void glade_app_command_delete_clipboard (void); - -void glade_app_command_undo (void); - -void glade_app_command_redo (void); - - -gint glade_app_config_save (void); - -void glade_app_set_transient_parent (GtkWindow *parent); - -GtkWindow *glade_app_get_transient_parent (void); - -void glade_app_set_accel_group (GtkAccelGroup *accel_group); - -void glade_app_update_instance_count (GladeProject *project); - - -GtkWidget *glade_app_undo_button_new (void); - -GtkWidget *glade_app_redo_button_new (void); - - -GList *glade_app_get_selection (void); - - -/* These handle selection on a global scope and take care - * of multiple project logic. - */ - -gboolean glade_app_is_selected (GObject *object); - -void glade_app_selection_set (GObject *object, - gboolean emit_signal); - -void glade_app_selection_add (GObject *object, - gboolean emit_signal); - -void glade_app_selection_remove (GObject *object, - gboolean emit_signal); - -void glade_app_selection_clear (gboolean emit_signal); - -void glade_app_selection_changed (void); - -/* package paths */ - -const gchar *glade_app_get_catalogs_dir (void) G_GNUC_CONST; - -const gchar *glade_app_get_modules_dir (void) G_GNUC_CONST; - -const gchar *glade_app_get_plugins_dir (void) G_GNUC_CONST; - -const gchar *glade_app_get_pixmaps_dir (void) G_GNUC_CONST; - -const gchar *glade_app_get_locale_dir (void) G_GNUC_CONST; - -G_END_DECLS - -#endif /* __GLADE_APP_H__ */ diff --git a/gladeui/glade-base-editor.c b/gladeui/glade-base-editor.c deleted file mode 100644 index 8f3f6605..00000000 --- a/gladeui/glade-base-editor.c +++ /dev/null @@ -1,1866 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2006 Juan Pablo Ugarte. - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Authors: - * Juan Pablo Ugarte <juanpablougarte@gmail.com> - */ - -#include "config.h" - -#include "glade.h" -#include "glade-editor-property.h" -#include "glade-base-editor.h" -#include "glade-accumulators.h" - -#include <string.h> -#include <glib/gi18n-lib.h> -#include <gdk/gdkkeysyms.h> - -typedef enum -{ - GLADE_BASE_EDITOR_GTYPE, - GLADE_BASE_EDITOR_NAME, - GLADE_BASE_EDITOR_N_COLUMNS -}GladeBaseEditorChildEnum; - -typedef enum -{ - GLADE_BASE_EDITOR_MENU_GWIDGET, - GLADE_BASE_EDITOR_MENU_OBJECT, - GLADE_BASE_EDITOR_MENU_TYPE_NAME, - GLADE_BASE_EDITOR_MENU_NAME, - GLADE_BASE_EDITOR_MENU_N_COLUMNS -}GladeBaseEditorEnum; - -struct _GladeBaseEditorPrivate -{ - GladeWidget *gcontainer; /* The container we are editing */ - GtkListStore *children; - - /* Editor UI */ - GtkWidget *paned, *popup, *table, *treeview; - GtkWidget *remove_button, *signal_editor_w; - GladeSignalEditor *signal_editor; - - GtkListStore *lstore; - GtkTreeStore *tstore; - GtkTreeModel *model; - GladeProject *project; - - /* Add button data */ - GType add_type; - gboolean add_as_child; - - /* Temporal variables */ - GtkTreeIter iter; /* used in idle functions */ - gint row; - - gboolean updating_treeview; -}; - -typedef struct _GladeBaseEditorSignal GladeBaseEditorSignal; - -typedef enum _GladeBaseEditorSignalType -{ - SIGNAL_CHILD_SELECTED, - SIGNAL_CHANGE_TYPE, - SIGNAL_GET_DISPLAY_NAME, - SIGNAL_BUILD_CHILD, - SIGNAL_DELETE_CHILD, - SIGNAL_MOVE_CHILD, - LAST_SIGNAL -} GladeBaseEditorSignalType; - -struct _GladeBaseEditorSignal -{ - GladeBaseEditor *object; -}; - -static guint glade_base_editor_signals [LAST_SIGNAL] = { 0 }; -static GtkVBoxClass *parent_class = NULL; - -static void glade_base_editor_set_container (GladeBaseEditor *editor, - GObject *container); -static void glade_base_editor_block_callbacks (GladeBaseEditor *editor, - gboolean block); - -/* glade_base_editor_store_* wrapper functions to use the tree/list store */ -static void -glade_base_editor_store_set (GladeBaseEditor *editor, GtkTreeIter *iter, ...) -{ - va_list args; - - va_start (args, iter); - - if (editor->priv->tstore) - gtk_tree_store_set_valist (editor->priv->tstore, iter, args); - else - gtk_list_store_set_valist (editor->priv->lstore, iter, args); - - va_end (args); -} - -static void -glade_base_editor_store_remove (GladeBaseEditor *editor, GtkTreeIter *iter) -{ - if (editor->priv->tstore) - gtk_tree_store_remove (editor->priv->tstore, iter); - else - gtk_list_store_remove (editor->priv->lstore, iter); -} - -static void -glade_base_editor_store_clear (GladeBaseEditor *editor) -{ - gtk_tree_view_set_model (GTK_TREE_VIEW (editor->priv->treeview), NULL); - - if (editor->priv->tstore) - gtk_tree_store_clear (editor->priv->tstore); - else - gtk_list_store_clear (editor->priv->lstore); - - gtk_tree_view_set_model (GTK_TREE_VIEW (editor->priv->treeview), editor->priv->model); -} - -static void -glade_base_editor_store_append (GladeBaseEditor *editor, - GtkTreeIter *iter, - GtkTreeIter *parent) -{ - if (editor->priv->tstore) - gtk_tree_store_append (editor->priv->tstore, iter, parent); - else - gtk_list_store_append (editor->priv->lstore, iter); -} - -static void -glade_base_editor_store_insert_after (GladeBaseEditor *editor, - GtkTreeIter *iter, - GtkTreeIter *parent, - GtkTreeIter *sibling) -{ - if (editor->priv->tstore) - gtk_tree_store_insert_after (editor->priv->tstore, iter, parent, sibling); - else - gtk_list_store_insert_after (editor->priv->lstore, iter, sibling); -} - -static gboolean -glade_base_editor_get_type_info (GladeBaseEditor *e, - GtkTreeIter *retiter, - GType child_type, - ...) -{ - GtkTreeModel *model = GTK_TREE_MODEL (e->priv->children); - GtkTreeIter iter; - GType type; - - if (gtk_tree_model_get_iter_first (model, &iter) == FALSE) - return FALSE; - - do - { - gtk_tree_model_get (model, &iter, - GLADE_BASE_EDITOR_GTYPE, &type, - -1); - if (child_type == type) - { - va_list args; - va_start (args, child_type); - gtk_tree_model_get_valist (model, &iter, args); - va_end (args); - if (retiter) *retiter = iter; - return TRUE; - } - } while (gtk_tree_model_iter_next (model, &iter)); - - return FALSE; -} - -static gchar * -glade_base_editor_get_display_name (GladeBaseEditor *editor, - GladeWidget *gchild) -{ - gchar *retval; - g_signal_emit (editor, - glade_base_editor_signals[SIGNAL_GET_DISPLAY_NAME], - 0, gchild, &retval); - return retval; -} - -static void -glade_base_editor_fill_store_real (GladeBaseEditor *e, - GladeWidget *gwidget, - GtkTreeIter *parent) -{ - GtkWidget *widget = GTK_WIDGET (glade_widget_get_object (gwidget)); - GList *children, *l; - GtkTreeIter iter; - - children = l = glade_widget_adaptor_get_children (gwidget->adaptor, - G_OBJECT (widget)); - - while (l) - { - GObject *child = (GObject*)l->data; - GladeWidget *gchild; - - if(child && (gchild = glade_widget_get_from_gobject (child))) - { - gchar *type_name, *name; - - if (glade_base_editor_get_type_info (e, NULL, - G_OBJECT_TYPE (child), - GLADE_BASE_EDITOR_NAME, &type_name, - -1)) - { - glade_base_editor_store_append (e, &iter, parent); - - name = glade_base_editor_get_display_name (e, gchild); - - glade_base_editor_store_set (e, &iter, - GLADE_BASE_EDITOR_MENU_GWIDGET, gchild, - GLADE_BASE_EDITOR_MENU_OBJECT, child, - GLADE_BASE_EDITOR_MENU_TYPE_NAME, type_name, - GLADE_BASE_EDITOR_MENU_NAME, name, - -1); - - if (GTK_IS_CONTAINER (child)) - glade_base_editor_fill_store_real (e, gchild, &iter); - - g_free (name); - g_free (type_name); - } - else - if (GTK_IS_CONTAINER (child)) - glade_base_editor_fill_store_real (e, gchild, parent); - - } - - l = g_list_next (l); - } - - g_list_free (children); -} - -static void -glade_base_editor_fill_store (GladeBaseEditor *e) -{ - glade_base_editor_store_clear (e); - gtk_tree_view_set_model (GTK_TREE_VIEW (e->priv->treeview), NULL); - glade_base_editor_fill_store_real (e, e->priv->gcontainer, NULL); - gtk_tree_view_set_model (GTK_TREE_VIEW (e->priv->treeview), e->priv->model); -} - -static gboolean -glade_base_editor_get_child_selected (GladeBaseEditor *e, GtkTreeIter *iter) -{ - GtkTreeSelection *sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (e->priv->treeview)); - return gtk_tree_selection_get_selected (sel, NULL, iter); -} - -static void -glade_base_editor_name_activate (GtkEntry *entry, GladeWidget *gchild) -{ - const gchar *text = gtk_entry_get_text (GTK_ENTRY (entry)); - - if (strcmp (glade_widget_get_name (gchild), text)) - glade_command_set_name (gchild, text); -} - -static gboolean -glade_base_editor_name_focus_out (GtkWidget *entry, - GdkEventFocus *event, - GladeWidget *gchild) -{ - glade_base_editor_name_activate (GTK_ENTRY (entry), gchild); - return FALSE; -} - -static void -glade_base_editor_remove_widget (GtkWidget *widget, gpointer container) -{ - gtk_container_remove (GTK_CONTAINER (container), widget); -} - -static void -glade_base_editor_table_attach (GladeBaseEditor *e, - GtkWidget *child1, - GtkWidget *child2) -{ - GtkTable *table = GTK_TABLE (e->priv->table); - gint row = e->priv->row; - - if (child1) - { - gtk_table_attach (table, child1, 0, 1, row, row + 1, - GTK_FILL, GTK_EXPAND | GTK_FILL, 2, 0); - gtk_widget_show (child1); - } - - if (child2) - { - gtk_table_attach (table, child2, 1, 2, row, row + 1, - GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 2, 0); - gtk_widget_show (child2); - } - - e->priv->row++; -} - -static void -glade_base_editor_clear (GladeBaseEditor *editor) -{ - GladeBaseEditorPrivate *e = editor->priv; - gtk_container_foreach (GTK_CONTAINER (e->table), - glade_base_editor_remove_widget, e->table); - e->row = 0; - gtk_widget_set_sensitive (e->remove_button, FALSE); - glade_signal_editor_load_widget (e->signal_editor, NULL); -} - -static void -glade_base_editor_treeview_cursor_changed (GtkTreeView *treeview, - GladeBaseEditor *editor) -{ - GladeBaseEditorPrivate *e = editor->priv; - GtkTreeIter iter; - GObject *child; - GladeWidget *gchild; - - if (! glade_base_editor_get_child_selected (editor, &iter)) - return; - - glade_base_editor_clear (editor); - gtk_widget_set_sensitive (e->remove_button, TRUE); - - gtk_tree_model_get (e->model, &iter, - GLADE_BASE_EDITOR_MENU_GWIDGET, &gchild, - GLADE_BASE_EDITOR_MENU_OBJECT, &child, - -1); - - /* Emit child-selected signal and let the user add the properties */ - g_signal_emit (editor, glade_base_editor_signals[SIGNAL_CHILD_SELECTED], - 0, gchild); - - /* Update Signal Editor*/ - glade_signal_editor_load_widget (e->signal_editor, gchild); -} - -static gboolean -glade_base_editor_update_properties_idle (gpointer data) -{ - glade_base_editor_treeview_cursor_changed (NULL, (GladeBaseEditor *)data); - return FALSE; -} - - -static void -glade_base_editor_update_properties (GladeBaseEditor *editor) -{ - g_idle_add (glade_base_editor_update_properties_idle, editor); -} - -static void -glade_base_editor_set_cursor (GladeBaseEditor *e, GtkTreeIter *iter) -{ - GtkTreePath *path; - GtkTreeIter real_iter; - - if (iter == NULL && - glade_base_editor_get_child_selected (e, &real_iter)) - iter = &real_iter; - - if (iter && (path = gtk_tree_model_get_path (e->priv->model, iter))) - { - gtk_tree_view_set_cursor (GTK_TREE_VIEW (e->priv->treeview), path, NULL, FALSE); - gtk_tree_path_free (path); - } -} - -static gboolean -glade_base_editor_find_child_real (GladeBaseEditor *e, - GladeWidget *gchild, - GtkTreeIter *iter) -{ - GtkTreeModel *model = e->priv->model; - GtkTreeIter child_iter; - GladeWidget *child; - - do - { - gtk_tree_model_get (model, iter, GLADE_BASE_EDITOR_MENU_GWIDGET, &child, -1); - - if (child == gchild) return TRUE; - - if (gtk_tree_model_iter_children (model, &child_iter, iter)) - if (glade_base_editor_find_child_real (e, gchild, &child_iter)) - { - *iter = child_iter; - return TRUE; - } - } - while (gtk_tree_model_iter_next (model, iter)); - - return FALSE; -} - -static gboolean -glade_base_editor_find_child (GladeBaseEditor *e, - GladeWidget *child, - GtkTreeIter *iter) -{ - if (gtk_tree_model_get_iter_first (e->priv->model, iter)) - return glade_base_editor_find_child_real (e, child, iter); - - return FALSE; -} - -static void -glade_base_editor_select_child (GladeBaseEditor *e, - GladeWidget *child) -{ - GtkTreeIter iter; - - if (glade_base_editor_find_child (e, child, &iter)) - glade_base_editor_set_cursor (e, &iter); -} - -static void -glade_base_editor_child_change_type (GladeBaseEditor *editor, - GtkTreeIter *iter, - GType type) -{ - GladeWidget *gchild; - GObject *child; - gchar *class_name; - gboolean retval; - - glade_base_editor_block_callbacks (editor, TRUE); - - /* Get old widget data */ - gtk_tree_model_get (editor->priv->model, iter, - GLADE_BASE_EDITOR_MENU_GWIDGET, &gchild, - GLADE_BASE_EDITOR_MENU_OBJECT, &child, - -1); - - if (type == G_OBJECT_TYPE (child)) return; - - /* Start of glade-command */ - - if (glade_base_editor_get_type_info (editor, NULL, type, - GLADE_BASE_EDITOR_NAME, &class_name, - -1)) - { - glade_command_push_group (_("Setting object type on %s to %s"), - glade_widget_get_name (gchild), - class_name); - g_free (class_name); - } - else return; - - g_signal_emit (editor, - glade_base_editor_signals [SIGNAL_CHANGE_TYPE], - 0, gchild, type, &retval); - - /* End of glade-command */ - glade_command_pop_group (); - - /* Update properties */ - glade_base_editor_update_properties (editor); - - glade_base_editor_block_callbacks (editor, FALSE); -} - -static void -glade_base_editor_type_changed (GtkComboBox *widget, GladeBaseEditor *e) -{ - GtkTreeIter iter, combo_iter; - GType type; - - if (! glade_base_editor_get_child_selected (e, &iter)) - return; - - gtk_combo_box_get_active_iter (widget, &combo_iter); - - gtk_tree_model_get (gtk_combo_box_get_model (widget), &combo_iter, - GLADE_BASE_EDITOR_GTYPE, &type, -1); - - glade_base_editor_child_change_type (e, &iter, type); -} - -static void -glade_base_editor_child_type_edited (GtkCellRendererText *cell, - const gchar *path_string, - const gchar *new_text, - GladeBaseEditor *editor) -{ - GladeBaseEditorPrivate *e = editor->priv; - GtkTreeModel *child_class = GTK_TREE_MODEL (e->children); - GtkTreePath *path; - GtkTreeIter iter, combo_iter; - GType type; - gchar *type_name; - - path = gtk_tree_path_new_from_string (path_string); - gtk_tree_model_get_iter (e->model, &iter, path); - gtk_tree_model_get (e->model, &iter, - GLADE_BASE_EDITOR_MENU_TYPE_NAME, &type_name, - -1); - if (strcmp (type_name, new_text) == 0) - { - g_free (type_name); - return; - } - - /* Lookup GladeWidgetClass */ - gtk_tree_model_get_iter_first (child_class, &combo_iter); - do - { - gtk_tree_model_get (child_class, &combo_iter, - GLADE_BASE_EDITOR_GTYPE, &type, - GLADE_BASE_EDITOR_NAME, &type_name, - -1); - - if (strcmp (type_name, new_text) == 0) break; - - g_free (type_name); - } while (gtk_tree_model_iter_next (child_class, &combo_iter)); - - glade_base_editor_child_change_type (editor, &iter, type); -} - -static gint -glade_base_editor_popup_handler (GtkWidget *treeview, - GdkEventButton *event, - GladeBaseEditor *e) -{ - GtkTreePath *path; - - if (event->button == 3) - { - if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (treeview), - (gint) event->x, (gint) event->y, &path, NULL, NULL, NULL)) - { - gtk_tree_view_set_cursor (GTK_TREE_VIEW (treeview), path, NULL, FALSE); - gtk_tree_path_free (path); - } - - gtk_menu_popup (GTK_MENU (e->priv->popup), NULL, NULL, NULL, NULL, - event->button, event->time); - return TRUE; - } - - return FALSE; -} - -static void -glade_base_editor_reorder_children (GladeBaseEditor *editor, GtkTreeIter *child) -{ - GtkTreeModel *model = editor->priv->model; - GladeWidget *gchild; - GladeProperty *property; - GtkTreeIter parent, iter; - gint position = 0; - - if (gtk_tree_model_iter_parent (model, &parent, child)) - gtk_tree_model_iter_children (model, &iter, &parent); - else - gtk_tree_model_get_iter_first (model, &iter); - - do - { - gtk_tree_model_get (model, &iter, GLADE_BASE_EDITOR_MENU_GWIDGET, &gchild, -1); - - if ((property = glade_widget_get_property (gchild, "position")) != NULL) - glade_command_set_property (property, position); - position++; - } while (gtk_tree_model_iter_next (model, &iter)); -} - -static void -glade_base_editor_add_child (GladeBaseEditor *editor, - GType type, - gboolean as_child) -{ - GladeBaseEditorPrivate *e = editor->priv; - GtkTreeIter iter, new_iter; - GladeWidget *gparent, *gchild = NULL, *gchild_new; - gchar *type_name, *name, *class_name; - - if (glade_base_editor_get_type_info (editor, NULL, type, - GLADE_BASE_EDITOR_NAME, &class_name, - -1) == FALSE) return; - - glade_base_editor_block_callbacks (editor, TRUE); - - gparent = e->gcontainer; - - if (glade_base_editor_get_child_selected (editor, &iter)) - { - gtk_tree_model_get (e->model, &iter, - GLADE_BASE_EDITOR_MENU_GWIDGET, &gchild, - -1); - if (as_child) - { - glade_base_editor_store_append (editor, &new_iter, &iter); - gparent = gchild; - } - else - { - glade_base_editor_store_insert_after (editor, &new_iter, - NULL, &iter); - gparent = glade_widget_get_parent (gchild); - } - - } - else - glade_base_editor_store_append (editor, &new_iter, NULL); - - glade_command_push_group (_("Add a %s to %s"), class_name, - glade_widget_get_name (gparent)); - g_free (class_name); - - /* Build Child */ - g_signal_emit (editor, glade_base_editor_signals[SIGNAL_BUILD_CHILD], - 0, gparent, type, &gchild_new); - - if (gchild_new == NULL) - { - glade_command_pop_group (); - glade_base_editor_store_remove (editor, &new_iter); - return; - } - - glade_base_editor_get_type_info (editor, NULL, type, - GLADE_BASE_EDITOR_NAME, &type_name, - -1); - - name = glade_base_editor_get_display_name (editor, gchild_new); - - glade_base_editor_store_set (editor, &new_iter, - GLADE_BASE_EDITOR_MENU_GWIDGET, gchild_new, - GLADE_BASE_EDITOR_MENU_OBJECT, glade_widget_get_object (gchild_new), - GLADE_BASE_EDITOR_MENU_TYPE_NAME, type_name, - GLADE_BASE_EDITOR_MENU_NAME, name, - -1); - - glade_base_editor_reorder_children (editor, &new_iter); - - gtk_tree_view_expand_all (GTK_TREE_VIEW (e->treeview)); - glade_base_editor_set_cursor (editor, &new_iter); - - glade_command_pop_group (); - - glade_base_editor_block_callbacks (editor, FALSE); - - g_free (name); - g_free (type_name); -} - -static void -glade_base_editor_add_item_activate (GtkMenuItem *menuitem, GladeBaseEditor *e) -{ - GObject *item = G_OBJECT (menuitem); - GType type = GPOINTER_TO_INT (g_object_get_data (item, "object_type")); - gboolean as_child = GPOINTER_TO_INT (g_object_get_data (item, "object_as_child")); - - glade_base_editor_add_child (e, type, as_child); -} - -static void -glade_base_editor_add_activate (GtkButton *button, GladeBaseEditor *e) -{ - if (e->priv->add_type) - glade_base_editor_add_child (e, e->priv->add_type, e->priv->add_as_child); -} - -static void -glade_base_editor_delete_child (GladeBaseEditor *e) -{ - GladeWidget *child, *gparent; - GtkTreeIter iter, parent; - gboolean retval; - - if (!glade_base_editor_get_child_selected (e, &iter)) return; - - gtk_tree_model_get (e->priv->model, &iter, - GLADE_BASE_EDITOR_MENU_GWIDGET, &child, -1); - - if (gtk_tree_model_iter_parent (e->priv->model, &parent, &iter)) - gtk_tree_model_get (e->priv->model, &parent, - GLADE_BASE_EDITOR_MENU_GWIDGET, &gparent, - -1); - else - gparent = e->priv->gcontainer; - - glade_command_push_group (_("Delete %s child from %s"), - glade_widget_get_name (child), - glade_widget_get_name (gparent)); - - /* Emit delete-child signal */ - g_signal_emit (e, glade_base_editor_signals[SIGNAL_DELETE_CHILD], - 0, gparent, child, &retval); - - glade_command_pop_group (); -} - - -static gboolean -glade_base_editor_treeview_key_press_event (GtkWidget *widget, - GdkEventKey *event, - GladeBaseEditor *e) -{ - if (event->keyval == GDK_Delete) - glade_base_editor_delete_child (e); - - return FALSE; -} - -static void -glade_base_editor_delete_activate (GtkButton *button, GladeBaseEditor *e) -{ - glade_base_editor_delete_child (e); -} - -static gboolean -glade_base_editor_is_child (GladeBaseEditor *e, - GladeWidget *gchild, - gboolean valid_type) -{ - GladeWidget *gcontainer; - - if (valid_type) - { - GObject *child = glade_widget_get_object (gchild); - - gcontainer = e->priv->gcontainer; - - if (gchild->internal || - glade_base_editor_get_type_info (e, NULL, - G_OBJECT_TYPE (child), - -1) == FALSE) - return FALSE; - } - else - { - GtkTreeIter iter; - if (glade_base_editor_get_child_selected (e, &iter)) - gtk_tree_model_get (e->priv->model, &iter, - GLADE_BASE_EDITOR_MENU_GWIDGET, &gcontainer, - -1); - else - return FALSE; - } - - while ((gchild = glade_widget_get_parent (gchild))) - if (gchild == gcontainer) return TRUE; - - return FALSE; -} - -static gboolean -glade_base_editor_update_treeview_idle (gpointer data) -{ - GladeBaseEditor *e = ((GladeBaseEditor *) data); - GList *selection = glade_project_selection_get (e->priv->project); - - glade_base_editor_block_callbacks (e, TRUE); - - glade_base_editor_fill_store (e); - glade_base_editor_clear (e); - - gtk_tree_view_expand_all (GTK_TREE_VIEW (e->priv->treeview)); - - if (selection) - { - GladeWidget *widget = glade_widget_get_from_gobject (G_OBJECT (selection->data)); - if (glade_base_editor_is_child (e, widget, TRUE)) - glade_base_editor_select_child (e, widget); - } - - e->priv->updating_treeview = FALSE; - glade_base_editor_block_callbacks (e, FALSE); - - return FALSE; -} - -static void -glade_base_editor_project_widget_name_changed (GladeProject *project, - GladeWidget *widget, - GladeBaseEditor *editor) -{ - GladeWidget *selected_child; - GtkTreeIter iter; - - if (glade_base_editor_get_child_selected (editor, &iter)) - { - gtk_tree_model_get (editor->priv->model, &iter, - GLADE_BASE_EDITOR_MENU_GWIDGET, &selected_child, - -1); - if (widget == selected_child) - glade_base_editor_update_properties (editor); - } -} - -static void -glade_base_editor_project_closed (GladeProject *project, GladeBaseEditor *e) -{ - glade_base_editor_set_container (e, NULL); -} - -static void -glade_base_editor_reorder (GladeBaseEditor *editor, GtkTreeIter *iter) -{ - GladeBaseEditorPrivate *e = editor->priv; - GladeWidget *gchild, *gparent; - GtkTreeIter parent_iter; - gboolean retval; - - glade_command_push_group (_("Reorder %s's children"), - glade_widget_get_name (e->gcontainer)); - - gtk_tree_model_get (e->model, iter, - GLADE_BASE_EDITOR_MENU_GWIDGET, &gchild, -1); - - if (gtk_tree_model_iter_parent (e->model, &parent_iter, iter)) - gtk_tree_model_get (e->model, &parent_iter, - GLADE_BASE_EDITOR_MENU_GWIDGET, &gparent, - -1); - else - gparent = e->gcontainer; - - g_signal_emit (editor, glade_base_editor_signals [SIGNAL_MOVE_CHILD], - 0, gparent, gchild, &retval); - - if (retval) - glade_base_editor_reorder_children (editor, iter); - else - { - glade_base_editor_clear (editor); - glade_base_editor_fill_store (editor); - glade_base_editor_find_child (editor, gchild, &editor->priv->iter); - } - - glade_command_pop_group (); -} - -static gboolean -glade_base_editor_drag_and_drop_idle (gpointer data) -{ - GladeBaseEditor *e = (GladeBaseEditor *) data; - - glade_base_editor_reorder (e, &e->priv->iter); - gtk_tree_view_expand_all (GTK_TREE_VIEW (e->priv->treeview)); - glade_base_editor_set_cursor (e, &e->priv->iter); - glade_base_editor_block_callbacks (e, FALSE); - - return FALSE; -} - -static void -glade_base_editor_row_inserted (GtkTreeModel *model, - GtkTreePath *path, - GtkTreeIter *iter, - GladeBaseEditor *e) -{ - e->priv->iter = *iter; - glade_base_editor_block_callbacks (e, TRUE); - g_idle_add (glade_base_editor_drag_and_drop_idle, e); -} - -static void -glade_base_editor_project_remove_widget (GladeProject *project, - GladeWidget *widget, - GladeBaseEditor *e) -{ - if (widget == e->priv->gcontainer) - { - glade_base_editor_set_container (e, NULL); - return; - } - - if (glade_base_editor_is_child (e, widget, TRUE)) - { - GtkTreeIter iter; - if (glade_base_editor_find_child (e, widget, &iter)) - { - glade_base_editor_store_remove (e, &iter); - glade_base_editor_clear (e); - } - } - - if (widget->internal && - glade_base_editor_is_child (e, widget, FALSE)) - glade_base_editor_update_properties (e); -} - -static void -glade_base_editor_project_add_widget (GladeProject *project, - GladeWidget *widget, - GladeBaseEditor *e) -{ - if (e->priv->updating_treeview) return; - - if (glade_base_editor_is_child (e, widget, TRUE)) - { - e->priv->updating_treeview = TRUE; - g_idle_add (glade_base_editor_update_treeview_idle, e); - } - - if (widget->internal && - glade_base_editor_is_child (e, widget, FALSE)) - glade_base_editor_update_properties (e); -} - -static gboolean -glade_base_editor_update_display_name (GtkTreeModel *model, - GtkTreePath *path, - GtkTreeIter *iter, - gpointer data) -{ - GladeBaseEditor *editor = (GladeBaseEditor *) data; - GladeWidget *gchild; - gchar *name; - - gtk_tree_model_get (model, iter, - GLADE_BASE_EDITOR_MENU_GWIDGET, &gchild, - -1); - - name = glade_base_editor_get_display_name (editor, gchild); - - glade_base_editor_store_set (editor, iter, - GLADE_BASE_EDITOR_MENU_NAME, name, - -1); - g_free (name); - - return FALSE; -} - -static void -glade_base_editor_project_changed (GladeProject *project, - GladeCommand *command, - gboolean forward, - GladeBaseEditor *editor) -{ - gtk_tree_model_foreach (editor->priv->model, - glade_base_editor_update_display_name, - editor); -} - - - -static void -glade_base_editor_project_disconnect (GladeBaseEditor *editor) -{ - GladeBaseEditorPrivate *e = editor->priv; - - if (e->project == NULL) return; - - g_signal_handlers_disconnect_by_func (e->project, - glade_base_editor_project_closed, editor); - - g_signal_handlers_disconnect_by_func (e->project, - glade_base_editor_project_remove_widget, editor); - - g_signal_handlers_disconnect_by_func (e->project, - glade_base_editor_project_add_widget, editor); - - g_signal_handlers_disconnect_by_func (e->project, - glade_base_editor_project_widget_name_changed, editor); - - g_signal_handlers_disconnect_by_func (e->project, - glade_base_editor_project_changed, editor); -} - -static void -glade_base_editor_set_container (GladeBaseEditor *editor, - GObject *container) -{ - GladeBaseEditorPrivate *e = editor->priv; - - if (e->project) - glade_base_editor_project_disconnect (editor); - - if (container == NULL) - { - e->gcontainer = NULL; - e->project = NULL; - glade_base_editor_block_callbacks (editor, TRUE); - glade_base_editor_clear (editor); - glade_base_editor_store_clear (editor); - gtk_list_store_clear (e->children); - gtk_widget_set_sensitive (e->paned, FALSE); - glade_base_editor_block_callbacks (editor, FALSE); - return; - } - - gtk_widget_set_sensitive (e->paned, TRUE); - - e->gcontainer = glade_widget_get_from_gobject (container); - - e->project = glade_widget_get_project (e->gcontainer); - - g_signal_connect (e->project, "close", - G_CALLBACK (glade_base_editor_project_closed), - editor); - - g_signal_connect (e->project, "remove-widget", - G_CALLBACK (glade_base_editor_project_remove_widget), - editor); - - g_signal_connect (e->project, "add-widget", - G_CALLBACK (glade_base_editor_project_add_widget), - editor); - - g_signal_connect (e->project, "widget-name-changed", - G_CALLBACK (glade_base_editor_project_widget_name_changed), - editor); - - g_signal_connect (e->project, "changed", - G_CALLBACK (glade_base_editor_project_changed), - editor); -} - -/*************************** GladeBaseEditor Class ****************************/ - -static void -glade_base_editor_finalize (GObject *object) -{ - GladeBaseEditor *cobj = GLADE_BASE_EDITOR (object); - - /* Free private members, etc. */ - glade_base_editor_project_disconnect (cobj); - - g_free (cobj->priv); - G_OBJECT_CLASS(parent_class)->finalize(object); -} - -/* Default handlers */ -static gboolean -glade_base_editor_change_type (GladeBaseEditor *editor, - GladeWidget *gchild, - GType type) -{ - GladeBaseEditorPrivate *e = editor->priv; - GladeWidgetAdaptor *adaptor = glade_widget_adaptor_get_by_type (type); - GladeWidget *parent, *gchild_new; - GList list = {0, }, *children, *l; - GObject *child, *child_new; - GtkTreeIter iter; - gchar *name, *class_name; - - if (glade_base_editor_get_type_info (editor, NULL, type, - GLADE_BASE_EDITOR_NAME, &class_name, - -1) == FALSE) - return TRUE; - - parent = glade_widget_get_parent (gchild); - child = glade_widget_get_object (gchild); - name = g_strdup (glade_widget_get_name (gchild)); - glade_base_editor_find_child (editor, gchild, &iter); - - /* Create new widget */ - gchild_new = glade_command_create (adaptor, parent, NULL, e->project); - child_new = glade_widget_get_object (gchild_new); - - /* Cut and Paste childrens */ - if ((children = glade_widget_adaptor_get_children (gchild->adaptor, child))) - { - GList *gchildren = NULL; - - l = children; - while (l) - { - GladeWidget *w = glade_widget_get_from_gobject (l->data); - - if (w && !w->internal) - gchildren = g_list_prepend (gchildren, w); - - l= g_list_next (l); - } - - if (gchildren) - { - glade_command_dnd (gchildren, gchild_new, NULL); - - g_list_free (children); - g_list_free (gchildren); - } - } - - /* Copy properties */ - glade_widget_copy_properties (gchild_new, gchild); - - /* Delete old widget */ - list.data = gchild; - glade_command_delete (&list); - - /* Apply packing properties to the new object */ - l = gchild->packing_properties; - while (l) - { - GladeProperty *orig_prop = (GladeProperty *) l->data; - GladeProperty *dup_prop = glade_widget_get_property (gchild_new, - orig_prop->klass->id); - glade_property_set_value (dup_prop, orig_prop->value); - l = g_list_next (l); - } - - /* Set the name */ - glade_widget_set_name (gchild_new, name); - - if (GTK_IS_WIDGET (child_new)) - gtk_widget_show_all (GTK_WIDGET (child_new)); - - glade_base_editor_store_set (editor, &iter, - GLADE_BASE_EDITOR_MENU_GWIDGET, gchild_new, - GLADE_BASE_EDITOR_MENU_OBJECT, child_new, - GLADE_BASE_EDITOR_MENU_TYPE_NAME, class_name, - -1); - g_free (class_name); - g_free (name); - - return TRUE; -} - -static gchar * -glade_base_editor_get_display_name_impl (GladeBaseEditor *editor, - GladeWidget *gchild) -{ - return g_strdup (glade_widget_get_name (gchild)); -} - -static GladeWidget * -glade_base_editor_build_child (GladeBaseEditor *editor, - GladeWidget *gparent, - GType type) -{ - return glade_command_create (glade_widget_adaptor_get_by_type (type), - gparent, NULL, - glade_widget_get_project (gparent)); -} - -static gboolean -glade_base_editor_move_child (GladeBaseEditor *editor, - GladeWidget *gparent, - GladeWidget *gchild) -{ - GList list = {0, }; - - if (gparent != glade_widget_get_parent (gchild)) - { - list.data = gchild; - glade_command_dnd (&list, gparent, NULL); - } - - return TRUE; -} - -static gboolean -glade_base_editor_delete_child_impl (GladeBaseEditor *editor, - GladeWidget *gparent, - GladeWidget *gchild) -{ - GList list = {0, }; - - list.data = gchild; - glade_command_delete (&list); - - return TRUE; -} - -static void -glade_base_editor_class_init (GladeBaseEditorClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS(klass); - - parent_class = g_type_class_peek_parent(klass); - object_class->finalize = glade_base_editor_finalize; - - klass->change_type = glade_base_editor_change_type; - klass->get_display_name = glade_base_editor_get_display_name_impl; - klass->build_child = glade_base_editor_build_child; - klass->delete_child = glade_base_editor_delete_child_impl; - klass->move_child = glade_base_editor_move_child; - - /** - * GladeBaseEditor::child-selected: - * @gladebaseeditor: the #GladeBaseEditor which received the signal. - * @gchild: the selected #GladeWidget. - * - * Emited when the user selects a child in the editor's treeview. - * You can add the relevant child properties here using - * glade_base_editor_add_default_properties() and glade_base_editor_add_properties() - * You can also add labels with glade_base_editor_add_label to make the - * editor look pretty. - */ - glade_base_editor_signals [SIGNAL_CHILD_SELECTED] = - g_signal_new ("child-selected", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GladeBaseEditorClass, child_selected), - NULL, NULL, - glade_marshal_VOID__OBJECT, - G_TYPE_NONE, - 1, - G_TYPE_OBJECT); - - /** - * GladeBaseEditor::child-change-type: - * @gladebaseeditor: the #GladeBaseEditor which received the signal. - * @child: the #GObject being changed. - * @type: the new type for @child. - * - * Returns TRUE to stop signal emision. - */ - glade_base_editor_signals [SIGNAL_CHANGE_TYPE] = - g_signal_new ("change-type", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GladeBaseEditorClass, change_type), - glade_boolean_handled_accumulator, NULL, - glade_marshal_BOOLEAN__OBJECT_UINT, - G_TYPE_BOOLEAN, - 2, - G_TYPE_OBJECT, G_TYPE_UINT); - - /** - * GladeBaseEditor::get-display-name: - * @gladebaseeditor: the #GladeBaseEditor which received the signal. - * @gchild: the child to get display name string to show in @gladebaseeditor - * treeview. - * - * Returns a newly allocated string. - */ - glade_base_editor_signals [SIGNAL_GET_DISPLAY_NAME] = - g_signal_new ("get-display-name", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GladeBaseEditorClass, get_display_name), - glade_string_accumulator, NULL, - glade_marshal_STRING__OBJECT, - G_TYPE_STRING, - 1, - G_TYPE_OBJECT); - - /** - * GladeBaseEditor::build-child: - * @gladebaseeditor: the #GladeBaseEditor which received the signal. - * @gparent: the parent of the new child - * @type: the #GType of the child - * - * Create a child widget here if something else must be done other than - * calling glade_command_create() such as creating an intermediate parent. - * Returns the newly created #GladeWidget or NULL if child cant be created - */ - glade_base_editor_signals [SIGNAL_BUILD_CHILD] = - g_signal_new ("build-child", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GladeBaseEditorClass, build_child), - glade_stop_emission_accumulator, NULL, - glade_marshal_OBJECT__OBJECT_UINT, - G_TYPE_OBJECT, - 2, - G_TYPE_OBJECT, G_TYPE_UINT); - - /** - * GladeBaseEditor::delete-child: - * @gladebaseeditor: the #GladeBaseEditor which received the signal. - * @gparent: the parent - * @gchild: the child to delete - */ - glade_base_editor_signals [SIGNAL_DELETE_CHILD] = - g_signal_new ("delete-child", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GladeBaseEditorClass, delete_child), - glade_boolean_handled_accumulator, NULL, - glade_marshal_BOOLEAN__OBJECT_OBJECT, - G_TYPE_BOOLEAN, - 2, - G_TYPE_OBJECT, G_TYPE_OBJECT); - - /** - * GladeBaseEditor::move-child: - * @gladebaseeditor: the #GladeBaseEditor which received the signal. - * @gparent: the new parent of @gchild - * @gchild: the #GladeWidget to move - * - * Move child here if something else must be done other than cut & paste. - * Returns wheater child has been sucessfully moved or not. - */ - glade_base_editor_signals [SIGNAL_MOVE_CHILD] = - g_signal_new ("move-child", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GladeBaseEditorClass, move_child), - glade_stop_emission_accumulator, NULL, - glade_marshal_BOOLEAN__OBJECT_OBJECT, - G_TYPE_BOOLEAN, - 2, - G_TYPE_OBJECT, G_TYPE_OBJECT); -} - -static void -glade_base_editor_block_callbacks (GladeBaseEditor *editor, gboolean block) -{ - GladeBaseEditorPrivate *e = editor->priv; - if (block) - { - g_signal_handlers_block_by_func (e->model, glade_base_editor_row_inserted, editor); - if (e->project) - { - g_signal_handlers_block_by_func (e->project, glade_base_editor_project_remove_widget, editor); - g_signal_handlers_block_by_func (e->project, glade_base_editor_project_add_widget, editor); - g_signal_handlers_block_by_func (e->project, glade_base_editor_project_changed, editor); - } - } - else - { - g_signal_handlers_unblock_by_func (e->model, glade_base_editor_row_inserted, editor); - if (e->project) - { - g_signal_handlers_unblock_by_func (e->project, glade_base_editor_project_remove_widget, editor); - g_signal_handlers_unblock_by_func (e->project, glade_base_editor_project_add_widget, editor); - g_signal_handlers_unblock_by_func (e->project, glade_base_editor_project_changed, editor); - } - } -} - -static void -glade_base_editor_realize_callback (GtkWidget *widget, gpointer user_data) -{ - GladeBaseEditor *editor = GLADE_BASE_EDITOR (widget); - - glade_base_editor_block_callbacks (editor, TRUE); - - glade_base_editor_fill_store (editor); - gtk_tree_view_expand_all (GTK_TREE_VIEW (editor->priv->treeview)); - - glade_base_editor_block_callbacks (editor, FALSE); -} - -static void -glade_base_editor_init (GladeBaseEditor *editor) -{ - GladeBaseEditorPrivate *e; - GtkCellRenderer *renderer; - GtkTreeViewColumn *column; - GtkWidget *paned, *hbox, *vbox, *tree_vbox, *scroll, *button_table, *button; - - gtk_box_set_spacing (GTK_BOX (editor), 8); - - e = editor->priv = g_new0(GladeBaseEditorPrivate, 1); - - /* Children store */ - e->children = gtk_list_store_new (GLADE_BASE_EDITOR_N_COLUMNS, - G_TYPE_GTYPE, G_TYPE_STRING); - - /* Paned */ - e->paned = paned = gtk_vpaned_new (); - gtk_widget_show (paned); - gtk_box_pack_start (GTK_BOX (editor), paned, TRUE, TRUE, 0); - - /* Hbox */ - hbox = gtk_hbox_new (FALSE, 8); - gtk_widget_show (hbox); - gtk_paned_pack1 (GTK_PANED (paned), hbox, TRUE, FALSE); - - /* TreeView Vbox */ - tree_vbox = gtk_vbox_new (FALSE, 8); - gtk_widget_show (tree_vbox); - gtk_box_pack_start (GTK_BOX (hbox), tree_vbox, FALSE, TRUE, 0); - - /* ScrolledWindow */ - scroll = gtk_scrolled_window_new (NULL, NULL); - gtk_widget_show (scroll); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_IN); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); - gtk_box_pack_start (GTK_BOX (tree_vbox), scroll, TRUE, TRUE, 0); - - /* TreeView */ - e->treeview = gtk_tree_view_new (); - gtk_widget_show (e->treeview); - gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (e->treeview), TRUE); - gtk_tree_view_set_reorderable (GTK_TREE_VIEW (e->treeview), TRUE); - - gtk_widget_add_events (e->treeview, GDK_KEY_PRESS_MASK); - g_signal_connect (e->treeview, "key-press-event", - G_CALLBACK (glade_base_editor_treeview_key_press_event), editor); - - g_signal_connect (e->treeview, "cursor-changed", - G_CALLBACK (glade_base_editor_treeview_cursor_changed), editor); - - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes (_("Label"), renderer, - "text", GLADE_BASE_EDITOR_MENU_NAME, NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (e->treeview), column); - - renderer = gtk_cell_renderer_combo_new (); - g_object_set (renderer, - "model", e->children, - "text-column", GLADE_BASE_EDITOR_NAME, - "has-entry", FALSE, - "editable", TRUE, - NULL); - g_signal_connect (renderer, "edited", - G_CALLBACK (glade_base_editor_child_type_edited), editor); - column = gtk_tree_view_column_new_with_attributes (_("Type"), renderer, - "text", GLADE_BASE_EDITOR_MENU_TYPE_NAME, NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (e->treeview), column); - - gtk_container_add (GTK_CONTAINER (scroll), e->treeview); - - /* Add/Remove buttons */ - button_table = gtk_table_new (1, 2, TRUE); - gtk_widget_show (button_table); - gtk_table_set_col_spacings (GTK_TABLE (button_table), 8); - gtk_box_pack_start (GTK_BOX (tree_vbox), button_table, FALSE, TRUE, 0); - - button = gtk_button_new_from_stock (GTK_STOCK_ADD); - gtk_widget_show (button); - g_signal_connect (button, "clicked", - G_CALLBACK (glade_base_editor_add_activate), editor); - gtk_table_attach_defaults (GTK_TABLE (button_table), button, 0, 1, 0, 1); - - e->remove_button = button = gtk_button_new_from_stock (GTK_STOCK_REMOVE); - gtk_widget_show (button); - g_signal_connect (button, "clicked", - G_CALLBACK (glade_base_editor_delete_activate), editor); - gtk_table_attach_defaults (GTK_TABLE (button_table), button, 1, 2, 0, 1); - - /* Properties Vbox */ - vbox = gtk_vbox_new (FALSE, 8); - gtk_widget_show (vbox); - gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0); - - /* Tables */ - e->table = gtk_table_new (1, 2, FALSE); - gtk_widget_show (e->table); - gtk_table_set_row_spacings (GTK_TABLE (e->table), 4); - gtk_box_pack_start (GTK_BOX (vbox), e->table, FALSE, TRUE, 0); - - /* Signal Editor */ - e->signal_editor = glade_signal_editor_new (NULL); - e->signal_editor_w = glade_signal_editor_get_widget (e->signal_editor); - gtk_widget_show (e->signal_editor_w); - gtk_widget_set_size_request (e->signal_editor_w, -1, 96); - gtk_paned_pack2 (GTK_PANED (paned), e->signal_editor_w, FALSE, FALSE); - - /* Update the treeview on realize event */ - g_signal_connect (editor, "realize", - G_CALLBACK (glade_base_editor_realize_callback), - NULL); -} - -/********************************* Public API *********************************/ -GType -glade_base_editor_get_type () -{ - static GType type = 0; - - if(type == 0) { - static const GTypeInfo our_info = { - sizeof (GladeBaseEditorClass), - NULL, - NULL, - (GClassInitFunc)glade_base_editor_class_init, - NULL, - NULL, - sizeof (GladeBaseEditor), - 0, - (GInstanceInitFunc)glade_base_editor_init, - }; - - type = g_type_register_static (GTK_TYPE_VBOX, "GladeBaseEditor", - &our_info, 0); - } - - return type; -} - -/** - * glade_base_editor_new: - * @container: the container this new editor will edit. - * @tree_like: TRUE if container's children can have children. - * @... A NULL terminated list of gchar *, GType - * - * Creates a new GladeBaseEditor with support for all the object types indicated - * in the variable argument list. - * Argument List: - * o The type name - * o The GType the editor will support - * - * Returns a new GladeBaseEditor. - */ -GladeBaseEditor * -glade_base_editor_new (GObject *container, gboolean tree_like, ...) -{ - GladeBaseEditor *editor; - GladeBaseEditorPrivate *e; - va_list args; - gchar *name; - GtkTreeIter iter; - - g_return_val_if_fail (GTK_IS_CONTAINER (container), NULL); - - editor = GLADE_BASE_EDITOR (g_object_new (GLADE_TYPE_BASE_EDITOR, NULL)); - e = editor->priv; - - /* Store */ - if (tree_like) - { - e->tstore = gtk_tree_store_new (GLADE_BASE_EDITOR_MENU_N_COLUMNS, - G_TYPE_OBJECT, - G_TYPE_OBJECT, - G_TYPE_STRING, - G_TYPE_STRING); - e->model = GTK_TREE_MODEL (e->tstore); - } - else - { - e->lstore = gtk_list_store_new (GLADE_BASE_EDITOR_MENU_N_COLUMNS, - G_TYPE_OBJECT, - G_TYPE_OBJECT, - G_TYPE_STRING, - G_TYPE_STRING); - e->model = GTK_TREE_MODEL (e->lstore); - } - - gtk_tree_view_set_model (GTK_TREE_VIEW (e->treeview), e->model); - gtk_tree_view_expand_all (GTK_TREE_VIEW (e->treeview)); - - g_signal_connect (e->model, "row-inserted", - G_CALLBACK (glade_base_editor_row_inserted), - editor); - - va_start (args, tree_like); - - while ((name = va_arg (args, gchar *))) - { - gtk_list_store_append (editor->priv->children, &iter); - gtk_list_store_set (editor->priv->children, &iter, - GLADE_BASE_EDITOR_GTYPE, va_arg (args, GType), - GLADE_BASE_EDITOR_NAME, name, - -1); - } - - va_end (args); - - glade_base_editor_set_container (editor, container); - - return editor; -} - - -/** - * glade_base_editor_add_default_properties: - * @editor: a #GladeBaseEditor - * @gchild: a #GladeWidget - * - * Add @gchild name and type property to @editor - * - * NOTE: This function is intended to be used in "child-selected" callbacks - */ -void -glade_base_editor_add_default_properties (GladeBaseEditor *editor, - GladeWidget *gchild) -{ - GladeBaseEditorPrivate *e = editor->priv; - GtkTreeIter combo_iter; - GtkWidget *label, *entry; - GtkTreeModel *child_class = GTK_TREE_MODEL (e->children); - GtkCellRenderer *renderer; - gboolean retval; - GObject *child = glade_widget_get_object (gchild); - - g_return_if_fail (GLADE_IS_BASE_EDITOR (editor)); - g_return_if_fail (GLADE_IS_WIDGET (gchild)); - - /* Name */ - label = gtk_label_new (_("Name :")); - gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.0); - - entry = gtk_entry_new (); - gtk_entry_set_text (GTK_ENTRY (entry), glade_widget_get_name (gchild)); - g_signal_connect (entry, "activate", G_CALLBACK (glade_base_editor_name_activate), gchild); - g_signal_connect (entry, "focus-out-event", G_CALLBACK (glade_base_editor_name_focus_out), gchild); - glade_base_editor_table_attach (editor, label, entry); - - /* Type */ - label = gtk_label_new (_("Type :")); - gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.0); - - entry = gtk_combo_box_new (); - gtk_combo_box_set_model (GTK_COMBO_BOX (entry), child_class); - - renderer = gtk_cell_renderer_text_new (); - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (entry), renderer, FALSE); - gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (entry), renderer, "text", - GLADE_BASE_EDITOR_NAME, NULL); - - if ((retval = glade_base_editor_get_type_info (editor, &combo_iter, G_OBJECT_TYPE (child), -1))) - gtk_combo_box_set_active_iter (GTK_COMBO_BOX (entry), &combo_iter); - - g_signal_connect (entry, "changed", G_CALLBACK (glade_base_editor_type_changed), editor); - glade_base_editor_table_attach (editor, label, entry); -} - -/** - * glade_base_editor_add_properties: - * @editor: a #GladeBaseEditor - * @gchild: a #GladeWidget - * @...: A NULL terminated list of properties names. - * - * Add @gchild properties to @editor - * - * NOTE: This function is intended to be used in "child-selected" callbacks - */ -void -glade_base_editor_add_properties (GladeBaseEditor *editor, - GladeWidget *gchild, - ...) -{ - GladeEditorProperty *eprop; - va_list args; - gchar *property; - - g_return_if_fail (GLADE_IS_BASE_EDITOR (editor)); - g_return_if_fail (GLADE_IS_WIDGET (gchild)); - - va_start (args, gchild); - property = va_arg (args, gchar *); - - while (property) - { - eprop = glade_editor_property_new_from_widget (gchild, property, TRUE); - if (eprop) - glade_base_editor_table_attach (editor, - GLADE_EDITOR_PROPERTY (eprop)->eventbox, - GTK_WIDGET (eprop)); - property = va_arg (args, gchar *); - } -} - -/** - * glade_base_editor_add_label: - * @editor: a #GladeBaseEditor - * @str: the label string - * - * Adds a new label to @editor - * - * NOTE: This function is intended to be used in "child-selected" callbacks - */ -void -glade_base_editor_add_label (GladeBaseEditor *editor, gchar *str) -{ - GtkWidget *label; - gchar *markup; - gint row; - - g_return_if_fail (GLADE_IS_BASE_EDITOR (editor)); - g_return_if_fail (str != NULL); - - label = gtk_label_new (NULL); - markup = g_strdup_printf ("<span rise=\"-20000\"><b>%s</b></span>", str); - row = editor->priv->row; - - gtk_label_set_markup (GTK_LABEL (label), markup); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0); - gtk_table_attach (GTK_TABLE (editor->priv->table), label, 0, 2, row, row + 1, - GTK_FILL, GTK_EXPAND | GTK_FILL, 2, 0); - gtk_widget_show (label); - editor->priv->row++; - - g_free (markup); -} - -/** - * glade_base_editor_add_popup_items: - * @editor: a #GladeBaseEditor - * @...: a NULL terminated list of gchar *, #GType, gboolean - * - * Adds a new popup item to the editor. - * Three parameters are needed for each new popup item: - * o the popup item's label - * o the object type this popup item will create - * o whether this popup item will add the new object as child - */ -void -glade_base_editor_add_popup_items (GladeBaseEditor *editor, ...) -{ - va_list args; - GtkMenuShell *menu; - GtkWidget *item; - gchar *label; - GType type; - gboolean as_child; - - g_return_if_fail (GLADE_IS_BASE_EDITOR (editor)); - - if (editor->priv->popup == NULL) - { - /* Create PopUp */ - editor->priv->popup = gtk_menu_new (); - gtk_widget_show (editor->priv->popup); - g_signal_connect (editor->priv->treeview, "button-press-event", - G_CALLBACK (glade_base_editor_popup_handler), - editor); - } - - menu = GTK_MENU_SHELL (editor->priv->popup); - - va_start (args, editor); - - while ((label = va_arg (args, gchar *))) - { - type = va_arg (args, GType); - as_child = va_arg (args, gboolean); - - if (!glade_base_editor_get_type_info (editor, NULL, type, -1)) - continue; - - item = gtk_menu_item_new_with_label (label); - gtk_widget_show (item); - - g_object_set_data (G_OBJECT (item), "object_type", - GINT_TO_POINTER (type)); - - g_object_set_data (G_OBJECT (item), "object_as_child", - GINT_TO_POINTER (as_child)); - - if (editor->priv->add_type == 0) - { - editor->priv->add_type = type; - editor->priv->add_as_child = as_child; - } - - g_signal_connect (item, "activate", - G_CALLBACK (glade_base_editor_add_item_activate), editor); - gtk_menu_shell_append (menu, item); - } -} - -/** - * glade_base_editor_set_show_signal_editor: - * @editor: a #GladeBaseEditor - * @val: - * - * Shows/hide @editor 's signal editor - */ -void -glade_base_editor_set_show_signal_editor (GladeBaseEditor *editor, gboolean val) -{ - g_return_if_fail (GLADE_IS_BASE_EDITOR (editor)); - - if (val) - gtk_widget_show (editor->priv->signal_editor_w); - else - gtk_widget_hide (editor->priv->signal_editor_w); -} - -/* Convenience functions */ - -static void -glade_base_editor_help (GtkButton *button, gchar *markup) -{ - GtkWidget *dialog; - - dialog = gtk_message_dialog_new (glade_app_get_transient_parent (), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_INFO, - GTK_BUTTONS_CLOSE, " "); - - gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog), markup); - - gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); -} - -/** - * glade_base_editor_pack_new_window: - * @editor: a #GladeBaseEditor - * @title: the window title - * @help_markup: the help text - * - * This convenience function create a new modal window and packs @editor in it. - * Returns the newly created window - */ -GtkWidget * -glade_base_editor_pack_new_window (GladeBaseEditor *editor, - gchar *title, - gchar *help_markup) -{ - GtkWidget *window, *buttonbox, *button; - gchar *real_title; - - g_return_val_if_fail (GLADE_IS_BASE_EDITOR (editor), NULL); - - /* Window */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_modal (GTK_WINDOW (window), TRUE); - gtk_window_set_type_hint (GTK_WINDOW (window), GDK_WINDOW_TYPE_HINT_DIALOG); - - if (title) - { - real_title = g_strdup_printf ("%s - %s", title, - glade_widget_get_name (editor->priv->gcontainer)); - gtk_window_set_title (GTK_WINDOW (window), real_title); - g_free (real_title); - } - - /* Button Box */ - buttonbox = gtk_hbutton_box_new (); - gtk_widget_show (buttonbox); - gtk_button_box_set_layout (GTK_BUTTON_BOX (buttonbox), GTK_BUTTONBOX_END); - gtk_box_set_spacing (GTK_BOX (buttonbox), 8); - gtk_box_pack_start (GTK_BOX (editor), buttonbox, FALSE, TRUE, 0); - - button = glade_app_undo_button_new (); - gtk_widget_show (button); - gtk_container_add (GTK_CONTAINER (buttonbox), button); - - button = glade_app_redo_button_new (); - gtk_widget_show (button); - gtk_container_add (GTK_CONTAINER (buttonbox), button); - - button = gtk_button_new_from_stock (GTK_STOCK_CLOSE); - gtk_widget_show (button); - g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_widget_destroy), window); - gtk_container_add (GTK_CONTAINER (buttonbox), button); - - if (help_markup) - { - button = gtk_button_new_from_stock (GTK_STOCK_HELP); - gtk_widget_show (button); - g_signal_connect (button, "clicked", - G_CALLBACK (glade_base_editor_help), - help_markup); - gtk_container_add (GTK_CONTAINER (buttonbox), button); - gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (buttonbox), button, TRUE); - } - - gtk_container_set_border_width (GTK_CONTAINER (editor), 6); - gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (editor)); - - gtk_window_set_default_size (GTK_WINDOW (window), 640, 480); - - return window; -} diff --git a/gladeui/glade-base-editor.h b/gladeui/glade-base-editor.h deleted file mode 100644 index 46420df6..00000000 --- a/gladeui/glade-base-editor.h +++ /dev/null @@ -1,92 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2006 Juan Pablo Ugarte. - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Authors: - * Juan Pablo Ugarte <juanpablougarte@gmail.com> - */ -#ifndef __GLADE_BASE_EDITOR_H__ -#define __GLADE_BASE_EDITOR_H__ - -#include <gladeui/glade-widget.h> -#include <gladeui/glade-marshallers.h> - -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -#define GLADE_TYPE_BASE_EDITOR (glade_base_editor_get_type ()) -#define GLADE_BASE_EDITOR(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GLADE_TYPE_BASE_EDITOR, GladeBaseEditor)) -#define GLADE_BASE_EDITOR_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GLADE_TYPE_BASE_EDITOR, GladeBaseEditorClass)) -#define GLADE_IS_BASE_EDITOR(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GLADE_TYPE_BASE_EDITOR)) -#define GLADE_IS_BASE_EDITOR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GLADE_TYPE_BASE_EDITOR)) -#define GLADE_BASE_EDITOR_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GLADE_TYPE_BASE_EDITOR, GladeBaseEditorClass)) - -typedef struct _GladeBaseEditor GladeBaseEditor; -typedef struct _GladeBaseEditorPrivate GladeBaseEditorPrivate; -typedef struct _GladeBaseEditorClass GladeBaseEditorClass; - -struct _GladeBaseEditor -{ - GtkVBox parent; - - GladeBaseEditorPrivate *priv; -}; - -struct _GladeBaseEditorClass -{ - GtkVBoxClass parent_class; - - void (*child_selected) (GladeBaseEditor *, GladeWidget *); - gboolean (*change_type) (GladeBaseEditor *, GladeWidget *, GType); - gchar * (*get_display_name) (GladeBaseEditor *, GladeWidget *); - GladeWidget * (*build_child) (GladeBaseEditor *, GladeWidget *, GType); - gboolean (*delete_child) (GladeBaseEditor *, GladeWidget *, GladeWidget *); - gboolean (*move_child) (GladeBaseEditor *, GladeWidget *, GladeWidget *); -}; - - -GType glade_base_editor_get_type (void); - -GladeBaseEditor *glade_base_editor_new (GObject *container, - gboolean tree_like, - ...); - -void glade_base_editor_add_default_properties (GladeBaseEditor *editor, - GladeWidget *gchild); - -void glade_base_editor_add_properties (GladeBaseEditor *editor, - GladeWidget *gchild, - ...); - -void glade_base_editor_add_label (GladeBaseEditor *editor, - gchar *str); - -void glade_base_editor_add_popup_items (GladeBaseEditor *editor, - ...); - -void glade_base_editor_set_show_signal_editor (GladeBaseEditor *editor, - gboolean val); - -/* Convenience functions */ -GtkWidget *glade_base_editor_pack_new_window (GladeBaseEditor *editor, - gchar *title, - gchar *markup); - -G_END_DECLS - -#endif /* __GLADE_BASE_EDITOR_H__ */ diff --git a/gladeui/glade-builtins.c b/gladeui/glade-builtins.c deleted file mode 100644 index a5838cfd..00000000 --- a/gladeui/glade-builtins.c +++ /dev/null @@ -1,664 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * glade-clipboard.c - An object for handling Cut/Copy/Paste. - * - * Copyright (C) 2005 The GNOME Foundation. - * - * Author(s): - * Tristan Van Berkom <tvb@gnome.org> - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <glib-object.h> -#include <glib/gi18n-lib.h> -#include <string.h> -#include "glade-builtins.h" - - -struct _GladeParamSpecObjects { - GParamSpec parent_instance; - - GType type; /* Object or interface type accepted - * in this object list. - */ -}; - -struct _GladeParamSpecAccel { - GParamSpec parent_instance; - - GType type; /* The type this accel key is for; this allows - * us to verify the validity of any signals for - * this type. - */ -}; - - -/************************************************************ - * Auto-generate the enum type for stock properties * - ************************************************************/ - -/* Hard-coded list of stock images from gtk+ that are not stock "items" */ -static const gchar *builtin_stock_images[] = -{ - "gtk-dialog-authentication", /* GTK_STOCK_DIALOG_AUTHENTICATION */ - "gtk-dnd", /* GTK_STOCK_DND */ - "gtk-dnd-multiple", /* GTK_STOCK_DND_MULTIPLE */ - "gtk-color-picker", /* GTK_STOCK_COLOR_PICKER */ - "gtk-directory", /* GTK_STOCK_DIRECTORY */ - "gtk-file", /* GTK_STOCK_FILE */ - "gtk-missing-image" /* GTK_STOCK_MISSING_IMAGE */ -}; - -static GSList *stock_prefixs = NULL; -static gboolean stock_prefixs_done = FALSE; - -/* FIXME: func needs documentation - */ -void -glade_standard_stock_append_prefix (const gchar *prefix) -{ - if (stock_prefixs_done) - { - g_warning ("glade_standard_stock_append_prefix should be used in catalog init-function"); - return; - } - - stock_prefixs = g_slist_append (stock_prefixs, g_strdup (prefix)); -} - -static GArray * -list_stock_items (gboolean include_images) -{ - GtkStockItem item; - GSList *l, *stock_list, *p; - gchar *stock_id, *prefix; - gint stock_enum = 1, i; - GEnumValue value; - GArray *values; - - /* We have ownership of the retuened list & the - * strings within - */ - stock_list = g_slist_reverse (gtk_stock_list_ids ()); - - values = g_array_sized_new (TRUE, TRUE, sizeof (GEnumValue), - g_slist_length (stock_list) + 2); - - - /* Add first "no stock" element */ - value.value_nick = g_strdup ("glade-none"); /* Passing ownership here */ - value.value_name = g_strdup ("None"); - value.value = 0; - values = g_array_append_val (values, value); - - /* We want gtk+ stock items to appear first */ - if ((stock_prefixs && strcmp (stock_prefixs->data, "gtk-")) || - stock_prefixs == NULL) - stock_prefixs = g_slist_prepend (stock_prefixs, g_strdup ("gtk-")); - - for (p = stock_prefixs; p; p = g_slist_next (p)) - { - prefix = p->data; - - for (l = stock_list; l; l = g_slist_next (l)) - { - stock_id = l->data; - if (g_str_has_prefix (stock_id, prefix) == FALSE || - gtk_stock_lookup (stock_id, &item) == FALSE ) - continue; - - value.value = stock_enum++; - value.value_name = g_strdup (item.label); - value.value_nick = stock_id; /* Passing ownership here */ - values = g_array_append_val (values, value); - } - - /* Images are appended after the gtk+ group of items */ - if (include_images && !strcmp (prefix, "gtk-")) - { - for (i = 0; i < G_N_ELEMENTS (builtin_stock_images); i++) - { - value.value = stock_enum++; - value.value_name = g_strdup (builtin_stock_images[i]); - value.value_nick = g_strdup (builtin_stock_images[i]); - values = g_array_append_val (values, value); - } - } - - } - - /* Add the trailing end marker */ - value.value = 0; - value.value_name = NULL; - value.value_nick = NULL; - values = g_array_append_val (values, value); - - stock_prefixs_done = TRUE; - g_slist_free (stock_list); - - return values; -} - -GType -glade_standard_stock_get_type (void) -{ - static GType etype = 0; - - if (etype == 0) { - GArray *values = list_stock_items (FALSE); - - etype = g_enum_register_static ("GladeStock", - (GEnumValue *)g_array_free (values, FALSE)); - } - return etype; -} - - -GType -glade_standard_stock_image_get_type (void) -{ - static GType etype = 0; - - if (etype == 0) { - GArray *values = list_stock_items (TRUE); - - etype = g_enum_register_static ("GladeStockImage", - (GEnumValue *)g_array_free (values, FALSE)); - } - return etype; -} - -GParamSpec * -glade_standard_stock_spec (void) -{ - return g_param_spec_enum ("stock", _("Stock"), - _("A builtin stock item"), - GLADE_TYPE_STOCK, - 0, G_PARAM_READWRITE); -} - -GParamSpec * -glade_standard_stock_image_spec (void) -{ - return g_param_spec_enum ("stock-image", _("Stock Image"), - _("A builtin stock image"), - GLADE_TYPE_STOCK_IMAGE, - 0, G_PARAM_READWRITE); -} - - -/**************************************************************** - * A GList boxed type used by GladeParamSpecObjects and * - * GladeParamSpecAccel * - ****************************************************************/ -GType -glade_glist_get_type (void) -{ - static GType type_id = 0; - - if (!type_id) - type_id = g_boxed_type_register_static - ("GladeGList", - (GBoxedCopyFunc) g_list_copy, - (GBoxedFreeFunc) g_list_free); - return type_id; -} - -GList * -glade_accel_list_copy (GList *accels) -{ - GList *ret = NULL, *list; - GladeAccelInfo *info, *dup_info; - - for (list = accels; list; list = list->next) - { - info = list->data; - - dup_info = g_new0 (GladeAccelInfo, 1); - dup_info->signal = g_strdup (info->signal); - dup_info->key = info->key; - dup_info->modifiers = info->modifiers; - - ret = g_list_prepend (ret, dup_info); - } - - return g_list_reverse (ret); -} - -void -glade_accel_list_free (GList *accels) -{ - GList *list; - GladeAccelInfo *info; - - for (list = accels; list; list = list->next) - { - info = list->data; - - g_free (info->signal); - g_free (info); - } - g_list_free (accels); -} - -GType -glade_accel_glist_get_type (void) -{ - static GType type_id = 0; - - if (!type_id) - type_id = g_boxed_type_register_static - ("GladeAccelGList", - (GBoxedCopyFunc) glade_accel_list_copy, - (GBoxedFreeFunc) glade_accel_list_free); - return type_id; -} - - -/**************************************************************** - * Built-in GladeParamSpecAccel for accelerator properties * - ****************************************************************/ -gboolean -glade_keyval_valid (guint val) -{ - gint i; - - for (i = 0; GladeKeys[i].name != NULL; i++) - { - if (GladeKeys[i].value == val) - return TRUE; - } - return FALSE; -} - - -static void -param_accel_init (GParamSpec *pspec) -{ - GladeParamSpecAccel *ospec = GLADE_PARAM_SPEC_ACCEL (pspec); - ospec->type = G_TYPE_OBJECT; -} - -static void -param_accel_set_default (GParamSpec *pspec, - GValue *value) -{ - if (value->data[0].v_pointer != NULL) - { - g_free (value->data[0].v_pointer); - } - value->data[0].v_pointer = NULL; -} - -static gboolean -param_accel_validate (GParamSpec *pspec, - GValue *value) -{ - /* GladeParamSpecAccel *aspec = GLADE_PARAM_SPEC_ACCEL (pspec); */ - GList *accels, *list, *toremove = NULL; - GladeAccelInfo *info; - - accels = value->data[0].v_pointer; - - for (list = accels; list; list = list->next) - { - info = list->data; - - /* Is it an invalid key ? */ - if (glade_keyval_valid (info->key) == FALSE || - /* Does the modifier contain any unwanted bits ? */ - info->modifiers & GDK_MODIFIER_MASK || - /* Do we have a signal ? */ - /* FIXME: Check if the signal is valid for 'type' */ - info->signal == NULL) - toremove = g_list_prepend (toremove, info); - } - - for (list = toremove; list; list = list->next) - accels = g_list_remove (accels, list->data); - - if (toremove) g_list_free (toremove); - - value->data[0].v_pointer = accels; - - return toremove != NULL; -} - -static gint -param_accel_values_cmp (GParamSpec *pspec, - const GValue *value1, - const GValue *value2) -{ - guint8 *p1 = value1->data[0].v_pointer; - guint8 *p2 = value2->data[0].v_pointer; - - /* not much to compare here, try to at least provide stable lesser/greater result */ - - return p1 < p2 ? -1 : p1 > p2; -} - -GType -glade_param_accel_get_type (void) -{ - static GType accel_type = 0; - - if (accel_type == 0) - { - static /* const */ GParamSpecTypeInfo pspec_info = { - sizeof (GladeParamSpecAccel), /* instance_size */ - 16, /* n_preallocs */ - param_accel_init, /* instance_init */ - 0xdeadbeef, /* value_type, assigned further down */ - NULL, /* finalize */ - param_accel_set_default, /* value_set_default */ - param_accel_validate, /* value_validate */ - param_accel_values_cmp, /* values_cmp */ - }; - pspec_info.value_type = GLADE_TYPE_ACCEL_GLIST; - - accel_type = g_param_type_register_static - ("GladeParamAccel", &pspec_info); - } - return accel_type; -} - -GParamSpec * -glade_param_spec_accel (const gchar *name, - const gchar *nick, - const gchar *blurb, - GType widget_type, - GParamFlags flags) -{ - GladeParamSpecAccel *pspec; - - pspec = g_param_spec_internal (GLADE_TYPE_PARAM_ACCEL, - name, nick, blurb, flags); - - pspec->type = widget_type; - return G_PARAM_SPEC (pspec); -} - -/**************************************************************** - * Built-in GladeParamSpecObjects for object list properties * - * (Used as a pspec to desctibe an AtkRelationSet, but can * - * for any object list property) * - ****************************************************************/ -static void -param_objects_init (GParamSpec *pspec) -{ - GladeParamSpecObjects *ospec = GLADE_PARAM_SPEC_OBJECTS (pspec); - ospec->type = G_TYPE_OBJECT; -} - -static void -param_objects_set_default (GParamSpec *pspec, - GValue *value) -{ - if (value->data[0].v_pointer != NULL) - { - g_free (value->data[0].v_pointer); - } - value->data[0].v_pointer = NULL; -} - -static gboolean -param_objects_validate (GParamSpec *pspec, - GValue *value) -{ - GladeParamSpecObjects *ospec = GLADE_PARAM_SPEC_OBJECTS (pspec); - GList *objects, *list, *toremove = NULL; - GObject *object; - - objects = value->data[0].v_pointer; - - for (list = objects; list; list = list->next) - { - object = list->data; - - if (G_TYPE_IS_INTERFACE (ospec->type) && - glade_util_class_implements_interface - (G_OBJECT_TYPE (object), ospec->type) == FALSE) - toremove = g_list_prepend (toremove, object); - else if (G_TYPE_IS_INTERFACE (ospec->type) == FALSE && - g_type_is_a (G_OBJECT_TYPE (object), - ospec->type) == FALSE) - toremove = g_list_prepend (toremove, object); - } - - for (list = toremove; list; list = list->next) - { - object = list->data; - objects = g_list_remove (objects, object); - } - if (toremove) g_list_free (toremove); - - value->data[0].v_pointer = objects; - - return toremove != NULL; -} - -static gint -param_objects_values_cmp (GParamSpec *pspec, - const GValue *value1, - const GValue *value2) -{ - guint8 *p1 = value1->data[0].v_pointer; - guint8 *p2 = value2->data[0].v_pointer; - - /* not much to compare here, try to at least provide stable lesser/greater result */ - - return p1 < p2 ? -1 : p1 > p2; -} - -GType -glade_param_objects_get_type (void) -{ - static GType objects_type = 0; - - if (objects_type == 0) - { - static /* const */ GParamSpecTypeInfo pspec_info = { - sizeof (GladeParamSpecObjects), /* instance_size */ - 16, /* n_preallocs */ - param_objects_init, /* instance_init */ - 0xdeadbeef, /* value_type, assigned further down */ - NULL, /* finalize */ - param_objects_set_default, /* value_set_default */ - param_objects_validate, /* value_validate */ - param_objects_values_cmp, /* values_cmp */ - }; - pspec_info.value_type = GLADE_TYPE_GLIST; - - objects_type = g_param_type_register_static - ("GladeParamObjects", &pspec_info); - } - return objects_type; -} - -GParamSpec * -glade_param_spec_objects (const gchar *name, - const gchar *nick, - const gchar *blurb, - GType accepted_type, - GParamFlags flags) -{ - GladeParamSpecObjects *pspec; - - pspec = g_param_spec_internal (GLADE_TYPE_PARAM_OBJECTS, - name, nick, blurb, flags); - - pspec->type = accepted_type; - return G_PARAM_SPEC (pspec); -} - -void -glade_param_spec_objects_set_type (GladeParamSpecObjects *pspec, - GType type) -{ - pspec->type = type; -} - -GType -glade_param_spec_objects_get_type (GladeParamSpecObjects *pspec) -{ - return pspec->type; -} - -/* This was developed for the purpose of holding a list - * of 'targets' in an AtkRelation (we are setting it up - * as a property) - */ -GParamSpec * -glade_standard_objects_spec (void) -{ - return glade_param_spec_objects ("objects", _("Objects"), - _("A list of objects"), - G_TYPE_OBJECT, - G_PARAM_READWRITE); -} - -/* Pixbuf Type */ -GParamSpec * -glade_standard_pixbuf_spec (void) -{ - return g_param_spec_object ("pixbuf", _("Pixbuf"), - _("A pixbuf value"), GDK_TYPE_PIXBUF, - G_PARAM_READWRITE); -} - -/* GdkColor */ -GParamSpec * -glade_standard_gdkcolor_spec (void) -{ - return g_param_spec_boxed ("gdkcolor", _("GdkColor"), - _("A gdk color value"), GDK_TYPE_COLOR, - G_PARAM_READWRITE); -} - -/* Accelerator spec */ -GParamSpec * -glade_standard_accel_spec (void) -{ - return glade_param_spec_accel ("accelerators", _("Accelerators"), - _("A list of accelerator keys"), - GTK_TYPE_WIDGET, - G_PARAM_READWRITE); -} - -/**************************************************************** - * Basic types follow * - ****************************************************************/ -GParamSpec * -glade_standard_int_spec (void) -{ - return g_param_spec_int ("int", _("Integer"), - _("An integer value"), - G_MININT, G_MAXINT, - 0, G_PARAM_READWRITE); -} - -GParamSpec * -glade_standard_uint_spec (void) -{ - return g_param_spec_uint ("uint", _("Unsigned Integer"), - _("An unsigned integer value"), - 0, G_MAXUINT, 0, G_PARAM_READWRITE); -} - -GParamSpec * -glade_standard_string_spec (void) -{ - return g_param_spec_string ("string", _("String"), - _("An entry"), "", - G_PARAM_READWRITE); -} - -GParamSpec * -glade_standard_strv_spec (void) -{ - return g_param_spec_boxed ("strv", _("Strv"), - _("String array"), - G_TYPE_STRV, - G_PARAM_READWRITE); -} - -GParamSpec * -glade_standard_float_spec (void) -{ - return g_param_spec_float ("float", _("Float"), - _("A floating point entry"), - 0.0F, G_MAXFLOAT, 0.0F, - G_PARAM_READWRITE); -} - -GParamSpec * -glade_standard_boolean_spec (void) -{ - return g_param_spec_boolean ("boolean", _("Boolean"), - _("A boolean value"), FALSE, - G_PARAM_READWRITE); -} - -guint -glade_builtin_key_from_string (const gchar *string) -{ - gint i; - - g_return_val_if_fail (string != NULL, 0); - - for (i = 0; GladeKeys[i].name != NULL; i++) - if (!strcmp (string, GladeKeys[i].name)) - return GladeKeys[i].value; - - return 0; -} - -const gchar * -glade_builtin_string_from_key (guint key) -{ - gint i; - - for (i = 0; GladeKeys[i].name != NULL; i++) - if (GladeKeys[i].value == key) - return GladeKeys[i].name; - return NULL; -} - -GType -glade_item_appearance_get_type (void) -{ - static GType etype = 0; - - if (etype == 0) - { - static const GEnumValue values[] = { - { GLADE_ITEM_ICON_AND_LABEL, "GLADE_ITEM_ICON_AND_LABEL", "icon-and-label" }, - { GLADE_ITEM_ICON_ONLY, "GLADE_ITEM_ICON_ONLY", "icon-only" }, - { GLADE_ITEM_LABEL_ONLY, "GLADE_ITEM_LABEL_ONLY", "label-only" }, - { 0, NULL, NULL } - }; - - etype = g_enum_register_static ("GladeItemAppearance", values); - - } - - return etype; -} diff --git a/gladeui/glade-builtins.h b/gladeui/glade-builtins.h deleted file mode 100644 index 378824d8..00000000 --- a/gladeui/glade-builtins.h +++ /dev/null @@ -1,107 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef __GLADE_BUILTINS_H__ -#define __GLADE_BUILTINS_H__ - -#include <glib-object.h> -#include <gladeui/glade.h> - -G_BEGIN_DECLS - -typedef struct _GladeParamSpecObjects GladeParamSpecObjects; -typedef struct _GladeParamSpecAccel GladeParamSpecAccel; -typedef struct _GladeKey GladeKey; - - -struct _GladeKey { - guint value; - gchar *name; -}; - -extern const GladeKey GladeKeys[]; - -#define GLADE_KEYS_LAST_ALPHANUM "9" -#define GLADE_KEYS_LAST_EXTRA "questiondown" -#define GLADE_KEYS_LAST_KP "KP_9" -#define GLADE_KEYS_LAST_FKEY "F35" - -#define GLADE_TYPE_STOCK (glade_standard_stock_get_type()) -#define GLADE_TYPE_STOCK_IMAGE (glade_standard_stock_image_get_type()) -#define GLADE_TYPE_GLIST (glade_glist_get_type()) -#define GLADE_TYPE_ACCEL_GLIST (glade_accel_glist_get_type()) -#define GLADE_TYPE_PARAM_OBJECTS (glade_param_objects_get_type()) -#define GLADE_TYPE_PARAM_ACCEL (glade_param_accel_get_type()) -#define GLADE_TYPE_ITEM_APPEARANCE (glade_item_appearance_get_type()) - -#define GLADE_IS_STOCK(pspec) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GLADE_TYPE_STOCK)) - -#define GLADE_IS_STOCK_IMAGE(pspec) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GLADE_TYPE_STOCK_IMAGE)) - -#define GLADE_IS_PARAM_SPEC_OBJECTS(pspec) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), \ - GLADE_TYPE_PARAM_OBJECTS)) -#define GLADE_PARAM_SPEC_OBJECTS(pspec) \ - (G_TYPE_CHECK_INSTANCE_CAST ((pspec), \ - GLADE_TYPE_PARAM_OBJECTS, GladeParamSpecObjects)) - -#define GLADE_IS_PARAM_SPEC_ACCEL(pspec) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), \ - GLADE_TYPE_PARAM_ACCEL)) -#define GLADE_PARAM_SPEC_ACCEL(pspec) \ - (G_TYPE_CHECK_INSTANCE_CAST ((pspec), \ - GLADE_TYPE_PARAM_ACCEL, GladeParamSpecAccel)) - -GType glade_standard_stock_get_type (void) G_GNUC_CONST; -GType glade_standard_stock_image_get_type (void) G_GNUC_CONST; -GType glade_glist_get_type (void) G_GNUC_CONST; -GType glade_accel_glist_get_type (void) G_GNUC_CONST; -GType glade_param_objects_get_type (void) G_GNUC_CONST; -GType glade_param_accel_get_type (void) G_GNUC_CONST; -GType glade_item_appearance_get_type (void) G_GNUC_CONST; - -guint glade_builtin_key_from_string (const gchar *string); -const gchar *glade_builtin_string_from_key (guint key); - - -GList *glade_accel_list_copy (GList *accels); -void glade_accel_list_free (GList *accels); - - - -GParamSpec *glade_param_spec_objects (const gchar *name, - const gchar *nick, - const gchar *blurb, - GType accepted_type, - GParamFlags flags); - -GParamSpec *glade_param_spec_accel (const gchar *name, - const gchar *nick, - const gchar *blurb, - GType widget_type, - GParamFlags flags); - -void glade_param_spec_objects_set_type (GladeParamSpecObjects *pspec, - GType type); -GType glade_param_spec_objects_get_type (GladeParamSpecObjects *pspec); - -GParamSpec *glade_standard_pixbuf_spec (void); -GParamSpec *glade_standard_gdkcolor_spec (void); -GParamSpec *glade_standard_objects_spec (void); -GParamSpec *glade_standard_stock_spec (void); -GParamSpec *glade_standard_stock_image_spec (void); -GParamSpec *glade_standard_accel_spec (void); -GParamSpec *glade_standard_int_spec (void); -GParamSpec *glade_standard_uint_spec (void); -GParamSpec *glade_standard_string_spec (void); -GParamSpec *glade_standard_strv_spec (void); -GParamSpec *glade_standard_float_spec (void); -GParamSpec *glade_standard_boolean_spec (void); - -void glade_standard_stock_append_prefix (const gchar *prefix); - -gboolean glade_keyval_valid (guint val); - -G_END_DECLS - -#endif /* __GLADE_BUILTINS_H__ */ diff --git a/gladeui/glade-catalog.c b/gladeui/glade-catalog.c deleted file mode 100644 index ad61a897..00000000 --- a/gladeui/glade-catalog.c +++ /dev/null @@ -1,650 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2001 Ximian, Inc. - * Copyright (C) 2004 Imendio AB - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Authors: - * Chema Celorio <chema@celorio.com> - */ - -#include <config.h> - -#include "glade.h" -#include "glade-catalog.h" -#include "glade-widget-adaptor.h" - -#include <string.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <glib.h> -#include <glib/gi18n-lib.h> - -typedef void (*GladeCatalogInitFunc) (void); - -struct _GladeCatalog -{ - gchar *language; /* Library language, NULL means language is C */ - gchar *library; /* Library name for backend support */ - - gchar *name; /* Symbolic catalog name */ - - gchar *dep_catalog; /* Symbolic name of the catalog that - * this catalog depends on */ - - gchar *domain; /* The domain to be used to translate - * strings from this catalog (otherwise this - * defaults to the library name) - */ - - gchar *book; /* Devhelp search domain - */ - - gchar *icon_prefix; /* the prefix for icons */ - - GList *widget_groups; /* List of widget groups (palette) */ - GList *adaptors; /* List of widget class adaptors (all) */ - - GladeXmlContext *context;/* Xml context is stored after open - * before classes are loaded */ - - GModule *module; - - gchar *init_function_name;/* Catalog's init function name */ - GladeCatalogInitFunc init_function; -}; - -struct _GladeWidgetGroup -{ - gchar *name; /* Group name */ - gchar *title; /* Group name in the palette */ - - gboolean expanded; /* Whether group is expanded in the palette */ - - GList *adaptors; /* List of class adaptors in the palette */ -}; - -static void catalog_load (GladeCatalog *catalog); - -static GladeCatalog *catalog_open (const gchar *filename); - -static GList *catalog_sort (GList *catalogs); - -static gboolean catalog_load_classes (GladeCatalog *catalog, - - GladeXmlNode *widgets_node); - -static gboolean catalog_load_group (GladeCatalog *catalog, - - GladeXmlNode *group_node); - -static void widget_group_destroy (GladeWidgetGroup *group); - -static void catalog_destroy (GladeCatalog *catalog); - -static void module_close (GModule *module); - - -/* List of catalogs successfully loaded. - */ -static GList *loaded_catalogs = NULL; - -static gboolean -catalog_get_function (GladeCatalog *catalog, - const gchar *symbol_name, - gpointer *symbol_ptr) -{ - if (catalog->module == NULL) - catalog->module = glade_util_load_library (catalog->library); - - if (catalog->module) - return g_module_symbol (catalog->module, symbol_name, symbol_ptr); - - return FALSE; -} - -static GladeCatalog * -catalog_allocate (void) -{ - GladeCatalog *catalog; - - catalog = g_slice_new0 (GladeCatalog); - - catalog->language = NULL; - catalog->library = NULL; - catalog->name = NULL; - catalog->dep_catalog = NULL; - catalog->domain = NULL; - catalog->book = NULL; - catalog->icon_prefix = NULL; - catalog->init_function_name = NULL; - catalog->module = NULL; - - catalog->context = NULL; - catalog->adaptors = NULL; - catalog->widget_groups = NULL; - - return catalog; -} - -static GladeCatalog * -catalog_open (const gchar *filename) -{ - GladeCatalog *catalog; - GladeXmlContext *context; - GladeXmlDoc *doc; - GladeXmlNode *root; - - /* get the context & root node of the catalog file */ - context = glade_xml_context_new_from_path (filename, - NULL, - GLADE_TAG_GLADE_CATALOG); - if (!context) - { - g_warning ("Couldn't open catalog [%s].", filename); - return NULL; - } - - doc = glade_xml_context_get_doc (context); - root = glade_xml_doc_get_root (doc); - - if (!glade_xml_node_verify (root, GLADE_TAG_GLADE_CATALOG)) - { - g_warning ("Catalog root node is not '%s', skipping %s", - GLADE_TAG_GLADE_CATALOG, filename); - glade_xml_context_free (context); - return NULL; - } - - catalog = catalog_allocate (); - catalog->context = context; - catalog->name = glade_xml_get_property_string (root, GLADE_TAG_NAME); - - if (!catalog->name) - { - g_warning ("Couldn't find required property 'name' in catalog root node"); - catalog_destroy (catalog); - return NULL; - } - - catalog->library = glade_xml_get_property_string (root, GLADE_TAG_LIBRARY); - catalog->dep_catalog = glade_xml_get_property_string (root, GLADE_TAG_DEPENDS); - catalog->domain = glade_xml_get_property_string (root, GLADE_TAG_DOMAIN); - catalog->book = glade_xml_get_property_string (root, GLADE_TAG_BOOK); - catalog->icon_prefix = glade_xml_get_property_string (root, GLADE_TAG_ICON_PREFIX); - catalog->init_function_name = glade_xml_get_value_string (root, GLADE_TAG_INIT_FUNCTION); - - /* catalog->icon_prefix defaults to catalog->name */ - if (!catalog->icon_prefix) - catalog->icon_prefix = g_strdup (catalog->name); - - if (catalog->init_function_name && catalog->language == NULL) - catalog_get_function (catalog, catalog->init_function_name, - (gpointer) &catalog->init_function); - - return catalog; -} - - -static void -catalog_load (GladeCatalog *catalog) -{ - GladeXmlDoc *doc; - GladeXmlNode *root; - GladeXmlNode *node; - - g_return_if_fail (catalog->context != NULL); - - doc = glade_xml_context_get_doc (catalog->context); - root = glade_xml_doc_get_root (doc); - node = glade_xml_node_get_children (root); - - for (; node; node = glade_xml_node_next (node)) - { - const gchar *node_name; - - node_name = glade_xml_node_get_name (node); - if (strcmp (node_name, GLADE_TAG_GLADE_WIDGET_CLASSES) == 0) - { - catalog_load_classes (catalog, node); - } - else if (strcmp (node_name, GLADE_TAG_GLADE_WIDGET_GROUP) == 0) - { - catalog_load_group (catalog, node); - } - else - continue; - } - - catalog->widget_groups = g_list_reverse (catalog->widget_groups); - catalog->context = - (glade_xml_context_free (catalog->context), NULL); - - return; -} - -static gint -catalog_find_by_name (GladeCatalog *catalog, const gchar *name) -{ - return strcmp (catalog->name, name); -} - -static GList * -catalog_sort (GList *catalogs) -{ - GList *l, *node, *sorted = NULL, *sort; - GladeCatalog *catalog, *cat; - - /* Add all dependant catalogs to the sorted list first */ - for (l = catalogs; l; l = l->next) - { - catalog = l->data; - sort = NULL; - - /* itterate ascending through dependancy hierarchy */ - while (catalog->dep_catalog) { - node = g_list_find_custom - (catalogs, catalog->dep_catalog, - (GCompareFunc)catalog_find_by_name); - - if ((cat = node->data) == NULL) - { - g_critical ("Catalog %s depends on catalog %s, not found", - catalog->name, catalog->dep_catalog); - break; - } - - /* Prepend to sort list */ - if (g_list_find (sort, cat) == NULL && - g_list_find (sorted, cat) == NULL) - sort = g_list_prepend (sort, cat); - - catalog = cat; - } - sorted = g_list_concat (sorted, sort); - } - - /* Append all independant catalogs after */ - for (l = catalogs; l; l = l->next) - if (g_list_find (sorted, l->data) == NULL) - sorted = g_list_append (sorted, l->data); - - g_list_free (catalogs); - return sorted; -} - -static GHashTable *modules = NULL; - -static GModule * -catalog_load_library (GladeCatalog *catalog) -{ - GModule *module; - - if (modules == NULL) - modules = g_hash_table_new_full (g_str_hash, - g_str_equal, - (GDestroyNotify) g_free, - (GDestroyNotify) module_close); - - if (catalog->library == NULL) - return NULL; - - if ((module = g_hash_table_lookup (modules, catalog->library))) - return module; - - if ((module = glade_util_load_library (catalog->library))) - g_hash_table_insert (modules, g_strdup (catalog->library), module); - else - g_warning ("Failed to load external library '%s'", - catalog->library); - - return module; -} - -static gboolean -catalog_load_classes (GladeCatalog *catalog, GladeXmlNode *widgets_node) -{ - GladeXmlNode *node; - GModule *module = catalog_load_library (catalog); - - node = glade_xml_node_get_children (widgets_node); - for (; node; node = glade_xml_node_next (node)) - { - const gchar *node_name, *domain; - GladeWidgetAdaptor *adaptor; - - node_name = glade_xml_node_get_name (node); - if (strcmp (node_name, GLADE_TAG_GLADE_WIDGET_CLASS) != 0) - continue; - - domain = catalog->domain ? catalog->domain : catalog->library; - - adaptor = glade_widget_adaptor_from_catalog (node, - catalog->name, - catalog->icon_prefix, - module, - domain, - catalog->book); - - catalog->adaptors = g_list_prepend (catalog->adaptors, adaptor); - } - - return TRUE; -} - -static gboolean -catalog_load_group (GladeCatalog *catalog, GladeXmlNode *group_node) -{ - GladeWidgetGroup *group; - GladeXmlNode *node; - char *title, *translated_title; - - group = g_slice_new0 (GladeWidgetGroup); - - group->name = glade_xml_get_property_string (group_node, - GLADE_TAG_NAME); - - if (!group->name) - { - g_warning ("Required property 'name' not found in group node"); - widget_group_destroy (group); - return FALSE; - } - - title = glade_xml_get_property_string (group_node, - GLADE_TAG_TITLE); - if (!title) - { - g_warning ("Required property 'title' not found in group node"); - widget_group_destroy (group); - return FALSE; - } - - /* by default, group is expanded in palette */ - group->expanded = TRUE; - - /* Translate it */ - translated_title = dgettext (catalog->domain ? - catalog->domain : catalog->library, - title); - if (translated_title != title) - { - group->title = g_strdup (translated_title); - g_free (title); - } - else - { - group->title = title; - } - - group->adaptors = NULL; - - node = glade_xml_node_get_children (group_node); - for (; node; node = glade_xml_node_next (node)) - { - const gchar *node_name; - GladeWidgetAdaptor *adaptor; - gchar *name; - - node_name = glade_xml_node_get_name (node); - - if (strcmp (node_name, GLADE_TAG_GLADE_WIDGET_CLASS_REF) == 0) - { - if ((name = - glade_xml_get_property_string (node, GLADE_TAG_NAME)) == NULL) - { - g_warning ("Couldn't find required property on %s", - GLADE_TAG_GLADE_WIDGET_CLASS); - continue; - } - - if ((adaptor = glade_widget_adaptor_get_by_name (name)) == NULL) - { - g_warning ("Tried to include undefined widget " - "class '%s' in a widget group", name); - g_free (name); - continue; - } - g_free (name); - - group->adaptors = g_list_prepend (group->adaptors, adaptor); - - } - else if (strcmp (node_name, GLADE_TAG_DEFAULT_PALETTE_STATE) == 0) - { - group->expanded = - glade_xml_get_property_boolean - (node, GLADE_TAG_EXPANDED, group->expanded); - } - } - - group->adaptors = g_list_reverse (group->adaptors); - - catalog->widget_groups = g_list_prepend (catalog->widget_groups, group); - - return TRUE; -} - -const GList * -glade_catalog_load_all (void) -{ - GDir *dir; - GError *error = NULL; - const gchar *filename; - GList *catalogs, *l; - GladeCatalog *catalog; - - /* Read all files in catalog dir */ - dir = g_dir_open (glade_app_get_catalogs_dir (), 0, &error); - if (!dir) - { - g_warning ("Failed to open catalog directory: %s", - error->message); - return NULL; - } - - /* Catalogs need dependancies, most catalogs depend on - * the gtk+ catalog, but some custom toolkits may depend - * on the gnome catalog for instance. - */ - catalogs = NULL; - while ((filename = g_dir_read_name (dir))) - { - gchar *catalog_filename; - - if (!g_str_has_suffix (filename, ".xml")) - continue; - - catalog_filename = g_build_filename (glade_app_get_catalogs_dir (), - filename, NULL); - catalog = catalog_open (catalog_filename); - g_free (catalog_filename); - - if (catalog) - catalogs = g_list_prepend (catalogs, catalog); - else - g_warning ("Unable to open the catalog file %s.\n", - filename); - } - g_dir_close (dir); - - /* After sorting, execute init function and then load */ - catalogs = catalog_sort (catalogs); - - for (l = catalogs; l; l = l->next) - { - catalog = l->data; - if (catalog->init_function) - catalog->init_function (); - } - - for (l = catalogs; l; l = l->next) - { - catalog = l->data; - catalog_load (catalog); - } - - loaded_catalogs = catalogs; - - return loaded_catalogs; -} - -const gchar * -glade_catalog_get_name (GladeCatalog *catalog) -{ - g_return_val_if_fail (catalog != NULL, NULL); - - return catalog->name; -} - -GList * -glade_catalog_get_widget_groups (GladeCatalog *catalog) -{ - g_return_val_if_fail (catalog != NULL, NULL); - - return catalog->widget_groups; -} - -GList * -glade_catalog_get_adaptors (GladeCatalog *catalog) -{ - g_return_val_if_fail (catalog != NULL, NULL); - - return catalog->adaptors; -} - -gboolean -glade_catalog_is_loaded (const gchar *name) -{ - GList *l; - - g_return_val_if_fail (name != NULL, FALSE); - g_assert (loaded_catalogs != NULL); - - for (l = loaded_catalogs; l; l = l->next) - { - GladeCatalog *catalog = GLADE_CATALOG (l->data); - if (strcmp (catalog->name, name) == 0) - return TRUE; - } - - return FALSE; -} - -static void -catalog_destroy (GladeCatalog *catalog) -{ - g_return_if_fail (GLADE_IS_CATALOG (catalog)); - - g_free (catalog->name); - g_free (catalog->language); - g_free (catalog->library); - g_free (catalog->dep_catalog); - g_free (catalog->domain); - g_free (catalog->book); - g_free (catalog->icon_prefix); - g_free (catalog->init_function_name); - - if (catalog->adaptors) - { - /* TODO: free adaptors */ - g_list_free (catalog->adaptors); - } - - if (catalog->widget_groups) - { - g_list_foreach (catalog->widget_groups, (GFunc) widget_group_destroy, NULL); - g_list_free (catalog->widget_groups); - } - - if (catalog->context) - glade_xml_context_free (catalog->context); - - g_slice_free (GladeCatalog, catalog); -} - -static void -module_close (GModule *module) -{ - g_module_close (module); -} - -void -glade_catalog_destroy_all (void) -{ - /* close catalogs */ - if (loaded_catalogs) - { - GList *l; - for (l = loaded_catalogs; l; l = l->next) - catalog_destroy (GLADE_CATALOG (l->data)); - g_list_free (loaded_catalogs); - loaded_catalogs = NULL; - } - - /* close plugin modules */ - if (modules) - { - g_hash_table_destroy (modules); - modules = NULL; - } -} - -const gchar * -glade_widget_group_get_name (GladeWidgetGroup *group) -{ - g_return_val_if_fail (group != NULL, NULL); - - return group->name; -} - -const gchar * -glade_widget_group_get_title (GladeWidgetGroup *group) -{ - g_return_val_if_fail (group != NULL, NULL); - - return group->title; -} - -gboolean -glade_widget_group_get_expanded (GladeWidgetGroup *group) -{ - g_return_val_if_fail (group != NULL, FALSE); - - return group->expanded; -} - -const GList * -glade_widget_group_get_adaptors (GladeWidgetGroup *group) -{ - g_return_val_if_fail (group != NULL, NULL); - - return group->adaptors; -} - -static void -widget_group_destroy (GladeWidgetGroup *group) -{ - g_return_if_fail (GLADE_IS_WIDGET_GROUP (group)); - - g_free (group->name); - g_free (group->title); - g_list_free (group->adaptors); - - g_slice_free (GladeWidgetGroup, group); -} - - diff --git a/gladeui/glade-catalog.h b/gladeui/glade-catalog.h deleted file mode 100644 index c8caf81d..00000000 --- a/gladeui/glade-catalog.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2001 Ximian, Inc. - * Copyright (C) 2004 Imendio AB - * Copyright (C) 2007 The GNOME Foundation - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef __GLADE_CATALOG_H__ -#define __GLADE_CATALOG_H__ - -#include <glib.h> - -G_BEGIN_DECLS - -#define GLADE_CATALOG(c) ((GladeCatalog *) c) -#define GLADE_IS_CATALOG(c) (c != NULL) - -typedef struct _GladeCatalog GladeCatalog; - -#define GLADE_WIDGET_GROUP(g) ((GladeWidgetGroup *) g) -#define GLADE_IS_WIDGET_GROUP(g) (g != NULL) - -typedef struct _GladeWidgetGroup GladeWidgetGroup; - - -const GList *glade_catalog_load_all (void); - -const gchar *glade_catalog_get_name (GladeCatalog *catalog); - -GList *glade_catalog_get_widget_groups (GladeCatalog *catalog); - -GList *glade_catalog_get_adaptors (GladeCatalog *catalog); - -gboolean glade_catalog_is_loaded (const gchar *name); - -void glade_catalog_destroy_all (void); - - -const gchar *glade_widget_group_get_name (GladeWidgetGroup *group); - -const gchar *glade_widget_group_get_title (GladeWidgetGroup *group); - -gboolean glade_widget_group_get_expanded (GladeWidgetGroup *group); - -const GList *glade_widget_group_get_adaptors (GladeWidgetGroup *group); - -G_END_DECLS - -#endif /* __GLADE_CATALOG_H__ */ diff --git a/gladeui/glade-clipboard-view.c b/gladeui/glade-clipboard-view.c deleted file mode 100644 index 76a71946..00000000 --- a/gladeui/glade-clipboard-view.c +++ /dev/null @@ -1,380 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * glade-clipboard-view.c - The View for the Clipboard. - * - * Copyright (C) 2001 The GNOME Foundation. - * - * Author(s): - * Archit Baweja <bighead@users.sourceforge.net> - * - * 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. - */ -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <glib/gi18n-lib.h> - -#include "glade.h" -#include "glade-clipboard.h" -#include "glade-clipboard-view.h" -#include "glade-widget.h" -#include "glade-widget-adaptor.h" -#include "glade-popup.h" - - -const gint GLADE_CLIPBOARD_VIEW_WIDTH = 230; -const gint GLADE_CLIPBOARD_VIEW_HEIGHT = 200; - -static void -glade_clipboard_view_class_init (GladeClipboardViewClass *klass) -{ - -} - -static void -glade_clipboard_view_init (GladeClipboardView *view) -{ - view->widget = NULL; - view->clipboard = NULL; - view->model = NULL; -} - -GType -glade_clipboard_view_get_type () -{ - static GType type = 0; - - if (!type) { - static const GTypeInfo info = { - sizeof (GladeClipboardViewClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) glade_clipboard_view_class_init, - (GClassFinalizeFunc) NULL, - NULL, - sizeof (GladeClipboardView), - 0, - (GInstanceInitFunc) glade_clipboard_view_init - }; - - type = g_type_register_static (GTK_TYPE_WINDOW, "GladeClipboardView", &info, 0); - } - - return type; -} - -static void -gcv_foreach_add_selection (GtkTreeModel *model, - GtkTreePath *path, - GtkTreeIter *iter, - gpointer data) -{ - GladeWidget *widget = NULL; - GladeClipboardView *view = (GladeClipboardView *)data; - gtk_tree_model_get (model, iter, 0, &widget, -1); - glade_clipboard_selection_add (view->clipboard, (widget)); -} - -static void -glade_clipboard_view_selection_changed_cb (GtkTreeSelection *sel, - GladeClipboardView *view) -{ - if (view->updating == FALSE) - { - glade_clipboard_selection_clear (view->clipboard); - gtk_tree_selection_selected_foreach - (sel, gcv_foreach_add_selection, view); - } -} - -static void -glade_clipboard_view_populate_model (GladeClipboardView *view) -{ - GladeClipboard *clipboard; - GtkTreeModel *model; - GladeWidget *widget; - GList *list; - GtkTreeIter iter; - - clipboard = GLADE_CLIPBOARD (view->clipboard); - model = GTK_TREE_MODEL (view->model); - - for (list = clipboard->widgets; list; list = list->next) - { - widget = list->data; - view->updating = TRUE; - gtk_list_store_append (GTK_LIST_STORE (model), &iter); - gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, widget, -1); - view->updating = FALSE; - } -} - -static void -glade_clipboard_view_cell_function (GtkTreeViewColumn *tree_column, - GtkCellRenderer *cell, - GtkTreeModel *tree_model, - GtkTreeIter *iter, - gpointer data) -{ - gboolean is_icon = GPOINTER_TO_INT (data); - GladeWidget *widget; - - gtk_tree_model_get (tree_model, iter, 0, &widget, -1); - - g_return_if_fail (GLADE_IS_WIDGET (widget)); - g_return_if_fail (widget->name != NULL); - - if (is_icon) - g_object_set (G_OBJECT (cell), - "icon-name", widget->adaptor->icon_name, - "stock-size", GTK_ICON_SIZE_MENU, - NULL); - else - g_object_set (G_OBJECT (cell), - "text", widget->name, - NULL); - -} - -static gint -glade_clipboard_view_button_press_cb (GtkWidget *widget, - GdkEventButton *event, - GladeClipboardView *view) -{ - GtkTreeView *tree_view = GTK_TREE_VIEW (widget); - GtkTreePath *path = NULL; - gboolean handled = FALSE; - - if (event->window == gtk_tree_view_get_bin_window (tree_view) && - gtk_tree_view_get_path_at_pos (tree_view, - (gint) event->x, (gint) event->y, - &path, NULL, - NULL, NULL) && path != NULL) - { - GtkTreeIter iter; - GladeWidget *widget = NULL; - if (gtk_tree_model_get_iter (GTK_TREE_MODEL (view->model), - &iter, path)) - { - /* Alright, now we can obtain - * the widget from the iter. - */ - gtk_tree_model_get (GTK_TREE_MODEL (view->model), &iter, - 0, &widget, -1); - if (widget != NULL && - event->button == 3) - { - glade_popup_clipboard_pop (widget, event); - handled = TRUE; - } - gtk_tree_path_free (path); - } - } - return handled; -} - -static void -glade_clipboard_view_create_tree_view (GladeClipboardView *view) -{ - GtkTreeSelection *sel; - GtkCellRenderer *renderer; - GtkTreeViewColumn *column; - - view->widget = - gtk_tree_view_new_with_model (GTK_TREE_MODEL (view->model)); - - column = gtk_tree_view_column_new (); - gtk_tree_view_column_set_title (column, _("Widget")); - - renderer = gtk_cell_renderer_pixbuf_new (); - gtk_tree_view_column_pack_start (column, renderer, FALSE); - gtk_tree_view_column_set_cell_data_func (column, renderer, - glade_clipboard_view_cell_function, - GINT_TO_POINTER (1), NULL); - - renderer = gtk_cell_renderer_text_new (); - g_object_set (G_OBJECT (renderer), - "xpad", 6, NULL); - gtk_tree_view_column_pack_start (column, renderer, TRUE); - gtk_tree_view_column_set_cell_data_func (column, renderer, - glade_clipboard_view_cell_function, - GINT_TO_POINTER (0), NULL); - - gtk_tree_view_append_column (GTK_TREE_VIEW (view->widget), column); - - sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (view->widget)); - gtk_tree_selection_set_mode (sel, GTK_SELECTION_MULTIPLE); - - g_signal_connect_data (G_OBJECT (sel), "changed", - G_CALLBACK (glade_clipboard_view_selection_changed_cb), - view, NULL, 0); - - /* Popup menu */ - g_signal_connect (G_OBJECT (view->widget), "button-press-event", - G_CALLBACK (glade_clipboard_view_button_press_cb), view); - -} - -static void -glade_clipboard_view_construct (GladeClipboardView *view) -{ - GtkWidget *scrolled_window, *viewport; - - view->model = gtk_list_store_new (1, G_TYPE_POINTER); - - glade_clipboard_view_populate_model (view); - glade_clipboard_view_create_tree_view (view); - glade_clipboard_view_refresh_sel (view); - - viewport = gtk_viewport_new (NULL, NULL); - gtk_viewport_set_shadow_type (GTK_VIEWPORT (viewport), GTK_SHADOW_OUT); - - scrolled_window = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_shadow_type - (GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_IN); - gtk_container_set_border_width (GTK_CONTAINER (scrolled_window), - 6); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - gtk_container_add (GTK_CONTAINER (scrolled_window), view->widget); - gtk_container_add (GTK_CONTAINER (viewport), scrolled_window); - gtk_container_add (GTK_CONTAINER (view), viewport); - - gtk_window_set_default_size (GTK_WINDOW (view), - GLADE_CLIPBOARD_VIEW_WIDTH, - GLADE_CLIPBOARD_VIEW_HEIGHT); - - gtk_window_set_type_hint (GTK_WINDOW (view), GDK_WINDOW_TYPE_HINT_UTILITY); - - gtk_widget_show_all (scrolled_window); - - return; -} - -/** - * glade_clipboard_view_new: - * @clipboard: a #GladeClipboard - * - * Create a new #GladeClipboardView widget for @clipboard. - * - * Returns: a new #GladeClipboardView cast to be a #GtkWidget - */ -GtkWidget * -glade_clipboard_view_new (GladeClipboard *clipboard) -{ - GladeClipboardView *view; - - g_return_val_if_fail (GLADE_IS_CLIPBOARD (clipboard), NULL); - - view = gtk_type_new (glade_clipboard_view_get_type ()); - view->clipboard = clipboard; - glade_clipboard_view_construct (view); - - return GTK_WIDGET (view); -} - -/** - * glade_clipboard_view_add: - * @view: a #GladeClipboardView - * @widget: a #GladeWidget - * - * Adds @widget to @view. - */ -void -glade_clipboard_view_add (GladeClipboardView *view, GladeWidget *widget) -{ - GtkTreeIter iter; - - g_return_if_fail (GLADE_IS_CLIPBOARD_VIEW (view)); - g_return_if_fail (GLADE_IS_WIDGET (widget)); - - view->updating = TRUE; - gtk_list_store_append (view->model, &iter); - gtk_list_store_set (view->model, &iter, 0, widget, -1); - view->updating = FALSE; -} - -/** - * glade_cliboard_view_remove: - * @view: a #GladeClipboardView - * @widget: a #GladeWidget - * - * Removes @widget from @view. - */ -void -glade_clipboard_view_remove (GladeClipboardView *view, GladeWidget *widget) -{ - GtkTreeIter iter; - GtkTreeModel *model; - GladeWidget *clip_widget; - - g_return_if_fail (GLADE_IS_CLIPBOARD_VIEW (view)); - g_return_if_fail (GLADE_IS_WIDGET (widget)); - - model = GTK_TREE_MODEL (view->model); - if (gtk_tree_model_get_iter_first (model, &iter)) - { - do - { - gtk_tree_model_get (model, &iter, 0, &clip_widget, -1); - if (widget == clip_widget) - break; - } - while (gtk_tree_model_iter_next (model, &iter)); - } - - view->updating = TRUE; - gtk_list_store_remove (view->model, &iter); - view->updating = FALSE; -} - -/** - * glade_clipboard_view_refresh_sel: - * @view: a #GladeClipboardView - * - * Synchronizes the treeview selection to the clipboard selection. - */ -void -glade_clipboard_view_refresh_sel (GladeClipboardView *view) -{ - GladeWidget *widget; - GtkTreeSelection *sel; - GList *list; - GtkTreeIter *iter; - - g_return_if_fail (GLADE_IS_CLIPBOARD_VIEW (view)); - - if (view->updating) return; - view->updating = TRUE; - - sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (view->widget)); - - gtk_tree_selection_unselect_all (sel); - for (list = view->clipboard->selection; - list && list->data; list = list->next) - { - widget = list->data; - if ((iter = glade_util_find_iter_by_widget - (GTK_TREE_MODEL (view->model), widget, 0)) != NULL) - { - gtk_tree_selection_select_iter (sel, iter); - /* gtk_tree_iter_free (iter); */ - } - } - view->updating = FALSE; -} diff --git a/gladeui/glade-clipboard-view.h b/gladeui/glade-clipboard-view.h deleted file mode 100644 index 3498c155..00000000 --- a/gladeui/glade-clipboard-view.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef __GLADE_CLIPBOARD_VIEW_H__ -#define __GLADE_CLIPBOARD_VIEW_H__ - -#include <gladeui/glade.h> - -G_BEGIN_DECLS - -#define GLADE_TYPE_CLIPBOARD_VIEW (glade_clipboard_view_get_type ()) -#define GLADE_CLIPBOARD_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_CLIPBOARD_VIEW, GladeClipboardView)) -#define GLADE_CLIPBOARD_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_CLIPBOARD_VIEW, GladeClipboardViewClass)) -#define GLADE_IS_CLIPBOARD_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_CLIPBOARD_VIEW)) -#define GLADE_IS_CLIPBOARD_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_CLIPBOARD_VIEW)) -#define GLADE_CLIPBOARD_VIEW_GET_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((obj), GLADE_TYPE_CLIPBOARD_VIEW, GladeClipboardViewClass)) - -typedef struct _GladeClipboardView GladeClipboardView; -typedef struct _GladeClipboardViewClass GladeClipboardViewClass; - -struct _GladeClipboardView -{ - GtkWindow parent_instance; - - GtkWidget *widget; /* The GtkTreeView widget */ - GtkListStore *model; /* The GtkListStore model for the View */ - GladeClipboard *clipboard; /* The Clipboard for which this is a view */ - gboolean updating; /* Prevent feedback from treeview when changing - * the selecion. */ -}; - -struct _GladeClipboardViewClass -{ - GtkWindowClass parent_class; -}; - - - -GType glade_clipboard_view_get_type (void) G_GNUC_CONST; - - -GtkWidget *glade_clipboard_view_new (GladeClipboard *clipboard); - -void glade_clipboard_view_add (GladeClipboardView *view, - GladeWidget *widget); - -void glade_clipboard_view_remove (GladeClipboardView *view, - GladeWidget *widget); - -void glade_clipboard_view_refresh_sel (GladeClipboardView *view); - -G_END_DECLS - -#endif /* __GLADE_CLIPBOARD_VIEW_H__ */ diff --git a/gladeui/glade-clipboard.c b/gladeui/glade-clipboard.c deleted file mode 100644 index 67b4c7e2..00000000 --- a/gladeui/glade-clipboard.c +++ /dev/null @@ -1,272 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * glade-clipboard.c - An object for handling Cut/Copy/Paste. - * - * Copyright (C) 2001 The GNOME Foundation. - * - * Author(s): - * Archit Baweja <bighead@users.sourceforge.net> - * - * 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. - */ - -#include "config.h" - -#include <glib/gi18n-lib.h> -#include "glade.h" -#include "glade-clipboard-view.h" -#include "glade-clipboard.h" -#include "glade-widget.h" -#include "glade-placeholder.h" -#include "glade-project.h" - -enum -{ - PROP_0, - PROP_HAS_SELECTION -}; - -static void -glade_project_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - GladeClipboard *clipboard = GLADE_CLIPBOARD (object); - - switch (prop_id) - { - case PROP_HAS_SELECTION: - g_value_set_boolean (value, clipboard->has_selection); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -glade_clipboard_class_init (GladeClipboardClass *klass) -{ - GObjectClass *object_class; - - object_class = G_OBJECT_CLASS (klass); - - object_class->get_property = glade_project_get_property; - - g_object_class_install_property (object_class, - PROP_HAS_SELECTION, - g_param_spec_boolean ("has-selection", - "Has Selection", - "Whether clipboard has a selection of items to paste", - FALSE, - G_PARAM_READABLE)); -} - -static void -glade_clipboard_init (GladeClipboard *clipboard) -{ - clipboard->widgets = NULL; - clipboard->view = NULL; - clipboard->selection = NULL; - clipboard->has_selection = FALSE; -} - -GType -glade_clipboard_get_type (void) -{ - static GType type = 0; - - if (!type) { - static const GTypeInfo info = { - sizeof (GladeClipboardClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) glade_clipboard_class_init, - (GClassFinalizeFunc) NULL, - NULL, - sizeof (GladeClipboard), - 0, - (GInstanceInitFunc) glade_clipboard_init - }; - - type = g_type_register_static (G_TYPE_OBJECT, - "GladeClipboard", &info, 0); - } - - return type; -} - -static void -glade_clipboard_set_has_selection (GladeClipboard *clipboard, gboolean has_selection) -{ - g_assert (GLADE_IS_CLIPBOARD (clipboard)); - - if (clipboard->has_selection != has_selection) - { - clipboard->has_selection = has_selection; - g_object_notify (G_OBJECT (clipboard), "has-selection"); - } - -} - -/** - * glade_clipboard_get_has_selection: - * @clipboard: a #GladeClipboard - * - * Returns: TRUE if this clipboard has selected items to paste. - */ -gboolean -glade_clipboard_get_has_selection (GladeClipboard *clipboard) -{ - g_assert (GLADE_IS_CLIPBOARD (clipboard)); - - return clipboard->has_selection; -} - - -/** - * glade_clipboard_new: - * - * Returns: a new #GladeClipboard object - */ -GladeClipboard * -glade_clipboard_new (void) -{ - return GLADE_CLIPBOARD (g_object_new (GLADE_TYPE_CLIPBOARD, NULL)); -} - -/** - * glade_clipboard_add: - * @clipboard: a #GladeClipboard - * @widgets: a #GList of #GladeWidgets - * - * Adds @widgets to @clipboard. - * This increases the reference count of each #GladeWidget in @widgets. - */ -void -glade_clipboard_add (GladeClipboard *clipboard, GList *widgets) -{ - GladeWidget *widget; - GList *list; - - /* - * Clear selection for the new widgets. - */ - glade_clipboard_selection_clear (clipboard); - - /* - * Add the widgets to the list of children. - */ - for (list = widgets; list && list->data; list = list->next) - { - widget = list->data; - clipboard->widgets = - g_list_prepend (clipboard->widgets, - g_object_ref (G_OBJECT (widget))); - /* - * Update view. - */ - glade_clipboard_selection_add (clipboard, widget); - if (clipboard->view) - { - glade_clipboard_view_add - (GLADE_CLIPBOARD_VIEW (clipboard->view), widget); - glade_clipboard_view_refresh_sel - (GLADE_CLIPBOARD_VIEW (clipboard->view)); - } - } - -} - -/** - * glade_clipboard_remove: - * @clipboard: a #GladeClipboard - * @widgets: a #GList of #GladeWidgets - * - * Removes @widgets from @clipboard. - */ -void -glade_clipboard_remove (GladeClipboard *clipboard, GList *widgets) -{ - GladeWidget *widget; - GList *list; - - for (list = widgets; list && list->data; list = list->next) - { - widget = list->data; - - clipboard->widgets = - g_list_remove (clipboard->widgets, widget); - glade_clipboard_selection_remove (clipboard, widget); - - /* - * If there is a view present, update it. - */ - if (clipboard->view) - glade_clipboard_view_remove - (GLADE_CLIPBOARD_VIEW (clipboard->view), widget); - - g_object_unref (G_OBJECT (widget)); - } - - /* - * Only default selection if nescisary - */ - if ((g_list_length (clipboard->selection) < 1) && - (list = g_list_first (clipboard->widgets)) != NULL) - { - glade_clipboard_selection_add - (clipboard, GLADE_WIDGET (list->data)); - glade_clipboard_view_refresh_sel - (GLADE_CLIPBOARD_VIEW (clipboard->view)); - } -} - -void -glade_clipboard_selection_add (GladeClipboard *clipboard, - GladeWidget *widget) -{ - g_return_if_fail (GLADE_IS_CLIPBOARD (clipboard)); - g_return_if_fail (GLADE_IS_WIDGET (widget)); - clipboard->selection = - g_list_prepend (clipboard->selection, widget); - - glade_clipboard_set_has_selection (clipboard, TRUE); -} - -void -glade_clipboard_selection_remove (GladeClipboard *clipboard, - GladeWidget *widget) -{ - g_return_if_fail (GLADE_IS_CLIPBOARD (clipboard)); - g_return_if_fail (GLADE_IS_WIDGET (widget)); - clipboard->selection = - g_list_remove (clipboard->selection, widget); - - if (g_list_length (clipboard->selection) == 0) - glade_clipboard_set_has_selection (clipboard, FALSE); -} - -void -glade_clipboard_selection_clear (GladeClipboard *clipboard) -{ - g_return_if_fail (GLADE_IS_CLIPBOARD (clipboard)); - clipboard->selection = - (g_list_free (clipboard->selection), NULL); - - glade_clipboard_set_has_selection (clipboard, FALSE); -} diff --git a/gladeui/glade-clipboard.h b/gladeui/glade-clipboard.h deleted file mode 100644 index f6ae5cc4..00000000 --- a/gladeui/glade-clipboard.h +++ /dev/null @@ -1,56 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef __GLADE_CLIPBOARD_H__ -#define __GLADE_CLIPBOARD_H__ - -#include <gladeui/glade.h> - -G_BEGIN_DECLS - -#define GLADE_TYPE_CLIPBOARD (glade_clipboard_get_type ()) -#define GLADE_CLIPBOARD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_CLIPBOARD, GladeClipboard)) -#define GLADE_IS_CLIPBOARD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_CLIPBOARD)) - -typedef struct _GladeClipboard GladeClipboard; -typedef struct _GladeClipboardClass GladeClipboardClass; - -struct _GladeClipboard -{ - GObject parent_instance; - - GList *widgets; /* A list of GladeWidget's on the clipboard */ - GList *selection; /* Selection list of GladeWidget's */ - gboolean has_selection; /* TRUE if clipboard has selection */ - GtkWidget *view; /* see glade-clipboard-view.c */ -}; - -struct _GladeClipboardClass -{ - GObjectClass parent_class; -}; - - - -GType glade_clipboard_get_type (void); - -GladeClipboard *glade_clipboard_new (void); - -void glade_clipboard_add (GladeClipboard *clipboard, - GList *widgets); - -void glade_clipboard_remove (GladeClipboard *clipboard, - GList *widgets); - -void glade_clipboard_selection_add (GladeClipboard *clipboard, - GladeWidget *widget); - -void glade_clipboard_selection_remove (GladeClipboard *clipboard, - GladeWidget *widget); - -void glade_clipboard_selection_clear (GladeClipboard *clipboard); - -gboolean glade_clipboard_get_has_selection (GladeClipboard *clipboard); - - -G_END_DECLS - -#endif /* __GLADE_CLIPBOARD_H__ */ diff --git a/gladeui/glade-command.c b/gladeui/glade-command.c deleted file mode 100644 index a0a7e9f7..00000000 --- a/gladeui/glade-command.c +++ /dev/null @@ -1,2045 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2002 JoaquÃn Cuenca Abela - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Authors: - * JoaquÃn Cuenca Abela <e98cuenc@yahoo.com> - * Archit Baweja <bighead@users.sourceforge.net> - */ -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <gtk/gtk.h> -#include <string.h> -#include <glib/gi18n-lib.h> -#include "glade.h" -#include "glade-project.h" -#include "glade-xml-utils.h" -#include "glade-widget.h" -#include "glade-palette.h" -#include "glade-command.h" -#include "glade-property.h" -#include "glade-property-class.h" -#include "glade-debug.h" -#include "glade-placeholder.h" -#include "glade-clipboard.h" -#include "glade-signal.h" -#include "glade-app.h" -#include "glade-fixed.h" - -/* Concerning placeholders: we do not hold any reference to placeholders, - * placeholders that are supplied by the backend are not reffed, placeholders - * that are created by glade-command are temporarily owned by glade-command - * untill they are added to a container; in which case it belongs to GTK+ - * and the backend (but I prefer to think of it as the backend). - */ -typedef struct { - GladeWidget *widget; - GladeWidget *parent; - GladeProject *project; - GladePlaceholder *placeholder; - gboolean props_recorded; - GList *pack_props; - gchar *special_type; - gulong handler_id; -} CommandData; - -static GObjectClass *parent_class = NULL; - -/* Group description used for the current group - */ -static gchar *gc_group_description = NULL; - -/* Use an id to avoid grouping together consecutive groups - */ -static gint gc_group_id = 1; - -/* Groups can be grouped together, push/pop must balance (duh!) - */ -static gint gc_group_depth = 0; - - -#define MAKE_TYPE(func, type, parent) \ -GType \ -func ## _get_type (void) \ -{ \ - static GType cmd_type = 0; \ - \ - if (!cmd_type) \ - { \ - static const GTypeInfo info = \ - { \ - sizeof (type ## Class), \ - (GBaseInitFunc) NULL, \ - (GBaseFinalizeFunc) NULL, \ - (GClassInitFunc) func ## _class_init, \ - (GClassFinalizeFunc) NULL, \ - NULL, \ - sizeof (type), \ - 0, \ - (GInstanceInitFunc) NULL \ - }; \ - \ - cmd_type = g_type_register_static (parent, #type, &info, 0); \ - } \ - \ - return cmd_type; \ -} \ - -static void -glade_command_finalize (GObject *obj) -{ - GladeCommand *cmd = (GladeCommand *) obj; - g_return_if_fail (cmd != NULL); - - if (cmd->description) - g_free (cmd->description); - - /* Call the base class dtor */ - (* G_OBJECT_CLASS (parent_class)->finalize) (obj); -} - -static gboolean -glade_command_unifies_impl (GladeCommand *this_cmd, GladeCommand *other_cmd) -{ - return FALSE; -} - -static void -glade_command_collapse_impl (GladeCommand *this_cmd, GladeCommand *other_cmd) -{ - g_return_if_reached (); -} - -static void -glade_command_class_init (GladeCommandClass *klass) -{ - GObjectClass* object_class; - - object_class = G_OBJECT_CLASS (klass); - parent_class = g_type_class_peek_parent (klass); - - object_class->finalize = glade_command_finalize; - - klass->undo = NULL; - klass->execute = NULL; - klass->unifies = glade_command_unifies_impl; - klass->collapse = glade_command_collapse_impl; -} - -/* compose the _get_type function for GladeCommand */ -MAKE_TYPE (glade_command, GladeCommand, G_TYPE_OBJECT) - - -#define GLADE_MAKE_COMMAND(type, func) \ -static gboolean \ -func ## _undo (GladeCommand *me); \ -static gboolean \ -func ## _execute (GladeCommand *me); \ -static void \ -func ## _finalize (GObject *object); \ -static gboolean \ -func ## _unifies (GladeCommand *this_cmd, GladeCommand *other_cmd); \ -static void \ -func ## _collapse (GladeCommand *this_cmd, GladeCommand *other_cmd); \ -static void \ -func ## _class_init (gpointer parent_tmp, gpointer notused) \ -{ \ - GladeCommandClass *parent = parent_tmp; \ - GObjectClass* object_class; \ - object_class = G_OBJECT_CLASS (parent); \ - parent->undo = func ## _undo; \ - parent->execute = func ## _execute; \ - parent->unifies = func ## _unifies; \ - parent->collapse = func ## _collapse; \ - object_class->finalize = func ## _finalize; \ -} \ -typedef struct { \ - GladeCommandClass cmd; \ -} type ## Class; \ -static MAKE_TYPE(func, type, GLADE_TYPE_COMMAND) - - -/** - * glade_command_execute: - * @command: A #GladeCommand - * - * Executes @command - * - * Returns: whether the command was successfully executed - */ -gboolean -glade_command_execute (GladeCommand *command) -{ - g_return_val_if_fail (GLADE_IS_COMMAND (command), FALSE); - return GLADE_COMMAND_GET_CLASS (command)->execute (command); -} - - -/** - * glade_command_undo: - * @command: A #GladeCommand - * - * Undo the effects of @command - * - * Returns whether the command was successfully reversed - */ -gboolean -glade_command_undo (GladeCommand *command) -{ - g_return_val_if_fail (GLADE_IS_COMMAND (command), FALSE); - return GLADE_COMMAND_GET_CLASS (command)->undo (command); -} - -/** - * glade_command_unifies: - * @command: A #GladeCommand - * @other: another #GladeCommand - * - * Checks whether @command and @other can be unified - * to make one single command. - * - * Returns: whether they can be unified. - */ -gboolean -glade_command_unifies (GladeCommand *command, - GladeCommand *other) -{ - g_return_val_if_fail (command, FALSE); - return GLADE_COMMAND_GET_CLASS (command)->unifies (command, other); -} - -/** - * glade_command_collapse: - * @command: A #GladeCommand - * @other: another #GladeCommand - * - * Merges @other into @command, so that @command now - * covers both commands and @other can be dispensed with. - */ -void -glade_command_collapse (GladeCommand *command, - GladeCommand *other) -{ - g_return_if_fail (command); - GLADE_COMMAND_GET_CLASS (command)->collapse (command, other); -} - -/** - * glade_command_push_group: - * @fmt: The collective desctiption of the command group. - * only the description of the first group on the - * stack is used when embedding groups. - * @...: args to the format string. - * - * Marks the begining of a group. - */ -void -glade_command_push_group (const gchar *fmt, ...) -{ - va_list args; - - g_return_if_fail (fmt); - - /* Only use the description for the first group. - */ - if (gc_group_depth++ == 0) - { - va_start (args, fmt); - gc_group_description = g_strdup_vprintf (fmt, args); - va_end (args); - } -} - -/** - * glade_command_pop_group: - * - * Mark the end of a command group. - */ -void -glade_command_pop_group (void) -{ - if (gc_group_depth-- == 1) - { - gc_group_description = (g_free (gc_group_description), NULL); - gc_group_id++; - } - - if (gc_group_depth < 0) - g_critical ("Unbalanced group stack detected in %s\n", - G_GNUC_PRETTY_FUNCTION); -} - -static void -glade_command_check_group (GladeCommand *cmd) -{ - g_return_if_fail (GLADE_IS_COMMAND (cmd)); - if (gc_group_description) - { - cmd->description = - (g_free (cmd->description), g_strdup (gc_group_description)); - cmd->group_id = gc_group_id; - } -} - -/**************************************************/ -/******* GLADE_COMMAND_SET_PROPERTY *******/ -/**************************************************/ - -/* create a new GladeCommandSetProperty class. Objects of this class will - * encapsulate a "set property" operation */ - -typedef struct { - GladeCommand parent; - gboolean set_once; - gboolean undo; - GList *sdata; -} GladeCommandSetProperty; - -/* standard macros */ -GLADE_MAKE_COMMAND (GladeCommandSetProperty, glade_command_set_property); -#define GLADE_COMMAND_SET_PROPERTY_TYPE (glade_command_set_property_get_type ()) -#define GLADE_COMMAND_SET_PROPERTY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GLADE_COMMAND_SET_PROPERTY_TYPE, GladeCommandSetProperty)) -#define GLADE_COMMAND_SET_PROPERTY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GLADE_COMMAND_SET_PROPERTY_TYPE, GladeCommandSetPropertyClass)) -#define GLADE_IS_COMMAND_SET_PROPERTY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GLADE_COMMAND_SET_PROPERTY_TYPE)) -#define GLADE_IS_COMMAND_SET_PROPERTY_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GLADE_COMMAND_SET_PROPERTY_TYPE)) - -/* Undo the last "set property command" */ -static gboolean -glade_command_set_property_undo (GladeCommand *cmd) -{ - return glade_command_set_property_execute (cmd); -} - -/* - * Execute the set property command and revert it. IE, after the execution of - * this function cmd will point to the undo action - */ -static gboolean -glade_command_set_property_execute (GladeCommand *cmd) -{ - GladeCommandSetProperty* me = (GladeCommandSetProperty*) cmd; - GList *l; - - g_return_val_if_fail (me != NULL, FALSE); - - if (me->set_once != FALSE) - glade_property_push_superuser (); - - for (l = me->sdata; l; l = l->next) - { - GValue new_value = { 0, }; - GCSetPropData *sdata = l->data; - - g_value_init (&new_value, G_VALUE_TYPE (sdata->new_value)); - - if (me->undo) - g_value_copy (sdata->old_value, &new_value); - else - g_value_copy (sdata->new_value, &new_value); - -#if 0 - { - gchar *str = - glade_property_class_make_string_from_gvalue - (sdata->property->klass, &new_value); - - g_print ("Setting %s property of %s to %s (sumode: %d)\n", - sdata->property->klass->id, - sdata->property->widget->name, - str, glade_property_superuser ()); - - g_free (str); - } -#endif - - /* Packing properties need to be refreshed here since - * they are reset when they get added to containers. - */ - if (sdata->property->klass->packing) - { - GladeProperty *tmp_prop; - - tmp_prop = glade_widget_get_pack_property - (sdata->property->widget, sdata->property->klass->id); - - if (sdata->property != tmp_prop) - { - g_object_unref (sdata->property); - sdata->property = g_object_ref (tmp_prop); - - } - } - - glade_property_set_value (sdata->property, &new_value); - - if (!me->set_once) - { - /* If some verify functions didnt pass on - * the first go.. we need to record the actual - * properties here. - */ - g_value_copy (sdata->property->value, - sdata->new_value); - } - - - g_value_unset (&new_value); - - - } - - if (me->set_once != FALSE) - glade_property_pop_superuser (); - - me->set_once = TRUE; - me->undo = !me->undo; - - return TRUE; -} - -static void -glade_command_set_property_finalize (GObject *obj) -{ - GladeCommandSetProperty *me; - GList *l; - - me = GLADE_COMMAND_SET_PROPERTY (obj); - - for (l = me->sdata; l; l = l->next) - { - GCSetPropData *sdata = l->data; - - if (sdata->property) - g_object_unref (G_OBJECT (sdata->property)); - - if (sdata->old_value) - { - if (G_VALUE_TYPE (sdata->old_value) != 0) - g_value_unset (sdata->old_value); - g_free (sdata->old_value); - } - if (G_VALUE_TYPE (sdata->new_value) != 0) - g_value_unset (sdata->new_value); - g_free (sdata->new_value); - - } - glade_command_finalize (obj); -} - -static gboolean -glade_command_set_property_unifies (GladeCommand *this_cmd, GladeCommand *other_cmd) -{ - GladeCommandSetProperty *cmd1, *cmd2; - GCSetPropData *pdata1, *pdata2; - GList *list, *l; - - if (GLADE_IS_COMMAND_SET_PROPERTY (this_cmd) && - GLADE_IS_COMMAND_SET_PROPERTY (other_cmd)) - { - cmd1 = (GladeCommandSetProperty*) this_cmd; - cmd2 = (GladeCommandSetProperty*) other_cmd; - - if (g_list_length (cmd1->sdata) != - g_list_length (cmd2->sdata)) - return FALSE; - - for (list = cmd1->sdata; list; list = list->next) - { - pdata1 = list->data; - for (l = cmd2->sdata; l; l = l->next) - { - pdata2 = l->data; - - if (pdata1->property->widget == pdata2->property->widget && - glade_property_class_match (pdata1->property->klass, - pdata2->property->klass)) - break; - } - - /* If both lists are the same length, and one class type - * is not found in the other list, then we cant unify. - */ - if (l == NULL) - return FALSE; - - } - - return TRUE; - } - return FALSE; -} - -static void -glade_command_set_property_collapse (GladeCommand *this_cmd, GladeCommand *other_cmd) -{ - GladeCommandSetProperty *cmd1, *cmd2; - GCSetPropData *pdata1, *pdata2; - GList *list, *l; - - g_return_if_fail (GLADE_IS_COMMAND_SET_PROPERTY (this_cmd) && - GLADE_IS_COMMAND_SET_PROPERTY (other_cmd)); - - cmd1 = (GladeCommandSetProperty*) this_cmd; - cmd2 = (GladeCommandSetProperty*) other_cmd; - - - for (list = cmd1->sdata; list; list = list->next) - { - pdata1 = list->data; - for (l = cmd2->sdata; l; l = l->next) - { - pdata2 = l->data; - - if (glade_property_class_match (pdata1->property->klass, - pdata2->property->klass)) - { - /* Merge the GCSetPropData structs manually here - */ - g_value_copy (pdata2->new_value, pdata1->new_value); - break; - } - } - } - - /* Set the description - */ - g_free (this_cmd->description); - this_cmd->description = other_cmd->description; - other_cmd->description = NULL; - - glade_app_update_ui (); -} - - -#define MAX_UNDO_MENU_ITEM_VALUE_LEN 10 -static gchar * -glade_command_set_property_description (GladeCommandSetProperty *me) -{ - GCSetPropData *sdata; - gchar *description = NULL; - gchar *value_name; - - g_assert (me->sdata); - - if (g_list_length (me->sdata) > 1) - description = g_strdup_printf (_("Setting multiple properties")); - else - { - sdata = me->sdata->data; - value_name = glade_property_class_make_string_from_gvalue (sdata->property->klass, - sdata->new_value); - if (!value_name || strlen (value_name) > MAX_UNDO_MENU_ITEM_VALUE_LEN - || strchr (value_name, '_')) { - description = g_strdup_printf (_("Setting %s of %s"), - sdata->property->klass->name, - sdata->property->widget->name); - } else { - description = g_strdup_printf (_("Setting %s of %s to %s"), - sdata->property->klass->name, - sdata->property->widget->name, value_name); - } - g_free (value_name); - } - - return description; -} - - -void -glade_command_set_properties_list (GladeProject *project, GList *props) -{ - GladeCommandSetProperty *me; - GladeCommand *cmd; - GCSetPropData *sdata; - GList *list; - - g_return_if_fail (GLADE_IS_PROJECT (project)); - g_return_if_fail (props); - - me = (GladeCommandSetProperty*) g_object_new (GLADE_COMMAND_SET_PROPERTY_TYPE, NULL); - cmd = GLADE_COMMAND (me); - - /* Ref all props */ - for (list = props; list; list = list->next) - { - sdata = list->data; - g_object_ref (G_OBJECT (sdata->property)); - } - - me->sdata = props; - cmd->description = glade_command_set_property_description (me); - - glade_command_check_group (GLADE_COMMAND (me)); - - /* Push onto undo stack only if it executes successfully. */ - if (glade_command_set_property_execute (GLADE_COMMAND (me))) - glade_project_push_undo (GLADE_PROJECT (project), - GLADE_COMMAND (me)); - else - /* No leaks on my shift! */ - g_object_unref (G_OBJECT (me)); -} - - -void -glade_command_set_properties (GladeProperty *property, const GValue *old_value, const GValue *new_value, ...) -{ - GCSetPropData *sdata; - GladeProperty *prop; - GValue *ovalue, *nvalue; - GList *list = NULL; - va_list vl; - - g_return_if_fail (GLADE_IS_PROPERTY (property)); - - /* Add first set */ - sdata = g_new (GCSetPropData, 1); - sdata->property = property; - sdata->old_value = g_new0 (GValue, 1); - sdata->new_value = g_new0 (GValue, 1); - g_value_init (sdata->old_value, G_VALUE_TYPE (old_value)); - g_value_init (sdata->new_value, G_VALUE_TYPE (new_value)); - g_value_copy (old_value, sdata->old_value); - g_value_copy (new_value, sdata->new_value); - list = g_list_prepend (list, sdata); - - va_start (vl, new_value); - while ((prop = va_arg (vl, GladeProperty *)) != NULL) - { - ovalue = va_arg (vl, GValue *); - nvalue = va_arg (vl, GValue *); - - g_assert (GLADE_IS_PROPERTY (prop)); - g_assert (G_IS_VALUE (ovalue)); - g_assert (G_IS_VALUE (nvalue)); - - sdata = g_new (GCSetPropData, 1); - sdata->property = g_object_ref (G_OBJECT (prop)); - sdata->old_value = g_new0 (GValue, 1); - sdata->new_value = g_new0 (GValue, 1); - g_value_init (sdata->old_value, G_VALUE_TYPE (ovalue)); - g_value_init (sdata->new_value, G_VALUE_TYPE (nvalue)); - g_value_copy (ovalue, sdata->old_value); - g_value_copy (nvalue, sdata->new_value); - list = g_list_prepend (list, sdata); - } - va_end (vl); - - glade_command_set_properties_list (property->widget->project, list); -} - -void -glade_command_set_property_value (GladeProperty *property, const GValue* pvalue) -{ - - /* Dont generate undo/redo items for unchanging property values. - */ - if (glade_property_equals_value (property, pvalue)) - return; - - glade_command_set_properties (property, property->value, pvalue, NULL); -} - -void -glade_command_set_property (GladeProperty *property, ...) -{ - GValue *value; - va_list args; - - g_return_if_fail (GLADE_IS_PROPERTY (property)); - - va_start (args, property); - value = glade_property_class_make_gvalue_from_vl (property->klass, args); - va_end (args); - - glade_command_set_property_value (property, value); -} - -/**************************************************/ -/******* GLADE_COMMAND_SET_NAME *******/ -/**************************************************/ - -/* create a new GladeCommandSetName class. Objects of this class will - * encapsulate a "set name" operation */ -typedef struct { - GladeCommand parent; - - GladeWidget *widget; - gchar *old_name; - gchar *name; -} GladeCommandSetName; - -/* standard macros */ -GLADE_MAKE_COMMAND (GladeCommandSetName, glade_command_set_name); -#define GLADE_COMMAND_SET_NAME_TYPE (glade_command_set_name_get_type ()) -#define GLADE_COMMAND_SET_NAME(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GLADE_COMMAND_SET_NAME_TYPE, GladeCommandSetName)) -#define GLADE_COMMAND_SET_NAME_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GLADE_COMMAND_SET_NAME_TYPE, GladeCommandSetNameClass)) -#define GLADE_IS_COMMAND_SET_NAME(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GLADE_COMMAND_SET_NAME_TYPE)) -#define GLADE_IS_COMMAND_SET_NAME_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GLADE_COMMAND_SET_NAME_TYPE)) - -/* Undo the last "set name command" */ -static gboolean -glade_command_set_name_undo (GladeCommand *cmd) -{ - return glade_command_set_name_execute (cmd); -} - -/* - * Execute the set name command and revert it. Ie, after the execution of this - * function cmd will point to the undo action - */ -static gboolean -glade_command_set_name_execute (GladeCommand *cmd) -{ - GladeCommandSetName* me = GLADE_COMMAND_SET_NAME (cmd); - char* tmp; - - g_return_val_if_fail (me != NULL, TRUE); - g_return_val_if_fail (me->widget != NULL, TRUE); - g_return_val_if_fail (me->name != NULL, TRUE); - - glade_widget_set_name (me->widget, me->name); - - tmp = me->old_name; - me->old_name = me->name; - me->name = tmp; - - return TRUE; -} - -static void -glade_command_set_name_finalize (GObject *obj) -{ - GladeCommandSetName* me; - - g_return_if_fail (GLADE_IS_COMMAND_SET_NAME (obj)); - - me = GLADE_COMMAND_SET_NAME (obj); - - g_free (me->old_name); - g_free (me->name); - - glade_command_finalize (obj); -} - -static gboolean -glade_command_set_name_unifies (GladeCommand *this_cmd, GladeCommand *other_cmd) -{ - GladeCommandSetName *cmd1; - GladeCommandSetName *cmd2; - - if (GLADE_IS_COMMAND_SET_NAME (this_cmd) && GLADE_IS_COMMAND_SET_NAME (other_cmd)) - { - cmd1 = GLADE_COMMAND_SET_NAME (this_cmd); - cmd2 = GLADE_COMMAND_SET_NAME (other_cmd); - - return (cmd1->widget == cmd2->widget); - } - - return FALSE; -} - -static void -glade_command_set_name_collapse (GladeCommand *this_cmd, GladeCommand *other_cmd) -{ - GladeCommandSetName *nthis = GLADE_COMMAND_SET_NAME (this_cmd); - GladeCommandSetName *nother = GLADE_COMMAND_SET_NAME (other_cmd); - - g_return_if_fail (GLADE_IS_COMMAND_SET_NAME (this_cmd) && GLADE_IS_COMMAND_SET_NAME (other_cmd)); - - g_free (nthis->old_name); - nthis->old_name = nother->old_name; - nother->old_name = NULL; - - g_free (this_cmd->description); - this_cmd->description = g_strdup_printf (_("Renaming %s to %s"), nthis->name, nthis->old_name); - - glade_app_update_ui (); -} - -/* this function takes the ownership of name */ -void -glade_command_set_name (GladeWidget *widget, const gchar* name) -{ - GladeCommandSetName *me; - GladeCommand *cmd; - - g_return_if_fail (GLADE_IS_WIDGET (widget)); - g_return_if_fail (name != NULL); - - /* Dont spam the queue with false name changes. - */ - if (!strcmp (widget->name, name)) - return; - - me = g_object_new (GLADE_COMMAND_SET_NAME_TYPE, NULL); - cmd = GLADE_COMMAND (me); - - me->widget = widget; - me->name = g_strdup (name); - me->old_name = g_strdup (widget->name); - - cmd->description = g_strdup_printf (_("Renaming %s to %s"), me->old_name, me->name); - - glade_command_check_group (GLADE_COMMAND (me)); - - if (glade_command_set_name_execute (GLADE_COMMAND (me))) - glade_project_push_undo (GLADE_PROJECT (widget->project), GLADE_COMMAND (me)); - else - g_object_unref (G_OBJECT (me)); -} - -/****************************************************************************** - * - * add/remove - * - * These canonical commands add/remove a widget list to/from the project. - * - *****************************************************************************/ - -typedef struct { - GladeCommand parent; - GladeProject *project; - GList *widgets; - gboolean add; - gboolean from_clipboard; -} GladeCommandAddRemove; - - -GLADE_MAKE_COMMAND (GladeCommandAddRemove, glade_command_add_remove); -#define GLADE_COMMAND_ADD_REMOVE_TYPE (glade_command_add_remove_get_type ()) -#define GLADE_COMMAND_ADD_REMOVE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GLADE_COMMAND_ADD_REMOVE_TYPE, GladeCommandAddRemove)) -#define GLADE_COMMAND_ADD_REMOVE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GLADE_COMMAND_ADD_REMOVE_TYPE, GladeCommandAddRemoveClass)) -#define GLADE_IS_COMMAND_ADD_REMOVE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GLADE_COMMAND_ADD_REMOVE_TYPE)) -#define GLADE_IS_COMMAND_ADD_REMOVE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GLADE_COMMAND_ADD_REMOVE_TYPE)) - -static void -glade_command_placeholder_destroyed (GtkObject *object, CommandData *cdata) -{ - if (GTK_OBJECT (cdata->placeholder) == object) - { - cdata->placeholder = NULL; - cdata->handler_id = 0; - } -} - -static void -glade_command_placeholder_connect (CommandData *cdata, - GladePlaceholder *placeholder) -{ - g_assert (cdata && cdata->placeholder == NULL); - - /* Something like a no-op with no placeholder */ - if ((cdata->placeholder = placeholder) == NULL) - return; - - cdata->handler_id = g_signal_connect - (placeholder, "destroy", - G_CALLBACK (glade_command_placeholder_destroyed), cdata); -} - -/** - * glade_command_add: - * @widgets: a #Glist - * @parent: a #GladeWidget - * @placeholder: a #GladePlaceholder - * @pasting: whether we are pasting an existing widget or creating a new one. - * - * Performs an add command on all widgets in @widgets to @parent, possibly - * replacing @placeholder (note toplevels dont need a parent; the active project - * will be used when pasting toplevel objects). - * Pasted widgets will persist packing properties from thier cut/copy source - * while newly added widgets will prefer packing defaults. - * - */ -static void -glade_command_add (GList *widgets, - GladeWidget *parent, - GladePlaceholder *placeholder, - gboolean pasting) -{ - GladeCommandAddRemove *me; - CommandData *cdata; - GladeWidget *widget = NULL; - GList *l, *list, *children, *placeholders = NULL; - GtkWidget *child; - - g_return_if_fail (widgets && widgets->data); - g_return_if_fail (parent == NULL || GLADE_IS_WIDGET (parent)); - - me = g_object_new (GLADE_COMMAND_ADD_REMOVE_TYPE, NULL); - me->add = TRUE; - me->from_clipboard = pasting; - - /* Things can go wrong in this function if the dataset is inacurate, - * we make no real attempt here to recover, just g_critical() and - * fix the bugs as they pop up. - */ - widget = GLADE_WIDGET (widgets->data); - if (placeholder && GTK_IS_WINDOW (widget->object) == FALSE) - { - GladeWidget *some_widget = glade_placeholder_get_parent (placeholder); - me->project = glade_widget_get_project (some_widget); - } - else me->project = glade_app_get_project(); - - GLADE_COMMAND (me)->description = - g_strdup_printf (_("Add %s"), g_list_length (widgets) == 1 ? - widget->name : _("multiple")); - - for (list = widgets; list && list->data; list = list->next) - { - widget = list->data; - cdata = g_new0 (CommandData, 1); - if (widget->internal) - g_critical ("Internal widget in Add"); - - /* Widget */ - cdata->widget = g_object_ref (G_OBJECT (widget)); - - /* Parent */ - if (parent == NULL) - cdata->parent = glade_widget_get_parent (widget); - else if (placeholder && GTK_IS_WINDOW (widget->object) == FALSE) - cdata->parent = glade_placeholder_get_parent (placeholder); - else if (GTK_IS_WINDOW (widget->object) == FALSE) - cdata->parent = parent; - if (cdata->parent == NULL && GTK_IS_WINDOW (widget->object) == FALSE) - g_critical ("Parentless non GtkWindow widget in Add"); - - /* Placeholder */ - if (placeholder != NULL && g_list_length (widgets) == 1) - { - glade_command_placeholder_connect (cdata, placeholder); - } - else if (cdata->parent && - glade_widget_placeholder_relation (cdata->parent, widget)) - { - GtkContainer *cont = GTK_CONTAINER (cdata->parent->object); - - child = glade_util_get_placeholder_from_pointer (cont); - if (child && g_list_find (placeholders, child) == NULL) - { - placeholders = g_list_append (placeholders, child); - glade_command_placeholder_connect - (cdata, GLADE_PLACEHOLDER (child)); - } - else if ((children = glade_widget_adaptor_get_children - (cdata->parent->adaptor, cdata->parent->object)) != NULL) - { - for (l = children; l && l->data; l = l->next) - { - child = l->data; - - /* Find a placeholder for this child */ - if (GLADE_IS_PLACEHOLDER (child) && - g_list_find (placeholders, child) == NULL) - { - placeholders = g_list_append (placeholders, child); - glade_command_placeholder_connect - (cdata, GLADE_PLACEHOLDER (child)); - break; - } - } - g_list_free (children); - } - } - - /* - * Save a copy of the original project so we can forward that to glade-project, - * who'll copy in any resource files needed by any properties that are getting - * cross-project pasted. - */ - cdata->project = cdata->widget->project; - - me->widgets = g_list_prepend (me->widgets, cdata); - } - - glade_command_check_group (GLADE_COMMAND (me)); - - /* - * Push it onto the undo stack only on success - */ - if (glade_command_add_remove_execute (GLADE_COMMAND (me))) - glade_project_push_undo (glade_app_get_project(), GLADE_COMMAND (me)); - else - g_object_unref (G_OBJECT (me)); - - if (placeholders) - g_list_free (placeholders); - -} /* end of glade_command_add() */ - -/** - * glade_command_remove: - * @widgets: a #GList of #GladeWidgets - * - * Performs a remove command on all widgets in @widgets from @parent. - */ -static void -glade_command_remove (GList *widgets) -{ - GladeCommandAddRemove *me; - GladeWidget *widget = NULL; - CommandData *cdata; - GList *list, *l; - - g_return_if_fail (widgets != NULL); - - me = g_object_new (GLADE_COMMAND_ADD_REMOVE_TYPE, NULL); - me->add = FALSE; - me->from_clipboard = FALSE; - - /* internal children cannot be deleted. Notify the user. */ - for (list = widgets; list && list->data; list = list->next) - { - widget = list->data; - if (widget->internal) - { - glade_util_ui_message (glade_app_get_window(), - GLADE_UI_WARN, - _("You cannot remove a widget internal to a composite widget.")); - return; - } - } - - me->project = glade_widget_get_project (widget); - - for (list = widgets; list && list->data; list = list->next) - { - widget = list->data; - - cdata = g_new0 (CommandData, 1); - cdata->widget = g_object_ref (G_OBJECT (widget)); - cdata->parent = glade_widget_get_parent (widget); - cdata->project = glade_widget_get_project (widget); - - if (widget->internal) - g_critical ("Internal widget in Remove"); - - if (cdata->parent != NULL && - glade_widget_placeholder_relation - (cdata->parent, cdata->widget)) - { - glade_command_placeholder_connect - (cdata, GLADE_PLACEHOLDER (glade_placeholder_new ())); - } - me->widgets = g_list_prepend (me->widgets, cdata); - - /* Dont record props in create_execute (whether or not we actually - * record any props here - */ - cdata->props_recorded = TRUE; - - /* Record packing props if not deleted from the clipboard */ - if (me->from_clipboard == FALSE) - { - for (l = widget->packing_properties; l; l = l->next) - cdata->pack_props = - g_list_prepend (cdata->pack_props, - glade_property_dup (GLADE_PROPERTY (l->data), - cdata->widget)); - } - } - - if (g_list_length (widgets) == 1) - GLADE_COMMAND (me)->description = - g_strdup_printf (_("Remove %s"), - GLADE_WIDGET (widgets->data)->name); - else - GLADE_COMMAND (me)->description = - g_strdup_printf (_("Remove multiple")); - - g_assert (widget); - - glade_command_check_group (GLADE_COMMAND (me)); - - if (glade_command_add_remove_execute (GLADE_COMMAND (me))) - glade_project_push_undo (GLADE_PROJECT (widget->project), GLADE_COMMAND (me)); - else - g_object_unref (G_OBJECT (me)); - -} /* end of glade_command_remove() */ - -static void -glade_command_transfer_props (GladeWidget *gnew, GList *saved_props) -{ - GList *l; - - for (l = saved_props; l; l = l->next) - { - GladeProperty *prop, *sprop = l->data; - - prop = glade_widget_get_pack_property (gnew, sprop->klass->id); - - if (prop && sprop->klass->transfer_on_paste && - glade_property_class_match (prop->klass, sprop->klass)) - glade_property_set_value (prop, sprop->value); - } -} - -static gboolean -glade_command_add_execute (GladeCommandAddRemove *me) -{ - GladeProject *active_project = glade_app_get_project (); - CommandData *cdata; - GList *list, *l, *saved_props; - gchar *special_child_type; - - if (me->widgets) - { - /* XXX FIXME: Selection here should be specific to the project - * related to this command - */ - glade_app_selection_clear (FALSE); - - for (list = me->widgets; list && list->data; list = list->next) - { - cdata = list->data; - saved_props = NULL; - - if (cdata->parent != NULL) - { - /* Prepare special-child-type for the paste. */ - if (me->from_clipboard) - { - if (cdata->props_recorded == FALSE) - { - /* Clear it the first time */ - g_object_set_data (cdata->widget->object, - "special-child-type", NULL); - } - else - { - g_object_set_data_full (cdata->widget->object, - "special-child-type", - g_strdup (cdata->special_type), - g_free); - } - } - - /* Only transfer properties when they are from the clipboard, - * otherwise prioritize packing defaults. - */ - if (me->from_clipboard) - { - saved_props = - glade_widget_dup_properties (cdata->widget->packing_properties, FALSE); - - glade_widget_set_packing_properties (cdata->widget, cdata->parent); - } - - /* glade_command_paste ganauntees that if - * there we are pasting to a placeholder, - * there is only one widget. - */ - if (cdata->placeholder) - { - glade_widget_replace - (cdata->parent, - G_OBJECT (cdata->placeholder), - cdata->widget->object); - } - else - { - glade_widget_add_child (cdata->parent, - cdata->widget, - cdata->props_recorded == FALSE); - } - - - glade_command_transfer_props (cdata->widget, saved_props); - - if (saved_props) - { - g_list_foreach (saved_props, (GFunc)g_object_unref, NULL); - g_list_free (saved_props); - } - - /* Now that we've added, apply any packing props if nescisary. */ - for (l = cdata->pack_props; l; l = l->next) - { - GValue value = { 0, }; - GladeProperty *saved_prop = l->data; - GladeProperty *widget_prop = - glade_widget_get_pack_property (cdata->widget, - saved_prop->klass->id); - - glade_property_get_value (saved_prop, &value); - glade_property_set_value (widget_prop, &value); - g_value_unset (&value); - } - - if (cdata->props_recorded == FALSE) - { - /* Save the packing properties after the initial paste. - * (this will be the defaults returned by the container - * implementation after initially adding them). - * - * Otherwise this recorded marker was set when cutting - */ - g_assert (cdata->pack_props == NULL); - for (l = cdata->widget->packing_properties; - l; l = l->next) - cdata->pack_props = - g_list_prepend - (cdata->pack_props, - glade_property_dup - (GLADE_PROPERTY (l->data), - cdata->widget)); - - - /* Record the special-type here after replacing */ - if ((special_child_type = - g_object_get_data (cdata->widget->object, - "special-child-type")) != NULL) - { - g_free (cdata->special_type); - cdata->special_type = g_strdup (special_child_type); - } - - /* Mark the properties as recorded */ - cdata->props_recorded = TRUE; - } - - - } - - /* Toplevels get pasted to the active project */ - if (me->from_clipboard && - GTK_WIDGET_TOPLEVEL (cdata->widget->object)) - glade_project_add_object - (active_project, cdata->project, - cdata->widget->object); - else - glade_project_add_object(me->project, cdata->project, cdata->widget->object); - - glade_app_selection_add(cdata->widget->object, FALSE); - - glade_widget_show (cdata->widget); - } - glade_app_selection_changed (); - } - return TRUE; - -} /* end of glade_command_add_execute() */ - -static gboolean -glade_command_remove_execute (GladeCommandAddRemove *me) -{ - CommandData *cdata; - GList *list; - - for (list = me->widgets; list && list->data; list = list->next) - { - cdata = list->data; - - if (cdata->parent) - { - if (cdata->placeholder) - glade_widget_replace(cdata->parent, cdata->widget->object, G_OBJECT (cdata->placeholder)); - else - glade_widget_remove_child (cdata->parent, cdata->widget); - } - - glade_project_remove_object(GLADE_PROJECT (cdata->widget->project), cdata->widget->object); - - glade_widget_hide (cdata->widget); - } - - return TRUE; -} - -/* - * Execute the cmd and revert it. Ie, after the execution of this - * function cmd will point to the undo action - */ -static gboolean -glade_command_add_remove_execute (GladeCommand *cmd) -{ - GladeCommandAddRemove *me = (GladeCommandAddRemove*) cmd; - gboolean retval; - - if (me->add) - retval = glade_command_add_execute (me); - else - retval = glade_command_remove_execute (me); - - me->add = !me->add; - - return retval; -} - -static gboolean -glade_command_add_remove_undo (GladeCommand *cmd) -{ - return glade_command_add_remove_execute (cmd); -} - -static void -glade_command_add_remove_finalize (GObject *obj) -{ - GladeCommandAddRemove *cmd; - CommandData *cdata; - GList *list; - - g_return_if_fail (GLADE_IS_COMMAND_ADD_REMOVE (obj)); - - cmd = GLADE_COMMAND_ADD_REMOVE (obj); - - for (list = cmd->widgets; list && list->data; list = list->next) - { - cdata = list->data; - - if (cdata->placeholder) - { - if (cdata->handler_id) - g_signal_handler_disconnect (cdata->placeholder, - cdata->handler_id); - if (GTK_OBJECT_FLOATING (cdata->placeholder)) - gtk_widget_destroy (GTK_WIDGET (cdata->placeholder)); - } - - if (cdata->widget) - g_object_unref (G_OBJECT (cdata->widget)); - } - g_list_free (cmd->widgets); - - glade_command_finalize (obj); -} - -static gboolean -glade_command_add_remove_unifies (GladeCommand *this_cmd, GladeCommand *other_cmd) -{ - return FALSE; -} - -static void -glade_command_add_remove_collapse (GladeCommand *this_cmd, GladeCommand *other_cmd) -{ - g_return_if_reached (); -} - -/****************************************************************************** - * - * clipboard_add/clipboard_remove - * - * These canonical commands add/remove a widget list to/from the clipboard. - * - *****************************************************************************/ - -typedef struct { - GladeCommand parent; - GList *widgets; - gboolean add; -} GladeCommandClipboardAddRemove; - - -GLADE_MAKE_COMMAND (GladeCommandClipboardAddRemove, glade_command_clipboard_add_remove); -#define GLADE_COMMAND_CLIPBOARD_ADD_REMOVE_TYPE (glade_command_clipboard_add_remove_get_type ()) -#define GLADE_COMMAND_CLIPBOARD_ADD_REMOVE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GLADE_COMMAND_CLIPBOARD_ADD_REMOVE_TYPE, GladeCommandClipboardAddRemove)) -#define GLADE_COMMAND_CLIPBOARD_ADD_REMOVE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GLADE_COMMAND_CLIPBOARD_ADD_REMOVE_TYPE, GladeCommandClipboardAddRemoveClass)) -#define GLADE_IS_COMMAND_CLIPBOARD_ADD_REMOVE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GLADE_COMMAND_CLIPBOARD_ADD_REMOVE_TYPE)) -#define GLADE_IS_COMMAND_CLIPBOARD_ADD_REMOVE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GLADE_COMMAND_CLIPBOARD_ADD_REMOVE_TYPE)) - -static void -glade_command_clipboard_add_remove_common (GList *widgets, gboolean add) -{ - GladeCommandClipboardAddRemove *me; - GladeWidget *widget = NULL; - GList *list; - - g_return_if_fail(widgets && widgets->data); - - me = g_object_new(GLADE_COMMAND_CLIPBOARD_ADD_REMOVE_TYPE, NULL); - for (list = widgets; list && list->data; list = list->next) - { - widget = g_object_ref(G_OBJECT(list->data)); - me->widgets = g_list_prepend (me->widgets, widget); - } - me->add = add; - if (add) - { - if (g_list_length (widgets) == 1) - GLADE_COMMAND(me)->description = g_strdup_printf (_("Clipboard add %s"), - widget->name); - else - GLADE_COMMAND(me)->description = g_strdup (_("Clipboard add multiple")); - } - else - { - if (g_list_length (widgets) == 1) - GLADE_COMMAND(me)->description = g_strdup_printf (_("Clipboard remove %s"), - widget->name); - else - GLADE_COMMAND(me)->description = g_strdup (_("Clipboard remove multiple")); - } - - glade_command_check_group(GLADE_COMMAND(me)); - - if (glade_command_clipboard_add_remove_execute(GLADE_COMMAND(me))) - { - glade_project_push_undo(glade_app_get_project(), GLADE_COMMAND(me)); - } - else - { - g_object_unref(G_OBJECT(me)); - } -} - -/** - * glade_command_clipboard_add: - * @widgets: a #GList - * - * Performs an add command on all widgets in @widgets to the clipboard. - */ -static void -glade_command_clipboard_add(GList *widgets) -{ - glade_command_clipboard_add_remove_common(widgets, TRUE); -} - -/** - * glade_command_clipboard_remove: - * @widgets: a #GList - * - * Performs a remove command on all widgets in @widgets from the clipboard. - */ - -/* not used anywhere */ - -#if 0 -static void -glade_command_clipboard_remove (GList *widgets) -{ - glade_command_clipboard_add_remove_common(widgets, FALSE); -} -#endif - -static gboolean -glade_command_clipboard_add_execute (GladeCommandClipboardAddRemove *me) -{ - GList *list, *widgets = NULL; - - for (list = me->widgets; list && list->data; list = list->next) - { - widgets = g_list_prepend(widgets, list->data); - } - if (widgets) - { - glade_clipboard_add(glade_app_get_clipboard(), widgets); - g_list_free(widgets); - } - - return TRUE; -} - -static gboolean -glade_command_clipboard_remove_execute (GladeCommandClipboardAddRemove *me) -{ - GList *list, *widgets = NULL; - - for (list = me->widgets; list && list->data; list = list->next) - { - widgets = g_list_prepend(widgets, list->data); - } - if (widgets) - { - glade_clipboard_remove(glade_app_get_clipboard(), widgets); - g_list_free(widgets); - } - - return TRUE; -} - -static gboolean -glade_command_clipboard_add_remove_execute (GladeCommand *cmd) -{ - GladeCommandClipboardAddRemove *me = (GladeCommandClipboardAddRemove*) cmd; - gboolean retval; - - if (me->add) - retval = glade_command_clipboard_add_execute (me); - else - retval = glade_command_clipboard_remove_execute (me); - - me->add = !me->add; - - return retval; -} - -static gboolean -glade_command_clipboard_add_remove_undo (GladeCommand *cmd) -{ - return glade_command_clipboard_add_remove_execute (cmd); -} - -static void -glade_command_clipboard_add_remove_finalize (GObject *obj) -{ - GladeCommandClipboardAddRemove *cmd; - GList *list; - - g_return_if_fail (GLADE_IS_COMMAND_CLIPBOARD_ADD_REMOVE (obj)); - - cmd = GLADE_COMMAND_CLIPBOARD_ADD_REMOVE (obj); - - for (list = cmd->widgets; list && list->data; list = list->next) - if (list->data) - g_object_unref(G_OBJECT(list->data)); - g_list_free (cmd->widgets); - - glade_command_finalize (obj); -} - -static gboolean -glade_command_clipboard_add_remove_unifies (GladeCommand *this_cmd, GladeCommand *other_cmd) -{ - return FALSE; -} - -static void -glade_command_clipboard_add_remove_collapse (GladeCommand *this_cmd, GladeCommand *other_cmd) -{ - g_return_if_reached (); -} - -/****************************************************************************** - * - * The following are command aliases. Their implementations are the actual - * glade commands. - * - *****************************************************************************/ - -/** - * glade_command_create: - * @adaptor: A #GladeWidgetAdaptor - * @placeholder: the placeholder which will be substituted by the widget - * @project: the project his widget belongs to. - * - * Creates a new widget using @adaptor and put in place of the @placeholder - * in the @project - * - * Returns the newly created widget. - */ -GladeWidget* -glade_command_create(GladeWidgetAdaptor *adaptor, GladeWidget *parent, GladePlaceholder *placeholder, GladeProject *project) -{ - GladeWidget *widget; - GList *widgets = NULL; - gchar *description; - - g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL); - g_return_val_if_fail (GLADE_IS_PROJECT (project), NULL); - if (GWA_IS_TOPLEVEL(adaptor) == FALSE) - g_return_val_if_fail (GLADE_IS_WIDGET(parent), NULL); - - /* attempt to create the widget -- widget may be null, e.g. the user clicked cancel on a query */ - widget = glade_widget_adaptor_create_widget(adaptor, TRUE, "parent", parent, "project", project, NULL); - if (widget == NULL) - { - return NULL; - } - widgets = g_list_prepend(widgets, widget); - description = g_strdup_printf (_("Create %s"), g_list_length (widgets) == 1 ? widget->name : _("multiple")); - glade_command_push_group(description); - glade_command_add(widgets, parent, placeholder, FALSE); - glade_command_pop_group(); - - if (widgets) - g_list_free(widgets); - - return widget; -} - -/** - * glade_command_delete: - * @widgets: a #GList of #GladeWidgets - * - * Performs a delete command on the list of widgets. - */ -void -glade_command_delete(GList *widgets) -{ - GladeWidget *widget; - gchar *description; - - g_return_if_fail (widgets != NULL); - - widget = widgets->data; - description = g_strdup_printf (_("Delete %s"), g_list_length (widgets) == 1 ? widget->name : _("multiple")); - glade_command_push_group(description); - glade_command_remove(widgets); - glade_command_pop_group(); -} - -/** - * glade_command_cut: - * @widgets: a #GList of #GladeWidgets - * - * Removes the list of widgets and adds them to the clipboard. - */ -void -glade_command_cut(GList *widgets) -{ - GladeWidget *widget; - GList *l; - gchar *description; - - g_return_if_fail (widgets != NULL); - - for (l = widgets; l; l = l->next) - g_object_set_data (G_OBJECT (l->data), "glade-command-was-cut", GINT_TO_POINTER (TRUE)); - - widget = widgets->data; - description = g_strdup_printf (_("Cut %s"), g_list_length (widgets) == 1 ? widget->name : _("multiple")); - glade_command_push_group(description); - glade_command_remove(widgets); - glade_command_clipboard_add(widgets); - glade_command_pop_group(); -} - -/** - * glade_command_copy: - * @widgets: a #GList of #GladeWidgets - * - * Copies the list of widgets and adds them to the clipboard. - */ -void -glade_command_copy(GList *widgets) -{ - GList *list, *copied_widgets = NULL; - GladeWidget *copied_widget = NULL; - gchar *description; - - g_return_if_fail (widgets != NULL); - - for (list = widgets; list && list->data; list = list->next) - { - copied_widget = glade_widget_dup(list->data, FALSE); - copied_widgets = g_list_prepend(copied_widgets, copied_widget); - } - description = g_strdup_printf (_("Copy %s"), g_list_length (widgets) == 1 ? copied_widget->name : _("multiple")); - glade_command_push_group(description); - glade_command_clipboard_add(copied_widgets); - glade_command_pop_group(); - - if (copied_widgets) - g_list_free(copied_widgets); -} - -/** - * glade_command_paste: - * @widgets: a #GList of #GladeWidget - * @parent: a #GladeWidget - * @placeholder: a #GladePlaceholder - * - * Performs a paste command on all widgets in @widgets to @parent, possibly - * replacing @placeholder (note toplevels dont need a parent; the active project - * will be used when pasting toplevel objects). - */ -void -glade_command_paste(GList *widgets, GladeWidget *parent, GladePlaceholder *placeholder) -{ - GList *list, *copied_widgets = NULL; - GladeWidget *copied_widget = NULL; - gchar *description; - gboolean exact; - - g_return_if_fail (widgets != NULL); - - for (list = widgets; list && list->data; list = list->next) - { - exact = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (list->data), "glade-command-was-cut")); - - copied_widget = glade_widget_dup(list->data, exact); - copied_widgets = g_list_prepend(copied_widgets, copied_widget); - } - description = g_strdup_printf (_("Paste %s"), g_list_length (widgets) == 1 ? copied_widget->name : _("multiple")); - glade_command_push_group(description); - glade_command_add(copied_widgets, parent, placeholder, TRUE); - glade_command_pop_group(); - - if (copied_widgets) - g_list_free(copied_widgets); -} - -/** - * glade_command_dnd: - * @widgets: a #GList of #GladeWidget - * @parent: a #GladeWidget - * @placeholder: a #GladePlaceholder - * - * Performs a drag-n-drop command, i.e. removes the list of widgets and adds them - * to the new parent, possibly replacing @placeholder (note toplevels dont need a - * parent; the active project will be used when pasting toplevel objects). - */ -void -glade_command_dnd(GList *widgets, GladeWidget *parent, GladePlaceholder *placeholder) -{ - GladeWidget *widget; - gchar *description; - - g_return_if_fail (widgets != NULL); - - widget = widgets->data; - description = g_strdup_printf (_("Drag-n-Drop from %s to %s"), parent->name, g_list_length (widgets) == 1 ? widget->name : _("multiple")); - glade_command_push_group(description); - glade_command_remove(widgets); - glade_command_add(widgets, parent, placeholder, TRUE); - glade_command_pop_group(); -} - -/*********************************************************/ -/******* GLADE_COMMAND_ADD_SIGNAL *******/ -/*********************************************************/ - -/* create a new GladeCommandAddRemoveChangeSignal class. Objects of this class will - * encapsulate an "add or remove signal handler" operation */ -typedef enum { - GLADE_ADD, - GLADE_REMOVE, - GLADE_CHANGE -} GladeAddType; - -typedef struct { - GladeCommand parent; - - GladeWidget *widget; - - GladeSignal *signal; - GladeSignal *new_signal; - - GladeAddType type; -} GladeCommandAddSignal; - -/* standard macros */ -GLADE_MAKE_COMMAND (GladeCommandAddSignal, glade_command_add_signal); -#define GLADE_COMMAND_ADD_SIGNAL_TYPE (glade_command_add_signal_get_type ()) -#define GLADE_COMMAND_ADD_SIGNAL(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GLADE_COMMAND_ADD_SIGNAL_TYPE, GladeCommandAddSignal)) -#define GLADE_COMMAND_ADD_SIGNAL_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GLADE_COMMAND_ADD_SIGNAL_TYPE, GladeCommandAddSignalClass)) -#define GLADE_IS_COMMAND_ADD_SIGNAL(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GLADE_COMMAND_ADD_SIGNAL_TYPE)) -#define GLADE_IS_COMMAND_ADD_SIGNAL_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GLADE_COMMAND_ADD_SIGNAL_TYPE)) - -static void -glade_command_add_signal_finalize (GObject *obj) -{ - GladeCommandAddSignal *cmd = GLADE_COMMAND_ADD_SIGNAL (obj); - - g_object_unref (cmd->widget); - - if (cmd->signal) - glade_signal_free (cmd->signal); - if (cmd->new_signal) - glade_signal_free (cmd->new_signal); - - glade_command_finalize (obj); -} - -static gboolean -glade_command_add_signal_undo (GladeCommand *this_cmd) -{ - return glade_command_add_signal_execute (this_cmd); -} - -static gboolean -glade_command_add_signal_execute (GladeCommand *this_cmd) -{ - GladeCommandAddSignal *cmd = GLADE_COMMAND_ADD_SIGNAL (this_cmd); - GladeSignal *temp; - - switch (cmd->type) - { - case GLADE_ADD: - glade_widget_add_signal_handler (cmd->widget, cmd->signal); - cmd->type = GLADE_REMOVE; - break; - case GLADE_REMOVE: - glade_widget_remove_signal_handler (cmd->widget, cmd->signal); - cmd->type = GLADE_ADD; - break; - case GLADE_CHANGE: - glade_widget_change_signal_handler (cmd->widget, - cmd->signal, - cmd->new_signal); - temp = cmd->signal; - cmd->signal = cmd->new_signal; - cmd->new_signal = temp; - break; - default: - break; - } - return TRUE; -} - -static gboolean -glade_command_add_signal_unifies (GladeCommand *this_cmd, GladeCommand *other_cmd) -{ - return FALSE; -} - -static void -glade_command_add_signal_collapse (GladeCommand *this_cmd, GladeCommand *other_cmd) -{ - g_return_if_reached (); -} - -static void -glade_command_add_remove_change_signal (GladeWidget *glade_widget, - const GladeSignal *signal, - const GladeSignal *new_signal, - GladeAddType type) -{ - GladeCommandAddSignal *me = GLADE_COMMAND_ADD_SIGNAL - (g_object_new (GLADE_COMMAND_ADD_SIGNAL_TYPE, NULL)); - GladeCommand *cmd = GLADE_COMMAND (me); - - /* we can only add/remove a signal to a widget that has been wrapped by a GladeWidget */ - g_assert (glade_widget != NULL); - g_assert (glade_widget->project != NULL); - - me->widget = g_object_ref(glade_widget); - me->type = type; - me->signal = glade_signal_clone (signal); - me->new_signal = new_signal ? - glade_signal_clone (new_signal) : NULL; - - cmd->description = - g_strdup_printf (type == GLADE_ADD ? _("Add signal handler %s") : - type == GLADE_REMOVE ? _("Remove signal handler %s") : - _("Change signal handler %s"), - signal->handler); - - glade_command_check_group (GLADE_COMMAND (me)); - - if (glade_command_add_signal_execute (cmd)) - glade_project_push_undo (GLADE_PROJECT (glade_widget->project), cmd); - else - g_object_unref (G_OBJECT (me)); -} - -/** - * glade_command_add_signal: - * @glade_widget: a #GladeWidget - * @signal: a #GladeSignal - * - * TODO: write me - */ -void -glade_command_add_signal (GladeWidget *glade_widget, const GladeSignal *signal) -{ - glade_command_add_remove_change_signal - (glade_widget, signal, NULL, GLADE_ADD); -} - -/** - * glade_command_remove_signal: - * @glade_widget: a #GladeWidget - * @signal: a #GladeSignal - * - * TODO: write me - */ -void -glade_command_remove_signal (GladeWidget *glade_widget, const GladeSignal *signal) -{ - glade_command_add_remove_change_signal - (glade_widget, signal, NULL, GLADE_REMOVE); -} - -/** - * glade_command_change_signal: - * @glade_widget: a #GladeWidget - * @old: a #GladeSignal - * @new: a #GladeSignal - * - * TODO: write me - */ -void -glade_command_change_signal (GladeWidget *glade_widget, - const GladeSignal *old, - const GladeSignal *new_signal) -{ - glade_command_add_remove_change_signal - (glade_widget, old, new_signal, GLADE_CHANGE); -} - -/****************************************************************************** - * - * set i18n metadata - * - * This command sets the i18n metadata on a label property. - * - *****************************************************************************/ - -typedef struct { - GladeCommand parent; - GladeProperty *property; - gboolean translatable; - gboolean has_context; - gchar *comment; - gboolean old_translatable; - gboolean old_has_context; - gchar *old_comment; -} GladeCommandSetI18n; - - -GLADE_MAKE_COMMAND (GladeCommandSetI18n, glade_command_set_i18n); -#define GLADE_COMMAND_SET_I18N_TYPE (glade_command_set_i18n_get_type ()) -#define GLADE_COMMAND_SET_I18N(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GLADE_COMMAND_SET_I18N_TYPE, GladeCommandSetI18n)) -#define GLADE_COMMAND_SET_I18N_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GLADE_COMMAND_SET_I18N_TYPE, GladeCommandSetI18nClass)) -#define GLADE_IS_COMMAND_SET_I18N(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GLADE_COMMAND_SET_I18N_TYPE)) -#define GLADE_IS_COMMAND_SET_I18N_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GLADE_COMMAND_SET_I18N_TYPE)) - -static gboolean -glade_command_set_i18n_execute(GladeCommand *cmd) -{ - GladeCommandSetI18n *me = (GladeCommandSetI18n *)cmd; - gboolean temp_translatable; - gboolean temp_has_context; - gchar *temp_comment; - - /* sanity check */ - g_return_val_if_fail (me != NULL, TRUE); - g_return_val_if_fail (me->property != NULL, TRUE); - - /* set the new values in the property */ - glade_property_i18n_set_translatable(me->property, me->translatable); - glade_property_i18n_set_has_context(me->property, me->has_context); - glade_property_i18n_set_comment(me->property, me->comment); - - /* swap the current values with the old values to prepare for undo */ - temp_translatable = me->translatable; - temp_has_context = me->has_context; - temp_comment = me->comment; - me->translatable = me->old_translatable; - me->has_context = me->old_has_context; - me->comment = me->old_comment; - me->old_translatable = temp_translatable; - me->old_has_context = temp_has_context; - me->old_comment = temp_comment; - - return TRUE; -} - -static gboolean -glade_command_set_i18n_undo(GladeCommand *cmd) -{ - return glade_command_set_i18n_execute(cmd); -} - -static void -glade_command_set_i18n_finalize(GObject *obj) -{ - GladeCommandSetI18n *me; - - g_return_if_fail(GLADE_IS_COMMAND_SET_I18N(obj)); - - me = GLADE_COMMAND_SET_I18N(obj); - g_free (me->comment); - g_free (me->old_comment); - - glade_command_finalize(obj); -} - -static gboolean -glade_command_set_i18n_unifies (GladeCommand *this_cmd, GladeCommand *other_cmd) -{ - GladeCommandSetI18n *cmd1; - GladeCommandSetI18n *cmd2; - - if (GLADE_IS_COMMAND_SET_I18N (this_cmd) && GLADE_IS_COMMAND_SET_I18N (other_cmd)) - { - cmd1 = GLADE_COMMAND_SET_I18N (this_cmd); - cmd2 = GLADE_COMMAND_SET_I18N (other_cmd); - - return (cmd1->property == cmd2->property); - } - - return FALSE; -} - -static void -glade_command_set_i18n_collapse (GladeCommand *this_cmd, GladeCommand *other_cmd) -{ - /* this command is the one that will be used for an undo of the sequence of like commands */ - GladeCommandSetI18n *this = GLADE_COMMAND_SET_I18N (this_cmd); - - /* the other command contains the values that will be used for a redo */ - GladeCommandSetI18n *other = GLADE_COMMAND_SET_I18N (other_cmd); - - g_return_if_fail (GLADE_IS_COMMAND_SET_I18N (this_cmd) && GLADE_IS_COMMAND_SET_I18N (other_cmd)); - - /* adjust this command to contain, as its old values, the other command's current values */ - this->old_translatable = other->old_translatable; - this->old_has_context = other->old_has_context; - g_free (this->old_comment); - this->old_comment = other->old_comment; - other->old_comment = NULL; - - glade_app_update_ui (); -} - -/** - * glade_command_set_i18n: - * @property: a #GladeProperty - * @translatable: a #gboolean - * @has_context: a #gboolean - * @comment: a #const gchar * - * - * Sets the i18n data on the property. - */ -void -glade_command_set_i18n (GladeProperty *property, gboolean translatable, gboolean has_context, const gchar *comment) -{ - GladeCommandSetI18n *me; - - g_return_if_fail(property); - - /* check that something changed before continuing with the command */ - if (translatable == property->i18n_translatable && - has_context == property->i18n_has_context && - ((comment == NULL && property->i18n_comment == NULL) || - (comment && property->i18n_comment && !strcmp(property->i18n_comment, comment)))) - return; - - /* load up the command */ - me = g_object_new(GLADE_COMMAND_SET_I18N_TYPE, NULL); - me->property = property; - me->translatable = translatable; - me->has_context = has_context; - me->comment = g_strdup(comment); - me->old_translatable = property->i18n_translatable; - me->old_has_context = property->i18n_has_context; - me->old_comment = g_strdup(property->i18n_comment); - GLADE_COMMAND(me)->description = g_strdup_printf(_("Setting i18n metadata"));; - - glade_command_check_group(GLADE_COMMAND(me)); - - /* execute the command and push it on the stack if successful */ - if (glade_command_set_i18n_execute(GLADE_COMMAND(me))) - { - glade_project_push_undo(glade_app_get_project(), GLADE_COMMAND(me)); - } - else - { - g_object_unref(G_OBJECT(me)); - } -} - - diff --git a/gladeui/glade-command.h b/gladeui/glade-command.h deleted file mode 100644 index f71dfdce..00000000 --- a/gladeui/glade-command.h +++ /dev/null @@ -1,142 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef __GLADE_COMMAND_H__ -#define __GLADE_COMMAND_H__ - -#include <gladeui/glade-placeholder.h> -#include <gladeui/glade-widget.h> -#include <gladeui/glade-signal.h> -#include <gladeui/glade-property.h> -#include <gladeui/glade-project.h> -#include <glib-object.h> - -G_BEGIN_DECLS - - -#define GLADE_TYPE_COMMAND (glade_command_get_type ()) -#define GLADE_COMMAND(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_COMMAND, GladeCommand)) -#define GLADE_COMMAND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_COMMAND, GladeCommandClass)) -#define GLADE_IS_COMMAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_COMMAND)) -#define GLADE_IS_COMMAND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_COMMAND)) -#define GLADE_COMMAND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GLADE_TYPE_COMMAND, GladeCommandClass)) - -typedef struct _GladeCommand GladeCommand; -typedef struct _GladeCommandClass GladeCommandClass; -typedef struct _GCSetPropData GCSetPropData; - -struct _GCSetPropData { - GladeProperty *property; - GValue *new_value; - GValue *old_value; -}; - -struct _GladeCommand -{ - GObject parent; - - gchar *description; /* a string describing the command. - * It's used in the undo/redo menu entry. - */ - - gint group_id; /* If this is part of a command group, this is - * the group id (id is needed only to ensure that - * consecutive groups dont get merged). - */ -}; - -struct _GladeCommandClass -{ - GObjectClass parent_class; - - gboolean (* execute) (GladeCommand *this_cmd); - gboolean (* undo) (GladeCommand *this_cmd); - gboolean (* unifies) (GladeCommand *this_cmd, GladeCommand *other_cmd); - void (* collapse) (GladeCommand *this_cmd, GladeCommand *other_cmd); -}; - - - -GType glade_command_get_type (void); - -void glade_command_push_group (const gchar *fmt, - ...); - -void glade_command_pop_group (void); - - -gboolean glade_command_execute (GladeCommand *command); - -gboolean glade_command_undo (GladeCommand *command); - -gboolean glade_command_unifies (GladeCommand *command, - GladeCommand *other); - -void glade_command_collapse (GladeCommand *command, - GladeCommand *other); - -/************************** properties *********************************/ - -void glade_command_set_property (GladeProperty *property, - ...); - -void glade_command_set_property_value (GladeProperty *property, - const GValue *value); - -void glade_command_set_properties (GladeProperty *property, - const GValue *old_value, - const GValue *new_value, - ...); - -void glade_command_set_properties_list (GladeProject *project, - GList *props); /* list of GCSetPropData */ - -/************************** name ******************************/ - -void glade_command_set_name (GladeWidget *glade_widget, const gchar *name); - - -/************************ create/delete ******************************/ - -void glade_command_delete (GList *widgets); - -GladeWidget *glade_command_create (GladeWidgetAdaptor *adaptor, - GladeWidget *parent, - GladePlaceholder *placeholder, - GladeProject *project); - -/************************ cut/copy/paste ******************************/ - -void glade_command_cut (GList *widgets); - -void glade_command_copy (GList *widgets); - -void glade_command_paste (GList *widgets, - GladeWidget *parent, - GladePlaceholder *placeholder); - -void glade_command_dnd (GList *widgets, - GladeWidget *parent, - GladePlaceholder *placeholder); - -/************************ signals ******************************/ - -void glade_command_add_signal (GladeWidget *glade_widget, - const GladeSignal *signal); - -void glade_command_remove_signal (GladeWidget *glade_widget, - const GladeSignal *signal); - -void glade_command_change_signal (GladeWidget *glade_widget, - const GladeSignal *old, - const GladeSignal *new_signal); - -/************************ set i18n ******************************/ - -void glade_command_set_i18n (GladeProperty *property, - gboolean translatable, - gboolean has_context, - const gchar *comment); - - -G_END_DECLS - -#endif /* __GLADE_COMMAND_H__ */ diff --git a/gladeui/glade-cursor.c b/gladeui/glade-cursor.c deleted file mode 100644 index 10ad910d..00000000 --- a/gladeui/glade-cursor.c +++ /dev/null @@ -1,200 +0,0 @@ -/* -*- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Authors: - * Chema Celorio <chema@celorio.com> - */ - -#include "config.h" - -#include "glade-app.h" -#include "glade-palette.h" -#include "glade-cursor.h" -#include "glade-widget-adaptor.h" - -#include <glib.h> -#include <glib/gi18n.h> - -#define ADD_PIXBUF_FILENAME "plus.png" - -static GladeCursor *cursor = NULL; - -static void -set_cursor_recurse (GtkWidget *widget, - GdkCursor *gdk_cursor) -{ - GList *children, *list; - - if (!GTK_WIDGET_VISIBLE (widget) || - !GTK_WIDGET_REALIZED (widget)) - return; - - gdk_window_set_cursor (widget->window, gdk_cursor); - - if (GTK_IS_CONTAINER (widget) && - (children = - glade_util_container_get_all_children (GTK_CONTAINER (widget))) != NULL) - { - for (list = children; list; list = list->next) - { - set_cursor_recurse (GTK_WIDGET (list->data), gdk_cursor); - } - g_list_free (children); - } -} - - -static void -set_cursor (GdkCursor *gdk_cursor) -{ - GladeProject *project; - GList *list, *projects; - - for (projects = glade_app_get_projects (); - projects; projects = projects->next) - { - project = projects->data; - - for (list = (GList *) glade_project_get_objects (project); - list; list = list->next) - { - GObject *object = list->data; - - if (GTK_IS_WINDOW (object)) - { - set_cursor_recurse (GTK_WIDGET (object), gdk_cursor); - } - } - } -} - -/** - * glade_cursor_set: - * @window: a #GdkWindow - * @type: a #GladeCursorType - * - * Sets the cursor for @window to something appropriate based on @type. - * (also sets the cursor on all visible project widgets) - */ -void -glade_cursor_set (GdkWindow *window, GladeCursorType type) -{ - GladeWidgetAdaptor *adaptor; - GdkCursor *the_cursor = NULL; - g_return_if_fail (cursor != NULL); - - switch (type) { - case GLADE_CURSOR_SELECTOR: - the_cursor = cursor->selector; - break; - case GLADE_CURSOR_ADD_WIDGET: - if ((adaptor = - glade_palette_get_current_item (glade_app_get_palette ())) != NULL) - { - g_object_get (adaptor, "cursor", &the_cursor, NULL); - - if (the_cursor == NULL) - the_cursor = cursor->add_widget; - - } - else - the_cursor = cursor->add_widget; - break; - case GLADE_CURSOR_RESIZE_TOP_LEFT: - the_cursor = cursor->resize_top_left; - break; - case GLADE_CURSOR_RESIZE_TOP_RIGHT: - the_cursor = cursor->resize_top_right; - break; - case GLADE_CURSOR_RESIZE_BOTTOM_LEFT: - the_cursor = cursor->resize_bottom_left; - break; - case GLADE_CURSOR_RESIZE_BOTTOM_RIGHT: - the_cursor = cursor->resize_bottom_right; - break; - case GLADE_CURSOR_RESIZE_LEFT: - the_cursor = cursor->resize_left; - break; - case GLADE_CURSOR_RESIZE_RIGHT: - the_cursor = cursor->resize_right; - break; - case GLADE_CURSOR_RESIZE_TOP: - the_cursor = cursor->resize_top; - break; - case GLADE_CURSOR_RESIZE_BOTTOM: - the_cursor = cursor->resize_bottom; - break; - case GLADE_CURSOR_DRAG: - the_cursor = cursor->drag; - break; - default: - break; - } - - set_cursor (cursor->selector); - gdk_window_set_cursor (window, the_cursor); -} - -/** - * glade_cursor_init: - * - * Initializes cursors for use with glade_cursor_set(). - */ -void -glade_cursor_init (void) -{ - gchar *path; - GError *error = NULL; - - cursor = g_new0 (GladeCursor, 1); - - cursor->selector = gdk_cursor_new (GDK_TOP_LEFT_ARROW); - cursor->add_widget = gdk_cursor_new (GDK_PLUS); - cursor->resize_top_left = gdk_cursor_new (GDK_TOP_LEFT_CORNER); - cursor->resize_top_right = gdk_cursor_new (GDK_TOP_RIGHT_CORNER); - cursor->resize_bottom_left = gdk_cursor_new (GDK_BOTTOM_LEFT_CORNER); - cursor->resize_bottom_right = gdk_cursor_new (GDK_BOTTOM_RIGHT_CORNER); - cursor->resize_left = gdk_cursor_new (GDK_LEFT_SIDE); - cursor->resize_right = gdk_cursor_new (GDK_RIGHT_SIDE); - cursor->resize_top = gdk_cursor_new (GDK_TOP_SIDE); - cursor->resize_bottom = gdk_cursor_new (GDK_BOTTOM_SIDE); - cursor->drag = gdk_cursor_new (GDK_FLEUR); - cursor->add_widget_pixbuf = NULL; - - /* load "add" cursor pixbuf */ - path = g_build_filename (glade_app_get_pixmaps_dir (), ADD_PIXBUF_FILENAME, NULL); - - cursor->add_widget_pixbuf = gdk_pixbuf_new_from_file (path, &error); - - if (cursor->add_widget_pixbuf == NULL) - { - g_critical (_("Unable to load image (%s)"), error->message); - - g_error_free (error); - error = NULL; - } - g_free (path); -} - -const GdkPixbuf* -glade_cursor_get_add_widget_pixbuf (void) -{ - g_return_val_if_fail (cursor != NULL, NULL); - - return cursor->add_widget_pixbuf; -} diff --git a/gladeui/glade-cursor.h b/gladeui/glade-cursor.h deleted file mode 100644 index b56cfba5..00000000 --- a/gladeui/glade-cursor.h +++ /dev/null @@ -1,55 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef __GLADE_CURSOR_H__ -#define __GLADE_CURSOR_H__ - -G_BEGIN_DECLS - -/* GladeCursor is just a structures that has a pointer to all the cursors - * that we are going to use. The benefit of this struct is that once - * glade_cursor_init is called you just need to call glade_cursor_set - * with it's enumed value to set the window cursor. - */ - -/* Has a pointer to the loaded GdkCursors. It is loaded when _init - * is called - */ -typedef struct _GladeCursor { - GdkCursor *selector; - GdkCursor *add_widget; /* fallback cursor if we cannot use widget_class->cursor */ - GdkCursor *resize_top_left; - GdkCursor *resize_top_right; - GdkCursor *resize_bottom_left; - GdkCursor *resize_bottom_right; - GdkCursor *resize_left; - GdkCursor *resize_right; - GdkCursor *resize_top; - GdkCursor *resize_bottom; - GdkCursor *drag; - - GdkPixbuf *add_widget_pixbuf; /* a pixbuf of the generic 'add' cursor */ -} GladeCursor; - -/* Enumed values for each of the cursors for GladeCursor. For every - * GdkCursor above there should be a enum here - */ -typedef enum { - GLADE_CURSOR_SELECTOR, - GLADE_CURSOR_ADD_WIDGET, - GLADE_CURSOR_RESIZE_TOP_LEFT, - GLADE_CURSOR_RESIZE_TOP_RIGHT, - GLADE_CURSOR_RESIZE_BOTTOM_LEFT, - GLADE_CURSOR_RESIZE_BOTTOM_RIGHT, - GLADE_CURSOR_RESIZE_LEFT, - GLADE_CURSOR_RESIZE_RIGHT, - GLADE_CURSOR_RESIZE_TOP, - GLADE_CURSOR_RESIZE_BOTTOM, - GLADE_CURSOR_DRAG -} GladeCursorType; - -void glade_cursor_init (void); -void glade_cursor_set (GdkWindow *window, GladeCursorType type); -const GdkPixbuf* glade_cursor_get_add_widget_pixbuf (void); - -G_END_DECLS - -#endif /* __GLADE_CURSOR_H__ */ diff --git a/gladeui/glade-custom.c b/gladeui/glade-custom.c deleted file mode 100644 index 069593b6..00000000 --- a/gladeui/glade-custom.c +++ /dev/null @@ -1,275 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * glade-custom.c - An emulation of a custom widget used to - * support the glade-2 style custom widget. - * - * Copyright (C) 2005 The GNOME Foundation. - * - * Author(s): - * Tristan Van Berkom <tvb@gnome.org> - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <glib/gi18n-lib.h> - -#include "glade-custom.h" - -enum -{ - PROP_0, - PROP_CREATION, - PROP_STR1, - PROP_STR2, - PROP_INT1, - PROP_INT2 -}; - -static GtkWidgetClass *parent_class = NULL; - -/* Ignore properties. - */ -static void -glade_custom_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ -} - -static void -glade_custom_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ -} - - -static void -glade_custom_finalize (GObject *object) -{ - GladeCustom *custom; - - g_return_if_fail (GLADE_IS_CUSTOM (object)); - custom = GLADE_CUSTOM (object); - - /* custom->custom_pixmap can be NULL if the custom - * widget is destroyed before it's realized */ - if (custom->custom_pixmap) - g_object_unref (custom->custom_pixmap); - - G_OBJECT_CLASS (parent_class)->finalize (object); -} - -static void -glade_custom_send_configure (GladeCustom *custom) -{ - GtkWidget *widget; - GdkEvent *event = gdk_event_new (GDK_CONFIGURE); - - widget = GTK_WIDGET (custom); - - event->configure.window = g_object_ref (widget->window); - event->configure.send_event = TRUE; - event->configure.x = widget->allocation.x; - event->configure.y = widget->allocation.y; - event->configure.width = widget->allocation.width; - event->configure.height = widget->allocation.height; - - gtk_widget_event (widget, event); - gdk_event_free (event); -} - -static void -glade_custom_realize (GtkWidget *widget) -{ - GladeCustom *custom; - GdkWindowAttr attributes; - gint attributes_mask; - - g_return_if_fail (GLADE_IS_CUSTOM (widget)); - - custom = GLADE_CUSTOM (widget); - - GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); - - attributes.window_type = GDK_WINDOW_CHILD; - attributes.x = widget->allocation.x; - attributes.y = widget->allocation.y; - attributes.width = widget->allocation.width; - attributes.height = widget->allocation.height; - attributes.wclass = GDK_INPUT_OUTPUT; - attributes.visual = gtk_widget_get_visual (widget); - attributes.colormap = gtk_widget_get_colormap (widget); - attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK; - - attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; - - widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), - &attributes, attributes_mask); - gdk_window_set_user_data (widget->window, custom); - - widget->style = gtk_style_attach (widget->style, widget->window); - - glade_custom_send_configure (custom); - - if (!custom->custom_pixmap) - { - custom->custom_pixmap = - gdk_pixmap_colormap_create_from_xpm_d - (NULL, gtk_widget_get_colormap (GTK_WIDGET (custom)), - NULL, NULL, custom_xpm); - - g_assert(G_IS_OBJECT(custom->custom_pixmap)); - } - gdk_window_set_back_pixmap (GTK_WIDGET (custom)->window, custom->custom_pixmap, FALSE); -} - -static void -glade_custom_size_allocate (GtkWidget *widget, GtkAllocation *allocation) -{ - g_return_if_fail (GLADE_IS_CUSTOM (widget)); - g_return_if_fail (allocation != NULL); - - widget->allocation = *allocation; - - if (GTK_WIDGET_REALIZED (widget)) - { - gdk_window_move_resize (widget->window, - allocation->x, allocation->y, - allocation->width, allocation->height); - - glade_custom_send_configure (GLADE_CUSTOM (widget)); - } -} - -static gboolean -glade_custom_expose (GtkWidget *widget, GdkEventExpose *event) -{ - GdkGC *light_gc; - GdkGC *dark_gc; - gint w, h; - - g_return_val_if_fail (GLADE_IS_CUSTOM (widget), FALSE); - - light_gc = widget->style->light_gc[GTK_STATE_NORMAL]; - dark_gc = widget->style->dark_gc[GTK_STATE_NORMAL]; - gdk_drawable_get_size (event->window, &w, &h); - - gdk_draw_line (event->window, light_gc, 0, 0, w - 1, 0); - gdk_draw_line (event->window, light_gc, 0, 0, 0, h - 1); - gdk_draw_line (event->window, dark_gc, 0, h - 1, w - 1, h - 1); - gdk_draw_line (event->window, dark_gc, w - 1, 0, w - 1, h - 1); - - /* glade_util_queue_draw_nodes (event->window); */ - return FALSE; -} - -static void -glade_custom_init (GladeCustom *custom) -{ - custom->custom_pixmap = NULL; - - gtk_widget_set_size_request (GTK_WIDGET (custom), - GLADE_CUSTOM_WIDTH_REQ, - GLADE_CUSTOM_HEIGHT_REQ); - - gtk_widget_show (GTK_WIDGET (custom)); -} - -static void -glade_custom_class_init (GladeCustomClass *klass) -{ - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - parent_class = g_type_class_peek_parent (klass); - - object_class->finalize = glade_custom_finalize; - object_class->set_property = glade_custom_set_property; - object_class->get_property = glade_custom_get_property; - - widget_class->realize = glade_custom_realize; - widget_class->size_allocate = glade_custom_size_allocate; - widget_class->expose_event = glade_custom_expose; - - g_object_class_install_property - (object_class, PROP_CREATION, - g_param_spec_string - ("creation-function", _("Creation Function"), - _("The function which creates this widget"), - NULL, G_PARAM_READWRITE)); - - g_object_class_install_property - (object_class, PROP_STR1, - g_param_spec_string - ("string1", _("String 1"), - _("The first string argument to pass to the function"), - NULL, G_PARAM_READWRITE)); - - g_object_class_install_property - (object_class, PROP_STR2, - g_param_spec_string - ("string2", _("String 2"), - _("The second string argument to pass to the function"), - NULL, G_PARAM_READWRITE)); - - g_object_class_install_property - (object_class, PROP_INT1, - g_param_spec_int - ("int1", _("Integer 1"), - _("The first integer argument to pass to the function"), - G_MININT, G_MAXINT, 0, G_PARAM_READWRITE)); - - g_object_class_install_property - (object_class, PROP_INT2, - g_param_spec_int - ("int2", _("Integer 2"), - _("The second integer argument to pass to the function"), - G_MININT, G_MAXINT, 0, G_PARAM_READWRITE)); -} - -GType -custom_get_type (void) -{ - static GType custom_type = 0; - - if (!custom_type) - { - static const GTypeInfo custom_info = - { - sizeof (GladeCustomClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) glade_custom_class_init, - (GClassFinalizeFunc) NULL, - NULL, /* class_data */ - sizeof (GladeCustom), - 0, /* n_preallocs */ - (GInstanceInitFunc) glade_custom_init, - }; - custom_type = - g_type_register_static (GTK_TYPE_WIDGET, - "Custom", - &custom_info, 0); - } - return custom_type; -} diff --git a/gladeui/glade-custom.h b/gladeui/glade-custom.h deleted file mode 100644 index c804627b..00000000 --- a/gladeui/glade-custom.h +++ /dev/null @@ -1,62 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef __GLADE_CUSTOM_H__ -#define __GLADE_CUSTOM_H__ - -#include <gladeui/glade.h> -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -#define GLADE_TYPE_CUSTOM (custom_get_type ()) -#define GLADE_CUSTOM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_CUSTOM, GladeCustom)) -#define GLADE_CUSTOM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_CUSTOM, GladeCustomClass)) -#define GLADE_IS_CUSTOM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_CUSTOM)) -#define GLADE_IS_CUSTOM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_CUSTOM)) -#define GLADE_CUSTOM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GLADE_TYPE_CUSTOM, GladeCustomClass)) - -#define GLADE_CUSTOM_WIDTH_REQ 20 -#define GLADE_CUSTOM_HEIGHT_REQ 20 - -/* taken from glade 2 */ -static char * custom_xpm[] = { -"8 8 4 1", -" c None", -". c #BBBBBB", -"+ c #D6D6D6", -"@ c #6B5EFF", -".+..+...", -"+..@@@..", -"..@...++", -"..@...++", -"+.@..+..", -".++@@@..", -"..++....", -"..++...."}; - - -typedef struct _GladeCustom GladeCustom; -typedef struct _GladeCustomClass GladeCustomClass; - -struct _GladeCustom -{ - GtkWidget widget; - - GdkPixmap *custom_pixmap; - - -}; - -struct _GladeCustomClass -{ - GtkWidgetClass parent_class; -}; - -/* Since the class is called Custom and not GladeCustom, - * glade-widget-class will search for custom_get_type() instead - * if glade_custom_get_type() - */ -GType custom_get_type (void) G_GNUC_CONST; - -G_END_DECLS - -#endif /* __GLADE_CUSTOM_H__ */ diff --git a/gladeui/glade-debug.c b/gladeui/glade-debug.c deleted file mode 100644 index 007eb945..00000000 --- a/gladeui/glade-debug.c +++ /dev/null @@ -1,71 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2003 Joaquin Cuenca Abela - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Authors: - * Joaquin Cuenca Abela <e98cuenc@yahoo.com> - */ - -#include "config.h" - -#include "glade.h" -#include "glade-debug.h" - -#ifdef G_OS_UNIX -#include <signal.h> -#endif - -#ifndef RETSIGTYPE -#define RETSIGTYPE void -#endif - - -static void -glade_log_handler (const char *domain, - GLogLevelFlags level, - const char *message, - gpointer data) -{ - static volatile int want_breakpoint = 0; - - g_log_default_handler (domain, level, message, data); - if (want_breakpoint && ((level & (G_LOG_LEVEL_CRITICAL /* | G_LOG_LEVEL_WARNING */)) != 0)) - G_BREAKPOINT (); -} - -static void -glade_set_log_handler (const char *domain) -{ - g_log_set_handler (domain, G_LOG_LEVEL_MASK, glade_log_handler, NULL); -} - -/** - * glade_setup_log_handlers: - * - * Sets up a log handler to manage all %G_LOG_LEVEL_MASK errors of domain: - * GLib, GLib-GObject, Gtk, Gdk, and domainless. - */ -void -glade_setup_log_handlers () -{ - glade_set_log_handler (""); - glade_set_log_handler ("GLib"); - glade_set_log_handler ("GLib-GObject"); - glade_set_log_handler ("Gtk"); - glade_set_log_handler ("Gdk"); -} - diff --git a/gladeui/glade-debug.h b/gladeui/glade-debug.h deleted file mode 100644 index cde6d9c6..00000000 --- a/gladeui/glade-debug.h +++ /dev/null @@ -1,11 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef __GLADE_DEBUG_H__ -#define __GLADE_DEBUG_H__ - -G_BEGIN_DECLS - -void glade_setup_log_handlers (void); - -G_END_DECLS - -#endif /* __GLADE_DEBUG_H__ */ diff --git a/gladeui/glade-design-layout.c b/gladeui/glade-design-layout.c deleted file mode 100644 index 500bc2c2..00000000 --- a/gladeui/glade-design-layout.c +++ /dev/null @@ -1,928 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * glade-design-layout.c - * - * Copyright (C) 2006 Vincent Geddes - * - * Authors: - * Vincent Geddes <vgeddes@metroweb.co.za> - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#include "config.h" - -#include "glade.h" -#include "glade-design-layout.h" - -#include <gtk/gtk.h> - -#define GLADE_DESIGN_LAYOUT_GET_PRIVATE(object) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((object), \ - GLADE_TYPE_DESIGN_LAYOUT, \ - GladeDesignLayoutPrivate)) - -#define OUTLINE_WIDTH 4 -#define PADDING 12 - - -typedef enum -{ - GLADE_ACTIVITY_NONE, - GLADE_ACTIVITY_RESIZE_WIDTH, - GLADE_ACTIVITY_RESIZE_HEIGHT, - GLADE_ACTIVITY_RESIZE_WIDTH_AND_HEIGHT - -} GladeActivity; - -typedef enum -{ - GLADE_REGION_INSIDE = 0, - GLADE_REGION_EAST, - GLADE_REGION_SOUTH, - GLADE_REGION_SOUTH_EAST, - GLADE_REGION_WEST_OF_SOUTH_EAST, - GLADE_REGION_NORTH_OF_SOUTH_EAST, - GLADE_REGION_OUTSIDE -} GladePointerRegion; - -struct _GladeDesignLayoutPrivate -{ - GdkWindow *event_window; - - GdkCursor *cursor_resize_bottom; - GdkCursor *cursor_resize_right; - GdkCursor *cursor_resize_bottom_right; - - /* state machine */ - GladeActivity activity; /* the current activity */ - GtkRequisition *current_size_request; - gint dx; /* child.width - event.pointer.x */ - gint dy; /* child.height - event.pointer.y */ - gint new_width; /* user's new requested width */ - gint new_height; /* user's new requested height */ - - gulong widget_event_id; -}; - -static GtkBinClass *parent_class = NULL; - - -G_DEFINE_TYPE(GladeDesignLayout, glade_design_layout, GTK_TYPE_BIN) - -static GladePointerRegion -glade_design_layout_get_pointer_region (GladeDesignLayout *layout, gint x, gint y) -{ - GladeDesignLayoutPrivate *priv; - GtkAllocation *child_allocation; - GladePointerRegion region = GLADE_REGION_INSIDE; - - priv = GLADE_DESIGN_LAYOUT_GET_PRIVATE (layout); - - child_allocation = >K_BIN (layout)->child->allocation; - - if ((x >= (child_allocation->x + child_allocation->width)) && - (x < (child_allocation->x + child_allocation->width + OUTLINE_WIDTH))) - { - if ((y < (child_allocation->y + child_allocation->height - OUTLINE_WIDTH)) && - (y >= child_allocation->y - OUTLINE_WIDTH)) - region = GLADE_REGION_EAST; - - else if ((y < (child_allocation->y + child_allocation->height)) && - (y >= (child_allocation->y + child_allocation->height - OUTLINE_WIDTH))) - region = GLADE_REGION_NORTH_OF_SOUTH_EAST; - - else if ((y < (child_allocation->y + child_allocation->height + OUTLINE_WIDTH)) && - (y >= (child_allocation->y + child_allocation->height))) - region = GLADE_REGION_SOUTH_EAST; - } - else if ((y >= (child_allocation->y + child_allocation->height)) && - (y < (child_allocation->y + child_allocation->height + OUTLINE_WIDTH))) - { - if ((x < (child_allocation->x + child_allocation->width - OUTLINE_WIDTH)) && - (x >= child_allocation->x - OUTLINE_WIDTH)) - region = GLADE_REGION_SOUTH; - - else if ((x < (child_allocation->x + child_allocation->width)) && - (x >= (child_allocation->x + child_allocation->width - OUTLINE_WIDTH))) - region = GLADE_REGION_WEST_OF_SOUTH_EAST; - - else if ((x < (child_allocation->x + child_allocation->width + OUTLINE_WIDTH)) && - (x >= (child_allocation->x + child_allocation->width))) - region = GLADE_REGION_SOUTH_EAST; - } - - if (x < PADDING || y < PADDING || - x >= (child_allocation->x + child_allocation->width + OUTLINE_WIDTH) || - y >= (child_allocation->y + child_allocation->height + OUTLINE_WIDTH)) - region = GLADE_REGION_OUTSIDE; - - return region; -} - - -/* this handler ensures that the user cannot - * resize a widget below it minimum acceptable size */ -static void -child_size_request_handler (GtkWidget *widget, - GtkRequisition *req, - GladeDesignLayout *layout) -{ - GladeDesignLayoutPrivate *priv; - gint new_width, new_height; - gint old_width, old_height; - - priv = GLADE_DESIGN_LAYOUT_GET_PRIVATE (layout); - - priv->current_size_request->width = req->width; - priv->current_size_request->height = req->height; - - new_width = widget->allocation.width; - new_height = widget->allocation.height; - - if (req->width > new_width) - new_width = req->width; - - if (req->height > new_height) - new_height = req->height; - - if ((new_width != widget->allocation.width) || - (new_height != widget->allocation.height)) - { - old_width = widget->requisition.width; - old_height = widget->requisition.height; - - gtk_widget_set_size_request (widget, new_width, new_height); - - if (old_width > new_width) - widget->requisition.width = old_width; - - if (old_height > new_height) - widget->requisition.height = old_height; - } - - gtk_widget_queue_draw (GTK_WIDGET (layout)); - -} - -static gboolean -glade_design_layout_leave_notify_event (GtkWidget *widget, GdkEventCrossing *ev) -{ - GtkWidget *child; - GladeDesignLayoutPrivate *priv; - - if ((child = GTK_BIN (widget)->child) == NULL) - return FALSE; - - priv = GLADE_DESIGN_LAYOUT_GET_PRIVATE (widget); - - if (priv->activity == GLADE_ACTIVITY_NONE) - gdk_window_set_cursor (priv->event_window, NULL); - - return FALSE; -} - - -static void -glade_design_layout_update_child (GladeDesignLayout *layout, - GtkWidget *child, - GtkAllocation *allocation) -{ - GladeDesignLayoutPrivate *priv; - GladeWidget *gchild; - - priv = GLADE_DESIGN_LAYOUT_GET_PRIVATE (layout); - - /* Update GladeWidget metadata */ - gchild = glade_widget_get_from_gobject (child); - g_object_set (gchild, - "toplevel-width", allocation->width, - "toplevel-height", allocation->height, - NULL); - - gtk_widget_size_allocate (child, allocation); - gtk_widget_queue_resize (GTK_WIDGET (layout)); -} - - - - - -/* A temp data struct that we use when looking for a widget inside a container - * we need a struct, because the forall can only pass one pointer - */ -typedef struct { - gint x; - gint y; - gboolean any; - GtkWidget *found; - GtkWidget *toplevel; -} GladeFindInContainerData; - -static void -glade_design_layout_find_inside_container (GtkWidget *widget, GladeFindInContainerData *data) -{ - gint x; - gint y; - - gtk_widget_translate_coordinates (data->toplevel, widget, data->x, data->y, &x, &y); - - if (GTK_WIDGET_MAPPED(widget) && - x >= 0 && x < widget->allocation.width && y >= 0 && y < widget->allocation.height) - { - if (glade_widget_get_from_gobject (widget) || data->any) - data->found = widget; - else if (GTK_IS_CONTAINER (widget)) - { - /* Recurse and see if any project objects exist - * under this container that is not in the project - * (mostly for dialog buttons). - */ - GladeFindInContainerData search; - search.x = data->x; - search.y = data->y; - search.toplevel = data->toplevel; - search.found = NULL; - - gtk_container_forall (GTK_CONTAINER (widget), (GtkCallback) - glade_design_layout_find_inside_container, &search); - - data->found = search.found; - } - } -} - -static GladeWidget * -glade_design_layout_deepest_gwidget_at_position (GtkContainer *toplevel, - GtkContainer *container, - gint top_x, gint top_y) -{ - GladeFindInContainerData data; - GladeWidget *ret_widget = NULL; - - data.x = top_x; - data.y = top_y; - data.any = FALSE; - data.toplevel = GTK_WIDGET (toplevel); - data.found = NULL; - - gtk_container_forall (container, (GtkCallback) - glade_design_layout_find_inside_container, &data); - - if (data.found && GTK_IS_CONTAINER (data.found)) - ret_widget = glade_design_layout_deepest_gwidget_at_position - (toplevel, GTK_CONTAINER (data.found), top_x, top_y); - else if (data.found) - ret_widget = glade_widget_get_from_gobject (data.found); - else - ret_widget = glade_widget_get_from_gobject (container); - - return ret_widget; -} - - -static GtkWidget * -glade_design_layout_deepest_widget_at_position (GtkContainer *toplevel, - GtkContainer *container, - gint top_x, gint top_y) -{ - GladeFindInContainerData data; - GtkWidget *ret_widget = NULL; - - data.x = top_x; - data.y = top_y; - data.any = TRUE; - data.toplevel = GTK_WIDGET (toplevel); - data.found = NULL; - - gtk_container_forall (container, (GtkCallback) - glade_design_layout_find_inside_container, &data); - - if (data.found && GTK_IS_CONTAINER (data.found)) - ret_widget = glade_design_layout_deepest_widget_at_position - (toplevel, GTK_CONTAINER (data.found), top_x, top_y); - else if (data.found) - ret_widget = data.found; - else - ret_widget = GTK_WIDGET (container); - - return ret_widget; -} - -static gboolean -glade_design_layout_motion_notify_event (GtkWidget *widget, GdkEventMotion *ev) -{ - GtkWidget *child; - GladeDesignLayoutPrivate *priv; - GladeWidget *child_glade_widget; - GladePointerRegion region; - GtkAllocation allocation; - gint x, y; - gint new_width, new_height; - - if ((child = GTK_BIN (widget)->child) == NULL) - return FALSE; - - priv = GLADE_DESIGN_LAYOUT_GET_PRIVATE (widget); - - gdk_window_get_pointer (priv->event_window, &x, &y, NULL); - - child_glade_widget = glade_widget_get_from_gobject (child); - allocation = child->allocation; - - if (priv->activity == GLADE_ACTIVITY_RESIZE_WIDTH) - { - new_width = x - priv->dx - PADDING - OUTLINE_WIDTH; - - if (new_width < priv->current_size_request->width) - new_width = priv->current_size_request->width; - - allocation.width = new_width; - - glade_design_layout_update_child (GLADE_DESIGN_LAYOUT (widget), - child, &allocation); - } - else if (priv->activity == GLADE_ACTIVITY_RESIZE_HEIGHT) - { - new_height = y - priv->dy - PADDING - OUTLINE_WIDTH; - - if (new_height < priv->current_size_request->height) - new_height = priv->current_size_request->height; - - allocation.height = new_height; - - glade_design_layout_update_child (GLADE_DESIGN_LAYOUT (widget), - child, &allocation); - } - else if (priv->activity == GLADE_ACTIVITY_RESIZE_WIDTH_AND_HEIGHT) - { - new_width = x - priv->dx - PADDING - OUTLINE_WIDTH; - new_height = y - priv->dy - PADDING - OUTLINE_WIDTH; - - if (new_width < priv->current_size_request->width) - new_width = priv->current_size_request->width; - if (new_height < priv->current_size_request->height) - new_height = priv->current_size_request->height; - - - allocation.height = new_height; - allocation.width = new_width; - - glade_design_layout_update_child (GLADE_DESIGN_LAYOUT (widget), - child, &allocation); - } - else - { - region = glade_design_layout_get_pointer_region (GLADE_DESIGN_LAYOUT (widget), x, y); - - if (region == GLADE_REGION_EAST) - gdk_window_set_cursor (priv->event_window, priv->cursor_resize_right); - - else if (region == GLADE_REGION_SOUTH) - gdk_window_set_cursor (priv->event_window, priv->cursor_resize_bottom); - - else if (region == GLADE_REGION_SOUTH_EAST || - region == GLADE_REGION_WEST_OF_SOUTH_EAST || - region == GLADE_REGION_NORTH_OF_SOUTH_EAST) - gdk_window_set_cursor (priv->event_window, priv->cursor_resize_bottom_right); - - else if (region == GLADE_REGION_OUTSIDE) - { - gdk_window_set_cursor (priv->event_window, NULL); - glade_cursor_set (priv->event_window, GLADE_CURSOR_SELECTOR); - } - } - return FALSE; -} - -static gboolean -glade_design_layout_button_press_event (GtkWidget *widget, GdkEventButton *ev) -{ - GtkWidget *child; - GladePointerRegion region; - GladeDesignLayoutPrivate *priv; - gint x, y; - - if ((child = GTK_BIN (widget)->child) == NULL) - return FALSE; - - priv = GLADE_DESIGN_LAYOUT_GET_PRIVATE (widget); - - gdk_window_get_pointer (priv->event_window, &x, &y, NULL); - region = glade_design_layout_get_pointer_region (GLADE_DESIGN_LAYOUT (widget), x, y); - - if (((GdkEventButton *) ev)->button == 1) - { - priv->dx = x - (child->allocation.x + child->allocation.width); - priv->dy = y - (child->allocation.y + child->allocation.height); - - if (region == GLADE_REGION_EAST) - { - priv->activity = GLADE_ACTIVITY_RESIZE_WIDTH; - gdk_window_set_cursor (priv->event_window, priv->cursor_resize_right); - } - if (region == GLADE_REGION_SOUTH) - { - priv->activity = GLADE_ACTIVITY_RESIZE_HEIGHT; - gdk_window_set_cursor (priv->event_window, priv->cursor_resize_bottom); - } - if (region == GLADE_REGION_SOUTH_EAST) - { - priv->activity = GLADE_ACTIVITY_RESIZE_WIDTH_AND_HEIGHT; - gdk_window_set_cursor (priv->event_window, priv->cursor_resize_bottom_right); - } - if (region == GLADE_REGION_WEST_OF_SOUTH_EAST) - { - priv->activity = GLADE_ACTIVITY_RESIZE_WIDTH_AND_HEIGHT; - gdk_window_set_cursor (priv->event_window, priv->cursor_resize_bottom_right); - } - if (region == GLADE_REGION_NORTH_OF_SOUTH_EAST) - { - priv->activity = GLADE_ACTIVITY_RESIZE_WIDTH_AND_HEIGHT; - gdk_window_set_cursor (priv->event_window, priv->cursor_resize_bottom_right); - } - } - - return FALSE; -} - -static gboolean -glade_design_layout_button_release_event (GtkWidget *widget, GdkEventButton *ev) -{ - GladeDesignLayoutPrivate *priv; - GtkWidget *child; - - if ((child = GTK_BIN (widget)->child) == NULL) - return FALSE; - - priv = GLADE_DESIGN_LAYOUT_GET_PRIVATE (widget); - - priv->activity = GLADE_ACTIVITY_NONE; - gdk_window_set_cursor (priv->event_window, NULL); - - return FALSE; -} - -static void -glade_design_layout_size_request (GtkWidget *widget, GtkRequisition *requisition) -{ - GladeDesignLayoutPrivate *priv; - GtkRequisition child_requisition; - GtkWidget *child; - GladeWidget *gchild; - gint child_width = 0; - gint child_height = 0; - - priv = GLADE_DESIGN_LAYOUT_GET_PRIVATE (widget); - - requisition->width = 0; - requisition->height = 0; - - child = GTK_BIN (widget)->child; - - if (child && GTK_WIDGET_VISIBLE (child)) - { - gchild = glade_widget_get_from_gobject (child); - g_assert (gchild); - - gtk_widget_size_request (child, &child_requisition); - - g_object_get (gchild, - "toplevel-width", &child_width, - "toplevel-height", &child_height, - NULL); - - child_width = MAX (child_width, child_requisition.width); - child_height = MAX (child_height, child_requisition.height); - - requisition->width = MAX (requisition->width, - 2 * PADDING + child_width + 2 * OUTLINE_WIDTH); - - requisition->height = MAX (requisition->height, - 2 * PADDING + child_height + 2 * OUTLINE_WIDTH); - } - - requisition->width += GTK_CONTAINER (widget)->border_width * 2; - requisition->height += GTK_CONTAINER (widget)->border_width * 2; -} - -static void -glade_design_layout_size_allocate (GtkWidget *widget, GtkAllocation *allocation) -{ - GladeDesignLayoutPrivate *priv; - GladeWidget *gchild; - GtkRequisition child_requisition; - GtkAllocation child_allocation; - GtkWidget *child; - gint border_width; - gint child_width = 0; - gint child_height = 0; - - priv = GLADE_DESIGN_LAYOUT_GET_PRIVATE (widget); - - widget->allocation = *allocation; - border_width = GTK_CONTAINER (widget)->border_width; - - if (GTK_WIDGET_REALIZED (widget)) - { - if (priv->event_window) - gdk_window_move_resize (priv->event_window, - allocation->x, - allocation->y, - allocation->width, - allocation->height); - - } - - child = GTK_BIN (widget)->child; - - if (child && GTK_WIDGET_VISIBLE (child)) - { - gchild = glade_widget_get_from_gobject (child); - g_assert (gchild); - - gtk_widget_get_child_requisition (child, &child_requisition); - - g_object_get (gchild, - "toplevel-width", &child_width, - "toplevel-height", &child_height, - NULL); - - child_width = MAX (child_width, child_requisition.width); - child_height = MAX (child_height, child_requisition.height); - - child_allocation.x = widget->allocation.x + border_width + PADDING + OUTLINE_WIDTH; - child_allocation.y = widget->allocation.y + border_width + PADDING + OUTLINE_WIDTH; - - child_allocation.width = child_width - 2 * border_width; - child_allocation.height = child_height - 2 * border_width; - - gtk_widget_size_allocate (child, &child_allocation); - } -} - -static void -glade_design_layout_map (GtkWidget *widget) -{ - GladeDesignLayoutPrivate *priv; - - priv = GLADE_DESIGN_LAYOUT_GET_PRIVATE (widget); - - if (priv->event_window) - gdk_window_show (priv->event_window); - - GTK_WIDGET_CLASS (parent_class)->map (widget); - -} - -static void -glade_design_layout_unmap (GtkWidget *widget) -{ - GladeDesignLayoutPrivate *priv; - - priv = GLADE_DESIGN_LAYOUT_GET_PRIVATE (widget); - - GTK_WIDGET_CLASS (parent_class)->unmap (widget); - - if (priv->event_window) - gdk_window_hide (priv->event_window); -} - -static void -glade_design_layout_realize (GtkWidget *widget) -{ - GladeDesignLayoutPrivate *priv; - GdkWindowAttr attributes; - gint attributes_mask; - gint border_width; - - priv = GLADE_DESIGN_LAYOUT_GET_PRIVATE (widget); - - GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); - - border_width = GTK_CONTAINER (widget)->border_width; - - attributes.x = widget->allocation.x; - attributes.y = widget->allocation.y; - attributes.width = widget->allocation.width; - attributes.height = widget->allocation.height; - - attributes.window_type = GDK_WINDOW_CHILD; - attributes.wclass = GDK_INPUT_ONLY; - attributes.event_mask = - gtk_widget_get_events (widget) | - GDK_POINTER_MOTION_MASK | - GDK_POINTER_MOTION_HINT_MASK | - GDK_BUTTON_PRESS_MASK | - GDK_BUTTON_RELEASE_MASK | - GDK_EXPOSURE_MASK | - GDK_ENTER_NOTIFY_MASK | - GDK_LEAVE_NOTIFY_MASK; - attributes_mask = GDK_WA_X | GDK_WA_Y; - - widget->window = gtk_widget_get_parent_window (widget); - g_object_ref (widget->window); - - priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget), - &attributes, attributes_mask); - gdk_window_set_user_data (priv->event_window, widget); - - widget->style = gtk_style_attach (widget->style, widget->window); - gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL); -} - -static void -glade_design_layout_unrealize (GtkWidget *widget) -{ - GladeDesignLayoutPrivate *priv; - - priv = GLADE_DESIGN_LAYOUT_GET_PRIVATE (widget); - - if (priv->event_window) - { - gdk_window_set_user_data (priv->event_window, NULL); - gdk_window_destroy (priv->event_window); - priv->event_window = NULL; - } - - GTK_WIDGET_CLASS (parent_class)->unrealize (widget); - -} - -static void -glade_design_layout_add (GtkContainer *container, GtkWidget *widget) -{ - GladeDesignLayout *layout; - - layout = GLADE_DESIGN_LAYOUT (container); - - layout->priv->current_size_request->width = 0; - layout->priv->current_size_request->height = 0; - - g_signal_connect (G_OBJECT (widget), "size-request", - G_CALLBACK (child_size_request_handler), - container); - - GTK_CONTAINER_CLASS (parent_class)->add (container, widget); - - gdk_window_lower (layout->priv->event_window); -} - -static void -glade_design_layout_remove (GtkContainer *container, GtkWidget *widget) -{ - g_signal_handlers_disconnect_by_func(G_OBJECT (widget), - G_CALLBACK (child_size_request_handler), - container); - - GTK_CONTAINER_CLASS (parent_class)->remove (container, widget); -} - -static void -glade_design_layout_dispose (GObject *object) -{ - GladeDesignLayoutPrivate *priv = GLADE_DESIGN_LAYOUT_GET_PRIVATE (object); - - if (priv->cursor_resize_bottom != NULL) { - gdk_cursor_unref (priv->cursor_resize_bottom); - priv->cursor_resize_bottom = NULL; - } - if (priv->cursor_resize_right != NULL) { - gdk_cursor_unref (priv->cursor_resize_right); - priv->cursor_resize_right = NULL; - } - if (priv->cursor_resize_bottom_right != NULL) { - gdk_cursor_unref (priv->cursor_resize_bottom_right); - priv->cursor_resize_bottom_right = NULL; - } - - G_OBJECT_CLASS (parent_class)->dispose (object); -} - -static void -glade_design_layout_finalize (GObject *object) -{ - GladeDesignLayoutPrivate *priv = GLADE_DESIGN_LAYOUT_GET_PRIVATE (object); - - g_signal_handler_disconnect (glade_app_get (), priv->widget_event_id); - - g_free (priv->current_size_request); - - G_OBJECT_CLASS (parent_class)->finalize (object); -} - -/* creates a gc to draw a nice border around the child */ -GdkGC* -create_outline_gc (GtkWidget *widget) -{ - GdkGC *gc; - GdkGCValues values; - - gc = gdk_gc_new (widget->window); - - /* we want the light_gc values as a start */ - gdk_gc_copy (gc, widget->style->light_gc[GTK_STATE_SELECTED]); - - values.line_width = OUTLINE_WIDTH; - gdk_gc_set_values (gc, &values, GDK_GC_LINE_WIDTH); - - return gc; -} - - -static gboolean -glade_design_layout_expose_event (GtkWidget *widget, GdkEventExpose *ev) -{ - GladeDesignLayout *layout; - GdkGC *gc; - GtkWidget *child; - gint x, y, w, h; - gint border_width; - - layout = GLADE_DESIGN_LAYOUT (widget); - - border_width = GTK_CONTAINER (widget)->border_width; - - /* draw a white widget background */ - gdk_draw_rectangle (widget->window, - widget->style->base_gc [GTK_WIDGET_STATE (widget)], - TRUE, - widget->allocation.x + border_width, - widget->allocation.y + border_width, - widget->allocation.width - 2 * border_width, - widget->allocation.height - 2 * border_width); - - child = GTK_BIN (widget)->child; - - if (child && GTK_WIDGET_VISIBLE (child)) - { - x = child->allocation.x - OUTLINE_WIDTH / 2; - y = child->allocation.y - OUTLINE_WIDTH / 2; - w = child->allocation.width + OUTLINE_WIDTH; - h = child->allocation.height + OUTLINE_WIDTH; - - gc = create_outline_gc (widget); - - /* draw outline around child */ - gdk_draw_rectangle (widget->window, - gc, - FALSE, - x, y, w, h); - - /* draw a filled rectangle in case child does not draw - * it's own background (a GTK_WIDGET_NO_WINDOW child). */ - gdk_draw_rectangle (widget->window, - widget->style->fg_gc[GTK_STATE_NORMAL], - TRUE, - x + OUTLINE_WIDTH / 2, y + OUTLINE_WIDTH / 2, - w - OUTLINE_WIDTH, h - OUTLINE_WIDTH); - - g_object_unref (gc); - } - - return TRUE; -} - -static gboolean -glade_design_layout_widget_event (GladeApp *app, - GladeWidget *event_gwidget, - GdkEvent *event, - GladeDesignLayout *layout) -{ - GladeWidget *gwidget; - GtkWidget *child; - gboolean retval; - gint x, y; - - gtk_widget_get_pointer (GTK_WIDGET (layout), &x, &y); - gwidget = glade_design_layout_deepest_gwidget_at_position - (GTK_CONTAINER (layout), GTK_CONTAINER (layout), x, y); - - child = glade_design_layout_deepest_widget_at_position - (GTK_CONTAINER (layout), GTK_CONTAINER (layout), x, y); - - /* First try a placeholder */ - if (GLADE_IS_PLACEHOLDER (child) && event->type != GDK_EXPOSE) - { - retval = gtk_widget_event (child, event); - - if (retval) - return retval; - } - - /* Then we try a GladeWidget */ - if (gwidget) - { - retval = glade_widget_event (gwidget, event); - - if (retval) - return retval; - } - - return FALSE; -} - -static gboolean -glade_design_layout_propagate_event (GtkWidget *widget, - GdkEvent *event) -{ - GtkWidget *child; - - if ((child = GTK_BIN (widget)->child) != NULL) - { - GladeWidget *gwidget = - glade_widget_get_from_gobject (child); - - if (gwidget) - return glade_design_layout_widget_event (glade_app_get (), - gwidget, event, - GLADE_DESIGN_LAYOUT (widget)); - } - return FALSE; -} - -static void -glade_design_layout_init (GladeDesignLayout *layout) -{ - GladeDesignLayoutPrivate *priv; - - layout->priv = priv = GLADE_DESIGN_LAYOUT_GET_PRIVATE (layout); - - GTK_WIDGET_SET_FLAGS (GTK_WIDGET (layout), GTK_NO_WINDOW); - - priv->event_window = NULL; - priv->activity = GLADE_ACTIVITY_NONE; - - priv->current_size_request = g_new0 (GtkRequisition, 1); - - priv->cursor_resize_bottom = gdk_cursor_new (GDK_BOTTOM_SIDE); - priv->cursor_resize_right = gdk_cursor_new (GDK_RIGHT_SIDE); - priv->cursor_resize_bottom_right = gdk_cursor_new (GDK_BOTTOM_RIGHT_CORNER); - - priv->new_width = -1; - priv->new_height = -1; - - priv->widget_event_id = - g_signal_connect (glade_app_get (), "widget-event", - G_CALLBACK (glade_design_layout_widget_event), - layout); - -} - -static void -glade_design_layout_class_init (GladeDesignLayoutClass *klass) -{ - GObjectClass *object_class; - GtkWidgetClass *widget_class; - GtkContainerClass *container_class; - - object_class = G_OBJECT_CLASS (klass); - parent_class = g_type_class_peek_parent (klass); - widget_class = GTK_WIDGET_CLASS (klass); - container_class = GTK_CONTAINER_CLASS (klass); - - object_class->dispose = glade_design_layout_dispose; - object_class->finalize = glade_design_layout_finalize; - - container_class->add = glade_design_layout_add; - container_class->remove = glade_design_layout_remove; - - widget_class->event = glade_design_layout_propagate_event; - widget_class->motion_notify_event = glade_design_layout_motion_notify_event; - widget_class->leave_notify_event = glade_design_layout_leave_notify_event; - widget_class->button_press_event = glade_design_layout_button_press_event; - widget_class->button_release_event = glade_design_layout_button_release_event; - widget_class->realize = glade_design_layout_realize; - widget_class->unrealize = glade_design_layout_unrealize; - widget_class->map = glade_design_layout_map; - widget_class->unmap = glade_design_layout_unmap; - widget_class->expose_event = glade_design_layout_expose_event; - widget_class->size_request = glade_design_layout_size_request; - widget_class->size_allocate = glade_design_layout_size_allocate; - - g_type_class_add_private (object_class, sizeof (GladeDesignLayoutPrivate)); - -} - -GtkWidget* -glade_design_layout_new (void) -{ - GladeDesignLayout *layout; - - layout = g_object_new (GLADE_TYPE_DESIGN_LAYOUT, NULL); - - return GTK_WIDGET (layout); -} diff --git a/gladeui/glade-design-layout.h b/gladeui/glade-design-layout.h deleted file mode 100644 index 1b6e00c2..00000000 --- a/gladeui/glade-design-layout.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * glade-design-layout.h - * - * Copyright (C) 2006 Vincent Geddes - * - * Authors: - * Vincent Geddes <vgeddes@metroweb.co.za> - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#ifndef __GLADE_DESIGN_LAYOUT_H__ -#define __GLADE_DESIGN_LAYOUT_H__ - -#include <gtk/gtkbin.h> - -G_BEGIN_DECLS - -#define GLADE_TYPE_DESIGN_LAYOUT (glade_design_layout_get_type ()) -#define GLADE_DESIGN_LAYOUT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_DESIGN_LAYOUT, GladeDesignLayout)) -#define GLADE_DESIGN_LAYOUT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_DESIGN_LAYOUT, GladeDesignLayoutClass)) -#define GLADE_IS_DESIGN_LAYOUT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_DESIGN_LAYOUT)) -#define GLADE_IS_DESIGN_LAYOUT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_DESIGN_LAYOUT)) -#define GLADE_DESIGN_LAYOUT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GLADE_TYPE_DESIGN_LAYOUT, GladeDesignLayoutClass)) - -typedef struct _GladeDesignLayout GladeDesignLayout; -typedef struct _GladeDesignLayoutPrivate GladeDesignLayoutPrivate; -typedef struct _GladeDesignLayoutClass GladeDesignLayoutClass; - -struct _GladeDesignLayout -{ - GtkBin bin; /* The parent is an event box */ - - GladeDesignLayoutPrivate *priv; -}; - -struct _GladeDesignLayoutClass -{ - GtkBinClass parent_class; - -}; - - -GType glade_design_layout_get_type (void) G_GNUC_CONST; - -GtkWidget *glade_design_layout_new (void); - - -G_END_DECLS - -#endif /* __GLADE_DESIGN_LAYOUT_H__ */ diff --git a/gladeui/glade-design-view.c b/gladeui/glade-design-view.c deleted file mode 100644 index d5ddc081..00000000 --- a/gladeui/glade-design-view.c +++ /dev/null @@ -1,196 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * glade-design-view.c - * - * Copyright (C) 2006 Vincent Geddes - * - * Authors: - * Vincent Geddes <vincent.geddes@gmail.com> - * - * 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 - * MERCHANDESIGN_VIEWILITY 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#include "config.h" - -#include "glade.h" -#include "glade-utils.h" -#include "glade-design-view.h" -#include "glade-design-layout.h" - -#include <glib.h> -#include <glib/gi18n.h> - -#define GLADE_DESIGN_VIEW_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), GLADE_TYPE_DESIGN_VIEW, GladeDesignViewPrivate)) - -#define GLADE_DESIGN_VIEW_KEY "GLADE_DESIGN_VIEW_KEY" - -enum -{ - PROP_0, - PROP_PROJECT, -}; - -struct _GladeDesignViewPrivate -{ - GtkWidget *layout; - - GladeProject *project; -}; - -static GtkVBoxClass *parent_class = NULL; - - -G_DEFINE_TYPE(GladeDesignView, glade_design_view, GTK_TYPE_VBOX) - -static void -glade_design_view_set_project (GladeDesignView *view, GladeProject *project) -{ - g_return_if_fail (GLADE_IS_PROJECT (project)); - - view->priv->project = project; - - g_object_set_data (G_OBJECT (view->priv->project), GLADE_DESIGN_VIEW_KEY, view); - -} - -static void -glade_design_view_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - switch (prop_id) - { - case PROP_PROJECT: - glade_design_view_set_project (GLADE_DESIGN_VIEW (object), g_value_get_object (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -glade_design_view_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - switch (prop_id) - { - case PROP_PROJECT: - g_value_set_object (value, GLADE_DESIGN_VIEW (object)->priv->project); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -glade_design_view_init (GladeDesignView *view) -{ - GtkWidget *sw; - GtkWidget *viewport; - - view->priv = GLADE_DESIGN_VIEW_GET_PRIVATE (view); - - view->priv->project = NULL; - view->priv->layout = glade_design_layout_new (); - - sw = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN); - - viewport = gtk_viewport_new (NULL, NULL); - gtk_viewport_set_shadow_type (GTK_VIEWPORT (viewport), GTK_SHADOW_NONE); - gtk_container_add (GTK_CONTAINER (viewport), view->priv->layout); - gtk_container_add (GTK_CONTAINER (sw), viewport); - - gtk_widget_show (sw); - gtk_widget_show (viewport); - gtk_widget_show (view->priv->layout); - - gtk_box_pack_start (GTK_BOX (view), sw, TRUE, TRUE, 0); - - gtk_container_set_border_width (GTK_CONTAINER (view), 0); -} - -static void -glade_design_view_class_init (GladeDesignViewClass *klass) -{ - GObjectClass *object_class; - GtkWidgetClass *widget_class; - - parent_class = g_type_class_peek_parent (klass); - object_class = G_OBJECT_CLASS (klass); - widget_class = GTK_WIDGET_CLASS (klass); - - object_class->get_property = glade_design_view_get_property; - object_class->set_property = glade_design_view_set_property; - - g_object_class_install_property (object_class, - PROP_PROJECT, - g_param_spec_object ("project", - "Project", - "The project for this view", - GLADE_TYPE_PROJECT, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - - g_type_class_add_private (object_class, sizeof (GladeDesignViewPrivate)); -} - -GladeProject* -glade_design_view_get_project (GladeDesignView *view) -{ - g_return_val_if_fail (GLADE_IS_DESIGN_VIEW (view), NULL); - - return view->priv->project; - -} - -GtkWidget * -glade_design_view_new (GladeProject *project) -{ - GladeDesignView *view; - - g_return_val_if_fail (GLADE_IS_PROJECT (project), NULL); - - view = g_object_new (GLADE_TYPE_DESIGN_VIEW, - "project", project, - NULL); - - return GTK_WIDGET (view); -} - -GladeDesignView * -glade_design_view_get_from_project (GladeProject *project) -{ - gpointer p; - - g_return_val_if_fail (GLADE_IS_PROJECT (project), NULL); - - p = g_object_get_data (G_OBJECT (project), GLADE_DESIGN_VIEW_KEY); - - return (p != NULL) ? GLADE_DESIGN_VIEW (p) : NULL; - -} - -GladeDesignLayout * -glade_design_view_get_layout (GladeDesignView *view) -{ - return GLADE_DESIGN_LAYOUT (view->priv->layout); -} diff --git a/gladeui/glade-design-view.h b/gladeui/glade-design-view.h deleted file mode 100644 index fbba1ee2..00000000 --- a/gladeui/glade-design-view.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * glade-design-view.h - * - * Copyright (C) 2006 Vincent Geddes - * - * Authors: - * Vincent Geddes <vincent.geddes@gmail.com> - * - * 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 - * MERCHANDESIGN_VIEWILITY 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#ifndef __GLADE_DESIGN_VIEW_H__ -#define __GLADE_DESIGN_VIEW_H__ - -#include <gladeui/glade.h> -#include <gladeui/glade-project.h> -#include <gladeui/glade-design-layout.h> - -#include <gtk/gtkvbox.h> - -G_BEGIN_DECLS - -#define GLADE_TYPE_DESIGN_VIEW (glade_design_view_get_type ()) -#define GLADE_DESIGN_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_DESIGN_VIEW, GladeDesignView)) -#define GLADE_DESIGN_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_DESIGN_VIEW, GladeDesignViewClass)) -#define GLADE_IS_DESIGN_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_DESIGN_VIEW)) -#define GLADE_IS_DESIGN_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_DESIGN_VIEW)) -#define GLADE_DESIGN_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GLADE_TYPE_DESIGN_VIEW, GladeDesignViewClass)) - -typedef struct _GladeDesignView GladeDesignView; -typedef struct _GladeDesignViewPrivate GladeDesignViewPrivate; -typedef struct _GladeDesignViewClass GladeDesignViewClass; - -struct _GladeDesignView -{ - GtkVBox parent_instance; - - GladeDesignViewPrivate *priv; -}; - -struct _GladeDesignViewClass -{ - GtkVBoxClass parent_class; - -}; - - -GType glade_design_view_get_type (void) G_GNUC_CONST; - -GtkWidget *glade_design_view_new (GladeProject *project); - -GladeProject *glade_design_view_get_project (GladeDesignView *view); - -GladeDesignView *glade_design_view_get_from_project (GladeProject *project); - -GladeDesignLayout *glade_design_view_get_layout (GladeDesignView *view); - - -G_END_DECLS - -#endif /* __GLADE_DESIGN_VIEW_H__ */ diff --git a/gladeui/glade-editor-property.c b/gladeui/glade-editor-property.c deleted file mode 100644 index 86414bd2..00000000 --- a/gladeui/glade-editor-property.c +++ /dev/null @@ -1,3889 +0,0 @@ -/* -*- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Authors: - * Tristan Van Berkom <tvb@gnome.org> - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdio.h> -#include <string.h> -#include <glib/gi18n-lib.h> -#include <gtk/gtk.h> -#include <gdk/gdkkeysyms.h> - -#include "glade.h" -#include "glade-widget.h" -#include "glade-editor-property.h" -#include "glade-property.h" -#include "glade-command.h" -#include "glade-project.h" -#include "glade-builtins.h" -#include "glade-marshallers.h" - -enum { - PROP_0, - PROP_PROPERTY_CLASS, - PROP_USE_COMMAND, - PROP_SHOW_INFO -}; - -enum { - GTK_DOC_SEARCH, - LAST_SIGNAL -}; - -static GtkTableClass *table_class; -static GladeEditorPropertyClass *editor_property_class; - -static guint glade_editor_property_signals[LAST_SIGNAL] = { 0 }; - -#define GLADE_PROPERTY_TABLE_ROW_SPACING 2 -#define FLAGS_COLUMN_SETTING 0 -#define FLAGS_COLUMN_SYMBOL 1 - -/******************************************************************************* - Boiler plate macros (inspired from glade-command.c) - *******************************************************************************/ -#define MAKE_TYPE(func, type, parent) \ -GType \ -func ## _get_type (void) \ -{ \ - static GType cmd_type = 0; \ - \ - if (!cmd_type) \ - { \ - static const GTypeInfo info = \ - { \ - sizeof (type ## Class), \ - (GBaseInitFunc) NULL, \ - (GBaseFinalizeFunc) NULL, \ - (GClassInitFunc) func ## _class_init, \ - (GClassFinalizeFunc) NULL, \ - NULL, \ - sizeof (type), \ - 0, \ - (GInstanceInitFunc) NULL \ - }; \ - \ - cmd_type = g_type_register_static (parent, #type, &info, 0); \ - } \ - \ - return cmd_type; \ -} \ - - -#define GLADE_MAKE_EPROP(type, func) \ -static void \ -func ## _finalize (GObject *object); \ -static void \ -func ## _load (GladeEditorProperty *me, GladeProperty *property); \ -static GtkWidget * \ -func ## _create_input (GladeEditorProperty *me); \ -static void \ -func ## _class_init (gpointer parent_tmp, gpointer notused) \ -{ \ - GladeEditorPropertyClass *parent = parent_tmp; \ - GObjectClass* object_class; \ - object_class = G_OBJECT_CLASS (parent); \ - parent->load = func ## _load; \ - parent->create_input = func ## _create_input; \ - object_class->finalize = func ## _finalize; \ -} \ -typedef struct { \ - GladeEditorPropertyClass cmd; \ -} type ## Class; \ -static MAKE_TYPE(func, type, GLADE_TYPE_EDITOR_PROPERTY) - - - - -/******************************************************************************* - GladeEditorPropertyClass - *******************************************************************************/ - -/* declare this forwardly for the finalize routine */ -static void glade_editor_property_load_common (GladeEditorProperty *eprop, - GladeProperty *property); - -/* For use in editor implementations - */ -static void -glade_editor_property_commit (GladeEditorProperty *eprop, - GValue *value) -{ - g_return_if_fail (GLADE_IS_EDITOR_PROPERTY (eprop)); - - if (eprop->use_command == FALSE) - glade_property_set_value (eprop->property, value); - else - glade_command_set_property_value (eprop->property, value); - - /* If the value was denied by a verify function, we'll have to - * reload the real value. - */ - if (g_param_values_cmp (eprop->property->klass->pspec, - eprop->property->value, value) != 0) - GLADE_EDITOR_PROPERTY_GET_CLASS (eprop)->load (eprop, eprop->property); -} - - - -static void -glade_editor_property_tooltip_cb (GladeProperty *property, - const gchar *tooltip, - GladeEditorProperty *eprop) -{ - glade_util_widget_set_tooltip (eprop->input, tooltip); - glade_util_widget_set_tooltip (eprop->eventbox, tooltip); -} - -static void -glade_eprop_label_style_update_cb (GtkWidget *label, - GtkStyle *prev, - GladeEditorProperty *eprop) -{ - if (eprop->insensitive_colour) - gdk_color_free (eprop->insensitive_colour); - if (eprop->normal_colour) - gdk_color_free (eprop->normal_colour); - - eprop->insensitive_colour = - gdk_color_copy (&(label->style->fg[GTK_STATE_INSENSITIVE])); - eprop->normal_colour = - gdk_color_copy (&(label->style->fg[GTK_STATE_NORMAL])); -} - -static void -glade_editor_property_sensitivity_cb (GladeProperty *property, - GParamSpec *pspec, - GladeEditorProperty *eprop) -{ - gboolean sensitive = glade_property_get_sensitive (eprop->property); - - g_signal_handlers_block_by_func - (eprop->item_label, glade_eprop_label_style_update_cb, eprop); - gtk_widget_modify_fg - (GTK_WIDGET (eprop->item_label), - GTK_STATE_NORMAL, - sensitive ? eprop->normal_colour : eprop->insensitive_colour); - g_signal_handlers_unblock_by_func - (eprop->item_label, glade_eprop_label_style_update_cb, eprop); - - if (sensitive == FALSE) - gtk_widget_set_sensitive (eprop->input, FALSE); - else if (glade_property_get_enabled (property) != FALSE) - gtk_widget_set_sensitive (eprop->input, TRUE); - - if (eprop->check) - gtk_widget_set_sensitive (eprop->check, sensitive); -} - -static void -glade_editor_property_value_changed_cb (GladeProperty *property, - GValue *old_value, - GValue *value, - GladeEditorProperty *eprop) -{ - g_assert (eprop->property == property); - glade_editor_property_load (eprop, eprop->property); -} - -static void -glade_editor_property_enabled_cb (GladeProperty *property, - GParamSpec *pspec, - GladeEditorProperty *eprop) -{ - gboolean enabled; - g_assert (eprop->property == property); - - if (eprop->klass->optional) - { - enabled = glade_property_get_enabled (property); - - /* sensitive = enabled && */ - if (enabled == FALSE) - gtk_widget_set_sensitive (eprop->input, FALSE); - else if (glade_property_get_sensitive (property)) - gtk_widget_set_sensitive (eprop->input, TRUE); - - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (eprop->check), enabled); - } -} - -static void -glade_editor_property_enabled_toggled_cb (GtkWidget *check, - GladeEditorProperty *eprop) -{ - glade_property_set_enabled (eprop->property, - gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check))); -} - -static void -glade_editor_property_info_clicked_cb (GtkWidget *info, - GladeEditorProperty *eprop) -{ - GladeWidgetAdaptor *adaptor; - gchar *search, *book; - - adaptor = glade_widget_adaptor_from_pspec (eprop->klass->pspec); - search = g_strdup_printf ("The %s property", eprop->klass->id); - - g_object_get (adaptor, "book", &book, NULL); - - g_signal_emit (G_OBJECT (eprop), - glade_editor_property_signals[GTK_DOC_SEARCH], - 0, book, - g_type_name (eprop->klass->pspec->owner_type), search); - - g_free (book); - g_free (search); -} - -static GtkWidget * -glade_editor_property_create_info_button (GladeEditorProperty *eprop) -{ - GtkWidget *image; - GtkWidget *button; - - button = gtk_button_new (); - - image = glade_util_get_devhelp_icon (GTK_ICON_SIZE_MENU); - gtk_widget_show (image); - - gtk_container_add (GTK_CONTAINER (button), image); - - glade_util_widget_set_tooltip (button, _("View GTK+ documentation for this property")); - - return button; -} - -static GObject * -glade_editor_property_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties) -{ - GObject *obj; - GladeEditorProperty *eprop; - gchar *text; - - /* Invoke parent constructor (eprop->klass should be resolved by this point) . */ - obj = G_OBJECT_CLASS (table_class)->constructor - (type, n_construct_properties, construct_properties); - - eprop = GLADE_EDITOR_PROPERTY (obj); - - /* Create label (make label visible but not the eventbox) */ - text = g_strdup_printf ("%s:", eprop->klass->name); - eprop->item_label = gtk_label_new (text); - eprop->eventbox = gtk_event_box_new (); - g_free (text); - gtk_widget_show (eprop->item_label); - - /* Deal with label colours */ - glade_eprop_label_style_update_cb (eprop->item_label, NULL, eprop); - g_signal_connect (G_OBJECT (eprop->item_label), "style-set", - G_CALLBACK (glade_eprop_label_style_update_cb), eprop); - - /* keep our own reference */ - g_object_ref (G_OBJECT (eprop->eventbox)); - - gtk_misc_set_alignment (GTK_MISC (eprop->item_label), 1.0, 0.5); - gtk_container_add (GTK_CONTAINER (eprop->eventbox), eprop->item_label); - - /* Create hbox and possibly check button - */ - if (eprop->klass->optional) - { - eprop->check = gtk_check_button_new (); - gtk_widget_show (eprop->check); - gtk_box_pack_start (GTK_BOX (eprop), eprop->check, FALSE, FALSE, 0); - g_signal_connect (G_OBJECT (eprop->check), "toggled", - G_CALLBACK (glade_editor_property_enabled_toggled_cb), eprop); - - } - - /* Create the class specific input widget and add it */ - eprop->input = GLADE_EDITOR_PROPERTY_GET_CLASS (eprop)->create_input (eprop); - gtk_widget_show (eprop->input); - gtk_box_pack_start (GTK_BOX (eprop), eprop->input, TRUE, TRUE, 0); - - /* Create the informational button and add it */ - eprop->info = glade_editor_property_create_info_button (eprop); - g_signal_connect (G_OBJECT (eprop->info), "clicked", - G_CALLBACK (glade_editor_property_info_clicked_cb), eprop); - - - gtk_box_pack_start (GTK_BOX (eprop), eprop->info, FALSE, FALSE, 2); - - return obj; -} - -static void -glade_editor_property_finalize (GObject *object) -{ - GladeEditorProperty *eprop = GLADE_EDITOR_PROPERTY (object); - - /* detatch from loaded property */ - glade_editor_property_load_common (eprop, NULL); - - if (eprop->insensitive_colour) - gdk_color_free (eprop->insensitive_colour); - if (eprop->normal_colour) - gdk_color_free (eprop->normal_colour); - - G_OBJECT_CLASS (table_class)->finalize (object); -} - -static void -glade_editor_property_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - GladeEditorProperty *eprop = GLADE_EDITOR_PROPERTY (object); - - switch (prop_id) - { - case PROP_PROPERTY_CLASS: - eprop->klass = g_value_get_pointer (value); - break; - case PROP_USE_COMMAND: - eprop->use_command = g_value_get_boolean (value); - break; - case PROP_SHOW_INFO: - if (g_value_get_boolean (value)) - glade_editor_property_show_info (eprop); - else - glade_editor_property_hide_info (eprop); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -glade_editor_property_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - GladeEditorProperty *eprop = GLADE_EDITOR_PROPERTY (object); - - switch (prop_id) - { - case PROP_PROPERTY_CLASS: - g_value_set_pointer (value, eprop->klass); - break; - case PROP_USE_COMMAND: - g_value_set_boolean (value, eprop->use_command); - break; - case PROP_SHOW_INFO: - g_value_set_boolean (value, eprop->show_info); - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -glade_eprop_property_finalized (GladeEditorProperty *eprop, - GladeProperty *where_property_was) -{ - eprop->tooltip_id = 0; - eprop->sensitive_id = 0; - eprop->changed_id = 0; - eprop->enabled_id = 0; - eprop->property = NULL; - - glade_editor_property_load (eprop, NULL); -} - -static void -glade_editor_property_load_common (GladeEditorProperty *eprop, - GladeProperty *property) -{ - /* Hide properties that are removed for some particular widgets. - */ - if (property) - { - gtk_widget_show (GTK_WIDGET (eprop)); - gtk_widget_show (eprop->eventbox); - } - else - { - gtk_widget_hide (GTK_WIDGET (eprop)); - gtk_widget_hide (eprop->eventbox); - } - - /* disconnect anything from previously loaded property */ - if (eprop->property != property && eprop->property != NULL) - { - if (eprop->tooltip_id > 0) - g_signal_handler_disconnect (eprop->property, - eprop->tooltip_id); - if (eprop->sensitive_id > 0) - g_signal_handler_disconnect (eprop->property, - eprop->sensitive_id); - if (eprop->changed_id > 0) - g_signal_handler_disconnect (eprop->property, - eprop->changed_id); - if (eprop->enabled_id > 0) - g_signal_handler_disconnect (eprop->property, - eprop->enabled_id); - - eprop->tooltip_id = 0; - eprop->sensitive_id = 0; - eprop->changed_id = 0; - eprop->enabled_id = 0; - - /* Unref it here */ - g_object_weak_unref (G_OBJECT (eprop->property), - (GWeakNotify)glade_eprop_property_finalized, - eprop); - - - /* For a reason I cant quite tell yet, this is the only - * safe way to nullify the property member of the eprop - * without leeking signal connections to properties :-/ - */ - if (property == NULL) - { - eprop->property = NULL; - } - } - - /* Connect new stuff, deal with tooltip - */ - if (eprop->property != property && property != NULL) - { - eprop->property = property; - - eprop->tooltip_id = - g_signal_connect (G_OBJECT (eprop->property), - "tooltip-changed", - G_CALLBACK (glade_editor_property_tooltip_cb), - eprop); - eprop->sensitive_id = - g_signal_connect (G_OBJECT (eprop->property), - "notify::sensitive", - G_CALLBACK (glade_editor_property_sensitivity_cb), - eprop); - eprop->changed_id = - g_signal_connect (G_OBJECT (eprop->property), - "value-changed", - G_CALLBACK (glade_editor_property_value_changed_cb), - eprop); - eprop->enabled_id = - g_signal_connect (G_OBJECT (eprop->property), - "notify::enabled", - G_CALLBACK (glade_editor_property_enabled_cb), - eprop); - - /* In query dialogs when the user hits cancel, - * these babies go away (so better stay protected). - */ - g_object_weak_ref (G_OBJECT (eprop->property), - (GWeakNotify)glade_eprop_property_finalized, - eprop); - - /* Load initial tooltips - */ - glade_editor_property_tooltip_cb - (property, glade_property_get_tooltip (property), eprop); - - /* Load initial enabled state - */ - glade_editor_property_enabled_cb (property, NULL, eprop); - - /* Load initial sensitive state. - */ - glade_editor_property_sensitivity_cb (property, NULL, eprop); - } -} - -static void -glade_editor_property_init (GladeEditorProperty *eprop) -{ - -} - -static void -glade_editor_property_class_init (GladeEditorPropertyClass *eprop_class) -{ - GObjectClass *object_class; - g_return_if_fail (eprop_class != NULL); - - /* Both parent classes assigned here. - */ - editor_property_class = eprop_class; - table_class = g_type_class_peek_parent (eprop_class); - object_class = G_OBJECT_CLASS (eprop_class); - - /* GObjectClass */ - object_class->constructor = glade_editor_property_constructor; - object_class->finalize = glade_editor_property_finalize; - object_class->get_property = glade_editor_property_get_property; - object_class->set_property = glade_editor_property_set_property; - - /* Class methods */ - eprop_class->load = glade_editor_property_load_common; - eprop_class->create_input = NULL; - - /** - * GladeEditorProperty::gtk-doc-search: - * @gladeeditor: the #GladeEditorProperty which received the signal. - * @arg1: the (#gchar *) book to search or %NULL - * @arg2: the (#gchar *) page to search or %NULL - * @arg3: the (#gchar *) search string or %NULL - * - * Emitted when the editor property requests that a doc-search be performed. - */ - glade_editor_property_signals[GTK_DOC_SEARCH] = - g_signal_new ("gtk-doc-search", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GladeEditorPropertyClass, - gtk_doc_search), - NULL, NULL, - glade_marshal_VOID__STRING_STRING_STRING, - G_TYPE_NONE, 3, - G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); - - /* Properties */ - g_object_class_install_property - (object_class, PROP_PROPERTY_CLASS, - g_param_spec_pointer - ("property-class", _("Property Class"), - _("The GladePropertyClass this GladeEditorProperty was created for"), - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - - g_object_class_install_property - (object_class, PROP_USE_COMMAND, - g_param_spec_boolean - ("use-command", _("Use Command"), - _("Whether we should use the command API for the undo/redo stack"), - FALSE, G_PARAM_READWRITE)); - - g_object_class_install_property - (object_class, PROP_SHOW_INFO, - g_param_spec_boolean - ("show-info", _("Show Info"), - _("Whether we should show an informational button"), - FALSE, G_PARAM_READWRITE)); -} - - -GType -glade_editor_property_get_type (void) -{ - static GType property_type = 0; - - if (!property_type) - { - static const GTypeInfo property_info = - { - sizeof (GladeEditorPropertyClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) glade_editor_property_class_init, - (GClassFinalizeFunc) NULL, - NULL, /* class_data */ - sizeof (GladeEditorProperty), - 0, /* n_preallocs */ - (GInstanceInitFunc) glade_editor_property_init, - }; - property_type = - g_type_register_static (GTK_TYPE_HBOX, - "GladeEditorProperty", - &property_info, 0); - } - return property_type; -} - -/******************************************************************************* - GladeEditorPropertyNumericClass - *******************************************************************************/ -typedef struct { - GladeEditorProperty parent_instance; - - GtkWidget *spin; -} GladeEPropNumeric; - -GLADE_MAKE_EPROP (GladeEPropNumeric, glade_eprop_numeric) -#define GLADE_TYPE_EPROP_NUMERIC (glade_eprop_numeric_get_type()) -#define GLADE_EPROP_NUMERIC(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EPROP_NUMERIC, GladeEPropNumeric)) -#define GLADE_EPROP_NUMERIC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EPROP_NUMERIC, GladeEPropNumericClass)) -#define GLADE_IS_EPROP_NUMERIC(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_NUMERIC)) -#define GLADE_IS_EPROP_NUMERIC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_EPROP_NUMERIC)) -#define GLADE_EPROP_NUMERIC_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GLADE_EPROP_NUMERIC, GladeEPropNumericClass)) - -static void -glade_eprop_numeric_finalize (GObject *object) -{ - /* Chain up */ - G_OBJECT_CLASS (editor_property_class)->finalize (object); -} - -static void -glade_eprop_numeric_load (GladeEditorProperty *eprop, GladeProperty *property) -{ - gfloat val = 0.0F; - GladeEPropNumeric *eprop_numeric = GLADE_EPROP_NUMERIC (eprop); - - /* Chain up first */ - editor_property_class->load (eprop, property); - - if (property) - { - if (G_IS_PARAM_SPEC_INT(eprop->klass->pspec)) - val = (gfloat) g_value_get_int (property->value); - else if (G_IS_PARAM_SPEC_UINT(eprop->klass->pspec)) - val = (gfloat) g_value_get_uint (property->value); - else if (G_IS_PARAM_SPEC_LONG(eprop->klass->pspec)) - val = (gfloat) g_value_get_long (property->value); - else if (G_IS_PARAM_SPEC_ULONG(eprop->klass->pspec)) - val = (gfloat) g_value_get_ulong (property->value); - else if (G_IS_PARAM_SPEC_INT64(eprop->klass->pspec)) - val = (gfloat) g_value_get_int64 (property->value); - else if (G_IS_PARAM_SPEC_UINT64(eprop->klass->pspec)) - val = (gfloat) g_value_get_uint64 (property->value); - else if (G_IS_PARAM_SPEC_DOUBLE(eprop->klass->pspec)) - val = (gfloat) g_value_get_double (property->value); - else if (G_IS_PARAM_SPEC_FLOAT(eprop->klass->pspec)) - val = g_value_get_float (property->value); - else - g_warning ("Unsupported type %s\n", - g_type_name(G_PARAM_SPEC_TYPE (eprop->klass->pspec))); - gtk_spin_button_set_value (GTK_SPIN_BUTTON (eprop_numeric->spin), val); - } -} - - -static void -glade_eprop_numeric_changed (GtkWidget *spin, - GladeEditorProperty *eprop) -{ - GValue val = { 0, }; - - if (eprop->loading) return; - - g_value_init (&val, eprop->klass->pspec->value_type); - - if (G_IS_PARAM_SPEC_INT(eprop->klass->pspec)) - g_value_set_int (&val, gtk_spin_button_get_value_as_int - (GTK_SPIN_BUTTON (spin))); - else if (G_IS_PARAM_SPEC_UINT(eprop->klass->pspec)) - g_value_set_uint (&val, gtk_spin_button_get_value_as_int - (GTK_SPIN_BUTTON (spin))); - else if (G_IS_PARAM_SPEC_LONG(eprop->klass->pspec)) - g_value_set_long (&val, (glong)gtk_spin_button_get_value_as_int - (GTK_SPIN_BUTTON (spin))); - else if (G_IS_PARAM_SPEC_ULONG(eprop->klass->pspec)) - g_value_set_ulong (&val, (gulong)gtk_spin_button_get_value_as_int - (GTK_SPIN_BUTTON (spin))); - else if (G_IS_PARAM_SPEC_INT64(eprop->klass->pspec)) - g_value_set_int64 (&val, (gint64)gtk_spin_button_get_value_as_int - (GTK_SPIN_BUTTON (spin))); - else if (G_IS_PARAM_SPEC_UINT64(eprop->klass->pspec)) - g_value_set_uint64 (&val, (guint64)gtk_spin_button_get_value_as_int - (GTK_SPIN_BUTTON (spin))); - else if (G_IS_PARAM_SPEC_FLOAT(eprop->klass->pspec)) - g_value_set_float (&val, (gfloat) gtk_spin_button_get_value - (GTK_SPIN_BUTTON (spin))); - else if (G_IS_PARAM_SPEC_DOUBLE(eprop->klass->pspec)) - g_value_set_double (&val, gtk_spin_button_get_value - (GTK_SPIN_BUTTON (spin))); - else - g_warning ("Unsupported type %s\n", - g_type_name(G_PARAM_SPEC_TYPE (eprop->klass->pspec))); - - glade_editor_property_commit (eprop, &val); - g_value_unset (&val); -} - -static GtkWidget * -glade_eprop_numeric_create_input (GladeEditorProperty *eprop) -{ - GladeEPropNumeric *eprop_numeric = GLADE_EPROP_NUMERIC (eprop); - GtkAdjustment *adjustment; - - adjustment = glade_property_class_make_adjustment (eprop->klass); - eprop_numeric->spin = gtk_spin_button_new (adjustment, 4, - G_IS_PARAM_SPEC_FLOAT (eprop->klass->pspec) || - G_IS_PARAM_SPEC_DOUBLE (eprop->klass->pspec) - ? 2 : 0); - gtk_widget_show (eprop_numeric->spin); - - g_signal_connect (G_OBJECT (eprop_numeric->spin), "value_changed", - G_CALLBACK (glade_eprop_numeric_changed), - eprop); - - return eprop_numeric->spin; -} - -/******************************************************************************* - GladeEditorPropertyEnumClass - *******************************************************************************/ -typedef struct { - GladeEditorProperty parent_instance; - - GtkWidget *option_menu; -} GladeEPropEnum; - -GLADE_MAKE_EPROP (GladeEPropEnum, glade_eprop_enum) -#define GLADE_TYPE_EPROP_ENUM (glade_eprop_enum_get_type()) -#define GLADE_EPROP_ENUM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EPROP_ENUM, GladeEPropEnum)) -#define GLADE_EPROP_ENUM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EPROP_ENUM, GladeEPropEnumClass)) -#define GLADE_IS_EPROP_ENUM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_ENUM)) -#define GLADE_IS_EPROP_ENUM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_EPROP_ENUM)) -#define GLADE_EPROP_ENUM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GLADE_EPROP_ENUM, GladeEPropEnumClass)) - - -static void -glade_eprop_enum_finalize (GObject *object) -{ - /* Chain up */ - G_OBJECT_CLASS (editor_property_class)->finalize (object); -} - -static void -glade_eprop_enum_load (GladeEditorProperty *eprop, GladeProperty *property) -{ - GladeEPropEnum *eprop_enum = GLADE_EPROP_ENUM (eprop); - GEnumClass *eclass; - guint i; - gint value; - - /* Chain up first */ - editor_property_class->load (eprop, property); - - if (property) - { - eclass = g_type_class_ref (eprop->klass->pspec->value_type); - value = g_value_get_enum (property->value); - - for (i = 0; i < eclass->n_values; i++) - if (eclass->values[i].value == value) - break; - - gtk_option_menu_set_history (GTK_OPTION_MENU (eprop_enum->option_menu), - i < eclass->n_values ? i : 0); - g_type_class_unref (eclass); - } -} - -static void -glade_eprop_enum_changed (GtkWidget *menu_item, - GladeEditorProperty *eprop) -{ - gint ival; - GValue val = { 0, }; - GladeProperty *property; - - if (eprop->loading) return; - - ival = GPOINTER_TO_INT(g_object_get_data (G_OBJECT (menu_item), GLADE_ENUM_DATA_TAG)); - - property = eprop->property; - - g_value_init (&val, eprop->klass->pspec->value_type); - g_value_set_enum (&val, ival); - - glade_editor_property_commit (eprop, &val); - g_value_unset (&val); -} - -static GtkWidget * -glade_editor_create_input_enum_item (GladeEditorProperty *eprop, - const gchar *name, - gint value) -{ - GtkWidget *menu_item; - - menu_item = gtk_menu_item_new_with_label (name); - - g_signal_connect (G_OBJECT (menu_item), "activate", - G_CALLBACK (glade_eprop_enum_changed), - eprop); - - g_object_set_data (G_OBJECT (menu_item), GLADE_ENUM_DATA_TAG, GINT_TO_POINTER(value)); - - return menu_item; -} - -static GtkWidget * -glade_editor_create_input_stock_item (GladeEditorProperty *eprop, - const gchar *id, - gint value) -{ - GtkWidget *menu_item = gtk_image_menu_item_new_from_stock (id, NULL); - - g_signal_connect (G_OBJECT (menu_item), "activate", - G_CALLBACK (glade_eprop_enum_changed), - eprop); - - g_object_set_data (G_OBJECT (menu_item), GLADE_ENUM_DATA_TAG, GINT_TO_POINTER(value)); - - return menu_item; -} - -static GtkWidget * -glade_eprop_enum_create_input (GladeEditorProperty *eprop) -{ - GladeEPropEnum *eprop_enum = GLADE_EPROP_ENUM (eprop); - GtkWidget *menu_item, *menu; - GladePropertyClass *klass; - GEnumClass *eclass; - gboolean stock; - guint i; - - klass = eprop->klass; - eclass = g_type_class_ref (klass->pspec->value_type); - stock = (klass->pspec->value_type == GLADE_TYPE_STOCK) || - (klass->pspec->value_type == GLADE_TYPE_STOCK_IMAGE); - - menu = gtk_menu_new (); - - for (i = 0; i < eclass->n_values; i++) - { - const gchar *value_name = - glade_property_class_get_displayable_value - (klass, eclass->values[i].value); - if (value_name == NULL) value_name = eclass->values[i].value_name; - - if (stock && strcmp (eclass->values[i].value_nick, "glade-none")) - menu_item = glade_editor_create_input_stock_item - (eprop, - eclass->values[i].value_nick, - eclass->values[i].value); - else - menu_item = glade_editor_create_input_enum_item - (eprop, value_name, eclass->values[i].value); - - gtk_widget_show (menu_item); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item); - } - - eprop_enum->option_menu = gtk_option_menu_new (); - gtk_option_menu_set_menu (GTK_OPTION_MENU (eprop_enum->option_menu), menu); - - gtk_widget_show_all (eprop_enum->option_menu); - - g_type_class_unref (eclass); - - return eprop_enum->option_menu; -} - -/******************************************************************************* - GladeEditorPropertyFlagsClass - *******************************************************************************/ -typedef struct { - GladeEditorProperty parent_instance; - - GtkTreeModel *model; - GtkWidget *entry; -} GladeEPropFlags; - -GLADE_MAKE_EPROP (GladeEPropFlags, glade_eprop_flags) -#define GLADE_TYPE_EPROP_FLAGS (glade_eprop_flags_get_type()) -#define GLADE_EPROP_FLAGS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EPROP_FLAGS, GladeEPropFlags)) -#define GLADE_EPROP_FLAGS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EPROP_FLAGS, GladeEPropFlagsClass)) -#define GLADE_IS_EPROP_FLAGS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_FLAGS)) -#define GLADE_IS_EPROP_FLAGS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_EPROP_FLAGS)) -#define GLADE_EPROP_FLAGS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GLADE_EPROP_FLAGS, GladeEPropFlagsClass)) - -static void -glade_eprop_flags_finalize (GObject *object) -{ - GladeEPropFlags *eprop_flags = GLADE_EPROP_FLAGS(object); - - g_object_unref (G_OBJECT (eprop_flags->model)); - - /* Chain up */ - G_OBJECT_CLASS (editor_property_class)->finalize (object); -} - -static void -glade_eprop_flags_load (GladeEditorProperty *eprop, GladeProperty *property) -{ - GladeEPropFlags *eprop_flags = GLADE_EPROP_FLAGS (eprop); - GFlagsClass *klass; - guint flag_num, value; - GString *string = g_string_new (NULL); - - /* Chain up first */ - editor_property_class->load (eprop, property); - - gtk_list_store_clear(GTK_LIST_STORE(eprop_flags->model)); - - if (property) - { - /* Populate the model with the flags. */ - klass = g_type_class_ref (G_VALUE_TYPE (property->value)); - value = g_value_get_flags (property->value); - - /* Step through each of the flags in the class. */ - for (flag_num = 0; flag_num < klass->n_values; flag_num++) { - GtkTreeIter iter; - guint mask; - gboolean setting; - const gchar *value_name; - - mask = klass->values[flag_num].value; - setting = ((value & mask) == mask) ? TRUE : FALSE; - - value_name = glade_property_class_get_displayable_value - (eprop->klass, klass->values[flag_num].value); - - if (value_name == NULL) value_name = klass->values[flag_num].value_name; - - /* Setup string for property label */ - if (setting) - { - if (string->len > 0) - g_string_append (string, " | "); - g_string_append (string, value_name); - } - - /* Add a row to represent the flag. */ - gtk_list_store_append (GTK_LIST_STORE(eprop_flags->model), &iter); - gtk_list_store_set (GTK_LIST_STORE(eprop_flags->model), &iter, - FLAGS_COLUMN_SETTING, - setting, - FLAGS_COLUMN_SYMBOL, - value_name, - -1); - - } - g_type_class_unref(klass); - } - - gtk_entry_set_text (GTK_ENTRY (eprop_flags->entry), string->str); - - g_string_free (string, TRUE); -} - - -static void -flag_toggled_direct (GtkCellRendererToggle *cell, - gchar *path_string, - GladeEditorProperty *eprop) -{ - GtkTreeIter iter; - guint new_value = 0; - gboolean selected; - guint value = 0; - gint flag_num = 0; - GFlagsClass *klass; - - GladeEPropFlags *eprop_flags = GLADE_EPROP_FLAGS(eprop); - - if (!eprop->property) - return ; - - klass = g_type_class_ref (G_VALUE_TYPE (eprop->property->value)); - value = g_value_get_flags (eprop->property->value); - - gtk_tree_model_get_iter_from_string (eprop_flags->model, &iter, path_string); - - gtk_tree_model_get (eprop_flags->model, &iter, - FLAGS_COLUMN_SETTING, &selected, - -1); - - selected = selected ? FALSE : TRUE; - - gtk_list_store_set (GTK_LIST_STORE (eprop_flags->model), &iter, - FLAGS_COLUMN_SETTING, selected, - -1); - - - gtk_tree_model_get_iter_first (GTK_TREE_MODEL (eprop_flags->model), &iter); - - /* Step through each of the flags in the class, checking if - the corresponding toggle in the dialog is selected, If it - is, OR the flags' mask with the new value. */ - for (flag_num = 0; flag_num < klass->n_values; flag_num++) { - gboolean setting; - - gtk_tree_model_get (GTK_TREE_MODEL (eprop_flags->model), &iter, - FLAGS_COLUMN_SETTING, &setting, - -1); - - if (setting) - new_value |= klass->values[flag_num].value; - - gtk_tree_model_iter_next (GTK_TREE_MODEL (eprop_flags->model), - &iter); - } - - /* If the new_value is different from the old value, we need - to update the property. */ - if (new_value != value) { - GValue val = { 0, }; - - g_value_init (&val, G_VALUE_TYPE (eprop->property->value)); - g_value_set_flags (&val, new_value); - - glade_editor_property_commit (eprop, &val); - g_value_unset (&val); - } - - - -} - -static GtkWidget* -glade_eprop_flags_create_treeview(GladeEditorProperty *eprop) -{ - GtkWidget *scrolled_window; - GtkWidget *tree_view; - GtkTreeViewColumn *column; - GtkCellRenderer *renderer; - GladeEPropFlags *eprop_flags=GLADE_EPROP_FLAGS(eprop); - if (!eprop_flags->model) - eprop_flags->model = GTK_TREE_MODEL(gtk_list_store_new (2, G_TYPE_BOOLEAN, - G_TYPE_STRING)); - - - scrolled_window = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), - GTK_SHADOW_IN); - gtk_widget_show (scrolled_window); - - - - tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (eprop_flags->model)); - gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), FALSE); - gtk_widget_show (tree_view); - gtk_container_add (GTK_CONTAINER (scrolled_window), tree_view); - - column = gtk_tree_view_column_new (); - - renderer = gtk_cell_renderer_toggle_new (); - gtk_tree_view_column_pack_start (column, renderer, FALSE); - gtk_tree_view_column_set_attributes (column, renderer, - "active", FLAGS_COLUMN_SETTING, - NULL); - - g_signal_connect (renderer, "toggled", - G_CALLBACK (flag_toggled_direct), eprop); - - - renderer = gtk_cell_renderer_text_new (); - gtk_tree_view_column_pack_start (column, renderer, TRUE); - gtk_tree_view_column_set_attributes (column, renderer, - "text", FLAGS_COLUMN_SYMBOL, - NULL); - - gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column); - - - - return scrolled_window; -} - -static void -glade_eprop_flags_show_dialog (GtkWidget *button, - GladeEditorProperty *eprop) -{ - GtkWidget *dialog; - GtkWidget *view; - GtkWidget *label; - GtkWidget *vbox; - - dialog = gtk_dialog_new_with_buttons (_("Select Fields"), - GTK_WINDOW (gtk_widget_get_toplevel (button)), - GTK_DIALOG_MODAL, - GTK_STOCK_CLOSE, - GTK_RESPONSE_CLOSE, - NULL); - - gtk_window_set_default_size (GTK_WINDOW (dialog), 300, 400); - gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); - gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE); - - /* HIG spacings */ - gtk_container_set_border_width (GTK_CONTAINER (dialog), 5); - gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 2); /* 2 * 5 + 2 = 12 */ - gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area), 5); - gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->action_area), 6); - - vbox = gtk_vbox_new (FALSE, 6); - gtk_container_set_border_width (GTK_CONTAINER (vbox), 5); - - view = glade_eprop_flags_create_treeview (eprop); - - label = gtk_label_new_with_mnemonic (_("_Select individual fields:")); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), gtk_bin_get_child (GTK_BIN (view))); - - gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (vbox), view, TRUE, TRUE, 0); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), vbox, TRUE, TRUE, 0); - - gtk_widget_show (label); - gtk_widget_show (view); - gtk_widget_show (vbox); - - gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); -} - - -static GtkWidget * -glade_eprop_flags_create_input (GladeEditorProperty *eprop) -{ - GtkWidget *vbox, *hbox, *button, *widget; - GladeEPropFlags *eprop_flags = GLADE_EPROP_FLAGS(eprop); - - hbox = gtk_hbox_new (FALSE, 0); - vbox = gtk_vbox_new (FALSE, 0); - - widget = glade_eprop_flags_create_treeview (eprop); - - eprop_flags->entry = gtk_entry_new (); - gtk_entry_set_editable (GTK_ENTRY (eprop_flags->entry), FALSE); - - gtk_box_pack_start (GTK_BOX (vbox), eprop_flags->entry, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (vbox), widget, TRUE, TRUE, 0); - gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0); - - button = gtk_button_new_with_label ("..."); - gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); - - gtk_widget_show_all (hbox); - - g_signal_connect (G_OBJECT (button), "clicked", - G_CALLBACK (glade_eprop_flags_show_dialog), - eprop); - - return hbox; -} - -/******************************************************************************* - GladeEditorPropertyColorClass - *******************************************************************************/ -typedef struct { - GladeEditorProperty parent_instance; - - GtkWidget *cbutton; - GtkWidget *entry; -} GladeEPropColor; - -GLADE_MAKE_EPROP (GladeEPropColor, glade_eprop_color) -#define GLADE_TYPE_EPROP_COLOR (glade_eprop_color_get_type()) -#define GLADE_EPROP_COLOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EPROP_COLOR, GladeEPropColor)) -#define GLADE_EPROP_COLOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EPROP_COLOR, GladeEPropColorClass)) -#define GLADE_IS_EPROP_COLOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_COLOR)) -#define GLADE_IS_EPROP_COLOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_EPROP_COLOR)) -#define GLADE_EPROP_COLOR_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GLADE_EPROP_COLOR, GladeEPropColorClass)) - - -static void -glade_eprop_color_finalize (GObject *object) -{ - /* Chain up */ - G_OBJECT_CLASS (editor_property_class)->finalize (object); -} - -static void -glade_eprop_color_load (GladeEditorProperty *eprop, GladeProperty *property) -{ - GladeEPropColor *eprop_color = GLADE_EPROP_COLOR (eprop); - GdkColor *color; - gchar *text; - - /* Chain up first */ - editor_property_class->load (eprop, property); - - if (property) - { - if ((text = glade_property_class_make_string_from_gvalue - (eprop->klass, property->value)) != NULL) - { - gtk_entry_set_text (GTK_ENTRY (eprop_color->entry), text); - g_free (text); - } - else - gtk_entry_set_text (GTK_ENTRY (eprop_color->entry), ""); - - if ((color = g_value_get_boxed (property->value)) != NULL) - gtk_color_button_set_color (GTK_COLOR_BUTTON (eprop_color->cbutton), - color); - else - { - GdkColor black = { 0, }; - - /* Manually fill it with black for an NULL value. - */ - if (gdk_color_parse("Black", &black) && - gdk_colormap_alloc_color(gtk_widget_get_default_colormap(), - &black, FALSE, TRUE)) - gtk_color_button_set_color - (GTK_COLOR_BUTTON (eprop_color->cbutton), - &black); - } - } -} - -static void -glade_eprop_color_changed (GtkWidget *button, - GladeEditorProperty *eprop) -{ - GdkColor color = { 0, }; - GValue value = { 0, }; - - if (eprop->loading) return; - - gtk_color_button_get_color (GTK_COLOR_BUTTON (button), &color); - - g_value_init (&value, GDK_TYPE_COLOR); - g_value_set_boxed (&value, &color); - - glade_editor_property_commit (eprop, &value); - g_value_unset (&value); -} - -static GtkWidget * -glade_eprop_color_create_input (GladeEditorProperty *eprop) -{ - GladeEPropColor *eprop_color = GLADE_EPROP_COLOR (eprop); - GtkWidget *hbox; - - hbox = gtk_hbox_new (FALSE, 0); - - eprop_color->entry = gtk_entry_new (); - gtk_entry_set_editable (GTK_ENTRY (eprop_color->entry), FALSE); - gtk_widget_show (eprop_color->entry); - gtk_box_pack_start (GTK_BOX (hbox), eprop_color->entry, TRUE, TRUE, 0); - - eprop_color->cbutton = gtk_color_button_new (); - gtk_widget_show (eprop_color->cbutton); - gtk_box_pack_start (GTK_BOX (hbox), eprop_color->cbutton, FALSE, FALSE, 0); - - g_signal_connect (G_OBJECT (eprop_color->cbutton), "color-set", - G_CALLBACK (glade_eprop_color_changed), - eprop); - - return hbox; -} - -/******************************************************************************* - GladeEditorPropertyTextClass - *******************************************************************************/ -typedef struct { - GladeEditorProperty parent_instance; - - GtkWidget *text_entry; -} GladeEPropText; - -GLADE_MAKE_EPROP (GladeEPropText, glade_eprop_text) -#define GLADE_TYPE_EPROP_TEXT (glade_eprop_text_get_type()) -#define GLADE_EPROP_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EPROP_TEXT, GladeEPropText)) -#define GLADE_EPROP_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EPROP_TEXT, GladeEPropTextClass)) -#define GLADE_IS_EPROP_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_TEXT)) -#define GLADE_IS_EPROP_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_EPROP_TEXT)) -#define GLADE_EPROP_TEXT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GLADE_EPROP_TEXT, GladeEPropTextClass)) - -static void -glade_eprop_text_finalize (GObject *object) -{ - /* Chain up */ - G_OBJECT_CLASS (editor_property_class)->finalize (object); -} - -static void -glade_eprop_text_load (GladeEditorProperty *eprop, GladeProperty *property) -{ - GladeEPropText *eprop_text = GLADE_EPROP_TEXT (eprop); - - /* Chain up first */ - editor_property_class->load (eprop, property); - - if (property == NULL) return; - - if (GTK_IS_ENTRY (eprop_text->text_entry)) - { - GtkEntry *entry = GTK_ENTRY (eprop_text->text_entry); - const gchar *text = g_value_get_string (property->value); - - gtk_entry_set_text (entry, text ? text : ""); - - } - else if (GTK_IS_TEXT_VIEW (eprop_text->text_entry)) - { - GtkTextBuffer *buffer; - - buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (eprop_text->text_entry)); - - if (G_VALUE_HOLDS (property->value, G_TYPE_STRV) || - G_VALUE_HOLDS (property->value, G_TYPE_VALUE_ARRAY)) - { - gchar *text = glade_property_class_make_string_from_gvalue ( - property->klass, property->value); - gtk_text_buffer_set_text (buffer, text ? text : "", -1); - g_free (text); - } - else - { - const gchar *text = g_value_get_string (property->value); - gtk_text_buffer_set_text (buffer, text ? text : "", -1); - } - } - else - { - g_warning ("BUG! Invalid Text Widget type."); - } -} - -static void -glade_eprop_text_changed_common (GladeEditorProperty *eprop, - const gchar *text, - gboolean use_command) -{ - GValue *val; - gchar *prop_text; - - if (eprop->property->klass->pspec->value_type == G_TYPE_STRV || - eprop->property->klass->pspec->value_type == G_TYPE_VALUE_ARRAY) - { - val = glade_property_class_make_gvalue_from_string - (eprop->property->klass, text, NULL); - } - else - { - val = g_new0 (GValue, 1); - - g_value_init (val, G_TYPE_STRING); - - glade_property_get (eprop->property, &prop_text); - - /* Here we try not to modify the project state by not - * modifying a null value for an unchanged property. - */ - if (prop_text == NULL && - text && text[0] == '\0') - g_value_set_string (val, NULL); - else if (text == NULL && - prop_text && prop_text == '\0') - g_value_set_string (val, ""); - else - g_value_set_string (val, text); - } - - glade_editor_property_commit (eprop, val); - g_value_unset (val); - g_free (val); -} - -static void -glade_eprop_text_changed (GtkWidget *entry, - GladeEditorProperty *eprop) -{ - gchar *text; - - if (eprop->loading) return; - - text = gtk_editable_get_chars (GTK_EDITABLE (entry), 0, -1); - glade_eprop_text_changed_common (eprop, text, eprop->use_command); - - g_free (text); -} - -static gboolean -glade_eprop_text_entry_focus_out (GtkWidget *entry, - GdkEventFocus *event, - GladeEditorProperty *eprop) -{ - glade_eprop_text_changed (entry, eprop); - return FALSE; -} - -static gboolean -glade_eprop_text_text_view_focus_out (GtkTextView *view, - GdkEventFocus *event, - GladeEditorProperty *eprop) -{ - gchar *text; - GtkTextBuffer *buffer; - GtkTextIter start, end; - - if (eprop->loading) return FALSE; - - buffer = gtk_text_view_get_buffer (view); - - gtk_text_buffer_get_start_iter (buffer, &start); - gtk_text_buffer_get_end_iter (buffer, &end); - - text = gtk_text_buffer_get_text (buffer, &start, &end, FALSE); - - glade_eprop_text_changed_common (eprop, text, eprop->use_command); - - g_free (text); - return FALSE; -} - -static void -glade_eprop_text_show_i18n_dialog (GtkWidget *entry, - GladeEditorProperty *eprop) -{ - GtkWidget *dialog; - GtkWidget *vbox, *hbox; - GtkWidget *label; - GtkWidget *sw; - GtkWidget *alignment; - GtkWidget *text_view, *comment_view; - GtkTextBuffer *text_buffer, *comment_buffer; - GtkWidget *translatable_button, *context_button; - const gchar *text; - gint res; - gchar *str; - GParamSpec *pspec; - - dialog = gtk_dialog_new_with_buttons (_("Edit Text"), - GTK_WINDOW (gtk_widget_get_toplevel (entry)), - GTK_DIALOG_MODAL, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OK, GTK_RESPONSE_OK, - NULL); - - gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); - gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); - - gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog), - GTK_RESPONSE_OK, - GTK_RESPONSE_CANCEL, - -1); - - /* HIG spacings */ - gtk_container_set_border_width (GTK_CONTAINER (dialog), 5); - gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 2); /* 2 * 5 + 2 = 12 */ - gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area), 5); - gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->action_area), 6); - - - vbox = gtk_vbox_new (FALSE, 6); - gtk_container_set_border_width (GTK_CONTAINER (vbox), 5); - gtk_widget_show (vbox); - - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), vbox, TRUE, TRUE, 0); - - /* Text */ - label = gtk_label_new_with_mnemonic (_("_Text:")); - gtk_widget_show (label); - gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); - gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); - - sw = gtk_scrolled_window_new (NULL, NULL); - gtk_widget_show (sw); - gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0); - gtk_widget_set_size_request (sw, 400, 200); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN); - - text_view = gtk_text_view_new (); - gtk_widget_show (text_view); - - gtk_label_set_mnemonic_widget (GTK_LABEL (label), text_view); - - gtk_container_add (GTK_CONTAINER (sw), text_view); - - text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view)); - - text = g_value_get_string (eprop->property->value); - if (text) - { - gtk_text_buffer_set_text (text_buffer, - text, - -1); - } - - /* Translatable and context prefix. */ - hbox = gtk_hbox_new (FALSE, 12); - gtk_widget_show (hbox); - - gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); - - translatable_button = gtk_check_button_new_with_mnemonic (_("T_ranslatable")); - gtk_widget_show (translatable_button); - gtk_box_pack_start (GTK_BOX (hbox), translatable_button, FALSE, FALSE, 0); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (translatable_button), - glade_property_i18n_get_translatable (eprop->property)); - - /* Add a cute tooltip */ - if ((pspec = - g_object_class_find_property (G_OBJECT_GET_CLASS (eprop->property), - "i18n-translatable")) != NULL) - glade_util_widget_set_tooltip (translatable_button, - g_param_spec_get_blurb (pspec)); - - context_button = gtk_check_button_new_with_mnemonic (_("_Has context prefix")); - gtk_widget_show (context_button); - gtk_box_pack_start (GTK_BOX (hbox), context_button, FALSE, FALSE, 0); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (context_button), - glade_property_i18n_get_has_context (eprop->property)); - - /* Add a cute tooltip */ - if ((pspec = - g_object_class_find_property (G_OBJECT_GET_CLASS (eprop->property), - "i18n-has-context")) != NULL) - glade_util_widget_set_tooltip (context_button, - g_param_spec_get_blurb (pspec)); - - alignment = gtk_alignment_new (0.5, 0.5, 1, 1); - gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 12, 0, 0, 0); - gtk_widget_show (alignment); - - /* Comments. */ - label = gtk_label_new_with_mnemonic (_("Co_mments for translators:")); - gtk_widget_show (label); - gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); - gtk_container_add (GTK_CONTAINER (alignment), label); - gtk_box_pack_start (GTK_BOX (vbox), alignment, FALSE, FALSE, 0); - - sw = gtk_scrolled_window_new (NULL, NULL); - gtk_widget_show (sw); - gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN); - - comment_view = gtk_text_view_new (); - gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (comment_view), GTK_WRAP_WORD); - gtk_widget_show (comment_view); - - gtk_label_set_mnemonic_widget (GTK_LABEL (label), comment_view); - - gtk_container_add (GTK_CONTAINER (sw), comment_view); - - comment_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (comment_view)); - - text = glade_property_i18n_get_comment (eprop->property); - if (text) - { - gtk_text_buffer_set_text (comment_buffer, - text, - -1); - } - - res = gtk_dialog_run (GTK_DIALOG (dialog)); - if (res == GTK_RESPONSE_OK) { - GtkTextIter start, end; - gboolean translatable, has_context; - - /* get the new values for translatable, has_context, and comment */ - translatable = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (translatable_button)); - has_context = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (context_button)); - - gtk_text_buffer_get_bounds (comment_buffer, &start, &end); - str = gtk_text_buffer_get_text (comment_buffer, &start, &end, TRUE); - if (str[0] == '\0') - { - g_free (str); - str = NULL; - } - - /* set the new i18n data via a glade command so it can be undone */ - glade_command_set_i18n (eprop->property, translatable, has_context, str); - g_free (str); - - /* Text */ - gtk_text_buffer_get_bounds (text_buffer, &start, &end); - str = gtk_text_buffer_get_text (text_buffer, &start, &end, TRUE); - if (str[0] == '\0') - { - g_free (str); - str = NULL; - } - - /* set the new text */ - glade_eprop_text_changed_common (eprop, str, eprop->use_command); - g_free (str); - - } - - gtk_widget_destroy (dialog); -} - -static GtkWidget * -glade_eprop_text_create_input (GladeEditorProperty *eprop) -{ - GladeEPropText *eprop_text = GLADE_EPROP_TEXT (eprop); - GladePropertyClass *klass; - GtkWidget *hbox; - - klass = eprop->klass; - - hbox = gtk_hbox_new (FALSE, 0); - - if (klass->visible_lines > 1 || - klass->pspec->value_type == G_TYPE_STRV || - klass->pspec->value_type == G_TYPE_VALUE_ARRAY) - { - GtkWidget *swindow; - - swindow = gtk_scrolled_window_new (NULL, NULL); - - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swindow), GTK_SHADOW_IN); - - eprop_text->text_entry = gtk_text_view_new (); - - gtk_container_add (GTK_CONTAINER (swindow), eprop_text->text_entry); - gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (swindow), TRUE, TRUE, 0); - - gtk_widget_show_all (swindow); - - g_signal_connect (G_OBJECT (eprop_text->text_entry), "focus-out-event", - G_CALLBACK (glade_eprop_text_text_view_focus_out), - eprop); - } else { - eprop_text->text_entry = gtk_entry_new (); - gtk_widget_show (eprop_text->text_entry); - - gtk_box_pack_start (GTK_BOX (hbox), eprop_text->text_entry, TRUE, TRUE, 0); - - g_signal_connect (G_OBJECT (eprop_text->text_entry), "activate", - G_CALLBACK (glade_eprop_text_changed), - eprop); - - g_signal_connect (G_OBJECT (eprop_text->text_entry), "focus-out-event", - G_CALLBACK (glade_eprop_text_entry_focus_out), - eprop); - } - - if (klass->translatable) { - GtkWidget *button = gtk_button_new_with_label ("..."); - gtk_widget_show (button); - gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); - g_signal_connect (button, "clicked", - G_CALLBACK (glade_eprop_text_show_i18n_dialog), - eprop); - } - return hbox; -} - -/******************************************************************************* - GladeEditorPropertyBoolClass - *******************************************************************************/ -typedef struct { - GladeEditorProperty parent_instance; - - GtkWidget *toggle; -} GladeEPropBool; - -GLADE_MAKE_EPROP (GladeEPropBool, glade_eprop_bool) -#define GLADE_TYPE_EPROP_BOOL (glade_eprop_bool_get_type()) -#define GLADE_EPROP_BOOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EPROP_BOOL, GladeEPropBool)) -#define GLADE_EPROP_BOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EPROP_BOOL, GladeEPropBoolClass)) -#define GLADE_IS_EPROP_BOOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_BOOL)) -#define GLADE_IS_EPROP_BOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_EPROP_BOOL)) -#define GLADE_EPROP_BOOL_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GLADE_EPROP_BOOL, GladeEPropBoolClass)) - -static void -glade_eprop_bool_finalize (GObject *object) -{ - /* Chain up */ - G_OBJECT_CLASS (editor_property_class)->finalize (object); -} - -static void -glade_eprop_bool_load (GladeEditorProperty *eprop, GladeProperty *property) -{ - GladeEPropBool *eprop_bool = GLADE_EPROP_BOOL (eprop); - GtkWidget *label; - gboolean state; - - /* Chain up first */ - editor_property_class->load (eprop, property); - - if (property) - { - state = g_value_get_boolean (property->value); - - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (eprop_bool->toggle), state); - - label = GTK_BIN (eprop_bool->toggle)->child; - gtk_label_set_text (GTK_LABEL (label), state ? _("Yes") : _("No")); - } -} - -static void -glade_eprop_bool_changed (GtkWidget *button, - GladeEditorProperty *eprop) -{ - GtkWidget *label; - gboolean state; - GValue val = { 0, }; - - if (eprop->loading) return; - - state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)); - label = GTK_BIN (button)->child; - gtk_label_set_text (GTK_LABEL (label), state ? _("Yes") : _("No")); - - g_value_init (&val, G_TYPE_BOOLEAN); - g_value_set_boolean (&val, state); - - glade_editor_property_commit (eprop, &val); - - g_value_unset (&val); -} - -static GtkWidget * -glade_eprop_bool_create_input (GladeEditorProperty *eprop) -{ - GladeEPropBool *eprop_bool = GLADE_EPROP_BOOL (eprop); - - eprop_bool->toggle = gtk_toggle_button_new_with_label (_("No")); - - g_signal_connect (G_OBJECT (eprop_bool->toggle), "toggled", - G_CALLBACK (glade_eprop_bool_changed), - eprop); - - return eprop_bool->toggle; -} - - -/******************************************************************************* - GladeEditorPropertyUnicharClass - *******************************************************************************/ -typedef struct { - GladeEditorProperty parent_instance; - - GtkWidget *entry; -} GladeEPropUnichar; - -GLADE_MAKE_EPROP (GladeEPropUnichar, glade_eprop_unichar) -#define GLADE_TYPE_EPROP_UNICHAR (glade_eprop_unichar_get_type()) -#define GLADE_EPROP_UNICHAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EPROP_UNICHAR, GladeEPropUnichar)) -#define GLADE_EPROP_UNICHAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EPROP_UNICHAR, GladeEPropUnicharClass)) -#define GLADE_IS_EPROP_UNICHAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_UNICHAR)) -#define GLADE_IS_EPROP_UNICHAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_EPROP_UNICHAR)) -#define GLADE_EPROP_UNICHAR_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GLADE_EPROP_UNICHAR, GladeEPropUnicharClass)) - -static void -glade_eprop_unichar_finalize (GObject *object) -{ - /* Chain up */ - G_OBJECT_CLASS (editor_property_class)->finalize (object); -} - -static void -glade_eprop_unichar_load (GladeEditorProperty *eprop, GladeProperty *property) -{ - GladeEPropUnichar *eprop_unichar = GLADE_EPROP_UNICHAR (eprop); - - /* Chain up first */ - editor_property_class->load (eprop, property); - - if (property && GTK_IS_ENTRY (eprop_unichar->entry)) - { - GtkEntry *entry = GTK_ENTRY (eprop_unichar->entry); - gchar utf8st[8]; - gint n; - - if ((n = g_unichar_to_utf8 (g_value_get_uint (property->value), utf8st))) - { - utf8st[n] = '\0'; - gtk_entry_set_text (entry, utf8st); - } - } -} - - -static void -glade_eprop_unichar_changed (GtkWidget *entry, - GladeEditorProperty *eprop) -{ - const gchar *text; - - if (eprop->loading) return; - - if ((text = gtk_entry_get_text (GTK_ENTRY (entry))) != NULL) - { - gunichar unich = g_utf8_get_char (text); - GValue val = { 0, }; - - g_value_init (&val, G_TYPE_UINT); - g_value_set_uint (&val, unich); - - glade_editor_property_commit (eprop, &val); - - g_value_unset (&val); - } -} - -static void -glade_eprop_unichar_delete (GtkEditable *editable, - gint start_pos, - gint end_pos, - GladeEditorProperty *eprop) -{ - if (eprop->loading) return; - gtk_editable_select_region (editable, 0, -1); - g_signal_stop_emission_by_name (G_OBJECT (editable), "delete_text"); -} - -static void -glade_eprop_unichar_insert (GtkWidget *entry, - const gchar *text, - gint length, - gint *position, - GladeEditorProperty *eprop) -{ - if (eprop->loading) return; - g_signal_handlers_block_by_func - (G_OBJECT (entry), G_CALLBACK (glade_eprop_unichar_changed), eprop); - g_signal_handlers_block_by_func - (G_OBJECT (entry), G_CALLBACK (glade_eprop_unichar_insert), eprop); - g_signal_handlers_block_by_func - (G_OBJECT (entry), G_CALLBACK (glade_eprop_unichar_delete), eprop); - - gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1); - *position = 0; - gtk_editable_insert_text (GTK_EDITABLE (entry), text, 1, position); - - g_signal_handlers_unblock_by_func - (G_OBJECT (entry), G_CALLBACK (glade_eprop_unichar_changed), eprop); - g_signal_handlers_unblock_by_func - (G_OBJECT (entry), G_CALLBACK (glade_eprop_unichar_insert), eprop); - g_signal_handlers_unblock_by_func - (G_OBJECT (entry), G_CALLBACK (glade_eprop_unichar_delete), eprop); - - g_signal_stop_emission_by_name (G_OBJECT (entry), "insert_text"); - - glade_eprop_unichar_changed (entry, eprop); -} - -static GtkWidget * -glade_eprop_unichar_create_input (GladeEditorProperty *eprop) -{ - GladeEPropUnichar *eprop_unichar = GLADE_EPROP_UNICHAR (eprop); - - eprop_unichar->entry = gtk_entry_new (); - - /* it's 2 to prevent spirious beeps... */ - gtk_entry_set_max_length (GTK_ENTRY (eprop_unichar->entry), 2); - - g_signal_connect (G_OBJECT (eprop_unichar->entry), "changed", - G_CALLBACK (glade_eprop_unichar_changed), eprop); - g_signal_connect (G_OBJECT (eprop_unichar->entry), "insert_text", - G_CALLBACK (glade_eprop_unichar_insert), eprop); - g_signal_connect (G_OBJECT (eprop_unichar->entry), "delete_text", - G_CALLBACK (glade_eprop_unichar_delete), eprop); - return eprop_unichar->entry; -} - -/******************************************************************************* - GladeEditorPropertyResourceClass - *******************************************************************************/ -typedef struct { - GladeEditorProperty parent_instance; - - GtkWidget *entry, *button; -} GladeEPropResource; - -GLADE_MAKE_EPROP (GladeEPropResource, glade_eprop_resource) -#define GLADE_TYPE_EPROP_RESOURCE (glade_eprop_resource_get_type()) -#define GLADE_EPROP_RESOURCE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EPROP_RESOURCE, GladeEPropResource)) -#define GLADE_EPROP_RESOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EPROP_RESOURCE, GladeEPropResourceClass)) -#define GLADE_IS_EPROP_RESOURCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_RESOURCE)) -#define GLADE_IS_EPROP_RESOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_EPROP_RESOURCE)) -#define GLADE_EPROP_RESOURCE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GLADE_EPROP_RESOURCE, GladeEPropResourceClass)) - -static void -glade_eprop_resource_finalize (GObject *object) -{ - /* Chain up */ - G_OBJECT_CLASS (editor_property_class)->finalize (object); -} - -static void -glade_eprop_resource_entry_activate (GtkEntry *entry, GladeEditorProperty *eprop) -{ - GladeProject *project = glade_widget_get_project (eprop->property->widget); - GValue *value = glade_property_class_make_gvalue_from_string - (eprop->klass, gtk_entry_get_text(entry), project); - - /* Set project resource here where we still have the fullpath. - */ - glade_project_set_resource (project, eprop->property, - gtk_entry_get_text(entry)); - - glade_editor_property_commit (eprop, value); - - g_value_unset (value); - g_free (value); -} - -static gboolean -glade_eprop_resource_entry_focus_out (GtkWidget *entry, - GdkEventFocus *event, - GladeEditorProperty *eprop) -{ - glade_eprop_resource_entry_activate (GTK_ENTRY (entry), eprop); - return FALSE; -} - -static void -glade_eprop_resource_select_file (GtkButton *button, GladeEditorProperty *eprop) -{ - GladeProject *project = glade_widget_get_project (eprop->property->widget); - GtkWidget *dialog; - GtkFileFilter *filter; - GValue *value; - gchar *file, *basename; - - if (eprop->loading) return; - - dialog = gtk_file_chooser_dialog_new ("Select a File", - NULL, - GTK_FILE_CHOOSER_ACTION_OPEN, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, - NULL); - - gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog), TRUE); - - if (eprop->klass->pspec->value_type == GDK_TYPE_PIXBUF) - { - filter = gtk_file_filter_new (); - gtk_file_filter_add_pixbuf_formats (filter); - gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter); - } - - if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) - { - file = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); - - /* Set project resource here where we still have the fullpath. - */ - glade_project_set_resource (project, eprop->property, file); - basename = g_path_get_basename (file); - - value = glade_property_class_make_gvalue_from_string - (eprop->klass, basename, project); - - glade_editor_property_commit (eprop, value); - - g_value_unset (value); - g_free (value); - g_free (file); - g_free (basename); - } - gtk_widget_destroy (dialog); -} - -static void -glade_eprop_resource_load (GladeEditorProperty *eprop, GladeProperty *property) -{ - GladeEPropResource *eprop_resource = GLADE_EPROP_RESOURCE (eprop); - gchar *file; - - /* Chain up first */ - editor_property_class->load (eprop, property); - - if (property == NULL) return; - - file = glade_property_class_make_string_from_gvalue - (eprop->klass, property->value); - if (file) - { - gtk_entry_set_text (GTK_ENTRY (eprop_resource->entry), file); - g_free (file); - } - else - { - gtk_entry_set_text (GTK_ENTRY (eprop_resource->entry), ""); - } -} - -static GtkWidget * -glade_eprop_resource_create_input (GladeEditorProperty *eprop) -{ - GladeEPropResource *eprop_resource = GLADE_EPROP_RESOURCE (eprop); - GtkWidget *hbox; - - hbox = gtk_hbox_new (FALSE, 0); - - eprop_resource->entry = gtk_entry_new (); - gtk_widget_show (eprop_resource->entry); - - eprop_resource->button = gtk_button_new_with_label ("..."); - gtk_widget_show (eprop_resource->button); - - gtk_box_pack_start (GTK_BOX (hbox), eprop_resource->entry, TRUE, TRUE, 0); - gtk_box_pack_start (GTK_BOX (hbox), eprop_resource->button, FALSE, FALSE, 0); - - g_signal_connect (G_OBJECT (eprop_resource->entry), "activate", - G_CALLBACK (glade_eprop_resource_entry_activate), - eprop); - g_signal_connect (G_OBJECT (eprop_resource->entry), "focus-out-event", - G_CALLBACK (glade_eprop_resource_entry_focus_out), - eprop); - g_signal_connect (G_OBJECT (eprop_resource->button), "clicked", - G_CALLBACK (glade_eprop_resource_select_file), - eprop); - - return hbox; -} - - -/******************************************************************************* - GladeEditorPropertyObjectClass - *******************************************************************************/ -enum { - OBJ_COLUMN_WIDGET = 0, - OBJ_COLUMN_WIDGET_NAME, - OBJ_COLUMN_WIDGET_CLASS, - OBJ_COLUMN_SELECTED, - OBJ_COLUMN_SELECTABLE, - OBJ_NUM_COLUMNS -}; - -#define GLADE_RESPONSE_CLEAR 42 - -typedef struct { - GladeEditorProperty parent_instance; - - GtkWidget *entry; -} GladeEPropObject; - -GLADE_MAKE_EPROP (GladeEPropObject, glade_eprop_object) -#define GLADE_TYPE_EPROP_OBJECT (glade_eprop_object_get_type()) -#define GLADE_EPROP_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EPROP_OBJECT, GladeEPropObject)) -#define GLADE_EPROP_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EPROP_OBJECT, GladeEPropObjectClass)) -#define GLADE_IS_EPROP_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_OBJECT)) -#define GLADE_IS_EPROP_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_EPROP_OBJECT)) -#define GLADE_EPROP_OBJECT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GLADE_EPROP_OBJECT, GladeEPropObjectClass)) - -static void -glade_eprop_object_finalize (GObject *object) -{ - /* Chain up */ - G_OBJECT_CLASS (editor_property_class)->finalize (object); -} - - -static gchar * -glade_eprop_object_name (const gchar *name, - GtkTreeStore *model, - GtkTreeIter *parent_iter) -{ - GtkTreePath *path; - GString *string; - gint i; - - string = g_string_new (name); - - if (parent_iter) - { - path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), parent_iter); - for (i = 0; i < gtk_tree_path_get_depth (path); i++) - g_string_prepend (string, " "); - } - - return g_string_free (string, FALSE); -} - -static gboolean -glade_eprop_object_is_selected (GladeEditorProperty *eprop, - GladeWidget *widget) -{ - GList *list; - - if (GLADE_IS_PARAM_SPEC_OBJECTS (eprop->klass->pspec)) - { - glade_property_get (eprop->property, &list); - return g_list_find (list, widget->object) != NULL; - } - return glade_property_equals (eprop->property, widget->object); -} - - -/* - * Note that widgets is a list of GtkWidgets, while what we store - * in the model are the associated GladeWidgets. - */ -static void -glade_eprop_object_populate_view_real (GladeEditorProperty *eprop, - GtkTreeStore *model, - GList *widgets, - GtkTreeIter *parent_iter) -{ - GList *children, *list; - GtkTreeIter iter; - gboolean good_type, has_decendant; - - for (list = widgets; list; list = list->next) - { - GladeWidget *widget; - - if ((widget = glade_widget_get_from_gobject (list->data)) != NULL) - { - - if (GLADE_IS_PARAM_SPEC_OBJECTS (eprop->klass->pspec)) - { - has_decendant = glade_widget_has_decendant - (widget, - glade_param_spec_objects_get_type - (GLADE_PARAM_SPEC_OBJECTS(eprop->klass->pspec))); - good_type = - glade_util_class_implements_interface - (widget->adaptor->type, - glade_param_spec_objects_get_type - (GLADE_PARAM_SPEC_OBJECTS(eprop->klass->pspec))); - } - else - { - has_decendant = glade_widget_has_decendant - (widget, eprop->klass->pspec->value_type); - - good_type = g_type_is_a (widget->adaptor->type, - eprop->klass->pspec->value_type); - - } - - if (good_type || has_decendant) - { - gtk_tree_store_append (model, &iter, parent_iter); - gtk_tree_store_set - (model, &iter, - OBJ_COLUMN_WIDGET, widget, - OBJ_COLUMN_WIDGET_NAME, - glade_eprop_object_name (widget->name, model, parent_iter), - OBJ_COLUMN_WIDGET_CLASS, - widget->adaptor->title, - /* Selectable if its a compatible type and - * its not itself. - */ - OBJ_COLUMN_SELECTABLE, - good_type && (widget != eprop->property->widget), - OBJ_COLUMN_SELECTED, - good_type && glade_eprop_object_is_selected - (eprop, widget), -1); - } - - if (has_decendant && - (children = glade_widget_adaptor_get_children - (widget->adaptor, widget->object)) != NULL) - { - GtkTreeIter *copy = NULL; - - copy = gtk_tree_iter_copy (&iter); - glade_eprop_object_populate_view_real (eprop, model, children, copy); - gtk_tree_iter_free (copy); - - g_list_free (children); - } - } - } -} - -static void -glade_eprop_object_populate_view (GladeEditorProperty *eprop, - GtkTreeView *view) -{ - GtkTreeStore *model = (GtkTreeStore *)gtk_tree_view_get_model (view); - GladeProject *project = glade_app_get_project (); - GList *list, *toplevels = NULL; - - /* Make a list of only the toplevel widgets */ - for (list = (GList *) glade_project_get_objects (project); list; list = list->next) - { - GObject *object = G_OBJECT (list->data); - GladeWidget *gwidget = glade_widget_get_from_gobject (object); - g_assert (gwidget); - - if (gwidget->parent == NULL) - toplevels = g_list_append (toplevels, object); - } - - /* add the widgets and recurse */ - glade_eprop_object_populate_view_real (eprop, model, toplevels, NULL); - g_list_free (toplevels); -} - -static gboolean -glade_eprop_object_clear_iter (GtkTreeModel *model, - GtkTreePath *path, - GtkTreeIter *iter, - gpointer data) -{ - gtk_tree_store_set (GTK_TREE_STORE (model), iter, - OBJ_COLUMN_SELECTED, FALSE, -1); - return FALSE; -} - -static gboolean -glade_eprop_object_selected_widget (GtkTreeModel *model, - GtkTreePath *path, - GtkTreeIter *iter, - GladeWidget **ret) -{ - gboolean selected; - GladeWidget *widget; - - gtk_tree_model_get (model, iter, - OBJ_COLUMN_SELECTED, &selected, - OBJ_COLUMN_WIDGET, &widget, -1); - - if (selected) - { - *ret = widget; - return TRUE; - } - return FALSE; -} - -static void -glade_eprop_object_selected (GtkCellRendererToggle *cell, - gchar *path_str, - GtkTreeModel *model) -{ - GtkTreePath *path = gtk_tree_path_new_from_string (path_str); - GtkTreeIter iter; - gboolean enabled, radio; - - radio = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (model), "radio-list")); - - gtk_tree_model_get_iter (model, &iter, path); - gtk_tree_model_get (model, &iter, - OBJ_COLUMN_SELECTED, &enabled, -1); - - /* Clear the rest of the view first - */ - if (radio) - gtk_tree_model_foreach (model, glade_eprop_object_clear_iter, NULL); - - gtk_tree_store_set (GTK_TREE_STORE (model), &iter, - OBJ_COLUMN_SELECTED, - radio ? TRUE : !enabled, -1); - - gtk_tree_path_free (path); -} - -static GtkWidget * -glade_eprop_object_view (GladeEditorProperty *eprop, - gboolean radio) -{ - GtkWidget *view_widget; - GtkTreeModel *model; - GtkCellRenderer *renderer; - GtkTreeViewColumn *column; - - model = (GtkTreeModel *)gtk_tree_store_new - (OBJ_NUM_COLUMNS, - G_TYPE_OBJECT, /* The GladeWidget */ - G_TYPE_STRING, /* The GladeWidget's name */ - G_TYPE_STRING, /* The GladeWidgetClass title */ - G_TYPE_BOOLEAN, /* Whether this row is selected or not */ - G_TYPE_BOOLEAN); /* Whether this GladeWidget is - * of an acceptable type and - * therefore can be selected. - */ - - g_object_set_data (G_OBJECT (model), "radio-list", GINT_TO_POINTER (radio)); - - view_widget = gtk_tree_view_new_with_model (model); - - /* Pass ownership to the view */ - g_object_unref (G_OBJECT (model)); - g_object_set (G_OBJECT (view_widget), "enable-search", FALSE, NULL); - - /********************* fake invisible column *********************/ - renderer = gtk_cell_renderer_text_new (); - g_object_set (G_OBJECT (renderer), "editable", FALSE, "visible", FALSE, NULL); - - column = gtk_tree_view_column_new_with_attributes (NULL, renderer, NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (view_widget), column); - - gtk_tree_view_column_set_visible (column, FALSE); - gtk_tree_view_set_expander_column (GTK_TREE_VIEW (view_widget), column); - - /************************ selected column ************************/ - renderer = gtk_cell_renderer_toggle_new (); - g_object_set (G_OBJECT (renderer), - "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE, - "activatable", TRUE, - "radio", radio, - NULL); - g_signal_connect (renderer, "toggled", - G_CALLBACK (glade_eprop_object_selected), model); - gtk_tree_view_insert_column_with_attributes - (GTK_TREE_VIEW (view_widget), 0, - NULL, renderer, - "visible", OBJ_COLUMN_SELECTABLE, - "sensitive", OBJ_COLUMN_SELECTABLE, - "active", OBJ_COLUMN_SELECTED, - NULL); - - /********************* widget name column *********************/ - renderer = gtk_cell_renderer_text_new (); - g_object_set (G_OBJECT (renderer), "editable", FALSE, NULL); - gtk_tree_view_insert_column_with_attributes - (GTK_TREE_VIEW (view_widget), 1, - _("Name"), renderer, - "text", OBJ_COLUMN_WIDGET_NAME, - NULL); - - /***************** widget class title column ******************/ - renderer = gtk_cell_renderer_text_new (); - g_object_set (G_OBJECT (renderer), - "editable", FALSE, - "style", PANGO_STYLE_ITALIC, - "foreground", "Gray", NULL); - gtk_tree_view_insert_column_with_attributes - (GTK_TREE_VIEW (view_widget), 2, - _("Class"), renderer, - "text", OBJ_COLUMN_WIDGET_CLASS, - NULL); - - return view_widget; -} - - -static gchar * -glade_eprop_object_dialog_title (GladeEditorProperty *eprop) -{ - GladeWidgetAdaptor *adaptor; - const gchar *format = - GLADE_IS_PARAM_SPEC_OBJECTS (eprop->klass->pspec) ? - _("Choose %s implementors") : _("Choose a %s in this project"); - - if (GLADE_IS_PARAM_SPEC_OBJECTS (eprop->klass->pspec)) - return g_strdup_printf (format, g_type_name - (glade_param_spec_objects_get_type - (GLADE_PARAM_SPEC_OBJECTS (eprop->klass->pspec)))); - else if ((adaptor = - glade_widget_adaptor_get_by_type - (eprop->klass->pspec->value_type)) != NULL) - return g_strdup_printf (format, adaptor->title); - - /* Fallback on type name (which would look like "GtkButton" - * instead of "Button" and maybe not translated). - */ - return g_strdup_printf (format, g_type_name - (eprop->klass->pspec->value_type)); -} - -static void -glade_eprop_object_show_dialog (GtkWidget *dialog_button, - GladeEditorProperty *eprop) -{ - GtkWidget *dialog, *parent; - GtkWidget *vbox, *label, *sw; - GtkWidget *tree_view; - GladeProject *project; - gchar *title = glade_eprop_object_dialog_title (eprop); - gint res; - - - project = glade_widget_get_project (eprop->property->widget); - parent = gtk_widget_get_toplevel (GTK_WIDGET (eprop)); - - dialog = gtk_dialog_new_with_buttons (title, - GTK_WINDOW (parent), - GTK_DIALOG_MODAL, - GTK_STOCK_CLEAR, GLADE_RESPONSE_CLEAR, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OK, GTK_RESPONSE_OK, - NULL); - g_free (title); - - gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog), - GTK_RESPONSE_OK, - GTK_RESPONSE_CANCEL, - GLADE_RESPONSE_CLEAR, - -1); - - gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); - gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); - - /* HIG settings */ - gtk_container_set_border_width (GTK_CONTAINER (dialog), 5); - gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 2); /* 2 * 5 + 2 = 12 */ - gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area), 5); - gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->action_area), 6); - - vbox = gtk_vbox_new (FALSE, 6); - gtk_widget_show (vbox); - - gtk_container_set_border_width (GTK_CONTAINER (vbox), 5); - - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), vbox, TRUE, TRUE, 0); - - /* Checklist */ - label = gtk_label_new_with_mnemonic (_("O_bjects:")); - gtk_widget_show (label); - gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); - gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); - - sw = gtk_scrolled_window_new (NULL, NULL); - gtk_widget_show (sw); - gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0); - gtk_widget_set_size_request (sw, 400, 200); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN); - - - tree_view = glade_eprop_object_view (eprop, TRUE); - glade_eprop_object_populate_view (eprop, GTK_TREE_VIEW (tree_view)); - - - gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view)); - - gtk_widget_show (tree_view); - gtk_container_add (GTK_CONTAINER (sw), tree_view); - - gtk_label_set_mnemonic_widget (GTK_LABEL (label), tree_view); - - - /* Run the dialog */ - res = gtk_dialog_run (GTK_DIALOG (dialog)); - if (res == GTK_RESPONSE_OK) - { - GladeWidget *selected = NULL; - - gtk_tree_model_foreach - (gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view)), - (GtkTreeModelForeachFunc) - glade_eprop_object_selected_widget, &selected); - - if (selected) - { - GValue *value = glade_property_class_make_gvalue_from_string - (eprop->klass, selected->name, project); - - glade_editor_property_commit (eprop, value); - - g_value_unset (value); - g_free (value); - } - } - else if (res == GLADE_RESPONSE_CLEAR) - { - GValue *value = glade_property_class_make_gvalue_from_string - (eprop->klass, NULL, project); - - glade_editor_property_commit (eprop, value); - - g_value_unset (value); - g_free (value); - } - - gtk_widget_destroy (dialog); -} - - -static void -glade_eprop_object_load (GladeEditorProperty *eprop, GladeProperty *property) -{ - GladeEPropObject *eprop_object = GLADE_EPROP_OBJECT (eprop); - gchar *obj_name; - - /* Chain up first */ - editor_property_class->load (eprop, property); - - if (property == NULL) return; - - if ((obj_name = glade_property_class_make_string_from_gvalue - (eprop->klass, property->value)) != NULL) - { - gtk_entry_set_text (GTK_ENTRY (eprop_object->entry), obj_name); - g_free (obj_name); - } - else - gtk_entry_set_text (GTK_ENTRY (eprop_object->entry), ""); - -} - -static GtkWidget * -glade_eprop_object_create_input (GladeEditorProperty *eprop) -{ - GladeEPropObject *eprop_object = GLADE_EPROP_OBJECT (eprop); - GtkWidget *hbox; - GtkWidget *button; - - hbox = gtk_hbox_new (FALSE, 0); - eprop_object->entry = gtk_entry_new (); - gtk_entry_set_editable (GTK_ENTRY (eprop_object->entry), FALSE); - gtk_widget_show (eprop_object->entry); - gtk_box_pack_start (GTK_BOX (hbox), eprop_object->entry, TRUE, TRUE, 0); - - button = gtk_button_new_with_label ("..."); - gtk_widget_show (button); - gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); - - g_signal_connect (G_OBJECT (button), "clicked", - G_CALLBACK (glade_eprop_object_show_dialog), - eprop); - return hbox; -} - - -/******************************************************************************* - GladeEditorPropertyObjectsClass - *******************************************************************************/ - -typedef struct { - GladeEditorProperty parent_instance; - - GtkWidget *entry; -} GladeEPropObjects; - -GLADE_MAKE_EPROP (GladeEPropObjects, glade_eprop_objects) -#define GLADE_TYPE_EPROP_OBJECTS (glade_eprop_objects_get_type()) -#define GLADE_EPROP_OBJECTS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EPROP_OBJECTS, GladeEPropObjects)) -#define GLADE_EPROP_OBJECTS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EPROP_OBJECTS, GladeEPropObjectsClass)) -#define GLADE_IS_EPROP_OBJECTS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_OBJECTS)) -#define GLADE_IS_EPROP_OBJECTS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_EPROP_OBJECTS)) -#define GLADE_EPROP_OBJECTS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GLADE_EPROP_OBJECTS, GladeEPropObjectsClass)) - -static void -glade_eprop_objects_finalize (GObject *object) -{ - /* Chain up */ - G_OBJECT_CLASS (editor_property_class)->finalize (object); -} - -static void -glade_eprop_objects_load (GladeEditorProperty *eprop, GladeProperty *property) -{ - GladeEPropObjects *eprop_objects = GLADE_EPROP_OBJECTS (eprop); - gchar *obj_name; - - /* Chain up first */ - editor_property_class->load (eprop, property); - - if (property == NULL) return; - - if ((obj_name = glade_property_class_make_string_from_gvalue - (eprop->klass, property->value)) != NULL) - { - gtk_entry_set_text (GTK_ENTRY (eprop_objects->entry), obj_name); - g_free (obj_name); - } - else - gtk_entry_set_text (GTK_ENTRY (eprop_objects->entry), ""); - -} - -static gboolean -glade_eprop_objects_selected_widget (GtkTreeModel *model, - GtkTreePath *path, - GtkTreeIter *iter, - GList **ret) -{ - gboolean selected; - GladeWidget *widget; - - gtk_tree_model_get (model, iter, - OBJ_COLUMN_SELECTED, &selected, - OBJ_COLUMN_WIDGET, &widget, -1); - - if (selected) - *ret = g_list_append (*ret, widget->object); - - return FALSE; -} - -static void -glade_eprop_objects_show_dialog (GtkWidget *dialog_button, - GladeEditorProperty *eprop) -{ - GtkWidget *dialog, *parent; - GtkWidget *vbox, *label, *sw; - GtkWidget *tree_view; - GladeProject *project; - gchar *title = glade_eprop_object_dialog_title (eprop); - gint res; - - - project = glade_widget_get_project (eprop->property->widget); - parent = gtk_widget_get_toplevel (GTK_WIDGET (eprop)); - - - dialog = gtk_dialog_new_with_buttons (title, - GTK_WINDOW (parent), - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_STOCK_CLEAR, GLADE_RESPONSE_CLEAR, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OK, GTK_RESPONSE_OK, - NULL); - g_free (title); - gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); - - vbox = gtk_vbox_new (FALSE, 6); - gtk_widget_show (vbox); - - gtk_container_set_border_width (GTK_CONTAINER (vbox), 6); - - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), vbox, TRUE, TRUE, 0); - - /* Checklist */ - label = gtk_label_new (_("Objects:")); - gtk_widget_show (label); - gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); - gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); - - sw = gtk_scrolled_window_new (NULL, NULL); - gtk_widget_show (sw); - gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0); - gtk_widget_set_size_request (sw, 400, 200); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN); - - tree_view = glade_eprop_object_view (eprop, FALSE); - glade_eprop_object_populate_view (eprop, GTK_TREE_VIEW (tree_view)); - - gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view)); - - gtk_widget_show (tree_view); - gtk_container_add (GTK_CONTAINER (sw), tree_view); - - /* Run the dialog */ - res = gtk_dialog_run (GTK_DIALOG (dialog)); - if (res == GTK_RESPONSE_OK) - { - GValue *value; - GList *selected = NULL; - - gtk_tree_model_foreach - (gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view)), - (GtkTreeModelForeachFunc) - glade_eprop_objects_selected_widget, &selected); - - value = glade_property_class_make_gvalue - (eprop->klass, selected); - - glade_editor_property_commit (eprop, value); - - g_value_unset (value); - g_free (value); - } - else if (res == GLADE_RESPONSE_CLEAR) - { - GValue *value = glade_property_class_make_gvalue - (eprop->klass, NULL); - - glade_editor_property_commit (eprop, value); - - g_value_unset (value); - g_free (value); - } - gtk_widget_destroy (dialog); -} - -static GtkWidget * -glade_eprop_objects_create_input (GladeEditorProperty *eprop) -{ - GladeEPropObjects *eprop_objects = GLADE_EPROP_OBJECTS (eprop); - GtkWidget *hbox; - GtkWidget *button; - - hbox = gtk_hbox_new (FALSE, 0); - eprop_objects->entry = gtk_entry_new (); - gtk_entry_set_editable (GTK_ENTRY (eprop_objects->entry), FALSE); - gtk_widget_show (eprop_objects->entry); - gtk_box_pack_start (GTK_BOX (hbox), eprop_objects->entry, TRUE, TRUE, 0); - - button = gtk_button_new_with_label ("..."); - gtk_widget_show (button); - gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); - - g_signal_connect (G_OBJECT (button), "clicked", - G_CALLBACK (glade_eprop_objects_show_dialog), - eprop); - return hbox; -} - - -/******************************************************************************* - GladeEditorPropertyAdjustmentClass - *******************************************************************************/ -typedef struct { - GladeEditorProperty parent_instance; - - GtkWidget *value, *lower, *upper, *step_increment, *page_increment, *page_size; - GtkAdjustment *value_adj; - struct - { - gulong value, lower, upper, step_increment, page_increment, page_size; - }ids; -} GladeEPropAdjustment; - -GLADE_MAKE_EPROP (GladeEPropAdjustment, glade_eprop_adjustment) -#define GLADE_TYPE_EPROP_ADJUSTMENT (glade_eprop_adjustment_get_type()) -#define GLADE_EPROP_ADJUSTMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EPROP_ADJUSTMENT, GladeEPropAdjustment)) -#define GLADE_EPROP_ADJUSTMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EPROP_ADJUSTMENT, GladeEPropAdjustmentClass)) -#define GLADE_IS_EPROP_ADJUSTMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_ADJUSTMENT)) -#define GLADE_IS_EPROP_ADJUSTMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_EPROP_ADJUSTMENT)) -#define GLADE_EPROP_ADJUSTMENT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GLADE_EPROP_ADJUSTMENT, GladeEPropAdjustmentClass)) - -static void -glade_eprop_adjustment_finalize (GObject *object) -{ - /* Chain up */ - G_OBJECT_CLASS (editor_property_class)->finalize (object); -} - -typedef struct _EPropAdjIdle EPropAdjIdleData; - -struct _EPropAdjIdle -{ - GladeEditorProperty *eprop; - gdouble value; -}; - -static gboolean -glade_eprop_adj_set_value_idle (gpointer p) -{ - EPropAdjIdleData *data = (EPropAdjIdleData *) p; - GladeEPropAdjustment *eprop_adj = GLADE_EPROP_ADJUSTMENT (data->eprop); - - gtk_spin_button_set_value (GTK_SPIN_BUTTON (eprop_adj->value), data->value); - - g_free (p); - - return FALSE; -} - -static void -glade_eprop_adj_value_changed (GtkAdjustment *adj, GladeEditorProperty *eprop) -{ - EPropAdjIdleData *data; - - g_signal_handlers_disconnect_by_func (adj, glade_eprop_adj_value_changed, eprop); - - /* Don`t do anything if the loaded property is not the same */ - if (adj != g_value_get_object (eprop->property->value)) return; - - data = g_new (EPropAdjIdleData, 1); - - data->eprop = eprop; - data->value = adj->value; - - /* Update GladeEPropAdjustment value spinbutton in an idle funtion */ - g_idle_add (glade_eprop_adj_set_value_idle, data); - - /* Set adjustment to the old value */ - adj->value = gtk_spin_button_get_value (GTK_SPIN_BUTTON ( - GLADE_EPROP_ADJUSTMENT (eprop)->value)); -} - -static void -glade_eprop_adjustment_load (GladeEditorProperty *eprop, GladeProperty *property) -{ - GladeEPropAdjustment *eprop_adj = GLADE_EPROP_ADJUSTMENT (eprop); - GObject *object; - GtkAdjustment *adj; - - /* Chain up first */ - editor_property_class->load (eprop, property); - - if (property == NULL) return; - - object = g_value_get_object (property->value); - if (object == NULL) return; - - adj = GTK_ADJUSTMENT (object); - - /* Keep track of external adjustment changes */ - g_signal_connect (object, "value-changed", - G_CALLBACK (glade_eprop_adj_value_changed), - eprop); - - /* Update adjustment's values */ - eprop_adj->value_adj->lower = adj->lower; - eprop_adj->value_adj->upper = adj->upper; - eprop_adj->value_adj->step_increment = adj->step_increment; - eprop_adj->value_adj->page_increment = adj->page_increment; - eprop_adj->value_adj->page_size = adj->page_size; - - /* Block Handlers */ - g_signal_handler_block (eprop_adj->value, eprop_adj->ids.value); - g_signal_handler_block (eprop_adj->lower, eprop_adj->ids.lower); - g_signal_handler_block (eprop_adj->upper, eprop_adj->ids.upper); - g_signal_handler_block (eprop_adj->step_increment, eprop_adj->ids.step_increment); - g_signal_handler_block (eprop_adj->page_increment, eprop_adj->ids.page_increment); - g_signal_handler_block (eprop_adj->page_size, eprop_adj->ids.page_size); - - /* Update spinbuttons values */ - gtk_spin_button_set_value (GTK_SPIN_BUTTON (eprop_adj->value), adj->value); - gtk_spin_button_set_value (GTK_SPIN_BUTTON (eprop_adj->lower), adj->lower); - gtk_spin_button_set_value (GTK_SPIN_BUTTON (eprop_adj->upper), adj->upper); - gtk_spin_button_set_value (GTK_SPIN_BUTTON (eprop_adj->step_increment), adj->step_increment); - gtk_spin_button_set_value (GTK_SPIN_BUTTON (eprop_adj->page_increment), adj->page_increment); - gtk_spin_button_set_value (GTK_SPIN_BUTTON (eprop_adj->page_size), adj->page_size); - - /* Unblock Handlers */ - g_signal_handler_unblock (eprop_adj->value, eprop_adj->ids.value); - g_signal_handler_unblock (eprop_adj->lower, eprop_adj->ids.lower); - g_signal_handler_unblock (eprop_adj->upper, eprop_adj->ids.upper); - g_signal_handler_unblock (eprop_adj->step_increment, eprop_adj->ids.step_increment); - g_signal_handler_unblock (eprop_adj->page_increment, eprop_adj->ids.page_increment); - g_signal_handler_unblock (eprop_adj->page_size, eprop_adj->ids.page_size); -} - -static GtkAdjustment * -glade_eprop_adjustment_dup_adj (GladeEditorProperty *eprop) -{ - GtkAdjustment *adj; - GObject *object; - - object = g_value_get_object (eprop->property->value); - if (object == NULL) return NULL; - - adj = GTK_ADJUSTMENT (object); - - return GTK_ADJUSTMENT (gtk_adjustment_new (adj->value, - adj->lower, - adj->upper, - adj->step_increment, - adj->page_increment, - adj->page_size)); -} - -static void -glade_eprop_adjustment_prop_changed_common (GladeEditorProperty *eprop, - GtkAdjustment *adjustment) -{ - GValue value = {0, }; - - g_value_init (&value, GTK_TYPE_ADJUSTMENT); - g_value_set_object (&value, G_OBJECT (adjustment)); - - glade_editor_property_commit (eprop, &value); - - g_value_unset (&value); -} - -#define GLADE_EPROP_ADJUSTMENT_DEFINE_VALUE_CHANGED_FUNC(p) \ -static void \ -glade_eprop_adjustment_ ## p ## _changed (GtkSpinButton *spin, \ - GladeEditorProperty *eprop) \ -{ \ - GtkAdjustment *adj = glade_eprop_adjustment_dup_adj (eprop); \ - if (adj == NULL) return; \ - adj->p = gtk_spin_button_get_value (spin); \ - glade_eprop_adjustment_prop_changed_common (eprop, adj); \ -} - -GLADE_EPROP_ADJUSTMENT_DEFINE_VALUE_CHANGED_FUNC (value) -GLADE_EPROP_ADJUSTMENT_DEFINE_VALUE_CHANGED_FUNC (lower) -GLADE_EPROP_ADJUSTMENT_DEFINE_VALUE_CHANGED_FUNC (upper) -GLADE_EPROP_ADJUSTMENT_DEFINE_VALUE_CHANGED_FUNC (step_increment) -GLADE_EPROP_ADJUSTMENT_DEFINE_VALUE_CHANGED_FUNC (page_increment) -GLADE_EPROP_ADJUSTMENT_DEFINE_VALUE_CHANGED_FUNC (page_size) - -#define GLADE_EPROP_ADJUSTMENT_CONNECT(object, prop) \ -g_signal_connect (object, "value_changed", \ -G_CALLBACK (glade_eprop_adjustment_ ## prop ## _changed), eprop); - -static void -glade_eprop_adjustment_table_add_label (GtkTable *table, - gint pos, - gchar *label, - gchar *tip) -{ - GtkWidget *widget, *eventbox = gtk_event_box_new (); - - widget = gtk_label_new (label); - gtk_misc_set_alignment (GTK_MISC (widget), 1, 0); - - gtk_container_add (GTK_CONTAINER (eventbox), widget); - - glade_util_widget_set_tooltip (eventbox, tip); - - gtk_table_attach_defaults (table, eventbox, 0, 1, pos, pos + 1); -} - -static GtkWidget * -glade_eprop_adjustment_create_input (GladeEditorProperty *eprop) -{ - GladeEPropAdjustment *eprop_adj = GLADE_EPROP_ADJUSTMENT (eprop); - GtkWidget *widget; - GtkTable *table; - - eprop_adj->value = gtk_spin_button_new_with_range (-G_MAXDOUBLE, G_MAXDOUBLE, 1); - gtk_spin_button_set_digits (GTK_SPIN_BUTTON (eprop_adj->value), 2); - eprop_adj->ids.value = GLADE_EPROP_ADJUSTMENT_CONNECT (eprop_adj->value, value); - eprop_adj->value_adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (eprop_adj->value)); - - eprop_adj->lower = gtk_spin_button_new_with_range (-G_MAXDOUBLE, G_MAXDOUBLE, 1); - gtk_spin_button_set_digits (GTK_SPIN_BUTTON (eprop_adj->lower), 2); - eprop_adj->ids.lower = GLADE_EPROP_ADJUSTMENT_CONNECT (eprop_adj->lower, lower); - - eprop_adj->upper = gtk_spin_button_new_with_range (-G_MAXDOUBLE, G_MAXDOUBLE, 1); - gtk_spin_button_set_digits (GTK_SPIN_BUTTON (eprop_adj->upper), 2); - eprop_adj->ids.upper = GLADE_EPROP_ADJUSTMENT_CONNECT (eprop_adj->upper, upper); - - eprop_adj->step_increment = gtk_spin_button_new_with_range (0, G_MAXDOUBLE, 1); - gtk_spin_button_set_digits (GTK_SPIN_BUTTON (eprop_adj->step_increment), 2); - eprop_adj->ids.step_increment = GLADE_EPROP_ADJUSTMENT_CONNECT (eprop_adj->step_increment, step_increment); - - eprop_adj->page_increment = gtk_spin_button_new_with_range (0, G_MAXDOUBLE, 1); - gtk_spin_button_set_digits (GTK_SPIN_BUTTON (eprop_adj->page_increment), 2); - eprop_adj->ids.page_increment = GLADE_EPROP_ADJUSTMENT_CONNECT (eprop_adj->page_increment, page_increment); - - eprop_adj->page_size = gtk_spin_button_new_with_range (0, G_MAXDOUBLE, 1); - gtk_spin_button_set_digits (GTK_SPIN_BUTTON (eprop_adj->page_size), 2); - eprop_adj->ids.page_size = GLADE_EPROP_ADJUSTMENT_CONNECT (eprop_adj->page_size, page_size); - - /* Eprop */ - widget = gtk_table_new (6, 2, FALSE); - table = GTK_TABLE (widget); - gtk_table_set_col_spacings (table, 4); - - glade_eprop_adjustment_table_add_label (table, 0, _("Value:"), - _("The current value")); - - glade_eprop_adjustment_table_add_label (table, 1, _("Lower:"), - _("The minimum value")); - - glade_eprop_adjustment_table_add_label (table, 2, _("Upper:"), - _("The maximum value")); - - glade_eprop_adjustment_table_add_label (table, 3, _("Step inc:"), - _("The increment to use to make minor changes to the value")); - - glade_eprop_adjustment_table_add_label (table, 4, _("Page inc:"), - _("The increment to use to make major changes to the value")); - - glade_eprop_adjustment_table_add_label (table, 5, _("Page size:"), - _("The page size (in a GtkScrollbar this is the size of the area which is currently visible)")); - - gtk_table_attach_defaults (table, eprop_adj->value, 1, 2, 0, 1); - gtk_table_attach_defaults (table, eprop_adj->lower, 1, 2, 1, 2); - gtk_table_attach_defaults (table, eprop_adj->upper, 1, 2, 2, 3); - gtk_table_attach_defaults (table, eprop_adj->step_increment, 1, 2, 3, 4); - gtk_table_attach_defaults (table, eprop_adj->page_increment, 1, 2, 4, 5); - gtk_table_attach_defaults (table, eprop_adj->page_size, 1, 2, 5, 6); - - gtk_widget_show_all (widget); - - return widget; -} - - -/******************************************************************************* - GladeEditorPropertyAccelClass - *******************************************************************************/ -enum { - ACCEL_COLUMN_SIGNAL = 0, - ACCEL_COLUMN_REAL_SIGNAL, - ACCEL_COLUMN_KEY, - ACCEL_COLUMN_MOD_SHIFT, - ACCEL_COLUMN_MOD_CNTL, - ACCEL_COLUMN_MOD_ALT, - ACCEL_COLUMN_IS_CLASS, - ACCEL_COLUMN_IS_SIGNAL, - ACCEL_COLUMN_KEY_ENTERED, - ACCEL_COLUMN_KEY_SLOT, - ACCEL_NUM_COLUMNS -}; - -enum { - ACCEL_COMBO_COLUMN_TEXT = 0, - ACCEL_COMBO_NUM_COLUMNS, -}; - -typedef struct { - GladeEditorProperty parent_instance; - - GtkWidget *entry; - GList *parent_iters; - GtkTreeModel *model; -} GladeEPropAccel; - -typedef struct { - GtkTreeIter *iter; - gchar *name; /* <-- dont free */ -} GladeEpropIterTab; - - -static GtkTreeModel *keysyms_model = NULL; - -GLADE_MAKE_EPROP (GladeEPropAccel, glade_eprop_accel) -#define GLADE_TYPE_EPROP_ACCEL (glade_eprop_accel_get_type()) -#define GLADE_EPROP_ACCEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EPROP_ACCEL, GladeEPropAccel)) -#define GLADE_EPROP_ACCEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EPROP_ACCEL, GladeEPropAccelClass)) -#define GLADE_IS_EPROP_ACCEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_ACCEL)) -#define GLADE_IS_EPROP_ACCEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_EPROP_ACCEL)) -#define GLADE_EPROP_ACCEL_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GLADE_EPROP_ACCEL, GladeEPropAccelClass)) - - -static GtkTreeModel * -create_keysyms_model (void) -{ - GtkTreeModel *model; - GtkTreeIter iter, alphanum, fkey, keypad, other, extra; - GtkTreeIter *parent; - gint i; - - model = (GtkTreeModel *)gtk_tree_store_new - (ACCEL_COMBO_NUM_COLUMNS, - G_TYPE_STRING); /* The Key charachter name */ - - gtk_tree_store_append (GTK_TREE_STORE (model), &alphanum, NULL); - gtk_tree_store_set - (GTK_TREE_STORE (model), &alphanum, - ACCEL_COMBO_COLUMN_TEXT, _("Alphanumerical"), -1); - - gtk_tree_store_append (GTK_TREE_STORE (model), &extra, NULL); - gtk_tree_store_set - (GTK_TREE_STORE (model), &extra, - ACCEL_COMBO_COLUMN_TEXT, _("Extra"), -1); - - gtk_tree_store_append (GTK_TREE_STORE (model), &keypad, NULL); - gtk_tree_store_set - (GTK_TREE_STORE (model), &keypad, - ACCEL_COMBO_COLUMN_TEXT, _("Keypad"), -1); - - gtk_tree_store_append (GTK_TREE_STORE (model), &fkey, NULL); - gtk_tree_store_set - (GTK_TREE_STORE (model), &fkey, - ACCEL_COMBO_COLUMN_TEXT, _("Functions"), -1); - - gtk_tree_store_append (GTK_TREE_STORE (model), &other, NULL); - gtk_tree_store_set - (GTK_TREE_STORE (model), &other, - ACCEL_COMBO_COLUMN_TEXT, _("Other"), -1); - - parent = &alphanum; - - for (i = 0; GladeKeys[i].name != NULL; i++) - { - gtk_tree_store_append (GTK_TREE_STORE (model), &iter, parent); - gtk_tree_store_set - (GTK_TREE_STORE (model), &iter, - ACCEL_COMBO_COLUMN_TEXT, GladeKeys[i].name, -1); - - if (!strcmp (GladeKeys[i].name, GLADE_KEYS_LAST_ALPHANUM)) - parent = &extra; - else if (!strcmp (GladeKeys[i].name, GLADE_KEYS_LAST_EXTRA)) - parent = &keypad; - else if (!strcmp (GladeKeys[i].name, GLADE_KEYS_LAST_KP)) - parent = &fkey; - else if (!strcmp (GladeKeys[i].name, GLADE_KEYS_LAST_FKEY)) - parent = &other; - } - return model; -} - -static void -glade_eprop_accel_finalize (GObject *object) -{ - /* Chain up */ - G_OBJECT_CLASS (editor_property_class)->finalize (object); -} - -static void -glade_eprop_accel_load (GladeEditorProperty *eprop, - GladeProperty *property) -{ - GladeEPropAccel *eprop_accel = GLADE_EPROP_ACCEL (eprop); - gchar *accels; - - /* Chain up first */ - editor_property_class->load (eprop, property); - - if (property == NULL) return; - - if ((accels = glade_property_class_make_string_from_gvalue - (eprop->klass, property->value)) != NULL) - { - gtk_entry_set_text (GTK_ENTRY (eprop_accel->entry), accels); - g_free (accels); - } - else - gtk_entry_set_text (GTK_ENTRY (eprop_accel->entry), ""); - -} - -static gint -eprop_find_iter (GladeEpropIterTab *iter_tab, - gchar *name) -{ - return strcmp (iter_tab->name, name); -} - -static void -iter_tab_free (GladeEpropIterTab *iter_tab) -{ - gtk_tree_iter_free (iter_tab->iter); - g_free (iter_tab); -} - -static void -glade_eprop_accel_populate_view (GladeEditorProperty *eprop, - GtkTreeView *view) -{ - GladeEPropAccel *eprop_accel = GLADE_EPROP_ACCEL (eprop); - GladeSignalClass *sclass; - GladeWidgetAdaptor *adaptor = glade_widget_adaptor_from_pclass (eprop->klass); - GtkTreeStore *model = (GtkTreeStore *)gtk_tree_view_get_model (view); - GtkTreeIter iter; - GladeEpropIterTab *parent_tab; - GladeAccelInfo *info; - GList *list, *l, *found, *accelerators; - gchar *name; - - accelerators = g_value_get_boxed (eprop->property->value); - - /* First make parent iters... - */ - for (list = adaptor->signals; list; list = list->next) - { - sclass = list->data; - - /* Only action signals have accelerators. */ - if ((sclass->query.signal_flags & G_SIGNAL_ACTION) == 0) - continue; - - if (g_list_find_custom (eprop_accel->parent_iters, - sclass->type, - (GCompareFunc)eprop_find_iter) == NULL) - { - gtk_tree_store_append (model, &iter, NULL); - gtk_tree_store_set (model, &iter, - ACCEL_COLUMN_SIGNAL, sclass->type, - ACCEL_COLUMN_IS_CLASS, TRUE, - ACCEL_COLUMN_IS_SIGNAL, FALSE, - -1); - - parent_tab = g_new0 (GladeEpropIterTab, 1); - parent_tab->name = sclass->type; - parent_tab->iter = gtk_tree_iter_copy (&iter); - - eprop_accel->parent_iters = - g_list_prepend (eprop_accel->parent_iters, - parent_tab); - } - } - - /* Now we populate... - */ - for (list = adaptor->signals; list; list = list->next) - { - sclass = list->data; - - /* Only action signals have accelerators. */ - if ((sclass->query.signal_flags & G_SIGNAL_ACTION) == 0) - continue; - - if ((found = g_list_find_custom (eprop_accel->parent_iters, - sclass->type, - (GCompareFunc)eprop_find_iter)) != NULL) - { - parent_tab = found->data; - name = g_strdup_printf (" %s", sclass->name); - - /* Populate from accelerator list - */ - for (l = accelerators; l; l = l->next) - { - info = l->data; - - if (strcmp (info->signal, sclass->name)) - continue; - - gtk_tree_store_append (model, &iter, parent_tab->iter); - gtk_tree_store_set - (model, &iter, - ACCEL_COLUMN_SIGNAL, name, - ACCEL_COLUMN_REAL_SIGNAL, sclass->name, - ACCEL_COLUMN_IS_CLASS, FALSE, - ACCEL_COLUMN_IS_SIGNAL, TRUE, - ACCEL_COLUMN_MOD_SHIFT, - (info->modifiers & GDK_SHIFT_MASK) != 0, - ACCEL_COLUMN_MOD_CNTL, - (info->modifiers & GDK_CONTROL_MASK) != 0, - ACCEL_COLUMN_MOD_ALT, - (info->modifiers & GDK_MOD1_MASK) != 0, - ACCEL_COLUMN_KEY, - glade_builtin_string_from_key (info->key), - ACCEL_COLUMN_KEY_ENTERED, TRUE, - ACCEL_COLUMN_KEY_SLOT, FALSE, - -1); - } - - /* Append a new empty slot at the end */ - gtk_tree_store_append (model, &iter, parent_tab->iter); - gtk_tree_store_set - (model, &iter, - ACCEL_COLUMN_SIGNAL, name, - ACCEL_COLUMN_REAL_SIGNAL, sclass->name, - ACCEL_COLUMN_IS_CLASS, FALSE, - ACCEL_COLUMN_IS_SIGNAL, TRUE, - ACCEL_COLUMN_MOD_SHIFT, FALSE, - ACCEL_COLUMN_MOD_CNTL, FALSE, - ACCEL_COLUMN_MOD_ALT, FALSE, - ACCEL_COLUMN_KEY, _("<choose a key>"), - ACCEL_COLUMN_KEY_ENTERED, FALSE, - ACCEL_COLUMN_KEY_SLOT, TRUE, - -1); - - g_free (name); - } - } -} - -static void -key_edited (GtkCellRendererText *cell, - const gchar *path_string, - const gchar *new_text, - GladeEditorProperty *eprop) -{ - GladeEPropAccel *eprop_accel = GLADE_EPROP_ACCEL (eprop); - gboolean key_was_set; - const gchar *text; - GtkTreeIter iter, parent_iter, new_iter; - - if (!gtk_tree_model_get_iter_from_string (eprop_accel->model, - &iter, path_string)) - return; - - gtk_tree_model_get (eprop_accel->model, &iter, - ACCEL_COLUMN_KEY_ENTERED, &key_was_set, - -1); - - /* If user selects "none"; remove old entry or ignore new one. - */ - if (!new_text || new_text[0] == '\0' || - glade_builtin_string_from_key ((guint)new_text[0]) == NULL || - g_utf8_collate (new_text, _("None")) == 0 || - g_utf8_collate (new_text, _("<choose a key>")) == 0) - { - if (key_was_set) - gtk_tree_store_remove - (GTK_TREE_STORE (eprop_accel->model), &iter); - - return; - } - - if (glade_builtin_key_from_string (new_text) != 0) - text = new_text; - else - text = glade_builtin_string_from_key ((guint)new_text[0]); - - gtk_tree_store_set - (GTK_TREE_STORE (eprop_accel->model), &iter, - ACCEL_COLUMN_KEY, text, - ACCEL_COLUMN_KEY_ENTERED, TRUE, - ACCEL_COLUMN_KEY_SLOT, FALSE, - -1); - - /* Append a new one if needed - */ - if (key_was_set == FALSE && - gtk_tree_model_iter_parent (eprop_accel->model, - &parent_iter, &iter)) - { - gchar *signal, *real_signal; - - gtk_tree_model_get (eprop_accel->model, &iter, - ACCEL_COLUMN_SIGNAL, &signal, - ACCEL_COLUMN_REAL_SIGNAL, &real_signal, - -1); - - /* Append a new empty slot at the end */ - gtk_tree_store_insert_after (GTK_TREE_STORE (eprop_accel->model), - &new_iter, &parent_iter, &iter); - gtk_tree_store_set (GTK_TREE_STORE (eprop_accel->model), &new_iter, - ACCEL_COLUMN_SIGNAL, signal, - ACCEL_COLUMN_REAL_SIGNAL, real_signal, - ACCEL_COLUMN_IS_CLASS, FALSE, - ACCEL_COLUMN_IS_SIGNAL, TRUE, - ACCEL_COLUMN_MOD_SHIFT, FALSE, - ACCEL_COLUMN_MOD_CNTL, FALSE, - ACCEL_COLUMN_MOD_ALT, FALSE, - ACCEL_COLUMN_KEY, _("<choose a key>"), - ACCEL_COLUMN_KEY_ENTERED, FALSE, - ACCEL_COLUMN_KEY_SLOT, TRUE, - -1); - g_free (signal); - g_free (real_signal); - } -} - -static void -modifier_toggled (GtkCellRendererToggle *cell, - gchar *path_string, - GladeEditorProperty *eprop) -{ - GladeEPropAccel *eprop_accel = GLADE_EPROP_ACCEL (eprop); - GtkTreeIter iter; - gint column; - gboolean active, key_entered; - - if (!gtk_tree_model_get_iter_from_string (eprop_accel->model, - &iter, path_string)) - return; - - column = GPOINTER_TO_INT (g_object_get_data - (G_OBJECT (cell), "model-column")); - - gtk_tree_model_get - (eprop_accel->model, &iter, - ACCEL_COLUMN_KEY_ENTERED, &key_entered, - column, &active, -1); - - if (key_entered) - gtk_tree_store_set - (GTK_TREE_STORE (eprop_accel->model), &iter, - column, !active, -1); -} - - -static GtkWidget * -glade_eprop_accel_view (GladeEditorProperty *eprop) -{ - GladeEPropAccel *eprop_accel = GLADE_EPROP_ACCEL (eprop); - GtkWidget *view_widget; - GtkCellRenderer *renderer; - GtkTreeViewColumn *column; - - eprop_accel->model = (GtkTreeModel *)gtk_tree_store_new - (ACCEL_NUM_COLUMNS, - G_TYPE_STRING, /* The GSignal name formatted for display */ - G_TYPE_STRING, /* The GSignal name */ - G_TYPE_STRING, /* The Gdk keycode */ - G_TYPE_BOOLEAN, /* The shift modifier */ - G_TYPE_BOOLEAN, /* The cntl modifier */ - G_TYPE_BOOLEAN, /* The alt modifier */ - G_TYPE_BOOLEAN, /* Whether this is a class entry */ - G_TYPE_BOOLEAN, /* Whether this is a signal entry (oposite of above) */ - G_TYPE_BOOLEAN, /* Whether the key has been entered for this row */ - G_TYPE_BOOLEAN); /* Oposite of above */ - - view_widget = gtk_tree_view_new_with_model (eprop_accel->model); - g_object_set (G_OBJECT (view_widget), "enable-search", FALSE, NULL); - - /********************* fake invisible column *********************/ - renderer = gtk_cell_renderer_text_new (); - g_object_set (G_OBJECT (renderer), "editable", FALSE, "visible", FALSE, NULL); - - column = gtk_tree_view_column_new_with_attributes (NULL, renderer, NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (view_widget), column); - - gtk_tree_view_column_set_visible (column, FALSE); - gtk_tree_view_set_expander_column (GTK_TREE_VIEW (view_widget), column); - - /********************* signal name column *********************/ - renderer = gtk_cell_renderer_text_new (); - g_object_set (G_OBJECT (renderer), - "editable", FALSE, - "weight", PANGO_WEIGHT_BOLD, - NULL); - - column = gtk_tree_view_column_new_with_attributes - (_("Signal"), renderer, - "text", ACCEL_COLUMN_SIGNAL, - "weight-set", ACCEL_COLUMN_IS_CLASS, - NULL); - - g_object_set (G_OBJECT (column), "expand", TRUE, NULL); - - gtk_tree_view_append_column (GTK_TREE_VIEW (view_widget), column); - - /********************* key name column *********************/ - if (keysyms_model == NULL) - keysyms_model = create_keysyms_model (); - - renderer = gtk_cell_renderer_combo_new (); - g_object_set (G_OBJECT (renderer), - "editable", TRUE, - "model", keysyms_model, - "text-column", ACCEL_COMBO_COLUMN_TEXT, - "has-entry", TRUE, - "style", PANGO_STYLE_ITALIC, - "foreground", "Gray", - NULL); - - g_signal_connect (renderer, "edited", - G_CALLBACK (key_edited), eprop); - - column = gtk_tree_view_column_new_with_attributes - (_("Key"), renderer, - "text", ACCEL_COLUMN_KEY, - "style-set", ACCEL_COLUMN_KEY_SLOT, - "foreground-set", ACCEL_COLUMN_KEY_SLOT, - "visible", ACCEL_COLUMN_IS_SIGNAL, - NULL); - - g_object_set (G_OBJECT (column), "expand", TRUE, NULL); - - gtk_tree_view_append_column (GTK_TREE_VIEW (view_widget), column); - - /********************* shift modifier column *********************/ - renderer = gtk_cell_renderer_toggle_new (); - column = gtk_tree_view_column_new_with_attributes - (_("Shift"), renderer, - "visible", ACCEL_COLUMN_IS_SIGNAL, - "sensitive", ACCEL_COLUMN_KEY_ENTERED, - "active", ACCEL_COLUMN_MOD_SHIFT, - NULL); - - g_object_set_data (G_OBJECT (renderer), "model-column", - GINT_TO_POINTER (ACCEL_COLUMN_MOD_SHIFT)); - g_signal_connect (G_OBJECT (renderer), "toggled", - G_CALLBACK (modifier_toggled), eprop); - - gtk_tree_view_append_column (GTK_TREE_VIEW (view_widget), column); - - /********************* control modifier column *********************/ - renderer = gtk_cell_renderer_toggle_new (); - column = gtk_tree_view_column_new_with_attributes - (_("Control"), renderer, - "visible", ACCEL_COLUMN_IS_SIGNAL, - "sensitive", ACCEL_COLUMN_KEY_ENTERED, - "active", ACCEL_COLUMN_MOD_CNTL, - NULL); - - g_object_set_data (G_OBJECT (renderer), "model-column", - GINT_TO_POINTER (ACCEL_COLUMN_MOD_CNTL)); - g_signal_connect (G_OBJECT (renderer), "toggled", - G_CALLBACK (modifier_toggled), eprop); - - gtk_tree_view_append_column (GTK_TREE_VIEW (view_widget), column); - - /********************* alt modifier column *********************/ - renderer = gtk_cell_renderer_toggle_new (); - column = gtk_tree_view_column_new_with_attributes - (_("Alt"), renderer, - "visible", ACCEL_COLUMN_IS_SIGNAL, - "sensitive", ACCEL_COLUMN_KEY_ENTERED, - "active", ACCEL_COLUMN_MOD_ALT, - NULL); - - g_object_set_data (G_OBJECT (renderer), "model-column", - GINT_TO_POINTER (ACCEL_COLUMN_MOD_ALT)); - g_signal_connect (G_OBJECT (renderer), "toggled", - G_CALLBACK (modifier_toggled), eprop); - - gtk_tree_view_append_column (GTK_TREE_VIEW (view_widget), column); - - return view_widget; -} - -static gboolean -glade_eprop_accel_accum_accelerators (GtkTreeModel *model, - GtkTreePath *path, - GtkTreeIter *iter, - GList **ret) -{ - GladeAccelInfo *info; - gchar *signal, *key_str; - gboolean shift, cntl, alt, entered; - - gtk_tree_model_get (model, iter, ACCEL_COLUMN_KEY_ENTERED, &entered, -1); - if (entered == FALSE) return FALSE; - - gtk_tree_model_get (model, iter, - ACCEL_COLUMN_REAL_SIGNAL, &signal, - ACCEL_COLUMN_KEY, &key_str, - ACCEL_COLUMN_MOD_SHIFT, &shift, - ACCEL_COLUMN_MOD_CNTL, &cntl, - ACCEL_COLUMN_MOD_ALT, &alt, - -1); - - info = g_new0 (GladeAccelInfo, 1); - info->signal = signal; - info->key = glade_builtin_key_from_string (key_str); - info->modifiers = (shift ? GDK_SHIFT_MASK : 0) | - (cntl ? GDK_CONTROL_MASK : 0) | - (alt ? GDK_MOD1_MASK : 0); - - *ret = g_list_prepend (*ret, info); - - g_free (key_str); - - return FALSE; -} - - -static void -glade_eprop_accel_show_dialog (GtkWidget *dialog_button, - GladeEditorProperty *eprop) -{ - GladeEPropAccel *eprop_accel = GLADE_EPROP_ACCEL (eprop); - GtkWidget *dialog, *parent, *vbox, *sw, *tree_view; - GladeProject *project; - GValue *value; - GList *accelerators = NULL; - gint res; - - project = glade_widget_get_project (eprop->property->widget); - parent = gtk_widget_get_toplevel (GTK_WIDGET (eprop)); - - dialog = gtk_dialog_new_with_buttons (_("Choose accelerator keys..."), - GTK_WINDOW (parent), - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_STOCK_CLEAR, GLADE_RESPONSE_CLEAR, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OK, GTK_RESPONSE_OK, - NULL); - - gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); - - vbox = gtk_vbox_new (FALSE, 6); - gtk_widget_show (vbox); - - gtk_container_set_border_width (GTK_CONTAINER (vbox), 6); - - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), vbox, TRUE, TRUE, 0); - - sw = gtk_scrolled_window_new (NULL, NULL); - gtk_widget_show (sw); - gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0); - gtk_widget_set_size_request (sw, 400, 200); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN); - - tree_view = glade_eprop_accel_view (eprop); - glade_eprop_accel_populate_view (eprop, GTK_TREE_VIEW (tree_view)); - - gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view)); - - gtk_widget_show (tree_view); - gtk_container_add (GTK_CONTAINER (sw), tree_view); - - /* Run the dialog */ - res = gtk_dialog_run (GTK_DIALOG (dialog)); - if (res == GTK_RESPONSE_OK) - { - gtk_tree_model_foreach - (gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view)), - (GtkTreeModelForeachFunc) - glade_eprop_accel_accum_accelerators, &accelerators); - - value = g_new0 (GValue, 1); - g_value_init (value, GLADE_TYPE_ACCEL_GLIST); - g_value_take_boxed (value, accelerators); - - glade_editor_property_commit (eprop, value); - - g_value_unset (value); - g_free (value); - } - else if (res == GLADE_RESPONSE_CLEAR) - { - value = g_new0 (GValue, 1); - g_value_init (value, GLADE_TYPE_ACCEL_GLIST); - g_value_set_boxed (value, NULL); - - glade_editor_property_commit (eprop, value); - - g_value_unset (value); - g_free (value); - } - - /* Clean up ... - */ - gtk_widget_destroy (dialog); - - g_object_unref (G_OBJECT (eprop_accel->model)); - eprop_accel->model = NULL; - - if (eprop_accel->parent_iters) - { - g_list_foreach (eprop_accel->parent_iters, (GFunc)iter_tab_free, NULL); - g_list_free (eprop_accel->parent_iters); - eprop_accel->parent_iters = NULL; - } - -} - -static GtkWidget * -glade_eprop_accel_create_input (GladeEditorProperty *eprop) -{ - GladeEPropAccel *eprop_accel = GLADE_EPROP_ACCEL (eprop); - GtkWidget *hbox; - GtkWidget *button; - - hbox = gtk_hbox_new (FALSE, 0); - eprop_accel->entry = gtk_entry_new (); - gtk_entry_set_editable (GTK_ENTRY (eprop_accel->entry), FALSE); - gtk_widget_show (eprop_accel->entry); - gtk_box_pack_start (GTK_BOX (hbox), eprop_accel->entry, TRUE, TRUE, 0); - - button = gtk_button_new_with_label ("..."); - gtk_widget_show (button); - gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); - - g_signal_connect (G_OBJECT (button), "clicked", - G_CALLBACK (glade_eprop_accel_show_dialog), - eprop); - - return hbox; -} - - - -/******************************************************************************* - Misc static stuff - *******************************************************************************/ -static GType -glade_editor_property_type (GParamSpec *pspec) -{ - GType type = 0; - - if (pspec->value_type == GLADE_TYPE_STOCK || - G_IS_PARAM_SPEC_ENUM(pspec)) - type = GLADE_TYPE_EPROP_ENUM; - else if (G_IS_PARAM_SPEC_FLAGS(pspec)) - type = GLADE_TYPE_EPROP_FLAGS; - else if (G_IS_PARAM_SPEC_VALUE_ARRAY (pspec)) - { - if (pspec->value_type == G_TYPE_VALUE_ARRAY) - type = GLADE_TYPE_EPROP_TEXT; - } - else if (G_IS_PARAM_SPEC_BOXED(pspec)) - { - if (pspec->value_type == GDK_TYPE_COLOR) - type = GLADE_TYPE_EPROP_COLOR; - else if (pspec->value_type == G_TYPE_STRV) - type = GLADE_TYPE_EPROP_TEXT; - } - else if (G_IS_PARAM_SPEC_STRING(pspec)) - type = GLADE_TYPE_EPROP_TEXT; - else if (G_IS_PARAM_SPEC_BOOLEAN(pspec)) - type = GLADE_TYPE_EPROP_BOOL; - else if (G_IS_PARAM_SPEC_FLOAT(pspec) || - G_IS_PARAM_SPEC_DOUBLE(pspec) || - G_IS_PARAM_SPEC_INT(pspec) || - G_IS_PARAM_SPEC_UINT(pspec) || - G_IS_PARAM_SPEC_LONG(pspec) || - G_IS_PARAM_SPEC_ULONG(pspec) || - G_IS_PARAM_SPEC_INT64(pspec) || - G_IS_PARAM_SPEC_UINT64(pspec)) - type = GLADE_TYPE_EPROP_NUMERIC; - else if (G_IS_PARAM_SPEC_UNICHAR(pspec)) - type = GLADE_TYPE_EPROP_UNICHAR; - else if (G_IS_PARAM_SPEC_OBJECT(pspec)) - { - if (pspec->value_type == GDK_TYPE_PIXBUF) - type = GLADE_TYPE_EPROP_RESOURCE; - else if (pspec->value_type == GTK_TYPE_ADJUSTMENT) - type = GLADE_TYPE_EPROP_ADJUSTMENT; - else - type = GLADE_TYPE_EPROP_OBJECT; - } - else if (GLADE_IS_PARAM_SPEC_OBJECTS(pspec)) - type = GLADE_TYPE_EPROP_OBJECTS; - else if (GLADE_IS_PARAM_SPEC_ACCEL(pspec)) - type = GLADE_TYPE_EPROP_ACCEL; - - return type; -} - -/******************************************************************************* - API - *******************************************************************************/ - -/** - * glade_editor_property_new: - * @klass: A #GladePropertyClass - * @use_command: Whether the undo/redo stack applies here. - * - * This is a factory function to create the correct type of - * editor property that can edit the said type of #GladePropertyClass - * - * Returns: A newly created GladeEditorProperty of the correct type - */ -GladeEditorProperty * -glade_editor_property_new (GladePropertyClass *klass, - gboolean use_command) -{ - GladeEditorProperty *eprop; - GType type = 0; - - /* Find the right type of GladeEditorProperty for this - * GladePropertyClass. - */ - if ((type = glade_editor_property_type (klass->pspec)) == 0) - g_error ("%s : pspec '%s' type '%s' not implemented (%s)\n", - G_GNUC_PRETTY_FUNCTION, - klass->name, - g_type_name (G_PARAM_SPEC_TYPE (klass->pspec)), - g_type_name (klass->pspec->value_type)); - - /* special case for resource specs which are hand specified in the catalog. */ - if (klass->resource) type = GLADE_TYPE_EPROP_RESOURCE; - - /* Create and return the correct type of GladeEditorProperty */ - eprop = g_object_new (type, - "property-class", klass, - "use-command", use_command, - NULL); - - return eprop; -} - -/** - * glade_editor_property_new_from_widget: - * @widget: A #GladeWidget - * @property: The widget's property - * @use_command: Whether the undo/redo stack applies here. - * - * This is a convenience function to create a GladeEditorProperty corresponding - * to @property - * - * Returns: A newly created and connected GladeEditorProperty - */ -GladeEditorProperty * -glade_editor_property_new_from_widget (GladeWidget *widget, - const gchar *property, - gboolean use_command) -{ - GladeEditorProperty *eprop; - GladeProperty *p; - - p = glade_widget_get_property (widget, property); - g_return_val_if_fail (GLADE_IS_PROPERTY (p), NULL); - - eprop = glade_editor_property_new (p->klass, use_command); - glade_editor_property_load (eprop, p); - - return eprop; -} - -/** - * glade_editor_property_supported: - * @pspec: A #GParamSpec - * - * Returns: whether this pspec is supported by GladeEditorProperties. - */ -gboolean -glade_editor_property_supported (GParamSpec *pspec) -{ - return glade_editor_property_type (pspec) != 0; -} - - -/** - * glade_editor_property_load: - * @eprop: A #GladeEditorProperty - * @property: A #GladeProperty - * - * Loads @property values into @eprop and connects. - */ -void -glade_editor_property_load (GladeEditorProperty *eprop, - GladeProperty *property) -{ - g_return_if_fail (GLADE_IS_EDITOR_PROPERTY (eprop)); - g_return_if_fail (property == NULL || GLADE_IS_PROPERTY (property)); - - eprop->loading = TRUE; - GLADE_EDITOR_PROPERTY_GET_CLASS (eprop)->load (eprop, property); - eprop->loading = FALSE; -} - - -/** - * glade_editor_property_load_by_widget: - * @eprop: A #GladeEditorProperty - * @widget: A #GladeWidget - * - * Convenience function to load the appropriate #GladeProperty into - * @eprop from @widget - */ -void -glade_editor_property_load_by_widget (GladeEditorProperty *eprop, - GladeWidget *widget) -{ - GladeProperty *property = NULL; - - g_return_if_fail (GLADE_IS_EDITOR_PROPERTY (eprop)); - g_return_if_fail (widget == NULL || GLADE_IS_WIDGET (widget)); - - if (widget) - /* properties are allowed to be missing on some internal widgets */ - property = glade_widget_get_property (widget, eprop->klass->id); - - glade_editor_property_load (eprop, property); -} - -/** - * glade_editor_property_show_info: - * @eprop: A #GladeEditorProperty - * - * Show the control widget to access help for @eprop - */ -void -glade_editor_property_show_info (GladeEditorProperty *eprop) -{ - GladeWidgetAdaptor *adaptor; - gchar *book; - - g_return_if_fail (GLADE_IS_EDITOR_PROPERTY (eprop)); - - adaptor = glade_widget_adaptor_from_pspec (eprop->klass->pspec); - - g_object_get (adaptor, "book", &book, NULL); - - if (eprop->klass->virt == FALSE && - book != NULL) - gtk_widget_show (eprop->info); - else - { - /* Put insensitive controls to balance the UI with - * other eprops. - */ - gtk_widget_show (eprop->info); - gtk_widget_set_sensitive (eprop->info, FALSE); - } - - g_free (book); - eprop->show_info = TRUE; - g_object_notify (G_OBJECT (eprop), "show-info"); -} - -/** - * glade_editor_property_hide_info: - * @eprop: A #GladeEditorProperty - * - * Hide the control widget to access help for @eprop - */ -void -glade_editor_property_hide_info (GladeEditorProperty *eprop) -{ - g_return_if_fail (GLADE_IS_EDITOR_PROPERTY (eprop)); - - gtk_widget_hide (eprop->info); - - eprop->show_info = FALSE; - g_object_notify (G_OBJECT (eprop), "show-info"); -} diff --git a/gladeui/glade-editor-property.h b/gladeui/glade-editor-property.h deleted file mode 100644 index 5e2a7fc2..00000000 --- a/gladeui/glade-editor-property.h +++ /dev/null @@ -1,107 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef __GLADE_EDITOR_PROPERTY_H__ -#define __GLADE_EDITOR_PROPERTY_H__ - -G_BEGIN_DECLS - -#define GLADE_TYPE_EDITOR_PROPERTY (glade_editor_property_get_type()) -#define GLADE_EDITOR_PROPERTY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EDITOR_PROPERTY, GladeEditorProperty)) -#define GLADE_EDITOR_PROPERTY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EDITOR_PROPERTY, GladeEditorPropertyClass)) -#define GLADE_IS_EDITOR_PROPERTY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EDITOR_PROPERTY)) -#define GLADE_IS_EDITOR_PROPERTY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_EDITOR_PROPERTY)) -#define GLADE_EDITOR_PROPERTY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GLADE_EDITOR_PROPERTY, GladeEditorPropertyClass)) - - -typedef struct _GladeEditorProperty GladeEditorProperty; -typedef struct _GladeEditorPropertyClass GladeEditorPropertyClass; - -struct _GladeEditorProperty -{ - GtkHBox parent_instance; - - GladePropertyClass *klass; /* The property class this GladeEditorProperty was created for - */ - GladeProperty *property; /* The currently loaded property - */ - - GtkWidget *item_label; /* Name of property (need a handle to set visual insensitive state) - */ - GtkWidget *eventbox; /* Eventbox on item_label. - */ - - GtkWidget *input; /* Input part of property (need to set sensitivity seperately) - */ - - GtkWidget *check; /* Check button for optional properties. - */ - - GtkWidget *info; /* Informational button - */ - - gulong tooltip_id; /* signal connection id for tooltip changes */ - gulong sensitive_id; /* signal connection id for sensitivity changes */ - gulong changed_id; /* signal connection id for value changes */ - gulong enabled_id; /* signal connection id for enable/disable changes */ - - gboolean loading; /* True during glade_editor_property_load calls, this - * is used to avoid feedback from input widgets. - */ - - gboolean use_command; /* Whether we should use the glade command interface - * or skip directly to GladeProperty interface. - * (used for query dialogs). - */ - - gboolean show_info; /* Whether we should show an informational button - * for this property - */ - - GdkColor *insensitive_colour; /* For setting insensitive background on */ - GdkColor *normal_colour; /* labels without setting them insensitive - * (tooltips dont work on insensitive widgets - * at this time) - */ -}; - -struct _GladeEditorPropertyClass { - GtkHBoxClass parent_class; - - void (* load) (GladeEditorProperty *, GladeProperty *); - - /* private */ - GtkWidget *(* create_input) (GladeEditorProperty *); - - void (* gtk_doc_search)(GladeEditorProperty *, - const gchar *, - const gchar *, - const gchar *); - -}; - - - -GType glade_editor_property_get_type (void); - -GladeEditorProperty *glade_editor_property_new (GladePropertyClass *klass, - gboolean use_command); - -GladeEditorProperty *glade_editor_property_new_from_widget (GladeWidget *widget, - const gchar *property, - gboolean use_command); - -void glade_editor_property_load (GladeEditorProperty *eprop, - GladeProperty *property); - -void glade_editor_property_load_by_widget (GladeEditorProperty *eprop, - GladeWidget *widget); - -gboolean glade_editor_property_supported (GParamSpec *pspec); - -void glade_editor_property_show_info (GladeEditorProperty *eprop); - -void glade_editor_property_hide_info (GladeEditorProperty *eprop); - - -G_END_DECLS - -#endif /* __GLADE_EDITOR_PROPERTY_H__ */ diff --git a/gladeui/glade-editor.c b/gladeui/glade-editor.c deleted file mode 100644 index ff8f92cd..00000000 --- a/gladeui/glade-editor.c +++ /dev/null @@ -1,1554 +0,0 @@ -/* -*- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Authors: - * Chema Celorio <chema@celorio.com> - */ - - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdio.h> -#include <string.h> -#include <glib/gi18n-lib.h> - -#include "glade.h" -#include "glade-widget.h" -#include "glade-widget-adaptor.h" -#include "glade-editor.h" -#include "glade-signal-editor.h" -#include "glade-parameter.h" -#include "glade-property.h" -#include "glade-property-class.h" -#include "glade-command.h" -#include "glade-debug.h" -#include "glade-marshallers.h" -#include "glade-project.h" -#include "glade-utils.h" -#include "glade-editor-property.h" - -enum -{ - PROP_0, - PROP_SHOW_INFO, - PROP_SHOW_CONTEXT_INFO -}; - -enum { - GTK_DOC_SEARCH, - LAST_SIGNAL -}; - -static GtkVBoxClass *parent_class = NULL; -static guint glade_editor_signals[LAST_SIGNAL] = { 0 }; - -static void glade_editor_reset_dialog (GladeEditor *editor); - -static void -glade_editor_gtk_doc_search_cb (GladeEditorProperty *eprop, - const gchar *book, - const gchar *page, - const gchar *search, - GladeEditor *editor) -{ - /* Just act as a hub for search signals here */ - g_signal_emit (G_OBJECT (editor), - glade_editor_signals[GTK_DOC_SEARCH], - 0, book, page, search); -} - -static void -glade_editor_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - GladeEditor *editor = GLADE_EDITOR (object); - - switch (prop_id) - { - case PROP_SHOW_INFO: - if (g_value_get_boolean (value)) - glade_editor_show_info (editor); - else - glade_editor_hide_info (editor); - break; - case PROP_SHOW_CONTEXT_INFO: - if (g_value_get_boolean (value)) - glade_editor_show_context_info (editor); - else - glade_editor_hide_context_info (editor); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -glade_editor_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - GladeEditor *editor = GLADE_EDITOR (object); - - switch (prop_id) - { - case PROP_SHOW_INFO: - g_value_set_boolean (value, editor->show_info); - break; - case PROP_SHOW_CONTEXT_INFO: - g_value_set_boolean (value, editor->show_context_info); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - - -static void -glade_editor_class_init (GladeEditorClass *klass) -{ - GObjectClass *object_class; - - parent_class = g_type_class_peek_parent (klass); - object_class = G_OBJECT_CLASS (klass); - - object_class->set_property = glade_editor_set_property; - object_class->get_property = glade_editor_get_property; - - klass->gtk_doc_search = NULL; - - /* Properties */ - g_object_class_install_property - (object_class, PROP_SHOW_INFO, - g_param_spec_boolean ("show-info", - _("Show info"), - _("Whether to show an informational " - "button for the loaded widget"), - FALSE, G_PARAM_READABLE)); - - g_object_class_install_property - (object_class, PROP_SHOW_CONTEXT_INFO, - g_param_spec_boolean ("show-context-info", - _("Show context info"), - _("Whether to show an informational button for " - "each property and signal in the editor"), - FALSE, G_PARAM_READABLE)); - - - /** - * GladeEditor::gtk-doc-search: - * @gladeeditor: the #GladeEditor which received the signal. - * @arg1: the (#gchar *) book to search or %NULL - * @arg2: the (#gchar *) page to search or %NULL - * @arg3: the (#gchar *) search string or %NULL - * - * Emitted when the editor requests that a doc-search be performed. - */ - glade_editor_signals[GTK_DOC_SEARCH] = - g_signal_new ("gtk-doc-search", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GladeEditorClass, - gtk_doc_search), - NULL, NULL, - glade_marshal_VOID__STRING_STRING_STRING, - G_TYPE_NONE, 3, - G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); -} - -static GtkWidget * -glade_editor_notebook_page (GladeEditor *editor, const gchar *name) -{ - GtkWidget *alignment; - GtkWidget *sw; - GtkWidget *label_widget; - GtkWidget *image; - static gchar *path; - static gint page = 0; - - /* alignment is needed to ensure property labels have some padding on the left */ - alignment = gtk_alignment_new (0.5, 0, 1, 0); - gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 6, 0); - - /* construct tab label widget */ - if (g_utf8_collate (name, _("Accessibility")) == 0) - { - path = g_build_filename (glade_app_get_pixmaps_dir (), "atk.png", NULL); - image = gtk_image_new_from_file (path); - label_widget = gtk_event_box_new (); - gtk_container_add (GTK_CONTAINER (label_widget), image); - gtk_widget_show (label_widget); - gtk_widget_show (image); - - glade_util_widget_set_tooltip (label_widget, name); - } - else - { - label_widget = gtk_label_new_with_mnemonic (name); - } - - /* configure page container */ - if (g_utf8_collate (name, _("_Signals")) == 0) - { - gtk_alignment_set (GTK_ALIGNMENT (alignment), 0.5, 0.5, 1, 1); - gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 0, 0); - - gtk_container_set_border_width (GTK_CONTAINER (alignment), 6); - gtk_notebook_insert_page (GTK_NOTEBOOK (editor->notebook), alignment, - label_widget, page++); - } - else - { - /* wrap the alignment in a scrolled window */ - sw = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (sw), - GTK_WIDGET (alignment)); - gtk_container_set_border_width (GTK_CONTAINER (sw), 6); - - gtk_notebook_insert_page (GTK_NOTEBOOK (editor->notebook), sw, - label_widget, page++); - - } - - return alignment; -} - -static void -glade_editor_on_reset_click (GtkButton *button, - GladeEditor *editor) -{ - glade_editor_reset_dialog (editor); -} - -static void -glade_editor_on_docs_click (GtkButton *button, - GladeEditor *editor) -{ - gchar *book; - - if (editor->loaded_widget) - { - g_object_get (editor->loaded_widget->adaptor, "book", &book, NULL); - g_signal_emit (G_OBJECT (editor), - glade_editor_signals[GTK_DOC_SEARCH], - 0, book, editor->loaded_widget->adaptor->name, NULL); - g_free (book); - } -} - - -static GtkWidget * -glade_editor_create_info_button (GladeEditor *editor) -{ - GtkWidget *button; - GtkWidget *image; - - button = gtk_button_new (); - - image = glade_util_get_devhelp_icon (GTK_ICON_SIZE_BUTTON); - gtk_widget_show (image); - - gtk_container_add (GTK_CONTAINER (button), image); - - glade_util_widget_set_tooltip (button, _("View documentation for the selected widget")); - g_signal_connect (G_OBJECT (button), "clicked", - G_CALLBACK (glade_editor_on_docs_click), editor); - - return button; -} - - -static GtkWidget * -glade_editor_create_reset_button (GladeEditor *editor) -{ - GtkWidget *image; - GtkWidget *button; - - button = gtk_button_new (); - - image = gtk_image_new_from_stock ("gtk-clear", GTK_ICON_SIZE_BUTTON); - - gtk_container_add (GTK_CONTAINER (button), image); - - glade_util_widget_set_tooltip (button, _("Reset widget properties to their defaults")); - g_signal_connect (G_OBJECT (button), "clicked", - G_CALLBACK (glade_editor_on_reset_click), editor); - - return button; -} - -static void -glade_editor_init (GladeEditor *editor) -{ - GtkSizeGroup *size_group; - GtkWidget *hbox; - - editor->notebook = gtk_notebook_new (); - editor->page_widget = glade_editor_notebook_page (editor, _("_General")); - editor->page_packing = glade_editor_notebook_page (editor, _("_Packing")); - editor->page_common = glade_editor_notebook_page (editor, _("_Common")); - editor->page_signals = glade_editor_notebook_page (editor, _("_Signals")); - editor->page_atk = glade_editor_notebook_page (editor, _("Accessibility")); - editor->widget_tables = NULL; - editor->packing_etable = NULL; - editor->loading = FALSE; - - gtk_container_set_border_width (GTK_CONTAINER (editor->notebook), 0); - - gtk_box_pack_start (GTK_BOX (editor), editor->notebook, TRUE, TRUE, 0); - - hbox = gtk_hbox_new (FALSE, 6); - gtk_container_set_border_width (GTK_CONTAINER (hbox), 0); - gtk_box_pack_start (GTK_BOX (editor), hbox, FALSE, FALSE, 0); - - size_group = gtk_size_group_new (GTK_SIZE_GROUP_BOTH); - - /* Reset button */ - editor->reset_button = glade_editor_create_reset_button (editor); - gtk_box_pack_end (GTK_BOX (hbox), editor->reset_button, FALSE, FALSE, 0); - gtk_size_group_add_widget (size_group, editor->reset_button); - - /* Documentation button */ - editor->info_button = glade_editor_create_info_button (editor); - gtk_box_pack_end (GTK_BOX (hbox), editor->info_button, FALSE, FALSE, 0); - gtk_size_group_add_widget (size_group, editor->info_button); - - g_object_unref(size_group); - - gtk_widget_show_all (GTK_WIDGET (editor)); - if (editor->show_info) - gtk_widget_show (editor->info_button); - else - gtk_widget_hide (editor->info_button); - - gtk_widget_hide (GTK_WIDGET (editor)); -} - -GType -glade_editor_get_type (void) -{ - static GType type = 0; - - if (!type) { - static const GTypeInfo info = { - sizeof (GladeEditorClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) glade_editor_class_init, - (GClassFinalizeFunc) NULL, - NULL, - sizeof (GladeEditor), - 0, - (GInstanceInitFunc) glade_editor_init - }; - - type = g_type_register_static (GTK_TYPE_VBOX, "GladeEditor", &info, 0); - } - - return type; -} - -/** - * glade_editor_new: - * - * Returns: a new #GladeEditor - */ -GladeEditor * -glade_editor_new (void) -{ - GladeEditor *editor; - - editor = g_object_new (GLADE_TYPE_EDITOR, - "spacing", 6, - NULL); - - return editor; -} - -/* - * We call this function when the user changes the widget name using the - * entry on the properties editor. - */ -static void -glade_editor_widget_name_changed (GtkWidget *editable, GladeEditor *editor) -{ - GladeWidget *widget; - gchar *new_name; - - g_return_if_fail (GTK_IS_EDITABLE (editable)); - g_return_if_fail (GLADE_IS_EDITOR (editor)); - - if (editor->loading) return; - - widget = editor->loaded_widget; - new_name = gtk_editable_get_chars (GTK_EDITABLE (editable), 0, -1); - glade_command_set_name (widget, new_name); - g_free (new_name); -} - - -static gboolean -glade_editor_widget_name_focus_out (GtkWidget *entry, - GdkEventFocus *event, - GladeEditor *editor) -{ - glade_editor_widget_name_changed (entry, editor); - return FALSE; -} - -static void -glade_editor_table_attach (GtkWidget *table, GtkWidget *child, gint pos, gint row) -{ - gtk_table_attach (GTK_TABLE (table), child, - pos, pos+1, row, row +1, - pos ? GTK_EXPAND | GTK_FILL : GTK_FILL, - GTK_EXPAND | GTK_FILL, - 3, 1); -} - -static GladeEditorProperty * -glade_editor_table_append_item (GladeEditorTable *table, - GladePropertyClass *klass, - gboolean from_query_dialog) -{ - GladeEditorProperty *property; - - property = glade_editor_property_new (klass, from_query_dialog == FALSE); - gtk_widget_show (GTK_WIDGET (property)); - gtk_widget_show_all (property->eventbox); - - if (table->editor->show_context_info && from_query_dialog == FALSE) - glade_editor_property_show_info (property); - else - glade_editor_property_hide_info (property); - - g_signal_connect (G_OBJECT (property), "gtk-doc-search", - G_CALLBACK (glade_editor_gtk_doc_search_cb), - table->editor); - - glade_editor_table_attach (table->table_widget, property->eventbox, 0, table->rows); - glade_editor_table_attach (table->table_widget, GTK_WIDGET (property), 1, table->rows); - - table->rows++; - - return property; -} - -static void -glade_editor_table_append_name_field (GladeEditorTable *table) -{ - GtkWidget *label; - - /* Name */ - label = gtk_label_new (_("Name:")); - gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); - gtk_widget_show (label); - - table->name_entry = gtk_entry_new (); - gtk_widget_show (table->name_entry); - - g_signal_connect (G_OBJECT (table->name_entry), "activate", - G_CALLBACK (glade_editor_widget_name_changed), - table->editor); - - g_signal_connect (G_OBJECT (table->name_entry), "focus-out-event", - G_CALLBACK (glade_editor_widget_name_focus_out), - table->editor); - - glade_editor_table_attach (table->table_widget, label, 0, table->rows); - glade_editor_table_attach (table->table_widget, table->name_entry, 1, table->rows); - - table->rows++; -} - -static void -glade_editor_table_append_class_field (GladeEditorTable *table) -{ - GtkWidget *label; - GtkWidget *class_entry; - - /* Class */ - label = gtk_label_new (_("Class:")); - gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); - gtk_widget_show (label); - - class_entry = gtk_entry_new (); - gtk_entry_set_text (GTK_ENTRY (class_entry), table->adaptor->name); - gtk_editable_set_editable (GTK_EDITABLE (class_entry), FALSE); - gtk_widget_show (class_entry); - - glade_editor_table_attach (table->table_widget, label, 0, table->rows); - glade_editor_table_attach (table->table_widget, class_entry, 1, table->rows); - - table->rows++; -} - -static gint -glade_editor_property_class_comp (gconstpointer a, gconstpointer b) -{ - const GladePropertyClass *ca = a, *cb = b; - - if (ca->pspec->owner_type == cb->pspec->owner_type) - { - gdouble result = ca->weight - cb->weight; - /* Avoid cast to int */ - if (result < 0.0) return -1; - else if (result > 0.0) return 1; - else return 0; - } - else - { - if (g_type_is_a (ca->pspec->owner_type, cb->pspec->owner_type)) - return (ca->common || ca->packing) ? 1 : -1; - else - return (ca->common || ca->packing) ? -1 : 1; - } -} - -static GList * -glade_editor_get_sorted_properties (GladeWidgetAdaptor *adaptor) -{ - GList *l, *a = NULL, *b = NULL; - - for (l = adaptor->properties; l && l->data; l = g_list_next (l)) - { - GladePropertyClass *klass = l->data; - - if (klass->common || klass->packing) - a = g_list_prepend (a, klass); - else - b = g_list_prepend (b, klass); - } - - a = g_list_sort (a, glade_editor_property_class_comp); - b = g_list_sort (b, glade_editor_property_class_comp); - - return g_list_concat (a, b); -} - -static gboolean -glade_editor_table_append_items (GladeEditorTable *table, - GladeWidgetAdaptor *adaptor, - GladeEditorTableType type) -{ - GladeEditorProperty *property; - GladePropertyClass *property_class; - GList *list, *sorted_list; - - sorted_list = glade_editor_get_sorted_properties (adaptor); - - for (list = sorted_list; list != NULL; list = list->next) - { - property_class = (GladePropertyClass *) list->data; - - if (!glade_property_class_is_visible (property_class)) - continue; - if (type == TABLE_TYPE_QUERY && !property_class->query) - continue; - else if (type == TABLE_TYPE_COMMON && !property_class->common) - continue; - else if (type == TABLE_TYPE_GENERAL && property_class->common) - continue; - else if (type == TABLE_TYPE_ATK && - (property_class->type == GPC_NORMAL || - property_class->type == GPC_ACCEL_PROPERTY)) - continue; - else if (type != TABLE_TYPE_ATK && - (property_class->type != GPC_NORMAL && - property_class->type != GPC_ACCEL_PROPERTY)) - continue; - - property = glade_editor_table_append_item (table, property_class, - type == TABLE_TYPE_QUERY); - table->properties = g_list_prepend (table->properties, property); - } - - g_list_free (sorted_list); - - return TRUE; -} - -static GladeEditorTable * -glade_editor_table_new (void) -{ - GladeEditorTable *table; - - table = g_new0 (GladeEditorTable, 1); - - table->table_widget = gtk_table_new (0, 0, FALSE); - - g_object_ref (G_OBJECT(table->table_widget)); - - return table; -} - -static void -glade_editor_table_free (GladeEditorTable *etable) -{ - g_object_unref (G_OBJECT(etable->table_widget)); - g_free (etable); -} - -static GladeEditorTable * -glade_editor_table_create (GladeEditor *editor, - GladeWidgetAdaptor *adaptor, - GladeEditorTableType type) -{ - GladeEditorTable *table; - - g_return_val_if_fail (GLADE_IS_EDITOR (editor), NULL); - g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL); - - table = glade_editor_table_new (); - table->editor = editor; - table->adaptor = adaptor; - table->type = type; - - if (type == TABLE_TYPE_GENERAL) - { - glade_editor_table_append_class_field (table); - glade_editor_table_append_name_field (table); - } - - if (!glade_editor_table_append_items (table, adaptor, type)) - return NULL; - - gtk_widget_show (table->table_widget); - - return table; -} - -static GladeEditorTable * -glade_editor_get_table_from_class (GladeEditor *editor, - GladeWidgetAdaptor *adaptor, - GladeEditorTableType type) -{ - GladeEditorTable *table; - GList *list; - - for (list = editor->widget_tables; list; list = list->next) - { - table = list->data; - if (type != table->type) - continue; - if (table->adaptor == adaptor) - return table; - } - - table = glade_editor_table_create (editor, adaptor, type); - g_return_val_if_fail (table != NULL, NULL); - - editor->widget_tables = g_list_prepend (editor->widget_tables, table); - - return table; -} - -static void -glade_editor_load_page (GladeEditor *editor, - GladeWidgetAdaptor *adaptor, - GladeEditorTableType type) -{ - GladeEditorTable *table; - GtkContainer *container = NULL; - GtkWidget *scrolled_window; - GList *list, *children; - GtkAdjustment *adj; - - /* Remove the old table that was in this container */ - switch (type) - { - case TABLE_TYPE_GENERAL: - container = GTK_CONTAINER (editor->page_widget); - break; - case TABLE_TYPE_COMMON: - container = GTK_CONTAINER (editor->page_common); - break; - case TABLE_TYPE_ATK: - container = GTK_CONTAINER (editor->page_atk); - break; - case TABLE_TYPE_PACKING: - case TABLE_TYPE_QUERY: - default: - g_critical ("Unreachable code reached !"); - break; - } - - children = gtk_container_get_children (container); - for (list = children; list; list = list->next) { - GtkWidget *widget = list->data; - g_return_if_fail (GTK_IS_WIDGET (widget)); - gtk_widget_ref (widget); - gtk_container_remove (container, widget); - } - g_list_free (children); - - if (!adaptor) - return; - - table = glade_editor_get_table_from_class (editor, adaptor, type); - - /* Attach the new table */ - gtk_container_add (GTK_CONTAINER (container), table->table_widget); - - /* Enable tabbed keynav in the editor */ - if (table) - { - scrolled_window = gtk_widget_get_parent (GTK_WIDGET (container)); - scrolled_window = gtk_widget_get_parent (scrolled_window); - - /* FIXME: Save pointer to the scrolled window (or just the - adjustments) before hand. */ - g_assert (GTK_IS_SCROLLED_WINDOW (scrolled_window)); - - adj = gtk_scrolled_window_get_vadjustment - (GTK_SCROLLED_WINDOW (scrolled_window)); - gtk_container_set_focus_vadjustment - (GTK_CONTAINER (table->table_widget), adj); - - adj = gtk_scrolled_window_get_hadjustment - (GTK_SCROLLED_WINDOW (scrolled_window)); - gtk_container_set_focus_hadjustment - (GTK_CONTAINER (table->table_widget), adj); - } -} - -/** - * glade_editor_update_widget_name: - * @editor: a #GladeEditor - * - * TODO: write me - */ -void -glade_editor_update_widget_name (GladeEditor *editor) -{ - GladeEditorTable *table = glade_editor_get_table_from_class - (editor, editor->loaded_adaptor, TABLE_TYPE_GENERAL); - - g_signal_handlers_block_by_func (G_OBJECT (table->name_entry), glade_editor_widget_name_changed, editor); - gtk_entry_set_text (GTK_ENTRY (table->name_entry), editor->loaded_widget->name); - g_signal_handlers_unblock_by_func (G_OBJECT (table->name_entry), glade_editor_widget_name_changed, editor); -} - -static void -glade_editor_load_signal_page (GladeEditor *editor) -{ - if (editor->signal_editor == NULL) { - editor->signal_editor = glade_signal_editor_new ((gpointer) editor); - gtk_container_add (GTK_CONTAINER (editor->page_signals), - glade_signal_editor_get_widget (editor->signal_editor)); - } -} - -static void -glade_editor_load_widget_class (GladeEditor *editor, GladeWidgetAdaptor *adaptor) -{ - glade_editor_load_page (editor, adaptor, TABLE_TYPE_GENERAL); - glade_editor_load_page (editor, adaptor, TABLE_TYPE_COMMON); - glade_editor_load_page (editor, adaptor, TABLE_TYPE_ATK); - - glade_editor_load_signal_page (editor); - - editor->loaded_adaptor = adaptor; -} - -static gint -glade_editor_property_comp (gconstpointer a, gconstpointer b) -{ - const GladeProperty *prop_a = a, *prop_b = b; - return glade_editor_property_class_comp (prop_a->klass, prop_b->klass); -} - -static void -glade_editor_load_packing_page (GladeEditor *editor, GladeWidget *widget) -{ - GladeEditorProperty *editor_property; - GladeProperty *property; - GladeWidget *parent; - GList *list, *sorted_list; - GtkWidget *child; - - /* Remove the old properties */ - if ((child = gtk_bin_get_child (GTK_BIN (editor->page_packing))) != NULL) - gtk_container_remove (GTK_CONTAINER (editor->page_packing), child); - - /* Free the packing editor table */ - if (editor->packing_etable) - editor->packing_etable = - (glade_editor_table_free (editor->packing_etable), NULL); - - /* Free the packing editor properties (we gave ownership to - * packing_etable->table_widget, so no need to unref them here). - */ - editor->packing_eprops = (g_list_free (editor->packing_eprops), NULL); - - - /* if the widget is a toplevel there are no packing properties */ - if (widget == NULL || (parent = glade_widget_get_parent (widget)) == NULL) - return; - - /* Now add the new properties */ - editor->packing_etable = glade_editor_table_new (); - editor->packing_etable->editor = editor; - editor->packing_etable->type = TABLE_TYPE_PACKING; - - /* Sort packing properties by weight */ - sorted_list = g_list_copy (widget->packing_properties); - sorted_list = g_list_sort (sorted_list, glade_editor_property_comp); - - for (list = sorted_list; list && list->data; list = list->next) - { - property = GLADE_PROPERTY (list->data); - - if (glade_property_class_is_visible (property->klass) == FALSE) - continue; - - editor_property = glade_editor_table_append_item (editor->packing_etable, - property->klass, FALSE); - editor->packing_eprops = g_list_prepend (editor->packing_eprops, editor_property); - glade_editor_property_load (editor_property, property); - } - - g_list_free (sorted_list); - - gtk_widget_show (editor->packing_etable->table_widget); - - gtk_container_add (GTK_CONTAINER (editor->page_packing), - editor->packing_etable->table_widget); -} - -static void -glade_editor_close_cb (GladeProject *project, - GladeEditor *editor) -{ - /* Detected project we are viewing was closed, - * detatch from editor. - */ - glade_editor_load_widget (editor, NULL); -} - -static void -glade_editor_load_table (GladeEditor *editor, - GladeWidget *widget, - GladeEditorTableType type) -{ - GladeEditorProperty *property; - GladeEditorTable *table; - GList *list; - - table = glade_editor_get_table_from_class - (editor, widget->adaptor, type); - if (table->name_entry) - gtk_entry_set_text (GTK_ENTRY (table->name_entry), widget->name); - - for (list = table->properties; list; list = list->next) - { - property = list->data; - glade_editor_property_load_by_widget (property, widget); - } -} - -static void -glade_editor_load_widget_real (GladeEditor *editor, GladeWidget *widget) -{ - GladeWidgetAdaptor *adaptor; - GladeProject *project; - gchar *book; - - /* Disconnect from last widget */ - if (editor->loaded_widget != NULL) - { - project = glade_widget_get_project (editor->loaded_widget); - g_signal_handler_disconnect (G_OBJECT (project), - editor->project_closed_signal_id); - } - /* Load the GladeWidgetClass */ - adaptor = widget ? widget->adaptor : NULL; - if (editor->loaded_adaptor != adaptor || adaptor == NULL) - glade_editor_load_widget_class (editor, adaptor); - - glade_editor_load_packing_page (editor, widget); - glade_signal_editor_load_widget (editor->signal_editor, widget); - - /* we are just clearing, we are done */ - if (widget == NULL) - { - gtk_widget_set_sensitive (editor->reset_button, FALSE); - gtk_widget_set_sensitive (editor->info_button, FALSE); - - editor->loaded_widget = NULL; - return; - } - gtk_widget_set_sensitive (editor->reset_button, TRUE); - - g_object_get (editor->loaded_adaptor, "book", &book, NULL); - gtk_widget_set_sensitive (editor->info_button, book != NULL); - g_free (book); - - editor->loading = TRUE; - - /* Load each GladeEditorProperty from 'widget' */ - glade_editor_load_table (editor, widget, TABLE_TYPE_GENERAL); - glade_editor_load_table (editor, widget, TABLE_TYPE_COMMON); - glade_editor_load_table (editor, widget, TABLE_TYPE_ATK); - - editor->loaded_widget = widget; - editor->loading = FALSE; - - /* Connect to new widget */ - project = glade_widget_get_project (editor->loaded_widget); - editor->project_closed_signal_id = - g_signal_connect (G_OBJECT (project), "close", - G_CALLBACK (glade_editor_close_cb), editor); -} - -/** - * glade_editor_load_widget: - * @editor: a #GladeEditor - * @widget: a #GladeWidget - * - * Load @widget into @editor. If @widget is %NULL, clear the editor. - */ -void -glade_editor_load_widget (GladeEditor *editor, GladeWidget *widget) -{ - g_return_if_fail (GLADE_IS_EDITOR (editor)); - g_return_if_fail (widget == NULL || GLADE_IS_WIDGET (widget)); - - if (editor->loaded_widget == widget) - return; - - glade_editor_load_widget_real (editor, widget); -} - -/** - * glade_editor_refresh: - * @editor: a #GladeEditor - * - * Synchronize @editor with the currently loaded widget. - */ -void -glade_editor_refresh (GladeEditor *editor) -{ - g_return_if_fail (GLADE_IS_EDITOR (editor)); - glade_editor_load_widget_real (editor, editor->loaded_widget); -} - -static void -query_dialog_style_set_cb (GtkWidget *dialog, - GtkStyle *previous_style, - gpointer user_data) -{ - gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), 12); - gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 12); - gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area), 0); - gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->action_area), 6); -} - - -gboolean -glade_editor_query_dialog (GladeEditor *editor, GladeWidget *widget) -{ - GtkWidget *dialog; - GladeEditorTable *table; - gchar *title; - GList *list; - GladeEditorProperty *property; - gint answer; - gboolean retval = TRUE; - - title = g_strdup_printf (_("Create a %s"), widget->adaptor->name); - - dialog = gtk_dialog_new_with_buttons (title, NULL, - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | - GTK_DIALOG_NO_SEPARATOR, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OK, GTK_RESPONSE_OK, - NULL); - - g_free (title); - - gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog), - GTK_RESPONSE_OK, - GTK_RESPONSE_CANCEL, - -1); - gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); - - table = glade_editor_get_table_from_class (editor, - widget->adaptor, - TABLE_TYPE_QUERY); - - - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), - table->table_widget, - FALSE, FALSE, 6); - for (list = table->properties; list; list = list->next) - { - property = list->data; - glade_editor_property_load_by_widget (property, widget); - } - - g_signal_connect (dialog, "style-set", - G_CALLBACK (query_dialog_style_set_cb), - NULL); - - answer = gtk_dialog_run (GTK_DIALOG (dialog)); - - /* - * If user cancel's we cancel the whole "create operation" by - * return FALSE. glade_widget_new() will see the FALSE, and - * take care of canceling the "create" operation. - */ - if (answer == GTK_RESPONSE_CANCEL) - retval = FALSE; - - gtk_container_remove (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), - table->table_widget); - - gtk_widget_destroy (dialog); - return retval; -} - -enum { - COLUMN_ENABLED = 0, - COLUMN_PROP_NAME, - COLUMN_PROPERTY, - COLUMN_PARENT, - COLUMN_CHILD, - COLUMN_DEFAULT, - COLUMN_NDEFAULT, - COLUMN_DEFSTRING, - NUM_COLUMNS -}; - - -static void -glade_editor_reset_toggled (GtkCellRendererToggle *cell, - gchar *path_str, - GtkTreeModel *model) -{ - GtkTreePath *path = gtk_tree_path_new_from_string (path_str); - GtkTreeIter iter; - gboolean enabled; - - /* get toggled iter */ - gtk_tree_model_get_iter (model, &iter, path); - gtk_tree_model_get (model, &iter, - COLUMN_ENABLED, &enabled, -1); - gtk_tree_store_set (GTK_TREE_STORE (model), &iter, - COLUMN_ENABLED, !enabled, -1); - gtk_tree_path_free (path); -} - -static GtkWidget * -glade_editor_reset_view (GladeEditor *editor) -{ - GtkWidget *view_widget; - GtkTreeModel *model; - GtkCellRenderer *renderer; - GtkTreeViewColumn *column; - - model = (GtkTreeModel *)gtk_tree_store_new - (NUM_COLUMNS, - G_TYPE_BOOLEAN, /* Enabled value */ - G_TYPE_STRING, /* Property name */ - GLADE_TYPE_PROPERTY, /* The property */ - G_TYPE_BOOLEAN, /* Parent node ? */ - G_TYPE_BOOLEAN, /* Child node ? */ - G_TYPE_BOOLEAN, /* Has default value */ - G_TYPE_BOOLEAN, /* Doesn't have defaut */ - G_TYPE_STRING); /* Default string */ - - view_widget = gtk_tree_view_new_with_model (model); - g_object_set (G_OBJECT (view_widget), "enable-search", FALSE, NULL); - - /********************* fake invisible column *********************/ - renderer = gtk_cell_renderer_text_new (); - g_object_set (G_OBJECT (renderer), "editable", FALSE, "visible", FALSE, NULL); - - column = gtk_tree_view_column_new_with_attributes (NULL, renderer, NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (view_widget), column); - - gtk_tree_view_column_set_visible (column, FALSE); - gtk_tree_view_set_expander_column (GTK_TREE_VIEW (view_widget), column); - - /************************ enabled column ************************/ - renderer = gtk_cell_renderer_toggle_new (); - g_object_set (G_OBJECT (renderer), - "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE, - "activatable", TRUE, - NULL); - g_signal_connect (renderer, "toggled", - G_CALLBACK (glade_editor_reset_toggled), model); - gtk_tree_view_insert_column_with_attributes - (GTK_TREE_VIEW (view_widget), COLUMN_ENABLED, - _("Reset"), renderer, - "sensitive", COLUMN_NDEFAULT, - "activatable", COLUMN_NDEFAULT, - "active", COLUMN_ENABLED, - "visible", COLUMN_CHILD, - NULL); - - /********************* property name column *********************/ - renderer = gtk_cell_renderer_text_new (); - g_object_set (G_OBJECT (renderer), - "editable", FALSE, - "weight", PANGO_WEIGHT_BOLD, NULL); - gtk_tree_view_insert_column_with_attributes - (GTK_TREE_VIEW (view_widget), COLUMN_PROP_NAME, - _("Property"), renderer, - "text", COLUMN_PROP_NAME, - "weight-set", COLUMN_PARENT, - NULL); - - /******************* default indicator column *******************/ - renderer = gtk_cell_renderer_text_new (); - g_object_set (G_OBJECT (renderer), - "editable", FALSE, - "style", PANGO_STYLE_ITALIC, - "foreground", "Gray", NULL); - gtk_tree_view_insert_column_with_attributes - (GTK_TREE_VIEW (view_widget), COLUMN_DEFSTRING, - NULL, renderer, - "text", COLUMN_DEFSTRING, - "visible", COLUMN_DEFAULT, - NULL); - - return view_widget; -} - -static void -glade_editor_populate_reset_view (GladeEditor *editor, - GtkTreeView *tree_view) -{ - GtkTreeStore *model = (GtkTreeStore *)gtk_tree_view_get_model (tree_view); - GtkTreeIter property_iter, general_iter, common_iter, atk_iter, *iter; - GList *list; - GladeProperty *property; - gboolean def; - - g_return_if_fail (editor->loaded_widget != NULL); - - gtk_tree_store_append (model, &general_iter, NULL); - gtk_tree_store_set (model, &general_iter, - COLUMN_PROP_NAME, _("General"), - COLUMN_PROPERTY, NULL, - COLUMN_PARENT, TRUE, - COLUMN_CHILD, FALSE, - COLUMN_DEFAULT, FALSE, - COLUMN_NDEFAULT, FALSE, - -1); - - gtk_tree_store_append (model, &common_iter, NULL); - gtk_tree_store_set (model, &common_iter, - COLUMN_PROP_NAME, _("Common"), - COLUMN_PROPERTY, NULL, - COLUMN_PARENT, TRUE, - COLUMN_CHILD, FALSE, - COLUMN_DEFAULT, FALSE, - COLUMN_NDEFAULT, FALSE, - -1); - - gtk_tree_store_append (model, &atk_iter, NULL); - gtk_tree_store_set (model, &atk_iter, - COLUMN_PROP_NAME, _("Accessibility"), - COLUMN_PROPERTY, NULL, - COLUMN_PARENT, TRUE, - COLUMN_CHILD, FALSE, - COLUMN_DEFAULT, FALSE, - COLUMN_NDEFAULT, FALSE, - -1); - - /* General & Common */ - for (list = editor->loaded_widget->properties; list; list = list->next) - { - property = list->data; - - if (glade_property_class_is_visible (property->klass) == FALSE) - continue; - - if (property->klass->type != GPC_NORMAL && - property->klass->type != GPC_ACCEL_PROPERTY) - iter = &atk_iter; - else if (property->klass->common) - iter = &common_iter; - else - iter = &general_iter; - - def = glade_property_default (property); - - gtk_tree_store_append (model, &property_iter, iter); - gtk_tree_store_set (model, &property_iter, - COLUMN_ENABLED, !def, - COLUMN_PROP_NAME, property->klass->name, - COLUMN_PROPERTY, property, - COLUMN_PARENT, FALSE, - COLUMN_CHILD, TRUE, - COLUMN_DEFAULT, def, - COLUMN_NDEFAULT, !def, - COLUMN_DEFSTRING, _("(default)"), - -1); - } -} - -static gboolean -glade_editor_reset_selection_changed_cb (GtkTreeSelection *selection, - GtkTextView *desc_view) -{ - GtkTreeIter iter; - GladeProperty *property = NULL; - GtkTreeModel *model = NULL; - GtkTextBuffer *text_buffer; - - const gchar *message = - _("Select the properties that you want to reset to their default values"); - - /* Find selected data and show property blurb here */ - if (gtk_tree_selection_get_selected (selection, &model, &iter)) - { - text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (desc_view)); - gtk_tree_model_get (model, &iter, COLUMN_PROPERTY, &property, -1); - gtk_text_buffer_set_text (text_buffer, - property ? glade_property_get_tooltip (property) : message, - -1); - if (property) - g_object_unref (G_OBJECT (property)); - } - return TRUE; -} - -static gboolean -glade_editor_reset_foreach_selection (GtkTreeModel *model, - GtkTreePath *path, - GtkTreeIter *iter, - gboolean select) -{ - gboolean def; - - gtk_tree_model_get (model, iter, COLUMN_DEFAULT, &def, -1); - /* Dont modify rows that are already default */ - if (def == FALSE) - gtk_tree_store_set (GTK_TREE_STORE (model), iter, - COLUMN_ENABLED, select, -1); - return FALSE; -} - - -static void -glade_editor_reset_select_all_clicked (GtkButton *button, - GtkTreeView *tree_view) -{ - GtkTreeModel *model = gtk_tree_view_get_model (tree_view); - gtk_tree_model_foreach (model, (GtkTreeModelForeachFunc) - glade_editor_reset_foreach_selection, - GINT_TO_POINTER (TRUE)); -} - -static void -glade_editor_reset_unselect_all_clicked (GtkButton *button, - GtkTreeView *tree_view) -{ - GtkTreeModel *model = gtk_tree_view_get_model (tree_view); - gtk_tree_model_foreach (model, (GtkTreeModelForeachFunc) - glade_editor_reset_foreach_selection, - GINT_TO_POINTER (FALSE)); -} - -static gboolean -glade_editor_reset_accumulate_selected_props (GtkTreeModel *model, - GtkTreePath *path, - GtkTreeIter *iter, - GList **accum) -{ - GladeProperty *property; - gboolean enabled, def; - - gtk_tree_model_get (model, iter, - COLUMN_PROPERTY, &property, - COLUMN_ENABLED, &enabled, - COLUMN_DEFAULT, &def, - -1); - - if (property && enabled && !def) - *accum = g_list_prepend (*accum, property); - - - if (property) - g_object_unref (G_OBJECT (property)); - - return FALSE; -} - -static GList * -glade_editor_reset_get_selected_props (GtkTreeModel *model) -{ - GList *ret = NULL; - - gtk_tree_model_foreach (model, (GtkTreeModelForeachFunc) - glade_editor_reset_accumulate_selected_props, &ret); - - return ret; -} - -static void -glade_editor_reset_properties (GList *props) -{ - GList *list, *sdata_list = NULL; - GCSetPropData *sdata; - GladeProperty *prop; - GladeProject *project = NULL; - - for (list = props; list; list = list->next) - { - prop = list->data; - - project = glade_widget_get_project (prop->widget); - - sdata = g_new (GCSetPropData, 1); - sdata->property = prop; - - sdata->old_value = g_new0 (GValue, 1); - sdata->new_value = g_new0 (GValue, 1); - - glade_property_get_value (prop, sdata->old_value); - glade_property_get_default (prop, sdata->new_value); - - sdata_list = g_list_prepend (sdata_list, sdata); - } - - if (project) - /* GladeCommand takes ownership of allocated list, ugly but practicle */ - glade_command_set_properties_list (project, sdata_list); - -} - -static void -glade_editor_reset_dialog (GladeEditor *editor) -{ - GtkTreeSelection *selection; - GtkWidget *dialog, *parent; - GtkWidget *vbox, *hbox, *label, *sw, *button; - GtkWidget *tree_view, *description_view; - gint res; - GList *list; - - parent = gtk_widget_get_toplevel (GTK_WIDGET (editor)); - dialog = gtk_dialog_new_with_buttons (_("Reset Widget Properties"), - GTK_WINDOW (parent), - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OK, GTK_RESPONSE_OK, - NULL); - - gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); - - vbox = gtk_vbox_new (FALSE, 6); - gtk_widget_show (vbox); - - gtk_container_set_border_width (GTK_CONTAINER (vbox), 6); - - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), vbox, TRUE, TRUE, 0); - - /* Checklist */ - label = gtk_label_new_with_mnemonic (_("_Properties:")); - gtk_widget_show (label); - gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); - gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); - - sw = gtk_scrolled_window_new (NULL, NULL); - gtk_widget_show (sw); - gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0); - gtk_widget_set_size_request (sw, 400, 200); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN); - - - tree_view = glade_editor_reset_view (editor); - if (editor->loaded_widget) - glade_editor_populate_reset_view (editor, GTK_TREE_VIEW (tree_view)); - gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view)); - - gtk_widget_show (tree_view); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), tree_view); - gtk_container_add (GTK_CONTAINER (sw), tree_view); - - /* Select all / Unselect all */ - hbox = gtk_hbutton_box_new (); - gtk_button_box_set_layout (GTK_BUTTON_BOX (hbox), GTK_BUTTONBOX_END); - gtk_widget_show (hbox); - gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0); - - button = gtk_button_new_with_mnemonic (_("_Select All")); - gtk_widget_show (button); - gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); - gtk_container_set_border_width (GTK_CONTAINER (button), 6); - g_signal_connect (G_OBJECT (button), "clicked", - G_CALLBACK (glade_editor_reset_select_all_clicked), tree_view); - - button = gtk_button_new_with_mnemonic (_("_Unselect All")); - gtk_widget_show (button); - gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); - gtk_container_set_border_width (GTK_CONTAINER (button), 6); - g_signal_connect (G_OBJECT (button), "clicked", - G_CALLBACK (glade_editor_reset_unselect_all_clicked), tree_view); - - - /* Description */ - label = gtk_label_new_with_mnemonic (_("Property _Description:")); - gtk_widget_show (label); - gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); - gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); - - sw = gtk_scrolled_window_new (NULL, NULL); - gtk_widget_show (sw); - gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0); - gtk_widget_set_size_request (sw, 400, 80); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN); - - description_view = gtk_text_view_new (); - gtk_text_view_set_editable (GTK_TEXT_VIEW (description_view), FALSE); - gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (description_view), GTK_WRAP_WORD); - - gtk_widget_show (description_view); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), description_view); - gtk_container_add (GTK_CONTAINER (sw), description_view); - - /* Update description */ - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)); - g_signal_connect (G_OBJECT (selection), "changed", - G_CALLBACK (glade_editor_reset_selection_changed_cb), - description_view); - - - - /* Run the dialog */ - res = gtk_dialog_run (GTK_DIALOG (dialog)); - if (res == GTK_RESPONSE_OK) { - - /* get all selected properties and reset properties through glade_command */ - if ((list = glade_editor_reset_get_selected_props - (gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view)))) != NULL) - { - glade_editor_reset_properties (list); - g_list_free (list); - } - } - gtk_widget_destroy (dialog); -} - -void -glade_editor_show_info (GladeEditor *editor) -{ - g_return_if_fail (GLADE_IS_EDITOR (editor)); - - if (editor->show_info != TRUE) - { - editor->show_info = TRUE; - gtk_widget_show (editor->info_button); - - g_object_notify (G_OBJECT (editor), "show-info"); - } -} - -void -glade_editor_hide_info (GladeEditor *editor) -{ - g_return_if_fail (GLADE_IS_EDITOR (editor)); - - if (editor->show_info != FALSE) - { - editor->show_info = FALSE; - gtk_widget_hide (editor->info_button); - - g_object_notify (G_OBJECT (editor), "show-info"); - } -} - -void -glade_editor_show_context_info (GladeEditor *editor) -{ - GList *list, *props; - GladeEditorTable *etable; - - g_return_if_fail (GLADE_IS_EDITOR (editor)); - - if (editor->show_context_info != TRUE) - { - editor->show_context_info = TRUE; - - for (list = editor->widget_tables; list; list = list->next) - { - etable = list->data; - for (props = etable->properties; props; props = props->next) - glade_editor_property_show_info - (GLADE_EDITOR_PROPERTY (props->data)); - } - - if (editor->packing_etable) - { - etable = editor->packing_etable; - for (props = etable->properties; props; props = props->next) - glade_editor_property_show_info - (GLADE_EDITOR_PROPERTY (props->data)); - - } - g_object_notify (G_OBJECT (editor), "show-context-info"); - } -} - -void -glade_editor_hide_context_info (GladeEditor *editor) -{ - GList *list, *props; - GladeEditorTable *etable; - - g_return_if_fail (GLADE_IS_EDITOR (editor)); - - if (editor->show_context_info != FALSE) - { - editor->show_context_info = FALSE; - - for (list = editor->widget_tables; list; list = list->next) - { - etable = list->data; - for (props = etable->properties; props; props = props->next) - glade_editor_property_hide_info - (GLADE_EDITOR_PROPERTY (props->data)); - } - - if (editor->packing_etable) - { - etable = editor->packing_etable; - for (props = etable->properties; props; props = props->next) - glade_editor_property_hide_info - (GLADE_EDITOR_PROPERTY (props->data)); - - } - g_object_notify (G_OBJECT (editor), "show-context-info"); - } -} diff --git a/gladeui/glade-editor.h b/gladeui/glade-editor.h deleted file mode 100644 index 6faeff21..00000000 --- a/gladeui/glade-editor.h +++ /dev/null @@ -1,207 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef __GLADE_EDITOR_H__ -#define __GLADE_EDITOR_H__ - -#include <gladeui/glade-signal-editor.h> - -G_BEGIN_DECLS - - -#define GLADE_TYPE_EDITOR (glade_editor_get_type ()) -#define GLADE_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EDITOR, GladeEditor)) -#define GLADE_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EDITOR, GladeEditorClass)) -#define GLADE_IS_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EDITOR)) -#define GLADE_IS_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_EDITOR)) -#define GLADE_EDITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GLADE_TYPE_EDITOR, GladeEditorClass)) - -#define GLADE_EDITOR_TABLE(t) ((GladeEditorTable *)t) -#define GLADE_IS_EDITOR_TABLE(t) (t != NULL) - -typedef struct _GladeEditor GladeEditor; -typedef struct _GladeEditorClass GladeEditorClass; -typedef struct _GladeEditorTable GladeEditorTable; - -typedef enum _GladeEditorTableType -{ - TABLE_TYPE_GENERAL, - TABLE_TYPE_COMMON, - TABLE_TYPE_PACKING, - TABLE_TYPE_ATK, - TABLE_TYPE_QUERY -} GladeEditorTableType; - -/* The GladeEditor is a window that is used to display and modify widget - * properties. The glade editor contains the details of the selected - * widget for the selected project - */ -struct _GladeEditor -{ - GtkVBox vbox; /* The editor is a vbox */ - - GtkWidget *notebook; /* The notebook widget */ - - GladeWidget *loaded_widget; /* A handy pointer to the GladeWidget - * that is loaded in the editor. NULL - * if no widgets are selected - */ - - GladeWidgetAdaptor *loaded_adaptor; /* A pointer to the loaded - * GladeWidgetAdaptor. Note that we can - * have a class loaded without a - * loaded_widget. For this reason we - * can't use loaded_widget->adaptor. - * When a widget is selected we load - * this class in the editor first and - * then fill the values of the inputs - * with the GladeProperty items. - * This is usefull for not having - * to redraw/container_add the widgets - * when we switch from widgets of the - * same class - */ - - - /* The editor has (at this moment) four tabs; these are pointers to the - * widget inside each tab. The widgets are wrapped into a scrolled window. - * The page_* widgets are deparented and parented with - * ((GladeEditorTable *)etable)->table_widget when a widget is selected and - * the correct editor table is found. The exception is `page_signals' which - * always contains the same signal editor widget which simply reloads when - * loading a widget. - */ - GtkWidget *page_widget; - GtkWidget *page_packing; - GtkWidget *page_common; - GtkWidget *page_signals; - GtkWidget *page_atk; - - GladeSignalEditor *signal_editor; /* The signal editor packed into vbox_signals - */ - - GList *widget_tables; /* A list of GladeEditorTable. We have a table - * (gtktable) for each GladeWidgetClass, if - * we don't have one yet, we create it when - * we are asked to load a widget of a particular - * GladeWidgetClass - */ - - GladeEditorTable *packing_etable; /* Packing pages are dynamicly created each - * selection, this pointer is only to free - * the last packing page. - */ - - GList *packing_eprops; /* Current list of packing GladeEditorProperties - */ - - gboolean loading; /* Use when loading a GladeWidget into the editor - * we set this flag so that we can ignore the - * "changed" signal of the name entry text since - * the name has not really changed, just a new name - * was loaded. - */ - - gulong project_closed_signal_id; /* Unload widget when widget's project closes. - */ - - GtkWidget *reset_button; /* The reset button - */ - - GtkWidget *info_button; /* The actual informational button - */ - - gboolean show_info; /* Whether or not to show an informational button - */ - gboolean show_context_info; /* Whether or not to show an informational - * button for each property and signal. - */ -}; - -struct _GladeEditorClass -{ - GtkVBoxClass parent_class; - - void (*add_signal) (GladeEditor *editor, const char *id_widget, - GType type_widget, guint id_signal, - const char *callback_name); - - void (*gtk_doc_search) (GladeEditor *, - const gchar *, - const gchar *, - const gchar *); - -}; - -/* For each glade widget class that we have modified, we create a - * GladeEditorTable. A GladeEditorTable is mainly a gtk_table with all the - * widgets to edit a particular GladeWidgetClass (well the first tab of the - * gtk notebook). When a widget of is selected - * and going to be edited, we create a GladeEditorTable, when another widget - * of the same class is loaded so that it can be edited, we just update the - * contents of the editor table to relfect the values of that GladeWidget - */ -struct _GladeEditorTable -{ - GladeEditor *editor; /* Handy pointer that avoids havving to pass the - * editor arround. - */ - - GladeWidgetAdaptor *adaptor; /* The GladeWidgetAdaptor this - * table belongs to. - */ - - GtkWidget *table_widget; /* This widget is a gtk_vbox that is displayed - * in the glade-editor when a widget of this - * class is selected. It is hiden when another - * type is selected. When we select a widget - * we load into the inputs inside this table - * the information about the selected widget. - */ - - GtkWidget *name_entry; /* A pointer to the gtk_entry that holds - * the name of the widget. This is the - * first item _pack'ed to the table_widget. - * We have a pointer here because it is an - * entry which will not be created from a - * GladeProperty but rather from code. - */ - - GList *properties; /* A list of GladeEditorPropery items. - * For each row in the gtk_table, there is a - * corrsponding GladeEditorProperty struct. - */ - - GladeEditorTableType type; /* Is this table to be used in the common tab, ? - * the general tab, a packing tab or the query popup ? - */ - - gint rows; -}; - - -GType glade_editor_get_type (void); - -GladeEditor *glade_editor_new (void); - -void glade_editor_load_widget (GladeEditor *editor, - GladeWidget *widget); - -void glade_editor_refresh (GladeEditor *editor); - -void glade_editor_update_widget_name (GladeEditor *editor); - -gboolean glade_editor_query_dialog (GladeEditor *editor, - GladeWidget *widget); - -void glade_editor_show_info (GladeEditor *editor); - -void glade_editor_show_context_info (GladeEditor *editor); - -void glade_editor_hide_info (GladeEditor *editor); - -void glade_editor_hide_context_info (GladeEditor *editor); - - - -G_END_DECLS - -#endif /* __GLADE_EDITOR_H__ */ diff --git a/gladeui/glade-fixed.c b/gladeui/glade-fixed.c deleted file mode 100644 index ff4d1387..00000000 --- a/gladeui/glade-fixed.c +++ /dev/null @@ -1,1071 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * glade-fixed.c - A GladeWidget derivative object wrapper designed to - * handle free-form child placement for containers such as - * GtkFixed and GtkLayout. - * - * Copyright (C) 2006 The GNOME Foundation. - * - * Author(s): - * Tristan Van Berkom <tvb@gnome.org> - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <glib-object.h> -#include <glib/gi18n-lib.h> -#include <gdk/gdkkeysyms.h> - -#include "glade.h" -#include "glade-accumulators.h" -#include "glade-marshallers.h" -#include "glade-popup.h" -#include "glade-fixed.h" - -/* properties */ -enum { - PROP_0, - PROP_X_PROP, - PROP_Y_PROP, - PROP_WIDTH_PROP, - PROP_HEIGHT_PROP, - PROP_CAN_RESIZE -}; - -/* signals */ -enum { - CONFIGURE_CHILD, - CONFIGURE_BEGIN, - CONFIGURE_END, - FIXED_SIGNALS -}; - -typedef struct { - gulong press_id; - gulong release_id; - gulong motion_id; -} GFSigData; - -#define CHILD_WIDTH_MIN 20 -#define CHILD_HEIGHT_MIN 20 -#define CHILD_WIDTH_DEF 100 -#define CHILD_HEIGHT_DEF 80 - -#define GRAB_BORDER_WIDTH 7 -#define GRAB_CORNER_WIDTH 7 - -static GObjectClass *parent_class; -static guint glade_fixed_signals[FIXED_SIGNALS]; - -/******************************************************************************* - Static helper routines - *******************************************************************************/ -static GladeCursorType -glade_fixed_get_operation (GtkWidget *widget, - gint x, - gint y) -{ - GladeCursorType operation = GLADE_CURSOR_DRAG; - -#if 0 - g_print ("%s called (width %d height %d x %d y %d)\n", - __FUNCTION__, - widget->allocation.width, - widget->allocation.height, x, y); -#endif - - if (x < GRAB_BORDER_WIDTH) { - if (y < GRAB_BORDER_WIDTH) - operation = GLADE_CURSOR_RESIZE_TOP_LEFT; - else if (y > widget->allocation.height - GRAB_BORDER_WIDTH) - operation = GLADE_CURSOR_RESIZE_BOTTOM_LEFT; - else - operation = GLADE_CURSOR_RESIZE_LEFT; - } else if (x > widget->allocation.width - GRAB_BORDER_WIDTH) { - if (y < GRAB_BORDER_WIDTH) - operation = GLADE_CURSOR_RESIZE_TOP_RIGHT; - else if (y > widget->allocation.height - GRAB_BORDER_WIDTH) - operation = GLADE_CURSOR_RESIZE_BOTTOM_RIGHT; - else - operation = GLADE_CURSOR_RESIZE_RIGHT; - } else if (y < GRAB_BORDER_WIDTH) { - if (x < GRAB_BORDER_WIDTH) - operation = GLADE_CURSOR_RESIZE_TOP_LEFT; - else if (x > widget->allocation.width - GRAB_BORDER_WIDTH) - operation = GLADE_CURSOR_RESIZE_TOP_RIGHT; - else - operation = GLADE_CURSOR_RESIZE_TOP; - } else if (y > widget->allocation.height - GRAB_BORDER_WIDTH) { - if (x < GRAB_BORDER_WIDTH) - operation = GLADE_CURSOR_RESIZE_BOTTOM_LEFT; - else if (x > widget->allocation.width - GRAB_BORDER_WIDTH) - operation = GLADE_CURSOR_RESIZE_BOTTOM_RIGHT; - else - operation = GLADE_CURSOR_RESIZE_BOTTOM; - } - return operation; -} - -static void -glade_fixed_save_state (GladeFixed *fixed, - GladeWidget *child) -{ - gtk_widget_get_pointer (GTK_WIDGET (GLADE_WIDGET (fixed)->object), - &(GLADE_FIXED (fixed)->pointer_x_origin), - &(GLADE_FIXED (fixed)->pointer_y_origin)); - - gtk_widget_translate_coordinates (GTK_WIDGET (child->object), - GTK_WIDGET (GLADE_WIDGET (fixed)->object), - 0, 0, - &(fixed->child_x_origin), - &(fixed->child_y_origin)); - - fixed->child_width_origin = GTK_WIDGET (child->object)->allocation.width; - fixed->child_height_origin = GTK_WIDGET (child->object)->allocation.height; - - fixed->pointer_x_child_origin = - fixed->pointer_x_origin - fixed->child_x_origin; - fixed->pointer_y_child_origin = - fixed->pointer_y_origin - fixed->child_y_origin; -} - - -static void -glade_fixed_filter_event (GladeFixed *fixed, - gint *x, - gint *y, - gint left, - gint right, - gint top, - gint bottom) -{ - gint cont_width, cont_height; - - g_return_if_fail (x && y); - - cont_width = GTK_WIDGET (GLADE_WIDGET (fixed)->object)->allocation.width; - cont_height = GTK_WIDGET (GLADE_WIDGET (fixed)->object)->allocation.height; - - /* Clip out mouse events that are outside the window. - */ - if ((left || fixed->operation == GLADE_CURSOR_DRAG) && - *x - fixed->pointer_x_child_origin < 0) - *x = fixed->pointer_x_child_origin; - if ((top || fixed->operation == GLADE_CURSOR_DRAG) && - *y - fixed->pointer_y_child_origin < 0) - *y = fixed->pointer_y_child_origin; - - if ((right || fixed->operation == GLADE_CURSOR_DRAG) && - *x + (fixed->child_width_origin - - fixed->pointer_x_child_origin) > cont_width) - *x = cont_width - (fixed->child_width_origin - - fixed->pointer_x_child_origin); - if ((bottom || fixed->operation == GLADE_CURSOR_DRAG) && - *y + (fixed->child_height_origin - - fixed->pointer_y_child_origin) > cont_height) - *y = cont_height - (fixed->child_height_origin - - fixed->pointer_y_child_origin); - - /* Clip out mouse events that mean shrinking to less than 0. - */ - if (left && - (*x - fixed->pointer_x_child_origin) > - (fixed->child_x_origin + (fixed->child_width_origin - CHILD_WIDTH_MIN))) { - *x = (fixed->child_x_origin + (fixed->child_width_origin - CHILD_WIDTH_MIN)) - - fixed->pointer_x_child_origin; - } else if (right && - (*x - fixed->pointer_x_child_origin) < - fixed->child_x_origin - (fixed->child_width_origin + CHILD_WIDTH_MIN)) { - *x = (fixed->child_x_origin - (fixed->child_width_origin + CHILD_WIDTH_MIN)) + - fixed->pointer_x_child_origin; - } - - - if (top && - (*y - fixed->pointer_y_child_origin) > - (fixed->child_y_origin + (fixed->child_height_origin - CHILD_HEIGHT_MIN))) { - *y = (fixed->child_y_origin + (fixed->child_height_origin - CHILD_HEIGHT_MIN)) - - fixed->pointer_y_child_origin; - } else if (bottom && - (*y - fixed->pointer_y_child_origin) < - fixed->child_y_origin - (fixed->child_height_origin + CHILD_HEIGHT_MIN)) { - *y = (fixed->child_y_origin - (fixed->child_height_origin + CHILD_HEIGHT_MIN)) + - fixed->pointer_y_child_origin; - } -} - -static void -glade_fixed_handle_swindow (GladeFixed *fixed, - GdkRectangle *area) -{ - GtkWidget *fixed_widget = GTK_WIDGET (GLADE_WIDGET (fixed)->object); - GtkWidget *swindow = NULL, *swindow_child = NULL; - GtkAdjustment *hadj, *vadj; - gint x, y; - - swindow_child = swindow = fixed_widget; - while (swindow && !GTK_IS_SCROLLED_WINDOW (swindow)) - { - if (!GTK_IS_VIEWPORT (swindow)) - swindow_child = swindow; - - swindow = swindow->parent; - } - - if (swindow) - { - /* Set the adjustments to use appropriate pixel units and then - * square in on the target drop area. - */ - hadj = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (swindow)); - vadj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (swindow)); - - g_object_set (G_OBJECT (hadj), - "lower", 0.0F, - "upper", (gdouble) swindow_child->allocation.width + 0.0, - NULL); - - g_object_set (G_OBJECT (vadj), - "lower", 0.0F, - "upper", (gdouble) swindow_child->allocation.height + 0.0, - NULL); - - gtk_widget_translate_coordinates (fixed_widget, - swindow_child, - area->x, area->y, &x, &y); - - gtk_adjustment_clamp_page (hadj, x, x + area->width); - gtk_adjustment_clamp_page (vadj, y, y + area->height); - } -} - -static void -glade_fixed_configure_widget (GladeFixed *fixed, - GladeWidget *child) -{ - GladeWidget *gwidget = GLADE_WIDGET (fixed); - GdkRectangle new_area; - gboolean handled, right, left, top, bottom; - gint x, y; - - gtk_widget_get_pointer (GTK_WIDGET (gwidget->object), &x, &y); - - right = GLADE_FIXED_CURSOR_RIGHT (fixed->operation); - left = GLADE_FIXED_CURSOR_LEFT (fixed->operation); - top = GLADE_FIXED_CURSOR_TOP (fixed->operation); - bottom = GLADE_FIXED_CURSOR_BOTTOM (fixed->operation); - - /* Filter out events that make your widget go out of bounds */ - glade_fixed_filter_event (fixed, &x, &y, left, right, top, bottom); - - new_area.x = fixed->child_x_origin; - new_area.y = fixed->child_y_origin; - new_area.width = fixed->child_width_origin; - new_area.height = fixed->child_height_origin; - - /* Modify current size. - */ - if (fixed->operation == GLADE_CURSOR_DRAG) - { - /* Move widget */ - new_area.x = fixed->child_x_origin + - x - fixed->pointer_x_origin; - new_area.y = fixed->child_y_origin + - y - fixed->pointer_y_origin; - - } else { - - if (bottom) - { - new_area.height = - fixed->child_height_origin + - (y - fixed->pointer_y_origin); - } else if (top) - { - - new_area.height = - fixed->child_height_origin - - (y - fixed->pointer_y_origin); - new_area.y = - fixed->child_y_origin + - (y - fixed->pointer_y_origin); - } - - if (right) - { - new_area.width = - fixed->child_width_origin + - (x - fixed->pointer_x_origin); - } else if (left) - { - new_area.width = - fixed->child_width_origin - - (x - fixed->pointer_x_origin); - new_area.x = - fixed->child_x_origin + - (x - fixed->pointer_x_origin); - } - } - - /* Trim */ - if (new_area.width < CHILD_WIDTH_MIN) - new_area.width = CHILD_WIDTH_MIN; - if (new_area.height < CHILD_WIDTH_MIN) - new_area.height = CHILD_HEIGHT_MIN; - - /* before configuring the child widget, make make sure the target child - * widget area is visible if the GladeFixed is placed inside a scrolled - * window or a viewport inside a scrolled window. - */ - glade_fixed_handle_swindow (fixed, &new_area); - - /* Apply new rectangle to the object */ - g_signal_emit (G_OBJECT (fixed), - glade_fixed_signals[CONFIGURE_CHILD], - 0, child, &new_area, &handled); - - /* Correct glitches when some widgets are draged over others */ - gtk_widget_queue_draw (GTK_WIDGET (GLADE_WIDGET (fixed)->object)); -} - -static void -glade_fixed_disconnect_child (GladeFixed *fixed, - GladeWidget *child) -{ - GFSigData *data; - - if (GTK_IS_WIDGET (child->object) == FALSE) - return; - - if ((data = g_object_get_data (G_OBJECT (child), "glade-fixed-signal-data")) != NULL) - { - g_signal_handler_disconnect (child, data->press_id); - g_signal_handler_disconnect (child, data->release_id); - g_signal_handler_disconnect (child, data->motion_id); - - g_object_set_data (G_OBJECT (child), "glade-fixed-signal-data", NULL); - } -} - -static void -glade_fixed_connect_child (GladeFixed *fixed, - GladeWidget *child) -{ - GFSigData *data; - - if (GTK_IS_WIDGET (child->object) == FALSE) - return; - - if ((data = g_object_get_data (G_OBJECT (child), "glade-fixed-signal-data")) != NULL) - glade_fixed_disconnect_child (fixed, child); - - data = g_new (GFSigData, 1); - - /* Connect-after here... leave a chance for selection - */ - data->press_id = - g_signal_connect_after - (child, "button-press-event", G_CALLBACK - (GLADE_FIXED_GET_CLASS(fixed)->child_event), fixed); - data->release_id = - g_signal_connect - (child, "button-release-event", G_CALLBACK - (GLADE_FIXED_GET_CLASS(fixed)->child_event), fixed); - data->motion_id = - g_signal_connect - (child, "motion-notify-event", G_CALLBACK - (GLADE_FIXED_GET_CLASS(fixed)->child_event), fixed); - - - g_object_set_data_full (G_OBJECT (child), "glade-fixed-signal-data", - data, g_free); -} - -/******************************************************************************* - GladeFixedClass - *******************************************************************************/ -static gboolean -glade_fixed_configure_child_impl (GladeFixed *fixed, - GladeWidget *child, - GdkRectangle *rect) -{ - /* Make sure we can modify these properties */ - glade_widget_pack_property_set_enabled (child, fixed->x_prop, TRUE); - glade_widget_pack_property_set_enabled (child, fixed->y_prop, TRUE); - glade_widget_property_set_enabled (child, fixed->width_prop, TRUE); - glade_widget_property_set_enabled (child, fixed->height_prop, TRUE); - - glade_widget_pack_property_set (child, fixed->x_prop, rect->x); - glade_widget_pack_property_set (child, fixed->y_prop, rect->y); - glade_widget_property_set (child, fixed->width_prop, rect->width); - glade_widget_property_set (child, fixed->height_prop, rect->height); - return TRUE; -} - - -static gboolean -glade_fixed_configure_end_impl (GladeFixed *fixed, - GladeWidget *child) -{ - GValue x_value = { 0, }; - GValue y_value = { 0, }; - GValue width_value = { 0, }; - GValue height_value = { 0, }; - GValue new_x_value = { 0, }; - GValue new_y_value = { 0, }; - GValue new_width_value = { 0, }; - GValue new_height_value = { 0, }; - GladeProperty *x_prop, *y_prop, *width_prop, *height_prop; - - x_prop = glade_widget_get_pack_property (child, fixed->x_prop); - y_prop = glade_widget_get_pack_property (child, fixed->y_prop); - width_prop = glade_widget_get_property (child, fixed->width_prop); - height_prop = glade_widget_get_property (child, fixed->height_prop); - - g_return_val_if_fail (GLADE_IS_PROPERTY (x_prop), FALSE); - g_return_val_if_fail (GLADE_IS_PROPERTY (y_prop), FALSE); - g_return_val_if_fail (GLADE_IS_PROPERTY (width_prop), FALSE); - g_return_val_if_fail (GLADE_IS_PROPERTY (height_prop), FALSE); - - g_value_init (&x_value, G_TYPE_INT); - g_value_init (&y_value, G_TYPE_INT); - g_value_init (&width_value, G_TYPE_INT); - g_value_init (&height_value, G_TYPE_INT); - - glade_property_get_value (x_prop, &new_x_value); - glade_property_get_value (y_prop, &new_y_value); - glade_property_get_value (width_prop, &new_width_value); - glade_property_get_value (height_prop, &new_height_value); - - g_value_set_int (&x_value, fixed->child_x_origin); - g_value_set_int (&y_value, fixed->child_y_origin); - g_value_set_int (&width_value, fixed->child_width_origin); - g_value_set_int (&height_value, fixed->child_height_origin); - - glade_command_push_group (_("Placing %s inside %s"), - child->name, - GLADE_WIDGET (fixed)->name); - - /* whew, all that for this call ! - */ - glade_command_set_properties (x_prop, &x_value, &new_x_value, - y_prop, &y_value, &new_y_value, - width_prop, &width_value, &new_width_value, - height_prop, &height_value, &new_height_value, - NULL); - - glade_command_pop_group (); - - g_value_unset (&x_value); - g_value_unset (&y_value); - g_value_unset (&width_value); - g_value_unset (&height_value); - g_value_unset (&new_x_value); - g_value_unset (&new_y_value); - g_value_unset (&new_width_value); - g_value_unset (&new_height_value); - - return TRUE; -} - - -static void -glade_fixed_cancel_operation (GladeFixed *fixed, - GladeCursorType new_operation) -{ - gboolean handled; - - g_signal_emit (G_OBJECT (fixed), - glade_fixed_signals[CONFIGURE_END], - 0, fixed->configuring, &handled); - - /* Leave the machine state intact untill after - * the user handled signal. - */ - fixed->operation = new_operation; - fixed->configuring = NULL; -} - -static gboolean -glade_fixed_handle_child_event (GladeFixed *fixed, - GladeWidget *child, - GtkWidget *event_widget, - GdkEvent *event) -{ - GladeCursorType operation; - GdkModifierType event_state = 0; - GladePointerMode pointer_mode; - GtkWidget *fixed_widget, *child_widget; - gint fixed_x, fixed_y, child_x, child_y; - gboolean handled = FALSE, sig_handled; - - fixed_widget = GTK_WIDGET (GLADE_WIDGET (fixed)->object); - child_widget = GTK_WIDGET (child->object); - - pointer_mode = glade_app_get_pointer_mode (); - - /* when widget->window points to a parent window, these calculations - * would be wrong if we based them on the GTK_WIDGET (fixed)->window, - * so we must always consult the event widget's window - */ - gtk_widget_get_pointer (fixed_widget, &fixed_x, &fixed_y); - - /* Container widgets are trustable to have widget->window occupying - * the entire widget allocation (gtk_widget_get_pointer broken on GtkEntry). - */ - gtk_widget_translate_coordinates (fixed_widget, - child_widget, - fixed_x, fixed_y, - &child_x, &child_y); - - if (fixed->can_resize) - operation = glade_fixed_get_operation (GTK_WIDGET (child->object), - child_x, child_y); - else - operation = GLADE_CURSOR_DRAG; - - gdk_event_get_state (event, &event_state); - - switch (event->type) - { - case GDK_MOTION_NOTIFY: - if (fixed->configuring == NULL) - { - if ((event_state & GDK_SHIFT_MASK) || - pointer_mode == GLADE_POINTER_DRAG_RESIZE) - glade_cursor_set (((GdkEventAny *)event)->window, - operation); - else if (pointer_mode == GLADE_POINTER_SELECT) - glade_cursor_set (((GdkEventAny *)event)->window, - GLADE_CURSOR_SELECTOR); - - } else if (fixed->configuring && !(event_state & GDK_BUTTON1_MASK)) - { - /* Cancel drags that no longer have mouse down */ - glade_cursor_set (((GdkEventAny *)event)->window, - operation); - - glade_fixed_cancel_operation (fixed, operation); - handled = TRUE; - } else if (fixed->configuring) - { - /* Need to update mouse for configures. */ - gtk_widget_get_pointer (fixed_widget, - &fixed->mouse_x, &fixed->mouse_y); - - glade_fixed_configure_widget (fixed, child); - glade_cursor_set (((GdkEventAny *)event)->window, - fixed->operation); - handled = TRUE; - } - - gdk_window_get_pointer (GTK_WIDGET (child->object)->window, NULL, NULL, NULL); - break; - case GDK_BUTTON_PRESS: - /* We cant rely on GDK_BUTTON1_MASK since event->state isnt yet updated - * by the current event itself - */ - if (((GdkEventButton *)event)->button == 1 && - ((event_state & GDK_SHIFT_MASK) || - pointer_mode == GLADE_POINTER_DRAG_RESIZE)) - { - fixed->configuring = child; - /* Save widget allocation and pointer pos */ - glade_fixed_save_state (fixed, child); - - fixed->operation = operation; - glade_cursor_set (((GdkEventAny *)event)->window, fixed->operation); - - g_signal_emit (G_OBJECT (fixed), - glade_fixed_signals[CONFIGURE_BEGIN], - 0, child, &sig_handled); - - handled = TRUE; - } - break; - case GDK_BUTTON_RELEASE: - if (((GdkEventButton *)event)->button == 1 && fixed->configuring) - { - - if ((event_state & GDK_SHIFT_MASK) || - pointer_mode == GLADE_POINTER_DRAG_RESIZE) - glade_cursor_set (((GdkEventAny *)event)->window, - operation); - else - glade_cursor_set (((GdkEventAny *)event)->window, - GLADE_CURSOR_SELECTOR); - - glade_fixed_cancel_operation (fixed, operation); - handled = TRUE; - } - break; - default: - break; - } - return handled; -} - -static gint -glade_fixed_child_event (GladeWidget *gwidget, - GdkEvent *event, - GladeFixed *fixed) -{ - GtkWidget *event_widget; - - /* Get the basic event info... */ - gdk_window_get_user_data (((GdkEventAny *)event)->window, (gpointer)&event_widget); - - /* Skip all this choosyness if we're already in a drag/resize - */ - if (fixed->configuring) - { - return glade_fixed_handle_child_event - (fixed, fixed->configuring, event_widget, event); - } - - g_return_val_if_fail (GLADE_IS_WIDGET (gwidget), FALSE); - - /* Early return for fixed children with selection in - * the palette. - */ - if (GLADE_IS_FIXED (gwidget) && - glade_app_get_pointer_mode() == GLADE_POINTER_ADD_WIDGET) - { - glade_cursor_set (((GdkEventAny *)event)->window, - GLADE_CURSOR_ADD_WIDGET); - return FALSE; - } - - return glade_fixed_handle_child_event - (fixed, gwidget, event_widget, event); - -} - -/******************************************************************************* - GladeWidgetClass - *******************************************************************************/ -static void -glade_fixed_add_child_impl (GladeWidget *gwidget_fixed, - GladeWidget *child, - gboolean at_mouse) -{ - GladeFixed *fixed = GLADE_FIXED (gwidget_fixed); - GdkRectangle rect; - gboolean handled; - - g_return_if_fail (GLADE_IS_FIXED (fixed)); - g_return_if_fail (GLADE_IS_WIDGET (child)); - - /* Chain up for the basic parenting */ - GLADE_WIDGET_CLASS (parent_class)->add_child - (GLADE_WIDGET (fixed), child, at_mouse); - - gtk_widget_add_events (GTK_WIDGET (child->object), - GDK_POINTER_MOTION_MASK | - GDK_POINTER_MOTION_HINT_MASK | - GDK_BUTTON_PRESS_MASK | - GDK_BUTTON_RELEASE_MASK | - GDK_ENTER_NOTIFY_MASK); - - glade_fixed_connect_child (fixed, child); - - /* Setup rect and send configure - */ - if (fixed->creating) - { - rect.x = fixed->mouse_x; - rect.y = fixed->mouse_y; - rect.width = CHILD_WIDTH_DEF; - rect.height = CHILD_HEIGHT_DEF; - - g_signal_emit (G_OBJECT (fixed), - glade_fixed_signals[CONFIGURE_CHILD], - 0, child, &rect, &handled); - } - else if (at_mouse) - { - rect.x = fixed->mouse_x; - rect.y = fixed->mouse_y; - rect.width = GTK_WIDGET (child->object)->allocation.width; - rect.height = GTK_WIDGET (child->object)->allocation.height; - - if (rect.width < CHILD_WIDTH_DEF) - rect.width = CHILD_WIDTH_DEF; - - if (rect.height < CHILD_HEIGHT_DEF) - rect.height = CHILD_HEIGHT_DEF; - - g_signal_emit (G_OBJECT (fixed), - glade_fixed_signals[CONFIGURE_CHILD], - 0, child, &rect, &handled); - } - return; -} - -static void -glade_fixed_remove_child_impl (GladeWidget *fixed, - GladeWidget *child) -{ - glade_fixed_disconnect_child (GLADE_FIXED (fixed), child); - - /* Chain up for the basic unparenting */ - GLADE_WIDGET_CLASS (parent_class)->remove_child - (GLADE_WIDGET (fixed), child); -} - -static void -glade_fixed_replace_child_impl (GladeWidget *fixed, - GObject *old_object, - GObject *new_object) -{ - GladeWidget *gnew_widget = glade_widget_get_from_gobject (new_object); - GladeWidget *gold_widget = glade_widget_get_from_gobject (old_object); - - if (gold_widget) - glade_fixed_disconnect_child (GLADE_FIXED (fixed), gold_widget); - - /* Chain up for the basic reparenting */ - GLADE_WIDGET_CLASS (parent_class)->replace_child - (GLADE_WIDGET (fixed), old_object, new_object); - - if (gnew_widget) - glade_fixed_connect_child (GLADE_FIXED (fixed), gnew_widget); -} - -static gint -glade_fixed_event (GladeWidget *gwidget_fixed, - GdkEvent *event) -{ - GladeFixed *fixed = GLADE_FIXED (gwidget_fixed); - GladeWidgetAdaptor *adaptor; - GtkWidget *event_widget; - gboolean handled = FALSE; - - adaptor = glade_palette_get_current_item (glade_app_get_palette ()); - - /* Get the event widget and the deep widget */ - gdk_window_get_user_data (((GdkEventAny *)event)->window, (gpointer)&event_widget); - - /* If the GladeWidget used this event... let it slide. - */ - if (GLADE_WIDGET_CLASS (parent_class)->event (gwidget_fixed, event)) - return TRUE; - - switch (event->type) - { - - case GDK_BUTTON_PRESS: - case GDK_MOTION_NOTIFY: - case GDK_BUTTON_RELEASE: - gtk_widget_get_pointer (GTK_WIDGET (gwidget_fixed->object), - &fixed->mouse_x, &fixed->mouse_y); - if (fixed->configuring) - { - return glade_fixed_handle_child_event - (fixed, fixed->configuring, - event_widget, event); - } - break; - default: - break; - } - - switch (event->type) - { - case GDK_BUTTON_PRESS: /* add widget */ - if (((GdkEventButton *) event)->button == 1) - { - - if (adaptor != NULL) - { - /* A widget type is selected in the palette. - * Add a new widget of that type. - */ - fixed->creating = TRUE; - glade_command_create (adaptor, - GLADE_WIDGET (fixed), NULL, - GLADE_WIDGET (fixed)->project); - fixed->creating = FALSE; - - glade_palette_deselect_current_item (glade_app_get_palette(), TRUE); - - handled = TRUE; - } - } - break; - case GDK_MOTION_NOTIFY: - if (glade_app_get_pointer_mode() == GLADE_POINTER_ADD_WIDGET) - { - glade_cursor_set (((GdkEventAny *)event)->window, - GLADE_CURSOR_ADD_WIDGET); - - handled = TRUE; - } - else if (GLADE_IS_FIXED (gwidget_fixed->parent) == FALSE && - glade_app_get_pointer_mode() == GLADE_POINTER_SELECT) - glade_cursor_set (((GdkEventAny *)event)->window, - GLADE_CURSOR_SELECTOR); - break; - default: - break; - } - return handled; -} - -/******************************************************************************* - GObjectClass - *******************************************************************************/ -static void -glade_fixed_finalize (GObject *object) -{ - GladeFixed *fixed = GLADE_FIXED (object); - - /* A GladeFixed should be finalized as a result of its - * GtkContainer being destroyed, so we shouldn't need to bother - * about disconnecting all the child signals. - */ - g_free (fixed->x_prop); - g_free (fixed->y_prop); - g_free (fixed->width_prop); - g_free (fixed->height_prop); - - G_OBJECT_CLASS (parent_class)->finalize (object); -} - -static void -glade_fixed_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - GladeFixed *fixed = GLADE_FIXED (object); - - switch (prop_id) - { - case PROP_X_PROP: - g_free (fixed->x_prop); - fixed->x_prop = g_value_dup_string (value); - break; - case PROP_Y_PROP: - g_free (fixed->y_prop); - fixed->y_prop = g_value_dup_string (value); - break; - case PROP_WIDTH_PROP: - g_free (fixed->width_prop); - fixed->width_prop = g_value_dup_string (value); - break; - case PROP_HEIGHT_PROP: - g_free (fixed->height_prop); - fixed->height_prop = g_value_dup_string (value); - break; - case PROP_CAN_RESIZE: - fixed->can_resize = g_value_get_boolean (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -glade_fixed_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - GladeFixed *fixed = GLADE_FIXED (object); - - switch (prop_id) - { - case PROP_X_PROP: g_value_set_string (value, fixed->x_prop); break; - case PROP_Y_PROP: g_value_set_string (value, fixed->y_prop); break; - case PROP_WIDTH_PROP: g_value_set_string (value, fixed->width_prop); break; - case PROP_HEIGHT_PROP: g_value_set_string (value, fixed->height_prop); break; - case PROP_CAN_RESIZE: g_value_set_boolean (value, fixed->can_resize); break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -glade_fixed_init (GladeFixed *fixed) -{ - /* Set defaults */ - fixed->x_prop = g_strdup ("x"); - fixed->y_prop = g_strdup ("y"); - fixed->width_prop = g_strdup ("width"); - fixed->height_prop = g_strdup ("height"); - fixed->can_resize = TRUE; -} - -static void -glade_fixed_class_init (GladeFixedClass *fixed_class) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (fixed_class); - GladeWidgetClass *gwidget_class = GLADE_WIDGET_CLASS (fixed_class); - - parent_class = - G_OBJECT_CLASS - (g_type_class_peek_parent (gobject_class)); - - gobject_class->finalize = glade_fixed_finalize; - gobject_class->set_property = glade_fixed_set_property; - gobject_class->get_property = glade_fixed_get_property; - - gwidget_class->event = glade_fixed_event; - gwidget_class->add_child = glade_fixed_add_child_impl; - gwidget_class->remove_child = glade_fixed_remove_child_impl; - gwidget_class->replace_child = glade_fixed_replace_child_impl; - - fixed_class->configure_child = glade_fixed_configure_child_impl; - fixed_class->configure_begin = NULL; - fixed_class->configure_end = glade_fixed_configure_end_impl; - fixed_class->child_event = glade_fixed_child_event; - - /* Properties */ - g_object_class_install_property - (gobject_class, PROP_X_PROP, - g_param_spec_string - ("x_prop", _("X position property"), - _("The property used to set the X position of a child object"), - "x", G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); - - g_object_class_install_property - (gobject_class, PROP_Y_PROP, - g_param_spec_string - ("y_prop", _("Y position property"), - _("The property used to set the Y position of a child object"), - "y", G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); - - g_object_class_install_property - (gobject_class, PROP_WIDTH_PROP, - g_param_spec_string - ("width_prop", _("Width property"), - _("The property used to set the width of a child object"), - "width-request", G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); - - g_object_class_install_property - (gobject_class, PROP_HEIGHT_PROP, - g_param_spec_string - ("height_prop", _("Height property"), - _("The property used to set the height of a child object"), - "height-request", G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); - - g_object_class_install_property - (gobject_class, PROP_CAN_RESIZE, - g_param_spec_boolean - ("can_resize", _("Can resize"), - _("Whether this container supports resizes of child widgets"), - TRUE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); - - /** - * GladeFixed::configure-child: - * @gladewidget: the #GladeFixed which received the signal. - * @arg1: the child #GladeWidget - * @arg2: a pointer to a #GdkRectange describing the new size. - * - * Delegates the Drag/Resize job. - * - * Returns: %TRUE means you have handled the event and cancels the - * default handler from being triggered. - */ - glade_fixed_signals[CONFIGURE_CHILD] = - g_signal_new ("configure-child", - G_TYPE_FROM_CLASS (gobject_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET - (GladeFixedClass, configure_child), - glade_boolean_handled_accumulator, NULL, - glade_marshal_BOOLEAN__OBJECT_POINTER, - G_TYPE_BOOLEAN, 2, G_TYPE_OBJECT, G_TYPE_POINTER); - - /** - * GladeFixed::configure-begin: - * @gladewidget: the #GladeFixed which received the signal. - * @arg1: the child #GladeWidget - * - * Signals the beginning of a Drag/Resize - * - * Returns: %TRUE means you have handled the event and cancels the - * default handler from being triggered. - */ - glade_fixed_signals[CONFIGURE_BEGIN] = - g_signal_new ("configure-begin", - G_TYPE_FROM_CLASS (gobject_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET - (GladeFixedClass, configure_begin), - glade_boolean_handled_accumulator, NULL, - glade_marshal_BOOLEAN__OBJECT, - G_TYPE_BOOLEAN, 1, G_TYPE_OBJECT); - - /** - * GladeFixed::configure-end: - * @gladewidget: the #GladeFixed which received the signal. - * @arg1: the child #GladeWidget - * - * Signals the end of a Drag/Resize - * - * Returns: %TRUE means you have handled the event and cancels the - * default handler from being triggered. - */ - glade_fixed_signals[CONFIGURE_END] = - g_signal_new ("configure-end", - G_TYPE_FROM_CLASS (gobject_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET - (GladeFixedClass, configure_end), - glade_boolean_handled_accumulator, NULL, - glade_marshal_BOOLEAN__OBJECT, - G_TYPE_BOOLEAN, 1, G_TYPE_OBJECT); -} - - -/******************************************************************************* - API -*******************************************************************************/ - -GType -glade_fixed_get_type (void) -{ - static GType fixed_type = 0; - - if (!fixed_type) - { - static const GTypeInfo fixed_info = - { - sizeof (GladeFixedClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) glade_fixed_class_init, - (GClassFinalizeFunc) NULL, - NULL, /* class_data */ - sizeof (GladeFixed), - 0, /* n_preallocs */ - (GInstanceInitFunc) glade_fixed_init, - }; - fixed_type = - g_type_register_static (GLADE_TYPE_WIDGET, - "GladeFixed", - &fixed_info, 0); - } - return fixed_type; -} diff --git a/gladeui/glade-fixed.h b/gladeui/glade-fixed.h deleted file mode 100644 index a1b2f2e6..00000000 --- a/gladeui/glade-fixed.h +++ /dev/null @@ -1,93 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef __GLADE_FIXED_H__ -#define __GLADE_FIXED_H__ - -#include <glib-object.h> -#include <gdk/gdk.h> - -#include <gladeui/glade-widget.h> -#include <gladeui/glade-cursor.h> - -G_BEGIN_DECLS - -#define GLADE_TYPE_FIXED (glade_fixed_get_type()) -#define GLADE_FIXED(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_FIXED, GladeFixed)) -#define GLADE_FIXED_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_FIXED, GladeFixedClass)) -#define GLADE_IS_FIXED(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_FIXED)) -#define GLADE_IS_FIXED_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_FIXED)) -#define GLADE_FIXED_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GLADE_FIXED, GladeFixedClass)) - -/* Convenience macros used in pointer events. - */ -#define GLADE_FIXED_CURSOR_TOP(type) \ - ((type) == GLADE_CURSOR_RESIZE_TOP_RIGHT || \ - (type) == GLADE_CURSOR_RESIZE_TOP_LEFT || \ - (type) == GLADE_CURSOR_RESIZE_TOP) - -#define GLADE_FIXED_CURSOR_BOTTOM(type) \ - ((type) == GLADE_CURSOR_RESIZE_BOTTOM_RIGHT || \ - (type) == GLADE_CURSOR_RESIZE_BOTTOM_LEFT || \ - (type) == GLADE_CURSOR_RESIZE_BOTTOM) - -#define GLADE_FIXED_CURSOR_RIGHT(type) \ - ((type) == GLADE_CURSOR_RESIZE_TOP_RIGHT || \ - (type) == GLADE_CURSOR_RESIZE_BOTTOM_RIGHT || \ - (type) == GLADE_CURSOR_RESIZE_RIGHT) - -#define GLADE_FIXED_CURSOR_LEFT(type) \ - ((type) == GLADE_CURSOR_RESIZE_TOP_LEFT || \ - (type) == GLADE_CURSOR_RESIZE_BOTTOM_LEFT || \ - (type) == GLADE_CURSOR_RESIZE_LEFT) - -typedef struct _GladeFixed GladeFixed; -typedef struct _GladeFixedClass GladeFixedClass; - -struct _GladeFixed { - GladeWidget parent_instance; - - gchar *x_prop; /* packing property names (on child widgets) used */ - gchar *y_prop; /* to obtain & configure widget coordinates */ - gchar *width_prop; /* property names (on child widgets) used to obtain */ - gchar *height_prop; /* & configure widget dimentions. */ - - gboolean can_resize; /* whether the container supports child resizes or only - * drags. - */ - - /* State machine used to commit properties at the end - * of a drag or a resize (i.e. a "configure"). - */ - gint pointer_x_origin; - gint pointer_y_origin; - gint pointer_x_child_origin; - gint pointer_y_child_origin; - gint child_x_origin; - gint child_y_origin; - gint child_width_origin; - gint child_height_origin; - - GladeWidget *configuring; - GladeCursorType operation; - gboolean creating; - gint mouse_x; - gint mouse_y; -}; - -struct _GladeFixedClass { - GladeWidgetClass parent_class; - - gboolean (* configure_child) (GladeFixed *, GladeWidget *, GdkRectangle *); - gboolean (* configure_begin) (GladeFixed *, GladeWidget *); - gboolean (* configure_end) (GladeFixed *, GladeWidget *); - - /* Signal handler for child widgets - */ - gint (* child_event) (GladeWidget *, GdkEvent *, GladeFixed *); - -}; - -GType glade_fixed_get_type (void); - -G_END_DECLS - -#endif /* __GLADE_FIXED_H__ */ diff --git a/gladeui/glade-id-allocator.c b/gladeui/glade-id-allocator.c deleted file mode 100644 index e2053171..00000000 --- a/gladeui/glade-id-allocator.c +++ /dev/null @@ -1,190 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2004 Owen Taylor - * - * Authors: - * Owen Taylor <otaylor@redhat.com> - * - * Modified by the Glade developers - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#include "config.h" -#include "glade-id-allocator.h" - -#include <glib.h> -#include <string.h> - -#define INITIAL_WORDS 4 - -struct _GladeIDAllocator -{ - guint n_words; - guint32 *data; -}; - -/** - * glade_id_allocator_new: - * - * Returns: a new #GladeIDAllocator - */ -GladeIDAllocator * -glade_id_allocator_new (void) -{ - GladeIDAllocator *allocator = g_slice_new (GladeIDAllocator); - - allocator->n_words = INITIAL_WORDS; - allocator->data = g_new (guint32, INITIAL_WORDS); - - memset (allocator->data, 0xff, INITIAL_WORDS * sizeof (guint32)); - - return allocator; -} - -/** - * glade_id_allocator_destroy: - * @allocator: a #GladeIDAllocator - * - * Frees @allocator and its associated memory - */ -void -glade_id_allocator_destroy (GladeIDAllocator *allocator) -{ - g_return_if_fail (allocator != NULL); - - g_free (allocator->data); - g_slice_free (GladeIDAllocator, allocator); -} - -static inline gint -first_set_bit (guint32 word) -{ - static const char table[16] = { - 4, 0, 1, 0, - 2, 0, 1, 0, - 3, 0, 1, 0, - 2, 0, 1, 0 - }; - - gint result = 0; - - if ((word & 0xffff) == 0) - { - word >>= 16; - result += 16; - } - - if ((word & 0xff) == 0) - { - word >>= 8; - result += 8; - } - - if ((word & 0xf) == 0) - { - word >>= 4; - result += 4; - } - - return result + table[word & 0xf]; -} - -/** - * glade_id_allocator_alloc: - * @allocator: a #GladeIDAllocator - * - * TODO: write me - * Returns: - */ -guint -glade_id_allocator_allocate (GladeIDAllocator *allocator) -{ - guint i; - - g_return_val_if_fail (allocator != NULL, 0); - - for (i = 0; i < allocator->n_words; i++) - { - if (allocator->data[i] != 0) - { - gint free_bit = first_set_bit (allocator->data[i]); - allocator->data[i] &= ~(1 << free_bit); - - return 32 * i + free_bit + 1; - } - } - - { - guint n_words = allocator->n_words; - - allocator->data = g_renew (guint32, allocator->data, n_words * 2); - memset (&allocator->data[n_words], 0xff, n_words * sizeof (guint32)); - allocator->n_words = n_words * 2; - - allocator->data[n_words] = 0xffffffff - 1; - - return 32 * n_words + 1; - } -} - -/** - * glade_id_allocator_release: - * @allocator: - * @id: - * - * TODO: write me - */ -void -glade_id_allocator_release (GladeIDAllocator *allocator, - guint id) -{ - g_return_if_fail (allocator != NULL); - - id--; - allocator->data[id >> 5] |= 1 << (id & 31); -} - -#ifdef GLADE_ID_ALLOCATOR_TEST -int main (int argc, char **argv) -{ - GladeIDAllocator *allocator = glade_id_allocator_new (); - guint i; - guint iter; - - for (i = 0; i < 1000; i++) - { - guint id = glade_id_allocator_allocate (allocator); - g_assert (id == i); - } - - for (i = 0; i < 1000; i++) - glade_id_allocator_release (allocator, i); - - for (iter = 0; iter < 10000; iter++) - { - for (i = 0; i < 1000; i++) - glade_id_allocator_alloc (allocator); - - for (i = 0; i < 1000; i++) - glade_id_allocator_release (allocator, i); - } - - glade_id_allocator_destroy (allocator); - - return 0; -} -#endif diff --git a/gladeui/glade-id-allocator.h b/gladeui/glade-id-allocator.h deleted file mode 100644 index f842fdb3..00000000 --- a/gladeui/glade-id-allocator.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2004 Owen Taylor - * - * Authors: - * Owen Taylor <otaylor@redhat.com> - * - * Modified by the Glade developers - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#ifndef __GLADE_ID_ALLOCATOR_H__ -#define __GLADE_ID_ALLOCATOR_H__ - -#include <glib.h> - -G_BEGIN_DECLS - -typedef struct _GladeIDAllocator GladeIDAllocator; - -GladeIDAllocator *glade_id_allocator_new (void); - -void glade_id_allocator_destroy (GladeIDAllocator *allocator); - -guint glade_id_allocator_allocate (GladeIDAllocator *allocator); - -void glade_id_allocator_release (GladeIDAllocator *allocator, - guint id); - -G_END_DECLS - -#endif /* __GLADE_ID_ALLOCATOR_H__ */ - diff --git a/gladeui/glade-inspector.c b/gladeui/glade-inspector.c deleted file mode 100644 index 4d1d9a59..00000000 --- a/gladeui/glade-inspector.c +++ /dev/null @@ -1,807 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * glade-inspector.h - * - * Copyright (C) 2001 Ximian, Inc. - * Copyright (C) 2007 Vincent Geddes - * - * Authors: - * Chema Celorio - * Tristan Van Berkom <tvb@gnome.org> - * Vincent Geddes <vincent.geddes@gmail.com> - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include <config.h> - -#include "glade.h" -#include "glade-widget.h" -#include "glade-project.h" -#include "glade-widget-adaptor.h" -#include "glade-inspector.h" -#include "glade-popup.h" -#include "glade-app.h" - -#include <string.h> -#include <glib/gi18n-lib.h> - -#define GLADE_INSPECTOR_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object),\ - GLADE_TYPE_INSPECTOR, \ - GladeInspectorPrivate)) - -enum -{ - PROP_0, - PROP_PROJECT -}; - -enum -{ - SELECTION_CHANGED, - ITEM_ACTIVATED, - LAST_SIGNAL -}; - -enum -{ - WIDGET_COLUMN, - N_COLUMNS -}; - -struct _GladeInspectorPrivate -{ - GtkWidget *view; - GtkTreeStore *model; - - GladeProject *project; -}; - - -static guint glade_inspector_signals[LAST_SIGNAL] = {0}; - - -static void glade_inspector_dispose (GObject *object); -static void glade_inspector_finalize (GObject *object); -static void add_columns (GtkTreeView *inspector); -static void item_activated_cb (GtkTreeView *view, - GtkTreePath *path, - GtkTreeViewColumn *column, - GladeInspector *inspector); -static void selection_changed_cb (GtkTreeSelection *selection, - GladeInspector *inspector); -static gint button_press_cb (GtkWidget *widget, - GdkEventButton *event, - GladeInspector *inspector); -static void update_model (GladeInspector *inspector); -static void disconnect_project_signals (GladeInspector *inspector, - GladeProject *project); -static void connect_project_signals (GladeInspector *inspector, - GladeProject *project); - -G_DEFINE_TYPE (GladeInspector, glade_inspector, GTK_TYPE_VBOX) - - -static void -glade_inspector_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - GladeInspector *inspector = GLADE_INSPECTOR (object); - - switch (property_id) - { - case PROP_PROJECT: - glade_inspector_set_project (inspector, g_value_get_object (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -glade_inspector_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - GladeInspector *inspector = GLADE_INSPECTOR (object); - - switch (property_id) - { - case PROP_PROJECT: - g_value_set_object (value, glade_inspector_get_project (inspector)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -inspector_notify_cb (GObject *object, - GParamSpec *pspec) -{ - update_model (GLADE_INSPECTOR (object)); -} - -static void -glade_inspector_class_init (GladeInspectorClass *klass) -{ - GObjectClass *object_class; - - object_class = G_OBJECT_CLASS (klass); - - object_class->dispose = glade_inspector_dispose; - object_class->finalize = glade_inspector_finalize; - object_class->set_property = glade_inspector_set_property; - object_class->get_property = glade_inspector_get_property; - - /** - * GladeInspector::selection-changed: - * @inspector: the object which received the signal - * - * Emitted when the selection changes in the GladeInspector. - */ - glade_inspector_signals[SELECTION_CHANGED] = - g_signal_new ("selection-changed", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GladeInspectorClass, selection_changed), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); - - /** - * GladeInspector::item-activated: - * @inspector: the object which received the signal - * - * Emitted when a item is activated in the GladeInspector. - */ - glade_inspector_signals[ITEM_ACTIVATED] = - g_signal_new ("item-activated", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GladeInspectorClass, item_activated), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); - - g_object_class_install_property (object_class, - PROP_PROJECT, - g_param_spec_object ("project", - _("Project"), - _("The project being inspected"), - GLADE_TYPE_PROJECT, - G_PARAM_READABLE | G_PARAM_WRITABLE)); - - g_type_class_add_private (klass, sizeof (GladeInspectorPrivate)); -} - -static void -glade_inspector_init (GladeInspector *inspector) -{ - GladeInspectorPrivate *priv; - GtkWidget *sw; - GtkTreeSelection *selection; - - inspector->priv = priv = GLADE_INSPECTOR_GET_PRIVATE (inspector); - - gtk_widget_push_composite_child (); - - priv->project = NULL; - priv->view = gtk_tree_view_new (); - - priv->model = gtk_tree_store_new (N_COLUMNS, G_TYPE_POINTER); - gtk_tree_view_set_model (GTK_TREE_VIEW (priv->view), GTK_TREE_MODEL (priv->model)); - g_object_unref (G_OBJECT (priv->model)); - - add_columns (GTK_TREE_VIEW (priv->view)); - - g_signal_connect (G_OBJECT (priv->view), "row-activated", - G_CALLBACK (item_activated_cb), inspector); - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->view)); - gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE); - g_signal_connect (G_OBJECT (selection), "changed", - G_CALLBACK (selection_changed_cb), inspector); - - /* popup menu */ - g_signal_connect (G_OBJECT (priv->view), "button-press-event", - G_CALLBACK (button_press_cb), inspector); - - g_signal_connect (G_OBJECT (inspector), "notify::project", - G_CALLBACK (inspector_notify_cb), - NULL); - - sw = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN); - gtk_container_add (GTK_CONTAINER (sw), priv->view); - gtk_box_pack_start (GTK_BOX (inspector), sw, TRUE, TRUE, 0); - - gtk_widget_show (priv->view); - gtk_widget_show (sw); - - gtk_widget_pop_composite_child (); -} - - -static void -glade_inspector_dispose (GObject *object) -{ - GladeInspectorPrivate *priv = GLADE_INSPECTOR_GET_PRIVATE (object); - - if (priv->project) - { - disconnect_project_signals (GLADE_INSPECTOR (object), priv->project); - g_object_unref (priv->project); - priv->project = NULL; - } - - G_OBJECT_CLASS (glade_inspector_parent_class)->dispose (object); -} - -static void -glade_inspector_finalize (GObject *object) -{ - G_OBJECT_CLASS (glade_inspector_parent_class)->finalize (object); -} - -static void -fill_model (GtkTreeStore *model, - const GList *widgets, - GtkTreeIter *parent_iter) -{ - GList *children, *l; - GtkTreeIter iter; - - for (l = (GList *) widgets; l; l = l->next) - { - GladeWidget *widget; - - widget = glade_widget_get_from_gobject ((GObject *) l->data); - - if (widget != NULL) - { - gtk_tree_store_append (model, &iter, parent_iter); - gtk_tree_store_set (model, &iter, WIDGET_COLUMN, widget, -1); - - children = glade_widget_adaptor_get_children (widget->adaptor, widget->object); - - if (children != NULL) - { - GtkTreeIter *copy = NULL; - - copy = gtk_tree_iter_copy (&iter); - - fill_model (model, children, copy); - - gtk_tree_iter_free (copy); - - g_list_free (children); - } - } - } -} - -static void -update_model (GladeInspector *inspector) -{ - GladeInspectorPrivate *priv = inspector->priv; - GList *l, *toplevels = NULL; - - gtk_tree_store_clear (priv->model); - - if (!priv->project) - return; - - /* make a list of only the toplevel widgets */ - for (l = (GList *) glade_project_get_objects (priv->project); l; l = l->next) - { - GObject *object = G_OBJECT (l->data); - GladeWidget *gwidget = glade_widget_get_from_gobject (object); - g_assert (gwidget); - - if (gwidget->parent == NULL) - toplevels = g_list_prepend (toplevels, object); - } - - /* recursively fill model */ - fill_model (priv->model, toplevels, NULL); - g_list_free (toplevels); -} - -static void -project_add_widget_cb (GladeProject *project, - GladeWidget *widget, - GladeInspector *inspector) -{ - GladeWidget *parent_widget; - GtkTreeIter widget_iter, *parent_iter = NULL; - GList *l; - - parent_widget = glade_widget_get_parent (widget); - if (parent_widget != NULL) - parent_iter = glade_util_find_iter_by_widget (GTK_TREE_MODEL (inspector->priv->model), - parent_widget, - WIDGET_COLUMN); - /* we have to add parents first, then children */ - if (!parent_iter && parent_widget) - return; - - gtk_tree_store_append (inspector->priv->model, &widget_iter, parent_iter); - gtk_tree_store_set (inspector->priv->model, &widget_iter, WIDGET_COLUMN, widget, -1); - - fill_model (inspector->priv->model, - l = glade_widget_adaptor_get_children (widget->adaptor, widget->object), - &widget_iter); - - g_list_free (l); -} - -static void -project_remove_widget_cb (GladeProject *project, - GladeWidget *widget, - GladeInspector *inspector) -{ - GtkTreeIter *iter; - - iter = glade_util_find_iter_by_widget (GTK_TREE_MODEL (inspector->priv->model), - widget, - WIDGET_COLUMN); - if (iter) - { - gtk_tree_store_remove (inspector->priv->model, iter); - gtk_tree_iter_free (iter); - } -} - -static void -project_widget_name_changed_cb (GladeProject *project, - GladeWidget *widget, - GladeInspector *inspector) -{ - GtkTreeModel *model; - GtkTreeIter *iter; - GtkTreePath *path; - - model = GTK_TREE_MODEL (inspector->priv->model); - - iter = glade_util_find_iter_by_widget (model, widget, WIDGET_COLUMN); - - if (iter) - { - path = gtk_tree_model_get_path (model, iter); - gtk_tree_model_row_changed (model, path, iter); - gtk_tree_iter_free (iter); - } -} - -static void -project_selection_changed_cb (GladeProject *project, - GladeInspector *inspector) -{ - GladeWidget *widget; - GtkTreeSelection *selection; - GtkTreeModel *model; - GtkTreeIter *iter; - GtkTreePath *path, *ancestor_path; - GList *list; - - g_return_if_fail (GLADE_IS_INSPECTOR (inspector)); - g_return_if_fail (GLADE_IS_PROJECT (project)); - g_return_if_fail (inspector->priv->project == project); - - g_signal_handlers_block_by_func (gtk_tree_view_get_selection (GTK_TREE_VIEW (inspector->priv->view)), - G_CALLBACK (selection_changed_cb), - inspector); - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (inspector->priv->view)); - g_return_if_fail (selection != NULL); - - model = GTK_TREE_MODEL (inspector->priv->model); - - gtk_tree_selection_unselect_all (selection); - - for (list = glade_project_selection_get (project); - list && list->data; list = list->next) - { - if ((widget = glade_widget_get_from_gobject - (G_OBJECT (list->data))) != NULL) - { - if ((iter = glade_util_find_iter_by_widget - (model, widget, WIDGET_COLUMN)) != NULL) - { - path = gtk_tree_model_get_path (model, iter); - ancestor_path = gtk_tree_path_copy (path); - - /* expand parent node */ - if (gtk_tree_path_up (ancestor_path)) - gtk_tree_view_expand_to_path (GTK_TREE_VIEW (inspector->priv->view), ancestor_path); - - gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (inspector->priv->view), - path, - NULL, - TRUE, - 0.5, - 0); - - gtk_tree_selection_select_iter (selection, iter); - - gtk_tree_iter_free (iter); - gtk_tree_path_free (path); - gtk_tree_path_free (ancestor_path); - } - } - } - - g_signal_handlers_unblock_by_func (gtk_tree_view_get_selection (GTK_TREE_VIEW (inspector->priv->view)), - G_CALLBACK (selection_changed_cb), - inspector); -} - -static void -selection_foreach_func (GtkTreeModel *model, - GtkTreePath *path, - GtkTreeIter *iter, - gpointer data) -{ - GladeWidget *widget; - - gtk_tree_model_get (model, iter, WIDGET_COLUMN, &widget, -1); - - glade_app_selection_add (glade_widget_get_object (widget), FALSE); -} - -static void -selection_changed_cb (GtkTreeSelection *selection, - GladeInspector *inspector) -{ - g_signal_handlers_block_by_func (inspector->priv->project, - G_CALLBACK (project_selection_changed_cb), - inspector); - - glade_app_selection_clear (FALSE); - - gtk_tree_selection_selected_foreach (selection, - selection_foreach_func, - inspector); - glade_app_selection_changed (); - - g_signal_handlers_unblock_by_func (inspector->priv->project, - G_CALLBACK (project_selection_changed_cb), - inspector); - - g_signal_emit_by_name (inspector, "selection-changed"); -} - -static void -item_activated_cb (GtkTreeView *view, - GtkTreePath *path, - GtkTreeViewColumn *column, - GladeInspector *inspector) -{ - g_signal_emit_by_name (inspector, "item-activated"); -} - -static gint -button_press_cb (GtkWidget *widget, - GdkEventButton *event, - GladeInspector *inspector) -{ - GtkTreeView *view = GTK_TREE_VIEW (widget); - GtkTreePath *path = NULL; - gboolean handled = FALSE; - - if (event->window == gtk_tree_view_get_bin_window (view) && - gtk_tree_view_get_path_at_pos (view, (gint) event->x, (gint) event->y, - &path, NULL, - NULL, NULL) && path != NULL) - { - GtkTreeIter iter; - GladeWidget *widget = NULL; - if (gtk_tree_model_get_iter (GTK_TREE_MODEL (inspector->priv->model), - &iter, path)) - { - /* now we can obtain the widget from the iter. - */ - gtk_tree_model_get (GTK_TREE_MODEL (inspector->priv->model), &iter, - WIDGET_COLUMN, &widget, -1); - if (widget != NULL && event->button == 3) - { - glade_popup_widget_pop (widget, event, FALSE); - handled = TRUE; - } - gtk_tree_path_free (path); - } - } - return handled; -} - -typedef enum -{ - CELL_ICON, - CELL_NAME, - CELL_MISC -} CellType; - -static void -glade_inspector_cell_function (GtkTreeViewColumn *tree_column, - GtkCellRenderer *cell, - GtkTreeModel *tree_model, - GtkTreeIter *iter, - gpointer data) -{ - CellType type = GPOINTER_TO_INT (data); - GladeWidget *widget; - gchar *icon_name, *text = NULL, *child_type; - - gtk_tree_model_get (tree_model, iter, WIDGET_COLUMN, &widget, -1); - - /* The cell exists, but no widget has been associated with it */ - if (!GLADE_IS_WIDGET (widget)) - return; - - g_return_if_fail (widget->name != NULL); - g_return_if_fail (widget->adaptor != NULL); - g_return_if_fail (widget->adaptor->name != NULL); - - switch (type) - { - case CELL_ICON: - g_object_get (widget->adaptor, "icon-name", &icon_name, NULL); - g_object_set (G_OBJECT (cell), "icon-name", icon_name, NULL); - g_free (icon_name); - break; - - case CELL_NAME: - g_object_set (G_OBJECT (cell), "text", widget->name, NULL); - break; - case CELL_MISC: - /* special child type / internal child */ - if (glade_widget_get_internal (widget) != NULL) - text = g_strdup_printf (_("(internal %s)"), - glade_widget_get_internal (widget)); - else if ((child_type = g_object_get_data (glade_widget_get_object (widget), - "special-child-type")) != NULL) - text = g_strdup_printf (_("(%s child)"), child_type); - - g_object_set (G_OBJECT (cell), "text", text ? text : " ", NULL); - if (text) g_free (text); - break; - default: - break; - } -} - -static gboolean -glade_inspector_search_func (GtkTreeModel *model, - gint column, - const gchar *key, - GtkTreeIter *iter, - gpointer search_data) -{ - GladeWidget *widget; - - gtk_tree_model_get (model, iter, WIDGET_COLUMN, &widget, -1); - - if (!widget) - return TRUE; - - g_return_val_if_fail (widget->name != NULL, TRUE); - - return ! g_str_has_prefix (widget->name, key); -} - -static void -add_columns (GtkTreeView *view) -{ - GtkTreeViewColumn *column; - GtkCellRenderer *renderer; - - column = gtk_tree_view_column_new (); - - renderer = gtk_cell_renderer_pixbuf_new (); - gtk_tree_view_column_pack_start (column, renderer, FALSE); - gtk_tree_view_column_set_cell_data_func (column, renderer, - glade_inspector_cell_function, - GINT_TO_POINTER (CELL_ICON), NULL); - - renderer = gtk_cell_renderer_text_new (); - g_object_set (G_OBJECT (renderer), - "xpad", 6, NULL); - gtk_tree_view_column_pack_start (column, renderer, TRUE); - gtk_tree_view_column_set_cell_data_func (column, renderer, - glade_inspector_cell_function, - GINT_TO_POINTER (CELL_NAME), NULL); - - renderer = gtk_cell_renderer_text_new (); - g_object_set (G_OBJECT (renderer), - "style", PANGO_STYLE_ITALIC, - "foreground", "Gray", NULL); - gtk_tree_view_column_pack_start (column, renderer, TRUE); - gtk_tree_view_column_set_cell_data_func (column, renderer, - glade_inspector_cell_function, - GINT_TO_POINTER (CELL_MISC), NULL); - - gtk_tree_view_append_column (view, column); - - /* Set search column */ - gtk_tree_view_set_search_equal_func (view, glade_inspector_search_func, NULL, NULL); - gtk_tree_view_set_enable_search (view, TRUE); - gtk_tree_view_set_search_column (view, WIDGET_COLUMN); - - gtk_tree_view_set_headers_visible (view, FALSE); -} - -static void -disconnect_project_signals (GladeInspector *inspector, - GladeProject *project) -{ - g_signal_handlers_disconnect_by_func (G_OBJECT (project), - G_CALLBACK (project_add_widget_cb), - inspector); - g_signal_handlers_disconnect_by_func (G_OBJECT (project), - G_CALLBACK (project_remove_widget_cb), - inspector); - g_signal_handlers_disconnect_by_func (G_OBJECT (project), - G_CALLBACK (project_widget_name_changed_cb), - inspector); - g_signal_handlers_disconnect_by_func (G_OBJECT (project), - G_CALLBACK (project_selection_changed_cb), - inspector); -} - -static void -connect_project_signals (GladeInspector *inspector, - GladeProject *project) -{ - g_signal_connect (G_OBJECT (project), "add-widget", - G_CALLBACK (project_add_widget_cb), - inspector); - g_signal_connect (G_OBJECT (project), "remove-widget", - G_CALLBACK (project_remove_widget_cb), - inspector); - g_signal_connect (G_OBJECT (project), "widget-name-changed", - G_CALLBACK (project_widget_name_changed_cb), - inspector); - g_signal_connect (G_OBJECT (project), "selection-changed", - G_CALLBACK (project_selection_changed_cb), - inspector); -} - -/** - * glade_inspector_set_project: - * @inspector: a #GladeInspector - * @project: a #GladeProject - * - * Sets the current project of @inspector to @project. To unset the current - * project, pass %NULL for @project. - */ -void -glade_inspector_set_project (GladeInspector *inspector, - GladeProject *project) -{ - g_return_if_fail (GLADE_IS_INSPECTOR (inspector)); - g_return_if_fail (GLADE_IS_PROJECT (project) || project == NULL); - - if (inspector->priv->project) - { - disconnect_project_signals (inspector, inspector->priv->project); - g_object_unref (inspector->priv->project); - inspector->priv->project = NULL; - } - - if (project) - { - inspector->priv->project = project; - g_object_ref (inspector->priv->project); - connect_project_signals (inspector, inspector->priv->project); - } - - g_object_notify (G_OBJECT (inspector), "project"); -} - -/** - * glade_inspector_get_project: - * @inspector: a #GladeInspector - * - * Note that the method does not ref the returned #GladeProject. - * - * Returns: A #GladeProject - */ -GladeProject * -glade_inspector_get_project (GladeInspector *inspector) -{ - g_return_val_if_fail (GLADE_IS_INSPECTOR (inspector), NULL); - - return inspector->priv->project; -} - -/** - * glade_inspector_get_selected_items: - * @inspector: a #GladeInspector - * - * Returns the selected items in the inspector. - * - * Returns: A #GList - */ -GList * -glade_inspector_get_selected_items (GladeInspector *inspector) -{ - GtkTreeSelection* selection; - GList *items = NULL, *paths; - - - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (inspector->priv->view)); - - paths = gtk_tree_selection_get_selected_rows (selection, NULL); - - for (; paths; paths = paths->next) - { - GtkTreeIter iter; - GtkTreePath *path = (GtkTreePath *) paths->data; - GladeWidget *widget = NULL; - - gtk_tree_model_get_iter (GTK_TREE_MODEL (inspector->priv->model), &iter, path); - gtk_tree_model_get (GTK_TREE_MODEL (inspector->priv->model), &iter, WIDGET_COLUMN, &widget, -1); - - items = g_list_prepend (items, widget); - } - - g_list_foreach (paths, (GFunc) gtk_tree_path_free, NULL); - g_list_free (paths); - - return items; -} - -/** - * glade_inspector_new: - * - * Creates a new #GladeInspector - * - * Returns: a new #GladeInspector - */ -GtkWidget * -glade_inspector_new (void) -{ - return g_object_new (GLADE_TYPE_INSPECTOR, NULL); -} - -/** - * glade_inspector_new_with_project: - * @project: a #GladeProject - * - * Creates a new #GladeInspector with @project - * - * Returns: a new #GladeInspector - */ -GtkWidget * -glade_inspector_new_with_project (GladeProject *project) -{ - g_return_val_if_fail (GLADE_IS_PROJECT (project), NULL); - - return g_object_new (GLADE_TYPE_INSPECTOR, - "project", project, - NULL); -} - - diff --git a/gladeui/glade-inspector.h b/gladeui/glade-inspector.h deleted file mode 100644 index 935e34d8..00000000 --- a/gladeui/glade-inspector.h +++ /dev/null @@ -1,81 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * glade-inspector.h - * - * Copyright (C) 2001 Ximian, Inc. - * Copyright (C) 2007 Vincent Geddes - * - * Authors: - * Chema Celorio - * Tristan Van Berkom <tvb@gnome.org> - * Vincent Geddes <vincent.geddes@gmail.com> - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef __GLADE_INSPECTOR_H__ -#define __GLADE_INSPECTOR_H__ - -#include <gtk/gtkvbox.h> - -/* forward declaration */ -struct GladeProject; - -G_BEGIN_DECLS - -#define GLADE_TYPE_INSPECTOR (glade_inspector_get_type ()) -#define GLADE_INSPECTOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_INSPECTOR, GladeInspector)) -#define GLADE_INSPECTOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_INSPECTOR, GladeInspectorClass)) -#define GLADE_IS_INSPECTOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_INSPECTOR)) -#define GLADE_IS_INSPECTOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_INSPECTOR)) -#define GLADE_INSPECTOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GLADE_TYPE_INSPECTOR, GladeInspectorClass)) - -typedef struct _GladeInspector GladeInspector; -typedef struct _GladeInspectorClass GladeInspectorClass; -typedef struct _GladeInspectorPrivate GladeInspectorPrivate; - -struct _GladeInspector -{ - GtkVBox parent_instance; - - GladeInspectorPrivate *priv; -}; - -struct _GladeInspectorClass -{ - GtkVBoxClass parent_class; - - void (* selection_changed) (GladeInspector *inspector); - - void (* item_activated) (GladeInspector *inspector); -}; - - -GType glade_inspector_get_type (void) G_GNUC_CONST; - -GtkWidget *glade_inspector_new (void); - -GtkWidget *glade_inspector_new_with_project (GladeProject *project); - -void glade_inspector_set_project (GladeInspector *inspector, - GladeProject *project); - -GladeProject *glade_inspector_get_project (GladeInspector *inspector); - -GList *glade_inspector_get_selected_items (GladeInspector *inspector); - -G_END_DECLS - -#endif /* __GLADE_INSPECTOR_H__ */ diff --git a/gladeui/glade-keysyms.c b/gladeui/glade-keysyms.c deleted file mode 100644 index 2b028981..00000000 --- a/gladeui/glade-keysyms.c +++ /dev/null @@ -1,1360 +0,0 @@ -#include <gdk/gdkkeysyms.h> - -#include "glade-builtins.h" - -/* - * This is automatically generated by ${glade-2 cvs}/tools/getkeys.pl - */ -const GladeKey GladeKeys[] = -{ - { GDK_A, "A" }, - { GDK_B, "B" }, - { GDK_C, "C" }, - { GDK_D, "D" }, - { GDK_E, "E" }, - { GDK_F, "F" }, - { GDK_G, "G" }, - { GDK_H, "H" }, - { GDK_I, "I" }, - { GDK_J, "J" }, - { GDK_K, "K" }, - { GDK_L, "L" }, - { GDK_M, "M" }, - { GDK_N, "N" }, - { GDK_O, "O" }, - { GDK_P, "P" }, - { GDK_Q, "Q" }, - { GDK_R, "R" }, - { GDK_S, "S" }, - { GDK_T, "T" }, - { GDK_U, "U" }, - { GDK_V, "V" }, - { GDK_W, "W" }, - { GDK_X, "X" }, - { GDK_Y, "Y" }, - { GDK_Z, "Z" }, - { GDK_a, "a" }, - { GDK_b, "b" }, - { GDK_c, "c" }, - { GDK_d, "d" }, - { GDK_e, "e" }, - { GDK_f, "f" }, - { GDK_g, "g" }, - { GDK_h, "h" }, - { GDK_i, "i" }, - { GDK_j, "j" }, - { GDK_k, "k" }, - { GDK_l, "l" }, - { GDK_m, "m" }, - { GDK_n, "n" }, - { GDK_o, "o" }, - { GDK_p, "p" }, - { GDK_q, "q" }, - { GDK_r, "r" }, - { GDK_s, "s" }, - { GDK_t, "t" }, - { GDK_u, "u" }, - { GDK_v, "v" }, - { GDK_w, "w" }, - { GDK_x, "x" }, - { GDK_y, "y" }, - { GDK_z, "z" }, - - { GDK_0, "0" }, - { GDK_1, "1" }, - { GDK_2, "2" }, - { GDK_3, "3" }, - { GDK_4, "4" }, - { GDK_5, "5" }, - { GDK_6, "6" }, - { GDK_7, "7" }, - { GDK_8, "8" }, - { GDK_9, "9" }, - - { GDK_BackSpace, "BackSpace" }, - { GDK_Tab, "Tab" }, - { GDK_Return, "Return" }, - { GDK_Escape, "Escape" }, - { GDK_Delete, "Delete" }, - { GDK_Insert, "Insert" }, - { GDK_space, "space" }, - - { GDK_Home, "Home" }, - { GDK_Left, "Left" }, - { GDK_Up, "Up" }, - { GDK_Right, "Right" }, - { GDK_Down, "Down" }, - { GDK_Page_Up, "Page_Up" }, - { GDK_Page_Down, "Page_Down" }, - { GDK_End, "End" }, - - { GDK_exclam, "exclam" }, - { GDK_quotedbl, "quotedbl" }, - { GDK_numbersign, "numbersign" }, - { GDK_dollar, "dollar" }, - { GDK_percent, "percent" }, - { GDK_ampersand, "ampersand" }, - { GDK_apostrophe, "apostrophe" }, - { GDK_quoteright, "quoteright" }, - { GDK_parenleft, "parenleft" }, - { GDK_parenright, "parenright" }, - { GDK_asterisk, "asterisk" }, - { GDK_plus, "plus" }, - { GDK_comma, "comma" }, - { GDK_minus, "minus" }, - { GDK_period, "period" }, - { GDK_slash, "slash" }, - { GDK_colon, "colon" }, - { GDK_semicolon, "semicolon" }, - { GDK_less, "less" }, - { GDK_equal, "equal" }, - { GDK_greater, "greater" }, - { GDK_question, "question" }, - { GDK_at, "at" }, - { GDK_bracketleft, "bracketleft" }, - { GDK_backslash, "backslash" }, - { GDK_bracketright, "bracketright" }, - { GDK_asciicircum, "asciicircum" }, - { GDK_underscore, "underscore" }, - { GDK_grave, "grave" }, - { GDK_quoteleft, "quoteleft" }, - { GDK_braceleft, "braceleft" }, - { GDK_bar, "bar" }, - { GDK_braceright, "braceright" }, - { GDK_asciitilde, "asciitilde" }, - { GDK_nobreakspace, "nobreakspace" }, - { GDK_exclamdown, "exclamdown" }, - { GDK_cent, "cent" }, - { GDK_sterling, "sterling" }, - { GDK_currency, "currency" }, - { GDK_yen, "yen" }, - { GDK_brokenbar, "brokenbar" }, - { GDK_section, "section" }, - { GDK_diaeresis, "diaeresis" }, - { GDK_copyright, "copyright" }, - { GDK_ordfeminine, "ordfeminine" }, - { GDK_guillemotleft, "guillemotleft" }, - { GDK_notsign, "notsign" }, - { GDK_hyphen, "hyphen" }, - { GDK_registered, "registered" }, - { GDK_macron, "macron" }, - { GDK_degree, "degree" }, - { GDK_plusminus, "plusminus" }, - { GDK_twosuperior, "twosuperior" }, - { GDK_threesuperior, "threesuperior" }, - { GDK_acute, "acute" }, - { GDK_mu, "mu" }, - { GDK_paragraph, "paragraph" }, - { GDK_periodcentered, "periodcentered" }, - { GDK_cedilla, "cedilla" }, - { GDK_onesuperior, "onesuperior" }, - { GDK_masculine, "masculine" }, - { GDK_guillemotright, "guillemotright" }, - { GDK_onequarter, "onequarter" }, - { GDK_onehalf, "onehalf" }, - { GDK_threequarters, "threequarters" }, - { GDK_questiondown, "questiondown" }, - - { GDK_KP_Space, "KP_Space" }, - { GDK_KP_Tab, "KP_Tab" }, - { GDK_KP_Enter, "KP_Enter" }, - { GDK_KP_F1, "KP_F1" }, - { GDK_KP_F2, "KP_F2" }, - { GDK_KP_F3, "KP_F3" }, - { GDK_KP_F4, "KP_F4" }, - { GDK_KP_Home, "KP_Home" }, - { GDK_KP_Left, "KP_Left" }, - { GDK_KP_Up, "KP_Up" }, - { GDK_KP_Right, "KP_Right" }, - { GDK_KP_Down, "KP_Down" }, - { GDK_KP_Prior, "KP_Prior" }, - { GDK_KP_Page_Up, "KP_Page_Up" }, - { GDK_KP_Next, "KP_Next" }, - { GDK_KP_Page_Down, "KP_Page_Down" }, - { GDK_KP_End, "KP_End" }, - { GDK_KP_Begin, "KP_Begin" }, - { GDK_KP_Insert, "KP_Insert" }, - { GDK_KP_Delete, "KP_Delete" }, - { GDK_KP_Equal, "KP_Equal" }, - { GDK_KP_Multiply, "KP_Multiply" }, - { GDK_KP_Add, "KP_Add" }, - { GDK_KP_Separator, "KP_Separator" }, - { GDK_KP_Subtract, "KP_Subtract" }, - { GDK_KP_Decimal, "KP_Decimal" }, - { GDK_KP_Divide, "KP_Divide" }, - { GDK_KP_0, "KP_0" }, - { GDK_KP_1, "KP_1" }, - { GDK_KP_2, "KP_2" }, - { GDK_KP_3, "KP_3" }, - { GDK_KP_4, "KP_4" }, - { GDK_KP_5, "KP_5" }, - { GDK_KP_6, "KP_6" }, - { GDK_KP_7, "KP_7" }, - { GDK_KP_8, "KP_8" }, - { GDK_KP_9, "KP_9" }, - - { GDK_F1, "F1" }, - { GDK_F2, "F2" }, - { GDK_F3, "F3" }, - { GDK_F4, "F4" }, - { GDK_F5, "F5" }, - { GDK_F6, "F6" }, - { GDK_F7, "F7" }, - { GDK_F8, "F8" }, - { GDK_F9, "F9" }, - { GDK_F10, "F10" }, - { GDK_F11, "F11" }, - { GDK_F12, "F12" }, - { GDK_F13, "F13" }, - { GDK_F14, "F14" }, - { GDK_F15, "F15" }, - { GDK_F16, "F16" }, - { GDK_F17, "F17" }, - { GDK_F18, "F18" }, - { GDK_F19, "F19" }, - { GDK_F20, "F20" }, - { GDK_F21, "F21" }, - { GDK_F22, "F22" }, - { GDK_F23, "F23" }, - { GDK_F24, "F24" }, - { GDK_F25, "F25" }, - { GDK_F26, "F26" }, - { GDK_F27, "F27" }, - { GDK_F28, "F28" }, - { GDK_F29, "F29" }, - { GDK_F30, "F30" }, - { GDK_F31, "F31" }, - { GDK_F32, "F32" }, - { GDK_F33, "F33" }, - { GDK_F34, "F34" }, - { GDK_F35, "F35" }, - - { GDK_VoidSymbol, "VoidSymbol" }, - { GDK_Linefeed, "Linefeed" }, - { GDK_Clear, "Clear" }, - { GDK_Pause, "Pause" }, - { GDK_Scroll_Lock, "Scroll_Lock" }, - { GDK_Sys_Req, "Sys_Req" }, - { GDK_Multi_key, "Multi_key" }, - { GDK_Codeinput, "Codeinput" }, - { GDK_SingleCandidate, "SingleCandidate" }, - { GDK_MultipleCandidate, "MultipleCandidate" }, - { GDK_PreviousCandidate, "PreviousCandidate" }, - { GDK_Kanji, "Kanji" }, - { GDK_Muhenkan, "Muhenkan" }, - { GDK_Henkan_Mode, "Henkan_Mode" }, - { GDK_Henkan, "Henkan" }, - { GDK_Romaji, "Romaji" }, - { GDK_Hiragana, "Hiragana" }, - { GDK_Katakana, "Katakana" }, - { GDK_Hiragana_Katakana, "Hiragana_Katakana" }, - { GDK_Zenkaku, "Zenkaku" }, - { GDK_Hankaku, "Hankaku" }, - { GDK_Zenkaku_Hankaku, "Zenkaku_Hankaku" }, - { GDK_Touroku, "Touroku" }, - { GDK_Massyo, "Massyo" }, - { GDK_Kana_Lock, "Kana_Lock" }, - { GDK_Kana_Shift, "Kana_Shift" }, - { GDK_Eisu_Shift, "Eisu_Shift" }, - { GDK_Eisu_toggle, "Eisu_toggle" }, - { GDK_Kanji_Bangou, "Kanji_Bangou" }, - { GDK_Zen_Koho, "Zen_Koho" }, - { GDK_Mae_Koho, "Mae_Koho" }, - { GDK_Prior, "Prior" }, - { GDK_Next, "Next" }, - { GDK_Begin, "Begin" }, - { GDK_Select, "Select" }, - { GDK_Print, "Print" }, - { GDK_Execute, "Execute" }, - { GDK_Undo, "Undo" }, - { GDK_Redo, "Redo" }, - { GDK_Menu, "Menu" }, - { GDK_Find, "Find" }, - { GDK_Cancel, "Cancel" }, - { GDK_Help, "Help" }, - { GDK_Break, "Break" }, - { GDK_Mode_switch, "Mode_switch" }, - { GDK_script_switch, "script_switch" }, - { GDK_Num_Lock, "Num_Lock" }, - { GDK_L1, "L1" }, - { GDK_L2, "L2" }, - { GDK_L3, "L3" }, - { GDK_L4, "L4" }, - { GDK_L5, "L5" }, - { GDK_L6, "L6" }, - { GDK_L7, "L7" }, - { GDK_L8, "L8" }, - { GDK_L9, "L9" }, - { GDK_L10, "L10" }, - { GDK_R1, "R1" }, - { GDK_R2, "R2" }, - { GDK_R3, "R3" }, - { GDK_R4, "R4" }, - { GDK_R5, "R5" }, - { GDK_R6, "R6" }, - { GDK_R7, "R7" }, - { GDK_R8, "R8" }, - { GDK_R9, "R9" }, - { GDK_R10, "R10" }, - { GDK_R11, "R11" }, - { GDK_R12, "R12" }, - { GDK_R13, "R13" }, - { GDK_R14, "R14" }, - { GDK_R15, "R15" }, - { GDK_Shift_L, "Shift_L" }, - { GDK_Shift_R, "Shift_R" }, - { GDK_Control_L, "Control_L" }, - { GDK_Control_R, "Control_R" }, - { GDK_Caps_Lock, "Caps_Lock" }, - { GDK_Shift_Lock, "Shift_Lock" }, - { GDK_Meta_L, "Meta_L" }, - { GDK_Meta_R, "Meta_R" }, - { GDK_Alt_L, "Alt_L" }, - { GDK_Alt_R, "Alt_R" }, - { GDK_Super_L, "Super_L" }, - { GDK_Super_R, "Super_R" }, - { GDK_Hyper_L, "Hyper_L" }, - { GDK_Hyper_R, "Hyper_R" }, - { GDK_ISO_Lock, "ISO_Lock" }, - { GDK_ISO_Level2_Latch, "ISO_Level2_Latch" }, - { GDK_ISO_Level3_Shift, "ISO_Level3_Shift" }, - { GDK_ISO_Level3_Latch, "ISO_Level3_Latch" }, - { GDK_ISO_Level3_Lock, "ISO_Level3_Lock" }, - { GDK_ISO_Group_Shift, "ISO_Group_Shift" }, - { GDK_ISO_Group_Latch, "ISO_Group_Latch" }, - { GDK_ISO_Group_Lock, "ISO_Group_Lock" }, - { GDK_ISO_Next_Group, "ISO_Next_Group" }, - { GDK_ISO_Next_Group_Lock, "ISO_Next_Group_Lock" }, - { GDK_ISO_Prev_Group, "ISO_Prev_Group" }, - { GDK_ISO_Prev_Group_Lock, "ISO_Prev_Group_Lock" }, - { GDK_ISO_First_Group, "ISO_First_Group" }, - { GDK_ISO_First_Group_Lock, "ISO_First_Group_Lock" }, - { GDK_ISO_Last_Group, "ISO_Last_Group" }, - { GDK_ISO_Last_Group_Lock, "ISO_Last_Group_Lock" }, - { GDK_ISO_Left_Tab, "ISO_Left_Tab" }, - { GDK_ISO_Move_Line_Up, "ISO_Move_Line_Up" }, - { GDK_ISO_Move_Line_Down, "ISO_Move_Line_Down" }, - { GDK_ISO_Partial_Line_Up, "ISO_Partial_Line_Up" }, - { GDK_ISO_Partial_Line_Down, "ISO_Partial_Line_Down" }, - { GDK_ISO_Partial_Space_Left, "ISO_Partial_Space_Left" }, - { GDK_ISO_Partial_Space_Right, "ISO_Partial_Space_Right" }, - { GDK_ISO_Set_Margin_Left, "ISO_Set_Margin_Left" }, - { GDK_ISO_Set_Margin_Right, "ISO_Set_Margin_Right" }, - { GDK_ISO_Release_Margin_Left, "ISO_Release_Margin_Left" }, - { GDK_ISO_Release_Margin_Right, "ISO_Release_Margin_Right" }, - { GDK_ISO_Release_Both_Margins, "ISO_Release_Both_Margins" }, - { GDK_ISO_Fast_Cursor_Left, "ISO_Fast_Cursor_Left" }, - { GDK_ISO_Fast_Cursor_Right, "ISO_Fast_Cursor_Right" }, - { GDK_ISO_Fast_Cursor_Up, "ISO_Fast_Cursor_Up" }, - { GDK_ISO_Fast_Cursor_Down, "ISO_Fast_Cursor_Down" }, - { GDK_ISO_Continuous_Underline, "ISO_Continuous_Underline" }, - { GDK_ISO_Discontinuous_Underline, "ISO_Discontinuous_Underline" }, - { GDK_ISO_Emphasize, "ISO_Emphasize" }, - { GDK_ISO_Center_Object, "ISO_Center_Object" }, - { GDK_ISO_Enter, "ISO_Enter" }, - { GDK_dead_grave, "dead_grave" }, - { GDK_dead_acute, "dead_acute" }, - { GDK_dead_circumflex, "dead_circumflex" }, - { GDK_dead_tilde, "dead_tilde" }, - { GDK_dead_macron, "dead_macron" }, - { GDK_dead_breve, "dead_breve" }, - { GDK_dead_abovedot, "dead_abovedot" }, - { GDK_dead_diaeresis, "dead_diaeresis" }, - { GDK_dead_abovering, "dead_abovering" }, - { GDK_dead_doubleacute, "dead_doubleacute" }, - { GDK_dead_caron, "dead_caron" }, - { GDK_dead_cedilla, "dead_cedilla" }, - { GDK_dead_ogonek, "dead_ogonek" }, - { GDK_dead_iota, "dead_iota" }, - { GDK_dead_voiced_sound, "dead_voiced_sound" }, - { GDK_dead_semivoiced_sound, "dead_semivoiced_sound" }, - { GDK_dead_belowdot, "dead_belowdot" }, - { GDK_dead_hook, "dead_hook" }, - { GDK_dead_horn, "dead_horn" }, - { GDK_First_Virtual_Screen, "First_Virtual_Screen" }, - { GDK_Prev_Virtual_Screen, "Prev_Virtual_Screen" }, - { GDK_Next_Virtual_Screen, "Next_Virtual_Screen" }, - { GDK_Last_Virtual_Screen, "Last_Virtual_Screen" }, - { GDK_Terminate_Server, "Terminate_Server" }, - { GDK_AccessX_Enable, "AccessX_Enable" }, - { GDK_AccessX_Feedback_Enable, "AccessX_Feedback_Enable" }, - { GDK_RepeatKeys_Enable, "RepeatKeys_Enable" }, - { GDK_SlowKeys_Enable, "SlowKeys_Enable" }, - { GDK_BounceKeys_Enable, "BounceKeys_Enable" }, - { GDK_StickyKeys_Enable, "StickyKeys_Enable" }, - { GDK_MouseKeys_Enable, "MouseKeys_Enable" }, - { GDK_MouseKeys_Accel_Enable, "MouseKeys_Accel_Enable" }, - { GDK_Overlay1_Enable, "Overlay1_Enable" }, - { GDK_Overlay2_Enable, "Overlay2_Enable" }, - { GDK_AudibleBell_Enable, "AudibleBell_Enable" }, - { GDK_Pointer_Left, "Pointer_Left" }, - { GDK_Pointer_Right, "Pointer_Right" }, - { GDK_Pointer_Up, "Pointer_Up" }, - { GDK_Pointer_Down, "Pointer_Down" }, - { GDK_Pointer_UpLeft, "Pointer_UpLeft" }, - { GDK_Pointer_UpRight, "Pointer_UpRight" }, - { GDK_Pointer_DownLeft, "Pointer_DownLeft" }, - { GDK_Pointer_DownRight, "Pointer_DownRight" }, - { GDK_Pointer_Button_Dflt, "Pointer_Button_Dflt" }, - { GDK_Pointer_Button1, "Pointer_Button1" }, - { GDK_Pointer_Button2, "Pointer_Button2" }, - { GDK_Pointer_Button3, "Pointer_Button3" }, - { GDK_Pointer_Button4, "Pointer_Button4" }, - { GDK_Pointer_Button5, "Pointer_Button5" }, - { GDK_Pointer_DblClick_Dflt, "Pointer_DblClick_Dflt" }, - { GDK_Pointer_DblClick1, "Pointer_DblClick1" }, - { GDK_Pointer_DblClick2, "Pointer_DblClick2" }, - { GDK_Pointer_DblClick3, "Pointer_DblClick3" }, - { GDK_Pointer_DblClick4, "Pointer_DblClick4" }, - { GDK_Pointer_DblClick5, "Pointer_DblClick5" }, - { GDK_Pointer_Drag_Dflt, "Pointer_Drag_Dflt" }, - { GDK_Pointer_Drag1, "Pointer_Drag1" }, - { GDK_Pointer_Drag2, "Pointer_Drag2" }, - { GDK_Pointer_Drag3, "Pointer_Drag3" }, - { GDK_Pointer_Drag4, "Pointer_Drag4" }, - { GDK_Pointer_Drag5, "Pointer_Drag5" }, - { GDK_Pointer_EnableKeys, "Pointer_EnableKeys" }, - { GDK_Pointer_Accelerate, "Pointer_Accelerate" }, - { GDK_Pointer_DfltBtnNext, "Pointer_DfltBtnNext" }, - { GDK_Pointer_DfltBtnPrev, "Pointer_DfltBtnPrev" }, - { GDK_3270_Duplicate, "3270_Duplicate" }, - { GDK_3270_FieldMark, "3270_FieldMark" }, - { GDK_3270_Right2, "3270_Right2" }, - { GDK_3270_Left2, "3270_Left2" }, - { GDK_3270_BackTab, "3270_BackTab" }, - { GDK_3270_EraseEOF, "3270_EraseEOF" }, - { GDK_3270_EraseInput, "3270_EraseInput" }, - { GDK_3270_Reset, "3270_Reset" }, - { GDK_3270_Quit, "3270_Quit" }, - { GDK_3270_PA1, "3270_PA1" }, - { GDK_3270_PA2, "3270_PA2" }, - { GDK_3270_PA3, "3270_PA3" }, - { GDK_3270_Test, "3270_Test" }, - { GDK_3270_Attn, "3270_Attn" }, - { GDK_3270_CursorBlink, "3270_CursorBlink" }, - { GDK_3270_AltCursor, "3270_AltCursor" }, - { GDK_3270_KeyClick, "3270_KeyClick" }, - { GDK_3270_Jump, "3270_Jump" }, - { GDK_3270_Ident, "3270_Ident" }, - { GDK_3270_Rule, "3270_Rule" }, - { GDK_3270_Copy, "3270_Copy" }, - { GDK_3270_Play, "3270_Play" }, - { GDK_3270_Setup, "3270_Setup" }, - { GDK_3270_Record, "3270_Record" }, - { GDK_3270_ChangeScreen, "3270_ChangeScreen" }, - { GDK_3270_DeleteWord, "3270_DeleteWord" }, - { GDK_3270_ExSelect, "3270_ExSelect" }, - { GDK_3270_CursorSelect, "3270_CursorSelect" }, - { GDK_3270_PrintScreen, "3270_PrintScreen" }, - { GDK_3270_Enter, "3270_Enter" }, - - { GDK_Agrave, "Agrave" }, - { GDK_Aacute, "Aacute" }, - { GDK_Acircumflex, "Acircumflex" }, - { GDK_Atilde, "Atilde" }, - { GDK_Adiaeresis, "Adiaeresis" }, - { GDK_Aring, "Aring" }, - { GDK_AE, "AE" }, - { GDK_Ccedilla, "Ccedilla" }, - { GDK_Egrave, "Egrave" }, - { GDK_Eacute, "Eacute" }, - { GDK_Ecircumflex, "Ecircumflex" }, - { GDK_Ediaeresis, "Ediaeresis" }, - { GDK_Igrave, "Igrave" }, - { GDK_Iacute, "Iacute" }, - { GDK_Icircumflex, "Icircumflex" }, - { GDK_Idiaeresis, "Idiaeresis" }, - { GDK_ETH, "ETH" }, - { GDK_Eth, "Eth" }, - { GDK_Ntilde, "Ntilde" }, - { GDK_Ograve, "Ograve" }, - { GDK_Oacute, "Oacute" }, - { GDK_Ocircumflex, "Ocircumflex" }, - { GDK_Otilde, "Otilde" }, - { GDK_Odiaeresis, "Odiaeresis" }, - { GDK_multiply, "multiply" }, - { GDK_Ooblique, "Ooblique" }, - { GDK_Ugrave, "Ugrave" }, - { GDK_Uacute, "Uacute" }, - { GDK_Ucircumflex, "Ucircumflex" }, - { GDK_Udiaeresis, "Udiaeresis" }, - { GDK_Yacute, "Yacute" }, - { GDK_THORN, "THORN" }, - { GDK_Thorn, "Thorn" }, - { GDK_ssharp, "ssharp" }, - { GDK_agrave, "agrave" }, - { GDK_aacute, "aacute" }, - { GDK_acircumflex, "acircumflex" }, - { GDK_atilde, "atilde" }, - { GDK_adiaeresis, "adiaeresis" }, - { GDK_aring, "aring" }, - { GDK_ae, "ae" }, - { GDK_ccedilla, "ccedilla" }, - { GDK_egrave, "egrave" }, - { GDK_eacute, "eacute" }, - { GDK_ecircumflex, "ecircumflex" }, - { GDK_ediaeresis, "ediaeresis" }, - { GDK_igrave, "igrave" }, - { GDK_iacute, "iacute" }, - { GDK_icircumflex, "icircumflex" }, - { GDK_idiaeresis, "idiaeresis" }, - { GDK_eth, "eth" }, - { GDK_ntilde, "ntilde" }, - { GDK_ograve, "ograve" }, - { GDK_oacute, "oacute" }, - { GDK_ocircumflex, "ocircumflex" }, - { GDK_otilde, "otilde" }, - { GDK_odiaeresis, "odiaeresis" }, - { GDK_division, "division" }, - { GDK_oslash, "oslash" }, - { GDK_ugrave, "ugrave" }, - { GDK_uacute, "uacute" }, - { GDK_ucircumflex, "ucircumflex" }, - { GDK_udiaeresis, "udiaeresis" }, - { GDK_yacute, "yacute" }, - { GDK_thorn, "thorn" }, - { GDK_ydiaeresis, "ydiaeresis" }, - { GDK_Aogonek, "Aogonek" }, - { GDK_breve, "breve" }, - { GDK_Lstroke, "Lstroke" }, - { GDK_Lcaron, "Lcaron" }, - { GDK_Sacute, "Sacute" }, - { GDK_Scaron, "Scaron" }, - { GDK_Scedilla, "Scedilla" }, - { GDK_Tcaron, "Tcaron" }, - { GDK_Zacute, "Zacute" }, - { GDK_Zcaron, "Zcaron" }, - { GDK_Zabovedot, "Zabovedot" }, - { GDK_aogonek, "aogonek" }, - { GDK_ogonek, "ogonek" }, - { GDK_lstroke, "lstroke" }, - { GDK_lcaron, "lcaron" }, - { GDK_sacute, "sacute" }, - { GDK_caron, "caron" }, - { GDK_scaron, "scaron" }, - { GDK_scedilla, "scedilla" }, - { GDK_tcaron, "tcaron" }, - { GDK_zacute, "zacute" }, - { GDK_doubleacute, "doubleacute" }, - { GDK_zcaron, "zcaron" }, - { GDK_zabovedot, "zabovedot" }, - { GDK_Racute, "Racute" }, - { GDK_Abreve, "Abreve" }, - { GDK_Lacute, "Lacute" }, - { GDK_Cacute, "Cacute" }, - { GDK_Ccaron, "Ccaron" }, - { GDK_Eogonek, "Eogonek" }, - { GDK_Ecaron, "Ecaron" }, - { GDK_Dcaron, "Dcaron" }, - { GDK_Dstroke, "Dstroke" }, - { GDK_Nacute, "Nacute" }, - { GDK_Ncaron, "Ncaron" }, - { GDK_Odoubleacute, "Odoubleacute" }, - { GDK_Rcaron, "Rcaron" }, - { GDK_Uring, "Uring" }, - { GDK_Udoubleacute, "Udoubleacute" }, - { GDK_Tcedilla, "Tcedilla" }, - { GDK_racute, "racute" }, - { GDK_abreve, "abreve" }, - { GDK_lacute, "lacute" }, - { GDK_cacute, "cacute" }, - { GDK_ccaron, "ccaron" }, - { GDK_eogonek, "eogonek" }, - { GDK_ecaron, "ecaron" }, - { GDK_dcaron, "dcaron" }, - { GDK_dstroke, "dstroke" }, - { GDK_nacute, "nacute" }, - { GDK_ncaron, "ncaron" }, - { GDK_odoubleacute, "odoubleacute" }, - { GDK_udoubleacute, "udoubleacute" }, - { GDK_rcaron, "rcaron" }, - { GDK_uring, "uring" }, - { GDK_tcedilla, "tcedilla" }, - { GDK_abovedot, "abovedot" }, - { GDK_Hstroke, "Hstroke" }, - { GDK_Hcircumflex, "Hcircumflex" }, - { GDK_Iabovedot, "Iabovedot" }, - { GDK_Gbreve, "Gbreve" }, - { GDK_Jcircumflex, "Jcircumflex" }, - { GDK_hstroke, "hstroke" }, - { GDK_hcircumflex, "hcircumflex" }, - { GDK_idotless, "idotless" }, - { GDK_gbreve, "gbreve" }, - { GDK_jcircumflex, "jcircumflex" }, - { GDK_Cabovedot, "Cabovedot" }, - { GDK_Ccircumflex, "Ccircumflex" }, - { GDK_Gabovedot, "Gabovedot" }, - { GDK_Gcircumflex, "Gcircumflex" }, - { GDK_Ubreve, "Ubreve" }, - { GDK_Scircumflex, "Scircumflex" }, - { GDK_cabovedot, "cabovedot" }, - { GDK_ccircumflex, "ccircumflex" }, - { GDK_gabovedot, "gabovedot" }, - { GDK_gcircumflex, "gcircumflex" }, - { GDK_ubreve, "ubreve" }, - { GDK_scircumflex, "scircumflex" }, - { GDK_kra, "kra" }, - { GDK_kappa, "kappa" }, - { GDK_Rcedilla, "Rcedilla" }, - { GDK_Itilde, "Itilde" }, - { GDK_Lcedilla, "Lcedilla" }, - { GDK_Emacron, "Emacron" }, - { GDK_Gcedilla, "Gcedilla" }, - { GDK_Tslash, "Tslash" }, - { GDK_rcedilla, "rcedilla" }, - { GDK_itilde, "itilde" }, - { GDK_lcedilla, "lcedilla" }, - { GDK_emacron, "emacron" }, - { GDK_gcedilla, "gcedilla" }, - { GDK_tslash, "tslash" }, - { GDK_ENG, "ENG" }, - { GDK_eng, "eng" }, - { GDK_Amacron, "Amacron" }, - { GDK_Iogonek, "Iogonek" }, - { GDK_Eabovedot, "Eabovedot" }, - { GDK_Imacron, "Imacron" }, - { GDK_Ncedilla, "Ncedilla" }, - { GDK_Omacron, "Omacron" }, - { GDK_Kcedilla, "Kcedilla" }, - { GDK_Uogonek, "Uogonek" }, - { GDK_Utilde, "Utilde" }, - { GDK_Umacron, "Umacron" }, - { GDK_amacron, "amacron" }, - { GDK_iogonek, "iogonek" }, - { GDK_eabovedot, "eabovedot" }, - { GDK_imacron, "imacron" }, - { GDK_ncedilla, "ncedilla" }, - { GDK_omacron, "omacron" }, - { GDK_kcedilla, "kcedilla" }, - { GDK_uogonek, "uogonek" }, - { GDK_utilde, "utilde" }, - { GDK_umacron, "umacron" }, - { GDK_OE, "OE" }, - { GDK_oe, "oe" }, - { GDK_Ydiaeresis, "Ydiaeresis" }, - { GDK_overline, "overline" }, - { GDK_kana_fullstop, "kana_fullstop" }, - { GDK_kana_openingbracket, "kana_openingbracket" }, - { GDK_kana_closingbracket, "kana_closingbracket" }, - { GDK_kana_comma, "kana_comma" }, - { GDK_kana_conjunctive, "kana_conjunctive" }, - { GDK_kana_middledot, "kana_middledot" }, - { GDK_kana_WO, "kana_WO" }, - { GDK_kana_a, "kana_a" }, - { GDK_kana_i, "kana_i" }, - { GDK_kana_u, "kana_u" }, - { GDK_kana_e, "kana_e" }, - { GDK_kana_o, "kana_o" }, - { GDK_kana_ya, "kana_ya" }, - { GDK_kana_yu, "kana_yu" }, - { GDK_kana_yo, "kana_yo" }, - { GDK_kana_tsu, "kana_tsu" }, - { GDK_kana_tu, "kana_tu" }, - { GDK_prolongedsound, "prolongedsound" }, - { GDK_kana_A, "kana_A" }, - { GDK_kana_I, "kana_I" }, - { GDK_kana_U, "kana_U" }, - { GDK_kana_E, "kana_E" }, - { GDK_kana_O, "kana_O" }, - { GDK_kana_KA, "kana_KA" }, - { GDK_kana_KI, "kana_KI" }, - { GDK_kana_KU, "kana_KU" }, - { GDK_kana_KE, "kana_KE" }, - { GDK_kana_KO, "kana_KO" }, - { GDK_kana_SA, "kana_SA" }, - { GDK_kana_SHI, "kana_SHI" }, - { GDK_kana_SU, "kana_SU" }, - { GDK_kana_SE, "kana_SE" }, - { GDK_kana_SO, "kana_SO" }, - { GDK_kana_TA, "kana_TA" }, - { GDK_kana_CHI, "kana_CHI" }, - { GDK_kana_TI, "kana_TI" }, - { GDK_kana_TSU, "kana_TSU" }, - { GDK_kana_TU, "kana_TU" }, - { GDK_kana_TE, "kana_TE" }, - { GDK_kana_TO, "kana_TO" }, - { GDK_kana_NA, "kana_NA" }, - { GDK_kana_NI, "kana_NI" }, - { GDK_kana_NU, "kana_NU" }, - { GDK_kana_NE, "kana_NE" }, - { GDK_kana_NO, "kana_NO" }, - { GDK_kana_HA, "kana_HA" }, - { GDK_kana_HI, "kana_HI" }, - { GDK_kana_FU, "kana_FU" }, - { GDK_kana_HU, "kana_HU" }, - { GDK_kana_HE, "kana_HE" }, - { GDK_kana_HO, "kana_HO" }, - { GDK_kana_MA, "kana_MA" }, - { GDK_kana_MI, "kana_MI" }, - { GDK_kana_MU, "kana_MU" }, - { GDK_kana_ME, "kana_ME" }, - { GDK_kana_MO, "kana_MO" }, - { GDK_kana_YA, "kana_YA" }, - { GDK_kana_YU, "kana_YU" }, - { GDK_kana_YO, "kana_YO" }, - { GDK_kana_RA, "kana_RA" }, - { GDK_kana_RI, "kana_RI" }, - { GDK_kana_RU, "kana_RU" }, - { GDK_kana_RE, "kana_RE" }, - { GDK_kana_RO, "kana_RO" }, - { GDK_kana_WA, "kana_WA" }, - { GDK_kana_N, "kana_N" }, - { GDK_voicedsound, "voicedsound" }, - { GDK_semivoicedsound, "semivoicedsound" }, - { GDK_kana_switch, "kana_switch" }, - { GDK_Arabic_comma, "Arabic_comma" }, - { GDK_Arabic_semicolon, "Arabic_semicolon" }, - { GDK_Arabic_question_mark, "Arabic_question_mark" }, - { GDK_Arabic_hamza, "Arabic_hamza" }, - { GDK_Arabic_maddaonalef, "Arabic_maddaonalef" }, - { GDK_Arabic_hamzaonalef, "Arabic_hamzaonalef" }, - { GDK_Arabic_hamzaonwaw, "Arabic_hamzaonwaw" }, - { GDK_Arabic_hamzaunderalef, "Arabic_hamzaunderalef" }, - { GDK_Arabic_hamzaonyeh, "Arabic_hamzaonyeh" }, - { GDK_Arabic_alef, "Arabic_alef" }, - { GDK_Arabic_beh, "Arabic_beh" }, - { GDK_Arabic_tehmarbuta, "Arabic_tehmarbuta" }, - { GDK_Arabic_teh, "Arabic_teh" }, - { GDK_Arabic_theh, "Arabic_theh" }, - { GDK_Arabic_jeem, "Arabic_jeem" }, - { GDK_Arabic_hah, "Arabic_hah" }, - { GDK_Arabic_khah, "Arabic_khah" }, - { GDK_Arabic_dal, "Arabic_dal" }, - { GDK_Arabic_thal, "Arabic_thal" }, - { GDK_Arabic_ra, "Arabic_ra" }, - { GDK_Arabic_zain, "Arabic_zain" }, - { GDK_Arabic_seen, "Arabic_seen" }, - { GDK_Arabic_sheen, "Arabic_sheen" }, - { GDK_Arabic_sad, "Arabic_sad" }, - { GDK_Arabic_dad, "Arabic_dad" }, - { GDK_Arabic_tah, "Arabic_tah" }, - { GDK_Arabic_zah, "Arabic_zah" }, - { GDK_Arabic_ain, "Arabic_ain" }, - { GDK_Arabic_ghain, "Arabic_ghain" }, - { GDK_Arabic_tatweel, "Arabic_tatweel" }, - { GDK_Arabic_feh, "Arabic_feh" }, - { GDK_Arabic_qaf, "Arabic_qaf" }, - { GDK_Arabic_kaf, "Arabic_kaf" }, - { GDK_Arabic_lam, "Arabic_lam" }, - { GDK_Arabic_meem, "Arabic_meem" }, - { GDK_Arabic_noon, "Arabic_noon" }, - { GDK_Arabic_ha, "Arabic_ha" }, - { GDK_Arabic_heh, "Arabic_heh" }, - { GDK_Arabic_waw, "Arabic_waw" }, - { GDK_Arabic_alefmaksura, "Arabic_alefmaksura" }, - { GDK_Arabic_yeh, "Arabic_yeh" }, - { GDK_Arabic_fathatan, "Arabic_fathatan" }, - { GDK_Arabic_dammatan, "Arabic_dammatan" }, - { GDK_Arabic_kasratan, "Arabic_kasratan" }, - { GDK_Arabic_fatha, "Arabic_fatha" }, - { GDK_Arabic_damma, "Arabic_damma" }, - { GDK_Arabic_kasra, "Arabic_kasra" }, - { GDK_Arabic_shadda, "Arabic_shadda" }, - { GDK_Arabic_sukun, "Arabic_sukun" }, - { GDK_Arabic_switch, "Arabic_switch" }, - { GDK_Serbian_dje, "Serbian_dje" }, - { GDK_Macedonia_gje, "Macedonia_gje" }, - { GDK_Cyrillic_io, "Cyrillic_io" }, - { GDK_Ukrainian_ie, "Ukrainian_ie" }, - { GDK_Ukranian_je, "Ukranian_je" }, - { GDK_Macedonia_dse, "Macedonia_dse" }, - { GDK_Ukrainian_i, "Ukrainian_i" }, - { GDK_Ukranian_i, "Ukranian_i" }, - { GDK_Ukrainian_yi, "Ukrainian_yi" }, - { GDK_Ukranian_yi, "Ukranian_yi" }, - { GDK_Cyrillic_je, "Cyrillic_je" }, - { GDK_Serbian_je, "Serbian_je" }, - { GDK_Cyrillic_lje, "Cyrillic_lje" }, - { GDK_Serbian_lje, "Serbian_lje" }, - { GDK_Cyrillic_nje, "Cyrillic_nje" }, - { GDK_Serbian_nje, "Serbian_nje" }, - { GDK_Serbian_tshe, "Serbian_tshe" }, - { GDK_Macedonia_kje, "Macedonia_kje" }, - { GDK_Ukrainian_ghe_with_upturn, "Ukrainian_ghe_with_upturn" }, - { GDK_Byelorussian_shortu, "Byelorussian_shortu" }, - { GDK_Cyrillic_dzhe, "Cyrillic_dzhe" }, - { GDK_Serbian_dze, "Serbian_dze" }, - { GDK_numerosign, "numerosign" }, - { GDK_Serbian_DJE, "Serbian_DJE" }, - { GDK_Macedonia_GJE, "Macedonia_GJE" }, - { GDK_Cyrillic_IO, "Cyrillic_IO" }, - { GDK_Ukrainian_IE, "Ukrainian_IE" }, - { GDK_Ukranian_JE, "Ukranian_JE" }, - { GDK_Macedonia_DSE, "Macedonia_DSE" }, - { GDK_Ukrainian_I, "Ukrainian_I" }, - { GDK_Ukranian_I, "Ukranian_I" }, - { GDK_Ukrainian_YI, "Ukrainian_YI" }, - { GDK_Ukranian_YI, "Ukranian_YI" }, - { GDK_Cyrillic_JE, "Cyrillic_JE" }, - { GDK_Serbian_JE, "Serbian_JE" }, - { GDK_Cyrillic_LJE, "Cyrillic_LJE" }, - { GDK_Serbian_LJE, "Serbian_LJE" }, - { GDK_Cyrillic_NJE, "Cyrillic_NJE" }, - { GDK_Serbian_NJE, "Serbian_NJE" }, - { GDK_Serbian_TSHE, "Serbian_TSHE" }, - { GDK_Macedonia_KJE, "Macedonia_KJE" }, - { GDK_Ukrainian_GHE_WITH_UPTURN, "Ukrainian_GHE_WITH_UPTURN" }, - { GDK_Byelorussian_SHORTU, "Byelorussian_SHORTU" }, - { GDK_Cyrillic_DZHE, "Cyrillic_DZHE" }, - { GDK_Serbian_DZE, "Serbian_DZE" }, - { GDK_Cyrillic_yu, "Cyrillic_yu" }, - { GDK_Cyrillic_a, "Cyrillic_a" }, - { GDK_Cyrillic_be, "Cyrillic_be" }, - { GDK_Cyrillic_tse, "Cyrillic_tse" }, - { GDK_Cyrillic_de, "Cyrillic_de" }, - { GDK_Cyrillic_ie, "Cyrillic_ie" }, - { GDK_Cyrillic_ef, "Cyrillic_ef" }, - { GDK_Cyrillic_ghe, "Cyrillic_ghe" }, - { GDK_Cyrillic_ha, "Cyrillic_ha" }, - { GDK_Cyrillic_i, "Cyrillic_i" }, - { GDK_Cyrillic_shorti, "Cyrillic_shorti" }, - { GDK_Cyrillic_ka, "Cyrillic_ka" }, - { GDK_Cyrillic_el, "Cyrillic_el" }, - { GDK_Cyrillic_em, "Cyrillic_em" }, - { GDK_Cyrillic_en, "Cyrillic_en" }, - { GDK_Cyrillic_o, "Cyrillic_o" }, - { GDK_Cyrillic_pe, "Cyrillic_pe" }, - { GDK_Cyrillic_ya, "Cyrillic_ya" }, - { GDK_Cyrillic_er, "Cyrillic_er" }, - { GDK_Cyrillic_es, "Cyrillic_es" }, - { GDK_Cyrillic_te, "Cyrillic_te" }, - { GDK_Cyrillic_u, "Cyrillic_u" }, - { GDK_Cyrillic_zhe, "Cyrillic_zhe" }, - { GDK_Cyrillic_ve, "Cyrillic_ve" }, - { GDK_Cyrillic_softsign, "Cyrillic_softsign" }, - { GDK_Cyrillic_yeru, "Cyrillic_yeru" }, - { GDK_Cyrillic_ze, "Cyrillic_ze" }, - { GDK_Cyrillic_sha, "Cyrillic_sha" }, - { GDK_Cyrillic_e, "Cyrillic_e" }, - { GDK_Cyrillic_shcha, "Cyrillic_shcha" }, - { GDK_Cyrillic_che, "Cyrillic_che" }, - { GDK_Cyrillic_hardsign, "Cyrillic_hardsign" }, - { GDK_Cyrillic_YU, "Cyrillic_YU" }, - { GDK_Cyrillic_A, "Cyrillic_A" }, - { GDK_Cyrillic_BE, "Cyrillic_BE" }, - { GDK_Cyrillic_TSE, "Cyrillic_TSE" }, - { GDK_Cyrillic_DE, "Cyrillic_DE" }, - { GDK_Cyrillic_IE, "Cyrillic_IE" }, - { GDK_Cyrillic_EF, "Cyrillic_EF" }, - { GDK_Cyrillic_GHE, "Cyrillic_GHE" }, - { GDK_Cyrillic_HA, "Cyrillic_HA" }, - { GDK_Cyrillic_I, "Cyrillic_I" }, - { GDK_Cyrillic_SHORTI, "Cyrillic_SHORTI" }, - { GDK_Cyrillic_KA, "Cyrillic_KA" }, - { GDK_Cyrillic_EL, "Cyrillic_EL" }, - { GDK_Cyrillic_EM, "Cyrillic_EM" }, - { GDK_Cyrillic_EN, "Cyrillic_EN" }, - { GDK_Cyrillic_O, "Cyrillic_O" }, - { GDK_Cyrillic_PE, "Cyrillic_PE" }, - { GDK_Cyrillic_YA, "Cyrillic_YA" }, - { GDK_Cyrillic_ER, "Cyrillic_ER" }, - { GDK_Cyrillic_ES, "Cyrillic_ES" }, - { GDK_Cyrillic_TE, "Cyrillic_TE" }, - { GDK_Cyrillic_U, "Cyrillic_U" }, - { GDK_Cyrillic_ZHE, "Cyrillic_ZHE" }, - { GDK_Cyrillic_VE, "Cyrillic_VE" }, - { GDK_Cyrillic_SOFTSIGN, "Cyrillic_SOFTSIGN" }, - { GDK_Cyrillic_YERU, "Cyrillic_YERU" }, - { GDK_Cyrillic_ZE, "Cyrillic_ZE" }, - { GDK_Cyrillic_SHA, "Cyrillic_SHA" }, - { GDK_Cyrillic_E, "Cyrillic_E" }, - { GDK_Cyrillic_SHCHA, "Cyrillic_SHCHA" }, - { GDK_Cyrillic_CHE, "Cyrillic_CHE" }, - { GDK_Cyrillic_HARDSIGN, "Cyrillic_HARDSIGN" }, - { GDK_Greek_ALPHAaccent, "Greek_ALPHAaccent" }, - { GDK_Greek_EPSILONaccent, "Greek_EPSILONaccent" }, - { GDK_Greek_ETAaccent, "Greek_ETAaccent" }, - { GDK_Greek_IOTAaccent, "Greek_IOTAaccent" }, - { GDK_Greek_IOTAdieresis, "Greek_IOTAdieresis" }, - { GDK_Greek_IOTAdiaeresis, "Greek_IOTAdiaeresis" }, - { GDK_Greek_OMICRONaccent, "Greek_OMICRONaccent" }, - { GDK_Greek_UPSILONaccent, "Greek_UPSILONaccent" }, - { GDK_Greek_UPSILONdieresis, "Greek_UPSILONdieresis" }, - { GDK_Greek_OMEGAaccent, "Greek_OMEGAaccent" }, - { GDK_Greek_accentdieresis, "Greek_accentdieresis" }, - { GDK_Greek_horizbar, "Greek_horizbar" }, - { GDK_Greek_alphaaccent, "Greek_alphaaccent" }, - { GDK_Greek_epsilonaccent, "Greek_epsilonaccent" }, - { GDK_Greek_etaaccent, "Greek_etaaccent" }, - { GDK_Greek_iotaaccent, "Greek_iotaaccent" }, - { GDK_Greek_iotadieresis, "Greek_iotadieresis" }, - { GDK_Greek_iotaaccentdieresis, "Greek_iotaaccentdieresis" }, - { GDK_Greek_omicronaccent, "Greek_omicronaccent" }, - { GDK_Greek_upsilonaccent, "Greek_upsilonaccent" }, - { GDK_Greek_upsilondieresis, "Greek_upsilondieresis" }, - { GDK_Greek_upsilonaccentdieresis, "Greek_upsilonaccentdieresis" }, - { GDK_Greek_omegaaccent, "Greek_omegaaccent" }, - { GDK_Greek_ALPHA, "Greek_ALPHA" }, - { GDK_Greek_BETA, "Greek_BETA" }, - { GDK_Greek_GAMMA, "Greek_GAMMA" }, - { GDK_Greek_DELTA, "Greek_DELTA" }, - { GDK_Greek_EPSILON, "Greek_EPSILON" }, - { GDK_Greek_ZETA, "Greek_ZETA" }, - { GDK_Greek_ETA, "Greek_ETA" }, - { GDK_Greek_THETA, "Greek_THETA" }, - { GDK_Greek_IOTA, "Greek_IOTA" }, - { GDK_Greek_KAPPA, "Greek_KAPPA" }, - { GDK_Greek_LAMDA, "Greek_LAMDA" }, - { GDK_Greek_LAMBDA, "Greek_LAMBDA" }, - { GDK_Greek_MU, "Greek_MU" }, - { GDK_Greek_NU, "Greek_NU" }, - { GDK_Greek_XI, "Greek_XI" }, - { GDK_Greek_OMICRON, "Greek_OMICRON" }, - { GDK_Greek_PI, "Greek_PI" }, - { GDK_Greek_RHO, "Greek_RHO" }, - { GDK_Greek_SIGMA, "Greek_SIGMA" }, - { GDK_Greek_TAU, "Greek_TAU" }, - { GDK_Greek_UPSILON, "Greek_UPSILON" }, - { GDK_Greek_PHI, "Greek_PHI" }, - { GDK_Greek_CHI, "Greek_CHI" }, - { GDK_Greek_PSI, "Greek_PSI" }, - { GDK_Greek_OMEGA, "Greek_OMEGA" }, - { GDK_Greek_alpha, "Greek_alpha" }, - { GDK_Greek_beta, "Greek_beta" }, - { GDK_Greek_gamma, "Greek_gamma" }, - { GDK_Greek_delta, "Greek_delta" }, - { GDK_Greek_epsilon, "Greek_epsilon" }, - { GDK_Greek_zeta, "Greek_zeta" }, - { GDK_Greek_eta, "Greek_eta" }, - { GDK_Greek_theta, "Greek_theta" }, - { GDK_Greek_iota, "Greek_iota" }, - { GDK_Greek_kappa, "Greek_kappa" }, - { GDK_Greek_lamda, "Greek_lamda" }, - { GDK_Greek_lambda, "Greek_lambda" }, - { GDK_Greek_mu, "Greek_mu" }, - { GDK_Greek_nu, "Greek_nu" }, - { GDK_Greek_xi, "Greek_xi" }, - { GDK_Greek_omicron, "Greek_omicron" }, - { GDK_Greek_pi, "Greek_pi" }, - { GDK_Greek_rho, "Greek_rho" }, - { GDK_Greek_sigma, "Greek_sigma" }, - { GDK_Greek_finalsmallsigma, "Greek_finalsmallsigma" }, - { GDK_Greek_tau, "Greek_tau" }, - { GDK_Greek_upsilon, "Greek_upsilon" }, - { GDK_Greek_phi, "Greek_phi" }, - { GDK_Greek_chi, "Greek_chi" }, - { GDK_Greek_psi, "Greek_psi" }, - { GDK_Greek_omega, "Greek_omega" }, - { GDK_Greek_switch, "Greek_switch" }, - { GDK_leftradical, "leftradical" }, - { GDK_topleftradical, "topleftradical" }, - { GDK_horizconnector, "horizconnector" }, - { GDK_topintegral, "topintegral" }, - { GDK_botintegral, "botintegral" }, - { GDK_vertconnector, "vertconnector" }, - { GDK_topleftsqbracket, "topleftsqbracket" }, - { GDK_botleftsqbracket, "botleftsqbracket" }, - { GDK_toprightsqbracket, "toprightsqbracket" }, - { GDK_botrightsqbracket, "botrightsqbracket" }, - { GDK_topleftparens, "topleftparens" }, - { GDK_botleftparens, "botleftparens" }, - { GDK_toprightparens, "toprightparens" }, - { GDK_botrightparens, "botrightparens" }, - { GDK_leftmiddlecurlybrace, "leftmiddlecurlybrace" }, - { GDK_rightmiddlecurlybrace, "rightmiddlecurlybrace" }, - { GDK_topleftsummation, "topleftsummation" }, - { GDK_botleftsummation, "botleftsummation" }, - { GDK_topvertsummationconnector, "topvertsummationconnector" }, - { GDK_botvertsummationconnector, "botvertsummationconnector" }, - { GDK_toprightsummation, "toprightsummation" }, - { GDK_botrightsummation, "botrightsummation" }, - { GDK_rightmiddlesummation, "rightmiddlesummation" }, - { GDK_lessthanequal, "lessthanequal" }, - { GDK_notequal, "notequal" }, - { GDK_greaterthanequal, "greaterthanequal" }, - { GDK_integral, "integral" }, - { GDK_therefore, "therefore" }, - { GDK_variation, "variation" }, - { GDK_infinity, "infinity" }, - { GDK_nabla, "nabla" }, - { GDK_approximate, "approximate" }, - { GDK_similarequal, "similarequal" }, - { GDK_ifonlyif, "ifonlyif" }, - { GDK_implies, "implies" }, - { GDK_identical, "identical" }, - { GDK_radical, "radical" }, - { GDK_includedin, "includedin" }, - { GDK_includes, "includes" }, - { GDK_intersection, "intersection" }, - { GDK_union, "union" }, - { GDK_logicaland, "logicaland" }, - { GDK_logicalor, "logicalor" }, - { GDK_partialderivative, "partialderivative" }, - { GDK_function, "function" }, - { GDK_leftarrow, "leftarrow" }, - { GDK_uparrow, "uparrow" }, - { GDK_rightarrow, "rightarrow" }, - { GDK_downarrow, "downarrow" }, - { GDK_blank, "blank" }, - { GDK_soliddiamond, "soliddiamond" }, - { GDK_checkerboard, "checkerboard" }, - { GDK_ht, "ht" }, - { GDK_ff, "ff" }, - { GDK_cr, "cr" }, - { GDK_lf, "lf" }, - { GDK_nl, "nl" }, - { GDK_vt, "vt" }, - { GDK_lowrightcorner, "lowrightcorner" }, - { GDK_uprightcorner, "uprightcorner" }, - { GDK_upleftcorner, "upleftcorner" }, - { GDK_lowleftcorner, "lowleftcorner" }, - { GDK_crossinglines, "crossinglines" }, - { GDK_horizlinescan1, "horizlinescan1" }, - { GDK_horizlinescan3, "horizlinescan3" }, - { GDK_horizlinescan5, "horizlinescan5" }, - { GDK_horizlinescan7, "horizlinescan7" }, - { GDK_horizlinescan9, "horizlinescan9" }, - { GDK_leftt, "leftt" }, - { GDK_rightt, "rightt" }, - { GDK_bott, "bott" }, - { GDK_topt, "topt" }, - { GDK_vertbar, "vertbar" }, - { GDK_emspace, "emspace" }, - { GDK_enspace, "enspace" }, - { GDK_em3space, "em3space" }, - { GDK_em4space, "em4space" }, - { GDK_digitspace, "digitspace" }, - { GDK_punctspace, "punctspace" }, - { GDK_thinspace, "thinspace" }, - { GDK_hairspace, "hairspace" }, - { GDK_emdash, "emdash" }, - { GDK_endash, "endash" }, - { GDK_signifblank, "signifblank" }, - { GDK_ellipsis, "ellipsis" }, - { GDK_doubbaselinedot, "doubbaselinedot" }, - { GDK_onethird, "onethird" }, - { GDK_twothirds, "twothirds" }, - { GDK_onefifth, "onefifth" }, - { GDK_twofifths, "twofifths" }, - { GDK_threefifths, "threefifths" }, - { GDK_fourfifths, "fourfifths" }, - { GDK_onesixth, "onesixth" }, - { GDK_fivesixths, "fivesixths" }, - { GDK_careof, "careof" }, - { GDK_figdash, "figdash" }, - { GDK_leftanglebracket, "leftanglebracket" }, - { GDK_decimalpoint, "decimalpoint" }, - { GDK_rightanglebracket, "rightanglebracket" }, - { GDK_marker, "marker" }, - { GDK_oneeighth, "oneeighth" }, - { GDK_threeeighths, "threeeighths" }, - { GDK_fiveeighths, "fiveeighths" }, - { GDK_seveneighths, "seveneighths" }, - { GDK_trademark, "trademark" }, - { GDK_signaturemark, "signaturemark" }, - { GDK_trademarkincircle, "trademarkincircle" }, - { GDK_leftopentriangle, "leftopentriangle" }, - { GDK_rightopentriangle, "rightopentriangle" }, - { GDK_emopencircle, "emopencircle" }, - { GDK_emopenrectangle, "emopenrectangle" }, - { GDK_leftsinglequotemark, "leftsinglequotemark" }, - { GDK_rightsinglequotemark, "rightsinglequotemark" }, - { GDK_leftdoublequotemark, "leftdoublequotemark" }, - { GDK_rightdoublequotemark, "rightdoublequotemark" }, - { GDK_prescription, "prescription" }, - { GDK_minutes, "minutes" }, - { GDK_seconds, "seconds" }, - { GDK_latincross, "latincross" }, - { GDK_hexagram, "hexagram" }, - { GDK_filledrectbullet, "filledrectbullet" }, - { GDK_filledlefttribullet, "filledlefttribullet" }, - { GDK_filledrighttribullet, "filledrighttribullet" }, - { GDK_emfilledcircle, "emfilledcircle" }, - { GDK_emfilledrect, "emfilledrect" }, - { GDK_enopencircbullet, "enopencircbullet" }, - { GDK_enopensquarebullet, "enopensquarebullet" }, - { GDK_openrectbullet, "openrectbullet" }, - { GDK_opentribulletup, "opentribulletup" }, - { GDK_opentribulletdown, "opentribulletdown" }, - { GDK_openstar, "openstar" }, - { GDK_enfilledcircbullet, "enfilledcircbullet" }, - { GDK_enfilledsqbullet, "enfilledsqbullet" }, - { GDK_filledtribulletup, "filledtribulletup" }, - { GDK_filledtribulletdown, "filledtribulletdown" }, - { GDK_leftpointer, "leftpointer" }, - { GDK_rightpointer, "rightpointer" }, - { GDK_club, "club" }, - { GDK_diamond, "diamond" }, - { GDK_heart, "heart" }, - { GDK_maltesecross, "maltesecross" }, - { GDK_dagger, "dagger" }, - { GDK_doubledagger, "doubledagger" }, - { GDK_checkmark, "checkmark" }, - { GDK_ballotcross, "ballotcross" }, - { GDK_musicalsharp, "musicalsharp" }, - { GDK_musicalflat, "musicalflat" }, - { GDK_malesymbol, "malesymbol" }, - { GDK_femalesymbol, "femalesymbol" }, - { GDK_telephone, "telephone" }, - { GDK_telephonerecorder, "telephonerecorder" }, - { GDK_phonographcopyright, "phonographcopyright" }, - { GDK_caret, "caret" }, - { GDK_singlelowquotemark, "singlelowquotemark" }, - { GDK_doublelowquotemark, "doublelowquotemark" }, - { GDK_cursor, "cursor" }, - { GDK_leftcaret, "leftcaret" }, - { GDK_rightcaret, "rightcaret" }, - { GDK_downcaret, "downcaret" }, - { GDK_upcaret, "upcaret" }, - { GDK_overbar, "overbar" }, - { GDK_downtack, "downtack" }, - { GDK_upshoe, "upshoe" }, - { GDK_downstile, "downstile" }, - { GDK_underbar, "underbar" }, - { GDK_jot, "jot" }, - { GDK_quad, "quad" }, - { GDK_uptack, "uptack" }, - { GDK_circle, "circle" }, - { GDK_upstile, "upstile" }, - { GDK_downshoe, "downshoe" }, - { GDK_rightshoe, "rightshoe" }, - { GDK_leftshoe, "leftshoe" }, - { GDK_lefttack, "lefttack" }, - { GDK_righttack, "righttack" }, - { GDK_hebrew_doublelowline, "hebrew_doublelowline" }, - { GDK_hebrew_aleph, "hebrew_aleph" }, - { GDK_hebrew_bet, "hebrew_bet" }, - { GDK_hebrew_beth, "hebrew_beth" }, - { GDK_hebrew_gimel, "hebrew_gimel" }, - { GDK_hebrew_gimmel, "hebrew_gimmel" }, - { GDK_hebrew_dalet, "hebrew_dalet" }, - { GDK_hebrew_daleth, "hebrew_daleth" }, - { GDK_hebrew_he, "hebrew_he" }, - { GDK_hebrew_waw, "hebrew_waw" }, - { GDK_hebrew_zain, "hebrew_zain" }, - { GDK_hebrew_zayin, "hebrew_zayin" }, - { GDK_hebrew_chet, "hebrew_chet" }, - { GDK_hebrew_het, "hebrew_het" }, - { GDK_hebrew_tet, "hebrew_tet" }, - { GDK_hebrew_teth, "hebrew_teth" }, - { GDK_hebrew_yod, "hebrew_yod" }, - { GDK_hebrew_finalkaph, "hebrew_finalkaph" }, - { GDK_hebrew_kaph, "hebrew_kaph" }, - { GDK_hebrew_lamed, "hebrew_lamed" }, - { GDK_hebrew_finalmem, "hebrew_finalmem" }, - { GDK_hebrew_mem, "hebrew_mem" }, - { GDK_hebrew_finalnun, "hebrew_finalnun" }, - { GDK_hebrew_nun, "hebrew_nun" }, - { GDK_hebrew_samech, "hebrew_samech" }, - { GDK_hebrew_samekh, "hebrew_samekh" }, - { GDK_hebrew_ayin, "hebrew_ayin" }, - { GDK_hebrew_finalpe, "hebrew_finalpe" }, - { GDK_hebrew_pe, "hebrew_pe" }, - { GDK_hebrew_finalzade, "hebrew_finalzade" }, - { GDK_hebrew_finalzadi, "hebrew_finalzadi" }, - { GDK_hebrew_zade, "hebrew_zade" }, - { GDK_hebrew_zadi, "hebrew_zadi" }, - { GDK_hebrew_qoph, "hebrew_qoph" }, - { GDK_hebrew_kuf, "hebrew_kuf" }, - { GDK_hebrew_resh, "hebrew_resh" }, - { GDK_hebrew_shin, "hebrew_shin" }, - { GDK_hebrew_taw, "hebrew_taw" }, - { GDK_hebrew_taf, "hebrew_taf" }, - { GDK_Hebrew_switch, "Hebrew_switch" }, - { GDK_Thai_kokai, "Thai_kokai" }, - { GDK_Thai_khokhai, "Thai_khokhai" }, - { GDK_Thai_khokhuat, "Thai_khokhuat" }, - { GDK_Thai_khokhwai, "Thai_khokhwai" }, - { GDK_Thai_khokhon, "Thai_khokhon" }, - { GDK_Thai_khorakhang, "Thai_khorakhang" }, - { GDK_Thai_ngongu, "Thai_ngongu" }, - { GDK_Thai_chochan, "Thai_chochan" }, - { GDK_Thai_choching, "Thai_choching" }, - { GDK_Thai_chochang, "Thai_chochang" }, - { GDK_Thai_soso, "Thai_soso" }, - { GDK_Thai_chochoe, "Thai_chochoe" }, - { GDK_Thai_yoying, "Thai_yoying" }, - { GDK_Thai_dochada, "Thai_dochada" }, - { GDK_Thai_topatak, "Thai_topatak" }, - { GDK_Thai_thothan, "Thai_thothan" }, - { GDK_Thai_thonangmontho, "Thai_thonangmontho" }, - { GDK_Thai_thophuthao, "Thai_thophuthao" }, - { GDK_Thai_nonen, "Thai_nonen" }, - { GDK_Thai_dodek, "Thai_dodek" }, - { GDK_Thai_totao, "Thai_totao" }, - { GDK_Thai_thothung, "Thai_thothung" }, - { GDK_Thai_thothahan, "Thai_thothahan" }, - { GDK_Thai_thothong, "Thai_thothong" }, - { GDK_Thai_nonu, "Thai_nonu" }, - { GDK_Thai_bobaimai, "Thai_bobaimai" }, - { GDK_Thai_popla, "Thai_popla" }, - { GDK_Thai_phophung, "Thai_phophung" }, - { GDK_Thai_fofa, "Thai_fofa" }, - { GDK_Thai_phophan, "Thai_phophan" }, - { GDK_Thai_fofan, "Thai_fofan" }, - { GDK_Thai_phosamphao, "Thai_phosamphao" }, - { GDK_Thai_moma, "Thai_moma" }, - { GDK_Thai_yoyak, "Thai_yoyak" }, - { GDK_Thai_rorua, "Thai_rorua" }, - { GDK_Thai_ru, "Thai_ru" }, - { GDK_Thai_loling, "Thai_loling" }, - { GDK_Thai_lu, "Thai_lu" }, - { GDK_Thai_wowaen, "Thai_wowaen" }, - { GDK_Thai_sosala, "Thai_sosala" }, - { GDK_Thai_sorusi, "Thai_sorusi" }, - { GDK_Thai_sosua, "Thai_sosua" }, - { GDK_Thai_hohip, "Thai_hohip" }, - { GDK_Thai_lochula, "Thai_lochula" }, - { GDK_Thai_oang, "Thai_oang" }, - { GDK_Thai_honokhuk, "Thai_honokhuk" }, - { GDK_Thai_paiyannoi, "Thai_paiyannoi" }, - { GDK_Thai_saraa, "Thai_saraa" }, - { GDK_Thai_maihanakat, "Thai_maihanakat" }, - { GDK_Thai_saraaa, "Thai_saraaa" }, - { GDK_Thai_saraam, "Thai_saraam" }, - { GDK_Thai_sarai, "Thai_sarai" }, - { GDK_Thai_saraii, "Thai_saraii" }, - { GDK_Thai_saraue, "Thai_saraue" }, - { GDK_Thai_sarauee, "Thai_sarauee" }, - { GDK_Thai_sarau, "Thai_sarau" }, - { GDK_Thai_sarauu, "Thai_sarauu" }, - { GDK_Thai_phinthu, "Thai_phinthu" }, - { GDK_Thai_maihanakat_maitho, "Thai_maihanakat_maitho" }, - { GDK_Thai_baht, "Thai_baht" }, - { GDK_Thai_sarae, "Thai_sarae" }, - { GDK_Thai_saraae, "Thai_saraae" }, - { GDK_Thai_sarao, "Thai_sarao" }, - { GDK_Thai_saraaimaimuan, "Thai_saraaimaimuan" }, - { GDK_Thai_saraaimaimalai, "Thai_saraaimaimalai" }, - { GDK_Thai_lakkhangyao, "Thai_lakkhangyao" }, - { GDK_Thai_maiyamok, "Thai_maiyamok" }, - { GDK_Thai_maitaikhu, "Thai_maitaikhu" }, - { GDK_Thai_maiek, "Thai_maiek" }, - { GDK_Thai_maitho, "Thai_maitho" }, - { GDK_Thai_maitri, "Thai_maitri" }, - { GDK_Thai_maichattawa, "Thai_maichattawa" }, - { GDK_Thai_thanthakhat, "Thai_thanthakhat" }, - { GDK_Thai_nikhahit, "Thai_nikhahit" }, - { GDK_Thai_leksun, "Thai_leksun" }, - { GDK_Thai_leknung, "Thai_leknung" }, - { GDK_Thai_leksong, "Thai_leksong" }, - { GDK_Thai_leksam, "Thai_leksam" }, - { GDK_Thai_leksi, "Thai_leksi" }, - { GDK_Thai_lekha, "Thai_lekha" }, - { GDK_Thai_lekhok, "Thai_lekhok" }, - { GDK_Thai_lekchet, "Thai_lekchet" }, - { GDK_Thai_lekpaet, "Thai_lekpaet" }, - { GDK_Thai_lekkao, "Thai_lekkao" }, - { GDK_Hangul, "Hangul" }, - { GDK_Hangul_Start, "Hangul_Start" }, - { GDK_Hangul_End, "Hangul_End" }, - { GDK_Hangul_Hanja, "Hangul_Hanja" }, - { GDK_Hangul_Jamo, "Hangul_Jamo" }, - { GDK_Hangul_Romaja, "Hangul_Romaja" }, - { GDK_Hangul_Codeinput, "Hangul_Codeinput" }, - { GDK_Hangul_Jeonja, "Hangul_Jeonja" }, - { GDK_Hangul_Banja, "Hangul_Banja" }, - { GDK_Hangul_PreHanja, "Hangul_PreHanja" }, - { GDK_Hangul_PostHanja, "Hangul_PostHanja" }, - { GDK_Hangul_SingleCandidate, "Hangul_SingleCandidate" }, - { GDK_Hangul_MultipleCandidate, "Hangul_MultipleCandidate" }, - { GDK_Hangul_PreviousCandidate, "Hangul_PreviousCandidate" }, - { GDK_Hangul_Special, "Hangul_Special" }, - { GDK_Hangul_switch, "Hangul_switch" }, - { GDK_Hangul_Kiyeog, "Hangul_Kiyeog" }, - { GDK_Hangul_SsangKiyeog, "Hangul_SsangKiyeog" }, - { GDK_Hangul_KiyeogSios, "Hangul_KiyeogSios" }, - { GDK_Hangul_Nieun, "Hangul_Nieun" }, - { GDK_Hangul_NieunJieuj, "Hangul_NieunJieuj" }, - { GDK_Hangul_NieunHieuh, "Hangul_NieunHieuh" }, - { GDK_Hangul_Dikeud, "Hangul_Dikeud" }, - { GDK_Hangul_SsangDikeud, "Hangul_SsangDikeud" }, - { GDK_Hangul_Rieul, "Hangul_Rieul" }, - { GDK_Hangul_RieulKiyeog, "Hangul_RieulKiyeog" }, - { GDK_Hangul_RieulMieum, "Hangul_RieulMieum" }, - { GDK_Hangul_RieulPieub, "Hangul_RieulPieub" }, - { GDK_Hangul_RieulSios, "Hangul_RieulSios" }, - { GDK_Hangul_RieulTieut, "Hangul_RieulTieut" }, - { GDK_Hangul_RieulPhieuf, "Hangul_RieulPhieuf" }, - { GDK_Hangul_RieulHieuh, "Hangul_RieulHieuh" }, - { GDK_Hangul_Mieum, "Hangul_Mieum" }, - { GDK_Hangul_Pieub, "Hangul_Pieub" }, - { GDK_Hangul_SsangPieub, "Hangul_SsangPieub" }, - { GDK_Hangul_PieubSios, "Hangul_PieubSios" }, - { GDK_Hangul_Sios, "Hangul_Sios" }, - { GDK_Hangul_SsangSios, "Hangul_SsangSios" }, - { GDK_Hangul_Ieung, "Hangul_Ieung" }, - { GDK_Hangul_Jieuj, "Hangul_Jieuj" }, - { GDK_Hangul_SsangJieuj, "Hangul_SsangJieuj" }, - { GDK_Hangul_Cieuc, "Hangul_Cieuc" }, - { GDK_Hangul_Khieuq, "Hangul_Khieuq" }, - { GDK_Hangul_Tieut, "Hangul_Tieut" }, - { GDK_Hangul_Phieuf, "Hangul_Phieuf" }, - { GDK_Hangul_Hieuh, "Hangul_Hieuh" }, - { GDK_Hangul_A, "Hangul_A" }, - { GDK_Hangul_AE, "Hangul_AE" }, - { GDK_Hangul_YA, "Hangul_YA" }, - { GDK_Hangul_YAE, "Hangul_YAE" }, - { GDK_Hangul_EO, "Hangul_EO" }, - { GDK_Hangul_E, "Hangul_E" }, - { GDK_Hangul_YEO, "Hangul_YEO" }, - { GDK_Hangul_YE, "Hangul_YE" }, - { GDK_Hangul_O, "Hangul_O" }, - { GDK_Hangul_WA, "Hangul_WA" }, - { GDK_Hangul_WAE, "Hangul_WAE" }, - { GDK_Hangul_OE, "Hangul_OE" }, - { GDK_Hangul_YO, "Hangul_YO" }, - { GDK_Hangul_U, "Hangul_U" }, - { GDK_Hangul_WEO, "Hangul_WEO" }, - { GDK_Hangul_WE, "Hangul_WE" }, - { GDK_Hangul_WI, "Hangul_WI" }, - { GDK_Hangul_YU, "Hangul_YU" }, - { GDK_Hangul_EU, "Hangul_EU" }, - { GDK_Hangul_YI, "Hangul_YI" }, - { GDK_Hangul_I, "Hangul_I" }, - { GDK_Hangul_J_Kiyeog, "Hangul_J_Kiyeog" }, - { GDK_Hangul_J_SsangKiyeog, "Hangul_J_SsangKiyeog" }, - { GDK_Hangul_J_KiyeogSios, "Hangul_J_KiyeogSios" }, - { GDK_Hangul_J_Nieun, "Hangul_J_Nieun" }, - { GDK_Hangul_J_NieunJieuj, "Hangul_J_NieunJieuj" }, - { GDK_Hangul_J_NieunHieuh, "Hangul_J_NieunHieuh" }, - { GDK_Hangul_J_Dikeud, "Hangul_J_Dikeud" }, - { GDK_Hangul_J_Rieul, "Hangul_J_Rieul" }, - { GDK_Hangul_J_RieulKiyeog, "Hangul_J_RieulKiyeog" }, - { GDK_Hangul_J_RieulMieum, "Hangul_J_RieulMieum" }, - { GDK_Hangul_J_RieulPieub, "Hangul_J_RieulPieub" }, - { GDK_Hangul_J_RieulSios, "Hangul_J_RieulSios" }, - { GDK_Hangul_J_RieulTieut, "Hangul_J_RieulTieut" }, - { GDK_Hangul_J_RieulPhieuf, "Hangul_J_RieulPhieuf" }, - { GDK_Hangul_J_RieulHieuh, "Hangul_J_RieulHieuh" }, - { GDK_Hangul_J_Mieum, "Hangul_J_Mieum" }, - { GDK_Hangul_J_Pieub, "Hangul_J_Pieub" }, - { GDK_Hangul_J_PieubSios, "Hangul_J_PieubSios" }, - { GDK_Hangul_J_Sios, "Hangul_J_Sios" }, - { GDK_Hangul_J_SsangSios, "Hangul_J_SsangSios" }, - { GDK_Hangul_J_Ieung, "Hangul_J_Ieung" }, - { GDK_Hangul_J_Jieuj, "Hangul_J_Jieuj" }, - { GDK_Hangul_J_Cieuc, "Hangul_J_Cieuc" }, - { GDK_Hangul_J_Khieuq, "Hangul_J_Khieuq" }, - { GDK_Hangul_J_Tieut, "Hangul_J_Tieut" }, - { GDK_Hangul_J_Phieuf, "Hangul_J_Phieuf" }, - { GDK_Hangul_J_Hieuh, "Hangul_J_Hieuh" }, - { GDK_Hangul_RieulYeorinHieuh, "Hangul_RieulYeorinHieuh" }, - { GDK_Hangul_SunkyeongeumMieum, "Hangul_SunkyeongeumMieum" }, - { GDK_Hangul_SunkyeongeumPieub, "Hangul_SunkyeongeumPieub" }, - { GDK_Hangul_PanSios, "Hangul_PanSios" }, - { GDK_Hangul_KkogjiDalrinIeung, "Hangul_KkogjiDalrinIeung" }, - { GDK_Hangul_SunkyeongeumPhieuf, "Hangul_SunkyeongeumPhieuf" }, - { GDK_Hangul_YeorinHieuh, "Hangul_YeorinHieuh" }, - { GDK_Hangul_AraeA, "Hangul_AraeA" }, - { GDK_Hangul_AraeAE, "Hangul_AraeAE" }, - { GDK_Hangul_J_PanSios, "Hangul_J_PanSios" }, - { GDK_Hangul_J_KkogjiDalrinIeung, "Hangul_J_KkogjiDalrinIeung" }, - { GDK_Hangul_J_YeorinHieuh, "Hangul_J_YeorinHieuh" }, - { GDK_Korean_Won, "Korean_Won" }, - { GDK_EcuSign, "EcuSign" }, - { GDK_ColonSign, "ColonSign" }, - { GDK_CruzeiroSign, "CruzeiroSign" }, - { GDK_FFrancSign, "FFrancSign" }, - { GDK_LiraSign, "LiraSign" }, - { GDK_MillSign, "MillSign" }, - { GDK_NairaSign, "NairaSign" }, - { GDK_PesetaSign, "PesetaSign" }, - { GDK_RupeeSign, "RupeeSign" }, - { GDK_WonSign, "WonSign" }, - { GDK_NewSheqelSign, "NewSheqelSign" }, - { GDK_DongSign, "DongSign" }, - { GDK_EuroSign, "EuroSign" }, - - { 0, NULL } -}; diff --git a/gladeui/glade-marshallers.list b/gladeui/glade-marshallers.list deleted file mode 100644 index 72fea562..00000000 --- a/gladeui/glade-marshallers.list +++ /dev/null @@ -1,17 +0,0 @@ -VOID:POINTER,POINTER -VOID:STRING,ULONG,UINT,STRING -VOID:OBJECT -VOID:OBJECT,BOOLEAN -VOID:STRING,STRING,STRING -OBJECT:POINTER -OBJECT:OBJECT,UINT -BOOLEAN:STRING -BOOLEAN:BOXED -BOOLEAN:OBJECT -BOOLEAN:OBJECT,BOXED -BOOLEAN:OBJECT,POINTER -BOOLEAN:OBJECT,BOOLEAN -BOOLEAN:OBJECT,UINT -BOOLEAN:OBJECT,OBJECT -BOOLEAN:OBJECT,STRING -STRING:OBJECT diff --git a/gladeui/glade-palette-box.c b/gladeui/glade-palette-box.c deleted file mode 100644 index e8c2e33a..00000000 --- a/gladeui/glade-palette-box.c +++ /dev/null @@ -1,468 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * glade-palette-box.c - * - * Copyright (C) 2007 Vincent Geddes. - * - * Author: Vincent Geddes <vincent.geddes@gmail.com> - * - * 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. - * - */ - -#include <config.h> - -#include "glade-palette-box.h" - -#define GLADE_PALETTE_BOX_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object),\ - GLADE_TYPE_PALETTE_BOX, \ - GladePaletteBoxPrivate)) - -enum -{ - PROP_0 -}; - -enum -{ - CHILD_PROP_0, - CHILD_PROP_POSITION -}; - -struct _GladePaletteBoxPrivate -{ - GList *children; - -}; - -typedef struct -{ - GtkWidget *widget; -} GladePaletteBoxChild; - -static void glade_palette_box_add (GtkContainer *container, GtkWidget *widget); - -static void glade_palette_box_remove (GtkContainer *container, GtkWidget *widget); - -static GType glade_palette_box_child_type (GtkContainer *container); - -static void glade_palette_box_size_request (GtkWidget *widget, GtkRequisition *requisition); - -static void glade_palette_box_size_allocate (GtkWidget *widget, GtkAllocation *allocation); - -static void glade_palette_box_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data); - -static void glade_palette_box_set_child_property (GtkContainer *container, - GtkWidget *child, - guint property_id, - const GValue *value, - GParamSpec *pspec); - -static void glade_palette_box_get_child_property (GtkContainer *container, - GtkWidget *child, - guint property_id, - GValue *value, - GParamSpec *pspec); - - -G_DEFINE_TYPE (GladePaletteBox, glade_palette_box, GTK_TYPE_CONTAINER); - - -static void -glade_palette_box_class_init (GladePaletteBoxClass *klass) -{ - GtkWidgetClass *widget_class; - GtkContainerClass *container_class; - - container_class = GTK_CONTAINER_CLASS (klass); - widget_class = GTK_WIDGET_CLASS (klass); - - widget_class->size_request = glade_palette_box_size_request; - widget_class->size_allocate = glade_palette_box_size_allocate; - - container_class->add = glade_palette_box_add; - container_class->remove = glade_palette_box_remove; - container_class->forall = glade_palette_box_forall; - container_class->child_type = glade_palette_box_child_type; - container_class->set_child_property = glade_palette_box_set_child_property; - container_class->get_child_property = glade_palette_box_get_child_property; - - gtk_container_class_install_child_property (container_class, - CHILD_PROP_POSITION, - g_param_spec_int ("position", - "Position", - "The index of the child in the parent", - -1, G_MAXINT, 0, - G_PARAM_READWRITE)); - - g_type_class_add_private (klass, sizeof (GladePaletteBoxPrivate)); -} - -static void -glade_palette_box_init (GladePaletteBox *box) -{ - GTK_WIDGET_SET_FLAGS (box, GTK_NO_WINDOW); - gtk_widget_set_redraw_on_allocate (GTK_WIDGET (box), FALSE); - - box->priv = GLADE_PALETTE_BOX_GET_PRIVATE (box); - - box->priv->children = NULL; -} - -static void -glade_palette_box_set_child_property (GtkContainer *container, - GtkWidget *child, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - - switch (property_id) - { - case CHILD_PROP_POSITION: - glade_palette_box_reorder_child (GLADE_PALETTE_BOX (container), - child, - g_value_get_int (value)); - break; - default: - GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec); - break; - } -} - -static void -glade_palette_box_get_child_property (GtkContainer *container, - GtkWidget *child, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - GList *list; - guint i; - - switch (property_id) - { - case CHILD_PROP_POSITION: - i = 0; - for (list = GLADE_PALETTE_BOX_GET_PRIVATE (container)->children; list; list = list->next) - { - GladePaletteBoxChild *child_entry; - - child_entry = list->data; - if (child_entry->widget == child) - break; - i++; - } - g_value_set_int (value, list ? i : -1); - break; - default: - GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec); - break; - } -} - -/* do some badass mathematics */ -static gint -calculate_children_width_allocation (GtkWidget *widget, - GtkAllocation *allocation, - GtkRequisition *child_requisition, - gint nvis_children) -{ - gint w; /* container width */ - gint cw; /* children width request */ - gint tmp = 0; - - g_assert (child_requisition->width >= 0); - - w = allocation->width - GTK_CONTAINER (widget)->border_width; - cw = child_requisition->width; - - if ((nvis_children * cw) < w ) - return cw; - - if ((tmp = w - w % cw) == 0) - return child_requisition->width; - else - return w / (tmp / cw); -} - -static void -glade_palette_box_size_request (GtkWidget *widget, GtkRequisition *requisition) -{ - GladePaletteBox *box; - GladePaletteBoxChild *child; - GtkRequisition child_requisition; - GList *l; - gint nvis_children = 0; - - box = GLADE_PALETTE_BOX (widget); - - requisition->width = 0; - requisition->height = 0; - child_requisition.width = 0; - child_requisition.height = 0; - - for (l = box->priv->children; l; l = l->next) - { - child = (GladePaletteBoxChild *) (l->data); - - if (GTK_WIDGET_VISIBLE (child->widget)) - { - GtkRequisition requisition; - gtk_widget_size_request (child->widget, &requisition); - - child_requisition.width = MAX (child_requisition.width, requisition.width); - - nvis_children += 1; - } - } - - if (nvis_children > 0) - { - requisition->width += child_requisition.width; - requisition->height += child_requisition.height; - } - - requisition->width += GTK_CONTAINER (box)->border_width * 2; - requisition->height += GTK_CONTAINER (box)->border_width * 2; -} - -static void -glade_palette_box_size_allocate (GtkWidget *widget, GtkAllocation *allocation) -{ - GladePaletteBox *box; - GladePaletteBoxChild *child; - GList *l; - GtkRequisition child_requisition; - GtkAllocation child_allocation; - gint nvis_children = 0; - gint x, y; - gint rows = 1; - gint children_width; - - box = GLADE_PALETTE_BOX (widget); - widget->allocation = *allocation; - - child_requisition.width = 0; - child_requisition.height = 0; - - /* Retrieve maximum requisition from children */ - for (l = box->priv->children; l; l = l->next) - { - child = (GladePaletteBoxChild *) (l->data); - - if (GTK_WIDGET_VISIBLE (child->widget)) - { - GtkRequisition requisition; - - gtk_widget_get_child_requisition (child->widget, &requisition); - - child_requisition.width = MAX (child_requisition.width, requisition.width); - child_requisition.height = MAX (child_requisition.height, requisition.height); - - nvis_children += 1; - } - } - - if (nvis_children <= 0) - return; - - x = allocation->x + GTK_CONTAINER (box)->border_width; - y = allocation->y + GTK_CONTAINER (box)->border_width; - - children_width = calculate_children_width_allocation (widget, allocation, - &child_requisition, - nvis_children); - - /* Allocate real estate to children */ - for (l = box->priv->children; l; l = l->next) - { - gint horizontal_space_remaining; - - child = (GladePaletteBoxChild *) (l->data); - - if (GTK_WIDGET_VISIBLE (child->widget)) - { - child_allocation.x = x; - child_allocation.y = y; - child_allocation.width = children_width; - child_allocation.height = child_requisition.height; - - gtk_widget_size_allocate (child->widget, &child_allocation); - - x += child_allocation.width; - - /* calculate horizontal space remaining */ - horizontal_space_remaining = x - - allocation->x - + GTK_CONTAINER (box)->border_width - + children_width; - - /* jump to next row */ - if ((horizontal_space_remaining > allocation->width) && l->next ) - { - x = allocation->x + GTK_CONTAINER (box)->border_width; - y += child_allocation.height; - rows++; - } - } - } - - /* force minimum height */ - gtk_widget_set_size_request (widget, -1, rows * child_allocation.height); -} - -static void -glade_palette_box_add (GtkContainer *container, GtkWidget *widget) -{ - GladePaletteBox *box; - GladePaletteBoxChild *child; - - g_return_if_fail (GLADE_IS_PALETTE_BOX (container)); - g_return_if_fail (GTK_IS_WIDGET (widget)); - g_return_if_fail (widget->parent == NULL); - - box = GLADE_PALETTE_BOX (container); - - child = g_slice_new (GladePaletteBoxChild); - child->widget = widget; - box->priv->children = g_list_append (box->priv->children, child); - - gtk_widget_set_parent (widget, GTK_WIDGET (box)); - -} - -static void -glade_palette_box_remove (GtkContainer *container, GtkWidget *widget) -{ - GladePaletteBox *box; - GladePaletteBoxChild *child; - GList *children; - - g_return_if_fail (GLADE_IS_PALETTE_BOX (container)); - g_return_if_fail (GTK_IS_WIDGET (widget)); - - box = GLADE_PALETTE_BOX (container); - - children = box->priv->children; - while (children != NULL) - { - child = children->data; - children = g_list_next (children); - - if (child->widget == widget) - { - gboolean was_visible; - - was_visible = GTK_WIDGET_VISIBLE (widget); - - gtk_widget_unparent (widget); - - box->priv->children = g_list_remove (box->priv->children, child); - - g_slice_free (GladePaletteBoxChild, child); - - if (was_visible) - gtk_widget_queue_resize (GTK_WIDGET (container)); - break; - } - - } - -} - -static void -glade_palette_box_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data) -{ - GladePaletteBox *box; - GladePaletteBoxChild *child; - GList *children; - - g_return_if_fail (callback != NULL); - - box = GLADE_PALETTE_BOX (container); - - children = box->priv->children; - while (children != NULL) - { - child = children->data; - children = g_list_next (children); - - (* callback) (child->widget, callback_data); - } -} - -void -glade_palette_box_reorder_child (GladePaletteBox *box, - GtkWidget *child, - gint position) -{ - GList *old_link; - GList *new_link; - GladePaletteBoxChild *child_info = NULL; - gint old_position; - - g_return_if_fail (GLADE_IS_PALETTE_BOX (box)); - g_return_if_fail (GTK_IS_WIDGET (child)); - - old_link = box->priv->children; - old_position = 0; - while (old_link) - { - child_info = old_link->data; - if (child_info->widget == child) - break; - - old_link = old_link->next; - old_position++; - } - - g_return_if_fail (old_link != NULL); - - if (position == old_position) - return; - - box->priv->children = g_list_delete_link (box->priv->children, old_link); - - if (position < 0) - new_link = NULL; - else - new_link = g_list_nth (box->priv->children, position); - - box->priv->children = g_list_insert_before (box->priv->children, new_link, child_info); - - gtk_widget_child_notify (child, "position"); - if (GTK_WIDGET_VISIBLE (child) && GTK_WIDGET_VISIBLE (box)) - gtk_widget_queue_resize (child); -} - -static GType -glade_palette_box_child_type (GtkContainer *container) -{ - return GTK_TYPE_WIDGET; -} - -GtkWidget* -glade_palette_box_new (void) -{ - return g_object_new (GLADE_TYPE_PALETTE_BOX, NULL); -} diff --git a/gladeui/glade-palette-box.h b/gladeui/glade-palette-box.h deleted file mode 100644 index 687a4cdc..00000000 --- a/gladeui/glade-palette-box.h +++ /dev/null @@ -1,70 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * glade-palette-box.h - * - * Copyright (C) 2007 Vincent Geddes. - * - * Author: Vincent Geddes <vincent.geddes@gmail.com> - * - * 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. - * - */ - -#ifndef __GLADE_PALETTE_BOX_H__ -#define __GLADE_PALETTE_BOX_H__ - -#include <gtk/gtkcontainer.h> - -G_BEGIN_DECLS - -#define GLADE_TYPE_PALETTE_BOX (glade_palette_box_get_type ()) -#define GLADE_PALETTE_BOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_PALETTE_BOX, GladePaletteBox)) -#define GLADE_PALETTE_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_PALETTE_BOX, GladePaletteBoxClass)) -#define GLADE_IS_PALETTE_BOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_PALETTE_BOX)) -#define GLADE_IS_PALETTE_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_PALETTE_BOX)) -#define GLADE_PALETTE_BOX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GLADE_TYPE_PALETTE_BOX, GladePaletteBoxClass)) - -typedef struct _GladePaletteBox GladePaletteBox; -typedef struct _GladePaletteBoxPrivate GladePaletteBoxPrivate; -typedef struct _GladePaletteBoxClass GladePaletteBoxClass; - -struct _GladePaletteBox -{ - GtkContainer parent_instance; - - GladePaletteBoxPrivate *priv; -}; - -struct _GladePaletteBoxClass -{ - GtkContainerClass parent_class; -}; - - - - -GType glade_palette_box_get_type (void) G_GNUC_CONST; - -GtkWidget *glade_palette_box_new (void); - -void glade_palette_box_reorder_child (GladePaletteBox *box, - GtkWidget *child, - gint position); - - -G_END_DECLS - -#endif /* __GLADE_PALETTE_BOX_H__ */ diff --git a/gladeui/glade-palette-expander.c b/gladeui/glade-palette-expander.c deleted file mode 100644 index 7eca432a..00000000 --- a/gladeui/glade-palette-expander.c +++ /dev/null @@ -1,672 +0,0 @@ -/* - * glade-palette-expander.c - A container which can hide its child - * - * Copyright (C) 2007 Vincent Geddes - * - * Author: Vincent Geddes <vincent.geddes@gmail.com> - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#include <config.h> - -#include "glade-palette-expander.h" - -#include <gtk/gtkcontainer.h> -#include <gtk/gtkbutton.h> -#include <gtk/gtkalignment.h> -#include <gtk/gtklabel.h> -#include <gtk/gtkhbox.h> -#include <gtk/gtkarrow.h> -#include <gtk/gtkdnd.h> - -#define GLADE_PALETTE_EXPANDER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \ - GLADE_TYPE_PALETTE_EXPANDER, \ - GladePaletteExpanderPrivate)) - -enum -{ - PROP_0, - PROP_EXPANDED, - PROP_LABEL, - PROP_SPACING, - PROP_USE_MARKUP -}; - -struct _GladePaletteExpanderPrivate -{ - GtkWidget *button; - GtkWidget *arrow; - GtkWidget *label; - - gboolean expanded; - gboolean use_markup; - gboolean button_down; - guint spacing; - guint expand_timer_handle; - -}; - -static void glade_palette_expander_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); -static void glade_palette_expander_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); -static void glade_palette_expander_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static void glade_palette_expander_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static void glade_palette_expander_map (GtkWidget *widget); -static void glade_palette_expander_unmap (GtkWidget *widget); -static void glade_palette_expander_add (GtkContainer *container, - GtkWidget *widget); -static void glade_palette_expander_remove (GtkContainer *container, - GtkWidget *widget); -static void glade_palette_expander_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data); -static void button_clicked (GtkButton *button, - GladePaletteExpander *expander); - - -static gboolean button_drag_motion (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time, - GladePaletteExpander *expander); - -static void button_drag_leave (GtkWidget *widget, - GdkDragContext *context, - guint time, - GladePaletteExpander *expander); - -static void glade_palette_expander_activate (GladePaletteExpander *expander); -void glade_palette_expander_set_expanded (GladePaletteExpander *expander, - gboolean expanded); -gboolean glade_palette_expander_get_expanded (GladePaletteExpander *expander); -void glade_palette_expander_set_label (GladePaletteExpander *expander, - const gchar *label); -const gchar *glade_palette_expander_get_label (GladePaletteExpander *expander); -void glade_palette_expander_set_spacing (GladePaletteExpander *expander, - guint spacing); -guint glade_palette_expander_get_spacing (GladePaletteExpander *expander); - - -G_DEFINE_TYPE (GladePaletteExpander, glade_palette_expander, GTK_TYPE_BIN); - -static void -glade_palette_expander_class_init (GladePaletteExpanderClass *klass) -{ - GObjectClass *object_class; - GtkWidgetClass *widget_class; - GtkContainerClass *container_class; - - object_class = G_OBJECT_CLASS (klass); - widget_class = GTK_WIDGET_CLASS (klass); - container_class = GTK_CONTAINER_CLASS (klass); - - object_class->set_property = glade_palette_expander_set_property; - object_class->get_property = glade_palette_expander_get_property; - - container_class->add = glade_palette_expander_add; - container_class->remove = glade_palette_expander_remove; - container_class->forall = glade_palette_expander_forall; - - widget_class->size_request = glade_palette_expander_size_request; - widget_class->size_allocate = glade_palette_expander_size_allocate; - widget_class->map = glade_palette_expander_map; - widget_class->unmap = glade_palette_expander_unmap; - - klass->activate = glade_palette_expander_activate; - - g_object_class_install_property (object_class, - PROP_EXPANDED, - g_param_spec_boolean ("expanded", - "Expanded", - "Whether the expander has been opened to " - "reveal the child widget", - FALSE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); - - g_object_class_install_property (object_class, - PROP_LABEL, - g_param_spec_string ("label", - "Label", - "Text of the expander's label", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); - - g_object_class_install_property (object_class, - PROP_SPACING, - g_param_spec_uint ("spacing", - "Spacing", - "Space to put between the expander and the child widget", - 0, - G_MAXUINT, - 0, - G_PARAM_READWRITE)); - - g_object_class_install_property (object_class, - PROP_USE_MARKUP, - g_param_spec_boolean ("use-markup", - "Use Markup", - "The text of the label includes Pango XML markup" - "reveal the child widget", - FALSE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); - - widget_class->activate_signal = - g_signal_new ("activate", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (GladePaletteExpanderClass, activate), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - g_type_class_add_private (klass, sizeof (GladePaletteExpanderPrivate)); -} - -static void -glade_palette_expander_init (GladePaletteExpander *expander) -{ - GladePaletteExpanderPrivate *priv; - GtkWidget *hbox; - GtkWidget *alignment; - - expander->priv = priv = GLADE_PALETTE_EXPANDER_GET_PRIVATE (expander); - - GTK_WIDGET_SET_FLAGS (expander, GTK_NO_WINDOW); - - priv->spacing = 0; - priv->expanded = FALSE; - priv->use_markup = FALSE; - priv->button_down = FALSE; - - gtk_widget_push_composite_child (); - - priv->button = gtk_button_new (); - gtk_button_set_focus_on_click (GTK_BUTTON (priv->button), FALSE); - priv->arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_NONE); - priv->label = gtk_label_new (NULL); - gtk_misc_set_alignment (GTK_MISC (priv->label), 0.0, 0.5); - - alignment = gtk_alignment_new (0.0, 0.5, 1, 1); - - hbox = gtk_hbox_new (FALSE, 3); - - gtk_container_add (GTK_CONTAINER (alignment), hbox); - gtk_container_add (GTK_CONTAINER (priv->button), alignment); - gtk_box_pack_start (GTK_BOX (hbox), priv->arrow, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (hbox), priv->label, FALSE, FALSE, 0); - - gtk_widget_set_parent (priv->button, GTK_WIDGET (expander)); - - gtk_widget_pop_composite_child (); - - g_signal_connect (priv->button, "clicked", - G_CALLBACK (button_clicked), - expander); - - g_signal_connect (priv->button, "drag-motion", - G_CALLBACK (button_drag_motion), - expander); - - g_signal_connect (priv->button, "drag-leave", - G_CALLBACK (button_drag_leave), - expander); - - gtk_widget_show_all (priv->button); - - gtk_drag_dest_set (GTK_WIDGET (priv->button), 0, NULL, 0, 0); - gtk_drag_dest_set_track_motion (GTK_WIDGET (priv->button), TRUE); -} - -static void -glade_palette_expander_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - GladePaletteExpander *expander = GLADE_PALETTE_EXPANDER (object); - - switch (prop_id) - { - case PROP_EXPANDED: - glade_palette_expander_set_expanded (expander, g_value_get_boolean (value)); - break; - case PROP_LABEL: - glade_palette_expander_set_label (expander, g_value_get_string (value)); - break; - case PROP_SPACING: - glade_palette_expander_set_spacing (expander, g_value_get_int (value)); - break; - case PROP_USE_MARKUP: - glade_palette_expander_set_use_markup (expander, g_value_get_boolean (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -glade_palette_expander_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - GladePaletteExpander *expander = GLADE_PALETTE_EXPANDER (object); - - switch (prop_id) - { - case PROP_EXPANDED: - g_value_set_boolean (value, glade_palette_expander_get_expanded (expander)); - break; - case PROP_LABEL: - g_value_set_string (value, glade_palette_expander_get_label (expander)); - break; - case PROP_SPACING: - g_value_set_int (value, glade_palette_expander_get_spacing (expander)); - break; - case PROP_USE_MARKUP: - g_value_set_boolean (value, glade_palette_expander_get_use_markup (expander)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -glade_palette_expander_size_request (GtkWidget *widget, - GtkRequisition *requisition) -{ - GladePaletteExpanderPrivate *priv; - GladePaletteExpander *expander; - GtkBin *bin; - gint border_width; - - bin = GTK_BIN (widget); - expander = GLADE_PALETTE_EXPANDER (widget); - priv = expander->priv; - - border_width = GTK_CONTAINER (widget)->border_width; - - requisition->width = 0; - requisition->height = 0; - - - if (GTK_WIDGET_VISIBLE (priv->button)) - { - GtkRequisition button_requisition; - - gtk_widget_size_request (priv->button, &button_requisition); - - requisition->width += button_requisition.width; - requisition->height += button_requisition.height; - } - - if (bin->child && gtk_widget_get_child_visible (bin->child)) - { - GtkRequisition child_requisition; - - gtk_widget_size_request (bin->child, &child_requisition); - - requisition->width = MAX (requisition->width, child_requisition.width); - requisition->height += child_requisition.height + priv->spacing; - } - - requisition->width += 2 * border_width; - requisition->height += 2 * border_width; -} - -static void -glade_palette_expander_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) -{ - GladePaletteExpanderPrivate *priv; - GladePaletteExpander *expander; - GtkBin *bin; - GtkRequisition child_requisition; - gboolean child_visible = FALSE; - gint border_width; - gint button_height; - - expander = GLADE_PALETTE_EXPANDER (widget); - bin = GTK_BIN (widget); - priv = expander->priv; - - border_width = GTK_CONTAINER (widget)->border_width; - - child_requisition.width = 0; - child_requisition.height = 0; - - if (bin->child && gtk_widget_get_child_visible (bin->child)) - { - child_visible = TRUE; - gtk_widget_get_child_requisition (bin->child, &child_requisition); - } - - widget->allocation = *allocation; - - if (GTK_WIDGET_VISIBLE (priv->button)) - { - GtkAllocation button_allocation; - GtkRequisition button_requisition; - - gtk_widget_get_child_requisition (priv->button, &button_requisition); - - button_allocation.x = widget->allocation.x + border_width; - button_allocation.y = widget->allocation.y + border_width; - - button_allocation.width = MAX (allocation->width - 2 * border_width, 1); - - button_allocation.height = MIN (button_requisition.height, - allocation->height - 2 * border_width - - (child_visible ? priv->spacing : 0)); - - button_allocation.height = MAX (button_allocation.height, 1); - - gtk_widget_size_allocate (priv->button, &button_allocation); - - button_height = button_allocation.height; - } - else - { - button_height = 0; - } - - if (child_visible) - { - GtkAllocation child_allocation; - - child_allocation.x = widget->allocation.x + border_width; - child_allocation.y = widget->allocation.y + border_width + button_height + priv->spacing; - - child_allocation.width = MAX (allocation->width - 2 * border_width, 1); - - child_allocation.height = allocation->height - button_height - - 2 * border_width - priv->spacing; - child_allocation.height = MAX (child_allocation.height, 1); - - gtk_widget_size_allocate (bin->child, &child_allocation); - } -} - -static void -glade_palette_expander_map (GtkWidget *widget) -{ - GladePaletteExpanderPrivate *priv = GLADE_PALETTE_EXPANDER (widget)->priv; - - gtk_widget_map (priv->button); - - GTK_WIDGET_CLASS (glade_palette_expander_parent_class)->map (widget); -} - -static void -glade_palette_expander_unmap (GtkWidget *widget) -{ - GladePaletteExpanderPrivate *priv = GLADE_PALETTE_EXPANDER (widget)->priv; - - GTK_WIDGET_CLASS (glade_palette_expander_parent_class)->unmap (widget); - - gtk_widget_unmap (priv->button); -} - -static void -glade_palette_expander_add (GtkContainer *container, - GtkWidget *widget) -{ - GTK_CONTAINER_CLASS (glade_palette_expander_parent_class)->add (container, widget); - - gtk_widget_set_child_visible (widget, GLADE_PALETTE_EXPANDER (container)->priv->expanded); - gtk_widget_queue_resize (GTK_WIDGET (container)); -} - -static void -glade_palette_expander_remove (GtkContainer *container, - GtkWidget *widget) -{ - GladePaletteExpander *expander = GLADE_PALETTE_EXPANDER (container); - - if (expander->priv->button == widget) - { - gtk_widget_unparent (expander->priv->button); - expander->priv->button = NULL; - - if (GTK_WIDGET_VISIBLE (expander)) - gtk_widget_queue_resize (GTK_WIDGET (expander)); - - g_object_notify (G_OBJECT (expander), "label"); - } - else - { - GTK_CONTAINER_CLASS (glade_palette_expander_parent_class)->remove (container, widget); - } - -} - -static void -glade_palette_expander_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data) -{ - GtkBin *bin = GTK_BIN (container); - GladePaletteExpanderPrivate *priv = GLADE_PALETTE_EXPANDER_GET_PRIVATE (container); - - if (bin->child) - (* callback) (bin->child, callback_data); - - if (priv->button) - (* callback) (priv->button, callback_data); -} - -static gboolean -expand_timeout (gpointer data) -{ - GladePaletteExpander *expander = (GladePaletteExpander *) (data); - GladePaletteExpanderPrivate *priv = expander->priv; - - GDK_THREADS_ENTER (); - - priv->expand_timer_handle = 0; - glade_palette_expander_set_expanded (expander, TRUE); - - GDK_THREADS_LEAVE (); - - return FALSE; -} - -static gboolean -button_drag_motion (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time, - GladePaletteExpander *expander) -{ - GladePaletteExpanderPrivate *priv = expander->priv; - - if (!priv->expanded && !priv->expand_timer_handle) - { - GtkSettings *settings; - guint timeout; - - settings = gtk_widget_get_settings (widget); - g_object_get (settings, "gtk-timeout-expand", &timeout, NULL); - - priv->expand_timer_handle = g_timeout_add (timeout, - (GSourceFunc) expand_timeout, - expander); - } - - return TRUE; -} - -static void -button_drag_leave (GtkWidget *widget, - GdkDragContext *context, - guint time, - GladePaletteExpander *expander) -{ - GladePaletteExpanderPrivate *priv = expander->priv; - - if (priv->expand_timer_handle) - { - g_source_remove (priv->expand_timer_handle); - priv->expand_timer_handle = 0; - } -} - -static void -button_clicked (GtkButton *button, - GladePaletteExpander *expander) -{ - gtk_widget_activate (GTK_WIDGET (expander)); -} - -static void -glade_palette_expander_activate (GladePaletteExpander *expander) -{ - glade_palette_expander_set_expanded (expander, !expander->priv->expanded); -} - -void -glade_palette_expander_set_expanded (GladePaletteExpander *expander, gboolean expanded) -{ - GladePaletteExpanderPrivate *priv; - - g_return_if_fail (GLADE_IS_PALETTE_EXPANDER (expander)); - - priv = expander->priv; - - expanded = expanded != FALSE; - - if (priv->expanded != expanded) - { - priv->expanded = expanded; - - if (GTK_BIN (expander)->child) - { - gtk_widget_set_child_visible (GTK_BIN (expander)->child, priv->expanded); - gtk_widget_queue_resize (GTK_WIDGET (expander)); - } - - gtk_arrow_set (GTK_ARROW (priv->arrow), - priv->expanded ? GTK_ARROW_DOWN : GTK_ARROW_RIGHT, - GTK_SHADOW_NONE); - - g_object_notify (G_OBJECT (expander), "expanded"); - } -} - -gboolean -glade_palette_expander_get_expanded (GladePaletteExpander *expander) -{ - g_return_val_if_fail (GLADE_IS_PALETTE_EXPANDER (expander), FALSE); - - return expander->priv->expanded; -} - -void -glade_palette_expander_set_label (GladePaletteExpander *expander, const gchar *label) -{ - GladePaletteExpanderPrivate *priv; - g_return_if_fail (GLADE_IS_PALETTE_EXPANDER (expander)); - - priv = GLADE_PALETTE_EXPANDER_GET_PRIVATE (expander); - - gtk_label_set_label (GTK_LABEL (priv->label), label); - g_object_notify (G_OBJECT (expander), "label"); -} - -const gchar * -glade_palette_expander_get_label (GladePaletteExpander *expander) -{ - g_return_val_if_fail (GLADE_IS_PALETTE_EXPANDER (expander), NULL); - - return gtk_label_get_label (GTK_LABEL (expander->priv->label)); -} - -void -glade_palette_expander_set_spacing (GladePaletteExpander *expander, - guint spacing) -{ - g_return_if_fail (GLADE_IS_PALETTE_EXPANDER (expander)); - - if (expander->priv->spacing != spacing) - { - expander->priv->spacing = spacing; - - gtk_widget_queue_resize (GTK_WIDGET (expander)); - - g_object_notify (G_OBJECT (expander), "spacing"); - } -} - -guint -glade_palette_expander_get_spacing (GladePaletteExpander *expander) -{ - g_return_val_if_fail (GLADE_IS_PALETTE_EXPANDER (expander), 0); - - return expander->priv->spacing; -} - -void -glade_palette_expander_set_use_markup (GladePaletteExpander *expander, - gboolean use_markup) -{ - GladePaletteExpanderPrivate *priv; - - g_return_if_fail (GLADE_IS_PALETTE_EXPANDER (expander)); - - priv = expander->priv; - - use_markup = use_markup != FALSE; - - if (priv->use_markup != use_markup) - { - priv->use_markup = use_markup; - - gtk_label_set_use_markup (GTK_LABEL (priv->label), use_markup); - - g_object_notify (G_OBJECT (expander), "use-markup"); - } -} - -gboolean -glade_palette_expander_get_use_markup (GladePaletteExpander *expander) -{ - g_return_val_if_fail (GLADE_IS_PALETTE_EXPANDER (expander), FALSE); - - return expander->priv->use_markup; -} - -GtkWidget * -glade_palette_expander_new (const gchar *label) -{ - return g_object_new (GLADE_TYPE_PALETTE_EXPANDER, - "label", label, - NULL); -} - diff --git a/gladeui/glade-palette-expander.h b/gladeui/glade-palette-expander.h deleted file mode 100644 index f080b4c7..00000000 --- a/gladeui/glade-palette-expander.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * glade-palette-expander.h - A container which can hide its child - * - * Copyright (C) 2007 Vincent Geddes - * - * Author: Vincent Geddes <vincent.geddes@gmail.com> - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#ifndef __GLADE_PALETTE_EXPANDER_H__ -#define __GLADE_PALETTE_EXPANDER_H__ - -#include <gtk/gtkbin.h> - -G_BEGIN_DECLS - -#define GLADE_TYPE_PALETTE_EXPANDER (glade_palette_expander_get_type ()) -#define GLADE_PALETTE_EXPANDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_PALETTE_EXPANDER, GladePaletteExpander)) -#define GLADE_PALETTE_EXPANDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_PALETTE_EXPANDER, GladePaletteExpanderClass)) -#define GLADE_IS_PALETTE_EXPANDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_PALETTE_EXPANDER)) -#define GLADE_IS_PALETTE_EXPANDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_PALETTE_EXPANDER)) -#define GLADE_PALETTE_EXPANDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GLADE_TYPE_PALETTE_EXPANDER, GladePaletteExpanderClass)) - -typedef struct _GladePaletteExpander GladePaletteExpander; -typedef struct _GladePaletteExpanderPrivate GladePaletteExpanderPrivate; -typedef struct _GladePaletteExpanderClass GladePaletteExpanderClass; - -struct _GladePaletteExpander -{ - GtkBin parent_instance; - - GladePaletteExpanderPrivate *priv; -}; - -struct _GladePaletteExpanderClass -{ - GtkBinClass parent_class; - - void (* activate) (GladePaletteExpander *expander); -}; - - -GType glade_palette_expander_get_type (void) G_GNUC_CONST; - -GtkWidget *glade_palette_expander_new (const gchar *label); - -void glade_palette_expander_set_expanded (GladePaletteExpander *expander, - gboolean expanded); - -gboolean glade_palette_expander_get_expanded (GladePaletteExpander *expander); - -void glade_palette_expander_set_spacing (GladePaletteExpander *expander, - guint spacing); - -guint glade_palette_expander_get_spacing (GladePaletteExpander *expander); - -void glade_palette_expander_set_label (GladePaletteExpander *expander, - const gchar *label); - -const gchar *glade_palette_expander_get_label (GladePaletteExpander *expander); - -void glade_palette_expander_set_use_markup (GladePaletteExpander *expander, - gboolean use_markup); - -gboolean glade_palette_expander_get_use_markup (GladePaletteExpander *expander); - - -G_END_DECLS - -#endif /* __GLADE_PALETTE_EXPANDER_H__ */ diff --git a/gladeui/glade-palette-item.c b/gladeui/glade-palette-item.c deleted file mode 100644 index 420f1697..00000000 --- a/gladeui/glade-palette-item.c +++ /dev/null @@ -1,399 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * glade-palette-item.c - * - * Copyright (C) 2007 Vincent Geddes - * - * Authors: Vincent Geddes <vgeddes@metroweb.co.za> - * - * 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. - * - */ - -#include "config.h" - -#include <gtk/gtkalignment.h> -#include <gtk/gtkhbox.h> -#include <gtk/gtklabel.h> -#include <gtk/gtkimage.h> - -#include "glade.h" -#include "glade-palette-item.h" - -#define GLADE_PALETTE_ITEM_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object),\ - GLADE_TYPE_PALETTE_ITEM, \ - GladePaletteItemPrivate)) - - -struct _GladePaletteItemPrivate -{ - GtkWidget *alignment; /* The contents of the button */ - GtkWidget *hbox; - GtkWidget *icon; - GtkWidget *label; - - GladeItemAppearance appearance; /* The appearance of the button */ - - gboolean use_small_icon; - - GladeWidgetAdaptor *adaptor; /* The widget class adaptor associated - * with this item - */ -}; - -enum -{ - PROP_0, - PROP_ADAPTOR, - PROP_APPEARANCE, - PROP_USE_SMALL_ICON -}; - - -G_DEFINE_TYPE(GladePaletteItem, glade_palette_item, GTK_TYPE_TOGGLE_BUTTON) - -static void -glade_palette_item_update_appearance (GladePaletteItem *item) -{ - GladePaletteItemPrivate *priv; - GtkWidget *child; - GList *l; - - g_return_if_fail (GLADE_IS_PALETTE_ITEM (item)); - priv = GLADE_PALETTE_ITEM_GET_PRIVATE (item); - - child = gtk_bin_get_child (GTK_BIN (item)); - - if (GTK_IS_WIDGET (child)) - gtk_container_remove (GTK_CONTAINER (item), child); - - for (l = gtk_container_get_children (GTK_CONTAINER (priv->hbox)); l; l=l->next) - gtk_container_remove (GTK_CONTAINER (priv->hbox), GTK_WIDGET (l->data)); - - if (priv->appearance == GLADE_ITEM_ICON_AND_LABEL) - { - gtk_box_pack_start (GTK_BOX (priv->hbox), priv->icon, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (priv->hbox), priv->label, FALSE, FALSE, 0); - gtk_container_add (GTK_CONTAINER (item), priv->alignment); - } - else if (priv->appearance == GLADE_ITEM_ICON_ONLY) - { - - gtk_container_add (GTK_CONTAINER (item), priv->icon); - gtk_misc_set_alignment (GTK_MISC (priv->icon), 0.5, 0.5); - - } - else if (priv->appearance == GLADE_ITEM_LABEL_ONLY) - { - gtk_container_add (GTK_CONTAINER (item), priv->label); - gtk_misc_set_alignment (GTK_MISC (priv->label), 0.0, 0.5); - } - else - g_return_if_reached (); -} - - -/** - * glade_palette_item_set_appearance: - * @palette: A #GladePaletteItem. - * @appearance: The appearance of the item. - * - * Sets the appearance of the item. - */ -void -glade_palette_item_set_appearance (GladePaletteItem *item, GladeItemAppearance appearance) -{ - GladePaletteItemPrivate *priv; - g_return_if_fail (GLADE_IS_PALETTE_ITEM (item)); - priv = GLADE_PALETTE_ITEM_GET_PRIVATE (item); - - - if (priv->appearance != appearance) - { - priv->appearance = appearance; - - glade_palette_item_update_appearance (item); - - g_object_notify (G_OBJECT (item), "appearance"); - } -} - -void -glade_palette_item_set_use_small_icon (GladePaletteItem *item, gboolean use_small_icon) -{ - GladePaletteItemPrivate *priv; - - g_return_if_fail (GLADE_IS_PALETTE_ITEM (item)); - priv = GLADE_PALETTE_ITEM_GET_PRIVATE (item); - - if (priv->use_small_icon != use_small_icon) - { - priv->use_small_icon = use_small_icon; - - if (use_small_icon != FALSE) - gtk_image_set_from_icon_name (GTK_IMAGE (priv->icon), priv->adaptor->icon_name, GTK_ICON_SIZE_MENU); - else - gtk_image_set_from_icon_name (GTK_IMAGE (priv->icon), priv->adaptor->icon_name, GTK_ICON_SIZE_BUTTON); - - g_object_notify (G_OBJECT (item), "use-small-icon"); - } -} - -static void -glade_palette_set_adaptor (GladePaletteItem *item, GladeWidgetAdaptor *adaptor) -{ - GladePaletteItemPrivate *priv; - - priv = GLADE_PALETTE_ITEM_GET_PRIVATE (item); - - priv->adaptor = adaptor; - - gtk_label_set_text (GTK_LABEL (priv->label), adaptor->title); - - gtk_image_set_from_icon_name (GTK_IMAGE (priv->icon), adaptor->icon_name, GTK_ICON_SIZE_BUTTON); -} - -static void -glade_palette_item_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - GladePaletteItem *item; - GladePaletteItemPrivate *priv; - - item = GLADE_PALETTE_ITEM (object); - - g_return_if_fail (GLADE_IS_PALETTE_ITEM (item)); - - priv = GLADE_PALETTE_ITEM_GET_PRIVATE (item); - - switch (prop_id) - { - case PROP_ADAPTOR: - glade_palette_set_adaptor (item, g_value_get_object (value)); - break; - case PROP_APPEARANCE: - glade_palette_item_set_appearance (item, g_value_get_enum (value)); - break; - case PROP_USE_SMALL_ICON: - glade_palette_item_set_use_small_icon (item, g_value_get_boolean (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -glade_palette_item_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - GladePaletteItem *item = GLADE_PALETTE_ITEM (object); - GladePaletteItemPrivate *priv = GLADE_PALETTE_ITEM_GET_PRIVATE (item); - - switch (prop_id) - { - case PROP_ADAPTOR: - g_value_set_pointer (value, (gpointer) priv->adaptor); - break; - case PROP_APPEARANCE: - g_value_set_enum (value, priv->appearance); - break; - case PROP_USE_SMALL_ICON: - g_value_set_boolean (value, priv->use_small_icon); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -glade_palette_item_dispose (GObject *object) -{ - GladePaletteItem *item; - GladePaletteItemPrivate *priv; - - item = GLADE_PALETTE_ITEM (object); - priv = GLADE_PALETTE_ITEM_GET_PRIVATE (item); -/* - if (priv->alignment) - { - g_object_unref (priv->alignment); - priv->alignment = NULL; - } - if (priv->hbox) - { - g_object_unref (priv->hbox); - priv->hbox = NULL; - } - if (priv->icon) - { - g_object_unref (priv->icon); - priv->icon = NULL; - } - if (priv->label) - { - g_object_unref (priv->label); - priv->label = NULL; - } -*/ - G_OBJECT_CLASS (glade_palette_item_parent_class)->dispose (object); -} - -static void -glade_palette_item_class_init (GladePaletteItemClass *klass) -{ - GObjectClass *object_class; - - object_class = G_OBJECT_CLASS (klass); - - object_class->get_property = glade_palette_item_get_property; - object_class->set_property = glade_palette_item_set_property; - object_class->dispose = glade_palette_item_dispose; - - g_object_class_install_property (object_class, - PROP_ADAPTOR, - g_param_spec_object ("adaptor", - "Adaptor", - "The widget adaptor associated with this item", - GLADE_TYPE_WIDGET_ADAPTOR, - G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE )); - - g_object_class_install_property (object_class, - PROP_APPEARANCE, - g_param_spec_enum ("appearance", - "Appearance", - "The appearance of the item", - GLADE_TYPE_ITEM_APPEARANCE, - GLADE_ITEM_ICON_ONLY, - G_PARAM_READWRITE)); - - g_object_class_install_property (object_class, - PROP_APPEARANCE, - g_param_spec_boolean ("use-small-icon", - "Use Small Icon", - "Whether to use small icon", - FALSE, - G_PARAM_READWRITE)); - - g_type_class_add_private (klass, sizeof (GladePaletteItemPrivate)); -} - - -static void -glade_palette_item_init (GladePaletteItem *item) -{ - GladePaletteItemPrivate *priv; - - priv = item->priv = GLADE_PALETTE_ITEM_GET_PRIVATE (item); - - priv->label = NULL; - priv->adaptor = NULL; - priv->use_small_icon = FALSE; - priv->appearance = 0; - - priv->alignment = gtk_alignment_new (0.0, 0.5, 0.5, 0.5); - g_object_ref_sink (priv->alignment); - gtk_widget_show (GTK_WIDGET (priv->alignment)); - - priv->hbox = gtk_hbox_new (FALSE, 6); - g_object_ref_sink (priv->hbox); - gtk_widget_show (GTK_WIDGET (priv->hbox)); - - priv->icon = gtk_image_new (); - g_object_ref_sink (priv->icon); - gtk_widget_show (GTK_WIDGET (priv->icon)); - - priv->label = gtk_label_new (NULL); - g_object_ref_sink (priv->label); - gtk_widget_show (GTK_WIDGET (priv->label)); - - gtk_container_add (GTK_CONTAINER (priv->alignment), priv->hbox); - - gtk_button_set_relief (GTK_BUTTON (item), GTK_RELIEF_NONE); - gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (item), FALSE); -} - -/** - * glade_palette_item_new: - * @adaptor: A #GladeWidgetAdaptor - * @group: The group to add this item to. - * @appearance: The appearance of the item - * - * Returns: A #GtkWidget - */ -GtkWidget* -glade_palette_item_new (GladeWidgetAdaptor *adaptor) -{ - GladePaletteItem *item; - - g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL); - - item = g_object_new (GLADE_TYPE_PALETTE_ITEM, - "adaptor", adaptor, - "appearance", GLADE_ITEM_ICON_ONLY, - NULL); - - return GTK_WIDGET (item); -} - -/** - * glade_palette_item_get_appearance: - * @palette: A #GladePaletteItem - * - * Returns: the appearance of the item. - */ -GladeItemAppearance -glade_palette_item_get_appearance (GladePaletteItem *item) -{ - GladePaletteItemPrivate *priv; - - g_return_val_if_fail (GLADE_IS_PALETTE_ITEM (item), FALSE); - priv = GLADE_PALETTE_ITEM_GET_PRIVATE (item); - - return priv->appearance; -} - -gboolean -glade_palette_item_get_use_small_icon (GladePaletteItem *item) -{ - GladePaletteItemPrivate *priv; - - g_return_val_if_fail (GLADE_IS_PALETTE_ITEM (item), FALSE); - priv = GLADE_PALETTE_ITEM_GET_PRIVATE (item); - - return priv->use_small_icon; -} - -/** - * glade_palette_item_get_adaptor: - * @palette: A #GladePaletteItem - * - * Returns: the #GladeWidgetClass associated with this item. - */ -GladeWidgetAdaptor * -glade_palette_item_get_adaptor (GladePaletteItem *item) -{ - GladePaletteItemPrivate *priv; - g_return_val_if_fail (GLADE_IS_PALETTE_ITEM (item), NULL); - priv = GLADE_PALETTE_ITEM_GET_PRIVATE (item); - - return priv->adaptor; -} diff --git a/gladeui/glade-palette-item.h b/gladeui/glade-palette-item.h deleted file mode 100644 index 208f3746..00000000 --- a/gladeui/glade-palette-item.h +++ /dev/null @@ -1,84 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * glade-palette-item.h - * - * Copyright (C) 2006 Vincent Geddes - * - * Authors: - * Vincent Geddes <vgeddes@gnome.org> - * - * 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. - * - */ - -#ifndef __GLADE_PALETTE_ITEM_H__ -#define __GLADE_PALETTE_ITEM_H__ - -#include <gladeui/glade.h> -#include <gladeui/glade-palette.h> -#include <gladeui/glade-widget-adaptor.h> - -#include <gtk/gtktogglebutton.h> - -G_BEGIN_DECLS - -#define GLADE_TYPE_PALETTE_ITEM (glade_palette_item_get_type ()) -#define GLADE_PALETTE_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_PALETTE_ITEM, GladePaletteItem)) -#define GLADE_PALETTE_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_PALETTE_ITEM, GladePaletteItemClass)) -#define GLADE_IS_PALETTE_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_PALETTE_ITEM)) -#define GLADE_IS_PALETTE_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_PALETTE_ITEM)) -#define GLADE_PALETTE_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GLADE_TYPE_PALETTE_ITEM, GladePaletteItemClass)) - - -typedef struct _GladePaletteItem GladePaletteItem; -typedef struct _GladePaletteItemPrivate GladePaletteItemPrivate; -typedef struct _GladePaletteItemClass GladePaletteItemClass; - -struct _GladePaletteItem -{ - GtkToggleButton parent_instance; - - GladePaletteItemPrivate *priv; - -}; - -struct _GladePaletteItemClass -{ - GtkToggleButtonClass parent_class; - - -}; - -GType glade_palette_item_get_type (void) G_GNUC_CONST; - -GtkWidget *glade_palette_item_new (GladeWidgetAdaptor *adaptor); - -GladeWidgetAdaptor *glade_palette_item_get_adaptor (GladePaletteItem *item); - -GladeItemAppearance glade_palette_item_get_appearance (GladePaletteItem *item); - -void glade_palette_item_set_appearance (GladePaletteItem *item, - GladeItemAppearance appearance); - -gboolean glade_palette_item_get_use_small_icon (GladePaletteItem *item); - -void glade_palette_item_set_use_small_icon (GladePaletteItem *item, - gboolean use_small_icon); - - -G_END_DECLS - -#endif /* __GLADE_PALETTE_ITEM_H__ */ diff --git a/gladeui/glade-palette.c b/gladeui/glade-palette.c deleted file mode 100644 index 05207488..00000000 --- a/gladeui/glade-palette.c +++ /dev/null @@ -1,783 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * glade-palette.c - * - * Copyright (C) 2006 The GNOME Foundation. - * Copyright (C) 2001-2005 Ximian, Inc. - * - * Authors: - * Chema Celorio - * Joaquin Cuenca Abela <e98cuenc@yahoo.com> - * Vincent Geddes <vgeddes@metroweb.co.za> - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "glade.h" -#include "glade-app.h" -#include "glade-palette.h" -#include "glade-palette-item.h" -#include "glade-palette-box.h" -#include "glade-palette-expander.h" -#include "glade-catalog.h" -#include "glade-project.h" -#include "glade-widget.h" -#include "glade-widget-adaptor.h" - -#include <glib/gi18n-lib.h> -#include <gdk/gdk.h> - -#define GLADE_PALETTE_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object),\ - GLADE_TYPE_PALETTE, \ - GladePalettePrivate)) - -struct _GladePalettePrivate -{ - const GList *catalogs; /* List of widget catalogs */ - - GtkWidget *selector_hbox; - GtkWidget *selector_button; - - GtkWidget *tray; /* Where all the item groups are contained */ - - GladePaletteItem *current_item; /* The currently selected item */ - - GSList *sections; /* List of GladePaletteExpanders */ - - GtkTooltips *tooltips; /* Tooltips for the item buttons */ - GtkTooltips *static_tooltips; /* These tooltips never get disabled */ - - GtkSizeGroup *size_group; /* All items have the same dimensions */ - - GladeItemAppearance item_appearance; - - gboolean use_small_item_icons; - - gboolean sticky_selection_mode; /* whether sticky_selection mode has been enabled */ -}; - -enum -{ - TOGGLED, - LAST_SIGNAL -}; - -enum -{ - PROP_0, - PROP_CURRENT_ITEM, - PROP_ITEM_APPEARANCE, - PROP_USE_SMALL_ITEM_ICONS, - PROP_SHOW_SELECTOR_BUTTON, - PROP_CATALOGS -}; - -static guint glade_palette_signals[LAST_SIGNAL] = {0}; - -static void glade_palette_append_item_group (GladePalette *palette, GladeWidgetGroup *group); - -static void glade_palette_update_appearance (GladePalette *palette); - -G_DEFINE_TYPE (GladePalette, glade_palette, GTK_TYPE_VBOX) - - -static void -selector_button_toggled_cb (GtkToggleButton *button, GladePalette *palette) -{ - if (gtk_toggle_button_get_active (button)) - { - glade_palette_deselect_current_item (palette, FALSE); - } - else if (glade_palette_get_current_item (palette) == FALSE) - { - gtk_toggle_button_set_active (button, TRUE); - } -} - -static void -glade_palette_set_catalogs (GladePalette *palette, GList *catalogs) -{ - GladePalettePrivate *priv; - GList *l; - - g_return_if_fail (GLADE_IS_PALETTE (palette)); - priv = GLADE_PALETTE_GET_PRIVATE (palette); - - priv->catalogs = catalogs; - - for (l = (GList *) priv->catalogs; l; l = l->next) - { - GList *groups = glade_catalog_get_widget_groups (GLADE_CATALOG (l->data)); - - for (; groups; groups = groups->next) - { - GladeWidgetGroup *group = GLADE_WIDGET_GROUP (groups->data); - - if (glade_widget_group_get_adaptors (group)) - glade_palette_append_item_group (palette, group); - } - } - - gtk_widget_show_all (priv->tray); - - g_object_unref (priv->size_group); -} - -/** - * glade_palette_set_item_appearance: - * @palette: a #GladePalette - * @item_appearance: the item appearance - * - * Sets the appearance of the palette items. - */ -void -glade_palette_set_item_appearance (GladePalette *palette, GladeItemAppearance item_appearance) -{ - GladePalettePrivate *priv; - g_return_if_fail (GLADE_IS_PALETTE (palette)); - priv = GLADE_PALETTE_GET_PRIVATE (palette); - - if (priv->item_appearance != item_appearance) - { - priv->item_appearance = item_appearance; - - glade_palette_update_appearance (palette); - - g_object_notify (G_OBJECT (palette), "item-appearance"); - } -} - -/** - * glade_palette_set_use_small_item_icons: - * @palette: a #GladePalette - * @use_small_item_icons: Whether to use small item icons - * - * Sets whether to use small item icons. - */ -void -glade_palette_set_use_small_item_icons (GladePalette *palette, gboolean use_small_item_icons) -{ - GladePalettePrivate *priv; - g_return_if_fail (GLADE_IS_PALETTE (palette)); - priv = GLADE_PALETTE_GET_PRIVATE (palette); - - if (priv->use_small_item_icons != use_small_item_icons) - { - priv->use_small_item_icons = use_small_item_icons; - - glade_palette_update_appearance (palette); - - g_object_notify (G_OBJECT (palette), "use-small-item-icons"); - - } - -} - -/** - * glade_palette_set_show_selector_button: - * @palette: a #GladePalette - * @show_selector_button: whether to show selector button - * - * Sets whether to show the internal widget selector button - */ -void -glade_palette_set_show_selector_button (GladePalette *palette, gboolean show_selector_button) -{ - GladePalettePrivate *priv; - g_return_if_fail (GLADE_IS_PALETTE (palette)); - priv = GLADE_PALETTE_GET_PRIVATE (palette); - - if (GTK_WIDGET_VISIBLE (priv->selector_hbox) != show_selector_button) - { - if (show_selector_button) - gtk_widget_show (priv->selector_hbox); - else - gtk_widget_hide (priv->selector_hbox); - - g_object_notify (G_OBJECT (palette), "show-selector-button"); - - } - -} - -/* override GtkWidget::show_all since we have internal widgets we wish to keep - * hidden unless we decide otherwise, like the hidden selector button. - */ -static void -glade_palette_show_all (GtkWidget *widget) -{ - gtk_widget_show (widget); -} - -static void -glade_palette_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - GladePalette *palette = GLADE_PALETTE (object); - - switch (prop_id) - { - case PROP_USE_SMALL_ITEM_ICONS: - glade_palette_set_use_small_item_icons (palette, g_value_get_boolean (value)); - break; - case PROP_ITEM_APPEARANCE: - glade_palette_set_item_appearance (palette, g_value_get_enum (value)); - break; - case PROP_SHOW_SELECTOR_BUTTON: - glade_palette_set_show_selector_button (palette, g_value_get_boolean (value)); - break; - case PROP_CATALOGS: - glade_palette_set_catalogs (palette, g_value_get_pointer (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -glade_palette_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - GladePalette *palette = GLADE_PALETTE (object); - GladePalettePrivate *priv = GLADE_PALETTE_GET_PRIVATE (palette); - - switch (prop_id) - { - case PROP_CURRENT_ITEM: - g_value_set_pointer (value, (gpointer) glade_palette_item_get_adaptor (priv->current_item)); - break; - case PROP_USE_SMALL_ITEM_ICONS: - g_value_set_boolean (value, priv->use_small_item_icons); - break; - case PROP_SHOW_SELECTOR_BUTTON: - g_value_set_boolean (value, GTK_WIDGET_VISIBLE (priv->selector_button)); - break; - case PROP_ITEM_APPEARANCE: - g_value_set_enum (value, priv->item_appearance); - break; - case PROP_CATALOGS: - g_value_set_pointer (value, (gpointer) priv->catalogs); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -glade_palette_dispose (GObject *object) -{ - GladePalettePrivate *priv; - - priv = GLADE_PALETTE_GET_PRIVATE (object); - - priv->catalogs = NULL; - - if (priv->tray) - { - g_object_unref (priv->tray); - priv->tray = NULL; - } - if (priv->tooltips) - { - g_object_unref (priv->tooltips); - priv->tooltips = NULL; - } - if (priv->static_tooltips) - { - g_object_unref (priv->static_tooltips); - priv->static_tooltips = NULL; - } - - G_OBJECT_CLASS (glade_palette_parent_class)->dispose (object); -} - -static void -glade_palette_finalize (GObject *object) -{ - GladePalettePrivate *priv; - - priv = GLADE_PALETTE_GET_PRIVATE (object); - - g_slist_free (priv->sections); - - G_OBJECT_CLASS (glade_palette_parent_class)->finalize (object); -} - -static void -glade_palette_class_init (GladePaletteClass *klass) -{ - GObjectClass *object_class; - GtkWidgetClass *widget_class; - - object_class = G_OBJECT_CLASS (klass); - widget_class = GTK_WIDGET_CLASS (klass); - - klass->toggled = NULL; - - object_class->get_property = glade_palette_get_property; - object_class->set_property = glade_palette_set_property; - object_class->dispose = glade_palette_dispose; - object_class->finalize = glade_palette_finalize; - - widget_class->show_all = glade_palette_show_all; - - glade_palette_signals[TOGGLED] = - g_signal_new ("toggled", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GladePaletteClass, toggled), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); - - g_object_class_install_property (object_class, - PROP_ITEM_APPEARANCE, - g_param_spec_enum ("item-appearance", - "Item Appearance", - "The appearance of the palette items", - GLADE_TYPE_ITEM_APPEARANCE, - GLADE_ITEM_ICON_ONLY, - G_PARAM_READWRITE)); - - g_object_class_install_property (object_class, - PROP_ITEM_APPEARANCE, - g_param_spec_boolean ("use-small-item-icons", - "Use Small Item Icons", - "Whether to use small icons to represent items", - FALSE, - G_PARAM_READWRITE)); - - g_object_class_install_property (object_class, - PROP_ITEM_APPEARANCE, - g_param_spec_boolean ("show-selector-button", - "Show Selector Button", - "Whether to show the internal selector button", - TRUE, - G_PARAM_READWRITE)); - - g_object_class_install_property (object_class, - PROP_CURRENT_ITEM, - g_param_spec_pointer ("current-item", - "Current Item Class", - "The GladeWidgetAdaptor of the currently selected item", - G_PARAM_READABLE)); - - g_object_class_install_property (object_class, - PROP_CATALOGS, - g_param_spec_pointer ("catalogs", - "Widget catalogs", - "The widget catalogs for the palette", - G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE)); - - g_type_class_add_private (object_class, sizeof (GladePalettePrivate)); -} - -static void -glade_palette_on_button_toggled (GtkWidget *button, GladePalette *palette) -{ - GladePalettePrivate *priv; - GdkModifierType mask; - GladeWidgetAdaptor *adaptor; - - g_return_if_fail (GLADE_IS_PALETTE (palette)); - g_return_if_fail (GTK_IS_TOGGLE_BUTTON (button)); - priv = GLADE_PALETTE_GET_PRIVATE (palette); - - /* if we are toggling currently active item into non-active state */ - if (priv->current_item == GLADE_PALETTE_ITEM (button)) - { - priv->current_item = NULL; - g_object_notify (G_OBJECT (palette), "current-item"); - - glade_app_set_pointer_mode (GLADE_POINTER_SELECT); - - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->selector_button), TRUE); - - priv->sticky_selection_mode = FALSE; - - g_signal_emit (G_OBJECT (palette), glade_palette_signals[TOGGLED], 0); - - return; - } - - /* now we are interested only in buttons which toggle from inactive to active */ - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))) - return; - - if (priv->current_item && (GLADE_PALETTE_ITEM (button) != priv->current_item)) - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->current_item), FALSE); - - priv->current_item = GLADE_PALETTE_ITEM (button); - g_object_notify (G_OBJECT (palette), "current-item"); - - glade_app_set_pointer_mode (GLADE_POINTER_ADD_WIDGET); - - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->selector_button), FALSE); - - /* check whether to enable sticky selection */ - adaptor = glade_palette_item_get_adaptor (GLADE_PALETTE_ITEM (button)); - gdk_window_get_pointer (button->window, NULL, NULL, &mask); - priv->sticky_selection_mode = (!GWA_IS_TOPLEVEL (adaptor)) && (mask & GDK_CONTROL_MASK); - - g_signal_emit (G_OBJECT (palette), glade_palette_signals[TOGGLED], 0); -} - -static GtkWidget* -glade_palette_new_item (GladePalette *palette, GladeWidgetAdaptor *adaptor) -{ - GladePalettePrivate *priv; - GtkWidget *item; - - g_return_val_if_fail (GLADE_IS_PALETTE (palette), NULL); - g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL); - priv = GLADE_PALETTE_GET_PRIVATE (palette); - - item = glade_palette_item_new (adaptor); - - glade_palette_item_set_appearance (GLADE_PALETTE_ITEM (item), priv->item_appearance); - - gtk_tooltips_set_tip (priv->tooltips, item, adaptor->title, NULL); - - g_signal_connect (G_OBJECT (item), "toggled", - G_CALLBACK (glade_palette_on_button_toggled), palette); - - return item; -} - -static GtkWidget* -glade_palette_new_item_group (GladePalette *palette, GladeWidgetGroup *group) -{ - GladePalettePrivate *priv; - GtkWidget *expander; - GtkWidget *box; - GtkWidget *item; - GList *l; - gchar *title; - - g_return_val_if_fail (GLADE_IS_PALETTE (palette), NULL); - g_return_val_if_fail (group != NULL, NULL); - priv = GLADE_PALETTE_GET_PRIVATE (palette); - - box = glade_palette_box_new (); - - /* Go through all the widget classes in this catalog. */ - for (l = (GList *) glade_widget_group_get_adaptors (group); l; l = l->next) - { - GladeWidgetAdaptor *adaptor = GLADE_WIDGET_ADAPTOR (l->data); - - /* Create new item */ - item = glade_palette_new_item (palette, adaptor); - gtk_size_group_add_widget (priv->size_group, GTK_WIDGET (item)); - gtk_container_add (GTK_CONTAINER (box), item); - - } - - title = g_strdup_printf ("%s", glade_widget_group_get_title (group)); - - /* Put items box in a expander */ - expander = glade_palette_expander_new (title); - glade_palette_expander_set_spacing (GLADE_PALETTE_EXPANDER (expander), 2); - glade_palette_expander_set_use_markup (GLADE_PALETTE_EXPANDER (expander), TRUE); - gtk_container_set_border_width (GTK_CONTAINER (expander), 0); - - /* set default expanded state */ - glade_palette_expander_set_expanded (GLADE_PALETTE_EXPANDER (expander), - glade_widget_group_get_expanded (group)); - - gtk_container_add (GTK_CONTAINER (expander), box); - - g_free (title); - - return expander; -} - -static void -glade_palette_append_item_group (GladePalette *palette, - GladeWidgetGroup *group) -{ - GladePalettePrivate *priv; - GtkWidget *expander; - - g_return_if_fail (GLADE_IS_PALETTE (palette)); - g_return_if_fail (group != NULL); - priv = GLADE_PALETTE_GET_PRIVATE (palette); - - expander = glade_palette_new_item_group (palette, group); - - priv->sections = g_slist_append (priv->sections, expander); - - gtk_box_pack_start (GTK_BOX (priv->tray), expander, FALSE, FALSE, 0); - -} - -static void -glade_palette_update_appearance (GladePalette *palette) -{ - GladePalettePrivate *priv; - GtkWidget *viewport; - GSList *sections; - GList *items, *i; - - priv = GLADE_PALETTE_GET_PRIVATE (palette); - - for (sections = priv->sections; sections; sections = sections->next) - { - items = gtk_container_get_children (GTK_CONTAINER (gtk_bin_get_child (GTK_BIN (sections->data)))); - - for (i = items; i; i = i->next) - { - glade_palette_item_set_appearance (GLADE_PALETTE_ITEM (i->data), priv->item_appearance); - glade_palette_item_set_use_small_icon (GLADE_PALETTE_ITEM (i->data), priv->use_small_item_icons); - } - g_list_free (items); - } - - /* FIXME: Removing and then adding the tray again to the Viewport - * is the only way I can get the Viewport to - * respect the new width of the tray. - * There should be a better solution. - */ - viewport = gtk_widget_get_parent (priv->tray); - if (viewport != NULL) - { - gtk_container_remove (GTK_CONTAINER (viewport), priv->tray); - gtk_container_add (GTK_CONTAINER (viewport), priv->tray); - } - - if (priv->item_appearance == GLADE_ITEM_ICON_ONLY) - gtk_tooltips_enable (priv->tooltips); - else - gtk_tooltips_disable (priv->tooltips); - -} - -static GtkWidget* -glade_palette_create_selector_button (GladePalette *palette) -{ - GtkWidget *selector; - GtkWidget *image; - gchar *path; - - /* create selector button */ - selector = gtk_toggle_button_new (); - - gtk_container_set_border_width (GTK_CONTAINER (selector), 0); - - path = g_build_filename (glade_app_get_pixmaps_dir (), "selector.png", NULL); - image = gtk_image_new_from_file (path); - gtk_widget_show (image); - - gtk_container_add (GTK_CONTAINER (selector), image); - gtk_button_set_relief (GTK_BUTTON (selector), GTK_RELIEF_NONE); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (selector), TRUE); - - g_signal_connect (G_OBJECT (selector), "toggled", - G_CALLBACK (selector_button_toggled_cb), - palette); - - g_free (path); - - return selector; -} - -static void -glade_palette_init (GladePalette *palette) -{ - GladePalettePrivate *priv; - GtkWidget *sw; - - priv = palette->priv = GLADE_PALETTE_GET_PRIVATE (palette); - - priv->catalogs = NULL; - priv->current_item = NULL; - priv->sections = NULL; - priv->item_appearance = GLADE_ITEM_ICON_ONLY; - priv->use_small_item_icons = FALSE; - priv->sticky_selection_mode = FALSE; - - /* create selector button */ - priv->selector_button = glade_palette_create_selector_button (palette); - priv->selector_hbox = gtk_hbox_new (FALSE, 0); - gtk_box_pack_start (GTK_BOX (priv->selector_hbox), priv->selector_button, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (palette), priv->selector_hbox, FALSE, FALSE, 0); - gtk_widget_show (priv->selector_button); - gtk_widget_show (priv->selector_hbox); - - /* create tooltips */ - priv->tooltips = gtk_tooltips_new (); - g_object_ref_sink (GTK_OBJECT (priv->tooltips)); - priv->static_tooltips = gtk_tooltips_new (); - g_object_ref_sink (GTK_OBJECT (priv->static_tooltips)); - - gtk_tooltips_set_tip (priv->static_tooltips, priv->selector_button, _("Widget selector"), NULL); - - /* create size group */ - priv->size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); - gtk_size_group_set_ignore_hidden (priv->size_group, FALSE); - - /* add items tray (via a scrolled window) */ - priv->tray = gtk_vbox_new (FALSE, 0); - g_object_ref_sink (G_OBJECT (priv->tray)); - gtk_container_set_border_width (GTK_CONTAINER (priv->tray), 1); - - sw = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), - GTK_POLICY_NEVER, - GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (sw), priv->tray); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), - GTK_SHADOW_NONE); - - gtk_box_pack_start (GTK_BOX (palette), sw, TRUE, TRUE, 0); - - gtk_widget_show (sw); - gtk_widget_show (priv->tray); - - gtk_widget_set_no_show_all (GTK_WIDGET (palette), TRUE); -} - -/** - * glade_palette_get_current_item: - * @palette: a #GladePalette - * - * Gets the #GladeWidgetAdaptor of the currently selected item. - * - * Returns: the #GladeWidgetAdaptor of currently selected item, or NULL - * if no item is selected. - */ -GladeWidgetAdaptor * -glade_palette_get_current_item (GladePalette *palette) -{ - g_return_val_if_fail (GLADE_IS_PALETTE (palette), NULL); - - if (palette->priv->current_item) - { - return glade_palette_item_get_adaptor (palette->priv->current_item); - } - else - { - return NULL; - } - -} - -/** - * glade_palette_new: - * @catalogs: the widget catalogs for the palette. - * - * Creates a new #GladePalette widget - * - * Returns: a new #GladePalette - */ -GtkWidget* -glade_palette_new (const GList *catalogs) -{ - GladePalette *palette; - - g_return_val_if_fail (catalogs != NULL, NULL); - - palette = g_object_new (GLADE_TYPE_PALETTE, - "spacing", 2, - "item-appearance", GLADE_ITEM_ICON_ONLY, - "catalogs", catalogs, - NULL); - - return GTK_WIDGET (palette); -} - -/** - * glade_palette_deselect_current_item: - * @palette: a #GladePalette - * @sticky_aware: whether to consider sticky selection mode - * - * Deselects the currently selected item - */ -void -glade_palette_deselect_current_item (GladePalette *palette, gboolean sticky_aware) -{ - g_return_if_fail (GLADE_IS_PALETTE (palette)); - - if (sticky_aware && palette->priv->sticky_selection_mode) - return; - - if (palette->priv->current_item) - { - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (palette->priv->current_item), FALSE); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (palette->priv->selector_button), TRUE); - - palette->priv->current_item = NULL; - g_object_notify (G_OBJECT (palette), "current-item"); - - glade_app_set_pointer_mode (GLADE_POINTER_SELECT); - - g_signal_emit (G_OBJECT (palette), glade_palette_signals[TOGGLED], 0); - - } - -} - -/** - * glade_palette_get_item_appearance: - * @palette: a #GladePalette - * - * Returns: The appearance of the palette items - */ -GladeItemAppearance -glade_palette_get_item_appearance (GladePalette *palette) -{; - g_return_val_if_fail (GLADE_IS_PALETTE (palette), GLADE_ITEM_ICON_ONLY); - - return palette->priv->item_appearance; -} - -/** - * glade_palette_get_use_small_item_icons: - * @palette: a #GladePalette - * - * Returns: Whether small item icons are used - */ -gboolean -glade_palette_get_use_small_item_icons (GladePalette *palette) -{ - g_return_val_if_fail (GLADE_IS_PALETTE (palette), FALSE); - - return palette->priv->use_small_item_icons; -} - -/** - * glade_palette_get_show_selector_button: - * @palette: a #GladePalette - * - * Returns: Whether the selector button is visible - */ -gboolean -glade_palette_get_show_selector_button (GladePalette *palette) -{ - g_return_val_if_fail (GLADE_IS_PALETTE (palette), FALSE); - - return GTK_WIDGET_VISIBLE (palette->priv->selector_hbox); -} - diff --git a/gladeui/glade-palette.h b/gladeui/glade-palette.h deleted file mode 100644 index 3d4bd43d..00000000 --- a/gladeui/glade-palette.h +++ /dev/null @@ -1,98 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * glade-palette.h - * - * Copyright (C) 2006 The GNOME Foundation. - * Copyright (C) 2001-2005 Ximian, Inc. - * - * Authors: - * Chema Celorio - * Joaquin Cuenca Abela <e98cuenc@yahoo.com> - * Vincent Geddes <vgeddes@metroweb.co.za> - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#ifndef __GLADE_PALETTE_H__ -#define __GLADE_PALETTE_H__ - -#include <gladeui/glade.h> - -#include <gtk/gtkvbox.h> - -G_BEGIN_DECLS - -#define GLADE_TYPE_PALETTE (glade_palette_get_type ()) -#define GLADE_PALETTE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_PALETTE, GladePalette)) -#define GLADE_PALETTE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_PALETTE, GladePaletteClass)) -#define GLADE_IS_PALETTE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_PALETTE)) -#define GLADE_IS_PALETTE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_PALETTE)) -#define GLADE_PALETTE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GLADE_TYPE_PALETTE, GladePaletteClass)) - -typedef struct _GladePalette GladePalette; -typedef struct _GladePalettePrivate GladePalettePrivate; -typedef struct _GladePaletteClass GladePaletteClass; - -struct _GladePalette -{ - GtkVBox parent_instance; - - GladePalettePrivate *priv; -}; - -struct _GladePaletteClass -{ - GtkVBoxClass parent_class; - - void (*toggled) (GladePalette *palette); -}; - -typedef enum -{ - GLADE_ITEM_ICON_AND_LABEL, - GLADE_ITEM_ICON_ONLY, - GLADE_ITEM_LABEL_ONLY -} GladeItemAppearance; - - -GType glade_palette_get_type (void) G_GNUC_CONST; - -GtkWidget *glade_palette_new (const GList *catalogs); - -void glade_palette_deselect_current_item (GladePalette *palette, - gboolean sticky_aware); - -GladeWidgetAdaptor *glade_palette_get_current_item (GladePalette *palette); - -GladeItemAppearance glade_palette_get_item_appearance (GladePalette *palette); - -void glade_palette_set_item_appearance (GladePalette *palette, - GladeItemAppearance appearance); - -gboolean glade_palette_get_use_small_item_icons (GladePalette *palette); - -void glade_palette_set_use_small_item_icons (GladePalette *palette, - gboolean use_small_item_icons); - -void glade_palette_set_show_selector_button (GladePalette *palette, - gboolean show_selector_button); - -gboolean glade_palette_get_show_selector_button (GladePalette *palette); - -G_END_DECLS - -#endif /* __GLADE_PALETTE_H__ */ - diff --git a/gladeui/glade-parameter.c b/gladeui/glade-parameter.c deleted file mode 100644 index cbb149b4..00000000 --- a/gladeui/glade-parameter.c +++ /dev/null @@ -1,287 +0,0 @@ -/* -*- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Authors: - * Chema Celorio <chema@celorio.com> - */ - -#include "config.h" - -#include <stdlib.h> /* for atoi and atof */ -#include <string.h> - -#include "glade.h" -#include "glade-xml-utils.h" -#include "glade-parameter.h" -#include "glade-property-class.h" - -/** - * glade_parameter_get_integer: - * @parameters: a #GList of #GladeParameters - * @key: a string containing the parameter name - * @value: a pointer to a #gint - * - * Searches through @parameters looking for a #GladeParameter named @key. If - * found, it stores a #gint representation of its value into @value. - */ -void -glade_parameter_get_integer (GList *parameters, const gchar *key, gint *value) -{ - GladeParameter *parameter; - GList *list; - - list = parameters; - for (; list != NULL; list = list->next) { - parameter = list->data; - if (strcmp (key, parameter->key) == 0) { - *value = g_ascii_strtoll (parameter->value, NULL, 10); - return; - } - } -} - -/** - * glade_parameter_get_float: - * @parameters: a #GList of #GladeParameters - * @key: a string containing the parameter name - * @value: a pointer to a #gfloat - * - * Searches through @parameters looking for a #GladeParameter named @key. If - * found, it stores a #gfloat representation of its value into @value. - */ -void -glade_parameter_get_float (GList *parameters, const gchar *key, gfloat *value) -{ - GladeParameter *parameter; - GList *list; - - list = parameters; - for (; list != NULL; list = list->next) { - parameter = list->data; - if (strcmp (key, parameter->key) == 0) { - *value = (float) g_ascii_strtod (parameter->value, NULL); - return; - } - } -} - -/** - * glade_parameter_get_boolean: - * @parameters: a #GList of #GladeParameters - * @key: a string containing the parameter name - * @value: a pointer to a #gboolean - * - * Searches through @parameters looking for a #GladeParameter named @key. If - * found, it stores a #gboolean representation of its value into @value. - */ -void -glade_parameter_get_boolean (GList *parameters, const gchar *key, gboolean *value) -{ - GladeParameter *parameter; - GList *list; - - list = parameters; - for (; list != NULL; list = list->next) { - parameter = list->data; - if (strcmp (key, parameter->key) == 0) { - if (strcmp (parameter->value, GLADE_TAG_TRUE) == 0) - *value = TRUE; - else if (strcmp (parameter->value, GLADE_TAG_FALSE) == 0) - *value = FALSE; - else - g_warning ("Invalid boolean parameter *%s* (%s/%s)", - parameter->value, GLADE_TAG_TRUE, GLADE_TAG_FALSE); - return; - } - } -} - -/** - * glade_parameter_get_string: - * @parameters: a #GList of #GladeParameters - * @key: a string containing the parameter name - * @value: a pointer to an string - * - * Searches through @parameters looking for a #GladeParameter named @key. If - * found, it stores a newly copied string representation of its value into - * @value. - */ -void -glade_parameter_get_string (GList *parameters, const gchar *key, gchar **value) -{ - GladeParameter *parameter; - GList *list; - - list = parameters; - for (; list != NULL; list = list->next) { - parameter = list->data; - if (strcmp (key, parameter->key) == 0) { - if (*value != NULL) - g_free (*value); - *value = g_strdup (parameter->value); - return; - } - } -} - -/** - * glade_parameter_free: - * @parameter: a #GladeParameter - * - * Frees @parameter and its associated memory. - */ -void -glade_parameter_free (GladeParameter *parameter) -{ - if (!parameter) - return; - - g_free (parameter->key); - g_free (parameter->value); - g_free (parameter); -} - -/** - * glade_parameter_new: - * - * Returns: a new #GladeParameter - */ -GladeParameter * -glade_parameter_new (void) -{ - GladeParameter *parameter; - - parameter = g_new0 (GladeParameter, 1); - - return parameter; -} - -/** - * glade_parameter_clone: - * @parameter: a #GladeParameter - * - * Returns: a new #GladeParameter cloned from @parameter - */ -GladeParameter * -glade_parameter_clone (GladeParameter *parameter) -{ - GladeParameter *clone; - - if (parameter == NULL) - return NULL; - - clone = glade_parameter_new (); - clone->key = g_strdup (parameter->key); - clone->value = g_strdup (parameter->value); - - return clone; -} - -static GladeParameter * -glade_parameter_new_from_node (GladeXmlNode *node) -{ - GladeParameter *parameter; - - if (!glade_xml_node_verify (node, GLADE_TAG_PARAMETER)) - return NULL; - - parameter = glade_parameter_new (); - parameter->key = glade_xml_get_property_string_required (node, GLADE_TAG_KEY, NULL); - parameter->value = glade_xml_get_property_string_required (node, GLADE_TAG_VALUE, NULL); - - if (!parameter->key || !parameter->value) - return NULL; - - return parameter; -} - -/** - * glade_parameter_list_find_by_key: - * @list: a #GList containing #GladeParameters - * @key: a string used as a parameter key - * - * Searches through @list looking for a node which contains a - * #GladeParameter matching @key - * - * Returns: the #GList node containing the located #GladeParameter, - * or %NULL if none is found - */ -static GList * -glade_parameter_list_find_by_key (GList *list, const gchar *key) -{ - GladeParameter *parameter; - - for (; list != NULL; list = list->next) { - parameter = list->data; - g_return_val_if_fail (parameter->key != NULL, NULL); - if (strcmp (parameter->key, key) == 0) - return list; - } - - return NULL; -} - -/** - * glade_parameter_list_new_from_node: - * @list: a #GList node - * @node: a #GladeXmlNode - * - * TODO: write me - * - * Returns: - */ -GList * -glade_parameter_list_new_from_node (GList *list, GladeXmlNode *node) -{ - GladeParameter *parameter; - GladeXmlNode *child; - GList *findme; - - if (!glade_xml_node_verify (node, GLADE_TAG_PARAMETERS)) - return NULL; - child = glade_xml_search_child (node, GLADE_TAG_PARAMETER); - if (child == NULL) - return NULL; - - child = glade_xml_node_get_children (node); - - for (; child != NULL; child = glade_xml_node_next (child)) { - if (!glade_xml_node_verify (child, GLADE_TAG_PARAMETER)) - return NULL; - - parameter = glade_parameter_new_from_node (child); - if (parameter == NULL) - return NULL; - /* Is this parameter already there ? just replace - * the pointer and free the old one - */ - findme = glade_parameter_list_find_by_key (list, - parameter->key); - if (findme) { - glade_parameter_free (findme->data); - findme->data = parameter; - continue; - } - - list = g_list_prepend (list, parameter); - } - - list = g_list_reverse (list); - - return list; -} diff --git a/gladeui/glade-parameter.h b/gladeui/glade-parameter.h deleted file mode 100644 index 7b4d6e1d..00000000 --- a/gladeui/glade-parameter.h +++ /dev/null @@ -1,54 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef __GLADE_PARAMETER_H__ -#define __GLADE_PARAMETER_H__ - -G_BEGIN_DECLS - -/* The GladeParameter is a pair of a key and a value. It is used by the - * GladeSetting object. We store in a string the value no matter the - * type of the paramter it is. This adds "extra" information to a - * GladeProperty that we can blindly parse/set/query - * The valid parameter keys depend on the type of the property - - <Property> - <Type>Integer</Type> - ..... - <Parameters> - <Parameter Key="Min" Value="0"/> - <Parameter Key="Max" Value="10000"/> - <Parameter Key="Default" Value="0"/> - <Parameter Key="StepIncrement" Value="1"/> - <Parameter Key="PageIncrement" Value="10"/> - <Parameter Key="ClimbRate" Value="1"/> - </Parameters> - </Property> - - */ -typedef struct _GladeParameter GladeParameter; - -struct _GladeParameter { - - gchar *key; /* The name of the parameter */ - gchar *value; /* The textual representation of the parameter */ -}; - - -GladeParameter *glade_parameter_new (void); - -GladeParameter *glade_parameter_clone (GladeParameter *parameter); - -void glade_parameter_free (GladeParameter *parameter); - -void glade_parameter_get_float (GList *parameters, const gchar *key, gfloat *value); - -void glade_parameter_get_integer (GList *parameters, const gchar *key, gint *value); - -void glade_parameter_get_boolean (GList *parameters, const gchar *key, gboolean *value); - -void glade_parameter_get_string (GList *parameters, const gchar *key, gchar **value); - -GList * glade_parameter_list_new_from_node (GList *list, GladeXmlNode *node); - -G_END_DECLS - -#endif /* __GLADE_PARAMETER_H__ */ diff --git a/gladeui/glade-parser.c b/gladeui/glade-parser.c deleted file mode 100644 index 2e32068a..00000000 --- a/gladeui/glade-parser.c +++ /dev/null @@ -1,1709 +0,0 @@ - -/* -*- Mode: C; c-basic-offset: 4 -*- - * libglade - a library for building interfaces from XML files at runtime - * Copyright (C) 1998-2002 James Henstridge <james@daa.com.au> - * - * glade-parser.c: functions for parsing glade-2.0 files - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -#include <stdio.h> -#include <string.h> -#include <glib.h> -#include <glib/gi18n-lib.h> -#include <libxml/parser.h> -#include <time.h> - -#include "glade-parser.h" -#include "glade.h" - -#define GLADE_NOTE(a,b) - -typedef enum { - PARSER_START, - PARSER_GLADE_INTERFACE, - PARSER_REQUIRES, - PARSER_WIDGET, - PARSER_WIDGET_PROPERTY, - PARSER_WIDGET_ATK, - PARSER_WIDGET_ATK_PROPERTY, - PARSER_WIDGET_ATK_ACTION, - PARSER_WIDGET_ATK_RELATION, - PARSER_WIDGET_AFTER_ATK, - PARSER_WIDGET_SIGNAL, - PARSER_WIDGET_AFTER_SIGNAL, - PARSER_WIDGET_ACCEL, - PARSER_WIDGET_AFTER_ACCEL, - PARSER_WIDGET_CHILD, - PARSER_WIDGET_CHILD_AFTER_WIDGET, - PARSER_WIDGET_CHILD_PACKING, - PARSER_WIDGET_CHILD_PACKING_PROPERTY, - PARSER_WIDGET_CHILD_AFTER_PACKING, - PARSER_WIDGET_CHILD_PLACEHOLDER, - PARSER_WIDGET_CHILD_AFTER_PLACEHOLDER, - PARSER_FINISH, - PARSER_UNKNOWN -} ParserState; - -#ifdef DEBUG -static const gchar *state_names[] = { - "START", - "GLADE_INTERFACE", - "REQUIRES", - "WIDGET", - "WIDGET_PROPERTY", - "WIDGET_ATK", - "WIDGET_ATK_PROPERTY", - "WIDGET_ATK_ACTION", - "WIDGET_ATK_RELATION", - "WIDGET_AFTER_ATK", - "WIDGET_SIGNAL", - "WIDGET_AFTER_SIGNAL", - "WIDGET_ACCEL", - "WIDGET_AFTER_ACCEL", - "WIDGET_CHILD", - "WIDGET_CHILD_AFTER_WIDGET", - "WIDGET_CHILD_PACKING", - "WIDGET_CHILD_PACKING_PROPERTY", - "WIDGET_CHILD_AFTER_PACKING", - "WIDGET_CHILD_PLACEHOLDER", - "WIDGET_CHILD_AFTER_PLACEHOLDER", - "FINISH", - "UNKNOWN", -}; -#endif - -typedef struct _GladeParseState GladeParseState; -struct _GladeParseState { - ParserState state; - - const gchar *domain; - - guint unknown_depth; /* handle recursive unrecognised tags */ - ParserState prev_state; /* the last `known' state we were in */ - - guint widget_depth; - GString *content; - - GladeInterface *interface; - GladeWidgetInfo *widget; - - enum {PROP_NONE, PROP_WIDGET, PROP_ATK, PROP_CHILD } prop_type; - gchar *prop_name; - gchar *comment; - gboolean translate_prop; - gboolean context_prop; - GArray *props; - - GArray *signals; - GArray *atk_actions; - GArray *relations; - GArray *accels; -}; - -static GladeWidgetInfo * -create_widget_info(GladeInterface *interface, const xmlChar **attrs) -{ - GladeWidgetInfo *info = g_new0(GladeWidgetInfo, 1); - gint i; - - for (i = 0; attrs && attrs[i] != NULL; i += 2) { - if (!xmlStrcmp(attrs[i], BAD_CAST("class"))) - info->classname = glade_xml_alloc_string (interface, CAST_BAD(attrs[i+1])); - else if (!xmlStrcmp(attrs[i], BAD_CAST("id"))) - info->name = glade_xml_alloc_string (interface, CAST_BAD(attrs[i+1])); - else - g_warning("unknown attribute `%s' for <widget>.", attrs[i]); - } - if (info->classname == NULL || info->name == NULL) - g_warning("<widget> element missing required attributes!"); - g_hash_table_insert(interface->names, info->name, info); - return info; -} - -static inline void -flush_properties(GladeParseState *state) -{ - if (state->props == NULL) - return; - switch (state->prop_type) { - case PROP_NONE: - break; - case PROP_WIDGET: - if (state->widget->properties) - g_warning("we already read all the props for this key. Leaking"); - state->widget->properties = (GladePropInfo *)state->props->data; - state->widget->n_properties = state->props->len; - g_array_free(state->props, FALSE); - break; - case PROP_ATK: - if (state->widget->atk_props) - g_warning("we already read all the ATK props for this key. Leaking"); - state->widget->atk_props = (GladePropInfo *)state->props->data; - state->widget->n_atk_props = state->props->len; - g_array_free(state->props, FALSE); - break; - case PROP_CHILD: - if (state->widget->n_children == 0) { - g_warning("no children, but have child properties!"); - g_array_free(state->props, TRUE); - } else { - GladeChildInfo *info = &state->widget->children[ - state->widget->n_children-1]; - if (info->properties) - g_warning("we already read all the child props for this key. Leaking"); - info->properties = (GladePropInfo *)state->props->data; - info->n_properties = state->props->len; - g_array_free(state->props, FALSE); - } - break; - } - state->prop_type = PROP_NONE; - state->prop_name = NULL; - state->props = NULL; -} - -static inline void -flush_signals(GladeParseState *state) -{ - if (state->signals) { - state->widget->signals = (GladeSignalInfo *)state->signals->data; - state->widget->n_signals = state->signals->len; - g_array_free(state->signals, FALSE); - } - state->signals = NULL; -} - -static inline void -flush_actions(GladeParseState *state) -{ - if (state->atk_actions) { - state->widget->atk_actions = (GladeAtkActionInfo *)state->atk_actions->data; - state->widget->n_atk_actions = state->atk_actions->len; - g_array_free(state->atk_actions, FALSE); - } - state->atk_actions = NULL; -} - -static inline void -flush_relations(GladeParseState *state) -{ - if (state->relations) { - state->widget->relations = (GladeAtkRelationInfo *)state->relations->data; - state->widget->n_relations = state->relations->len; - g_array_free(state->relations, FALSE); - } - state->relations = NULL; -} - -static inline void -flush_accels(GladeParseState *state) -{ - if (state->accels) { - state->widget->accels = (GladeAccelInfo *)state->accels->data; - state->widget->n_accels = state->accels->len; - g_array_free(state->accels, FALSE); - } - state->accels = NULL; -} - -static inline void -handle_atk_action(GladeParseState *state, const xmlChar **attrs) -{ - gint i; - GladeAtkActionInfo info = { 0 }; - - flush_properties(state); - - for (i = 0; attrs && attrs[i] != NULL; i += 2) { - if (!xmlStrcmp(attrs[i], BAD_CAST("action_name"))) - info.action_name = glade_xml_alloc_string(state->interface, CAST_BAD(attrs[i+1])); - else if (!xmlStrcmp(attrs[i], BAD_CAST("description"))) - info.description = glade_xml_alloc_string(state->interface, CAST_BAD(attrs[i+1])); - else - g_warning("unknown attribute `%s' for <action>.", attrs[i]); - } - if (info.action_name == NULL) { - g_warning("required <atkaction> attribute 'action_name' missing!!!"); - return; - } - if (!state->atk_actions) - state->atk_actions = g_array_new(FALSE, FALSE, - sizeof(GladeAtkActionInfo)); - g_array_append_val(state->atk_actions, info); -} - -static inline void -handle_atk_relation(GladeParseState *state, const xmlChar **attrs) -{ - gint i; - GladeAtkRelationInfo info = { 0 }; - - flush_properties(state); - - for (i = 0; attrs && attrs[i] != NULL; i += 2) { - if (!xmlStrcmp(attrs[i], BAD_CAST("target"))) - info.target = glade_xml_alloc_string(state->interface, CAST_BAD(attrs[i+1])); - else if (!xmlStrcmp(attrs[i], BAD_CAST("type"))) - info.type = glade_xml_alloc_string(state->interface, CAST_BAD(attrs[i+1])); - else - g_warning("unknown attribute `%s' for <signal>.", attrs[i]); - } - if (info.target == NULL || info.type == NULL) { - g_warning("required <atkrelation> attributes ('target' and/or 'type') missing!!!"); - return; - } - if (!state->relations) - state->relations = g_array_new(FALSE, FALSE, - sizeof(GladeAtkRelationInfo)); - g_array_append_val(state->relations, info); -} - -static inline void -handle_signal(GladeParseState *state, const xmlChar **attrs) -{ - GladeSignalInfo info = { 0 }; - gint i; - - flush_properties(state); - - info.after = FALSE; - for (i = 0; attrs && attrs[i] != NULL; i += 2) { - if (!xmlStrcmp(attrs[i], BAD_CAST("name"))) - info.name = glade_xml_alloc_string(state->interface, CAST_BAD(attrs[i+1])); - else if (!xmlStrcmp(attrs[i], BAD_CAST("handler"))) - info.handler = glade_xml_alloc_string(state->interface, CAST_BAD(attrs[i+1])); - else if (!xmlStrcmp(attrs[i], BAD_CAST("after"))) - info.after = attrs[i+1][0] == 'y'; - else if (!xmlStrcmp(attrs[i], BAD_CAST("lookup"))) - info.lookup = attrs[i+1][0] == 'y'; - else if (!xmlStrcmp(attrs[i], BAD_CAST("object"))) - info.object = glade_xml_alloc_string(state->interface, CAST_BAD(attrs[i+1])); - else if (!xmlStrcmp(attrs[i], BAD_CAST("last_modification_time"))) - /* Do nothing. */; - else - g_warning("unknown attribute `%s' for <signal>.", attrs[i]); - } - if (info.name == NULL || info.handler == NULL) { - g_warning("required <signal> attributes missing!!!"); - return; - } - if (!state->signals) - state->signals = g_array_new(FALSE, FALSE, - sizeof(GladeSignalInfo)); - g_array_append_val(state->signals, info); -} - -static inline void -handle_accel(GladeParseState *state, const xmlChar **attrs) -{ - GladeAccelInfo info = { 0 }; - gint i; - - flush_properties(state); - flush_signals(state); - flush_actions(state); - flush_relations(state); - - for (i = 0; attrs && attrs[i] != NULL; i += 2) { - if (!xmlStrcmp(attrs[i], BAD_CAST("key"))) - info.key = gdk_keyval_from_name(CAST_BAD(attrs[i+1])); - else if (!xmlStrcmp(attrs[i], BAD_CAST("modifiers"))) { - const xmlChar *pos = attrs[i+1]; - - info.modifiers = 0; - while (pos[0]) - if (!xmlStrncmp(pos, BAD_CAST("GDK_"), 4)) { - pos += 4; - if (!xmlStrncmp(pos, BAD_CAST("SHIFT_MASK"), 10)) { - info.modifiers |= GDK_SHIFT_MASK; - pos += 10; - } else if (!xmlStrncmp(pos, BAD_CAST("LOCK_MASK"), 9)) { - info.modifiers |= GDK_LOCK_MASK; - pos += 9; - } else if (!xmlStrncmp(pos, BAD_CAST("CONTROL_MASK"), 12)) { - info.modifiers |= GDK_CONTROL_MASK; - pos += 12; - } else if (!xmlStrncmp(pos, BAD_CAST("MOD"), 3) && - !xmlStrncmp(pos+4, BAD_CAST("_MASK"), 5)) { - switch (pos[3]) { - case '1': - info.modifiers |= GDK_MOD1_MASK; break; - case '2': - info.modifiers |= GDK_MOD2_MASK; break; - case '3': - info.modifiers |= GDK_MOD3_MASK; break; - case '4': - info.modifiers |= GDK_MOD4_MASK; break; - case '5': - info.modifiers |= GDK_MOD5_MASK; break; - } - pos += 9; - } else if (!xmlStrncmp(pos, BAD_CAST("BUTTON"), 6) && - !xmlStrncmp(pos+7, BAD_CAST("_MASK"), 5)) { - switch (pos[6]) { - case '1': - info.modifiers |= GDK_BUTTON1_MASK; break; - case '2': - info.modifiers |= GDK_BUTTON2_MASK; break; - case '3': - info.modifiers |= GDK_BUTTON3_MASK; break; - case '4': - info.modifiers |= GDK_BUTTON4_MASK; break; - case '5': - info.modifiers |= GDK_BUTTON5_MASK; break; - } - pos += 12; - } else if (!xmlStrncmp(pos, BAD_CAST("RELEASE_MASK"), 12)) { - info.modifiers |= GDK_RELEASE_MASK; - pos += 12; - } else - pos++; - } else - pos++; - } else if (!xmlStrcmp(attrs[i], BAD_CAST("signal"))) - info.signal = glade_xml_alloc_string(state->interface, CAST_BAD(attrs[i+1])); - else - g_warning("unknown attribute `%s' for <accelerator>.", attrs[i]); - } - if (info.key == 0 || info.signal == NULL) { - g_warning("required <accelerator> attributes missing!!!"); - return; - } - if (!state->accels) - state->accels = g_array_new(FALSE, FALSE, - sizeof(GladeAccelInfo)); - - g_array_append_val(state->accels, info); -} - -static inline void -handle_child(GladeParseState *state, const xmlChar **attrs) -{ - GladeChildInfo *info; - gint i; - - /* make sure all of these are flushed */ - flush_properties(state); - flush_signals(state); - flush_actions(state); - flush_relations(state); - flush_accels(state); - - state->widget->n_children++; - state->widget->children = g_renew(GladeChildInfo, state->widget->children, - state->widget->n_children); - info = &state->widget->children[state->widget->n_children-1]; - info->internal_child = NULL; - info->properties = NULL; - info->n_properties = 0; - info->child = NULL; - - for (i = 0; attrs && attrs[i] != NULL; i += 2) { - if (!xmlStrcmp(attrs[i], BAD_CAST("internal-child"))) - info->internal_child = glade_xml_alloc_string(state->interface, CAST_BAD(attrs[i+1])); - else - g_warning("unknown attribute `%s' for <child>.", attrs[i]); - } -} - -static void -glade_parser_start_document(GladeParseState *state) -{ - state->state = PARSER_START; - - state->unknown_depth = 0; - state->prev_state = PARSER_UNKNOWN; - - state->widget_depth = 0; - state->content = g_string_sized_new(128); - - state->interface = glade_parser_interface_new (); - state->widget = NULL; - - state->prop_type = PROP_NONE; - state->prop_name = NULL; - state->comment = NULL; - state->translate_prop = FALSE; - state->props = NULL; - - state->signals = NULL; - state->accels = NULL; -} - -static void -glade_parser_end_document(GladeParseState *state) -{ - g_string_free(state->content, TRUE); - - if (state->unknown_depth != 0) - g_warning("unknown_depth != 0 (%d)", state->unknown_depth); - if (state->widget_depth != 0) - g_warning("widget_depth != 0 (%d)", state->widget_depth); -} - -static void -glade_parser_comment (GladeParseState *state, const xmlChar *comment) -{ - if (state->state == PARSER_START) - state->interface->comment = g_strdup (CAST_BAD (comment)); -} - -static void -glade_parser_start_element(GladeParseState *state, - const xmlChar *name, const xmlChar **attrs) -{ - gint i; - - GLADE_NOTE(PARSER, g_message("<%s> in state %s", - name, state_names[state->state])); - - switch (state->state) { - case PARSER_START: - if (!xmlStrcmp(name, BAD_CAST("glade-interface"))) { - state->state = PARSER_GLADE_INTERFACE; -#if 0 - /* check for correct XML namespace */ - for (i = 0; attrs && attrs[i] != NULL; i += 2) { - if (!strcmp(attrs[i], "xmlns") && - !strcmp(attrs[i+1], "...")) { - g_warning("bad XML namespace `%s'.", attrs[i+1]); - } else - g_warning("unknown attribute `%s' for <glade-interface>", - attrs[i]); - } -#endif - } else { - g_warning("Expected <glade-interface>. Got <%s>.", name); - state->prev_state = state->state; - state->state = PARSER_UNKNOWN; - state->unknown_depth++; - } - break; - case PARSER_GLADE_INTERFACE: - if (!xmlStrcmp(name, BAD_CAST("requires"))) { - for (i = 0; attrs && attrs[i] != NULL; i += 2) { - if (!xmlStrcmp(attrs[i], BAD_CAST("lib"))) { - GladeInterface *iface = state->interface; - - /* add to the list of requirements for this module */ - iface->n_requires++; - iface->requires = g_renew(gchar *, iface->requires, - iface->n_requires); - iface->requires[iface->n_requires-1] = - glade_xml_alloc_string(iface, CAST_BAD(attrs[i+1])); - } else - g_warning("unknown attribute `%s' for <requires>.", - attrs[i]); - } - state->state = PARSER_REQUIRES; - } else if (!xmlStrcmp(name, BAD_CAST("widget"))) { - GladeInterface *iface = state->interface; - - iface->n_toplevels++; - iface->toplevels = g_renew(GladeWidgetInfo *, iface->toplevels, - iface->n_toplevels); - state->widget = create_widget_info(iface, attrs); - iface->toplevels[iface->n_toplevels-1] = state->widget; - - state->widget_depth++; - state->prop_type = PROP_NONE; - state->prop_name = NULL; - state->comment = NULL; - state->props = NULL; - state->signals = NULL; - state->accels = NULL; - - state->state = PARSER_WIDGET; - } else { - g_warning("Unexpected element <%s> inside <glade-interface>.", - name); - state->prev_state = state->state; - state->state = PARSER_UNKNOWN; - state->unknown_depth++; - } - break; - case PARSER_REQUIRES: - g_warning("<requires> element should be empty. Found <%s>.", name); - state->prev_state = state->state; - state->state = PARSER_UNKNOWN; - state->unknown_depth++; - break; - case PARSER_WIDGET: - if (!xmlStrcmp(name, BAD_CAST("property"))) { - gboolean bad_agent = FALSE; - - if (state->prop_type != PROP_NONE && - state->prop_type != PROP_WIDGET) - g_warning("non widget properties defined here (oh no!)"); - state->translate_prop = FALSE; - for (i = 0; attrs && attrs[i] != NULL; i += 2) { - if (!xmlStrcmp(attrs[i], BAD_CAST("name"))) - state->prop_name = glade_xml_alloc_propname(state->interface, - CAST_BAD(attrs[i+1])); - else if (!xmlStrcmp(attrs[i], BAD_CAST("translatable"))) - state->translate_prop = !xmlStrcmp(attrs[i+1], BAD_CAST("yes")); - else if (!xmlStrcmp(attrs[i], BAD_CAST("context"))) - state->context_prop = !xmlStrcmp(attrs[i+1], BAD_CAST("yes")); - else if (!xmlStrcmp(attrs[i], BAD_CAST("comments"))) - state->comment = glade_xml_alloc_string(state->interface, - CAST_BAD(attrs[i+1])); - else if (!xmlStrcmp(attrs[i], BAD_CAST("agent"))) - bad_agent = xmlStrcmp(attrs[i], BAD_CAST("libglade")) != 0; - else - g_warning("unknown attribute `%s' for <property>.", - attrs[i]); - } - if (bad_agent) { - /* ignore the property ... */ - state->prev_state = state->state; - state->state = PARSER_UNKNOWN; - state->unknown_depth++; - } else { - state->prop_type = PROP_WIDGET; - state->state = PARSER_WIDGET_PROPERTY; - } - } else if (!xmlStrcmp(name, BAD_CAST("accessibility"))) { - flush_properties(state); - - if (attrs != NULL && attrs[0] != NULL) - g_warning("<accessibility> element should have no attributes"); - state->state = PARSER_WIDGET_ATK; - } else if (!xmlStrcmp(name, BAD_CAST("signal"))) { - handle_signal(state, attrs); - state->state = PARSER_WIDGET_SIGNAL; - } else if (!xmlStrcmp(name, BAD_CAST("accelerator"))) { - handle_accel(state, attrs); - state->state = PARSER_WIDGET_ACCEL; - } else if (!xmlStrcmp(name, BAD_CAST("child"))) { - handle_child(state, attrs); - state->state = PARSER_WIDGET_CHILD; - } else { - g_warning("Unexpected element <%s> inside <widget>.", name); - state->prev_state = state->state; - state->state = PARSER_UNKNOWN; - state->unknown_depth++; - } - break; - case PARSER_WIDGET_PROPERTY: - g_warning("<property> element should be empty. Found <%s>.", name); - state->prev_state = state->state; - state->state = PARSER_UNKNOWN; - state->unknown_depth++; - break; - case PARSER_WIDGET_ATK: - if (!xmlStrcmp(name, BAD_CAST("atkproperty"))) { - if (state->prop_type != PROP_NONE && - state->prop_type != PROP_ATK) - g_warning("non atk properties defined here (oh no!)"); - state->prop_type = PROP_ATK; - state->translate_prop = FALSE; - for (i = 0; attrs && attrs[i] != NULL; i += 2) { - if (!xmlStrcmp(attrs[i], BAD_CAST("name"))) - state->prop_name = glade_xml_alloc_propname(state->interface, - CAST_BAD(attrs[i+1])); - else if (!xmlStrcmp(attrs[i], BAD_CAST("translatable"))) - state->translate_prop = !xmlStrcmp(attrs[i+1], BAD_CAST("yes")); - else if (!xmlStrcmp(attrs[i], BAD_CAST("context"))) - state->context_prop = !xmlStrcmp(attrs[i+1], BAD_CAST("yes")); - else if (!xmlStrcmp(attrs[i], BAD_CAST("comments"))) - state->comment = glade_xml_alloc_string(state->interface, - CAST_BAD(attrs[i+1])); - else - g_warning("unknown attribute `%s' for <atkproperty>.", - attrs[i]); - } - state->state = PARSER_WIDGET_ATK_PROPERTY; - } else if (!xmlStrcmp(name, BAD_CAST("atkaction"))) { - handle_atk_action(state, attrs); - state->state = PARSER_WIDGET_ATK_ACTION; - } else if (!xmlStrcmp(name, BAD_CAST("atkrelation"))) { - handle_atk_relation(state, attrs); - state->state = PARSER_WIDGET_ATK_RELATION; - } else { - g_warning("Unexpected element <%s> inside <accessibility>.", name); - state->prev_state = state->state; - state->state = PARSER_UNKNOWN; - state->unknown_depth++; - } - break; - case PARSER_WIDGET_ATK_PROPERTY: - if (!xmlStrcmp(name, BAD_CAST("accessibility"))) { - state->state = PARSER_WIDGET_ATK; - } else { - g_warning("Unexpected element <%s> inside <atkproperty>.", name); - state->prev_state = state->state; - state->state = PARSER_UNKNOWN; - state->unknown_depth++; - } - break; - case PARSER_WIDGET_ATK_ACTION: - g_warning("<atkaction> element should be empty. Found <%s>.", name); - state->prev_state = state->state; - state->state = PARSER_UNKNOWN; - state->unknown_depth++; - break; - case PARSER_WIDGET_ATK_RELATION: - g_warning("<atkrelation> element should be empty. Found <%s>.", name); - state->prev_state = state->state; - state->state = PARSER_UNKNOWN; - state->unknown_depth++; - break; - case PARSER_WIDGET_AFTER_ATK: - if (!xmlStrcmp(name, BAD_CAST("signal"))) { - handle_signal(state, attrs); - state->state = PARSER_WIDGET_SIGNAL; - } else if (!xmlStrcmp(name, BAD_CAST("accelerator"))) { - handle_accel(state, attrs); - state->state = PARSER_WIDGET_ACCEL; - } else if (!xmlStrcmp(name, BAD_CAST("child"))) { - handle_child(state, attrs); - state->state = PARSER_WIDGET_CHILD; - } else { - g_warning("Unexpected element <%s> inside <widget>.", name); - state->prev_state = state->state; - state->state = PARSER_UNKNOWN; - state->unknown_depth++; - } - break; - case PARSER_WIDGET_SIGNAL: - g_warning("<signal> element should be empty. Found <%s>.", name); - state->prev_state = state->state; - state->state = PARSER_UNKNOWN; - state->unknown_depth++; - break; - case PARSER_WIDGET_AFTER_SIGNAL: - if (!xmlStrcmp(name, BAD_CAST("accelerator"))) { - handle_accel(state, attrs); - state->state = PARSER_WIDGET_ACCEL; - } else if (!xmlStrcmp(name, BAD_CAST("child"))) { - handle_child(state, attrs); - state->state = PARSER_WIDGET_CHILD; - } else { - g_warning("Unexpected element <%s> inside <widget>.", name); - state->prev_state = state->state; - state->state = PARSER_UNKNOWN; - state->unknown_depth++; - } - break; - case PARSER_WIDGET_ACCEL: - g_warning("<accelerator> element should be empty. Found <%s>.", name); - state->prev_state = state->state; - state->state = PARSER_UNKNOWN; - state->unknown_depth++; - break; - case PARSER_WIDGET_AFTER_ACCEL: - if (!xmlStrcmp(name, BAD_CAST("child"))) { - handle_child(state, attrs); - state->state = PARSER_WIDGET_CHILD; - } else { - g_warning("Unexpected element <%s> inside <widget>.", name); - state->prev_state = state->state; - state->state = PARSER_UNKNOWN; - state->unknown_depth++; - } - break; - case PARSER_WIDGET_CHILD: - if (!xmlStrcmp(name, BAD_CAST("widget"))) { - GladeWidgetInfo *parent = state->widget; - GladeChildInfo *info = &parent->children[parent->n_children-1]; - - if (info->child) - g_warning("widget pointer already set!! not good"); - - state->widget = create_widget_info(state->interface, attrs); - info->child = state->widget; - info->child->parent = parent; - - state->widget_depth++; - state->prop_type = PROP_NONE; - state->prop_name = NULL; - state->comment = NULL; - state->props = NULL; - state->signals = NULL; - state->accels = NULL; - - state->state = PARSER_WIDGET; - } else if (!xmlStrcmp(name, BAD_CAST("placeholder"))) { - /* this isn't a real child, so load a NULL ChildInfo to - * symbolize a placeholder - */ - state->state = PARSER_WIDGET_CHILD_PLACEHOLDER; - } else { - g_warning("Unexpected element <%s> inside <child>.", name); - state->prev_state = state->state; - state->state = PARSER_UNKNOWN; - state->unknown_depth++; - } - break; - case PARSER_WIDGET_CHILD_AFTER_WIDGET: - if (!xmlStrcmp(name, BAD_CAST("packing"))) { - state->state = PARSER_WIDGET_CHILD_PACKING; - } else { - g_warning("Unexpected element <%s> inside <child>.", name); - state->prev_state = state->state; - state->state = PARSER_UNKNOWN; - state->unknown_depth++; - } - break; - case PARSER_WIDGET_CHILD_PACKING: - if (!xmlStrcmp(name, BAD_CAST("property"))) { - gboolean bad_agent = FALSE; - - if (state->prop_type != PROP_NONE && - state->prop_type != PROP_CHILD) - g_warning("non child properties defined here (oh no!)"); - state->translate_prop = FALSE; - for (i = 0; attrs && attrs[i] != NULL; i += 2) { - if (!xmlStrcmp(attrs[i], BAD_CAST("name"))) - state->prop_name = glade_xml_alloc_propname(state->interface, - CAST_BAD(attrs[i+1])); - else if (!xmlStrcmp(attrs[i], BAD_CAST("translatable"))) - state->translate_prop = !xmlStrcmp(attrs[i+1], BAD_CAST("yes")); - else if (!xmlStrcmp(attrs[i], BAD_CAST("context"))) - state->context_prop = !xmlStrcmp(attrs[i+1], BAD_CAST("yes")); - else if (!xmlStrcmp(attrs[i], BAD_CAST("comments"))) - state->comment = glade_xml_alloc_string(state->interface, - CAST_BAD(attrs[i+1])); - else if (!xmlStrcmp(attrs[i], BAD_CAST("agent"))) - bad_agent = xmlStrcmp(attrs[i], BAD_CAST("libglade")) != 0; - else - g_warning("unknown attribute `%s' for <property>.", - attrs[i]); - } - if (bad_agent) { - /* ignore the property ... */ - state->prev_state = state->state; - state->state = PARSER_UNKNOWN; - state->unknown_depth++; - } else { - state->prop_type = PROP_CHILD; - state->state = PARSER_WIDGET_CHILD_PACKING_PROPERTY; - } - } else { - g_warning("Unexpected element <%s> inside <child>.", name); - state->prev_state = state->state; - state->state = PARSER_UNKNOWN; - state->unknown_depth++; - } - break; - case PARSER_WIDGET_CHILD_PACKING_PROPERTY: - g_warning("<property> element should be empty. Found <%s>.", name); - state->prev_state = state->state; - state->state = PARSER_UNKNOWN; - state->unknown_depth++; - break; - case PARSER_WIDGET_CHILD_AFTER_PACKING: - g_warning("<child> should have no elements after <packing>. Found <%s>.", name); - state->prev_state = state->state; - state->state = PARSER_UNKNOWN; - state->unknown_depth++; - break; - case PARSER_WIDGET_CHILD_PLACEHOLDER: - g_warning("<placeholder> should be empty. Found <%s>.", name); - state->prev_state = state->state; - state->state = PARSER_UNKNOWN; - state->unknown_depth++; - break; - case PARSER_WIDGET_CHILD_AFTER_PLACEHOLDER: - /* Get packing info on placeholders, for special cases */ - if (!xmlStrcmp(name, BAD_CAST("packing"))) { - state->state = PARSER_WIDGET_CHILD_PACKING; - } else { - g_warning("Unexpected element <%s> inside <child>.", name); - state->prev_state = state->state; - state->state = PARSER_UNKNOWN; - state->unknown_depth++; - } - break; - case PARSER_FINISH: - g_warning("There should be no elements here. Found <%s>.", name); - state->prev_state = state->state; - state->state = PARSER_UNKNOWN; - state->unknown_depth++; - break; - case PARSER_UNKNOWN: - state->unknown_depth++; - break; - } - /* truncate the content string ... */ - g_string_truncate(state->content, 0); -} - -static void -glade_parser_end_element(GladeParseState *state, const xmlChar *name) -{ - GladePropInfo prop; - - GLADE_NOTE(PARSER, g_message("</%s> in state %s", - name, state_names[state->state])); - - switch (state->state) { - case PARSER_START: - g_warning("should not be closing any elements in this state"); - break; - case PARSER_GLADE_INTERFACE: - if (xmlStrcmp(name, BAD_CAST("glade-interface")) != 0) - g_warning("should find </glade-interface> here. Found </%s>", - name); - state->state = PARSER_FINISH; - break; - case PARSER_REQUIRES: - if (xmlStrcmp(name, BAD_CAST("requires")) != 0) - g_warning("should find </requires> here. Found </%s>", name); - state->state = PARSER_GLADE_INTERFACE; - break; - case PARSER_WIDGET: - case PARSER_WIDGET_AFTER_ATK: - case PARSER_WIDGET_AFTER_SIGNAL: - case PARSER_WIDGET_AFTER_ACCEL: - if (xmlStrcmp(name, BAD_CAST("widget")) != 0) - g_warning("should find </widget> here. Found </%s>", name); - flush_properties(state); - flush_signals(state); - flush_actions(state); - flush_relations(state); - flush_accels(state); - state->widget = state->widget->parent; - state->widget_depth--; - - if (state->widget_depth == 0) - state->state = PARSER_GLADE_INTERFACE; - else - state->state = PARSER_WIDGET_CHILD_AFTER_WIDGET; - break; - case PARSER_WIDGET_PROPERTY: - if (xmlStrcmp(name, BAD_CAST("property")) != 0) - g_warning("should find </property> here. Found </%s>", name); - if (!state->props) - state->props = g_array_new(FALSE, FALSE, sizeof(GladePropInfo)); - - prop.name = state->prop_name; - prop.has_context = state->context_prop; - prop.translatable = state->translate_prop; - prop.comment = state->comment; - prop.value = glade_xml_alloc_string(state->interface, state->content->str); - - g_array_append_val(state->props, prop); - state->prop_name = NULL; - state->comment = NULL; - state->state = PARSER_WIDGET; - break; - case PARSER_WIDGET_ATK: - if (xmlStrcmp(name, BAD_CAST("accessibility")) != 0) - g_warning("should find </accessibility> here. Found </%s>", name); - flush_properties(state); /* flush the ATK properties */ - state->state = PARSER_WIDGET_AFTER_ATK; - break; - case PARSER_WIDGET_ATK_PROPERTY: - if (xmlStrcmp(name, BAD_CAST("atkproperty")) != 0) - g_warning("should find </atkproperty> here. Found </%s>", name); - if (!state->props) - state->props = g_array_new(FALSE, FALSE, sizeof(GladePropInfo)); - prop.name = state->prop_name; - prop.has_context = state->context_prop; - prop.translatable = state->translate_prop; - prop.comment = state->comment; - prop.value = glade_xml_alloc_string(state->interface, state->content->str); - - g_array_append_val(state->props, prop); - state->prop_name = NULL; - state->comment = NULL; - - state->state = PARSER_WIDGET_ATK; - break; - case PARSER_WIDGET_ATK_ACTION: - if (xmlStrcmp(name, BAD_CAST("atkaction")) != 0) - g_warning("should find </atkaction> here. Found </%s>", name); - state->prop_name = NULL; - state->state = PARSER_WIDGET_ATK; - break; - case PARSER_WIDGET_ATK_RELATION: - if (xmlStrcmp(name, BAD_CAST("atkrelation")) != 0) - g_warning("should find </atkrelation> here. Found </%s>", name); - state->prop_name = NULL; - state->state = PARSER_WIDGET_ATK; - break; - case PARSER_WIDGET_SIGNAL: - if (xmlStrcmp(name, BAD_CAST("signal")) != 0) - g_warning("should find </signal> here. Found </%s>", name); - state->state = PARSER_WIDGET_AFTER_ATK; - break; - case PARSER_WIDGET_ACCEL: - if (xmlStrcmp(name, BAD_CAST("accelerator")) != 0) - g_warning("should find </accelerator> here. Found </%s>", name); - state->state = PARSER_WIDGET_AFTER_SIGNAL; - break; - case PARSER_WIDGET_CHILD: - if (xmlStrcmp(name, BAD_CAST("child")) != 0) - g_warning("should find </child> here. Found </%s>", name); - /* if we are ending the element in this state, then there - * hasn't been a <widget> element inside this <child> - * element. (If there was, then we would be in - * PARSER_WIDGET_CHILD_AFTER_WIDGET state. */ - g_warning("no <widget> element found inside <child>. Discarding"); - g_free(state->widget->children[ - state->widget->n_children-1].properties); - state->widget->n_children--; - state->state = PARSER_WIDGET_AFTER_ACCEL; - break; - case PARSER_WIDGET_CHILD_AFTER_WIDGET: - if (xmlStrcmp(name, BAD_CAST("child")) != 0) - g_warning("should find </child> here. Found </%s>", name); - state->state = PARSER_WIDGET_AFTER_ACCEL; - break; - case PARSER_WIDGET_CHILD_PACKING: - if (xmlStrcmp(name, BAD_CAST("packing")) != 0) - g_warning("should find </packing> here. Found </%s>", name); - state->state = PARSER_WIDGET_CHILD_AFTER_PACKING; - flush_properties(state); /* flush the properties. */ - break; - case PARSER_WIDGET_CHILD_PACKING_PROPERTY: - if (xmlStrcmp(name, BAD_CAST("property")) != 0) - g_warning("should find </property> here. Found </%s>", name); - if (!state->props) - state->props = g_array_new(FALSE, FALSE, sizeof(GladePropInfo)); - - prop.name = state->prop_name; - prop.has_context = state->context_prop; - prop.translatable = state->translate_prop; - prop.comment = state->comment; - prop.value = glade_xml_alloc_string(state->interface, state->content->str); - - g_array_append_val(state->props, prop); - state->prop_name = NULL; - state->comment = NULL; - - state->state = PARSER_WIDGET_CHILD_PACKING; - break; - case PARSER_WIDGET_CHILD_AFTER_PACKING: - if (xmlStrcmp(name, BAD_CAST("child")) != 0) - g_warning("should find </child> here. Found </%s>", name); - state->state = PARSER_WIDGET_AFTER_ACCEL; - break; - case PARSER_WIDGET_CHILD_PLACEHOLDER: - if (xmlStrcmp(name, BAD_CAST("placeholder")) != 0) - g_warning("should find </placeholder> here. Found </%s>", name); - state->state = PARSER_WIDGET_CHILD_AFTER_PLACEHOLDER; - break; - case PARSER_WIDGET_CHILD_AFTER_PLACEHOLDER: - if (xmlStrcmp(name, BAD_CAST("child")) != 0) - g_warning("should find </child> here. Found </%s>", name); - state->state = PARSER_WIDGET_AFTER_ACCEL; - break; - case PARSER_FINISH: - g_warning("should not be closing any elements in this state"); - break; - case PARSER_UNKNOWN: - state->unknown_depth--; - if (state->unknown_depth == 0) - state->state = state->prev_state; - break; - } -} - -static void -glade_parser_characters(GladeParseState *state, const xmlChar *chars, gint len) -{ - switch (state->state) { - case PARSER_WIDGET_PROPERTY: - case PARSER_WIDGET_ATK_PROPERTY: - case PARSER_WIDGET_CHILD_PACKING_PROPERTY: - g_string_append_len(state->content, CAST_BAD(chars), len); - break; - default: - /* don't care about content in any other states */ - break; - } -} - -static xmlEntityPtr -glade_parser_get_entity(GladeParseState *state, const xmlChar *name) -{ - return xmlGetPredefinedEntity(name); -} - -static void -glade_parser_warning(GladeParseState *state, const gchar *msg, ...) -{ - va_list args; - - va_start(args, msg); - g_logv("XML", G_LOG_LEVEL_WARNING, msg, args); - va_end(args); -} - -static void -glade_parser_error(GladeParseState *state, const gchar *msg, ...) -{ - va_list args; - - va_start(args, msg); - g_logv("XML", G_LOG_LEVEL_CRITICAL, msg, args); - va_end(args); -} - -static void -glade_parser_fatal_error(GladeParseState *state, const gchar *msg, ...) -{ - va_list args; - - va_start(args, msg); - g_logv("XML", G_LOG_LEVEL_ERROR, msg, args); - va_end(args); -} - -static xmlSAXHandler glade_parser = { - 0, /* internalSubset */ - 0, /* isStandalone */ - 0, /* hasInternalSubset */ - 0, /* hasExternalSubset */ - 0, /* resolveEntity */ - (getEntitySAXFunc)glade_parser_get_entity, /* getEntity */ - 0, /* entityDecl */ - 0, /* notationDecl */ - 0, /* attributeDecl */ - 0, /* elementDecl */ - 0, /* unparsedEntityDecl */ - 0, /* setDocumentLocator */ - (startDocumentSAXFunc)glade_parser_start_document, /* startDocument */ - (endDocumentSAXFunc)glade_parser_end_document, /* endDocument */ - (startElementSAXFunc)glade_parser_start_element, /* startElement */ - (endElementSAXFunc)glade_parser_end_element, /* endElement */ - 0, /* reference */ - (charactersSAXFunc)glade_parser_characters, /* characters */ - 0, /* ignorableWhitespace */ - 0, /* processingInstruction */ - (commentSAXFunc)glade_parser_comment, /* comment */ - (warningSAXFunc)glade_parser_warning, /* warning */ - (errorSAXFunc)glade_parser_error, /* error */ - (fatalErrorSAXFunc)glade_parser_fatal_error, /* fatalError */ -}; - -static void -widget_info_free(GladeWidgetInfo *info) -{ - gint i; - - if (!info) return; - - g_free(info->properties); - g_free(info->atk_props); - g_free(info->signals); - g_free(info->accels); - - for (i = 0; i < info->n_children; i++) { - g_free(info->children[i].properties); - widget_info_free(info->children[i].child); - } - g_free(info->children); - g_free(info); -} - -/** - * glade_parser_interface_new - * - * Returns a newly allocated GladeInterface. - */ -GladeInterface * -glade_parser_interface_new () -{ - GladeInterface *interface; - interface = g_new0 (GladeInterface, 1); - interface->names = g_hash_table_new (g_str_hash, g_str_equal); - interface->strings = g_hash_table_new_full (g_str_hash, - g_str_equal, - (GDestroyNotify)g_free, - NULL); - return interface; -} - -/** - * glade_parser_interface_destroy - * @interface: the GladeInterface structure. - * - * Frees a GladeInterface structure. - */ -void -glade_parser_interface_destroy (GladeInterface *interface) -{ - gint i; - - g_return_if_fail(interface != NULL); - - /* free requirements */ - g_free(interface->requires); - - for (i = 0; i < interface->n_toplevels; i++) - widget_info_free(interface->toplevels[i]); - g_free(interface->toplevels); - - g_hash_table_destroy(interface->names); - - /* free the strings hash table. The destroy notify will take care - * of the strings. */ - g_hash_table_destroy(interface->strings); - - g_free (interface->comment); - - g_free(interface); -} - -/** - * glade_parser_interface_new_from_file - * @file: the filename of the glade XML file. - * @domain: the translation domain for the XML file. - * - * This function parses a Glade XML interface file to a GladeInterface - * object (which is libglade's internal representation of the - * interface data). - * - * Generally, user code won't need to call this function. Instead, it - * should go through the GladeXML interfaces. - * - * Returns: the GladeInterface structure for the XML file. - */ -GladeInterface * -glade_parser_interface_new_from_file (const gchar *file, const gchar *domain) -{ - GladeParseState state = { 0 }; - int prevSubstituteEntities; - int rc; - - if (!g_file_test(file, G_FILE_TEST_IS_REGULAR)) { - glade_util_ui_message (glade_app_get_window (), - GLADE_UI_ERROR, - _("Could not find glade file %s"), file); - return NULL; - } - - state.interface = NULL; - if (domain) - state.domain = domain; - else - state.domain = textdomain(NULL); - - prevSubstituteEntities = xmlSubstituteEntitiesDefault(1); - - rc = xmlSAXUserParseFile(&glade_parser, &state, file); - - xmlSubstituteEntitiesDefault(prevSubstituteEntities); - - if (rc < 0) { - glade_util_ui_message (glade_app_get_window (), - GLADE_UI_ERROR, - _("Errors parsing glade file %s"), file); - if (state.interface) - glade_parser_interface_destroy (state.interface); - return NULL; - } - if (state.state != PARSER_FINISH) { - glade_util_ui_message (glade_app_get_window (), - GLADE_UI_ERROR, - _("Errors parsing glade file %s"), file); - if (state.interface) - glade_parser_interface_destroy(state.interface); - return NULL; - } - return state.interface; -} - -/** - * glade_parser_interface_new_from_buffer - * @buffer: a buffer in memory containing XML data. - * @len: the length of @buffer. - * @domain: the translation domain for the XML file. - * - * This function is similar to glade_parser_parse_file, except that it - * parses XML data from a buffer in memory. This could be used to - * embed an interface into the executable, for instance. - * - * Generally, user code won't need to call this function. Instead, it - * should go through the GladeXML interfaces. - * - * Returns: the GladeInterface structure for the XML buffer. - */ -GladeInterface * -glade_parser_interface_new_from_buffer (const gchar *buffer, - gint len, - const gchar *domain) -{ - GladeParseState state = { 0 }; - int prevSubstituteEntities; - int rc; - - state.interface = NULL; - if (domain) - state.domain = domain; - else - state.domain = textdomain(NULL); - - prevSubstituteEntities = xmlSubstituteEntitiesDefault(1); - - rc = xmlSAXUserParseMemory(&glade_parser, &state, buffer, len); - - xmlSubstituteEntitiesDefault(prevSubstituteEntities); - - if (rc < 0) { - g_warning("document not well formed!"); - if (state.interface) - glade_parser_interface_destroy (state.interface); - return NULL; - } - if (state.state != PARSER_FINISH) { - g_warning("did not finish in PARSER_FINISH state!"); - if (state.interface) - glade_parser_interface_destroy(state.interface); - return NULL; - } - return state.interface; -} - -static gchar * -modifier_string_from_bits (GdkModifierType modifiers) -{ - GString *string = g_string_new (""); - - if (modifiers & GDK_SHIFT_MASK) { - if (string->len > 0) - g_string_append (string, " | "); - g_string_append (string, "GDK_SHIFT_MASK"); - } - - if (modifiers & GDK_LOCK_MASK) { - if (string->len > 0) - g_string_append (string, " | "); - g_string_append (string, "GDK_LOCK_MASK"); - } - - if (modifiers & GDK_CONTROL_MASK) { - if (string->len > 0) - g_string_append (string, " | "); - g_string_append (string, "GDK_CONTROL_MASK"); - } - - if (modifiers & GDK_MOD1_MASK) { - if (string->len > 0) - g_string_append (string, " | "); - g_string_append (string, "GDK_MOD1_MASK"); - } - - if (modifiers & GDK_MOD2_MASK) { - if (string->len > 0) - g_string_append (string, " | "); - g_string_append (string, "GDK_MOD2_MASK"); - } - - if (modifiers & GDK_MOD3_MASK) { - if (string->len > 0) - g_string_append (string, " | "); - g_string_append (string, "GDK_MOD3_MASK"); - } - - if (modifiers & GDK_MOD4_MASK) { - if (string->len > 0) - g_string_append (string, " | "); - g_string_append (string, "GDK_MOD4_MASK"); - } - - if (modifiers & GDK_MOD5_MASK) { - if (string->len > 0) - g_string_append (string, " | "); - g_string_append (string, "GDK_MOD5_MASK"); - } - - if (modifiers & GDK_BUTTON1_MASK) { - if (string->len > 0) - g_string_append (string, " | "); - g_string_append (string, "GDK_BUTTON1_MASK"); - } - - if (modifiers & GDK_BUTTON2_MASK) { - if (string->len > 0) - g_string_append (string, " | "); - g_string_append (string, "GDK_BUTTON2_MASK"); - } - - if (modifiers & GDK_BUTTON3_MASK) { - if (string->len > 0) - g_string_append (string, " | "); - g_string_append (string, "GDK_BUTTON3_MASK"); - } - - if (modifiers & GDK_BUTTON4_MASK) { - if (string->len > 0) - g_string_append (string, " | "); - g_string_append (string, "GDK_BUTTON4_MASK"); - } - - if (modifiers & GDK_BUTTON5_MASK) { - if (string->len > 0) - g_string_append (string, " | "); - g_string_append (string, "GDK_BUTTON5_MASK"); - } - - if (modifiers & GDK_RELEASE_MASK) { - if (string->len > 0) - g_string_append (string, " | "); - g_string_append (string, "GDK_RELEASE_MASK"); - } - - if (string->len > 0) - return g_string_free (string, FALSE); - - g_string_free (string, TRUE); - return NULL; -} - -static void -dump_widget(xmlNode *parent, GladeWidgetInfo *info, gint indent) -{ - xmlNode *widget; - gint i, j; - - if (info == NULL) { - widget = xmlNewNode(NULL, BAD_CAST("placeholder")); - xmlAddChild(parent, widget); - return; - } - - widget = xmlNewNode(NULL, BAD_CAST("widget")); - - xmlSetProp(widget, BAD_CAST("class"), BAD_CAST(info->classname)); - xmlSetProp(widget, BAD_CAST("id"), BAD_CAST(info->name)); - xmlAddChild(parent, widget); - xmlNodeAddContent(widget, BAD_CAST("\n")); - - for (i = 0; i < info->n_properties; i++) { - xmlNode *node; - - for (j = 0; j < indent + 1; j++) - xmlNodeAddContent(widget, BAD_CAST(" ")); - node = xmlNewNode(NULL, BAD_CAST("property")); - xmlSetProp(node, BAD_CAST("name"), BAD_CAST(info->properties[i].name)); - if (info->properties[i].translatable) - xmlSetProp(node, BAD_CAST("translatable"), BAD_CAST("yes")); - if (info->properties[i].has_context) - xmlSetProp(node, BAD_CAST("context"), BAD_CAST("yes")); - if (info->properties[i].comment) - xmlSetProp(node, BAD_CAST("comments"), - BAD_CAST(info->properties[i].comment)); - xmlNodeSetContent(node, BAD_CAST(info->properties[i].value)); - xmlAddChild(widget, node); - xmlNodeAddContent(widget, BAD_CAST("\n")); - } - - if (info->n_atk_props != 0 || - info->n_atk_actions != 0 || - info->n_relations != 0) { - xmlNode *atk; - - for (j = 0; j < indent + 1; j++) - xmlNodeAddContent(widget, BAD_CAST(" ")); - atk = xmlNewNode(NULL, BAD_CAST("accessibility")); - xmlAddChild(widget, atk); - xmlNodeAddContent(widget, BAD_CAST("\n")); - xmlNodeAddContent(atk, BAD_CAST("\n")); - - for (i = 0; i < info->n_atk_props; i++) { - xmlNode *node; - - for (j = 0; j < indent + 2; j++) - xmlNodeAddContent(atk, BAD_CAST(" ")); - node = xmlNewNode(NULL, BAD_CAST("atkproperty")); - xmlSetProp(node, BAD_CAST("name"), BAD_CAST(info->atk_props[i].name)); - if (info->atk_props[i].translatable) - xmlSetProp(node, BAD_CAST("translatable"), BAD_CAST("yes")); - if (info->atk_props[i].has_context) - xmlSetProp(node, BAD_CAST("context"), BAD_CAST("yes")); - if (info->atk_props[i].comment) - xmlSetProp(node, BAD_CAST("comments"), - BAD_CAST(info->atk_props[i].comment)); - xmlNodeSetContent(node, BAD_CAST(info->atk_props[i].value)); - xmlAddChild(atk, node); - xmlNodeAddContent(atk, BAD_CAST("\n")); - } - - for (i = 0; i < info->n_atk_actions; i++) { - xmlNode *node; - - for (j = 0; j < indent + 2; j++) - xmlNodeAddContent(atk, BAD_CAST(" ")); - node = xmlNewNode(NULL, BAD_CAST("atkaction")); - xmlSetProp(node, BAD_CAST("action_name"), - BAD_CAST(info->atk_actions[i].action_name)); - xmlSetProp(node, BAD_CAST("description"), - BAD_CAST(info->atk_actions[i].description)); - xmlAddChild(atk, node); - xmlNodeAddContent(atk, BAD_CAST("\n")); - } - - for (i = 0; i < info->n_relations; i++) { - xmlNode *node; - - for (j = 0; j < indent + 2; j++) - xmlNodeAddContent(atk, BAD_CAST(" ")); - node = xmlNewNode(NULL, BAD_CAST("atkrelation")); - xmlSetProp(node, BAD_CAST("target"), - BAD_CAST(info->relations[i].target)); - xmlSetProp(node, BAD_CAST("type"), - BAD_CAST(info->relations[i].type)); - xmlAddChild(atk, node); - xmlNodeAddContent(atk, BAD_CAST("\n")); - } - - for (j = 0; j < indent + 1; j++) - xmlNodeAddContent(atk, BAD_CAST(" ")); - } - - for (i = 0; i < info->n_signals; i++) { - xmlNode *node; - - for (j = 0; j < indent + 1; j++) - xmlNodeAddContent(widget, BAD_CAST(" ")); - - node = xmlNewNode(NULL, BAD_CAST("signal")); - xmlSetProp(node, BAD_CAST("name"), BAD_CAST(info->signals[i].name)); - xmlSetProp(node, BAD_CAST("handler"), BAD_CAST(info->signals[i].handler)); - if (info->signals[i].after) - xmlSetProp(node, BAD_CAST("after"), BAD_CAST("yes")); - if (info->signals[i].lookup) - xmlSetProp(node, BAD_CAST("lookup"), BAD_CAST("yes")); - if (info->signals[i].object) - xmlSetProp(node, BAD_CAST("object"), BAD_CAST(info->signals[i].object)); - xmlAddChild(widget, node); - xmlNodeAddContent(widget, BAD_CAST("\n")); - } - - for (i = 0; i < info->n_accels; i++) { - xmlNode *node; - gchar *modifiers; - - modifiers = modifier_string_from_bits (info->accels[i].modifiers); - - for (j = 0; j < indent + 1; j++) - xmlNodeAddContent(widget, BAD_CAST(" ")); - - node = xmlNewNode(NULL, BAD_CAST("accelerator")); - xmlSetProp(node, BAD_CAST("key"), BAD_CAST(gdk_keyval_name(info->accels[i].key))); - xmlSetProp(node, BAD_CAST("modifiers"), BAD_CAST(modifiers)); - xmlSetProp(node, BAD_CAST("signal"), BAD_CAST(info->accels[i].signal)); - xmlAddChild(widget, node); - xmlNodeAddContent(widget, BAD_CAST("\n")); - - if (modifiers) - g_free (modifiers); - } - - for (i = 0; i < info->n_children; i++) { - xmlNode *child, *packing; - GladeChildInfo *childinfo = &info->children[i]; - gint k; - - for (j = 0; j < indent + 1; j++) - xmlNodeAddContent(widget, BAD_CAST(" ")); - - child = xmlNewNode(NULL, BAD_CAST("child")); - if (childinfo->internal_child) - xmlSetProp(child, BAD_CAST("internal-child"), BAD_CAST(childinfo->internal_child)); - xmlAddChild(widget, child); - xmlNodeAddContent(widget, BAD_CAST("\n")); - xmlNodeAddContent(child, BAD_CAST("\n")); - - for (j = 0; j < indent + 2; j++) - xmlNodeAddContent(child, BAD_CAST(" ")); - dump_widget(child, childinfo->child, indent + 2); - xmlNodeAddContent(child, BAD_CAST("\n")); - - if (childinfo->n_properties) { - for (j = 0; j < indent + 2; j++) - xmlNodeAddContent(child, BAD_CAST(" ")); - packing = xmlNewNode(NULL, BAD_CAST("packing")); - xmlAddChild(child, packing); - xmlNodeAddContent(packing, BAD_CAST("\n")); - - for (k = 0; k < childinfo->n_properties; k++) { - xmlNode *node; - - for (j = 0; j < indent + 3; j++) - xmlNodeAddContent(packing, BAD_CAST(" ")); - node = xmlNewNode(NULL, BAD_CAST("property")); - xmlSetProp(node, BAD_CAST("name"), BAD_CAST(childinfo->properties[k].name)); - if (childinfo->properties[k].translatable) - xmlSetProp(node, BAD_CAST("translatable"), BAD_CAST("yes")); - if (childinfo->properties[k].has_context) - xmlSetProp(node, BAD_CAST("context"), BAD_CAST("yes")); - if (childinfo->properties[k].comment) - xmlSetProp(node, BAD_CAST("comments"), - BAD_CAST(childinfo->properties[k].comment)); - xmlNodeSetContent(node, BAD_CAST(childinfo->properties[k].value)); - xmlAddChild(packing, node); - xmlNodeAddContent(packing, BAD_CAST("\n")); - } - } - - if (childinfo->n_properties) { - for (j = 0; j < indent + 2; j++) - xmlNodeAddContent(packing, BAD_CAST(" ")); - xmlNodeAddContent(child, BAD_CAST("\n")); - } - - for (j = 0; j < indent + 1; j++) - xmlNodeAddContent(child, BAD_CAST(" ")); - } - - for (j = 0; j < indent; j++) - xmlNodeAddContent(widget, BAD_CAST(" ")); -} - -static xmlDoc * -glade_interface_make_doc (GladeInterface *interface) -{ - xmlDoc *doc; - xmlNode *root, *comment; - gint i; - - doc = xmlNewDoc(BAD_CAST("1.0")); - doc->standalone = FALSE; - xmlCreateIntSubset(doc, BAD_CAST("glade-interface"), - NULL, BAD_CAST("glade-2.0.dtd")); - - if (interface->comment) - { - comment = xmlNewComment(BAD_CAST (interface->comment)); - xmlDocSetRootElement(doc, comment); - } - - root = xmlNewNode(NULL, BAD_CAST("glade-interface")); - xmlDocSetRootElement(doc, root); - - xmlNodeAddContent(root, BAD_CAST("\n")); - - for (i = 0; i < interface->n_requires; i++) { - xmlNode *node = xmlNewNode(NULL, BAD_CAST("requires")); - - xmlSetProp(node, BAD_CAST("lib"), BAD_CAST(interface->requires[i])); - - xmlNodeAddContent(root, BAD_CAST(" ")); - xmlAddChild(root, node); - xmlNodeAddContent(root, BAD_CAST("\n")); - } - - for (i = 0; i < interface->n_toplevels; i++) { - xmlNodeAddContent(root, BAD_CAST(" ")); - dump_widget(root, interface->toplevels[i], 1); - xmlNodeAddContent(root, BAD_CAST("\n")); - } - return doc; -} - -static void -glade_interface_buffer (GladeInterface *interface, - gpointer *buffer, - gint *size) -{ - xmlDoc *doc; - g_return_if_fail (interface != NULL); - g_return_if_fail (buffer != NULL); - g_return_if_fail (size != NULL); - - doc = glade_interface_make_doc (interface); - xmlDocDumpFormatMemoryEnc(doc, (xmlChar **)buffer, - size, "UTF-8", TRUE); - xmlFreeDoc(doc); -} - -/** - * glade_parser_interface_dump - * @interface: the GladeInterface - * @filename: the filename to write the interface data to. - * @error: a #GError for error handleing. - * - * This function dumps the contents of a GladeInterface into a file as - * XML. It is used by glade to write glade files. - * - * Returns whether the write was successfull or not. - */ -gboolean -glade_parser_interface_dump (GladeInterface *interface, - const gchar *filename, - GError **error) -{ - GIOChannel *fd; - gpointer buffer; - gint size, retval = G_IO_STATUS_ERROR; - - glade_interface_buffer (interface, &buffer, &size); - - if (buffer == NULL) - { - g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_NOMEM, - _("Could not allocate memory for interface")); - return FALSE; - } - - if ((fd = g_io_channel_new_file (filename, "w", error))) - { - retval = g_io_channel_write_chars (fd, buffer, size, NULL, error); - g_io_channel_shutdown(fd, TRUE, NULL); - g_io_channel_unref (fd); - } - - xmlFree (buffer); - - return (retval == G_IO_STATUS_NORMAL) ? TRUE : FALSE; -} - -G_CONST_RETURN gchar * -glade_parser_pvalue_from_winfo (GladeWidgetInfo *winfo, - const gchar *pname) -{ - gchar *dup_name = g_strdup (pname); - gint i; - - /* Make '_' & '-' synonymous here for convenience. - */ - glade_util_replace (dup_name, '-', '_'); - for (i = 0; i < winfo->n_properties; i++) - { - if (!strcmp (pname, winfo->properties[i].name) || - !strcmp (dup_name, winfo->properties[i].name)) - return winfo->properties[i].value; - } - return NULL; -} - - -#if 0 -int -main(int argc, char **argv) { - gtk_init(&argc, &argv); - if (argc > 1) { - GladeInterface *interface = glade_parser_parse_file(argv[1]); - g_message("output: %p", interface); - if (interface) { - glade_interface_dump(interface, "/dev/stdout"); - glade_interface_destroy(interface); - } - } else - g_message("need filename"); - return 0; -} -#endif diff --git a/gladeui/glade-parser.h b/gladeui/glade-parser.h deleted file mode 100644 index d849161f..00000000 --- a/gladeui/glade-parser.h +++ /dev/null @@ -1,152 +0,0 @@ -/* -*- Mode: C; c-basic-offset: 4 -*- - * libglade - a library for building interfaces from XML files at runtime - * Copyright (C) 1998-2002 James Henstridge <james@daa.com.au> - * - * glade-parser.h: functions for parsing glade-2.0 files - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef __GLADE_PARSER_H__ -#define __GLADE_PARSER_H__ - -#include <glib.h> -#include <gdk/gdk.h> - -G_BEGIN_DECLS - -#define CAST_BAD (gchar *) - -typedef struct _GladePropInfo GladePropInfo; -typedef struct _GladeSignalInfo GladeSignalInfo; -typedef struct _GladeAtkActionInfo GladeAtkActionInfo; -typedef struct _GladeAccelInfo GladeAccelInfo; -typedef struct _GladeWidgetInfo GladeWidgetInfo; -typedef struct _GladeChildInfo GladeChildInfo; -typedef struct _GladeInterface GladeInterface; -typedef struct _GladeAtkRelationInfo GladeAtkRelationInfo; -typedef struct _GladePackingDefault GladePackingDefault; - -struct _GladePropInfo { - gchar *name; - gchar *value; - gchar *comment; - guint translatable : 1; - guint has_context : 1; -}; - -struct _GladeSignalInfo { - gchar *name; - gchar *handler; - gchar *object; /* represents userdata, if lookup is FALSE, then do connect_object with a - * widget looked up by name, otherwise g_module_lookup() */ - guint after : 1; - guint lookup : 1; -}; - -struct _GladePackingDefault { - gchar *id; - gchar *value; -}; - -struct _GladeAtkActionInfo { - gchar *action_name; - gchar *description; -}; - -struct _GladeAtkRelationInfo { - gchar *target; - gchar *type; -}; - -struct _GladeAccelInfo { - guint key; - GdkModifierType modifiers; - gchar *signal; -}; - -struct _GladeWidgetInfo { - GladeWidgetInfo *parent; - - gchar *classname; - gchar *name; - - GladePropInfo *properties; - guint n_properties; - - GladePropInfo *atk_props; - guint n_atk_props; - - GladeSignalInfo *signals; - guint n_signals; - - GladeAtkActionInfo *atk_actions; - guint n_atk_actions; - - GladeAtkRelationInfo *relations; - guint n_relations; - - GladeAccelInfo *accels; - guint n_accels; - - GladeChildInfo *children; - guint n_children; -}; - -struct _GladeChildInfo { - GladePropInfo *properties; - guint n_properties; - - GladeWidgetInfo *child; - gchar *internal_child; -}; - -struct _GladeInterface { - gchar **requires; - guint n_requires; - - GladeWidgetInfo **toplevels; - guint n_toplevels; - - GHashTable *names; - - GHashTable *strings; - - gchar *comment; -}; - -/* the actual functions ... */ -GladeInterface *glade_parser_interface_new (void); - -GladeInterface *glade_parser_interface_new_from_file (const gchar *file, - const gchar *domain); - -GladeInterface *glade_parser_interface_new_from_buffer (const gchar *buffer, - gint len, - const gchar *domain); - -void glade_parser_interface_destroy (GladeInterface *interface); - -gboolean glade_parser_interface_dump (GladeInterface *interface, - const gchar *filename, - GError **error); - -G_CONST_RETURN gchar *glade_parser_pvalue_from_winfo (GladeWidgetInfo *winfo, - const gchar *pname); - -G_END_DECLS - -#endif diff --git a/gladeui/glade-placeholder.c b/gladeui/glade-placeholder.c deleted file mode 100644 index 2ca84444..00000000 --- a/gladeui/glade-placeholder.c +++ /dev/null @@ -1,410 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2003, 2004 Joaquin Cuenca Abela - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Authors: - * Joaquin Cuenca Abela <e98cuenc@yahoo.com> - */ - -#include "config.h" - -#include <gtk/gtk.h> -#include "glade.h" -#include "glade-placeholder.h" -#include "glade-xml-utils.h" -#include "glade-project.h" -#include "glade-command.h" -#include "glade-palette.h" -#include "glade-popup.h" -#include "glade-cursor.h" -#include "glade-widget.h" -#include "glade-app.h" - -static void glade_placeholder_class_init (GladePlaceholderClass *klass); -static void glade_placeholder_init (GladePlaceholder *placeholder); -static void glade_placeholder_finalize (GObject *object); -static void glade_placeholder_realize (GtkWidget *widget); -static void glade_placeholder_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static void glade_placeholder_send_configure (GladePlaceholder *placeholder); -static gboolean glade_placeholder_expose (GtkWidget *widget, - GdkEventExpose *event); -static gboolean glade_placeholder_motion_notify_event (GtkWidget *widget, - GdkEventMotion *event); -static gboolean glade_placeholder_button_press (GtkWidget *widget, - GdkEventButton *event); -static gboolean glade_placeholder_popup_menu (GtkWidget *widget); - - -static GtkWidgetClass *parent_class = NULL; - -static char *placeholder_xpm[] = { - /* columns rows colors chars-per-pixel */ - "8 8 2 1", - " c #bbbbbb", - ". c #d6d6d6", - /* pixels */ - " . . ", - ". . ", - " ..", - " ..", - ". . ", - " . . ", - " .. ", - " .. " -}; - -/** - * glade_placeholder_get_type: - * - * Creates the typecode for the #GladePlaceholder object type. - * - * Returns: the typecode for the #GladePlaceholder object type - */ -GType -glade_placeholder_get_type (void) -{ - static GType placeholder_type = 0; - - if (!placeholder_type) - { - static const GTypeInfo placeholder_info = - { - sizeof (GladePlaceholderClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) glade_placeholder_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (GladePlaceholder), - 0, /* n_preallocs */ - (GInstanceInitFunc) glade_placeholder_init, - }; - - placeholder_type = g_type_register_static (GTK_TYPE_WIDGET, "GladePlaceholder", - &placeholder_info, 0); - } - - return placeholder_type; -} - -static void -glade_placeholder_class_init (GladePlaceholderClass *klass) -{ - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - parent_class = g_type_class_peek_parent (klass); - - object_class->finalize = glade_placeholder_finalize; - widget_class->realize = glade_placeholder_realize; - widget_class->size_allocate = glade_placeholder_size_allocate; - widget_class->expose_event = glade_placeholder_expose; - widget_class->motion_notify_event = glade_placeholder_motion_notify_event; - widget_class->button_press_event = glade_placeholder_button_press; - widget_class->popup_menu = glade_placeholder_popup_menu; -} - -static void -glade_placeholder_notify_parent (GObject *gobject, - GParamSpec *arg1, - gpointer user_data) -{ - GladePlaceholder *placeholder = GLADE_PLACEHOLDER (gobject); - GladeWidget *parent = glade_placeholder_get_parent (placeholder); - - if (placeholder->packing_actions) - { - g_list_foreach (placeholder->packing_actions, (GFunc)g_object_unref, NULL); - g_list_free (placeholder->packing_actions); - placeholder->packing_actions = NULL; - } - - if (parent && parent->adaptor->packing_actions) - placeholder->packing_actions = glade_widget_adaptor_pack_actions_new (parent->adaptor); -} - -static void -glade_placeholder_init (GladePlaceholder *placeholder) -{ - placeholder->placeholder_pixmap = NULL; - placeholder->packing_actions = NULL; - - GTK_WIDGET_SET_FLAGS (GTK_WIDGET (placeholder), GTK_CAN_FOCUS); - - gtk_widget_set_size_request (GTK_WIDGET (placeholder), - GLADE_PLACEHOLDER_WIDTH_REQ, - GLADE_PLACEHOLDER_HEIGHT_REQ); - - g_signal_connect (placeholder, "notify::parent", - G_CALLBACK (glade_placeholder_notify_parent), - NULL); - - gtk_widget_show (GTK_WIDGET (placeholder)); -} - -/** - * glade_placeholder_new: - * - * Returns: a new #GladePlaceholder cast as a #GtkWidget - */ -GtkWidget * -glade_placeholder_new (void) -{ - return g_object_new (GLADE_TYPE_PLACEHOLDER, NULL); -} - -static void -glade_placeholder_finalize (GObject *object) -{ - GladePlaceholder *placeholder; - - g_return_if_fail (GLADE_IS_PLACEHOLDER (object)); - placeholder = GLADE_PLACEHOLDER (object); - - /* placeholder->placeholder_pixmap can be NULL if the placeholder is - * destroyed before it's realized */ - if (placeholder->placeholder_pixmap) - g_object_unref (placeholder->placeholder_pixmap); - - if (placeholder->packing_actions) - { - g_list_foreach (placeholder->packing_actions, (GFunc)g_object_unref, NULL); - g_list_free (placeholder->packing_actions); - } - - G_OBJECT_CLASS (parent_class)->finalize (object); -} - -static void -glade_placeholder_realize (GtkWidget *widget) -{ - GladePlaceholder *placeholder; - GdkWindowAttr attributes; - gint attributes_mask; - - g_return_if_fail (GLADE_IS_PLACEHOLDER (widget)); - - placeholder = GLADE_PLACEHOLDER (widget); - - GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); - - attributes.window_type = GDK_WINDOW_CHILD; - attributes.x = widget->allocation.x; - attributes.y = widget->allocation.y; - attributes.width = widget->allocation.width; - attributes.height = widget->allocation.height; - attributes.wclass = GDK_INPUT_OUTPUT; - attributes.visual = gtk_widget_get_visual (widget); - attributes.colormap = gtk_widget_get_colormap (widget); - attributes.event_mask = - gtk_widget_get_events (widget) | - GDK_EXPOSURE_MASK | - GDK_BUTTON_PRESS_MASK | - GDK_BUTTON_RELEASE_MASK | - GDK_POINTER_MOTION_MASK; - - attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; - - widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask); - gdk_window_set_user_data (widget->window, placeholder); - - widget->style = gtk_style_attach (widget->style, widget->window); - - glade_placeholder_send_configure (GLADE_PLACEHOLDER (widget)); - - if (!placeholder->placeholder_pixmap) - { - placeholder->placeholder_pixmap = gdk_pixmap_colormap_create_from_xpm_d (NULL, - gtk_widget_get_colormap (GTK_WIDGET (placeholder)), - NULL, NULL, placeholder_xpm); - g_assert(G_IS_OBJECT(placeholder->placeholder_pixmap)); - } - - gdk_window_set_back_pixmap (GTK_WIDGET (placeholder)->window, placeholder->placeholder_pixmap, FALSE); -} - -static void -glade_placeholder_size_allocate (GtkWidget *widget, GtkAllocation *allocation) -{ - g_return_if_fail (GLADE_IS_PLACEHOLDER (widget)); - g_return_if_fail (allocation != NULL); - - widget->allocation = *allocation; - - if (GTK_WIDGET_REALIZED (widget)) - { - gdk_window_move_resize (widget->window, - allocation->x, allocation->y, - allocation->width, allocation->height); - - glade_placeholder_send_configure (GLADE_PLACEHOLDER (widget)); - } -} - -static void -glade_placeholder_send_configure (GladePlaceholder *placeholder) -{ - GtkWidget *widget; - GdkEvent *event = gdk_event_new (GDK_CONFIGURE); - - widget = GTK_WIDGET (placeholder); - - event->configure.window = g_object_ref (widget->window); - event->configure.send_event = TRUE; - event->configure.x = widget->allocation.x; - event->configure.y = widget->allocation.y; - event->configure.width = widget->allocation.width; - event->configure.height = widget->allocation.height; - - gtk_widget_event (widget, event); - gdk_event_free (event); -} - -static GladeProject* -glade_placeholder_get_project (GladePlaceholder *placeholder) -{ - GladeWidget *parent; - parent = glade_placeholder_get_parent (placeholder); - return parent ? GLADE_PROJECT (parent->project) : NULL; -} - -static gboolean -glade_placeholder_expose (GtkWidget *widget, GdkEventExpose *event) -{ - GdkGC *light_gc; - GdkGC *dark_gc; - gint w, h; - - g_return_val_if_fail (GLADE_IS_PLACEHOLDER (widget), FALSE); - - light_gc = widget->style->light_gc[GTK_STATE_NORMAL]; - dark_gc = widget->style->dark_gc[GTK_STATE_NORMAL]; - gdk_drawable_get_size (event->window, &w, &h); - - gdk_draw_line (event->window, light_gc, 0, 0, w - 1, 0); - gdk_draw_line (event->window, light_gc, 0, 0, 0, h - 1); - gdk_draw_line (event->window, dark_gc, 0, h - 1, w - 1, h - 1); - gdk_draw_line (event->window, dark_gc, w - 1, 0, w - 1, h - 1); - - glade_util_queue_draw_nodes (event->window); - - return FALSE; -} - -static gboolean -glade_placeholder_motion_notify_event (GtkWidget *widget, GdkEventMotion *event) -{ - GladePointerMode pointer_mode; - GladeWidget *gparent; - - g_return_val_if_fail (GLADE_IS_PLACEHOLDER (widget), FALSE); - - gparent = glade_placeholder_get_parent (GLADE_PLACEHOLDER (widget)); - pointer_mode = glade_app_get_pointer_mode (); - - if (pointer_mode == GLADE_POINTER_SELECT && - /* If we are the child of a widget that is in a GladeFixed, then - * we are the means of drag/resize and we dont want to fight for - * the cursor (ideally; GladeCursor should somehow deal with such - * concurrencies I suppose). - */ - (gparent->parent && - GLADE_IS_FIXED (gparent->parent)) == FALSE) - glade_cursor_set (event->window, GLADE_CURSOR_SELECTOR); - else if (pointer_mode == GLADE_POINTER_ADD_WIDGET) - glade_cursor_set (event->window, GLADE_CURSOR_ADD_WIDGET); - - return FALSE; -} - -static gboolean -glade_placeholder_button_press (GtkWidget *widget, GdkEventButton *event) -{ - GladePlaceholder *placeholder; - GladeProject *project; - GladeWidgetAdaptor *adaptor; - GladePalette *palette; - gboolean handled = FALSE; - - g_return_val_if_fail (GLADE_IS_PLACEHOLDER (widget), FALSE); - - adaptor = glade_palette_get_current_item (glade_app_get_palette ()); - - palette = glade_app_get_palette (); - placeholder = GLADE_PLACEHOLDER (widget); - project = glade_placeholder_get_project (placeholder); - - if (!GTK_WIDGET_HAS_FOCUS (widget)) - gtk_widget_grab_focus (widget); - - if (event->button == 1 && event->type == GDK_BUTTON_PRESS) - { - if (adaptor != NULL) - { - /* A widget type is selected in the palette. - * Add a new widget of that type. - */ - glade_command_create - (adaptor, - glade_placeholder_get_parent (placeholder), - placeholder, project); - - glade_palette_deselect_current_item (glade_app_get_palette(), TRUE); - - /* reset the cursor */ - glade_cursor_set (event->window, GLADE_CURSOR_SELECTOR); - - handled = TRUE; - } - } - else if (event->button == 3 && event->type == GDK_BUTTON_PRESS) - { - glade_popup_placeholder_pop (placeholder, event); - handled = TRUE; - } - - return handled; -} - -static gboolean -glade_placeholder_popup_menu (GtkWidget *widget) -{ - g_return_val_if_fail (GLADE_IS_PLACEHOLDER (widget), FALSE); - - glade_popup_placeholder_pop (GLADE_PLACEHOLDER (widget), NULL); - - return TRUE; -} - -GladeWidget * -glade_placeholder_get_parent (GladePlaceholder *placeholder) -{ - GtkWidget *widget; - GladeWidget *parent = NULL; - - g_return_val_if_fail (GLADE_IS_PLACEHOLDER (placeholder), NULL); - - for (widget = gtk_widget_get_parent (GTK_WIDGET (placeholder)); - widget != NULL; - widget = gtk_widget_get_parent (widget)) - { - if ((parent = glade_widget_get_from_gobject (widget)) != NULL) - break; - } - return parent; -} diff --git a/gladeui/glade-placeholder.h b/gladeui/glade-placeholder.h deleted file mode 100644 index 566ea907..00000000 --- a/gladeui/glade-placeholder.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef __GLADE_PLACEHOLDER_H__ -#define __GLADE_PLACEHOLDER_H__ - -#include <gladeui/glade-widget.h> -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -#define GLADE_TYPE_PLACEHOLDER (glade_placeholder_get_type ()) -#define GLADE_PLACEHOLDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_PLACEHOLDER, GladePlaceholder)) -#define GLADE_PLACEHOLDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_PLACEHOLDER, GladePlaceholderClass)) -#define GLADE_IS_PLACEHOLDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_PLACEHOLDER)) -#define GLADE_IS_PLACEHOLDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_PLACEHOLDER)) -#define GLADE_PLACEHOLDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GLADE_TYPE_PLACEHOLDER, GladePlaceholderClass)) - -#define GLADE_PLACEHOLDER_WIDTH_REQ 20 -#define GLADE_PLACEHOLDER_HEIGHT_REQ 20 - -typedef struct _GladePlaceholder GladePlaceholder; -typedef struct _GladePlaceholderClass GladePlaceholderClass; - - -struct _GladePlaceholder -{ - GtkWidget widget; - - GdkPixmap *placeholder_pixmap; - - GList *packing_actions; -}; - -struct _GladePlaceholderClass -{ - GtkWidgetClass parent_class; -}; - - -GType glade_placeholder_get_type (void) G_GNUC_CONST; - -GtkWidget *glade_placeholder_new (void); - -GladeWidget *glade_placeholder_get_parent (GladePlaceholder *placeholder); - -G_END_DECLS - -#endif /* __GLADE_PLACEHOLDER_H__ */ diff --git a/gladeui/glade-popup.c b/gladeui/glade-popup.c deleted file mode 100644 index f998485a..00000000 --- a/gladeui/glade-popup.c +++ /dev/null @@ -1,481 +0,0 @@ -/* -*- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Authors: - * Chema Celorio <chema@celorio.com> - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <glib/gi18n-lib.h> - -#include "glade.h" -#include "glade-widget.h" -#include "glade-widget-adaptor.h" -#include "glade-popup.h" -#include "glade-placeholder.h" -#include "glade-clipboard.h" -#include "glade-command.h" -#include "glade-project.h" -#include "glade-app.h" - -/******************************************************** - WIDGET POPUP - *******************************************************/ -static void -glade_popup_select_cb (GtkMenuItem *item, GladeWidget *widget) -{ - glade_util_clear_selection (); - glade_app_selection_set - (glade_widget_get_object (widget), TRUE); -} - -static void -glade_popup_cut_cb (GtkMenuItem *item, GladeWidget *widget) -{ - GladeProject *project = glade_app_get_project (); - - glade_util_clear_selection (); - - /* Assign selection first */ - if (glade_project_is_selected - (project, glade_widget_get_object (widget)) == FALSE) - { - glade_app_selection_set - (glade_widget_get_object (widget), FALSE); - } - glade_app_command_cut (); -} - -static void -glade_popup_copy_cb (GtkMenuItem *item, GladeWidget *widget) -{ - GladeProject *project = glade_app_get_project (); - - glade_util_clear_selection (); - - /* Assign selection first */ - if (glade_project_is_selected - (project, glade_widget_get_object (widget)) == FALSE) - glade_app_selection_set - (glade_widget_get_object (widget), FALSE); - - glade_app_command_copy (); -} - -static void -glade_popup_paste_cb (GtkMenuItem *item, GladeWidget *widget) -{ - glade_util_clear_selection (); - - /* The selected widget is the paste destination */ - glade_app_selection_set (glade_widget_get_object (widget), FALSE); - - glade_app_command_paste (NULL); -} - -static void -glade_popup_delete_cb (GtkMenuItem *item, GladeWidget *widget) -{ - GladeProject *project = glade_app_get_project (); - - /* Assign selection first */ - if (glade_project_is_selected - (project, glade_widget_get_object (widget)) == FALSE) - glade_app_selection_set - (glade_widget_get_object (widget), FALSE); - - glade_app_command_delete (); -} - -/******************************************************** - PLACEHOLDER POPUP - *******************************************************/ -static void -glade_popup_placeholder_paste_cb (GtkMenuItem *item, - GladePlaceholder *placeholder) -{ - glade_util_clear_selection (); - glade_app_selection_clear (FALSE); - - glade_app_command_paste (placeholder); -} - - -/******************************************************** - CLIPBOARD POPUP - *******************************************************/ -static void -glade_popup_clipboard_paste_cb (GtkMenuItem *item, - GladeWidget *widget) -{ - glade_util_clear_selection (); - glade_app_selection_clear (FALSE); - - glade_app_command_paste (NULL); -} - -static void -glade_popup_clipboard_delete_cb (GtkMenuItem *item, GladeWidget *widget) -{ - glade_app_command_delete_clipboard (); -} - -/******************************************************** - POPUP BUILDING - *******************************************************/ -static GtkWidget * -glade_popup_append_item (GtkWidget *popup_menu, - const gchar *stock_id, - const gchar *label, - gboolean sensitive, - gpointer callback, - gpointer data) -{ - GtkWidget *menu_item; - - if (stock_id && label) - { - menu_item = gtk_image_menu_item_new_with_mnemonic (label); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), - gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_MENU)); - } - else if (stock_id) - menu_item = gtk_image_menu_item_new_from_stock (stock_id, NULL); - else - menu_item = gtk_menu_item_new_with_mnemonic (label); - - if (callback) - g_signal_connect (G_OBJECT (menu_item), "activate", - G_CALLBACK (callback), data); - - gtk_widget_set_sensitive (menu_item, sensitive); - gtk_widget_show (menu_item); - gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), menu_item); - - return menu_item; -} - - -static void -glade_popup_menuitem_activated (GtkMenuItem *item, const gchar *action_path) -{ - GladeWidget *widget; - - if ((widget = g_object_get_data (G_OBJECT (item), "gwa-data"))) - glade_widget_adaptor_action_activate (widget->adaptor, - widget->object, - action_path); -} - -static void -glade_popup_menuitem_packing_activated (GtkMenuItem *item, const gchar *action_path) -{ - GladeWidget *widget; - - if ((widget = g_object_get_data (G_OBJECT (item), "gwa-data"))) - glade_widget_adaptor_child_action_activate (widget->parent->adaptor, - widget->parent->object, - widget->object, - action_path); -} - -static void -glade_popup_menuitem_ph_packing_activated (GtkMenuItem *item, const gchar *action_path) -{ - GladePlaceholder *ph; - GladeWidget *parent; - - if ((ph = g_object_get_data (G_OBJECT (item), "gwa-data"))) - { - parent = glade_placeholder_get_parent (ph); - glade_widget_adaptor_child_action_activate (parent->adaptor, - parent->object, - G_OBJECT (ph), - action_path); - } -} - -static gint -glade_popup_action_populate_menu_real (GtkWidget *menu, - GList *actions, - GCallback callback, - gpointer data) -{ - GtkWidget *item; - GList *list; - gint n = 0; - - for (list = actions; list; list = g_list_next (list)) - { - GladeWidgetAction *a = list->data; - GtkWidget *submenu = NULL; - - if (a->actions) - { - submenu = gtk_menu_new (); - n += glade_popup_action_populate_menu_real (submenu, - a->actions, - callback, - data); - } - - item = glade_popup_append_item (menu, - a->klass->stock, - a->klass->label, TRUE, - (a->actions) ? NULL : callback, - (a->actions) ? NULL : a->klass->path); - - g_object_set_data (G_OBJECT (item), "gwa-data", data); - gtk_widget_set_sensitive (item, a->sensitive); - - if (submenu) - gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu); - - n++; - } - - return n; -} - -/* - * glade_popup_action_populate_menu: - * @menu: a GtkMenu to put the actions menu items. - * @widget: A #GladeWidget - * @action: a @widget subaction or NULL to include all actions. - * @packing: TRUE to include packing actions - * - * Populate a GtkMenu with widget's actions - * - * Returns the number of action appended to the menu. - */ -gint -glade_popup_action_populate_menu (GtkWidget *menu, - GladeWidget *widget, - GladeWidgetAction *action, - gboolean packing) -{ - gint n; - - g_return_val_if_fail (GTK_IS_MENU (menu), 0); - g_return_val_if_fail (GLADE_IS_WIDGET (widget), 0); - - if (action) - { - g_return_val_if_fail (GLADE_IS_WIDGET_ACTION (action), 0); - if (glade_widget_get_action (widget, action->klass->path)) - return glade_popup_action_populate_menu_real (menu, - action->actions, - G_CALLBACK (glade_popup_menuitem_activated), - widget); - - if (glade_widget_get_pack_action (widget, action->klass->path)) - return glade_popup_action_populate_menu_real (menu, - action->actions, - G_CALLBACK (glade_popup_menuitem_packing_activated), - widget); - - return 0; - } - - n = glade_popup_action_populate_menu_real (menu, - widget->actions, - G_CALLBACK (glade_popup_menuitem_activated), - widget); - - if (packing && widget->packing_actions) - { - if (n) - { - GtkWidget *separator = gtk_menu_item_new (); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), separator); - gtk_widget_show (separator); - } - n += glade_popup_action_populate_menu_real (menu, - widget->packing_actions, - G_CALLBACK (glade_popup_menuitem_packing_activated), - widget); - } - - return n; -} - -static GtkWidget * -glade_popup_create_menu (GladeWidget *widget, gboolean packing) -{ - GtkWidget *popup_menu; - gboolean sensitive; - - popup_menu = gtk_menu_new (); - - glade_popup_append_item (popup_menu, NULL, _("_Select"), TRUE, - glade_popup_select_cb, widget); - glade_popup_append_item (popup_menu, GTK_STOCK_CUT, NULL, TRUE, - glade_popup_cut_cb, widget); - glade_popup_append_item (popup_menu, GTK_STOCK_COPY, NULL, TRUE, - glade_popup_copy_cb, widget); - - sensitive = glade_clipboard_get_has_selection (glade_app_get_clipboard ()); - glade_popup_append_item (popup_menu, GTK_STOCK_PASTE, NULL, sensitive, - glade_popup_paste_cb, widget); - - glade_popup_append_item (popup_menu, GTK_STOCK_DELETE, NULL, TRUE, - glade_popup_delete_cb, widget); - - if (widget->actions || (packing && widget->packing_actions)) - { - GtkWidget *separator = gtk_menu_item_new (); - gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), separator); - gtk_widget_show (separator); - - glade_popup_action_populate_menu (popup_menu, widget, NULL, packing); - } - - return popup_menu; -} - -static GtkWidget * -glade_popup_create_placeholder_menu (GladePlaceholder *placeholder) -{ - GtkWidget *popup_menu; - gboolean sensitive; - - popup_menu = gtk_menu_new (); - - sensitive = glade_clipboard_get_has_selection (glade_app_get_clipboard ()); - glade_popup_append_item (popup_menu, GTK_STOCK_PASTE, NULL, sensitive, - glade_popup_placeholder_paste_cb, placeholder); - - if (placeholder->packing_actions) - { - GtkWidget *separator = gtk_menu_item_new (); - gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), separator); - gtk_widget_show (separator); - - glade_popup_action_populate_menu_real (popup_menu, - placeholder->packing_actions, - G_CALLBACK (glade_popup_menuitem_ph_packing_activated), - placeholder); - } - - return popup_menu; -} - - -static GtkWidget * -glade_popup_create_clipboard_menu (GladeWidget *widget) -{ - GtkWidget *popup_menu; - - popup_menu = gtk_menu_new (); - - if (GTK_WIDGET_TOPLEVEL (glade_widget_get_object (widget))) - { - glade_popup_append_item (popup_menu, GTK_STOCK_PASTE, - NULL, TRUE, - glade_popup_clipboard_paste_cb, NULL); - } - - glade_popup_append_item (popup_menu, GTK_STOCK_DELETE, NULL, TRUE, - glade_popup_clipboard_delete_cb, widget); - - return popup_menu; -} - -void -glade_popup_widget_pop (GladeWidget *widget, - GdkEventButton *event, - gboolean packing) -{ - GtkWidget *popup_menu; - gint button; - gint event_time; - - g_return_if_fail (GLADE_IS_WIDGET (widget)); - - popup_menu = glade_popup_create_menu (widget, packing); - - if (event) - { - button = event->button; - event_time = event->time; - } - else - { - button = 0; - event_time = gtk_get_current_event_time (); - } - gtk_menu_popup (GTK_MENU (popup_menu), NULL, NULL, - NULL, NULL, button, event_time); -} - -void -glade_popup_placeholder_pop (GladePlaceholder *placeholder, - GdkEventButton *event) -{ - GtkWidget *popup_menu; - gint button; - gint event_time; - - g_return_if_fail (GLADE_IS_PLACEHOLDER (placeholder)); - - popup_menu = glade_popup_create_placeholder_menu (placeholder); - - if (event) - { - button = event->button; - event_time = event->time; - } - else - { - button = 0; - event_time = gtk_get_current_event_time (); - } - - gtk_menu_popup (GTK_MENU (popup_menu), NULL, NULL, - NULL, NULL, button, event_time); -} - -void -glade_popup_clipboard_pop (GladeWidget *widget, - GdkEventButton *event) -{ - GtkWidget *popup_menu; - gint button; - gint event_time; - - g_return_if_fail (GLADE_IS_WIDGET (widget)); - - popup_menu = glade_popup_create_clipboard_menu (widget); - - if (event) - { - button = event->button; - event_time = event->time; - } - else - { - button = 0; - event_time = gtk_get_current_event_time (); - } - - gtk_menu_popup (GTK_MENU (popup_menu), NULL, NULL, - NULL, NULL, button, event_time); -} diff --git a/gladeui/glade-popup.h b/gladeui/glade-popup.h deleted file mode 100644 index 313240b7..00000000 --- a/gladeui/glade-popup.h +++ /dev/null @@ -1,24 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef __GLADE_POPUP_H__ -#define __GLADE_POPUP_H__ - -G_BEGIN_DECLS - -void glade_popup_widget_pop (GladeWidget *widget, - GdkEventButton *event, - gboolean packing); - -void glade_popup_placeholder_pop (GladePlaceholder *placeholder, - GdkEventButton *event); - -void glade_popup_clipboard_pop (GladeWidget *widget, - GdkEventButton *event); - -gint glade_popup_action_populate_menu (GtkWidget *menu, - GladeWidget *widget, - GladeWidgetAction *action, - gboolean packing); - -G_END_DECLS - -#endif /* __GLADE_POPUP_H__ */ diff --git a/gladeui/glade-project.c b/gladeui/glade-project.c deleted file mode 100644 index 31c8ba12..00000000 --- a/gladeui/glade-project.c +++ /dev/null @@ -1,2309 +0,0 @@ -/* -*- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Authors: - * Chema Celorio <chema@celorio.com> - */ - -#include <config.h> - -#include <string.h> -#include <stdlib.h> -#include <glib.h> -#include <glib/gi18n-lib.h> -#include <glib/gstdio.h> - -#include "glade.h" -#include "glade-widget.h" -#include "glade-id-allocator.h" -#include "glade-app.h" -#include "glade-marshallers.h" -#include "glade-catalog.h" - -#include "glade-project.h" - -#define GLADE_PROJECT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GLADE_TYPE_PROJECT, GladeProjectPrivate)) - -enum -{ - ADD_WIDGET, - REMOVE_WIDGET, - WIDGET_NAME_CHANGED, - SELECTION_CHANGED, - CLOSE, - RESOURCE_ADDED, - RESOURCE_REMOVED, - CHANGED, - PARSE_FINISHED, - LAST_SIGNAL -}; - -enum -{ - PROP_0, - PROP_MODIFIED, - PROP_HAS_SELECTION, - PROP_PATH, - PROP_READ_ONLY -}; - -struct _GladeProjectPrivate -{ - gchar *path; /* The full canonical path of the glade file for this project */ - - guint instance_count; /* How many projects with this name */ - - gint unsaved_number; /* A unique number for this project if it is untitled */ - - gboolean readonly; /* A flag that is set if the project is readonly */ - - gboolean loading; /* A flags that is set when the project is loading */ - - gboolean modified; /* A flag that is set when a project has unsaved modifications - * if this flag is not set we don't have to query - * for confirmation after a close or exit is - * requested - */ - - GList *objects; /* A list of #GObjects that make up this project. - * The objects are stored in no particular order. - */ - - GList *selection; /* We need to keep the selection in the project - * because we have multiple projects and when the - * user switchs between them, he will probably - * not want to loose the selection. This is a list - * of #GtkWidget items. - */ - - gboolean has_selection; /* Whether the project has a selection */ - - GList *undo_stack; /* A stack with the last executed commands */ - GList *prev_redo_item; /* Points to the item previous to the redo items */ - GHashTable *widget_names_allocator; /* hash table with the used widget names */ - GHashTable *widget_old_names; /* widget -> old name of the widget */ - GtkTooltips *tooltips; - - GladeCommand *first_modification; /* we record the first modification, so that we - * can set "modification" to FALSE when we - * undo this modification - */ - - GtkAccelGroup *accel_group; - - GHashTable *resources; /* resource filenames & thier associated properties */ - - gchar *comment; /* XML comment, Glade will preserve whatever comment was - * in file, so users can delete or change it. - */ - - time_t mtime; /* last UTC modification time of file, or 0 if it could not be read */ -}; - - -static guint glade_project_signals[LAST_SIGNAL] = {0}; - -static GladeIDAllocator *unsaved_number_allocator = NULL; - -static gboolean glade_project_load_from_interface (GladeProject *project, - GladeInterface *interface, - const gchar *path); - - -G_DEFINE_TYPE (GladeProject, glade_project, G_TYPE_OBJECT) - - -/******************************************************************* - GObjectClass - *******************************************************************/ - -static GladeIDAllocator * -get_unsaved_number_allocator (void) -{ - if (unsaved_number_allocator == NULL) - unsaved_number_allocator = glade_id_allocator_new (); - - return unsaved_number_allocator; -} - -static void -glade_project_list_unref (GList *original_list) -{ - GList *l; - for (l = original_list; l; l = l->next) - g_object_unref (G_OBJECT (l->data)); - - if (original_list != NULL) - g_list_free (original_list); -} - -static void -glade_project_dispose (GObject *object) -{ - GladeProject *project = GLADE_PROJECT (object); - GList *list; - GladeWidget *gwidget; - - /* Emit close signal */ - g_signal_emit (object, glade_project_signals [CLOSE], 0); - - glade_project_selection_clear (project, TRUE); - - glade_project_list_unref (project->priv->undo_stack); - project->priv->undo_stack = NULL; - - /* Unparent all widgets in the heirarchy first - * (Since we are bookkeeping exact reference counts, we - * dont want the hierarchy to just get destroyed) - */ - for (list = project->priv->objects; list; list = list->next) - { - gwidget = glade_widget_get_from_gobject (list->data); - - if (gwidget->parent && - gwidget->internal == NULL && - glade_widget_adaptor_has_child (gwidget->parent->adaptor, - gwidget->parent->object, - gwidget->object)) - glade_widget_remove_child (gwidget->parent, gwidget); - } - - /* Remove objects from the project */ - for (list = project->priv->objects; list; list = list->next) - { - gwidget = glade_widget_get_from_gobject (list->data); - - g_object_unref (G_OBJECT (list->data)); /* Remove the GladeProject reference */ - g_object_unref (G_OBJECT (gwidget)); /* Remove the overall "Glade" reference */ - } - project->priv->objects = NULL; - - gtk_object_destroy (GTK_OBJECT (project->priv->tooltips)); - project->priv->tooltips = NULL; - - G_OBJECT_CLASS (glade_project_parent_class)->dispose (object); -} - -static void -glade_project_finalize (GObject *object) -{ - GladeProject *project = GLADE_PROJECT (object); - - g_free (project->priv->path); - g_free (project->priv->comment); - - if (project->priv->unsaved_number > 0) - glade_id_allocator_release (get_unsaved_number_allocator (), project->priv->unsaved_number); - - g_hash_table_destroy (project->priv->widget_names_allocator); - g_hash_table_destroy (project->priv->widget_old_names); - g_hash_table_destroy (project->priv->resources); - - G_OBJECT_CLASS (glade_project_parent_class)->finalize (object); -} - -static void -glade_project_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - GladeProject *project = GLADE_PROJECT (object); - - switch (prop_id) - { - case PROP_MODIFIED: - g_value_set_boolean (value, project->priv->modified); - break; - case PROP_HAS_SELECTION: - g_value_set_boolean (value, project->priv->has_selection); - break; - case PROP_READ_ONLY: - g_value_set_boolean (value, project->priv->readonly); - break; - case PROP_PATH: - g_value_set_string (value, project->priv->path); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -/** - * glade_project_set_modified: - * @project: a #GladeProject - * @modified: Whether the project should be set as modified or not - * @modification: The first #GladeCommand which caused the project to have unsaved changes - * - * Set's whether a #GladeProject should be flagged as modified or not. This is useful - * for indicating that a project has unsaved changes. If @modified is #TRUE, then - * @modification will be recorded as the first change which caused the project to - * have unsaved changes. @modified is #FALSE then @modification will be ignored. - * - * If @project is already flagged as modified, then calling this method with - * @modified as #TRUE, will have no effect. Likewise, if @project is unmodified - * then calling this method with @modified as #FALSE, will have no effect. - * - */ -static void -glade_project_set_modified (GladeProject *project, - gboolean modified, - GladeCommand *modification) -{ - GladeProjectPrivate *priv = project->priv; - - if (priv->modified != modified) - { - priv->modified = !priv->modified; - - if (priv->modified) - { - g_assert (priv->first_modification == NULL); - g_assert (modification != NULL); - priv->first_modification = modification; - } - else - { - g_assert (priv->first_modification != NULL); - priv->first_modification = NULL; - } - - g_object_notify (G_OBJECT (project), "modified"); - } -} - -/******************************************************************* - GladeProjectClass - *******************************************************************/ -static void -glade_project_walk_back (GladeProject *project) -{ - if (project->priv->prev_redo_item) - project->priv->prev_redo_item = project->priv->prev_redo_item->prev; -} - -static void -glade_project_walk_forward (GladeProject *project) -{ - if (project->priv->prev_redo_item) - project->priv->prev_redo_item = project->priv->prev_redo_item->next; - else - project->priv->prev_redo_item = project->priv->undo_stack; -} - -static void -glade_project_undo_impl (GladeProject *project) -{ - GladeCommand *cmd, *next_cmd; - - while ((cmd = glade_project_next_undo_item (project)) != NULL) - { - glade_command_undo (cmd); - - glade_project_walk_back (project); - - g_signal_emit (G_OBJECT (project), - glade_project_signals [CHANGED], - 0, cmd, FALSE); - - if ((next_cmd = glade_project_next_undo_item (project)) != NULL && - (next_cmd->group_id == 0 || next_cmd->group_id != cmd->group_id)) - break; - } -} - -static void -glade_project_redo_impl (GladeProject *project) -{ - GladeCommand *cmd, *next_cmd; - - while ((cmd = glade_project_next_redo_item (project)) != NULL) - { - glade_command_execute (cmd); - - glade_project_walk_forward (project); - - g_signal_emit (G_OBJECT (project), - glade_project_signals [CHANGED], - 0, cmd, TRUE); - - if ((next_cmd = glade_project_next_redo_item (project)) != NULL && - (next_cmd->group_id == 0 || next_cmd->group_id != cmd->group_id)) - break; - } -} - -static GladeCommand * -glade_project_next_undo_item_impl (GladeProject *project) -{ - GList *l; - - if ((l = project->priv->prev_redo_item) == NULL) - return NULL; - - return GLADE_COMMAND (l->data); -} - -static GladeCommand * -glade_project_next_redo_item_impl (GladeProject *project) -{ - GList *l; - - if ((l = project->priv->prev_redo_item) == NULL) - return project->priv->undo_stack ? - GLADE_COMMAND (project->priv->undo_stack->data) : NULL; - else - return l->next ? GLADE_COMMAND (l->next->data) : NULL; -} - -static void -glade_project_push_undo_impl (GladeProject *project, GladeCommand *cmd) -{ - GladeProjectPrivate *priv = project->priv; - GList *tmp_redo_item; - - /* If there are no "redo" items, and the last "undo" item unifies with - us, then we collapse the two items in one and we're done */ - if (priv->prev_redo_item != NULL && priv->prev_redo_item->next == NULL) - { - GladeCommand *cmd1 = priv->prev_redo_item->data; - - if (glade_command_unifies (cmd1, cmd)) - { - glade_command_collapse (cmd1, cmd); - g_object_unref (cmd); - - g_signal_emit (G_OBJECT (project), - glade_project_signals [CHANGED], - 0, cmd1, TRUE); - return; - } - } - - /* We should now free all the "redo" items */ - tmp_redo_item = g_list_next (priv->prev_redo_item); - while (tmp_redo_item) - { - g_assert (tmp_redo_item->data); - - /* just for safety, we might not need this */ - if (GLADE_COMMAND (tmp_redo_item->data) == priv->first_modification) - priv->first_modification = NULL; - - g_object_unref (G_OBJECT (tmp_redo_item->data)); - - tmp_redo_item = g_list_next (tmp_redo_item); - } - - if (priv->prev_redo_item) - { - g_list_free (g_list_next (priv->prev_redo_item)); - priv->prev_redo_item->next = NULL; - } - else - { - g_list_free (priv->undo_stack); - priv->undo_stack = NULL; - } - - /* and then push the new undo item */ - priv->undo_stack = g_list_append (priv->undo_stack, cmd); - - if (project->priv->prev_redo_item == NULL) - priv->prev_redo_item = priv->undo_stack; - else - priv->prev_redo_item = g_list_next (priv->prev_redo_item); - - - g_signal_emit (G_OBJECT (project), - glade_project_signals [CHANGED], - 0, cmd, TRUE); -} - -static void -glade_project_changed_impl (GladeProject *project, - GladeCommand *command, - gboolean forward) -{ - if (!project->priv->loading) - { - /* if this command is the first modification to cause the project - * to have unsaved changes, then we can now flag the project as unmodified - */ - if (command == project->priv->first_modification) - glade_project_set_modified (project, FALSE, NULL); - else - glade_project_set_modified (project, TRUE, command); - } - glade_app_update_ui (); -} - -/******************************************************************* - Initializers - *******************************************************************/ -static void -glade_project_init (GladeProject *project) -{ - GladeProjectPrivate *priv; - - project->priv = priv = GLADE_PROJECT_GET_PRIVATE (project); - - priv->path = NULL; - priv->instance_count = 0; - priv->readonly = FALSE; - priv->objects = NULL; - priv->selection = NULL; - priv->has_selection = FALSE; - priv->undo_stack = NULL; - priv->prev_redo_item = NULL; - priv->first_modification = NULL; - priv->widget_names_allocator = g_hash_table_new_full (g_str_hash, - g_str_equal, - g_free, - (GDestroyNotify) glade_id_allocator_destroy); - - priv->widget_old_names = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) g_free); - - priv->tooltips = gtk_tooltips_new (); - priv->accel_group = NULL; - - priv->resources = g_hash_table_new_full (g_direct_hash, - g_direct_equal, - NULL, g_free); - - priv->unsaved_number = glade_id_allocator_allocate (get_unsaved_number_allocator ()); -} - -static void -glade_project_class_init (GladeProjectClass *klass) -{ - GObjectClass *object_class; - - object_class = G_OBJECT_CLASS (klass); - - object_class->get_property = glade_project_get_property; - object_class->finalize = glade_project_finalize; - object_class->dispose = glade_project_dispose; - - klass->add_object = NULL; - klass->remove_object = NULL; - klass->undo = glade_project_undo_impl; - klass->redo = glade_project_redo_impl; - klass->next_undo_item = glade_project_next_undo_item_impl; - klass->next_redo_item = glade_project_next_redo_item_impl; - klass->push_undo = glade_project_push_undo_impl; - - klass->widget_name_changed = NULL; - klass->selection_changed = NULL; - klass->close = NULL; - klass->resource_added = NULL; - klass->resource_removed = NULL; - klass->changed = glade_project_changed_impl; - - /** - * GladeProject::add-widget: - * @gladeproject: the #GladeProject which received the signal. - * @arg1: the #GladeWidget that was added to @gladeproject. - * - * Emitted when a widget is added to a project. - */ - glade_project_signals[ADD_WIDGET] = - g_signal_new ("add_widget", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GladeProjectClass, add_object), - NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, - 1, - GLADE_TYPE_WIDGET); - - /** - * GladeProject::remove-widget: - * @gladeproject: the #GladeProject which received the signal. - * @arg1: the #GladeWidget that was removed from @gladeproject. - * - * Emitted when a widget is removed from a project. - */ - glade_project_signals[REMOVE_WIDGET] = - g_signal_new ("remove_widget", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GladeProjectClass, remove_object), - NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, - 1, - GLADE_TYPE_WIDGET); - - - /** - * GladeProject::widget-name-changed: - * @gladeproject: the #GladeProject which received the signal. - * @arg1: the #GladeWidget who's name changed. - * - * Emitted when @gwidget's name changes. - */ - glade_project_signals[WIDGET_NAME_CHANGED] = - g_signal_new ("widget_name_changed", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GladeProjectClass, widget_name_changed), - NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, - 1, - GLADE_TYPE_WIDGET); - - - /** - * GladeProject::selection-changed: - * @gladeproject: the #GladeProject which received the signal. - * - * Emitted when @gladeproject selection list changes. - */ - glade_project_signals[SELECTION_CHANGED] = - g_signal_new ("selection_changed", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GladeProjectClass, selection_changed), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); - - - /** - * GladeProject::close: - * @gladeproject: the #GladeProject which received the signal. - * - * Emitted when a project is closing (a good time to clean up - * any associated resources). - */ - glade_project_signals[CLOSE] = - g_signal_new ("close", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GladeProjectClass, close), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); - - - /** - * GladeProject::resource-added: - * @gladeproject: the #GladeProject which received the signal. - * @arg1: the file's basename (in the project path). - * - * Emitted when a resource file required by a #GladeProperty is - * added to @gladeproject - */ - glade_project_signals[RESOURCE_ADDED] = - g_signal_new ("resource-added", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GladeProjectClass, resource_added), - NULL, NULL, - g_cclosure_marshal_VOID__STRING, - G_TYPE_NONE, - 1, - G_TYPE_STRING); - - /** - * GladeProject::resource-removed: - * @gladeproject: the #GladeProject which received the signal. - * @arg1: the file's basename - * - * Emitted when a resource file is removed from @gladeproject - */ - glade_project_signals[RESOURCE_REMOVED] = - g_signal_new ("resource-removed", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GladeProjectClass, resource_removed), - NULL, NULL, - g_cclosure_marshal_VOID__STRING, - G_TYPE_NONE, - 1, - G_TYPE_STRING); - - - /** - * GladeProject::changed: - * @gladeproject: the #GladeProject which received the signal. - * @arg1: the #GladeCommand that was executed - * @arg2: whether the command was executed or undone. - * - * Emitted when a @gladeproject's state changes via a #GladeCommand. - */ - glade_project_signals[CHANGED] = - g_signal_new ("changed", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (GladeProjectClass, changed), - NULL, NULL, - glade_marshal_VOID__OBJECT_BOOLEAN, - G_TYPE_NONE, - 2, - GLADE_TYPE_COMMAND, G_TYPE_BOOLEAN); - - /** - * GladeProject::parse-finished: - * @gladeproject: the #GladeProject which received the signal. - * - * Emitted when @gladeproject parsing has finished. - */ - glade_project_signals[PARSE_FINISHED] = - g_signal_new ("parse-finished", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (GladeProjectClass, parse_finished), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); - - g_object_class_install_property (object_class, - PROP_MODIFIED, - g_param_spec_boolean ("modified", - _(""), - _("Whether project has beem modified since it was last saved"), - FALSE, - G_PARAM_READABLE)); - - g_object_class_install_property (object_class, - PROP_HAS_SELECTION, - g_param_spec_boolean ("has-selection", - _("Has Selection"), - _("Whether project has a selection"), - FALSE, - G_PARAM_READABLE)); - - g_object_class_install_property (object_class, - PROP_READ_ONLY, - g_param_spec_boolean ("read-only", - _("Read Only"), - _("Whether project is read only or not"), - FALSE, - G_PARAM_READABLE)); - - g_object_class_install_property (object_class, - PROP_PATH, - g_param_spec_string ("path", - _("Path"), - _("The filesystem path of the project"), - NULL, - G_PARAM_READABLE)); - - g_type_class_add_private (klass, sizeof (GladeProjectPrivate)); -} - -/******************************************************************* - API - *******************************************************************/ - -static void -glade_project_set_readonly (GladeProject *project, gboolean readonly) -{ - g_assert (GLADE_IS_PROJECT (project)); - - if (project->priv->readonly != readonly) - { - project->priv->readonly = readonly; - g_object_notify (G_OBJECT (project), "read-only"); - } -} - -/** - * glade_project_get_readonly: - * @project: a #GladeProject - * - * Gets whether the project is read only or not - * - * Returns: TRUE if project is read only - */ -gboolean -glade_project_get_readonly (GladeProject *project) -{ - g_return_val_if_fail (GLADE_IS_PROJECT (project), FALSE); - - return project->priv->readonly; -} - -/** - * glade_project_new: - * - * Creates a new #GladeProject. - * - * Returns: a new #GladeProject - */ -GladeProject * -glade_project_new (void) -{ - return g_object_new (GLADE_TYPE_PROJECT, NULL); -} - -gboolean -glade_project_load_from_file (GladeProject *project, const gchar *path) -{ - GladeInterface *interface; - - g_return_val_if_fail (GLADE_IS_PROJECT (project), FALSE); - g_return_val_if_fail (path != NULL, FALSE); - - interface = glade_parser_interface_new_from_file (path, NULL); - - if (interface != NULL) - { - if (!glade_project_load_from_interface (project, interface, path)) - { - glade_parser_interface_destroy (interface); - return FALSE; - } - glade_parser_interface_destroy (interface); - } - else - { - return FALSE; - } - - if (glade_util_file_is_writeable (project->priv->path) == FALSE) - glade_project_set_readonly (project, TRUE); - - project->priv->modified = FALSE; - - project->priv->mtime = glade_util_get_file_mtime (project->priv->path, NULL); - - return TRUE; -} - - -/** - * glade_project_selection_changed: - * @project: a #GladeProject - * - * Causes @project to emit a "selection_changed" signal. - */ -void -glade_project_selection_changed (GladeProject *project) -{ - g_return_if_fail (GLADE_IS_PROJECT (project)); - g_signal_emit (G_OBJECT (project), - glade_project_signals [SELECTION_CHANGED], - 0); -} - -static void -glade_project_on_widget_notify (GladeWidget *widget, GParamSpec *arg, GladeProject *project) -{ - g_return_if_fail (GLADE_IS_WIDGET (widget)); - g_return_if_fail (GLADE_IS_PROJECT (project)); - - switch (arg->name[0]) - { - case 'n': - if (strcmp (arg->name, "name") == 0) - { - const char *old_name = g_hash_table_lookup (project->priv->widget_old_names, widget); - glade_project_widget_name_changed (project, widget, old_name); - g_hash_table_insert (project->priv->widget_old_names, widget, g_strdup (glade_widget_get_name (widget))); - } - - case 'p': - if (strcmp (arg->name, "project") == 0) - glade_project_remove_object (project, glade_widget_get_object (widget)); - } -} - - -static void -gp_sync_resources (GladeProject *project, - GladeProject *prev_project, - GladeWidget *gwidget, - gboolean remove) -{ - GList *prop_list, *l; - GladeProperty *property; - gchar *resource, *full_resource; - - prop_list = g_list_copy (gwidget->properties); - prop_list = g_list_concat - (prop_list, g_list_copy (gwidget->packing_properties)); - - for (l = prop_list; l; l = l->next) - { - property = l->data; - if (property->klass->resource) - { - GValue value = { 0, }; - - if (remove) - { - glade_project_set_resource (project, property, NULL); - continue; - } - - glade_property_get_value (property, &value); - - if ((resource = glade_property_class_make_string_from_gvalue - (property->klass, &value)) != NULL) - { - full_resource = glade_project_resource_fullpath - (prev_project ? prev_project : project, resource); - - /* Use a full path here so that the current - * working directory isnt used. - */ - glade_project_set_resource (project, - property, - full_resource); - - g_free (full_resource); - g_free (resource); - } - g_value_unset (&value); - } - } - g_list_free (prop_list); -} - -static void -glade_project_sync_resources_for_widget (GladeProject *project, - GladeProject *prev_project, - GladeWidget *gwidget, - gboolean remove) -{ - GList *children, *l; - GladeWidget *gchild; - - children = glade_widget_adaptor_get_children - (gwidget->adaptor, gwidget->object); - - for (l = children; l; l = l->next) - if ((gchild = - glade_widget_get_from_gobject (l->data)) != NULL) - glade_project_sync_resources_for_widget - (project, prev_project, gchild, remove); - if (children) - g_list_free (children); - - gp_sync_resources (project, prev_project, gwidget, remove); -} - -/** - * glade_project_add_object: - * @project: the #GladeProject the widget is added to - * @old_project: the #GladeProject the widget was previously in - * (or %NULL for the clipboard) - * @object: the #GObject to add - * - * Adds an object to the project. - */ -void -glade_project_add_object (GladeProject *project, - GladeProject *old_project, - GObject *object) -{ - GladeWidget *gwidget; - GList *list, *children; - GtkWindow *transient_parent; - static gint reentrancy_count = 0; - - g_return_if_fail (GLADE_IS_PROJECT (project)); - g_return_if_fail (G_IS_OBJECT (object)); - - /* We don't list placeholders */ - if (GLADE_IS_PLACEHOLDER (object)) - return; - - /* Only widgets accounted for in the catalog or widgets declared - * in the plugin with glade_widget_new_for_internal_child () are - * usefull in the project. - */ - if ((gwidget = glade_widget_get_from_gobject (object)) == NULL) - return; - - /* Code body starts here */ - reentrancy_count++; - - if ((children = glade_widget_adaptor_get_children - (gwidget->adaptor, gwidget->object)) != NULL) - { - for (list = children; list && list->data; list = list->next) - glade_project_add_object - (project, old_project, G_OBJECT (list->data)); - g_list_free (children); - } - - glade_widget_set_project (gwidget, (gpointer)project); - g_hash_table_insert (project->priv->widget_old_names, - gwidget, g_strdup (glade_widget_get_name (gwidget))); - - g_signal_connect (G_OBJECT (gwidget), "notify", - (GCallback) glade_project_on_widget_notify, project); - - project->priv->objects = g_list_prepend (project->priv->objects, g_object_ref (object)); - - g_signal_emit (G_OBJECT (project), - glade_project_signals [ADD_WIDGET], - 0, gwidget); - - if (GTK_IS_WINDOW (object) && - (transient_parent = glade_app_get_transient_parent ()) != NULL) - gtk_window_set_transient_for (GTK_WINDOW (object), transient_parent); - - /* Notify widget it was added to the project */ - glade_widget_project_notify (gwidget, project); - - /* Call this once at the end for every recursive call */ - if (--reentrancy_count == 0) - glade_project_sync_resources_for_widget - (project, old_project, gwidget, FALSE); -} - -/** - * glade_project_has_object: - * @project: the #GladeProject the widget is added to - * @object: the #GObject to search - * - * Returns whether this object is in this project. - */ -gboolean -glade_project_has_object (GladeProject *project, GObject *object) -{ - g_return_val_if_fail (GLADE_IS_PROJECT (project), FALSE); - g_return_val_if_fail (G_IS_OBJECT (object), FALSE); - return (g_list_find (project->priv->objects, object)) != NULL; -} - -/** - * glade_project_release_widget_name: - * @project: a #GladeProject - * @glade_widget: - * @widget_name: - * - * TODO: Write me - */ -static void -glade_project_release_widget_name (GladeProject *project, GladeWidget *glade_widget, const char *widget_name) -{ - const char *first_number = widget_name; - char *end_number; - char *base_widget_name; - GladeIDAllocator *id_allocator; - gunichar ch; - int id; - - g_return_if_fail (GLADE_IS_PROJECT (project)); - g_return_if_fail (GLADE_IS_WIDGET (glade_widget)); - - do - { - ch = g_utf8_get_char (first_number); - - if (ch == 0 || g_unichar_isdigit (ch)) - break; - - first_number = g_utf8_next_char (first_number); - } - while (TRUE); - - if (ch == 0) - return; - - base_widget_name = g_strdup (widget_name); - *(base_widget_name + (first_number - widget_name)) = 0; - - id_allocator = g_hash_table_lookup (project->priv->widget_names_allocator, base_widget_name); - if (id_allocator == NULL) - goto lblend; - - id = (int) strtol (first_number, &end_number, 10); - if (*end_number != 0) - goto lblend; - - glade_id_allocator_release (id_allocator, id); - - lblend: - g_hash_table_remove (project->priv->widget_old_names, glade_widget); - g_free (base_widget_name); -} - -/** - * glade_project_remove_object: - * @project: a #GladeProject - * @object: the #GObject to remove - * - * Removes @object from @project. - * - * Note that when removing the #GObject from the project we - * don't change ->project in the associated #GladeWidget; this - * way UNDO can work. - */ -void -glade_project_remove_object (GladeProject *project, GObject *object) -{ - GladeWidget *gwidget; - GList *link, *list, *children; - static gint reentrancy_count = 0; - - g_return_if_fail (GLADE_IS_PROJECT (project)); - g_return_if_fail (G_IS_OBJECT (object)); - - if (GLADE_IS_PLACEHOLDER (object)) - return; - - if ((gwidget = glade_widget_get_from_gobject (object)) == NULL) - return; - - /* Code body starts here */ - reentrancy_count++; - - /* Notify widget is being removed from the project */ - glade_widget_project_notify (gwidget, NULL); - - if ((children = - glade_widget_adaptor_get_children (gwidget->adaptor, - gwidget->object)) != NULL) - { - for (list = children; list && list->data; list = list->next) - glade_project_remove_object (project, G_OBJECT (list->data)); - g_list_free (children); - } - - glade_project_selection_remove (project, object, TRUE); - - if ((link = g_list_find (project->priv->objects, object)) != NULL) - { - g_object_unref (object); - glade_project_release_widget_name (project, gwidget, - glade_widget_get_name (gwidget)); - project->priv->objects = g_list_delete_link (project->priv->objects, link); - } - - g_signal_emit (G_OBJECT (project), - glade_project_signals [REMOVE_WIDGET], - 0, - gwidget); - - /* Call this once at the end for every recursive call */ - if (--reentrancy_count == 0) - glade_project_sync_resources_for_widget (project, NULL, gwidget, TRUE); -} - -/** - * glade_project_widget_name_changed: - * @project: a #GladeProject - * @widget: a #GladeWidget - * @old_name: - * - * TODO: write me - */ -void -glade_project_widget_name_changed (GladeProject *project, GladeWidget *widget, const char *old_name) -{ - g_return_if_fail (GLADE_IS_PROJECT (project)); - g_return_if_fail (GLADE_IS_WIDGET (widget)); - - glade_project_release_widget_name (project, widget, old_name); - - g_signal_emit (G_OBJECT (project), - glade_project_signals [WIDGET_NAME_CHANGED], - 0, - widget); -} - -/** - * glade_project_get_widget_by_name: - * @project: a #GladeProject - * @name: The user visible name of the widget we are looking for - * - * Searches through @project looking for a #GladeWidget named @name. - * - * Returns: a pointer to the widget, %NULL if the widget does not exist - */ -GladeWidget * -glade_project_get_widget_by_name (GladeProject *project, const gchar *name) -{ - GList *list; - - g_return_val_if_fail (GLADE_IS_PROJECT (project), NULL); - g_return_val_if_fail (name != NULL, NULL); - - for (list = project->priv->objects; list; list = list->next) { - GladeWidget *widget; - - widget = glade_widget_get_from_gobject (list->data); - g_return_val_if_fail (widget->name != NULL, NULL); - if (strcmp (widget->name, name) == 0) - return widget; - } - - return NULL; -} - -/** - * glade_project_new_widget_name: - * @project: a #GladeProject - * @base_name: base name of the widget to create - * - * Creates a new name for a widget that doesn't collide with any of the names - * already in @project. This name will start with @base_name. - * - * Returns: a string containing the new name, %NULL if there is not enough - * memory for this string - */ -char * -glade_project_new_widget_name (GladeProject *project, const char *base_name) -{ - GladeIDAllocator *id_allocator; - const gchar *number; - gchar *name = NULL, *freeme = NULL; - guint i = 1; - - g_return_val_if_fail (GLADE_IS_PROJECT (project), NULL); - - number = base_name + strlen (base_name); - - while (number > base_name && g_ascii_isdigit (number[-1])) - --number; - - if (*number) - { - freeme = g_strndup (base_name, number - base_name); - base_name = freeme; - } - - id_allocator = g_hash_table_lookup (project->priv->widget_names_allocator, base_name); - - if (id_allocator == NULL) - { - id_allocator = glade_id_allocator_new (); - g_hash_table_insert (project->priv->widget_names_allocator, - g_strdup (base_name), id_allocator); - } - - while (TRUE) - { - i = glade_id_allocator_allocate (id_allocator); - name = g_strdup_printf ("%s%u", base_name, i); - - /* ok, there is no widget with this name, so return the name */ - if (glade_project_get_widget_by_name (project, name) == NULL) - return name; - - /* we already have a widget with this name, so free the name and - * try again with another number */ - g_free (name); - i++; - } - - g_free (freeme); - return name; -} - -static void -glade_project_set_has_selection (GladeProject *project, gboolean has_selection) -{ - g_assert (GLADE_IS_PROJECT (project)); - - if (project->priv->has_selection != has_selection) - { - project->priv->has_selection = has_selection; - g_object_notify (G_OBJECT (project), "has-selection"); - } -} - -/** - * glade_project_get_has_selection: - * @project: a #GladeProject - * - * Returns: whether @project currently has a selection - */ -gboolean -glade_project_get_has_selection (GladeProject *project) -{ - g_assert (GLADE_IS_PROJECT (project)); - - return project->priv->has_selection; -} - -/** - * glade_project_is_selected: - * @project: a #GladeProject - * @object: a #GObject - * - * Returns: whether @object is in @project selection - */ -gboolean -glade_project_is_selected (GladeProject *project, - GObject *object) -{ - g_return_val_if_fail (GLADE_IS_PROJECT (project), FALSE); - return (g_list_find (project->priv->selection, object)) != NULL; -} - -/** - * glade_project_selection_clear: - * @project: a #GladeProject - * @emit_signal: whether or not to emit a signal indication a selection change - * - * Clears @project's selection chain - * - * If @emit_signal is %TRUE, calls glade_project_selection_changed(). - */ -void -glade_project_selection_clear (GladeProject *project, gboolean emit_signal) -{ - g_return_if_fail (GLADE_IS_PROJECT (project)); - if (project->priv->selection == NULL) - return; - - glade_util_clear_selection (); - - g_list_free (project->priv->selection); - project->priv->selection = NULL; - glade_project_set_has_selection (project, FALSE); - - if (emit_signal) - glade_project_selection_changed (project); -} - -/** - * glade_project_selection_remove: - * @project: a #GladeProject - * @object: a #GObject in @project - * @emit_signal: whether or not to emit a signal - * indicating a selection change - * - * Removes @object from the selection chain of @project - * - * If @emit_signal is %TRUE, calls glade_project_selection_changed(). - */ -void -glade_project_selection_remove (GladeProject *project, - GObject *object, - gboolean emit_signal) -{ - g_return_if_fail (GLADE_IS_PROJECT (project)); - g_return_if_fail (G_IS_OBJECT (object)); - - if (glade_project_is_selected (project, object)) - { - if (GTK_IS_WIDGET (object)) - glade_util_remove_selection (GTK_WIDGET (object)); - project->priv->selection = g_list_remove (project->priv->selection, object); - if (project->priv->selection == NULL) - glade_project_set_has_selection (project, FALSE); - if (emit_signal) - glade_project_selection_changed (project); - } -} - -/** - * glade_project_selection_add: - * @project: a #GladeProject - * @object: a #GObject in @project - * @emit_signal: whether or not to emit a signal indicating - * a selection change - * - * Adds @object to the selection chain of @project - * - * If @emit_signal is %TRUE, calls glade_project_selection_changed(). - */ -void -glade_project_selection_add (GladeProject *project, - GObject *object, - gboolean emit_signal) -{ - g_return_if_fail (GLADE_IS_PROJECT (project)); - g_return_if_fail (G_IS_OBJECT (object)); - g_return_if_fail (g_list_find (project->priv->objects, object) != NULL); - - if (glade_project_is_selected (project, object) == FALSE) - { - if (GTK_IS_WIDGET (object)) - glade_util_add_selection (GTK_WIDGET (object)); - if (project->priv->selection == NULL) - glade_project_set_has_selection (project, TRUE); - project->priv->selection = g_list_prepend (project->priv->selection, object); - if (emit_signal) - glade_project_selection_changed (project); - } -} - -/** - * glade_project_selection_set: - * @project: a #GladeProject - * @object: a #GObject in @project - * @emit_signal: whether or not to emit a signal - * indicating a selection change - * - * Set the selection in @project to @object - * - * If @emit_signal is %TRUE, calls glade_project_selection_changed(). - */ -void -glade_project_selection_set (GladeProject *project, - GObject *object, - gboolean emit_signal) -{ - g_return_if_fail (GLADE_IS_PROJECT (project)); - g_return_if_fail (G_IS_OBJECT (object)); - - if (g_list_find (project->priv->objects, object) == NULL) - return; - - if (project->priv->selection == NULL) - glade_project_set_has_selection (project, TRUE); - - if (glade_project_is_selected (project, object) == FALSE || - g_list_length (project->priv->selection) != 1) - { - glade_project_selection_clear (project, FALSE); - glade_project_selection_add (project, object, emit_signal); - } -} - -/** - * glade_project_selection_get: - * @project: a #GladeProject - * - * Returns: a #GList containing the #GtkWidget items currently selected in - * @project - */ -GList * -glade_project_selection_get (GladeProject *project) -{ - g_return_val_if_fail (GLADE_IS_PROJECT (project), NULL); - - return project->priv->selection; -} - -static GList * -glade_project_required_libs (GladeProject *project) -{ - GList *required = NULL, *l, *ll; - GladeWidget *gwidget; - gboolean listed; - - for (l = project->priv->objects; l; l = l->next) - { - gchar *catalog = NULL; - - gwidget = glade_widget_get_from_gobject (l->data); - g_assert (gwidget); - - g_object_get (gwidget->adaptor, "catalog", &catalog, NULL); - - if (catalog) - { - listed = FALSE; - for (ll = required; ll; ll = ll->next) - if (!strcmp ((gchar *)ll->data, catalog)) - { - listed = TRUE; - break; - } - - if (!listed) - required = g_list_prepend (required, catalog); - } - } - return required; -} - -#define GLADE_XML_COMMENT "Generated with "PACKAGE_NAME - -static gchar * -glade_project_make_comment () -{ - time_t now = time (NULL); - gchar *comment; - comment = g_strdup_printf (GLADE_XML_COMMENT" "PACKAGE_VERSION" on %s", - ctime (&now)); - glade_util_replace (comment, '\n', ' '); - - return comment; -} - -static void -glade_project_update_comment (GladeProject *project) -{ - gchar **lines, **l, *comment = NULL; - - /* If project has no comment -> add the new one */ - if (project->priv->comment == NULL) - { - project->priv->comment = glade_project_make_comment (); - return; - } - - for (lines = l = g_strsplit (project->priv->comment, "\n", 0); *l; l++) - { - gchar *start; - - /* Ignore leading spaces */ - for (start = *l; *start && g_ascii_isspace (*start); start++); - - if (g_str_has_prefix (start, GLADE_XML_COMMENT)) - { - /* This line was generated by glade -> updating... */ - g_free (*l); - *l = comment = glade_project_make_comment (); - } - } - - if (comment) - { - g_free (project->priv->comment); - project->priv->comment = g_strjoinv ("\n", lines); - } - - g_strfreev (lines); -} - -/** - * glade_project_write: - * @project: a #GladeProject - * - * Returns: a libglade's GladeInterface representation of the - * project and its contents - */ -static GladeInterface * -glade_project_write (GladeProject *project) -{ - GladeInterface *interface; - GList *required, *list, *tops = NULL; - gchar **strv = NULL; - guint i; - - interface = glade_parser_interface_new (); - - if ((required = glade_project_required_libs (project)) != NULL) - { - strv = g_malloc0 (g_list_length (required) * sizeof (char *)); - for (i = 0, list = required; list; i++, list = list->next) - strv[i] = list->data; /* list->data is allocated for us */ - - interface->n_requires = g_list_length (required); - interface->requires = strv; - - g_list_free (required); - } - - for (i = 0, list = project->priv->objects; list; list = list->next) - { - GladeWidget *widget; - GladeWidgetInfo *info; - - widget = glade_widget_get_from_gobject (list->data); - - /* - * Append toplevel widgets. Each widget then takes - * care of appending its children. - */ - if (widget->parent == NULL) - { - info = glade_widget_write (widget, interface); - if (!info) - return NULL; - - tops = g_list_prepend (tops, info); - ++i; - } - } - interface->n_toplevels = i; - interface->toplevels = (GladeWidgetInfo **) g_new (GladeWidgetInfo *, i); - for (i = 0, list = tops; list; list = list->next, ++i) - interface->toplevels[i] = list->data; - - g_list_free (tops); - - glade_project_update_comment (project); - interface->comment = g_strdup (project->priv->comment); - - return interface; -} - -static gboolean -loadable_interface (GladeInterface *interface, const gchar *path) -{ - GString *string = g_string_new (NULL); - gboolean loadable = TRUE; - guint i; - - /* Check for required plugins here - */ - for (i = 0; i < interface->n_requires; i++) - if (!glade_catalog_is_loaded (interface->requires[i])) - { - g_string_append (string, interface->requires[i]); - loadable = FALSE; - } - - if (loadable == FALSE) - glade_util_ui_message (glade_app_get_window(), - GLADE_UI_ERROR, - _("Failed to load %s.\n" - "The following required catalogs are unavailable: %s"), - path, string->str); - g_string_free (string, TRUE); - return loadable; -} - -static void -glade_project_fix_object_props (GladeProject *project) -{ - GList *l, *ll; - GValue *value; - GladeWidget *gwidget; - GladeProperty *property; - gchar *txt; - - for (l = project->priv->objects; l; l = l->next) - { - gwidget = glade_widget_get_from_gobject (l->data); - - for (ll = gwidget->properties; ll; ll = ll->next) - { - property = GLADE_PROPERTY (ll->data); - - if (glade_property_class_is_object (property->klass) && - (txt = g_object_get_data (G_OBJECT (property), - "glade-loaded-object")) != NULL) - { - /* Parse the object list and set the property to it - * (this magicly works for both objects & object lists) - */ - value = glade_property_class_make_gvalue_from_string - (property->klass, txt, project); - - glade_property_set_value (property, value); - - g_value_unset (value); - g_free (value); - - g_object_set_data (G_OBJECT (property), - "glade-loaded-object", NULL); - } - } - } -} - -static gboolean -glade_project_load_from_interface (GladeProject *project, - GladeInterface *interface, - const gchar *path) -{ - GladeWidget *widget; - guint i; - - g_return_val_if_fail (project != NULL, FALSE); - g_return_val_if_fail (interface != NULL, FALSE); - g_return_val_if_fail (path != NULL, FALSE); - - if (loadable_interface (interface, path) == FALSE) - return FALSE; - - project->priv->path = glade_util_canonical_path (path); - - project->priv->selection = NULL; - project->priv->objects = NULL; - project->priv->loading = TRUE; - - /* keep a comment */ - if (interface->comment) - project->priv->comment = g_strdup (interface->comment); - - for (i = 0; i < interface->n_toplevels; ++i) - { - widget = glade_widget_read ((gpointer) project, interface->toplevels[i]); - - if (!widget) - { - g_warning ("Failed to read a <widget> tag"); - continue; - } - - glade_project_add_object (project, NULL, widget->object); - } - - /* Reset project status here too so that you get a clean - * slate after calling glade_project_open(). - */ - project->priv->modified = FALSE; - project->priv->loading = FALSE; - - /* Emit "parse-finished" signal */ - g_signal_emit (project, glade_project_signals [PARSE_FINISHED], 0); - - /* Now we have to loop over all the object properties - * and fix'em all ('cause they probably weren't found) - */ - glade_project_fix_object_props (project); - - return TRUE; -} - -/** - * glade_project_load: - * @path: - * - * Opens a project at the given path. - * - * Returns: a new #GladeProject for the opened project on success, %NULL on - * failure - */ -GladeProject * -glade_project_load (const gchar *path) -{ - GladeProject *project; - gboolean retval; - - g_return_val_if_fail (path != NULL, NULL); - - project = glade_project_new (); - - retval = glade_project_load_from_file (project, path); - - if (retval) - { - return project; - } - else - { - g_object_unref (project); - return NULL; - } -} - -static void -glade_project_move_resources (GladeProject *project, - const gchar *old_dir, - const gchar *new_dir) -{ - GList *list, *resources; - gchar *old_name, *new_name; - - if (old_dir == NULL || /* <-- Cant help you :( */ - new_dir == NULL) /* <-- Unlikely */ - return; - - if ((resources = /* Nothing to do here */ - glade_project_list_resources (project)) == NULL) - return; - - for (list = resources; list; list = list->next) - { - old_name = g_build_filename - (old_dir, (gchar *)list->data, NULL); - new_name = g_build_filename - (new_dir, (gchar *)list->data, NULL); - glade_util_copy_file (old_name, new_name); - g_free (old_name); - g_free (new_name); - } - g_list_free (resources); -} - -/** - * glade_project_save: - * @project: a #GladeProject - * @path: location to save glade file - * @error: an error from the G_FILE_ERROR domain. - * - * Saves @project to the given path. - * - * Returns: %TRUE on success, %FALSE on failure - */ -gboolean -glade_project_save (GladeProject *project, const gchar *path, GError **error) -{ - GladeInterface *interface; - gboolean ret; - gchar *canonical_path; - - g_return_val_if_fail (GLADE_IS_PROJECT (project), FALSE); - g_return_val_if_fail (path != NULL, FALSE); - - interface = glade_project_write (project); - if (!interface) - { - g_warning ("Could not write glade document\n"); - return FALSE; - } - - ret = glade_parser_interface_dump (interface, path, error); - glade_parser_interface_destroy (interface); - - canonical_path = glade_util_canonical_path (path); - g_assert (canonical_path); - - if (project->priv->path == NULL || - strcmp (canonical_path, project->priv->path)) - { - gchar *old_dir, *new_dir; - - if (project->priv->path) - { - old_dir = g_path_get_dirname (project->priv->path); - new_dir = g_path_get_dirname (canonical_path); - - glade_project_move_resources (project, - old_dir, - new_dir); - g_free (old_dir); - g_free (new_dir); - } - project->priv->path = (g_free (project->priv->path), - g_strdup (canonical_path)); - } - - glade_project_set_readonly (project, - !glade_util_file_is_writeable (project->priv->path)); - - project->priv->mtime = glade_util_get_file_mtime (project->priv->path, NULL); - - glade_project_set_modified (project, FALSE, NULL); - - if (project->priv->unsaved_number > 0) - { - glade_id_allocator_release (get_unsaved_number_allocator (), project->priv->unsaved_number); - project->priv->unsaved_number = 0; - } - - g_free (canonical_path); - - return ret; -} - - -/** - * glade_project_undo: - * @project: a #GladeProject - * - * Undoes a #GladeCommand in this project. - */ -void -glade_project_undo (GladeProject *project) -{ - g_return_if_fail (GLADE_IS_PROJECT (project)); - GLADE_PROJECT_GET_CLASS (project)->undo (project); -} - -/** - * glade_project_undo: - * @project: a #GladeProject - * - * Redoes a #GladeCommand in this project. - */ -void -glade_project_redo (GladeProject *project) -{ - g_return_if_fail (GLADE_IS_PROJECT (project)); - GLADE_PROJECT_GET_CLASS (project)->redo (project); -} - -/** - * glade_project_next_undo_item: - * @project: a #GladeProject - * - * Gets the next undo item on @project's command stack. - * - * Returns: the #GladeCommand - */ -GladeCommand * -glade_project_next_undo_item (GladeProject *project) -{ - g_return_val_if_fail (GLADE_IS_PROJECT (project), NULL); - return GLADE_PROJECT_GET_CLASS (project)->next_undo_item (project); -} - - -/** - * glade_project_next_redo_item: - * @project: a #GladeProject - * - * Gets the next redo item on @project's command stack. - * - * Returns: the #GladeCommand - */ -GladeCommand * -glade_project_next_redo_item (GladeProject *project) -{ - g_return_val_if_fail (GLADE_IS_PROJECT (project), NULL); - return GLADE_PROJECT_GET_CLASS (project)->next_redo_item (project); -} - - - -/** - * glade_project_push_undo: - * @project: a #GladeProject - * @cmd: the #GladeCommand - * - * Pushes a newly created #GladeCommand onto @projects stack. - */ -void -glade_project_push_undo (GladeProject *project, GladeCommand *cmd) -{ - g_return_if_fail (GLADE_IS_PROJECT (project)); - g_return_if_fail (GLADE_IS_COMMAND (cmd)); - - GLADE_PROJECT_GET_CLASS (project)->push_undo (project, cmd); -} - -static GList * -walk_command (GList *list, gboolean forward) -{ - GladeCommand *cmd = list->data; - GladeCommand *next_cmd; - - if (forward) - list = list->next; - else - list = list->prev; - - next_cmd = list ? list->data : NULL; - - while (list && next_cmd->group_id != 0 && - next_cmd->group_id == cmd->group_id) - { - if (forward) - list = list->next; - else - list = list->prev; - - if (list) - next_cmd = list->data; - } - - return list; -} - -static void -undo_item_activated (GtkMenuItem *item, - GladeProject *project) -{ - gint index, next_index; - - GladeCommand *cmd = g_object_get_data (G_OBJECT (item), "command-data"); - GladeCommand *next_cmd; - - index = g_list_index (project->priv->undo_stack, cmd); - - do - { - next_cmd = glade_project_next_undo_item (project); - next_index = g_list_index (project->priv->undo_stack, next_cmd); - - glade_project_undo (project); - - } while (next_index > index); -} - -static void -redo_item_activated (GtkMenuItem *item, - GladeProject *project) -{ - gint index, next_index; - - GladeCommand *cmd = g_object_get_data (G_OBJECT (item), "command-data"); - GladeCommand *next_cmd; - - index = g_list_index (project->priv->undo_stack, cmd); - - do - { - next_cmd = glade_project_next_redo_item (project); - next_index = g_list_index (project->priv->undo_stack, next_cmd); - - glade_project_redo (project); - - } while (next_index < index); -} - - -/** - * glade_project_undo_items: - * @project: A #GladeProject - * - * Creates a menu of the undo items in the project stack - * - * Returns: A newly created menu - */ -GtkWidget * -glade_project_undo_items (GladeProject *project) -{ - GtkWidget *menu = NULL; - GtkWidget *item; - GladeCommand *cmd; - GList *l; - - for (l = project->priv->prev_redo_item; l; l = walk_command (l, FALSE)) - { - cmd = l->data; - - if (!menu) menu = gtk_menu_new (); - - item = gtk_menu_item_new_with_label (cmd->description); - gtk_widget_show (item); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), GTK_WIDGET (item)); - g_object_set_data (G_OBJECT (item), "command-data", cmd); - - g_signal_connect (G_OBJECT (item), "activate", - G_CALLBACK (undo_item_activated), project); - - } - - return menu; -} - -/** - * glade_project_redo_items: - * @project: A #GladeProject - * - * Creates a menu of the undo items in the project stack - * - * Returns: A newly created menu - */ -GtkWidget * -glade_project_redo_items (GladeProject *project) -{ - GtkWidget *menu = NULL; - GtkWidget *item; - GladeCommand *cmd; - GList *l; - - for (l = project->priv->prev_redo_item ? - project->priv->prev_redo_item->next : - project->priv->undo_stack; - l; l = walk_command (l, TRUE)) - { - cmd = l->data; - - if (!menu) menu = gtk_menu_new (); - - item = gtk_menu_item_new_with_label (cmd->description); - gtk_widget_show (item); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), GTK_WIDGET (item)); - g_object_set_data (G_OBJECT (item), "command-data", cmd); - - g_signal_connect (G_OBJECT (item), "activate", - G_CALLBACK (redo_item_activated), project); - - } - - return menu; -} - - -void -glade_project_reset_path (GladeProject *project) -{ - g_return_if_fail (GLADE_IS_PROJECT (project)); - project->priv->path = (g_free (project->priv->path), NULL); -} - -/** - * glade_project_get_tooltips: - * @project: a #GladeProject - * - * Returns: a #GtkTooltips object containing all tooltips for @project - */ -GtkTooltips * -glade_project_get_tooltips (GladeProject *project) -{ - g_return_val_if_fail (GLADE_IS_PROJECT (project), NULL); - return project->priv->tooltips; -} - -/** - * glade_project_set_accel_group: - * @project: A #GladeProject - * @accel_group: The @GtkAccelGroup - * - * Set @accel_group to every top level widget in @project. - */ -void -glade_project_set_accel_group (GladeProject *project, GtkAccelGroup *accel_group) -{ - GList *objects; - - g_return_if_fail (GLADE_IS_PROJECT (project) && GTK_IS_ACCEL_GROUP (accel_group)); - - objects = project->priv->objects; - while (objects) - { - if(GTK_IS_WINDOW (objects->data)) - { - if (project->priv->accel_group) - gtk_window_remove_accel_group (GTK_WINDOW (objects->data), project->priv->accel_group); - - gtk_window_add_accel_group (GTK_WINDOW (objects->data), accel_group); - } - - objects = objects->next; - } - - project->priv->accel_group = accel_group; -} - -/** - * glade_project_resource_fullpath: - * @project: The #GladeProject. - * @resource: The resource basename - * - * Returns: A newly allocated string holding the - * full path the the project resource. - */ -gchar * -glade_project_resource_fullpath (GladeProject *project, - const gchar *resource) -{ - gchar *fullpath, *project_dir; - - g_return_val_if_fail (GLADE_IS_PROJECT (project), NULL); - - if (project->priv->path == NULL) - return g_strdup (resource); - - project_dir = g_path_get_dirname (project->priv->path); - fullpath = g_build_filename (project_dir, resource, NULL); - g_free (project_dir); - - return fullpath; -} - - -static gboolean -find_resource_by_resource (GladeProperty *key, - const gchar *resource, - const gchar *resource_cmp) -{ - g_assert (resource); - g_assert (resource_cmp); - return (!strcmp (resource, resource_cmp)); -} - - - -/** - * glade_project_set_resource: - * @project: A #GladeProject - * @property: The #GladeProperty this resource is required by - * @resource: The resource file basename to be found in the same - * directory as the glade file. - * - * Adds/Modifies/Removes a resource from a project; any project resources - * will be copied when using "Save As...", when moving widgets across projects - * and will be copied into the project's directory when selected. - */ -void -glade_project_set_resource (GladeProject *project, - GladeProperty *property, - const gchar *resource) -{ - gchar *last_resource, *last_resource_dup = NULL, *base_resource = NULL; - gchar *fullpath, *dirname; - - g_return_if_fail (GLADE_IS_PROJECT (project)); - g_return_if_fail (GLADE_IS_PROPERTY (property)); - - if ((last_resource = - g_hash_table_lookup (project->priv->resources, property)) != NULL) - last_resource_dup = g_strdup (last_resource); - - /* Get dependable input */ - if (resource && resource[0] != '\0' && strcmp (resource, ".")) - base_resource = g_path_get_basename (resource); - - /* If the resource has been removed or the base name has changed - * then remove from hash and emit removed. - */ - if (last_resource_dup && - (base_resource == NULL || strcmp (last_resource_dup, base_resource))) - { - g_hash_table_remove (project->priv->resources, property); - - if (g_hash_table_find (project->priv->resources, - (GHRFunc)find_resource_by_resource, - last_resource_dup) == NULL) - g_signal_emit (G_OBJECT (project), - glade_project_signals [RESOURCE_REMOVED], - 0, last_resource_dup); - } - - /* Copy files when importing widgets with resources. - */ - if (project->priv->path) - { - dirname = g_path_get_dirname (project->priv->path); - fullpath = g_build_filename (dirname, base_resource, NULL); - - if (resource && project->priv->path && - g_file_test (resource, G_FILE_TEST_IS_REGULAR) && - strcmp (fullpath, resource)) - { - /* FIXME: In the case of copy/pasting widgets - * across projects we should ask the user about - * copying any resources. - */ - glade_util_copy_file (resource, fullpath); - } - g_free (fullpath); - g_free (dirname); - } - - if (base_resource) - { - - /* If the resource has been added or the base name has - * changed then emit added. - */ - if ((last_resource_dup == NULL || - strcmp (last_resource_dup, base_resource)) && - g_hash_table_find (project->priv->resources, - (GHRFunc)find_resource_by_resource, - base_resource) == NULL) - g_signal_emit (G_OBJECT (project), - glade_project_signals [RESOURCE_ADDED], - 0, base_resource); - - g_hash_table_insert (project->priv->resources, property, base_resource); - - } - g_free (last_resource_dup); -} - -static void -list_resources_accum (GladeProperty *key, - gchar *value, - GList **list) -{ - *list = g_list_prepend (*list, value); -} - - - -/** - * glade_project_list_resources: - * @project: A #GladeProject - * - * Returns: A newly allocated #GList of file basenames - * of resources in this project, note that the - * strings are not allocated and are unsafe to - * use once the projects state changes. - * The returned list should be freed with g_list_free. - */ -GList * -glade_project_list_resources (GladeProject *project) -{ - GList *list = NULL; - g_return_val_if_fail (GLADE_IS_PROJECT (project), NULL); - - g_hash_table_foreach (project->priv->resources, - (GHFunc)list_resources_accum, &list); - return list; -} - -const gchar * -glade_project_get_path (GladeProject *project) -{ - g_return_val_if_fail (GLADE_IS_PROJECT (project), NULL); - - return project->priv->path; -} - -gchar * -glade_project_get_name (GladeProject *project) -{ - g_return_val_if_fail (GLADE_IS_PROJECT (project), NULL); - - if (project->priv->path) - return g_filename_display_basename (project->priv->path); - else - return g_strdup_printf (_("Unsaved %i"), project->priv->unsaved_number); -} - -/** - * glade_project_is_loading: - * @project: A #GladeProject - * - * Returns: Whether the project is being loaded or not - * - */ -gboolean -glade_project_is_loading (GladeProject *project) -{ - g_return_val_if_fail (GLADE_IS_PROJECT (project), FALSE); - - return project->priv->loading; -} - -time_t -glade_project_get_file_mtime (GladeProject *project) -{ - g_return_val_if_fail (GLADE_IS_PROJECT (project), 0); - - return project->priv->mtime; -} - -const GList * -glade_project_get_objects (GladeProject *project) -{ - g_return_val_if_fail (GLADE_IS_PROJECT (project), NULL); - - return project->priv->objects; -} - -guint -glade_project_get_instance_count (GladeProject *project) -{ - g_return_val_if_fail (GLADE_IS_PROJECT (project), 0); - - return project->priv->instance_count; -} - -void -glade_project_set_instance_count (GladeProject *project, guint instance_count) -{ - g_return_if_fail (GLADE_IS_PROJECT (project)); - - project->priv->instance_count = instance_count; -} - -/** - * glade_project_get_modified: - * @project: a #GladeProject - * - * Get's whether the project has been modified since it was last saved. - * - * Returns: #TRUE if the project has been modified since it was last saved - */ -gboolean -glade_project_get_modified (GladeProject *project) -{ - g_return_val_if_fail (GLADE_IS_PROJECT (project), FALSE); - - return project->priv->modified; -} - diff --git a/gladeui/glade-project.h b/gladeui/glade-project.h deleted file mode 100644 index 442381a8..00000000 --- a/gladeui/glade-project.h +++ /dev/null @@ -1,165 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef __GLADE_PROJECT_H__ -#define __GLADE_PROJECT_H__ - -#include <gladeui/glade-widget.h> -#include <gladeui/glade-command.h> - -G_BEGIN_DECLS - -#define GLADE_TYPE_PROJECT (glade_project_get_type ()) -#define GLADE_PROJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_PROJECT, GladeProject)) -#define GLADE_PROJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_PROJECT, GladeProjectClass)) -#define GLADE_IS_PROJECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_PROJECT)) -#define GLADE_IS_PROJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_PROJECT)) -#define GLADE_PROJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GLADE_TYPE_PROJECT, GladeProjectClass)) - -typedef struct _GladeProjectPrivate GladeProjectPrivate; -typedef struct _GladeProjectClass GladeProjectClass; - -struct _GladeProject -{ - GObject parent_instance; - - GladeProjectPrivate *priv; -}; - -struct _GladeProjectClass -{ - GObjectClass parent_class; - - void (*add_object) (GladeProject *project, - GladeWidget *widget); - void (*remove_object) (GladeProject *project, - GladeWidget *widget); - - void (*undo) (GladeProject *project); - void (*redo) (GladeProject *project); - GladeCommand *(*next_undo_item) (GladeProject *project); - GladeCommand *(*next_redo_item) (GladeProject *project); - void (*push_undo) (GladeProject *project, - GladeCommand *command); - - void (*changed) (GladeProject *project, - GladeCommand *command, - gboolean forward); - - void (*widget_name_changed) (GladeProject *project, - GladeWidget *widget); - void (*selection_changed) (GladeProject *project); - void (*close) (GladeProject *project); - - void (*resource_added) (GladeProject *project, - const gchar *resource); - void (*resource_removed) (GladeProject *project, - const gchar *resource); - void (*parse_finished) (GladeProject *project); -}; - - -GType glade_project_get_type (void) G_GNUC_CONST; - -GladeProject *glade_project_new (void); - -gboolean glade_project_load_from_file (GladeProject *project, const gchar *path); - -GladeProject *glade_project_load (const gchar *path); - -gboolean glade_project_save (GladeProject *project, - const gchar *path, - GError **error); - -const gchar *glade_project_get_path (GladeProject *project); - -gchar *glade_project_get_name (GladeProject *project); - - -void glade_project_undo (GladeProject *project); - -void glade_project_redo (GladeProject *project); - -GladeCommand *glade_project_next_undo_item (GladeProject *project); - -GladeCommand *glade_project_next_redo_item (GladeProject *project); - -void glade_project_push_undo (GladeProject *project, - GladeCommand *cmd); - -GtkWidget *glade_project_undo_items (GladeProject *project); - -GtkWidget *glade_project_redo_items (GladeProject *project); - -void glade_project_reset_path (GladeProject *project); - -gboolean glade_project_get_readonly (GladeProject *project); - -const GList *glade_project_get_objects (GladeProject *project); - -void glade_project_add_object (GladeProject *project, - GladeProject *old_project, - GObject *object); - -void glade_project_remove_object (GladeProject *project, GObject *object); - -gboolean glade_project_has_object (GladeProject *project, GObject *object); - -GladeWidget *glade_project_get_widget_by_name (GladeProject *project, const char *name); - -char *glade_project_new_widget_name (GladeProject *project, const char *base_name); - -void glade_project_widget_name_changed (GladeProject *project, GladeWidget *widget, - const char *old_name); - -GtkTooltips *glade_project_get_tooltips (GladeProject *project); - -/* Selection */ - -gboolean glade_project_is_selected (GladeProject *project, - GObject *object); - -void glade_project_selection_set (GladeProject *project, - GObject *object, - gboolean emit_signal); - -void glade_project_selection_add (GladeProject *project, - GObject *object, - gboolean emit_signal); - -void glade_project_selection_remove (GladeProject *project, - GObject *object, - gboolean emit_signal); - -void glade_project_selection_clear (GladeProject *project, - gboolean emit_signal); - -void glade_project_selection_changed (GladeProject *project); - -GList *glade_project_selection_get (GladeProject *project); - -gboolean glade_project_get_has_selection (GladeProject *project); - -void glade_project_set_accel_group (GladeProject *project, - GtkAccelGroup *accel_group); - -void glade_project_set_resource (GladeProject *project, - GladeProperty *property, - const gchar *resource); - -GList *glade_project_list_resources (GladeProject *project); - -gchar *glade_project_resource_fullpath (GladeProject *project, - const gchar *resource); - -gboolean glade_project_is_loading (GladeProject *project); - -time_t glade_project_get_file_mtime (GladeProject *project); - -guint glade_project_get_instance_count (GladeProject *project); - -void glade_project_set_instance_count (GladeProject *project, guint instance_count); - -gboolean glade_project_get_modified (GladeProject *project); - -G_END_DECLS - -#endif /* __GLADE_PROJECT_H__ */ diff --git a/gladeui/glade-property-class.c b/gladeui/glade-property-class.c deleted file mode 100644 index 8720d7f0..00000000 --- a/gladeui/glade-property-class.c +++ /dev/null @@ -1,1854 +0,0 @@ -/* -*- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Authors: - * Chema Celorio <chema@celorio.com> - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> -#include <stdlib.h> -#include <gmodule.h> -#include <glib/gi18n-lib.h> - -#include "glade.h" -#include "glade-widget.h" -#include "glade-parameter.h" -#include "glade-property.h" -#include "glade-property-class.h" -#include "glade-editor-property.h" -#include "glade-debug.h" - -#define NUMERICAL_STEP_INCREMENT 1 -#define FLOATING_STEP_INCREMENT 0.01F -#define NUMERICAL_PAGE_INCREMENT 10 -#define NUMERICAL_PAGE_SIZE 1 - - -/* Hardcoded recognized atk actions - */ -typedef struct { - gchar *prop_name; - gchar *id; - gchar *name; - gchar *tooltip; -} GPCAtkPropertyTab; - -static const GPCAtkPropertyTab action_names_table[] = { - { "click", "atk-click", N_("Click"), - N_("Set the description of the Click atk action") }, - { "press", "atk-press", N_("Press"), - N_("Set the description of the Press atk action") }, - { "release", "atk-release", N_("Release"), - N_("Set the description of the Release atk action") }, - { "activate", "atk-activate", N_("Activate"), - N_("Set the description of the Activate atk action") } -}; - -static const GPCAtkPropertyTab relation_names_table[] = { - { "controlled-by", "atk-controlled-by", N_("Controlled By"), - N_("Indicates an object controlled by one or more target objects") }, - - { "controlled-for", "atk-controlled-for", N_("Controller For"), - N_("Indicates an object is a controller for one or more target objects") }, - - { "labelled-by", "atk-labelled-by", N_("Labelled By"), - N_("Indicates an object is labelled by one or more target objects") }, - - { "label-for", "atk-label-for", N_("Label For"), - N_("Indicates an object is a label for one or more target objects") }, - - { "member-of", "atk-member-of", N_("Member Of"), - N_("Indicates an object is a member of a group of one or more target objects") }, - - { "child-node-of", "atk-child-node-of", N_("Child Node Of"), - N_("Indicates an object is a cell in a treetable which is displayed " - "because a cell in the same column is expanded and identifies that cell") }, - - { "flows-to", "atk-flows-to", N_("Flows To"), - N_("Indicates that the object has content that flows logically to another " - "AtkObject in a sequential way (text-flow, for instance).") }, - - { "flows-from", "atk-flows-from", N_("Flows From"), - N_("Indicates that the object has content that flows logically from another " - "AtkObject in a sequential way, (for instance text-flow)") }, - - { "subwindow-of", "atk-subwindow-of", N_("Subwindow Of"), - N_("Indicates a subwindow attached to a component but otherwise has no " - "connection in the UI hierarchy to that component") }, - - { "embeds", "atk-embeds", N_("Embeds"), - N_("Indicates that the object visually embeds another object's content, " - "i.e. this object's content flows around another's content") }, - - { "embedded-by", "atk-embedded-by", N_("Embedded By"), - N_("Inverse of 'Embeds', indicates that this object's content " - "is visually embedded in another object") }, - - { "popup-for", "atk-popup-for", N_("Popup For"), - N_("Indicates that an object is a popup for another object") }, - - { "parent-window-of", "atk-parent-window-of", N_("Parent Window Of"), - N_("Indicates that an object is a parent window of another object") } -}; - - -/** - * glade_property_class_atk_realname: - * @atk_name: The id of the atk property - * - * Translates a GladePropertyClass->id to the name that should be - * saved into the glade file. - * - * Returns: a pointer to a constant string. - */ -G_CONST_RETURN gchar * -glade_property_class_atk_realname (const gchar *atk_name) -{ - gint i; - - g_return_val_if_fail (atk_name != NULL, NULL); - - for (i = 0; i < G_N_ELEMENTS (action_names_table); i++) - if (!strcmp (action_names_table[i].id, atk_name)) - return action_names_table[i].prop_name; - - for (i = 0; i < G_N_ELEMENTS (relation_names_table); i++) - if (!strcmp (relation_names_table[i].id, atk_name)) - return relation_names_table[i].prop_name; - - return atk_name; -} - -/** - * glade_property_class_new: - * @handle: A generic pointer (i.e. a #GladeWidgetClass) - * - * Returns: a new #GladePropertyClass - */ -GladePropertyClass * -glade_property_class_new (gpointer handle) -{ - GladePropertyClass *property_class; - - property_class = g_new0 (GladePropertyClass, 1); - property_class->handle = handle; - property_class->pspec = NULL; - property_class->id = NULL; - property_class->name = NULL; - property_class->tooltip = NULL; - property_class->def = NULL; - property_class->orig_def = NULL; - property_class->parameters = NULL; - property_class->displayable_values = NULL; - property_class->query = FALSE; - property_class->optional = FALSE; - property_class->optional_default = FALSE; - property_class->common = FALSE; - property_class->packing = FALSE; - property_class->is_modified = FALSE; - property_class->visible = TRUE; - property_class->save = TRUE; - property_class->save_always = FALSE; - property_class->ignore = FALSE; - property_class->resource = FALSE; - property_class->translatable = FALSE; - property_class->type = GPC_NORMAL; - property_class->virt = TRUE; - property_class->transfer_on_paste = FALSE; - property_class->weight = -1.0; - - return property_class; -} - -/** - * glade_property_class_clone: - * @property_class: a #GladePropertyClass - * - * Returns: a new #GladePropertyClass cloned from @property_class - */ -GladePropertyClass * -glade_property_class_clone (GladePropertyClass *property_class) -{ - GladePropertyClass *clone; - - g_return_val_if_fail (GLADE_IS_PROPERTY_CLASS (property_class), NULL); - - clone = g_new0 (GladePropertyClass, 1); - - memcpy (clone, property_class, sizeof(GladePropertyClass)); - - clone->pspec = property_class->pspec; - clone->id = g_strdup (clone->id); - clone->name = g_strdup (clone->name); - clone->tooltip = g_strdup (clone->tooltip); - - if (G_IS_VALUE (property_class->def)) - { - clone->def = g_new0 (GValue, 1); - g_value_init (clone->def, property_class->pspec->value_type); - g_value_copy (property_class->def, clone->def); - } - - if (G_IS_VALUE (property_class->orig_def)) - { - clone->orig_def = g_new0 (GValue, 1); - g_value_init (clone->orig_def, property_class->pspec->value_type); - g_value_copy (property_class->orig_def, clone->orig_def); - } - - if (clone->parameters) - { - GList *parameter; - - clone->parameters = g_list_copy (clone->parameters); - - for (parameter = clone->parameters; - parameter != NULL; - parameter = parameter->next) - parameter->data = - glade_parameter_clone ((GladeParameter*) parameter->data); - } - - if (property_class->displayable_values) - { - gint i, len; - GEnumValue val; - GArray *disp_val; - - disp_val = property_class->displayable_values; - len = disp_val->len; - - clone->displayable_values = g_array_new(FALSE, TRUE, sizeof(GEnumValue)); - - for (i = 0; i < len; i++) - { - val.value = g_array_index(disp_val, GEnumValue, i).value; - val.value_name = g_strdup (g_array_index(disp_val, GEnumValue, i).value_name); - val.value_nick = g_strdup (g_array_index(disp_val, GEnumValue, i).value_nick); - - g_array_append_val(clone->displayable_values, val); - } - } - - return clone; -} - -/** - * glade_property_class_free: - * @property_class: a #GladePropertyClass - * - * Frees @klass and its associated memory. - */ -void -glade_property_class_free (GladePropertyClass *property_class) -{ - if (property_class == NULL) - return; - - g_return_if_fail (GLADE_IS_PROPERTY_CLASS (property_class)); - - g_free (property_class->id); - g_free (property_class->tooltip); - g_free (property_class->name); - if (property_class->orig_def) - { - if (G_VALUE_TYPE (property_class->orig_def) != 0) - g_value_unset (property_class->orig_def); - g_free (property_class->orig_def); - } - if (property_class->def) - { - if (G_VALUE_TYPE (property_class->def) != 0) - g_value_unset (property_class->def); - g_free (property_class->def); - } - g_list_foreach (property_class->parameters, (GFunc) glade_parameter_free, NULL); - g_list_free (property_class->parameters); - - if (property_class->displayable_values) - { - gint i, len; - GArray *disp_val; - - disp_val = property_class->displayable_values; - len = disp_val->len; - - for (i = 0; i < len; i++) - { - gchar *name, *nick; - - name = (gchar *) g_array_index (disp_val, GEnumValue, i).value_name; - if (name) - g_free (name); - - nick = (gchar *) g_array_index (disp_val, GEnumValue, i).value_nick; - if (nick) - g_free (nick); - } - - g_array_free (disp_val, TRUE); - } - - g_free (property_class); -} - - -static GValue * -glade_property_class_get_default_from_spec (GParamSpec *spec) -{ - GValue *value; - value = g_new0 (GValue, 1); - g_value_init (value, spec->value_type); - g_param_value_set_default (spec, value); - return value; -} - - -static gchar * -glade_property_class_make_string_from_enum (GType etype, gint eval) -{ - GEnumClass *eclass; - gchar *string = NULL; - guint i; - - g_return_val_if_fail ((eclass = g_type_class_ref (etype)) != NULL, NULL); - for (i = 0; i < eclass->n_values; i++) - { - if (eval == eclass->values[i].value) - { - string = g_strdup (eclass->values[i].value_name); - break; - } - } - g_type_class_unref (eclass); - return string; -} - -static gchar * -glade_property_class_make_string_from_flags (GladePropertyClass *klass, guint fvals, gboolean displayables) -{ - GFlagsClass *fclass; - GFlagsValue *fvalue; - GString *string; - gchar *retval; - - g_return_val_if_fail ((fclass = g_type_class_ref (klass->pspec->value_type)) != NULL, NULL); - - string = g_string_new(""); - - while ((fvalue = g_flags_get_first_value(fclass, fvals)) != NULL) - { - const gchar *val_str = NULL; - - fvals &= ~fvalue->value; - - if (displayables) - val_str = glade_property_class_get_displayable_value(klass, fvalue->value); - - if (string->str[0]) - g_string_append(string, " | "); - - g_string_append (string, (val_str) ? val_str : fvalue->value_name); - - /* If one of the flags value is 0 this loop become infinite :) */ - if (fvalue->value == 0) break; - } - - retval = string->str; - - g_type_class_unref (fclass); - g_string_free(string, FALSE); - - return retval; -} - -static gchar * -glade_property_class_make_string_from_object (GladePropertyClass *property_class, - GObject *object) -{ - GladeWidget *gwidget; - gchar *string = NULL, *filename; - - if (!object) return NULL; - - if (property_class->pspec->value_type == GDK_TYPE_PIXBUF) - { - if ((filename = g_object_get_data (object, "GladeFileName")) != NULL) - string = g_path_get_basename (filename); - } - else if (property_class->pspec->value_type == GTK_TYPE_ADJUSTMENT) - { - GtkAdjustment *adj = GTK_ADJUSTMENT (object); - GString *str = g_string_sized_new (G_ASCII_DTOSTR_BUF_SIZE * 6 + 6); - gchar buff[G_ASCII_DTOSTR_BUF_SIZE]; - - g_ascii_dtostr (buff, sizeof (buff), adj->value); - g_string_append (str, buff); - - g_string_append_c (str, ' '); - g_ascii_dtostr (buff, sizeof (buff), adj->lower); - g_string_append (str, buff); - - g_string_append_c (str, ' '); - g_ascii_dtostr (buff, sizeof (buff), adj->upper); - g_string_append (str, buff); - - g_string_append_c (str, ' '); - g_ascii_dtostr (buff, sizeof (buff), adj->step_increment); - g_string_append (str, buff); - - g_string_append_c (str, ' '); - g_ascii_dtostr (buff, sizeof (buff), adj->page_increment); - g_string_append (str, buff); - - g_string_append_c (str, ' '); - g_ascii_dtostr (buff, sizeof (buff), adj->page_size); - g_string_append (str, buff); - - string = g_string_free (str, FALSE); - } - else if ((gwidget = glade_widget_get_from_gobject (object)) != NULL) - string = g_strdup (gwidget->name); - else - g_critical ("Object type property refers to an object " - "outside the project"); - - return string; -} - -static gchar * -glade_property_class_make_string_from_objects (GladePropertyClass *property_class, - GList *objects) -{ - GObject *object; - GList *list; - gchar *string = NULL, *obj_str, *tmp; - - for (list = objects; list; list = list->next) - { - object = list->data; - - obj_str = glade_property_class_make_string_from_object - (property_class, object); - - if (string == NULL) - string = obj_str; - else if (obj_str != NULL) - { - tmp = g_strdup_printf ("%s%s%s", string, GPC_OBJECT_DELIMITER, obj_str); - string = (g_free (string), tmp); - g_free (obj_str); - } - } - return string; -} - -/* This is not used to save in the glade file... and its a one-way conversion. - * its only usefull to show the values in the UI. - */ -static gchar * -glade_property_class_make_string_from_accels (GladePropertyClass *property_class, - GList *accels) -{ - GladeAccelInfo *info; - GString *string; - GList *list; - - string = g_string_new (""); - - for (list = accels; list; list = list->next) - { - info = list->data; - - if (info->modifiers & GDK_SHIFT_MASK) - g_string_append (string, "SHIFT-"); - - if (info->modifiers & GDK_CONTROL_MASK) - g_string_append (string, "CNTL-"); - - if (info->modifiers & GDK_MOD1_MASK) - g_string_append (string, "ALT-"); - - g_string_append (string, glade_builtin_string_from_key (info->key)); - - if (list->next) - g_string_append (string, ", "); - } - - return g_string_free (string, FALSE); -} - -/** - * glade_property_class_make_string_from_gvalue: - * @property_class: A #GladePropertyClass - * @value: A #GValue - * - * Returns: A newly allocated string representation of @value - */ -gchar * -glade_property_class_make_string_from_gvalue (GladePropertyClass *property_class, - const GValue *value) -{ - gchar *string = NULL, **strv, str[G_ASCII_DTOSTR_BUF_SIZE]; - GObject *object; - GdkColor *color; - GList *objects, *accels; - - if (G_IS_PARAM_SPEC_ENUM(property_class->pspec)) - { - gint eval = g_value_get_enum (value); - string = glade_property_class_make_string_from_enum - (property_class->pspec->value_type, eval); - } - else if (G_IS_PARAM_SPEC_FLAGS(property_class->pspec)) - { - guint flags = g_value_get_flags (value); - string = glade_property_class_make_string_from_flags - (property_class, flags, FALSE); - } - else if (G_IS_PARAM_SPEC_VALUE_ARRAY (property_class->pspec)) - { - GValueArray *value_array = g_value_get_boxed (value); - - if (value_array && value_array->n_values && - G_VALUE_HOLDS (&value_array->values [0], G_TYPE_STRING)) - { - gint i, n_values = value_array->n_values; - GString *gstring = g_string_new (NULL); - - for (i = 0; i < n_values; i++) - { - g_string_append (gstring, g_value_get_string (&value_array->values [i])); - g_string_append_c (gstring, '\n'); - } - string = gstring->str; - g_string_free (gstring, FALSE); - } - } - else if (G_IS_PARAM_SPEC_BOXED(property_class->pspec)) - { - if (property_class->pspec->value_type == GDK_TYPE_COLOR) - { - color = g_value_get_boxed (value); - if (color) - string = g_strdup_printf ("#%04x%04x%04x", - color->red, - color->green, - color->blue); - } - else if (property_class->pspec->value_type == G_TYPE_STRV) - { - strv = g_value_get_boxed (value); - if (strv) string = g_strjoinv ("\n", strv); - } - } - else if (G_IS_PARAM_SPEC_INT(property_class->pspec)) - string = g_strdup_printf ("%d", g_value_get_int (value)); - else if (G_IS_PARAM_SPEC_UINT(property_class->pspec)) - string = g_strdup_printf ("%u", g_value_get_uint (value)); - else if (G_IS_PARAM_SPEC_LONG(property_class->pspec)) - string = g_strdup_printf ("%ld", g_value_get_long (value)); - else if (G_IS_PARAM_SPEC_ULONG(property_class->pspec)) - string = g_strdup_printf ("%lu", g_value_get_ulong (value)); - else if (G_IS_PARAM_SPEC_INT64(property_class->pspec)) - string = g_strdup_printf ("%" G_GINT64_FORMAT, g_value_get_int64 (value)); - else if (G_IS_PARAM_SPEC_UINT64(property_class->pspec)) - string = g_strdup_printf ("%" G_GUINT64_FORMAT, g_value_get_uint64 (value)); - else if (G_IS_PARAM_SPEC_FLOAT(property_class->pspec)) - { - g_ascii_dtostr (str, sizeof (str), g_value_get_float (value)); - string = g_strdup (str); - } - else if (G_IS_PARAM_SPEC_DOUBLE(property_class->pspec)) - { - g_ascii_dtostr (str, sizeof (str), g_value_get_double (value)); - string = g_strdup (str); - } - else if (G_IS_PARAM_SPEC_STRING(property_class->pspec)) - { - if (property_class->resource && g_value_get_string (value) != NULL) - string = g_path_get_basename - (g_value_get_string (value)); - else - string = g_value_dup_string (value); - } - else if (G_IS_PARAM_SPEC_CHAR(property_class->pspec)) - string = g_strdup_printf ("%c", g_value_get_char (value)); - else if (G_IS_PARAM_SPEC_UCHAR(property_class->pspec)) - string = g_strdup_printf ("%c", g_value_get_uchar (value)); - else if (G_IS_PARAM_SPEC_UNICHAR(property_class->pspec)) - { - int len; - string = g_malloc (7); - len = g_unichar_to_utf8 (g_value_get_uint (value), string); - string[len] = '\0'; - } - else if (G_IS_PARAM_SPEC_BOOLEAN(property_class->pspec)) - string = g_strdup_printf ("%s", g_value_get_boolean (value) ? - GLADE_TAG_TRUE : GLADE_TAG_FALSE); - else if (G_IS_PARAM_SPEC_OBJECT(property_class->pspec)) - { - object = g_value_get_object (value); - string = glade_property_class_make_string_from_object - (property_class, object); - } - else if (GLADE_IS_PARAM_SPEC_OBJECTS (property_class->pspec)) - { - objects = g_value_get_boxed (value); - string = glade_property_class_make_string_from_objects - (property_class, objects); - } - else if (GLADE_IS_PARAM_SPEC_ACCEL (property_class->pspec)) - { - accels = g_value_get_boxed (value); - string = glade_property_class_make_string_from_accels - (property_class, accels); - } - else - g_critical ("Unsupported pspec type %s", - g_type_name(G_PARAM_SPEC_TYPE (property_class->pspec))); - - return string; -} - -/* This is copied exactly from libglade. I've just renamed the function. - */ -static guint -glade_property_class_make_flags_from_string (GType type, const char *string) -{ - GFlagsClass *fclass; - gchar *endptr, *prevptr; - guint i, j, ret = 0; - char *flagstr; - - ret = strtoul(string, &endptr, 0); - if (endptr != string) /* parsed a number */ - return ret; - - fclass = g_type_class_ref(type); - - - flagstr = g_strdup (string); - for (ret = i = j = 0; ; i++) { - gboolean eos; - - eos = flagstr [i] == '\0'; - - if (eos || flagstr [i] == '|') { - GFlagsValue *fv; - const char *flag; - gunichar ch; - - flag = &flagstr [j]; - endptr = &flagstr [i]; - - if (!eos) { - flagstr [i++] = '\0'; - j = i; - } - - /* trim spaces */ - for (;;) - { - ch = g_utf8_get_char (flag); - if (!g_unichar_isspace (ch)) - break; - flag = g_utf8_next_char (flag); - } - - while (endptr > flag) - { - prevptr = g_utf8_prev_char (endptr); - ch = g_utf8_get_char (prevptr); - if (!g_unichar_isspace (ch)) - break; - endptr = prevptr; - } - - if (endptr > flag) - { - *endptr = '\0'; - fv = g_flags_get_value_by_name (fclass, flag); - - if (!fv) - fv = g_flags_get_value_by_nick (fclass, flag); - - if (fv) - ret |= fv->value; - else - g_warning ("Unknown flag: '%s'", flag); - } - - if (eos) - break; - } - } - - g_free (flagstr); - - g_type_class_unref(fclass); - - return ret; -} - -/* This is copied exactly from libglade. I've just renamed the function. - */ -static gint -glade_property_class_make_enum_from_string (GType type, const char *string) -{ - GEnumClass *eclass; - GEnumValue *ev; - gchar *endptr; - gint ret = 0; - - ret = strtoul(string, &endptr, 0); - if (endptr != string) /* parsed a number */ - return ret; - - eclass = g_type_class_ref(type); - ev = g_enum_get_value_by_name(eclass, string); - if (!ev) ev = g_enum_get_value_by_nick(eclass, string); - if (ev) ret = ev->value; - - g_type_class_unref(eclass); - - return ret; -} - -static GObject * -glade_property_class_make_object_from_string (GladePropertyClass *property_class, - const gchar *string, - GladeProject *project) -{ - GObject *object = NULL; - gchar *fullpath; - - if (string == NULL) return NULL; - - if (property_class->pspec->value_type == GDK_TYPE_PIXBUF && project) - { - GdkPixbuf *pixbuf; - - fullpath = glade_project_resource_fullpath (project, string); - - if ((pixbuf = gdk_pixbuf_new_from_file (fullpath, NULL)) == NULL) - { - static GdkPixbuf *icon = NULL; - - if (icon == NULL) - { - GtkWidget *widget = gtk_label_new (""); - icon = gtk_widget_render_icon (widget, - GTK_STOCK_MISSING_IMAGE, - GTK_ICON_SIZE_MENU, NULL); - gtk_object_sink (GTK_OBJECT (widget)); - } - - pixbuf = gdk_pixbuf_copy (icon); - } - - if (pixbuf) - { - object = G_OBJECT (pixbuf); - g_object_set_data_full (object, "GladeFileName", - g_strdup (string), g_free); - } - - g_free (fullpath); - } - if (property_class->pspec->value_type == GTK_TYPE_ADJUSTMENT) - { - gdouble value, lower, upper, step_increment, page_increment, page_size; - gchar *pstring = (gchar*) string; - - value = g_ascii_strtod (pstring, &pstring); - lower = g_ascii_strtod (pstring, &pstring); - upper = g_ascii_strtod (pstring, &pstring); - step_increment = g_ascii_strtod (pstring, &pstring); - page_increment = g_ascii_strtod (pstring, &pstring); - page_size = g_ascii_strtod (pstring, &pstring); - - object = G_OBJECT (gtk_adjustment_new (value, lower, upper, step_increment, page_increment, page_size)); - } - else - { - GladeWidget *gwidget; - if ((gwidget = glade_project_get_widget_by_name - (project, string)) != NULL) - object = gwidget->object; - } - - return object; -} - -static GList * -glade_property_class_make_objects_from_string (GladePropertyClass *property_class, - const gchar *string, - GladeProject *project) -{ - GList *objects = NULL; - GObject *object; - gchar **split; - guint i; - - if ((split = g_strsplit (string, GPC_OBJECT_DELIMITER, 0)) != NULL) - { - for (i = 0; split[i]; i++) - { - if ((object = glade_property_class_make_object_from_string - (property_class, split[i], project)) != NULL) - objects = g_list_prepend (objects, object); - } - g_strfreev (split); - } - return objects; -} - -/** - * glade_property_class_make_gvalue_from_string: - * @property_class: A #GladePropertyClass - * @string: a string representation of this property - * @project: the glade project that the associated property - * belongs to. - * - * Returns: A #GValue created based on the @property_class - * and @string criteria. - */ -GValue * -glade_property_class_make_gvalue_from_string (GladePropertyClass *property_class, - const gchar *string, - GladeProject *project) -{ - GValue *value = g_new0 (GValue, 1); - gchar **strv, *fullpath; - GdkColor color = { 0, }; - - g_value_init (value, property_class->pspec->value_type); - - if (G_IS_PARAM_SPEC_ENUM(property_class->pspec)) - { - gint eval = glade_property_class_make_enum_from_string - (property_class->pspec->value_type, string); - g_value_set_enum (value, eval); - } - else if (G_IS_PARAM_SPEC_FLAGS(property_class->pspec)) - { - guint flags = glade_property_class_make_flags_from_string - (property_class->pspec->value_type, string); - g_value_set_flags (value, flags); - } - else if (G_IS_PARAM_SPEC_VALUE_ARRAY (property_class->pspec)) - { - GValueArray *value_array = g_value_array_new (0); - GValue str_value = {0, }; - gint i; - - g_value_init (&str_value, G_TYPE_STRING); - strv = g_strsplit (string, "\n", 0); - - for (i = 0; strv[i]; i++) - { - g_value_set_static_string (&str_value, strv[i]); - value_array = g_value_array_append (value_array, &str_value); - } - g_value_set_boxed (value, value_array); - g_strfreev (strv); - } - else if (G_IS_PARAM_SPEC_BOXED(property_class->pspec)) - { - if (property_class->pspec->value_type == GDK_TYPE_COLOR) - { - if (gdk_color_parse(string, &color) && - gdk_colormap_alloc_color(gtk_widget_get_default_colormap(), - &color, FALSE, TRUE)) - g_value_set_boxed(value, &color); - else - g_warning ("could not parse colour name `%s'", string); - } - else if (property_class->pspec->value_type == G_TYPE_STRV) - { - strv = g_strsplit (string, "\n", 0); - g_value_take_boxed (value, strv); - } - } - else if (G_IS_PARAM_SPEC_INT(property_class->pspec)) - g_value_set_int (value, g_ascii_strtoll (string, NULL, 10)); - else if (G_IS_PARAM_SPEC_UINT(property_class->pspec)) - g_value_set_uint (value, g_ascii_strtoull (string, NULL, 10)); - else if (G_IS_PARAM_SPEC_LONG(property_class->pspec)) - g_value_set_long (value, g_ascii_strtoll (string, NULL, 10)); - else if (G_IS_PARAM_SPEC_ULONG(property_class->pspec)) - g_value_set_ulong (value, g_ascii_strtoull (string, NULL, 10)); - else if (G_IS_PARAM_SPEC_INT64(property_class->pspec)) - g_value_set_int64 (value, g_ascii_strtoll (string, NULL, 10)); - else if (G_IS_PARAM_SPEC_UINT64(property_class->pspec)) - g_value_set_uint64 (value, g_ascii_strtoull (string, NULL, 10)); - else if (G_IS_PARAM_SPEC_FLOAT(property_class->pspec)) - g_value_set_float (value, (float) g_ascii_strtod (string, NULL)); - else if (G_IS_PARAM_SPEC_DOUBLE(property_class->pspec)) - g_value_set_double (value, g_ascii_strtod (string, NULL)); - else if (G_IS_PARAM_SPEC_STRING(property_class->pspec)) - { - /* This can be called when loading defaults from - * catalog files... it wont happen and we cant do - * anything for it. - */ - if (property_class->resource && project) - { - fullpath = g_build_filename - (glade_project_get_path (project), string, NULL); - g_value_set_string (value, fullpath); - g_free (fullpath); - } - else g_value_set_string (value, string); - } - else if (G_IS_PARAM_SPEC_CHAR(property_class->pspec)) - g_value_set_char (value, string[0]); - else if (G_IS_PARAM_SPEC_UCHAR(property_class->pspec)) - g_value_set_uchar (value, string[0]); - else if (G_IS_PARAM_SPEC_UNICHAR(property_class->pspec)) - g_value_set_uint (value, g_utf8_get_char (string)); - else if (G_IS_PARAM_SPEC_BOOLEAN(property_class->pspec)) - { - if (strcmp (string, GLADE_TAG_TRUE) == 0) - g_value_set_boolean (value, TRUE); - else - g_value_set_boolean (value, FALSE); - } - else if (G_IS_PARAM_SPEC_OBJECT(property_class->pspec)) - { - GObject *object = glade_property_class_make_object_from_string - (property_class, string, project); - g_value_set_object (value, object); - } - else if (GLADE_IS_PARAM_SPEC_OBJECTS (property_class->pspec)) - { - GList *objects = glade_property_class_make_objects_from_string - (property_class, string, project); - g_value_set_boxed (value, objects); - } - else - g_critical ("Unsupported pspec type %s", - g_type_name(G_PARAM_SPEC_TYPE (property_class->pspec))); - - return value; -} - -/** - * glade_property_class_make_gvalue_from_vl: - * @property_class: A #GladePropertyClass - * @vl: a #va_list holding one argument of the correct type - * specified by @property_class - * - * Returns: A #GValue created based on the @property_class - * and a @vl arg of the correct type. - */ -GValue * -glade_property_class_make_gvalue_from_vl (GladePropertyClass *klass, - va_list vl) -{ - GValue *value; - - g_return_val_if_fail (klass != NULL, NULL); - - value = g_new0 (GValue, 1); - g_value_init (value, klass->pspec->value_type); - - if (G_IS_PARAM_SPEC_ENUM(klass->pspec)) - g_value_set_enum (value, va_arg (vl, gint)); - else if (G_IS_PARAM_SPEC_FLAGS(klass->pspec)) - g_value_set_flags (value, va_arg (vl, gint)); - else if (G_IS_PARAM_SPEC_INT(klass->pspec)) - g_value_set_int (value, va_arg (vl, gint)); - else if (G_IS_PARAM_SPEC_UINT(klass->pspec)) - g_value_set_uint (value, va_arg (vl, guint)); - else if (G_IS_PARAM_SPEC_LONG(klass->pspec)) - g_value_set_long (value, va_arg (vl, glong)); - else if (G_IS_PARAM_SPEC_ULONG(klass->pspec)) - g_value_set_ulong (value, va_arg (vl, gulong)); - else if (G_IS_PARAM_SPEC_INT64(klass->pspec)) - g_value_set_int64 (value, va_arg (vl, gint64)); - else if (G_IS_PARAM_SPEC_UINT64(klass->pspec)) - g_value_set_uint64 (value, va_arg (vl, guint64)); - else if (G_IS_PARAM_SPEC_FLOAT(klass->pspec)) - g_value_set_float (value, (gfloat)va_arg (vl, gdouble)); - else if (G_IS_PARAM_SPEC_DOUBLE(klass->pspec)) - g_value_set_double (value, va_arg (vl, gdouble)); - else if (G_IS_PARAM_SPEC_STRING(klass->pspec)) - g_value_set_string (value, va_arg (vl, gchar *)); - else if (G_IS_PARAM_SPEC_CHAR(klass->pspec)) - g_value_set_char (value, (gchar)va_arg (vl, gint)); - else if (G_IS_PARAM_SPEC_UCHAR(klass->pspec)) - g_value_set_uchar (value, (guchar)va_arg (vl, guint)); - else if (G_IS_PARAM_SPEC_UNICHAR(klass->pspec)) - g_value_set_uint (value, va_arg (vl, gunichar)); - else if (G_IS_PARAM_SPEC_BOOLEAN(klass->pspec)) - g_value_set_boolean (value, va_arg (vl, gboolean)); - else if (G_IS_PARAM_SPEC_OBJECT(klass->pspec)) - g_value_set_object (value, va_arg (vl, gpointer)); - else if (G_IS_PARAM_SPEC_BOXED(klass->pspec)) - g_value_set_boxed (value, va_arg (vl, gpointer)); - else if (GLADE_IS_PARAM_SPEC_OBJECTS(klass->pspec)) - g_value_set_boxed (value, va_arg (vl, gpointer)); - else - g_critical ("Unsupported pspec type %s", - g_type_name(G_PARAM_SPEC_TYPE (klass->pspec))); - - return value; -} - -/** - * glade_property_class_make_gvalue: - * @klass: A #GladePropertyClass - * @...: an argument of the correct type specified by @property_class - * - * Returns: A #GValue created based on the @property_class - * and the provided argument. - */ -GValue * -glade_property_class_make_gvalue (GladePropertyClass *klass, - ...) -{ - GValue *value; - va_list vl; - - g_return_val_if_fail (klass != NULL, NULL); - - va_start (vl, klass); - value = glade_property_class_make_gvalue_from_vl (klass, vl); - va_end (vl); - - return value; -} - - -/** - * glade_property_class_set_vl_from_gvalue: - * @klass: A #GladePropertyClass - * @value: A #GValue to set - * @vl: a #va_list holding one argument of the correct type - * specified by @klass - * - * - * Sets @vl from @value based on @klass criteria. - */ -void -glade_property_class_set_vl_from_gvalue (GladePropertyClass *klass, - GValue *value, - va_list vl) -{ - g_return_if_fail (klass != NULL); - g_return_if_fail (value != NULL); - - /* The argument is a pointer of the specified type, cast the pointer and assign - * the value using the proper g_value_get_ variation. - */ - if (G_IS_PARAM_SPEC_ENUM(klass->pspec)) - *(gint *)(va_arg (vl, gint *)) = g_value_get_enum (value); - else if (G_IS_PARAM_SPEC_FLAGS(klass->pspec)) - *(gint *)(va_arg (vl, gint *)) = g_value_get_flags (value); - else if (G_IS_PARAM_SPEC_INT(klass->pspec)) - *(gint *)(va_arg (vl, gint *)) = g_value_get_int (value); - else if (G_IS_PARAM_SPEC_UINT(klass->pspec)) - *(guint *)(va_arg (vl, guint *)) = g_value_get_uint (value); - else if (G_IS_PARAM_SPEC_LONG(klass->pspec)) - *(glong *)(va_arg (vl, glong *)) = g_value_get_long (value); - else if (G_IS_PARAM_SPEC_ULONG(klass->pspec)) - *(gulong *)(va_arg (vl, gulong *)) = g_value_get_ulong (value); - else if (G_IS_PARAM_SPEC_INT64(klass->pspec)) - *(gint64 *)(va_arg (vl, gint64 *)) = g_value_get_int64 (value); - else if (G_IS_PARAM_SPEC_UINT64(klass->pspec)) - *(guint64 *)(va_arg (vl, guint64 *)) = g_value_get_uint64 (value); - else if (G_IS_PARAM_SPEC_FLOAT(klass->pspec)) - *(gfloat *)(va_arg (vl, gdouble *)) = g_value_get_float (value); - else if (G_IS_PARAM_SPEC_DOUBLE(klass->pspec)) - *(gdouble *)(va_arg (vl, gdouble *)) = g_value_get_double (value); - else if (G_IS_PARAM_SPEC_STRING(klass->pspec)) - *(gchar **)(va_arg (vl, gchar *)) = (gchar *)g_value_get_string (value); - else if (G_IS_PARAM_SPEC_CHAR(klass->pspec)) - *(gchar *)(va_arg (vl, gint *)) = g_value_get_char (value); - else if (G_IS_PARAM_SPEC_UCHAR(klass->pspec)) - *(guchar *)(va_arg (vl, guint *)) = g_value_get_uchar (value); - else if (G_IS_PARAM_SPEC_UNICHAR(klass->pspec)) - *(guint *)(va_arg (vl, gunichar *)) = g_value_get_uint (value); - else if (G_IS_PARAM_SPEC_BOOLEAN(klass->pspec)) - *(gboolean *)(va_arg (vl, gboolean *)) = g_value_get_boolean (value); - else if (G_IS_PARAM_SPEC_OBJECT(klass->pspec)) - *(gpointer *)(va_arg (vl, gpointer *)) = g_value_get_object (value); - else if (G_IS_PARAM_SPEC_BOXED(klass->pspec)) - *(gpointer *)(va_arg (vl, gpointer *)) = g_value_get_boxed (value); - else if (GLADE_IS_PARAM_SPEC_OBJECTS(klass->pspec)) - *(gpointer *)(va_arg (vl, gpointer *)) = g_value_get_boxed (value); - else - g_critical ("Unsupported pspec type %s", - g_type_name(G_PARAM_SPEC_TYPE (klass->pspec))); -} - -/** - * glade_property_class_get_from_gvalue: - * @klass: A #GladePropertyClass - * @value: A #GValue to set - * @...: a return location of the correct type - * - * - * Assignes the provided return location to @value - */ -void -glade_property_class_get_from_gvalue (GladePropertyClass *klass, - GValue *value, - ...) -{ - va_list vl; - - g_return_if_fail (klass != NULL); - - va_start (vl, value); - glade_property_class_set_vl_from_gvalue (klass, value, vl); - va_end (vl); -} - -/** - * glade_property_class_list_atk_relations: - * @handle: A generic pointer (i.e. a #GladeWidgetClass) - * @owner_type: The #GType of the owning widget class. - * - * Returns: a #GList of newly created atk relation #GladePropertyClass. - */ -GList * -glade_property_class_list_atk_relations (gpointer handle, - GType owner_type) -{ - const GPCAtkPropertyTab *relation_tab = NULL; - GladePropertyClass *property_class; - GList *list = NULL; - gint i; - - /* Loop through our hard-coded table enties */ - for (i = 0; i < G_N_ELEMENTS (relation_names_table); i++) - { - relation_tab = &relation_names_table[i]; - - property_class = glade_property_class_new (handle); - property_class->pspec = - glade_param_spec_objects (relation_tab->id, - _(relation_tab->name), - _(relation_tab->tooltip), - ATK_TYPE_IMPLEMENTOR, - G_PARAM_READWRITE); - - property_class->pspec->owner_type = owner_type; - property_class->id = g_strdup (relation_tab->id); - property_class->name = g_strdup (_(relation_tab->name)); - property_class->tooltip = g_strdup (_(relation_tab->tooltip)); - property_class->type = GPC_ATK_RELATION; - property_class->visible_lines = 2; - property_class->ignore = TRUE; - - property_class->def = - glade_property_class_make_gvalue_from_string - (property_class, "", NULL); - - property_class->orig_def = - glade_property_class_make_gvalue_from_string - (property_class, "", NULL); - - list = g_list_prepend (list, property_class); - } - - return g_list_reverse (list); -} - -/** - * glade_property_class_accel_property: - * @handle: A generic pointer (i.e. a #GladeWidgetClass) - * @owner_type: The #GType of the owning widget class. - * - * Returns: a newly created #GladePropertyClass for accelerators - * of the prescribed @owner_type. - */ -GladePropertyClass * -glade_property_class_accel_property (gpointer handle, - GType owner_type) -{ - GladePropertyClass *property_class; - GValue *def_value; - - property_class = glade_property_class_new (handle); - property_class->pspec = - glade_param_spec_accel ("accelerators", _("Accelerators"), - _("A list of accelerator keys"), - owner_type, - G_PARAM_READWRITE); - - - property_class->pspec->owner_type = owner_type; - property_class->id = g_strdup (g_param_spec_get_name - (property_class->pspec)); - property_class->name = g_strdup (g_param_spec_get_nick - (property_class->pspec)); - property_class->tooltip = g_strdup (g_param_spec_get_blurb - (property_class->pspec)); - - property_class->type = GPC_ACCEL_PROPERTY; - property_class->ignore = TRUE; - property_class->common = TRUE; - - /* Setup default */ - def_value = g_new0 (GValue, 1); - g_value_init (def_value, GLADE_TYPE_ACCEL_GLIST); - g_value_set_boxed (def_value, NULL); - property_class->def = def_value; - - /* Setup original default */ - def_value = g_new0 (GValue, 1); - g_value_init (def_value, GLADE_TYPE_ACCEL_GLIST); - g_value_set_boxed (def_value, NULL); - property_class->orig_def = def_value; - - return property_class; -} - - -/** - * glade_property_class_new_from_spec: - * @handle: A generic pointer (i.e. a #GladeWidgetClass) - * @spec: A #GParamSpec - * - * Returns: a newly created #GladePropertyClass based on @spec - * or %NULL if its unsupported. - */ -GladePropertyClass * -glade_property_class_new_from_spec (gpointer handle, - GParamSpec *spec) -{ - GObjectClass *gtk_widget_class; - GladePropertyClass *property_class; - - g_return_val_if_fail (spec != NULL, NULL); - gtk_widget_class = g_type_class_ref (GTK_TYPE_WIDGET); - - /* Only properties that are _new_from_spec() are - * not virtual properties - */ - property_class = glade_property_class_new (handle); - property_class->virt = FALSE; - property_class->pspec = spec; - - /* We only use the writable properties */ - if ((spec->flags & G_PARAM_WRITABLE) == 0) - goto failed; - - /* Register only editable properties. - */ - if (!glade_editor_property_supported (property_class->pspec)) - goto failed; - - property_class->id = g_strdup (spec->name); - property_class->name = g_strdup (g_param_spec_get_nick (spec)); - - - /* If its on the GtkWidgetClass, it goes in "common" - * (unless stipulated otherwise in the xml file) - */ - if (g_object_class_find_property (gtk_widget_class, - g_param_spec_get_name (spec)) != NULL) - property_class->common = TRUE; - - /* Flag the construct only properties */ - if (spec->flags & G_PARAM_CONSTRUCT_ONLY) - property_class->construct_only = TRUE; - - if (g_type_is_a (spec->owner_type, ATK_TYPE_OBJECT)) - { - property_class->type = GPC_ATK_PROPERTY; - property_class->ignore = TRUE; - - /* We only use the name and desctription props, - * they are both translatable. - */ - property_class->translatable = TRUE; - } - - if (!property_class->id || !property_class->name) - { - g_critical ("No name or id for " - "glade_property_class_new_from_spec, failed."); - goto failed; - } - - property_class->tooltip = g_strdup (g_param_spec_get_blurb (spec)); - property_class->orig_def = glade_property_class_get_default_from_spec (spec); - property_class->def = glade_property_class_get_default_from_spec (spec); - - g_type_class_unref (gtk_widget_class); - return property_class; - - failed: - glade_property_class_free (property_class); - g_type_class_unref (gtk_widget_class); - return NULL; -} - -/** - * glade_property_class_is_visible: - * @property_class: A #GladePropertyClass - * - * - * Returns: whether or not to show this property in the editor - */ -gboolean -glade_property_class_is_visible (GladePropertyClass *klass) -{ - g_return_val_if_fail (GLADE_IS_PROPERTY_CLASS (klass), FALSE); - return klass->visible; -} - -/** - * glade_property_class_is_object: - * @property_class: A #GladePropertyClass - * - * - * Returns: whether or not this is an object property - * that refers to another object in this project. - */ -gboolean -glade_property_class_is_object (GladePropertyClass *klass) -{ - g_return_val_if_fail (GLADE_IS_PROPERTY_CLASS (klass), FALSE); - - return (GLADE_IS_PARAM_SPEC_OBJECTS (klass->pspec) || - (G_IS_PARAM_SPEC_OBJECT(klass->pspec) && - klass->pspec->value_type != GDK_TYPE_PIXBUF && - klass->pspec->value_type != GTK_TYPE_ADJUSTMENT)); -} - - -/** - * glade_property_class_get_displayable_value: - * @klass: the property class to search in - * @value: the value to search - * - * Search a displayable values for @value in this property class. - * - * Returns: a (gchar *) if a diplayable value was found, otherwise NULL. - */ -const gchar * -glade_property_class_get_displayable_value(GladePropertyClass *klass, gint value) -{ - gint i, len; - GArray *disp_val = klass->displayable_values; - - if (disp_val == NULL) return NULL; - - len = disp_val->len; - - for (i = 0; i < len; i++) - if (g_array_index (disp_val, GEnumValue, i).value == value) - return g_array_index (disp_val, GEnumValue, i).value_name; - - return NULL; -} - -/** - * gpc_get_displayable_values_from_node: - * @node: a GLADE_TAG_DISPLAYABLE_VALUES node - * @values: an array of the values wich node overrides. - * @n_values: the size of @values - * - * Returns: a (GArray *) of GEnumValue of the overridden fields. - */ -static GArray * -gpc_get_displayable_values_from_node (GladeXmlNode *node, - GladePropertyClass *klass, - const gchar *domain) -{ - gpointer the_class = g_type_class_ref (klass->pspec->value_type); - GArray *array; - GladeXmlNode *child; - GEnumValue *values; - gint n_values, n = 0; - gboolean first_not_found = TRUE; - - if (G_IS_PARAM_SPEC_ENUM (klass->pspec)) - { - GEnumClass *eclass = the_class; - values = eclass->values; - n_values = eclass->n_values; - } - else - { - GFlagsClass *fclass = the_class; - values = (GEnumValue*)fclass->values; - n_values = fclass->n_values; - } - - if ((child = glade_xml_search_child (node, GLADE_TAG_VALUE)) == NULL) - return NULL; - - array = g_array_new (FALSE, TRUE, sizeof(GEnumValue)); - - child = glade_xml_node_get_children (node); - while (child != NULL) - { - gint i; - gchar *id, *name, *nick; - GEnumValue val; - - id = glade_xml_get_property_string_required (child, GLADE_TAG_ID, NULL); - name = glade_xml_get_property_string (child, GLADE_TAG_NAME); - nick = glade_xml_get_property_string (child, GLADE_TAG_NICK); - - for(i=0; i < n_values; i++) - { - if(strcmp (id, values[i].value_name) == 0) - { - gchar *translated; - - val=values[i]; - - /* Tedious memory handling; if dgettext doesn't return - * a translation, dont free the untranslated string. - */ - if (name) - { - translated = dgettext (domain, name); - if (name != translated) - { - val.value_name = g_strdup (translated); - g_free (name); - } - else - { - val.value_name = name; - } - } - if (nick) - { - translated = dgettext (domain, nick); - if (nick != translated) - { - val.value_nick = g_strdup (translated); - g_free (nick); - } - else - { - val.value_nick = nick; - } - } - - g_array_append_val (array, val); - break; - } - } - - if (i == n_values) - { - if (first_not_found) - { - g_message (_("Displayable value id not found in %s::%s"), - ((GladeWidgetAdaptor*)klass->handle)->name, klass->id); - first_not_found = FALSE; - } - g_message ("\t%s",id); - } - else n++; - - g_free(id); - - child = glade_xml_node_next (child); - } - - if (n != n_values) - { - gint i; - - g_message (_("%d missing displayable value for %s::%s"), n_values - n, - ((GladeWidgetAdaptor*)klass->handle)->name, klass->id); - - for(i=0; i < n_values; i++) - { - gboolean not_found = TRUE; - child = glade_xml_node_get_children (node); - while (child != NULL) - { - if(strcmp (glade_xml_get_property_string_required (child, GLADE_TAG_ID, NULL), - values[i].value_name) == 0) - { - not_found = FALSE; - break; - } - child = glade_xml_node_next (child); - } - - if (not_found) - g_message ("\t%s", values[i].value_name); - } - } - - g_type_class_unref (the_class); - - return array; -} - -/** - * glade_property_class_make_adjustment: - * @property_class: a pointer to the property class - * - * Creates and appropriate GtkAdjustment for use in the editor - * - * Returns: An appropriate #GtkAdjustment for use in the Property editor - */ -GtkAdjustment * -glade_property_class_make_adjustment (GladePropertyClass *property_class) -{ - gdouble min = 0, max = 0, def = 0; - gboolean float_range = FALSE; - - g_return_val_if_fail (property_class != NULL, NULL); - g_return_val_if_fail (property_class->pspec != NULL, NULL); - - if (G_IS_PARAM_SPEC_INT(property_class->pspec)) - { - min = (gdouble)((GParamSpecInt *) property_class->pspec)->minimum; - max = (gdouble)((GParamSpecInt *) property_class->pspec)->maximum; - def = (gdouble)((GParamSpecInt *) property_class->pspec)->default_value; - } else if (G_IS_PARAM_SPEC_UINT(property_class->pspec)) - { - min = (gdouble)((GParamSpecUInt *) property_class->pspec)->minimum; - max = (gdouble)((GParamSpecUInt *) property_class->pspec)->maximum; - def = (gdouble)((GParamSpecUInt *) property_class->pspec)->default_value; - } else if (G_IS_PARAM_SPEC_LONG(property_class->pspec)) - { - min = (gdouble)((GParamSpecLong *) property_class->pspec)->minimum; - max = (gdouble)((GParamSpecLong *) property_class->pspec)->maximum; - def = (gdouble)((GParamSpecLong *) property_class->pspec)->default_value; - } else if (G_IS_PARAM_SPEC_ULONG(property_class->pspec)) - { - min = (gdouble)((GParamSpecULong *) property_class->pspec)->minimum; - max = (gdouble)((GParamSpecULong *) property_class->pspec)->maximum; - def = (gdouble)((GParamSpecULong *) property_class->pspec)->default_value; - } else if (G_IS_PARAM_SPEC_INT64(property_class->pspec)) - { - min = (gdouble)((GParamSpecInt64 *) property_class->pspec)->minimum; - max = (gdouble)((GParamSpecInt64 *) property_class->pspec)->maximum; - def = (gdouble)((GParamSpecInt64 *) property_class->pspec)->default_value; - } else if (G_IS_PARAM_SPEC_UINT64(property_class->pspec)) - { - min = (gdouble)((GParamSpecUInt64 *) property_class->pspec)->minimum; - max = (gdouble)((GParamSpecUInt64 *) property_class->pspec)->maximum; - def = (gdouble)((GParamSpecUInt64 *) property_class->pspec)->default_value; - } else if (G_IS_PARAM_SPEC_FLOAT(property_class->pspec)) - { - float_range = TRUE; - min = (gdouble)((GParamSpecFloat *) property_class->pspec)->minimum; - max = (gdouble)((GParamSpecFloat *) property_class->pspec)->maximum; - def = (gdouble)((GParamSpecFloat *) property_class->pspec)->default_value; - } else if (G_IS_PARAM_SPEC_DOUBLE(property_class->pspec)) - { - float_range = TRUE; - min = (gdouble)((GParamSpecDouble *) property_class->pspec)->minimum; - max = (gdouble)((GParamSpecDouble *) property_class->pspec)->maximum; - def = (gdouble)((GParamSpecDouble *) property_class->pspec)->default_value; - } else - { - g_critical ("Can't make adjustment for pspec type %s", - g_type_name(G_PARAM_SPEC_TYPE (property_class->pspec))); - } - - return (GtkAdjustment *)gtk_adjustment_new (def, min, max, - float_range ? - FLOATING_STEP_INCREMENT : - NUMERICAL_STEP_INCREMENT, - NUMERICAL_PAGE_INCREMENT, - NUMERICAL_PAGE_SIZE); -} - -/** - * glade_property_class_update_from_node: - * @node: the property node - * @module: a #GModule to lookup symbols from the plugin - * @object_type: the #GType of the owning object - * @property_class: a pointer to the property class - * @domain: the domain to translate catalog strings from - * - * Updates the @property_class with the contents of the node in the xml - * file. Only the values found in the xml file are overridden. - * - * Returns: %TRUE on success. @property_class is set to NULL if the property - * has Disabled="TRUE". - */ -gboolean -glade_property_class_update_from_node (GladeXmlNode *node, - GModule *module, - GType object_type, - GladePropertyClass **property_class, - const gchar *domain) -{ - GladePropertyClass *klass; - gchar *buf, *translated; - GladeXmlNode *child; - - g_return_val_if_fail (property_class != NULL, FALSE); - - /* for code cleanliness... */ - klass = *property_class; - - g_return_val_if_fail (GLADE_IS_PROPERTY_CLASS (klass), FALSE); - g_return_val_if_fail (glade_xml_node_verify (node, GLADE_TAG_PROPERTY), FALSE); - - /* check the id */ - buf = glade_xml_get_property_string_required (node, GLADE_TAG_ID, NULL); - if (!buf) - return FALSE; - g_free (buf); - - - /* If Disabled="TRUE" we set *property_class to NULL, but we return TRUE. - * The caller may want to remove this property from its list. - */ - if (glade_xml_get_property_boolean (node, GLADE_TAG_DISABLED, FALSE)) - { - glade_property_class_free (klass); - *property_class = NULL; - return TRUE; - } - - /* ...the spec... */ - buf = glade_xml_get_value_string (node, GLADE_TAG_SPEC); - if (buf) - { - /* ... get the tooltip from the pspec ... */ - if ((klass->pspec = glade_utils_get_pspec_from_funcname (buf)) != NULL) - { - /* Make sure we can tell properties apart by there - * owning class. - */ - klass->pspec->owner_type = object_type; - - if (klass->tooltip) g_free (klass->tooltip); - if (klass->name) g_free (klass->name); - - klass->tooltip = g_strdup (g_param_spec_get_blurb (klass->pspec)); - klass->name = g_strdup (g_param_spec_get_nick (klass->pspec)); - - if (klass->pspec->flags & G_PARAM_CONSTRUCT_ONLY) - klass->construct_only = TRUE; - - if (klass->def) { - g_value_unset (klass->def); - g_free (klass->def); - } - klass->def = glade_property_class_get_default_from_spec (klass->pspec); - - if (klass->orig_def == NULL) - klass->orig_def = - glade_property_class_get_default_from_spec (klass->pspec); - - } - - g_free (buf); - } - else if (!klass->pspec) - { - /* If catalog file didn't specify a pspec function - * and this property isn't found by introspection - * we simply handle it as a property that has been - * disabled. - */ - glade_property_class_free (klass); - *property_class = NULL; - return TRUE; - } - - /* Get the default */ - if ((buf = glade_xml_get_property_string (node, GLADE_TAG_DEFAULT)) != NULL) - { - if (klass->def) { - g_value_unset (klass->def); - g_free (klass->def); - } - klass->def = glade_property_class_make_gvalue_from_string (klass, buf, NULL); - g_free (buf); - } - - /* If needed, update the name... */ - if ((buf = glade_xml_get_property_string (node, GLADE_TAG_NAME)) != NULL) - { - g_free (klass->name); - - translated = dgettext (domain, buf); - if (buf != translated) - { - /* translated is owned by gettext */ - klass->name = g_strdup (translated); - g_free (buf); - } - else - { - klass->name = buf; - } - } - - /* ...and the tooltip */ - if ((buf = glade_xml_get_value_string (node, GLADE_TAG_TOOLTIP)) != NULL) - { - g_free (klass->tooltip); - - translated = dgettext (domain, buf); - if (buf != translated) - { - /* translated is owned by gettext */ - klass->tooltip = g_strdup (translated); - g_free (buf); - } - else - { - klass->tooltip = buf; - } - } - - /* Visible lines */ - glade_xml_get_value_int (node, GLADE_TAG_VISIBLE_LINES, &klass->visible_lines); - - /* Get the Parameters */ - if ((child = glade_xml_search_child (node, GLADE_TAG_PARAMETERS)) != NULL) - klass->parameters = glade_parameter_list_new_from_node (klass->parameters, child); - - /* Whether or not the property is translatable. This is only used for - * string properties. - */ - klass->translatable = glade_xml_get_property_boolean (node, GLADE_TAG_TRANSLATABLE, - klass->translatable); - - /* common, optional, etc */ - klass->common = glade_xml_get_property_boolean (node, GLADE_TAG_COMMON, klass->common); - klass->optional = glade_xml_get_property_boolean (node, GLADE_TAG_OPTIONAL, klass->optional); - klass->query = glade_xml_get_property_boolean (node, GLADE_TAG_QUERY, klass->query); - klass->save = glade_xml_get_property_boolean (node, GLADE_TAG_SAVE, klass->save); - klass->visible = glade_xml_get_property_boolean (node, GLADE_TAG_VISIBLE, klass->visible); - klass->ignore = glade_xml_get_property_boolean (node, GLADE_TAG_IGNORE, klass->ignore); - klass->resource = glade_xml_get_property_boolean (node, GLADE_TAG_RESOURCE, klass->resource); - klass->weight = glade_xml_get_property_double (node, GLADE_TAG_WEIGHT, klass->weight); - klass->transfer_on_paste = glade_xml_get_property_boolean (node, GLADE_TAG_TRANSFER_ON_PASTE, klass->transfer_on_paste); - klass->save_always = glade_xml_get_property_boolean (node, GLADE_TAG_SAVE_ALWAYS, klass->save_always); - - /* If this property's value is an enumeration or flag then we try to get the displayable values */ - if (G_IS_PARAM_SPEC_ENUM(klass->pspec) || - G_IS_PARAM_SPEC_FLAGS(klass->pspec)) - { - child = glade_xml_search_child (node, GLADE_TAG_DISPLAYABLE_VALUES); - if (child) - { - klass->displayable_values = gpc_get_displayable_values_from_node - (child, klass, domain); - } - else if (!klass->displayable_values && klass->visible && - klass->pspec->value_type != GLADE_TYPE_STOCK && - klass->pspec->value_type != GLADE_TYPE_STOCK_IMAGE) - { - /* Displayable values could be defined in the parent class - * We do not need displayable values if the property is not visible - */ - g_message (_("No displayable values for %s::%s"), - ((GladeWidgetAdaptor*)klass->handle)->name, klass->id); - } - } - - /* A sprinkle of hard-code to get atk properties working right - */ - if (glade_xml_get_property_boolean (node, GLADE_TAG_ATK_ACTION, FALSE)) - klass->type = GPC_ATK_ACTION; - else if (glade_xml_get_property_boolean (node, GLADE_TAG_ATK_PROPERTY, FALSE)) - { - if (GLADE_IS_PARAM_SPEC_OBJECTS (klass->pspec)) - klass->type = GPC_ATK_RELATION; - else - klass->type = GPC_ATK_PROPERTY; - } - - /* Special case accelerators here. - */ - if (GLADE_IS_PARAM_SPEC_ACCEL (klass->pspec)) - klass->type = GPC_ACCEL_PROPERTY; - - /* Special case pixbuf here. - */ - if (klass->pspec->value_type == GDK_TYPE_PIXBUF) - klass->resource = TRUE; - - if (klass->optional) - klass->optional_default = - glade_xml_get_property_boolean (node, GLADE_TAG_OPTIONAL_DEFAULT, - klass->optional_default); - - /* notify that we changed the property class */ - klass->is_modified = TRUE; - - return TRUE; -} - - - -/** - * glade_property_class_match: - * @klass: a #GladePropertyClass - * @comp: a #GladePropertyClass - * - * Returns: whether @klass and @comp are a match or not - * (properties in seperate decendant heirarchies that - * have the same name are not matches). - */ -gboolean -glade_property_class_match (GladePropertyClass *klass, - GladePropertyClass *comp) -{ - g_return_val_if_fail (klass != NULL, FALSE); - g_return_val_if_fail (comp != NULL, FALSE); - - return (strcmp (klass->id, comp->id) == 0 && - klass->packing == comp->packing && - klass->pspec->owner_type == comp->pspec->owner_type); -} - - -/** - * glade_property_class_void_value: - * @klass: a #GladePropertyClass - * - * Returns: Whether @value for this @klass is voided; a voided value - * can be a %NULL value for boxed or object type param specs. - */ -gboolean -glade_property_class_void_value (GladePropertyClass *klass, - GValue *value) -{ - g_return_val_if_fail (GLADE_IS_PROPERTY_CLASS (klass), FALSE); - - if (G_IS_PARAM_SPEC_OBJECT (klass->pspec) && - g_value_get_object (value) == NULL) - return TRUE; - else if (G_IS_PARAM_SPEC_BOXED (klass->pspec) && - g_value_get_boxed (value) == NULL) - return TRUE; - - return FALSE; -} diff --git a/gladeui/glade-property-class.h b/gladeui/glade-property-class.h deleted file mode 100644 index 57a66757..00000000 --- a/gladeui/glade-property-class.h +++ /dev/null @@ -1,221 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef __GLADE_PROPERTY_CLASS_H__ -#define __GLADE_PROPERTY_CLASS_H__ - -#include <glib.h> -#include <glib-object.h> -#include <gtk/gtkadjustment.h> - -G_BEGIN_DECLS - -/* The GladePropertyClass structure parameters of a GladeProperty. - * All entries in the GladeEditor are GladeProperties (except signals) - * All GladeProperties are associated with a GParamSpec. - */ -#define GLADE_PROPERTY_CLASS(gpc) ((GladePropertyClass *) gpc) -#define GLADE_IS_PROPERTY_CLASS(gpc) (gpc != NULL) - -#define GPC_OBJECT_DELIMITER ", " -#define GPC_PROPERTY_NAMELEN 512 /* Enough space for a property name I think */ - -typedef struct _GladePropertyClass GladePropertyClass; - -/** - * GPCType: - * @GPC_NORMAL: is not an atk property - * @GPC_ATK_PROPERTY: is a property of an #AtkImplementor object - * @GPC_ATK_RELATION: is an atk relation set property - * @GPC_ATK_ACTION: is an atk action property - * @GPC_ACCEL_PROPERTY: is an accelerator key property - */ -typedef enum { - GPC_NORMAL, - GPC_ATK_PROPERTY, - GPC_ATK_RELATION, - GPC_ATK_ACTION, - GPC_ACCEL_PROPERTY -} GPCType; - -struct _GladePropertyClass -{ - GPCType type; /* A symbolic type used to load/save properties differently - */ - - gpointer handle; /* The GladeWidgetClass that this property class - * was created for. - */ - - GParamSpec *pspec; /* The Parameter Specification for this property. - */ - - gchar *id; /* The id of the property. Like "label" or "xpad" - * this is a non-translatable string - */ - - gchar *name; /* The name of the property. Like "Label" or "X Pad" - * this is a translatable string - */ - - gchar *tooltip; /* The default tooltip for the property editor rows. - */ - - gboolean virt; /* Whether this is a virtual property with its pspec supplied - * via the catalog (or hard code-paths); or FALSE if its a real - * GObject introspected property - */ - - GValue *def; /* The default value for this property (this will exist - * as a copy of orig_def if not specified by the catalog) - */ - - GValue *orig_def; /* The real default value obtained through introspection. - * (used to decide whether we should write to the - * glade file or not, or to restore the loaded property - * correctly); all property classes have and orig_def. - */ - - GList *parameters; /* list of GladeParameter objects. This list - * provides with an extra set of key-value - * pairs to specify aspects of this property. - * - * This is unused by glade and only maintained - * to be of possible use in plugin code. - */ - - GArray *displayable_values; /* If this property's value is an enumeration/flags and - * there is some value name overridden in a catalog - * then it will point to a GEnumValue array with the - * modified names, otherwise NULL. - */ - - gboolean query; /* Whether we should explicitly ask the user about this property - * when instantiating a widget with this property (through a popup - * dialog). - */ - - gboolean optional; /* Some properties are optional by nature like - * default width. It can be set or not set. A - * default property has a check box in the - * left that enables/disables the input - */ - - gboolean optional_default; /* For optional values, what the default is */ - - gboolean construct_only; /* Whether this property is G_PARAM_CONSTRUCT_ONLY or not */ - - gboolean common; /* Common properties go in the common tab */ - gboolean packing; /* Packing properties go in the packing tab */ - - - gboolean translatable; /* The property should be translatable, which - * means that it needs extra parameters in the - * UI. - */ - - gint visible_lines; /* When this pspec calls for a text editor, how many - * lines should be visible in the editor. - */ - - /* These three are the master switches for the glade-file output, - * property editor availability & live object updates in the glade environment. - */ - gboolean save; /* Whether we should save to the glade file or not - * (mostly just for custom glade properties) - */ - gboolean save_always; /* Used to make a special case exception and always - * save this property regardless of what the default - * value is (used for some special cases like properties - * that are assigned initial values in composite widgets - * or derived widget code). - */ - gboolean visible; /* Whether or not to show this property in the editor - */ - gboolean ignore; /* When true, we will not sync the object when the property - * changes. - */ - - - gboolean is_modified; /* If true, this property_class has been "modified" from the - * the standard property by a xml file. */ - - gboolean resource; /* Some property types; such as some file specifying - * string properties or GDK_TYPE_PIXBUF properties; are - * resource files and are treated specialy (a filechooser - * popup is used and the resource is copied to the project - * directory). - */ - - gboolean transfer_on_paste; /* If this is a packing prop, - * wether we should transfer it on paste. - */ - - gdouble weight; /* This will determine the position of this property in - * the editor. - */ - -}; - - -GladePropertyClass *glade_property_class_new (gpointer handle); - -GladePropertyClass *glade_property_class_new_from_spec (gpointer handle, - GParamSpec *spec); - -GList *glade_property_class_list_atk_relations (gpointer handle, - GType owner_type); - -GladePropertyClass *glade_property_class_accel_property (gpointer handle, - GType owner_type); - - -GladePropertyClass *glade_property_class_clone (GladePropertyClass *property_class); - -void glade_property_class_free (GladePropertyClass *property_class); - -gboolean glade_property_class_is_visible (GladePropertyClass *property_class); - -gboolean glade_property_class_is_object (GladePropertyClass *property_class); - -GValue *glade_property_class_make_gvalue_from_string (GladePropertyClass *property_class, - const gchar *string, - GladeProject *project); - -gchar *glade_property_class_make_string_from_gvalue (GladePropertyClass *property_class, - const GValue *value); - -GValue *glade_property_class_make_gvalue_from_vl (GladePropertyClass *property_class, - va_list vl); - -void glade_property_class_set_vl_from_gvalue (GladePropertyClass *klass, - GValue *value, - va_list vl); - -GValue *glade_property_class_make_gvalue (GladePropertyClass *klass, - ...); - -void glade_property_class_get_from_gvalue (GladePropertyClass *klass, - GValue *value, - ...); - -gboolean glade_property_class_update_from_node (GladeXmlNode *node, - GModule *module, - GType object_type, - GladePropertyClass **property_class, - const gchar *domain); - -G_CONST_RETURN gchar *glade_property_class_get_displayable_value (GladePropertyClass *klass, - gint value); - -GtkAdjustment *glade_property_class_make_adjustment (GladePropertyClass *property_class); - -gboolean glade_property_class_match (GladePropertyClass *klass, - GladePropertyClass *comp); - -gboolean glade_property_class_void_value (GladePropertyClass *klass, - GValue *value); - -G_CONST_RETURN gchar *glade_property_class_atk_realname (const gchar *atk_name); - -G_END_DECLS - -#endif /* __GLADE_PROPERTY_CLASS_H__ */ diff --git a/gladeui/glade-property.c b/gladeui/glade-property.c deleted file mode 100644 index 4bd9ccf9..00000000 --- a/gladeui/glade-property.c +++ /dev/null @@ -1,1661 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2001 Ximian, Inc. - * Copyright (C) 2006 The GNOME Foundation. - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Authors: - * Chema Celorio <chema@celorio.com> - * Tristan Van Berkom <tvb@gnome.org> - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdio.h> -#include <stdlib.h> /* for atoi and atof */ -#include <string.h> - -#include <glib/gi18n-lib.h> - -#include "glade.h" -#include "glade-widget.h" -#include "glade-property.h" -#include "glade-property-class.h" -#include "glade-parameter.h" -#include "glade-project.h" -#include "glade-widget-adaptor.h" -#include "glade-debug.h" -#include "glade-app.h" -#include "glade-editor.h" -#include "glade-marshallers.h" - -enum -{ - VALUE_CHANGED, - TOOLTIP_CHANGED, - LAST_SIGNAL -}; - -enum -{ - PROP_0, - PROP_ENABLED, - PROP_SENSITIVE, - PROP_I18N_TRANSLATABLE, - PROP_I18N_HAS_CONTEXT, - PROP_I18N_COMMENT -}; - -static guint glade_property_signals[LAST_SIGNAL] = { 0 }; -static GObjectClass* parent_class = NULL; - -/******************************************************************************* - GladeProperty class methods - *******************************************************************************/ -static GladeProperty * -glade_property_dup_impl (GladeProperty *template_prop, GladeWidget *widget) -{ - GladeProperty *property; - - property = g_object_new (GLADE_TYPE_PROPERTY, - "enabled", template_prop->enabled, - "sensitive", template_prop->sensitive, - "i18n-translatable", template_prop->i18n_translatable, - "i18n-has-context", template_prop->i18n_has_context, - "i18n-comment", template_prop->i18n_comment, - NULL); - property->klass = template_prop->klass; - property->widget = widget; - property->value = g_new0 (GValue, 1); - - property->insensitive_tooltip = - template_prop->insensitive_tooltip ? - g_strdup (template_prop->insensitive_tooltip) : NULL; - - g_value_init (property->value, template_prop->value->g_type); - g_value_copy (template_prop->value, property->value); - - return property; -} - -static gboolean -glade_property_equals_value_impl (GladeProperty *property, - const GValue *value) -{ - if (G_IS_PARAM_SPEC_STRING (property->klass->pspec)) - { - const gchar *prop_str, *value_str; - - /* in string specs; NULL and '\0' are - * treated as equivalent. - */ - prop_str = g_value_get_string (property->value); - value_str = g_value_get_string (value); - - if (prop_str == NULL && value_str && value_str[0] == '\0') - return TRUE; - else if (value_str == NULL && prop_str && prop_str[0] == '\0') - return TRUE; - } - - return !g_param_values_cmp (property->klass->pspec, - property->value, value); -} - - -static void -glade_property_update_prop_refs (GladeProperty *property, - const GValue *old_value, - const GValue *new_value) -{ - GladeWidget *gold, *gnew; - GObject *old_object, *new_object; - GList *old_list, *new_list, *list, *removed, *added; - - if (GLADE_IS_PARAM_SPEC_OBJECTS (property->klass->pspec)) - { - /* Make our own copies incase we're walking an - * unstable list - */ - old_list = g_value_dup_boxed (old_value); - new_list = g_value_dup_boxed (new_value); - - /* Diff up the GList */ - removed = glade_util_removed_from_list (old_list, new_list); - added = glade_util_added_in_list (old_list, new_list); - - /* Adjust the appropriate prop refs */ - for (list = removed; list; list = list->next) - { - old_object = list->data; - gold = glade_widget_get_from_gobject (old_object); - glade_widget_remove_prop_ref (gold, property); - } - for (list = added; list; list = list->next) - { - new_object = list->data; - gnew = glade_widget_get_from_gobject (new_object); - glade_widget_add_prop_ref (gnew, property); - } - - g_list_free (removed); - g_list_free (added); - g_list_free (old_list); - g_list_free (new_list); - } - else - { - if ((old_object = g_value_get_object (old_value)) != NULL) - { - gold = glade_widget_get_from_gobject (old_object); - glade_widget_remove_prop_ref (gold, property); - } - - if ((new_object = g_value_get_object (new_value)) != NULL) - { - gnew = glade_widget_get_from_gobject (new_object); - glade_widget_add_prop_ref (gnew, property); - } - } -} - -static gboolean -glade_property_verify (GladeProperty *property, const GValue *value) -{ - if (property->klass->packing) - { - if (property->widget->parent) - return glade_widget_adaptor_child_verify_property (property->widget->parent->adaptor, - property->widget->parent->object, - property->widget->object, - property->klass->id, - value); - else - return FALSE; - } - else - { - return glade_widget_adaptor_verify_property (property->widget->adaptor, - property->widget->object, - property->klass->id, - value); - } -} - -static void -glade_property_set_value_impl (GladeProperty *property, const GValue *value) -{ - GladeProject *project = property->widget ? - glade_widget_get_project (property->widget) : NULL; - gboolean changed = FALSE; - GValue old_value = {0,}; - -#if 0 - { - gchar *str = glade_property_class_make_string_from_gvalue - (property->klass, value); - g_print ("Setting property %s on %s to %s\n", - property->klass->id, - property->widget ? property->widget->name : "unknown", str); - g_free (str); - } -#endif - - if (!g_value_type_compatible (G_VALUE_TYPE (property->value), G_VALUE_TYPE (value))) - { - g_warning ("Trying to assign an incompatible value to property %s\n", - property->klass->id); - return; - } - - /* Check if the backend doesnt give us permission to - * set this value. - */ - if (glade_property_superuser () == FALSE && property->widget && - project && glade_project_is_loading (project) == FALSE && - glade_property_verify (property, value) == FALSE) - return; - - /* save "changed" state. - */ - changed = g_param_values_cmp (property->klass->pspec, - property->value, value) != 0; - - - /* Add/Remove references from widget ref stacks here - * (before assigning the value) - */ - if (property->widget && changed && glade_property_class_is_object (property->klass)) - glade_property_update_prop_refs (property, property->value, value); - - - /* Make a copy of the old value */ - g_value_init (&old_value, G_VALUE_TYPE (property->value)); - g_value_copy (property->value, &old_value); - - /* Assign property first so that; if the object need be - * rebuilt, it will reflect the new value - */ - g_value_reset (property->value); - g_value_copy (value, property->value); - - GLADE_PROPERTY_GET_KLASS (property)->sync (property); - - if (changed && property->widget) - { - g_signal_emit (G_OBJECT (property), - glade_property_signals[VALUE_CHANGED], - 0, &old_value, property->value); - } - - g_value_unset (&old_value); -} - -static void -glade_property_get_value_impl (GladeProperty *property, GValue *value) -{ - - g_value_init (value, property->klass->pspec->value_type); - g_value_copy (property->value, value); -} - -static void -glade_property_get_default_impl (GladeProperty *property, GValue *value) -{ - - g_value_init (value, property->klass->pspec->value_type); - g_value_copy (property->klass->def, value); -} - -static void -glade_property_sync_impl (GladeProperty *property) -{ - - /* Heh, here are the many reasons not to - * sync a property ;-) - */ - if (/* the class can be NULL during object, - * construction this is just a temporary state */ - property->klass == NULL || - /* optional properties that are disabled */ - property->enabled == FALSE || - /* explicit "never sync" flag */ - property->klass->ignore || - /* avoid recursion */ - property->syncing || - /* No widget owns this property yet */ - property->widget == NULL) - return; - - property->syncing = TRUE; - - /* In the case of construct_only, the widget instance must be rebuilt - * to apply the property - */ - if (property->klass->construct_only) - glade_widget_rebuild (property->widget); - else if (property->klass->packing) - glade_widget_child_set_property (glade_widget_get_parent (property->widget), - property->widget, - property->klass->id, - property->value); - else - glade_widget_object_set_property (property->widget, - property->klass->id, - property->value); - - property->syncing = FALSE; -} - -static void -glade_property_load_impl (GladeProperty *property) -{ - GObject *object; - GObjectClass *oclass; - - if (property->widget == NULL || - property->klass->packing || - property->klass->type != GPC_NORMAL || - !(property->klass->pspec->flags & G_PARAM_READABLE)) - return; - object = glade_widget_get_object (property->widget); - oclass = G_OBJECT_GET_CLASS (object); - - if (g_object_class_find_property (oclass, property->klass->id)) - g_object_get_property (object, property->klass->id, property->value); -} - -static gboolean -glade_property_write_impl (GladeProperty *property, - GladeInterface *interface, - GArray *props) -{ - GladePropInfo info = { 0, }; - GladeAtkActionInfo ainfo = { 0, }; - GList *list; - gchar *name, *value, **split, *tmp; - gint i; - - if (!property->klass->save || !property->enabled) - return FALSE; - - g_assert (property->klass->orig_def); - g_assert (property->klass->def); - - /* Skip properties that are default by original pspec default - * (excepting those that specified otherwise). - */ - if (!(property->klass->save_always || property->save_always) && - glade_property_equals_value (property, property->klass->orig_def)) - return FALSE; - - /* we should change each '-' by '_' on the name of the property - * (<property name="...">) */ - if (property->klass->type != GPC_NORMAL) - { - - tmp = (gchar *)glade_property_class_atk_realname (property->klass->id); - name = g_strdup (tmp); - } - else - { - name = g_strdup (property->klass->id); - } - - /* convert the value of this property to a string */ - if (property->klass->type == GPC_ACCEL_PROPERTY || - (value = glade_property_class_make_string_from_gvalue - (property->klass, property->value)) == NULL) - /* make sure we keep the empty string, also... upcomming - * funcs that may not like NULL. - */ - value = g_strdup (""); - else - { - /* Escape the string so that it will be parsed as it should. */ - tmp = value; - value = g_markup_escape_text (value, -1); - g_free (tmp); - } - - switch (property->klass->type) - { - case GPC_ATK_PROPERTY: - tmp = g_strdup_printf ("AtkObject::%s", name); - g_free (name); - name = tmp; - /* Dont break here ... */ - case GPC_NORMAL: - info.name = glade_xml_alloc_propname(interface, name); - info.value = glade_xml_alloc_string(interface, value); - - if (property->klass->translatable) - { - info.translatable = property->i18n_translatable; - info.has_context = property->i18n_has_context; - if (property->i18n_comment) - info.comment = glade_xml_alloc_string - (interface, property->i18n_comment); - } - g_array_append_val (props, info); - break; - case GPC_ATK_RELATION: - if ((split = g_strsplit (value, GPC_OBJECT_DELIMITER, 0)) != NULL) - { - for (i = 0; split[i] != NULL; i++) - { - GladeAtkRelationInfo rinfo = { 0, }; - rinfo.type = glade_xml_alloc_string(interface, name); - rinfo.target = glade_xml_alloc_string(interface, split[i]); - g_array_append_val (props, rinfo); - } - g_strfreev (split); - } - break; - case GPC_ATK_ACTION: - ainfo.action_name = glade_xml_alloc_string(interface, name); - ainfo.description = glade_xml_alloc_string(interface, value); - g_array_append_val (props, ainfo); - break; - case GPC_ACCEL_PROPERTY: - for (list = g_value_get_boxed (property->value); - list; list = list->next) - { - GladeAccelInfo *accel = list->data; - GladeAccelInfo accel_info = { 0, }; - - accel_info.signal = glade_xml_alloc_string(interface, accel->signal); - accel_info.key = accel->key; - accel_info.modifiers = accel->modifiers; - - g_array_append_val (props, accel_info); - } - break; - default: - break; - } - - g_free (name); - g_free (value); - - return TRUE; -} - -static G_CONST_RETURN gchar * -glade_property_get_tooltip_impl (GladeProperty *property) -{ - gchar *tooltip = NULL; - if (property->sensitive == FALSE) - tooltip = property->insensitive_tooltip; - else - tooltip = property->klass->tooltip; - return tooltip; -} - -/******************************************************************************* - GObjectClass & Object Construction - *******************************************************************************/ -static void -glade_property_set_real_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - GladeProperty *property = GLADE_PROPERTY (object); - - switch (prop_id) - { - case PROP_ENABLED: - glade_property_set_enabled (property, g_value_get_boolean (value)); - break; - case PROP_SENSITIVE: - property->sensitive = g_value_get_boolean (value); - break; - case PROP_I18N_TRANSLATABLE: - glade_property_i18n_set_translatable (property, g_value_get_boolean (value)); - break; - case PROP_I18N_HAS_CONTEXT: - glade_property_i18n_set_has_context (property, g_value_get_boolean (value)); - break; - case PROP_I18N_COMMENT: - glade_property_i18n_set_comment (property, g_value_get_string (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -glade_property_get_real_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - GladeProperty *property = GLADE_PROPERTY (object); - - switch (prop_id) - { - case PROP_ENABLED: - g_value_set_boolean (value, glade_property_get_enabled (property)); - break; - case PROP_SENSITIVE: - g_value_set_boolean (value, glade_property_get_sensitive (property)); - break; - case PROP_I18N_TRANSLATABLE: - g_value_set_boolean (value, glade_property_i18n_get_translatable (property)); - break; - case PROP_I18N_HAS_CONTEXT: - g_value_set_boolean (value, glade_property_i18n_get_has_context (property)); - break; - case PROP_I18N_COMMENT: - g_value_set_string (value, glade_property_i18n_get_comment (property)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -glade_property_finalize (GObject *object) -{ - GladeProperty *property = GLADE_PROPERTY (object); - - if (property->value) - { - g_value_unset (property->value); - g_free (property->value); - } - if (property->i18n_comment) - g_free (property->i18n_comment); - - G_OBJECT_CLASS (parent_class)->finalize (object); -} - -static void -glade_property_init (GladeProperty *property) -{ - property->enabled = TRUE; - property->sensitive = TRUE; - property->i18n_translatable = TRUE; - property->i18n_has_context = FALSE; - property->i18n_comment = NULL; -} - -static void -glade_property_klass_init (GladePropertyKlass *prop_class) -{ - GObjectClass *object_class; - g_return_if_fail (prop_class != NULL); - - parent_class = g_type_class_peek_parent (prop_class); - object_class = G_OBJECT_CLASS (prop_class); - - /* GObjectClass */ - object_class->set_property = glade_property_set_real_property; - object_class->get_property = glade_property_get_real_property; - object_class->finalize = glade_property_finalize; - - /* Class methods */ - prop_class->dup = glade_property_dup_impl; - prop_class->equals_value = glade_property_equals_value_impl; - prop_class->set_value = glade_property_set_value_impl; - prop_class->get_value = glade_property_get_value_impl; - prop_class->get_default = glade_property_get_default_impl; - prop_class->sync = glade_property_sync_impl; - prop_class->load = glade_property_load_impl; - prop_class->write = glade_property_write_impl; - prop_class->get_tooltip = glade_property_get_tooltip_impl; - prop_class->value_changed = NULL; - prop_class->tooltip_changed = NULL; - - /* Properties */ - g_object_class_install_property - (object_class, PROP_ENABLED, - g_param_spec_boolean - ("enabled", _("Enabled"), - _("If the property is optional, this is its enabled state"), - TRUE, G_PARAM_READWRITE)); - - g_object_class_install_property - (object_class, PROP_SENSITIVE, - g_param_spec_boolean - ("sensitive", _("Sensitive"), - _("This gives backends control to set property sensitivity"), - TRUE, G_PARAM_READWRITE)); - - g_object_class_install_property - (object_class, PROP_I18N_COMMENT, - g_param_spec_string - ("i18n-comment", _("Comment"), - _("Comment for translators"), - NULL, G_PARAM_READWRITE)); - - g_object_class_install_property - (object_class, PROP_I18N_TRANSLATABLE, - g_param_spec_boolean - ("i18n-translatable", _("Translatable"), - _("Whether this property is translatable or not"), - TRUE, G_PARAM_READWRITE)); - - g_object_class_install_property - (object_class, PROP_I18N_HAS_CONTEXT, - g_param_spec_boolean - ("i18n-has-context", _("Has Context"), - _("Whether or not the translatable string has a context prefix"), - FALSE, G_PARAM_READWRITE)); - - /* Signal */ - glade_property_signals[VALUE_CHANGED] = - g_signal_new ("value-changed", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GladePropertyKlass, - value_changed), - NULL, NULL, - glade_marshal_VOID__POINTER_POINTER, - G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_POINTER); - - glade_property_signals[TOOLTIP_CHANGED] = - g_signal_new ("tooltip-changed", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GladePropertyKlass, - tooltip_changed), - NULL, NULL, - g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, 1, G_TYPE_POINTER); - - -} - - -GType -glade_property_get_type (void) -{ - static GType property_type = 0; - - if (!property_type) - { - static const GTypeInfo property_info = - { - sizeof (GladePropertyKlass), /* Klass is our class */ - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) glade_property_klass_init, - (GClassFinalizeFunc) NULL, - NULL, /* class_data */ - sizeof (GladeProperty), - 0, /* n_preallocs */ - (GInstanceInitFunc) glade_property_init, - }; - property_type = - g_type_register_static (G_TYPE_OBJECT, - "GladeProperty", - &property_info, 0); - } - return property_type; -} - -/******************************************************************************* - GladeInterface Parsing code - *******************************************************************************/ -static GValue * -glade_property_read_packing (GladeProperty *property, - GladePropertyClass *pclass, - GladeProject *project, - GladeChildInfo *info, - gboolean free_value) -{ - GValue *gvalue = NULL; - gint i; - gchar *id; - - for (i = 0; i < info->n_properties; ++i) - { - GladePropInfo *pinfo = info->properties + i; - - id = glade_util_read_prop_name (pinfo->name); - - if (!strcmp (id, pclass->id)) - { - gvalue = glade_property_class_make_gvalue_from_string - (pclass, pinfo->value, project); - - if (property) - { - glade_property_i18n_set_translatable - (property, pinfo->translatable); - glade_property_i18n_set_has_context - (property, pinfo->has_context); - glade_property_i18n_set_comment - (property, pinfo->comment); - - property->enabled = TRUE; - - GLADE_PROPERTY_GET_KLASS (property)->set_value - (property, gvalue); - } - - if (free_value) - { - g_value_unset (gvalue); - g_free (gvalue); - } - - g_free (id); - break; - } - g_free (id); - } - return gvalue; -} - -static GValue * -glade_property_read_normal (GladeProperty *property, - GladePropertyClass *pclass, - GladeProject *project, - GladeWidgetInfo *info, - gboolean free_value) -{ - GValue *gvalue = NULL; - gint i; - gchar *id; - - for (i = 0; i < info->n_properties; ++i) - { - GladePropInfo *pinfo = info->properties + i; - - id = glade_util_read_prop_name (pinfo->name); - - if (!strcmp (id, pclass->id)) - { - if (property && glade_property_class_is_object (pclass)) - { - /* we must synchronize this directly after loading this project - * (i.e. lookup the actual objects after they've been parsed and - * are present). - */ - g_object_set_data_full (G_OBJECT (property), - "glade-loaded-object", - g_strdup (pinfo->value), g_free); - } - else - { - gvalue = glade_property_class_make_gvalue_from_string - (pclass, pinfo->value, project); - - if (property) - GLADE_PROPERTY_GET_KLASS - (property)->set_value (property, gvalue); - - if (free_value) - { - g_value_unset (gvalue); - g_free (gvalue); - } - } - - if (property) - { - glade_property_i18n_set_translatable - (property, pinfo->translatable); - glade_property_i18n_set_has_context - (property, pinfo->has_context); - glade_property_i18n_set_comment - (property, pinfo->comment); - - property->enabled = TRUE; - } - - g_free (id); - break; - } - g_free (id); - } - return gvalue; -} - -static GValue * -glade_property_read_atk_prop (GladeProperty *property, - GladePropertyClass *pclass, - GladeProject *project, - GladeWidgetInfo *info, - gboolean free_value) -{ - GValue *gvalue = NULL; - gint i; - gchar *id; - - for (i = 0; i < info->n_atk_props; ++i) - { - GladePropInfo *pinfo = info->atk_props + i; - - id = glade_util_read_prop_name (pinfo->name); - - if (!strcmp (id, pclass->id)) - { - gvalue = glade_property_class_make_gvalue_from_string - (pclass, pinfo->value, project); - - if (property) - { - glade_property_i18n_set_translatable - (property, pinfo->translatable); - glade_property_i18n_set_has_context - (property, pinfo->has_context); - glade_property_i18n_set_comment - (property, pinfo->comment); - - property->enabled = TRUE; - - GLADE_PROPERTY_GET_KLASS (property)->set_value - (property, gvalue); - } - - if (free_value) - { - g_value_unset (gvalue); - g_free (gvalue); - } - - g_free (id); - break; - } - g_free (id); - } - return gvalue; -} - -static GValue * -glade_property_read_atk_relation (GladeProperty *property, - GladePropertyClass *pclass, - GladeProject *project, - GladeWidgetInfo *info) -{ - const gchar *class_id; - gchar *id, *string = NULL, *tmp; - gint i; - - for (i = 0; i < info->n_relations; ++i) - { - GladeAtkRelationInfo *rinfo = info->relations + i; - - id = glade_util_read_prop_name (rinfo->type); - class_id = glade_property_class_atk_realname (pclass->id); - - if (!strcmp (id, class_id)) - { - if (string == NULL) - string = g_strdup (rinfo->target); - else - { - tmp = g_strdup_printf ("%s%s%s", string, - GPC_OBJECT_DELIMITER, rinfo->target); - string = (g_free (string), tmp); - } - } - g_free (id); - } - - /* we must synchronize this directly after loading this project - * (i.e. lookup the actual objects after they've been parsed and - * are present). - */ - if (property) - { - g_object_set_data_full (G_OBJECT (property), "glade-loaded-object", - g_strdup (string), g_free); - } - - return NULL; -} - -static GValue * -glade_property_read_atk_action (GladeProperty *property, - GladePropertyClass *pclass, - GladeProject *project, - GladeWidgetInfo *info, - gboolean free_value) -{ - GValue *gvalue = NULL; - const gchar *class_id; - gchar *id; - gint i; - - for (i = 0; i < info->n_atk_actions; ++i) - { - GladeAtkActionInfo *ainfo = info->atk_actions + i; - - id = glade_util_read_prop_name (ainfo->action_name); - class_id = glade_property_class_atk_realname (pclass->id); - - if (!strcmp (id, class_id)) - { - /* Need special case for NULL values here ??? */ - - gvalue = glade_property_class_make_gvalue_from_string - (pclass, ainfo->description, project); - - if (property) - GLADE_PROPERTY_GET_KLASS - (property)->set_value (property, gvalue); - - if (free_value) - { - g_value_unset (gvalue); - g_free (gvalue); - } - g_free (id); - break; - } - g_free (id); - } - return gvalue; -} - -static GValue * -glade_property_read_accel_prop (GladeProperty *property, - GladePropertyClass *pclass, - GladeProject *project, - GladeWidgetInfo *info, - gboolean free_value) -{ - GValue *gvalue = NULL; - GList *accels = NULL; - gint i; - - for (i = 0; i < info->n_accels; ++i) - { - GladeAccelInfo *ainfo = info->accels + i; - - GladeAccelInfo *ainfo_dup = g_new0 (GladeAccelInfo, 1); - - ainfo_dup = g_new0 (GladeAccelInfo, 1); - ainfo_dup->signal = g_strdup (ainfo->signal); - ainfo_dup->key = ainfo->key; - ainfo_dup->modifiers = ainfo->modifiers; - - accels = g_list_prepend (accels, ainfo_dup); - } - - gvalue = g_new0 (GValue, 1); - g_value_init (gvalue, GLADE_TYPE_ACCEL_GLIST); - g_value_take_boxed (gvalue, accels); - - - if (property) - GLADE_PROPERTY_GET_KLASS - (property)->set_value (property, gvalue); - - - if (free_value) - { - g_value_unset (gvalue); - g_free (gvalue); - } - - return gvalue; -} - - -/******************************************************************************* - API - *******************************************************************************/ -/** - * glade_property_new: - * @klass: A #GladePropertyClass defining this property - * @widget: The #GladeWidget this property is created for - * @value: The initial #GValue of the property or %NULL - * (the #GladeProperty will assume ownership of @value) - * - * Creates a #GladeProperty of type @klass for @widget with @value; if - * @value is %NULL, then the introspected default value for that property - * will be used. - * - * Returns: The newly created #GladeProperty - */ -GladeProperty * -glade_property_new (GladePropertyClass *klass, - GladeWidget *widget, - GValue *value) -{ - GladeProperty *property; - - g_return_val_if_fail (GLADE_IS_PROPERTY_CLASS (klass), NULL); - - property = - (GladeProperty *)g_object_new (GLADE_TYPE_PROPERTY, NULL); - property->klass = klass; - property->widget = widget; - property->value = value; - - if (klass->optional) - property->enabled = klass->optional_default; - - if (property->value == NULL) - { - g_assert (klass->orig_def); - - property->value = g_new0 (GValue, 1); - g_value_init (property->value, klass->orig_def->g_type); - g_value_copy (klass->orig_def, property->value); - } - return property; -} - -/** - * glade_property_dup: - * @template_prop: A #GladeProperty - * @widget: A #GladeWidget - * - * Returns: A newly duplicated property based on the new widget - */ -GladeProperty * -glade_property_dup (GladeProperty *template_prop, GladeWidget *widget) -{ - g_return_val_if_fail (GLADE_IS_PROPERTY (template_prop), NULL); - return GLADE_PROPERTY_GET_KLASS (template_prop)->dup (template_prop, widget); -} - -static void -glade_property_reset_common (GladeProperty *property, gboolean original) -{ - g_return_if_fail (GLADE_IS_PROPERTY (property)); - - GLADE_PROPERTY_GET_KLASS (property)->set_value - (property, (original) ? property->klass->orig_def : property->klass->def); -} - -/** - * glade_property_reset: - * @property: A #GladeProperty - * - * Resets this property to its default value - */ -void -glade_property_reset (GladeProperty *property) -{ - glade_property_reset_common (property, FALSE); -} - -/** - * glade_property_original_reset: - * @property: A #GladeProperty - * - * Resets this property to its original default value - */ -void -glade_property_original_reset (GladeProperty *property) -{ - glade_property_reset_common (property, TRUE); -} - -static gboolean -glade_property_default_common (GladeProperty *property, gboolean orig) -{ - g_return_val_if_fail (GLADE_IS_PROPERTY (property), FALSE); - return GLADE_PROPERTY_GET_KLASS (property)->equals_value - (property, (orig) ? property->klass->orig_def : property->klass->def); -} - -/** - * glade_property_default: - * @property: A #GladeProperty - * - * Returns: Whether this property is at its default value - */ -gboolean -glade_property_default (GladeProperty *property) -{ - return glade_property_default_common (property, FALSE); -} - -/** - * glade_property_original_default: - * @property: A #GladeProperty - * - * Returns: Whether this property is at its original default value - */ -gboolean -glade_property_original_default (GladeProperty *property) -{ - return glade_property_default_common (property, TRUE); -} - -/** - * glade_property_equals_value: - * @property: a #GladeProperty - * @value: a #GValue - * - * Returns: Whether this property is equal to the value provided - */ -gboolean -glade_property_equals_value (GladeProperty *property, - const GValue *value) -{ - g_return_val_if_fail (GLADE_IS_PROPERTY (property), FALSE); - return GLADE_PROPERTY_GET_KLASS (property)->equals_value (property, value); -} - -/** - * glade_property_equals_va_list: - * @property: a #GladeProperty - * @vl: a va_list - * - * Returns: Whether this property is equal to the value provided - */ -static gboolean -glade_property_equals_va_list (GladeProperty *property, va_list vl) -{ - GValue *value; - gboolean ret; - - g_return_val_if_fail (GLADE_IS_PROPERTY (property), FALSE); - - value = glade_property_class_make_gvalue_from_vl (property->klass, vl); - - ret = GLADE_PROPERTY_GET_KLASS (property)->equals_value (property, value); - - g_value_unset (value); - g_free (value); - return ret; -} - -/** - * glade_property_equals: - * @property: a #GladeProperty - * @...: a provided property value - * - * Returns: Whether this property is equal to the value provided - */ -gboolean -glade_property_equals (GladeProperty *property, ...) -{ - va_list vl; - gboolean ret; - - g_return_val_if_fail (GLADE_IS_PROPERTY (property), FALSE); - - va_start (vl, property); - ret = glade_property_equals_va_list (property, vl); - va_end (vl); - - return ret; -} - -/** - * glade_property_set_value: - * @property: a #GladeProperty - * @value: a #GValue - * - * Sets the property's value - */ -void -glade_property_set_value (GladeProperty *property, const GValue *value) -{ - g_return_if_fail (GLADE_IS_PROPERTY (property)); - g_return_if_fail (value != NULL); - GLADE_PROPERTY_GET_KLASS (property)->set_value (property, value); -} - -/** - * glade_property_set_va_list: - * @property: a #GladeProperty - * @vl: a va_list with value to set - * - * Sets the property's value - */ -void -glade_property_set_va_list (GladeProperty *property, va_list vl) -{ - GValue *value; - - g_return_if_fail (GLADE_IS_PROPERTY (property)); - - value = glade_property_class_make_gvalue_from_vl (property->klass, vl); - - GLADE_PROPERTY_GET_KLASS (property)->set_value (property, value); - - g_value_unset (value); - g_free (value); -} - -/** - * glade_property_set: - * @property: a #GladeProperty - * @...: the value to set - * - * Sets the property's value (in a convenient way) - */ -void -glade_property_set (GladeProperty *property, ...) -{ - va_list vl; - - g_return_if_fail (GLADE_IS_PROPERTY (property)); - - va_start (vl, property); - glade_property_set_va_list (property, vl); - va_end (vl); -} - -/** - * glade_property_get_value: - * @property: a #GladeProperty - * @value: a #GValue - * - * Retrieve the property value - */ -void -glade_property_get_value (GladeProperty *property, GValue *value) -{ - g_return_if_fail (GLADE_IS_PROPERTY (property)); - g_return_if_fail (value != NULL); - GLADE_PROPERTY_GET_KLASS (property)->get_value (property, value); -} - -/** - * glade_property_get_default: - * @property: a #GladeProperty - * @value: a #GValue - * - * Retrieve the default property value - */ -void -glade_property_get_default (GladeProperty *property, GValue *value) -{ - g_return_if_fail (GLADE_IS_PROPERTY (property)); - g_return_if_fail (value != NULL); - GLADE_PROPERTY_GET_KLASS (property)->get_default (property, value); -} - -/** - * glade_property_get_va_list: - * @property: a #GladeProperty - * @vl: a va_list - * - * Retrieve the property value - */ -void -glade_property_get_va_list (GladeProperty *property, va_list vl) -{ - g_return_if_fail (GLADE_IS_PROPERTY (property)); - glade_property_class_set_vl_from_gvalue (property->klass, property->value, vl); -} - -/** - * glade_property_get: - * @property: a #GladeProperty - * @...: An address to store the value - * - * Retrieve the property value - */ -void -glade_property_get (GladeProperty *property, ...) -{ - va_list vl; - - g_return_if_fail (GLADE_IS_PROPERTY (property)); - - va_start (vl, property); - glade_property_get_va_list (property, vl); - va_end (vl); -} - -/** - * glade_property_sync: - * @property: a #GladeProperty - * - * Synchronize the object with this property - */ -void -glade_property_sync (GladeProperty *property) -{ - g_return_if_fail (GLADE_IS_PROPERTY (property)); - GLADE_PROPERTY_GET_KLASS (property)->sync (property); -} - -/** - * glade_property_load: - * @property: a #GladeProperty - * - * Loads the value of @property from the coresponding object instance - */ -void -glade_property_load (GladeProperty *property) -{ - g_return_if_fail (GLADE_IS_PROPERTY (property)); - GLADE_PROPERTY_GET_KLASS (property)->load (property); -} - -/** - * glade_property_read: - * @property: a #GladeProperty or #NULL - * @pclass: the #GladePropertyClass - * @project: the #GladeProject - * @info: a #GladeWidgetInfo struct or a #GladeChildInfo struct if - * a packing property is passed. - * @free_value: Whether the return value should be freed after applying - * it to the property or if it should be returned in tact. - * - * Read the value and any attributes for @property from @info, assumes - * @property is being loaded for @project - * - * Returns: The newly created #GValue if successfull (and if @free_value == FALSE) - * - * Note that object values will only be resolved after the project is - * completely loaded - */ -GValue * -glade_property_read (GladeProperty *property, - GladePropertyClass *pclass, - GladeProject *project, - gpointer info, - gboolean free_value) -{ - GValue *ret = NULL; - - g_return_val_if_fail (pclass != NULL, FALSE); - g_return_val_if_fail (info != NULL, FALSE); - - if (pclass->packing) - { - ret = glade_property_read_packing - (property, pclass, project, (GladeChildInfo *)info, free_value); - } - else switch (pclass->type) - { - case GPC_NORMAL: - ret = glade_property_read_normal - (property, pclass, project, (GladeWidgetInfo *)info, free_value); - break; - case GPC_ATK_PROPERTY: - ret = glade_property_read_atk_prop - (property, pclass, project, (GladeWidgetInfo *)info, free_value); - break; - case GPC_ATK_RELATION: - ret = glade_property_read_atk_relation - (property, pclass, project, (GladeWidgetInfo *)info); - break; - case GPC_ATK_ACTION: - ret = glade_property_read_atk_action - (property, pclass, project, (GladeWidgetInfo *)info, free_value); - break; - case GPC_ACCEL_PROPERTY: - ret = glade_property_read_accel_prop - (property, pclass, project, (GladeWidgetInfo *)info, free_value); - break; - default: - break; - } - - return ret; -} - - -/** - * glade_property_write: - * @property: a #GladeProperty - * @interface: a #GladeInterface - * @props: a GArray of #GladePropInfo - * - * Write this property to the GladeInterface metadata - */ -gboolean -glade_property_write (GladeProperty *property, GladeInterface *interface, GArray *props) -{ - g_return_val_if_fail (GLADE_IS_PROPERTY (property), FALSE); - g_return_val_if_fail (interface != NULL, FALSE); - g_return_val_if_fail (props != NULL, FALSE); - return GLADE_PROPERTY_GET_KLASS (property)->write (property, interface, props); -} - -/** - * glade_property_add_object: - * @property: a #GladeProperty - * @object: The #GObject to add - * - * Adds @object to the object list in @property. - * - * Note: This function expects @property to be a #GladeParamSpecObjects - * or #GParamSpecObject type property. - */ -void -glade_property_add_object (GladeProperty *property, - GObject *object) -{ - GList *list = NULL, *new_list = NULL; - - g_return_if_fail (GLADE_IS_PROPERTY (property)); - g_return_if_fail (G_IS_OBJECT (object)); - g_return_if_fail (GLADE_IS_PARAM_SPEC_OBJECTS (property->klass->pspec) || - G_IS_PARAM_SPEC_OBJECT (property->klass->pspec)); - - if (GLADE_IS_PARAM_SPEC_OBJECTS (property->klass->pspec)) - { - glade_property_get (property, &list); - new_list = g_list_copy (list); - - new_list = g_list_append (new_list, object); - glade_property_set (property, new_list); - - /* ownership of the list is not passed - * through glade_property_set() - */ - g_list_free (new_list); - } - else - { - glade_property_set (property, object); - } -} - -/** - * glade_property_remove_object: - * @property: a #GladeProperty - * @object: The #GObject to add - * - * Removes @object from the object list in @property. - * - * Note: This function expects @property to be a #GladeParamSpecObjects - * or #GParamSpecObject type property. - */ -void -glade_property_remove_object (GladeProperty *property, - GObject *object) -{ - GList *list = NULL, *new_list = NULL; - - g_return_if_fail (GLADE_IS_PROPERTY (property)); - g_return_if_fail (G_IS_OBJECT (object)); - g_return_if_fail (GLADE_IS_PARAM_SPEC_OBJECTS (property->klass->pspec) || - G_IS_PARAM_SPEC_OBJECT (property->klass->pspec)); - - if (GLADE_IS_PARAM_SPEC_OBJECTS (property->klass->pspec)) - { - /* If object isnt in list; list should stay in tact. - * not bothering to check for now. - */ - glade_property_get (property, &list); - new_list = g_list_copy (list); - - new_list = g_list_remove (new_list, object); - glade_property_set (property, new_list); - - /* ownership of the list is not passed - * through glade_property_set() - */ - g_list_free (new_list); - } - else - { - glade_property_set (property, object); - } - - glade_property_class_get_from_gvalue (property->klass, - property->value, - &list); - - glade_property_set (property, list); -} - - -/** - * glade_property_get_tooltip: - * @property: a #GladeProperty - * - * Returns: The appropriate tooltip for the editor - */ -G_CONST_RETURN gchar * -glade_property_get_tooltip (GladeProperty *property) -{ - g_return_val_if_fail (GLADE_IS_PROPERTY (property), NULL); - return GLADE_PROPERTY_GET_KLASS (property)->get_tooltip (property); -} - -/* Parameters for translatable properties. */ -void -glade_property_i18n_set_comment (GladeProperty *property, - const gchar *str) -{ - g_return_if_fail (GLADE_IS_PROPERTY (property)); - if (property->i18n_comment) - g_free (property->i18n_comment); - - property->i18n_comment = g_strdup (str); - g_object_notify (G_OBJECT (property), "i18n-comment"); -} - -const gchar * -glade_property_i18n_get_comment (GladeProperty *property) -{ - g_return_val_if_fail (GLADE_IS_PROPERTY (property), NULL); - return property->i18n_comment; -} - -void -glade_property_i18n_set_translatable (GladeProperty *property, - gboolean translatable) -{ - g_return_if_fail (GLADE_IS_PROPERTY (property)); - property->i18n_translatable = translatable; - g_object_notify (G_OBJECT (property), "i18n-translatable"); -} - -gboolean -glade_property_i18n_get_translatable (GladeProperty *property) -{ - g_return_val_if_fail (GLADE_IS_PROPERTY (property), FALSE); - return property->i18n_translatable; -} - -void -glade_property_i18n_set_has_context (GladeProperty *property, - gboolean has_context) -{ - g_return_if_fail (GLADE_IS_PROPERTY (property)); - property->i18n_has_context = has_context; - g_object_notify (G_OBJECT (property), "i18n-has-context"); -} - -gboolean -glade_property_i18n_get_has_context (GladeProperty *property) -{ - g_return_val_if_fail (GLADE_IS_PROPERTY (property), FALSE); - return property->i18n_has_context; -} - -void -glade_property_set_sensitive (GladeProperty *property, - gboolean sensitive, - const gchar *reason) -{ - g_return_if_fail (GLADE_IS_PROPERTY (property)); - - /* reason is only why we're disableing it */ - if (sensitive == FALSE) - { - if (property->insensitive_tooltip) - g_free (property->insensitive_tooltip); - property->insensitive_tooltip = - g_strdup (reason); - } - - if (property->sensitive != sensitive) - { - gchar *tooltip; - property->sensitive = sensitive; - - tooltip = (gchar *)GLADE_PROPERTY_GET_KLASS - (property)->get_tooltip (property); - - g_signal_emit (G_OBJECT (property), - glade_property_signals[TOOLTIP_CHANGED], - 0, tooltip); - - } - g_object_notify (G_OBJECT (property), "sensitive"); -} - -gboolean -glade_property_get_sensitive (GladeProperty *property) -{ - g_return_val_if_fail (GLADE_IS_PROPERTY (property), FALSE); - return property->sensitive; -} - -/** - * glade_property_set_save_always: - * @property: A #GladeProperty - * @setting: the value to set - * - * Sets whether this property should be special cased - * to always be saved regardless of its default value. - * (used for some special cases like properties - * that are assigned initial values in composite widgets - * or derived widget code). - */ -void -glade_property_set_save_always (GladeProperty *property, - gboolean setting) -{ - g_return_if_fail (GLADE_IS_PROPERTY (property)); - - property->save_always = setting; -} - -/** - * glade_property_get_save_always: - * @property: A #GladeProperty - * - * Returns whether this property is special cased - * to always be saved regardless of its default value. - */ -gboolean -glade_property_get_save_always (GladeProperty *property) -{ - g_return_val_if_fail (GLADE_IS_PROPERTY (property), FALSE); - - return property->save_always; -} - -void -glade_property_set_enabled (GladeProperty *property, - gboolean enabled) -{ - g_return_if_fail (GLADE_IS_PROPERTY (property)); - - property->enabled = enabled; - if (enabled) - glade_property_sync (property); - - g_object_notify (G_OBJECT (property), "enabled"); -} - -gboolean -glade_property_get_enabled (GladeProperty *property) -{ - g_return_val_if_fail (GLADE_IS_PROPERTY (property), FALSE); - return property->enabled; -} - - -static gint glade_property_su_stack = 0; - -void -glade_property_push_superuser (void) -{ - glade_property_su_stack++; -} - -void -glade_property_pop_superuser (void) -{ - if (--glade_property_su_stack < 0) - { - g_critical ("Bug: property super user stack is corrupt.\n"); - } -} - -gboolean -glade_property_superuser (void) -{ - return glade_property_su_stack > 0; -} diff --git a/gladeui/glade-property.h b/gladeui/glade-property.h deleted file mode 100644 index a0c0c4a1..00000000 --- a/gladeui/glade-property.h +++ /dev/null @@ -1,199 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef __GLADE_PROPERTY_H__ -#define __GLADE_PROPERTY_H__ - -#include <glib-object.h> - -G_BEGIN_DECLS - -#define GLADE_TYPE_PROPERTY (glade_property_get_type()) -#define GLADE_PROPERTY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_PROPERTY, GladeProperty)) -#define GLADE_PROPERTY_KLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_PROPERTY, GladePropertyKlass)) -#define GLADE_IS_PROPERTY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_PROPERTY)) -#define GLADE_IS_PROPERTY_KLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_PROPERTY)) -#define GLADE_PROPERTY_GET_KLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GLADE_PROPERTY, GladePropertyKlass)) - -typedef struct _GladePropertyKlass GladePropertyKlass; - -/* A GladeProperty is an instance of a GladePropertyClass. - * There will be one GladePropertyClass for "GtkLabel->label" but one - * GladeProperty for each GtkLabel in the GladeProject. - */ -struct _GladeProperty -{ - GObject parent_instance; - - GladePropertyClass *klass; /* A pointer to the GladeProperty that this - * setting specifies - */ - GladeWidget *widget; /* A pointer to the GladeWidget that this - * GladeProperty is modifying - */ - - GValue *value; /* The value of the property - */ - - gboolean sensitive; /* Whether this property is sensitive (if the - * property is "optional" this takes precedence). - */ - gchar *insensitive_tooltip; /* Tooltip to display when in insensitive state - * (used to explain why the property is insensitive) - */ - - gboolean enabled; /* Enabled is a flag that is used for GladeProperties - * that have the optional flag set to let us know - * if this widget has this GladeSetting enabled or - * not. (Like default size, it can be specified or - * unspecified). This flag also sets the state - * of the property->input state for the loaded - * widget. - */ - - gboolean save_always; /* Used to make a special case exception and always - * save this property regardless of what the default - * value is (used for some special cases like properties - * that are assigned initial values in composite widgets - * or derived widget code). - */ - - /* Used only for translatable strings. */ - gboolean i18n_translatable; - gboolean i18n_has_context; - gchar *i18n_comment; - - gboolean syncing; /* Avoid recursion while synchronizing object with value. - */ -}; - - -struct _GladePropertyKlass -{ - GObjectClass parent_class; - - /* Class methods */ - GladeProperty * (* dup) (GladeProperty *, GladeWidget *); - gboolean (* equals_value) (GladeProperty *, const GValue *); - void (* set_value) (GladeProperty *, const GValue *); - void (* get_value) (GladeProperty *, GValue *); - void (* get_default) (GladeProperty *, GValue *); - void (* sync) (GladeProperty *); - void (* load) (GladeProperty *); - gboolean (* write) (GladeProperty *, GladeInterface *, GArray *); - G_CONST_RETURN gchar * (* get_tooltip) (GladeProperty *); - - /* Signals */ - void (* value_changed) (GladeProperty *, GValue *, GValue *); - void (* tooltip_changed) (GladeProperty *, const gchar *); -}; - - -GType glade_property_get_type (void) G_GNUC_CONST; - -GladeProperty *glade_property_new (GladePropertyClass *klass, - GladeWidget *widget, - GValue *value); - -GladeProperty *glade_property_dup (GladeProperty *template_prop, - GladeWidget *widget); - -void glade_property_reset (GladeProperty *property); - -void glade_property_original_reset (GladeProperty *property); - -gboolean glade_property_default (GladeProperty *property); - -gboolean glade_property_original_default (GladeProperty *property); - -gboolean glade_property_equals_value (GladeProperty *property, - const GValue *value); - -gboolean glade_property_equals (GladeProperty *property, - ...); - -void glade_property_set_value (GladeProperty *property, - const GValue *value); - -void glade_property_set_va_list (GladeProperty *property, - va_list vl); - -void glade_property_set (GladeProperty *property, - ...); - -void glade_property_get_value (GladeProperty *property, - GValue *value); - -void glade_property_get_default (GladeProperty *property, - GValue *value); - -void glade_property_get_va_list (GladeProperty *property, - va_list vl); - -void glade_property_get (GladeProperty *property, - ...); - -void glade_property_add_object (GladeProperty *property, - GObject *object); - -void glade_property_remove_object (GladeProperty *property, - GObject *object); - -void glade_property_sync (GladeProperty *property); - -void glade_property_load (GladeProperty *property); - -GValue *glade_property_read (GladeProperty *property, - GladePropertyClass *pclass, - GladeProject *project, - gpointer info, - gboolean free_value); - -gboolean glade_property_write (GladeProperty *property, - GladeInterface *interface, - GArray *props); - -G_CONST_RETURN gchar *glade_property_get_tooltip (GladeProperty *property); - -void glade_property_set_sensitive (GladeProperty *property, - gboolean sensitive, - const gchar *reason); - -gboolean glade_property_get_sensitive (GladeProperty *property); - - -void glade_property_set_save_always (GladeProperty *property, - gboolean setting); - -gboolean glade_property_get_save_always (GladeProperty *property); - - -void glade_property_set_enabled (GladeProperty *property, - gboolean enabled); - -gboolean glade_property_get_enabled (GladeProperty *property); - - -void glade_property_i18n_set_comment (GladeProperty *property, - const gchar *str); - -G_CONST_RETURN gchar *glade_property_i18n_get_comment (GladeProperty *property); - -void glade_property_i18n_set_translatable (GladeProperty *property, - gboolean translatable); - -gboolean glade_property_i18n_get_translatable (GladeProperty *property); - -void glade_property_i18n_set_has_context (GladeProperty *property, - gboolean has_context); - -gboolean glade_property_i18n_get_has_context (GladeProperty *property); - - -void glade_property_push_superuser (void); - -void glade_property_pop_superuser (void); - -gboolean glade_property_superuser (void); - -G_END_DECLS - -#endif /* __GLADE_PROPERTY_H__ */ diff --git a/gladeui/glade-signal-editor.c b/gladeui/glade-signal-editor.c deleted file mode 100644 index 28363777..00000000 --- a/gladeui/glade-signal-editor.c +++ /dev/null @@ -1,969 +0,0 @@ -/* -*- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Authors: - * Shane Butler <shane_b@users.sourceforge.net> - * Joaquin Cuenca Abela <e98cuenc@yahoo.com> - */ -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> -#include <glib/gi18n-lib.h> - -#include "glade.h" -#include "glade-widget.h" -#include "glade-widget-adaptor.h" -#include "glade-signal.h" -#include "glade-signal-editor.h" -#include "glade-editor.h" -#include "glade-command.h" - - -enum -{ - COLUMN_SIGNAL, - COLUMN_HANDLER, - COLUMN_AFTER, - COLUMN_USERDATA, - COLUMN_LOOKUP, - - COLUMN_USERDATA_SLOT, - COLUMN_LOOKUP_VISIBLE, - COLUMN_AFTER_VISIBLE, - COLUMN_HANDLER_EDITABLE, - COLUMN_USERDATA_EDITABLE, - COLUMN_SLOT, /* if this row contains a "<Type...>" label */ - COLUMN_BOLD, - NUM_COLUMNS -}; - -#define HANDLER_DEFAULT _("<Type the signal's handler here>") -#define USERDATA_DEFAULT _("<Type the object's name here>") - -static void -glade_signal_editor_after_toggled (GtkCellRendererToggle *cell, - gchar *path_str, - gpointer data) -{ - GladeSignalEditor *editor = (GladeSignalEditor*) data; - GtkTreeModel *model = GTK_TREE_MODEL (editor->model); - GtkTreeIter iter; - GtkTreeIter iter_parent; - GladeSignal *old_signal; - GladeSignal *new_signal; - GtkTreePath *path = gtk_tree_path_new_from_string (path_str); - gchar *signal_name; - gchar *handler; - gchar *userdata; - gboolean lookup; - gboolean after; - - /* get toggled iter */ - gtk_tree_model_get_iter (model, &iter, path); - gtk_tree_model_get (model, &iter, - COLUMN_SIGNAL, &signal_name, - COLUMN_HANDLER, &handler, - COLUMN_USERDATA,&userdata, - COLUMN_LOOKUP, &lookup, - COLUMN_AFTER, &after, -1); - if (signal_name == NULL) - { - if (!gtk_tree_model_iter_parent (model, &iter_parent, &iter)) - g_assert (FALSE); - - gtk_tree_model_get (model, &iter_parent, COLUMN_SIGNAL, &signal_name, -1); - g_assert (signal_name != NULL); - } - - old_signal = glade_signal_new (signal_name, handler, userdata, lookup, after); - new_signal = glade_signal_new (signal_name, handler, userdata, lookup, !after); - - glade_command_change_signal (editor->widget, old_signal, new_signal); - gtk_tree_store_set (GTK_TREE_STORE (model), &iter, COLUMN_AFTER, !after, -1); - - glade_signal_free (old_signal); - glade_signal_free (new_signal); - gtk_tree_path_free (path); - g_free (signal_name); - g_free (handler); - g_free (userdata); -} - -/* - glade files do not support symbol names as signal handler user_data arguments - yet, so we disabled the lookup column. -*/ -#define LOOKUP_COLUMN 0 - -#if LOOKUP_COLUMN -static void -glade_signal_editor_lookup_toggled (GtkCellRendererToggle *cell, - gchar *path_str, - gpointer data) -{ - GladeSignalEditor *editor = (GladeSignalEditor*) data; - GtkTreeModel *model = GTK_TREE_MODEL (editor->model); - GtkTreeIter iter; - GtkTreeIter iter_parent; - GladeSignal *old_signal; - GladeSignal *new_signal; - GtkTreePath *path = gtk_tree_path_new_from_string (path_str); - gchar *signal_name; - gchar *handler; - gchar *userdata; - gboolean lookup; - gboolean after; - - /* get toggled iter */ - gtk_tree_model_get_iter (model, &iter, path); - gtk_tree_model_get (model, &iter, - COLUMN_SIGNAL, &signal_name, - COLUMN_HANDLER, &handler, - COLUMN_USERDATA,&userdata, - COLUMN_LOOKUP, &lookup, - COLUMN_AFTER, &after, -1); - if (signal_name == NULL) - { - if (!gtk_tree_model_iter_parent (model, &iter_parent, &iter)) - g_assert (FALSE); - - gtk_tree_model_get (model, &iter_parent, COLUMN_SIGNAL, &signal_name, -1); - g_assert (signal_name != NULL); - } - - old_signal = glade_signal_new (signal_name, handler, userdata, lookup, after); - new_signal = glade_signal_new (signal_name, handler, userdata, !lookup, after); - - glade_command_change_signal (editor->widget, old_signal, new_signal); - gtk_tree_store_set (GTK_TREE_STORE (model), &iter, COLUMN_LOOKUP, !lookup, -1); - - glade_signal_free (old_signal); - glade_signal_free (new_signal); - gtk_tree_path_free (path); - g_free (signal_name); - g_free (handler); - g_free (userdata); -} - - -static gboolean -glade_signal_editor_is_valid_identifier (const char *text) -{ - char ch; - - if (text == NULL) - return FALSE; - - ch = *text++; - if (!(ch == '_' || (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))) - return FALSE; - - while ((ch = *text++) != 0) - if (!(ch == '_' || (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9'))) - return FALSE; - - return TRUE; -} -#endif - -static void -append_slot (GtkTreeModel *model, GtkTreeIter *iter_signal) -{ - GtkTreeIter iter_new_slot; - GtkTreeIter iter_class; - - gtk_tree_store_append (GTK_TREE_STORE (model), &iter_new_slot, iter_signal); - gtk_tree_store_set (GTK_TREE_STORE (model), &iter_new_slot, - COLUMN_HANDLER, _(HANDLER_DEFAULT), - COLUMN_USERDATA, _(USERDATA_DEFAULT), - COLUMN_LOOKUP, FALSE, - COLUMN_LOOKUP_VISIBLE, FALSE, - COLUMN_HANDLER_EDITABLE, TRUE, - COLUMN_USERDATA_EDITABLE,FALSE, - COLUMN_AFTER, FALSE, - COLUMN_AFTER_VISIBLE, FALSE, - COLUMN_SLOT, TRUE, - COLUMN_USERDATA_SLOT, TRUE, - -1); - gtk_tree_model_iter_parent (model, &iter_class, iter_signal); - - /* mark the signal & class name as bold */ - gtk_tree_store_set (GTK_TREE_STORE (model), iter_signal, COLUMN_BOLD, TRUE, -1); - gtk_tree_store_set (GTK_TREE_STORE (model), &iter_class, COLUMN_BOLD, TRUE, -1); -} - -static void -remove_slot (GtkTreeModel *model, GtkTreeIter *iter) -{ - GtkTreeIter iter_next; - GtkTreeIter iter_class; - GtkTreeIter iter_signal; - gboolean removing_top_signal_handler = TRUE; - char *signal_name; - - gtk_tree_model_get (model, iter, COLUMN_SIGNAL, &signal_name, -1); - if (signal_name == NULL) - { - gtk_tree_model_iter_parent (model, &iter_signal, iter); - removing_top_signal_handler = FALSE; - } - else - iter_signal = *iter; - - g_free (signal_name); - - gtk_tree_model_iter_parent (model, &iter_class, &iter_signal); - - /* special case for removing the handler of the first row */ - if (removing_top_signal_handler) - gtk_tree_model_iter_nth_child (model, &iter_next, iter, 0); - else - { - iter_next = *iter; - gtk_tree_model_iter_next (model, &iter_next); - } - - do - { - gchar *handler; - gboolean after; - gboolean slot; - gboolean visible; - - gtk_tree_model_get (model, &iter_next, - COLUMN_HANDLER, &handler, - COLUMN_AFTER, &after, - COLUMN_SLOT, &slot, - COLUMN_AFTER_VISIBLE, &visible, -1); - - gtk_tree_store_set (GTK_TREE_STORE (model), iter, - COLUMN_HANDLER, handler, - COLUMN_AFTER, after, - COLUMN_SLOT, slot, - COLUMN_AFTER_VISIBLE, visible, -1); - g_free (handler); - - *iter = iter_next; - } - while (gtk_tree_model_iter_next (model, &iter_next)); - - gtk_tree_store_remove (GTK_TREE_STORE (model), iter); - - if (!gtk_tree_model_iter_has_child (model, &iter_signal)) - { - /* mark the signal & class name as normal */ - gtk_tree_store_set (GTK_TREE_STORE (model), &iter_signal, - COLUMN_BOLD, FALSE, -1); - gtk_tree_store_set (GTK_TREE_STORE (model), &iter_class, - COLUMN_BOLD, FALSE, -1); - } -} - -static gboolean -is_void_signal_handler (const gchar *signal_handler) -{ - return ( signal_handler == NULL || - *signal_handler == 0 || - g_utf8_collate (signal_handler, _(HANDLER_DEFAULT)) == 0); -} - -static gboolean -is_void_user_data (const gchar *user_data) -{ - return ( user_data == NULL || - *user_data == 0 || - g_utf8_collate (user_data, _(USERDATA_DEFAULT)) == 0); -} - -static void -glade_signal_editor_handler_cell_edited (GtkCellRendererText *cell, - const gchar *path_str, - const gchar *new_handler, - gpointer data) -{ - GladeWidget *glade_widget = ((GladeSignalEditor*) data)->widget; - GtkTreeModel *model = GTK_TREE_MODEL (((GladeSignalEditor*) data)->model); - GtkTreePath *path = gtk_tree_path_new_from_string (path_str); - GtkTreeIter iter; - GtkTreeIter iter_signal; - gchar *signal_name; - gchar *old_handler; - gchar *userdata; - gboolean lookup; - gboolean after; - gboolean slot; - - gtk_tree_model_get_iter (model, &iter, path); - gtk_tree_model_get (model, &iter, - COLUMN_SIGNAL, &signal_name, - COLUMN_HANDLER, &old_handler, - COLUMN_USERDATA, &userdata, - COLUMN_LOOKUP, &lookup, - COLUMN_AFTER, &after, - COLUMN_SLOT, &slot, -1); - - if (signal_name == NULL) - { - if (!gtk_tree_model_iter_parent (model, &iter_signal, &iter)) - g_assert (FALSE); - - gtk_tree_model_get (model, &iter_signal, COLUMN_SIGNAL, &signal_name, -1); - g_assert (signal_name != NULL); - } - else - iter_signal = iter; - - /* false alarm */ - if (slot && is_void_signal_handler(new_handler)) - return; - - /* we're adding a new handler */ - if (slot && !is_void_signal_handler(new_handler)) - { - GladeSignal *new_signal = glade_signal_new (signal_name, new_handler, - NULL, FALSE, FALSE); - glade_command_add_signal (glade_widget, new_signal); - glade_signal_free (new_signal); - gtk_tree_store_set (GTK_TREE_STORE (model), &iter, - COLUMN_HANDLER, new_handler, - COLUMN_AFTER_VISIBLE, TRUE, - COLUMN_SLOT, FALSE, - COLUMN_USERDATA_EDITABLE,TRUE, -1); - - /* append a <Type...> slot */ - append_slot (model, &iter_signal); - } - - /* we're removing a signal handler */ - if (!slot && is_void_signal_handler(new_handler)) - { - GladeSignal *old_signal = - glade_signal_new (signal_name, - old_handler, - is_void_user_data (userdata) ? NULL : userdata, - lookup, after); - glade_command_remove_signal (glade_widget, old_signal); - glade_signal_free (old_signal); - - gtk_tree_store_set - (GTK_TREE_STORE (model), &iter, - COLUMN_HANDLER, _(HANDLER_DEFAULT), - COLUMN_AFTER, FALSE, - COLUMN_USERDATA, _(USERDATA_DEFAULT), - COLUMN_LOOKUP, FALSE, - COLUMN_LOOKUP_VISIBLE, FALSE, - COLUMN_HANDLER_EDITABLE, TRUE, - COLUMN_USERDATA_EDITABLE,FALSE, - COLUMN_AFTER_VISIBLE, FALSE, - COLUMN_SLOT, TRUE, - COLUMN_USERDATA_SLOT, TRUE, - -1); - - remove_slot (model, &iter); - } - - /* we're changing a signal handler */ - if (!slot && !is_void_signal_handler(new_handler)) - { - GladeSignal *old_signal = - glade_signal_new - (signal_name, - old_handler, - is_void_user_data(userdata) ? NULL : userdata, - lookup, - after); - GladeSignal *new_signal = - glade_signal_new - (signal_name, - new_handler, - is_void_user_data(userdata) ? NULL : userdata, - lookup, - after); - - glade_command_change_signal (glade_widget, old_signal, new_signal); - - glade_signal_free (old_signal); - glade_signal_free (new_signal); - - gtk_tree_store_set (GTK_TREE_STORE (model), &iter, - COLUMN_HANDLER, new_handler, - COLUMN_AFTER_VISIBLE, TRUE, - COLUMN_SLOT, FALSE, - COLUMN_USERDATA_EDITABLE,TRUE, -1); - } - - gtk_tree_path_free (path); - g_free (signal_name); - g_free (old_handler); - g_free (userdata); -} - -static void -glade_signal_editor_construct_handler_store (GladeSignalEditor *editor) -{ - const gchar *handlers[] = {"gtk_widget_show", - "gtk_widget_hide", - "gtk_widget_grab_focus", - "gtk_widget_destroy", - "gtk_true", - "gtk_false", - "gtk_main_quit", - NULL}; - GtkTreeIter iter, *iters = editor->iters; - GtkEntryCompletion *completion; - GtkListStore *store; - gint i; - - store = gtk_list_store_new (1, G_TYPE_STRING); - - gtk_list_store_append (store, &iters[0]); - gtk_list_store_append (store, &iters[1]); - - for (i = 0; handlers[i]; i++) - { - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, 0, handlers[i], -1); - } - - completion = gtk_entry_completion_new (); - gtk_entry_completion_set_model (completion, GTK_TREE_MODEL (store)); - gtk_entry_completion_set_text_column (completion, 0); - gtk_entry_completion_set_inline_completion (completion, TRUE); - gtk_entry_completion_set_popup_completion (completion, FALSE); - - editor->handler_store = store; - editor->completion = completion; -} - -static void -glade_signal_editor_handler_store_update (GladeSignalEditor *editor, - const gchar *path) -{ - GtkTreeModel *model = GTK_TREE_MODEL (editor->model); - GtkListStore *store = editor->handler_store; - GtkTreeIter iter, *iters = editor->iters; - gchar *handler, *signal, *name; - - name = (gchar *) glade_widget_get_name (editor->widget); - - if (gtk_tree_model_get_iter_from_string (model, &iter, path)) - { - gtk_tree_model_get (model, &iter, COLUMN_SIGNAL, &signal, -1); - if (signal) glade_util_replace (signal, '-', '_'); - else return; - } - else return; - - handler = g_strdup_printf ("on_%s_%s", name, signal); - gtk_list_store_set (store, &iters[0], 0, handler, -1); - g_free (handler); - - handler = g_strdup_printf ("%s_%s_cb", name, signal); - gtk_list_store_set (store, &iters[1], 0, handler, -1); - g_free (handler); - - g_free (signal); -} - -static void -glade_signal_editor_editing_started (GtkEntry *entry, gboolean handler) -{ - const gchar *text = gtk_entry_get_text (entry); - - if ((handler) ? is_void_signal_handler (text) : is_void_user_data (text)) - gtk_entry_set_text (entry, ""); -} - -static void -glade_signal_editor_handler_editing_started (GtkCellRenderer *cell, - GtkCellEditable *editable, - const gchar *path, - GladeSignalEditor *editor) -{ - GtkEntry *entry = GTK_ENTRY (gtk_bin_get_child (GTK_BIN (editable))); - - glade_signal_editor_editing_started (entry, TRUE); - - glade_signal_editor_handler_store_update (editor, path); - - gtk_entry_set_completion (entry, editor->completion); -} - -static void -glade_signal_editor_user_data_editing_started (GtkCellRenderer *cell, - GtkCellEditable *editable, - const gchar *path, - GladeSignalEditor *editor) -{ - GtkEntry *entry = GTK_ENTRY (editable); - GtkEntryCompletion *completion; - GtkListStore *store; - GtkTreeIter iter; - GList *list; - - g_return_if_fail (editor->widget != NULL); - - glade_signal_editor_editing_started (entry, FALSE); - - store = gtk_list_store_new (1, G_TYPE_STRING); - - for (list = (GList *) glade_project_get_objects (editor->widget->project); - list && list->data; - list = g_list_next (list)) - { - GladeWidget *widget = glade_widget_get_from_gobject (list->data); - - if (widget) - { - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, 0, widget->name, -1); - } - } - - gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), 0, - GTK_SORT_DESCENDING); - - completion = gtk_entry_completion_new (); - - gtk_entry_completion_set_model (completion, GTK_TREE_MODEL (store)); - gtk_entry_completion_set_text_column (completion, 0); - gtk_entry_set_completion (entry, completion); - - /* Get rid of references */ - g_object_unref (store); - g_object_unref (completion); -} - -static void -glade_signal_editor_userdata_cell_edited (GtkCellRendererText *cell, - const gchar *path_str, - const gchar *new_userdata, - gpointer data) -{ - GladeWidget *glade_widget = ((GladeSignalEditor*) data)->widget; - GtkTreeModel *model = GTK_TREE_MODEL (((GladeSignalEditor*) data)->model); - GtkTreePath *path = gtk_tree_path_new_from_string (path_str); - GtkTreeIter iter; - GtkTreeIter iter_signal; - GladeSignal *old_signal, *new_signal; - gchar *signal_name; - gchar *old_userdata; - gchar *handler; - gboolean after; - gboolean lookup; - - gtk_tree_model_get_iter (model, &iter, path); - gtk_tree_model_get (model, &iter, - COLUMN_SIGNAL, &signal_name, - COLUMN_HANDLER, &handler, - COLUMN_USERDATA, &old_userdata, - COLUMN_LOOKUP, &lookup, - COLUMN_AFTER, &after, -1); - - if (signal_name == NULL) - { - if (!gtk_tree_model_iter_parent (model, &iter_signal, &iter)) - g_assert (FALSE); - - gtk_tree_model_get (model, &iter_signal, COLUMN_SIGNAL, &signal_name, -1); - g_assert (signal_name != NULL); - } - else - iter_signal = iter; - - /* We are removing userdata */ - if (is_void_user_data(new_userdata)) - { - gtk_tree_store_set (GTK_TREE_STORE (model), &iter, - COLUMN_USERDATA_SLOT, TRUE, - COLUMN_USERDATA, _(USERDATA_DEFAULT), - COLUMN_LOOKUP, FALSE, - COLUMN_LOOKUP_VISIBLE, FALSE, -1); - } - else - { - gtk_tree_store_set (GTK_TREE_STORE (model), &iter, - COLUMN_USERDATA_SLOT, FALSE, - COLUMN_USERDATA, new_userdata, - COLUMN_LOOKUP_VISIBLE, TRUE, - -1); - } - - old_signal = - glade_signal_new - (signal_name, handler, - is_void_user_data(old_userdata) ? NULL : old_userdata, - lookup, after); - - new_signal = - glade_signal_new - (signal_name, handler, - is_void_user_data(new_userdata) ? NULL : new_userdata, - lookup, after); - - if (glade_signal_equal (old_signal, new_signal) == FALSE) - glade_command_change_signal (glade_widget, old_signal, new_signal); - - glade_signal_free (old_signal); - glade_signal_free (new_signal); - - gtk_tree_path_free (path); - g_free (signal_name); - g_free (handler); - g_free (old_userdata); -} - -static void -row_activated (GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn *tree_view_column, gpointer user_data) -{ - gtk_tree_view_set_cursor (view, path, tree_view_column, TRUE); - gtk_widget_grab_focus (GTK_WIDGET (view)); -} - -static GtkWidget * -glade_signal_editor_construct_signals_list (GladeSignalEditor *editor) -{ - GtkTreeView *view; - GtkWidget *view_widget; - GtkTreeViewColumn *column; - GtkCellRenderer *renderer; - GtkTreeModel *model; - - editor->model = gtk_tree_store_new - (NUM_COLUMNS, - G_TYPE_STRING, /* Signal value */ - G_TYPE_STRING, /* Handler value */ - G_TYPE_BOOLEAN, /* After value */ - G_TYPE_STRING, /* User data value */ - G_TYPE_BOOLEAN, /* module lookup string for - * user data */ - G_TYPE_BOOLEAN, /* Whether userdata is a slot */ - G_TYPE_BOOLEAN, /* Lookup visibility */ - G_TYPE_BOOLEAN, /* After visibility */ - G_TYPE_BOOLEAN, /* Handler editable */ - G_TYPE_BOOLEAN, /* Userdata editable */ - G_TYPE_BOOLEAN, /* New slot */ - G_TYPE_BOOLEAN); /* Mark with bold */ - - model = GTK_TREE_MODEL (editor->model); - - view_widget = gtk_tree_view_new_with_model (model); - g_object_set (G_OBJECT (view_widget), "enable-search", FALSE, NULL); - - view = GTK_TREE_VIEW (view_widget); - - /* the view now holds a reference, we can get rid of our own */ - g_object_unref (G_OBJECT (editor->model)); - - g_signal_connect(view, "row-activated", (GCallback) row_activated, NULL); - - /* Contruct handler model */ - glade_signal_editor_construct_handler_store (editor); - - /************************ signal column ************************/ - renderer = gtk_cell_renderer_text_new (); - g_object_set (G_OBJECT (renderer), "weight", PANGO_WEIGHT_BOLD, NULL); - column = gtk_tree_view_column_new_with_attributes - (_("Signal"), renderer, "text", COLUMN_SIGNAL, "weight-set", COLUMN_BOLD, NULL); - gtk_tree_view_append_column (view, column); - - /************************ handler column ************************/ - renderer = gtk_cell_renderer_combo_new (); - g_object_set (G_OBJECT (renderer), - "style", PANGO_STYLE_ITALIC, - "foreground", "Gray", - "model", GTK_TREE_MODEL (editor->handler_store), - "text-column", 0, - NULL); - - g_signal_connect (renderer, "edited", - G_CALLBACK (glade_signal_editor_handler_cell_edited), editor); - - g_signal_connect (renderer, "editing-started", - G_CALLBACK (glade_signal_editor_handler_editing_started), - editor); - - column = gtk_tree_view_column_new_with_attributes - (_("Handler"), renderer, - "text", COLUMN_HANDLER, - "style_set", COLUMN_SLOT, - "foreground_set", COLUMN_SLOT, - "editable", COLUMN_HANDLER_EDITABLE, NULL); - - gtk_tree_view_append_column (view, column); - - /************************ userdata column ************************/ - renderer = gtk_cell_renderer_text_new (); - g_object_set (G_OBJECT (renderer), - "style", PANGO_STYLE_ITALIC, - "foreground", "Gray", NULL); - - g_signal_connect (renderer, "edited", - G_CALLBACK (glade_signal_editor_userdata_cell_edited), editor); - - g_signal_connect (renderer, "editing-started", - G_CALLBACK (glade_signal_editor_user_data_editing_started), - editor); - - column = gtk_tree_view_column_new_with_attributes - (_("User data"), renderer, - "text", COLUMN_USERDATA, - "style_set", COLUMN_USERDATA_SLOT, - "foreground_set", COLUMN_USERDATA_SLOT, - "editable", COLUMN_USERDATA_EDITABLE, NULL); - - gtk_tree_view_append_column (view, column); - -#if LOOKUP_COLUMN - /************************ lookup column ************************/ - renderer = gtk_cell_renderer_toggle_new (); - g_signal_connect (renderer, "toggled", - G_CALLBACK (glade_signal_editor_lookup_toggled), editor); - column = gtk_tree_view_column_new_with_attributes - (_("Lookup"), renderer, - "active", COLUMN_LOOKUP, - "visible", COLUMN_LOOKUP_VISIBLE, NULL); - - gtk_tree_view_append_column (view, column); -#endif - /************************ after column ************************/ - renderer = gtk_cell_renderer_toggle_new (); - g_signal_connect (renderer, "toggled", - G_CALLBACK (glade_signal_editor_after_toggled), editor); - column = gtk_tree_view_column_new_with_attributes - (_("After"), renderer, - "active", COLUMN_AFTER, - "visible", COLUMN_AFTER_VISIBLE, NULL); - gtk_tree_view_append_column (view, column); - - return view_widget; -} - -static void -glade_signal_editor_construct (GladeSignalEditor *editor) -{ - GtkWidget *vbox; - GtkWidget *scroll; - - vbox = gtk_vbox_new (FALSE, 0); - editor->main_window = vbox; - - scroll = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll), - GTK_SHADOW_IN); - - editor->signals_list = glade_signal_editor_construct_signals_list (editor); - gtk_container_add (GTK_CONTAINER (scroll), editor->signals_list); - - gtk_box_pack_start (GTK_BOX (vbox), scroll, TRUE, TRUE, 0); - - gtk_widget_show_all (editor->main_window); -} - -/** - * glade_signal_editor_get_widget: - * @editor: a #GladeSignalEditor - * - * Returns: the #GtkWidget that is the main window for @editor, or %NULL if - * it does not exist - */ -GtkWidget * -glade_signal_editor_get_widget (GladeSignalEditor *editor) -{ - g_return_val_if_fail (GLADE_IS_SIGNAL_EDITOR (editor), NULL); - g_return_val_if_fail (GTK_IS_WIDGET (editor->main_window), NULL); - - return editor->main_window; -} - -/** - * glade_signal_editor_new: - * @editor: a #GladeEditor - * - * Returns: a new #GladeSignalEditor associated with @editor - */ -GladeSignalEditor * -glade_signal_editor_new (gpointer *editor) -{ - GladeSignalEditor *signal_editor; - - signal_editor = g_new0 (GladeSignalEditor, 1); - - glade_signal_editor_construct (signal_editor); - signal_editor->editor = editor; - - return signal_editor; -} - -/** - * glade_signal_editor_load_widget: - * @editor: a #GladeSignalEditor - * @widget: a #GladeWidget - * - * TODO: write me - */ -void -glade_signal_editor_load_widget (GladeSignalEditor *editor, - GladeWidget *widget) -{ - GList *list; - const gchar *last_type = ""; - GtkTreeIter iter; - GtkTreeIter parent_class; - GtkTreeIter parent_signal; - GtkTreePath *path_first; - GPtrArray *signals; - - g_return_if_fail (GLADE_IS_SIGNAL_EDITOR (editor)); - g_return_if_fail (widget == NULL || GLADE_IS_WIDGET (widget)); - - gtk_tree_store_clear (editor->model); - - editor->widget = widget; - editor->adaptor = widget ? widget->adaptor : NULL; - - if (!widget) - return; - - /* Loop over every signal type - */ - for (list = editor->adaptor->signals; list; list = list->next) - { - GladeSignalClass *signal = (GladeSignalClass *) list->data; - - /* Add class name that this signal belongs to. - */ - if (strcmp(last_type, signal->type)) - { - gtk_tree_store_append (editor->model, &parent_class, NULL); - gtk_tree_store_set (editor->model, &parent_class, - COLUMN_SIGNAL, signal->type, - COLUMN_AFTER_VISIBLE, FALSE, - COLUMN_HANDLER_EDITABLE, FALSE, - COLUMN_USERDATA_EDITABLE,FALSE, - COLUMN_SLOT, FALSE, - COLUMN_BOLD, FALSE, -1); - last_type = signal->type; - } - - gtk_tree_store_append (editor->model, &parent_signal, &parent_class); - signals = glade_widget_list_signal_handlers (widget, signal->name); - - if (!signals || signals->len == 0) - { - gtk_tree_store_set - (editor->model, &parent_signal, - COLUMN_SIGNAL, signal->name, - COLUMN_HANDLER, _(HANDLER_DEFAULT), - COLUMN_AFTER, FALSE, - COLUMN_USERDATA, _(USERDATA_DEFAULT), - COLUMN_LOOKUP, FALSE, - COLUMN_LOOKUP_VISIBLE, FALSE, - COLUMN_HANDLER_EDITABLE, TRUE, - COLUMN_USERDATA_EDITABLE,FALSE, - COLUMN_AFTER_VISIBLE, FALSE, - COLUMN_SLOT, TRUE, - COLUMN_USERDATA_SLOT, TRUE, - -1); - } - else - { - guint i; - GtkTreePath *path_parent_class; - GladeSignal *widget_signal = - (GladeSignal*) g_ptr_array_index (signals, 0); - - /* mark the class of this signal as bold and expand it, - * as there is at least one signal with handler */ - gtk_tree_store_set (editor->model, &parent_class, COLUMN_BOLD, TRUE, -1); - path_parent_class = - gtk_tree_model_get_path (GTK_TREE_MODEL (editor->model), - &parent_class); - gtk_tree_view_expand_row (GTK_TREE_VIEW (editor->signals_list), - path_parent_class, FALSE); - gtk_tree_path_free (path_parent_class); - - gtk_tree_store_set - (editor->model, &parent_signal, - COLUMN_SIGNAL, signal->name, - COLUMN_HANDLER, widget_signal->handler, - COLUMN_AFTER, widget_signal->after, - COLUMN_USERDATA, - widget_signal->userdata ? - widget_signal->userdata : _(USERDATA_DEFAULT), - COLUMN_LOOKUP, widget_signal->lookup, - COLUMN_LOOKUP_VISIBLE, - widget_signal->userdata ? TRUE : FALSE, - COLUMN_AFTER_VISIBLE, TRUE, - COLUMN_HANDLER_EDITABLE, TRUE, - COLUMN_USERDATA_EDITABLE, TRUE, - COLUMN_SLOT, FALSE, - COLUMN_USERDATA_SLOT, - widget_signal->userdata ? FALSE : TRUE, - COLUMN_BOLD, TRUE, -1); - - for (i = 1; i < signals->len; i++) - { - widget_signal = (GladeSignal*) g_ptr_array_index (signals, i); - gtk_tree_store_append (editor->model, &iter, &parent_signal); - - gtk_tree_store_set - (editor->model, &iter, - COLUMN_HANDLER, widget_signal->handler, - COLUMN_AFTER, widget_signal->after, - COLUMN_USERDATA, - widget_signal->userdata ? - widget_signal->userdata : _(USERDATA_DEFAULT), - COLUMN_LOOKUP, widget_signal->lookup, - COLUMN_LOOKUP_VISIBLE, - widget_signal->userdata ? TRUE : FALSE, - COLUMN_AFTER_VISIBLE, TRUE, - COLUMN_HANDLER_EDITABLE, TRUE, - COLUMN_USERDATA_EDITABLE, TRUE, - COLUMN_SLOT, FALSE, - COLUMN_USERDATA_SLOT, - widget_signal->userdata ? FALSE : TRUE, - -1); - } - - /* add the <Type...> slot */ - gtk_tree_store_append (editor->model, &iter, &parent_signal); - gtk_tree_store_set - (editor->model, &iter, - COLUMN_HANDLER, _(HANDLER_DEFAULT), - COLUMN_AFTER, FALSE, - COLUMN_USERDATA, _(USERDATA_DEFAULT), - COLUMN_LOOKUP, FALSE, - COLUMN_LOOKUP_VISIBLE, FALSE, - COLUMN_HANDLER_EDITABLE, TRUE, - COLUMN_USERDATA_EDITABLE,FALSE, - COLUMN_AFTER_VISIBLE, FALSE, - COLUMN_SLOT, TRUE, - COLUMN_USERDATA_SLOT, TRUE, -1); - } - } - - path_first = gtk_tree_path_new_first (); - gtk_tree_view_expand_row (GTK_TREE_VIEW (editor->signals_list), path_first, FALSE); - gtk_tree_path_free (path_first); -} diff --git a/gladeui/glade-signal-editor.h b/gladeui/glade-signal-editor.h deleted file mode 100644 index d4b38096..00000000 --- a/gladeui/glade-signal-editor.h +++ /dev/null @@ -1,50 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef __GLADE_SIGNAL_EDITOR_H__ -#define __GLADE_SIGNAL_EDITOR_H__ - -#include <gladeui/glade.h> - -G_BEGIN_DECLS - - -#define GLADE_SIGNAL_EDITOR(e) ((GladeSignalEditor *)e) -#define GLADE_IS_SIGNAL_EDITOR(e) (e != NULL) - -typedef struct _GladeSignalEditor GladeSignalEditor; - - -/* The GladeSignalEditor is used to house the signal editor interface and - * associated functionality. - */ -struct _GladeSignalEditor -{ - GtkWidget *main_window; /* A vbox where all the widgets are added */ - - GladeWidget *widget; - GladeWidgetAdaptor *adaptor; - - gpointer *editor; - - GtkWidget *signals_list; - GtkTreeStore *model; - GtkTreeView *tree_view; - - GtkListStore *handler_store; /* This store contains all the posible handler names */ - GtkEntryCompletion *completion; - GtkTreeIter iters[2]; -}; - - - -GtkWidget *glade_signal_editor_get_widget (GladeSignalEditor *editor); - - -GladeSignalEditor *glade_signal_editor_new (gpointer *editor); - - -void glade_signal_editor_load_widget (GladeSignalEditor *editor, GladeWidget *widget); - - -G_END_DECLS - -#endif /* __GLADE_SIGNAL_EDITOR_H__ */ diff --git a/gladeui/glade-signal.c b/gladeui/glade-signal.c deleted file mode 100644 index 1bf5dd9c..00000000 --- a/gladeui/glade-signal.c +++ /dev/null @@ -1,166 +0,0 @@ -/* -*- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Authors: - * Chema Celorio <chema@celorio.com> - * Paolo Borelli <pborelli@katamail.com> - */ - -#include "config.h" - -#include <string.h> - -#include <glib/gi18n-lib.h> - -#include "glade.h" -#include "glade-signal.h" -#include "glade-xml-utils.h" - -/** - * glade_signal_new: - * @name: a name for the signal - * @handler: a handler function for the signal - * @after: #gboolean indicating whether this handler should be called after - * the default handler - * - * Creates a new #GladeSignal with the given parameters. - * - * Returns: the new #GladeSignal - */ -GladeSignal *glade_signal_new (const gchar *name, - const gchar *handler, - const gchar *userdata, - gboolean lookup, - gboolean after) -{ - GladeSignal *signal = g_new0 (GladeSignal, 1); - - signal->name = g_strdup (name); - signal->handler = g_strdup (handler); - signal->userdata = userdata ? g_strdup (userdata) : NULL; - signal->lookup = lookup; - signal->after = after; - - return signal; -} - -/** - * glade_signal_free: - * @signal: a #GladeSignal - * - * Frees @signal and its associated memory. - */ -void -glade_signal_free (GladeSignal *signal) -{ - g_return_if_fail (GLADE_IS_SIGNAL (signal)); - - g_free (signal->name); - g_free (signal->handler); - if (signal->userdata) g_free (signal->userdata); - g_free (signal); -} - -/** - * glade_signal_equal: - * @sig1: a #GladeSignal - * @sig2: a #GladeSignal - * - * Returns: %TRUE if @sig1 and @sig2 have identical attributes, %FALSE otherwise - */ -gboolean -glade_signal_equal (GladeSignal *sig1, GladeSignal *sig2) -{ - gboolean ret = FALSE; - g_return_val_if_fail (GLADE_IS_SIGNAL (sig1), FALSE); - g_return_val_if_fail (GLADE_IS_SIGNAL (sig2), FALSE); - - if (!strcmp (sig1->name, sig2->name) && - !strcmp (sig1->handler, sig2->handler) && - sig1->after == sig2->after && - sig1->lookup == sig2->lookup) - { - if ((sig1->userdata == NULL && sig2->userdata == NULL) || - (sig1->userdata != NULL && sig2->userdata != NULL && - !strcmp (sig1->userdata, sig2->userdata))) - ret = TRUE; - } - - return ret; -} - -/** - * glade_signal_clone: - * @signal: a #GladeSignal - * - * Returns: a new #GladeSignal with the same attributes as @signal - */ -GladeSignal * -glade_signal_clone (const GladeSignal *signal) -{ - return glade_signal_new (signal->name, - signal->handler, - signal->userdata, - signal->lookup, - signal->after); -} - -/** - * glade_signal_write: - * @info: - * @signal: - * @interface: - * - * Returns: TRUE if succeed - */ -gboolean -glade_signal_write (GladeSignalInfo *info, GladeSignal *signal, - GladeInterface *interface) -{ - info->name = glade_xml_alloc_string(interface, signal->name); - glade_util_replace (info->name, '-', '_'); - info->handler = glade_xml_alloc_string(interface, signal->handler); - info->object = - signal->userdata ? - glade_xml_alloc_string(interface, signal->userdata) : NULL; - info->after = signal->after; - info->lookup = signal->lookup; - return TRUE; -} - -/* - * Returns a new GladeSignal with the attributes defined in node - */ -GladeSignal *glade_signal_new_from_signal_info (GladeSignalInfo *info) -{ - GladeSignal *signal; - - g_return_val_if_fail (info != NULL, NULL); - - signal = g_new0 (GladeSignal, 1); - signal->name = g_strdup (info->name); - glade_util_replace (signal->name, '_', '-'); - signal->handler = g_strdup (info->handler); - signal->after = info->after; - signal->userdata = g_strdup (info->object); - - if (!signal->name) - return NULL; - - return signal; -} diff --git a/gladeui/glade-signal.h b/gladeui/glade-signal.h deleted file mode 100644 index 0c2ff3ac..00000000 --- a/gladeui/glade-signal.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef __GLADE_SIGNAL_H__ -#define __GLADE_SIGNAL_H__ - -#include "glade-parser.h" - -G_BEGIN_DECLS - - -#define GLADE_SIGNAL(s) ((GladeSignal *)s) -#define GLADE_IS_SIGNAL(s) (s != NULL) - -typedef struct _GladeSignal GladeSignal; - -struct _GladeSignal -{ - gchar *name; /* Signal name eg "clicked" */ - gchar *handler; /* Handler function eg "gtk_main_quit" */ - gchar *userdata; /* User data signal handler argument */ - gboolean lookup; /* Whether user_data should be looked up - * with the GModule interface by libglade. - */ - gboolean after; /* Connect after TRUE or FALSE */ -}; - - -GladeSignal *glade_signal_new (const gchar *name, - const gchar *handler, - const gchar *userdata, - gboolean lookup, - gboolean after); -GladeSignal *glade_signal_clone (const GladeSignal *signal); -void glade_signal_free (GladeSignal *signal); - -gboolean glade_signal_equal (GladeSignal *sig1, GladeSignal *sig2); - -gboolean glade_signal_write (GladeSignalInfo *info, GladeSignal *signal, - GladeInterface *interface); - -GladeSignal *glade_signal_new_from_signal_info (GladeSignalInfo *info); - - -G_END_DECLS - -#endif /* __GLADE_SIGNAL_H__ */ diff --git a/gladeui/glade-utils.c b/gladeui/glade-utils.c deleted file mode 100644 index 723d8e40..00000000 --- a/gladeui/glade-utils.c +++ /dev/null @@ -1,1847 +0,0 @@ -/* -*- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Authors: - * Chema Celorio <chema@celorio.com> - */ - -#include <config.h> - -#include "glade.h" -#include "glade-project.h" -#include "glade-command.h" -#include "glade-debug.h" -#include "glade-placeholder.h" -#include "glade-widget.h" -#include "glade-widget-adaptor.h" -#include "glade-property.h" -#include "glade-property-class.h" -#include "glade-clipboard.h" -#include "glade-fixed.h" - -#include <string.h> -#include <gtk/gtktooltips.h> -#include <gdk/gdkkeysyms.h> -#include <gmodule.h> -#include <glib/gi18n-lib.h> -#include <glib/gstdio.h> -#include <errno.h> - -#ifdef G_OS_WIN32 -#define WIN32_LEAN_AND_MEAN -#include <windows.h> -#include <shellapi.h> -#endif - -#define GLADE_UTIL_SELECTION_NODE_SIZE 7 -#define GLADE_UTIL_COPY_BUFFSIZE 1024 - -#define GLADE_DEVHELP_ICON_NAME "devhelp" -#define GLADE_DEVHELP_FALLBACK_ICON_FILE "devhelp.png" - -/* List of widgets that have selection - */ -static GList *glade_util_selection = NULL; - -static GtkTooltips *glade_tooltips = NULL; - -/** - * glade_util_widget_set_tooltip: - * @widget: a #GtkWidget - * @str: a string - * - * Creates a new tooltip from @str and sets @widget to use it. - */ -void -glade_util_widget_set_tooltip (GtkWidget *widget, const gchar *str) -{ - g_return_if_fail (widget != NULL); - if (str == NULL) - return; - - if (glade_tooltips == NULL) - { - glade_tooltips = gtk_tooltips_new (); - - g_object_ref (G_OBJECT (glade_tooltips)); - gtk_object_sink (GTK_OBJECT (glade_tooltips)); - } - - gtk_tooltips_set_tip (glade_tooltips, widget, str, NULL); -} - -/** - * glade_util_compose_get_type_func: - * @name: - * - * TODO: write me - * - * Returns: - */ -static gchar * -glade_util_compose_get_type_func (const gchar *name) -{ - gchar *retval; - GString *tmp; - gint i = 1, j; - - tmp = g_string_new (name); - - while (tmp->str[i]) - { - if (g_ascii_isupper (tmp->str[i])) - { - tmp = g_string_insert_c (tmp, i++, '_'); - - j = 0; - while (g_ascii_isupper (tmp->str[i++])) - j++; - - if (j > 2) - g_string_insert_c (tmp, i-2, '_'); - - continue; - } - i++; - } - - tmp = g_string_append (tmp, "_get_type"); - retval = g_ascii_strdown (tmp->str, tmp->len); - g_string_free (tmp, TRUE); - - return retval; -} - -/** - * glade_util_get_type_from_name: - * @name: the name of the #GType - like 'GtkWidget' or a "get-type" function. - * @have_func: function-name flag -- true if the name is a "get-type" function. - * - * Returns the type using the "get type" function name based on @name. - * If the @have_func flag is true,@name is used directly, otherwise the get-type - * function is contrived from @name then used. - * - * Returns: the new #GType - */ -GType -glade_util_get_type_from_name (const gchar *name, gboolean have_func) -{ - static GModule *allsymbols = NULL; - GType (*get_type) (); - GType type = 0; - gchar *func_name = (gchar*)name; - - if ((type = g_type_from_name (name)) == 0 && - (have_func || (func_name = glade_util_compose_get_type_func (name)) != NULL)) - { - - if (!allsymbols) - allsymbols = g_module_open (NULL, 0); - - if (g_module_symbol (allsymbols, func_name, - (gpointer) &get_type)) - { - g_assert (get_type); - type = get_type (); - } - else - { - g_warning (_("We could not find the symbol \"%s\""), - func_name); - } - g_free (func_name); - } - - if (type == 0) - g_warning(_("Could not get the type from \"%s\""), name); - - return type; -} - -/** - * glade_utils_get_pspec_from_funcname: - * @funcname: the symbol name of a function to generate a #GParamSpec - * - * Returns: A #GParamSpec created by the delagate function - * specified by @funcname - */ -GParamSpec * -glade_utils_get_pspec_from_funcname (const gchar *funcname) -{ - static GModule *allsymbols = NULL; - GParamSpec *pspec = NULL; - GParamSpec *(*get_pspec)() = NULL; - - if (!allsymbols) - allsymbols = g_module_open (NULL, 0); - - if (!g_module_symbol (allsymbols, funcname, - (gpointer) &get_pspec)) { - g_warning (_("We could not find the symbol \"%s\""), - funcname); - return FALSE; - } - - g_assert (get_pspec); - pspec = get_pspec (); - - return pspec; -} - -/** - * glade_util_ui_message: - * @parent: a #GtkWindow cast as a #GtkWidget - * @format: a printf style format string - * @type: a #GladeUIMessageType - * @...: args for the format. - * - * Creates a new warning dialog window as a child of @parent containing - * the text of @format, runs it, then destroys it on close. Depending - * on @type, a cancel button may apear or the icon may change. - * - * Returns: True if the @type was GLADE_UI_ARE_YOU_SURE and the user - * selected "OK", True if the @type was GLADE_UI_YES_OR_NO and - * the user selected "YES"; False otherwise. - */ -gboolean -glade_util_ui_message (GtkWidget *parent, - GladeUIMessageType type, - const gchar *format, - ...) -{ - GtkWidget *dialog; - GtkMessageType message_type = GTK_MESSAGE_INFO; - GtkButtonsType buttons_type = GTK_BUTTONS_OK; - va_list args; - gchar *string; - gint response; - - va_start (args, format); - string = g_strdup_vprintf (format, args); - va_end (args); - - /* Get message_type */ - switch (type) - { - case GLADE_UI_INFO: message_type = GTK_MESSAGE_INFO; break; - case GLADE_UI_WARN: - case GLADE_UI_ARE_YOU_SURE: - message_type = GTK_MESSAGE_WARNING; - break; - case GLADE_UI_ERROR: message_type = GTK_MESSAGE_ERROR; break; - case GLADE_UI_YES_OR_NO: message_type = GTK_MESSAGE_QUESTION; break; - break; - default: - g_critical ("Bad arg for glade_util_ui_message"); - break; - } - - - /* Get buttons_type */ - switch (type) - { - case GLADE_UI_INFO: - case GLADE_UI_WARN: - case GLADE_UI_ERROR: - buttons_type = GTK_BUTTONS_OK; - break; - case GLADE_UI_ARE_YOU_SURE: buttons_type = GTK_BUTTONS_OK_CANCEL; break; - case GLADE_UI_YES_OR_NO: buttons_type = GTK_BUTTONS_YES_NO; break; - break; - default: - g_critical ("Bad arg for glade_util_ui_message"); - break; - } - - dialog = gtk_message_dialog_new (GTK_WINDOW (parent), - GTK_DIALOG_DESTROY_WITH_PARENT, - message_type, - buttons_type, - string); - - response = gtk_dialog_run (GTK_DIALOG (dialog)); - - gtk_widget_destroy (dialog); - g_free (string); - - return (response == GTK_RESPONSE_OK || response == GTK_RESPONSE_YES); -} - - - - - -typedef struct { - GtkStatusbar *statusbar; - guint context_id; - guint message_id; -} FlashInfo; - -static const guint32 flash_length = 3000; - -static gboolean -remove_message_timeout (FlashInfo * fi) -{ - gtk_statusbar_remove (fi->statusbar, fi->context_id, fi->message_id); - g_free (fi); - - /* remove the timeout */ - return FALSE; -} - -/** - * glade_utils_flash_message: - * @statusbar: The statusbar - * @context_id: The message context_id - * @format: The message to flash on the statusbar - * - * Flash a temporary message on the statusbar. - */ -void -glade_util_flash_message (GtkWidget *statusbar, guint context_id, gchar *format, ...) -{ - va_list args; - FlashInfo *fi; - gchar *message; - - g_return_if_fail (GTK_IS_STATUSBAR (statusbar)); - g_return_if_fail (format != NULL); - - va_start (args, format); - message = g_strdup_vprintf (format, args); - va_end (args); - - fi = g_new (FlashInfo, 1); - fi->statusbar = GTK_STATUSBAR (statusbar); - fi->context_id = context_id; - fi->message_id = gtk_statusbar_push (fi->statusbar, fi->context_id, message); - - gtk_timeout_add (flash_length, (GtkFunction) remove_message_timeout, fi); - - g_free (message); -} - -static gint -glade_util_compare_uline_labels (const gchar *labela, const gchar *labelb) -{ - for (;;) { - gunichar c1, c2; - - if (*labela == '\0') - return (*labelb == '\0') ? 0 : -1; - if (*labelb == '\0') - return 1; - - c1 = g_utf8_get_char (labela); - if (c1 == '_') { - labela = g_utf8_next_char (labela); - c1 = g_utf8_get_char (labela); - } - - c2 = g_utf8_get_char (labelb); - if (c2 == '_') { - labelb = g_utf8_next_char (labelb); - c2 = g_utf8_get_char (labelb); - } - - if (c1 < c2) - return -1; - if (c1 > c2) - return 1; - - labela = g_utf8_next_char (labela); - labelb = g_utf8_next_char (labelb); - } - - /* Shouldn't be reached. */ - return 0; -} - -/** - * glade_util_compare_stock_labels: - * @a: a #gconstpointer to a #GtkStockItem - * @b: a #gconstpointer to a #GtkStockItem - * - * This is a #GCompareFunc that compares the labels of two stock items, - * ignoring any '_' characters. It isn't particularly efficient. - * - * Returns: negative value if @a < @b; zero if @a = @b; - * positive value if @a > @b - */ -gint -glade_util_compare_stock_labels (gconstpointer a, gconstpointer b) -{ - const gchar *stock_ida = a, *stock_idb = b; - GtkStockItem itema, itemb; - gboolean founda, foundb; - gint retval; - - founda = gtk_stock_lookup (stock_ida, &itema); - foundb = gtk_stock_lookup (stock_idb, &itemb); - - if (founda) - { - if (!foundb) - retval = -1; - else - /* FIXME: Not ideal for UTF-8. */ - retval = glade_util_compare_uline_labels (itema.label, itemb.label); - } - else - { - if (!foundb) - retval = 0; - else - retval = 1; - } - - return retval; -} - -/** - * glade_util_gtk_combo_func: - * @data: - * - * TODO: write me - * - * Returns: - */ -gchar * -glade_util_gtk_combo_func (gpointer data) -{ - GtkListItem * listitem = data; - - /* I needed to pinch this as well - Damon. */ - static const gchar *gtk_combo_string_key = "gtk-combo-string-value"; - - GtkWidget *label; - gchar *ltext = NULL; - - ltext = (gchar *) gtk_object_get_data (GTK_OBJECT (listitem), - gtk_combo_string_key); - if (!ltext) { - label = GTK_BIN (listitem)->child; - if (!label || !GTK_IS_LABEL (label)) - return NULL; - ltext = (gchar*) gtk_label_get_text (GTK_LABEL (label)); - } - - return ltext; -} - -/* These are pinched from gtkcombo.c */ -/** - * glade_util_gtk_combo_find: - * @combo: - * - * TODO: write me - * - * Returns: - */ -gpointer /* GtkListItem * */ -glade_util_gtk_combo_find (GtkCombo * combo) -{ - gchar *text; - gchar *ltext; - GList *clist; - int (*string_compare) (const char *, const char *); - - if (combo->case_sensitive) - string_compare = strcmp; - else - string_compare = g_strcasecmp; - - text = (gchar*) gtk_entry_get_text (GTK_ENTRY (combo->entry)); - clist = GTK_LIST (combo->list)->children; - - while (clist && clist->data) { - ltext = glade_util_gtk_combo_func (GTK_LIST_ITEM (clist->data)); - if (!ltext) - continue; - if (!(*string_compare) (ltext, text)) - return (GtkListItem *) clist->data; - clist = clist->next; - } - - return NULL; -} - -/** - * glade_util_hide_window: - * @window: a #GtkWindow - * - * If you use this function to handle the delete_event of a window, when it - * will be shown again it will appear in the position where it was before - * beeing hidden. - */ -void -glade_util_hide_window (GtkWindow *window) -{ - gint x, y; - - g_return_if_fail (GTK_IS_WINDOW (window)); - - /* remember position of window for when it is used again */ - gtk_window_get_position (window, &x, &y); - - gtk_widget_hide (GTK_WIDGET (window)); - - gtk_window_move(window, x, y); -} - -/** - * glade_util_file_dialog_new: - * @title: dialog title - * @parent: the parent #GtkWindow for the dialog - * @action: a #GladeUtilFileDialogType to say if the dialog will open or save - * - * Returns: a "glade file" file chooser dialog. The caller is responsible - * for showing the dialog - */ -GtkWidget * -glade_util_file_dialog_new (const gchar *title, GtkWindow *parent, - GladeUtilFileDialogType action) -{ - GtkWidget *file_dialog; - GtkFileFilter *file_filter; - - g_return_val_if_fail ((action == GLADE_FILE_DIALOG_ACTION_OPEN || - action == GLADE_FILE_DIALOG_ACTION_SAVE), NULL); - - file_dialog = gtk_file_chooser_dialog_new (title, parent, action, - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL, - action == GLADE_FILE_DIALOG_ACTION_OPEN ? - GTK_STOCK_OPEN : GTK_STOCK_SAVE, - GTK_RESPONSE_OK, - NULL); - - file_filter = gtk_file_filter_new (); - gtk_file_filter_add_pattern (file_filter, "*"); - gtk_file_filter_set_name (file_filter, _("All Files")); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (file_dialog), file_filter); - - file_filter = gtk_file_filter_new (); - gtk_file_filter_add_pattern (file_filter, "*.glade"); - gtk_file_filter_set_name (file_filter, _("Glade Files")); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (file_dialog), file_filter); - - gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (file_dialog), file_filter); - - gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (file_dialog), TRUE); - gtk_dialog_set_default_response (GTK_DIALOG (file_dialog), GTK_RESPONSE_OK); - - return file_dialog; -} - -/** - * glade_util_replace: - * @str: a string - * @a: a #gchar - * @b: a #gchar - * - * Replaces each occurance of the character @a in @str to @b. - */ -void -glade_util_replace (gchar *str, gchar a, gchar b) -{ - g_return_if_fail (str != NULL); - - while (*str != 0) - { - if (*str == a) - *str = b; - - str = g_utf8_next_char (str); - } -} - -/** - * glade_util_read_prop_name: - * @str: a string - * - * Return a usable version of a property identifier as found - * in a freshly parserd #GladeInterface - */ -gchar * -glade_util_read_prop_name (const gchar *str) -{ - gchar *id; - - g_return_val_if_fail (str != NULL, NULL); - - id = g_strdup (str); - - glade_util_replace (id, '_', '-'); - - if (strstr (id, "::")) - { - /* Extract the second half of "AtkObject::accessible_name" - */ - gchar **split = g_strsplit (id, "::", 0); - g_free (id); - id = g_strdup (split[1]); - g_strfreev (split); - } - return id; -} - - -/** - * glade_util_duplicate_underscores: - * @name: a string - * - * Duplicates @name, but the copy has two underscores in place of any single - * underscore in the original. - * - * Returns: a newly allocated string - */ -gchar * -glade_util_duplicate_underscores (const gchar *name) -{ - const gchar *tmp; - const gchar *last_tmp = name; - gchar *underscored_name = g_malloc (strlen (name) * 2 + 1); - gchar *tmp_underscored = underscored_name; - - for (tmp = last_tmp; *tmp; tmp = g_utf8_next_char (tmp)) - { - if (*tmp == '_') - { - memcpy (tmp_underscored, last_tmp, tmp - last_tmp + 1); - tmp_underscored += tmp - last_tmp + 1; - last_tmp = tmp + 1; - *tmp_underscored++ = '_'; - } - } - - memcpy (tmp_underscored, last_tmp, tmp - last_tmp + 1); - - return underscored_name; -} - -/* This returns the window that the given widget's position is relative to. - Usually this is the widget's parent's window. But if the widget is a - toplevel, we use its own window, as it doesn't have a parent. - Some widgets also lay out widgets in different ways. */ -static GdkWindow* -glade_util_get_window_positioned_in (GtkWidget *widget) -{ - GtkWidget *parent; - - parent = widget->parent; - -#ifdef USE_GNOME - /* BonoboDockItem widgets use a different window when floating. - FIXME: I've left this here so we remember to add it when we add - GNOME support. */ - if (BONOBO_IS_DOCK_ITEM (widget) - && BONOBO_DOCK_ITEM (widget)->is_floating) { - return BONOBO_DOCK_ITEM (widget)->float_window; - } - - if (parent && BONOBO_IS_DOCK_ITEM (parent) - && BONOBO_DOCK_ITEM (parent)->is_floating) { - return BONOBO_DOCK_ITEM (parent)->float_window; - } -#endif - - if (parent) - return parent->window; - - return widget->window; -} - -static void -glade_util_draw_nodes (GdkWindow *window, GdkGC *gc, - gint x, gint y, - gint width, gint height) -{ - if (width > GLADE_UTIL_SELECTION_NODE_SIZE && height > GLADE_UTIL_SELECTION_NODE_SIZE) { - gdk_draw_rectangle (window, gc, TRUE, - x, y, - GLADE_UTIL_SELECTION_NODE_SIZE, - GLADE_UTIL_SELECTION_NODE_SIZE); - gdk_draw_rectangle (window, gc, TRUE, - x, y + height - GLADE_UTIL_SELECTION_NODE_SIZE, - GLADE_UTIL_SELECTION_NODE_SIZE, - GLADE_UTIL_SELECTION_NODE_SIZE); - gdk_draw_rectangle (window, gc, TRUE, - x + width - GLADE_UTIL_SELECTION_NODE_SIZE, y, - GLADE_UTIL_SELECTION_NODE_SIZE, - GLADE_UTIL_SELECTION_NODE_SIZE); - gdk_draw_rectangle (window, gc, TRUE, - x + width - GLADE_UTIL_SELECTION_NODE_SIZE, - y + height - GLADE_UTIL_SELECTION_NODE_SIZE, - GLADE_UTIL_SELECTION_NODE_SIZE, - GLADE_UTIL_SELECTION_NODE_SIZE); - } - - gdk_draw_rectangle (window, gc, FALSE, x, y, width - 1, height - 1); -} - -/* This calculates the offset of the given window within its toplevel. - It also returns the toplevel. */ -static void -glade_util_calculate_window_offset (GdkWindow *window, - gint *x, gint *y, - GdkWindow **toplevel) -{ - gint tmp_x, tmp_y; - - /* Calculate the offset of the window within its toplevel. */ - *x = 0; - *y = 0; - - for (;;) { - if (gdk_window_get_window_type (window) != GDK_WINDOW_CHILD) - break; - gdk_window_get_position (window, &tmp_x, &tmp_y); - *x += tmp_x; - *y += tmp_y; - window = gdk_window_get_parent (window); - } - - *toplevel = window; -} - -/* This returns TRUE if it is OK to draw the selection nodes for the given - selected widget inside the given window that has received an expose event. - For most widgets it returns TRUE, but if a selected widget is inside a - widget like a viewport, that uses its own coordinate system, then it only - returns TRUE if the expose window is inside the viewport as well. */ -static gboolean -glade_util_can_draw_nodes (GtkWidget *sel_widget, GdkWindow *sel_win, - GdkWindow *expose_win) -{ - GtkWidget *widget, *viewport = NULL; - GdkWindow *viewport_win = NULL; - - /* Check if the selected widget is inside a viewport. */ - for (widget = sel_widget->parent; widget; widget = widget->parent) { - if (GTK_IS_VIEWPORT (widget)) { - viewport = widget; - viewport_win = GTK_VIEWPORT (widget)->bin_window; - break; - } - } - - /* If there is no viewport-type widget above the selected widget, - it is OK to draw the selection anywhere. */ - if (!viewport) - return TRUE; - - /* If we have a viewport-type widget, check if the expose_win is - beneath the viewport. If it is, we can draw in it. If not, we - can't.*/ - for (;;) { - if (expose_win == sel_win) - return TRUE; - if (expose_win == viewport_win) - return FALSE; - if (gdk_window_get_window_type (expose_win) != GDK_WINDOW_CHILD) - break; - expose_win = gdk_window_get_parent (expose_win); - } - - return FALSE; -} - -/** - * glade_util_draw_nodes_idle: - * @expose_win: a #GdkWindow - * - * Redraws any selection nodes that intersect @expose_win. Steps through all - * selected widgets, finds their coordinates, and calls glade_util_draw_nodes() - * if appropriate. - * - * Returns: %FALSE - */ -static gboolean -glade_util_draw_nodes_idle (GdkWindow *expose_win) -{ - GtkWidget *expose_widget; - gint expose_win_x, expose_win_y; - gint expose_win_w, expose_win_h; - GdkWindow *expose_toplevel; - GdkGC *gc; - GList *elem; - - /* Check that the window is still alive. */ - if (!gdk_window_is_viewable (expose_win)) - goto out; - - /* Find the corresponding GtkWidget */ - gdk_window_get_user_data (expose_win, (gpointer)&expose_widget); - - gc = expose_widget->style->black_gc; - - /* Calculate the offset of the expose window within its toplevel. */ - glade_util_calculate_window_offset (expose_win, - &expose_win_x, - &expose_win_y, - &expose_toplevel); - - gdk_drawable_get_size (expose_win, - &expose_win_w, &expose_win_h); - - /* Step through all the selected widgets. */ - for (elem = glade_util_selection; elem; elem = elem->next) { - - GtkWidget *sel_widget; - GdkWindow *sel_win, *sel_toplevel; - gint sel_x, sel_y, x, y, w, h; - - sel_widget = elem->data; - - if ((sel_win = glade_util_get_window_positioned_in (sel_widget)) == NULL) - continue; - - /* Calculate the offset of the selected widget's window - within its toplevel. */ - glade_util_calculate_window_offset (sel_win, &sel_x, &sel_y, - &sel_toplevel); - - /* We only draw the nodes if the window that got the expose - event is in the same toplevel as the selected widget. */ - if (expose_toplevel == sel_toplevel - && glade_util_can_draw_nodes (sel_widget, sel_win, - expose_win)) { - x = sel_x + sel_widget->allocation.x - expose_win_x; - y = sel_y + sel_widget->allocation.y - expose_win_y; - w = sel_widget->allocation.width; - h = sel_widget->allocation.height; - - /* Draw the selection nodes if they intersect the - expose window bounds. */ - if (x < expose_win_w && x + w >= 0 - && y < expose_win_h && y + h >= 0) { - glade_util_draw_nodes (expose_win, gc, - x, y, w, h); - } - } - } - - out: - /* Remove the reference added in glade_util_queue_draw_nodes(). */ - g_object_unref (G_OBJECT (expose_win)); - - /* Return FALSE so the idle handler isn't called again. */ - return FALSE; -} - -#define GLADE_DRAW_NODES_IDLE_PRIORITY GTK_PRIORITY_DEFAULT + 10 - -/** - * glade_util_queue_draw_nodes: - * @window: A #GdkWindow - * - * This function should be called whenever a widget in the interface receives - * an expose event. It sets up an idle function which will redraw any selection - * nodes that intersect the the exposed window. - */ -void -glade_util_queue_draw_nodes (GdkWindow *window) -{ - g_return_if_fail (GDK_IS_WINDOW (window)); - - g_idle_add_full (GLADE_DRAW_NODES_IDLE_PRIORITY, - (GSourceFunc)glade_util_draw_nodes_idle, - window, NULL); - - g_object_ref (G_OBJECT (window)); -} - - -/** - * glade_util_add_selection: - * @widget: a #GtkWidget - * - * Add visual selection to this GtkWidget - */ -void -glade_util_add_selection (GtkWidget *widget) -{ - g_return_if_fail (GTK_IS_WIDGET (widget)); - if (glade_util_has_selection (widget)) - return; - - glade_util_selection = - g_list_prepend (glade_util_selection, widget); - gtk_widget_queue_draw (widget); -} - -/** - * glade_util_remove_selection: - * @widget: a #GtkWidget - * - * Remove visual selection from this GtkWidget - */ -void -glade_util_remove_selection (GtkWidget *widget) -{ - g_return_if_fail (GTK_IS_WIDGET (widget)); - if (!glade_util_has_selection (widget)) - return; - - glade_util_selection = - g_list_remove (glade_util_selection, widget); - - /* We redraw the parent, since the selection rectangle may not be - cleared if we just redraw the widget itself. */ - gtk_widget_queue_draw (widget->parent ? - widget->parent : widget); -} - -/** - * glade_util_clear_selection: - * - * Clear all visual selections - */ -void -glade_util_clear_selection (void) -{ - GtkWidget *widget; - GList *list; - - for (list = glade_util_selection; - list && list->data; - list = list->next) - { - widget = list->data; - gtk_widget_queue_draw (widget->parent ? - widget->parent : widget); - } - glade_util_selection = - (g_list_free (glade_util_selection), NULL); -} - -/** - * glade_util_has_selection: - * @widget: a #GtkWidget - * - * Returns: %TRUE if @widget has visual selection, %FALSE otherwise - */ -gboolean -glade_util_has_selection (GtkWidget *widget) -{ - g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); - return g_list_find (glade_util_selection, widget) != NULL; -} - -/** - * glade_util_get_selectoin: - * - * Returns: The list of selected #GtkWidgets - */ -GList * -glade_util_get_selection () -{ - return glade_util_selection; -} - -/* - * taken from gtk... maybe someday we can convince them to - * expose gtk_container_get_all_children - */ -static void -gtk_container_children_callback (GtkWidget *widget, - gpointer client_data) -{ - GList **children; - - children = (GList**) client_data; - *children = g_list_prepend (*children, widget); -} - -/** - * glade_util_container_get_all_children: - * @container: a #GtkContainer - * - * Use this to itterate over all children in a GtkContainer, - * as it used _forall() instead of _foreach() (and the GTK+ version - * of this function is simply not exposed). - * - * Note that glade_widget_class_get_children() is the high-level - * abstraction and will usually end up calling this function. - * - * Returns: a #GList giving the contents of @container - */ -GList * -glade_util_container_get_all_children (GtkContainer *container) -{ - GList *children = NULL; - - g_return_val_if_fail (GTK_IS_CONTAINER (container), NULL); - - gtk_container_forall (container, - gtk_container_children_callback, - &children); - - /* Preserve the natural order by reversing the list */ - return g_list_reverse (children); -} - -/** - * glade_util_count_placeholders: - * @parent: a #GladeWidget - * - * Returns the amount of #GladePlaceholders parented by @parent - */ -gint -glade_util_count_placeholders (GladeWidget *parent) -{ - gint placeholders = 0; - GList *list, *children; - - /* count placeholders */ - if ((children = glade_widget_adaptor_get_children - (parent->adaptor, parent->object)) != NULL) - { - for (list = children; list && list->data; list = list->next) - { - if (GLADE_IS_PLACEHOLDER (list->data)) - placeholders++; - } - g_list_free (children); - } - - return placeholders; -} - -static GtkTreeIter * -glade_util_find_iter (GtkTreeModel *model, - GtkTreeIter *iter, - GladeWidget *findme, - gint column) -{ - GtkTreeIter *retval = NULL; - GladeWidget *widget; - GtkTreeIter *next; - - g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL); - g_return_val_if_fail (iter != NULL, NULL); - - next = gtk_tree_iter_copy (iter); - g_return_val_if_fail (next != NULL, NULL); - - while (retval == NULL) - { - gtk_tree_model_get (model, next, column, &widget, -1); - if (widget == NULL) { - g_warning ("Could not get the glade widget from the model"); - break; - } - else if (widget == findme) - { - retval = gtk_tree_iter_copy (next); - break; - } - else if (gtk_tree_model_iter_has_child (model, next)) - { - GtkTreeIter child; - gtk_tree_model_iter_children (model, &child, next); - if ((retval = glade_util_find_iter - (model, &child, findme, column)) != NULL) - break; - } - - if (!gtk_tree_model_iter_next (model, next)) - break; - } - gtk_tree_iter_free (next); - - return retval; -} - -/** - * glade_util_find_iter_by_widget: - * @model: a #GtkTreeModel - * @findme: a #GladeWidget - * @column: a #gint - * - * Looks through @model for the #GtkTreeIter corresponding to - * @findme under @column. - * - * Returns: a newly allocated #GtkTreeIter from @model corresponding - * to @findme which should be freed with gtk_tree_iter_free() - * - */ -GtkTreeIter * -glade_util_find_iter_by_widget (GtkTreeModel *model, - GladeWidget *findme, - gint column) -{ - GtkTreeIter iter; - if (gtk_tree_model_get_iter_first (model, &iter)) - { - return glade_util_find_iter (model, &iter, findme, column); - } - return NULL; -} - -gboolean -glade_util_basenames_match (const gchar *path1, - const gchar *path2) -{ - gboolean match = FALSE; - gchar *bname1; - gchar *bname2; - - if (path1 && path2) - { - bname1 = g_path_get_basename (path1); - bname2 = g_path_get_basename (path2); - - match = !strcmp (bname1, bname2); - - g_free (bname1); - g_free (bname2); - } - return match; -} - -/** - * glade_util_purify_list: - * @list: A #GList - * - * Returns: A newly allocated version of @list with no - * duplicate data entries - */ -GList * -glade_util_purify_list (GList *list) -{ - GList *l, *newlist = NULL; - - for (l = list; l; l = l->next) - if (!g_list_find (newlist, l->data)) - newlist = g_list_prepend (newlist, l->data); - - g_list_free (list); - - return g_list_reverse (newlist); -} - -/** - * glade_util_added_in_list: - * @old: the old #GList - * @new: the new #GList - * - * Returns: A newly allocated #GList of elements that - * are in @new but not in @old - * - */ -GList * -glade_util_added_in_list (GList *old_list, - GList *new_list) -{ - GList *added = NULL, *list; - - for (list = new_list; list; list = list->next) - { - if (!g_list_find (old_list, list->data)) - added = g_list_prepend (added, list->data); - } - - return g_list_reverse (added); -} - -/** - * glade_util_removed_from_list: - * @old: the old #GList - * @new: the new #GList - * - * Returns: A newly allocated #GList of elements that - * are in @old no longer in @new - * - */ -GList * -glade_util_removed_from_list (GList *old_list, - GList *new_list) -{ - GList *added = NULL, *list; - - for (list = old_list; list; list = list->next) - { - if (!g_list_find (new_list, list->data)) - added = g_list_prepend (added, list->data); - } - - return g_list_reverse (added); -} - - -/** - * glade_util_canonical_path: - * @path: any path that may contain ".." or "." components - * - * Returns: an absolute path to the specified file or directory - * that contains no ".." or "." components (this does - * not call readlink like realpath() does). - * - * Note: on some systems; I think its possible that we dont have - * permission to execute in the directory in which the glade - * file resides; I decided finally to do it this way anyway - * since libc's realpath() does exactly the same. - */ -gchar * -glade_util_canonical_path (const gchar *path) -{ - gchar *orig_dir, *dirname, *basename, *direct_dir, *direct_name = NULL; - - g_return_val_if_fail (path != NULL, NULL); - - basename = g_path_get_basename (path); - - if ((orig_dir = g_get_current_dir ()) != NULL) - { - if ((dirname = g_path_get_dirname (path)) != NULL) - { - if (g_chdir (dirname) == 0) - { - if ((direct_dir = g_get_current_dir ()) != NULL) - direct_name = - g_build_filename (direct_dir, basename, NULL); - else - g_warning ("g_path"); - - if (g_chdir (orig_dir) != 0) - g_warning ("Unable to chdir back to %s directory (%s)", - orig_dir, g_strerror (errno)); - - } else g_warning ("Unable to chdir to %s directory (%s)", - dirname, g_strerror (errno)); - - g_free (dirname); - } else g_warning ("Unable to get directory component of %s\n", path); - g_free (orig_dir); - } - - if (basename) g_free (basename); - - return direct_name; -} - -static gboolean -glade_util_canonical_match (const gchar *src_path, - const gchar *dest_path) -{ - gchar *canonical_src, *canonical_dest; - gboolean match; - canonical_src = glade_util_canonical_path (src_path); - canonical_dest = glade_util_canonical_path (dest_path); - - match = (strcmp (canonical_src, canonical_dest) == 0); - - g_free (canonical_src); - g_free (canonical_dest); - - return match; -} - -/** - * glade_util_copy_file: - * @src_path: the path to the source file - * @dest_path: the path to the destination file to create or overwrite. - * - * Copies a file from @src to @dest, queries the user - * if it involves overwriting the target and displays an - * error message upon failure. - * - * Returns: True if the copy was successfull. - */ -gboolean -glade_util_copy_file (const gchar *src_path, - const gchar *dest_path) -{ - GIOChannel *src, *dest; - GError *error = NULL; - GIOStatus read_status, write_status = G_IO_STATUS_ERROR; - gchar buffer[GLADE_UTIL_COPY_BUFFSIZE]; - gsize bytes_read, bytes_written, written; - gboolean success = FALSE; - - /* FIXME: This may break if src_path & dest_path are actually - * the same file, right now the canonical comparison is the - * best check I have. - */ - if (glade_util_canonical_match (src_path, dest_path)) - return FALSE; - - if (g_file_test (dest_path, G_FILE_TEST_IS_REGULAR) != FALSE) - if (glade_util_ui_message - (glade_app_get_window(), GLADE_UI_YES_OR_NO, - _("%s exists.\nDo you want to replace it?"), dest_path) == FALSE) - return FALSE; - - - if ((src = g_io_channel_new_file (src_path, "r", &error)) != NULL) - { - g_io_channel_set_encoding (src, NULL, NULL); - - if ((dest = g_io_channel_new_file (dest_path, "w", &error)) != NULL) - { - g_io_channel_set_encoding (dest, NULL, NULL); - - while ((read_status = g_io_channel_read_chars - (src, buffer, GLADE_UTIL_COPY_BUFFSIZE, - &bytes_read, &error)) != G_IO_STATUS_ERROR) - { - bytes_written = 0; - while ((write_status = g_io_channel_write_chars - (dest, buffer + bytes_written, - bytes_read - bytes_written, - &written, &error)) != G_IO_STATUS_ERROR && - (bytes_written + written) < bytes_read) - bytes_written += written; - - if (write_status == G_IO_STATUS_ERROR) - { - glade_util_ui_message (glade_app_get_window(), - GLADE_UI_ERROR, - _("Error writing to %s: %s"), - dest_path, error->message); - error = (g_error_free (error), NULL); - break; - } - - /* Break on EOF & ERROR but not AGAIN and not NORMAL */ - if (read_status == G_IO_STATUS_EOF) break; - } - - if (read_status == G_IO_STATUS_ERROR) - { - glade_util_ui_message (glade_app_get_window(), - GLADE_UI_ERROR, - _("Error reading %s: %s"), - src_path, error->message); - error = (g_error_free (error), NULL); - } - - - /* From here on, unless we have problems shutting down, succuss ! */ - success = (read_status == G_IO_STATUS_EOF && - write_status == G_IO_STATUS_NORMAL); - - if (g_io_channel_shutdown (dest, TRUE, &error) != G_IO_STATUS_NORMAL) - { - glade_util_ui_message - (glade_app_get_window(), - GLADE_UI_ERROR, - _("Error shutting down I/O channel %s: %s"), - dest_path, error->message); - error = (g_error_free (error), NULL); - success = FALSE; - } - } - else - { - glade_util_ui_message (glade_app_get_window(), - GLADE_UI_ERROR, - _("Failed to open %s for writing: %s"), - dest_path, error->message); - error = (g_error_free (error), NULL); - - } - - - if (g_io_channel_shutdown (src, TRUE, &error) != G_IO_STATUS_NORMAL) - { - glade_util_ui_message (glade_app_get_window(), - GLADE_UI_ERROR, - _("Error shutting down io channel %s: %s"), - src_path, error->message); - success = FALSE; - } - } - else - { - glade_util_ui_message (glade_app_get_window(), - GLADE_UI_ERROR, - _("Failed to open %s for reading: %s"), - src_path, error->message); - error = (g_error_free (error), NULL); - } - return success; -} - -/** - * glade_util_class_implements_interface: - * @class_type: A #GType - * @iface_type: A #GType - * - * Returns: whether @class_type implements the @iface_type interface - */ -gboolean -glade_util_class_implements_interface (GType class_type, - GType iface_type) -{ - GType *ifaces; - guint n_ifaces, i; - gboolean implemented = FALSE; - - if ((ifaces = g_type_interfaces (class_type, &n_ifaces)) != NULL) - { - for (i = 0; i < n_ifaces; i++) - if (ifaces[i] == iface_type) - { - implemented = TRUE; - break; - } - g_free (ifaces); - } - return implemented; -} - - -/** - * glade_util_load_library: - * @library_name: name of the library - * - * Loads the named library from the Glade modules directory, or failing that - * from the standard platform specific directories. - * - * The @library_name should not include any platform specifix prefix or suffix, - * those are automatically added, if needed, by g_module_build_path() - * - * Returns: a #GModule on success, or %NULL on failure. - */ -GModule * -glade_util_load_library (const gchar *library_name) -{ - gchar *path; - GModule *module; - - path = g_module_build_path (glade_app_get_modules_dir (), library_name); - - if ((module = g_module_open (path, G_MODULE_BIND_LAZY)) == NULL) - { - g_warning (_("Unable to open the module %s (%s)."), - path, g_module_error()); - } - - g_free (path); - - return module; -} - -/** - * glade_util_file_is_writeable: - * @path: the path to the file - * - * Checks whether the file at @path is writeable - * - * Returns: TRUE if file is writeable - */ -gboolean -glade_util_file_is_writeable (const gchar *path) -{ - GIOChannel *channel; - g_return_val_if_fail (path != NULL, FALSE); - - /* The only way to really know if the file is writable */ - if ((channel = g_io_channel_new_file (path, "a+", NULL)) != NULL) - { - g_io_channel_unref (channel); - return TRUE; - } - return FALSE; -} - -/** - * glade_util_have_devhelp: - * - * Returns: whether the devhelp module is loaded - */ -gboolean -glade_util_have_devhelp (void) -{ - static gint have_devhelp = -1; - gchar *ptr; - gint cnt, ret, major, minor; - GError *error = NULL; - -#define DEVHELP_OLD_MESSAGE \ - "The DevHelp installed on your system is too old, " \ - "devhelp feature will be disabled." - -#define DEVHELP_MISSING_MESSAGE \ - "No DevHelp installed on your system, " \ - "devhelp feature will be disabled." - - if (have_devhelp >= 0) return have_devhelp; - - have_devhelp = 0; - - if ((ptr = g_find_program_in_path ("devhelp")) != NULL) - { - g_free (ptr); - - if (g_spawn_command_line_sync ("devhelp --version", - &ptr, NULL, &ret, &error)) - { - /* If we have a successfull return code.. parse the output. - */ - if (ret == 0) - { - gchar name[16]; - if ((cnt = sscanf (ptr, "%15s %d.%d\n", - name, &major, &minor)) == 3) - { - /* Devhelp 0.12 required. - */ - if (major >= 0 && minor >= 12) - have_devhelp = 1; - else - g_message (DEVHELP_OLD_MESSAGE); - } - else - - { - if (ptr != NULL || strlen (ptr) > 0) - g_warning ("devhelp had unparsable output: " - "'%s' (parsed %d elements)", ptr, cnt); - else - g_message (DEVHELP_OLD_MESSAGE); - } - } - else g_warning ("devhelp had bad return code: '%d'", ret); - } - else - { - g_warning ("Error trying to launch devhelp: %s", - error->message); - g_error_free (error); - } - } - else g_message (DEVHELP_MISSING_MESSAGE); - - return have_devhelp; -} - -/** - * glade_util_get_devhelp_icon: - * @size: the preferred icon size - * - * Creates an image displaying the devhelp icon. - * - * Returns: a #GtkImage - */ -GtkWidget* -glade_util_get_devhelp_icon (GtkIconSize size) -{ - GtkIconTheme *icon_theme; - GdkScreen *screen; - GtkWidget *image; - gchar *path; - - image = gtk_image_new (); - screen = gtk_widget_get_screen (GTK_WIDGET (image)); - icon_theme = gtk_icon_theme_get_for_screen (screen); - - if (gtk_icon_theme_has_icon (icon_theme, GLADE_DEVHELP_ICON_NAME)) - { - gtk_image_set_from_icon_name (GTK_IMAGE (image), GLADE_DEVHELP_ICON_NAME, size); - } - else - { - path = g_build_filename (glade_app_get_pixmaps_dir (), GLADE_DEVHELP_FALLBACK_ICON_FILE, NULL); - - gtk_image_set_from_file (GTK_IMAGE (image), path); - - g_free (path); - } - - return image; -} - -/** - * glade_util_search_devhep: - * @devhelp: the devhelp widget created by the devhelp module. - * @book: the devhelp book (or %NULL) - * @page: the page in the book (or %NULL) - * @search: the search string (or %NULL) - * - * Envokes devhelp with the appropriate search string - * - */ -void -glade_util_search_devhelp (const gchar *book, - const gchar *page, - const gchar *search) -{ - GError *error = NULL; - gchar *book_comm = NULL, *page_comm = NULL; - gchar *string; - - g_return_if_fail (glade_util_have_devhelp ()); - - if (book) book_comm = g_strdup_printf ("book:%s ", book); - if (page) page_comm = g_strdup_printf ("page:%s ", page); - - string = g_strdup_printf ("devhelp -s \"%s%s%s\"", - book_comm ? book_comm : "", - page_comm ? page_comm : "", - search ? search : ""); - - if (g_spawn_command_line_async (string, &error) == FALSE) - { - g_warning ("Error envoking devhelp: %s", error->message); - g_error_free (error); - } - - g_free (string); - if (book_comm) g_free (book_comm); - if (page_comm) g_free (page_comm); -} - -GtkWidget * -glade_util_get_placeholder_from_pointer (GtkContainer *container) -{ - GtkWidget *toplevel; - GtkWidget *retval = NULL, *child; - GList *c, *l; - gint x, y, x2, y2; - - g_return_val_if_fail (GTK_IS_CONTAINER (container), NULL); - - toplevel = gtk_widget_get_toplevel (GTK_WIDGET (container)); - - gtk_widget_get_pointer (toplevel, &x, &y); - - for (c = l = glade_util_container_get_all_children (container); - l; - l = g_list_next (l)) - { - child = l->data; - - if (GLADE_IS_PLACEHOLDER (child) && - GTK_WIDGET_MAPPED (child)) - { - gtk_widget_translate_coordinates (toplevel, child, - x, y, &x2, &y2); - - - if (x2 >= 0 && y2 >= 0 && - x2 <= child->allocation.width && - y2 <= child->allocation.height) - { - retval = child; - break; - } - } - } - - g_list_free (c); - - return retval; -} - -/** - * glade_util_object_is_loading: - * @object: A #GObject - * - * Returns: Whether the object's project is being loaded or not. - * - */ -gboolean -glade_util_object_is_loading (GObject *object) -{ - GladeProject *project; - GladeWidget *widget; - - g_return_val_if_fail (G_IS_OBJECT (object), FALSE); - - widget = glade_widget_get_from_gobject (object); - g_return_val_if_fail (GLADE_IS_WIDGET (widget), FALSE); - - project = glade_widget_get_project (widget); - - return glade_project_is_loading (project); -} - -#ifdef G_OS_WIN32 - -static gboolean -glade_util_url_show_win32 (const gchar *url) -{ - HINSTANCE h; - - h = ShellExecuteA (NULL, "open", url, NULL, NULL, SW_SHOWNORMAL); - - if ((int)h <= 32) - return FALSE; - - return TRUE; -} - -#else - -/* pilfered from Beast - birnetutils.cc */ -static gboolean -glade_util_url_show_unix (const gchar *url) -{ - static struct { - const gchar *prg, *arg1, *prefix, *postfix; - gboolean asyncronous; /* start asyncronously and check exit code to catch launch errors */ - volatile gboolean disabled; - } browsers[] = { - - /* configurable, working browser launchers */ - { "gnome-open", NULL, "", "", 0 }, /* opens in background, correct exit_code */ - { "exo-open", NULL, "", "", 0 }, /* opens in background, correct exit_code */ - - /* non-configurable working browser launchers */ - { "kfmclient", "openURL", "", "", 0 }, /* opens in background, correct exit_code */ - { "gnome-moz-remote", "--newwin", "", "", 0 }, /* opens in background, correct exit_code */ - -#if 0 /* broken/unpredictable browser launchers */ - { "browser-config", NULL, "", "", 0 }, /* opens in background (+ sleep 5), broken exit_code (always 0) */ - { "xdg-open", NULL, "", "", 0 }, /* opens in foreground (first browser) or background, correct exit_code */ - { "sensible-browser", NULL, "", "", 0 }, /* opens in foreground (first browser) or background, correct exit_code */ - { "htmlview", NULL, "", "", 0 }, /* opens in foreground (first browser) or background, correct exit_code */ -#endif - - /* direct browser invocation */ - { "x-www-browser", NULL, "", "", 1 }, /* opens in foreground, browser alias */ - { "firefox", NULL, "", "", 1 }, /* opens in foreground, correct exit_code */ - { "mozilla-firefox", NULL, "", "", 1 }, /* opens in foreground, correct exit_code */ - { "mozilla", NULL, "", "", 1 }, /* opens in foreground, correct exit_code */ - { "konqueror", NULL, "", "", 1 }, /* opens in foreground, correct exit_code */ - { "opera", "-newwindow", "", "", 1 }, /* opens in foreground, correct exit_code */ - { "epiphany", NULL, "", "", 1 }, /* opens in foreground, correct exit_code */ - { "galeon", NULL, "", "", 1 }, /* opens in foreground, correct exit_code */ - { "amaya", NULL, "", "", 1 }, /* opens in foreground, correct exit_code */ - { "dillo", NULL, "", "", 1 }, /* opens in foreground, correct exit_code */ - - }; - - guint i; - for (i = 0; i < G_N_ELEMENTS (browsers); i++) - - if (!browsers[i].disabled) - { - gchar *args[128] = { 0, }; - guint n = 0; - gchar *string; - gchar fallback_error[64] = "Ok"; - gboolean success; - - args[n++] = (gchar*) browsers[i].prg; - - if (browsers[i].arg1) - args[n++] = (gchar*) browsers[i].arg1; - - string = g_strconcat (browsers[i].prefix, url, browsers[i].postfix, NULL); - args[n] = string; - - if (!browsers[i].asyncronous) /* start syncronously and check exit code */ - { - gint exit_status = -1; - success = g_spawn_sync (NULL, /* cwd */ - args, - NULL, /* envp */ - G_SPAWN_SEARCH_PATH, - NULL, /* child_setup() */ - NULL, /* user_data */ - NULL, /* standard_output */ - NULL, /* standard_error */ - &exit_status, - NULL); - success = success && !exit_status; - - if (exit_status) - g_snprintf (fallback_error, sizeof (fallback_error), "exitcode: %u", exit_status); - - } - else - { - success = g_spawn_async (NULL, /* cwd */ - args, - NULL, /* envp */ - G_SPAWN_SEARCH_PATH, - NULL, /* child_setup() */ - NULL, /* user_data */ - NULL, /* child_pid */ - NULL); - } - - g_free (string); - if (success) - return TRUE; - browsers[i].disabled = TRUE; - } - - /* reset all disabled states if no browser could be found */ - for (i = 0; i < G_N_ELEMENTS (browsers); i++) - browsers[i].disabled = FALSE; - - return FALSE; -} - -#endif - -/** - * glade_util_url_show: - * @url: An URL to display - * - * Portable function for showing an URL @url in a web browser. - * - * Returns: TRUE if a web browser was successfully launched, or FALSE - * - */ -gboolean -glade_util_url_show (const gchar *url) -{ - g_return_val_if_fail (url != NULL, FALSE); - -#ifdef G_OS_WIN32 - return glade_util_url_show_win32 (url); -#else - return glade_util_url_show_unix (url); -#endif -} - -/** - * glade_util_get_file_mtime: - * @filename: A filename - * @error: return location for errors - * - * Gets the UTC modification time of file @filename. - * - * Returns: The mtime of the file, or %0 if the file attributes - * could not be read. - */ -time_t -glade_util_get_file_mtime (const gchar *filename, GError **error) -{ - struct stat info; - gint retval; - - retval = g_stat (filename, &info); - - if (retval != 0) { - g_set_error (error, - G_FILE_ERROR, - g_file_error_from_errno (errno), - "could not stat file '%s': %s", filename, g_strerror (errno)); - return (time_t) 0; - } else { - return info.st_mtime; - } -} diff --git a/gladeui/glade-utils.h b/gladeui/glade-utils.h deleted file mode 100644 index be4112cf..00000000 --- a/gladeui/glade-utils.h +++ /dev/null @@ -1,138 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef __GLADE_UTILS_H__ -#define __GLADE_UTILS_H__ - -#include <glib.h> - -G_BEGIN_DECLS - - -typedef enum _GladeUtilFileDialogType -{ - GLADE_FILE_DIALOG_ACTION_OPEN, - GLADE_FILE_DIALOG_ACTION_SAVE -} GladeUtilFileDialogType; - -typedef enum -{ - GLADE_UI_INFO, - GLADE_UI_WARN, - GLADE_UI_ERROR, - GLADE_UI_ARE_YOU_SURE, - GLADE_UI_YES_OR_NO -} GladeUIMessageType; - - -void glade_util_widget_set_tooltip (GtkWidget *widget, const gchar *str); - -GType glade_util_get_type_from_name (const gchar *name, gboolean have_func); - -GParamSpec *glade_utils_get_pspec_from_funcname (const gchar *funcname); - -gboolean glade_util_ui_message (GtkWidget *parent, - GladeUIMessageType type, - const gchar *format, ...); - -void glade_util_flash_message (GtkWidget *statusbar, - guint context_id, - gchar *format, ...); - -/* This is a GCompareFunc for comparing the labels of 2 stock items, ignoring - any '_' characters. It isn't particularly efficient. */ - -gint glade_util_compare_stock_labels (gconstpointer a, gconstpointer b); - - -void glade_util_hide_window (GtkWindow *window); - -gchar *glade_util_gtk_combo_func (gpointer data); - -gpointer glade_util_gtk_combo_find (GtkCombo *combo); - - -GtkWidget *glade_util_file_dialog_new (const gchar *title, - GtkWindow *parent, - GladeUtilFileDialogType action); - -void glade_util_replace (gchar *str, gchar a, gchar b); - -gchar *glade_util_read_prop_name (const gchar *str); - -gchar *glade_util_duplicate_underscores (const gchar *name); - - -void glade_util_add_selection (GtkWidget *widget); - -void glade_util_remove_selection (GtkWidget *widget); - -gboolean glade_util_has_selection (GtkWidget *widget); - -void glade_util_clear_selection (void); - -GList *glade_util_get_selection (void); - - -void glade_util_queue_draw_nodes (GdkWindow *window); - - -GList *glade_util_container_get_all_children (GtkContainer *container); - - -gint glade_util_count_placeholders (GladeWidget *parent); - - -GtkTreeIter *glade_util_find_iter_by_widget (GtkTreeModel *model, - GladeWidget *findme, - gint column); - - -gboolean glade_util_basenames_match (const gchar *path1, - const gchar *path2); - - -GList *glade_util_purify_list (GList *list); - -GList *glade_util_added_in_list (GList *old_list, - GList *new_list); - -GList *glade_util_removed_from_list (GList *old_list, - GList *new_list); - -gchar *glade_util_canonical_path (const gchar *path); - - -gboolean glade_util_copy_file (const gchar *src_path, - const gchar *dest_path); - -gboolean glade_util_class_implements_interface (GType class_type, - GType iface_type); - - -GModule *glade_util_load_library (const gchar *library_name); - - -gboolean glade_util_file_is_writeable (const gchar *path); - - -gboolean glade_util_have_devhelp (void); - -GtkWidget *glade_util_get_devhelp_icon (GtkIconSize size); - -void glade_util_search_devhelp (const gchar *book, - const gchar *page, - const gchar *search); - -GtkWidget *glade_util_get_placeholder_from_pointer (GtkContainer *container); - - -gboolean glade_util_object_is_loading (GObject *object); - - -gboolean glade_util_url_show (const gchar *url); - - -time_t glade_util_get_file_mtime (const gchar *filename, GError **error); - -G_END_DECLS - -#endif /* __GLADE_UTILS_H__ */ diff --git a/gladeui/glade-widget-action.c b/gladeui/glade-widget-action.c deleted file mode 100644 index a041e2a5..00000000 --- a/gladeui/glade-widget-action.c +++ /dev/null @@ -1,261 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2007 Juan Pablo Ugarte. - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Authors: - * Juan Pablo Ugarte <juanpablougarte@gmail.com> - */ - -#include "glade-widget-action.h" -#include "config.h" -#include <glib/gi18n-lib.h> - -enum -{ - PROP_0, - - PROP_CLASS, - PROP_SENSITIVE -}; - -G_DEFINE_TYPE (GladeWidgetAction, glade_widget_action, G_TYPE_OBJECT); - -static void -glade_widget_action_init (GladeWidgetAction *object) -{ - object->sensitive = TRUE; - object->actions = NULL; -} - -static void -glade_widget_action_finalize (GObject *object) -{ - GladeWidgetAction *action = GLADE_WIDGET_ACTION (object); - - if (action->actions) - { - g_list_foreach (action->actions, (GFunc)g_object_unref, NULL); - g_list_free (action->actions); - } - - G_OBJECT_CLASS (glade_widget_action_parent_class)->finalize (object); -} - -static GObject * -glade_widget_action_constructor(GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties) -{ - GladeWidgetAction *action; - GObject *object; - GList *l; - - object = G_OBJECT_CLASS (glade_widget_action_parent_class)->constructor - (type, n_construct_properties, construct_properties); - - action = GLADE_WIDGET_ACTION (object); - - if (action->klass == NULL) - { - g_warning ("GladeWidgetAction constructed without class property"); - return object; - } - - for (l = action->klass->actions; l; l = g_list_next (l)) - { - GWActionClass *action_class = l->data; - GObject *obj = g_object_new (GLADE_TYPE_WIDGET_ACTION, - "class", action_class, - NULL); - - action->actions = g_list_prepend (action->actions, - GLADE_WIDGET_ACTION (obj)); - } - - action->actions = g_list_reverse (action->actions); - - return object; -} - -static void -glade_widget_action_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) -{ - GladeWidgetAction *action = GLADE_WIDGET_ACTION (object); - - g_return_if_fail (GLADE_IS_WIDGET_ACTION (object)); - - switch (prop_id) - { - case PROP_CLASS: - action->klass = g_value_get_pointer (value); - break; - case PROP_SENSITIVE: - glade_widget_action_set_sensitive (action, - g_value_get_boolean (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -glade_widget_action_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) -{ - GladeWidgetAction *action = GLADE_WIDGET_ACTION (object); - - g_return_if_fail (GLADE_IS_WIDGET_ACTION (object)); - - switch (prop_id) - { - case PROP_CLASS: - g_value_set_pointer (value, action->klass); - break; - case PROP_SENSITIVE: - g_value_set_boolean (value, action->sensitive); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -glade_widget_action_class_init (GladeWidgetActionClass *klass) -{ - GObjectClass* object_class = G_OBJECT_CLASS (klass); - glade_widget_action_parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass)); - - object_class->constructor = glade_widget_action_constructor; - object_class->finalize = glade_widget_action_finalize; - object_class->set_property = glade_widget_action_set_property; - object_class->get_property = glade_widget_action_get_property; - - g_object_class_install_property (object_class, - PROP_CLASS, - g_param_spec_pointer ("class", - _("class"), - _("GladeWidgetActionClass structure pointer"), - G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE)); - - g_object_class_install_property (object_class, - PROP_SENSITIVE, - g_param_spec_boolean ("sensitive", - _("Sensitive"), - _("Wheater or not this action is sensitive"), - TRUE, - G_PARAM_READWRITE)); - -} - -/** - * glade_widegt_action_class_free: - * @action: a GWActionClass - * - * Frees a GWActionClass. - */ -void -glade_widget_action_class_free (GWActionClass *action) -{ - if (action->actions) - g_list_foreach (action->actions, (GFunc)glade_widget_action_class_free, NULL); - - /*Dont free id since it points to path*/ - g_free (action->path); - g_free (action->label); - g_free (action->stock); - g_free (action); -} - -/** - * glade_widget_action_class_clone: - * @action: a GWActionClass - * - * Returns: a newlly allocated copy of @action. - */ -GWActionClass * -glade_widget_action_class_clone (GWActionClass *action) -{ - GWActionClass *copy; - GList *l; - - g_return_val_if_fail (action != NULL, NULL); - - copy = g_new0 (GWActionClass, 1); - copy->path = g_strdup (action->path); - copy->label = g_strdup (action->label); - copy->stock = g_strdup (action->stock); - copy->important = action->important; - - /* id points to path! */ - copy->id = copy->path + (action->id - action->path); - - for (l = action->actions; l; l = g_list_next (l)) - { - GWActionClass *child = glade_widget_action_class_clone (l->data); - copy->actions = g_list_prepend (copy->actions, child); - } - - copy->actions = g_list_reverse (copy->actions); - - return copy; -} - -/** - * glade_widget_action_remove: - * @action: a #GladeWidgetAction - * @child: a #GladeWidgetAction - * - * Remove an action. - * - * Returns: whether or not @child was removed from @action. - */ -gboolean -glade_widget_action_remove (GladeWidgetAction *action, - GladeWidgetAction *child) -{ - GList *l; - - g_return_val_if_fail (GLADE_IS_WIDGET_ACTION (action), FALSE); - g_return_val_if_fail (GLADE_IS_WIDGET_ACTION (child), FALSE); - - for (l = action->actions; l; l = g_list_next (l)) - { - if (child == l->data) - { - action->actions = g_list_remove (action->actions, child); - return TRUE; - } - } - return FALSE; -} - -/** - * glade_widget_action_set_sensitive: - * @action: a #GladeWidgetAction - * @sensitive: - * - * Set whether or not this action is sensitive. - * - */ -void -glade_widget_action_set_sensitive (GladeWidgetAction *action, gboolean sensitive) -{ - g_return_if_fail (GLADE_IS_WIDGET_ACTION (action)); - action->sensitive = sensitive; - g_object_notify (G_OBJECT (action), "sensitive"); -} diff --git a/gladeui/glade-widget-action.h b/gladeui/glade-widget-action.h deleted file mode 100644 index 7cb66606..00000000 --- a/gladeui/glade-widget-action.h +++ /dev/null @@ -1,82 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2007 Juan Pablo Ugarte. - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Authors: - * Juan Pablo Ugarte <juanpablougarte@gmail.com> - */ - -#ifndef _GLADE_WIDGET_ACTION_H_ -#define _GLADE_WIDGET_ACTION_H_ - -#include <glib-object.h> - -G_BEGIN_DECLS - -#define GLADE_TYPE_WIDGET_ACTION (glade_widget_action_get_type ()) -#define GLADE_WIDGET_ACTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_WIDGET_ACTION, GladeWidgetAction)) -#define GLADE_WIDGET_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_WIDGET_ACTION, GladeWidgetActionClass)) -#define GLADE_IS_WIDGET_ACTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_WIDGET_ACTION)) -#define GLADE_IS_WIDGET_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_WIDGET_ACTION)) -#define GLADE_WIDGET_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GLADE_TYPE_WIDGET_ACTION, GladeWidgetActionClass)) - -typedef struct _GladeWidgetActionClass GladeWidgetActionClass; -typedef struct _GladeWidgetAction GladeWidgetAction; -typedef struct _GWActionClass GWActionClass; - -struct _GWActionClass -{ - gchar *id; /* The identifier of this action in the action tree */ - gchar *path; /* Full action path */ - gchar *label; /* A translated label to show in the UI for this action */ - gchar *stock; /* If set, this stock item will be shown in the UI along side - * the label */ - gboolean important; /* If this action is important */ - - GList *actions; /* Recursive list of child actions */ -}; - -struct _GladeWidgetActionClass -{ - GObjectClass parent_class; -}; - -struct _GladeWidgetAction -{ - GObject parent_instance; - - GWActionClass *klass; /* The action class */ - - gboolean sensitive; /* If this action is sensitive or not */ - - GList *actions; /* List of actions */ -}; - -GType glade_widget_action_get_type (void) G_GNUC_CONST; - -void glade_widget_action_class_free (GWActionClass *action); - -GWActionClass *glade_widget_action_class_clone (GWActionClass *action); - -gboolean glade_widget_action_remove (GladeWidgetAction *action, - GladeWidgetAction *child); - -void glade_widget_action_set_sensitive (GladeWidgetAction *action, - gboolean sensitive); -G_END_DECLS - -#endif /* _GLADE_WIDGET_ACTION_H_ */ diff --git a/gladeui/glade-widget-adaptor.c b/gladeui/glade-widget-adaptor.c deleted file mode 100644 index d44a5f1a..00000000 --- a/gladeui/glade-widget-adaptor.c +++ /dev/null @@ -1,2679 +0,0 @@ -/* -*- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Authors: - * Tristan Van Berkom <tvb@gnome.org> - */ - -#include <config.h> - -#include "glade.h" -#include "glade-widget-adaptor.h" -#include "glade-xml-utils.h" -#include "glade-property-class.h" -#include "glade-signal.h" -#include "glade-marshallers.h" -#include "glade-accumulators.h" - -/* For g_file_exists */ -#include <sys/types.h> -#include <string.h> - -#include <glib/gdir.h> -#include <glib/gi18n-lib.h> -#include <gmodule.h> -#include <ctype.h> - -#define DEFAULT_ICON_NAME "widget-gtk-frame" - -#define GLADE_WIDGET_ADAPTOR_GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((o), GLADE_TYPE_WIDGET_ADAPTOR, GladeWidgetAdaptorPrivate)) - -struct _GladeWidgetAdaptorPrivate { - - gchar *catalog; /* The name of the widget catalog this class - * was declared by. - */ - - gchar *book; /* DevHelp search namespace for this widget class - */ - - GdkCursor *cursor; /* a cursor for inserting widgets */ - - gchar *special_child_type; /* Special case code for children that - * are special children (like notebook tab - * widgets for example). - */ -}; - -struct _GladeChildPacking { - gchar *parent_name; - GList *packing_defaults; -}; - -enum { - PROP_0, - PROP_NAME, - PROP_TYPE, - PROP_TITLE, - PROP_GENERIC_NAME, - PROP_ICON_NAME, - PROP_CATALOG, - PROP_BOOK, - PROP_SPECIAL_TYPE, - PROP_CURSOR -}; - -typedef struct _GladeChildPacking GladeChildPacking; - -static GObjectClass *parent_class = NULL; -static GHashTable *adaptor_hash = NULL; - -/******************************************************************************* - Helper functions - *******************************************************************************/ -static GladeWidgetAdaptor * -gwa_get_parent_adaptor (GladeWidgetAdaptor *adaptor) -{ - GladeWidgetAdaptor *parent_adaptor = NULL; - GType iter_type; - - for (iter_type = g_type_parent (adaptor->type); - iter_type > 0; - iter_type = g_type_parent (iter_type)) - { - if ((parent_adaptor = - glade_widget_adaptor_get_by_type (iter_type)) != NULL) - return parent_adaptor; - } - - return NULL; -} - -/* - This function assignes "weight" to each property in its natural order staring from 1. - If parent is 0 weight will be set for every GladePropertyClass in the list. - This function will not override weight if it is already set (weight >= 0.0) -*/ -static void -gwa_properties_set_weight (GList **properties, GType parent) -{ - gint normal = 0, common = 0, packing = 0; - GList *l; - - for (l = *properties; l && l->data; l = g_list_next (l)) - { - GladePropertyClass *klass = l->data; - GPCType type = klass->type; - - if (klass->visible && - (parent) ? parent == klass->pspec->owner_type : TRUE && - (type == GPC_NORMAL || type == GPC_ACCEL_PROPERTY)) - { - /* Use a different counter for each tab (common, packing and normal) */ - if (klass->common) common++; - else if (klass->packing) packing++; - else normal++; - - /* Skip if it is already set */ - if (klass->weight >= 0.0) continue; - - /* Special-casing weight of properties for seperate tabs */ - if (klass->common) klass->weight = common; - else if (klass->packing) klass->weight = packing; - else klass->weight = normal; - } - } -} - -static void -gwa_create_cursor (GladeWidgetAdaptor *adaptor) -{ - GdkPixbuf *tmp_pixbuf, *widget_pixbuf; - const GdkPixbuf *add_pixbuf; - GdkDisplay *display; - GError *error = NULL; - - /* only certain widget classes need to have cursors */ - if (G_TYPE_IS_INSTANTIATABLE (adaptor->type) == FALSE || - G_TYPE_IS_ABSTRACT (adaptor->type) != FALSE || - adaptor->generic_name == NULL) - return; - - /* cannot continue if 'add widget' cursor pixbuf has not been loaded for any reason */ - if ((add_pixbuf = glade_cursor_get_add_widget_pixbuf ()) == NULL) - return; - - display = gdk_display_get_default (); - - /* create a temporary pixbuf clear to transparent black*/ - tmp_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, 32, 32); - gdk_pixbuf_fill (tmp_pixbuf, 0x00000000); - - if (gtk_icon_theme_has_icon (gtk_icon_theme_get_default (), adaptor->icon_name)) - { - widget_pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), - adaptor->icon_name, - 22, - 0, - &error); - - if (error) { - g_warning ("Could not load image data for named icon '%s': %s", - adaptor->icon_name, - error->message); - g_error_free (error); - return; - } - - } else { - return; - } - - /* composite pixbufs */ - gdk_pixbuf_composite (widget_pixbuf, tmp_pixbuf, - 8, 8, 22, 22, - 8, 8, 1, 1, - GDK_INTERP_NEAREST, 255); - - gdk_pixbuf_composite (add_pixbuf, tmp_pixbuf, - 0, 0, 12, 12, - 0, 0, 1, 1, - GDK_INTERP_NEAREST, 255); - - - adaptor->priv->cursor = gdk_cursor_new_from_pixbuf (display, tmp_pixbuf, 6, 6); - - g_object_unref (tmp_pixbuf); - g_object_unref (widget_pixbuf); -} - - - -static gboolean -gwa_gtype_equal (gconstpointer v1, - gconstpointer v2) -{ - return *((const GType*) v1) == *((const GType*) v2); -} - -static guint -gwa_gtype_hash (gconstpointer v) -{ - return *(const GType*) v; -} - -static gboolean -glade_widget_adaptor_hash_find (gpointer key, gpointer value, gpointer user_data) -{ - GladeWidgetAdaptor *adaptor = value; - GType *type = user_data; - - if (g_type_is_a (adaptor->type, *type)) - { - *type = adaptor->type; - return TRUE; - } - - return FALSE; -} - -static void -glade_abort_if_derived_adaptors_exist (GType type) -{ - if (adaptor_hash) - { - GType retval = type; - - g_hash_table_find (adaptor_hash, - glade_widget_adaptor_hash_find, - &retval); - if (retval != type) - g_error (_("A derived adaptor (%s) of %s already exist!"), - g_type_name (retval), g_type_name (type)); - } -} - -/******************************************************************************* - Base Object Implementation detail - *******************************************************************************/ -static gint -gwa_signal_comp (gconstpointer a, gconstpointer b) -{ - const GladeSignalClass *signal_a = a, *signal_b = b; - return strcmp (signal_b->query.signal_name, signal_a->query.signal_name); -} - -static void -gwa_add_signals (GList **signals, GType type) -{ - guint count, *sig_ids, num_signals; - GladeSignalClass *cur; - GList *list = NULL; - - if (G_TYPE_IS_INSTANTIATABLE (type) || G_TYPE_IS_INTERFACE (type)) - { - sig_ids = g_signal_list_ids (type, &num_signals); - - for (count = 0; count < num_signals; count++) - { - cur = g_new0 (GladeSignalClass, 1); - - g_signal_query (sig_ids[count], &(cur->query)); - - /* Since glib gave us this signal id... it should - * exist no matter what. - */ - g_assert (cur->query.signal_id != 0); - - cur->name = (cur->query.signal_name); - cur->type = (gchar *) g_type_name (type); - - list = g_list_prepend (list, cur); - } - g_free (sig_ids); - - list = g_list_sort (list, gwa_signal_comp); - *signals = g_list_concat (list, *signals); - } -} - -static GList * -gwa_list_signals (GladeWidgetAdaptor *adaptor) -{ - GList *signals = NULL; - GType type, parent, *i, *p; - - g_return_val_if_fail (adaptor->type != 0, NULL); - - for (type = adaptor->type; g_type_is_a (type, G_TYPE_OBJECT); type = parent) - { - parent = g_type_parent (type); - - /* Add class signals */ - gwa_add_signals (&signals, type); - - /* Add class interfaces signals */ - for (i = p = g_type_interfaces (type, NULL); *i; i++) - if (!glade_util_class_implements_interface (parent, *i)) - gwa_add_signals (&signals, *i); - - g_free (p); - } - - return g_list_reverse (signals); -} - -static GList * -gwa_clone_parent_properties (GladeWidgetAdaptor *adaptor, gboolean is_packing) -{ - GladeWidgetAdaptor *parent_adaptor; - GList *properties = NULL, *list, *proplist; - - if ((parent_adaptor = gwa_get_parent_adaptor (adaptor)) != NULL) - { - proplist = is_packing ? - parent_adaptor->packing_props : - parent_adaptor->properties; - - for (list = proplist; list; list = list->next) - { - GladePropertyClass *pclass = - glade_property_class_clone (list->data); - pclass->handle = adaptor; - properties = g_list_prepend (properties, pclass); - } - } - - return g_list_reverse (properties); -} - -static void -gwa_setup_introspected_props_from_pspecs (GladeWidgetAdaptor *adaptor, - GParamSpec **specs, - gint n_specs, - gboolean is_packing) -{ - GladeWidgetAdaptor *parent_adaptor = gwa_get_parent_adaptor (adaptor); - GladePropertyClass *property_class; - GType class_type; - gint i; - GList *list = NULL; - - for (i = 0; i < n_specs; i++) - { - gboolean found; - - /* Only create properties that dont exist on the adaptor yet */ - for (found = FALSE, class_type = adaptor->type; - ((!parent_adaptor && class_type != 0) || - ( parent_adaptor && class_type != parent_adaptor->type)); - class_type = g_type_parent (class_type)) - if (specs[i]->owner_type == class_type || - (G_TYPE_IS_INTERFACE (specs[i]->owner_type) && - glade_util_class_implements_interface (class_type, specs[i]->owner_type))) - { - found = TRUE; - break; - } - - if (found && - (property_class = - glade_property_class_new_from_spec (adaptor, specs[i])) != NULL) - list = g_list_prepend (list, property_class); - } - - if (is_packing) - adaptor->packing_props = - g_list_concat (adaptor->packing_props, - g_list_reverse (list)); - else - adaptor->properties = - g_list_concat (adaptor->properties, - g_list_reverse (list)); -} - -/* XXX Atk relations and accel props disregarded - they should - * be implemented from the gtk+ catalog instead I think. - */ -static void -gwa_setup_properties (GladeWidgetAdaptor *adaptor, - GObjectClass *object_class, - gboolean is_packing) -{ - GParamSpec **specs = NULL; - guint n_specs = 0; - GList *l; - - /* only GtkContainer child propeties can be introspected */ - if (is_packing && !g_type_is_a (adaptor->type, GTK_TYPE_CONTAINER)) - return; - - /* First clone the parents properties */ - if (is_packing) - adaptor->packing_props = gwa_clone_parent_properties (adaptor, is_packing); - else - adaptor->properties = gwa_clone_parent_properties (adaptor, is_packing); - - /* Now automaticly introspect new properties added in this class, - * allow the class writer to decide what to override in the resulting - * list of properties. - */ - if (is_packing) - specs = gtk_container_class_list_child_properties (object_class, &n_specs); - else - specs = g_object_class_list_properties (object_class, &n_specs); - gwa_setup_introspected_props_from_pspecs (adaptor, specs, n_specs, is_packing); - g_free (specs); - - if (is_packing) - { - /* We have to mark packing properties from GladeWidgetAdaptor - * because GladePropertyClass doesnt have a valid parent GType - * to introspect it. - * - * (which could be used to call gtk_container_class_find_child_property() - * and properly introspect whether or not its a packing property). - */ - for (l = adaptor->packing_props; l; l = l->next) - { - GladePropertyClass *property_class = l->data; - property_class->packing = TRUE; - } - } -} - -static GList * -gwa_inherit_child_packing (GladeWidgetAdaptor *adaptor) -{ - GladeWidgetAdaptor *parent_adaptor; - GList *child_packings = NULL, *packing_list, *default_list; - - if ((parent_adaptor = gwa_get_parent_adaptor (adaptor)) != NULL) - { - for (packing_list = parent_adaptor->child_packings; - packing_list; packing_list = packing_list->next) - { - GladeChildPacking *packing = packing_list->data; - GladeChildPacking *packing_dup = g_new0 (GladeChildPacking, 1); - - packing_dup->parent_name = g_strdup (packing->parent_name); - - for (default_list = packing->packing_defaults; - default_list; default_list = default_list->next) - { - GladePackingDefault *def = default_list->data; - GladePackingDefault *def_dup = g_new0 (GladePackingDefault, 1); - - def_dup->id = g_strdup (def->id); - def_dup->value = g_strdup (def->value); - - packing_dup->packing_defaults = - g_list_prepend (packing_dup->packing_defaults, def_dup); - } - - child_packings = g_list_prepend (child_packings, packing_dup); - } - } - return child_packings; -} - -static GObject * -glade_widget_adaptor_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties) -{ - GladeWidgetAdaptor *adaptor, *parent_adaptor; - GObject *ret_obj; - GObjectClass *object_class; - - glade_abort_if_derived_adaptors_exist (type); - - ret_obj = G_OBJECT_CLASS (parent_class)->constructor - (type, n_construct_properties, construct_properties); - - adaptor = GLADE_WIDGET_ADAPTOR (ret_obj); - parent_adaptor = gwa_get_parent_adaptor (adaptor); - - if (adaptor->type == G_TYPE_NONE) - g_warning ("Adaptor created without a type"); - if (adaptor->name == NULL) - g_warning ("Adaptor created without a name"); - - /* Build decorations */ - if (!adaptor->icon_name) { - adaptor->icon_name = g_strdup ("gtk-missing-image"); - } - gwa_create_cursor (adaptor); - - /* Let it leek */ - if ((object_class = g_type_class_ref (adaptor->type))) - { - /* Build signals & properties */ - adaptor->signals = gwa_list_signals (adaptor); - gwa_setup_properties (adaptor, object_class, FALSE); - gwa_setup_properties (adaptor, object_class, TRUE); - } - else - g_critical ("Failed to get class for type %s\n", - g_type_name (adaptor->type)); - - /* Inherit packing defaults here */ - adaptor->child_packings = gwa_inherit_child_packing (adaptor); - - /* Inherit special-child-type */ - if (parent_adaptor) - adaptor->priv->special_child_type = - parent_adaptor->priv->special_child_type ? - g_strdup (parent_adaptor->priv->special_child_type) : NULL; - - /* Copy parent actions */ - if (parent_adaptor) - { - GList *l; - - if (parent_adaptor->actions) - { - for (l = parent_adaptor->actions; l; l = g_list_next (l)) - { - GWActionClass *child = glade_widget_action_class_clone (l->data); - adaptor->actions = g_list_prepend (adaptor->actions, child); - } - adaptor->actions = g_list_reverse (adaptor->actions); - } - - if (parent_adaptor->packing_actions) - { - for (l = parent_adaptor->packing_actions; l; l = g_list_next (l)) - { - GWActionClass *child = glade_widget_action_class_clone (l->data); - adaptor->packing_actions = g_list_prepend (adaptor->packing_actions, child); - } - adaptor->packing_actions = g_list_reverse (adaptor->packing_actions); - } - } - - return ret_obj; -} - -static void -gwa_packing_default_free (GladePackingDefault *def) -{ - g_free (def->id); - g_free (def->value); -} - -static void -gwa_child_packing_free (GladeChildPacking *packing) -{ - g_free (packing->parent_name); - - g_list_foreach (packing->packing_defaults, - (GFunc) gwa_packing_default_free, NULL); - g_list_free (packing->packing_defaults); -} - -static void -glade_widget_adaptor_finalize (GObject *object) -{ - GladeWidgetAdaptor *adaptor = GLADE_WIDGET_ADAPTOR (object); - - /* Free properties and signals */ - g_list_foreach (adaptor->properties, (GFunc) glade_property_class_free, NULL); - g_list_free (adaptor->properties); - - g_list_foreach (adaptor->packing_props, (GFunc) glade_property_class_free, NULL); - g_list_free (adaptor->packing_props); - - g_list_foreach (adaptor->signals, (GFunc) glade_signal_free, NULL); - g_list_free (adaptor->signals); - - - /* Free child packings */ - g_list_foreach (adaptor->child_packings, - (GFunc) gwa_child_packing_free, - NULL); - g_list_free (adaptor->child_packings); - - if (adaptor->priv->book) g_free (adaptor->priv->book); - if (adaptor->priv->catalog) g_free (adaptor->priv->catalog); - if (adaptor->priv->special_child_type) - g_free (adaptor->priv->special_child_type); - - if (adaptor->priv->cursor != NULL) - gdk_cursor_unref (adaptor->priv->cursor); - - if (adaptor->name) g_free (adaptor->name); - if (adaptor->generic_name) g_free (adaptor->generic_name); - if (adaptor->title) g_free (adaptor->title); - if (adaptor->icon_name) g_free (adaptor->icon_name); - - if (adaptor->actions) - { - g_list_foreach (adaptor->actions, - (GFunc) glade_widget_action_class_free, - NULL); - g_list_free (adaptor->actions); - } - - if (adaptor->packing_actions) - { - g_list_foreach (adaptor->packing_actions, - (GFunc) glade_widget_action_class_free, - NULL); - g_list_free (adaptor->packing_actions); - } - - g_free (adaptor->priv); - - G_OBJECT_CLASS (parent_class)->finalize (object); -} - -static void -glade_widget_adaptor_real_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - GladeWidgetAdaptor *adaptor; - - adaptor = GLADE_WIDGET_ADAPTOR (object); - - switch (prop_id) - { - case PROP_NAME: - /* assume once (construct-only) */ - adaptor->name = g_value_dup_string (value); - break; - case PROP_ICON_NAME: - /* assume once (construct-only) */ - adaptor->icon_name = g_value_dup_string (value); - break; - case PROP_TYPE: - adaptor->type = g_value_get_gtype (value); - break; - case PROP_TITLE: - if (adaptor->title) g_free (adaptor->title); - adaptor->title = g_value_dup_string (value); - break; - case PROP_GENERIC_NAME: - if (adaptor->generic_name) g_free (adaptor->generic_name); - adaptor->generic_name = g_value_dup_string (value); - break; - case PROP_CATALOG: - /* assume once (construct-only) */ - adaptor->priv->catalog = g_value_dup_string (value); - break; - case PROP_BOOK: - /* assume once (construct-only) */ - adaptor->priv->book = g_value_dup_string (value); - break; - case PROP_SPECIAL_TYPE: - /* assume once (construct-only) */ - adaptor->priv->special_child_type = g_value_dup_string (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -glade_widget_adaptor_real_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - - GladeWidgetAdaptor *adaptor; - - adaptor = GLADE_WIDGET_ADAPTOR (object); - - switch (prop_id) - { - case PROP_NAME: g_value_set_string (value, adaptor->name); break; - case PROP_TYPE: g_value_set_gtype (value, adaptor->type); break; - case PROP_TITLE: g_value_set_string (value, adaptor->title); break; - case PROP_GENERIC_NAME: g_value_set_string (value, adaptor->generic_name); break; - case PROP_ICON_NAME: g_value_set_string (value, adaptor->icon_name); break; - case PROP_CATALOG: g_value_set_string (value, adaptor->priv->catalog); break; - case PROP_BOOK: g_value_set_string (value, adaptor->priv->book); break; - case PROP_SPECIAL_TYPE: - g_value_set_string (value, adaptor->priv->special_child_type); - break; - case PROP_CURSOR: g_value_set_pointer (value, adaptor->priv->cursor); break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -/******************************************************************************* - GladeWidgetAdaptor base class implementations - *******************************************************************************/ -static void -glade_widget_adaptor_object_set_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *property_name, - const GValue *value) -{ - g_object_set_property (object, property_name, value); -} - -static void -glade_widget_adaptor_object_get_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *property_name, - GValue *value) -{ - g_object_get_property (object, property_name, value); -} - -static void -glade_widget_adaptor_object_action_activate (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *action_id) -{ - g_message ("No action_activate() support in adaptor %s for action '%s'", - adaptor->name, action_id); -} - -static void -glade_widget_adaptor_object_child_action_activate (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *object, - const gchar *action_id) -{ - g_message ("No child_action_activate() support in adaptor %s for action '%s'", - adaptor->name, action_id); -} - -/******************************************************************************* - GladeWidgetAdaptor type registration and class initializer - *******************************************************************************/ -static void -glade_widget_adaptor_init (GladeWidgetAdaptor *adaptor) -{ - adaptor->priv = GLADE_WIDGET_ADAPTOR_GET_PRIVATE (adaptor); -} - -static void -glade_widget_adaptor_class_init (GladeWidgetAdaptorClass *adaptor_class) -{ - GObjectClass *object_class; - g_return_if_fail (adaptor_class != NULL); - - parent_class = g_type_class_peek_parent (adaptor_class); - object_class = G_OBJECT_CLASS (adaptor_class); - - /* GObjectClass */ - object_class->constructor = glade_widget_adaptor_constructor; - object_class->finalize = glade_widget_adaptor_finalize; - object_class->set_property = glade_widget_adaptor_real_set_property; - object_class->get_property = glade_widget_adaptor_real_get_property; - - /* Class methods */ - adaptor_class->post_create = NULL; - adaptor_class->get_internal_child = NULL; - adaptor_class->verify_property = NULL; - adaptor_class->set_property = glade_widget_adaptor_object_set_property; - adaptor_class->get_property = glade_widget_adaptor_object_get_property; - adaptor_class->add = NULL; - adaptor_class->remove = NULL; - adaptor_class->replace_child = NULL; - adaptor_class->get_children = NULL; - adaptor_class->child_set_property = NULL; - adaptor_class->child_get_property = NULL; - adaptor_class->action_activate = glade_widget_adaptor_object_action_activate; - adaptor_class->child_action_activate= glade_widget_adaptor_object_child_action_activate; - - /* Base defaults here */ - adaptor_class->fixed = FALSE; - adaptor_class->toplevel = FALSE; - adaptor_class->use_placeholders = FALSE; - adaptor_class->default_width = -1; - adaptor_class->default_height = -1; - - /* Properties */ - g_object_class_install_property - (object_class, PROP_NAME, - g_param_spec_string - ("name", _("Name"), - _("Name of the class"), - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - - g_object_class_install_property - (object_class, PROP_TYPE, - g_param_spec_gtype - ("type", _("Type"), - _("GType of the class"), - G_TYPE_NONE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - - g_object_class_install_property - (object_class, PROP_TITLE, - g_param_spec_string - ("title", _("Title"), - _("Translated title for the class used in the glade UI"), - NULL, - G_PARAM_READWRITE)); - - g_object_class_install_property - (object_class, PROP_GENERIC_NAME, - g_param_spec_string - ("generic-name", _("Generic Name"), - _("Used to generate names of new widgets"), - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - - g_object_class_install_property - (object_class, PROP_ICON_NAME, - g_param_spec_string - ("icon-name", _("Icon Name"), - _("The icon name"), - DEFAULT_ICON_NAME, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - - g_object_class_install_property - (object_class, PROP_CATALOG, - g_param_spec_string - ("catalog", _("Catalog"), - _("The name of the widget catalog this class was declared by"), - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - - g_object_class_install_property - (object_class, PROP_BOOK, - g_param_spec_string - ("book", _("Book"), - _("DevHelp search namespace for this widget class"), - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - - g_object_class_install_property - (object_class, PROP_SPECIAL_TYPE, - g_param_spec_string - ("special-child-type", _("Special Child Type"), - _("Holds the name of the packing property to depict " - "special children for this container class"), - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - - g_object_class_install_property - (object_class, PROP_CURSOR, - g_param_spec_pointer - ("cursor", _("Cursor"), - _("A cursor for inserting widgets in the UI"), - G_PARAM_READABLE)); - - g_type_class_add_private (adaptor_class, sizeof (GladeWidgetAdaptorPrivate)); -} - -GType -glade_widget_adaptor_get_type (void) -{ - static GType adaptor_type = 0; - - if (!adaptor_type) - { - static const GTypeInfo adaptor_info = - { - sizeof (GladeWidgetAdaptorClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) glade_widget_adaptor_class_init, - (GClassFinalizeFunc) NULL, - NULL, /* class_data */ - sizeof (GladeWidgetAdaptor), - 0, /* n_preallocs */ - (GInstanceInitFunc) glade_widget_adaptor_init, - }; - adaptor_type = - g_type_register_static (G_TYPE_OBJECT, - "GladeGObjectAdaptor", - &adaptor_info, 0); - } - return adaptor_type; -} - -GType -glade_create_reason_get_type (void) -{ - static GType etype = 0; - - if (etype == 0) - { - static const GEnumValue values[] = { - { GLADE_CREATE_USER, "GLADE_CREATE_USER", "create-user" }, - { GLADE_CREATE_COPY, "GLADE_CREATE_COPY", "create-copy" }, - { GLADE_CREATE_LOAD, "GLADE_CREATE_LOAD", "create-load" }, - { GLADE_CREATE_REBUILD, "GLADE_CREATE_REBUILD", "create-rebuild" }, - { 0, NULL, NULL } - }; - - etype = g_enum_register_static ("GladeCreateReason", values); - - } - - return etype; -} - -/******************************************************************************* - Synthetic Object Derivation - *******************************************************************************/ -typedef struct -{ - GladeXmlNode *node; - GModule *module; -} GWADerivedClassData; - -static void -gwa_derived_init (GladeWidgetAdaptor *adaptor, gpointer g_class) -{ - -} - -static void -gwa_extend_with_node_load_sym (GladeWidgetAdaptorClass *klass, - GladeXmlNode *node, - GModule *module) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - gpointer symbol; - - /* - * We use a temporary variable to avoid a bogus gcc warning. - * the thing it that g_module_symbol() should use a function pointer - * instead of a gpointer! - */ - - if (glade_xml_load_sym_from_node (node, module, - GLADE_TAG_CONSTRUCTOR_FUNCTION, - &symbol)) - object_class->constructor = symbol; - - if (glade_xml_load_sym_from_node (node, module, - GLADE_TAG_POST_CREATE_FUNCTION, - &symbol)) - klass->post_create = symbol; - - if (glade_xml_load_sym_from_node (node, module, - GLADE_TAG_GET_INTERNAL_CHILD_FUNCTION, - &symbol)) - klass->get_internal_child = symbol; - - if (glade_xml_load_sym_from_node (node, module, - GLADE_TAG_SET_FUNCTION, - &symbol)) - klass->set_property = symbol; - - if (glade_xml_load_sym_from_node (node, module, - GLADE_TAG_GET_FUNCTION, - &symbol)) - klass->get_property = symbol; - - if (glade_xml_load_sym_from_node (node, module, - GLADE_TAG_VERIFY_FUNCTION, - &symbol)) - klass->verify_property = symbol; - - if (glade_xml_load_sym_from_node (node, module, - GLADE_TAG_ADD_CHILD_FUNCTION, - &symbol)) - klass->add = symbol; - - if (glade_xml_load_sym_from_node (node, module, - GLADE_TAG_REMOVE_CHILD_FUNCTION, - &symbol)) - klass->remove = symbol; - - if (glade_xml_load_sym_from_node (node, module, - GLADE_TAG_GET_CHILDREN_FUNCTION, - &symbol)) - klass->get_children = symbol; - - if (glade_xml_load_sym_from_node (node, module, - GLADE_TAG_CHILD_SET_PROP_FUNCTION, - &symbol)) - klass->child_set_property = symbol; - - if (glade_xml_load_sym_from_node (node, module, - GLADE_TAG_CHILD_GET_PROP_FUNCTION, - &symbol)) - klass->child_get_property = symbol; - - if (glade_xml_load_sym_from_node (node, module, - GLADE_TAG_CHILD_VERIFY_FUNCTION, - &symbol)) - klass->child_verify_property = symbol; - - if (glade_xml_load_sym_from_node (node, module, - GLADE_TAG_REPLACE_CHILD_FUNCTION, - &symbol)) - klass->replace_child = symbol; - - if (glade_xml_load_sym_from_node (node, module, - GLADE_TAG_ACTION_ACTIVATE_FUNCTION, - &symbol)) - klass->action_activate = symbol; - - if (glade_xml_load_sym_from_node (node, module, - GLADE_TAG_CHILD_ACTION_ACTIVATE_FUNCTION, - &symbol)) - klass->child_action_activate = symbol; -} - -static void -gwa_derived_class_init (GladeWidgetAdaptorClass *adaptor_class, - GWADerivedClassData *data) -{ - GladeXmlNode *node = data->node; - GModule *module = data->module; - - /* Load catalog symbols from module */ - if (module) gwa_extend_with_node_load_sym (adaptor_class, node, module); - - adaptor_class->fixed = - glade_xml_get_property_boolean - (node, GLADE_TAG_FIXED, adaptor_class->fixed); - - /* Check if this class is toplevel */ - adaptor_class->toplevel = - glade_xml_get_property_boolean - (node, GLADE_TAG_TOPLEVEL, adaptor_class->toplevel); - - /* Check if this class uses placeholders for child widgets */ - adaptor_class->use_placeholders = - glade_xml_get_property_boolean - (node, GLADE_TAG_USE_PLACEHOLDERS, adaptor_class->use_placeholders); - - /* Check default size when used as a toplevel in the GladeDesignView */ - adaptor_class->default_width = - glade_xml_get_property_int - (node, GLADE_TAG_DEFAULT_WIDTH, adaptor_class->default_width); - adaptor_class->default_height = - glade_xml_get_property_int - (node, GLADE_TAG_DEFAULT_HEIGHT, adaptor_class->default_height); -} - -static GType -gwa_derive_adaptor_for_type (GType object_type, GWADerivedClassData *data) -{ - GladeWidgetAdaptor *adaptor; - GType iter_type, derived_type; - GType parent_type = GLADE_TYPE_WIDGET_ADAPTOR; - gchar *type_name; - GTypeInfo adaptor_info = - { - sizeof (GladeWidgetAdaptorClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) gwa_derived_class_init, - (GClassFinalizeFunc) NULL, - data, /* class_data */ - sizeof (GladeWidgetAdaptor), - 0, /* n_preallocs */ - (GInstanceInitFunc) gwa_derived_init, - }; - - for (iter_type = g_type_parent (object_type); - iter_type > 0; - iter_type = g_type_parent (iter_type)) - { - if ((adaptor = - glade_widget_adaptor_get_by_type (iter_type)) != NULL) - { - parent_type = G_TYPE_FROM_INSTANCE (adaptor); - break; - } - } - - /* Note that we must pass ownership of the type_name string - * to the type system - */ - type_name = g_strdup_printf ("Glade%sAdaptor", g_type_name (object_type)); - derived_type = g_type_register_static (parent_type, type_name, - &adaptor_info, 0); - - return derived_type; -} - - -/******************************************************************************* - API - *******************************************************************************/ - -/** - * glade_widget_adaptor_register: - * @adaptor: A #GladeWidgetAdaptor - * - * Registers @adaptor into the Glade core (every supported - * object type must have a registered adaptor). - */ -void -glade_widget_adaptor_register (GladeWidgetAdaptor *adaptor) -{ - - g_return_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor)); - - if (glade_widget_adaptor_get_by_name (adaptor->name)) - { - g_warning ("Adaptor class for '%s' already registered", - adaptor->name); - return; - } - - if (!adaptor_hash) - adaptor_hash = g_hash_table_new_full (gwa_gtype_hash, gwa_gtype_equal, - g_free, g_object_unref); - - g_hash_table_insert (adaptor_hash, - g_memdup (&adaptor->type, - sizeof (GType)), adaptor); -} - -static GladePackingDefault * -gwa_default_from_child_packing (GladeChildPacking *packing, const gchar *id) -{ - GList *list; - - for (list = packing->packing_defaults; list; list = list->next) - { - GladePackingDefault *def = list->data; - - if (id && !strcmp (id, def->id)) - return def; - } - - return NULL; -} - -static GladeChildPacking * -glade_widget_adaptor_get_child_packing (GladeWidgetAdaptor *child_adaptor, - const gchar *parent_name) -{ - GList *l; - - for (l = child_adaptor->child_packings; l; l = l->next) - { - GladeChildPacking *packing; - - packing = (GladeChildPacking *) l->data; - - if (!strcmp (packing->parent_name, parent_name)) - return packing; - } - - return NULL; -} - -static void -gwa_set_packing_defaults_from_node (GladeWidgetAdaptor *adaptor, - GladeXmlNode *node) -{ - GladeXmlNode *child; - - for (child = glade_xml_node_get_children (node); - child; child = glade_xml_node_next (child)) - { - gchar *name; - GladeXmlNode *prop_node; - GladeChildPacking *packing; - - if (!glade_xml_node_verify (child, GLADE_TAG_PARENT_CLASS)) - continue; - - if ((name = glade_xml_get_property_string_required - (child, GLADE_TAG_NAME, adaptor->name)) == NULL) - continue; - - /* If a GladeChildPacking exists for this parent, use it - - * otherwise prepend a new one - */ - if ((packing = - glade_widget_adaptor_get_child_packing (adaptor, name)) == NULL) - { - - packing = g_new0 (GladeChildPacking, 1); - packing->parent_name = name; - - adaptor->child_packings = - g_list_prepend (adaptor->child_packings, packing); - - } - - for (prop_node = glade_xml_node_get_children (child); - prop_node; prop_node = glade_xml_node_next (prop_node)) - { - GladePackingDefault *def; - gchar *id; - gchar *value; - - if ((id = - glade_xml_get_property_string_required - (prop_node, GLADE_TAG_ID, adaptor->name)) == NULL) - continue; - - if ((value = - glade_xml_get_property_string_required - (prop_node, GLADE_TAG_DEFAULT, adaptor->name)) == NULL) - { - g_free (id); - continue; - } - - if ((def = gwa_default_from_child_packing (packing, id)) == NULL) - { - def = g_new0 (GladePackingDefault, 1); - def->id = id; - def->value = value; - - packing->packing_defaults = - g_list_prepend (packing->packing_defaults, def); - } - else - { - g_free (id); - g_free (def->value); - def->value = value; - } - - adaptor->child_packings = - g_list_prepend (adaptor->child_packings, packing); - - } - } -} - -static void -gwa_update_properties_from_node (GladeWidgetAdaptor *adaptor, - GladeXmlNode *node, - GModule *module, - GList **properties, - const gchar *domain, - gboolean is_packing) -{ - GladeXmlNode *child; - - for (child = glade_xml_node_get_children (node); - child; child = glade_xml_node_next (child)) - { - gchar *id; - GList *list; - GladePropertyClass *property_class; - gboolean updated; - - if (!glade_xml_node_verify (child, GLADE_TAG_PROPERTY)) - continue; - - id = glade_xml_get_property_string_required - (child, GLADE_TAG_ID, adaptor->name); - if (!id) - continue; - - /* property names from catalogs also need to have the '-' form */ - glade_util_replace (id, '_', '-'); - - /* find the property in our list, if not found append a new property */ - for (list = *properties; list && list->data; list = list->next) - { - property_class = GLADE_PROPERTY_CLASS (list->data); - if (property_class->id != NULL && - g_ascii_strcasecmp (id, property_class->id) == 0) - break; - } - - if (list) - { - property_class = GLADE_PROPERTY_CLASS (list->data); - } - else - { - property_class = glade_property_class_new (adaptor); - property_class->id = g_strdup (id); - - /* When creating new virtual packing properties, - * make sure we mark them as such here. - */ - if (is_packing) - property_class->packing = TRUE; - - *properties = g_list_append (*properties, property_class); - list = g_list_last (*properties); - } - - if ((updated = glade_property_class_update_from_node - (child, module, adaptor->type, - &property_class, domain)) == FALSE) - { - g_warning ("failed to update %s property of %s from xml", - id, adaptor->name); - g_free (id); - continue; - } - - /* the property has Disabled=TRUE ... */ - if (!property_class) - *properties = g_list_delete_link (*properties, list); - - g_free (id); - } -} - -static void -gwa_action_update_from_node (GladeWidgetAdaptor *adaptor, - gboolean is_packing, - GladeXmlNode *node, - gchar *group_path) -{ - GladeXmlNode *child; - gchar *id, *label, *stock, *action_path; - gboolean group, important; - - for (child = glade_xml_node_get_children (node); - child; child = glade_xml_node_next (child)) - { - if ((group = glade_xml_node_verify_silent (child, GLADE_TAG_ACTION)) == FALSE) - continue; - - id = glade_xml_get_property_string_required - (child, GLADE_TAG_ID, adaptor->name); - if (id == NULL) - continue; - - if (group_path) - action_path = g_strdup_printf ("%s/%s", group_path, id); - else - action_path = id; - - label = glade_xml_get_property_string (child, GLADE_TAG_NAME); - stock = glade_xml_get_property_string (child, GLADE_TAG_STOCK); - important = glade_xml_get_property_boolean (child, GLADE_TAG_IMPORTANT, FALSE); - - if (is_packing) - glade_widget_adaptor_pack_action_add (adaptor, action_path, label, stock, important); - else - glade_widget_adaptor_action_add (adaptor, action_path, label, stock, important); - - if (group) gwa_action_update_from_node (adaptor, is_packing, child, action_path); - - g_free (id); - g_free (label); - g_free (stock); - if (group_path) g_free (action_path); - } -} - -static gboolean -gwa_extend_with_node (GladeWidgetAdaptor *adaptor, - GladeXmlNode *node, - GModule *module, - const gchar *domain) -{ - GladeXmlNode *child; - gchar *child_type; - - /* Override the special-child-type here */ - if ((child_type = - glade_xml_get_value_string (node, GLADE_TAG_SPECIAL_CHILD_TYPE)) != NULL) - adaptor->priv->special_child_type = - (g_free (adaptor->priv->special_child_type), child_type); - - /* if we found a <properties> tag on the xml file, we add the properties - * that we read from the xml file to the class. - */ - if ((child = - glade_xml_search_child (node, GLADE_TAG_PROPERTIES)) != NULL) - gwa_update_properties_from_node - (adaptor, child, module, &adaptor->properties, domain, FALSE); - - if ((child = - glade_xml_search_child (node, GLADE_TAG_PACKING_PROPERTIES)) != NULL) - gwa_update_properties_from_node - (adaptor, child, module, &adaptor->packing_props, domain, TRUE); - - if ((child = - glade_xml_search_child (node, GLADE_TAG_PACKING_DEFAULTS)) != NULL) - gwa_set_packing_defaults_from_node (adaptor, child); - - /* Update actions from child node */ - if ((child = - glade_xml_search_child (node, GLADE_TAG_ACTIONS)) != NULL) - gwa_action_update_from_node (adaptor, FALSE, child, NULL); - - /* Update packing actions from child node */ - if ((child = - glade_xml_search_child (node, GLADE_TAG_PACKING_ACTIONS)) != NULL) - gwa_action_update_from_node (adaptor, TRUE, child, NULL); - - return TRUE; -} - -/** - * create_icon_name_for_adaptor: - * @adaptor_name: The name of the widget class - * @adaptor_type: The #GType of the adaptor class - * @icon_name: The icon name as set from the catalog - * @icon_prefix: The icon prefix as set from the catalog - * @generic_name: The generic name for the widget class - * - * Creates a suitable icon name for an adaptor, based on several parameters. - * - * Returns: An icon name, or NULL if the adaptor does not require one. - */ -static gchar * -create_icon_name_for_adaptor (const gchar *adaptor_name, - GType adaptor_type, - const gchar *icon_name, - const gchar *icon_prefix, - const gchar *generic_name) -{ - gchar *name; - - /* only certain widget adaptors need to have icons */ - if (G_TYPE_IS_INSTANTIATABLE (adaptor_type) == FALSE || - G_TYPE_IS_ABSTRACT (adaptor_type) != FALSE || - generic_name == NULL) - { - return NULL; - } - - /* if no icon name has been specified, we then fallback to a default icon name */ - if (!icon_name) - name = g_strdup_printf ("widget-%s-%s", icon_prefix, generic_name); - else - name = g_strdup (icon_name); - - /* check if icon is available */ - if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (), name)) - { - g_warning ("No icon named '%s' was found for widget class '%s'.", name, adaptor_name); - g_free (name); - name = g_strdup (DEFAULT_ICON_NAME); - } - - return name; -} - -/** - * glade_widget_adaptor_from_catalog: - * @class_node: A #GladeXmlNode - * @catname: the name of the owning catalog - * @library: the name of the library used to load class methods from - * @domain: the domain to translate strings from this plugin from - * @book: the devhelp search domain for the owning catalog. - * - * Dynamicly creates a subclass of #GladeWidgetAdaptor and subclasses - * the closest parent adaptor (parent class adapters must be creates/registerd - * prior to child classes, otherwise inheritance wont work) and parses in - * the relevent catalog info. - */ -GladeWidgetAdaptor * -glade_widget_adaptor_from_catalog (GladeXmlNode *class_node, - const gchar *catname, - const gchar *icon_prefix, - GModule *module, - const gchar *domain, - const gchar *book) -{ - GladeWidgetAdaptor *adaptor = NULL; - gchar *name, *generic_name, *icon_name, *adaptor_icon_name, *adaptor_name, *func_name; - gchar *title, *translated_title; - GType object_type, adaptor_type, parent_type; - GWADerivedClassData data; - - if (!glade_xml_node_verify (class_node, GLADE_TAG_GLADE_WIDGET_CLASS)) - { - g_warning ("Widget class node is not '%s'", - GLADE_TAG_GLADE_WIDGET_CLASS); - return NULL; - } - - if ((name = glade_xml_get_property_string_required - (class_node, GLADE_TAG_NAME, NULL)) == NULL) - return NULL; - - /* get the object type directly by function, if possible, else by name hack */ - if ((func_name = glade_xml_get_property_string (class_node, GLADE_TAG_GET_TYPE_FUNCTION)) != NULL) - object_type = glade_util_get_type_from_name (func_name, TRUE); - else - object_type = glade_util_get_type_from_name (name, FALSE); - - if (object_type == 0) - { - g_warning ("Failed to load the GType for '%s'", name); - g_free (name); - return NULL; - } - - if (glade_widget_adaptor_get_by_type (object_type)) - { - g_warning ("Adaptor class for '%s' already defined", - g_type_name (object_type)); - g_free (name); - return NULL; - } - - if ((adaptor_name = glade_xml_get_property_string (class_node, GLADE_TAG_ADAPTOR))) - adaptor_type = g_type_from_name (adaptor_name); - else - { - /* - * We use this struct pointer to pass data to - * gwa_derived_class_init() because we must override constructor() - * from the catalog before calling g_object_new() :P - */ - data.node = class_node; - data.module = module; - adaptor_type = gwa_derive_adaptor_for_type (object_type, &data); - } - - if (adaptor_type == 0) - { - g_warning ("Failed to get %s's adaptor %s", name, - (adaptor_name) ? adaptor_name : ""); - g_free (adaptor_name); - g_free (name); - return NULL; - } - - generic_name = glade_xml_get_property_string (class_node, GLADE_TAG_GENERIC_NAME); - icon_name = glade_xml_get_property_string (class_node, GLADE_TAG_ICON_NAME); - - /* get a suitable icon name for adaptor */ - adaptor_icon_name = create_icon_name_for_adaptor (name, - adaptor_type, - icon_name, - icon_prefix, - generic_name); - - adaptor = g_object_new (adaptor_type, - "type", object_type, - "name", name, - "generic-name", generic_name, - "icon-name", adaptor_icon_name, - NULL); - - g_free (generic_name); - g_free (icon_name); - g_free (adaptor_icon_name); - - - title = glade_xml_get_property_string_required (class_node, - GLADE_TAG_TITLE, - "This value is needed to " - "display object class names " - "in the UI"); - if (title == NULL) - { - g_warning ("Class '%s' declared without a '%s' attribute", name, GLADE_TAG_TITLE); - adaptor->title = g_strdup (name); - } - else - { - /* translate */ - translated_title = dgettext (domain, title); - if (translated_title != title) - { - /* gettext owns translated_title */ - adaptor->title = g_strdup (translated_title); - g_free (title); - } - else - { - adaptor->title = title; - } - } - - if (G_TYPE_IS_INSTANTIATABLE (adaptor->type) && - G_TYPE_IS_ABSTRACT (adaptor->type) == FALSE && - adaptor->generic_name == NULL) - { - g_warning ("Instantiatable class '%s' built without a '%s'", - name, GLADE_TAG_GENERIC_NAME); - } - - /* Perform a stoopid fallback just incase */ - if (adaptor->generic_name == NULL) - adaptor->generic_name = g_strdup ("widget"); - - /* Dont mention gtk+ as a required lib in the generated glade file */ - if (strcmp (catname, "gtk+")) - adaptor->priv->catalog = g_strdup (catname); - - if (book) - adaptor->priv->book = g_strdup (book); - - gwa_extend_with_node (adaptor, class_node, module, domain); - - /* Set default weight on properties */ - for (parent_type = adaptor->type; - parent_type != 0; - parent_type = g_type_parent (parent_type)) - { - gwa_properties_set_weight (&adaptor->properties, parent_type); - gwa_properties_set_weight (&adaptor->packing_props, parent_type); - } - - glade_widget_adaptor_register (adaptor); - - return adaptor; -} - -/** - * glade_widget_adaptor_create_internal: - * @parent: The parent #GladeWidget, or %NULL for children - * outside of the hierarchy. - * @internal_object: the #GObject - * @internal_name: a string identifier for this internal widget. - * @anarchist: Whether or not this widget is a widget outside - * of the parent's hierarchy (like a popup window) - * @reason: The #GladeCreateReason for which this internal widget - * was created (usually just pass the reason from the post_create - * function; note also this is used only by the plugin code so - * pass something usefull here). - * - * A convenienve function to create a #GladeWidget of the prescribed type - * for internal widgets. - * - * Returns: a freshly created #GladeWidget wrapper object for the - * @internal_object of name @internal_name - */ -GladeWidget * -glade_widget_adaptor_create_internal (GladeWidget *parent, - GObject *internal_object, - const gchar *internal_name, - const gchar *parent_name, - gboolean anarchist, - GladeCreateReason reason) -{ - GladeWidgetAdaptor *adaptor; - GladeProject *project; - - g_return_val_if_fail (GLADE_IS_WIDGET (parent), NULL); - project = glade_widget_get_project (parent); - - if ((adaptor = glade_widget_adaptor_get_by_name - (G_OBJECT_TYPE_NAME (internal_object))) == NULL) - { - g_critical ("Unable to find widget class for type %s", - G_OBJECT_TYPE_NAME (internal_object)); - return NULL; - } - - return glade_widget_adaptor_create_widget (adaptor, FALSE, - "anarchist", anarchist, - "parent", parent, - "project", project, - "internal", internal_name, - "internal-name", parent_name, - "reason", reason, - "object", internal_object, - NULL); -} - -/** - * glade_widget_adaptor_create_widget: - * @adaptor: a #GladeWidgetAdaptor - * @query: whether to display query dialogs if - * applicable to the class - * @...: a %NULL terminated list of string/value pairs of #GladeWidget - * properties - * - * - * This factory function returns a new #GladeWidget of the correct type/class - * with the properties defined in @... and queries the user if nescisary. - * - * The resulting object will have all default properties applied to it - * including the overrides specified in the catalog, unless the catalog - * has specified 'ignore' for that property. - * - * Note that the widget class must be fed twice; once as the - * leading arg... and also as the property for the #GladeWidget - * - * this macro returns the newly created #GladeWidget - */ -GladeWidget * -glade_widget_adaptor_create_widget_real (gboolean query, - const gchar *first_property, - ...) -{ - GladeWidgetAdaptor *adaptor; - GType gwidget_type; - GladeWidget *gwidget; - va_list vl, vl_copy; - - g_return_val_if_fail (strcmp (first_property, "adaptor") == 0, NULL); - - va_start (vl, first_property); - va_copy (vl_copy, vl); - - adaptor = va_arg (vl, GladeWidgetAdaptor *); - - va_end (vl); - - if (GLADE_IS_WIDGET_ADAPTOR (adaptor) == FALSE) - { - g_critical ("No adaptor found in glade_widget_adaptor_create_widget_real args"); - va_end (vl_copy); - return NULL; - } - - if (GWA_IS_FIXED (adaptor)) - gwidget_type = GLADE_TYPE_FIXED; - else - gwidget_type = GLADE_TYPE_WIDGET; - - - gwidget = (GladeWidget *)g_object_new_valist (gwidget_type, - first_property, - vl_copy); - va_end (vl_copy); - - if (query && glade_widget_adaptor_query (adaptor)) - { - GladeEditor *editor = glade_app_get_editor (); - - /* If user pressed cancel on query popup. */ - if (!glade_editor_query_dialog (editor, gwidget)) - { - g_object_unref (G_OBJECT (gwidget)); - return NULL; - } - } - - return gwidget; -} - -typedef struct -{ - const gchar *name; - GladeWidgetAdaptor *adaptor; -} GladeAdaptorSearchPair; - - -static void -search_adaptor_by_name (GType *type, - GladeWidgetAdaptor *adaptor, - GladeAdaptorSearchPair *pair) -{ - if (!strcmp (adaptor->name, pair->name)) - pair->adaptor = adaptor; -} - -/** - * glade_widget_adaptor_get_by_name: - * @name: name of the widget class (for instance: GtkButton) - * - * Returns: an existing #GladeWidgetAdaptor with the name equaling @name, - * or %NULL if such a class doesn't exist - **/ -GladeWidgetAdaptor * -glade_widget_adaptor_get_by_name (const gchar *name) -{ - - - GladeAdaptorSearchPair pair = { name, NULL }; - - if (adaptor_hash != NULL) - { - g_hash_table_foreach (adaptor_hash, - (GHFunc)search_adaptor_by_name, &pair); - } - return pair.adaptor; -} - - -/** - * glade_widget_adaptor_get_by_type: - * @type: the #GType of an object class - * - * Returns: an existing #GladeWidgetAdaptor with the type equaling @type, - * or %NULL if such a class doesn't exist - **/ -GladeWidgetAdaptor * -glade_widget_adaptor_get_by_type (GType type) -{ - if (adaptor_hash != NULL) - return g_hash_table_lookup (adaptor_hash, &type); - else - return NULL; -} - -/** - * glade_widget_adaptor_get_property_class: - * @adaptor: a #GladeWidgetAdaptor - * @name: a string - * - * Retrieves the #GladePropertyClass for @name in @adaptor - * - * Returns: A #GladePropertyClass object - */ -GladePropertyClass * -glade_widget_adaptor_get_property_class (GladeWidgetAdaptor *adaptor, - const gchar *name) -{ - GList *list; - GladePropertyClass *pclass; - - for (list = adaptor->properties; list && list->data; list = list->next) - { - pclass = list->data; - if (strcmp (pclass->id, name) == 0) - return pclass; - } - return NULL; -} - -/** - * glade_widget_adaptor_get_pack_property_class: - * @adaptor: a #GladeWidgetAdaptor - * @name: a string - * - * Retrieves the #GladePropertyClass for @name in - * @adaptor's child properties - * - * Returns: A #GladePropertyClass object - */ -GladePropertyClass * -glade_widget_adaptor_get_pack_property_class (GladeWidgetAdaptor *adaptor, - const gchar *name) -{ - GList *list; - GladePropertyClass *pclass; - - for (list = adaptor->packing_props; list && list->data; list = list->next) - { - pclass = list->data; - if (strcmp (pclass->id, name) == 0) - return pclass; - } - return NULL; -} - -/** - * glade_widget_class_default_params: - * @adaptor: a #GladeWidgetAdaptor - * @construct: whether to return construct params or not construct params - * @n_params: return location if any defaults are specified for this class. - * - * Returns: A list of params for use in g_object_newv () - */ -GParameter * -glade_widget_adaptor_default_params (GladeWidgetAdaptor *adaptor, - gboolean construct, - guint *n_params) -{ - GArray *params; - GObjectClass *oclass; - GParamSpec **pspec; - GladePropertyClass *pclass; - guint n_props, i; - - g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL); - g_return_val_if_fail (n_params != NULL, NULL); - - /* As a slight optimization, we never unref the class - */ - oclass = g_type_class_ref (adaptor->type); - pspec = g_object_class_list_properties (oclass, &n_props); - params = g_array_new (FALSE, FALSE, sizeof (GParameter)); - - for (i = 0; i < n_props; i++) - { - GParameter parameter = { 0, }; - - pclass = glade_widget_adaptor_get_property_class - (adaptor, pspec[i]->name); - - /* Ignore properties based on some criteria - */ - if (pclass == NULL || /* Unaccounted for in the builder */ - pclass->virt || /* should not be set before - GladeWidget wrapper exists */ - pclass->ignore) /* Catalog explicitly ignores the object */ - continue; - - if (construct && - (pspec[i]->flags & - (G_PARAM_CONSTRUCT|G_PARAM_CONSTRUCT_ONLY)) == 0) - continue; - else if (!construct && - (pspec[i]->flags & - (G_PARAM_CONSTRUCT|G_PARAM_CONSTRUCT_ONLY)) != 0) - continue; - - - if (g_value_type_compatible (G_VALUE_TYPE (pclass->def), - pspec[i]->value_type) == FALSE) - { - g_critical ("Type mismatch on %s property of %s", - parameter.name, adaptor->name); - continue; - } - - if (g_param_values_cmp (pspec[i], - pclass->def, - pclass->orig_def) == 0) - continue; - - parameter.name = pspec[i]->name; /* These are not copied/freed */ - g_value_init (¶meter.value, pspec[i]->value_type); - g_value_copy (pclass->def, ¶meter.value); - - g_array_append_val (params, parameter); - } - g_free (pspec); - - *n_params = params->len; - return (GParameter *)g_array_free (params, FALSE); -} - - -/** - * glade_widget_adaptor_post_create: - * @adaptor: A #GladeWidgetAdaptor - * @object: The #GObject - * @reason: The #GladeCreateReason that @object was created for - * - * An adaptor function to be called after the object is created - */ -void -glade_widget_adaptor_post_create (GladeWidgetAdaptor *adaptor, - GObject *object, - GladeCreateReason reason) -{ - g_return_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor)); - g_return_if_fail (G_IS_OBJECT (object)); - g_return_if_fail (g_type_is_a (G_OBJECT_TYPE (object), adaptor->type)); - - if (GLADE_WIDGET_ADAPTOR_GET_CLASS (adaptor)->post_create) - GLADE_WIDGET_ADAPTOR_GET_CLASS (adaptor)->post_create (adaptor, object, reason); - /* XXX Dont complain here if no implementation is found */ -} - -/** - * glade_widget_adaptor_get_internal_child: - * @adaptor: A #GladeWidgetAdaptor - * @object: The #GObject - * @internal_name: The string identifier of the internal object - * - * Retrieves the internal object @internal_name from @object - * - * Returns: The internal #GObject - */ -GObject * -glade_widget_adaptor_get_internal_child (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *internal_name) -{ - g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL); - g_return_val_if_fail (G_IS_OBJECT (object), NULL); - g_return_val_if_fail (internal_name != NULL, NULL); - g_return_val_if_fail (g_type_is_a (G_OBJECT_TYPE (object), adaptor->type), NULL); - - if (GLADE_WIDGET_ADAPTOR_GET_CLASS (adaptor)->get_internal_child) - return GLADE_WIDGET_ADAPTOR_GET_CLASS - (adaptor)->get_internal_child (adaptor, object, internal_name); - else - g_critical ("No get_internal_child() support in adaptor %s", adaptor->name); - - return NULL; -} - -/** - * glade_widget_adaptor_set_property: - * @adaptor: A #GladeWidgetAdaptor - * @object: The #GObject - * @property_name: The property identifier - * @value: The #GValue - * - * This delagate function is used to apply the property value on - * the runtime object. - * - */ -void -glade_widget_adaptor_set_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *property_name, - const GValue *value) -{ - g_return_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor)); - g_return_if_fail (G_IS_OBJECT (object)); - g_return_if_fail (property_name != NULL && value != NULL); - g_return_if_fail (g_type_is_a (G_OBJECT_TYPE (object), adaptor->type)); - - /* The base class provides an implementation */ - GLADE_WIDGET_ADAPTOR_GET_CLASS - (adaptor)->set_property (adaptor, object, property_name, value); -} - - -/** - * glade_widget_adaptor_get_property: - * @adaptor: A #GladeWidgetAdaptor - * @object: The #GObject - * @property_name: The property identifier - * @value: The #GValue - * - * Gets @value of @property_name on @object. - * - */ -void -glade_widget_adaptor_get_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *property_name, - GValue *value) -{ - g_return_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor)); - g_return_if_fail (G_IS_OBJECT (object)); - g_return_if_fail (property_name != NULL && value != NULL); - g_return_if_fail (g_type_is_a (G_OBJECT_TYPE (object), adaptor->type)); - - /* The base class provides an implementation */ - GLADE_WIDGET_ADAPTOR_GET_CLASS - (adaptor)->get_property (adaptor, object, property_name, value); -} - - -/** - * glade_widget_adaptor_verify_property: - * @adaptor: A #GladeWidgetAdaptor - * @object: The #GObject - * @property_name: The property identifier - * @value: The #GValue - * - * This delagate function is always called whenever setting any - * properties with the exception of load time, and copy/paste time - * (basicly the two places where we recreate a hierarchy that we - * already know "works") its basicly an optional backend provided - * boundry checker for properties. - * - * Returns: whether or not its OK to set @value on @object, this function - * will silently return TRUE if the class did not provide a verify function. - */ -gboolean -glade_widget_adaptor_verify_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *property_name, - const GValue *value) -{ - g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), FALSE); - g_return_val_if_fail (G_IS_OBJECT (object), FALSE); - g_return_val_if_fail (property_name != NULL && value != NULL, FALSE); - g_return_val_if_fail (g_type_is_a (G_OBJECT_TYPE (object), adaptor->type), FALSE); - - if (GLADE_WIDGET_ADAPTOR_GET_CLASS (adaptor)->verify_property) - return GLADE_WIDGET_ADAPTOR_GET_CLASS - (adaptor)->verify_property (adaptor, object, property_name, value); - - return TRUE; -} - -/** - * glade_widget_adaptor_add: - * @adaptor: A #GladeWidgetAdaptor - * @container: The #GObject container - * @child: The #GObject child - * - * Adds @child to @container. - */ -void -glade_widget_adaptor_add (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child) -{ - g_return_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor)); - g_return_if_fail (G_IS_OBJECT (container)); - g_return_if_fail (G_IS_OBJECT (child)); - g_return_if_fail (g_type_is_a (G_OBJECT_TYPE (container), adaptor->type)); - - if (GLADE_WIDGET_ADAPTOR_GET_CLASS (adaptor)->add) - GLADE_WIDGET_ADAPTOR_GET_CLASS (adaptor)->add (adaptor, container, child); - else - g_critical ("No add() support in adaptor %s", adaptor->name); -} - - -/** - * glade_widget_adaptor_remove: - * @adaptor: A #GladeWidgetAdaptor - * @container: The #GObject container - * @child: The #GObject child - * - * Removes @child from @container. - */ -void -glade_widget_adaptor_remove (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child) -{ - g_return_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor)); - g_return_if_fail (G_IS_OBJECT (container)); - g_return_if_fail (G_IS_OBJECT (child)); - g_return_if_fail (g_type_is_a (G_OBJECT_TYPE (container), adaptor->type)); - - if (GLADE_WIDGET_ADAPTOR_GET_CLASS (adaptor)->remove) - GLADE_WIDGET_ADAPTOR_GET_CLASS (adaptor)->remove (adaptor, container, child); - else - g_critical ("No remove() support in adaptor %s", adaptor->name); -} - -/** - * glade_widget_adaptor_remove: - * @adaptor: A #GladeWidgetAdaptor - * @container: The #GObject container - * - * Lists the children of @container. - * - * Returns: A #GList of children - */ -GList * -glade_widget_adaptor_get_children (GladeWidgetAdaptor *adaptor, - GObject *container) -{ - g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL); - g_return_val_if_fail (G_IS_OBJECT (container), NULL); - g_return_val_if_fail (g_type_is_a (G_OBJECT_TYPE (container), adaptor->type), NULL); - - if (GLADE_WIDGET_ADAPTOR_GET_CLASS (adaptor)->get_children) - return GLADE_WIDGET_ADAPTOR_GET_CLASS - (adaptor)->get_children (adaptor, container); - - /* Dont complain here if no implementation is found */ - - return NULL; -} - -/** - * glade_widget_adaptor_has_child: - * @adaptor: A #GladeWidgetAdaptor - * @container: The #GObject container - * @child: The #GObject child - * - * Returns whether @child is infact inside @container. - */ -gboolean -glade_widget_adaptor_has_child (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child) -{ - GList *list, *children = NULL; - gboolean found = FALSE; - - children = glade_widget_adaptor_get_children (adaptor, container); - - for (list = children; list && list->data; list = list->next) - { - if (list->data == child) - { - found = TRUE; - break; - } - } - - g_list_free (children); - return found; -} - -/** - * glade_widget_adaptor_child_set_property: - * @adaptor: A #GladeWidgetAdaptor - * @container: The #GObject container - * @child: The #GObject child - * @property_name: The id of the property - * @value: The @GValue - * - * Sets @child's packing property identified by @property_name to @value. - */ -void -glade_widget_adaptor_child_set_property (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child, - const gchar *property_name, - const GValue *value) -{ - g_return_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor)); - g_return_if_fail (G_IS_OBJECT (container)); - g_return_if_fail (G_IS_OBJECT (child)); - g_return_if_fail (property_name != NULL && value != NULL); - g_return_if_fail (g_type_is_a (G_OBJECT_TYPE (container), adaptor->type)); - - if (GLADE_WIDGET_ADAPTOR_GET_CLASS (adaptor)->child_set_property) - GLADE_WIDGET_ADAPTOR_GET_CLASS - (adaptor)->child_set_property (adaptor, container, child, - property_name, value); - else - g_critical ("No child_set_property() support in adaptor %s", adaptor->name); - -} - -/** - * glade_widget_adaptor_child_get_property: - * @adaptor: A #GladeWidgetAdaptor - * @container: The #GObject container - * @child: The #GObject child - * @property_name: The id of the property - * @value: The @GValue - * - * Gets @child's packing property identified by @property_name. - */ -void -glade_widget_adaptor_child_get_property (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child, - const gchar *property_name, - GValue *value) -{ - g_return_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor)); - g_return_if_fail (G_IS_OBJECT (container)); - g_return_if_fail (G_IS_OBJECT (child)); - g_return_if_fail (property_name != NULL && value != NULL); - g_return_if_fail (g_type_is_a (G_OBJECT_TYPE (container), adaptor->type)); - - if (GLADE_WIDGET_ADAPTOR_GET_CLASS (adaptor)->child_get_property) - GLADE_WIDGET_ADAPTOR_GET_CLASS - (adaptor)->child_get_property (adaptor, container, child, - property_name, value); - else - g_critical ("No child_set_property() support in adaptor %s", adaptor->name); -} - -/** - * glade_widget_adaptor_child_verify_property: - * @adaptor: A #GladeWidgetAdaptor - * @container: The #GObject container - * @child: The #GObject child - * @property_name: The id of the property - * @value: The @GValue - * - * This delagate function is always called whenever setting any - * properties with the exception of load time, and copy/paste time - * (basicly the two places where we recreate a hierarchy that we - * already know "works") its basicly an optional backend provided - * boundry checker for properties. - * - * Returns: whether or not its OK to set @value on @object, this function - * will silently return TRUE if the class did not provide a verify function. - */ -gboolean -glade_widget_adaptor_child_verify_property (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child, - const gchar *property_name, - const GValue *value) -{ - g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), FALSE); - g_return_val_if_fail (G_IS_OBJECT (container), FALSE); - g_return_val_if_fail (G_IS_OBJECT (child), FALSE); - g_return_val_if_fail (property_name != NULL && value != NULL, FALSE); - g_return_val_if_fail (g_type_is_a (G_OBJECT_TYPE (container), adaptor->type), FALSE); - - if (GLADE_WIDGET_ADAPTOR_GET_CLASS (adaptor)->child_verify_property) - return GLADE_WIDGET_ADAPTOR_GET_CLASS - (adaptor)->child_verify_property (adaptor, - container, child, - property_name, value); - - return TRUE; -} - - -/** - * glade_widget_adaptor_replace_child: - * @adaptor: A #GladeWidgetAdaptor - * @container: The #GObject container - * @old: The old #GObject child - * @new: The new #GObject child - * - * Replaces @old with @new in @container while positioning - * @new where @old was and assigning it appropriate packing - * property values. - */ -void -glade_widget_adaptor_replace_child (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *old_obj, - GObject *new_obj) -{ - g_return_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor)); - g_return_if_fail (G_IS_OBJECT (container)); - g_return_if_fail (G_IS_OBJECT (old_obj)); - g_return_if_fail (G_IS_OBJECT (new_obj)); - g_return_if_fail (g_type_is_a (G_OBJECT_TYPE (container), adaptor->type)); - - if (GLADE_WIDGET_ADAPTOR_GET_CLASS (adaptor)->replace_child) - GLADE_WIDGET_ADAPTOR_GET_CLASS - (adaptor)->replace_child (adaptor, container, old_obj, new_obj); - else - g_critical ("No replace_child() support in adaptor %s", adaptor->name); -} - -/** - * glade_widget_adaptor_query: - * @adaptor: A #GladeWidgetAdaptor - * - * Returns: whether the user needs to be queried for - * certain properties upon creation of this class. - */ -gboolean -glade_widget_adaptor_query (GladeWidgetAdaptor *adaptor) -{ - GladePropertyClass *pclass; - GList *l; - - g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), FALSE); - - for (l = adaptor->properties; l; l = l->next) - { - pclass = l->data; - - if (pclass->query) - return TRUE; - } - - return FALSE; -} - -/** - * glade_widget_adaptor_get_packing_default: - * @child_adaptor: A #GladeWidgetAdaptor - * @parent_adaptor: The #GladeWidgetAdaptor for the parent object - * @property_id: The string property identifier - * - * Gets the default value for @property_id on a widget governed by - * @child_adaptor when parented in a widget governed by @parent_adaptor - * - * Returns: a string representing the default value for @property_id - */ -G_CONST_RETURN gchar * -glade_widget_adaptor_get_packing_default (GladeWidgetAdaptor *child_adaptor, - GladeWidgetAdaptor *container_adaptor, - const gchar *id) -{ - GladeChildPacking *packing = NULL; - GList *l; - - g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (child_adaptor), NULL); - g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (container_adaptor), NULL); - - if ((packing = - glade_widget_adaptor_get_child_packing (child_adaptor, - container_adaptor->name)) != NULL) - { - for (l = packing->packing_defaults; l; l = l->next) - { - GladePackingDefault *def = l->data; - - if (strcmp (def->id, id) == 0) - return def->value; - } - } - return NULL; -} - -/** - * glade_widget_adaptor_is_container: - * @adaptor: A #GladeWidgetAdaptor - * - * Checks whether or not this adaptor has support - * to interface with child objects. - * - * Returns whether or not @adaptor is a container - */ -gboolean -glade_widget_adaptor_is_container (GladeWidgetAdaptor *adaptor) -{ - - g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), FALSE); - - /* A GWA container must at least implement add/remove/get_children - */ - return (GLADE_WIDGET_ADAPTOR_GET_CLASS (adaptor)->add && - GLADE_WIDGET_ADAPTOR_GET_CLASS (adaptor)->remove && - GLADE_WIDGET_ADAPTOR_GET_CLASS (adaptor)->get_children); -} - -static const gchar * -gwa_action_path_get_id (const gchar *action_path) -{ - const gchar *id; - - if ((id = g_strrstr (action_path, "/")) && id[1] != '\0') - return &id[1]; - else - return action_path; -} - -static GWActionClass * -gwa_action_lookup (GList *actions, const gchar *action_id) -{ - GList *l; - - for (l = actions; l; l = g_list_next (l)) - { - GWActionClass *action = l->data; - if (strcmp (action->id, action_id) == 0) - return action; - } - - return NULL; -} - -static GWActionClass * -gwa_action_get_last_group (GList *actions, const gchar *action_path) -{ - gchar **tokens = g_strsplit (action_path, "/", 0); - GWActionClass *group = NULL; - gint i; - - for (i = 0; tokens[i] && tokens[i+1]; i++) - { - if ((group = gwa_action_lookup (actions, tokens[i])) == NULL) - { - g_strfreev (tokens); - return NULL; - } - actions = group->actions; - } - - g_strfreev (tokens); - return group; -} - -static gboolean -glade_widget_adaptor_action_add_real (GList **list, - const gchar *action_path, - const gchar *label, - const gchar *stock, - gboolean important) -{ - GWActionClass *action, *group; - const gchar *id; - - id = gwa_action_path_get_id (action_path); - - if ((group = gwa_action_get_last_group (*list, action_path))) - list = &group->actions; - - if ((action = gwa_action_lookup (*list, id))) - { - /* Update parent's label/stock */ - if (label && action->label) - { - g_free (action->label); - if (strcmp (label, "") == 0) label = NULL; - action->label = (label) ? g_strdup (label) : NULL; - } - if (stock && action->stock) - { - g_free (action->stock); - if (strcmp (stock, "") == 0) stock = NULL; - action->stock = (stock) ? g_strdup (stock) : NULL; - } - } - else - { - /* New Action */ - action = g_new0 (GWActionClass, 1); - action->path = g_strdup (action_path); - action->id = (gchar*) gwa_action_path_get_id (action->path); - - if (label && strcmp (label, "") == 0) label = NULL; - if (stock && strcmp (stock, "") == 0) stock = NULL; - - action->label = (label) ? g_strdup (label) : NULL; - action->stock = (stock) ? g_strdup (stock) : NULL; - } - - action->important = important; - - *list = g_list_append (*list, action); - - return TRUE; -} - -/** - * glade_widget_adaptor_action_add: - * @adaptor: A #GladeWidgetAdaptor - * @action_path: The identifier of this action in the action tree - * @label: A translated label to show in the UI for this action - * @stock: If set, this stock item will be shown in the UI along side the label. - * @important: if this action is important. - * - * Add an action to @adaptor. - * If the action is present then it overrides label and stock - * - * Returns: whether or not the action was added/updated. - */ -gboolean -glade_widget_adaptor_action_add (GladeWidgetAdaptor *adaptor, - const gchar *action_path, - const gchar *label, - const gchar *stock, - gboolean important) -{ - g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), FALSE); - g_return_val_if_fail (action_path != NULL, FALSE); - - return glade_widget_adaptor_action_add_real (&adaptor->actions, - action_path, - label, - stock, - important); -} - -/** - * glade_widget_adaptor_pack_action_add: - * @adaptor: A #GladeWidgetAdaptor - * @action_path: The identifier of this action in the action tree - * @label: A translated label to show in the UI for this action - * @stock: If set, this stock item will be shown in the UI along side the label. - * @important: if this action is important. - * - * Add a packing action to @adaptor. - * If the action is present then it overrides label and stock - * - * Returns: whether or not the action was added/updated. - */ -gboolean -glade_widget_adaptor_pack_action_add (GladeWidgetAdaptor *adaptor, - const gchar *action_path, - const gchar *label, - const gchar *stock, - gboolean important) -{ - g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), FALSE); - g_return_val_if_fail (action_path != NULL, FALSE); - - return glade_widget_adaptor_action_add_real (&adaptor->packing_actions, - action_path, - label, - stock, - important); -} - -static gboolean -glade_widget_adaptor_action_remove_real (GList **list, const gchar *action_path) -{ - GWActionClass *action, *group; - const gchar *id; - - id = gwa_action_path_get_id (action_path); - - if ((group = gwa_action_get_last_group (*list, action_path))) - list = &group->actions; - - if ((action = gwa_action_lookup (*list, id)) == NULL) return FALSE; - - *list = g_list_remove (*list, action); - - glade_widget_action_class_free (action); - - return TRUE; -} - -/** - * glade_widget_adaptor_action_remove: - * @adaptor: A #GladeWidgetAdaptor - * @action_path: The identifier of this action in the action tree - * - * Remove an @adaptor's action. - * - * Returns: whether or not the action was removed. - */ -gboolean -glade_widget_adaptor_action_remove (GladeWidgetAdaptor *adaptor, - const gchar *action_path) -{ - g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), FALSE); - g_return_val_if_fail (action_path != NULL, FALSE); - - return glade_widget_adaptor_action_remove_real (&adaptor->actions, - action_path); -} - -/** - * glade_widget_adaptor_pack_action_remove: - * @adaptor: A #GladeWidgetAdaptor - * @action_path: The identifier of this action in the action tree - * - * Remove an @adaptor's packing action. - * - * Returns: whether or not the action was removed. - */ -gboolean -glade_widget_adaptor_pack_action_remove (GladeWidgetAdaptor *adaptor, - const gchar *action_path) -{ - g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), FALSE); - g_return_val_if_fail (action_path != NULL, FALSE); - - return glade_widget_adaptor_action_remove_real (&adaptor->packing_actions, - action_path); -} - - -/** - * glade_widget_adaptor_pack_actions_new: - * @adaptor: A #GladeWidgetAdaptor - * - * Create a list of packing actions. - * - * Returns: a new list of GladeWidgetAction. - */ -GList * -glade_widget_adaptor_pack_actions_new (GladeWidgetAdaptor *adaptor) -{ - GList *l, *list = NULL; - - g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL); - - for (l = adaptor->packing_actions; l; l = g_list_next (l)) - { - GWActionClass *action = l->data; - GObject *obj = g_object_new (GLADE_TYPE_WIDGET_ACTION, - "class", action, NULL); - - list = g_list_prepend (list, GLADE_WIDGET_ACTION (obj)); - } - return g_list_reverse (list); -} - -/** - * glade_widget_adaptor_action_activate: - * @adaptor: A #GladeWidgetAdaptor - * @object: The #GObject - * @action_path: The action identifier in the action tree - * - * An adaptor function to be called on widget actions. - */ -void -glade_widget_adaptor_action_activate (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *action_path) -{ - g_return_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor)); - g_return_if_fail (G_IS_OBJECT (object)); - g_return_if_fail (g_type_is_a (G_OBJECT_TYPE (object), adaptor->type)); - - GLADE_WIDGET_ADAPTOR_GET_CLASS (adaptor)->action_activate (adaptor, object, action_path); -} - -/** - * glade_widget_adaptor_child_action_activate: - * @adaptor: A #GladeWidgetAdaptor - * @object: The #GObject - * @action_path: The action identifier in the action tree - * - * An adaptor function to be called on widget actions. - */ -void -glade_widget_adaptor_child_action_activate (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *object, - const gchar *action_path) -{ - g_return_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor)); - g_return_if_fail (G_IS_OBJECT (container)); - g_return_if_fail (G_IS_OBJECT (object)); - g_return_if_fail (g_type_is_a (G_OBJECT_TYPE (container), adaptor->type)); - - GLADE_WIDGET_ADAPTOR_GET_CLASS (adaptor)->child_action_activate (adaptor, container, object, action_path); -} diff --git a/gladeui/glade-widget-adaptor.h b/gladeui/glade-widget-adaptor.h deleted file mode 100644 index 9956bdde..00000000 --- a/gladeui/glade-widget-adaptor.h +++ /dev/null @@ -1,620 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef __GLADE_WIDGET_ADAPTOR_H__ -#define __GLADE_WIDGET_ADAPTOR_H__ - -#include <gladeui/glade-xml-utils.h> -#include <gladeui/glade-property-class.h> -#include <glib-object.h> -#include <gmodule.h> -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -#define GLADE_TYPE_WIDGET_ADAPTOR (glade_widget_adaptor_get_type()) -#define GLADE_WIDGET_ADAPTOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_WIDGET_ADAPTOR, GladeWidgetAdaptor)) -#define GLADE_WIDGET_ADAPTOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_WIDGET_ADAPTOR, GladeWidgetAdaptorClass)) -#define GLADE_IS_WIDGET_ADAPTOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_WIDGET_ADAPTOR)) -#define GLADE_IS_WIDGET_ADAPTOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_WIDGET_ADAPTOR)) -#define GLADE_WIDGET_ADAPTOR_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GLADE_WIDGET_ADAPTOR, GladeWidgetAdaptorClass)) - -typedef struct _GladeWidgetAdaptor GladeWidgetAdaptor; -typedef struct _GladeWidgetAdaptorPrivate GladeWidgetAdaptorPrivate; -typedef struct _GladeWidgetAdaptorClass GladeWidgetAdaptorClass; - -/** - * GWA_IS_FIXED: - * @obj: A #GladeWidgetAdaptor - * - * Checks whether this widget adaptor should be handled - * as a free-form container - */ -#define GWA_IS_FIXED(obj) \ - ((obj) ? GLADE_WIDGET_ADAPTOR_GET_CLASS(obj)->fixed : FALSE) - -/** - * GWA_IS_TOPLEVEL: - * @obj: A #GladeWidgetAdaptor - * - * Checks whether this widget class has been marked as - * a toplevel one. - */ -#define GWA_IS_TOPLEVEL(obj) \ - ((obj) ? GLADE_WIDGET_ADAPTOR_GET_CLASS(obj)->toplevel : FALSE) - -/** - * GWA_USE_PLACEHOLDERS: - * @obj: A #GladeWidgetAdaptor - * - * Checks whether this widget class has been marked to - * use placeholders in child widget operations - */ -#define GWA_USE_PLACEHOLDERS(obj) \ - ((obj) ? GLADE_WIDGET_ADAPTOR_GET_CLASS(obj)->use_placeholders : FALSE) - - -/** - * GWA_DEFAULT_WIDTH: - * @obj: A #GladeWidgetAdaptor - * - * Returns the default width to be used when this widget - * is toplevel in the GladeDesignLayout - */ -#define GWA_DEFAULT_WIDTH(obj) \ - ((obj) ? GLADE_WIDGET_ADAPTOR_GET_CLASS(obj)->default_width : -1) - - -/** - * GWA_DEFAULT_HEIGHT: - * @obj: A #GladeWidgetAdaptor - * - * Returns the default width to be used when this widget - * is toplevel in the GladeDesignLayout - */ -#define GWA_DEFAULT_HEIGHT(obj) \ - ((obj) ? GLADE_WIDGET_ADAPTOR_GET_CLASS(obj)->default_height : -1) - -/** - * GWA_GET_CLASS: - * @type: A #GType - * - * Shorthand for referencing glade adaptor classes from - * the plugin eg. GWA_GET_CLASS (GTK_TYPE_CONTAINER)->post_create (adaptor... - */ -#define GWA_GET_CLASS(type) \ - (((type) == G_TYPE_OBJECT) ? \ - (GladeWidgetAdaptorClass *)g_type_class_peek (GLADE_TYPE_WIDGET_ADAPTOR) : \ - GLADE_WIDGET_ADAPTOR_GET_CLASS (glade_widget_adaptor_get_by_type(type))) - -/** - * GWA_GET_OCLASS: - * @type: A #GType. - * - * Same as GWA_GET_CLASS but casted to GObjectClass - */ -#define GWA_GET_OCLASS(type) ((GObjectClass*)GWA_GET_CLASS(type)) - - -#define GLADE_VALID_CREATE_REASON(reason) (reason >= 0 && reason < GLADE_CREATE_REASONS) - -/** - * GladeCreateReason: - * @GLADE_CREATE_USER: Was created at the user's request - * (this is a good time to set any properties - * or add children to the project; like GtkFrame's - * label for example). - * @GLADE_CREATE_COPY: Was created as a result of the copy/paste - * mechanism, at this point you can count on glade - * to follow up with properties and children on - * its own. - * @GLADE_CREATE_LOAD: Was created during the load process. - * @GLADE_CREATE_REBUILD: Was created as a replacement for another project - * object; this only happens when the user is - * changing a property that is marked by the type - * system as G_PARAM_SPEC_CONSTRUCT_ONLY. - * @GLADE_CREATE_REASONS: Never used. - * - * These are the reasons your #GladePostCreateFunc can be called. - */ -typedef enum -{ - GLADE_CREATE_USER = 0, - GLADE_CREATE_COPY, - GLADE_CREATE_LOAD, - GLADE_CREATE_REBUILD, - GLADE_CREATE_REASONS -} GladeCreateReason; - -#define GLADE_CREATE_REASON (glade_create_reason_get_type()) - -/** - * GladeSetPropertyFunc: - * @adaptor: A #GladeWidgetAdaptor - * @object: The #GObject - * @property_name: The property identifier - * @value: The #GValue - * - * This delagate function is used to apply the property value on - * the runtime object. - * - * Sets @value on @object for a given #GladePropertyClass - */ -typedef void (* GladeSetPropertyFunc) (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *property_name, - const GValue *value); - -/** - * GladeGetPropertyFunc: - * @adaptor: A #GladeWidgetAdaptor - * @object: The #GObject - * @property_name: The property identifier - * @value: The #GValue - * - * Gets @value on @object for a given #GladePropertyClass - */ -typedef void (* GladeGetPropertyFunc) (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *property_name, - GValue *value); - -/** - * GladeVerifyPropertyFunc: - * @adaptor: A #GladeWidgetAdaptor - * @object: The #GObject - * @property_name: The property identifier - * @value: The #GValue - * - * This delagate function is always called whenever setting any - * properties with the exception of load time, and copy/paste time - * (basicly the two places where we recreate a hierarchy that we - * already know "works") its basicly an optional backend provided - * boundry checker for properties. - * - * Returns: whether or not its OK to set @value on @object - */ -typedef gboolean (* GladeVerifyPropertyFunc) (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *property_name, - const GValue *value); - -/** - * GladeChildSetPropertyFunc: - * @adaptor: A #GladeWidgetAdaptor - * @container: The #GObject container - * @child: The #GObject child - * @property_name: The property name - * @value: The #GValue - * - * Called to set the packing property @property_name to @value - * on the @child object of @container. - */ -typedef void (* GladeChildSetPropertyFunc) (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child, - const gchar *property_name, - const GValue *value); - -/** - * GladeChildGetPropertyFunc: - * @adaptor: A #GladeWidgetAdaptor - * @container: The #GObject container - * @child: The #GObject child - * @property_name: The property name - * @value: The #GValue - * - * Called to get the packing property @property_name - * on the @child object of @container into @value. - */ -typedef void (* GladeChildGetPropertyFunc) (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child, - const gchar *property_name, - GValue *value); - -/** - * GladeChildVerifyPropertyFunc: - * @adaptor: A #GladeWidgetAdaptor - * @container: The #GObject container - * @child: The #GObject child - * @property_name: The property name - * @value: The #GValue - * - * This delagate function is always called whenever setting any - * properties with the exception of load time, and copy/paste time - * (basicly the two places where we recreate a hierarchy that we - * already know "works") its basicly an optional backend provided - * boundry checker for properties. - * - * Returns: whether or not its OK to set @value on @object - */ -typedef gboolean (* GladeChildVerifyPropertyFunc) (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child, - const gchar *property_name, - const GValue *value); - - -/** - * GladeGetChildrenFunc: - * @container: A #GObject container - * @Returns: A #GList of #GObject children. - * - * A function called to get @containers children. - */ -typedef GList *(* GladeGetChildrenFunc) (GladeWidgetAdaptor *adaptor, - GObject *container); - -/** - * GladeAddChildFunc: - * @parent: A #GObject container - * @child: A #GObject child - * - * Called to add @child to @parent. - */ -typedef void (* GladeAddChildFunc) (GladeWidgetAdaptor *adaptor, - GObject *parent, - GObject *child); -/** - * GladeRemoveChildFunc: - * @parent: A #GObject container - * @child: A #GObject child - * - * Called to remove @child from @parent. - */ -typedef void (* GladeRemoveChildFunc) (GladeWidgetAdaptor *adaptor, - GObject *parent, - GObject *child); - -/** - * GladeReplaceChildFunc: - * @container: A #GObject container - * @old: The old #GObject child - * @new: The new #GObject child to take its place - * - * Called to swap placeholders with project objects - * in containers. - */ -typedef void (* GladeReplaceChildFunc) (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *old_obj, - GObject *new_obj); - -/** - * GladePostCreateFunc: - * @object: a #GObject - * @reason: a #GladeCreateReason - * - * This function is called exactly once for any project object - * instance and can be for any #GladeCreateReason. - */ -typedef void (* GladePostCreateFunc) (GladeWidgetAdaptor *adaptor, - GObject *object, - GladeCreateReason reason); - -/** - * GladeGetInternalFunc: - * @parent: A #GObject composite object - * @name: A string identifier - * @child: A return location for a #GObject - * - * Called to lookup @child in composite object @parent by @name. - */ -typedef GObject *(* GladeGetInternalFunc) (GladeWidgetAdaptor *adaptor, - GObject *parent, - const gchar *name); - -/** - * GladeActionActivatedFunc: - * @adaptor: A #GladeWidgetAdaptor - * @object: The #GObject - * @action_path: The action path - * - * This delagate function is used to catch actions from the core. - * - */ -typedef void (* GladeActionActivateFunc) (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *action_path); - -/** - * GladeChildActionActivatedFunc: - * @adaptor: A #GladeWidgetAdaptor - * @container: The #GtkContainer - * @object: The #GObject - * @action_path: The action path - * - * This delagate function is used to catch packing actions from the core. - * - */ -typedef void (* GladeChildActionActivateFunc) (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *object, - const gchar *action_path); - -/* GladeSignalClass contains all the info we need for a given signal, such as - * the signal name, and maybe more in the future - */ -typedef struct _GladeSignalClass GladeSignalClass; -struct _GladeSignalClass -{ - GSignalQuery query; - - const gchar *name; /* Name of the signal, eg clicked */ - gchar *type; /* Name of the object class that this signal belongs to - * eg GtkButton */ - -}; - -/* Note that everything that must be processed at the creation of - * every instance is managed on the instance structure, and everywhere - * that we want to take advantage of inheritance is handled in the class - * structure. - */ -struct _GladeWidgetAdaptor -{ - GObject parent_instance; - - GType type; /* GType of the widget */ - - gchar *name; /* Name of the widget, for example GtkButton */ - - - gchar *generic_name; /* Used to generate names of new widgets, for - * example "button" so that we generate button1, - * button2, buttonX .. - */ - - gchar *icon_name; /* icon name for widget class */ - - gchar *title; /* Translated class name used in the UI */ - - GList *properties; /* List of GladePropertyClass objects. - * [see glade-property.h] this list contains - * properties about the widget that we are going - * to modify. Like "title", "label", "rows" . - * Each property creates an input in the propety - * editor. - */ - GList *packing_props; /* List of GladePropertyClass objects that describe - * properties for child objects packing definition - - * note there may be more than one type of child supported - * by a widget and thus they may have different sets - * of properties for each type - this association is - * managed on the GladePropertyClass proper. - */ - - GList *signals; /* List of GladeSignalClass objects */ - - GList *child_packings; /* Default packing property values */ - - GList *actions; /* A list of GWActionClass */ - - GList *packing_actions;/* A list of GWActionClass for child objects */ - - GladeWidgetAdaptorPrivate *priv; - -}; - -struct _GladeWidgetAdaptorClass -{ - GObjectClass parent_class; - - gboolean fixed; /* If this is a GtkContainer, use free-form - * placement with drag/resize/paste at mouse... - */ - gboolean toplevel; /* If this class is toplevel */ - - gboolean use_placeholders; /* Whether or not to use placeholders - * to interface with child widgets. - */ - - gint default_width; /* Default width in GladeDesignLayout */ - gint default_height; /* Default height in GladeDesignLayout */ - - GladePostCreateFunc post_create; /* Executed after widget creation: - * plugins use this to setup various - * support codes. - */ - - GladeGetInternalFunc get_internal_child; /* Retrieves the the internal child - * of the given name. - */ - - /* Delagate to verify if this is a valid value for this property, - * if this function exists and returns FALSE, then glade_property_set - * will abort before making any changes - */ - GladeVerifyPropertyFunc verify_property; - - /* An optional backend function used instead of g_object_set() - * virtual properties must be handled with this function. - */ - GladeSetPropertyFunc set_property; - - /* An optional backend function used instead of g_object_get() - * virtual properties must be handled with this function. - * - * Note that since glade knows what the property values are - * at all times regardless of the objects copy, this is currently - * only used to obtain the values of packing properties that are - * set by the said object's parent at "container_add" time. - */ - GladeGetPropertyFunc get_property; - - - GladeAddChildFunc add; /* Adds a new child of this type */ - GladeRemoveChildFunc remove; /* Removes a child from the container */ - GladeGetChildrenFunc get_children; /* Returns a list of direct children for - * this support type. - */ - - - - GladeChildVerifyPropertyFunc child_verify_property; /* A boundry checker for - * packing properties - */ - GladeChildSetPropertyFunc child_set_property; /* Sets/Gets a packing property */ - GladeChildGetPropertyFunc child_get_property; /* for this child */ - - GladeReplaceChildFunc replace_child; /* This method replaces a - * child widget with - * another one: it's used to - * replace a placeholder with - * a widget and viceversa. - */ - - GladeActionActivateFunc action_activate; /* This method is used to catch actions */ - GladeChildActionActivateFunc child_action_activate; /* This method is used to catch packing actions */ -}; - -#define glade_widget_adaptor_create_widget(adaptor, query, ...) \ - (glade_widget_adaptor_create_widget_real (query, "adaptor", adaptor, __VA_ARGS__)); - -#define glade_widget_adaptor_from_pclass(pclass) \ - ((pclass) ? (GladeWidgetAdaptor *)((GladePropertyClass *)(pclass))->handle : NULL) - -#define glade_widget_adaptor_from_pspec(pspec) \ - ((pspec) ? glade_widget_adaptor_get_by_type (((GParamSpec *)(pspec))->owner_type) : NULL) - -GType glade_widget_adaptor_get_type (void) G_GNUC_CONST; - - -GType glade_create_reason_get_type (void) G_GNUC_CONST; - - -GladeWidgetAdaptor *glade_widget_adaptor_from_catalog (GladeXmlNode *class_node, - const gchar *catname, - const gchar *icon_prefix, - GModule *module, - const gchar *domain, - const gchar *book); - -void glade_widget_adaptor_register (GladeWidgetAdaptor *adaptor); - -GladeWidget *glade_widget_adaptor_create_internal (GladeWidget *parent, - GObject *internal_object, - const gchar *internal_name, - const gchar *parent_name, - gboolean anarchist, - GladeCreateReason reason); - -GladeWidget *glade_widget_adaptor_create_widget_real (gboolean query, - const gchar *first_property, - ...); - - -GladeWidgetAdaptor *glade_widget_adaptor_get_by_name (const gchar *name); - -GladeWidgetAdaptor *glade_widget_adaptor_get_by_type (GType type); - -GladePropertyClass *glade_widget_adaptor_get_property_class (GladeWidgetAdaptor *adaptor, - const gchar *name); - -GladePropertyClass *glade_widget_adaptor_get_pack_property_class (GladeWidgetAdaptor *adaptor, - const gchar *name); - -GParameter *glade_widget_adaptor_default_params (GladeWidgetAdaptor *adaptor, - gboolean construct, - guint *n_params); - -void glade_widget_adaptor_post_create (GladeWidgetAdaptor *adaptor, - GObject *object, - GladeCreateReason reason); - -GObject *glade_widget_adaptor_get_internal_child (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *internal_name); - -void glade_widget_adaptor_set_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *property_name, - const GValue *value); - -void glade_widget_adaptor_get_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *property_name, - GValue *value); - -gboolean glade_widget_adaptor_verify_property (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *property_name, - const GValue *value); - -void glade_widget_adaptor_add (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child); - -void glade_widget_adaptor_remove (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child); - -GList *glade_widget_adaptor_get_children (GladeWidgetAdaptor *adaptor, - GObject *container); - -gboolean glade_widget_adaptor_has_child (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child); - -void glade_widget_adaptor_child_set_property (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child, - const gchar *property_name, - const GValue *value); - -void glade_widget_adaptor_child_get_property (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child, - const gchar *property_name, - GValue *value); - -gboolean glade_widget_adaptor_child_verify_property (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *child, - const gchar *property_name, - const GValue *value); - -void glade_widget_adaptor_replace_child (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *old_obj, - GObject *new_obj); - -gboolean glade_widget_adaptor_query (GladeWidgetAdaptor *adaptor); - -G_CONST_RETURN -gchar *glade_widget_adaptor_get_packing_default(GladeWidgetAdaptor *child_adaptor, - GladeWidgetAdaptor *parent_adaptor, - const gchar *propert_id); - -gboolean glade_widget_adaptor_is_container (GladeWidgetAdaptor *adaptor); - -gboolean glade_widget_adaptor_action_add (GladeWidgetAdaptor *adaptor, - const gchar *action_path, - const gchar *label, - const gchar *stock, - gboolean important); - -gboolean glade_widget_adaptor_pack_action_add (GladeWidgetAdaptor *adaptor, - const gchar *action_path, - const gchar *label, - const gchar *stock, - gboolean important); - -gboolean glade_widget_adaptor_action_remove (GladeWidgetAdaptor *adaptor, - const gchar *action_path); - -gboolean glade_widget_adaptor_pack_action_remove (GladeWidgetAdaptor *adaptor, - const gchar *action_path); - -GList *glade_widget_adaptor_pack_actions_new (GladeWidgetAdaptor *adaptor); - -void glade_widget_adaptor_action_activate (GladeWidgetAdaptor *adaptor, - GObject *object, - const gchar *action_path); - -void glade_widget_adaptor_child_action_activate (GladeWidgetAdaptor *adaptor, - GObject *container, - GObject *object, - const gchar *action_path); -G_END_DECLS - -#endif /* __GLADE_WIDGET_ADAPTOR_H__ */ diff --git a/gladeui/glade-widget.c b/gladeui/glade-widget.c deleted file mode 100644 index 892fe09b..00000000 --- a/gladeui/glade-widget.c +++ /dev/null @@ -1,4096 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2004 Joaquin Cuenca Abela - * Copyright (C) 2001, 2002, 2003 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Authors: - * Joaquin Cuenca Abela <e98cuenc@yahoo.com> - * Chema Celorio <chema@celorio.com> - * Tristan Van Berkom <tvb@gnome.org> - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> -#include <glib-object.h> -#include <gdk/gdkkeysyms.h> -#include <glib/gi18n-lib.h> -#include "glade.h" -#include "glade-accumulators.h" -#include "glade-project.h" -#include "glade-widget-adaptor.h" -#include "glade-widget.h" -#include "glade-marshallers.h" -#include "glade-property.h" -#include "glade-property-class.h" -#include "glade-placeholder.h" -#include "glade-signal.h" -#include "glade-popup.h" -#include "glade-editor.h" -#include "glade-app.h" -#include "glade-design-view.h" -#include "glade-widget-action.h" - - - -static void glade_widget_set_adaptor (GladeWidget *widget, - GladeWidgetAdaptor *adaptor); -static void glade_widget_set_properties (GladeWidget *widget, - GList *properties); -static GParameter *glade_widget_info_params (GladeWidgetAdaptor *adaptor, - GladeWidgetInfo *info, - gboolean construct, - guint *n_params); -static void glade_widget_fill_from_widget_info (GladeWidgetInfo *info, - GladeWidget *widget, - gboolean apply_props); -static GladeWidget *glade_widget_new_from_widget_info (GladeWidgetInfo *info, - GladeProject *project, - GladeWidget *parent); - -static gboolean glade_window_is_embedded (GtkWindow *window); -static void glade_widget_embed (GladeWidget *widget); - -enum -{ - ADD_SIGNAL_HANDLER, - REMOVE_SIGNAL_HANDLER, - CHANGE_SIGNAL_HANDLER, - BUTTON_PRESS_EVENT, - BUTTON_RELEASE_EVENT, - MOTION_NOTIFY_EVENT, - LAST_SIGNAL -}; - -enum -{ - PROP_0, - PROP_NAME, - PROP_INTERNAL, - PROP_ANARCHIST, - PROP_OBJECT, - PROP_ADAPTOR, - PROP_PROJECT, - PROP_PROPERTIES, - PROP_PARENT, - PROP_INTERNAL_NAME, - PROP_TEMPLATE, - PROP_INFO, - PROP_REASON, - PROP_TOPLEVEL_WIDTH, - PROP_TOPLEVEL_HEIGHT -}; - -static guint glade_widget_signals[LAST_SIGNAL] = {0}; -static GObjectClass *parent_class = NULL; - -/* Sometimes we need to use the project deep in the loading code, - * this is just a shortcut way to get the project. - */ -static GladeProject *loading_project = NULL; -static GQuark glade_widget_name_quark = 0; - -/******************************************************************************* - GladeWidget class methods - *******************************************************************************/ -static void -glade_widget_set_packing_actions (GladeWidget *widget, GladeWidget *parent) -{ - if (widget->packing_actions) - { - g_list_foreach (widget->packing_actions, (GFunc)g_object_unref, NULL); - g_list_free (widget->packing_actions); - widget->packing_actions = NULL; - } - - if (parent->adaptor->packing_actions) - widget->packing_actions = glade_widget_adaptor_pack_actions_new (parent->adaptor); -} - -static void -glade_widget_add_child_impl (GladeWidget *widget, - GladeWidget *child, - gboolean at_mouse) -{ - /* Safe to set the parent first... setting it afterwards - * creates packing properties, and that is not always - * desirable. - */ - glade_widget_set_parent (child, widget); - - glade_widget_adaptor_add - (widget->adaptor, widget->object, child->object); - - glade_widget_set_packing_properties (child, widget); - glade_widget_set_packing_actions (child, widget); -} - -static void -glade_widget_remove_child_impl (GladeWidget *widget, - GladeWidget *child) -{ - glade_widget_adaptor_remove - (widget->adaptor, widget->object, child->object); -} - -static void -glade_widget_replace_child_impl (GladeWidget *widget, - GObject *old_object, - GObject *new_object) -{ - GladeWidget *gnew_widget = glade_widget_get_from_gobject (new_object); - GladeWidget *gold_widget = glade_widget_get_from_gobject (old_object); - - if (gnew_widget) gnew_widget->parent = widget; - if (gold_widget && gold_widget != gnew_widget) - gold_widget->parent = NULL; - - glade_widget_adaptor_replace_child - (widget->adaptor, widget->object, - old_object, new_object); - - /* Setup packing properties here so we can introspect the new - * values from the backend. - */ - if (gnew_widget) - { - glade_widget_set_packing_properties (gnew_widget, widget); - glade_widget_set_packing_actions (gnew_widget, widget); - } -} - -static void -glade_widget_add_signal_handler_impl (GladeWidget *widget, GladeSignal *signal_handler) -{ - GPtrArray *signals; - GladeSignal *new_signal_handler; - - g_return_if_fail (GLADE_IS_WIDGET (widget)); - g_return_if_fail (GLADE_IS_SIGNAL (signal_handler)); - - signals = glade_widget_list_signal_handlers (widget, signal_handler->name); - if (!signals) - { - signals = g_ptr_array_new (); - g_hash_table_insert (widget->signals, g_strdup (signal_handler->name), signals); - } - - new_signal_handler = glade_signal_clone (signal_handler); - g_ptr_array_add (signals, new_signal_handler); -} - -static void -glade_widget_remove_signal_handler_impl (GladeWidget *widget, GladeSignal *signal_handler) -{ - GPtrArray *signals; - GladeSignal *tmp_signal_handler; - guint i; - - g_return_if_fail (GLADE_IS_WIDGET (widget)); - g_return_if_fail (GLADE_IS_SIGNAL (signal_handler)); - - signals = glade_widget_list_signal_handlers (widget, signal_handler->name); - - /* trying to remove an inexistent signal? */ - g_assert (signals); - - for (i = 0; i < signals->len; i++) - { - tmp_signal_handler = g_ptr_array_index (signals, i); - if (glade_signal_equal (tmp_signal_handler, signal_handler)) - { - glade_signal_free (tmp_signal_handler); - g_ptr_array_remove_index (signals, i); - break; - } - } -} - -static void -glade_widget_change_signal_handler_impl (GladeWidget *widget, - GladeSignal *old_signal_handler, - GladeSignal *new_signal_handler) -{ - GPtrArray *signals; - GladeSignal *tmp_signal_handler; - guint i; - - g_return_if_fail (GLADE_IS_WIDGET (widget)); - g_return_if_fail (GLADE_IS_SIGNAL (old_signal_handler)); - g_return_if_fail (GLADE_IS_SIGNAL (new_signal_handler)); - g_return_if_fail (strcmp (old_signal_handler->name, new_signal_handler->name) == 0); - - signals = glade_widget_list_signal_handlers (widget, old_signal_handler->name); - - /* trying to remove an inexistent signal? */ - g_assert (signals); - - for (i = 0; i < signals->len; i++) - { - tmp_signal_handler = g_ptr_array_index (signals, i); - if (glade_signal_equal (tmp_signal_handler, old_signal_handler)) - { - if (strcmp (old_signal_handler->handler, - new_signal_handler->handler) != 0) - { - g_free (tmp_signal_handler->handler); - tmp_signal_handler->handler = - g_strdup (new_signal_handler->handler); - } - - /* Handler */ - if (tmp_signal_handler->handler) - g_free (tmp_signal_handler->handler); - tmp_signal_handler->handler = - g_strdup (new_signal_handler->handler); - - /* Object */ - if (tmp_signal_handler->userdata) - g_free (tmp_signal_handler->userdata); - tmp_signal_handler->userdata = - g_strdup (new_signal_handler->userdata); - - tmp_signal_handler->after = new_signal_handler->after; - tmp_signal_handler->lookup = new_signal_handler->lookup; - break; - } - } -} - - -static gboolean -glade_widget_button_press_event_impl (GladeWidget *gwidget, - GdkEvent *base_event) -{ - GtkWidget *widget; - GdkEventButton *event = (GdkEventButton *)base_event; - gboolean handled = FALSE; - - /* make sure to grab focus, since we may stop default handlers */ - widget = GTK_WIDGET (glade_widget_get_object (gwidget)); - if (GTK_WIDGET_CAN_FOCUS (widget) && !GTK_WIDGET_HAS_FOCUS (widget)) - gtk_widget_grab_focus (widget); - - /* if it's already selected don't stop default handlers, e.g. toggle button */ - if (event->button == 1) - { - if (event->state & GDK_CONTROL_MASK) - { - if (glade_project_is_selected (gwidget->project, - gwidget->object)) - glade_app_selection_remove - (gwidget->object, TRUE); - else - glade_app_selection_add - (gwidget->object, TRUE); - handled = TRUE; - } - else if (glade_project_is_selected (gwidget->project, - gwidget->object) == FALSE) - { - glade_util_clear_selection (); - glade_app_selection_set - (gwidget->object, TRUE); - - /* Add selection without interrupting event flow - * when shift is down, this allows better behaviour - * for GladeFixed children - */ - handled = !(event->state & GDK_SHIFT_MASK); - } - } - else if (event->button == 3) - { - glade_popup_widget_pop (gwidget, event, TRUE); - handled = TRUE; - } - - return handled; -} - -static gboolean -glade_widget_event_impl (GladeWidget *gwidget, - GdkEvent *event) -{ - gboolean handled = FALSE; - - g_return_val_if_fail (GLADE_IS_WIDGET (gwidget), FALSE); - - switch (event->type) - { - case GDK_BUTTON_PRESS: - g_signal_emit (gwidget, - glade_widget_signals[BUTTON_PRESS_EVENT], 0, - event, &handled); - break; - case GDK_BUTTON_RELEASE: - g_signal_emit (gwidget, - glade_widget_signals[BUTTON_RELEASE_EVENT], 0, - event, &handled); - break; - case GDK_MOTION_NOTIFY: - g_signal_emit (gwidget, - glade_widget_signals[MOTION_NOTIFY_EVENT], 0, - event, &handled); - break; - case GDK_EXPOSE: - case GDK_CONFIGURE: - glade_util_queue_draw_nodes (((GdkEventExpose*) event)->window); - break; - default: - break; - } - - return handled; -} - - -/** - * glade_widget_event: - * @event: A #GdkEvent - * - * Feed an event to be handled on the project GladeWidget - * hierarchy. - * - * Returns whether the event was handled or not. - */ -gboolean -glade_widget_event (GladeWidget *gwidget, - GdkEvent *event) -{ - gboolean handled = FALSE; - - /* Lets just avoid some synthetic events (like focus-change) */ - if (((GdkEventAny *)event)->window == NULL) return FALSE; - - handled = GLADE_WIDGET_GET_CLASS (gwidget)->event (gwidget, event); - -#if 0 - if (event->type != GDK_EXPOSE) - g_print ("event widget '%s' handled '%d' event '%d'\n", - gwidget->name, handled, event->type); -#endif - - return handled; -} - -/******************************************************************************* - GObjectClass & Object Construction - *******************************************************************************/ - -/* - * This function creates new GObject parameters based on the GType of the - * GladeWidgetAdaptor and its default values. - * - * If a GladeWidget is specified, it will be used to apply the - * values currently in use. - */ -static GParameter * -glade_widget_template_params (GladeWidget *widget, - gboolean construct, - guint *n_params) -{ - GladeWidgetAdaptor *klass; - GArray *params; - GObjectClass *oclass; - GParamSpec **pspec; - GladeProperty *glade_property; - GladePropertyClass *pclass; - guint n_props, i; - - g_return_val_if_fail (GLADE_IS_WIDGET (widget), NULL); - g_return_val_if_fail (n_params != NULL, NULL); - - klass = widget->adaptor; - - /* As a slight optimization, we never unref the class - */ - oclass = g_type_class_ref (klass->type); - pspec = g_object_class_list_properties (oclass, &n_props); - params = g_array_new (FALSE, FALSE, sizeof (GParameter)); - - for (i = 0; i < n_props; i++) - { - GParameter parameter = { 0, }; - - if ((glade_property = - glade_widget_get_property (widget, pspec[i]->name)) == NULL) - continue; - - pclass = glade_property->klass; - - /* Ignore properties based on some criteria - */ - if (pclass == NULL || /* Unaccounted for in the builder */ - pclass->virt || /* should not be set before - GladeWidget wrapper exists */ - pclass->ignore) /* Catalog explicitly ignores the object */ - continue; - - if (construct && - (pspec[i]->flags & - (G_PARAM_CONSTRUCT|G_PARAM_CONSTRUCT_ONLY)) == 0) - continue; - else if (!construct && - (pspec[i]->flags & - (G_PARAM_CONSTRUCT|G_PARAM_CONSTRUCT_ONLY)) != 0) - continue; - - if (g_value_type_compatible (G_VALUE_TYPE (pclass->def), - pspec[i]->value_type) == FALSE) - { - g_critical ("Type mismatch on %s property of %s", - parameter.name, klass->name); - continue; - } - - if (g_param_values_cmp (pspec[i], - glade_property->value, - pclass->orig_def) == 0) - continue; - - - parameter.name = pspec[i]->name; /* These are not copied/freed */ - g_value_init (¶meter.value, pspec[i]->value_type); - g_value_copy (glade_property->value, ¶meter.value); - - g_array_append_val (params, parameter); - } - g_free (pspec); - - *n_params = params->len; - return (GParameter *)g_array_free (params, FALSE); -} - -static void -free_params (GParameter *params, guint n_params) -{ - gint i; - for (i = 0; i < n_params; i++) - g_value_unset (&(params[i].value)); - g_free (params); - -} - -static GObject * -glade_widget_build_object (GladeWidgetAdaptor *adaptor, GladeWidget *widget, GladeWidgetInfo *info) -{ - GParameter *params; - GObject *object; - guint n_params, i; - - if (widget) - params = glade_widget_template_params (widget, TRUE, &n_params); - else if (info) - params = glade_widget_info_params (adaptor, info, TRUE, &n_params); - else - params = glade_widget_adaptor_default_params (adaptor, TRUE, &n_params); - - /* Create the new object with the correct parameters. - */ - object = g_object_newv (adaptor->type, n_params, params); - - free_params (params, n_params); - - if (widget) - params = glade_widget_template_params (widget, FALSE, &n_params); - else if (info) - params = glade_widget_info_params (adaptor, info, FALSE, &n_params); - else - params = glade_widget_adaptor_default_params (adaptor, FALSE, &n_params); - - for (i = 0; i < n_params; i++) - { - g_object_set_property (object, params[i].name, &(params[i].value)); - } - - free_params (params, n_params); - - return object; -} - -/** - * glade_widget_dup_properties: - * @template_props: the #GladeProperty list to copy - * @as_load: whether to behave as if loading the project - * - * Copies a list of properties, if @as_load is specified, then - * properties that are not saved to the glade file are ignored. - * - * Returns: A newly allocated #GList of new #GladeProperty objects. - */ -GList * -glade_widget_dup_properties (GList *template_props, gboolean as_load) -{ - GList *list, *properties = NULL; - - for (list = template_props; list && list->data; list = list->next) - { - GladeProperty *prop = list->data; - - if (prop->klass->save == FALSE && as_load) - continue; - - properties = g_list_prepend (properties, glade_property_dup (prop, NULL)); - } - return g_list_reverse (properties); -} - -/** - * glade_widget_remove_property: - * @widget: A #GladeWidget - * @id_property: the name of the property - * - * Removes the #GladeProperty indicated by @id_property - * from @widget (this is intended for use in the plugin, to - * remove properties from composite children that dont make - * sence to allow the user to specify, notably - properties - * that are proxied through the composite widget's properties or - * style properties). - */ -void -glade_widget_remove_property (GladeWidget *widget, - const gchar *id_property) -{ - GladeProperty *prop; - - g_return_if_fail (GLADE_IS_WIDGET (widget)); - g_return_if_fail (id_property); - - if ((prop = glade_widget_get_property (widget, id_property)) != NULL) - { - widget->properties = g_list_remove (widget->properties, prop); - g_object_unref (prop); - } - else - g_critical ("Couldnt find property %s on widget %s\n", - id_property, widget->name); -} - -static void -glade_widget_set_catalog_defaults (GList *list) -{ - GList *l; - for (l = list; l && l->data; l = l->next) - { - GladeProperty *prop = l->data; - GladePropertyClass *klass = prop->klass; - - if (glade_property_equals_value (prop, klass->orig_def) && - g_param_values_cmp (klass->pspec, klass->orig_def, klass->def)) - glade_property_reset (prop); - } -} - -static void -glade_widget_sync_custom_props (GladeWidget *widget) -{ - GList *l; - for (l = widget->properties; l && l->data; l = l->next) - { - GladeProperty *prop = GLADE_PROPERTY(l->data); - - /* XXX We need a better option to this hack. - * - * This used to be based on whether a function was - * provided by the backend to treat the said property, now - * that function is classwide so we dont know, so currently - * we are just syncing all properties for the sake of those - * properties. - */ - if (!prop->klass->construct_only) - glade_property_sync (prop); - - } -} - -static void -glade_widget_sync_packing_props (GladeWidget *widget) -{ - GList *l; - for (l = widget->packing_properties; l && l->data; l = l->next) { - GladeProperty *prop = GLADE_PROPERTY(l->data); - glade_property_sync (prop); - } -} - - -static GObject * -glade_widget_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties) -{ - GladeWidget *gwidget; - GObject *ret_obj, *object; - GList *properties = NULL, *list; - - ret_obj = G_OBJECT_CLASS (parent_class)->constructor - (type, n_construct_properties, construct_properties); - - gwidget = GLADE_WIDGET (ret_obj); - - if (gwidget->name == NULL) - { - if (gwidget->internal) - { - gchar *name_base = g_strdup_printf ("%s-%s", - gwidget->construct_internal, - gwidget->internal); - - if (gwidget->project) - { - gwidget->name = - glade_project_new_widget_name (gwidget->project, - name_base); - g_free (name_base); - } - else - gwidget->name = name_base; - - } - else if (gwidget->project) - gwidget->name = glade_project_new_widget_name - (GLADE_PROJECT (gwidget->project), - gwidget->adaptor->generic_name); - else - gwidget->name = - g_strdup (gwidget->adaptor->generic_name); - } - - if (gwidget->construct_template) - { - properties = glade_widget_dup_properties - (gwidget->construct_template->properties, FALSE); - - glade_widget_set_properties (gwidget, properties); - } - - if (gwidget->object == NULL) - { - object = glade_widget_build_object(gwidget->adaptor, - gwidget->construct_template, - gwidget->construct_info); - glade_widget_set_object (gwidget, object); - } - - /* Setup width/height */ - gwidget->width = GWA_DEFAULT_WIDTH (gwidget->adaptor); - gwidget->height = GWA_DEFAULT_HEIGHT (gwidget->adaptor); - - /* Introspect object properties before passing it to post_create, - * but only when its freshly created (depend on glade file at - * load time and copying properties at dup time). - */ - if (gwidget->construct_reason == GLADE_CREATE_USER) - for (list = gwidget->properties; list; list = list->next) - glade_property_load (GLADE_PROPERTY (list->data)); - - /* We only use catalog defaults when the widget was created by the user! */ - if (gwidget->construct_reason == GLADE_CREATE_USER) - glade_widget_set_catalog_defaults (gwidget->properties); - - /* Only call this once the GladeWidget is completely built - * (but before calling custom handlers...) - */ - glade_widget_adaptor_post_create (gwidget->adaptor, - gwidget->object, - gwidget->construct_reason); - - /* Virtual properties need to be explicitly synchronized. - */ - if (gwidget->construct_reason == GLADE_CREATE_USER) - glade_widget_sync_custom_props (gwidget); - - if (gwidget->parent && gwidget->packing_properties == NULL) - glade_widget_set_packing_properties (gwidget, gwidget->parent); - - if (GTK_IS_WIDGET (gwidget->object) && !GTK_WIDGET_TOPLEVEL (gwidget->object)) - { - gwidget->visible = TRUE; - gtk_widget_show_all (GTK_WIDGET (gwidget->object)); - } - else if (GTK_IS_WIDGET (gwidget->object) == FALSE) - gwidget->visible = TRUE; - - return ret_obj; -} - -static void -glade_widget_finalize (GObject *object) -{ - GladeWidget *widget = GLADE_WIDGET (object); - - g_return_if_fail (GLADE_IS_WIDGET (object)); - - g_free (widget->name); - g_free (widget->internal); - g_hash_table_destroy (widget->signals); - - G_OBJECT_CLASS(parent_class)->finalize(object); -} - -static void -glade_widget_dispose (GObject *object) -{ - GladeWidget *widget = GLADE_WIDGET (object); - - g_return_if_fail (GLADE_IS_WIDGET (object)); - - /* We do not keep a reference to internal widgets */ - if (widget->internal == NULL) - { - if (GTK_IS_OBJECT (widget->object)) - gtk_object_destroy (GTK_OBJECT (widget->object)); - else - g_object_unref (widget->object); - } - - if (widget->properties) - { - g_list_foreach (widget->properties, (GFunc)g_object_unref, NULL); - g_list_free (widget->properties); - } - - if (widget->packing_properties) - { - g_list_foreach (widget->packing_properties, (GFunc)g_object_unref, NULL); - g_list_free (widget->packing_properties); - } - - if (widget->actions) - { - g_list_foreach (widget->actions, (GFunc)g_object_unref, NULL); - g_list_free (widget->actions); - } - - if (widget->packing_actions) - { - g_list_foreach (widget->packing_actions, (GFunc)g_object_unref, NULL); - g_list_free (widget->packing_actions); - } - - if (G_OBJECT_CLASS(parent_class)->dispose) - G_OBJECT_CLASS(parent_class)->dispose(object); -} - -static void -glade_widget_set_real_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - GladeWidget *widget; - - widget = GLADE_WIDGET (object); - - switch (prop_id) - { - case PROP_NAME: - glade_widget_set_name (widget, g_value_get_string (value)); - break; - case PROP_INTERNAL: - glade_widget_set_internal (widget, g_value_get_string (value)); - break; - case PROP_ANARCHIST: - widget->anarchist = g_value_get_boolean (value); - break; - case PROP_OBJECT: - if (g_value_get_object (value)) - glade_widget_set_object (widget, g_value_get_object (value)); - break; - case PROP_PROJECT: - glade_widget_set_project (widget, GLADE_PROJECT (g_value_get_object (value))); - break; - case PROP_ADAPTOR: - glade_widget_set_adaptor (widget, GLADE_WIDGET_ADAPTOR - (g_value_get_object (value))); - break; - case PROP_PROPERTIES: - glade_widget_set_properties (widget, (GList *)g_value_get_pointer (value)); - break; - case PROP_PARENT: - glade_widget_set_parent (widget, GLADE_WIDGET (g_value_get_object (value))); - break; - case PROP_INTERNAL_NAME: - if (g_value_get_string (value)) - widget->construct_internal = g_value_dup_string (value); - break; - case PROP_TEMPLATE: - widget->construct_template = g_value_get_object (value); - break; - case PROP_INFO: - widget->construct_info = g_value_get_pointer (value); - break; - case PROP_REASON: - widget->construct_reason = g_value_get_int (value); - break; - case PROP_TOPLEVEL_WIDTH: - widget->width = g_value_get_int (value); - break; - case PROP_TOPLEVEL_HEIGHT: - widget->height = g_value_get_int (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -glade_widget_get_real_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - GladeWidget *widget; - - widget = GLADE_WIDGET (object); - - switch (prop_id) - { - case PROP_NAME: - g_value_set_string (value, widget->name); - break; - case PROP_INTERNAL: - g_value_set_string (value, widget->internal); - break; - case PROP_ANARCHIST: - g_value_set_boolean (value, widget->anarchist); - break; - case PROP_ADAPTOR: - g_value_set_object (value, widget->adaptor); - break; - case PROP_PROJECT: - g_value_set_object (value, G_OBJECT (widget->project)); - break; - case PROP_OBJECT: - g_value_set_object (value, widget->object); - break; - case PROP_PROPERTIES: - g_value_set_pointer (value, widget->properties); - break; - case PROP_PARENT: - g_value_set_object (value, widget->parent); - break; - case PROP_TOPLEVEL_WIDTH: - g_value_set_int (value, widget->width); - break; - case PROP_TOPLEVEL_HEIGHT: - g_value_set_int (value, widget->height); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -free_signals (gpointer value) -{ - GPtrArray *signals = (GPtrArray*) value; - guint i; - guint nb_signals; - - if (signals == NULL) - return; - - /* g_ptr_array_foreach (signals, (GFunc) glade_signal_free, NULL); - * only available in modern versions of Gtk+ */ - nb_signals = signals->len; - for (i = 0; i < nb_signals; i++) - glade_signal_free (g_ptr_array_index (signals, i)); - - g_ptr_array_free (signals, TRUE); -} - -static void -glade_widget_init (GladeWidget *widget) -{ - widget->adaptor = NULL; - widget->project = NULL; - widget->name = NULL; - widget->internal = NULL; - widget->object = NULL; - widget->properties = NULL; - widget->packing_properties = NULL; - widget->prop_refs = NULL; - widget->prop_refs_readonly = FALSE; - widget->signals = g_hash_table_new_full - (g_str_hash, g_str_equal, - (GDestroyNotify) g_free, - (GDestroyNotify) free_signals); - - /* Initial invalid values */ - widget->width = -1; - widget->height = -1; -} - -static void -glade_widget_class_init (GladeWidgetClass *klass) -{ - GObjectClass *object_class; - - if (glade_widget_name_quark == 0) - glade_widget_name_quark = - g_quark_from_static_string ("GladeWidgetDataTag"); - - object_class = G_OBJECT_CLASS (klass); - parent_class = g_type_class_peek_parent (klass); - - object_class->constructor = glade_widget_constructor; - object_class->finalize = glade_widget_finalize; - object_class->dispose = glade_widget_dispose; - object_class->set_property = glade_widget_set_real_property; - object_class->get_property = glade_widget_get_real_property; - - klass->add_child = glade_widget_add_child_impl; - klass->remove_child = glade_widget_remove_child_impl; - klass->replace_child = glade_widget_replace_child_impl; - klass->event = glade_widget_event_impl; - - klass->add_signal_handler = glade_widget_add_signal_handler_impl; - klass->remove_signal_handler = glade_widget_remove_signal_handler_impl; - klass->change_signal_handler = glade_widget_change_signal_handler_impl; - - klass->button_press_event = glade_widget_button_press_event_impl; - klass->button_release_event = NULL; - klass->motion_notify_event = NULL; - - g_object_class_install_property - (object_class, PROP_NAME, - g_param_spec_string ("name", _("Name"), - _("The name of the widget"), - NULL, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); - - g_object_class_install_property - (object_class, PROP_INTERNAL, - g_param_spec_string ("internal", _("Internal name"), - _("The internal name of the widget"), - NULL, G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); - - g_object_class_install_property - (object_class, PROP_ANARCHIST, - g_param_spec_boolean ("anarchist", _("Anarchist"), - _("Whether this composite child is " - "an ancestral child or an anarchist child"), - FALSE, G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY)); - - g_object_class_install_property - (object_class, PROP_OBJECT, - g_param_spec_object ("object", _("Object"), - _("The object associated"), - G_TYPE_OBJECT, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); - - g_object_class_install_property - (object_class, PROP_ADAPTOR, - g_param_spec_object ("adaptor", _("Adaptor"), - _("The class adaptor for the associated widget"), - GLADE_TYPE_WIDGET_ADAPTOR, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY)); - - g_object_class_install_property - (object_class, PROP_PROJECT, - g_param_spec_object ("project", _("Project"), - _("The glade project that " - "this widget belongs to"), - GLADE_TYPE_PROJECT, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); - - g_object_class_install_property - (object_class, PROP_PROPERTIES, - g_param_spec_pointer ("properties", _("Properties"), - _("A list of GladeProperties"), - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT_ONLY)); - - g_object_class_install_property - (object_class, PROP_PARENT, - g_param_spec_object ("parent", _("Parent"), - _("A pointer to the parenting GladeWidget"), - GLADE_TYPE_WIDGET, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); - - g_object_class_install_property - (object_class, PROP_INTERNAL_NAME, - g_param_spec_string ("internal-name", _("Internal Name"), - _("A generic name prefix for internal widgets"), - NULL, G_PARAM_CONSTRUCT_ONLY|G_PARAM_WRITABLE)); - - g_object_class_install_property - (object_class, PROP_TEMPLATE, - g_param_spec_object ("template", _("Template"), - _("A GladeWidget template to base a new widget on"), - GLADE_TYPE_WIDGET, - G_PARAM_CONSTRUCT_ONLY|G_PARAM_WRITABLE)); - - g_object_class_install_property - (object_class, PROP_INFO, - g_param_spec_pointer ("info", _("Info"), - _("A GladeWidgetInfo struct to base a new widget on"), - G_PARAM_CONSTRUCT_ONLY|G_PARAM_WRITABLE)); - - g_object_class_install_property - (object_class, PROP_REASON, - g_param_spec_int ("reason", _("Reason"), - _("A GladeCreateReason for this creation"), - GLADE_CREATE_USER, - GLADE_CREATE_REASONS - 1, - GLADE_CREATE_USER, - G_PARAM_CONSTRUCT_ONLY|G_PARAM_WRITABLE)); - - g_object_class_install_property - (object_class, PROP_TOPLEVEL_WIDTH, - g_param_spec_int ("toplevel-width", _("Toplevel Width"), - _("The width of the widget when toplevel in " - "the GladeDesignLayout"), - -1, - G_MAXINT, - -1, - G_PARAM_READWRITE)); - - g_object_class_install_property - (object_class, PROP_TOPLEVEL_HEIGHT, - g_param_spec_int ("toplevel-height", _("Toplevel Height"), - _("The height of the widget when toplevel in " - "the GladeDesignLayout"), - -1, - G_MAXINT, - -1, - G_PARAM_READWRITE)); - - /** - * GladeWidget::add-signal-handler: - * @gladewidget: the #GladeWidget which received the signal. - * @arg1: the #GladeSignal that was added to @gladewidget. - */ - glade_widget_signals[ADD_SIGNAL_HANDLER] = - g_signal_new ("add-signal-handler", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GladeWidgetClass, add_signal_handler), - NULL, NULL, - g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, - 1, - G_TYPE_POINTER); - - /** - * GladeWidget::remove-signal-handler: - * @gladewidget: the #GladeWidget which received the signal. - * @arg1: the #GladeSignal that was removed from @gladewidget. - */ - glade_widget_signals[REMOVE_SIGNAL_HANDLER] = - g_signal_new ("remove-signal-handler", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GladeWidgetClass, remove_signal_handler), - NULL, NULL, - g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, - 1, - G_TYPE_POINTER); - - - /** - * GladeWidget::change-signal-handler: - * @gladewidget: the #GladeWidget which received the signal. - * @arg1: the old #GladeSignal - * @arg2: the new #GladeSignal - */ - glade_widget_signals[CHANGE_SIGNAL_HANDLER] = - g_signal_new ("change-signal-handler", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GladeWidgetClass, change_signal_handler), - NULL, NULL, - glade_marshal_VOID__POINTER_POINTER, - G_TYPE_NONE, - 2, - G_TYPE_POINTER, G_TYPE_POINTER); - - - /** - * GladeWidget::button-press-event: - * @gladewidget: the #GladeWidget which received the signal. - * @arg1: the #GdkEvent - */ - glade_widget_signals[BUTTON_PRESS_EVENT] = - g_signal_new ("button-press-event", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GladeWidgetClass, button_press_event), - glade_boolean_handled_accumulator, NULL, - glade_marshal_BOOLEAN__BOXED, - G_TYPE_BOOLEAN, 1, - GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); - - /** - * GladeWidget::button-relese-event: - * @gladewidget: the #GladeWidget which received the signal. - * @arg1: the #GdkEvent - */ - glade_widget_signals[BUTTON_RELEASE_EVENT] = - g_signal_new ("button-release-event", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GladeWidgetClass, button_release_event), - glade_boolean_handled_accumulator, NULL, - glade_marshal_BOOLEAN__BOXED, - G_TYPE_BOOLEAN, 1, - GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); - - - /** - * GladeWidget::motion-notify-event: - * @gladewidget: the #GladeWidget which received the signal. - * @arg1: the #GdkEvent - */ - glade_widget_signals[MOTION_NOTIFY_EVENT] = - g_signal_new ("motion-notify-event", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GladeWidgetClass, motion_notify_event), - glade_boolean_handled_accumulator, NULL, - glade_marshal_BOOLEAN__BOXED, - G_TYPE_BOOLEAN, 1, - GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); -} - -GType -glade_widget_get_type (void) -{ - static GType widget_type = 0; - - if (!widget_type) - { - static const GTypeInfo widget_info = - { - sizeof (GladeWidgetClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) glade_widget_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (GladeWidget), - 0, /* n_preallocs */ - (GInstanceInitFunc) glade_widget_init, - }; - - widget_type = g_type_register_static (G_TYPE_OBJECT, "GladeWidget", - &widget_info, 0); - } - - return widget_type; -} - -/******************************************************************************* - Static stuff.... - *******************************************************************************/ -static void -glade_widget_copy_packing_props (GladeWidget *parent, - GladeWidget *child, - GladeWidget *template_widget) -{ - GladeProperty *dup_prop, *orig_prop; - GList *l; - - g_return_if_fail (child->parent == parent); - - glade_widget_set_packing_properties (child, parent); - - for (l = child->packing_properties; l && l->data; l = l->next) - { - dup_prop = GLADE_PROPERTY(l->data); - orig_prop = - glade_widget_get_property (template_widget, dup_prop->klass->id); - glade_property_set_value (dup_prop, orig_prop->value); - } -} - -static void -glade_widget_set_default_packing_properties (GladeWidget *container, - GladeWidget *child) -{ - GladePropertyClass *property_class; - GList *l; - - for (l = container->adaptor->packing_props; l; l = l->next) - { - const gchar *def; - GValue *value; - - property_class = l->data; - - if ((def = - glade_widget_adaptor_get_packing_default - (child->adaptor, container->adaptor, property_class->id)) == NULL) - continue; - - value = glade_property_class_make_gvalue_from_string (property_class, - def, - child->project); - - glade_widget_child_set_property (container, child, - property_class->id, value); - g_value_unset (value); - g_free (value); - } -} - -/** - * When looking for an internal child we have to walk up the hierarchy... - */ -static GObject * -glade_widget_get_internal_child (GladeWidget *parent, - const gchar *internal) -{ - while (parent) - { - GladeWidgetAdaptorClass *adaptor_class = - GLADE_WIDGET_ADAPTOR_GET_CLASS (parent->adaptor); - - if (adaptor_class->get_internal_child) - return glade_widget_adaptor_get_internal_child - (parent->adaptor, parent->object, internal); - - parent = glade_widget_get_parent (parent); - } - return NULL; -} - -static GladeGetInternalFunc -glade_widget_get_internal_func (GladeWidget *parent, GladeWidget **parent_ret) -{ - GladeWidget *gwidget; - - g_return_val_if_fail (GLADE_IS_WIDGET (parent), NULL); - - for (gwidget = parent; gwidget; gwidget = gwidget->parent) - { - GladeWidgetAdaptorClass *adaptor_class = - GLADE_WIDGET_ADAPTOR_GET_CLASS (gwidget->adaptor); - - if (adaptor_class->get_internal_child) - { - if (parent_ret) *parent_ret = gwidget; - return adaptor_class->get_internal_child; - } - } - g_error ("No internal child search function " - "provided for widget class %s (or any parents)", - parent->adaptor->name); - - return NULL; -} - - -static GladeWidget * -glade_widget_dup_internal (GladeWidget *parent, - GladeWidget *template_widget, - gboolean exact) -{ - GladeGetInternalFunc get_internal; - GladeWidget *gwidget = NULL, *internal_parent; - GList *list, *children; - GtkWidget *placeholder; - gchar *child_type; - - g_return_val_if_fail (template_widget != NULL && GLADE_IS_WIDGET(template_widget), NULL); - g_return_val_if_fail (parent == NULL || GLADE_IS_WIDGET (parent), NULL); - - /* Dont actually duplicate internal widgets, but recurse through them anyway. */ - if (template_widget->internal) - { - GObject *internal_object = NULL; - - if (parent && - (get_internal = - glade_widget_get_internal_func (parent, &internal_parent)) != NULL) - { - /* We cant use "parent" here, we have to recurse up the hierarchy to find - * the "parent" that has `get_internal_child' support (i.e. internal children - * may have depth). - */ - internal_object = get_internal (internal_parent->adaptor, - internal_parent->object, - template_widget->internal); - g_assert (internal_object); - - gwidget = glade_widget_get_from_gobject (internal_object); - g_assert (gwidget); - } - } - else - { - gchar *name; - - if (exact) - name = g_strdup (template_widget->name); - else - name = glade_project_new_widget_name (template_widget->project, - template_widget->name); - - gwidget = glade_widget_adaptor_create_widget - (template_widget->adaptor, FALSE, - "name", name, - "parent", parent, - "project", template_widget->project, - "template", template_widget, - "reason", GLADE_CREATE_COPY, NULL); - g_free (name); - } - - /* Copy signals over here regardless of internal or not... */ - if (exact) - glade_widget_copy_signals (gwidget, template_widget); - - if ((children = - glade_widget_adaptor_get_children (template_widget->adaptor, - template_widget->object)) != NULL) - { - for (list = children; list && list->data; list = list->next) - { - GObject *child = G_OBJECT (list->data); - GladeWidget *child_gwidget, *child_dup; - - child_type = g_object_get_data (child, "special-child-type"); - - if ((child_gwidget = glade_widget_get_from_gobject (child)) == NULL) - { - /* Bring the placeholders along ... - * but not unmarked internal children */ - if (GLADE_IS_PLACEHOLDER (child)) - { - placeholder = glade_placeholder_new (); - - g_object_set_data_full (G_OBJECT (placeholder), - "special-child-type", - g_strdup (child_type), - g_free); - - glade_widget_adaptor_add (gwidget->adaptor, - gwidget->object, - G_OBJECT (placeholder)); - } - } - else - { - /* Recurse through every GladeWidget (internal or not) */ - child_dup = glade_widget_dup_internal (gwidget, child_gwidget, exact); - - if (child_gwidget->internal == NULL) - { - g_object_set_data_full (child_dup->object, - "special-child-type", - g_strdup (child_type), - g_free); - - glade_widget_add_child (gwidget, child_dup, FALSE); - } - - /* Internal children that are not heirarchic children - * need to avoid copying these packing props (like popup windows - * created on behalf of composite widgets). - */ - if (glade_widget_adaptor_has_child (gwidget->adaptor, - gwidget->object, - child_dup->object)) - glade_widget_copy_packing_props (gwidget, - child_dup, - child_gwidget); - } - } - g_list_free (children); - } - - if (gwidget->internal) - glade_widget_copy_properties (gwidget, template_widget); - - if (gwidget->packing_properties == NULL) - gwidget->packing_properties = glade_widget_dup_properties (template_widget->packing_properties , FALSE); - - /* If custom properties are still at thier - * default value, they need to be synced. - */ - glade_widget_sync_custom_props (gwidget); - - /* Special case GtkWindow here and ensure the pasted window - * has the same size as the 'Cut' one. - */ - if (GTK_IS_WINDOW (gwidget->object)) - { - gint width, height; - g_assert (GTK_IS_WINDOW (template_widget->object)); - - gtk_window_get_size (GTK_WINDOW (template_widget->object), - &width, &height); - gtk_window_resize (GTK_WINDOW (gwidget->object), - width, height); - } - - return gwidget; -} - - -typedef struct { - GladeWidget *widget; - GtkWidget *placeholder; - GList *properties; - - gchar *internal_name; - GList *internal_list; -} GladeChildExtract; - -static GList * -glade_widget_extract_children (GladeWidget *gwidget) -{ - GladeChildExtract *extract; - GList *extract_list = NULL; - GList *children, *list; - - children = glade_widget_adaptor_get_children - (gwidget->adaptor, gwidget->object); - - for (list = children; list && list->data; list = list->next) - { - GObject *child = G_OBJECT(list->data); - GladeWidget *gchild = glade_widget_get_from_gobject (child); -#if 0 - g_print ("Extracting %s from %s\n", - gchild ? gchild->name : - GLADE_IS_PLACEHOLDER (child) ? "placeholder" : "unknown widget", - gwidget->name); -#endif - if (gchild && gchild->internal) - { - /* Recurse and collect any deep child hierarchies - * inside composite widgets. - */ - extract = g_new0 (GladeChildExtract, 1); - extract->internal_name = g_strdup (gchild->internal); - extract->internal_list = glade_widget_extract_children (gchild); - extract->properties = - glade_widget_dup_properties (gchild->properties, TRUE); - - extract_list = g_list_prepend (extract_list, extract); - - } - else if (gchild || GLADE_IS_PLACEHOLDER (child)) - { - extract = g_new0 (GladeChildExtract, 1); - - if (gchild) - { - extract->widget = g_object_ref (gchild); - - /* Make copies of the packing properties - */ - extract->properties = - glade_widget_dup_properties - (gchild->packing_properties, TRUE); - - glade_widget_remove_child (gwidget, gchild); - } - else - { - /* need to handle placeholders by hand here */ - extract->placeholder = g_object_ref (child); - glade_widget_adaptor_remove (gwidget->adaptor, - gwidget->object, child); - } - extract_list = - g_list_prepend (extract_list, extract); - } - } - - if (children) - g_list_free (children); - - return g_list_reverse (extract_list); -} - -static void -glade_widget_insert_children (GladeWidget *gwidget, GList *children) -{ - GladeChildExtract *extract; - GladeWidget *gchild; - GObject *internal_object; - GList *list, *l; - - for (list = children; list; list = list->next) - { - extract = list->data; - - if (extract->internal_name) - { - GladeGetInternalFunc get_internal; - GladeWidget *internal_parent; - - - /* Recurse and add deep widget hierarchies to internal - * widgets. - */ - get_internal = glade_widget_get_internal_func - (gwidget, &internal_parent); - - internal_object = get_internal (internal_parent->adaptor, - internal_parent->object, - extract->internal_name); - - gchild = glade_widget_get_from_gobject (internal_object); - - /* This will free the list... */ - glade_widget_insert_children (gchild, extract->internal_list); - - /* Set the properties after inserting the children */ - for (l = extract->properties; l; l = l->next) - { - GValue value = { 0, }; - GladeProperty *saved_prop = l->data; - GladeProperty *widget_prop = - glade_widget_get_property (gchild, - saved_prop->klass->id); - - glade_property_get_value (saved_prop, &value); - glade_property_set_value (widget_prop, &value); - g_value_unset (&value); - - /* Free them as we go ... */ - g_object_unref (saved_prop); - } - - if (extract->properties) - g_list_free (extract->properties); - - g_free (extract->internal_name); - } - else if (extract->widget) - { - glade_widget_add_child (gwidget, extract->widget, FALSE); - g_object_unref (extract->widget); - - for (l = extract->properties; l; l = l->next) - { - GValue value = { 0, }; - GladeProperty *saved_prop = l->data; - GladeProperty *widget_prop = - glade_widget_get_pack_property (extract->widget, - saved_prop->klass->id); - - glade_property_get_value (saved_prop, &value); - glade_property_set_value (widget_prop, &value); - g_value_unset (&value); - - /* Free them as we go ... */ - g_object_unref (saved_prop); - } - if (extract->properties) - g_list_free (extract->properties); - } - else - { - glade_widget_adaptor_add (gwidget->adaptor, - gwidget->object, - G_OBJECT (extract->placeholder)); - g_object_unref (extract->placeholder); - } - g_free (extract); - } - - if (children) - g_list_free (children); -} - -static void -glade_widget_set_properties (GladeWidget *widget, GList *properties) -{ - GladeProperty *property; - GList *list; - - if (properties) - { - if (widget->properties) - { - g_list_foreach (widget->properties, (GFunc)g_object_unref, NULL); - g_list_free (widget->properties); - } - widget->properties = properties; - - for (list = properties; list; list = list->next) - { - property = list->data; - - property->widget = widget; - } - } -} - -static void -glade_widget_set_actions (GladeWidget *widget, GladeWidgetAdaptor *adaptor) -{ - GList *l; - - for (l = adaptor->actions; l; l = g_list_next (l)) - { - GWActionClass *action = l->data; - GObject *obj = g_object_new (GLADE_TYPE_WIDGET_ACTION, - "class", action, NULL); - - widget->actions = g_list_prepend (widget->actions, - GLADE_WIDGET_ACTION (obj)); - } - widget->actions = g_list_reverse (widget->actions); -} - -static void -glade_widget_set_adaptor (GladeWidget *widget, GladeWidgetAdaptor *adaptor) -{ - GladePropertyClass *property_class; - GladeProperty *property; - GList *list; - - g_return_if_fail (GLADE_IS_WIDGET (widget)); - g_return_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor)); - /* calling set_class out of the constructor? */ - g_return_if_fail (widget->adaptor == NULL); - - widget->adaptor = adaptor; - - /* If we have no properties; we are not in the process of loading - */ - if (!widget->properties) - { - for (list = adaptor->properties; list; list = list->next) - { - property_class = GLADE_PROPERTY_CLASS(list->data); - if ((property = glade_property_new (property_class, - widget, NULL)) == NULL) - { - g_warning ("Failed to create [%s] property", - property_class->id); - continue; - } - - widget->properties = g_list_prepend (widget->properties, property); - } - widget->properties = g_list_reverse (widget->properties); - } - - /* Create actions from adaptor */ - glade_widget_set_actions (widget, adaptor); -} - -/* Connects a signal handler to the 'event' signal for a widget and - all its children recursively. We need this to draw the selection - rectangles and to get button press/release events reliably. */ -static void -glade_widget_connect_signal_handlers (GtkWidget *widget_gtk, - GCallback callback, - GladeWidget *gwidget) -{ - GList *children, *list; - - /* Check if we've already connected an event handler. */ - if (!g_object_get_data (G_OBJECT (widget_gtk), - GLADE_TAG_EVENT_HANDLER_CONNECTED)) - { - /* Make sure we can recieve the kind of events we're - * connecting for - */ - gtk_widget_add_events (widget_gtk, - GDK_POINTER_MOTION_MASK | /* Handle pointer events */ - GDK_POINTER_MOTION_HINT_MASK | /* for drag/resize and */ - GDK_BUTTON_PRESS_MASK | /* managing selection. */ - GDK_BUTTON_RELEASE_MASK); - - g_signal_connect (G_OBJECT (widget_gtk), "event", - callback, gwidget); - - g_object_set_data (G_OBJECT (widget_gtk), - GLADE_TAG_EVENT_HANDLER_CONNECTED, - GINT_TO_POINTER (1)); - } - - /* We also need to get expose events for any children. - */ - if (GTK_IS_CONTAINER (widget_gtk)) - { - if ((children = - glade_util_container_get_all_children (GTK_CONTAINER - (widget_gtk))) != NULL) - { - for (list = children; list; list = list->next) - glade_widget_connect_signal_handlers - (GTK_WIDGET (list->data), callback, gwidget); - g_list_free (children); - } - } -} - -/* - * Returns a list of GladeProperties from a list for the correct - * child type for this widget of this container. - */ -static GList * -glade_widget_create_packing_properties (GladeWidget *container, GladeWidget *widget) -{ - GladePropertyClass *property_class; - GladeProperty *property; - GList *list, *packing_props = NULL; - - /* XXX TODO: by checking with some GladePropertyClass metadata, decide - * which packing properties go on which type of children. - */ - for (list = container->adaptor->packing_props; - list && list->data; list = list->next) - { - property_class = list->data; - property = glade_property_new (property_class, widget, NULL); - packing_props = g_list_prepend (packing_props, property); - - } - return g_list_reverse (packing_props); -} - -/******************************************************************************* - GladeInterface Parsing code - *******************************************************************************/ -static gint -glade_widget_set_child_type_from_child_info (GladeChildInfo *child_info, - GladeWidgetAdaptor *parent_adaptor, - GObject *child) -{ - guint i; - GladePropInfo *prop_info; - gchar *special_child_type; - - g_object_get (parent_adaptor, "special-child-type", &special_child_type, NULL); - - if (!special_child_type) - return -1; - - for (i = 0; i < child_info->n_properties; ++i) - { - prop_info = child_info->properties + i; - if (!strcmp (prop_info->name, special_child_type)) - { - g_free (special_child_type); - - g_object_set_data_full (child, - "special-child-type", - g_strdup (prop_info->value), - g_free); - return i; - } - } - g_free (special_child_type); - return -1; -} - -static gboolean -glade_widget_new_child_from_child_info (GladeChildInfo *info, - GladeProject *project, - GladeWidget *parent) -{ - GladeWidget *child; - GList *list; - - g_return_val_if_fail (info != NULL, FALSE); - g_return_val_if_fail (project != NULL, FALSE); - - /* is it a placeholder? */ - if (!info->child) - { - GObject *palaceholder = G_OBJECT (glade_placeholder_new ()); - glade_widget_set_child_type_from_child_info - (info, parent->adaptor, palaceholder); - glade_widget_adaptor_add (parent->adaptor, - parent->object, - palaceholder); - return TRUE; - } - - /* is it an internal child? */ - if (info->internal_child) - { - GObject *child_object = - glade_widget_get_internal_child (parent, info->internal_child); - - if (!child_object) - { - g_warning ("Failed to locate internal child %s of %s", - info->internal_child, glade_widget_get_name (parent)); - return FALSE; - } - - if ((child = glade_widget_get_from_gobject (child_object)) == NULL) - g_error ("Unable to get GladeWidget for internal child %s\n", - info->internal_child); - - /* Apply internal widget name from here */ - glade_widget_set_name (child, info->child->name); - glade_widget_fill_from_widget_info (info->child, child, TRUE); - glade_widget_sync_custom_props (child); - } - else - { - child = glade_widget_new_from_widget_info (info->child, project, parent); - if (!child) - return FALSE; - - child->parent = parent; - - glade_widget_set_child_type_from_child_info - (info, parent->adaptor, child->object); - - glade_widget_add_child (parent, child, FALSE); - - glade_widget_sync_packing_props (child); - } - - /* Get the packing properties */ - for (list = child->packing_properties; list; list = list->next) - { - GladeProperty *property = list->data; - glade_property_read (property, property->klass, - loading_project, info, TRUE); - } - return TRUE; -} - -static void -glade_widget_fill_from_widget_info (GladeWidgetInfo *info, - GladeWidget *widget, - gboolean apply_props) -{ - GladeProperty *property; - GList *list; - guint i; - - g_return_if_fail (GLADE_IS_WIDGET (widget)); - g_return_if_fail (info != NULL); - - g_assert (strcmp (info->classname, widget->adaptor->name) == 0); - - /* Children */ - for (i = 0; i < info->n_children; ++i) - { - if (!glade_widget_new_child_from_child_info (info->children + i, - widget->project, widget)) - { - g_warning ("Failed to read child of %s", - glade_widget_get_name (widget)); - continue; - } - } - - /* Signals */ - for (i = 0; i < info->n_signals; ++i) - { - GladeSignal *signal; - - signal = glade_signal_new_from_signal_info (info->signals + i); - if (!signal) - { - g_warning ("Failed to read signal"); - continue; - } - glade_widget_add_signal_handler (widget, signal); - } - - /* Properties */ - if (apply_props) - { - for (list = widget->properties; list; list = list->next) - { - property = list->data; - glade_property_read (property, property->klass, - loading_project, info, TRUE); - } - } -} - - - -static GList * -glade_widget_properties_from_widget_info (GladeWidgetAdaptor *klass, - GladeWidgetInfo *info) -{ - GList *properties = NULL, *list; - - for (list = klass->properties; list && list->data; list = list->next) - { - GladePropertyClass *pclass = list->data; - GladeProperty *property; - - /* If there is a value in the XML, initialize property with it, - * otherwise initialize property to default. - */ - property = glade_property_new (pclass, NULL, NULL); - - glade_property_original_reset (property); - - glade_property_read (property, property->klass, - loading_project, info, TRUE); - - properties = g_list_prepend (properties, property); - } - - return g_list_reverse (properties); -} - -static GladeWidget * -glade_widget_new_from_widget_info (GladeWidgetInfo *info, - GladeProject *project, - GladeWidget *parent) -{ - GladeWidgetAdaptor *adaptor; - GladeWidget *widget; - GList *properties; - - g_return_val_if_fail (info != NULL, NULL); - g_return_val_if_fail (project != NULL, NULL); - - if ((adaptor = - glade_widget_adaptor_get_by_name (info->classname)) == NULL) - { - g_warning ("Widget class %s unknown.", info->classname); - return NULL; - } - - properties = glade_widget_properties_from_widget_info (adaptor, info); - widget = glade_widget_adaptor_create_widget - (adaptor, FALSE, - "name", info->name, - "parent", parent, - "project", project, - "info", info, - "properties", properties, - "reason", GLADE_CREATE_LOAD, NULL); - - /* create the packing_properties list, without setting them */ - if (parent) - widget->packing_properties = - glade_widget_create_packing_properties (parent, widget); - - /* Load children first */ - glade_widget_fill_from_widget_info (info, widget, FALSE); - - /* Now sync custom props, things like "size" on GtkBox need - * this to be done afterwards. - */ - glade_widget_sync_custom_props (widget); - - return widget; -} - -static GParameter * -glade_widget_info_params (GladeWidgetAdaptor *adaptor, - GladeWidgetInfo *info, - gboolean construct, - guint *n_params) -{ - GladePropertyClass *glade_property_class; - GObjectClass *oclass; - GParamSpec **pspec; - GArray *params; - guint i, n_props; - - oclass = g_type_class_ref (adaptor->type); - pspec = g_object_class_list_properties (oclass, &n_props); - params = g_array_new (FALSE, FALSE, sizeof (GParameter)); - - /* prepare parameters that have glade_property_class->def */ - for (i = 0; i < n_props; i++) - { - GParameter parameter = { 0, }; - GValue *value; - - glade_property_class = - glade_widget_adaptor_get_property_class (adaptor, - pspec[i]->name); - if (glade_property_class == NULL || - glade_property_class->virt || - glade_property_class->ignore) - continue; - - if (construct && - (pspec[i]->flags & - (G_PARAM_CONSTRUCT|G_PARAM_CONSTRUCT_ONLY)) == 0) - continue; - else if (!construct && - (pspec[i]->flags & - (G_PARAM_CONSTRUCT|G_PARAM_CONSTRUCT_ONLY)) != 0) - continue; - - - /* Try filling parameter with value from widget info. - */ - if ((value = glade_property_read (NULL, glade_property_class, - loading_project, info, FALSE)) != NULL) - { - parameter.name = pspec[i]->name; - g_value_init (¶meter.value, pspec[i]->value_type); - - g_value_copy (value, ¶meter.value); - g_value_unset (value); - g_free (value); - - g_array_append_val (params, parameter); - } - } - g_free(pspec); - - g_type_class_unref (oclass); - - *n_params = params->len; - return (GParameter *)g_array_free (params, FALSE); -} - -/******************************************************************************* - API - *******************************************************************************/ -GladeWidget * -glade_widget_get_from_gobject (gpointer object) -{ - g_return_val_if_fail (G_IS_OBJECT (object), NULL); - - return g_object_get_qdata (G_OBJECT (object), glade_widget_name_quark); -} - -static void -glade_widget_debug_real (GladeWidget *widget, int indent) -{ - g_print ("%*sGladeWidget at %p\n", indent, "", widget); - g_print ("%*sname = [%s]\n", indent, "", widget->name ? widget->name : "-"); - g_print ("%*sinternal = [%s]\n", indent, "", widget->internal ? widget->internal : "-"); - g_print ("%*sgobject = %p [%s]\n", - indent, "", widget->object, G_OBJECT_TYPE_NAME (widget->object)); - if (GTK_IS_WIDGET (widget->object)) - g_print ("%*sgtkwidget->parent = %p\n", indent, "", - gtk_widget_get_parent (GTK_WIDGET(widget->object))); - if (GTK_IS_CONTAINER (widget->object)) { - GList *children, *l; - children = glade_util_container_get_all_children - (GTK_CONTAINER (widget->object)); - for (l = children; l; l = l->next) { - GtkWidget *widget_gtk = GTK_WIDGET (l->data); - GladeWidget *widget = glade_widget_get_from_gobject (widget_gtk); - if (widget) { - glade_widget_debug_real (widget, indent + 2); - } else if (GLADE_IS_PLACEHOLDER (widget_gtk)) { - g_print ("%*sGtkWidget child %p is a placeholder.\n", - indent + 2, "", widget_gtk); - } else { - g_print ("%*sGtkWidget child %p [%s] has no glade widget.\n", - indent + 2, "", - widget_gtk, G_OBJECT_TYPE_NAME (widget_gtk)); - } - } - if (!children) - g_print ("%*shas no children\n", indent, ""); - g_list_free (children); - } else { - g_print ("%*snot a container\n", indent, ""); - } - g_print ("\n"); -} - -/** - * glade_widget_debug: - * @widget: a #GladeWidget - * - * Prints some information about a #GladeWidget, currently - * this is unmaintained. - */ -static void -glade_widget_debug (GladeWidget *widget) -{ - glade_widget_debug_real (widget, 0); -} - -/** - * glade_widget_show: - * @widget: A #GladeWidget - * - * Display @widget in it's project's GladeDesignView - */ -void -glade_widget_show (GladeWidget *widget) -{ - GladeDesignView *view; - GtkWidget *layout; - - g_return_if_fail (GLADE_IS_WIDGET (widget)); - - /* Position window at saved coordinates or in the center */ - if (GTK_IS_WINDOW (widget->object)) - { - if (!glade_window_is_embedded (GTK_WINDOW (widget->object))) - glade_widget_embed (widget); - - view = glade_design_view_get_from_project (glade_widget_get_project (widget)); - layout = GTK_WIDGET (glade_design_view_get_layout (view)); - - if (gtk_bin_get_child (GTK_BIN (layout)) != NULL) - gtk_container_remove (GTK_CONTAINER (layout), gtk_bin_get_child (GTK_BIN (layout))); - - gtk_container_add (GTK_CONTAINER (layout), GTK_WIDGET (widget->object)); - - gtk_widget_show_all (GTK_WIDGET (widget->object)); - - } else if (GTK_IS_WIDGET (widget->object)) { - gtk_widget_show_all (GTK_WIDGET (widget->object)); - } - widget->visible = TRUE; -} - -/** - * glade_widget_hide: - * @widget: A #GladeWidget - * - * Hide @widget - */ -void -glade_widget_hide (GladeWidget *widget) -{ - g_return_if_fail (GLADE_IS_WIDGET (widget)); - if (GTK_IS_WINDOW (widget->object)) - { - /* Save coordinates */ - gtk_widget_hide (GTK_WIDGET (widget->object)); - } - widget->visible = FALSE; -} - -/** - * glade_widget_add_prop_ref: - * @widget: A #GladeWidget - * @property: the #GladeProperty - * - * Adds @property to @widget 's list of referenced properties. - * - * Note: this is used to track object reference properties that - * go in and out of the project. - */ -void -glade_widget_add_prop_ref (GladeWidget *widget, GladeProperty *property) -{ - g_return_if_fail (GLADE_IS_WIDGET (widget)); - g_return_if_fail (GLADE_IS_PROPERTY (property)); - - if (property && !widget->prop_refs_readonly && - !g_list_find (widget->prop_refs, property)) - widget->prop_refs = g_list_prepend (widget->prop_refs, property); -} - -/** - * glade_widget_remove_prop_ref: - * @widget: A #GladeWidget - * @property: the #GladeProperty - * - * Removes @property from @widget 's list of referenced properties. - * - * Note: this is used to track object reference properties that - * go in and out of the project. - */ -void -glade_widget_remove_prop_ref (GladeWidget *widget, GladeProperty *property) -{ - g_return_if_fail (GLADE_IS_WIDGET (widget)); - g_return_if_fail (GLADE_IS_PROPERTY (property)); - - if (!widget->prop_refs_readonly) - widget->prop_refs = g_list_remove (widget->prop_refs, property); -} - -/** - * glade_widget_project_notify: - * @widget: A #GladeWidget - * @project: The #GladeProject (or %NULL) - * - * Notifies @widget that it is now in @project. - * - * Note that this doesnt really set the project; the project is saved - * for internal reasons even when the widget is on the clipboard. - * (also used for property references). - */ -void -glade_widget_project_notify (GladeWidget *widget, GladeProject *project) -{ - GList *l; - GladeProperty *property; - - g_return_if_fail (GLADE_IS_WIDGET (widget)); - - /* Since glade_property_set() will try to modify list, - * we protect it with the 'prop_refs_readonly' flag. - */ - widget->prop_refs_readonly = TRUE; - for (l = widget->prop_refs; l && l->data; l = l->next) - { - property = GLADE_PROPERTY (l->data); - - if (project != NULL && - project == property->widget->project) - glade_property_add_object (property, widget->object); - else - glade_property_remove_object (property, widget->object); - } - widget->prop_refs_readonly = FALSE; -} - -static void -glade_widget_copy_signal_foreach (const gchar *key, - GPtrArray *signals, - GladeWidget *dest) -{ - GladeSignal *signal; - gint i; - - for (i = 0; i < signals->len; i++) - { - signal = (GladeSignal *)signals->pdata[i]; - glade_widget_add_signal_handler (dest, signal); - } -} - -/** - * glade_widget_copy_signals: - * @widget: a 'dest' #GladeWidget - * @template_widget: a 'src' #GladeWidget - * - * Sets signals in @widget based on the values of - * matching signals in @template_widget - */ -void -glade_widget_copy_signals (GladeWidget *widget, - GladeWidget *template_widget) -{ - g_return_if_fail (GLADE_IS_WIDGET (widget)); - g_return_if_fail (GLADE_IS_WIDGET (template_widget)); - - g_hash_table_foreach (template_widget->signals, - (GHFunc)glade_widget_copy_signal_foreach, - widget); -} - -/** - * glade_widget_copy_properties: - * @widget: a 'dest' #GladeWidget - * @template_widget: a 'src' #GladeWidget - * - * Sets properties in @widget based on the values of - * matching properties in @template_widget - */ -void -glade_widget_copy_properties (GladeWidget *widget, - GladeWidget *template_widget) -{ - GList *l; - - g_return_if_fail (GLADE_IS_WIDGET (widget)); - g_return_if_fail (GLADE_IS_WIDGET (template_widget)); - - for (l = widget->properties; l && l->data; l = l->next) - { - GladeProperty *widget_prop = GLADE_PROPERTY(l->data); - GladeProperty *template_prop; - - /* Check if they share the same class definition, different - * properties may have the same name (support for - * copying properties across "not-quite" compatible widget - * classes, like GtkImageMenuItem --> GtkCheckMenuItem). - */ - if ((template_prop = - glade_widget_get_property (template_widget, - widget_prop->klass->id)) != NULL && - glade_property_class_match (template_prop->klass, widget_prop->klass)) - glade_property_set_value (widget_prop, template_prop->value); - } -} - -/** - * glade_widget_add_child: - * @parent: A #GladeWidget - * @child: the #GladeWidget to add - * @at_mouse: whether the added widget should be added - * at the current mouse position - * - * Adds @child to @parent in a generic way for this #GladeWidget parent. - */ -void -glade_widget_add_child (GladeWidget *parent, - GladeWidget *child, - gboolean at_mouse) -{ - g_return_if_fail (GLADE_IS_WIDGET (parent)); - g_return_if_fail (GLADE_IS_WIDGET (child)); - - GLADE_WIDGET_GET_CLASS (parent)->add_child (parent, child, at_mouse); -} - -/** - * glade_widget_remove_child: - * @parent: A #GladeWidget - * @child: the #GladeWidget to add - * - * Removes @child from @parent in a generic way for this #GladeWidget parent. - */ -void -glade_widget_remove_child (GladeWidget *parent, - GladeWidget *child) -{ - g_return_if_fail (GLADE_IS_WIDGET (parent)); - g_return_if_fail (GLADE_IS_WIDGET (child)); - - GLADE_WIDGET_GET_CLASS (parent)->remove_child (parent, child); -} - -/** - * glade_widget_dup: - * @template_widget: a #GladeWidget - * @exact: whether or not to creat an exact duplicate - * - * Creates a deep copy of #GladeWidget. if @exact is specified, - * the widget name is preserved and signals are carried over - * (this is used to maintain names & signals in Cut/Paste context - * as opposed to Copy/Paste contexts). - * - * Returns: The newly created #GladeWidget - */ -GladeWidget * -glade_widget_dup (GladeWidget *template_widget, - gboolean exact) -{ - GladeWidget *widget; - - g_return_val_if_fail (GLADE_IS_WIDGET (template_widget), NULL); - - glade_widget_push_superuser (); - widget = glade_widget_dup_internal (NULL, template_widget, exact); - glade_widget_pop_superuser (); - - return widget; -} - -/** - * glade_widget_rebuild: - * @glade_widget: a #GladeWidget - * - * Replaces the current widget instance with - * a new one while preserving all properties children and - * takes care of reparenting. - * - */ -void -glade_widget_rebuild (GladeWidget *glade_widget) -{ - GObject *new_object, *old_object; - GladeWidgetAdaptor *adaptor; - GList *children; - gboolean reselect = FALSE, inproject; - - g_return_if_fail (GLADE_IS_WIDGET (glade_widget)); - - - adaptor = glade_widget->adaptor; - - /* Here we take care removing the widget from the project and - * the selection before rebuilding the instance. - */ - inproject = glade_widget->project ? - (glade_project_has_object - (glade_widget->project, glade_widget->object) ? TRUE : FALSE) : FALSE; - - if (inproject) - { - if (glade_project_is_selected (glade_widget->project, - glade_widget->object)) - { - reselect = TRUE; - glade_project_selection_remove - (glade_widget->project, glade_widget->object, FALSE); - } - glade_project_remove_object (glade_widget->project, glade_widget->object); - } - - /* Extract and keep the child hierarchies aside... */ - children = glade_widget_extract_children (glade_widget); - - /* Hold a reference to the old widget while we transport properties - * and children from it - */ - new_object = glade_widget_build_object(adaptor, glade_widget, NULL); - old_object = g_object_ref(glade_widget_get_object(glade_widget)); - - glade_widget_set_object(glade_widget, new_object); - - /* Only call this once the object has a proper GladeWidget */ - glade_widget_adaptor_post_create (adaptor, new_object, GLADE_CREATE_REBUILD); - - /* Replace old object with new object in parent - */ - if (glade_widget->parent) - glade_widget_replace (glade_widget->parent, - old_object, new_object); - - /* Reparent any children of the old object to the new object - * (this function will consume and free the child list). - */ - glade_widget_push_superuser (); - glade_widget_insert_children (glade_widget, children); - glade_widget_pop_superuser (); - - /* Custom properties aren't transfered in build_object, since build_object - * is only concerned with object creation. - */ - glade_widget_sync_custom_props (glade_widget); - - /* Sync packing. - */ - glade_widget_sync_packing_props (glade_widget); - - if (g_type_is_a (adaptor->type, GTK_TYPE_WIDGET)) - { - /* Must use gtk_widget_destroy here for cases like dialogs and toplevels - * (otherwise I'd prefer g_object_unref() ) - */ - gtk_widget_destroy (GTK_WIDGET(old_object)); - } - else - g_object_unref (old_object); - - /* If the widget was in a project (and maybe the selection), then - * restore that stuff. - */ - if (inproject) - { - glade_project_add_object (glade_widget->project, NULL, - glade_widget->object); - if (reselect) - glade_project_selection_add - (glade_widget->project, glade_widget->object, TRUE); - } - - /* We shouldnt show if its not already visible */ - if (glade_widget->visible) - glade_widget_show (glade_widget); -} - -/** - * glade_widget_add_signal_handler: - * @widget: A #GladeWidget - * @signal_handler: The #GladeSignal - * - * Adds a signal handler for @widget - */ -void -glade_widget_add_signal_handler (GladeWidget *widget, GladeSignal *signal_handler) -{ - g_return_if_fail (GLADE_IS_WIDGET (widget)); - - g_signal_emit (widget, glade_widget_signals[ADD_SIGNAL_HANDLER], 0, signal_handler); -} - - -/** - * glade_widget_remove_signal_handler: - * @widget: A #GladeWidget - * @signal_handler: The #GladeSignal - * - * Removes a signal handler from @widget - */ -void -glade_widget_remove_signal_handler (GladeWidget *widget, GladeSignal *signal_handler) -{ - g_return_if_fail (GLADE_IS_WIDGET (widget)); - - g_signal_emit (widget, glade_widget_signals[REMOVE_SIGNAL_HANDLER], 0, signal_handler); -} - -/** - * glade_widget_change_signal_handler: - * @widget: A #GladeWidget - * @old_signal_handler: the old #GladeSignal - * @new_signal_handler: the new #GladeSignal - * - * Changes a #GladeSignal on @widget - */ -void -glade_widget_change_signal_handler (GladeWidget *widget, - GladeSignal *old_signal_handler, - GladeSignal *new_signal_handler) -{ - g_return_if_fail (GLADE_IS_WIDGET (widget)); - - g_signal_emit (widget, glade_widget_signals[CHANGE_SIGNAL_HANDLER], 0, - old_signal_handler, new_signal_handler); -} - -/** - * glade_widget_list_signal_handlers: - * @widget: a #GladeWidget - * @signal_name: the name of the signal - * - * Returns: A #GPtrArray of #GladeSignal for @signal_name - */ -GPtrArray * -glade_widget_list_signal_handlers (GladeWidget *widget, - const gchar *signal_name) /* array of GladeSignal* */ -{ - g_return_val_if_fail (GLADE_IS_WIDGET (widget), NULL); - return g_hash_table_lookup (widget->signals, signal_name); -} - -/** - * glade_widget_set_name: - * @widget: a #GladeWidget - * @name: a string - * - * Sets @widget's name to @name. - */ -void -glade_widget_set_name (GladeWidget *widget, const gchar *name) -{ - g_return_if_fail (GLADE_IS_WIDGET (widget)); - if (widget->name != name) { - if (widget->name) - g_free (widget->name); - widget->name = g_strdup (name); - g_object_notify (G_OBJECT (widget), "name"); - } -} - -/** - * glade_widget_get_name: - * @widget: a #GladeWidget - * - * Returns: a pointer to @widget's name - */ -const gchar * -glade_widget_get_name (GladeWidget *widget) -{ - g_return_val_if_fail (GLADE_IS_WIDGET (widget), NULL); - return widget->name; -} - -/** - * glade_widget_set_internal: - * @widget: A #GladeWidget - * @internal: The internal name - * - * Sets the internal name of @widget to @internal - */ -void -glade_widget_set_internal (GladeWidget *widget, const gchar *internal) -{ - g_return_if_fail (GLADE_IS_WIDGET (widget)); - if (widget->internal != internal) { - g_free (widget->internal); - widget->internal = g_strdup (internal); - g_object_notify (G_OBJECT (widget), "internal"); - } -} - -/** - * glade_widget_get_internal: - * @widget: a #GladeWidget - * - * Returns: the internal name of @widget - */ -G_CONST_RETURN gchar * -glade_widget_get_internal (GladeWidget *widget) -{ - g_return_val_if_fail (GLADE_IS_WIDGET (widget), NULL); - return widget->internal; -} - -/** - * glade_widget_get_adaptor: - * @widget: a #GladeWidget - * - * Returns: the #GladeWidgetAdaptor of @widget - */ -GladeWidgetAdaptor * -glade_widget_get_adaptor (GladeWidget *widget) -{ - g_return_val_if_fail (GLADE_IS_WIDGET (widget), NULL); - return widget->adaptor; -} - -/** - * glade_widget_set_project: - * @widget: a #GladeWidget - * @project: a #GladeProject - * - * Makes @widget belong to @project. - */ -void -glade_widget_set_project (GladeWidget *widget, GladeProject *project) -{ - if (widget->project != project) { - widget->project = project; - g_object_notify (G_OBJECT (widget), "project"); - } -} - -/** - * glade_widget_get_project: - * @widget: a #GladeWidget - * - * Returns: the #GladeProject that @widget belongs to - */ -GladeProject * -glade_widget_get_project (GladeWidget *widget) -{ - g_return_val_if_fail (GLADE_IS_WIDGET (widget), NULL); - return widget->project; -} - -/** - * glade_widget_get_property: - * @widget: a #GladeWidget - * @id_property: a string naming a #GladeProperty - * - * Returns: the #GladeProperty in @widget named @id_property - */ -GladeProperty * -glade_widget_get_property (GladeWidget *widget, const gchar *id_property) -{ - static gchar id_buffer[GPC_PROPERTY_NAMELEN] = { 0, }; - GList *list; - GladeProperty *property; - - g_return_val_if_fail (GLADE_IS_WIDGET (widget), NULL); - g_return_val_if_fail (id_property != NULL, NULL); - - /* "-1" to always leave a trailing '\0' charachter */ - strncpy (id_buffer, id_property, GPC_PROPERTY_NAMELEN - 1); - glade_util_replace (id_buffer, '_', '-'); - - for (list = widget->properties; list; list = list->next) { - property = list->data; - if (strcmp (property->klass->id, id_buffer) == 0) - return property; - } - return glade_widget_get_pack_property (widget, id_property); -} - -/** - * glade_widget_get_pack_property: - * @widget: a #GladeWidget - * @id_property: a string naming a #GladeProperty - * - * Returns: the #GladeProperty in @widget named @id_property - */ -GladeProperty * -glade_widget_get_pack_property (GladeWidget *widget, const gchar *id_property) -{ - static gchar id_buffer[GPC_PROPERTY_NAMELEN] = { 0, }; - GList *list; - GladeProperty *property; - - g_return_val_if_fail (GLADE_IS_WIDGET (widget), NULL); - g_return_val_if_fail (id_property != NULL, NULL); - - /* "-1" to always leave a trailing '\0' charachter */ - strncpy (id_buffer, id_property, GPC_PROPERTY_NAMELEN - 1); - glade_util_replace (id_buffer, '_', '-'); - - for (list = widget->packing_properties; list; list = list->next) { - property = list->data; - if (strcmp (property->klass->id, id_buffer) == 0) - return property; - } - return NULL; -} - - -/** - * glade_widget_property_get: - * @widget: a #GladeWidget - * @id_property: a string naming a #GladeProperty - * @...: The return location for the value of the said #GladeProperty - * - * Gets the value of @id_property in @widget - * - * Returns: whether @id_property was found or not. - */ -gboolean -glade_widget_property_get (GladeWidget *widget, - const gchar *id_property, - ...) -{ - GladeProperty *property; - va_list vl; - - g_return_val_if_fail (GLADE_IS_WIDGET (widget), FALSE); - - if ((property = glade_widget_get_property (widget, id_property)) != NULL) - { - va_start (vl, id_property); - glade_property_get_va_list (property, vl); - va_end (vl); - return TRUE; - } - return FALSE; -} - -/** - * glade_widget_property_set: - * @widget: a #GladeWidget - * @id_property: a string naming a #GladeProperty - * @...: A value of the correct type for the said #GladeProperty - * - * Sets the value of @id_property in @widget - * - * Returns: whether @id_property was found or not. - */ -gboolean -glade_widget_property_set (GladeWidget *widget, - const gchar *id_property, - ...) -{ - GladeProperty *property; - va_list vl; - - g_return_val_if_fail (GLADE_IS_WIDGET (widget), FALSE); - - if ((property = glade_widget_get_property (widget, id_property)) != NULL) - { - va_start (vl, id_property); - glade_property_set_va_list (property, vl); - va_end (vl); - return TRUE; - } - return FALSE; -} - -/** - * glade_widget_pack_property_get: - * @widget: a #GladeWidget - * @id_property: a string naming a #GladeProperty - * @...: The return location for the value of the said #GladeProperty - * - * Gets the value of @id_property in @widget packing properties - * - * Returns: whether @id_property was found or not. - */ -gboolean -glade_widget_pack_property_get (GladeWidget *widget, - const gchar *id_property, - ...) -{ - GladeProperty *property; - va_list vl; - - g_return_val_if_fail (GLADE_IS_WIDGET (widget), FALSE); - - if ((property = glade_widget_get_pack_property (widget, id_property)) != NULL) - { - va_start (vl, id_property); - glade_property_get_va_list (property, vl); - va_end (vl); - return TRUE; - } - return FALSE; -} - -/** - * glade_widget_pack_property_set: - * @widget: a #GladeWidget - * @id_property: a string naming a #GladeProperty - * @...: The return location for the value of the said #GladeProperty - * - * Sets the value of @id_property in @widget packing properties - * - * Returns: whether @id_property was found or not. - */ -gboolean -glade_widget_pack_property_set (GladeWidget *widget, - const gchar *id_property, - ...) -{ - GladeProperty *property; - va_list vl; - - g_return_val_if_fail (GLADE_IS_WIDGET (widget), FALSE); - - if ((property = glade_widget_get_pack_property (widget, id_property)) != NULL) - { - va_start (vl, id_property); - glade_property_set_va_list (property, vl); - va_end (vl); - return TRUE; - } - return FALSE; -} - -/** - * glade_widget_property_set_sensitive: - * @widget: a #GladeWidget - * @id_property: a string naming a #GladeProperty - * @sensitive: setting sensitive or insensitive - * @reason: a description of why the user cant edit this property - * which will be used as a tooltip - * - * Sets the sensitivity of @id_property in @widget - * - * Returns: whether @id_property was found or not. - */ -gboolean -glade_widget_property_set_sensitive (GladeWidget *widget, - const gchar *id_property, - gboolean sensitive, - const gchar *reason) -{ - GladeProperty *property; - - g_return_val_if_fail (GLADE_IS_WIDGET (widget), FALSE); - - if ((property = glade_widget_get_property (widget, id_property)) != NULL) - { - glade_property_set_sensitive (property, sensitive, reason); - return TRUE; - } - return FALSE; -} - -/** - * glade_widget_pack_property_set_sensitive: - * @widget: a #GladeWidget - * @id_property: a string naming a #GladeProperty - * @sensitive: setting sensitive or insensitive - * @reason: a description of why the user cant edit this property - * which will be used as a tooltip - * - * Sets the sensitivity of @id_property in @widget's packing properties. - * - * Returns: whether @id_property was found or not. - */ -gboolean -glade_widget_pack_property_set_sensitive (GladeWidget *widget, - const gchar *id_property, - gboolean sensitive, - const gchar *reason) -{ - GladeProperty *property; - - g_return_val_if_fail (GLADE_IS_WIDGET (widget), FALSE); - - if ((property = glade_widget_get_pack_property (widget, id_property)) != NULL) - { - glade_property_set_sensitive (property, sensitive, reason); - return TRUE; - } - return FALSE; -} - - -/** - * glade_widget_property_set_enabled: - * @widget: a #GladeWidget - * @id_property: a string naming a #GladeProperty - * @enabled: setting enabled or disabled - * - * Sets the enabled state of @id_property in @widget; this is - * used for optional properties. - * - * Returns: whether @id_property was found or not. - */ -gboolean -glade_widget_property_set_enabled (GladeWidget *widget, - const gchar *id_property, - gboolean enabled) -{ - GladeProperty *property; - - g_return_val_if_fail (GLADE_IS_WIDGET (widget), FALSE); - - if ((property = glade_widget_get_property (widget, id_property)) != NULL) - { - glade_property_set_enabled (property, enabled); - return TRUE; - } - return FALSE; -} - -/** - * glade_widget_pack_property_set_enabled: - * @widget: a #GladeWidget - * @id_property: a string naming a #GladeProperty - * @enabled: setting enabled or disabled - * - * Sets the enabled state of @id_property in @widget's packing - * properties; this is used for optional properties. - * - * Returns: whether @id_property was found or not. - */ -gboolean -glade_widget_pack_property_set_enabled (GladeWidget *widget, - const gchar *id_property, - gboolean enabled) -{ - GladeProperty *property; - - g_return_val_if_fail (GLADE_IS_WIDGET (widget), FALSE); - - if ((property = glade_widget_get_pack_property (widget, id_property)) != NULL) - { - glade_property_set_enabled (property, enabled); - return TRUE; - } - return FALSE; -} - -/** - * glade_widget_property_set_save_always: - * @widget: a #GladeWidget - * @id_property: a string naming a #GladeProperty - * @setting: the setting - * - * Sets whether @id_property in @widget should be special cased - * to always be saved regardless of its default value. - * (used for some special cases like properties - * that are assigned initial values in composite widgets - * or derived widget code). - * - * Returns: whether @id_property was found or not. - */ -gboolean -glade_widget_property_set_save_always (GladeWidget *widget, - const gchar *id_property, - gboolean setting) -{ - GladeProperty *property; - - g_return_val_if_fail (GLADE_IS_WIDGET (widget), FALSE); - - if ((property = glade_widget_get_property (widget, id_property)) != NULL) - { - glade_property_set_save_always (property, setting); - return TRUE; - } - return FALSE; -} - -/** - * glade_widget_pack_property_set_save_always: - * @widget: a #GladeWidget - * @id_property: a string naming a #GladeProperty - * @setting: the setting - * - * Sets whether @id_property in @widget should be special cased - * to always be saved regardless of its default value. - * (used for some special cases like properties - * that are assigned initial values in composite widgets - * or derived widget code). - * - * Returns: whether @id_property was found or not. - */ -gboolean -glade_widget_pack_property_set_save_always (GladeWidget *widget, - const gchar *id_property, - gboolean setting) -{ - GladeProperty *property; - - g_return_val_if_fail (GLADE_IS_WIDGET (widget), FALSE); - - if ((property = glade_widget_get_pack_property (widget, id_property)) != NULL) - { - glade_property_set_save_always (property, setting); - return TRUE; - } - return FALSE; -} - - -/** - * glade_widget_property_reset: - * @widget: a #GladeWidget - * @id_property: a string naming a #GladeProperty - * - * Resets @id_property in @widget to it's default value - * - * Returns: whether @id_property was found or not. - */ -gboolean -glade_widget_property_reset (GladeWidget *widget, - const gchar *id_property) -{ - GladeProperty *property; - - g_return_val_if_fail (GLADE_IS_WIDGET (widget), FALSE); - - if ((property = glade_widget_get_property (widget, id_property)) != NULL) - { - glade_property_reset (property); - return TRUE; - } - return FALSE; -} - -/** - * glade_widget_pack_property_reset: - * @widget: a #GladeWidget - * @id_property: a string naming a #GladeProperty - * - * Resets @id_property in @widget's packing properties to it's default value - * - * Returns: whether @id_property was found or not. - */ -gboolean -glade_widget_pack_property_reset (GladeWidget *widget, - const gchar *id_property) -{ - GladeProperty *property; - - g_return_val_if_fail (GLADE_IS_WIDGET (widget), FALSE); - - if ((property = glade_widget_get_pack_property (widget, id_property)) != NULL) - { - glade_property_reset (property); - return TRUE; - } - return FALSE; -} - -static gboolean -glade_widget_property_default_common (GladeWidget *widget, - const gchar *id_property, gboolean original) -{ - GladeProperty *property; - - g_return_val_if_fail (GLADE_IS_WIDGET (widget), FALSE); - - if ((property = glade_widget_get_property (widget, id_property)) != NULL) - return (original) ? glade_property_original_default (property) : - glade_property_default (property); - - return FALSE; -} - -/** - * glade_widget_property_default: - * @widget: a #GladeWidget - * @id_property: a string naming a #GladeProperty - * - * Returns: whether whether @id_property was found and is - * currently set to it's default value. - */ -gboolean -glade_widget_property_default (GladeWidget *widget, - const gchar *id_property) -{ - return glade_widget_property_default_common (widget, id_property, FALSE); -} - -/** - * glade_widget_property_original_default: - * @widget: a #GladeWidget - * @id_property: a string naming a #GladeProperty - * - * Returns: whether whether @id_property was found and is - * currently set to it's original default value. - */ -gboolean -glade_widget_property_original_default (GladeWidget *widget, - const gchar *id_property) -{ - return glade_widget_property_default_common (widget, id_property, TRUE); -} - -/** - * glade_widget_pack_property_default: - * @widget: a #GladeWidget - * @id_property: a string naming a #GladeProperty - * - * Returns: whether whether @id_property was found and is - * currently set to it's default value. - */ -gboolean -glade_widget_pack_property_default (GladeWidget *widget, - const gchar *id_property) -{ - GladeProperty *property; - - g_return_val_if_fail (GLADE_IS_WIDGET (widget), FALSE); - - if ((property = glade_widget_get_pack_property (widget, id_property)) != NULL) - return glade_property_default (property); - - return FALSE; -} - - -/** - * glade_widget_object_set_property: - * @widget: A #GladeWidget - * @property_name: The property identifier - * @value: The #GValue - * - * This function applies @value to the property @property_name on - * the runtime object of @widget. - */ -void -glade_widget_object_set_property (GladeWidget *widget, - const gchar *property_name, - const GValue *value) -{ - g_return_if_fail (GLADE_IS_WIDGET (widget)); - g_return_if_fail (property_name != NULL && value != NULL); - - glade_widget_adaptor_set_property (widget->adaptor, - widget->object, - property_name, value); -} - - -/** - * glade_widget_object_get_property: - * @widget: A #GladeWidget - * @property_name: The property identifier - * @value: The #GValue - * - * This function retrieves the value of the property @property_name on - * the runtime object of @widget and sets it in @value. - */ -void -glade_widget_object_get_property (GladeWidget *widget, - const gchar *property_name, - GValue *value) -{ - g_return_if_fail (GLADE_IS_WIDGET (widget)); - g_return_if_fail (property_name != NULL && value != NULL); - - glade_widget_adaptor_get_property (widget->adaptor, - widget->object, - property_name, value); -} - -/** - * glade_widget_child_set_property: - * @widget: A #GladeWidget - * @child: The #GladeWidget child - * @property_name: The id of the property - * @value: The @GValue - * - * Sets @child's packing property identified by @property_name to @value. - */ -void -glade_widget_child_set_property (GladeWidget *widget, - GladeWidget *child, - const gchar *property_name, - const GValue *value) -{ - g_return_if_fail (GLADE_IS_WIDGET (widget)); - g_return_if_fail (GLADE_IS_WIDGET (child)); - g_return_if_fail (property_name != NULL && value != NULL); - - glade_widget_adaptor_child_set_property (widget->adaptor, - widget->object, - child->object, - property_name, value); -} - -/** - * glade_widget_child_get_property: - * @widget: A #GladeWidget - * @child: The #GladeWidget child - * @property_name: The id of the property - * @value: The @GValue - * - * Gets @child's packing property identified by @property_name. - */ -void -glade_widget_child_get_property (GladeWidget *widget, - GladeWidget *child, - const gchar *property_name, - GValue *value) -{ - g_return_if_fail (GLADE_IS_WIDGET (widget)); - g_return_if_fail (GLADE_IS_WIDGET (child)); - g_return_if_fail (property_name != NULL && value != NULL); - - glade_widget_adaptor_child_get_property (widget->adaptor, - widget->object, - child->object, - property_name, value); - -} - -static gboolean -glade_widget_event_private (GtkWidget *widget, - GdkEvent *event, - GladeWidget *gwidget) -{ - /* Whoa, now that's trust. */ - return glade_app_widget_event (gwidget, event); -} - -/** - * glade_widget_set_object: - * @gwidget: A #GladeWidget - * @new_object: the new #GObject for @gwidget - * - * Set the runtime object for this GladeWidget wrapper - * (this is used deep in the core and is probably unsafe - * to use elsewhere). - */ -void -glade_widget_set_object (GladeWidget *gwidget, GObject *new_object) -{ - GladeWidgetAdaptor *adaptor; - GObject *old_object; - - g_return_if_fail (GLADE_IS_WIDGET (gwidget)); - g_return_if_fail (G_IS_OBJECT (new_object)); - g_return_if_fail (g_type_is_a (G_OBJECT_TYPE (new_object), - gwidget->adaptor->type)); - - adaptor = gwidget->adaptor; - old_object = gwidget->object; - - /* Add internal reference to new widget if its not internal */ - if (gwidget->internal) - gwidget->object = G_OBJECT(new_object); - else - gwidget->object = g_object_ref (G_OBJECT(new_object)); - - g_object_set_qdata (G_OBJECT (new_object), glade_widget_name_quark, gwidget); - - if (g_type_is_a (gwidget->adaptor->type, GTK_TYPE_WIDGET)) - { - /* Disable any built-in DnD - */ - gtk_drag_dest_unset (GTK_WIDGET (new_object)); - gtk_drag_source_unset (GTK_WIDGET (new_object)); - - /* Take care of drawing selection directly on widgets - * for the time being - */ - glade_widget_connect_signal_handlers - (GTK_WIDGET(new_object), - G_CALLBACK (glade_widget_event_private), - gwidget); - } - - /* Remove internal reference to old widget */ - if (gwidget->internal == NULL && old_object) { - g_object_set_qdata (G_OBJECT (old_object), glade_widget_name_quark, NULL); - g_object_unref (G_OBJECT (old_object)); - } - g_object_notify (G_OBJECT (gwidget), "object"); -} - -/** - * glade_widget_get_object: - * @widget: a #GladeWidget - * - * Returns: the #GObject associated with @widget - */ -GObject * -glade_widget_get_object (GladeWidget *widget) -{ - g_return_val_if_fail (GLADE_IS_WIDGET (widget), NULL); - return widget->object; -} - -/** - * glade_widget_get_parent: - * @widget: A #GladeWidget - * - * Returns: The parenting #GladeWidget - */ -GladeWidget * -glade_widget_get_parent (GladeWidget *widget) -{ - g_return_val_if_fail (GLADE_IS_WIDGET (widget), NULL); - return widget->parent; -} - -/** - * glade_widget_set_parent: - * @widget: A #GladeWidget - * @parent: the parenting #GladeWidget (or %NULL) - * - * sets the parenting #GladeWidget - */ -void -glade_widget_set_parent (GladeWidget *widget, - GladeWidget *parent) -{ - GladeWidget *old_parent; - - g_return_if_fail (GLADE_IS_WIDGET (widget)); - - old_parent = widget->parent; - widget->parent = parent; - - /* Set packing props only if the object is actually parented by 'parent' - * (a subsequent call should come from glade_command after parenting). - */ - if (widget->object && parent != NULL && - glade_widget_adaptor_has_child - (parent->adaptor, parent->object, widget->object)) - { - if (old_parent == NULL || widget->packing_properties == NULL || - old_parent->adaptor->type != parent->adaptor->type) - glade_widget_set_packing_properties (widget, parent); - else - glade_widget_sync_packing_props (widget); - } - - if (parent) glade_widget_set_packing_actions (widget, parent); - - g_object_notify (G_OBJECT (widget), "parent"); -} - -/** - * glade_widget_set_packing_properties: - * @widget: A #GladeWidget - * @container: The parent #GladeWidget - * - * Generates the packing_properties list of the widget, given - * the class of the container we are adding the widget to. - * If the widget already has packing_properties, but the container - * has changed, the current list is freed and replaced. - */ -void -glade_widget_set_packing_properties (GladeWidget *widget, - GladeWidget *container) -{ - GList *list; - - g_return_if_fail (GLADE_IS_WIDGET (widget)); - g_return_if_fail (GLADE_IS_WIDGET (container)); - - g_list_foreach (widget->packing_properties, (GFunc)g_object_unref, NULL); - g_list_free (widget->packing_properties); - widget->packing_properties = NULL; - - /* We have to detect whether this is an anarchist child of a composite - * widget or not, in otherwords; whether its really a direct child or - * a child of a popup window created on the composite widget's behalf. - */ - if (widget->anarchist) return; - - widget->packing_properties = glade_widget_create_packing_properties (container, widget); - - /* Dont introspect on properties that are not parented yet. - */ - if (glade_widget_adaptor_has_child (container->adaptor, - container->object, - widget->object)) - { - glade_widget_set_default_packing_properties (container, widget); - - /* update the values of the properties to the ones we get from gtk */ - for (list = widget->packing_properties; - list && list->data; - list = list->next) - { - GladeProperty *property = list->data; - g_value_reset (property->value); - glade_widget_child_get_property - (container, - widget, property->klass->id, property->value); - } - } -} - -/** - * glade_widget_has_decendant: - * @widget: a #GladeWidget - * @type: a #GType - * - * Returns: whether this GladeWidget has any decendants of type @type - * or any decendants that implement the @type interface - */ -gboolean -glade_widget_has_decendant (GladeWidget *widget, GType type) -{ - GladeWidget *child; - GList *children, *l; - gboolean found = FALSE; - - if (G_TYPE_IS_INTERFACE (type) && - glade_util_class_implements_interface - (widget->adaptor->type, type)) - return TRUE; - else if (G_TYPE_IS_INTERFACE (type) == FALSE && - g_type_is_a (widget->adaptor->type, type)) - return TRUE; - - if ((children = glade_widget_adaptor_get_children - (widget->adaptor, widget->object)) != NULL) - { - for (l = children; l; l = l->next) - if ((child = glade_widget_get_from_gobject (l->data)) != NULL && - (found = glade_widget_has_decendant (child, type))) - break; - g_list_free (children); - } - return found; -} - -/** - * glade_widget_replace: - * @old_object: a #GObject - * @new_object: a #GObject - * - * Replaces a GObject with another GObject inside a GObject which - * behaves as a container. - * - * Note that both GObjects must be owned by a GladeWidget. - */ -void -glade_widget_replace (GladeWidget *parent, GObject *old_object, GObject *new_object) -{ - g_return_if_fail (G_IS_OBJECT (old_object)); - g_return_if_fail (G_IS_OBJECT (new_object)); - - GLADE_WIDGET_GET_CLASS (parent)->replace_child (parent, old_object, new_object); -} - -/* XML Serialization */ -static gboolean -glade_widget_write_child (GArray *children, GladeWidget *parent, GObject *object, GladeInterface *interface); - -typedef struct _WriteSignalsContext -{ - GladeInterface *interface; - GArray *signals; -} WriteSignalsContext; - -static void -glade_widget_write_signals (gpointer key, gpointer value, gpointer user_data) -{ - WriteSignalsContext *write_signals_context; - GPtrArray *signals; - guint i; - - write_signals_context = (WriteSignalsContext *) user_data; - signals = (GPtrArray *) value; - for (i = 0; i < signals->len; i++) - { - GladeSignal *signal = g_ptr_array_index (signals, i); - GladeSignalInfo signalinfo; - - glade_signal_write (&signalinfo, signal, - write_signals_context->interface); - g_array_append_val (write_signals_context->signals, - signalinfo); - } -} - -/** - * glade_widget_write: - * @widget: a #GladeWidget - * @interface: a #GladeInterface - * - * TODO: write me - * - * Returns: - */ -GladeWidgetInfo* -glade_widget_write (GladeWidget *widget, GladeInterface *interface) -{ - WriteSignalsContext write_signals_context; - GladeWidgetInfo *info; - GArray *props, *atk_props, *atk_actions, *atk_relations, *accels, *children; - GList *list; - - g_return_val_if_fail (GLADE_IS_WIDGET (widget), NULL); - - info = g_new0 (GladeWidgetInfo, 1); - - info->classname = glade_xml_alloc_string (interface, widget->adaptor->name); - info->name = glade_xml_alloc_string (interface, widget->name); - - /* Write the properties */ - props = g_array_new (FALSE, FALSE, sizeof (GladePropInfo)); - atk_props = g_array_new (FALSE, FALSE, sizeof (GladePropInfo)); - atk_relations = g_array_new (FALSE, FALSE, sizeof (GladeAtkRelationInfo)); - atk_actions = g_array_new (FALSE, FALSE, sizeof (GladeAtkActionInfo)); - accels = g_array_new (FALSE, FALSE, sizeof (GladeAccelInfo)); - - for (list = widget->properties; list; list = list->next) - { - GladeProperty *property = list->data; - - /* This should never happen */ - if (property->klass->packing) - continue; - - switch (property->klass->type) - { - case GPC_NORMAL: - glade_property_write (property, interface, props); - break; - case GPC_ATK_PROPERTY: - glade_property_write (property, interface, atk_props); - break; - case GPC_ATK_RELATION: - glade_property_write (property, interface, atk_relations); - break; - case GPC_ATK_ACTION: - glade_property_write (property, interface, atk_actions); - break; - case GPC_ACCEL_PROPERTY: - glade_property_write (property, interface, accels); - break; - default: - break; - } - } - - /* Properties */ - info->properties = (GladePropInfo *) props->data; - info->n_properties = props->len; - g_array_free(props, FALSE); - - /* Atk Properties */ - info->atk_props = (GladePropInfo *) atk_props->data; - info->n_atk_props = atk_props->len; - g_array_free(atk_props, FALSE); - - /* Atk Relations */ - info->relations = (GladeAtkRelationInfo *) atk_relations->data; - info->n_relations = atk_relations->len; - g_array_free(atk_relations, FALSE); - - /* Atk Actions */ - info->atk_actions = (GladeAtkActionInfo *) atk_actions->data; - info->n_atk_actions = atk_actions->len; - g_array_free(atk_actions, FALSE); - - /* Accels */ - info->accels = (GladeAccelInfo *) accels->data; - info->n_accels = accels->len; - g_array_free(accels, FALSE); - - /* Signals */ - write_signals_context.interface = interface; - write_signals_context.signals = g_array_new (FALSE, FALSE, - sizeof (GladeSignalInfo)); - g_hash_table_foreach (widget->signals, - glade_widget_write_signals, - &write_signals_context); - info->signals = (GladeSignalInfo *) - write_signals_context.signals->data; - info->n_signals = write_signals_context.signals->len; - g_array_free (write_signals_context.signals, FALSE); - - /* Children */ - if ((list = - glade_widget_adaptor_get_children (widget->adaptor, - widget->object)) != NULL) - { - children = g_array_new (FALSE, FALSE, sizeof (GladeChildInfo)); - while (list && list->data) - { - GObject *child = list->data; - glade_widget_write_child (children, widget, child, interface); - list = list->next; - } - info->children = (GladeChildInfo *) children->data; - info->n_children = children->len; - - g_array_free (children, FALSE); - g_list_free (list); - } - g_hash_table_insert(interface->names, info->name, info); - - return info; -} - - -static gboolean -glade_widget_write_special_child_prop (GArray *props, - GladeWidget *parent, - GObject *object, - GladeInterface *interface) -{ - GladePropInfo info = { 0 }; - gchar *buff, *special_child_type; - - buff = g_object_get_data (object, "special-child-type"); - - g_object_get (parent->adaptor, "special-child-type", &special_child_type, NULL); - - if (special_child_type && buff) - { - info.name = glade_xml_alloc_propname (interface, - special_child_type); - info.value = glade_xml_alloc_string (interface, buff); - g_array_append_val (props, info); - - g_free (special_child_type); - return TRUE; - } - g_free (special_child_type); - return FALSE; -} - -gboolean -glade_widget_write_child (GArray *children, - GladeWidget *parent, - GObject *object, - GladeInterface *interface) -{ - GladeChildInfo info = { 0 }; - GladeWidget *child_widget; - GList *list; - GArray *props; - - if (GLADE_IS_PLACEHOLDER (object)) - { - props = g_array_new (FALSE, FALSE, - sizeof (GladePropInfo)); - /* Here we have to add the "special-child-type" packing property */ - glade_widget_write_special_child_prop (props, parent, - object, interface); - - info.properties = (GladePropInfo *) props->data; - info.n_properties = props->len; - g_array_free(props, FALSE); - - g_array_append_val (children, info); - - return TRUE; - } - - child_widget = glade_widget_get_from_gobject (object); - if (!child_widget) - return FALSE; - - if (child_widget->internal) - info.internal_child = glade_xml_alloc_string(interface, child_widget->internal); - - info.child = glade_widget_write (child_widget, interface); - if (!info.child) - { - g_warning ("Failed to write child widget"); - return FALSE; - } - - /* Append the packing properties */ - props = g_array_new (FALSE, FALSE, sizeof (GladePropInfo)); - - /* Here we have to add the "special-child-type" packing property */ - glade_widget_write_special_child_prop (props, parent, - child_widget->object, - interface); - - if (child_widget->packing_properties != NULL) - { - for (list = child_widget->packing_properties; - list; list = list->next) - { - GladeProperty *property; - - property = list->data; - g_assert (property->klass->packing != FALSE); - glade_property_write (property, interface, props); - } - } - - info.properties = (GladePropInfo *) props->data; - info.n_properties = props->len; - g_array_free(props, FALSE); - - g_array_append_val (children, info); - - return TRUE; -} - -/** - * glade_widget_read: - * @project: a #GladeProject - * @info: a #GladeWidgetInfo - * - * Returns: a new #GladeWidget for @project, based on @info - */ -GladeWidget * -glade_widget_read (GladeProject *project, GladeWidgetInfo *info) -{ - GladeWidget *widget; - - glade_widget_push_superuser (); - loading_project = project; - - if ((widget = glade_widget_new_from_widget_info - (info, project, NULL)) != NULL) - { -#if 0 - if (glade_verbose) - glade_widget_debug (widget); -#endif - } - - loading_project = NULL; - glade_widget_pop_superuser (); - - return widget; -} - -static gint glade_widget_su_stack = 0; - -/** - * glade_widget_superuser: - * - * Checks if we are in superuser mode. - * - * Superuser mode is when we are - * - Loading a project - * - Dupping a widget recursively - * - Rebuilding an instance for a construct-only property - * - * In these cases, we must act like a load, this should be checked - * from the plugin when implementing containers, when undo/redo comes - * around, the plugin is responsable for maintaining the same container - * size when widgets are added/removed. - */ -gboolean -glade_widget_superuser (void) -{ - return glade_widget_su_stack > 0; -} - -/** - * glade_widget_push_superuser: - * - * Sets superuser mode - */ -void -glade_widget_push_superuser (void) -{ - glade_property_push_superuser (); - glade_widget_su_stack++; -} - - -/** - * glade_widget_pop_superuser: - * - * Unsets superuser mode - */ -void -glade_widget_pop_superuser (void) -{ - if (--glade_widget_su_stack < 0) - { - g_critical ("Bug: widget super user stack is corrupt.\n"); - } - glade_property_pop_superuser (); -} - - -/** - * glade_widget_placeholder_relation: - * @parent: A #GladeWidget - * @widget: The child #GladeWidget - * - * Returns whether placeholders should be used - * in operations concerning this parent & child. - * - * Currently that criteria is whether @parent is a - * GtkContainer, @widget is a GtkWidget and the parent - * adaptor has been marked to use placeholders. - * - * Returns: whether to use placeholders for this relationship. - */ -gboolean -glade_widget_placeholder_relation (GladeWidget *parent, - GladeWidget *widget) -{ - g_return_val_if_fail (GLADE_IS_WIDGET (parent), FALSE); - g_return_val_if_fail (GLADE_IS_WIDGET (widget), FALSE); - - return (GTK_IS_CONTAINER (parent->object) && - GTK_IS_WIDGET (widget->object) && - GWA_USE_PLACEHOLDERS (parent->adaptor)); -} - -static GladeWidgetAction * -glade_widget_action_lookup (GList **actions, const gchar *path, gboolean remove) -{ - GList *l; - - for (l = *actions; l; l = g_list_next (l)) - { - GladeWidgetAction *action = l->data; - - if (strcmp (action->klass->path, path) == 0) - { - if (remove) - { - *actions = g_list_remove (*actions, action); - g_object_unref (action); - return NULL; - } - return action; - } - - if (action->actions && - g_str_has_prefix (path, action->klass->path) && - (action = glade_widget_action_lookup (&action->actions, path, remove))) - return action; - } - - return NULL; -} - -/** - * glade_widget_get_action: - * @widget: a #GladeWidget - * @action_path: a full action path including groups - * - * Returns a #GladeWidgetAction object indentified by @action_path. - * - * Returns: the action or NULL if not found. - */ -GladeWidgetAction * -glade_widget_get_action (GladeWidget *widget, const gchar *action_path) -{ - g_return_val_if_fail (GLADE_IS_WIDGET (widget), NULL); - g_return_val_if_fail (action_path != NULL, NULL); - - return glade_widget_action_lookup (&widget->actions, action_path, FALSE); -} - -/** - * glade_widget_get_pack_action: - * @widget: a #GladeWidget - * @action_path: a full action path including groups - * - * Returns a #GladeWidgetAction object indentified by @action_path. - * - * Returns: the action or NULL if not found. - */ -GladeWidgetAction * -glade_widget_get_pack_action (GladeWidget *widget, const gchar *action_path) -{ - g_return_val_if_fail (GLADE_IS_WIDGET (widget), NULL); - g_return_val_if_fail (action_path != NULL, NULL); - - return glade_widget_action_lookup (&widget->packing_actions, action_path, FALSE); -} - -/** - * glade_widget_remove_action: - * @widget: a #GladeWidget - * @action_path: a full action path including groups - * - * Remove an action. - */ -void -glade_widget_remove_action (GladeWidget *widget, const gchar *action_path) -{ - g_return_if_fail (GLADE_IS_WIDGET (widget)); - g_return_if_fail (action_path != NULL); - - glade_widget_action_lookup (&widget->actions, action_path, TRUE); -} - -/** - * glade_widget_remove_pack_action: - * @widget: a #GladeWidget - * @action_path: a full action path including groups - * - * Remove a packing action. - */ -void -glade_widget_remove_pack_action (GladeWidget *widget, const gchar *action_path) -{ - g_return_if_fail (GLADE_IS_WIDGET (widget)); - g_return_if_fail (action_path != NULL); - - glade_widget_action_lookup (&widget->packing_actions, action_path, TRUE); -} - -/** - * glade_widget_create_action_menu: - * @widget: a #GladeWidget - * @action_path: an action path or NULL to include every @widget action. - * - * Create a new GtkMenu with every action in it. - * - */ -GtkWidget * -glade_widget_create_action_menu (GladeWidget *widget, const gchar *action_path) -{ - GladeWidgetAction *action = NULL; - GtkWidget *menu; - - g_return_val_if_fail (GLADE_IS_WIDGET (widget), NULL); - - if (action_path) - { - action = glade_widget_action_lookup (&widget->actions, action_path, FALSE); - if (action == NULL) - action = glade_widget_action_lookup (&widget->packing_actions, action_path, FALSE); - } - - menu = gtk_menu_new (); - if (glade_popup_action_populate_menu (menu, widget, action, TRUE)) - return menu; - - g_object_unref (G_OBJECT (menu)); - - return NULL; -} - -/******************************************************************************* - * Toplevel GladeWidget Embedding * - ****************************************************************************** - * - * Overrides realize() and size_allocate() by signal connection on GtkWindows. - * - * This is high crack code and should be replaced by a more robust implementation - * in GTK+ proper. - * - */ - -static GQuark -embedded_window_get_quark () -{ - static GQuark embedded_window_quark = 0; - - if (embedded_window_quark == 0) - embedded_window_quark = g_quark_from_string ("GladeEmbedWindow"); - - return embedded_window_quark; -} - -static gboolean -glade_window_is_embedded (GtkWindow *window) -{ - return GPOINTER_TO_INT (g_object_get_qdata ((GObject *) window, embedded_window_get_quark ())); -} - -static void -embedded_window_realize_handler (GtkWidget *widget) -{ - GtkWindow *window; - GdkWindowAttr attributes; - gint attributes_mask; - - window = GTK_WINDOW (widget); - - GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); - - attributes.window_type = GDK_WINDOW_CHILD; - attributes.wclass = GDK_INPUT_OUTPUT; - attributes.visual = gtk_widget_get_visual (widget); - attributes.colormap = gtk_widget_get_colormap (widget); - - attributes.x = widget->allocation.x; - attributes.y = widget->allocation.y; - attributes.width = widget->allocation.width; - attributes.height = widget->allocation.height; - - attributes.event_mask = gtk_widget_get_events (widget) | - GDK_EXPOSURE_MASK | - GDK_FOCUS_CHANGE_MASK | - GDK_KEY_PRESS_MASK | - GDK_KEY_RELEASE_MASK | - GDK_ENTER_NOTIFY_MASK | - GDK_LEAVE_NOTIFY_MASK | - GDK_STRUCTURE_MASK; - - attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; - - /* destroy the previously created window */ - if (GDK_IS_WINDOW (widget->window)) - { - gdk_window_hide (widget->window); - } - - widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), - &attributes, attributes_mask); - - gdk_window_enable_synchronized_configure (widget->window); - - gdk_window_set_user_data (widget->window, window); - - widget->style = gtk_style_attach (widget->style, widget->window); - gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL); - -} - -static void -embedded_window_size_allocate_handler (GtkWidget *widget) -{ - if (GTK_WIDGET_REALIZED (widget)) - { - gdk_window_move_resize (widget->window, - widget->allocation.x, - widget->allocation.y, - widget->allocation.width, - widget->allocation.height); - } -} - -/** - * glade_widget_embed: - * @window: a #GtkWindow - * - * Embeds a window by signal connection method - */ -static void -glade_widget_embed (GladeWidget *widget) -{ - GtkWindow *window; - - g_return_if_fail (GLADE_IS_WIDGET (widget)); - g_return_if_fail (GTK_IS_WINDOW (widget->object)); - - window = GTK_WINDOW (widget->object); - - if (glade_window_is_embedded (window) || GTK_WIDGET_REALIZED (GTK_WIDGET (window))) { - g_critical ("Cannot embed a window that is already realized or embedded"); - return; - } - - GTK_WIDGET_UNSET_FLAGS (GTK_WIDGET (window), GTK_TOPLEVEL); - gtk_container_set_resize_mode (GTK_CONTAINER (window), GTK_RESIZE_PARENT); - - g_signal_connect (G_OBJECT (window), "realize", - G_CALLBACK (embedded_window_realize_handler), NULL); - g_signal_connect (G_OBJECT (window), "size-allocate", - G_CALLBACK (embedded_window_size_allocate_handler), NULL); - - /* mark window as embedded */ - g_object_set_qdata (G_OBJECT (window), - embedded_window_get_quark (), GINT_TO_POINTER (TRUE)); -} - diff --git a/gladeui/glade-widget.h b/gladeui/glade-widget.h deleted file mode 100644 index bbb719fa..00000000 --- a/gladeui/glade-widget.h +++ /dev/null @@ -1,350 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef __GLADE_WIDGET_H__ -#define __GLADE_WIDGET_H__ - -#include <gladeui/glade-widget-adaptor.h> -#include <gladeui/glade-widget-action.h> -#include <gladeui/glade-signal.h> -#include <gladeui/glade-property.h> - -#include <glib.h> -#include <glib-object.h> - -G_BEGIN_DECLS - -#define GLADE_TYPE_WIDGET (glade_widget_get_type ()) -#define GLADE_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_WIDGET, GladeWidget)) -#define GLADE_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_WIDGET, GladeWidgetClass)) -#define GLADE_IS_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_WIDGET)) -#define GLADE_IS_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_WIDGET)) -#define GLADE_WIDGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GLADE_TYPE_WIDGET, GladeWidgetClass)) - -typedef struct _GladeWidgetClass GladeWidgetClass; - -struct _GladeWidget -{ - GObject parent_instance; - - GladeWidgetAdaptor *adaptor; /* An adaptor class for the object type */ - - GladeProject *project; /* A pointer to the project that this - widget currently belongs to. */ - - GladeWidget *parent; /* A pointer to the parent widget in the hierarchy */ - - gchar *name; /* The name of the widget. For example window1 or - * button2. This is a unique name and is the one - * used when loading widget with libglade - */ - - gchar *internal; /* If the widget is an internal child of - * another widget this is the name of the - * internal child, otherwise is NULL. - * Internal children cannot be deleted. - */ - - gboolean anarchist; /* Some composite widgets have internal children - * that are not part of the same hierarchy; hence 'anarchists', - * typicly a popup window or its child (we need to mark - * them so we can avoid bookkeeping packing props on them etc.). - */ - - GObject *object; /* A pointer to the object that was created. - * if it is a GtkWidget; it is shown as a "view" - * of the GladeWidget. This object is updated as - * the properties are modified for the GladeWidget. - */ - - 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 *packing_properties; /* A list of GladeProperty. Note that these - * properties are related to the container - * of the widget, thus they change after - * pasting the widget to a different - * container. Toplevels widget do not have - * packing properties. - * See also child_properties of - * GladeWidgetClass. - */ - - GHashTable *signals; /* A table with a GPtrArray of GladeSignals (signal handlers), - * indexed by its name */ - - gboolean visible; /* Local copy of widget visibility, we need to keep track of this - * since the objects copy may be invalid due to a rebuild. - */ - - - gboolean prop_refs_readonly; /* Whether this list is currently readonly */ - GList *prop_refs; /* List of properties in the project who's value are `this object' - * (this is used to set/unset those properties when the object is - * added/removed from the project). - */ - - gint width; /* Current size used in the UI, this is only */ - gint height; /* usefull for parentless widgets in the - * GladeDesignLayout */ - - GList *actions; /* A GladeWidgetAction list */ - - GList *packing_actions; /* A GladeWidgetAction list, this actions are - * related to the container and they are not always present. - */ - - /* Construct parameters: */ - GladeWidget *construct_template; - GladeWidgetInfo *construct_info; - GladeCreateReason construct_reason; - gchar *construct_internal; -}; - -struct _GladeWidgetClass -{ - GObjectClass parent_class; - - void (*add_child) (GladeWidget *, GladeWidget *, gboolean); - void (*remove_child) (GladeWidget *, GladeWidget *); - void (*replace_child) (GladeWidget *, GObject *, GObject *); - - void (*add_signal_handler) (GladeWidget *, GladeSignal *); - void (*remove_signal_handler) (GladeWidget *, GladeSignal *); - void (*change_signal_handler) (GladeWidget *, GladeSignal *, GladeSignal *); - - gint (*button_press_event) (GladeWidget *, GdkEvent *); - gint (*button_release_event) (GladeWidget *, GdkEvent *); - gint (*motion_notify_event) (GladeWidget *, GdkEvent *); - - gboolean (*event) (GladeWidget *, GdkEvent *); -}; - -/******************************************************************************* - General api - *******************************************************************************/ - -GType glade_widget_get_type (void); - -GladeWidget *glade_widget_get_from_gobject (gpointer object); - -void glade_widget_add_child (GladeWidget *parent, - GladeWidget *child, - gboolean at_mouse); - -void glade_widget_remove_child (GladeWidget *parent, - GladeWidget *child); - -GladeWidgetInfo *glade_widget_write (GladeWidget *widget, - GladeInterface *interface); - -GladeWidget *glade_widget_read (GladeProject *project, - GladeWidgetInfo *info); - -void glade_widget_replace (GladeWidget *parent, - GObject *old_object, - GObject *new_object); - -void glade_widget_rebuild (GladeWidget *gwidget); - -GladeWidget *glade_widget_dup (GladeWidget *template_widget, - gboolean exact); -void glade_widget_copy_signals (GladeWidget *widget, - GladeWidget *template_widget); -void glade_widget_copy_properties (GladeWidget *widget, - GladeWidget *template_widget); - -void glade_widget_set_packing_properties (GladeWidget *widget, - GladeWidget *container); - -GladeProperty *glade_widget_get_property (GladeWidget *widget, - const gchar *id_property); - -GladeProperty *glade_widget_get_pack_property (GladeWidget *widget, - const gchar *id_property); - -GList *glade_widget_dup_properties (GList *template_props, - gboolean as_load); - -void glade_widget_remove_property (GladeWidget *widget, - const gchar *id_property); - -void glade_widget_show (GladeWidget *widget); - -void glade_widget_hide (GladeWidget *widget); - -void glade_widget_add_signal_handler (GladeWidget *widget, - GladeSignal *signal_handler); - -void glade_widget_remove_signal_handler (GladeWidget *widget, - GladeSignal *signal_handler); - -void glade_widget_change_signal_handler (GladeWidget *widget, - GladeSignal *old_signal_handler, - GladeSignal *new_signal_handler); - -GPtrArray * glade_widget_list_signal_handlers (GladeWidget *widget, - const gchar *signal_name); - -gboolean glade_widget_has_decendant (GladeWidget *widget, - GType type); - -gboolean glade_widget_event (GladeWidget *gwidget, - GdkEvent *event); - -gboolean glade_widget_placeholder_relation (GladeWidget *parent, - GladeWidget *widget); - -GladeWidgetAction * glade_widget_get_action (GladeWidget *widget, - const gchar *action_path); - -GladeWidgetAction * glade_widget_get_pack_action (GladeWidget *widget, - const gchar *action_path); - -void glade_widget_remove_action (GladeWidget *widget, - const gchar *action_path); - -void glade_widget_remove_pack_action (GladeWidget *widget, - const gchar *action_path); - -GtkWidget * glade_widget_create_action_menu (GladeWidget *widget, - const gchar *action_path); - -/******************************************************************************* - Project, object property references - *******************************************************************************/ - -void glade_widget_project_notify (GladeWidget *widget, - GladeProject *project); - -void glade_widget_add_prop_ref (GladeWidget *widget, - GladeProperty *property); - -void glade_widget_remove_prop_ref (GladeWidget *widget, - GladeProperty *property); - -/******************************************************************************* - Functions that deal with properties on the runtime object - *******************************************************************************/ - -void glade_widget_object_set_property (GladeWidget *widget, - const gchar *property_name, - const GValue *value); - -void glade_widget_object_get_property (GladeWidget *widget, - const gchar *property_name, - GValue *value); - -void glade_widget_child_set_property (GladeWidget *widget, - GladeWidget *child, - const gchar *property_name, - const GValue *value); - -void glade_widget_child_get_property (GladeWidget *widget, - GladeWidget *child, - const gchar *property_name, - GValue *value); - -/******************************************************************************* - GladeProperty api convenience wrappers - *******************************************************************************/ - -gboolean glade_widget_property_get (GladeWidget *widget, - const gchar *id_property, - ...); - -gboolean glade_widget_property_set (GladeWidget *widget, - const gchar *id_property, - ...); - -gboolean glade_widget_pack_property_get (GladeWidget *widget, - const gchar *id_property, - ...); - -gboolean glade_widget_pack_property_set (GladeWidget *widget, - const gchar *id_property, - ...); - -gboolean glade_widget_property_reset (GladeWidget *widget, - const gchar *id_property); - -gboolean glade_widget_pack_property_reset (GladeWidget *widget, - const gchar *id_property); - -gboolean glade_widget_property_default (GladeWidget *widget, - const gchar *id_property); - -gboolean glade_widget_property_original_default (GladeWidget *widget, - const gchar *id_property); - -gboolean glade_widget_pack_property_default (GladeWidget *widget, - const gchar *id_property); - -gboolean glade_widget_property_set_sensitive (GladeWidget *widget, - const gchar *id_property, - gboolean sensitive, - const gchar *reason); - -gboolean glade_widget_pack_property_set_sensitive (GladeWidget *widget, - const gchar *id_property, - gboolean sensitive, - const gchar *reason); - -gboolean glade_widget_property_set_enabled (GladeWidget *widget, - const gchar *id_property, - gboolean enabled); - -gboolean glade_widget_pack_property_set_enabled (GladeWidget *widget, - const gchar *id_property, - gboolean enabled); - - -gboolean glade_widget_property_set_save_always (GladeWidget *widget, - const gchar *id_property, - gboolean setting); - -gboolean glade_widget_pack_property_set_save_always (GladeWidget *widget, - const gchar *id_property, - gboolean setting); - -/******************************************************************************* - Accessors - *******************************************************************************/ - -void glade_widget_set_name (GladeWidget *widget, - const gchar *name); - -G_CONST_RETURN gchar *glade_widget_get_name (GladeWidget *widget); - -void glade_widget_set_internal (GladeWidget *widget, - const gchar *internal); - -G_CONST_RETURN gchar *glade_widget_get_internal (GladeWidget *widget); - -void glade_widget_set_object (GladeWidget *gwidget, - GObject *new_object); - -GObject *glade_widget_get_object (GladeWidget *widget); - -void glade_widget_set_project (GladeWidget *widget, - GladeProject *project); - -GladeProject *glade_widget_get_project (GladeWidget *widget); - -GladeWidgetAdaptor *glade_widget_get_adaptor (GladeWidget *widget); - -GladeWidget *glade_widget_get_parent (GladeWidget *widget); - -void glade_widget_set_parent (GladeWidget *widget, - GladeWidget *parent); - -gboolean glade_widget_superuser (void); - -void glade_widget_push_superuser (void); - -void glade_widget_pop_superuser (void); - -G_END_DECLS - -#endif /* __GLADE_WIDGET_H__ */ diff --git a/gladeui/glade-xml-utils.c b/gladeui/glade-xml-utils.c deleted file mode 100644 index cc2f841f..00000000 --- a/gladeui/glade-xml-utils.c +++ /dev/null @@ -1,826 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* This functions are based on gnome-print/libgpa/gpa-xml.c which were in turn - * based on gnumeric/xml-io.c - */ -/* Authors: - * Daniel Veillard <Daniel.Veillard@w3.org> - * Miguel de Icaza <miguel@gnu.org> - * Chema Celorio <chema@gnome.org> - */ - -#include "config.h" - -#include <string.h> -#include <glib.h> -#include <errno.h> - -#include "glade-xml-utils.h" - -#include <libxml/tree.h> -#include <libxml/parser.h> -#include <libxml/parserInternals.h> -#include <libxml/xmlmemory.h> - -struct _GladeXmlNode -{ - xmlNodePtr node; -}; - -struct _GladeXmlDoc -{ - xmlDoc doc; -}; - -struct _GladeXmlContext { - GladeXmlDoc *doc; - gboolean freedoc; - xmlNsPtr ns; -}; - - -/* This is used inside for loops so that we skip xml comments - * <!-- i am a comment -> - * also to skip whitespace between nodes - */ -#define skip_text(node) if ((xmlStrcmp ( ((xmlNodePtr)node)->name, BAD_CAST("text")) == 0) ||\ - (xmlStrcmp ( ((xmlNodePtr)node)->name, BAD_CAST("comment")) == 0)) { \ - node = (GladeXmlNode *)((xmlNodePtr)node)->next; continue ; }; -#define skip_text_libxml(node) if ((xmlStrcmp ( ((xmlNodePtr)node)->name, BAD_CAST("text")) == 0) ||\ - (xmlStrcmp ( ((xmlNodePtr)node)->name, BAD_CAST("comment")) == 0)) { \ - node = ((xmlNodePtr)node)->next; continue ; }; - - -static gchar * -claim_string (xmlChar *string) -{ - gchar *ret; - ret = g_strdup (CAST_BAD(string)); - xmlFree (string); - return ret; -} - -/** - * glade_xml_set_value: - * @node_in: a #GladeXmlNode - * @name: a string - * @val: a string - * - * Sets the property @name in @node_in to @val - */ -void -glade_xml_set_value (GladeXmlNode *node_in, const gchar *name, const gchar *val) -{ - xmlNodePtr node = (xmlNodePtr) node_in; - xmlChar *ret; - - ret = xmlGetProp (node, BAD_CAST(name)); - if (ret) - { - xmlFree (ret); - xmlSetProp (node, BAD_CAST(name), BAD_CAST(val)); - return; - } -} - -/** - * glade_xml_get_content: - * @node_in: a #GladeXmlNode - * - * Returns a string containing the content of @node_in. - * Note: It is the caller's responsibility to free the memory used by this - * string. - */ -gchar * -glade_xml_get_content (GladeXmlNode *node_in) -{ - xmlNodePtr node = (xmlNodePtr) node_in; - xmlChar *val = xmlNodeGetContent(node); - - return claim_string (val); -} - -/** - * glade_xml_set_content: - * @node_in: a #GladeXmlNode - * @content: a string - * - * Sets the content of @node to @content. - */ -void -glade_xml_set_content (GladeXmlNode *node_in, const gchar *content) -{ - xmlNodePtr node = (xmlNodePtr) node_in; - - xmlNodeSetContent(node, BAD_CAST(content)); -} - -/* - * Get a value for a node either carried as an attibute or as - * the content of a child. - * - * Returns a g_malloc'ed string. Caller must free. - * (taken from gnumeric ) - * - */ -static gchar * -glade_xml_get_value (xmlNodePtr node, const gchar *name) -{ - xmlNodePtr child; - gchar *ret = NULL; - - for (child = node->children; child; child = child->next) - if (!xmlStrcmp (child->name, BAD_CAST(name))) - ret = claim_string (xmlNodeGetContent(child)); - - return ret; -} - -/** - * glade_xml_node_verify_silent: - * @node_in: a #GladeXmlNode - * @name: a string - * - * Returns: %TRUE if @node_in's name is equal to @name, %FALSE otherwise - */ -gboolean -glade_xml_node_verify_silent (GladeXmlNode *node_in, const gchar *name) -{ - xmlNodePtr node = (xmlNodePtr) node_in; - - g_return_val_if_fail (node != NULL, FALSE); - - if (xmlStrcmp (node->name, BAD_CAST(name)) != 0) - return FALSE; - return TRUE; -} - -/** - * glade_xml_node_verify: - * @node_in: a #GladeXmlNode - * @name: a string - * - * This is a wrapper around glade_xml_node_verify_silent(), only it emits - * a g_warning() if @node_in has a name different than @name. - * - * Returns: %TRUE if @node_in's name is equal to @name, %FALSE otherwise - */ -gboolean -glade_xml_node_verify (GladeXmlNode *node_in, const gchar *name) -{ - xmlNodePtr node = (xmlNodePtr) node_in; - - if (!glade_xml_node_verify_silent (node_in, name)) - { - g_warning ("Expected node was \"%s\", encountered \"%s\"", - name, node->name); - return FALSE; - } - - return TRUE; -} - -/** - * glade_xml_get_value_int: - * @node_in: a #GladeXmlNode - * @name: a string - * @val: a pointer to an #int - * - * Gets an integer value for a node either carried as an attribute or as - * the content of a child. - * - * Returns: %TRUE if the node is found, %FALSE otherwise - */ -gboolean -glade_xml_get_value_int (GladeXmlNode *node_in, const gchar *name, gint *val) -{ - xmlNodePtr node = (xmlNodePtr) node_in; - gchar *value, *endptr = NULL; - gint64 i; - - value = glade_xml_get_value (node, name); - if (value == NULL) - return FALSE; - - errno = 0; - i = g_ascii_strtoll (value, &endptr, 10); - if (errno != 0 || (i == 0 && endptr == value)) { - g_free (value); - return FALSE; - } - - g_free (value); - *val = (gint) i; - return TRUE; -} - -/** - * glade_xml_get_value_int_required: - * @node: a #GladeXmlNode - * @name: a string - * @val: a pointer to an #int - * - * This is a wrapper around glade_xml_get_value_int(), only it emits - * a g_warning() if @node_in did not contain the requested tag - * - * Returns: - **/ -gboolean -glade_xml_get_value_int_required (GladeXmlNode *node, const gchar *name, gint *val) -{ - gboolean ret; - - ret = glade_xml_get_value_int (node, name, val); - - if (ret == FALSE) - g_warning ("The file did not contained the required value \"%s\"\n" - "Under the \"%s\" tag.", name, glade_xml_node_get_name (node)); - - return ret; -} - -/* - * Get a String value for a node either carried as an attibute or as - * the content of a child. - */ -gchar * -glade_xml_get_value_string (GladeXmlNode *node_in, const gchar *name) -{ - xmlNodePtr node = (xmlNodePtr) node_in; - return glade_xml_get_value (node, name); -} - -static gchar * -glade_xml_get_property (xmlNodePtr node, const gchar *name) -{ - xmlChar *val; - - val = xmlGetProp (node, BAD_CAST(name)); - - if (val) - return claim_string (val); - - return NULL; -} - -static void -glade_xml_set_property (xmlNodePtr node, const gchar *name, const gchar *value) -{ - if (value) - xmlSetProp (node, BAD_CAST(name), BAD_CAST(value)); -} - -#define GLADE_TAG_TRUE "True" -#define GLADE_TAG_FALSE "False" -#define GLADE_TAG_TRUE2 "TRUE" -#define GLADE_TAG_FALSE2 "FALSE" -#define GLADE_TAG_TRUE3 "yes" -#define GLADE_TAG_FALSE3 "no" -/* - * Get a String value for a node either carried as an attibute or as - * the content of a child. - */ -gboolean -glade_xml_get_boolean (GladeXmlNode *node_in, const gchar *name, gboolean _default) -{ - xmlNodePtr node = (xmlNodePtr) node_in; - gchar * value; - gboolean ret = FALSE; - - value = glade_xml_get_value (node, name); - if (value == NULL) - return _default; - - if (strcmp (value, GLADE_TAG_FALSE) == 0) - ret = FALSE; - else if (strcmp (value, GLADE_TAG_FALSE2) == 0) - ret = FALSE; - else if (strcmp (value, GLADE_TAG_FALSE3) == 0) - ret = FALSE; - else if (strcmp (value, GLADE_TAG_TRUE) == 0) - ret = TRUE; - else if (strcmp (value, GLADE_TAG_TRUE2) == 0) - ret = TRUE; - else if (strcmp (value, GLADE_TAG_TRUE3) == 0) - ret = TRUE; - else - g_warning ("Boolean tag unrecognized *%s*\n", value); - - g_free (value); - - return ret; -} - -/* - * Get a String value for a node either carried as an attibute or as - * the content of a child. - */ -gboolean -glade_xml_get_property_boolean (GladeXmlNode *node_in, - const gchar *name, - gboolean _default) -{ - xmlNodePtr node = (xmlNodePtr) node_in; - gchar * value; - gboolean ret = FALSE; - - value = glade_xml_get_property (node, name); - if (value == NULL) - return _default; - - if (strcmp (value, GLADE_TAG_FALSE) == 0) - ret = FALSE; - else if (strcmp (value, GLADE_TAG_FALSE2) == 0) - ret = FALSE; - else if (strcmp (value, GLADE_TAG_FALSE3) == 0) - ret = FALSE; - else if (strcmp (value, GLADE_TAG_TRUE) == 0) - ret = TRUE; - else if (strcmp (value, GLADE_TAG_TRUE2) == 0) - ret = TRUE; - else if (strcmp (value, GLADE_TAG_TRUE3) == 0) - ret = TRUE; - else - g_warning ("Boolean tag unrecognized *%s*\n", value); - - g_free (value); - - return ret; -} - -gdouble -glade_xml_get_property_double (GladeXmlNode *node_in, - const gchar *name, - gdouble _default) -{ - xmlNodePtr node = (xmlNodePtr) node_in; - gdouble retval; - gchar *value; - - if ((value = glade_xml_get_property (node, name)) == NULL) - return _default; - - errno = 0; - - retval = g_ascii_strtod (value, NULL); - - if (errno) - { - g_free (value); - return _default; - } - else - { - g_free (value); - return retval; - } -} - -gint -glade_xml_get_property_int (GladeXmlNode *node_in, - const gchar *name, - gint _default) -{ - xmlNodePtr node = (xmlNodePtr) node_in; - gint retval; - gchar *value; - - if ((value = glade_xml_get_property (node, name)) == NULL) - return _default; - - retval = g_ascii_strtoll (value, NULL, 10); - - g_free (value); - - return retval; -} - -void -glade_xml_node_set_property_boolean (GladeXmlNode *node_in, - const gchar *name, - gboolean value) -{ - xmlNodePtr node = (xmlNodePtr) node_in; - - if (value) - glade_xml_set_property (node, name, GLADE_TAG_TRUE); - else - glade_xml_set_property (node, name, GLADE_TAG_FALSE); -} - -#undef GLADE_TAG_TRUE -#undef GLADE_TAG_FALSE -#undef GLADE_TAG_TRUE2 -#undef GLADE_TAG_FALSE2 -#undef GLADE_TAG_TRUE3 -#undef GLADE_TAG_FALSE3 - -gchar * -glade_xml_get_value_string_required (GladeXmlNode *node_in, - const gchar *name, - const gchar *xtra) -{ - xmlNodePtr node = (xmlNodePtr) node_in; - gchar *value = glade_xml_get_value (node, name); - - if (value == NULL) - { - if (xtra == NULL) - g_warning ("The file did not contained the required value \"%s\"\n" - "Under the \"%s\" tag.", name, node->name); - else - g_warning ("The file did not contained the required value \"%s\"\n" - "Under the \"%s\" tag (%s).", name, node->name, xtra); - } - - return value; -} - -gchar * -glade_xml_get_property_string (GladeXmlNode *node_in, const gchar *name) -{ - xmlNodePtr node = (xmlNodePtr) node_in; - - return glade_xml_get_property (node, name); -} - -void -glade_xml_node_set_property_string (GladeXmlNode *node_in, - const gchar *name, - const gchar *string) -{ - xmlNodePtr node = (xmlNodePtr) node_in; - - glade_xml_set_property (node, name, string); -} - -gchar * -glade_xml_get_property_string_required (GladeXmlNode *node_in, - const gchar *name, - const gchar *xtra) -{ - xmlNodePtr node = (xmlNodePtr) node_in; - gchar *value = glade_xml_get_property_string (node_in, name); - - if (value == NULL) - { - if (xtra == NULL) - g_warning ("The file did not contained the required property \"%s\"\n" - "Under the \"%s\" tag.", name, node->name); - else - g_warning ("The file did not contained the required property \"%s\"\n" - "Under the \"%s\" tag (%s).", name, node->name, xtra); - } - return value; -} - -/* - * Search a child by name, - */ -GladeXmlNode * -glade_xml_search_child (GladeXmlNode *node_in, const gchar *name) -{ - xmlNodePtr node; - xmlNodePtr child; - - g_return_val_if_fail (node_in != NULL, NULL); - g_return_val_if_fail (name != NULL, NULL); - - node = (xmlNodePtr) node_in; - - for (child = node->children; child; child = child->next) - { - if (!xmlStrcmp (child->name, BAD_CAST(name))) - return (GladeXmlNode *)child; - } - - return NULL; -} - -/** - * glade_xml_search_child_required: - * @tree: - * @name: - * - * just a small wrapper arround glade_xml_search_child that displays - * an error if the child was not found - * - * Return Value: - **/ -GladeXmlNode * -glade_xml_search_child_required (GladeXmlNode *node, const gchar* name) -{ - GladeXmlNode *child; - - child = glade_xml_search_child (node, name); - - if (child == NULL) - g_warning ("The file did not contained the required tag \"%s\"\n" - "Under the \"%s\" node.", name, glade_xml_node_get_name (node)); - - return child; -} - -/* --------------------------- Parse Context ----------------------------*/ - -static GladeXmlContext * -glade_xml_context_new_real (GladeXmlDoc *doc, gboolean freedoc, xmlNsPtr ns) -{ - GladeXmlContext *context = g_new0 (GladeXmlContext, 1); - - context->doc = doc; - context->freedoc = freedoc; - context->ns = ns; - - return context; -} - -GladeXmlContext * -glade_xml_context_new (GladeXmlDoc *doc, const gchar *name_space) -{ - /* We are not using the namespace now */ - return glade_xml_context_new_real (doc, FALSE, NULL); -} - -void -glade_xml_context_destroy (GladeXmlContext *context) -{ - g_return_if_fail (context != NULL); - if (context->freedoc) - xmlFreeDoc ((xmlDoc*)context->doc); - g_free (context); -} - -GladeXmlContext * -glade_xml_context_new_from_path (const gchar *full_path, - const gchar *nspace, - const gchar *root_name) -{ - GladeXmlContext *context; - xmlDocPtr doc; - xmlNsPtr name_space; - xmlNodePtr root; - - g_return_val_if_fail (full_path != NULL, NULL); - - doc = xmlParseFile (full_path); - - /* That's not an error condition. The file is not readable, and we can't know it - * before we try to read it (testing for readability is a call to race conditions). - * So we should not print a warning */ - if (doc == NULL) - return NULL; - - if (doc->children == NULL) { - g_warning ("Invalid xml File, tree empty [%s]&", full_path); - xmlFreeDoc (doc); - return NULL; - } - - name_space = xmlSearchNsByHref (doc, doc->children, BAD_CAST(nspace)); - if (name_space == NULL && nspace != NULL) - { - g_warning ("The file did not contained the expected name space\n" - "Expected \"%s\" [%s]", - nspace, full_path); - xmlFreeDoc (doc); - return NULL; - } - - root = xmlDocGetRootElement(doc); - if ((root->name == NULL) || (xmlStrcmp (root->name, BAD_CAST(root_name)) !=0 )) - { - g_warning ("The file did not contained the expected root name\n" - "Expected \"%s\", actual : \"%s\" [%s]", - root_name, root->name, full_path); - xmlFreeDoc (doc); - return NULL; - } - - context = glade_xml_context_new_real ((GladeXmlDoc *)doc, TRUE, name_space); - - return context; -} - -/** - * glade_xml_context_free: - * @context: - * - * Similar to glade_xml_context_destroy but it also frees the document set in the context - **/ -void -glade_xml_context_free (GladeXmlContext *context) -{ - g_return_if_fail (context != NULL); - if (context->doc) - xmlFreeDoc ((xmlDocPtr) context->doc); - context->doc = NULL; - - g_free (context); -} - -void -glade_xml_node_append_child (GladeXmlNode *node_in, GladeXmlNode *child_in) -{ - xmlNodePtr node = (xmlNodePtr) node_in; - xmlNodePtr child = (xmlNodePtr) child_in; - - g_return_if_fail (node != NULL); - g_return_if_fail (child != NULL); - - xmlAddChild (node, child); -} - -GladeXmlNode * -glade_xml_node_new (GladeXmlContext *context, const gchar *name) -{ - g_return_val_if_fail (context != NULL, NULL); - g_return_val_if_fail (name != NULL, NULL); - - return (GladeXmlNode *) xmlNewDocNode ((xmlDocPtr) context->doc, context->ns, BAD_CAST(name), NULL); -} - -void -glade_xml_node_delete (GladeXmlNode *node) -{ - xmlFreeNode ((xmlNodePtr) node); -} - -GladeXmlDoc * -glade_xml_context_get_doc (GladeXmlContext *context) -{ - return context->doc; -} - -static gboolean -glade_libxml_node_is_comment (xmlNodePtr node) { - if (node == NULL) - return FALSE; - if ((xmlStrcmp ( node->name, BAD_CAST("text")) == 0) || - (xmlStrcmp ( node->name, BAD_CAST("comment")) == 0)) - return TRUE; - return FALSE; -} - -GladeXmlNode * -glade_xml_node_get_children (GladeXmlNode *node_in) -{ - xmlNodePtr node = (xmlNodePtr) node_in; - xmlNodePtr children; - - children = node->children; - while (glade_libxml_node_is_comment (children)) - children = children->next; - - return (GladeXmlNode *)children; -} - -GladeXmlNode * -glade_xml_node_next (GladeXmlNode *node_in) -{ - xmlNodePtr node = (xmlNodePtr) node_in; - - node = node->next; - while (glade_libxml_node_is_comment (node)) - node = node->next; - - return (GladeXmlNode *)node; -} - -const gchar * -glade_xml_node_get_name (GladeXmlNode *node_in) -{ - xmlNodePtr node = (xmlNodePtr) node_in; - - return CAST_BAD(node->name); -} - -GladeXmlDoc * -glade_xml_doc_new (void) -{ - xmlDocPtr xml_doc = xmlNewDoc (BAD_CAST("1.0")); - - return (GladeXmlDoc *)xml_doc; -} - -void -glade_xml_doc_set_root (GladeXmlDoc *doc_in, GladeXmlNode *node_in) -{ - xmlNodePtr node = (xmlNodePtr) node_in; - xmlDocPtr doc = (xmlDocPtr) doc_in; - - xmlDocSetRootElement (doc, node); -} - -gint -glade_xml_doc_save (GladeXmlDoc *doc_in, const gchar *full_path) -{ - xmlDocPtr doc = (xmlDocPtr) doc_in; - - xmlKeepBlanksDefault (0); - return xmlSaveFormatFile (full_path, doc, 1); -} - -void -glade_xml_doc_free (GladeXmlDoc *doc_in) -{ - xmlDocPtr doc = (xmlDocPtr) doc_in; - - xmlFreeDoc (doc); -} - -/** - * glade_xml_doc_get_root: - * @doc: a #GladeXmlDoc - * - * Returns: the #GladeXmlNode that is the document root of @doc - */ -GladeXmlNode * -glade_xml_doc_get_root (GladeXmlDoc *doc) -{ - xmlNodePtr node; - - node = xmlDocGetRootElement((xmlDocPtr)(doc)); - - return (GladeXmlNode *)node; -} - -gchar * -glade_xml_alloc_string(GladeInterface *interface, const gchar *string) -{ - gchar *s; - - s = g_hash_table_lookup(interface->strings, string); - if (!s) { - s = g_strdup(string); - g_hash_table_insert(interface->strings, s, s); - } - - return s; -} - -gchar * -glade_xml_alloc_propname(GladeInterface *interface, const gchar *string) -{ - static GString *norm_str; - guint i; - - if (!norm_str) - norm_str = g_string_new_len(NULL, 64); - - /* assign the string to norm_str */ - g_string_assign(norm_str, string); - /* convert all dashes to underscores */ - for (i = 0; i < norm_str->len; i++) - if (norm_str->str[i] == '-') - norm_str->str[i] = '_'; - - return glade_xml_alloc_string(interface, norm_str->str); -} - -gboolean -glade_xml_load_sym_from_node (GladeXmlNode *node_in, - GModule *module, - gchar *tagname, - gpointer *sym_location) -{ - static GModule *self = NULL; - gboolean retval = FALSE; - gchar *buff; - - if (!self) - self = g_module_open (NULL, 0); - - if ((buff = glade_xml_get_value_string (node_in, tagname)) != NULL) - { - if (!module) - { - g_warning ("Catalog specified symbol '%s' for tag '%s', " - "no module available to load it from !", - buff, tagname); - g_free (buff); - return FALSE; - } - - /* I use here a g_warning to signal these errors instead of a dialog - * box, as if there is one of this kind of errors, there will probably - * a lot of them, and we don't want to inflict the user the pain of - * plenty of dialog boxes. Ideally, we should collect these errors, - * and show all of them at the end of the load process. - * - * I dont know who wrote the above in glade-property-class.c, but - * its a good point... makeing a bugzilla entry. - * -Tristan - * - * XXX http://bugzilla.gnome.org/show_bug.cgi?id=331797 - */ - if (g_module_symbol (module, buff, sym_location) || - g_module_symbol (self, buff, sym_location)) - retval = TRUE; - else - g_warning ("Could not find %s in %s or in global namespace\n", - buff, g_module_name (module)); - - g_free (buff); - } - return retval; -} diff --git a/gladeui/glade-xml-utils.h b/gladeui/glade-xml-utils.h deleted file mode 100644 index 7c72d52e..00000000 --- a/gladeui/glade-xml-utils.h +++ /dev/null @@ -1,189 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* TODO : s/glade_xml_get_/glade_xml_node_get/g */ -#ifndef __GLADE_XML_UTILS_H__ -#define __GLADE_XML_UTILS_H__ - -#include <gladeui/glade-parser.h> - -G_BEGIN_DECLS - -#define GLADE_XML_CONTEXT(c) ((GladeXmlContext *)c) -#define GLADE_XML_IS_CONTEXT(c) (c != NULL) - -typedef struct _GladeXmlContext GladeXmlContext; -typedef struct _GladeXmlNode GladeXmlNode; -typedef struct _GladeXmlDoc GladeXmlDoc; - -/* Used for catalog tags and attributes */ -#define GLADE_XML_TAG_PROJECT "glade-interface" -#define GLADE_XML_TAG_REQUIRES "requires" -#define GLADE_XML_TAG_WIDGET "widget" -#define GLADE_XML_TAG_PROPERTY "property" -#define GLADE_XML_TAG_CLASS "class" -#define GLADE_XML_TAG_ID "id" -#define GLADE_XML_TAG_SIGNAL "signal" -#define GLADE_XML_TAG_HANDLER "handler" -#define GLADE_XML_TAG_NAME "name" -#define GLADE_XML_TAG_CHILD "child" -#define GLADE_XML_TAG_SIGNAL "signal" -#define GLADE_XML_TAG_AFTER "after" -#define GLADE_XML_TAG_PACKING "packing" -#define GLADE_XML_TAG_PLACEHOLDER "placeholder" -#define GLADE_XML_TAG_INTERNAL_CHILD "internal-child" - -#define GLADE_TAG_GLADE_CATALOG "glade-catalog" -#define GLADE_TAG_GLADE_WIDGET_CLASSES "glade-widget-classes" -#define GLADE_TAG_GLADE_WIDGET_CLASS "glade-widget-class" -#define GLADE_TAG_GLADE_WIDGET_GROUP "glade-widget-group" -#define GLADE_TAG_GLADE_WIDGET_CLASS_REF "glade-widget-class-ref" -#define GLADE_TAG_ADAPTOR "adaptor" -#define GLADE_TAG_LIBRARY "library" -#define GLADE_TAG_DEPENDS "depends" -#define GLADE_TAG_DOMAIN "domain" -#define GLADE_TAG_BOOK "book" -#define GLADE_TAG_SIGNAL_NAME "signal-name" -#define GLADE_TAG_DEFAULT "default" -#define GLADE_TAG_DISABLED "disabled" -#define GLADE_TAG_DEFAULT_PALETTE_STATE "default-palette-state" -#define GLADE_TAG_REPLACE_CHILD_FUNCTION "replace-child-function" -#define GLADE_TAG_POST_CREATE_FUNCTION "post-create-function" -#define GLADE_TAG_GET_INTERNAL_CHILD_FUNCTION "get-internal-child-function" -#define GLADE_TAG_ADD_CHILD_FUNCTION "add-child-function" -#define GLADE_TAG_REMOVE_CHILD_FUNCTION "remove-child-function" -#define GLADE_TAG_GET_CHILDREN_FUNCTION "get-children-function" -#define GLADE_TAG_CHILD_SET_PROP_FUNCTION "child-set-property-function" -#define GLADE_TAG_CHILD_GET_PROP_FUNCTION "child-get-property-function" -#define GLADE_TAG_CHILD_VERIFY_FUNCTION "child-verify-function" -#define GLADE_TAG_CONSTRUCTOR_FUNCTION "constructor-function" -#define GLADE_TAG_ACTION_ACTIVATE_FUNCTION "action-activate-function" -#define GLADE_TAG_CHILD_ACTION_ACTIVATE_FUNCTION "child-action-activate-function" -#define GLADE_TAG_PROPERTIES "properties" -#define GLADE_TAG_PACKING_PROPERTIES "packing-properties" -#define GLADE_TAG_PROPERTY "property" -#define GLADE_TAG_ACTIONS "actions" -#define GLADE_TAG_PACKING_ACTIONS "packing-actions" -#define GLADE_TAG_ACTION "action" -#define GLADE_TAG_TYPE "type" -#define GLADE_TAG_SPEC "spec" -#define GLADE_TAG_TOOLTIP "tooltip" -#define GLADE_TAG_PARAMETERS "parameters" -#define GLADE_TAG_PARAMETER "parameter" -#define GLADE_TAG_SET_FUNCTION "set-property-function" -#define GLADE_TAG_GET_FUNCTION "get-property-function" -#define GLADE_TAG_VERIFY_FUNCTION "verify-function" -#define GLADE_TAG_QUERY "query" -#define GLADE_TAG_COMMON "common" -#define GLADE_TAG_OPTIONAL "optional" -#define GLADE_TAG_OPTIONAL_DEFAULT "optional-default" -#define GLADE_TAG_VISIBLE "visible" -#define GLADE_TAG_EXPANDED "expanded" -#define GLADE_TAG_GENERIC_NAME "generic-name" -#define GLADE_TAG_NAME "name" -#define GLADE_TAG_TITLE "title" -#define GLADE_TAG_ID "id" -#define GLADE_TAG_KEY "key" -#define GLADE_TAG_VALUE "value" -#define GLADE_TAG_TRANSLATABLE "translatable" -#define GLADE_TAG_PACKING_DEFAULTS "packing-defaults" -#define GLADE_TAG_PARENT_CLASS "parent-class" -#define GLADE_TAG_CHILD_PROPERTY "child-property" -#define GLADE_TAG_DISPLAYABLE_VALUES "displayable-values" -#define GLADE_TAG_NICK "nick" -#define GLADE_TAG_SPECIAL_CHILD_TYPE "special-child-type" -#define GLADE_TAG_SAVE "save" -#define GLADE_TAG_SAVE_ALWAYS "save-always" -#define GLADE_TAG_EDITABLE "editable" -#define GLADE_TAG_IGNORE "ignore" -#define GLADE_TAG_VISIBLE_LINES "visible-lines" -#define GLADE_TAG_RESOURCE "resource" -#define GLADE_TAG_INIT_FUNCTION "init-function" -#define GLADE_TAG_ATK_ACTION "atk-action" -#define GLADE_TAG_ATK_PROPERTY "atk-property" -#define GLADE_TAG_FIXED "fixed" -#define GLADE_TAG_TRANSFER_ON_PASTE "transfer-on-paste" -#define GLADE_TAG_WEIGHT "weight" -#define GLADE_TAG_STOCK "stock" -#define GLADE_TAG_GET_TYPE_FUNCTION "get-type-function" -#define GLADE_TAG_TOPLEVEL "toplevel" -#define GLADE_TAG_USE_PLACEHOLDERS "use-placeholders" -#define GLADE_TAG_DEFAULT_WIDTH "default-width" -#define GLADE_TAG_DEFAULT_HEIGHT "default-height" -#define GLADE_TAG_EVENT_HANDLER_CONNECTED "EventHandlerConnected" -#define GLADE_TAG_FALSE "False" -#define GLADE_TAG_TRUE "True" -#define GLADE_TAG_YES "Yes" -#define GLADE_TAG_NO "No" -#define GLADE_TAG_ICON_PREFIX "icon-prefix" -#define GLADE_TAG_ICON_NAME "icon-name" -#define GLADE_TAG_IMPORTANT "important" -#define GLADE_ENUM_DATA_TAG "GladeEnumDataTag" - - -/* search child */ -GladeXmlNode * glade_xml_search_child (GladeXmlNode * node, const gchar *name); -GladeXmlNode * glade_xml_search_child_required (GladeXmlNode * tree, const gchar* name); - -/* content */ - -gchar * glade_xml_get_content (GladeXmlNode * node_in); /* Get the content of the node */ -void glade_xml_set_content (GladeXmlNode *node_in, const gchar *content); - -gboolean glade_xml_get_value_int (GladeXmlNode * node_in, const gchar *name, int *val); -gboolean glade_xml_get_value_int_required (GladeXmlNode * node, const gchar *name, int *val); - -gchar * glade_xml_get_value_string (GladeXmlNode * node, const gchar *name); -gchar * glade_xml_get_value_string_required (GladeXmlNode * node, - const gchar *name, - const gchar *xtra_info); - -gboolean glade_xml_get_boolean (GladeXmlNode * node, const gchar *name, gboolean _default); - -void glade_xml_set_value (GladeXmlNode * node_in, const gchar *name, const gchar *val); - -/* Properties */ -gchar * glade_xml_get_property_string_required (GladeXmlNode *node_in, const gchar *name, const gchar *xtra); -gchar * glade_xml_get_property_string (GladeXmlNode *node_in, const gchar *name); -gboolean glade_xml_get_property_boolean (GladeXmlNode *node_in, const gchar *name, gboolean _default); -gdouble glade_xml_get_property_double (GladeXmlNode *node_in, const gchar *name, gdouble _default); -gint glade_xml_get_property_int (GladeXmlNode *node_in, const gchar *name, gint _default); - -void glade_xml_node_set_property_string (GladeXmlNode *node_in, const gchar *name, const gchar *string); -void glade_xml_node_set_property_boolean (GladeXmlNode *node_in, const gchar *name, gboolean value); - -/* Node operations */ -GladeXmlNode * glade_xml_node_new (GladeXmlContext *context, const gchar *name); -void glade_xml_node_delete (GladeXmlNode *node); -GladeXmlNode * glade_xml_node_get_children (GladeXmlNode *node); -GladeXmlNode * glade_xml_node_next (GladeXmlNode *node_in); -gboolean glade_xml_node_verify (GladeXmlNode * node_in, const gchar *name); -gboolean glade_xml_node_verify_silent (GladeXmlNode *node_in, const gchar *name); -const gchar * glade_xml_node_get_name (GladeXmlNode *node_in); -void glade_xml_node_append_child (GladeXmlNode * node, GladeXmlNode * child); - -/* Document Operatons */ -GladeXmlNode * glade_xml_doc_get_root (GladeXmlDoc *doc); -GladeXmlDoc * glade_xml_doc_new (void); -void glade_xml_doc_set_root (GladeXmlDoc *doc, GladeXmlNode *node); -void glade_xml_doc_free (GladeXmlDoc *doc_in); -gint glade_xml_doc_save (GladeXmlDoc *doc_in, const gchar *full_path); - -/* Parse Context */ -GladeXmlContext * glade_xml_context_new (GladeXmlDoc *doc, const gchar *name_space); -void glade_xml_context_destroy (GladeXmlContext *context); -void glade_xml_context_free (GladeXmlContext *context); -GladeXmlContext * glade_xml_context_new_from_path (const gchar *full_path, - const gchar *nspace, - const gchar *root_name); -GladeXmlDoc * glade_xml_context_get_doc (GladeXmlContext *context); - -gchar * glade_xml_alloc_string (GladeInterface *interface, const gchar *string); -gchar * glade_xml_alloc_propname (GladeInterface *interface, const gchar *string); - -gboolean glade_xml_load_sym_from_node (GladeXmlNode *node_in, - GModule *module, - gchar *tagname, - gpointer *sym_location); - -G_END_DECLS - -#endif /* __GLADE_XML_UTILS_H__ */ diff --git a/gladeui/glade.h b/gladeui/glade.h deleted file mode 100644 index 52b6bbc7..00000000 --- a/gladeui/glade.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * glade.h - * - * Copyright (C) 2007 The GNOME Foundation. - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ -#ifndef __GLADE_H__ -#define __GLADE_H__ - -/* FIXME: forward declarations to get around circular header dependencies. - */ -typedef struct _GladeWidget GladeWidget; -typedef struct _GladeProperty GladeProperty; -typedef struct _GladeProject GladeProject; - -#include <gladeui/glade-widget-adaptor.h> -#include <gladeui/glade-widget.h> -#include <gladeui/glade-property-class.h> -#include <gladeui/glade-property.h> -#include <gladeui/glade-project.h> -#include <gladeui/glade-app.h> -#include <gladeui/glade-command.h> -#include <gladeui/glade-editor.h> -#include <gladeui/glade-palette.h> -#include <gladeui/glade-clipboard.h> -#include <gladeui/glade-inspector.h> -#include <gladeui/glade-placeholder.h> -#include <gladeui/glade-utils.h> -#include <gladeui/glade-builtins.h> -#include <gladeui/glade-fixed.h> - -#endif /* __GLADE_H__ */ diff --git a/gladeui/glade_plugin.def b/gladeui/glade_plugin.def deleted file mode 100644 index 81f374ee..00000000 --- a/gladeui/glade_plugin.def +++ /dev/null @@ -1,27 +0,0 @@ -DESCRIPTION "Implements the core glade functions needed by plugins" -EXPORTS - glade_catalog_load_all - glade_command_create - glade_cursor_init - glade_editor_load_widget - glade_placeholder_get_type - glade_placeholder_new - glade_project_get_tooltips - glade_project_new - glade_project_open - glade_project_remove_widget - glade_project_selection_get - glade_project_window_get - glade_project_window_get_active_project - glade_project_window_new - glade_project_window_new_project - glade_project_window_open_project - glade_project_window_show_all - glade_property_set - glade_setup_log_handlers - glade_widget_class_dump_param_specs - glade_widget_class_get_by_name - glade_widget_get_project - glade_widget_get_property - glade_widget_get_type - glade_widget_new_for_internal_child diff --git a/gladeui/gladeui.rc.in b/gladeui/gladeui.rc.in deleted file mode 100644 index c1ae317c..00000000 --- a/gladeui/gladeui.rc.in +++ /dev/null @@ -1,30 +0,0 @@ -#include <winver.h> - -VS_VERSION_INFO VERSIONINFO - FILEVERSION @GLADE_MAJOR_VERSION@,@GLADE_MINOR_VERSION@,@GLADE_MICRO_VERSION@,0 - PRODUCTVERSION @GLADE_MAJOR_VERSION@,@GLADE_MINOR_VERSION@,@GLADE_MICRO_VERSION@,0 - FILEFLAGSMASK 0 - FILEFLAGS 0 - FILEOS VOS__WINDOWS32 - FILETYPE VFT_DLL - FILESUBTYPE VFT2_UNKNOWN - BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904B0" - BEGIN - VALUE "CompanyName", "The GNOME Foundation" - VALUE "FileDescription", "Glade Interface Designer @GLADE_MAJOR_VERSION@.@GLADE_MINOR_VERSION@.@GLADE_MICRO_VERSION@" - VALUE "FileVersion", "@GLADE_MAJOR_VERSION@.@GLADE_MINOR_VERSION@.@GLADE_MICRO_VERSION@.0" - VALUE "InternalName", "libgladeui-1-@GLADE_CURRENT_MINUS_AGE@" - VALUE "LegalCopyright", "Copyright © 2007 The GNOME Foundation" - VALUE "OriginalFilename", "libgladeui-1-@GLADE_CURRENT_MINUS_AGE@.dll" - VALUE "ProductName", "Glade Interface Designer" - VALUE "ProductVersion", "@GLADE_MAJOR_VERSION@.@GLADE_MINOR_VERSION@.@GLADE_MICRO_VERSION@" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x409, 1200 - END - END |