glade3 r2003 - in trunk: . gladeui plugins/gtk+
- From: tvb svn gnome org
- To: svn-commits-list gnome org
- Subject: glade3 r2003 - in trunk: . gladeui plugins/gtk+
- Date: Sun, 26 Oct 2008 08:12:09 +0000 (UTC)
Author: tvb
Date: Sun Oct 26 08:12:09 2008
New Revision: 2003
URL: http://svn.gnome.org/viewvc/glade3?rev=2003&view=rev
Log:
* plugins/gtk+/Makefile.am, plugins/gtk+/glade-tool-button-editor.[ch]:
Added GtkToolButtonEditor editable implementation.
* plugins/gtk+/gtk+.xml.in, plugins/gtk+/glade-gtk.c: Reimplemented toolbuttons
from ground up.
* gladeui/glade-editor-property.c: object dialog now doesnt do "new" for unmentioned
abstract or uninstantiatable types, also enhanced dialog title.
* gladeui/glade-project.c: Moved "parse-finished" emission to /after/ resolving
object properties (doh !).
Added:
trunk/plugins/gtk+/glade-tool-button-editor.c
trunk/plugins/gtk+/glade-tool-button-editor.h
Modified:
trunk/ChangeLog
trunk/gladeui/glade-builtins.c
trunk/gladeui/glade-editor-property.c
trunk/gladeui/glade-project.c
trunk/plugins/gtk+/Makefile.am
trunk/plugins/gtk+/glade-button-editor.h
trunk/plugins/gtk+/glade-gtk.c
trunk/plugins/gtk+/gtk+.xml.in
Modified: trunk/gladeui/glade-builtins.c
==============================================================================
--- trunk/gladeui/glade-builtins.c (original)
+++ trunk/gladeui/glade-builtins.c Sun Oct 26 08:12:09 2008
@@ -430,8 +430,9 @@
GParamSpec *
glade_standard_pixbuf_spec (void)
{
- return g_param_spec_object ("pixbuf", _("Pixbuf"),
- _("A pixbuf value"), GDK_TYPE_PIXBUF,
+ return g_param_spec_object ("pixbuf", _("Image File Name"),
+ _("Enter a filename, relative or fullpath to "
+ "load the image"), GDK_TYPE_PIXBUF,
G_PARAM_READWRITE);
}
Modified: trunk/gladeui/glade-editor-property.c
==============================================================================
--- trunk/gladeui/glade-editor-property.c (original)
+++ trunk/gladeui/glade-editor-property.c Sun Oct 26 08:12:09 2008
@@ -2537,9 +2537,14 @@
glade_eprop_object_dialog_title (GladeEditorProperty *eprop)
{
GladeWidgetAdaptor *adaptor;
- const gchar *format =
- GLADE_IS_PARAM_SPEC_OBJECTS (eprop->klass->pspec) ?
- _("Choose %s(s) in this project") : _("Choose a %s in this project");
+ const gchar *format;
+
+ if (eprop->klass->parentless_widget)
+ format = GLADE_IS_PARAM_SPEC_OBJECTS (eprop->klass->pspec) ?
+ _("Choose parentless %s(s) in this project") : _("Choose a parentless %s in this project");
+ else
+ format = GLADE_IS_PARAM_SPEC_OBJECTS (eprop->klass->pspec) ?
+ _("Choose %s(s) in this project") : _("Choose a %s in this project");
if (GLADE_IS_PARAM_SPEC_OBJECTS (eprop->klass->pspec))
return g_strdup_printf (format, g_type_name
@@ -2576,7 +2581,9 @@
{
if (eprop->property->klass->create_type)
create_adaptor = glade_widget_adaptor_get_by_name (eprop->property->klass->create_type);
- if (!create_adaptor)
+ if (!create_adaptor &&
+ G_TYPE_IS_INSTANTIATABLE (eprop->klass->pspec->value_type) &&
+ !G_TYPE_IS_ABSTRACT (eprop->klass->pspec->value_type))
create_adaptor = glade_widget_adaptor_get_by_type (eprop->klass->pspec->value_type);
}
Modified: trunk/gladeui/glade-project.c
==============================================================================
--- trunk/gladeui/glade-project.c (original)
+++ trunk/gladeui/glade-project.c Sun Oct 26 08:12:09 2008
@@ -1122,14 +1122,16 @@
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);
+
+ /* Emit "parse-finished" signal */
+ g_signal_emit (project, glade_project_signals [PARSE_FINISHED], 0);
+
+
/* Update ui with versioning info
*/
glade_project_verify_project_for_ui (project);
Modified: trunk/plugins/gtk+/Makefile.am
==============================================================================
--- trunk/plugins/gtk+/Makefile.am (original)
+++ trunk/plugins/gtk+/Makefile.am Sun Oct 26 08:12:09 2008
@@ -25,14 +25,15 @@
libgladegtk_la_SOURCES = glade-gtk.c glade-accels.c glade-attributes.c glade-convert.c fixed-bg.xpm \
glade-column-types.c glade-model-data.c glade-text-button.c glade-cell-renderer-button.c \
- glade-icon-sources.c glade-button-editor.c
+ glade-icon-sources.c glade-button-editor.c glade-tool-button-editor.c
libgladegtk_la_LDFLAGS = -module -avoid-version $(AM_LDFLAGS)
libgladegtk_la_LIBADD = $(libgladeui) $(GTK_LIBS)
libgladegtkincludedir= $(includedir)/libgladeui-1.0/gladeui
libgladegtkinclude_HEADERS = glade-gtk.h glade-accels.h glade-attributes.h glade-column-types.h glade-model-data.h \
- glade-text-button.h glade-cell-renderer-button.h glade-icon-sources.h glade-button-editor.h
+ glade-text-button.h glade-cell-renderer-button.h glade-icon-sources.h glade-button-editor.h \
+ glade-tool-button-editor.c
if PLATFORM_WIN32
libgladegtk_la_LDFLAGS += -no-undefined
Modified: trunk/plugins/gtk+/glade-button-editor.h
==============================================================================
--- trunk/plugins/gtk+/glade-button-editor.h (original)
+++ trunk/plugins/gtk+/glade-button-editor.h Sun Oct 26 08:12:09 2008
@@ -19,8 +19,8 @@
* Authors:
* Tristan Van Berkom <tvb gnome org>
*/
-#ifndef _GLADE_TEXT_EDITOR_H_
-#define _GLADE_TEXT_EDITOR_H_
+#ifndef _GLADE_BUTTON_EDITOR_H_
+#define _GLADE_BUTTON_EDITOR_H_
#include <gtk/gtk.h>
@@ -31,7 +31,7 @@
#define GLADE_BUTTON_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_BUTTON_EDITOR, GladeButtonEditorClass))
#define GLADE_IS_BUTTON_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_BUTTON_EDITOR))
#define GLADE_IS_BUTTON_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_BUTTON_EDITOR))
-#define GLADE_BUTTON_EDITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GLADE_TYPE_BUTTON_EDITOR, GladeButtonButtonClass))
+#define GLADE_BUTTON_EDITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GLADE_TYPE_BUTTON_EDITOR, GladeButtonEditorClass))
typedef struct _GladeButtonEditor GladeButtonEditor;
typedef struct _GladeButtonEditorClass GladeButtonEditorClass;
Modified: trunk/plugins/gtk+/glade-gtk.c
==============================================================================
--- trunk/plugins/gtk+/glade-gtk.c (original)
+++ trunk/plugins/gtk+/glade-gtk.c Sun Oct 26 08:12:09 2008
@@ -32,6 +32,7 @@
#include "glade-model-data.h"
#include "glade-icon-sources.h"
#include "glade-button-editor.h"
+#include "glade-tool-button-editor.h"
#include <gladeui/glade-editor-property.h>
#include <gladeui/glade-base-editor.h>
@@ -180,6 +181,7 @@
0, G_PARAM_READWRITE);
}
+
GType
glade_gtk_image_type_get_type (void)
{
@@ -6699,7 +6701,6 @@
if (GTK_IS_TOOL_BUTTON (child))
glade_base_editor_add_properties (editor, gchild, FALSE,
"label",
- "glade-type",
"icon",
"glade-stock",
"icon-name",
@@ -6800,46 +6801,74 @@
}
/* ----------------------------- GtkToolButton ------------------------------ */
+GladeEditable *
+glade_gtk_tool_button_create_editable (GladeWidgetAdaptor *adaptor,
+ GladeEditorPageType type)
+{
+ GladeEditable *editable;
+
+ /* Get base editable */
+ editable = GWA_GET_CLASS (GTK_TYPE_CONTAINER)->create_editable (adaptor, type);
+
+ if (type == GLADE_PAGE_GENERAL)
+ return (GladeEditable *)glade_tool_button_editor_new (adaptor, editable);
+
+ return editable;
+}
+
+
static void
-glade_gtk_tool_button_set_type (GObject *object, const GValue *value)
+glade_gtk_tool_button_set_image_mode (GObject *object, const GValue *value)
{
GladeWidget *gbutton;
+ const gchar *insensitive_msg = _("Property disabled");
g_return_if_fail (GTK_IS_TOOL_BUTTON (object));
gbutton = glade_widget_get_from_gobject (object);
+
+ glade_widget_property_set_sensitive (gbutton, "glade-stock", FALSE, insensitive_msg);
+ glade_widget_property_set_sensitive (gbutton, "icon-name", FALSE, insensitive_msg);
+ glade_widget_property_set_sensitive (gbutton, "icon", FALSE, insensitive_msg);
+ glade_widget_property_set_sensitive (gbutton, "icon-widget", FALSE, insensitive_msg);
- if (glade_util_object_is_loading (object)) return;
-
- glade_widget_property_set_sensitive (gbutton, "icon", FALSE,
- _("This only applies with file type images"));
- glade_widget_property_set_sensitive (gbutton, "glade-stock", FALSE,
- _("This only applies with stock type images"));
- glade_widget_property_set_sensitive (gbutton, "icon-name", FALSE,
- _("This only applies to Icon Theme type images"));
-
- switch (g_value_get_enum (value))
+ switch (g_value_get_int (value))
{
- case GLADEGTK_IMAGE_FILENAME:
- glade_widget_property_set_sensitive (gbutton, "icon",
- TRUE, NULL);
- glade_widget_property_set (gbutton, "glade-stock", NULL);
- glade_widget_property_set (gbutton, "icon-name", NULL);
+ case GLADE_TB_MODE_STOCK:
+ glade_widget_property_set_sensitive (gbutton, "glade-stock", TRUE, NULL);
break;
- case GLADEGTK_IMAGE_STOCK:
- glade_widget_property_set_sensitive (gbutton, "glade-stock",
- TRUE, NULL);
- glade_widget_property_set (gbutton, "icon", NULL);
- glade_widget_property_set (gbutton, "icon-name", NULL);
+ case GLADE_TB_MODE_ICON:
+ glade_widget_property_set_sensitive (gbutton, "icon-name", TRUE, NULL);
break;
- case GLADEGTK_IMAGE_ICONTHEME:
- glade_widget_property_set_sensitive (gbutton, "icon-name",
- TRUE, NULL);
- glade_widget_property_set (gbutton, "icon", NULL);
- glade_widget_property_set (gbutton, "glade-stock", NULL);
+ case GLADE_TB_MODE_FILENAME:
+ glade_widget_property_set_sensitive (gbutton, "icon", TRUE, NULL);
+ break;
+ case GLADE_TB_MODE_CUSTOM:
+ glade_widget_property_set_sensitive (gbutton, "icon-widget", TRUE, NULL);
+ break;
+ default:
break;
}
}
+
+static void
+glade_gtk_tool_button_set_custom_label (GObject *object, const GValue *value)
+{
+ GladeWidget *gbutton;
+ const gchar *insensitive_msg = _("Property disabled");
+
+ g_return_if_fail (GTK_IS_TOOL_BUTTON (object));
+ gbutton = glade_widget_get_from_gobject (object);
+
+ glade_widget_property_set_sensitive (gbutton, "label", FALSE, insensitive_msg);
+ glade_widget_property_set_sensitive (gbutton, "label-widget", FALSE, insensitive_msg);
+
+ if (g_value_get_boolean (value))
+ glade_widget_property_set_sensitive (gbutton, "label-widget", TRUE, NULL);
+ else
+ glade_widget_property_set_sensitive (gbutton, "label", TRUE, NULL);
+}
+
static void
glade_gtk_tool_button_set_label (GObject *object, const GValue *value)
{
@@ -6893,6 +6922,7 @@
glade_widget_property_set (gbutton, "stock-id", NULL);
}
+/* legacy libglade property */
static void
glade_gtk_tool_button_set_icon (GObject *object, const GValue *value)
{
@@ -6907,26 +6937,19 @@
{
image = gtk_image_new_from_pixbuf (GDK_PIXBUF (pixbuf));
gtk_widget_show (image);
- glade_widget_property_set (gbutton, "glade-type", GLADEGTK_IMAGE_FILENAME);
}
-
gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (object), image);
}
static void
glade_gtk_tool_button_set_icon_name (GObject *object, const GValue *value)
{
- GladeWidget *gbutton;
const gchar *name;
g_return_if_fail (GTK_IS_TOOL_BUTTON (object));
- if ((name = g_value_get_string (value)))
- {
- gbutton = glade_widget_get_from_gobject (object);
- glade_widget_property_set (gbutton, "glade-type", GLADEGTK_IMAGE_ICONTHEME);
- }
-
+ name = g_value_get_string (value);
+
if (name && strlen (name) == 0) name = NULL;
gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (object), name);
@@ -6938,8 +6961,8 @@
const gchar *id,
const GValue *value)
{
- if (!strcmp (id, "glade-type"))
- glade_gtk_tool_button_set_type (object, value);
+ if (!strcmp (id, "image-mode"))
+ glade_gtk_tool_button_set_image_mode (object, value);
else if (!strcmp (id, "glade-stock"))
glade_gtk_tool_button_set_glade_stock (object, value);
else if (!strcmp (id, "icon-name"))
@@ -6950,12 +6973,71 @@
glade_gtk_tool_button_set_stock_id (object, value);
else if (!strcmp (id, "label"))
glade_gtk_tool_button_set_label (object, value);
+ else if (!strcmp (id, "custom-label"))
+ glade_gtk_tool_button_set_custom_label (object, value);
else
GWA_GET_CLASS (GTK_TYPE_TOOL_ITEM)->set_property (adaptor,
object,
id, value);
}
+static void
+glade_gtk_tool_button_parse_finished (GladeProject *project,
+ GladeWidget *widget)
+{
+ gchar *stock_str = NULL, *icon_name = NULL;
+ gint stock_id = 0;
+ GdkPixbuf *pixbuf = NULL;
+ GtkWidget *label_widget = NULL, *image_widget = NULL;
+
+ glade_widget_property_get (widget, "stock-id", &stock_str);
+ glade_widget_property_get (widget, "icon-name", &icon_name);
+ glade_widget_property_get (widget, "icon", &pixbuf);
+ glade_widget_property_get (widget, "icon-widget", &image_widget);
+ glade_widget_property_get (widget, "label-widget", &label_widget);
+
+ if (label_widget)
+ glade_widget_property_set (widget, "custom-label", TRUE);
+ else
+ glade_widget_property_set (widget, "custom-label", FALSE);
+
+ if (image_widget)
+ glade_widget_property_set (widget, "image-mode", GLADE_TB_MODE_CUSTOM);
+ else if (pixbuf)
+ glade_widget_property_set (widget, "image-mode", GLADE_TB_MODE_FILENAME);
+ else if (icon_name)
+ glade_widget_property_set (widget, "image-mode", GLADE_TB_MODE_ICON);
+ else if (stock_str)
+ {
+ /* Update the stock property */
+ stock_id = glade_utils_enum_value_from_string (GLADE_TYPE_STOCK_IMAGE, stock_str);
+ if (stock_id < 0)
+ stock_id = 0;
+ glade_widget_property_set (widget, "glade-stock", stock_id);
+
+ glade_widget_property_set (widget, "image-mode", GLADE_TB_MODE_STOCK);
+ }
+}
+
+void
+glade_gtk_tool_button_read_widget (GladeWidgetAdaptor *adaptor,
+ GladeWidget *widget,
+ GladeXmlNode *node)
+{
+ if (!glade_xml_node_verify
+ (node, GLADE_XML_TAG_WIDGET (glade_project_get_format (widget->project))))
+ return;
+
+ /* First chain up and read in all the normal properties.. */
+ GWA_GET_CLASS (G_TYPE_OBJECT)->read_widget (adaptor, widget, node);
+
+ /* Run this after the load so that icon-widget is resolved. */
+ g_signal_connect (glade_widget_get_project (widget),
+ "parse-finished",
+ G_CALLBACK (glade_gtk_tool_button_parse_finished),
+ widget);
+}
+
/* ----------------------------- GtkLabel ------------------------------ */
static void
glade_gtk_label_set_label (GObject *object, const GValue *value)
Added: trunk/plugins/gtk+/glade-tool-button-editor.c
==============================================================================
--- (empty file)
+++ trunk/plugins/gtk+/glade-tool-button-editor.c Sun Oct 26 08:12:09 2008
@@ -0,0 +1,527 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2008 Tristan Van Berkom.
+ *
+ * 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 <gladeui/glade.h>
+#include <glib/gi18n-lib.h>
+#include <gdk/gdkkeysyms.h>
+
+#include "glade-tool-button-editor.h"
+
+
+static void glade_tool_button_editor_finalize (GObject *object);
+
+static void glade_tool_button_editor_editable_init (GladeEditableIface *iface);
+
+static void glade_tool_button_editor_grab_focus (GtkWidget *widget);
+
+
+G_DEFINE_TYPE_WITH_CODE (GladeToolButtonEditor, glade_tool_button_editor, GTK_TYPE_VBOX,
+ G_IMPLEMENT_INTERFACE (GLADE_TYPE_EDITABLE,
+ glade_tool_button_editor_editable_init));
+
+
+static void
+glade_tool_button_editor_class_init (GladeToolButtonEditorClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ object_class->finalize = glade_tool_button_editor_finalize;
+ widget_class->grab_focus = glade_tool_button_editor_grab_focus;
+}
+
+static void
+glade_tool_button_editor_init (GladeToolButtonEditor *self)
+{
+}
+
+static void
+project_changed (GladeProject *project,
+ GladeCommand *command,
+ gboolean execute,
+ GladeToolButtonEditor *button_editor)
+{
+ if (button_editor->modifying ||
+ !GTK_WIDGET_MAPPED (button_editor))
+ return;
+
+ /* Reload on all commands */
+ glade_editable_load (GLADE_EDITABLE (button_editor), button_editor->loaded_widget);
+}
+
+
+static void
+project_finalized (GladeToolButtonEditor *button_editor,
+ GladeProject *where_project_was)
+{
+ button_editor->loaded_widget = NULL;
+
+ glade_editable_load (GLADE_EDITABLE (button_editor), NULL);
+}
+
+static void
+glade_tool_button_editor_load (GladeEditable *editable,
+ GladeWidget *widget)
+{
+ GladeToolButtonEditor *button_editor = GLADE_TOOL_BUTTON_EDITOR (editable);
+ gboolean custom_label = FALSE;
+ gint image_mode = 0;
+ GList *l;
+
+ button_editor->loading = TRUE;
+
+ /* Since we watch the project*/
+ if (button_editor->loaded_widget)
+ {
+ /* watch custom-child and use-stock properties here for reloads !!! */
+
+ g_signal_handlers_disconnect_by_func (G_OBJECT (button_editor->loaded_widget->project),
+ G_CALLBACK (project_changed), button_editor);
+
+ /* The widget could die unexpectedly... */
+ g_object_weak_unref (G_OBJECT (button_editor->loaded_widget->project),
+ (GWeakNotify)project_finalized,
+ button_editor);
+ }
+
+ /* Mark our widget... */
+ button_editor->loaded_widget = widget;
+
+ if (button_editor->loaded_widget)
+ {
+ /* This fires for undo/redo */
+ g_signal_connect (G_OBJECT (button_editor->loaded_widget->project), "changed",
+ G_CALLBACK (project_changed), button_editor);
+
+ /* The widget/project could die unexpectedly... */
+ g_object_weak_ref (G_OBJECT (button_editor->loaded_widget->project),
+ (GWeakNotify)project_finalized,
+ button_editor);
+ }
+
+ /* load the embedded editable... */
+ glade_editable_load (GLADE_EDITABLE (button_editor->embed), widget);
+
+ for (l = button_editor->properties; l; l = l->next)
+ glade_editor_property_load_by_widget (GLADE_EDITOR_PROPERTY (l->data), widget);
+
+ if (widget)
+ {
+ glade_widget_property_get (widget, "image-mode", &image_mode);
+ glade_widget_property_get (widget, "custom-label", &custom_label);
+
+ if (custom_label)
+ gtk_toggle_button_set_active
+ (GTK_TOGGLE_BUTTON (button_editor->custom_label_radio), TRUE);
+ else
+ gtk_toggle_button_set_active
+ (GTK_TOGGLE_BUTTON (button_editor->standard_label_radio), TRUE);
+
+ switch (image_mode)
+ {
+ case GLADE_TB_MODE_STOCK:
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button_editor->stock_radio), TRUE);
+ break;
+ case GLADE_TB_MODE_ICON:
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button_editor->icon_radio), TRUE);
+ break;
+ case GLADE_TB_MODE_FILENAME:
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button_editor->file_radio), TRUE);
+ break;
+ case GLADE_TB_MODE_CUSTOM:
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button_editor->custom_radio), TRUE);
+ break;
+ default:
+ break;
+ }
+ }
+ button_editor->loading = FALSE;
+}
+
+
+static void
+standard_label_toggled (GtkWidget *widget,
+ GladeToolButtonEditor *button_editor)
+{
+ GladeProperty *property;
+ GValue value = { 0, };
+
+ if (button_editor->loading || !button_editor->loaded_widget)
+ return;
+
+ if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_editor->standard_label_radio)))
+ return;
+
+ button_editor->modifying = TRUE;
+
+ glade_command_push_group (_("Setting %s to use standard label text"), button_editor->loaded_widget->name);
+
+ property = glade_widget_get_property (button_editor->loaded_widget, "label-widget");
+ glade_command_set_property (property, NULL);
+
+ property = glade_widget_get_property (button_editor->loaded_widget, "label");
+ glade_property_get_default (property, &value);
+ glade_command_set_property_value (property, &value);
+ g_value_unset (&value);
+ property = glade_widget_get_property (button_editor->loaded_widget, "custom-label");
+ glade_command_set_property (property, FALSE);
+
+ glade_command_pop_group ();
+
+ button_editor->modifying = FALSE;
+
+ /* reload buttons and sensitivity and stuff... */
+ glade_editable_load (GLADE_EDITABLE (button_editor),
+ button_editor->loaded_widget);
+}
+
+static void
+custom_label_toggled (GtkWidget *widget,
+ GladeToolButtonEditor *button_editor)
+{
+ GladeProperty *property;
+
+ if (button_editor->loading || !button_editor->loaded_widget)
+ return;
+
+ if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_editor->custom_label_radio)))
+ return;
+
+ button_editor->modifying = TRUE;
+
+ glade_command_push_group (_("Setting %s to use a custom label widget"), button_editor->loaded_widget->name);
+
+ property = glade_widget_get_property (button_editor->loaded_widget, "label");
+ glade_command_set_property (property, NULL);
+ property = glade_widget_get_property (button_editor->loaded_widget, "custom-label");
+ glade_command_set_property (property, TRUE);
+
+ glade_command_pop_group ();
+
+ button_editor->modifying = FALSE;
+
+ /* reload buttons and sensitivity and stuff... */
+ glade_editable_load (GLADE_EDITABLE (button_editor),
+ button_editor->loaded_widget);
+}
+
+static void
+stock_toggled (GtkWidget *widget,
+ GladeToolButtonEditor *button_editor)
+{
+ GladeProperty *property;
+
+ if (button_editor->loading || !button_editor->loaded_widget)
+ return;
+
+ if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_editor->stock_radio)))
+ return;
+
+ button_editor->modifying = TRUE;
+
+ glade_command_push_group (_("Setting %s to use an image from stock"), button_editor->loaded_widget->name);
+
+ property = glade_widget_get_property (button_editor->loaded_widget, "icon-name");
+ glade_command_set_property (property, NULL);
+ property = glade_widget_get_property (button_editor->loaded_widget, "icon");
+ glade_command_set_property (property, NULL);
+ property = glade_widget_get_property (button_editor->loaded_widget, "icon-widget");
+ glade_command_set_property (property, NULL);
+ property = glade_widget_get_property (button_editor->loaded_widget, "image-mode");
+ glade_command_set_property (property, GLADE_TB_MODE_STOCK);
+
+ glade_command_pop_group ();
+
+ button_editor->modifying = FALSE;
+
+ /* reload buttons and sensitivity and stuff... */
+ glade_editable_load (GLADE_EDITABLE (button_editor),
+ button_editor->loaded_widget);
+}
+
+
+static void
+icon_toggled (GtkWidget *widget,
+ GladeToolButtonEditor *button_editor)
+{
+ GladeProperty *property;
+
+ if (button_editor->loading || !button_editor->loaded_widget)
+ return;
+
+ if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_editor->icon_radio)))
+ return;
+
+ button_editor->modifying = TRUE;
+
+ glade_command_push_group (_("Setting %s to use an image from the icon theme"), button_editor->loaded_widget->name);
+
+ property = glade_widget_get_property (button_editor->loaded_widget, "glade-stock");
+ glade_command_set_property (property, 0);
+ property = glade_widget_get_property (button_editor->loaded_widget, "icon");
+ glade_command_set_property (property, NULL);
+ property = glade_widget_get_property (button_editor->loaded_widget, "icon-widget");
+ glade_command_set_property (property, NULL);
+ property = glade_widget_get_property (button_editor->loaded_widget, "image-mode");
+ glade_command_set_property (property, GLADE_TB_MODE_ICON);
+
+ glade_command_pop_group ();
+
+ button_editor->modifying = FALSE;
+
+ /* reload buttons and sensitivity and stuff... */
+ glade_editable_load (GLADE_EDITABLE (button_editor),
+ button_editor->loaded_widget);
+}
+
+static void
+file_toggled (GtkWidget *widget,
+ GladeToolButtonEditor *button_editor)
+{
+ GladeProperty *property;
+
+ if (button_editor->loading || !button_editor->loaded_widget)
+ return;
+
+ if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_editor->file_radio)))
+ return;
+
+ button_editor->modifying = TRUE;
+
+ glade_command_push_group (_("Setting %s to use an image from the icon theme"), button_editor->loaded_widget->name);
+
+ property = glade_widget_get_property (button_editor->loaded_widget, "glade-stock");
+ glade_command_set_property (property, 0);
+ property = glade_widget_get_property (button_editor->loaded_widget, "icon-name");
+ glade_command_set_property (property, NULL);
+ property = glade_widget_get_property (button_editor->loaded_widget, "icon-widget");
+ glade_command_set_property (property, NULL);
+ property = glade_widget_get_property (button_editor->loaded_widget, "image-mode");
+ glade_command_set_property (property, GLADE_TB_MODE_FILENAME);
+
+ glade_command_pop_group ();
+
+ button_editor->modifying = FALSE;
+
+ /* reload buttons and sensitivity and stuff... */
+ glade_editable_load (GLADE_EDITABLE (button_editor),
+ button_editor->loaded_widget);
+}
+
+static void
+custom_toggled (GtkWidget *widget,
+ GladeToolButtonEditor *button_editor)
+{
+ GladeProperty *property;
+
+ if (button_editor->loading || !button_editor->loaded_widget)
+ return;
+
+ if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_editor->custom_radio)))
+ return;
+
+ button_editor->modifying = TRUE;
+
+ glade_command_push_group (_("Setting %s to use an image from the icon theme"), button_editor->loaded_widget->name);
+
+ property = glade_widget_get_property (button_editor->loaded_widget, "glade-stock");
+ glade_command_set_property (property, 0);
+ property = glade_widget_get_property (button_editor->loaded_widget, "icon-name");
+ glade_command_set_property (property, NULL);
+ property = glade_widget_get_property (button_editor->loaded_widget, "icon");
+ glade_command_set_property (property, NULL);
+ property = glade_widget_get_property (button_editor->loaded_widget, "image-mode");
+ glade_command_set_property (property, GLADE_TB_MODE_CUSTOM);
+
+ glade_command_pop_group ();
+
+ button_editor->modifying = FALSE;
+
+ /* reload buttons and sensitivity and stuff... */
+ glade_editable_load (GLADE_EDITABLE (button_editor),
+ button_editor->loaded_widget);
+}
+
+
+static void
+glade_tool_button_editor_editable_init (GladeEditableIface *iface)
+{
+ iface->load = glade_tool_button_editor_load;
+}
+
+static void
+glade_tool_button_editor_finalize (GObject *object)
+{
+ GladeToolButtonEditor *button_editor = GLADE_TOOL_BUTTON_EDITOR (object);
+
+ if (button_editor->properties)
+ g_list_free (button_editor->properties);
+
+ G_OBJECT_CLASS (glade_tool_button_editor_parent_class)->finalize (object);
+}
+
+static void
+glade_tool_button_editor_grab_focus (GtkWidget *widget)
+{
+ GladeToolButtonEditor *button_editor = GLADE_TOOL_BUTTON_EDITOR (widget);
+
+ gtk_widget_grab_focus (button_editor->embed);
+}
+
+static void
+table_attach (GtkWidget *table,
+ GtkWidget *child,
+ gint pos, gint row)
+{
+ gtk_table_attach (GTK_TABLE (table), child,
+ pos, pos+1, row, row +1,
+ GTK_EXPAND | GTK_FILL,
+ GTK_EXPAND | GTK_FILL,
+ 3, 1);
+}
+
+
+GtkWidget *
+glade_tool_button_editor_new (GladeWidgetAdaptor *adaptor,
+ GladeEditable *embed)
+{
+ GladeToolButtonEditor *button_editor;
+ GladeEditorProperty *eprop;
+ GtkWidget *label, *alignment, *frame, *table;
+ gchar *str;
+
+ g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL);
+ g_return_val_if_fail (GLADE_IS_EDITABLE (embed), NULL);
+
+ button_editor = g_object_new (GLADE_TYPE_TOOL_BUTTON_EDITOR, NULL);
+ button_editor->embed = GTK_WIDGET (embed);
+
+ /* Pack the parent on top... */
+ gtk_box_pack_start (GTK_BOX (button_editor), GTK_WIDGET (embed), FALSE, FALSE, 0);
+
+ /* Label area frame... */
+ str = g_strdup_printf ("<b>%s</b>", _("Edit Label"));
+ label = gtk_label_new (str);
+ gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
+ g_free (str);
+ frame = gtk_frame_new (NULL);
+ gtk_frame_set_label_widget (GTK_FRAME (frame), label);
+ gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
+ gtk_box_pack_start (GTK_BOX (button_editor), frame, FALSE, FALSE, 8);
+
+ alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F);
+ gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0);
+ gtk_container_add (GTK_CONTAINER (frame), alignment);
+
+ table = gtk_table_new (0, 0, FALSE);
+ gtk_container_add (GTK_CONTAINER (alignment), table);
+
+ /* Standard label... */
+ eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "label", FALSE, TRUE);
+ button_editor->standard_label_radio = gtk_radio_button_new (NULL);
+ gtk_container_add (GTK_CONTAINER (button_editor->standard_label_radio),
+ eprop->item_label);
+ table_attach (table, button_editor->standard_label_radio, 0, 0);
+ table_attach (table, GTK_WIDGET (eprop), 1, 0);
+ button_editor->properties = g_list_prepend (button_editor->properties, eprop);
+
+ /* Custom label... */
+ eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "label-widget", FALSE, TRUE);
+ button_editor->custom_label_radio = gtk_radio_button_new_from_widget
+ (GTK_RADIO_BUTTON (button_editor->standard_label_radio));
+ gtk_container_add (GTK_CONTAINER (button_editor->custom_label_radio),
+ eprop->item_label);
+ table_attach (table, button_editor->custom_label_radio, 0, 1);
+ table_attach (table, GTK_WIDGET (eprop), 1, 1);
+ button_editor->properties = g_list_prepend (button_editor->properties, eprop);
+
+ /* Image area frame... */
+ str = g_strdup_printf ("<b>%s</b>", _("Edit Image"));
+ label = gtk_label_new (str);
+ gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
+ g_free (str);
+ frame = gtk_frame_new (NULL);
+ gtk_frame_set_label_widget (GTK_FRAME (frame), label);
+ gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
+ gtk_box_pack_start (GTK_BOX (button_editor), frame, FALSE, FALSE, 8);
+
+ alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F);
+ gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0);
+ gtk_container_add (GTK_CONTAINER (frame), alignment);
+
+ table = gtk_table_new (0, 0, FALSE);
+ gtk_container_add (GTK_CONTAINER (alignment), table);
+
+ /* Stock image... */
+ eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "glade-stock", FALSE, TRUE);
+ button_editor->stock_radio = gtk_radio_button_new (NULL);
+ gtk_container_add (GTK_CONTAINER (button_editor->stock_radio), eprop->item_label);
+ table_attach (table, button_editor->stock_radio, 0, 0);
+ table_attach (table, GTK_WIDGET (eprop), 1, 0);
+ button_editor->properties = g_list_prepend (button_editor->properties, eprop);
+
+ /* Icon theme image... */
+ eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "icon-name", FALSE, TRUE);
+ button_editor->icon_radio = gtk_radio_button_new_from_widget
+ (GTK_RADIO_BUTTON (button_editor->stock_radio));
+ gtk_container_add (GTK_CONTAINER (button_editor->icon_radio), eprop->item_label);
+ table_attach (table, button_editor->icon_radio, 0, 1);
+ table_attach (table, GTK_WIDGET (eprop), 1, 1);
+ button_editor->properties = g_list_prepend (button_editor->properties, eprop);
+
+ /* Filename... */
+ eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "icon", FALSE, TRUE);
+ button_editor->file_radio = gtk_radio_button_new_from_widget
+ (GTK_RADIO_BUTTON (button_editor->stock_radio));
+ gtk_container_add (GTK_CONTAINER (button_editor->file_radio), eprop->item_label);
+ table_attach (table, button_editor->file_radio, 0, 2);
+ table_attach (table, GTK_WIDGET (eprop), 1, 2);
+ button_editor->properties = g_list_prepend (button_editor->properties, eprop);
+
+ /* Custom embedded image widget... */
+ eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "icon-widget", FALSE, TRUE);
+ button_editor->custom_radio = gtk_radio_button_new_from_widget
+ (GTK_RADIO_BUTTON (button_editor->stock_radio));
+ gtk_container_add (GTK_CONTAINER (button_editor->custom_radio), eprop->item_label);
+ table_attach (table, button_editor->custom_radio, 0, 3);
+ table_attach (table, GTK_WIDGET (eprop), 1, 3);
+ button_editor->properties = g_list_prepend (button_editor->properties, eprop);
+
+ /* Connect radio button signals... */
+ g_signal_connect (G_OBJECT (button_editor->standard_label_radio), "toggled",
+ G_CALLBACK (standard_label_toggled), button_editor);
+ g_signal_connect (G_OBJECT (button_editor->custom_label_radio), "toggled",
+ G_CALLBACK (custom_label_toggled), button_editor);
+ g_signal_connect (G_OBJECT (button_editor->stock_radio), "toggled",
+ G_CALLBACK (stock_toggled), button_editor);
+ g_signal_connect (G_OBJECT (button_editor->icon_radio), "toggled",
+ G_CALLBACK (icon_toggled), button_editor);
+ g_signal_connect (G_OBJECT (button_editor->file_radio), "toggled",
+ G_CALLBACK (file_toggled), button_editor);
+ g_signal_connect (G_OBJECT (button_editor->custom_radio), "toggled",
+ G_CALLBACK (custom_toggled), button_editor);
+
+ gtk_widget_show_all (GTK_WIDGET (button_editor));
+
+ return GTK_WIDGET (button_editor);
+}
Added: trunk/plugins/gtk+/glade-tool-button-editor.h
==============================================================================
--- (empty file)
+++ trunk/plugins/gtk+/glade-tool-button-editor.h Sun Oct 26 08:12:09 2008
@@ -0,0 +1,81 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2008 Tristan Van Berkom.
+ *
+ * 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>
+ */
+#ifndef _GLADE_TOOL_BUTTON_EDITOR_H_
+#define _GLADE_TOOL_BUTTON_EDITOR_H_
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GLADE_TYPE_TOOL_BUTTON_EDITOR (glade_tool_button_editor_get_type ())
+#define GLADE_TOOL_BUTTON_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_TOOL_BUTTON_EDITOR, GladeToolButtonEditor))
+#define GLADE_TOOL_BUTTON_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_TOOL_BUTTON_EDITOR, GladeToolButtonEditorClass))
+#define GLADE_IS_TOOL_BUTTON_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_TOOL_BUTTON_EDITOR))
+#define GLADE_IS_TOOL_BUTTON_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_TOOL_BUTTON_EDITOR))
+#define GLADE_TOOL_BUTTON_EDITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GLADE_TYPE_TOOL_BUTTON_EDITOR, GladeToolButtonEditorClass))
+
+typedef struct _GladeToolButtonEditor GladeToolButtonEditor;
+typedef struct _GladeToolButtonEditorClass GladeToolButtonEditorClass;
+
+typedef enum {
+ GLADE_TB_MODE_STOCK = 0, /* default */
+ GLADE_TB_MODE_ICON,
+ GLADE_TB_MODE_FILENAME,
+ GLADE_TB_MODE_CUSTOM
+} GladeToolButtonImageMode;
+
+
+struct _GladeToolButtonEditor
+{
+ GtkVBox parent;
+
+ GladeWidget *loaded_widget; /* A handy pointer to the loaded widget ... */
+
+ GtkWidget *embed; /* Embedded parent class editor */
+
+ GtkWidget *standard_label_radio; /* Set label with label property */
+ GtkWidget *custom_label_radio; /* Set a widget to be placed as the tool button's label */
+
+
+ GtkWidget *stock_radio; /* Create the image from stock-id */
+ GtkWidget *icon_radio; /* Create the image with the icon theme */
+ GtkWidget *file_radio; /* Create the image from filename (libglade only) */
+ GtkWidget *custom_radio; /* Set a widget to be used in the image position */
+
+ GList *properties; /* A list of eprops to update at load() time */
+
+ gboolean loading; /* Loading flag for loading widgets in the editor */
+ gboolean modifying; /* Flag for monitoring project changes */
+};
+
+struct _GladeToolButtonEditorClass
+{
+ GtkVBoxClass parent;
+};
+
+GType glade_tool_button_editor_get_type (void);
+GtkWidget *glade_tool_button_editor_new (GladeWidgetAdaptor *adaptor,
+ GladeEditable *editable);
+
+G_END_DECLS
+
+#endif /* _GLADE_BUTTON_EDITOR_H_ */
Modified: trunk/plugins/gtk+/gtk+.xml.in
==============================================================================
--- trunk/plugins/gtk+/gtk+.xml.in (original)
+++ trunk/plugins/gtk+/gtk+.xml.in Sun Oct 26 08:12:09 2008
@@ -517,26 +517,33 @@
<glade-widget-class name="GtkToolButton" generic-name="toolbutton" _title="Tool Button">
-
+ <create-editable-function>glade_gtk_tool_button_create_editable</create-editable-function>
<set-property-function>glade_gtk_tool_button_set_property</set-property-function>
+ <read-widget-function>glade_gtk_tool_button_read_widget</read-widget-function>
<properties>
- <property id="icon-widget" parentless-widget="True" libglade-unsupported="True"/>
- <property id="label-widget" parentless-widget="True" libglade-unsupported="True"/>
- <property id="glade-type" _name="Image Type" save="False">
- <spec>glade_gtk_image_type_spec</spec>
- <displayable-values>
- <value id="GLADEGTK_IMAGE_FILENAME" _name="Filename"/>
- <value id="GLADEGTK_IMAGE_STOCK" _name="Stock"/>
- <value id="GLADEGTK_IMAGE_ICONTHEME" _name="Icon Theme"/>
- </displayable-values>
- </property>
- <property id="glade-stock" _name="Stock Image" save="False">
+ <!-- Virtual label type property -->
+ <property id="custom-label" visible="False" save="False">
+ <spec>glade_standard_boolean_spec</spec>
+ </property>
+ <!-- Virtual image edit mode property -->
+ <property id="image-mode" visible="False" save="False">
+ <spec>glade_standard_int_spec</spec>
+ </property>
+
+ <!-- Virtual stock comboentry property -->
+ <property id="stock-id" visible="False"/>
+ <property id="glade-stock" _name="Stock Image" save="False" custom-layout="True">
<spec>glade_standard_stock_image_spec</spec>
</property>
- <property id="label" translatable="True"/>
- <property id="icon" _name="File Name">
+ <property id="label" translatable="True" default="toolbutton" custom-layout="True"/>
+ <property id="label-widget" parentless-widget="True" libglade-unsupported="True"
+ create-type="GtkLabel" custom-layout="True"/>
+ <property id="icon-name" themed-icon="True" custom-layout="True"/>
+ <property id="icon" libglade-only="True" custom-layout="True">
<spec>glade_standard_pixbuf_spec</spec>
</property>
+ <property id="icon-widget" parentless-widget="True" libglade-unsupported="True"
+ create-type="GtkImage" custom-layout="True"/>
</properties>
</glade-widget-class>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]