From 40928bb578a61dcffb7d8d9ff47ed5cfe7b1dc76 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Thu, 4 Nov 2004 12:15:49 +0000 Subject: [PATCH] use a GtkUIManager instead of a GtkItemFactory. Added virtual function 2004-11-04 Michael Natterer * libgimpwidgets/gimpcolorbutton.[ch]: use a GtkUIManager instead of a GtkItemFactory. Added virtual function ::get_action_type() and create the manager's actions manually using that action type instead of using gtk_action_group_add_actions(). * app/widgets/gimpcolorpanel.c: override ::get_action_type() so it creates GimpActions (which can have a color attached) instead of GtkActions. Changed the menu item visibility and color preview code accordingly. * app/widgets/Makefile.am * app/widgets/gimpitemfactory.[ch]: finally removed. * configure.in: added -DGTK_DISABLE_DEPRECATED to CPPFLAGS again. --- ChangeLog | 17 + app/widgets/Makefile.am | 2 - app/widgets/gimpcolorpanel.c | 190 ++--- app/widgets/gimpitemfactory.c | 1175 ------------------------------ app/widgets/gimpitemfactory.h | 161 ---- configure.in | 5 +- libgimpwidgets/gimpcolorbutton.c | 328 +++++---- libgimpwidgets/gimpcolorbutton.h | 7 +- 8 files changed, 324 insertions(+), 1561 deletions(-) delete mode 100644 app/widgets/gimpitemfactory.c delete mode 100644 app/widgets/gimpitemfactory.h diff --git a/ChangeLog b/ChangeLog index f681cb343c..ba96e4f027 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2004-11-04 Michael Natterer + + * libgimpwidgets/gimpcolorbutton.[ch]: use a GtkUIManager instead + of a GtkItemFactory. Added virtual function ::get_action_type() + and create the manager's actions manually using that action type + instead of using gtk_action_group_add_actions(). + + * app/widgets/gimpcolorpanel.c: override ::get_action_type() so it + creates GimpActions (which can have a color attached) instead of + GtkActions. Changed the menu item visibility and color preview + code accordingly. + + * app/widgets/Makefile.am + * app/widgets/gimpitemfactory.[ch]: finally removed. + + * configure.in: added -DGTK_DISABLE_DEPRECATED to CPPFLAGS again. + 2004-11-04 Michael Natterer * libgimpwidgets/gimpoldwidgets.c: #undef GTK_DISABLE_DEPRECATED diff --git a/app/widgets/Makefile.am b/app/widgets/Makefile.am index b9740b6c3c..c48702437d 100644 --- a/app/widgets/Makefile.am +++ b/app/widgets/Makefile.am @@ -166,8 +166,6 @@ libappwidgets_a_sources = \ gimpimageeditor.h \ gimpimageview.c \ gimpimageview.h \ - gimpitemfactory.c \ - gimpitemfactory.h \ gimpitemtreeview.c \ gimpitemtreeview.h \ gimplayertreeview.c \ diff --git a/app/widgets/gimpcolorpanel.c b/app/widgets/gimpcolorpanel.c index f338418eef..aa7b882a73 100644 --- a/app/widgets/gimpcolorpanel.c +++ b/app/widgets/gimpcolorpanel.c @@ -27,9 +27,9 @@ #include "core/gimp.h" #include "core/gimpcontext.h" +#include "gimpaction.h" #include "gimpcolordialog.h" #include "gimpcolorpanel.h" -#include "gimpitemfactory.h" /* local function prototypes */ @@ -37,16 +37,17 @@ static void gimp_color_panel_class_init (GimpColorPanelClass *klass); static void gimp_color_panel_init (GimpColorPanel *panel); -static void gimp_color_panel_destroy (GtkObject *object); -static gboolean gimp_color_panel_button_press (GtkWidget *widget, - GdkEventButton *bevent); -static void gimp_color_panel_color_changed (GimpColorButton *button); -static void gimp_color_panel_clicked (GtkButton *button); +static void gimp_color_panel_destroy (GtkObject *object); +static gboolean gimp_color_panel_button_press (GtkWidget *widget, + GdkEventButton *bevent); +static void gimp_color_panel_clicked (GtkButton *button); +static void gimp_color_panel_color_changed (GimpColorButton *button); +static GType gimp_color_panel_get_action_type (GimpColorButton *button); -static void gimp_color_panel_dialog_update (GimpColorDialog *dialog, - const GimpRGB *color, - GimpColorDialogState state, - GimpColorPanel *panel); +static void gimp_color_panel_dialog_update (GimpColorDialog *dialog, + const GimpRGB *color, + GimpColorDialogState state, + GimpColorPanel *panel); static GimpColorButtonClass *parent_class = NULL; @@ -90,10 +91,11 @@ gimp_color_panel_class_init (GimpColorPanelClass *klass) parent_class = g_type_class_peek_parent (klass); - object_class->destroy = gimp_color_panel_destroy; - widget_class->button_press_event = gimp_color_panel_button_press; - button_class->clicked = gimp_color_panel_clicked; - color_button_class->color_changed = gimp_color_panel_color_changed; + object_class->destroy = gimp_color_panel_destroy; + widget_class->button_press_event = gimp_color_panel_button_press; + button_class->clicked = gimp_color_panel_clicked; + color_button_class->color_changed = gimp_color_panel_color_changed; + color_button_class->get_action_type = gimp_color_panel_get_action_type; } static void @@ -125,43 +127,45 @@ gimp_color_panel_button_press (GtkWidget *widget, { GimpColorButton *color_button; GimpColorPanel *color_panel; - GtkItemFactory *item_factory; - GimpRGB black, white; + GtkUIManager *ui_manager; + GtkActionGroup *group; + GtkAction *action; + GimpRGB color; color_button = GIMP_COLOR_BUTTON (widget); color_panel = GIMP_COLOR_PANEL (widget); - item_factory = GTK_ITEM_FACTORY (color_button->popup_menu); + ui_manager = GTK_UI_MANAGER (color_button->popup_menu); - gimp_item_factory_set_visible (item_factory, - "/Foreground color", - color_panel->context != NULL); - gimp_item_factory_set_visible (item_factory, - "/Background color", - color_panel->context != NULL); - gimp_item_factory_set_visible (item_factory, - "/fg-bg-separator", - color_panel->context != NULL); + group = gtk_ui_manager_get_action_groups (ui_manager)->data; + + action = gtk_action_group_get_action (group, + "color-button-use-foreground"); + g_object_set (action, "visible", color_panel->context != NULL, NULL); + + action = gtk_action_group_get_action (group, + "color-button-use-background"); + g_object_set (action, "visible", color_panel->context != NULL, NULL); if (color_panel->context) { - GimpRGB fg, bg; + action = gtk_action_group_get_action (group, + "color-button-use-foreground"); + gimp_context_get_foreground (color_panel->context, &color); + g_object_set (action, "color", &color, NULL); - gimp_context_get_foreground (color_panel->context, &fg); - gimp_context_get_background (color_panel->context, &bg); - - gimp_item_factory_set_color (item_factory, - "/Foreground color", &fg, FALSE); - gimp_item_factory_set_color (item_factory, - "/Background color", &bg, FALSE); + action = gtk_action_group_get_action (group, + "color-button-use-background"); + gimp_context_get_background (color_panel->context, &color); + g_object_set (action, "color", &color, NULL); } - gimp_rgba_set (&black, 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE); - gimp_rgba_set (&white, 1.0, 1.0, 1.0, GIMP_OPACITY_OPAQUE); + action = gtk_action_group_get_action (group, "color-button-use-black"); + gimp_rgba_set (&color, 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE); + g_object_set (action, "color", &color, NULL); - gimp_item_factory_set_color (item_factory, - "/Black", &black, FALSE); - gimp_item_factory_set_color (item_factory, - "/White", &white, FALSE); + action = gtk_action_group_get_action (group, "color-button-use-white"); + gimp_rgba_set (&color, 1.0, 1.0, 1.0, GIMP_OPACITY_OPAQUE); + g_object_set (action, "color", &color, NULL); } if (GTK_WIDGET_CLASS (parent_class)->button_press_event) @@ -170,53 +174,6 @@ gimp_color_panel_button_press (GtkWidget *widget, return FALSE; } -GtkWidget * -gimp_color_panel_new (const gchar *title, - const GimpRGB *color, - GimpColorAreaType type, - gint width, - gint height) -{ - GimpColorPanel *panel; - - g_return_val_if_fail (title != NULL, NULL); - g_return_val_if_fail (color != NULL, NULL); - - panel = g_object_new (GIMP_TYPE_COLOR_PANEL, NULL); - - GIMP_COLOR_BUTTON (panel)->title = g_strdup (title); - - gimp_color_button_set_type (GIMP_COLOR_BUTTON (panel), type); - gimp_color_button_set_color (GIMP_COLOR_BUTTON (panel), color); - gtk_widget_set_size_request (GTK_WIDGET (panel), width, height); - - return GTK_WIDGET (panel); -} - -void -gimp_color_panel_set_context (GimpColorPanel *panel, - GimpContext *context) -{ - g_return_if_fail (GIMP_IS_COLOR_PANEL (panel)); - g_return_if_fail (context == NULL || GIMP_IS_CONTEXT (context)); - - panel->context = context; -} - -static void -gimp_color_panel_color_changed (GimpColorButton *button) -{ - GimpColorPanel *panel = GIMP_COLOR_PANEL (button); - GimpRGB color; - - if (panel->color_dialog) - { - gimp_color_button_get_color (GIMP_COLOR_BUTTON (button), &color); - gimp_color_dialog_set_color (GIMP_COLOR_DIALOG (panel->color_dialog), - &color); - } -} - static void gimp_color_panel_clicked (GtkButton *button) { @@ -249,6 +206,65 @@ gimp_color_panel_clicked (GtkButton *button) gtk_window_present (GTK_WINDOW (panel->color_dialog)); } +static GType +gimp_color_panel_get_action_type (GimpColorButton *button) +{ + return GIMP_TYPE_ACTION; +} + + +/* public functions */ + +GtkWidget * +gimp_color_panel_new (const gchar *title, + const GimpRGB *color, + GimpColorAreaType type, + gint width, + gint height) +{ + GimpColorPanel *panel; + + g_return_val_if_fail (title != NULL, NULL); + g_return_val_if_fail (color != NULL, NULL); + + panel = g_object_new (GIMP_TYPE_COLOR_PANEL, NULL); + + GIMP_COLOR_BUTTON (panel)->title = g_strdup (title); + + gimp_color_button_set_type (GIMP_COLOR_BUTTON (panel), type); + gimp_color_button_set_color (GIMP_COLOR_BUTTON (panel), color); + gtk_widget_set_size_request (GTK_WIDGET (panel), width, height); + + return GTK_WIDGET (panel); +} + +static void +gimp_color_panel_color_changed (GimpColorButton *button) +{ + GimpColorPanel *panel = GIMP_COLOR_PANEL (button); + GimpRGB color; + + if (panel->color_dialog) + { + gimp_color_button_get_color (GIMP_COLOR_BUTTON (button), &color); + gimp_color_dialog_set_color (GIMP_COLOR_DIALOG (panel->color_dialog), + &color); + } +} + +void +gimp_color_panel_set_context (GimpColorPanel *panel, + GimpContext *context) +{ + g_return_if_fail (GIMP_IS_COLOR_PANEL (panel)); + g_return_if_fail (context == NULL || GIMP_IS_CONTEXT (context)); + + panel->context = context; +} + + +/* private functions */ + static void gimp_color_panel_dialog_update (GimpColorDialog *dialog, const GimpRGB *color, diff --git a/app/widgets/gimpitemfactory.c b/app/widgets/gimpitemfactory.c deleted file mode 100644 index f2e5e9cc50..0000000000 --- a/app/widgets/gimpitemfactory.c +++ /dev/null @@ -1,1175 +0,0 @@ -/* The GIMP -- an image manipulation program - * Copyright (C) 1995 Spencer Kimball and Peter Mattis - * - * 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 "string.h" - -#include -#include - -#include "libgimpbase/gimpbase.h" -#include "libgimpwidgets/gimpwidgets.h" - -#include "widgets-types.h" - -#include "config/gimpguiconfig.h" - -#include "core/gimp.h" - -#include "gimphelp-ids.h" -#include "gimpitemfactory.h" -#include "gimpwidgets-utils.h" - -#include "gimphelp.h" - -#include "gimp-intl.h" - - -/* local function prototypes */ - -static void gimp_item_factory_class_init (GimpItemFactoryClass *klass); -static void gimp_item_factory_init (GimpItemFactory *factory); - -static void gimp_item_factory_finalize (GObject *object); -static void gimp_item_factory_destroy (GtkObject *object); - -static void gimp_item_factory_create_branches (GimpItemFactory *factory, - GimpItemFactoryEntry *entry, - const gchar *textdomain); -static void gimp_item_factory_item_realize (GtkWidget *widget, - GimpItemFactory *factory); -static gboolean gimp_item_factory_item_key_press (GtkWidget *widget, - GdkEventKey *kevent, - GimpItemFactory *factory); -static void gimp_item_factory_menu_position (GtkMenu *menu, - gint *x, - gint *y, - gpointer data); -static gchar * gimp_item_factory_translate (const gchar *path, - gpointer data); - - -static GtkItemFactoryClass *parent_class = NULL; - - -GType -gimp_item_factory_get_type (void) -{ - static GType factory_type = 0; - - if (! factory_type) - { - static const GTypeInfo factory_info = - { - sizeof (GimpItemFactoryClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) gimp_item_factory_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (GimpItemFactory), - 0, /* n_preallocs */ - (GInstanceInitFunc) gimp_item_factory_init, - }; - - factory_type = g_type_register_static (GTK_TYPE_ITEM_FACTORY, - "GimpItemFactory", - &factory_info, 0); - } - - return factory_type; -} - -static void -gimp_item_factory_class_init (GimpItemFactoryClass *klass) -{ - GObjectClass *object_class; - GtkObjectClass *gtk_object_class; - - object_class = G_OBJECT_CLASS (klass); - gtk_object_class = GTK_OBJECT_CLASS (klass); - - parent_class = g_type_class_peek_parent (klass); - - object_class->finalize = gimp_item_factory_finalize; - - gtk_object_class->destroy = gimp_item_factory_destroy; - - klass->factories = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, NULL); -} - -static void -gimp_item_factory_init (GimpItemFactory *factory) -{ - factory->gimp = NULL; - factory->update_func = NULL; - factory->update_on_popup = FALSE; - factory->title = NULL; - factory->help_id = NULL; - factory->translation_trash = NULL; -} - -static void -gimp_item_factory_finalize (GObject *object) -{ - GimpItemFactory *factory; - - factory = GIMP_ITEM_FACTORY (object); - - if (factory->title) - { - g_free (factory->title); - factory->title = NULL; - } - - if (factory->help_id) - { - g_free (factory->help_id); - factory->help_id = NULL; - } - - G_OBJECT_CLASS (parent_class)->finalize (object); -} - -static void -gimp_item_factory_destroy (GtkObject *object) -{ - GimpItemFactory *factory; - gchar *factory_path; - - factory = GIMP_ITEM_FACTORY (object); - - factory_path = GTK_ITEM_FACTORY (object)->path; - - if (factory_path) - { - GimpItemFactoryClass *factory_class; - GList *list; - - factory_class = GIMP_ITEM_FACTORY_GET_CLASS (factory); - - list = g_hash_table_lookup (factory_class->factories, factory_path); - - if (list) - { - list = g_list_remove (list, factory); - - if (list) - g_hash_table_replace (factory_class->factories, - g_strdup (factory_path), - list); - else - g_hash_table_remove (factory_class->factories, factory_path); - } - } - - GTK_OBJECT_CLASS (parent_class)->destroy (object); - - if (GTK_ITEM_FACTORY (factory)->widget) - g_object_unref (GTK_ITEM_FACTORY (factory)->widget); -} - - -/* public functions */ - -GimpItemFactory * -gimp_item_factory_new (Gimp *gimp, - GType container_type, - const gchar *factory_path, - const gchar *title, - const gchar *help_id, - GimpItemFactoryUpdateFunc update_func, - gboolean update_on_popup, - guint n_entries, - GimpItemFactoryEntry *entries, - gpointer callback_data, - gboolean create_tearoff) -{ - GimpItemFactoryClass *factory_class; - GimpItemFactory *factory; - GList *list; - - g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL); - g_return_val_if_fail (factory_path != NULL, NULL); - g_return_val_if_fail (title != NULL, NULL); - g_return_val_if_fail (help_id != NULL, NULL); - g_return_val_if_fail (factory_path[0] == '<', NULL); - g_return_val_if_fail (factory_path[strlen (factory_path) - 1] == '>', NULL); - - factory_class = g_type_class_ref (GIMP_TYPE_ITEM_FACTORY); - - factory = g_object_new (GIMP_TYPE_ITEM_FACTORY, NULL); - - gtk_item_factory_construct (GTK_ITEM_FACTORY (factory), - container_type, - factory_path, - NULL); - - gtk_item_factory_set_translate_func (GTK_ITEM_FACTORY (factory), - gimp_item_factory_translate, - factory, - NULL); - - factory->gimp = gimp; - factory->update_func = update_func; - factory->update_on_popup = update_on_popup; - factory->create_tearoff = create_tearoff; - factory->title = g_strdup (title); - factory->help_id = g_strdup (help_id); - - list = g_hash_table_lookup (factory_class->factories, factory_path); - - list = g_list_append (list, factory); - - g_hash_table_replace (factory_class->factories, - g_strdup (factory_path), - list); - - gimp_item_factory_create_items (factory, - n_entries, - entries, - callback_data, 2, TRUE); - - g_type_class_unref (factory_class); - - if (GTK_ITEM_FACTORY (factory)->widget) - g_object_ref (GTK_ITEM_FACTORY (factory)->widget); - - return factory; -} - -GimpItemFactory * -gimp_item_factory_from_path (const gchar *path) -{ - GList *list; - - list = gimp_item_factories_from_path (path); - - if (list) - return list->data; - - return NULL; -} - -GList * -gimp_item_factories_from_path (const gchar *path) -{ - GimpItemFactoryClass *factory_class; - GList *list; - gchar *base_path; - gchar *p; - - g_return_val_if_fail (path != NULL, NULL); - - base_path = g_strdup (path); - - p = strchr (base_path, '>'); - - if (p) - p[1] = '\0'; - - factory_class = g_type_class_ref (GIMP_TYPE_ITEM_FACTORY); - - list = g_hash_table_lookup (factory_class->factories, base_path); - - g_type_class_unref (factory_class); - - g_free (base_path); - - return list; -} - -void -gimp_item_factory_create_item (GimpItemFactory *item_factory, - GimpItemFactoryEntry *entry, - const gchar *textdomain, - gpointer callback_data, - guint callback_type, - gboolean static_entry) -{ - GtkWidget *menu_item; - gchar *menu_path; - gboolean tearoffs; - - g_return_if_fail (GIMP_IS_ITEM_FACTORY (item_factory)); - g_return_if_fail (entry != NULL); - - tearoffs = GIMP_GUI_CONFIG (item_factory->gimp->config)->tearoff_menus; - - if (! (strstr (entry->entry.path, "tearoff"))) - { - if (tearoffs && item_factory->create_tearoff) - { - gimp_item_factory_create_branches (item_factory, entry, textdomain); - } - } - else if (! tearoffs || ! item_factory->create_tearoff) - { - return; - } - - if (entry->quark_string) - { - GQuark quark; - - if (static_entry) - quark = g_quark_from_static_string (entry->quark_string); - else - quark = g_quark_from_string (entry->quark_string); - - entry->entry.callback_action = (guint) quark; - } - - if (textdomain) - g_object_set_data (G_OBJECT (item_factory), "textdomain", - (gpointer) textdomain); - - gtk_item_factory_create_item (GTK_ITEM_FACTORY (item_factory), - (GtkItemFactoryEntry *) entry, - callback_data, - callback_type); - - if (textdomain) - g_object_set_data (G_OBJECT (item_factory), "textdomain", NULL); - - if (item_factory->translation_trash) - { - g_list_foreach (item_factory->translation_trash, (GFunc) g_free, NULL); - g_list_free (item_factory->translation_trash); - item_factory->translation_trash = NULL; - } - - menu_path = gimp_strip_uline (((GtkItemFactoryEntry *) entry)->path); - - menu_item = gtk_item_factory_get_item (GTK_ITEM_FACTORY (item_factory), - menu_path); - - g_free (menu_path); - - if (menu_item) - { - g_signal_connect_after (menu_item, "realize", - G_CALLBACK (gimp_item_factory_item_realize), - item_factory); - - if (entry->help_id) - { - if (static_entry) - g_object_set_data (G_OBJECT (menu_item), "gimp-help-id", - (gpointer) entry->help_id); - else - g_object_set_data_full (G_OBJECT (menu_item), "gimp-help-id", - g_strdup (entry->help_id), - g_free); - } - } -} - -void -gimp_item_factory_create_items (GimpItemFactory *item_factory, - guint n_entries, - GimpItemFactoryEntry *entries, - gpointer callback_data, - guint callback_type, - gboolean static_entries) -{ - gint i; - - for (i = 0; i < n_entries; i++) - { - gimp_item_factory_create_item (item_factory, - entries + i, - NULL, - callback_data, - callback_type, - static_entries); - } -} - -void -gimp_item_factory_update (GimpItemFactory *item_factory, - gpointer popup_data) -{ - g_return_if_fail (GIMP_IS_ITEM_FACTORY (item_factory)); - - if (item_factory->update_func) - item_factory->update_func (GTK_ITEM_FACTORY (item_factory), popup_data); -} - -void -gimp_item_factory_popup_with_data (GimpItemFactory *item_factory, - gpointer popup_data, - GtkWidget *parent, - GimpMenuPositionFunc position_func, - gpointer position_data, - GtkDestroyNotify popdown_func) -{ - GdkEvent *current_event; - gint x, y; - guint button; - guint32 activate_time; - - g_return_if_fail (GIMP_IS_ITEM_FACTORY (item_factory)); - g_return_if_fail (GTK_IS_WIDGET (parent)); - - if (item_factory->update_on_popup) - gimp_item_factory_update (item_factory, popup_data); - - if (! position_func) - { - position_func = gimp_item_factory_menu_position; - position_data = parent; - } - - (* position_func) (GTK_MENU (GTK_ITEM_FACTORY (item_factory)->widget), - &x, &y, position_data); - - current_event = gtk_get_current_event (); - - if (current_event && current_event->type == GDK_BUTTON_PRESS) - { - GdkEventButton *bevent; - - bevent = (GdkEventButton *) current_event; - - button = bevent->button; - activate_time = bevent->time; - } - else - { - button = 0; - activate_time = 0; - } - - gtk_item_factory_popup_with_data (GTK_ITEM_FACTORY (item_factory), - popup_data, - popdown_func, - x, y, - button, - activate_time); -} - -void -gimp_item_factory_set_active (GtkItemFactory *factory, - const gchar *path, - gboolean active) -{ - GtkWidget *widget; - - g_return_if_fail (GTK_IS_ITEM_FACTORY (factory)); - g_return_if_fail (path != NULL); - - widget = gtk_item_factory_get_widget (factory, path); - - if (widget) - { - if (GTK_IS_CHECK_MENU_ITEM (widget)) - { - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (widget), active); - } - else - { - g_warning ("%s: Unable to set \"active\" for menu item " - "of type \"%s\": %s", - G_STRFUNC, - g_type_name (G_TYPE_FROM_INSTANCE (widget)), - path); - } - } - else if (! strstr (path, "Script-Fu")) - { - g_warning ("%s: Unable to set \"active\" for menu item " - "which doesn't exist: %s", - G_STRFUNC, path); - } -} - -void -gimp_item_factories_set_active (const gchar *factory_path, - const gchar *path, - gboolean active) -{ - GList *list; - - g_return_if_fail (factory_path != NULL); - g_return_if_fail (path != NULL); - - for (list = gimp_item_factories_from_path (factory_path); - list; - list = g_list_next (list)) - { - gimp_item_factory_set_active (GTK_ITEM_FACTORY (list->data), - path, active); - } -} - -void -gimp_item_factory_set_color (GtkItemFactory *factory, - const gchar *path, - const GimpRGB *color, - gboolean set_label) -{ - GtkWidget *widget; - GtkWidget *area = NULL; - GtkWidget *label = NULL; - GdkScreen *screen; - - g_return_if_fail (GTK_IS_ITEM_FACTORY (factory)); - g_return_if_fail (path != NULL); - g_return_if_fail (color != NULL); - - widget = gtk_item_factory_get_widget (factory, path); - - if (! widget) - { - g_warning ("%s: Unable to set color of menu item " - "which doesn't exist: %s", - G_STRFUNC, path); - return; - } - - if (GTK_IS_HBOX (GTK_BIN (widget)->child)) - { - area = g_object_get_data (G_OBJECT (GTK_BIN (widget)->child), - "color_area"); - label = g_object_get_data (G_OBJECT (GTK_BIN (widget)->child), - "label"); - } - else if (GTK_IS_LABEL (GTK_BIN (widget)->child)) - { - GtkWidget *hbox; - gint width, height; - - label = GTK_BIN (widget)->child; - - g_object_ref (label); - - gtk_container_remove (GTK_CONTAINER (widget), label); - - hbox = gtk_hbox_new (FALSE, 4); - gtk_container_add (GTK_CONTAINER (widget), hbox); - gtk_widget_show (hbox); - - area = gimp_color_area_new (color, GIMP_COLOR_AREA_SMALL_CHECKS, 0); - gimp_color_area_set_draw_border (GIMP_COLOR_AREA (area), TRUE); - - screen = gtk_widget_get_screen (area); - gtk_icon_size_lookup_for_settings (gtk_settings_get_for_screen (screen), - GTK_ICON_SIZE_MENU, &width, &height); - - gtk_widget_set_size_request (area, width, height); - gtk_box_pack_start (GTK_BOX (hbox), area, FALSE, FALSE, 0); - gtk_widget_show (area); - - gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0); - gtk_widget_show (label); - - g_object_unref (label); - - g_object_set_data (G_OBJECT (hbox), "color_area", area); - g_object_set_data (G_OBJECT (hbox), "label", label); - } - - if (area) - gimp_color_area_set_color (GIMP_COLOR_AREA (area), color); - - if (label && set_label) - { - gchar *str; - - str = g_strdup_printf (_("RGBA (%0.3f, %0.3f, %0.3f, %0.3f)"), - color->r, color->g, color->b, color->a); - - gtk_label_set_text (GTK_LABEL (label), str); - - g_free (str); - } -} - -void -gimp_item_factories_set_color (const gchar *factory_path, - const gchar *path, - const GimpRGB *color, - gboolean set_label) -{ - GList *list; - - g_return_if_fail (factory_path != NULL); - g_return_if_fail (path != NULL); - g_return_if_fail (color != NULL); - - for (list = gimp_item_factories_from_path (factory_path); - list; - list = g_list_next (list)) - { - gimp_item_factory_set_color (GTK_ITEM_FACTORY (list->data), - path, color, set_label); - } -} - -void -gimp_item_factory_set_label (GtkItemFactory *factory, - const gchar *path, - const gchar *label) -{ - GtkWidget *widget; - - g_return_if_fail (GTK_IS_ITEM_FACTORY (factory)); - g_return_if_fail (path != NULL); - g_return_if_fail (label != NULL); - - widget = gtk_item_factory_get_widget (factory, path); - - if (widget) - { - if (GTK_IS_MENU (widget)) - widget = gtk_menu_get_attach_widget (GTK_MENU (widget)); - - if (GTK_IS_LABEL (GTK_BIN (widget)->child)) - gtk_label_set_text_with_mnemonic (GTK_LABEL (GTK_BIN (widget)->child), - label); - } - else - { - g_warning ("%s: Unable to set label of menu item " - "which doesn't exist: %s", - G_STRFUNC, path); - } -} - -void -gimp_item_factories_set_label (const gchar *factory_path, - const gchar *path, - const gchar *label) -{ - GList *list; - - g_return_if_fail (factory_path != NULL); - g_return_if_fail (path != NULL); - g_return_if_fail (label != NULL); - - for (list = gimp_item_factories_from_path (factory_path); - list; - list = g_list_next (list)) - { - gimp_item_factory_set_label (GTK_ITEM_FACTORY (list->data), - path, label); - } -} - -void -gimp_item_factory_set_sensitive (GtkItemFactory *factory, - const gchar *path, - gboolean sensitive) -{ - GtkWidget *widget; - - g_return_if_fail (GTK_IS_ITEM_FACTORY (factory)); - g_return_if_fail (path != NULL); - - widget = gtk_item_factory_get_widget (factory, path); - - if (widget) - { - gtk_widget_set_sensitive (widget, sensitive); - } - else if (! strstr (path, "Script-Fu")) - { - g_warning ("%s: Unable to set sensitivity of menu item " - "which doesn't exist: %s", - G_STRFUNC, path); - } -} - -void -gimp_item_factories_set_sensitive (const gchar *factory_path, - const gchar *path, - gboolean sensitive) -{ - GList *list; - - g_return_if_fail (factory_path != NULL); - g_return_if_fail (path != NULL); - - for (list = gimp_item_factories_from_path (factory_path); - list; - list = g_list_next (list)) - { - gimp_item_factory_set_sensitive (GTK_ITEM_FACTORY (list->data), - path, sensitive); - } -} - -void -gimp_item_factory_set_visible (GtkItemFactory *factory, - const gchar *path, - gboolean visible) -{ - GtkWidget *widget; - - g_return_if_fail (GTK_IS_ITEM_FACTORY (factory)); - g_return_if_fail (path != NULL); - - widget = gtk_item_factory_get_widget (factory, path); - - if (widget) - { - if (GTK_IS_MENU (widget)) - widget = gtk_menu_get_attach_widget (GTK_MENU (widget)); - - if (visible) - gtk_widget_show (widget); - else - gtk_widget_hide (widget); - } - else - { - g_warning ("%s: Unable to set visibility of menu item " - "which doesn't exist: %s", - G_STRFUNC, path); - } -} - -void -gimp_item_factories_set_visible (const gchar *factory_path, - const gchar *path, - gboolean visible) -{ - GList *list; - - g_return_if_fail (factory_path != NULL); - g_return_if_fail (path != NULL); - - for (list = gimp_item_factories_from_path (factory_path); - list; - list = g_list_next (list)) - { - gimp_item_factory_set_visible (GTK_ITEM_FACTORY (list->data), - path, visible); - } -} - -void -gimp_item_factory_tearoff_callback (GtkWidget *widget, - gpointer data, - guint action) -{ - if (GTK_IS_TEAROFF_MENU_ITEM (widget)) - { - GtkTearoffMenuItem *tomi = (GtkTearoffMenuItem *) widget; - - if (tomi->torn_off) - { - GtkWidget *toplevel; - - toplevel = gtk_widget_get_toplevel (widget); - - if (! GTK_IS_WINDOW (toplevel)) - { - g_warning ("%s: tearoff menu not in top level window", - G_STRFUNC); - } - else - { -#ifdef __GNUC__ -#warning FIXME: register tearoffs -#endif - g_object_set_data (G_OBJECT (widget), "tearoff-menu-toplevel", - toplevel); - } - } - else - { - GtkWidget *toplevel; - - toplevel = (GtkWidget *) g_object_get_data (G_OBJECT (widget), - "tearoff-menu-toplevel"); - - if (! toplevel) - { - g_warning ("%s: can't unregister tearoff menu top level window", - G_STRFUNC); - } - else - { -#ifdef __GNUC__ -#warning FIXME: unregister tearoffs -#endif - } - } - } -} - - -/* private functions */ - -static void -gimp_item_factory_create_branches (GimpItemFactory *factory, - GimpItemFactoryEntry *entry, - const gchar *textdomain) -{ - GString *tearoff_path; - gint factory_length; - gchar *p; - - if (! entry->entry.path) - return; - - tearoff_path = g_string_new (""); - - p = strchr (entry->entry.path, '/'); - factory_length = p - entry->entry.path; - - /* skip the first slash */ - if (p) - p = strchr (p + 1, '/'); - - while (p) - { - g_string_assign (tearoff_path, entry->entry.path + factory_length); - g_string_truncate (tearoff_path, p - entry->entry.path - factory_length); - - if (! gtk_item_factory_get_widget (GTK_ITEM_FACTORY (factory), - tearoff_path->str)) - { - GimpItemFactoryEntry branch_entry = - { - { NULL, NULL, NULL, 0, "" }, - NULL, - NULL - }; - - branch_entry.entry.path = tearoff_path->str; - - g_object_set_data (G_OBJECT (factory), "complete", entry->entry.path); - - gimp_item_factory_create_item (factory, - &branch_entry, - textdomain, - NULL, 2, TRUE); - - g_object_set_data (G_OBJECT (factory), "complete", NULL); - } - - g_string_append (tearoff_path, "/tearoff"); - - if (! gtk_item_factory_get_widget (GTK_ITEM_FACTORY (factory), - tearoff_path->str)) - { - GimpItemFactoryEntry tearoff_entry = - { - { NULL, NULL, - gimp_item_factory_tearoff_callback, 0, "" }, - NULL, - NULL, NULL - }; - - tearoff_entry.entry.path = tearoff_path->str; - - gimp_item_factory_create_item (factory, - &tearoff_entry, - textdomain, - NULL, 2, TRUE); - } - - p = strchr (p + 1, '/'); - } - - g_string_free (tearoff_path, TRUE); -} - -static void -gimp_item_factory_item_realize (GtkWidget *widget, - GimpItemFactory *item_factory) -{ - if (GTK_IS_MENU_SHELL (widget->parent)) - { - static GQuark quark_key_press_connected = 0; - - if (! quark_key_press_connected) - quark_key_press_connected = - g_quark_from_static_string ("gimp-menu-item-key-press-connected"); - - if (! GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget->parent), - quark_key_press_connected))) - { - g_signal_connect (widget->parent, "key_press_event", - G_CALLBACK (gimp_item_factory_item_key_press), - item_factory); - - g_object_set_qdata (G_OBJECT (widget->parent), - quark_key_press_connected, - GINT_TO_POINTER (TRUE)); - } - } -} - -static gboolean -gimp_item_factory_item_key_press (GtkWidget *widget, - GdkEventKey *kevent, - GimpItemFactory *item_factory) -{ - GtkWidget *active_menu_item; - gchar *help_id = NULL; - - active_menu_item = GTK_MENU_SHELL (widget)->active_menu_item; - - /* first, get the help page from the item - */ - if (active_menu_item) - { - help_id = g_object_get_data (G_OBJECT (active_menu_item), "gimp-help-id"); - - if (help_id && ! strlen (help_id)) - help_id = NULL; - } - - /* For any valid accelerator key except F1, continue with the - * standard GtkItemFactory callback and assign a new shortcut, but - * don't assign a shortcut to the help menu entries ... - */ - if (kevent->keyval != GDK_F1) - { - if (help_id && - gtk_accelerator_valid (kevent->keyval, 0) && - (strcmp (help_id, GIMP_HELP_HELP) == 0 || - strcmp (help_id, GIMP_HELP_HELP_CONTEXT) == 0)) - { - return TRUE; - } - - return FALSE; - } - - /* ...finally, if F1 was pressed over any menu, show it's help page... */ - - if (! help_id) - help_id = item_factory->help_id; - - { - gchar *help_domain = NULL; - gchar *help_string = NULL; - gchar *domain_separator; - - help_id = g_strdup (help_id); - - domain_separator = strchr (help_id, '?'); - - if (domain_separator) - { - *domain_separator = '\0'; - - help_domain = g_strdup (help_id); - help_string = g_strdup (domain_separator + 1); - } - else - { - help_string = g_strdup (help_id); - } - - gimp_help (item_factory->gimp, help_domain, help_string); - - g_free (help_domain); - g_free (help_string); - g_free (help_id); - } - - return TRUE; -} - -static void -gimp_item_factory_menu_position (GtkMenu *menu, - gint *x, - gint *y, - gpointer data) -{ - GdkScreen *screen; - GtkRequisition requisition; - GdkRectangle rect; - gint monitor; - gint pointer_x; - gint pointer_y; - - g_return_if_fail (GTK_IS_MENU (menu)); - g_return_if_fail (x != NULL); - g_return_if_fail (y != NULL); - g_return_if_fail (GTK_IS_WIDGET (data)); - - gdk_display_get_pointer (gtk_widget_get_display (GTK_WIDGET (data)), - &screen, &pointer_x, &pointer_y, NULL); - - monitor = gdk_screen_get_monitor_at_point (screen, pointer_x, pointer_y); - gdk_screen_get_monitor_geometry (screen, monitor, &rect); - - gtk_menu_set_screen (menu, screen); - - gtk_widget_size_request (GTK_WIDGET (menu), &requisition); - - if (gtk_widget_get_direction (GTK_WIDGET (menu)) == GTK_TEXT_DIR_RTL) - { - *x = pointer_x - 2 - requisition.width; - - if (*x < rect.x) - *x = pointer_x + 2; - } - else - { - *x = pointer_x + 2; - - if (*x + requisition.width > rect.x + rect.width) - *x = pointer_x - 2 - requisition.width; - } - - *y = pointer_y + 2; - - if (*y + requisition.height > rect.y + rect.height) - *y = pointer_y - 2 - requisition.height; - - if (*x < rect.x) *x = rect.x; - if (*y < rect.y) *y = rect.y; -} - -static gchar * -gimp_item_factory_translate (const gchar *path, - gpointer data) -{ - GtkItemFactory *item_factory; - GimpItemFactory *gimp_factory; - const gchar *retval; - gchar *translation; - gchar *domain = NULL; - gchar *complete = NULL; - gchar *p, *t; - - item_factory = GTK_ITEM_FACTORY (data); - gimp_factory = GIMP_ITEM_FACTORY (data); - - if (strstr (path, "tearoff") || - strstr (path, "/---") || - strstr (path, "/MRU")) - { - return (gchar *) path; - } - - domain = g_object_get_data (G_OBJECT (item_factory), "textdomain"); - complete = g_object_get_data (G_OBJECT (item_factory), "complete"); - - if (domain) /* use the plugin textdomain */ - { - gchar *full_path; - - full_path = g_strconcat (item_factory->path, path, NULL); - - if (complete) - { - /* This is a branch, use the complete path for translation, - * then strip off entries from the end until it matches. - */ - complete = g_strconcat (item_factory->path, complete, NULL); - translation = g_strdup (dgettext (domain, complete)); - - while (*complete && *translation && strcmp (complete, full_path)) - { - p = strrchr (complete, '/'); - t = strrchr (translation, '/'); - if (p && t) - { - *p = '\0'; - *t = '\0'; - } - else - break; - } - - g_free (complete); - /* DON'T set complete to NULL here */ - } - else - { - translation = g_strdup (dgettext (domain, full_path)); - } - - gimp_factory->translation_trash = - g_list_prepend (gimp_factory->translation_trash, translation); - - if (strncmp (item_factory->path, translation, - strlen (item_factory->path)) == 0) - { - retval = translation + strlen (item_factory->path); - } - else - { - g_warning ("%s: bad translation for menupath: %s", - G_STRFUNC, full_path); - - retval = path; - } - - g_free (full_path); - } - else /* use the gimp textdomain */ - { - if (complete) - { - /* This is a branch, use the complete path for translation, - * then strip off entries from the end until it matches. - */ - complete = g_strdup (complete); - translation = g_strdup (gettext (complete)); - - gimp_factory->translation_trash = - g_list_prepend (gimp_factory->translation_trash, translation); - - while (*complete && *translation && strcmp (complete, path)) - { - p = strrchr (complete, '/'); - t = strrchr (translation, '/'); - if (p && t) - { - *p = '\0'; - *t = '\0'; - } - else - break; - } - - g_free (complete); - /* DON'T set complete to NULL here */ - } - else - { - translation = gettext (path); - } - - if (*translation == '/') - { - retval = translation; - } - else - { - g_warning ("%s: bad translation for menupath: %s", - G_STRFUNC, path); - - retval = path; - } - } - - return (gchar *) retval; -} diff --git a/app/widgets/gimpitemfactory.h b/app/widgets/gimpitemfactory.h deleted file mode 100644 index 70cf2de0f6..0000000000 --- a/app/widgets/gimpitemfactory.h +++ /dev/null @@ -1,161 +0,0 @@ -/* The GIMP -- an image manipulation program - * Copyright (C) 1995 Spencer Kimball and Peter Mattis - * - * 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 __GIMP_ITEM_FACTORY_H__ -#define __GIMP_ITEM_FACTORY_H__ - -G_BEGIN_DECLS - - -typedef struct _GimpItemFactory GimpItemFactory; - - -typedef void (* GimpItemFactorySetupFunc) (GimpItemFactory *factory, - gpointer callback_data); -typedef void (* GimpItemFactoryUpdateFunc) (GtkItemFactory *factory, - gpointer update_data); - - -typedef struct _GimpItemFactoryEntry GimpItemFactoryEntry; - -struct _GimpItemFactoryEntry -{ - GtkItemFactoryEntry entry; - - const gchar *quark_string; - - const gchar *help_id; - const gchar *description; -}; - - -#define GIMP_TYPE_ITEM_FACTORY (gimp_item_factory_get_type ()) -#define GIMP_ITEM_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_ITEM_FACTORY, GimpItemFactory)) -#define GIMP_ITEM_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_ITEM_FACTORY, GimpItemFactoryClass)) -#define GIMP_IS_ITEM_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_ITEM_FACTORY)) -#define GIMP_IS_ITEM_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_ITEM_FACTORY)) -#define GIMP_ITEM_FACTORY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_ITEM_FACTORY, GimpItemFactoryClass)) - - -typedef struct _GimpItemFactoryClass GimpItemFactoryClass; - -struct _GimpItemFactory -{ - GtkItemFactory parent_instance; - - Gimp *gimp; - GimpItemFactoryUpdateFunc update_func; - gboolean update_on_popup; - gboolean create_tearoff; - gchar *title; - gchar *help_id; - - GList *translation_trash; -}; - -struct _GimpItemFactoryClass -{ - GtkItemFactoryClass parent_class; - - GHashTable *factories; -}; - - -GType gimp_item_factory_get_type (void) G_GNUC_CONST; - -GimpItemFactory * gimp_item_factory_new (Gimp *gimp, - GType container_type, - const gchar *factory_path, - const gchar *title, - const gchar *help_id, - GimpItemFactoryUpdateFunc update_func, - gboolean update_on_popup, - guint n_entries, - GimpItemFactoryEntry *entries, - gpointer callback_data, - gboolean create_tearoff); - -GimpItemFactory * gimp_item_factory_from_path (const gchar *path); -GList * gimp_item_factories_from_path (const gchar *path); - -void gimp_item_factory_create_item (GimpItemFactory *factory, - GimpItemFactoryEntry *entry, - const gchar *textdomain, - gpointer callback_data, - guint callback_type, - gboolean static_entry); -void gimp_item_factory_create_items (GimpItemFactory *factory, - guint n_entries, - GimpItemFactoryEntry *entries, - gpointer callback_data, - guint callback_type, - gboolean static_entries); - -void gimp_item_factory_update (GimpItemFactory *item_factory, - gpointer popup_data); -void gimp_item_factory_popup_with_data (GimpItemFactory *factory, - gpointer popup_data, - GtkWidget *parent, - GimpMenuPositionFunc position_func, - gpointer position_data, - GtkDestroyNotify popdown_func); - -void gimp_item_factory_set_active (GtkItemFactory *factory, - const gchar *path, - gboolean state); -void gimp_item_factories_set_active (const gchar *factory_path, - const gchar *path, - gboolean state); - -void gimp_item_factory_set_color (GtkItemFactory *factory, - const gchar *path, - const GimpRGB *color, - gboolean set_label); -void gimp_item_factories_set_color (const gchar *factory_path, - const gchar *path, - const GimpRGB *color, - gboolean set_label); - -void gimp_item_factory_set_label (GtkItemFactory *factory, - const gchar *path, - const gchar *label); -void gimp_item_factories_set_label (const gchar *factory_path, - const gchar *path, - const gchar *label); - -void gimp_item_factory_set_sensitive (GtkItemFactory *factory, - const gchar *path, - gboolean sensitive); -void gimp_item_factories_set_sensitive (const gchar *factory_path, - const gchar *path, - gboolean sensitive); - -void gimp_item_factory_set_visible (GtkItemFactory *factory, - const gchar *path, - gboolean visible); -void gimp_item_factories_set_visible (const gchar *factory_path, - const gchar *path, - gboolean visible); - -void gimp_item_factory_tearoff_callback (GtkWidget *widget, - gpointer data, - guint action); - -G_END_DECLS - -#endif /* __GIMP_ITEM_FACTORY_H__ */ diff --git a/configure.in b/configure.in index 10e3a0db14..ed95ffe374 100644 --- a/configure.in +++ b/configure.in @@ -1493,10 +1493,7 @@ if test "x$have_glib_2_5" != "xyes"; then fi if test "x$have_gtk_2_5" != "xyes"; then - CPPFLAGS="${CPPFLAGS} -DGDK_PIXBUF_DISABLE_DEPRECATED -DGDK_DISABLE_DEPRECATED" - -# -DGTK_DISABLE_DEPRECATED" - + CPPFLAGS="${CPPFLAGS} -DGDK_PIXBUF_DISABLE_DEPRECATED -DGDK_DISABLE_DEPRECATED -DGTK_DISABLE_DEPRECATED" fi if test "x$have_pango_1_5" != "xyes"; then diff --git a/libgimpwidgets/gimpcolorbutton.c b/libgimpwidgets/gimpcolorbutton.c index bf272c3c5f..73f63f0c2c 100644 --- a/libgimpwidgets/gimpcolorbutton.c +++ b/libgimpwidgets/gimpcolorbutton.c @@ -22,6 +22,8 @@ #include "config.h" +#include + #include #include "libgimpcolor/gimpcolor.h" @@ -47,13 +49,11 @@ #define TOUINT16(d) ((guint16) (d * 65535 + 0.5)) -typedef enum -{ - GIMP_COLOR_BUTTON_COLOR_FG, - GIMP_COLOR_BUTTON_COLOR_BG, - GIMP_COLOR_BUTTON_COLOR_BLACK, - GIMP_COLOR_BUTTON_COLOR_WHITE -} GimpColorButtonColor; +#define GIMP_COLOR_BUTTON_COLOR_FG "color-button-use-foreground" +#define GIMP_COLOR_BUTTON_COLOR_BG "color-button-use-background" +#define GIMP_COLOR_BUTTON_COLOR_BLACK "color-button-use-black" +#define GIMP_COLOR_BUTTON_COLOR_WHITE "color-button-use-white" + enum { @@ -63,7 +63,8 @@ enum static void gimp_color_button_class_init (GimpColorButtonClass *klass); -static void gimp_color_button_init (GimpColorButton *button); +static void gimp_color_button_init (GimpColorButton *button, + GimpColorButtonClass *klass); static void gimp_color_button_destroy (GtkObject *object); @@ -72,14 +73,13 @@ static gboolean gimp_color_button_button_press (GtkWidget *widget, static void gimp_color_button_state_changed (GtkWidget *widget, GtkStateType prev_state); static void gimp_color_button_clicked (GtkButton *button); +static GType gimp_color_button_get_action_type (GimpColorButton *button); + static void gimp_color_button_dialog_response (GtkWidget *dialog, gint response_id, GimpColorButton *button); -static void gimp_color_button_use_color (gpointer callback_data, - guint callback_action, - GtkWidget *widget); -static gchar * gimp_color_button_menu_translate (const gchar *path, - gpointer func_data); +static void gimp_color_button_use_color (GtkAction *action, + GimpColorButton *button); static void gimp_color_button_area_changed (GtkWidget *color_area, GimpColorButton *button); static void gimp_color_button_selection_changed (GtkWidget *selection, @@ -88,17 +88,29 @@ static void gimp_color_button_help_func (const gchar *help_id, gpointer help_data); -static GtkItemFactoryEntry menu_items[] = +static GtkActionEntry actions[] = { - { N_("/_Foreground Color"), NULL, - gimp_color_button_use_color, GIMP_COLOR_BUTTON_COLOR_FG, NULL }, - { N_("/_Background Color"), NULL, - gimp_color_button_use_color, GIMP_COLOR_BUTTON_COLOR_BG, NULL }, - { "/fg-bg-separator", NULL, NULL, 0, ""}, - { N_("/Blac_k"), NULL, - gimp_color_button_use_color, GIMP_COLOR_BUTTON_COLOR_BLACK, NULL }, - { N_("/_White"), NULL, - gimp_color_button_use_color, GIMP_COLOR_BUTTON_COLOR_WHITE, NULL }, + { "color-button-popup", NULL, + "Color Button Menu", NULL, NULL, + NULL + }, + + { GIMP_COLOR_BUTTON_COLOR_FG, NULL, + N_("_Foreground Color"), NULL, NULL, + G_CALLBACK (gimp_color_button_use_color) + }, + { GIMP_COLOR_BUTTON_COLOR_BG, NULL, + N_("_Background Color"), NULL, NULL, + G_CALLBACK (gimp_color_button_use_color) + }, + { GIMP_COLOR_BUTTON_COLOR_BLACK, NULL, + N_("Blac_k"), NULL, NULL, + G_CALLBACK (gimp_color_button_use_color) + }, + { GIMP_COLOR_BUTTON_COLOR_WHITE, NULL, + N_("_White"), NULL, NULL, + G_CALLBACK (gimp_color_button_use_color) + } }; static guint gimp_color_button_signals[LAST_SIGNAL] = { 0 }; @@ -145,12 +157,12 @@ gimp_color_button_class_init (GimpColorButtonClass *klass) gimp_color_button_signals[COLOR_CHANGED] = g_signal_new ("color_changed", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (GimpColorButtonClass, color_changed), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (GimpColorButtonClass, color_changed), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); object_class->destroy = gimp_color_button_destroy; @@ -160,12 +172,17 @@ gimp_color_button_class_init (GimpColorButtonClass *klass) button_class->clicked = gimp_color_button_clicked; klass->color_changed = NULL; + klass->get_action_type = gimp_color_button_get_action_type; } static void -gimp_color_button_init (GimpColorButton *button) +gimp_color_button_init (GimpColorButton *button, + GimpColorButtonClass *klass) { - GimpRGB color; + GtkActionGroup *group; + GtkUIManager *ui_manager; + GimpRGB color; + gint i; button->continuous_update = FALSE; button->title = NULL; @@ -174,19 +191,59 @@ gimp_color_button_init (GimpColorButton *button) gimp_rgba_set (&color, 0.0, 0.0, 0.0, 1.0); button->color_area = gimp_color_area_new (&color, FALSE, GDK_BUTTON2_MASK); g_signal_connect (button->color_area, "color_changed", - G_CALLBACK (gimp_color_button_area_changed), - button); + G_CALLBACK (gimp_color_button_area_changed), + button); gtk_container_add (GTK_CONTAINER (button), button->color_area); gtk_widget_show (button->color_area); /* right-click opens a popup */ - button->popup_menu = gtk_item_factory_new (GTK_TYPE_MENU, "", NULL); - gtk_item_factory_set_translate_func (button->popup_menu, - gimp_color_button_menu_translate, - NULL, NULL); - gtk_item_factory_create_items (button->popup_menu, - G_N_ELEMENTS (menu_items), menu_items, button); + button->popup_menu = ui_manager = gtk_ui_manager_new (); + + group = gtk_action_group_new ("color-button"); + + for (i = 0; i < G_N_ELEMENTS (actions); i++) + { + const gchar *label; + const gchar *tooltip; + GtkAction *action; + + label = gettext (actions[i].label); + tooltip = gettext (actions[i].label); + + action = g_object_new (klass->get_action_type (button), + "name", actions[i].name, + "label", label, + "tooltip", tooltip, + "stock-id", actions[i].stock_id, + NULL); + + if (actions[i].callback) + g_signal_connect (action, "activate", + actions[i].callback, + button); + + gtk_action_group_add_action_with_accel (group, action, + actions[i].accelerator); + + g_object_unref (action); + } + + gtk_ui_manager_insert_action_group (ui_manager, group, -1); + g_object_unref (group); + + gtk_ui_manager_add_ui_from_string + (ui_manager, + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "\n", + -1, NULL); } static void @@ -212,6 +269,12 @@ gimp_color_button_destroy (GtkObject *object) button->color_area = NULL; } + if (button->popup_menu) + { + g_object_unref (button->popup_menu); + button->popup_menu = NULL; + } + GTK_OBJECT_CLASS (parent_class)->destroy (object); } @@ -225,16 +288,20 @@ gimp_color_button_button_press (GtkWidget *widget, if (bevent->button == 3) { + GtkWidget *menu; + gdk_window_get_origin (GTK_WIDGET (widget)->window, &x, &y); x += widget->allocation.x; y += widget->allocation.y; - gtk_menu_set_screen (GTK_MENU (GTK_ITEM_FACTORY (button->popup_menu)->widget), - gtk_widget_get_screen (widget)); + menu = gtk_ui_manager_get_widget (button->popup_menu, + "/color-button-popup"); - gtk_item_factory_popup (button->popup_menu, - x + bevent->x, y + bevent->y, - bevent->button, bevent->time); + gtk_menu_set_screen (GTK_MENU (menu), gtk_widget_get_screen (widget)); + + gtk_menu_popup (GTK_MENU (menu), + NULL, NULL, NULL, NULL, + bevent->button, bevent->time); } if (GTK_WIDGET_CLASS (parent_class)->button_press_event) @@ -245,7 +312,7 @@ gimp_color_button_button_press (GtkWidget *widget, static void gimp_color_button_state_changed (GtkWidget *widget, - GtkStateType prev_state) + GtkStateType prev_state) { g_return_if_fail (GIMP_IS_COLOR_BUTTON (widget)); @@ -256,6 +323,67 @@ gimp_color_button_state_changed (GtkWidget *widget, GTK_WIDGET_CLASS (parent_class)->state_changed (widget, prev_state); } +static void +gimp_color_button_clicked (GtkButton *button) +{ + GimpColorButton *color_button = GIMP_COLOR_BUTTON (button); + + if (! color_button->dialog) + { + GtkWidget *dialog; + GtkWidget *selection; + GimpRGB color; + + gimp_color_button_get_color (color_button, &color); + + dialog = color_button->dialog = + gimp_dialog_new (color_button->title, COLOR_SELECTION_KEY, + GTK_WIDGET (button), 0, + gimp_color_button_help_func, NULL, + + GIMP_STOCK_RESET, RESPONSE_RESET, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OK, GTK_RESPONSE_OK, + + NULL); + + g_signal_connect (dialog, "response", + G_CALLBACK (gimp_color_button_dialog_response), + color_button); + g_signal_connect (dialog, "destroy", + G_CALLBACK (gtk_widget_destroyed), + &color_button->dialog); + + selection = gimp_color_selection_new (); + gtk_container_set_border_width (GTK_CONTAINER (selection), 6); + gimp_color_selection_set_show_alpha (GIMP_COLOR_SELECTION (selection), + gimp_color_button_has_alpha (color_button)); + gimp_color_selection_set_color (GIMP_COLOR_SELECTION (selection), &color); + gimp_color_selection_set_old_color (GIMP_COLOR_SELECTION (selection), + &color); + gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), selection); + gtk_widget_show (selection); + + g_signal_connect (selection, "color_changed", + G_CALLBACK (gimp_color_button_selection_changed), + button); + + g_object_set_data (G_OBJECT (color_button->dialog), COLOR_SELECTION_KEY, + selection); + } + + gtk_window_present (GTK_WINDOW (color_button->dialog)); +} + +static GType +gimp_color_button_get_action_type (GimpColorButton *button) +{ + return GTK_TYPE_ACTION; +} + + +/* public functions */ + /** * gimp_color_button_new: * @title: String that will be used as title for the color_selector. @@ -276,10 +404,10 @@ gimp_color_button_state_changed (GtkWidget *widget, **/ GtkWidget * gimp_color_button_new (const gchar *title, - gint width, - gint height, - const GimpRGB *color, - GimpColorAreaType type) + gint width, + gint height, + const GimpRGB *color, + GimpColorAreaType type) { GimpColorButton *button; @@ -306,7 +434,7 @@ gimp_color_button_new (const gchar *title, **/ void gimp_color_button_set_color (GimpColorButton *button, - const GimpRGB *color) + const GimpRGB *color) { g_return_if_fail (GIMP_IS_COLOR_BUTTON (button)); g_return_if_fail (color != NULL); @@ -323,7 +451,7 @@ gimp_color_button_set_color (GimpColorButton *button, **/ void gimp_color_button_get_color (GimpColorButton *button, - GimpRGB *color) + GimpRGB *color) { g_return_if_fail (GIMP_IS_COLOR_BUTTON (button)); g_return_if_fail (color != NULL); @@ -357,7 +485,7 @@ gimp_color_button_has_alpha (GimpColorButton *button) **/ void gimp_color_button_set_type (GimpColorButton *button, - GimpColorAreaType type) + GimpColorAreaType type) { g_return_if_fail (GIMP_IS_COLOR_BUTTON (button)); @@ -421,57 +549,8 @@ gimp_color_button_set_update (GimpColorButton *button, } } -static void -gimp_color_button_clicked (GtkButton *button) -{ - GimpColorButton *color_button = GIMP_COLOR_BUTTON (button); - if (! color_button->dialog) - { - GtkWidget *dialog; - GtkWidget *selection; - GimpRGB color; - - gimp_color_button_get_color (color_button, &color); - - dialog = color_button->dialog = - gimp_dialog_new (color_button->title, COLOR_SELECTION_KEY, - GTK_WIDGET (button), 0, - gimp_color_button_help_func, NULL, - - GIMP_STOCK_RESET, RESPONSE_RESET, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OK, GTK_RESPONSE_OK, - - NULL); - - g_signal_connect (dialog, "response", - G_CALLBACK (gimp_color_button_dialog_response), - color_button); - g_signal_connect (dialog, "destroy", - G_CALLBACK (gtk_widget_destroyed), - &color_button->dialog); - - selection = gimp_color_selection_new (); - gtk_container_set_border_width (GTK_CONTAINER (selection), 6); - gimp_color_selection_set_show_alpha (GIMP_COLOR_SELECTION (selection), - gimp_color_button_has_alpha (color_button)); - gimp_color_selection_set_color (GIMP_COLOR_SELECTION (selection), &color); - gimp_color_selection_set_old_color (GIMP_COLOR_SELECTION (selection), - &color); - gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), selection); - gtk_widget_show (selection); - - g_signal_connect (selection, "color_changed", - G_CALLBACK (gimp_color_button_selection_changed), - button); - - g_object_set_data (G_OBJECT (color_button->dialog), COLOR_SELECTION_KEY, - selection); - } - - gtk_window_present (GTK_WINDOW (color_button->dialog)); -} +/* private functions */ static void gimp_color_button_dialog_response (GtkWidget *dialog, @@ -514,43 +593,39 @@ gimp_color_button_dialog_response (GtkWidget *dialog, } static void -gimp_color_button_use_color (gpointer callback_data, - guint callback_action, - GtkWidget *widget) +gimp_color_button_use_color (GtkAction *action, + GimpColorButton *button) { - GimpRGB color; - GimpColorButtonColor type; + const gchar *name; + GimpRGB color; - type = (GimpColorButtonColor) callback_action; + name = gtk_action_get_name (action); + gimp_color_button_get_color (button, &color); - gimp_color_button_get_color (GIMP_COLOR_BUTTON (callback_data), &color); - - switch (type) + if (! strcmp (name, GIMP_COLOR_BUTTON_COLOR_FG)) { - case GIMP_COLOR_BUTTON_COLOR_FG: if (_gimp_get_foreground_func) _gimp_get_foreground_func (&color); else gimp_rgba_set (&color, 0.0, 0.0, 0.0, 1.0); - break; - - case GIMP_COLOR_BUTTON_COLOR_BG: + } + else if (! strcmp (name, GIMP_COLOR_BUTTON_COLOR_BG)) + { if (_gimp_get_background_func) _gimp_get_background_func (&color); else gimp_rgba_set (&color, 1.0, 1.0, 1.0, 1.0); - break; - - case GIMP_COLOR_BUTTON_COLOR_BLACK: + } + else if (! strcmp (name, GIMP_COLOR_BUTTON_COLOR_BLACK)) + { gimp_rgba_set (&color, 0.0, 0.0, 0.0, 1.0); - break; - - case GIMP_COLOR_BUTTON_COLOR_WHITE: + } + else if (! strcmp (name, GIMP_COLOR_BUTTON_COLOR_WHITE)) + { gimp_rgba_set (&color, 1.0, 1.0, 1.0, 1.0); - break; } - gimp_color_button_set_color (GIMP_COLOR_BUTTON (callback_data), &color); + gimp_color_button_set_color (button, &color); } static void @@ -605,13 +680,6 @@ gimp_color_button_selection_changed (GtkWidget *selection, } } -static gchar * -gimp_color_button_menu_translate (const gchar *path, - gpointer func_data) -{ - return (gettext (path)); -} - static void gimp_color_button_help_func (const gchar *help_id, gpointer help_data) diff --git a/libgimpwidgets/gimpcolorbutton.h b/libgimpwidgets/gimpcolorbutton.h index 08596a7bfc..1f8327d66e 100644 --- a/libgimpwidgets/gimpcolorbutton.h +++ b/libgimpwidgets/gimpcolorbutton.h @@ -62,10 +62,13 @@ struct _GimpColorButtonClass { GimpButtonClass parent_class; - void (* color_changed) (GimpColorButton *button); + /* signals */ + void (* color_changed) (GimpColorButton *button); + + /* virtual functions */ + GType (* get_action_type) (GimpColorButton *button); /* Padding for future expansion */ - void (* _gimp_reserved1) (void); void (* _gimp_reserved2) (void); void (* _gimp_reserved3) (void); void (* _gimp_reserved4) (void);