1
/* GIMP - The GNU Image Manipulation Program
2
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
4
* gimpcolorselectorpalette.c
5
* Copyright (C) 2006 Michael Natterer <mitch@gimp.org>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
#include "libgimpcolor/gimpcolor.h"
27
#include "libgimpwidgets/gimpwidgets.h"
29
#include "widgets-types.h"
31
#include "core/gimpcontext.h"
32
#include "core/gimppalette.h"
34
#include "gimpcolorselectorpalette.h"
35
#include "gimppaletteview.h"
36
#include "gimpviewrendererpalette.h"
39
static void gimp_color_selector_palette_set_color (GimpColorSelector *selector,
42
static void gimp_color_selector_palette_set_config (GimpColorSelector *selector,
43
GimpColorConfig *config);
46
G_DEFINE_TYPE (GimpColorSelectorPalette, gimp_color_selector_palette,
47
GIMP_TYPE_COLOR_SELECTOR)
49
#define parent_class gimp_color_selector_palette_parent_class
53
gimp_color_selector_palette_class_init (GimpColorSelectorPaletteClass *klass)
55
GimpColorSelectorClass *selector_class = GIMP_COLOR_SELECTOR_CLASS (klass);
57
selector_class->name = "Palette";
58
selector_class->help_id = "gimp-colorselector-palette";
59
selector_class->stock_id = GIMP_STOCK_PALETTE;
60
selector_class->set_color = gimp_color_selector_palette_set_color;
61
selector_class->set_config = gimp_color_selector_palette_set_config;
65
gimp_color_selector_palette_init (GimpColorSelectorPalette *select)
70
gimp_color_selector_palette_set_color (GimpColorSelector *selector,
74
GimpColorSelectorPalette *select = GIMP_COLOR_SELECTOR_PALETTE (selector);
78
GimpPalette *palette = gimp_context_get_palette (select->context);
80
if (palette && palette->n_colors > 0)
82
GimpPaletteEntry *entry;
84
entry = gimp_palette_find_entry (palette, rgb,
85
GIMP_PALETTE_VIEW (select->view)->selected);
88
gimp_palette_view_select_entry (GIMP_PALETTE_VIEW (select->view),
95
gimp_color_selector_palette_palette_changed (GimpContext *context,
97
GimpColorSelectorPalette *select)
99
gimp_view_set_viewable (GIMP_VIEW (select->view), GIMP_VIEWABLE (palette));
103
gimp_color_selector_palette_entry_clicked (GimpPaletteView *view,
104
GimpPaletteEntry *entry,
105
GdkModifierType state,
106
GimpColorSelector *selector)
108
selector->rgb = entry->color;
109
gimp_rgb_to_hsv (&selector->rgb, &selector->hsv);
111
gimp_color_selector_color_changed (selector);
115
gimp_color_selector_palette_set_config (GimpColorSelector *selector,
116
GimpColorConfig *config)
118
GimpColorSelectorPalette *select = GIMP_COLOR_SELECTOR_PALETTE (selector);
122
g_signal_handlers_disconnect_by_func (select->context,
123
gimp_color_selector_palette_palette_changed,
125
select->context = NULL;
129
select->context = g_object_get_data (G_OBJECT (config), "gimp-context");
137
frame = gtk_frame_new (NULL);
138
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
139
gtk_container_add (GTK_CONTAINER (select), frame);
140
gtk_widget_show (frame);
142
select->view = gimp_view_new_full_by_types (select->context,
143
GIMP_TYPE_PALETTE_VIEW,
147
gimp_view_set_expand (GIMP_VIEW (select->view), TRUE);
148
gimp_view_renderer_palette_set_cell_size
149
(GIMP_VIEW_RENDERER_PALETTE (GIMP_VIEW (select->view)->renderer),
151
gimp_view_renderer_palette_set_draw_grid
152
(GIMP_VIEW_RENDERER_PALETTE (GIMP_VIEW (select->view)->renderer),
154
gtk_container_add (GTK_CONTAINER (frame), select->view);
155
gtk_widget_show (select->view);
157
g_signal_connect (select->view, "entry-clicked",
158
G_CALLBACK (gimp_color_selector_palette_entry_clicked),
162
g_signal_connect_object (select->context, "palette-changed",
163
G_CALLBACK (gimp_color_selector_palette_palette_changed),
166
gimp_color_selector_palette_palette_changed (select->context,
167
gimp_context_get_palette (select->context),