2 * GTK - The GIMP Toolkit
3 * Copyright (C) 1998, 1999 Red Hat, Inc.
6 * This Library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This Library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with the Gnome Library; see the file COPYING.LIB. If not,
18 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
21 /* Color picker button for GNOME
23 * Author: Federico Mena <federico@nuclecu.unam.mx>
25 * Modified by the GTK+ Team and others 2003. See the AUTHORS
26 * file for a list of people on the GTK+ Team. See the ChangeLog
27 * files for a list of changes. These files are distributed with
28 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
33 #include "gtkcolorbutton.h"
34 #include "gdk/gdkkeysyms.h"
35 #include "gdk-pixbuf/gdk-pixbuf.h"
36 #include "gtkbutton.h"
38 #include "gtkalignment.h"
39 #include "gtkcolorsel.h"
40 #include "gtkcolorseldialog.h"
42 #include "gtkdrawingarea.h"
44 #include "gtkmarshalers.h"
45 #include "gtkprivate.h"
48 /* Size of checks and gray levels for alpha compositing checkerboard */
50 #define CHECK_DARK 21845 /* 65535 / 3 */
51 #define CHECK_LIGHT 43690
54 struct _GtkColorButtonPrivate
56 GdkPixbuf *pixbuf; /* Pixbuf for rendering sample */
57 GdkGC *gc; /* GC for drawing */
59 GtkWidget *draw_area; /* Widget where we draw the color sample */
60 GtkWidget *cs_dialog; /* Color selection dialog */
62 gchar *title; /* Title for the color selection window */
67 guint use_alpha : 1; /* Use alpha or not */
88 static void gtk_color_button_finalize (GObject *object);
89 static void gtk_color_button_set_property (GObject *object,
93 static void gtk_color_button_get_property (GObject *object,
98 /* gtkwidget signals */
99 static void gtk_color_button_realize (GtkWidget *widget);
100 static void gtk_color_button_unrealize (GtkWidget *widget);
101 static void gtk_color_button_state_changed (GtkWidget *widget,
102 GtkStateType previous_state);
103 static void gtk_color_button_style_set (GtkWidget *widget,
104 GtkStyle *previous_style);
106 /* gtkbutton signals */
107 static void gtk_color_button_clicked (GtkButton *button);
109 /* source side drag signals */
110 static void gtk_color_button_drag_begin (GtkWidget *widget,
111 GdkDragContext *context,
113 static void gtk_color_button_drag_data_get (GtkWidget *widget,
114 GdkDragContext *context,
115 GtkSelectionData *selection_data,
118 GtkColorButton *color_button);
120 /* target side drag signals */
121 static void gtk_color_button_drag_data_received (GtkWidget *widget,
122 GdkDragContext *context,
125 GtkSelectionData *selection_data,
128 GtkColorButton *color_button);
131 static guint color_button_signals[LAST_SIGNAL] = { 0 };
133 static const GtkTargetEntry drop_types[] = { { "application/x-color", 0, 0 } };
135 G_DEFINE_TYPE (GtkColorButton, gtk_color_button, GTK_TYPE_BUTTON)
138 gtk_color_button_class_init (GtkColorButtonClass *klass)
140 GObjectClass *gobject_class;
141 GtkWidgetClass *widget_class;
142 GtkButtonClass *button_class;
144 gobject_class = G_OBJECT_CLASS (klass);
145 widget_class = GTK_WIDGET_CLASS (klass);
146 button_class = GTK_BUTTON_CLASS (klass);
148 gobject_class->get_property = gtk_color_button_get_property;
149 gobject_class->set_property = gtk_color_button_set_property;
150 gobject_class->finalize = gtk_color_button_finalize;
151 widget_class->state_changed = gtk_color_button_state_changed;
152 widget_class->realize = gtk_color_button_realize;
153 widget_class->unrealize = gtk_color_button_unrealize;
154 widget_class->style_set = gtk_color_button_style_set;
155 button_class->clicked = gtk_color_button_clicked;
156 klass->color_set = NULL;
159 * GtkColorButton:use-alpha:
161 * If this property is set to %TRUE, the color swatch on the button is rendered against a
162 * checkerboard background to show its opacity and the opacity slider is displayed in the
163 * color selection dialog.
167 g_object_class_install_property (gobject_class,
169 g_param_spec_boolean ("use-alpha", P_("Use alpha"),
170 P_("Whether or not to give the color an alpha value"),
172 GTK_PARAM_READWRITE));
175 * GtkColorButton:title:
177 * The title of the color selection dialog
181 g_object_class_install_property (gobject_class,
183 g_param_spec_string ("title",
185 P_("The title of the color selection dialog"),
187 GTK_PARAM_READWRITE));
190 * GtkColorButton:color:
192 * The selected color.
196 g_object_class_install_property (gobject_class,
198 g_param_spec_boxed ("color",
200 P_("The selected color"),
202 GTK_PARAM_READWRITE));
205 * GtkColorButton:alpha:
207 * The selected opacity value (0 fully transparent, 65535 fully opaque).
211 g_object_class_install_property (gobject_class,
213 g_param_spec_uint ("alpha",
215 P_("The selected opacity value (0 fully transparent, 65535 fully opaque)"),
217 GTK_PARAM_READWRITE));
220 * GtkColorButton::color-set:
221 * @widget: the object which received the signal.
223 * The ::color-set signal is emitted when the user selects a color.
224 * When handling this signal, use gtk_color_button_get_color() and
225 * gtk_color_button_get_alpha() to find out which color was just selected.
227 * Note that this signal is only emitted when the <emphasis>user</emphasis>
228 * changes the color. If you need to react to programmatic color changes
229 * as well, use the notify::color signal.
233 color_button_signals[COLOR_SET] = g_signal_new (I_("color-set"),
234 G_TYPE_FROM_CLASS (gobject_class),
236 G_STRUCT_OFFSET (GtkColorButtonClass, color_set),
238 _gtk_marshal_VOID__VOID,
241 g_type_class_add_private (gobject_class, sizeof (GtkColorButtonPrivate));
245 render (GtkColorButton *color_button)
247 gint dark_r, dark_g, dark_b;
248 gint light_r, light_g, light_b;
249 gint i, j, rowstride;
253 guint8 insensitive_r = 0;
254 guint8 insensitive_g = 0;
255 guint8 insensitive_b = 0;
257 width = color_button->priv->draw_area->allocation.width;
258 height = color_button->priv->draw_area->allocation.height;
259 if (color_button->priv->pixbuf == NULL ||
260 gdk_pixbuf_get_width (color_button->priv->pixbuf) != width ||
261 gdk_pixbuf_get_height (color_button->priv->pixbuf) != height)
263 if (color_button->priv->pixbuf != NULL)
264 g_object_unref (color_button->priv->pixbuf);
265 color_button->priv->pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, width, height);
269 /* Compute dark and light check colors */
271 insensitive_r = GTK_WIDGET(color_button)->style->bg[GTK_STATE_INSENSITIVE].red >> 8;
272 insensitive_g = GTK_WIDGET(color_button)->style->bg[GTK_STATE_INSENSITIVE].green >> 8;
273 insensitive_b = GTK_WIDGET(color_button)->style->bg[GTK_STATE_INSENSITIVE].blue >> 8;
275 if (color_button->priv->use_alpha)
277 dark_r = ((CHECK_DARK << 16) + (color_button->priv->color.red - CHECK_DARK) * color_button->priv->alpha) >> 24;
278 dark_g = ((CHECK_DARK << 16) + (color_button->priv->color.green - CHECK_DARK) * color_button->priv->alpha) >> 24;
279 dark_b = ((CHECK_DARK << 16) + (color_button->priv->color.blue - CHECK_DARK) * color_button->priv->alpha) >> 24;
281 light_r = ((CHECK_LIGHT << 16) + (color_button->priv->color.red - CHECK_LIGHT) * color_button->priv->alpha) >> 24;
282 light_g = ((CHECK_LIGHT << 16) + (color_button->priv->color.green - CHECK_LIGHT) * color_button->priv->alpha) >> 24;
283 light_b = ((CHECK_LIGHT << 16) + (color_button->priv->color.blue - CHECK_LIGHT) * color_button->priv->alpha) >> 24;
287 dark_r = light_r = color_button->priv->color.red >> 8;
288 dark_g = light_g = color_button->priv->color.green >> 8;
289 dark_b = light_b = color_button->priv->color.blue >> 8;
292 /* Fill image buffer */
293 pixels = gdk_pixbuf_get_pixels (color_button->priv->pixbuf);
294 rowstride = gdk_pixbuf_get_rowstride (color_button->priv->pixbuf);
295 for (j = 0; j < height; j++)
297 if ((j / CHECK_SIZE) & 1)
318 for (i = 0; i < width; i++)
320 if (!gtk_widget_is_sensitive (GTK_WIDGET (color_button)) && (i+j)%2)
322 *(pixels + j * rowstride + i * 3) = insensitive_r;
323 *(pixels + j * rowstride + i * 3 + 1) = insensitive_g;
324 *(pixels + j * rowstride + i * 3 + 2) = insensitive_b;
326 else if ((i / CHECK_SIZE) & 1)
328 *(pixels + j * rowstride + i * 3) = c1[0];
329 *(pixels + j * rowstride + i * 3 + 1) = c1[1];
330 *(pixels + j * rowstride + i * 3 + 2) = c1[2];
334 *(pixels + j * rowstride + i * 3) = c2[0];
335 *(pixels + j * rowstride + i * 3 + 1) = c2[1];
336 *(pixels + j * rowstride + i * 3 + 2) = c2[2];
342 /* Handle exposure events for the color picker's drawing area */
344 expose_event (GtkWidget *widget,
345 GdkEventExpose *event,
348 GtkColorButton *color_button = GTK_COLOR_BUTTON (data);
350 gint width = color_button->priv->draw_area->allocation.width;
351 gint height = color_button->priv->draw_area->allocation.height;
353 if (color_button->priv->pixbuf == NULL ||
354 width != gdk_pixbuf_get_width (color_button->priv->pixbuf) ||
355 height != gdk_pixbuf_get_height (color_button->priv->pixbuf))
356 render (color_button);
358 gdk_draw_pixbuf (widget->window,
359 color_button->priv->gc,
360 color_button->priv->pixbuf,
361 event->area.x - widget->allocation.x,
362 event->area.y - widget->allocation.y,
368 event->area.x - widget->allocation.x,
369 event->area.y - widget->allocation.y);
374 gtk_color_button_realize (GtkWidget *widget)
376 GtkColorButton *color_button = GTK_COLOR_BUTTON (widget);
378 GTK_WIDGET_CLASS (gtk_color_button_parent_class)->realize (widget);
380 color_button->priv->gc = gdk_gc_new (widget->window);
382 render (color_button);
386 gtk_color_button_unrealize (GtkWidget *widget)
388 GtkColorButton *color_button = GTK_COLOR_BUTTON (widget);
390 g_object_unref (color_button->priv->gc);
391 color_button->priv->gc = NULL;
393 GTK_WIDGET_CLASS (gtk_color_button_parent_class)->unrealize (widget);
397 gtk_color_button_style_set (GtkWidget *widget,
398 GtkStyle *previous_style)
400 GtkColorButton *color_button = GTK_COLOR_BUTTON (widget);
402 GTK_WIDGET_CLASS (gtk_color_button_parent_class)->style_set (widget, previous_style);
404 if (gtk_widget_get_realized (widget))
406 if (color_button->priv->pixbuf != NULL)
407 g_object_unref (color_button->priv->pixbuf);
408 color_button->priv->pixbuf = NULL;
413 gtk_color_button_state_changed (GtkWidget *widget,
414 GtkStateType previous_state)
416 GtkColorButton *color_button = GTK_COLOR_BUTTON (widget);
418 if (widget->state == GTK_STATE_INSENSITIVE || previous_state == GTK_STATE_INSENSITIVE)
420 if (color_button->priv->pixbuf != NULL)
421 g_object_unref (color_button->priv->pixbuf);
422 color_button->priv->pixbuf = NULL;
427 gtk_color_button_drag_data_received (GtkWidget *widget,
428 GdkDragContext *context,
431 GtkSelectionData *selection_data,
434 GtkColorButton *color_button)
438 if (selection_data->length < 0)
441 /* We accept drops with the wrong format, since the KDE color
442 * chooser incorrectly drops application/x-color with format 8.
444 if (selection_data->length != 8)
446 g_warning (_("Received invalid color data\n"));
451 dropped = (guint16 *)selection_data->data;
453 color_button->priv->color.red = dropped[0];
454 color_button->priv->color.green = dropped[1];
455 color_button->priv->color.blue = dropped[2];
456 color_button->priv->alpha = dropped[3];
458 if (color_button->priv->pixbuf != NULL)
459 g_object_unref (color_button->priv->pixbuf);
460 color_button->priv->pixbuf = NULL;
462 gtk_widget_queue_draw (color_button->priv->draw_area);
464 g_signal_emit (color_button, color_button_signals[COLOR_SET], 0);
466 g_object_freeze_notify (G_OBJECT (color_button));
467 g_object_notify (G_OBJECT (color_button), "color");
468 g_object_notify (G_OBJECT (color_button), "alpha");
469 g_object_thaw_notify (G_OBJECT (color_button));
473 set_color_icon (GdkDragContext *context,
479 pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE,
482 pixel = ((color->red & 0xff00) << 16) |
483 ((color->green & 0xff00) << 8) |
484 (color->blue & 0xff00);
486 gdk_pixbuf_fill (pixbuf, pixel);
488 gtk_drag_set_icon_pixbuf (context, pixbuf, -2, -2);
489 g_object_unref (pixbuf);
493 gtk_color_button_drag_begin (GtkWidget *widget,
494 GdkDragContext *context,
497 GtkColorButton *color_button = data;
499 set_color_icon (context, &color_button->priv->color);
503 gtk_color_button_drag_data_get (GtkWidget *widget,
504 GdkDragContext *context,
505 GtkSelectionData *selection_data,
508 GtkColorButton *color_button)
512 dropped[0] = color_button->priv->color.red;
513 dropped[1] = color_button->priv->color.green;
514 dropped[2] = color_button->priv->color.blue;
515 dropped[3] = color_button->priv->alpha;
517 gtk_selection_data_set (selection_data, selection_data->target,
518 16, (guchar *)dropped, 8);
522 gtk_color_button_init (GtkColorButton *color_button)
524 GtkWidget *alignment;
529 /* Create the widgets */
530 color_button->priv = G_TYPE_INSTANCE_GET_PRIVATE (color_button,
531 GTK_TYPE_COLOR_BUTTON,
532 GtkColorButtonPrivate);
534 gtk_widget_push_composite_child ();
536 alignment = gtk_alignment_new (0.5, 0.5, 0.5, 1.0);
537 gtk_container_set_border_width (GTK_CONTAINER (alignment), 1);
538 gtk_container_add (GTK_CONTAINER (color_button), alignment);
539 gtk_widget_show (alignment);
541 frame = gtk_frame_new (NULL);
542 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_OUT);
543 gtk_container_add (GTK_CONTAINER (alignment), frame);
544 gtk_widget_show (frame);
546 /* Just some widget we can hook to expose-event on */
547 color_button->priv->draw_area = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
549 layout = gtk_widget_create_pango_layout (GTK_WIDGET (color_button), "Black");
550 pango_layout_get_pixel_extents (layout, NULL, &rect);
551 g_object_unref (layout);
553 gtk_widget_set_size_request (color_button->priv->draw_area, rect.width - 2, rect.height - 2);
554 g_signal_connect (color_button->priv->draw_area, "expose-event",
555 G_CALLBACK (expose_event), color_button);
556 gtk_container_add (GTK_CONTAINER (frame), color_button->priv->draw_area);
557 gtk_widget_show (color_button->priv->draw_area);
559 color_button->priv->title = g_strdup (_("Pick a Color")); /* default title */
561 /* Create the buffer for the image so that we can create an image.
562 * Also create the picker's pixmap.
564 color_button->priv->pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, rect.width, rect.height);
566 color_button->priv->gc = NULL;
568 /* Start with opaque black, alpha disabled */
570 color_button->priv->color.red = 0;
571 color_button->priv->color.green = 0;
572 color_button->priv->color.blue = 0;
573 color_button->priv->alpha = 65535;
574 color_button->priv->use_alpha = FALSE;
576 gtk_drag_dest_set (GTK_WIDGET (color_button),
577 GTK_DEST_DEFAULT_MOTION |
578 GTK_DEST_DEFAULT_HIGHLIGHT |
579 GTK_DEST_DEFAULT_DROP,
580 drop_types, 1, GDK_ACTION_COPY);
581 gtk_drag_source_set (GTK_WIDGET(color_button),
582 GDK_BUTTON1_MASK|GDK_BUTTON3_MASK,
585 g_signal_connect (color_button, "drag-begin",
586 G_CALLBACK (gtk_color_button_drag_begin), color_button);
587 g_signal_connect (color_button, "drag-data-received",
588 G_CALLBACK (gtk_color_button_drag_data_received), color_button);
589 g_signal_connect (color_button, "drag-data-get",
590 G_CALLBACK (gtk_color_button_drag_data_get), color_button);
592 gtk_widget_pop_composite_child ();
596 gtk_color_button_finalize (GObject *object)
598 GtkColorButton *color_button = GTK_COLOR_BUTTON (object);
600 if (color_button->priv->cs_dialog != NULL)
601 gtk_widget_destroy (color_button->priv->cs_dialog);
602 color_button->priv->cs_dialog = NULL;
604 if (color_button->priv->pixbuf != NULL)
605 g_object_unref (color_button->priv->pixbuf);
606 color_button->priv->pixbuf = NULL;
608 g_free (color_button->priv->title);
609 color_button->priv->title = NULL;
611 G_OBJECT_CLASS (gtk_color_button_parent_class)->finalize (object);
616 * gtk_color_button_new:
618 * Creates a new color button. This returns a widget in the form of
619 * a small button containing a swatch representing the current selected
620 * color. When the button is clicked, a color-selection dialog will open,
621 * allowing the user to select a color. The swatch will be updated to reflect
622 * the new color when the user finishes.
624 * Returns: a new color button.
629 gtk_color_button_new (void)
631 return g_object_new (GTK_TYPE_COLOR_BUTTON, NULL);
635 * gtk_color_button_new_with_color:
636 * @color: A #GdkColor to set the current color with.
638 * Creates a new color button.
640 * Returns: a new color button.
645 gtk_color_button_new_with_color (const GdkColor *color)
647 return g_object_new (GTK_TYPE_COLOR_BUTTON, "color", color, NULL);
651 dialog_ok_clicked (GtkWidget *widget,
654 GtkColorButton *color_button = GTK_COLOR_BUTTON (data);
655 GtkColorSelection *color_selection;
657 color_selection = GTK_COLOR_SELECTION (GTK_COLOR_SELECTION_DIALOG (color_button->priv->cs_dialog)->colorsel);
659 gtk_color_selection_get_current_color (color_selection, &color_button->priv->color);
660 color_button->priv->alpha = gtk_color_selection_get_current_alpha (color_selection);
662 if (color_button->priv->pixbuf != NULL)
663 g_object_unref (color_button->priv->pixbuf);
664 color_button->priv->pixbuf = NULL;
666 gtk_widget_hide (color_button->priv->cs_dialog);
668 gtk_widget_queue_draw (color_button->priv->draw_area);
670 g_signal_emit (color_button, color_button_signals[COLOR_SET], 0);
672 g_object_freeze_notify (G_OBJECT (color_button));
673 g_object_notify (G_OBJECT (color_button), "color");
674 g_object_notify (G_OBJECT (color_button), "alpha");
675 g_object_thaw_notify (G_OBJECT (color_button));
679 dialog_destroy (GtkWidget *widget,
682 GtkColorButton *color_button = GTK_COLOR_BUTTON (data);
684 color_button->priv->cs_dialog = NULL;
690 dialog_cancel_clicked (GtkWidget *widget,
693 GtkColorButton *color_button = GTK_COLOR_BUTTON (data);
695 gtk_widget_hide (color_button->priv->cs_dialog);
699 gtk_color_button_clicked (GtkButton *button)
701 GtkColorButton *color_button = GTK_COLOR_BUTTON (button);
702 GtkColorSelectionDialog *color_dialog;
704 /* if dialog already exists, make sure it's shown and raised */
705 if (!color_button->priv->cs_dialog)
707 /* Create the dialog and connects its buttons */
710 parent = gtk_widget_get_toplevel (GTK_WIDGET (color_button));
712 color_button->priv->cs_dialog = gtk_color_selection_dialog_new (color_button->priv->title);
714 color_dialog = GTK_COLOR_SELECTION_DIALOG (color_button->priv->cs_dialog);
716 if (gtk_widget_is_toplevel (parent) && GTK_IS_WINDOW (parent))
718 if (GTK_WINDOW (parent) != gtk_window_get_transient_for (GTK_WINDOW (color_dialog)))
719 gtk_window_set_transient_for (GTK_WINDOW (color_dialog), GTK_WINDOW (parent));
721 gtk_window_set_modal (GTK_WINDOW (color_dialog),
722 gtk_window_get_modal (GTK_WINDOW (parent)));
725 g_signal_connect (color_dialog->ok_button, "clicked",
726 G_CALLBACK (dialog_ok_clicked), color_button);
727 g_signal_connect (color_dialog->cancel_button, "clicked",
728 G_CALLBACK (dialog_cancel_clicked), color_button);
729 g_signal_connect (color_dialog, "destroy",
730 G_CALLBACK (dialog_destroy), color_button);
733 color_dialog = GTK_COLOR_SELECTION_DIALOG (color_button->priv->cs_dialog);
735 gtk_color_selection_set_has_opacity_control (GTK_COLOR_SELECTION (color_dialog->colorsel),
736 color_button->priv->use_alpha);
738 gtk_color_selection_set_previous_color (GTK_COLOR_SELECTION (color_dialog->colorsel),
739 &color_button->priv->color);
740 gtk_color_selection_set_previous_alpha (GTK_COLOR_SELECTION (color_dialog->colorsel),
741 color_button->priv->alpha);
743 gtk_color_selection_set_current_color (GTK_COLOR_SELECTION (color_dialog->colorsel),
744 &color_button->priv->color);
745 gtk_color_selection_set_current_alpha (GTK_COLOR_SELECTION (color_dialog->colorsel),
746 color_button->priv->alpha);
748 gtk_window_present (GTK_WINDOW (color_button->priv->cs_dialog));
752 * gtk_color_button_set_color:
753 * @color_button: a #GtkColorButton.
754 * @color: A #GdkColor to set the current color with.
756 * Sets the current color to be @color.
761 gtk_color_button_set_color (GtkColorButton *color_button,
762 const GdkColor *color)
764 g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button));
765 g_return_if_fail (color != NULL);
767 color_button->priv->color.red = color->red;
768 color_button->priv->color.green = color->green;
769 color_button->priv->color.blue = color->blue;
771 if (color_button->priv->pixbuf != NULL)
772 g_object_unref (color_button->priv->pixbuf);
773 color_button->priv->pixbuf = NULL;
775 gtk_widget_queue_draw (color_button->priv->draw_area);
777 g_object_notify (G_OBJECT (color_button), "color");
782 * gtk_color_button_set_alpha:
783 * @color_button: a #GtkColorButton.
784 * @alpha: an integer between 0 and 65535.
786 * Sets the current opacity to be @alpha.
791 gtk_color_button_set_alpha (GtkColorButton *color_button,
794 g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button));
796 color_button->priv->alpha = alpha;
798 if (color_button->priv->pixbuf != NULL)
799 g_object_unref (color_button->priv->pixbuf);
800 color_button->priv->pixbuf = NULL;
802 gtk_widget_queue_draw (color_button->priv->draw_area);
804 g_object_notify (G_OBJECT (color_button), "alpha");
808 * gtk_color_button_get_color:
809 * @color_button: a #GtkColorButton.
810 * @color: a #GdkColor to fill in with the current color.
812 * Sets @color to be the current color in the #GtkColorButton widget.
817 gtk_color_button_get_color (GtkColorButton *color_button,
820 g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button));
822 color->red = color_button->priv->color.red;
823 color->green = color_button->priv->color.green;
824 color->blue = color_button->priv->color.blue;
828 * gtk_color_button_get_alpha:
829 * @color_button: a #GtkColorButton.
831 * Returns the current alpha value.
833 * Return value: an integer between 0 and 65535.
838 gtk_color_button_get_alpha (GtkColorButton *color_button)
840 g_return_val_if_fail (GTK_IS_COLOR_BUTTON (color_button), 0);
842 return color_button->priv->alpha;
846 * gtk_color_button_set_use_alpha:
847 * @color_button: a #GtkColorButton.
848 * @use_alpha: %TRUE if color button should use alpha channel, %FALSE if not.
850 * Sets whether or not the color button should use the alpha channel.
855 gtk_color_button_set_use_alpha (GtkColorButton *color_button,
858 g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button));
860 use_alpha = (use_alpha != FALSE);
862 if (color_button->priv->use_alpha != use_alpha)
864 color_button->priv->use_alpha = use_alpha;
866 render (color_button);
867 gtk_widget_queue_draw (color_button->priv->draw_area);
869 g_object_notify (G_OBJECT (color_button), "use-alpha");
874 * gtk_color_button_get_use_alpha:
875 * @color_button: a #GtkColorButton.
877 * Does the color selection dialog use the alpha channel?
879 * Returns: %TRUE if the color sample uses alpha channel, %FALSE if not.
884 gtk_color_button_get_use_alpha (GtkColorButton *color_button)
886 g_return_val_if_fail (GTK_IS_COLOR_BUTTON (color_button), FALSE);
888 return color_button->priv->use_alpha;
893 * gtk_color_button_set_title:
894 * @color_button: a #GtkColorButton
895 * @title: String containing new window title.
897 * Sets the title for the color selection dialog.
902 gtk_color_button_set_title (GtkColorButton *color_button,
907 g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button));
909 old_title = color_button->priv->title;
910 color_button->priv->title = g_strdup (title);
913 if (color_button->priv->cs_dialog)
914 gtk_window_set_title (GTK_WINDOW (color_button->priv->cs_dialog),
915 color_button->priv->title);
917 g_object_notify (G_OBJECT (color_button), "title");
921 * gtk_color_button_get_title:
922 * @color_button: a #GtkColorButton
924 * Gets the title of the color selection dialog.
926 * Returns: An internal string, do not free the return value
930 G_CONST_RETURN gchar *
931 gtk_color_button_get_title (GtkColorButton *color_button)
933 g_return_val_if_fail (GTK_IS_COLOR_BUTTON (color_button), NULL);
935 return color_button->priv->title;
939 gtk_color_button_set_property (GObject *object,
944 GtkColorButton *color_button = GTK_COLOR_BUTTON (object);
949 gtk_color_button_set_use_alpha (color_button, g_value_get_boolean (value));
952 gtk_color_button_set_title (color_button, g_value_get_string (value));
955 gtk_color_button_set_color (color_button, g_value_get_boxed (value));
958 gtk_color_button_set_alpha (color_button, g_value_get_uint (value));
961 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
967 gtk_color_button_get_property (GObject *object,
972 GtkColorButton *color_button = GTK_COLOR_BUTTON (object);
978 g_value_set_boolean (value, gtk_color_button_get_use_alpha (color_button));
981 g_value_set_string (value, gtk_color_button_get_title (color_button));
984 gtk_color_button_get_color (color_button, &color);
985 g_value_set_boxed (value, &color);
988 g_value_set_uint (value, gtk_color_button_get_alpha (color_button));
991 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);