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 "gtksignal.h"
45 #include "gtkmarshalers.h"
48 /* Size of checks and gray levels for alpha compositing checkerboard */
50 #define CHECK_DARK 21845 /* 65535 / 3 */
51 #define CHECK_LIGHT 43690
53 #define GTK_COLOR_BUTTON_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_COLOR_BUTTON, GtkColorButtonPrivate))
55 struct _GtkColorButtonPrivate
57 GdkPixbuf *pixbuf; /* Pixbuf for rendering sample */
58 GdkGC *gc; /* GC for drawing */
60 GtkWidget *drawing_area;/* Drawing area for color sample */
61 GtkWidget *cs_dialog; /* Color selection dialog */
63 gchar *title; /* Title for the color selection window */
68 guint use_alpha : 1; /* Use alpha or not */
88 static void gtk_color_button_class_init (GtkColorButtonClass *klass);
89 static void gtk_color_button_init (GtkColorButton *color_button);
92 static void gtk_color_button_finalize (GObject *object);
93 static void gtk_color_button_set_property (GObject *object,
97 static void gtk_color_button_get_property (GObject *object,
102 /* gtkwidget signals */
103 static void gtk_color_button_realize (GtkWidget *widget);
104 static void gtk_color_button_state_changed (GtkWidget *widget,
105 GtkStateType previous_state);
106 static void gtk_color_button_style_set (GtkWidget *widget,
107 GtkStyle *previous_style);
109 /* gtkbutton signals */
110 static void gtk_color_button_clicked (GtkButton *button);
112 /* source side drag signals */
113 static void gtk_color_button_drag_begin (GtkWidget *widget,
114 GdkDragContext *context,
116 static void gtk_color_button_drag_data_get (GtkWidget *widget,
117 GdkDragContext *context,
118 GtkSelectionData *selection_data,
121 GtkColorButton *color_button);
123 /* target side drag signals */
124 static void gtk_color_button_drag_data_received (GtkWidget *widget,
125 GdkDragContext *context,
128 GtkSelectionData *selection_data,
131 GtkColorButton *color_button);
134 static gpointer parent_class = NULL;
135 static guint color_button_signals[LAST_SIGNAL] = { 0 };
137 static GtkTargetEntry drop_types[] = { { "application/x-color", 0, 0 } };
140 gtk_color_button_get_type (void)
142 static GType color_button_type = 0;
144 if (!color_button_type)
146 static const GTypeInfo color_button_info =
148 sizeof (GtkColorButtonClass),
149 NULL, /* base_init */
150 NULL, /* base_finalize */
151 (GClassInitFunc) gtk_color_button_class_init,
152 NULL, /* class_finalize */
153 NULL, /* class_data */
154 sizeof (GtkColorButton),
156 (GInstanceInitFunc) gtk_color_button_init,
160 g_type_register_static (GTK_TYPE_BUTTON, "GtkColorButton",
161 &color_button_info, 0);
164 return color_button_type;
168 gtk_color_button_class_init (GtkColorButtonClass *klass)
170 GObjectClass *gobject_class;
171 GtkObjectClass *object_class;
172 GtkWidgetClass *widget_class;
173 GtkButtonClass *button_class;
175 gobject_class = G_OBJECT_CLASS (klass);
176 object_class = GTK_OBJECT_CLASS (klass);
177 widget_class = GTK_WIDGET_CLASS (klass);
178 button_class = GTK_BUTTON_CLASS (klass);
180 parent_class = g_type_class_peek_parent (klass);
182 gobject_class->get_property = gtk_color_button_get_property;
183 gobject_class->set_property = gtk_color_button_set_property;
184 gobject_class->finalize = gtk_color_button_finalize;
185 widget_class->state_changed = gtk_color_button_state_changed;
186 widget_class->realize = gtk_color_button_realize;
187 widget_class->style_set = gtk_color_button_style_set;
188 button_class->clicked = gtk_color_button_clicked;
189 klass->color_set = NULL;
192 * GtkColorButton:use-alpha:
194 * If this property is set to %TRUE, the color swatch on the button is rendered against a
195 * checkerboard background to show its opacity and the opacity slider is displayed in the
196 * color selection dialog.
200 g_object_class_install_property (gobject_class,
202 g_param_spec_boolean ("use_alpha", _("Use alpha"),
203 _("Whether or not to give the color an alpha value"),
205 (G_PARAM_READABLE | G_PARAM_WRITABLE)));
208 * GtkColorButton:title:
210 * The title of the color selection dialog
214 g_object_class_install_property (gobject_class,
216 g_param_spec_string ("title",
218 _("The title of the color selection dialog"),
220 (G_PARAM_READABLE | G_PARAM_WRITABLE)));
223 * GtkColorButton:color:
225 * The selected color.
229 g_object_class_install_property (gobject_class,
231 g_param_spec_boxed ("color",
233 _("The selected color"),
235 G_PARAM_READABLE | G_PARAM_WRITABLE));
238 * GtkColorButton:alpha:
240 * The selected opacity value (0 fully transparent, 65535 fully opaque).
244 g_object_class_install_property (gobject_class,
246 g_param_spec_uint ("alpha",
248 _("The selected opacity value (0 fully transparent, 65535 fully opaque)"),
250 G_PARAM_READABLE | G_PARAM_WRITABLE));
253 * GtkColorButton::color-set:
254 * @widget: the object which received the signal.
256 * The ::color-set signal is emitted when the user selects a color. When handling this signal,
257 * use gtk_color_button_get_color() and gtk_color_button_get_alpha() to find out which color
262 color_button_signals[COLOR_SET] = g_signal_new ("color_set",
263 G_TYPE_FROM_CLASS (gobject_class),
265 G_STRUCT_OFFSET (GtkColorButtonClass, color_set),
267 _gtk_marshal_VOID__VOID,
270 g_type_class_add_private (gobject_class, sizeof (GtkColorButtonPrivate));
274 render (GtkColorButton *color_button)
276 gint dark_r, dark_g, dark_b;
277 gint light_r, light_g, light_b;
278 gint i, j, rowstride;
282 guint8 insensitive_r = 0;
283 guint8 insensitive_g = 0;
284 guint8 insensitive_b = 0;
286 width = color_button->priv->drawing_area->allocation.width;
287 height = color_button->priv->drawing_area->allocation.height;
288 if (color_button->priv->pixbuf == NULL ||
289 gdk_pixbuf_get_width (color_button->priv->pixbuf) != width ||
290 gdk_pixbuf_get_height (color_button->priv->pixbuf) != height)
292 if (color_button->priv->pixbuf != NULL)
293 g_object_unref (color_button->priv->pixbuf);
294 color_button->priv->pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, width, height);
298 /* Compute dark and light check colors */
300 insensitive_r = GTK_WIDGET(color_button)->style->bg[GTK_STATE_INSENSITIVE].red >> 8;
301 insensitive_g = GTK_WIDGET(color_button)->style->bg[GTK_STATE_INSENSITIVE].green >> 8;
302 insensitive_b = GTK_WIDGET(color_button)->style->bg[GTK_STATE_INSENSITIVE].blue >> 8;
304 if (color_button->priv->use_alpha)
306 dark_r = ((CHECK_DARK << 16) + (color_button->priv->color.red - CHECK_DARK) * color_button->priv->alpha) >> 24;
307 dark_g = ((CHECK_DARK << 16) + (color_button->priv->color.green - CHECK_DARK) * color_button->priv->alpha) >> 24;
308 dark_b = ((CHECK_DARK << 16) + (color_button->priv->color.blue - CHECK_DARK) * color_button->priv->alpha) >> 24;
310 light_r = ((CHECK_LIGHT << 16) + (color_button->priv->color.red - CHECK_LIGHT) * color_button->priv->alpha) >> 24;
311 light_g = ((CHECK_LIGHT << 16) + (color_button->priv->color.green - CHECK_LIGHT) * color_button->priv->alpha) >> 24;
312 light_b = ((CHECK_LIGHT << 16) + (color_button->priv->color.blue - CHECK_LIGHT) * color_button->priv->alpha) >> 24;
316 dark_r = light_r = color_button->priv->color.red >> 8;
317 dark_g = light_g = color_button->priv->color.green >> 8;
318 dark_b = light_b = color_button->priv->color.blue >> 8;
321 /* Fill image buffer */
322 pixels = gdk_pixbuf_get_pixels (color_button->priv->pixbuf);
323 rowstride = gdk_pixbuf_get_rowstride (color_button->priv->pixbuf);
324 for (j = 0; j < height; j++)
326 if ((j / CHECK_SIZE) & 1)
347 for (i = 0; i < width; i++)
349 if (!GTK_WIDGET_SENSITIVE (GTK_WIDGET (color_button)) && (i+j)%2)
351 *(pixels + j * rowstride + i * 3) = insensitive_r;
352 *(pixels + j * rowstride + i * 3 + 1) = insensitive_g;
353 *(pixels + j * rowstride + i * 3 + 2) = insensitive_b;
355 else if ((i / CHECK_SIZE) & 1)
357 *(pixels + j * rowstride + i * 3) = c1[0];
358 *(pixels + j * rowstride + i * 3 + 1) = c1[1];
359 *(pixels + j * rowstride + i * 3 + 2) = c1[2];
363 *(pixels + j * rowstride + i * 3) = c2[0];
364 *(pixels + j * rowstride + i * 3 + 1) = c2[1];
365 *(pixels + j * rowstride + i * 3 + 2) = c2[2];
371 /* Handle exposure events for the color picker's drawing area */
373 expose_event (GtkWidget *widget,
374 GdkEventExpose *event,
377 GtkColorButton *color_button = GTK_COLOR_BUTTON (data);
379 gint width = color_button->priv->drawing_area->allocation.width;
380 gint height = color_button->priv->drawing_area->allocation.height;
382 if (color_button->priv->pixbuf == NULL ||
383 width != gdk_pixbuf_get_width (color_button->priv->pixbuf) ||
384 height != gdk_pixbuf_get_height (color_button->priv->pixbuf))
385 render (color_button);
387 gdk_draw_pixbuf (widget->window,
388 color_button->priv->gc,
389 color_button->priv->pixbuf,
403 gtk_color_button_realize (GtkWidget *widget)
405 GtkColorButton *color_button = GTK_COLOR_BUTTON (widget);
407 GTK_WIDGET_CLASS (parent_class)->realize (widget);
409 if (color_button->priv->gc == NULL)
410 color_button->priv->gc = gdk_gc_new (widget->window);
412 render (color_button);
416 gtk_color_button_style_set (GtkWidget *widget,
417 GtkStyle *previous_style)
419 GtkColorButton *color_button = GTK_COLOR_BUTTON (widget);
421 GTK_WIDGET_CLASS (parent_class)->style_set (widget, previous_style);
423 if (GTK_WIDGET_REALIZED (widget))
425 if (color_button->priv->pixbuf != NULL)
426 g_object_unref (color_button->priv->pixbuf);
427 color_button->priv->pixbuf = NULL;
432 gtk_color_button_state_changed (GtkWidget *widget,
433 GtkStateType previous_state)
435 GtkColorButton *color_button = GTK_COLOR_BUTTON (widget);
437 if (widget->state == GTK_STATE_INSENSITIVE || previous_state == GTK_STATE_INSENSITIVE)
439 if (color_button->priv->pixbuf != NULL)
440 g_object_unref (color_button->priv->pixbuf);
441 color_button->priv->pixbuf = NULL;
446 gtk_color_button_drag_data_received (GtkWidget *widget,
447 GdkDragContext *context,
450 GtkSelectionData *selection_data,
453 GtkColorButton *color_button)
457 if (selection_data->length < 0)
460 /* We accept drops with the wrong format, since the KDE color
461 * chooser incorrectly drops application/x-color with format 8.
463 if (selection_data->length != 8)
465 g_warning (_("Received invalid color data\n"));
470 dropped = (guint16 *)selection_data->data;
472 color_button->priv->color.red = dropped[0];
473 color_button->priv->color.green = dropped[1];
474 color_button->priv->color.blue = dropped[2];
475 color_button->priv->alpha = dropped[3];
477 if (color_button->priv->pixbuf != NULL)
478 g_object_unref (color_button->priv->pixbuf);
479 color_button->priv->pixbuf = NULL;
481 gtk_widget_queue_draw (color_button->priv->drawing_area);
483 g_signal_emit (color_button, color_button_signals[COLOR_SET], 0);
485 g_object_freeze_notify (G_OBJECT (color_button));
486 g_object_notify (G_OBJECT (color_button), "color");
487 g_object_notify (G_OBJECT (color_button), "alpha");
488 g_object_thaw_notify (G_OBJECT (color_button));
492 set_color_icon (GdkDragContext *context,
498 pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE,
501 pixel = ((color->red & 0xff00) << 16) |
502 ((color->green & 0xff00) << 8) |
503 (color->blue & 0xff00);
505 gdk_pixbuf_fill (pixbuf, pixel);
507 gtk_drag_set_icon_pixbuf (context, pixbuf, -2, -2);
508 g_object_unref (pixbuf);
512 gtk_color_button_drag_begin (GtkWidget *widget,
513 GdkDragContext *context,
516 GtkColorButton *color_button = data;
518 set_color_icon (context, &color_button->priv->color);
522 gtk_color_button_drag_data_get (GtkWidget *widget,
523 GdkDragContext *context,
524 GtkSelectionData *selection_data,
527 GtkColorButton *color_button)
531 dropped[0] = color_button->priv->color.red;
532 dropped[1] = color_button->priv->color.green;
533 dropped[2] = color_button->priv->color.blue;
534 dropped[3] = color_button->priv->alpha;
536 gtk_selection_data_set (selection_data, selection_data->target,
537 16, (guchar *)dropped, 8);
541 gtk_color_button_init (GtkColorButton *color_button)
543 GtkWidget *alignment;
548 /* Create the widgets */
549 color_button->priv = GTK_COLOR_BUTTON_GET_PRIVATE (color_button);
551 gtk_widget_push_composite_child ();
553 alignment = gtk_alignment_new (0.5, 0.5, 0.5, 1.0);
554 gtk_container_set_border_width (GTK_CONTAINER (alignment), 1);
555 gtk_container_add (GTK_CONTAINER (color_button), alignment);
556 gtk_widget_show (alignment);
558 frame = gtk_frame_new (NULL);
559 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_OUT);
560 gtk_container_add (GTK_CONTAINER (alignment), frame);
561 gtk_widget_show (frame);
563 color_button->priv->drawing_area = gtk_drawing_area_new ();
565 layout = gtk_widget_create_pango_layout (GTK_WIDGET (color_button), "Black");
566 pango_layout_get_pixel_extents (layout, NULL, &rect);
567 gtk_widget_set_size_request (color_button->priv->drawing_area, rect.width - 2, rect.height - 2);
568 g_signal_connect (color_button->priv->drawing_area, "expose_event",
569 G_CALLBACK (expose_event), color_button);
570 gtk_container_add (GTK_CONTAINER (frame), color_button->priv->drawing_area);
571 gtk_widget_show (color_button->priv->drawing_area);
573 color_button->priv->title = g_strdup (_("Pick a Color")); /* default title */
575 /* Create the buffer for the image so that we can create an image.
576 * Also create the picker's pixmap.
578 color_button->priv->pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, rect.width, rect.height);
580 color_button->priv->gc = NULL;
582 /* Start with opaque black, alpha disabled */
584 color_button->priv->color.red = 0;
585 color_button->priv->color.green = 0;
586 color_button->priv->color.blue = 0;
587 color_button->priv->alpha = 65535;
588 color_button->priv->use_alpha = FALSE;
590 gtk_drag_dest_set (GTK_WIDGET (color_button),
591 GTK_DEST_DEFAULT_MOTION |
592 GTK_DEST_DEFAULT_HIGHLIGHT |
593 GTK_DEST_DEFAULT_DROP,
594 drop_types, 1, GDK_ACTION_COPY);
595 gtk_drag_source_set (GTK_WIDGET(color_button),
596 GDK_BUTTON1_MASK|GDK_BUTTON3_MASK,
599 g_signal_connect (color_button, "drag_begin",
600 G_CALLBACK (gtk_color_button_drag_begin), color_button);
601 g_signal_connect (color_button, "drag_data_received",
602 G_CALLBACK (gtk_color_button_drag_data_received), color_button);
603 g_signal_connect (color_button, "drag_data_get",
604 G_CALLBACK (gtk_color_button_drag_data_get), color_button);
606 gtk_widget_pop_composite_child ();
610 gtk_color_button_finalize (GObject *object)
612 GtkColorButton *color_button = GTK_COLOR_BUTTON (object);
614 if (color_button->priv->gc != NULL)
615 g_object_unref (G_OBJECT (color_button->priv->gc));
616 color_button->priv->gc = NULL;
618 if (color_button->priv->cs_dialog != NULL)
619 gtk_widget_destroy (color_button->priv->cs_dialog);
620 color_button->priv->cs_dialog = NULL;
622 if (color_button->priv->pixbuf != NULL)
623 g_object_unref (color_button->priv->pixbuf);
624 color_button->priv->pixbuf = NULL;
626 g_free (color_button->priv->title);
627 color_button->priv->title = NULL;
629 G_OBJECT_CLASS (parent_class)->finalize (object);
634 * gtk_color_button_new:
636 * Creates a new color button. This returns a widget in the form of
637 * a small button containing a swatch representing the current selected
638 * color. When the button is clicked, a color-selection dialog will open,
639 * allowing the user to select a color. The swatch will be updated to reflect
640 * the new color when the user finishes.
642 * Returns: a new color button.
647 gtk_color_button_new (void)
649 return g_object_new (GTK_TYPE_COLOR_BUTTON, NULL);
653 * gtk_color_button_new_with_color:
654 * @color: A #GdkColor to set the current color with.
656 * Creates a new color button.
658 * Returns: a new color button.
663 gtk_color_button_new_with_color (GdkColor *color)
665 return g_object_new (GTK_TYPE_COLOR_BUTTON, "color", color, NULL);
669 dialog_ok_clicked (GtkWidget *widget,
672 GtkColorButton *color_button = GTK_COLOR_BUTTON (data);
673 GtkColorSelection *color_selection;
675 color_selection = GTK_COLOR_SELECTION (GTK_COLOR_SELECTION_DIALOG (color_button->priv->cs_dialog)->colorsel);
677 gtk_color_selection_get_current_color (color_selection, &color_button->priv->color);
678 color_button->priv->alpha = gtk_color_selection_get_current_alpha (color_selection);
680 if (color_button->priv->pixbuf != NULL)
681 g_object_unref (color_button->priv->pixbuf);
682 color_button->priv->pixbuf = NULL;
684 gtk_widget_hide (color_button->priv->cs_dialog);
686 gtk_widget_queue_draw (color_button->priv->drawing_area);
688 g_signal_emit (color_button, color_button_signals[COLOR_SET], 0);
690 g_object_freeze_notify (G_OBJECT (color_button));
691 g_object_notify (G_OBJECT (color_button), "color");
692 g_object_notify (G_OBJECT (color_button), "alpha");
693 g_object_thaw_notify (G_OBJECT (color_button));
697 dialog_destroy (GtkWidget *widget,
700 GtkColorButton *color_button = GTK_COLOR_BUTTON (data);
702 color_button->priv->cs_dialog = NULL;
708 dialog_cancel_clicked (GtkWidget *widget,
711 GtkColorButton *color_button = GTK_COLOR_BUTTON (data);
713 gtk_widget_hide (color_button->priv->cs_dialog);
717 gtk_color_button_clicked (GtkButton *button)
719 GtkColorButton *color_button = GTK_COLOR_BUTTON (button);
720 GtkColorSelectionDialog *color_dialog;
722 /* if dialog already exists, make sure it's shown and raised */
723 if (!color_button->priv->cs_dialog)
725 /* Create the dialog and connects its buttons */
728 parent = gtk_widget_get_toplevel (GTK_WIDGET (color_button));
730 color_button->priv->cs_dialog = gtk_color_selection_dialog_new (color_button->priv->title);
732 color_dialog = GTK_COLOR_SELECTION_DIALOG (color_button->priv->cs_dialog);
735 gtk_window_set_transient_for (GTK_WINDOW (color_dialog),
736 GTK_WINDOW (parent));
738 g_signal_connect (color_dialog->ok_button, "clicked",
739 G_CALLBACK (dialog_ok_clicked), color_button);
740 g_signal_connect (color_dialog->cancel_button, "clicked",
741 G_CALLBACK (dialog_cancel_clicked), color_button);
742 g_signal_connect (color_dialog, "destroy",
743 G_CALLBACK (dialog_destroy), color_button);
745 /* If there is a grabbed window, set new dialog as modal */
746 if (gtk_grab_get_current ())
747 gtk_window_set_modal (GTK_WINDOW (color_button->priv->cs_dialog),TRUE);
750 color_dialog = GTK_COLOR_SELECTION_DIALOG (color_button->priv->cs_dialog);
752 gtk_color_selection_set_has_opacity_control (GTK_COLOR_SELECTION (color_dialog->colorsel),
753 color_button->priv->use_alpha);
755 gtk_color_selection_set_previous_color (GTK_COLOR_SELECTION (color_dialog->colorsel),
756 &color_button->priv->color);
757 gtk_color_selection_set_previous_alpha (GTK_COLOR_SELECTION (color_dialog->colorsel),
758 color_button->priv->alpha);
760 gtk_color_selection_set_current_color (GTK_COLOR_SELECTION (color_dialog->colorsel),
761 &color_button->priv->color);
762 gtk_color_selection_set_current_alpha (GTK_COLOR_SELECTION (color_dialog->colorsel),
763 color_button->priv->alpha);
765 gtk_window_present (GTK_WINDOW (color_button->priv->cs_dialog));
769 * gtk_color_button_set_color:
770 * @color_button: a #GtkColorButton.
771 * @color: A #GdkColor to set the current color with.
773 * Sets the current color to be @color.
778 gtk_color_button_set_color (GtkColorButton *color_button,
781 g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button));
783 color_button->priv->color.red = color->red;
784 color_button->priv->color.green = color->green;
785 color_button->priv->color.blue = color->blue;
787 g_object_notify (G_OBJECT (color_button), "color");
792 * gtk_color_button_set_alpha:
793 * @color_button: a #GtkColorButton.
794 * @alpha: an integer between 0 and 65535.
796 * Sets the current opacity to be @alpha.
801 gtk_color_button_set_alpha (GtkColorButton *color_button,
804 g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button));
806 color_button->priv->alpha = alpha;
808 g_object_notify (G_OBJECT (color_button), "alpha");
812 * gtk_color_button_get_color:
813 * @color_button: a #GtkColorButton.
814 * @color: a #GdkColor to fill in with the current color.
816 * Sets @color to be the current color in the #GtkColorButton widget.
821 gtk_color_button_get_color (GtkColorButton *color_button,
824 g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button));
826 color->red = color_button->priv->color.red;
827 color->green = color_button->priv->color.green;
828 color->blue = color_button->priv->color.blue;
832 * gtk_color_button_get_alpha:
833 * @color_button: a #GtkColorButton.
835 * Returns the current alpha value.
837 * Return value: an integer between 0 and 65535.
842 gtk_color_button_get_alpha (GtkColorButton *color_button)
844 g_return_val_if_fail (GTK_IS_COLOR_BUTTON (color_button), 0);
846 return color_button->priv->alpha;
850 * gtk_color_button_set_use_alpha:
851 * @color_button: a #GtkColorButton.
852 * @use_alpha: %TRUE if color button should use alpha channel, %FALSE if not.
854 * Sets whether or not the color button should use the alpha channel.
859 gtk_color_button_set_use_alpha (GtkColorButton *color_button,
862 g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button));
864 use_alpha = (use_alpha != FALSE);
866 if (color_button->priv->use_alpha != use_alpha)
868 color_button->priv->use_alpha = use_alpha;
870 render (color_button);
871 gtk_widget_queue_draw (color_button->priv->drawing_area);
873 g_object_notify (G_OBJECT (color_button), "use_alpha");
878 * gtk_color_button_get_use_alpha:
879 * @color_button: a #GtkColorButton.
881 * Does the color selection dialog use the alpha channel?
883 * Returns: %TRUE if the color sample uses alpha channel, %FALSE if not.
888 gtk_color_button_get_use_alpha (GtkColorButton *color_button)
890 g_return_val_if_fail (GTK_IS_COLOR_BUTTON (color_button), FALSE);
892 return color_button->priv->use_alpha;
897 * gtk_color_button_set_title:
898 * @color_button: a #GtkColorButton
899 * @title: String containing new window title.
901 * Sets the title for the color selection dialog.
906 gtk_color_button_set_title (GtkColorButton *color_button,
911 g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button));
913 old_title = color_button->priv->title;
914 color_button->priv->title = g_strdup (title);
917 if (color_button->priv->cs_dialog)
918 gtk_window_set_title (GTK_WINDOW (color_button->priv->cs_dialog),
919 color_button->priv->title);
921 g_object_notify (G_OBJECT (color_button), "title");
925 * gtk_color_button_get_title:
926 * @color_button: a #GtkColorButton
928 * Gets the title of the color selection dialog.
930 * Returns: An internal string, do not free the return value
934 G_CONST_RETURN gchar *
935 gtk_color_button_get_title (GtkColorButton *color_button)
937 g_return_val_if_fail (GTK_IS_COLOR_BUTTON (color_button), NULL);
939 return color_button->priv->title;
943 gtk_color_button_set_property (GObject *object,
948 GtkColorButton *color_button = GTK_COLOR_BUTTON (object);
953 gtk_color_button_set_use_alpha (color_button, g_value_get_boolean (value));
956 gtk_color_button_set_title (color_button, g_value_get_string (value));
959 gtk_color_button_set_color (color_button, g_value_get_boxed (value));
962 gtk_color_button_set_alpha (color_button, g_value_get_uint (value));
965 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
971 gtk_color_button_get_property (GObject *object,
976 GtkColorButton *color_button = GTK_COLOR_BUTTON (object);
982 g_value_set_boolean (value, gtk_color_button_get_use_alpha (color_button));
985 g_value_set_string (value, gtk_color_button_get_title (color_button));
988 gtk_color_button_get_color (color_button, &color);
989 g_value_set_boxed (value, &color);
992 g_value_set_uint (value, gtk_color_button_get_alpha (color_button));
995 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);