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"
46 #include "gtkprivate.h"
50 /* Size of checks and gray levels for alpha compositing checkerboard */
52 #define CHECK_DARK 21845 /* 65535 / 3 */
53 #define CHECK_LIGHT 43690
55 #define GTK_COLOR_BUTTON_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_COLOR_BUTTON, GtkColorButtonPrivate))
57 struct _GtkColorButtonPrivate
59 GdkPixbuf *pixbuf; /* Pixbuf for rendering sample */
60 GdkGC *gc; /* GC for drawing */
62 GtkWidget *draw_area; /* Widget where we draw the color sample */
63 GtkWidget *cs_dialog; /* Color selection dialog */
65 gchar *title; /* Title for the color selection window */
70 guint use_alpha : 1; /* Use alpha or not */
91 static void gtk_color_button_finalize (GObject *object);
92 static void gtk_color_button_set_property (GObject *object,
96 static void gtk_color_button_get_property (GObject *object,
101 /* gtkwidget signals */
102 static void gtk_color_button_realize (GtkWidget *widget);
103 static void gtk_color_button_unrealize (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 guint color_button_signals[LAST_SIGNAL] = { 0 };
136 static const GtkTargetEntry drop_types[] = { { "application/x-color", 0, 0 } };
138 G_DEFINE_TYPE (GtkColorButton, gtk_color_button, GTK_TYPE_BUTTON);
141 gtk_color_button_class_init (GtkColorButtonClass *klass)
143 GObjectClass *gobject_class;
144 GtkWidgetClass *widget_class;
145 GtkButtonClass *button_class;
147 gobject_class = G_OBJECT_CLASS (klass);
148 widget_class = GTK_WIDGET_CLASS (klass);
149 button_class = GTK_BUTTON_CLASS (klass);
151 gobject_class->get_property = gtk_color_button_get_property;
152 gobject_class->set_property = gtk_color_button_set_property;
153 gobject_class->finalize = gtk_color_button_finalize;
154 widget_class->state_changed = gtk_color_button_state_changed;
155 widget_class->realize = gtk_color_button_realize;
156 widget_class->unrealize = gtk_color_button_unrealize;
157 widget_class->style_set = gtk_color_button_style_set;
158 button_class->clicked = gtk_color_button_clicked;
159 klass->color_set = NULL;
162 * GtkColorButton:use-alpha:
164 * If this property is set to %TRUE, the color swatch on the button is rendered against a
165 * checkerboard background to show its opacity and the opacity slider is displayed in the
166 * color selection dialog.
170 g_object_class_install_property (gobject_class,
172 g_param_spec_boolean ("use-alpha", P_("Use alpha"),
173 P_("Whether or not to give the color an alpha value"),
175 GTK_PARAM_READWRITE));
178 * GtkColorButton:title:
180 * The title of the color selection dialog
184 g_object_class_install_property (gobject_class,
186 g_param_spec_string ("title",
188 P_("The title of the color selection dialog"),
190 GTK_PARAM_READWRITE));
193 * GtkColorButton:color:
195 * The selected color.
199 g_object_class_install_property (gobject_class,
201 g_param_spec_boxed ("color",
203 P_("The selected color"),
205 GTK_PARAM_READWRITE));
208 * GtkColorButton:alpha:
210 * The selected opacity value (0 fully transparent, 65535 fully opaque).
214 g_object_class_install_property (gobject_class,
216 g_param_spec_uint ("alpha",
218 P_("The selected opacity value (0 fully transparent, 65535 fully opaque)"),
220 GTK_PARAM_READWRITE));
223 * GtkColorButton::color-set:
224 * @widget: the object which received the signal.
226 * The ::color-set signal is emitted when the user selects a color. When handling this signal,
227 * use gtk_color_button_get_color() and gtk_color_button_get_alpha() to find out which color
232 color_button_signals[COLOR_SET] = g_signal_new (I_("color_set"),
233 G_TYPE_FROM_CLASS (gobject_class),
235 G_STRUCT_OFFSET (GtkColorButtonClass, color_set),
237 _gtk_marshal_VOID__VOID,
240 g_type_class_add_private (gobject_class, sizeof (GtkColorButtonPrivate));
244 render (GtkColorButton *color_button)
246 gint dark_r, dark_g, dark_b;
247 gint light_r, light_g, light_b;
248 gint i, j, rowstride;
252 guint8 insensitive_r = 0;
253 guint8 insensitive_g = 0;
254 guint8 insensitive_b = 0;
256 width = color_button->priv->draw_area->allocation.width;
257 height = color_button->priv->draw_area->allocation.height;
258 if (color_button->priv->pixbuf == NULL ||
259 gdk_pixbuf_get_width (color_button->priv->pixbuf) != width ||
260 gdk_pixbuf_get_height (color_button->priv->pixbuf) != height)
262 if (color_button->priv->pixbuf != NULL)
263 g_object_unref (color_button->priv->pixbuf);
264 color_button->priv->pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, width, height);
268 /* Compute dark and light check colors */
270 insensitive_r = GTK_WIDGET(color_button)->style->bg[GTK_STATE_INSENSITIVE].red >> 8;
271 insensitive_g = GTK_WIDGET(color_button)->style->bg[GTK_STATE_INSENSITIVE].green >> 8;
272 insensitive_b = GTK_WIDGET(color_button)->style->bg[GTK_STATE_INSENSITIVE].blue >> 8;
274 if (color_button->priv->use_alpha)
276 dark_r = ((CHECK_DARK << 16) + (color_button->priv->color.red - CHECK_DARK) * color_button->priv->alpha) >> 24;
277 dark_g = ((CHECK_DARK << 16) + (color_button->priv->color.green - CHECK_DARK) * color_button->priv->alpha) >> 24;
278 dark_b = ((CHECK_DARK << 16) + (color_button->priv->color.blue - CHECK_DARK) * color_button->priv->alpha) >> 24;
280 light_r = ((CHECK_LIGHT << 16) + (color_button->priv->color.red - CHECK_LIGHT) * color_button->priv->alpha) >> 24;
281 light_g = ((CHECK_LIGHT << 16) + (color_button->priv->color.green - CHECK_LIGHT) * color_button->priv->alpha) >> 24;
282 light_b = ((CHECK_LIGHT << 16) + (color_button->priv->color.blue - CHECK_LIGHT) * color_button->priv->alpha) >> 24;
286 dark_r = light_r = color_button->priv->color.red >> 8;
287 dark_g = light_g = color_button->priv->color.green >> 8;
288 dark_b = light_b = color_button->priv->color.blue >> 8;
291 /* Fill image buffer */
292 pixels = gdk_pixbuf_get_pixels (color_button->priv->pixbuf);
293 rowstride = gdk_pixbuf_get_rowstride (color_button->priv->pixbuf);
294 for (j = 0; j < height; j++)
296 if ((j / CHECK_SIZE) & 1)
317 for (i = 0; i < width; i++)
319 if (!GTK_WIDGET_IS_SENSITIVE (GTK_WIDGET (color_button)) && (i+j)%2)
321 *(pixels + j * rowstride + i * 3) = insensitive_r;
322 *(pixels + j * rowstride + i * 3 + 1) = insensitive_g;
323 *(pixels + j * rowstride + i * 3 + 2) = insensitive_b;
325 else if ((i / CHECK_SIZE) & 1)
327 *(pixels + j * rowstride + i * 3) = c1[0];
328 *(pixels + j * rowstride + i * 3 + 1) = c1[1];
329 *(pixels + j * rowstride + i * 3 + 2) = c1[2];
333 *(pixels + j * rowstride + i * 3) = c2[0];
334 *(pixels + j * rowstride + i * 3 + 1) = c2[1];
335 *(pixels + j * rowstride + i * 3 + 2) = c2[2];
341 /* Handle exposure events for the color picker's drawing area */
343 expose_event (GtkWidget *widget,
344 GdkEventExpose *event,
347 GtkColorButton *color_button = GTK_COLOR_BUTTON (data);
349 gint width = color_button->priv->draw_area->allocation.width;
350 gint height = color_button->priv->draw_area->allocation.height;
352 if (color_button->priv->pixbuf == NULL ||
353 width != gdk_pixbuf_get_width (color_button->priv->pixbuf) ||
354 height != gdk_pixbuf_get_height (color_button->priv->pixbuf))
355 render (color_button);
357 gdk_draw_pixbuf (widget->window,
358 color_button->priv->gc,
359 color_button->priv->pixbuf,
360 event->area.x - widget->allocation.x,
361 event->area.y - widget->allocation.y,
367 event->area.x - widget->allocation.x,
368 event->area.y - widget->allocation.y);
373 gtk_color_button_realize (GtkWidget *widget)
375 GtkColorButton *color_button = GTK_COLOR_BUTTON (widget);
377 GTK_WIDGET_CLASS (gtk_color_button_parent_class)->realize (widget);
379 color_button->priv->gc = gdk_gc_new (widget->window);
381 render (color_button);
385 gtk_color_button_unrealize (GtkWidget *widget)
387 GtkColorButton *color_button = GTK_COLOR_BUTTON (widget);
389 g_object_unref (color_button->priv->gc);
390 color_button->priv->gc = NULL;
392 GTK_WIDGET_CLASS (gtk_color_button_parent_class)->unrealize (widget);
396 gtk_color_button_style_set (GtkWidget *widget,
397 GtkStyle *previous_style)
399 GtkColorButton *color_button = GTK_COLOR_BUTTON (widget);
401 GTK_WIDGET_CLASS (gtk_color_button_parent_class)->style_set (widget, previous_style);
403 if (GTK_WIDGET_REALIZED (widget))
405 if (color_button->priv->pixbuf != NULL)
406 g_object_unref (color_button->priv->pixbuf);
407 color_button->priv->pixbuf = NULL;
412 gtk_color_button_state_changed (GtkWidget *widget,
413 GtkStateType previous_state)
415 GtkColorButton *color_button = GTK_COLOR_BUTTON (widget);
417 if (widget->state == GTK_STATE_INSENSITIVE || previous_state == GTK_STATE_INSENSITIVE)
419 if (color_button->priv->pixbuf != NULL)
420 g_object_unref (color_button->priv->pixbuf);
421 color_button->priv->pixbuf = NULL;
426 gtk_color_button_drag_data_received (GtkWidget *widget,
427 GdkDragContext *context,
430 GtkSelectionData *selection_data,
433 GtkColorButton *color_button)
437 if (selection_data->length < 0)
440 /* We accept drops with the wrong format, since the KDE color
441 * chooser incorrectly drops application/x-color with format 8.
443 if (selection_data->length != 8)
445 g_warning (_("Received invalid color data\n"));
450 dropped = (guint16 *)selection_data->data;
452 color_button->priv->color.red = dropped[0];
453 color_button->priv->color.green = dropped[1];
454 color_button->priv->color.blue = dropped[2];
455 color_button->priv->alpha = dropped[3];
457 if (color_button->priv->pixbuf != NULL)
458 g_object_unref (color_button->priv->pixbuf);
459 color_button->priv->pixbuf = NULL;
461 gtk_widget_queue_draw (color_button->priv->draw_area);
463 g_signal_emit (color_button, color_button_signals[COLOR_SET], 0);
465 g_object_freeze_notify (G_OBJECT (color_button));
466 g_object_notify (G_OBJECT (color_button), "color");
467 g_object_notify (G_OBJECT (color_button), "alpha");
468 g_object_thaw_notify (G_OBJECT (color_button));
472 set_color_icon (GdkDragContext *context,
478 pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE,
481 pixel = ((color->red & 0xff00) << 16) |
482 ((color->green & 0xff00) << 8) |
483 (color->blue & 0xff00);
485 gdk_pixbuf_fill (pixbuf, pixel);
487 gtk_drag_set_icon_pixbuf (context, pixbuf, -2, -2);
488 g_object_unref (pixbuf);
492 gtk_color_button_drag_begin (GtkWidget *widget,
493 GdkDragContext *context,
496 GtkColorButton *color_button = data;
498 set_color_icon (context, &color_button->priv->color);
502 gtk_color_button_drag_data_get (GtkWidget *widget,
503 GdkDragContext *context,
504 GtkSelectionData *selection_data,
507 GtkColorButton *color_button)
511 dropped[0] = color_button->priv->color.red;
512 dropped[1] = color_button->priv->color.green;
513 dropped[2] = color_button->priv->color.blue;
514 dropped[3] = color_button->priv->alpha;
516 gtk_selection_data_set (selection_data, selection_data->target,
517 16, (guchar *)dropped, 8);
521 gtk_color_button_init (GtkColorButton *color_button)
523 GtkWidget *alignment;
528 /* Create the widgets */
529 color_button->priv = GTK_COLOR_BUTTON_GET_PRIVATE (color_button);
531 gtk_widget_push_composite_child ();
533 alignment = gtk_alignment_new (0.5, 0.5, 0.5, 1.0);
534 gtk_container_set_border_width (GTK_CONTAINER (alignment), 1);
535 gtk_container_add (GTK_CONTAINER (color_button), alignment);
536 gtk_widget_show (alignment);
538 frame = gtk_frame_new (NULL);
539 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_OUT);
540 gtk_container_add (GTK_CONTAINER (alignment), frame);
541 gtk_widget_show (frame);
543 /* Just some widget we can hook to expose-event on */
544 color_button->priv->draw_area = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
546 layout = gtk_widget_create_pango_layout (GTK_WIDGET (color_button), "Black");
547 pango_layout_get_pixel_extents (layout, NULL, &rect);
548 g_object_unref (layout);
550 gtk_widget_set_size_request (color_button->priv->draw_area, rect.width - 2, rect.height - 2);
551 g_signal_connect (color_button->priv->draw_area, "expose-event",
552 G_CALLBACK (expose_event), color_button);
553 gtk_container_add (GTK_CONTAINER (frame), color_button->priv->draw_area);
554 gtk_widget_show (color_button->priv->draw_area);
556 color_button->priv->title = g_strdup (_("Pick a Color")); /* default title */
558 /* Create the buffer for the image so that we can create an image.
559 * Also create the picker's pixmap.
561 color_button->priv->pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, rect.width, rect.height);
563 color_button->priv->gc = NULL;
565 /* Start with opaque black, alpha disabled */
567 color_button->priv->color.red = 0;
568 color_button->priv->color.green = 0;
569 color_button->priv->color.blue = 0;
570 color_button->priv->alpha = 65535;
571 color_button->priv->use_alpha = FALSE;
573 gtk_drag_dest_set (GTK_WIDGET (color_button),
574 GTK_DEST_DEFAULT_MOTION |
575 GTK_DEST_DEFAULT_HIGHLIGHT |
576 GTK_DEST_DEFAULT_DROP,
577 drop_types, 1, GDK_ACTION_COPY);
578 gtk_drag_source_set (GTK_WIDGET(color_button),
579 GDK_BUTTON1_MASK|GDK_BUTTON3_MASK,
582 g_signal_connect (color_button, "drag_begin",
583 G_CALLBACK (gtk_color_button_drag_begin), color_button);
584 g_signal_connect (color_button, "drag_data_received",
585 G_CALLBACK (gtk_color_button_drag_data_received), color_button);
586 g_signal_connect (color_button, "drag_data_get",
587 G_CALLBACK (gtk_color_button_drag_data_get), color_button);
589 gtk_widget_pop_composite_child ();
593 gtk_color_button_finalize (GObject *object)
595 GtkColorButton *color_button = GTK_COLOR_BUTTON (object);
597 if (color_button->priv->cs_dialog != NULL)
598 gtk_widget_destroy (color_button->priv->cs_dialog);
599 color_button->priv->cs_dialog = NULL;
601 if (color_button->priv->pixbuf != NULL)
602 g_object_unref (color_button->priv->pixbuf);
603 color_button->priv->pixbuf = NULL;
605 g_free (color_button->priv->title);
606 color_button->priv->title = NULL;
608 G_OBJECT_CLASS (gtk_color_button_parent_class)->finalize (object);
613 * gtk_color_button_new:
615 * Creates a new color button. This returns a widget in the form of
616 * a small button containing a swatch representing the current selected
617 * color. When the button is clicked, a color-selection dialog will open,
618 * allowing the user to select a color. The swatch will be updated to reflect
619 * the new color when the user finishes.
621 * Returns: a new color button.
626 gtk_color_button_new (void)
628 return g_object_new (GTK_TYPE_COLOR_BUTTON, NULL);
632 * gtk_color_button_new_with_color:
633 * @color: A #GdkColor to set the current color with.
635 * Creates a new color button.
637 * Returns: a new color button.
642 gtk_color_button_new_with_color (const GdkColor *color)
644 return g_object_new (GTK_TYPE_COLOR_BUTTON, "color", color, NULL);
648 dialog_ok_clicked (GtkWidget *widget,
651 GtkColorButton *color_button = GTK_COLOR_BUTTON (data);
652 GtkColorSelection *color_selection;
654 color_selection = GTK_COLOR_SELECTION (GTK_COLOR_SELECTION_DIALOG (color_button->priv->cs_dialog)->colorsel);
656 gtk_color_selection_get_current_color (color_selection, &color_button->priv->color);
657 color_button->priv->alpha = gtk_color_selection_get_current_alpha (color_selection);
659 if (color_button->priv->pixbuf != NULL)
660 g_object_unref (color_button->priv->pixbuf);
661 color_button->priv->pixbuf = NULL;
663 gtk_widget_hide (color_button->priv->cs_dialog);
665 gtk_widget_queue_draw (color_button->priv->draw_area);
667 g_signal_emit (color_button, color_button_signals[COLOR_SET], 0);
669 g_object_freeze_notify (G_OBJECT (color_button));
670 g_object_notify (G_OBJECT (color_button), "color");
671 g_object_notify (G_OBJECT (color_button), "alpha");
672 g_object_thaw_notify (G_OBJECT (color_button));
676 dialog_destroy (GtkWidget *widget,
679 GtkColorButton *color_button = GTK_COLOR_BUTTON (data);
681 color_button->priv->cs_dialog = NULL;
687 dialog_cancel_clicked (GtkWidget *widget,
690 GtkColorButton *color_button = GTK_COLOR_BUTTON (data);
692 gtk_widget_hide (color_button->priv->cs_dialog);
696 gtk_color_button_clicked (GtkButton *button)
698 GtkColorButton *color_button = GTK_COLOR_BUTTON (button);
699 GtkColorSelectionDialog *color_dialog;
701 /* if dialog already exists, make sure it's shown and raised */
702 if (!color_button->priv->cs_dialog)
704 /* Create the dialog and connects its buttons */
707 parent = gtk_widget_get_toplevel (GTK_WIDGET (color_button));
709 color_button->priv->cs_dialog = gtk_color_selection_dialog_new (color_button->priv->title);
711 color_dialog = GTK_COLOR_SELECTION_DIALOG (color_button->priv->cs_dialog);
714 gtk_window_set_transient_for (GTK_WINDOW (color_dialog),
715 GTK_WINDOW (parent));
717 g_signal_connect (color_dialog->ok_button, "clicked",
718 G_CALLBACK (dialog_ok_clicked), color_button);
719 g_signal_connect (color_dialog->cancel_button, "clicked",
720 G_CALLBACK (dialog_cancel_clicked), color_button);
721 g_signal_connect (color_dialog, "destroy",
722 G_CALLBACK (dialog_destroy), color_button);
724 /* If there is a grabbed window, set new dialog as modal */
725 if (gtk_grab_get_current ())
726 gtk_window_set_modal (GTK_WINDOW (color_button->priv->cs_dialog),TRUE);
729 color_dialog = GTK_COLOR_SELECTION_DIALOG (color_button->priv->cs_dialog);
731 gtk_color_selection_set_has_opacity_control (GTK_COLOR_SELECTION (color_dialog->colorsel),
732 color_button->priv->use_alpha);
734 gtk_color_selection_set_previous_color (GTK_COLOR_SELECTION (color_dialog->colorsel),
735 &color_button->priv->color);
736 gtk_color_selection_set_previous_alpha (GTK_COLOR_SELECTION (color_dialog->colorsel),
737 color_button->priv->alpha);
739 gtk_color_selection_set_current_color (GTK_COLOR_SELECTION (color_dialog->colorsel),
740 &color_button->priv->color);
741 gtk_color_selection_set_current_alpha (GTK_COLOR_SELECTION (color_dialog->colorsel),
742 color_button->priv->alpha);
744 gtk_window_present (GTK_WINDOW (color_button->priv->cs_dialog));
748 * gtk_color_button_set_color:
749 * @color_button: a #GtkColorButton.
750 * @color: A #GdkColor to set the current color with.
752 * Sets the current color to be @color.
757 gtk_color_button_set_color (GtkColorButton *color_button,
758 const GdkColor *color)
760 g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button));
761 g_return_if_fail (color != NULL);
763 color_button->priv->color.red = color->red;
764 color_button->priv->color.green = color->green;
765 color_button->priv->color.blue = color->blue;
767 if (color_button->priv->pixbuf != NULL)
768 g_object_unref (color_button->priv->pixbuf);
769 color_button->priv->pixbuf = NULL;
771 gtk_widget_queue_draw (color_button->priv->draw_area);
773 g_object_notify (G_OBJECT (color_button), "color");
778 * gtk_color_button_set_alpha:
779 * @color_button: a #GtkColorButton.
780 * @alpha: an integer between 0 and 65535.
782 * Sets the current opacity to be @alpha.
787 gtk_color_button_set_alpha (GtkColorButton *color_button,
790 g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button));
792 color_button->priv->alpha = alpha;
794 if (color_button->priv->pixbuf != NULL)
795 g_object_unref (color_button->priv->pixbuf);
796 color_button->priv->pixbuf = NULL;
798 gtk_widget_queue_draw (color_button->priv->draw_area);
800 g_object_notify (G_OBJECT (color_button), "alpha");
804 * gtk_color_button_get_color:
805 * @color_button: a #GtkColorButton.
806 * @color: a #GdkColor to fill in with the current color.
808 * Sets @color to be the current color in the #GtkColorButton widget.
813 gtk_color_button_get_color (GtkColorButton *color_button,
816 g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button));
818 color->red = color_button->priv->color.red;
819 color->green = color_button->priv->color.green;
820 color->blue = color_button->priv->color.blue;
824 * gtk_color_button_get_alpha:
825 * @color_button: a #GtkColorButton.
827 * Returns the current alpha value.
829 * Return value: an integer between 0 and 65535.
834 gtk_color_button_get_alpha (GtkColorButton *color_button)
836 g_return_val_if_fail (GTK_IS_COLOR_BUTTON (color_button), 0);
838 return color_button->priv->alpha;
842 * gtk_color_button_set_use_alpha:
843 * @color_button: a #GtkColorButton.
844 * @use_alpha: %TRUE if color button should use alpha channel, %FALSE if not.
846 * Sets whether or not the color button should use the alpha channel.
851 gtk_color_button_set_use_alpha (GtkColorButton *color_button,
854 g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button));
856 use_alpha = (use_alpha != FALSE);
858 if (color_button->priv->use_alpha != use_alpha)
860 color_button->priv->use_alpha = use_alpha;
862 render (color_button);
863 gtk_widget_queue_draw (color_button->priv->draw_area);
865 g_object_notify (G_OBJECT (color_button), "use-alpha");
870 * gtk_color_button_get_use_alpha:
871 * @color_button: a #GtkColorButton.
873 * Does the color selection dialog use the alpha channel?
875 * Returns: %TRUE if the color sample uses alpha channel, %FALSE if not.
880 gtk_color_button_get_use_alpha (GtkColorButton *color_button)
882 g_return_val_if_fail (GTK_IS_COLOR_BUTTON (color_button), FALSE);
884 return color_button->priv->use_alpha;
889 * gtk_color_button_set_title:
890 * @color_button: a #GtkColorButton
891 * @title: String containing new window title.
893 * Sets the title for the color selection dialog.
898 gtk_color_button_set_title (GtkColorButton *color_button,
903 g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button));
905 old_title = color_button->priv->title;
906 color_button->priv->title = g_strdup (title);
909 if (color_button->priv->cs_dialog)
910 gtk_window_set_title (GTK_WINDOW (color_button->priv->cs_dialog),
911 color_button->priv->title);
913 g_object_notify (G_OBJECT (color_button), "title");
917 * gtk_color_button_get_title:
918 * @color_button: a #GtkColorButton
920 * Gets the title of the color selection dialog.
922 * Returns: An internal string, do not free the return value
926 G_CONST_RETURN gchar *
927 gtk_color_button_get_title (GtkColorButton *color_button)
929 g_return_val_if_fail (GTK_IS_COLOR_BUTTON (color_button), NULL);
931 return color_button->priv->title;
935 gtk_color_button_set_property (GObject *object,
940 GtkColorButton *color_button = GTK_COLOR_BUTTON (object);
945 gtk_color_button_set_use_alpha (color_button, g_value_get_boolean (value));
948 gtk_color_button_set_title (color_button, g_value_get_string (value));
951 gtk_color_button_set_color (color_button, g_value_get_boxed (value));
954 gtk_color_button_set_alpha (color_button, g_value_get_uint (value));
957 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
963 gtk_color_button_get_property (GObject *object,
968 GtkColorButton *color_button = GTK_COLOR_BUTTON (object);
974 g_value_set_boolean (value, gtk_color_button_get_use_alpha (color_button));
977 g_value_set_string (value, gtk_color_button_get_title (color_button));
980 gtk_color_button_get_color (color_button, &color);
981 g_value_set_boxed (value, &color);
984 g_value_set_uint (value, gtk_color_button_get_alpha (color_button));
987 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
992 #define __GTK_COLOR_BUTTON_C__
993 #include "gtkaliasdef.c"