use a GtkUIManager instead of a GtkItemFactory. Added virtual function
2004-11-04 Michael Natterer <mitch@gimp.org> * 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.
This commit is contained in:
committed by
Michael Natterer
parent
01bc7c92b9
commit
40928bb578
17
ChangeLog
17
ChangeLog
@ -1,3 +1,20 @@
|
||||
2004-11-04 Michael Natterer <mitch@gimp.org>
|
||||
|
||||
* 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 <mitch@gimp.org>
|
||||
|
||||
* libgimpwidgets/gimpoldwidgets.c: #undef GTK_DISABLE_DEPRECATED
|
||||
|
||||
@ -166,8 +166,6 @@ libappwidgets_a_sources = \
|
||||
gimpimageeditor.h \
|
||||
gimpimageview.c \
|
||||
gimpimageview.h \
|
||||
gimpitemfactory.c \
|
||||
gimpitemfactory.h \
|
||||
gimpitemtreeview.c \
|
||||
gimpitemtreeview.h \
|
||||
gimplayertreeview.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,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -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__ */
|
||||
@ -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
|
||||
|
||||
@ -22,6 +22,8 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#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, "<Separator>"},
|
||||
{ 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, "<popup>", 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,
|
||||
"<ui>\n"
|
||||
" <popup action=\"color-button-popup\">\n"
|
||||
" <menuitem action=\"" GIMP_COLOR_BUTTON_COLOR_FG "\" />\n"
|
||||
" <menuitem action=\"" GIMP_COLOR_BUTTON_COLOR_BG "\" />\n"
|
||||
" <separator />\n"
|
||||
" <menuitem action=\"" GIMP_COLOR_BUTTON_COLOR_BLACK "\" />\n"
|
||||
" <menuitem action=\"" GIMP_COLOR_BUTTON_COLOR_WHITE "\" />\n"
|
||||
" </popup>\n"
|
||||
"</ui>\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)
|
||||
|
||||
@ -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);
|
||||
|
||||
Reference in New Issue
Block a user