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

« back to all changes in this revision

Viewing changes to libgimpwidgets/gimpcolorbutton.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:
61
61
  LAST_SIGNAL
62
62
};
63
63
 
 
64
enum
 
65
{
 
66
  PROP_0,
 
67
  PROP_TITLE,
 
68
  PROP_COLOR,
 
69
  PROP_TYPE,
 
70
  PROP_UPDATE
 
71
};
 
72
 
64
73
 
65
74
static void     gimp_color_button_class_init   (GimpColorButtonClass *klass);
66
75
static void     gimp_color_button_init         (GimpColorButton      *button,
67
76
                                                GimpColorButtonClass *klass);
68
77
 
 
78
static void     gimp_color_button_get_property      (GObject         *object,
 
79
                                                     guint            property_id,
 
80
                                                     GValue          *value,
 
81
                                                     GParamSpec      *pspec);
 
82
static void     gimp_color_button_set_property      (GObject         *object,
 
83
                                                     guint            property_id,
 
84
                                                     const GValue    *value,
 
85
                                                     GParamSpec      *pspec);
 
86
static void     gimp_color_button_finalize          (GObject         *object);
 
87
 
69
88
static void     gimp_color_button_destroy           (GtkObject       *object);
70
89
 
71
90
static gboolean gimp_color_button_button_press      (GtkWidget       *widget,
88
107
                                                     gpointer         help_data);
89
108
 
90
109
 
91
 
static GtkActionEntry actions[] =
 
110
static const GtkActionEntry actions[] =
92
111
{
93
112
  { "color-button-popup", NULL,
94
113
    "Color Button Menu", NULL, NULL,
123
142
{
124
143
  static GType button_type = 0;
125
144
 
126
 
  if (!button_type)
 
145
  if (! button_type)
127
146
    {
128
 
      static const GTypeInfo button_info =
 
147
      const GTypeInfo button_info =
129
148
      {
130
149
        sizeof (GimpColorButtonClass),
131
150
        (GBaseInitFunc) NULL,
149
168
static void
150
169
gimp_color_button_class_init (GimpColorButtonClass *klass)
151
170
{
152
 
  GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
153
 
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
154
 
  GtkButtonClass *button_class = GTK_BUTTON_CLASS (klass);
 
171
  GObjectClass   *object_class     = G_OBJECT_CLASS (klass);
 
172
  GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass);
 
173
  GtkWidgetClass *widget_class     = GTK_WIDGET_CLASS (klass);
 
174
  GtkButtonClass *button_class     = GTK_BUTTON_CLASS (klass);
 
175
  GimpRGB         color;
155
176
 
156
177
  parent_class = g_type_class_peek_parent (klass);
157
178
 
158
179
  gimp_color_button_signals[COLOR_CHANGED] =
159
 
    g_signal_new ("color_changed",
 
180
    g_signal_new ("color-changed",
160
181
                  G_TYPE_FROM_CLASS (klass),
161
182
                  G_SIGNAL_RUN_FIRST,
162
183
                  G_STRUCT_OFFSET (GimpColorButtonClass, color_changed),
164
185
                  g_cclosure_marshal_VOID__VOID,
165
186
                  G_TYPE_NONE, 0);
166
187
 
167
 
  object_class->destroy            = gimp_color_button_destroy;
 
188
  object_class->get_property       = gimp_color_button_get_property;
 
189
  object_class->set_property       = gimp_color_button_set_property;
 
190
  object_class->finalize           = gimp_color_button_finalize;
 
191
 
 
192
  gtk_object_class->destroy        = gimp_color_button_destroy;
168
193
 
169
194
  widget_class->button_press_event = gimp_color_button_button_press;
170
195
  widget_class->state_changed      = gimp_color_button_state_changed;
173
198
 
174
199
  klass->color_changed             = NULL;
175
200
  klass->get_action_type           = gimp_color_button_get_action_type;
 
201
 
 
202
  gimp_rgba_set (&color, 0.0, 0.0, 0.0, 1.0);
 
203
 
 
204
  /**
 
205
   * GimpColorButton:title:
 
206
   *
 
207
   * The title to be used for the color selection dialog.
 
208
   *
 
209
   * Since: GIMP 2.4
 
210
   */
 
211
  g_object_class_install_property (object_class, PROP_TITLE,
 
212
                                   g_param_spec_string ("title", NULL, NULL,
 
213
                                                        NULL,
 
214
                                                        GIMP_PARAM_READWRITE |
 
215
                                                        G_PARAM_CONSTRUCT_ONLY));
 
216
  /**
 
217
   * GimpColorButton:color:
 
218
   *
 
219
   * The color displayed in the button's color area.
 
220
   *
 
221
   * Since: GIMP 2.4
 
222
   */
 
223
  g_object_class_install_property (object_class, PROP_COLOR,
 
224
                                   gimp_param_spec_rgb ("color", NULL, NULL,
 
225
                                                        TRUE, &color,
 
226
                                                        GIMP_PARAM_READWRITE |
 
227
                                                        G_PARAM_CONSTRUCT));
 
228
  /**
 
229
   * GimpColorButton:type:
 
230
   *
 
231
   * The type of the button's color area.
 
232
   *
 
233
   * Since: GIMP 2.4
 
234
   */
 
235
  g_object_class_install_property (object_class, PROP_TYPE,
 
236
                                   g_param_spec_enum ("type", NULL, NULL,
 
237
                                                      GIMP_TYPE_COLOR_AREA_TYPE,
 
238
                                                      GIMP_COLOR_AREA_FLAT,
 
239
                                                      GIMP_PARAM_READWRITE |
 
240
                                                      G_PARAM_CONSTRUCT));
 
241
  /**
 
242
   * GimpColorButton:continuous-update:
 
243
   *
 
244
   * The update policy of the color button.
 
245
   *
 
246
   * Since: GIMP 2.4
 
247
   */
 
248
  g_object_class_install_property (object_class, PROP_UPDATE,
 
249
                                   g_param_spec_boolean ("continuous-update",
 
250
                                                         NULL, NULL,
 
251
                                                         FALSE,
 
252
                                                         G_PARAM_READWRITE |
 
253
                                                         G_PARAM_CONSTRUCT));
176
254
}
177
255
 
178
256
static void
181
259
{
182
260
  GtkActionGroup *group;
183
261
  GtkUIManager   *ui_manager;
184
 
  GimpRGB         color;
185
262
  gint            i;
186
263
 
187
 
  button->continuous_update = FALSE;
188
 
  button->title             = NULL;
189
 
  button->dialog            = NULL;
190
 
 
191
 
  gimp_rgba_set (&color, 0.0, 0.0, 0.0, 1.0);
192
 
  button->color_area = gimp_color_area_new (&color, FALSE, GDK_BUTTON2_MASK);
193
 
  g_signal_connect (button->color_area, "color_changed",
 
264
  button->title  = NULL;
 
265
  button->dialog = NULL;
 
266
 
 
267
  button->color_area = g_object_new (GIMP_TYPE_COLOR_AREA,
 
268
                                     "drag-mask", GDK_BUTTON1_MASK,
 
269
                                     NULL);
 
270
 
 
271
  g_signal_connect (button->color_area, "color-changed",
194
272
                    G_CALLBACK (gimp_color_button_area_changed),
195
273
                    button);
196
274
 
244
322
}
245
323
 
246
324
static void
247
 
gimp_color_button_destroy (GtkObject *object)
 
325
gimp_color_button_finalize (GObject *object)
248
326
{
249
327
  GimpColorButton *button = GIMP_COLOR_BUTTON (object);
250
328
 
254
332
      button->title = NULL;
255
333
    }
256
334
 
 
335
  G_OBJECT_CLASS (parent_class)->finalize (object);
 
336
}
 
337
 
 
338
static void
 
339
gimp_color_button_get_property (GObject    *object,
 
340
                                guint       property_id,
 
341
                                GValue     *value,
 
342
                                GParamSpec *pspec)
 
343
{
 
344
  GimpColorButton *button = GIMP_COLOR_BUTTON (object);
 
345
 
 
346
  switch (property_id)
 
347
    {
 
348
    case PROP_TITLE:
 
349
      g_value_set_string (value, button->title);
 
350
      break;
 
351
 
 
352
    case PROP_COLOR:
 
353
      g_object_get_property (G_OBJECT (button->color_area), "color", value);
 
354
      break;
 
355
 
 
356
    case PROP_TYPE:
 
357
      g_object_get_property (G_OBJECT (button->color_area), "type", value);
 
358
      break;
 
359
 
 
360
    case PROP_UPDATE:
 
361
      g_value_set_boolean (value, button->continuous_update);
 
362
      break;
 
363
 
 
364
    default:
 
365
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
366
      break;
 
367
    }
 
368
}
 
369
 
 
370
static void
 
371
gimp_color_button_set_property (GObject      *object,
 
372
                                guint         property_id,
 
373
                                const GValue *value,
 
374
                                GParamSpec   *pspec)
 
375
{
 
376
  GimpColorButton *button = GIMP_COLOR_BUTTON (object);
 
377
 
 
378
  switch (property_id)
 
379
    {
 
380
    case PROP_TITLE:
 
381
      g_free (button->title);
 
382
      button->title = g_value_dup_string (value);
 
383
      break;
 
384
 
 
385
    case PROP_COLOR:
 
386
      g_object_set_property (G_OBJECT (button->color_area), "color", value);
 
387
      break;
 
388
 
 
389
    case PROP_TYPE:
 
390
      g_object_set_property (G_OBJECT (button->color_area), "type", value);
 
391
      break;
 
392
 
 
393
    case PROP_UPDATE:
 
394
      gimp_color_button_set_update (button, g_value_get_boolean (value));
 
395
      break;
 
396
 
 
397
    default:
 
398
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
399
      break;
 
400
    }
 
401
}
 
402
 
 
403
static void
 
404
gimp_color_button_destroy (GtkObject *object)
 
405
{
 
406
  GimpColorButton *button = GIMP_COLOR_BUTTON (object);
 
407
 
257
408
  if (button->dialog)
258
409
    {
259
410
      gtk_widget_destroy (button->dialog);
327
478
 
328
479
      dialog = color_button->dialog =
329
480
        gimp_dialog_new (color_button->title, COLOR_SELECTION_KEY,
330
 
                         GTK_WIDGET (button), 0,
 
481
                         gtk_widget_get_toplevel (GTK_WIDGET (button)), 0,
331
482
                         gimp_color_button_help_func, NULL,
332
483
 
333
484
                         GIMP_STOCK_RESET, RESPONSE_RESET,
336
487
 
337
488
                         NULL);
338
489
 
 
490
      gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
 
491
                                               RESPONSE_RESET,
 
492
                                               GTK_RESPONSE_OK,
 
493
                                               GTK_RESPONSE_CANCEL,
 
494
                                               -1);
 
495
 
339
496
      g_signal_connect (dialog, "response",
340
497
                        G_CALLBACK (gimp_color_button_dialog_response),
341
498
                        color_button);
353
510
      gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), selection);
354
511
      gtk_widget_show (selection);
355
512
 
356
 
      g_signal_connect (selection, "color_changed",
 
513
      g_signal_connect (selection, "color-changed",
357
514
                        G_CALLBACK (gimp_color_button_selection_changed),
358
515
                        button);
359
516
 
386
543
 * This returns a button with a preview showing the color.
387
544
 * When the button is clicked a GtkColorSelectionDialog is opened.
388
545
 * If the user changes the color the new color is written into the
389
 
 * array that was used to pass the initial color and the "color_changed"
 
546
 * array that was used to pass the initial color and the "color-changed"
390
547
 * signal is emitted.
391
548
 *
392
549
 * Returns: Pointer to the new #GimpColorButton widget.
402
559
 
403
560
  g_return_val_if_fail (color != NULL, NULL);
404
561
 
405
 
  button = g_object_new (GIMP_TYPE_COLOR_BUTTON, NULL);
406
 
 
407
 
  button->title = g_strdup (title);
 
562
  button = g_object_new (GIMP_TYPE_COLOR_BUTTON,
 
563
                         "title", title,
 
564
                         "type",  type,
 
565
                         "color", color,
 
566
                         NULL);
408
567
 
409
568
  gtk_widget_set_size_request (GTK_WIDGET (button->color_area), width, height);
410
569
 
411
 
  gimp_color_area_set_type (GIMP_COLOR_AREA (button->color_area), type);
412
 
  gimp_color_area_set_color (GIMP_COLOR_AREA (button->color_area), color);
413
 
 
414
570
  return GTK_WIDGET (button);
415
571
}
416
572
 
429
585
  g_return_if_fail (color != NULL);
430
586
 
431
587
  gimp_color_area_set_color (GIMP_COLOR_AREA (button->color_area), color);
 
588
 
 
589
  g_object_notify (G_OBJECT (button), "color");
432
590
}
433
591
 
434
592
/**
479
637
  g_return_if_fail (GIMP_IS_COLOR_BUTTON (button));
480
638
 
481
639
  gimp_color_area_set_type (GIMP_COLOR_AREA (button->color_area), type);
 
640
 
 
641
  g_object_notify (G_OBJECT (button), "type");
482
642
}
483
643
 
484
644
/**
502
662
 * @button:     A #GimpColorButton widget.
503
663
 * @continuous: The new setting of the @continuous_update property.
504
664
 *
505
 
 * When set to #TRUE, the @button will emit the "color_changed"
 
665
 * When set to #TRUE, the @button will emit the "color-changed"
506
666
 * continuously while the color is changed in the color selection
507
667
 * dialog.
508
668
 **/
535
695
              gimp_color_button_set_color (button, &color);
536
696
            }
537
697
        }
 
698
 
 
699
      g_object_notify (G_OBJECT (button), "continuous-update");
538
700
    }
539
701
}
540
702