~ubuntu-branches/ubuntu/hoary/gimp/hoary

« back to all changes in this revision

Viewing changes to app/widgets/gimpfgbgeditor.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2005-04-04 14:51:23 UTC
  • Revision ID: james.westby@ubuntu.com-20050404145123-9py049eeelfymur8
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* The GIMP -- an image manipulation program
 
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 *
 
4
 * gimpfgbgeditor.c
 
5
 * Copyright (C) 2004 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 <string.h>
 
25
 
 
26
#include <gtk/gtk.h>
 
27
 
 
28
#include "libgimpcolor/gimpcolor.h"
 
29
#include "libgimpwidgets/gimpwidgets.h"
 
30
 
 
31
#include "widgets-types.h"
 
32
 
 
33
#include "core/gimpcontext.h"
 
34
#include "core/gimpmarshal.h"
 
35
 
 
36
#include "gimpdnd.h"
 
37
#include "gimpfgbgeditor.h"
 
38
 
 
39
 
 
40
enum
 
41
{
 
42
  PROP_0,
 
43
  PROP_CONTEXT,
 
44
  PROP_ACTIVE_COLOR
 
45
};
 
46
 
 
47
enum
 
48
{
 
49
  COLOR_CLICKED,
 
50
  LAST_SIGNAL
 
51
};
 
52
 
 
53
typedef enum
 
54
{
 
55
  INVALID_AREA,
 
56
  FORE_AREA,
 
57
  BACK_AREA,
 
58
  SWAP_AREA,
 
59
  DEFAULT_AREA
 
60
} FgBgTarget;
 
61
 
 
62
 
 
63
static void     gimp_fg_bg_editor_class_init (GimpFgBgEditorClass *klass);
 
64
static void     gimp_fg_bg_editor_init       (GimpFgBgEditor      *editor);
 
65
 
 
66
static void     gimp_fg_bg_editor_set_property    (GObject        *object,
 
67
                                                   guint           property_id,
 
68
                                                   const GValue   *value,
 
69
                                                   GParamSpec     *pspec);
 
70
static void     gimp_fg_bg_editor_get_property    (GObject        *object,
 
71
                                                   guint           property_id,
 
72
                                                   GValue         *value,
 
73
                                                   GParamSpec     *pspec);
 
74
 
 
75
static void     gimp_fg_bg_editor_destroy         (GtkObject      *object);
 
76
static gboolean gimp_fg_bg_editor_expose          (GtkWidget      *widget,
 
77
                                                   GdkEventExpose *eevent);
 
78
static gboolean gimp_fg_bg_editor_button_press    (GtkWidget      *widget,
 
79
                                                   GdkEventButton *bevent);
 
80
static gboolean gimp_fg_bg_editor_button_release  (GtkWidget      *widget,
 
81
                                                   GdkEventButton *bevent);
 
82
static gboolean gimp_fg_bg_editor_drag_motion     (GtkWidget      *widget,
 
83
                                                   GdkDragContext *context,
 
84
                                                   gint            x,
 
85
                                                   gint            y,
 
86
                                                   guint           time);
 
87
 
 
88
static void     gimp_fg_bg_editor_drag_color      (GtkWidget      *widget,
 
89
                                                   GimpRGB        *color,
 
90
                                                   gpointer        data);
 
91
static void     gimp_fg_bg_editor_drop_color      (GtkWidget      *widget,
 
92
                                                   const GimpRGB  *color,
 
93
                                                   gpointer        data);
 
94
 
 
95
 
 
96
static guint  editor_signals[LAST_SIGNAL] = { 0 };
 
97
 
 
98
static GtkDrawingAreaClass *parent_class = NULL;
 
99
 
 
100
 
 
101
GType
 
102
gimp_fg_bg_editor_get_type (void)
 
103
{
 
104
  static GType type = 0;
 
105
 
 
106
  if (! type)
 
107
    {
 
108
      static const GTypeInfo info =
 
109
      {
 
110
        sizeof (GimpFgBgEditorClass),
 
111
        NULL,           /* base_init */
 
112
        NULL,           /* base_finalize */
 
113
        (GClassInitFunc) gimp_fg_bg_editor_class_init,
 
114
        NULL,           /* class_finalize */
 
115
        NULL,           /* class_data */
 
116
        sizeof (GimpFgBgEditor),
 
117
        0,              /* n_preallocs */
 
118
        (GInstanceInitFunc) gimp_fg_bg_editor_init,
 
119
      };
 
120
 
 
121
      type = g_type_register_static (GTK_TYPE_DRAWING_AREA,
 
122
                                     "GimpFgBgEditor",
 
123
                                     &info, 0);
 
124
    }
 
125
 
 
126
  return type;
 
127
}
 
128
 
 
129
static void
 
130
gimp_fg_bg_editor_class_init (GimpFgBgEditorClass *klass)
 
131
{
 
132
  GObjectClass   *object_class     = G_OBJECT_CLASS (klass);
 
133
  GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass);
 
134
  GtkWidgetClass *widget_class     = GTK_WIDGET_CLASS (klass);
 
135
 
 
136
  parent_class = g_type_class_peek_parent (klass);
 
137
 
 
138
  editor_signals[COLOR_CLICKED] =
 
139
    g_signal_new ("color-clicked",
 
140
                  G_TYPE_FROM_CLASS (klass),
 
141
                  G_SIGNAL_RUN_FIRST,
 
142
                  G_STRUCT_OFFSET (GimpFgBgEditorClass, color_clicked),
 
143
                  NULL, NULL,
 
144
                  gimp_marshal_VOID__ENUM,
 
145
                  G_TYPE_NONE, 1,
 
146
                  GIMP_TYPE_ACTIVE_COLOR);
 
147
 
 
148
  object_class->set_property         = gimp_fg_bg_editor_set_property;
 
149
  object_class->get_property         = gimp_fg_bg_editor_get_property;
 
150
 
 
151
  gtk_object_class->destroy          = gimp_fg_bg_editor_destroy;
 
152
 
 
153
  widget_class->expose_event         = gimp_fg_bg_editor_expose;
 
154
  widget_class->button_press_event   = gimp_fg_bg_editor_button_press;
 
155
  widget_class->button_release_event = gimp_fg_bg_editor_button_release;
 
156
  widget_class->drag_motion          = gimp_fg_bg_editor_drag_motion;
 
157
 
 
158
  g_object_class_install_property (object_class, PROP_CONTEXT,
 
159
                                   g_param_spec_object ("context",
 
160
                                                        NULL, NULL,
 
161
                                                        GIMP_TYPE_CONTEXT,
 
162
                                                        G_PARAM_READWRITE));
 
163
 
 
164
  g_object_class_install_property (object_class, PROP_ACTIVE_COLOR,
 
165
                                   g_param_spec_enum ("active-color",
 
166
                                                      NULL, NULL,
 
167
                                                      GIMP_TYPE_ACTIVE_COLOR,
 
168
                                                      GIMP_ACTIVE_COLOR_FOREGROUND,
 
169
                                                      G_PARAM_READWRITE));
 
170
}
 
171
 
 
172
static void
 
173
gimp_fg_bg_editor_init (GimpFgBgEditor *editor)
 
174
{
 
175
  editor->context      = NULL;
 
176
  editor->active_color = GIMP_ACTIVE_COLOR_FOREGROUND;
 
177
 
 
178
  gtk_widget_add_events (GTK_WIDGET (editor),
 
179
                         GDK_BUTTON_PRESS_MASK |
 
180
                         GDK_BUTTON_RELEASE_MASK);
 
181
 
 
182
  gimp_dnd_color_source_add (GTK_WIDGET (editor),
 
183
                             gimp_fg_bg_editor_drag_color, NULL);
 
184
  gimp_dnd_color_dest_add (GTK_WIDGET (editor),
 
185
                           gimp_fg_bg_editor_drop_color, NULL);
 
186
}
 
187
 
 
188
static void
 
189
gimp_fg_bg_editor_set_property (GObject      *object,
 
190
                                guint         property_id,
 
191
                                const GValue *value,
 
192
                                GParamSpec   *pspec)
 
193
{
 
194
  GimpFgBgEditor *editor = GIMP_FG_BG_EDITOR (object);
 
195
 
 
196
  switch (property_id)
 
197
    {
 
198
    case PROP_CONTEXT:
 
199
      gimp_fg_bg_editor_set_context (editor, g_value_get_object (value));
 
200
      break;
 
201
    case PROP_ACTIVE_COLOR:
 
202
      gimp_fg_bg_editor_set_active (editor, g_value_get_enum (value));
 
203
      break;
 
204
    default:
 
205
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
206
      break;
 
207
    }
 
208
}
 
209
 
 
210
static void
 
211
gimp_fg_bg_editor_get_property (GObject    *object,
 
212
                                guint       property_id,
 
213
                                GValue     *value,
 
214
                                GParamSpec *pspec)
 
215
{
 
216
  GimpFgBgEditor *editor = GIMP_FG_BG_EDITOR (object);
 
217
 
 
218
  switch (property_id)
 
219
    {
 
220
    case PROP_CONTEXT:
 
221
      g_value_set_object (value, editor->context);
 
222
      break;
 
223
    case PROP_ACTIVE_COLOR:
 
224
      g_value_set_enum (value, editor->active_color);
 
225
      break;
 
226
    default:
 
227
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
228
      break;
 
229
    }
 
230
}
 
231
 
 
232
static void
 
233
gimp_fg_bg_editor_destroy (GtkObject *object)
 
234
{
 
235
  GimpFgBgEditor *editor = GIMP_FG_BG_EDITOR (object);
 
236
 
 
237
  if (editor->context)
 
238
    gimp_fg_bg_editor_set_context (editor, NULL);
 
239
 
 
240
  if (editor->render_buf)
 
241
    {
 
242
      g_free (editor->render_buf);
 
243
      editor->render_buf = NULL;
 
244
      editor->render_buf_size = 0;
 
245
    }
 
246
 
 
247
  if (editor->default_icon)
 
248
    {
 
249
      g_object_unref (editor->default_icon);
 
250
      editor->default_icon = NULL;
 
251
    }
 
252
 
 
253
  if (editor->swap_icon)
 
254
    {
 
255
      g_object_unref (editor->swap_icon);
 
256
      editor->swap_icon = NULL;
 
257
    }
 
258
 
 
259
  GTK_OBJECT_CLASS (parent_class)->destroy (object);
 
260
}
 
261
 
 
262
static void
 
263
gimp_fg_bg_editor_draw_rect (GimpFgBgEditor *editor,
 
264
                             GdkDrawable    *drawable,
 
265
                             GdkGC          *gc,
 
266
                             gint            x,
 
267
                             gint            y,
 
268
                             gint            width,
 
269
                             gint            height,
 
270
                             const GimpRGB  *color)
 
271
{
 
272
  gint    rowstride;
 
273
  guchar  r, g, b;
 
274
  gint    xx, yy;
 
275
  guchar *bp;
 
276
 
 
277
  gimp_rgb_get_uchar (color, &r, &g, &b);
 
278
 
 
279
  rowstride = 3 * ((width + 3) & -4);
 
280
 
 
281
  if (! editor->render_buf || editor->render_buf_size < height * rowstride)
 
282
    {
 
283
      editor->render_buf_size = rowstride * height;
 
284
 
 
285
      g_free (editor->render_buf);
 
286
      editor->render_buf = g_malloc (editor->render_buf_size);
 
287
    }
 
288
 
 
289
  bp = editor->render_buf;
 
290
  for (xx = 0; xx < width; xx++)
 
291
    {
 
292
      *bp++ = r;
 
293
      *bp++ = g;
 
294
      *bp++ = b;
 
295
    }
 
296
 
 
297
  bp = editor->render_buf;
 
298
 
 
299
  for (yy = 1; yy < height; yy++)
 
300
    {
 
301
      bp += rowstride;
 
302
      memcpy (bp, editor->render_buf, rowstride);
 
303
    }
 
304
 
 
305
  gdk_draw_rgb_image (drawable, gc, x, y, width, height,
 
306
                      GDK_RGB_DITHER_MAX,
 
307
                      editor->render_buf,
 
308
                      rowstride);
 
309
}
 
310
 
 
311
static gboolean
 
312
gimp_fg_bg_editor_expose (GtkWidget      *widget,
 
313
                          GdkEventExpose *eevent)
 
314
{
 
315
  GimpFgBgEditor *editor = GIMP_FG_BG_EDITOR (widget);
 
316
  gint            width, height;
 
317
  gint            default_w, default_h;
 
318
  gint            swap_w, swap_h;
 
319
  gint            rect_w, rect_h;
 
320
  GimpRGB         color;
 
321
 
 
322
  if (! GTK_WIDGET_DRAWABLE (widget))
 
323
    return FALSE;
 
324
 
 
325
  width  = widget->allocation.width;
 
326
  height = widget->allocation.height;
 
327
 
 
328
  /*  draw the default colors pixbuf  */
 
329
  if (! editor->default_icon)
 
330
    editor->default_icon = gtk_widget_render_icon (widget,
 
331
                                                   GIMP_STOCK_DEFAULT_COLORS,
 
332
                                                   GTK_ICON_SIZE_MENU, NULL);
 
333
 
 
334
  default_w = gdk_pixbuf_get_width  (editor->default_icon);
 
335
  default_h = gdk_pixbuf_get_height (editor->default_icon);
 
336
  gdk_draw_pixbuf (widget->window, NULL, editor->default_icon,
 
337
                   0, 0, 0, height - default_h, default_w, default_h,
 
338
                   GDK_RGB_DITHER_NORMAL, 0, 0);
 
339
 
 
340
  /*  draw the swap colors pixbuf  */
 
341
  if (! editor->swap_icon)
 
342
    editor->swap_icon = gtk_widget_render_icon (widget,
 
343
                                                GIMP_STOCK_SWAP_COLORS,
 
344
                                                GTK_ICON_SIZE_MENU, NULL);
 
345
 
 
346
  swap_w = gdk_pixbuf_get_width  (editor->swap_icon);
 
347
  swap_h = gdk_pixbuf_get_height (editor->swap_icon);
 
348
  gdk_draw_pixbuf (widget->window, NULL, editor->swap_icon,
 
349
                   0, 0, width - swap_w, 0, swap_w, swap_h,
 
350
                   GDK_RGB_DITHER_NORMAL, 0, 0);
 
351
 
 
352
 
 
353
  rect_h = height - MAX (default_h, swap_h) - 2;
 
354
  rect_w = width  - MAX (default_w, swap_w) - 4;
 
355
 
 
356
  if (rect_h > (height * 3 / 4))
 
357
    rect_w = MAX (rect_w - (rect_h - ((height * 3 / 4))),
 
358
                  width * 2 / 3);
 
359
 
 
360
  editor->rect_width  = rect_w;
 
361
  editor->rect_height = rect_h;
 
362
 
 
363
 
 
364
  /*  draw the background area  */
 
365
 
 
366
  if (editor->context)
 
367
    {
 
368
      gimp_context_get_background (editor->context, &color);
 
369
      gimp_fg_bg_editor_draw_rect (editor,
 
370
                                   widget->window,
 
371
                                   widget->style->fg_gc[0],
 
372
                                   (width - rect_w),
 
373
                                   (height - rect_h),
 
374
                                   rect_w, rect_h,
 
375
                                   &color);
 
376
    }
 
377
 
 
378
  gtk_paint_shadow (widget->style, widget->window, GTK_STATE_NORMAL,
 
379
                    editor->active_color == GIMP_ACTIVE_COLOR_FOREGROUND ?
 
380
                    GTK_SHADOW_OUT : GTK_SHADOW_IN,
 
381
                    NULL, widget, NULL,
 
382
                    (width - rect_w),
 
383
                    (height - rect_h),
 
384
                    rect_w, rect_h);
 
385
 
 
386
 
 
387
  /*  draw the foreground area  */
 
388
 
 
389
  if (editor->context)
 
390
    {
 
391
      gimp_context_get_foreground (editor->context, &color);
 
392
      gimp_fg_bg_editor_draw_rect (editor,
 
393
                                   widget->window,
 
394
                                   widget->style->fg_gc[0],
 
395
                                   0, 0,
 
396
                                   rect_w, rect_h,
 
397
                                   &color);
 
398
    }
 
399
 
 
400
  gtk_paint_shadow (widget->style, widget->window, GTK_STATE_NORMAL,
 
401
                    editor->active_color == GIMP_ACTIVE_COLOR_BACKGROUND ?
 
402
                    GTK_SHADOW_OUT : GTK_SHADOW_IN,
 
403
                    NULL, widget, NULL,
 
404
                    0, 0,
 
405
                    rect_w, rect_h);
 
406
 
 
407
  return TRUE;
 
408
}
 
409
 
 
410
static FgBgTarget
 
411
gimp_fg_bg_editor_target (GimpFgBgEditor *editor,
 
412
                          gint            x,
 
413
                          gint            y)
 
414
{
 
415
  gint width  = GTK_WIDGET (editor)->allocation.width;
 
416
  gint height = GTK_WIDGET (editor)->allocation.height;
 
417
  gint rect_w = editor->rect_width;
 
418
  gint rect_h = editor->rect_height;
 
419
 
 
420
  if (x > 0 && x < rect_w && y > 0 && y < rect_h)
 
421
    return FORE_AREA;
 
422
  else if (x > (width - rect_w)  && x < width  &&
 
423
           y > (height - rect_h) && y < height)
 
424
    return BACK_AREA;
 
425
  else if (x > 0      && x < (width - rect_w) &&
 
426
           y > rect_h && y < height)
 
427
    return DEFAULT_AREA;
 
428
  else if (x > rect_w && x < width &&
 
429
           y > 0      && y < (height - rect_h))
 
430
    return SWAP_AREA;
 
431
 
 
432
  return INVALID_AREA;
 
433
}
 
434
 
 
435
static gboolean
 
436
gimp_fg_bg_editor_button_press (GtkWidget      *widget,
 
437
                                GdkEventButton *bevent)
 
438
{
 
439
  GimpFgBgEditor *editor = GIMP_FG_BG_EDITOR (widget);
 
440
 
 
441
  if (bevent->button == 1 && bevent->type == GDK_BUTTON_PRESS)
 
442
    {
 
443
      FgBgTarget target = gimp_fg_bg_editor_target (editor,
 
444
                                                    bevent->x, bevent->y);
 
445
 
 
446
      editor->click_target = INVALID_AREA;
 
447
 
 
448
      switch (target)
 
449
        {
 
450
        case FORE_AREA:
 
451
          if (editor->active_color != GIMP_ACTIVE_COLOR_FOREGROUND)
 
452
            gimp_fg_bg_editor_set_active (editor,
 
453
                                          GIMP_ACTIVE_COLOR_FOREGROUND);
 
454
          else
 
455
            editor->click_target = FORE_AREA;
 
456
          break;
 
457
 
 
458
        case BACK_AREA:
 
459
          if (editor->active_color != GIMP_ACTIVE_COLOR_BACKGROUND)
 
460
            gimp_fg_bg_editor_set_active (editor,
 
461
                                          GIMP_ACTIVE_COLOR_BACKGROUND);
 
462
          else
 
463
            editor->click_target = BACK_AREA;
 
464
          break;
 
465
 
 
466
        case SWAP_AREA:
 
467
          if (editor->context)
 
468
            gimp_context_swap_colors (editor->context);
 
469
          break;
 
470
 
 
471
        case DEFAULT_AREA:
 
472
          if (editor->context)
 
473
            gimp_context_set_default_colors (editor->context);
 
474
          break;
 
475
 
 
476
        default:
 
477
          break;
 
478
        }
 
479
    }
 
480
 
 
481
  return FALSE;
 
482
}
 
483
 
 
484
static gboolean
 
485
gimp_fg_bg_editor_button_release (GtkWidget      *widget,
 
486
                                  GdkEventButton *bevent)
 
487
{
 
488
  GimpFgBgEditor *editor = GIMP_FG_BG_EDITOR (widget);
 
489
 
 
490
  if (bevent->button == 1)
 
491
    {
 
492
      FgBgTarget target = gimp_fg_bg_editor_target (editor,
 
493
                                                    bevent->x, bevent->y);
 
494
 
 
495
      if (target == editor->click_target)
 
496
        {
 
497
          switch (target)
 
498
            {
 
499
            case FORE_AREA:
 
500
              g_signal_emit (editor, editor_signals[COLOR_CLICKED], 0,
 
501
                             GIMP_ACTIVE_COLOR_FOREGROUND);
 
502
              break;
 
503
 
 
504
            case BACK_AREA:
 
505
              g_signal_emit (editor, editor_signals[COLOR_CLICKED], 0,
 
506
                             GIMP_ACTIVE_COLOR_BACKGROUND);
 
507
              break;
 
508
 
 
509
            default:
 
510
              break;
 
511
            }
 
512
        }
 
513
 
 
514
      editor->click_target = INVALID_AREA;
 
515
    }
 
516
 
 
517
  return FALSE;
 
518
}
 
519
 
 
520
static gboolean
 
521
gimp_fg_bg_editor_drag_motion (GtkWidget      *widget,
 
522
                               GdkDragContext *context,
 
523
                               gint            x,
 
524
                               gint            y,
 
525
                               guint           time)
 
526
{
 
527
  GimpFgBgEditor *editor = GIMP_FG_BG_EDITOR (widget);
 
528
 
 
529
  editor->dnd_target = gimp_fg_bg_editor_target (editor, x, y);
 
530
 
 
531
  if (editor->dnd_target == FORE_AREA ||
 
532
      editor->dnd_target == BACK_AREA)
 
533
    {
 
534
      gdk_drag_status (context, GDK_ACTION_COPY, time);
 
535
 
 
536
      return TRUE;
 
537
    }
 
538
 
 
539
  gdk_drag_status (context, 0, time);
 
540
 
 
541
  return FALSE;
 
542
}
 
543
 
 
544
 
 
545
/*  public functions  */
 
546
 
 
547
GtkWidget *
 
548
gimp_fg_bg_editor_new (GimpContext *context)
 
549
{
 
550
  g_return_val_if_fail (context == NULL || GIMP_IS_CONTEXT (context), NULL);
 
551
 
 
552
  return g_object_new (GIMP_TYPE_FG_BG_EDITOR,
 
553
                       "context", context,
 
554
                       NULL);
 
555
}
 
556
 
 
557
void
 
558
gimp_fg_bg_editor_set_context (GimpFgBgEditor *editor,
 
559
                               GimpContext    *context)
 
560
{
 
561
  g_return_if_fail (GIMP_IS_FG_BG_EDITOR (editor));
 
562
  g_return_if_fail (context == NULL || GIMP_IS_CONTEXT (context));
 
563
 
 
564
  if (context == editor->context)
 
565
    return;
 
566
 
 
567
  if (editor->context)
 
568
    {
 
569
      g_signal_handlers_disconnect_by_func (editor->context,
 
570
                                            gtk_widget_queue_draw,
 
571
                                            editor);
 
572
      g_object_unref (editor->context);
 
573
      editor->context = NULL;
 
574
    }
 
575
 
 
576
  editor->context = context;
 
577
 
 
578
  if (context)
 
579
    {
 
580
      g_object_ref (context);
 
581
 
 
582
      g_signal_connect_swapped (context, "foreground_changed",
 
583
                                G_CALLBACK (gtk_widget_queue_draw),
 
584
                                editor);
 
585
      g_signal_connect_swapped (context, "background_changed",
 
586
                                G_CALLBACK (gtk_widget_queue_draw),
 
587
                                editor);
 
588
    }
 
589
 
 
590
  g_object_notify (G_OBJECT (editor), "context");
 
591
}
 
592
 
 
593
void
 
594
gimp_fg_bg_editor_set_active (GimpFgBgEditor  *editor,
 
595
                              GimpActiveColor  active)
 
596
{
 
597
  g_return_if_fail (GIMP_IS_FG_BG_EDITOR (editor));
 
598
 
 
599
  editor->active_color = active;
 
600
  gtk_widget_queue_draw (GTK_WIDGET (editor));
 
601
  g_object_notify (G_OBJECT (editor), "active-color");
 
602
}
 
603
 
 
604
 
 
605
/*  private functions  */
 
606
 
 
607
static void
 
608
gimp_fg_bg_editor_drag_color (GtkWidget *widget,
 
609
                              GimpRGB   *color,
 
610
                              gpointer   data)
 
611
{
 
612
  GimpFgBgEditor *editor = GIMP_FG_BG_EDITOR (widget);
 
613
 
 
614
  if (editor->context)
 
615
    {
 
616
      switch (editor->active_color)
 
617
        {
 
618
        case GIMP_ACTIVE_COLOR_FOREGROUND:
 
619
          gimp_context_get_foreground (editor->context, color);
 
620
          break;
 
621
 
 
622
        case GIMP_ACTIVE_COLOR_BACKGROUND:
 
623
          gimp_context_get_background (editor->context, color);
 
624
          break;
 
625
        }
 
626
    }
 
627
}
 
628
 
 
629
static void
 
630
gimp_fg_bg_editor_drop_color (GtkWidget     *widget,
 
631
                              const GimpRGB *color,
 
632
                              gpointer       data)
 
633
{
 
634
  GimpFgBgEditor *editor = GIMP_FG_BG_EDITOR (widget);
 
635
 
 
636
  if (editor->context)
 
637
    {
 
638
      switch (editor->dnd_target)
 
639
        {
 
640
        case FORE_AREA:
 
641
          gimp_context_set_foreground (editor->context, color);
 
642
          break;
 
643
 
 
644
        case BACK_AREA:
 
645
          gimp_context_set_background (editor->context, color);
 
646
          break;
 
647
 
 
648
        default:
 
649
          break;
 
650
        }
 
651
    }
 
652
}