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"
49 /* Size of checks and gray levels for alpha compositing checkerboard */
51 #define CHECK_DARK 21845 /* 65535 / 3 */
52 #define CHECK_LIGHT 43690
54 #define GTK_COLOR_BUTTON_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_COLOR_BUTTON, GtkColorButtonPrivate))
56 struct _GtkColorButtonPrivate
58 GdkPixbuf *pixbuf; /* Pixbuf for rendering sample */
59 GdkGC *gc; /* GC for drawing */
61 GtkWidget *draw_area; /* Widget where we draw the color sample */
62 GtkWidget *cs_dialog; /* Color selection dialog */
64 gchar *title; /* Title for the color selection window */
69 guint use_alpha : 1; /* Use alpha or not */
90 static void gtk_color_button_finalize (GObject *object);
91 static void gtk_color_button_set_property (GObject *object,
95 static void gtk_color_button_get_property (GObject *object,
100 /* gtkwidget signals */
101 static void gtk_color_button_realize (GtkWidget *widget);
102 static void gtk_color_button_unrealize (GtkWidget *widget);
103 static void gtk_color_button_state_changed (GtkWidget *widget,
104 GtkStateType previous_state);
105 static void gtk_color_button_style_set (GtkWidget *widget,
106 GtkStyle *previous_style);
108 /* gtkbutton signals */
109 static void gtk_color_button_clicked (GtkButton *button);
111 /* source side drag signals */
112 static void gtk_color_button_drag_begin (GtkWidget *widget,
113 GdkDragContext *context,
115 static void gtk_color_button_drag_data_get (GtkWidget *widget,
116 GdkDragContext *context,
117 GtkSelectionData *selection_data,
120 GtkColorButton *color_button);
122 /* target side drag signals */
123 static void gtk_color_button_drag_data_received (GtkWidget *widget,
124 GdkDragContext *context,
127 GtkSelectionData *selection_data,
130 GtkColorButton *color_button);
133 static guint color_button_signals[LAST_SIGNAL] = { 0 };
135 static const GtkTargetEntry drop_types[] = { { "application/x-color", 0, 0 } };
137 G_DEFINE_TYPE (GtkColorButton, gtk_color_button, GTK_TYPE_BUTTON)
140 gtk_color_button_class_init (GtkColorButtonClass *klass)
142 GObjectClass *gobject_class;
143 GtkWidgetClass *widget_class;
144 GtkButtonClass *button_class;
146 gobject_class = G_OBJECT_CLASS (klass);
147 widget_class = GTK_WIDGET_CLASS (klass);
148 button_class = GTK_BUTTON_CLASS (klass);
150 gobject_class->get_property = gtk_color_button_get_property;
151 gobject_class->set_property = gtk_color_button_set_property;
152 gobject_class->finalize = gtk_color_button_finalize;
153 widget_class->state_changed = gtk_color_button_state_changed;
154 widget_class->realize = gtk_color_button_realize;
155 widget_class->unrealize = gtk_color_button_unrealize;
156 widget_class->style_set = gtk_color_button_style_set;
157 button_class->clicked = gtk_color_button_clicked;
158 klass->color_set = NULL;
161 * GtkColorButton:use-alpha:
163 * If this property is set to %TRUE, the color swatch on the button is rendered against a
164 * checkerboard background to show its opacity and the opacity slider is displayed in the
165 * color selection dialog.
169 g_object_class_install_property (gobject_class,
171 g_param_spec_boolean ("use-alpha", P_("Use alpha"),
172 P_("Whether or not to give the color an alpha value"),
174 GTK_PARAM_READWRITE));
177 * GtkColorButton:title:
179 * The title of the color selection dialog
183 g_object_class_install_property (gobject_class,
185 g_param_spec_string ("title",
187 P_("The title of the color selection dialog"),
189 GTK_PARAM_READWRITE));
192 * GtkColorButton:color:
194 * The selected color.
198 g_object_class_install_property (gobject_class,
200 g_param_spec_boxed ("color",
202 P_("The selected color"),
204 GTK_PARAM_READWRITE));
207 * GtkColorButton:alpha:
209 * The selected opacity value (0 fully transparent, 65535 fully opaque).
213 g_object_class_install_property (gobject_class,
215 g_param_spec_uint ("alpha",
217 P_("The selected opacity value (0 fully transparent, 65535 fully opaque)"),
219 GTK_PARAM_READWRITE));
222 * GtkColorButton::color-set:
223 * @widget: the object which received the signal.
225 * The ::color-set signal is emitted when the user selects a color.
226 * When handling this signal, use gtk_color_button_get_color() and
227 * gtk_color_button_get_alpha() to find out which color was just selected.
229 * Note that this signal is only emitted when the <emphasis>user</emphasis>
230 * changes the color. If you need to react to programmatic color changes
231 * as well, use the notify::color signal.
235 color_button_signals[COLOR_SET] = g_signal_new (I_("color-set"),
236 G_TYPE_FROM_CLASS (gobject_class),
238 G_STRUCT_OFFSET (GtkColorButtonClass, color_set),
240 _gtk_marshal_VOID__VOID,
243 g_type_class_add_private (gobject_class, sizeof (GtkColorButtonPrivate));
247 render (GtkColorButton *color_button)
249 gint dark_r, dark_g, dark_b;
250 gint light_r, light_g, light_b;
251 gint i, j, rowstride;
255 guint8 insensitive_r = 0;
256 guint8 insensitive_g = 0;
257 guint8 insensitive_b = 0;
259 width = color_button->priv->draw_area->allocation.width;
260 height = color_button->priv->draw_area->allocation.height;
261 if (color_button->priv->pixbuf == NULL ||
262 gdk_pixbuf_get_width (color_button->priv->pixbuf) != width ||
263 gdk_pixbuf_get_height (color_button->priv->pixbuf) != height)
265 if (color_button->priv->pixbuf != NULL)
266 g_object_unref (color_button->priv->pixbuf);
267 color_button->priv->pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, width, height);
271 /* Compute dark and light check colors */
273 insensitive_r = GTK_WIDGET(color_button)->style->bg[GTK_STATE_INSENSITIVE].red >> 8;
274 insensitive_g = GTK_WIDGET(color_button)->style->bg[GTK_STATE_INSENSITIVE].green >> 8;
275 insensitive_b = GTK_WIDGET(color_button)->style->bg[GTK_STATE_INSENSITIVE].blue >> 8;
277 if (color_button->priv->use_alpha)
279 dark_r = ((CHECK_DARK << 16) + (color_button->priv->color.red - CHECK_DARK) * color_button->priv->alpha) >> 24;
280 dark_g = ((CHECK_DARK << 16) + (color_button->priv->color.green - CHECK_DARK) * color_button->priv->alpha) >> 24;
281 dark_b = ((CHECK_DARK << 16) + (color_button->priv->color.blue - CHECK_DARK) * color_button->priv->alpha) >> 24;
283 light_r = ((CHECK_LIGHT << 16) + (color_button->priv->color.red - CHECK_LIGHT) * color_button->priv->alpha) >> 24;
284 light_g = ((CHECK_LIGHT << 16) + (color_button->priv->color.green - CHECK_LIGHT) * color_button->priv->alpha) >> 24;
285 light_b = ((CHECK_LIGHT << 16) + (color_button->priv->color.blue - CHECK_LIGHT) * color_button->priv->alpha) >> 24;
289 dark_r = light_r = color_button->priv->color.red >> 8;
290 dark_g = light_g = color_button->priv->color.green >> 8;
291 dark_b = light_b = color_button->priv->color.blue >> 8;
294 /* Fill image buffer */
295 pixels = gdk_pixbuf_get_pixels (color_button->priv->pixbuf);
296 rowstride = gdk_pixbuf_get_rowstride (color_button->priv->pixbuf);
297 for (j = 0; j < height; j++)
299 if ((j / CHECK_SIZE) & 1)
320 for (i = 0; i < width; i++)
322 if (!GTK_WIDGET_IS_SENSITIVE (GTK_WIDGET (color_button)) && (i+j)%2)
324 *(pixels + j * rowstride + i * 3) = insensitive_r;
325 *(pixels + j * rowstride + i * 3 + 1) = insensitive_g;
326 *(pixels + j * rowstride + i * 3 + 2) = insensitive_b;
328 else if ((i / CHECK_SIZE) & 1)
330 *(pixels + j * rowstride + i * 3) = c1[0];
331 *(pixels + j * rowstride + i * 3 + 1) = c1[1];
332 *(pixels + j * rowstride + i * 3 + 2) = c1[2];
336 *(pixels + j * rowstride + i * 3) = c2[0];
337 *(pixels + j * rowstride + i * 3 + 1) = c2[1];
338 *(pixels + j * rowstride + i * 3 + 2) = c2[2];
344 /* Handle exposure events for the color picker's drawing area */
346 expose_event (GtkWidget *widget,
347 GdkEventExpose *event,
350 GtkColorButton *color_button = GTK_COLOR_BUTTON (data);
352 gint width = color_button->priv->draw_area->allocation.width;
353 gint height = color_button->priv->draw_area->allocation.height;
355 if (color_button->priv->pixbuf == NULL ||
356 width != gdk_pixbuf_get_width (color_button->priv->pixbuf) ||
357 height != gdk_pixbuf_get_height (color_button->priv->pixbuf))
358 render (color_button);
360 gdk_draw_pixbuf (widget->window,
361 color_button->priv->gc,
362 color_button->priv->pixbuf,
363 event->area.x - widget->allocation.x,
364 event->area.y - widget->allocation.y,
370 event->area.x - widget->allocation.x,
371 event->area.y - widget->allocation.y);
376 gtk_color_button_realize (GtkWidget *widget)
378 GtkColorButton *color_button = GTK_COLOR_BUTTON (widget);
380 GTK_WIDGET_CLASS (gtk_color_button_parent_class)->realize (widget);
382 color_button->priv->gc = gdk_gc_new (widget->window);
384 render (color_button);
388 gtk_color_button_unrealize (GtkWidget *widget)
390 GtkColorButton *color_button = GTK_COLOR_BUTTON (widget);
392 g_object_unref (color_button->priv->gc);
393 color_button->priv->gc = NULL;
395 GTK_WIDGET_CLASS (gtk_color_button_parent_class)->unrealize (widget);
399 gtk_color_button_style_set (GtkWidget *widget,
400 GtkStyle *previous_style)
402 GtkColorButton *color_button = GTK_COLOR_BUTTON (widget);
404 GTK_WIDGET_CLASS (gtk_color_button_parent_class)->style_set (widget, previous_style);
406 if (GTK_WIDGET_REALIZED (widget))
408 if (color_button->priv->pixbuf != NULL)
409 g_object_unref (color_button->priv->pixbuf);
410 color_button->priv->pixbuf = NULL;
415 gtk_color_button_state_changed (GtkWidget *widget,
416 GtkStateType previous_state)
418 GtkColorButton *color_button = GTK_COLOR_BUTTON (widget);
420 if (widget->state == GTK_STATE_INSENSITIVE || previous_state == GTK_STATE_INSENSITIVE)
422 if (color_button->priv->pixbuf != NULL)
423 g_object_unref (color_button->priv->pixbuf);
424 color_button->priv->pixbuf = NULL;
429 gtk_color_button_drag_data_received (GtkWidget *widget,
430 GdkDragContext *context,
433 GtkSelectionData *selection_data,
436 GtkColorButton *color_button)
440 if (selection_data->length < 0)
443 /* We accept drops with the wrong format, since the KDE color
444 * chooser incorrectly drops application/x-color with format 8.
446 if (selection_data->length != 8)
448 g_warning (_("Received invalid color data\n"));
453 dropped = (guint16 *)selection_data->data;
455 color_button->priv->color.red = dropped[0];
456 color_button->priv->color.green = dropped[1];
457 color_button->priv->color.blue = dropped[2];
458 color_button->priv->alpha = dropped[3];
460 if (color_button->priv->pixbuf != NULL)
461 g_object_unref (color_button->priv->pixbuf);
462 color_button->priv->pixbuf = NULL;
464 gtk_widget_queue_draw (color_button->priv->draw_area);
466 g_signal_emit (color_button, color_button_signals[COLOR_SET], 0);
468 g_object_freeze_notify (G_OBJECT (color_button));
469 g_object_notify (G_OBJECT (color_button), "color");
470 g_object_notify (G_OBJECT (color_button), "alpha");
471 g_object_thaw_notify (G_OBJECT (color_button));
475 set_color_icon (GdkDragContext *context,
481 pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE,
484 pixel = ((color->red & 0xff00) << 16) |
485 ((color->green & 0xff00) << 8) |
486 (color->blue & 0xff00);
488 gdk_pixbuf_fill (pixbuf, pixel);
490 gtk_drag_set_icon_pixbuf (context, pixbuf, -2, -2);
491 g_object_unref (pixbuf);
495 gtk_color_button_drag_begin (GtkWidget *widget,
496 GdkDragContext *context,
499 GtkColorButton *color_button = data;
501 set_color_icon (context, &color_button->priv->color);
505 gtk_color_button_drag_data_get (GtkWidget *widget,
506 GdkDragContext *context,
507 GtkSelectionData *selection_data,
510 GtkColorButton *color_button)
514 dropped[0] = color_button->priv->color.red;
515 dropped[1] = color_button->priv->color.green;
516 dropped[2] = color_button->priv->color.blue;
517 dropped[3] = color_button->priv->alpha;
519 gtk_selection_data_set (selection_data, selection_data->target,
520 16, (guchar *)dropped, 8);
524 gtk_color_button_init (GtkColorButton *color_button)
526 GtkWidget *alignment;
531 /* Create the widgets */
532 color_button->priv = GTK_COLOR_BUTTON_GET_PRIVATE (color_button);
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_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);
996 #define __GTK_COLOR_BUTTON_C__
997 #include "gtkaliasdef.c"