~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to app/widgets/gimpcolorselectorpalette.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GIMP - The GNU Image Manipulation Program
 
2
 * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
 
3
 *
 
4
 * gimpcolorselectorpalette.c
 
5
 * Copyright (C) 2006 Michael Natterer <mitch@gimp.org>
 
6
 *
 
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.
 
11
 *
 
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.
 
16
 *
 
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.
 
20
 */
 
21
 
 
22
#include "config.h"
 
23
 
 
24
#include <gtk/gtk.h>
 
25
 
 
26
#include "libgimpcolor/gimpcolor.h"
 
27
#include "libgimpwidgets/gimpwidgets.h"
 
28
 
 
29
#include "widgets-types.h"
 
30
 
 
31
#include "core/gimpcontext.h"
 
32
#include "core/gimppalette.h"
 
33
 
 
34
#include "gimpcolorselectorpalette.h"
 
35
#include "gimppaletteview.h"
 
36
#include "gimpviewrendererpalette.h"
 
37
 
 
38
 
 
39
static void   gimp_color_selector_palette_set_color  (GimpColorSelector *selector,
 
40
                                                      const GimpRGB     *rgb,
 
41
                                                      const GimpHSV     *hsv);
 
42
static void   gimp_color_selector_palette_set_config (GimpColorSelector *selector,
 
43
                                                      GimpColorConfig   *config);
 
44
 
 
45
 
 
46
G_DEFINE_TYPE (GimpColorSelectorPalette, gimp_color_selector_palette,
 
47
               GIMP_TYPE_COLOR_SELECTOR)
 
48
 
 
49
#define parent_class gimp_color_selector_palette_parent_class
 
50
 
 
51
 
 
52
static void
 
53
gimp_color_selector_palette_class_init (GimpColorSelectorPaletteClass *klass)
 
54
{
 
55
  GimpColorSelectorClass *selector_class = GIMP_COLOR_SELECTOR_CLASS (klass);
 
56
 
 
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;
 
62
}
 
63
 
 
64
static void
 
65
gimp_color_selector_palette_init (GimpColorSelectorPalette *select)
 
66
{
 
67
}
 
68
 
 
69
static void
 
70
gimp_color_selector_palette_set_color (GimpColorSelector *selector,
 
71
                                       const GimpRGB     *rgb,
 
72
                                       const GimpHSV     *hsv)
 
73
{
 
74
  GimpColorSelectorPalette *select = GIMP_COLOR_SELECTOR_PALETTE (selector);
 
75
 
 
76
  if (select->context)
 
77
    {
 
78
      GimpPalette *palette = gimp_context_get_palette (select->context);
 
79
 
 
80
      if (palette && palette->n_colors > 0)
 
81
        {
 
82
          GimpPaletteEntry *entry;
 
83
 
 
84
          entry = gimp_palette_find_entry (palette, rgb,
 
85
                                           GIMP_PALETTE_VIEW (select->view)->selected);
 
86
 
 
87
          if (entry)
 
88
            gimp_palette_view_select_entry (GIMP_PALETTE_VIEW (select->view),
 
89
                                            entry);
 
90
        }
 
91
    }
 
92
}
 
93
 
 
94
static void
 
95
gimp_color_selector_palette_palette_changed (GimpContext              *context,
 
96
                                             GimpPalette              *palette,
 
97
                                             GimpColorSelectorPalette *select)
 
98
{
 
99
  gimp_view_set_viewable (GIMP_VIEW (select->view), GIMP_VIEWABLE (palette));
 
100
}
 
101
 
 
102
static void
 
103
gimp_color_selector_palette_entry_clicked (GimpPaletteView   *view,
 
104
                                           GimpPaletteEntry  *entry,
 
105
                                           GdkModifierType    state,
 
106
                                           GimpColorSelector *selector)
 
107
{
 
108
  selector->rgb = entry->color;
 
109
  gimp_rgb_to_hsv (&selector->rgb, &selector->hsv);
 
110
 
 
111
  gimp_color_selector_color_changed (selector);
 
112
}
 
113
 
 
114
static void
 
115
gimp_color_selector_palette_set_config (GimpColorSelector *selector,
 
116
                                        GimpColorConfig   *config)
 
117
{
 
118
  GimpColorSelectorPalette *select = GIMP_COLOR_SELECTOR_PALETTE (selector);
 
119
 
 
120
  if (select->context)
 
121
    {
 
122
      g_signal_handlers_disconnect_by_func (select->context,
 
123
                                            gimp_color_selector_palette_palette_changed,
 
124
                                            select);
 
125
      select->context = NULL;
 
126
    }
 
127
 
 
128
  if (config)
 
129
    select->context = g_object_get_data (G_OBJECT (config), "gimp-context");
 
130
 
 
131
  if (select->context)
 
132
    {
 
133
      if (! select->view)
 
134
        {
 
135
          GtkWidget *frame;
 
136
 
 
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);
 
141
 
 
142
          select->view = gimp_view_new_full_by_types (select->context,
 
143
                                                      GIMP_TYPE_PALETTE_VIEW,
 
144
                                                      GIMP_TYPE_PALETTE,
 
145
                                                      100, 100, 0,
 
146
                                                      FALSE, TRUE, FALSE);
 
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),
 
150
             -1);
 
151
          gimp_view_renderer_palette_set_draw_grid
 
152
            (GIMP_VIEW_RENDERER_PALETTE (GIMP_VIEW (select->view)->renderer),
 
153
             TRUE);
 
154
          gtk_container_add (GTK_CONTAINER (frame), select->view);
 
155
          gtk_widget_show (select->view);
 
156
 
 
157
          g_signal_connect (select->view, "entry-clicked",
 
158
                            G_CALLBACK (gimp_color_selector_palette_entry_clicked),
 
159
                            select);
 
160
        }
 
161
 
 
162
      g_signal_connect_object (select->context, "palette-changed",
 
163
                               G_CALLBACK (gimp_color_selector_palette_palette_changed),
 
164
                               select, 0);
 
165
 
 
166
      gimp_color_selector_palette_palette_changed (select->context,
 
167
                                                   gimp_context_get_palette (select->context),
 
168
                                                   select);
 
169
    }
 
170
}