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

« back to all changes in this revision

Viewing changes to libgimpwidgets/gimpcolorscales.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:
29
29
 
30
30
#include <gtk/gtk.h>
31
31
 
 
32
#include "libgimpbase/gimpbase.h"
32
33
#include "libgimpcolor/gimpcolor.h"
33
34
#include "libgimpmath/gimpmath.h"
34
35
 
36
37
 
37
38
#include "gimpcolorscale.h"
38
39
#include "gimpcolorscales.h"
39
 
#include "gimpcolorhexentry.h"
40
40
#include "gimpwidgets.h"
41
41
 
42
42
#include "libgimp/libgimp-intl.h"
56
56
  GtkWidget         *toggles[7];
57
57
  GtkWidget         *sliders[7];
58
58
  GtkObject         *slider_data[7];
59
 
  GtkWidget         *hex_entry;
60
59
};
61
60
 
62
61
struct _GimpColorScalesClass
65
64
};
66
65
 
67
66
 
68
 
static void   gimp_color_scales_class_init (GimpColorScalesClass  *klass);
69
 
static void   gimp_color_scales_init       (GimpColorScales       *scales);
70
 
 
71
67
static void   gimp_color_scales_togg_sensitive (GimpColorSelector *selector,
72
68
                                                gboolean           sensitive);
73
69
static void   gimp_color_scales_togg_visible   (GimpColorSelector *selector,
88
84
static void   gimp_color_scales_scale_update   (GtkAdjustment     *adjustment,
89
85
                                                GimpColorScales   *scales);
90
86
 
91
 
static void   gimp_color_scales_entry_changed  (GimpColorHexEntry *entry,
92
 
                                                GimpColorScales   *scales);
93
 
 
94
 
 
95
 
static GimpColorSelectorClass *parent_class = NULL;
96
 
 
97
 
 
98
 
GType
99
 
gimp_color_scales_get_type (void)
100
 
{
101
 
  static GType scales_type = 0;
102
 
 
103
 
  if (! scales_type)
104
 
    {
105
 
      static const GTypeInfo scales_info =
106
 
      {
107
 
        sizeof (GimpColorScalesClass),
108
 
        (GBaseInitFunc) NULL,
109
 
        (GBaseFinalizeFunc) NULL,
110
 
        (GClassInitFunc) gimp_color_scales_class_init,
111
 
        NULL,           /* class_finalize */
112
 
        NULL,           /* class_data     */
113
 
        sizeof (GimpColorScales),
114
 
        0,              /* n_preallocs    */
115
 
        (GInstanceInitFunc) gimp_color_scales_init,
116
 
      };
117
 
 
118
 
      scales_type = g_type_register_static (GIMP_TYPE_COLOR_SELECTOR,
119
 
                                            "GimpColorScales",
120
 
                                            &scales_info, 0);
121
 
    }
122
 
 
123
 
  return scales_type;
124
 
}
 
87
 
 
88
G_DEFINE_TYPE (GimpColorScales, gimp_color_scales, GIMP_TYPE_COLOR_SELECTOR)
 
89
 
 
90
#define parent_class gimp_color_scales_parent_class
 
91
 
125
92
 
126
93
static void
127
94
gimp_color_scales_class_init (GimpColorScalesClass *klass)
128
95
{
129
96
  GimpColorSelectorClass *selector_class = GIMP_COLOR_SELECTOR_CLASS (klass);
130
97
 
131
 
  parent_class = g_type_class_peek_parent (klass);
132
 
 
133
98
  selector_class->name                  = _("Scales");
134
99
  selector_class->help_id               = "gimp-colorselector-scales";
135
100
  selector_class->stock_id              = GIMP_STOCK_TOOL_OPTIONS;
145
110
{
146
111
  GimpColorSelector *selector = GIMP_COLOR_SELECTOR (scales);
147
112
  GtkWidget         *table;
148
 
  GtkWidget         *hbox;
149
 
  GtkWidget         *label;
 
113
  GEnumClass        *enum_class;
150
114
  GSList            *group;
151
115
  gint               i;
152
116
 
153
 
  static const gchar *toggle_titles[] =
154
 
  {
155
 
    N_("_H"),
156
 
    N_("_S"),
157
 
    N_("_V"),
158
 
    N_("_R"),
159
 
    N_("_G"),
160
 
    N_("_B"),
161
 
    N_("_A")
162
 
  };
163
 
  static const gchar *slider_tips[7] =
164
 
  {
165
 
    N_("Hue"),
166
 
    N_("Saturation"),
167
 
    N_("Value"),
168
 
    N_("Red"),
169
 
    N_("Green"),
170
 
    N_("Blue"),
171
 
    N_("Alpha")
172
 
  };
173
 
  static gdouble slider_initial_vals[] = {   0,   0,   0,   0,   0,   0,   0 };
174
 
  static gdouble slider_max_vals[]     = { 360, 100, 100, 255, 255, 255, 100 };
175
 
  static gdouble slider_incs[]         = {  30,  10,  10,  16,  16,  16,  10 };
 
117
  static const gdouble slider_initial_vals[] =
 
118
    {   0,   0,   0,   0,   0,   0,   0 };
 
119
  static const gdouble slider_max_vals[] =
 
120
    { 360, 100, 100, 255, 255, 255, 100 };
 
121
  static const gdouble slider_incs[] =
 
122
    {  30,  10,  10,  16,  16,  16,  10 };
176
123
 
177
124
  /*  don't needs the toggles for our own operation  */
178
125
  selector->toggles_visible = FALSE;
186
133
  gtk_box_pack_start (GTK_BOX (scales), table, FALSE, FALSE, 0);
187
134
  gtk_widget_show (table);
188
135
 
 
136
  enum_class = g_type_class_ref (GIMP_TYPE_COLOR_SELECTOR_CHANNEL);
 
137
 
189
138
  group = NULL;
190
139
 
191
 
  for (i = 0; i < 7; i++)
 
140
  for (i = GIMP_COLOR_SELECTOR_HUE; i <= GIMP_COLOR_SELECTOR_ALPHA; i++)
192
141
    {
193
 
      if (i == 6)
194
 
        {
195
 
          scales->toggles[i] = NULL;
196
 
        }
 
142
      GimpEnumDesc *enum_desc;
 
143
 
 
144
      enum_desc = gimp_enum_get_desc (enum_class, i);
 
145
 
 
146
      if (i == GIMP_COLOR_SELECTOR_ALPHA)
 
147
        {
 
148
          scales->toggles[i] = NULL;
 
149
        }
197
150
      else
198
 
        {
199
 
          scales->toggles[i] = gtk_radio_button_new (group);
200
 
          group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (scales->toggles[i]));
201
 
          gtk_table_attach (GTK_TABLE (table), scales->toggles[i],
202
 
                            0, 1, i, i + 1,
203
 
                            GTK_SHRINK, GTK_EXPAND, 0, 0);
 
151
        {
 
152
          scales->toggles[i] = gtk_radio_button_new (group);
 
153
          group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (scales->toggles[i]));
 
154
          gtk_table_attach (GTK_TABLE (table), scales->toggles[i],
 
155
                            0, 1, i, i + 1,
 
156
                            GTK_SHRINK, GTK_EXPAND, 0, 0);
204
157
 
205
158
          if (selector->toggles_visible)
206
159
            gtk_widget_show (scales->toggles[i]);
207
160
 
208
 
          gimp_help_set_help_data (scales->toggles[i],
209
 
                                   gettext (slider_tips[i]), NULL);
 
161
          gimp_help_set_help_data (scales->toggles[i],
 
162
                                   gettext (enum_desc->value_help), NULL);
210
163
 
211
 
          g_signal_connect (scales->toggles[i], "toggled",
212
 
                            G_CALLBACK (gimp_color_scales_toggle_update),
213
 
                            scales);
214
 
        }
 
164
          g_signal_connect (scales->toggles[i], "toggled",
 
165
                            G_CALLBACK (gimp_color_scales_toggle_update),
 
166
                            scales);
 
167
        }
215
168
 
216
169
      scales->slider_data[i] =
217
170
        gimp_color_scale_entry_new (GTK_TABLE (table), 1, i,
218
 
                                    gettext (toggle_titles[i]),
 
171
                                    gettext (enum_desc->value_desc),
219
172
                                    -1, -1,
220
173
                                    slider_initial_vals[i],
221
174
                                    0.0, slider_max_vals[i],
222
175
                                    1.0, slider_incs[i],
223
176
                                    0,
224
 
                                    gettext (slider_tips[i]),
 
177
                                    gettext (enum_desc->value_help),
225
178
                                    NULL);
226
179
 
227
180
      scales->sliders[i] = GIMP_SCALE_ENTRY_SCALE (scales->slider_data[i]);
228
181
 
229
182
      gimp_color_scale_set_channel (GIMP_COLOR_SCALE (scales->sliders[i]), i);
230
183
 
231
 
      g_signal_connect (scales->slider_data[i], "value_changed",
232
 
                        G_CALLBACK (gimp_color_scales_scale_update),
233
 
                        scales);
 
184
      g_signal_connect (scales->slider_data[i], "value-changed",
 
185
                        G_CALLBACK (gimp_color_scales_scale_update),
 
186
                        scales);
234
187
    }
235
188
 
236
 
  /* The hex triplet entry */
237
 
  hbox = gtk_hbox_new (FALSE, 6);
238
 
  gtk_box_pack_end (GTK_BOX (scales), hbox, FALSE, FALSE, 0);
239
 
  gtk_widget_show (hbox);
240
 
 
241
 
  scales->hex_entry = gimp_color_hex_entry_new ();
242
 
  gimp_help_set_help_data (scales->hex_entry,
243
 
                           _("Hexadecimal color notation "
244
 
                             "as used in HTML and CSS"), NULL);
245
 
  gtk_box_pack_end (GTK_BOX (hbox), scales->hex_entry, TRUE, TRUE, 0);
246
 
  gtk_widget_show (scales->hex_entry);
247
 
 
248
 
  label = gtk_label_new_with_mnemonic (_("HTML _Notation:"));
249
 
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), scales->hex_entry);
250
 
  gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 0);
251
 
  gtk_widget_show (label);
252
 
 
253
 
  g_signal_connect (scales->hex_entry, "color_changed",
254
 
                    G_CALLBACK (gimp_color_scales_entry_changed),
255
 
                    scales);
 
189
  g_type_class_unref (enum_class);
256
190
}
257
191
 
258
192
static void
290
224
  GtkWidget       *label;
291
225
  GtkWidget       *scale;
292
226
  GtkWidget       *spin;
 
227
  GtkWidget       *table;
293
228
 
294
229
  label = GIMP_SCALE_ENTRY_LABEL (scales->slider_data[6]);
295
230
  scale = GIMP_SCALE_ENTRY_SCALE (scales->slider_data[6]);
296
231
  spin  = GIMP_SCALE_ENTRY_SPINBUTTON (scales->slider_data[6]);
297
232
 
 
233
  table = gtk_widget_get_parent (scale);
 
234
  if (GTK_IS_TABLE (table))
 
235
    {
 
236
      gtk_table_set_row_spacing (GTK_TABLE (table), 5, /* rgb <-> alpha */
 
237
                                 show_alpha ? 3 : 0);
 
238
    }
 
239
 
298
240
  if (show_alpha)
299
241
    {
300
242
      gtk_widget_show (label);
375
317
      gimp_color_scale_set_color (GIMP_COLOR_SCALE (scales->sliders[i]),
376
318
                                  &selector->rgb, &selector->hsv);
377
319
    }
378
 
 
379
 
  g_signal_handlers_block_by_func (scales->hex_entry,
380
 
                                   gimp_color_scales_entry_changed,
381
 
                                   scales);
382
 
 
383
 
  gimp_color_hex_entry_set_color (GIMP_COLOR_HEX_ENTRY (scales->hex_entry),
384
 
                                                        &selector->rgb);
385
 
 
386
 
  g_signal_handlers_unblock_by_func (scales->hex_entry,
387
 
                                     gimp_color_scales_entry_changed,
388
 
                                     scales);
389
320
}
390
321
 
391
322
static void
465
396
 
466
397
  gimp_color_selector_color_changed (selector);
467
398
}
468
 
 
469
 
static void
470
 
gimp_color_scales_entry_changed (GimpColorHexEntry *entry,
471
 
                                 GimpColorScales   *scales)
472
 
{
473
 
  GimpColorSelector *selector = GIMP_COLOR_SELECTOR (scales);
474
 
 
475
 
  gimp_color_hex_entry_get_color (entry, &selector->rgb);
476
 
 
477
 
  gimp_rgb_to_hsv (&selector->rgb, &selector->hsv);
478
 
  gimp_color_scales_update_scales (scales, -1);
479
 
 
480
 
  gimp_color_selector_color_changed (selector);
481
 
}