]> Pileus Git - ~andy/gtk/blob - gtk/gtkcolorswatch.c
Remove unused variables
[~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 "gtkcolorswatchprivate.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   gdouble width, height;
112   GtkStyleContext *context;
113   GtkStateFlags state;
114   GtkIconTheme *theme;
115   GtkIconInfo *icon_info = NULL;
116
117   theme = gtk_icon_theme_get_default ();
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       icon_info = gtk_icon_theme_lookup_icon (theme, swatch->priv->icon, 16,
186                                               GTK_ICON_LOOKUP_GENERIC_FALLBACK
187                                               | GTK_ICON_LOOKUP_USE_BUILTIN);
188     }
189   else if (swatch->priv->selected)
190     {
191       GdkRGBA bg, border;
192       GtkBorder border_width;
193       GIcon *gicon;
194
195       gtk_style_context_add_class (context, "color-active-badge");
196       gtk_style_context_get_background_color (context, state, &bg);
197       gtk_style_context_get_border_color (context, state, &border);
198       gtk_style_context_get_border (context, state, &border_width);
199
200       cairo_new_sub_path (cr);
201       cairo_arc (cr, width / 2, height / 2, 10, 0, 2 * G_PI);
202       cairo_close_path (cr);
203       gdk_cairo_set_source_rgba (cr, &bg);
204       cairo_fill_preserve (cr);
205
206       gdk_cairo_set_source_rgba (cr, &border);
207       cairo_set_line_width (cr, border_width.left);
208       cairo_stroke (cr);
209
210       gicon = g_themed_icon_new ("object-select-symbolic");
211       /* fallback for themes that don't have object-select-symbolic */
212       g_themed_icon_append_name (G_THEMED_ICON (gicon), "gtk-apply");
213
214       icon_info = gtk_icon_theme_lookup_by_gicon (theme, gicon, 16,
215                                                   GTK_ICON_LOOKUP_GENERIC_FALLBACK
216                                                   | GTK_ICON_LOOKUP_USE_BUILTIN);
217       g_object_unref (gicon);
218     }
219
220   if (icon_info != NULL)
221     {
222       GdkPixbuf *pixbuf;
223
224       pixbuf = gtk_icon_info_load_symbolic_for_context (icon_info, context,
225                                                         NULL, NULL);
226
227       if (pixbuf != NULL)
228         {
229           gtk_render_icon (context, cr, pixbuf,
230                            (width - gdk_pixbuf_get_width (pixbuf)) / 2,
231                            (height - gdk_pixbuf_get_height (pixbuf)) / 2);
232           g_object_unref (pixbuf);
233         }
234
235       gtk_icon_info_free (icon_info);
236     }
237
238   cairo_restore (cr);
239   gtk_style_context_restore (context);
240
241   return FALSE;
242 }
243
244 static void
245 drag_set_color_icon (GdkDragContext *context,
246                      const GdkRGBA  *color)
247 {
248   cairo_surface_t *surface;
249   cairo_t *cr;
250
251   surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 48, 32);
252   cr = cairo_create (surface);
253   gdk_cairo_set_source_rgba (cr, color);
254   cairo_paint (cr);
255
256   cairo_surface_set_device_offset (surface, -4, -4);
257   gtk_drag_set_icon_surface (context, surface);
258
259   cairo_destroy (cr);
260   cairo_surface_destroy (surface);
261 }
262
263 static void
264 swatch_drag_begin (GtkWidget      *widget,
265                    GdkDragContext *context)
266 {
267   GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
268   GdkRGBA color;
269
270   gtk_color_swatch_get_rgba (swatch, &color);
271   drag_set_color_icon (context, &color);
272 }
273
274 static void
275 swatch_drag_data_get (GtkWidget        *widget,
276                       GdkDragContext   *context,
277                       GtkSelectionData *selection_data,
278                       guint             info,
279                       guint             time)
280 {
281   GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
282   guint16 vals[4];
283   GdkRGBA color;
284
285   gtk_color_swatch_get_rgba (swatch, &color);
286
287   vals[0] = color.red * 0xffff;
288   vals[1] = color.green * 0xffff;
289   vals[2] = color.blue * 0xffff;
290   vals[3] = color.alpha * 0xffff;
291
292   gtk_selection_data_set (selection_data,
293                           gdk_atom_intern_static_string ("application/x-color"),
294                           16, (guchar *)vals, 8);
295 }
296
297 static void
298 swatch_drag_data_received (GtkWidget        *widget,
299                            GdkDragContext   *context,
300                            gint              x,
301                            gint              y,
302                            GtkSelectionData *selection_data,
303                            guint             info,
304                            guint             time)
305 {
306   gint length;
307   guint16 *vals;
308   GdkRGBA color;
309
310   length = gtk_selection_data_get_length (selection_data);
311
312   if (length < 0)
313     return;
314
315   /* We accept drops with the wrong format, since the KDE color
316    * chooser incorrectly drops application/x-color with format 8.
317    */
318   if (length != 8)
319     {
320       g_warning ("Received invalid color data\n");
321       return;
322     }
323
324   vals = (guint16 *) gtk_selection_data_get_data (selection_data);
325
326   color.red   = (gdouble)vals[0] / 0xffff;
327   color.green = (gdouble)vals[1] / 0xffff;
328   color.blue  = (gdouble)vals[2] / 0xffff;
329   color.alpha = (gdouble)vals[3] / 0xffff;
330
331   gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (widget), &color);
332 }
333
334 static void
335 swatch_get_preferred_width (GtkWidget *widget,
336                             gint      *min,
337                             gint      *nat)
338 {
339   *min = *nat = 48;
340 }
341
342 static void
343 swatch_get_preferred_height (GtkWidget *widget,
344                              gint      *min,
345                              gint      *nat)
346 {
347   *min = *nat = 32;
348 }
349
350 static gboolean
351 swatch_key_press (GtkWidget   *widget,
352                   GdkEventKey *event)
353 {
354   GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
355
356   if (event->keyval == GDK_KEY_space ||
357       event->keyval == GDK_KEY_Return ||
358       event->keyval == GDK_KEY_ISO_Enter||
359       event->keyval == GDK_KEY_KP_Enter ||
360       event->keyval == GDK_KEY_KP_Space)
361     {
362       if (swatch->priv->has_color && !swatch->priv->selected)
363         gtk_color_swatch_set_selected (swatch, TRUE);
364       else
365         g_signal_emit (swatch, signals[ACTIVATE], 0);
366       return TRUE;
367     }
368
369   if (GTK_WIDGET_CLASS (gtk_color_swatch_parent_class)->key_press_event (widget, event))
370     return TRUE;
371
372   return FALSE;
373 }
374
375 static gboolean
376 swatch_enter_notify (GtkWidget        *widget,
377                      GdkEventCrossing *event)
378 {
379   GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
380   swatch->priv->contains_pointer = TRUE;
381   return FALSE;
382 }
383
384 static gboolean
385 swatch_leave_notify (GtkWidget        *widget,
386                      GdkEventCrossing *event)
387 {
388   GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
389   swatch->priv->contains_pointer = FALSE;
390   return FALSE;
391 }
392
393 static void
394 emit_customize (GtkColorSwatch *swatch)
395 {
396   g_signal_emit (swatch, signals[CUSTOMIZE], 0);
397 }
398
399 static void
400 popup_position_func (GtkMenu   *menu,
401                      gint      *x,
402                      gint      *y,
403                      gboolean  *push_in,
404                      gpointer   user_data)
405 {
406   GtkWidget *widget;
407   GtkRequisition req;
408   gint root_x, root_y;
409   GdkScreen *screen;
410   GdkWindow *window;
411   GdkRectangle monitor;
412   gint monitor_num;
413
414   widget = GTK_WIDGET (user_data);
415   g_return_if_fail (gtk_widget_get_realized (widget));
416   window = gtk_widget_get_window (widget);
417
418   screen = gtk_widget_get_screen (widget);
419   monitor_num = gdk_screen_get_monitor_at_window (screen, window);
420   if (monitor_num < 0)
421     monitor_num = 0;
422   gtk_menu_set_monitor (menu, monitor_num);
423
424   gdk_window_get_origin (window, &root_x, &root_y);
425   gtk_widget_get_preferred_size (GTK_WIDGET (menu), &req, NULL);
426
427   /* Put corner of menu centered on swatch */
428   *x = root_x + gtk_widget_get_allocated_width (widget) / 2;
429   *y = root_y + gtk_widget_get_allocated_height (widget) / 2;
430
431   /* Ensure sanity */
432   gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
433   *x = CLAMP (*x, monitor.x, MAX (monitor.x, monitor.width - req.width));
434   *y = CLAMP (*y, monitor.y, MAX (monitor.y, monitor.height - req.height));
435 }
436
437 static void
438 do_popup (GtkWidget      *swatch,
439           GdkEventButton *event)
440 {
441   GtkWidget *menu;
442   GtkWidget *item;
443
444   menu = gtk_menu_new ();
445   item = gtk_menu_item_new_with_mnemonic (_("_Customize"));
446   gtk_menu_attach_to_widget (GTK_MENU (menu), swatch, NULL);
447
448   g_signal_connect_swapped (item, "activate",
449                             G_CALLBACK (emit_customize), swatch);
450
451   gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
452
453   gtk_widget_show_all (item);
454
455   if (event)
456     gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
457                     NULL, NULL, event->button, event->time);
458   else
459     gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
460                     popup_position_func, swatch,
461                     0, gtk_get_current_event_time ());
462 }
463
464 static gboolean
465 swatch_button_press (GtkWidget      *widget,
466                      GdkEventButton *event)
467 {
468   GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
469
470   gtk_widget_grab_focus (widget);
471
472   if (gdk_event_triggers_context_menu ((GdkEvent *) event) &&
473       swatch->priv->has_color)
474     {
475       do_popup (widget, event);
476       return TRUE;
477     }
478   else if (event->type == GDK_2BUTTON_PRESS &&
479            event->button == GDK_BUTTON_PRIMARY)
480     {
481       g_signal_emit (swatch, signals[ACTIVATE], 0);
482       return TRUE;
483     }
484
485   return FALSE;
486 }
487
488 static gboolean
489 swatch_button_release (GtkWidget      *widget,
490                        GdkEventButton *event)
491 {
492   GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
493
494   if (event->button == GDK_BUTTON_PRIMARY &&
495       swatch->priv->contains_pointer)
496     {
497       if (!swatch->priv->has_color)
498         {
499           g_signal_emit (swatch, signals[ACTIVATE], 0);
500           return TRUE;
501         }
502       else if (!swatch->priv->selected)
503         {
504           gtk_color_swatch_set_selected (swatch, TRUE);
505           return TRUE;
506         }
507     }
508
509   return FALSE;
510 }
511
512 static gboolean
513 swatch_popup_menu (GtkWidget *swatch)
514 {
515   do_popup (swatch, NULL);
516   return TRUE;
517 }
518
519 /* GObject implementation {{{1 */
520
521 static void
522 swatch_get_property (GObject    *object,
523                      guint       prop_id,
524                      GValue     *value,
525                      GParamSpec *pspec)
526 {
527   GtkColorSwatch *swatch = GTK_COLOR_SWATCH (object);
528   GdkRGBA color;
529
530   switch (prop_id)
531     {
532     case PROP_RGBA:
533       gtk_color_swatch_get_rgba (swatch, &color);
534       g_value_set_boxed (value, &color);
535       break;
536     case PROP_SELECTED:
537       g_value_set_boolean (value, swatch->priv->selected);
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_set_property (GObject      *object,
547                      guint         prop_id,
548                      const GValue *value,
549                      GParamSpec   *pspec)
550 {
551   GtkColorSwatch *swatch = GTK_COLOR_SWATCH (object);
552
553   switch (prop_id)
554     {
555     case PROP_RGBA:
556       gtk_color_swatch_set_rgba (swatch, g_value_get_boxed (value));
557       break;
558     case PROP_SELECTED:
559       gtk_color_swatch_set_selected (swatch, g_value_get_boolean (value));
560       break;
561     default:
562       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
563       break;
564     }
565 }
566
567 static void
568 swatch_finalize (GObject *object)
569 {
570   GtkColorSwatch *swatch = GTK_COLOR_SWATCH (object);
571
572   g_free (swatch->priv->icon);
573
574   G_OBJECT_CLASS (gtk_color_swatch_parent_class)->finalize (object);
575 }
576
577 static void
578 gtk_color_swatch_class_init (GtkColorSwatchClass *class)
579 {
580   GtkWidgetClass *widget_class = (GtkWidgetClass *)class;
581   GObjectClass *object_class = (GObjectClass *)class;
582
583   object_class->get_property = swatch_get_property;
584   object_class->set_property = swatch_set_property;
585   object_class->finalize = swatch_finalize;
586
587   widget_class->get_preferred_width = swatch_get_preferred_width;
588   widget_class->get_preferred_height = swatch_get_preferred_height;
589   widget_class->draw = swatch_draw;
590   widget_class->drag_begin = swatch_drag_begin;
591   widget_class->drag_data_get = swatch_drag_data_get;
592   widget_class->drag_data_received = swatch_drag_data_received;
593   widget_class->key_press_event = swatch_key_press;
594   widget_class->popup_menu = swatch_popup_menu;
595   widget_class->button_press_event = swatch_button_press;
596   widget_class->button_release_event = swatch_button_release;
597   widget_class->enter_notify_event = swatch_enter_notify;
598   widget_class->leave_notify_event = swatch_leave_notify;
599
600   signals[ACTIVATE] =
601     g_signal_new ("activate",
602                   GTK_TYPE_COLOR_SWATCH,
603                   G_SIGNAL_RUN_FIRST,
604                   G_STRUCT_OFFSET (GtkColorSwatchClass, activate),
605                   NULL, NULL, NULL, G_TYPE_NONE, 0);
606
607   signals[CUSTOMIZE] =
608     g_signal_new ("customize",
609                   GTK_TYPE_COLOR_SWATCH,
610                   G_SIGNAL_RUN_FIRST,
611                   G_STRUCT_OFFSET (GtkColorSwatchClass, customize),
612                   NULL, NULL, NULL, G_TYPE_NONE, 0);
613
614   g_object_class_install_property (object_class, PROP_RGBA,
615       g_param_spec_boxed ("rgba", P_("RGBA Color"), P_("Color as RGBA"),
616                           GDK_TYPE_RGBA, GTK_PARAM_READWRITE));
617
618   g_object_class_install_property (object_class, PROP_SELECTED,
619       g_param_spec_boolean ("selected", P_("Selected"), P_("Selected"),
620                             FALSE, GTK_PARAM_READWRITE));
621
622   g_type_class_add_private (object_class, sizeof (GtkColorSwatchPrivate));
623 }
624
625 /* Public API {{{1 */
626
627 GtkWidget *
628 gtk_color_swatch_new (void)
629 {
630   return (GtkWidget *) g_object_new (GTK_TYPE_COLOR_SWATCH, NULL);
631 }
632
633 static const GtkTargetEntry dnd_targets[] = {
634   { "application/x-color", 0 }
635 };
636
637 void
638 gtk_color_swatch_set_rgba (GtkColorSwatch *swatch,
639                            const GdkRGBA  *color)
640 {
641   GtkStyleContext *context;
642
643   context = gtk_widget_get_style_context (GTK_WIDGET (swatch));
644
645   if (!swatch->priv->has_color)
646     {
647       gtk_drag_source_set (GTK_WIDGET (swatch),
648                            GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
649                            dnd_targets, G_N_ELEMENTS (dnd_targets),
650                            GDK_ACTION_COPY | GDK_ACTION_MOVE);
651     }
652   else
653     {
654       gtk_style_context_remove_class (context, "color-light");
655       gtk_style_context_remove_class (context, "color-dark");
656     }
657
658   swatch->priv->has_color = TRUE;
659   swatch->priv->color = *color;
660
661   if (INTENSITY (swatch->priv->color.red, swatch->priv->color.green, swatch->priv->color.blue) > 0.5)
662     gtk_style_context_add_class (context, "color-light");
663   else
664     gtk_style_context_add_class (context, "color-dark");
665
666   gtk_widget_queue_draw (GTK_WIDGET (swatch));
667   g_object_notify (G_OBJECT (swatch), "rgba");
668 }
669
670 gboolean
671 gtk_color_swatch_get_rgba (GtkColorSwatch *swatch,
672                            GdkRGBA        *color)
673 {
674   if (swatch->priv->has_color)
675     {
676       color->red = swatch->priv->color.red;
677       color->green = swatch->priv->color.green;
678       color->blue = swatch->priv->color.blue;
679       color->alpha = swatch->priv->color.alpha;
680       return TRUE;
681     }
682   else
683     {
684       color->red = 1.0;
685       color->green = 1.0;
686       color->blue = 1.0;
687       color->alpha = 1.0;
688       return FALSE;
689     }
690 }
691
692 void
693 gtk_color_swatch_set_selected (GtkColorSwatch *swatch,
694                                gboolean        selected)
695 {
696   if (swatch->priv->selected != selected)
697     {
698       swatch->priv->selected = selected;
699       gtk_widget_queue_draw (GTK_WIDGET (swatch));
700       g_object_notify (G_OBJECT (swatch), "selected");
701     }
702 }
703
704 void
705 gtk_color_swatch_set_icon (GtkColorSwatch *swatch,
706                            const gchar    *icon)
707 {
708   swatch->priv->icon = g_strdup (icon);
709   gtk_widget_queue_draw (GTK_WIDGET (swatch));
710 }
711
712 void
713 gtk_color_swatch_set_can_drop (GtkColorSwatch *swatch,
714                                gboolean        can_drop)
715 {
716   if (!swatch->priv->can_drop)
717     gtk_drag_dest_set (GTK_WIDGET (swatch),
718                        GTK_DEST_DEFAULT_HIGHLIGHT |
719                        GTK_DEST_DEFAULT_MOTION |
720                        GTK_DEST_DEFAULT_DROP,
721                        dnd_targets, G_N_ELEMENTS (dnd_targets),
722                        GDK_ACTION_COPY);
723
724   swatch->priv->can_drop = can_drop;
725 }
726
727 void
728 gtk_color_swatch_set_use_alpha (GtkColorSwatch *swatch,
729                                 gboolean        use_alpha)
730 {
731   swatch->priv->use_alpha = use_alpha;
732   gtk_widget_queue_draw (GTK_WIDGET (swatch));
733 }
734
735 /* vim:set foldmethod=marker: */