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