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/.
31 #define GDK_DISABLE_DEPRECATION_WARNINGS
34 #include "gtkcolorbutton.h"
36 #include "gtkbutton.h"
38 #include "gtkalignment.h"
39 #include "gtkcolorchooser.h"
40 #include "gtkcolorchooserdialog.h"
42 #include "gtkdrawingarea.h"
44 #include "gtkmarshalers.h"
45 #include "gtkprivate.h"
50 * SECTION:gtkcolorbutton
51 * @Short_description: A button to launch a color selection dialog
52 * @Title: GtkColorButton
53 * @See_also: #GtkColorSelectionDialog, #GtkFontButton
55 * The #GtkColorButton is a button which displays the currently selected
56 * color an allows to open a color selection dialog to change the color.
57 * It is suitable widget for selecting a color in a preference dialog.
61 /* Size of checks and gray levels for alpha compositing checkerboard */
63 #define CHECK_DARK (1.0 / 3.0)
64 #define CHECK_LIGHT (2.0 / 3.0)
67 struct _GtkColorButtonPrivate
69 GtkWidget *draw_area; /* Widget where we draw the color sample */
70 GtkWidget *cs_dialog; /* Color selection dialog */
72 gchar *title; /* Title for the color selection window */
75 guint use_alpha : 1; /* Use alpha or not */
97 static void gtk_color_button_finalize (GObject *object);
98 static void gtk_color_button_set_property (GObject *object,
102 static void gtk_color_button_get_property (GObject *object,
107 /* gtkwidget signals */
108 static void gtk_color_button_state_changed (GtkWidget *widget,
109 GtkStateType previous_state);
111 /* gtkbutton signals */
112 static void gtk_color_button_clicked (GtkButton *button);
114 /* source side drag signals */
115 static void gtk_color_button_drag_begin (GtkWidget *widget,
116 GdkDragContext *context,
118 static void gtk_color_button_drag_data_get (GtkWidget *widget,
119 GdkDragContext *context,
120 GtkSelectionData *selection_data,
123 GtkColorButton *button);
125 /* target side drag signals */
126 static void gtk_color_button_drag_data_received (GtkWidget *widget,
127 GdkDragContext *context,
130 GtkSelectionData *selection_data,
133 GtkColorButton *button);
136 static guint color_button_signals[LAST_SIGNAL] = { 0 };
138 static const GtkTargetEntry drop_types[] = { { "application/x-color", 0, 0 } };
140 static void gtk_color_button_iface_init (GtkColorChooserInterface *iface);
142 G_DEFINE_TYPE_WITH_CODE (GtkColorButton, gtk_color_button, GTK_TYPE_BUTTON,
143 G_IMPLEMENT_INTERFACE (GTK_TYPE_COLOR_CHOOSER,
144 gtk_color_button_iface_init))
147 gtk_color_button_class_init (GtkColorButtonClass *klass)
149 GObjectClass *gobject_class;
150 GtkWidgetClass *widget_class;
151 GtkButtonClass *button_class;
153 gobject_class = G_OBJECT_CLASS (klass);
154 widget_class = GTK_WIDGET_CLASS (klass);
155 button_class = GTK_BUTTON_CLASS (klass);
157 gobject_class->get_property = gtk_color_button_get_property;
158 gobject_class->set_property = gtk_color_button_set_property;
159 gobject_class->finalize = gtk_color_button_finalize;
160 widget_class->state_changed = gtk_color_button_state_changed;
161 button_class->clicked = gtk_color_button_clicked;
162 klass->color_set = NULL;
165 * GtkColorButton:use-alpha:
167 * If this property is set to %TRUE, the color swatch on the button is
168 * rendered against a checkerboard background to show its opacity and
169 * the opacity slider is displayed in the color selection dialog.
173 g_object_class_install_property (gobject_class,
175 g_param_spec_boolean ("use-alpha", P_("Use alpha"),
176 P_("Whether to give the color an alpha value"),
178 GTK_PARAM_READWRITE));
181 * GtkColorButton:title:
183 * The title of the color selection dialog
187 g_object_class_install_property (gobject_class,
189 g_param_spec_string ("title",
191 P_("The title of the color selection dialog"),
193 GTK_PARAM_READWRITE));
196 * GtkColorButton:color:
198 * The selected color.
202 * Deprecated: 3.4: Use #GtkColorButton:rgba instead.
204 g_object_class_install_property (gobject_class,
206 g_param_spec_boxed ("color",
208 P_("The selected color"),
210 GTK_PARAM_READWRITE | G_PARAM_DEPRECATED));
213 * GtkColorButton:alpha:
215 * The selected opacity value (0 fully transparent, 65535 fully opaque).
219 g_object_class_install_property (gobject_class,
221 g_param_spec_uint ("alpha",
223 P_("The selected opacity value (0 fully transparent, 65535 fully opaque)"),
225 GTK_PARAM_READWRITE));
228 * GtkColorButton:rgba:
234 g_object_class_install_property (gobject_class,
236 g_param_spec_boxed ("rgba",
237 P_("Current RGBA Color"),
238 P_("The selected RGBA color"),
240 GTK_PARAM_READWRITE));
244 * GtkColorButton::color-set:
245 * @widget: the object which received the signal.
247 * The ::color-set signal is emitted when the user selects a color.
248 * When handling this signal, use gtk_color_button_get_color() and
249 * gtk_color_button_get_alpha() (or gtk_color_button_get_rgba()) to
250 * find out which color was just selected.
252 * Note that this signal is only emitted when the <emphasis>user</emphasis>
253 * changes the color. If you need to react to programmatic color changes
254 * as well, use the notify::color signal.
258 color_button_signals[COLOR_SET] = g_signal_new (I_("color-set"),
259 G_TYPE_FROM_CLASS (gobject_class),
261 G_STRUCT_OFFSET (GtkColorButtonClass, color_set),
263 _gtk_marshal_VOID__VOID,
266 g_type_class_add_private (gobject_class, sizeof (GtkColorButtonPrivate));
270 gtk_color_button_has_alpha (GtkColorButton *button)
272 return button->priv->use_alpha && button->priv->rgba.alpha < 1;
275 static cairo_pattern_t *
276 gtk_color_button_get_checkered (void)
278 /* need to respect pixman's stride being a multiple of 4 */
279 static unsigned char data[8] = { 0xFF, 0x00, 0x00, 0x00,
280 0x00, 0xFF, 0x00, 0x00 };
281 static cairo_surface_t *checkered = NULL;
282 cairo_pattern_t *pattern;
284 if (checkered == NULL)
286 checkered = cairo_image_surface_create_for_data (data,
291 pattern = cairo_pattern_create_for_surface (checkered);
292 cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
293 cairo_pattern_set_filter (pattern, CAIRO_FILTER_NEAREST);
298 /* Handle exposure events for the color picker's drawing area */
300 gtk_color_button_draw_cb (GtkWidget *widget,
304 GtkColorButton *button = GTK_COLOR_BUTTON (data);
305 cairo_pattern_t *checkered;
307 if (gtk_color_button_has_alpha (button))
309 cairo_set_source_rgb (cr, CHECK_DARK, CHECK_DARK, CHECK_DARK);
312 cairo_set_source_rgb (cr, CHECK_LIGHT, CHECK_LIGHT, CHECK_LIGHT);
313 cairo_scale (cr, CHECK_SIZE, CHECK_SIZE);
315 checkered = gtk_color_button_get_checkered ();
316 cairo_mask (cr, checkered);
317 cairo_pattern_destroy (checkered);
319 gdk_cairo_set_source_rgba (cr, &button->priv->rgba);
323 cairo_set_source_rgb (cr,
324 button->priv->rgba.red,
325 button->priv->rgba.green,
326 button->priv->rgba.blue);
331 if (!gtk_widget_is_sensitive (GTK_WIDGET (button)))
333 GtkStyleContext *context;
336 context = gtk_widget_get_style_context (widget);
337 gtk_style_context_get_background_color (context, GTK_STATE_FLAG_INSENSITIVE, &color);
339 gdk_cairo_set_source_rgba (cr, &color);
340 checkered = gtk_color_button_get_checkered ();
341 cairo_mask (cr, checkered);
342 cairo_pattern_destroy (checkered);
349 gtk_color_button_state_changed (GtkWidget *widget,
350 GtkStateType previous_state)
352 gtk_widget_queue_draw (widget);
356 gtk_color_button_drag_data_received (GtkWidget *widget,
357 GdkDragContext *context,
360 GtkSelectionData *selection_data,
363 GtkColorButton *button)
368 length = gtk_selection_data_get_length (selection_data);
373 /* We accept drops with the wrong format, since the KDE color
374 * chooser incorrectly drops application/x-color with format 8.
378 g_warning ("%s: Received invalid color data", G_STRFUNC);
383 dropped = (guint16 *) gtk_selection_data_get_data (selection_data);
385 button->priv->rgba.red = dropped[0] / 65535.;
386 button->priv->rgba.green = dropped[1] / 65535.;
387 button->priv->rgba.blue = dropped[2] / 65535.;
388 button->priv->rgba.alpha = dropped[3] / 65535.;
390 gtk_widget_queue_draw (button->priv->draw_area);
392 g_signal_emit (button, color_button_signals[COLOR_SET], 0);
394 g_object_freeze_notify (G_OBJECT (button));
395 g_object_notify (G_OBJECT (button), "color");
396 g_object_notify (G_OBJECT (button), "alpha");
397 g_object_notify (G_OBJECT (button), "rgba");
398 g_object_thaw_notify (G_OBJECT (button));
402 set_color_icon (GdkDragContext *context,
405 cairo_surface_t *surface;
408 surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24,
410 cr = cairo_create (surface);
412 gdk_cairo_set_source_rgba (cr, rgba);
415 gtk_drag_set_icon_surface (context, surface);
418 cairo_surface_destroy (surface);
422 gtk_color_button_drag_begin (GtkWidget *widget,
423 GdkDragContext *context,
426 GtkColorButton *button = data;
428 set_color_icon (context, &button->priv->rgba);
432 gtk_color_button_drag_data_get (GtkWidget *widget,
433 GdkDragContext *context,
434 GtkSelectionData *selection_data,
437 GtkColorButton *button)
441 dropped[0] = (guint16) (button->priv->rgba.red * 65535);
442 dropped[1] = (guint16) (button->priv->rgba.green * 65535);
443 dropped[2] = (guint16) (button->priv->rgba.blue * 65535);
444 dropped[3] = (guint16) (button->priv->rgba.alpha * 65535);
446 gtk_selection_data_set (selection_data,
447 gtk_selection_data_get_target (selection_data),
448 16, (guchar *)dropped, 8);
452 gtk_color_button_init (GtkColorButton *button)
454 GtkWidget *alignment;
459 /* Create the widgets */
460 button->priv = G_TYPE_INSTANCE_GET_PRIVATE (button,
461 GTK_TYPE_COLOR_BUTTON,
462 GtkColorButtonPrivate);
464 gtk_widget_push_composite_child ();
466 alignment = gtk_alignment_new (0.5, 0.5, 0.5, 1.0);
467 gtk_container_set_border_width (GTK_CONTAINER (alignment), 1);
468 gtk_container_add (GTK_CONTAINER (button), alignment);
469 gtk_widget_show (alignment);
471 frame = gtk_frame_new (NULL);
472 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_OUT);
473 gtk_container_add (GTK_CONTAINER (alignment), frame);
474 gtk_widget_show (frame);
476 /* Just some widget we can hook to expose-event on */
477 button->priv->draw_area = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
479 layout = gtk_widget_create_pango_layout (GTK_WIDGET (button), "Black");
480 pango_layout_get_pixel_extents (layout, NULL, &rect);
481 g_object_unref (layout);
483 gtk_widget_set_size_request (button->priv->draw_area, rect.width - 2, rect.height - 2);
484 g_signal_connect (button->priv->draw_area, "draw",
485 G_CALLBACK (gtk_color_button_draw_cb), button);
486 gtk_container_add (GTK_CONTAINER (frame), button->priv->draw_area);
487 gtk_widget_show (button->priv->draw_area);
489 button->priv->title = g_strdup (_("Pick a Color")); /* default title */
491 /* Start with opaque black, alpha disabled */
492 button->priv->rgba.red = 0;
493 button->priv->rgba.green = 0;
494 button->priv->rgba.blue = 0;
495 button->priv->rgba.alpha = 1;
496 button->priv->use_alpha = FALSE;
498 gtk_drag_dest_set (GTK_WIDGET (button),
499 GTK_DEST_DEFAULT_MOTION |
500 GTK_DEST_DEFAULT_HIGHLIGHT |
501 GTK_DEST_DEFAULT_DROP,
502 drop_types, 1, GDK_ACTION_COPY);
503 gtk_drag_source_set (GTK_WIDGET (button),
504 GDK_BUTTON1_MASK|GDK_BUTTON3_MASK,
507 g_signal_connect (button, "drag-begin",
508 G_CALLBACK (gtk_color_button_drag_begin), button);
509 g_signal_connect (button, "drag-data-received",
510 G_CALLBACK (gtk_color_button_drag_data_received), button);
511 g_signal_connect (button, "drag-data-get",
512 G_CALLBACK (gtk_color_button_drag_data_get), button);
514 gtk_widget_pop_composite_child ();
518 gtk_color_button_finalize (GObject *object)
520 GtkColorButton *button = GTK_COLOR_BUTTON (object);
522 if (button->priv->cs_dialog != NULL)
523 gtk_widget_destroy (button->priv->cs_dialog);
524 button->priv->cs_dialog = NULL;
526 g_free (button->priv->title);
527 button->priv->title = NULL;
529 G_OBJECT_CLASS (gtk_color_button_parent_class)->finalize (object);
534 * gtk_color_button_new:
536 * Creates a new color button.
538 * This returns a widget in the form of a small button containing
539 * a swatch representing the current selected color. When the button
540 * is clicked, a color-selection dialog will open, allowing the user
541 * to select a color. The swatch will be updated to reflect the new
542 * color when the user finishes.
544 * Returns: a new color button
549 gtk_color_button_new (void)
551 return g_object_new (GTK_TYPE_COLOR_BUTTON, NULL);
555 * gtk_color_button_new_with_color:
556 * @color: A #GdkColor to set the current color with
558 * Creates a new color button.
560 * Returns: a new color button
564 * Deprecated: 3.4: Use gtk_color_button_new_with_rgba() instead.
567 gtk_color_button_new_with_color (const GdkColor *color)
569 return g_object_new (GTK_TYPE_COLOR_BUTTON, "color", color, NULL);
573 * gtk_color_button_new_with_rgba:
574 * @rgba: A #GdkRGBA to set the current color with
576 * Creates a new color button.
578 * Returns: a new color button
583 gtk_color_button_new_with_rgba (const GdkRGBA *rgba)
585 return g_object_new (GTK_TYPE_COLOR_BUTTON, "rgba", rgba, NULL);
589 dialog_destroy (GtkWidget *widget,
592 GtkColorButton *button = GTK_COLOR_BUTTON (data);
594 button->priv->cs_dialog = NULL;
600 dialog_response (GtkDialog *dialog,
604 if (response == GTK_RESPONSE_CANCEL)
605 gtk_widget_hide (GTK_WIDGET (dialog));
606 else if (response == GTK_RESPONSE_OK)
608 GtkColorButton *button = GTK_COLOR_BUTTON (data);
610 gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (dialog),
611 &button->priv->rgba);
613 gtk_widget_hide (GTK_WIDGET (dialog));
615 gtk_widget_queue_draw (button->priv->draw_area);
617 g_signal_emit (button, color_button_signals[COLOR_SET], 0);
619 g_object_freeze_notify (G_OBJECT (button));
620 g_object_notify (G_OBJECT (button), "color");
621 g_object_notify (G_OBJECT (button), "alpha");
622 g_object_notify (G_OBJECT (button), "rgba");
623 g_object_thaw_notify (G_OBJECT (button));
628 gtk_color_button_clicked (GtkButton *b)
630 GtkColorButton *button = GTK_COLOR_BUTTON (b);
633 /* if dialog already exists, make sure it's shown and raised */
634 if (!button->priv->cs_dialog)
636 /* Create the dialog and connects its buttons */
639 parent = gtk_widget_get_toplevel (GTK_WIDGET (button));
641 button->priv->cs_dialog = dialog = gtk_color_chooser_dialog_new (button->priv->title, NULL);
643 if (gtk_widget_is_toplevel (parent) && GTK_IS_WINDOW (parent))
645 if (GTK_WINDOW (parent) != gtk_window_get_transient_for (GTK_WINDOW (dialog)))
646 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
648 gtk_window_set_modal (GTK_WINDOW (dialog),
649 gtk_window_get_modal (GTK_WINDOW (parent)));
652 g_signal_connect (dialog, "response",
653 G_CALLBACK (dialog_response), button);
654 g_signal_connect (dialog, "destroy",
655 G_CALLBACK (dialog_destroy), button);
658 gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER (button->priv->cs_dialog),
659 button->priv->use_alpha);
661 gtk_window_present (GTK_WINDOW (button->priv->cs_dialog));
665 * gtk_color_button_set_color:
666 * @button: a #GtkColorButton
667 * @color: A #GdkColor to set the current color with
669 * Sets the current color to be @color.
673 * Deprecated: Use gtk_color_chooser_set_rgba() instead.
676 gtk_color_button_set_color (GtkColorButton *button,
677 const GdkColor *color)
679 g_return_if_fail (GTK_IS_COLOR_BUTTON (button));
680 g_return_if_fail (color != NULL);
682 button->priv->rgba.red = color->red / 65535.;
683 button->priv->rgba.green = color->green / 65535.;
684 button->priv->rgba.blue = color->blue / 65535.;
686 gtk_widget_queue_draw (button->priv->draw_area);
688 g_object_notify (G_OBJECT (button), "color");
689 g_object_notify (G_OBJECT (button), "rgba");
694 * gtk_color_button_set_alpha:
695 * @button: a #GtkColorButton
696 * @alpha: an integer between 0 and 65535
698 * Sets the current opacity to be @alpha.
702 * Deprecated: 3.4: Use gtk_color_chooser_set_rgba() instead.
705 gtk_color_button_set_alpha (GtkColorButton *button,
708 g_return_if_fail (GTK_IS_COLOR_BUTTON (button));
710 button->priv->rgba.alpha = alpha / 65535.;
712 gtk_widget_queue_draw (button->priv->draw_area);
714 g_object_notify (G_OBJECT (button), "alpha");
715 g_object_notify (G_OBJECT (button), "rgba");
719 * gtk_color_button_get_color:
720 * @button: a #GtkColorButton
721 * @color: (out): a #GdkColor to fill in with the current color
723 * Sets @color to be the current color in the #GtkColorButton widget.
727 * Deprecated: 3.4: Use gtk_color_chooser_get_rgba() instead.
730 gtk_color_button_get_color (GtkColorButton *button,
733 g_return_if_fail (GTK_IS_COLOR_BUTTON (button));
735 color->red = (guint16) (button->priv->rgba.red * 65535);
736 color->green = (guint16) (button->priv->rgba.green * 65535);
737 color->blue = (guint16) (button->priv->rgba.blue * 65535);
741 * gtk_color_button_get_alpha:
742 * @button: a #GtkColorButton
744 * Returns the current alpha value.
746 * Return value: an integer between 0 and 65535
750 * Deprecated: 3.4: Use gtk_color_chooser_get_rgba() instead.
753 gtk_color_button_get_alpha (GtkColorButton *button)
755 g_return_val_if_fail (GTK_IS_COLOR_BUTTON (button), 0);
757 return (guint16) (button->priv->rgba.alpha * 65535);
761 * gtk_color_button_set_rgba:
762 * @button: a #GtkColorButton
763 * @rgba: a #GdkRGBA to set the current color with
765 * Sets the current color to be @rgba.
769 * Deprecated: 3.4: Use gtk_color_chooser_set_rgba() instead.
772 gtk_color_button_set_rgba (GtkColorButton *button,
775 g_return_if_fail (GTK_IS_COLOR_BUTTON (button));
776 g_return_if_fail (rgba != NULL);
778 button->priv->rgba = *rgba;
779 gtk_widget_queue_draw (button->priv->draw_area);
781 g_object_notify (G_OBJECT (button), "color");
782 g_object_notify (G_OBJECT (button), "alpha");
783 g_object_notify (G_OBJECT (button), "rgba");
787 * gtk_color_button_get_rgba:
788 * @button: a #GtkColorButton
789 * @rgba: (out): a #GdkRGBA to fill in with the current color
791 * Sets @rgba to be the current color in the #GtkColorButton widget.
795 * Deprecated: 3.4: Use gtk_color_chooser_get_rgba() instead.
798 gtk_color_button_get_rgba (GtkColorButton *button,
801 g_return_if_fail (GTK_IS_COLOR_BUTTON (button));
802 g_return_if_fail (rgba != NULL);
804 *rgba = button->priv->rgba;
808 * gtk_color_button_set_use_alpha:
809 * @button: a #GtkColorButton
810 * @use_alpha: %TRUE if color button should use alpha channel, %FALSE if not
812 * Sets whether or not the color button should use the alpha channel.
816 * Deprecated: 3.4: Use gtk_color_chooser_set_use_alpha() instead.
819 gtk_color_button_set_use_alpha (GtkColorButton *button,
822 g_return_if_fail (GTK_IS_COLOR_BUTTON (button));
824 use_alpha = (use_alpha != FALSE);
826 if (button->priv->use_alpha != use_alpha)
828 button->priv->use_alpha = use_alpha;
830 gtk_widget_queue_draw (button->priv->draw_area);
832 g_object_notify (G_OBJECT (button), "use-alpha");
837 * gtk_color_button_get_use_alpha:
838 * @button: a #GtkColorButton
840 * Does the color selection dialog use the alpha channel ?
842 * Returns: %TRUE if the color sample uses alpha channel, %FALSE if not
846 * Deprecated: 3.4: Use gtk_color_chooser_get_use_alpha() instead.
849 gtk_color_button_get_use_alpha (GtkColorButton *button)
851 g_return_val_if_fail (GTK_IS_COLOR_BUTTON (button), FALSE);
853 return button->priv->use_alpha;
858 * gtk_color_button_set_title:
859 * @button: a #GtkColorButton
860 * @title: String containing new window title
862 * Sets the title for the color selection dialog.
867 gtk_color_button_set_title (GtkColorButton *button,
872 g_return_if_fail (GTK_IS_COLOR_BUTTON (button));
874 old_title = button->priv->title;
875 button->priv->title = g_strdup (title);
878 if (button->priv->cs_dialog)
879 gtk_window_set_title (GTK_WINDOW (button->priv->cs_dialog),
880 button->priv->title);
882 g_object_notify (G_OBJECT (button), "title");
886 * gtk_color_button_get_title:
887 * @button: a #GtkColorButton
889 * Gets the title of the color selection dialog.
891 * Returns: An internal string, do not free the return value
896 gtk_color_button_get_title (GtkColorButton *button)
898 g_return_val_if_fail (GTK_IS_COLOR_BUTTON (button), NULL);
900 return button->priv->title;
904 gtk_color_button_set_property (GObject *object,
909 GtkColorButton *button = GTK_COLOR_BUTTON (object);
914 gtk_color_button_set_use_alpha (button, g_value_get_boolean (value));
917 gtk_color_button_set_title (button, g_value_get_string (value));
924 color = g_value_get_boxed (value);
926 rgba.red = color->red / 65535.0;
927 rgba.green = color->green / 65535.0;
928 rgba.blue = color->blue / 65535.0;
931 gtk_color_button_set_rgba (button, &rgba);
935 gtk_color_button_set_alpha (button, g_value_get_uint (value));
938 gtk_color_button_set_rgba (button, g_value_get_boxed (value));
941 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
947 gtk_color_button_get_property (GObject *object,
952 GtkColorButton *button = GTK_COLOR_BUTTON (object);
957 g_value_set_boolean (value, gtk_color_button_get_use_alpha (button));
960 g_value_set_string (value, gtk_color_button_get_title (button));
967 gtk_color_button_get_rgba (button, &rgba);
969 color.red = (guint16) (rgba.red * 65535 + 0.5);
970 color.green = (guint16) (rgba.green * 65535 + 0.5);
971 color.blue = (guint16) (rgba.blue * 65535 + 0.5);
973 g_value_set_boxed (value, &color);
977 g_value_set_uint (value, gtk_color_button_get_alpha (button));
983 gtk_color_button_get_rgba (button, &rgba);
984 g_value_set_boxed (value, &rgba);
988 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
994 gtk_color_button_add_palette (GtkColorChooser *chooser,
996 gint colors_per_line,
1000 GtkColorButton *button = GTK_COLOR_BUTTON (chooser);
1002 if (button->priv->cs_dialog)
1003 gtk_color_chooser_add_palette (GTK_COLOR_CHOOSER (button->priv->cs_dialog),
1004 horizontal, colors_per_line, n_colors, colors);
1007 typedef void (* get_rgba) (GtkColorChooser *, GdkRGBA *);
1008 typedef void (* set_rgba) (GtkColorChooser *, const GdkRGBA *);
1011 gtk_color_button_iface_init (GtkColorChooserInterface *iface)
1013 iface->get_rgba = (get_rgba)gtk_color_button_get_rgba;
1014 iface->set_rgba = (set_rgba)gtk_color_button_set_rgba;
1015 iface->add_palette = gtk_color_button_add_palette;