]> Pileus Git - ~andy/gtk/blob - gtk/gtkcolorswatch.c
color-swatch: use GtkThemingBackground to draw the background
[~andy/gtk] / gtk / gtkcolorswatch.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 2012 Red Hat, Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include "config.h"
21
22 #include "gtkcolorswatch.h"
23
24 #include "gtkroundedboxprivate.h"
25 #include "gtkthemingbackgroundprivate.h"
26 #include "gtkdnd.h"
27 #include "gtkicontheme.h"
28 #include "gtkmain.h"
29 #include "gtkmenu.h"
30 #include "gtkmenuitem.h"
31 #include "gtkmenushell.h"
32 #include "gtkprivate.h"
33 #include "gtkintl.h"
34
35
36 struct _GtkColorSwatchPrivate
37 {
38   GdkRGBA color;
39   gdouble radius[4];
40   gchar *icon;
41   guint    selected         : 1;
42   guint    has_color        : 1;
43   guint    can_drop         : 1;
44   guint    contains_pointer : 1;
45   guint    use_alpha        : 1;
46 };
47
48 enum
49 {
50   PROP_ZERO,
51   PROP_RGBA,
52   PROP_SELECTED
53 };
54
55 enum
56 {
57   ACTIVATE,
58   CUSTOMIZE,
59   LAST_SIGNAL
60 };
61
62 static guint signals[LAST_SIGNAL];
63
64 G_DEFINE_TYPE (GtkColorSwatch, gtk_color_swatch, GTK_TYPE_DRAWING_AREA)
65
66 static void
67 gtk_color_swatch_init (GtkColorSwatch *swatch)
68 {
69   swatch->priv = G_TYPE_INSTANCE_GET_PRIVATE (swatch,
70                                               GTK_TYPE_COLOR_SWATCH,
71                                               GtkColorSwatchPrivate);
72
73   gtk_widget_set_can_focus (GTK_WIDGET (swatch), TRUE);
74   gtk_widget_set_events (GTK_WIDGET (swatch), GDK_BUTTON_PRESS_MASK
75                                               | GDK_BUTTON_RELEASE_MASK
76                                               | GDK_EXPOSURE_MASK
77                                               | GDK_ENTER_NOTIFY_MASK
78                                               | GDK_LEAVE_NOTIFY_MASK);
79   swatch->priv->use_alpha = TRUE;
80 }
81
82 #define INTENSITY(r, g, b) ((r) * 0.30 + (g) * 0.59 + (b) * 0.11)
83
84 static cairo_pattern_t *
85 get_checkered_pattern (void)
86 {
87   /* need to respect pixman's stride being a multiple of 4 */
88   static unsigned char data[8] = { 0xFF, 0x00, 0x00, 0x00,
89                                    0x00, 0xFF, 0x00, 0x00 };
90   static cairo_surface_t *checkered = NULL;
91   cairo_pattern_t *pattern;
92
93   if (checkered == NULL)
94     checkered = cairo_image_surface_create_for_data (data,
95                                                      CAIRO_FORMAT_A8,
96                                                      2, 2, 4);
97
98   pattern = cairo_pattern_create_for_surface (checkered);
99   cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
100   cairo_pattern_set_filter (pattern, CAIRO_FILTER_NEAREST);
101
102   return pattern;
103 }
104
105 static gboolean
106 swatch_draw (GtkWidget *widget,
107              cairo_t   *cr)
108 {
109   GtkColorSwatch *swatch = (GtkColorSwatch*)widget;
110   GtkThemingBackground background;
111   GtkRoundedBox box;
112   gint i;
113   gdouble width, height;
114   GtkStyleContext *context;
115   GtkStateFlags state;
116   GdkRGBA bg;
117
118   context = gtk_widget_get_style_context (widget);
119   state = gtk_widget_get_state_flags (widget);
120   width = gtk_widget_get_allocated_width (widget);
121   height = gtk_widget_get_allocated_height (widget);
122
123   cairo_save (cr);
124
125   gtk_style_context_save (context);
126   gtk_style_context_set_state (context, state);
127
128   _gtk_theming_background_init_from_context (&background, context,
129                                              0, 0, width, height,
130                                              GTK_JUNCTION_NONE);
131
132   if (swatch->priv->has_color)
133     {
134       cairo_pattern_t *pattern;
135       cairo_matrix_t matrix;
136
137       if (swatch->priv->use_alpha)
138         {
139           cairo_save (cr);
140
141           _gtk_rounded_box_path (&background.clip_box, cr);
142           cairo_clip_preserve (cr);
143
144           cairo_set_source_rgb (cr, 0.33, 0.33, 0.33);
145           cairo_fill_preserve (cr);
146
147           pattern = get_checkered_pattern ();
148           cairo_matrix_init_scale (&matrix, 0.125, 0.125);
149           cairo_pattern_set_matrix (pattern, &matrix);
150
151           cairo_set_source_rgb (cr, 0.66, 0.66, 0.66);
152           cairo_mask (cr, pattern);
153           cairo_pattern_destroy (pattern);
154
155           cairo_restore (cr);
156
157           background.bg_color = swatch->priv->color;
158         }
159       else
160         {
161           background.bg_color = swatch->priv->color;
162           background.bg_color.alpha = 1.0;
163         }
164
165       _gtk_theming_background_render (&background, cr);
166     }
167
168   gtk_render_frame (context, cr,
169                     0, 0, width, height);
170
171   if (gtk_widget_has_visible_focus (widget))
172     {
173       cairo_set_line_width (cr, 2);
174       if (swatch->priv->has_color && INTENSITY (swatch->priv->color.red, swatch->priv->color.green, swatch->priv->color.blue) < 0.5)
175         cairo_set_source_rgba (cr, 1., 1., 1., 0.4);
176       else
177         cairo_set_source_rgba (cr, 0., 0., 0., 0.4);
178       _gtk_rounded_box_shrink (&background.clip_box, 3, 3, 3, 3);
179       _gtk_rounded_box_path (&background.clip_box, cr);
180       cairo_stroke (cr);
181     }
182
183   if (swatch->priv->icon)
184     {
185       GdkPixbuf *pixbuf;
186       GtkIconTheme *theme;
187       theme = gtk_icon_theme_get_default ();
188       pixbuf = gtk_icon_theme_load_icon (theme, "list-add-symbolic", 16,
189                                          GTK_ICON_LOOKUP_GENERIC_FALLBACK
190                                          | GTK_ICON_LOOKUP_USE_BUILTIN,
191                                          NULL);
192
193       gtk_render_icon (context, cr, pixbuf,
194                        (width - gdk_pixbuf_get_width (pixbuf)) / 2,
195                        (height - gdk_pixbuf_get_height (pixbuf)) / 2);
196       g_object_unref (pixbuf);
197     }
198   else  if (swatch->priv->selected)
199     {
200       gtk_style_context_get_background_color (context, state, &bg);
201       cairo_new_sub_path (cr);
202       cairo_arc (cr, width / 2, height / 2, 10, 0, 2 * G_PI);
203       cairo_close_path (cr);
204       gdk_cairo_set_source_rgba (cr, &bg);
205       cairo_fill_preserve (cr);
206       if (INTENSITY (swatch->priv->color.red, swatch->priv->color.green, swatch->priv->color.blue) > 0.5)
207         cairo_set_source_rgba (cr, 0., 0., 0., 0.4);
208       else
209         cairo_set_source_rgba (cr, 1., 1., 1., 0.4);
210       cairo_set_line_width (cr, 2);
211       cairo_stroke (cr);
212       gtk_style_context_set_state (context, state | GTK_STATE_FLAG_ACTIVE);
213       gtk_render_check (context, cr, width / 2 - 5, height / 2 - 5, 10, 10);
214     }
215
216   cairo_restore (cr);
217   gtk_style_context_restore (context);
218
219   return FALSE;
220 }
221
222 static void
223 drag_set_color_icon (GdkDragContext *context,
224                      const GdkRGBA  *color)
225 {
226   cairo_surface_t *surface;
227   cairo_t *cr;
228
229   surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 48, 32);
230   cr = cairo_create (surface);
231   gdk_cairo_set_source_rgba (cr, color);
232   cairo_paint (cr);
233
234   cairo_surface_set_device_offset (surface, -4, -4);
235   gtk_drag_set_icon_surface (context, surface);
236
237   cairo_destroy (cr);
238   cairo_surface_destroy (surface);
239 }
240
241 static void
242 swatch_drag_begin (GtkWidget      *widget,
243                    GdkDragContext *context)
244 {
245   GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
246   GdkRGBA color;
247
248   gtk_color_swatch_get_rgba (swatch, &color);
249   drag_set_color_icon (context, &color);
250 }
251
252 static void
253 swatch_drag_data_get (GtkWidget        *widget,
254                       GdkDragContext   *context,
255                       GtkSelectionData *selection_data,
256                       guint             info,
257                       guint             time)
258 {
259   GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
260   guint16 vals[4];
261   GdkRGBA color;
262
263   gtk_color_swatch_get_rgba (swatch, &color);
264
265   vals[0] = color.red * 0xffff;
266   vals[1] = color.green * 0xffff;
267   vals[2] = color.blue * 0xffff;
268   vals[3] = color.alpha * 0xffff;
269
270   gtk_selection_data_set (selection_data,
271                           gdk_atom_intern_static_string ("application/x-color"),
272                           16, (guchar *)vals, 8);
273 }
274
275 static void
276 swatch_drag_data_received (GtkWidget        *widget,
277                            GdkDragContext   *context,
278                            gint              x,
279                            gint              y,
280                            GtkSelectionData *selection_data,
281                            guint             info,
282                            guint             time)
283 {
284   gint length;
285   guint16 *vals;
286   GdkRGBA color;
287
288   length = gtk_selection_data_get_length (selection_data);
289
290   if (length < 0)
291     return;
292
293   /* We accept drops with the wrong format, since the KDE color
294    * chooser incorrectly drops application/x-color with format 8.
295    */
296   if (length != 8)
297     {
298       g_warning ("Received invalid color data\n");
299       return;
300     }
301
302   vals = (guint16 *) gtk_selection_data_get_data (selection_data);
303
304   color.red   = (gdouble)vals[0] / 0xffff;
305   color.green = (gdouble)vals[1] / 0xffff;
306   color.blue  = (gdouble)vals[2] / 0xffff;
307   color.alpha = (gdouble)vals[3] / 0xffff;
308
309   gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (widget), &color);
310 }
311
312 static void
313 swatch_get_preferred_width (GtkWidget *widget,
314                             gint      *min,
315                             gint      *nat)
316 {
317   *min = *nat = 48;
318 }
319
320 static void
321 swatch_get_preferred_height (GtkWidget *widget,
322                              gint      *min,
323                              gint      *nat)
324 {
325   *min = *nat = 32;
326 }
327
328 static gboolean
329 swatch_key_press (GtkWidget   *widget,
330                   GdkEventKey *event)
331 {
332   GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
333
334   if (event->keyval == GDK_KEY_space ||
335       event->keyval == GDK_KEY_Return ||
336       event->keyval == GDK_KEY_ISO_Enter||
337       event->keyval == GDK_KEY_KP_Enter ||
338       event->keyval == GDK_KEY_KP_Space)
339     {
340       if (swatch->priv->has_color && !swatch->priv->selected)
341         gtk_color_swatch_set_selected (swatch, TRUE);
342       else
343         g_signal_emit (swatch, signals[ACTIVATE], 0);
344       return TRUE;
345     }
346
347   if (GTK_WIDGET_CLASS (gtk_color_swatch_parent_class)->key_press_event (widget, event))
348     return TRUE;
349
350   return FALSE;
351 }
352
353 static gboolean
354 swatch_enter_notify (GtkWidget        *widget,
355                      GdkEventCrossing *event)
356 {
357   GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
358   swatch->priv->contains_pointer = TRUE;
359   return FALSE;
360 }
361
362 static gboolean
363 swatch_leave_notify (GtkWidget        *widget,
364                      GdkEventCrossing *event)
365 {
366   GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
367   swatch->priv->contains_pointer = FALSE;
368   return FALSE;
369 }
370
371 static void
372 emit_customize (GtkColorSwatch *swatch)
373 {
374   g_signal_emit (swatch, signals[CUSTOMIZE], 0);
375 }
376
377 static void
378 popup_position_func (GtkMenu   *menu,
379                      gint      *x,
380                      gint      *y,
381                      gboolean  *push_in,
382                      gpointer   user_data)
383 {
384   GtkWidget *widget;
385   GtkRequisition req;
386   gint root_x, root_y;
387   GdkScreen *screen;
388   GdkWindow *window;
389   GdkRectangle monitor;
390   gint monitor_num;
391
392   widget = GTK_WIDGET (user_data);
393   g_return_if_fail (gtk_widget_get_realized (widget));
394   window = gtk_widget_get_window (widget);
395
396   screen = gtk_widget_get_screen (widget);
397   monitor_num = gdk_screen_get_monitor_at_window (screen, window);
398   if (monitor_num < 0)
399     monitor_num = 0;
400   gtk_menu_set_monitor (menu, monitor_num);
401
402   gdk_window_get_origin (window, &root_x, &root_y);
403   gtk_widget_get_preferred_size (GTK_WIDGET (menu), &req, NULL);
404
405   /* Put corner of menu centered on swatch */
406   *x = root_x + gtk_widget_get_allocated_width (widget) / 2;
407   *y = root_y + gtk_widget_get_allocated_height (widget) / 2;
408
409   /* Ensure sanity */
410   gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
411   *x = CLAMP (*x, monitor.x, MAX (monitor.x, monitor.width - req.width));
412   *y = CLAMP (*y, monitor.y, MAX (monitor.y, monitor.height - req.height));
413 }
414
415 static void
416 do_popup (GtkWidget      *swatch,
417           GdkEventButton *event)
418 {
419   GtkWidget *menu;
420   GtkWidget *item;
421
422   menu = gtk_menu_new ();
423   item = gtk_menu_item_new_with_mnemonic (_("_Customize"));
424   gtk_menu_attach_to_widget (GTK_MENU (menu), swatch, NULL);
425
426   g_signal_connect_swapped (item, "activate",
427                             G_CALLBACK (emit_customize), swatch);
428
429   gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
430
431   gtk_widget_show_all (item);
432
433   if (event)
434     gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
435                     NULL, NULL, event->button, event->time);
436   else
437     gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
438                     popup_position_func, swatch,
439                     0, gtk_get_current_event_time ());
440 }
441
442 static gboolean
443 swatch_button_press (GtkWidget      *widget,
444                      GdkEventButton *event)
445 {
446   GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
447
448   gtk_widget_grab_focus (widget);
449
450   if (gdk_event_triggers_context_menu ((GdkEvent *) event) &&
451       swatch->priv->has_color)
452     {
453       do_popup (widget, event);
454       return TRUE;
455     }
456   else if (event->type == GDK_2BUTTON_PRESS &&
457            event->button == GDK_BUTTON_PRIMARY)
458     {
459       g_signal_emit (swatch, signals[ACTIVATE], 0);
460       return TRUE;
461     }
462
463   return FALSE;
464 }
465
466 static gboolean
467 swatch_button_release (GtkWidget      *widget,
468                        GdkEventButton *event)
469 {
470   GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
471
472   if (event->button == GDK_BUTTON_PRIMARY &&
473       swatch->priv->contains_pointer)
474     {
475       if (!swatch->priv->has_color)
476         {
477           g_signal_emit (swatch, signals[ACTIVATE], 0);
478           return TRUE;
479         }
480       else if (!swatch->priv->selected)
481         {
482           gtk_color_swatch_set_selected (swatch, TRUE);
483           return TRUE;
484         }
485     }
486
487   return FALSE;
488 }
489
490 static gboolean
491 swatch_popup_menu (GtkWidget *swatch)
492 {
493   do_popup (swatch, NULL);
494   return TRUE;
495 }
496
497 /* GObject implementation {{{1 */
498
499 static void
500 swatch_get_property (GObject    *object,
501                      guint       prop_id,
502                      GValue     *value,
503                      GParamSpec *pspec)
504 {
505   GtkColorSwatch *swatch = GTK_COLOR_SWATCH (object);
506   GdkRGBA color;
507
508   switch (prop_id)
509     {
510     case PROP_RGBA:
511       gtk_color_swatch_get_rgba (swatch, &color);
512       g_value_set_boxed (value, &color);
513       break;
514     case PROP_SELECTED:
515       g_value_set_boolean (value, swatch->priv->selected);
516       break;
517     default:
518       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
519       break;
520     }
521 }
522
523 static void
524 swatch_set_property (GObject      *object,
525                      guint         prop_id,
526                      const GValue *value,
527                      GParamSpec   *pspec)
528 {
529   GtkColorSwatch *swatch = GTK_COLOR_SWATCH (object);
530
531   switch (prop_id)
532     {
533     case PROP_RGBA:
534       gtk_color_swatch_set_rgba (swatch, g_value_get_boxed (value));
535       break;
536     case PROP_SELECTED:
537       gtk_color_swatch_set_selected (swatch, g_value_get_boolean (value));
538       break;
539     default:
540       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
541       break;
542     }
543 }
544
545 static void
546 swatch_finalize (GObject *object)
547 {
548   GtkColorSwatch *swatch = GTK_COLOR_SWATCH (object);
549
550   g_free (swatch->priv->icon);
551
552   G_OBJECT_CLASS (gtk_color_swatch_parent_class)->finalize (object);
553 }
554
555 static void
556 gtk_color_swatch_class_init (GtkColorSwatchClass *class)
557 {
558   GtkWidgetClass *widget_class = (GtkWidgetClass *)class;
559   GObjectClass *object_class = (GObjectClass *)class;
560
561   object_class->get_property = swatch_get_property;
562   object_class->set_property = swatch_set_property;
563   object_class->finalize = swatch_finalize;
564
565   widget_class->get_preferred_width = swatch_get_preferred_width;
566   widget_class->get_preferred_height = swatch_get_preferred_height;
567   widget_class->draw = swatch_draw;
568   widget_class->drag_begin = swatch_drag_begin;
569   widget_class->drag_data_get = swatch_drag_data_get;
570   widget_class->drag_data_received = swatch_drag_data_received;
571   widget_class->key_press_event = swatch_key_press;
572   widget_class->popup_menu = swatch_popup_menu;
573   widget_class->button_press_event = swatch_button_press;
574   widget_class->button_release_event = swatch_button_release;
575   widget_class->enter_notify_event = swatch_enter_notify;
576   widget_class->leave_notify_event = swatch_leave_notify;
577
578   signals[ACTIVATE] =
579     g_signal_new ("activate",
580                   GTK_TYPE_COLOR_SWATCH,
581                   G_SIGNAL_RUN_FIRST,
582                   G_STRUCT_OFFSET (GtkColorSwatchClass, activate),
583                   NULL, NULL, NULL, G_TYPE_NONE, 0);
584
585   signals[CUSTOMIZE] =
586     g_signal_new ("customize",
587                   GTK_TYPE_COLOR_SWATCH,
588                   G_SIGNAL_RUN_FIRST,
589                   G_STRUCT_OFFSET (GtkColorSwatchClass, customize),
590                   NULL, NULL, NULL, G_TYPE_NONE, 0);
591
592   g_object_class_install_property (object_class, PROP_RGBA,
593       g_param_spec_boxed ("rgba", P_("RGBA Color"), P_("Color as RGBA"),
594                           GDK_TYPE_RGBA, GTK_PARAM_READWRITE));
595
596   g_object_class_install_property (object_class, PROP_SELECTED,
597       g_param_spec_boolean ("selected", P_("Selected"), P_("Selected"),
598                             FALSE, GTK_PARAM_READWRITE));
599
600   g_type_class_add_private (object_class, sizeof (GtkColorSwatchPrivate));
601 }
602
603 /* Public API {{{1 */
604
605 GtkWidget *
606 gtk_color_swatch_new (void)
607 {
608   return (GtkWidget *) g_object_new (GTK_TYPE_COLOR_SWATCH, NULL);
609 }
610
611 static const GtkTargetEntry dnd_targets[] = {
612   { "application/x-color", 0 }
613 };
614
615 void
616 gtk_color_swatch_set_rgba (GtkColorSwatch *swatch,
617                            const GdkRGBA  *color)
618 {
619   GtkStyleContext *context;
620
621   context = gtk_widget_get_style_context (GTK_WIDGET (swatch));
622
623   if (!swatch->priv->has_color)
624     {
625       gtk_drag_source_set (GTK_WIDGET (swatch),
626                            GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
627                            dnd_targets, G_N_ELEMENTS (dnd_targets),
628                            GDK_ACTION_COPY | GDK_ACTION_MOVE);
629     }
630   else
631     {
632       gtk_style_context_remove_class (context, "color-light");
633       gtk_style_context_remove_class (context, "color-dark");
634     }
635
636   swatch->priv->has_color = TRUE;
637   swatch->priv->color = *color;
638
639   if (INTENSITY (swatch->priv->color.red, swatch->priv->color.green, swatch->priv->color.blue) > 0.5)
640     gtk_style_context_add_class (context, "color-light");
641   else
642     gtk_style_context_add_class (context, "color-dark");
643
644   gtk_widget_queue_draw (GTK_WIDGET (swatch));
645   g_object_notify (G_OBJECT (swatch), "rgba");
646 }
647
648 gboolean
649 gtk_color_swatch_get_rgba (GtkColorSwatch *swatch,
650                            GdkRGBA        *color)
651 {
652   if (swatch->priv->has_color)
653     {
654       color->red = swatch->priv->color.red;
655       color->green = swatch->priv->color.green;
656       color->blue = swatch->priv->color.blue;
657       color->alpha = swatch->priv->color.alpha;
658       return TRUE;
659     }
660   else
661     {
662       color->red = 1.0;
663       color->green = 1.0;
664       color->blue = 1.0;
665       color->alpha = 1.0;
666       return FALSE;
667     }
668 }
669
670 void
671 gtk_color_swatch_set_corner_radii (GtkColorSwatch *swatch,
672                                    gdouble         top_left,
673                                    gdouble         top_right,
674                                    gdouble         bottom_right,
675                                    gdouble         bottom_left)
676 {
677   swatch->priv->radius[0] = top_left;
678   swatch->priv->radius[1] = top_right;
679   swatch->priv->radius[2] = bottom_right;
680   swatch->priv->radius[3] = bottom_left;
681
682   gtk_widget_queue_draw (GTK_WIDGET (swatch));
683 }
684
685 void
686 gtk_color_swatch_set_selected (GtkColorSwatch *swatch,
687                                gboolean        selected)
688 {
689   if (swatch->priv->selected != selected)
690     {
691       swatch->priv->selected = selected;
692       gtk_widget_queue_draw (GTK_WIDGET (swatch));
693       g_object_notify (G_OBJECT (swatch), "selected");
694     }
695 }
696
697 void
698 gtk_color_swatch_set_icon (GtkColorSwatch *swatch,
699                            const gchar    *icon)
700 {
701   swatch->priv->icon = g_strdup (icon);
702   gtk_widget_queue_draw (GTK_WIDGET (swatch));
703 }
704
705 void
706 gtk_color_swatch_set_can_drop (GtkColorSwatch *swatch,
707                                gboolean        can_drop)
708 {
709   if (!swatch->priv->can_drop)
710     gtk_drag_dest_set (GTK_WIDGET (swatch),
711                        GTK_DEST_DEFAULT_HIGHLIGHT |
712                        GTK_DEST_DEFAULT_MOTION |
713                        GTK_DEST_DEFAULT_DROP,
714                        dnd_targets, G_N_ELEMENTS (dnd_targets),
715                        GDK_ACTION_COPY);
716
717   swatch->priv->can_drop = can_drop;
718 }
719
720 void
721 gtk_color_swatch_set_use_alpha (GtkColorSwatch *swatch,
722                                 gboolean        use_alpha)
723 {
724   swatch->priv->use_alpha = use_alpha;
725   gtk_widget_queue_draw (GTK_WIDGET (swatch));
726 }
727
728 /* vim:set foldmethod=marker: */