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"
35 #include "gtkbutton.h"
37 #include "gtkalignment.h"
38 #include "gtkcolorsel.h"
39 #include "gtkcolorseldialog.h"
41 #include "gtkdrawingarea.h"
43 #include "gtkmarshalers.h"
44 #include "gtkprivate.h"
49 * SECTION:gtkcolorbutton
50 * @Short_description: A button to launch a color selection dialog
51 * @Title: GtkColorButton
52 * @See_also: #GtkColorSelectionDialog, #GtkFontButton
54 * The #GtkColorButton is a button which displays the currently selected
55 * color an allows to open a color selection dialog to change the color.
56 * It is suitable widget for selecting a color in a preference dialog.
60 /* Size of checks and gray levels for alpha compositing checkerboard */
62 #define CHECK_DARK (1.0 / 3.0)
63 #define CHECK_LIGHT (2.0 / 3.0)
66 struct _GtkColorButtonPrivate
68 GtkWidget *draw_area; /* Widget where we draw the color sample */
69 GtkWidget *cs_dialog; /* Color selection dialog */
71 gchar *title; /* Title for the color selection window */
74 guint use_alpha : 1; /* Use alpha or not */
96 static void gtk_color_button_finalize (GObject *object);
97 static void gtk_color_button_set_property (GObject *object,
101 static void gtk_color_button_get_property (GObject *object,
106 /* gtkwidget signals */
107 static void gtk_color_button_state_changed (GtkWidget *widget,
108 GtkStateType previous_state);
110 /* gtkbutton signals */
111 static void gtk_color_button_clicked (GtkButton *button);
113 /* source side drag signals */
114 static void gtk_color_button_drag_begin (GtkWidget *widget,
115 GdkDragContext *context,
117 static void gtk_color_button_drag_data_get (GtkWidget *widget,
118 GdkDragContext *context,
119 GtkSelectionData *selection_data,
122 GtkColorButton *color_button);
124 /* target side drag signals */
125 static void gtk_color_button_drag_data_received (GtkWidget *widget,
126 GdkDragContext *context,
129 GtkSelectionData *selection_data,
132 GtkColorButton *color_button);
135 static guint color_button_signals[LAST_SIGNAL] = { 0 };
137 static const GtkTargetEntry drop_types[] = { { "application/x-color", 0, 0 } };
139 G_DEFINE_TYPE (GtkColorButton, gtk_color_button, GTK_TYPE_BUTTON)
142 gtk_color_button_class_init (GtkColorButtonClass *klass)
144 GObjectClass *gobject_class;
145 GtkWidgetClass *widget_class;
146 GtkButtonClass *button_class;
148 gobject_class = G_OBJECT_CLASS (klass);
149 widget_class = GTK_WIDGET_CLASS (klass);
150 button_class = GTK_BUTTON_CLASS (klass);
152 gobject_class->get_property = gtk_color_button_get_property;
153 gobject_class->set_property = gtk_color_button_set_property;
154 gobject_class->finalize = gtk_color_button_finalize;
155 widget_class->state_changed = gtk_color_button_state_changed;
156 button_class->clicked = gtk_color_button_clicked;
157 klass->color_set = NULL;
160 * GtkColorButton:use-alpha:
162 * If this property is set to %TRUE, the color swatch on the button is rendered against a
163 * checkerboard background to show its opacity and the opacity slider is displayed in the
164 * color selection dialog.
168 g_object_class_install_property (gobject_class,
170 g_param_spec_boolean ("use-alpha", P_("Use alpha"),
171 P_("Whether to give the color an alpha value"),
173 GTK_PARAM_READWRITE));
176 * GtkColorButton:title:
178 * The title of the color selection dialog
182 g_object_class_install_property (gobject_class,
184 g_param_spec_string ("title",
186 P_("The title of the color selection dialog"),
188 GTK_PARAM_READWRITE));
191 * GtkColorButton:color:
193 * The selected color.
197 * Deprecated: 3.4: Use #GtkColorButton:rgba instead.
199 g_object_class_install_property (gobject_class,
201 g_param_spec_boxed ("color",
203 P_("The selected color"),
205 GTK_PARAM_READWRITE | G_PARAM_DEPRECATED));
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:rgba:
229 g_object_class_install_property (gobject_class,
231 g_param_spec_boxed ("rgba",
232 P_("Current RGBA Color"),
233 P_("The selected RGBA color"),
235 GTK_PARAM_READWRITE));
239 * GtkColorButton::color-set:
240 * @widget: the object which received the signal.
242 * The ::color-set signal is emitted when the user selects a color.
243 * When handling this signal, use gtk_color_button_get_color() and
244 * gtk_color_button_get_alpha() (or gtk_color_button_get_rgba()) to
245 * find out which color was just selected.
247 * Note that this signal is only emitted when the <emphasis>user</emphasis>
248 * changes the color. If you need to react to programmatic color changes
249 * as well, use the notify::color signal.
253 color_button_signals[COLOR_SET] = g_signal_new (I_("color-set"),
254 G_TYPE_FROM_CLASS (gobject_class),
256 G_STRUCT_OFFSET (GtkColorButtonClass, color_set),
258 _gtk_marshal_VOID__VOID,
261 g_type_class_add_private (gobject_class, sizeof (GtkColorButtonPrivate));
265 gtk_color_button_has_alpha (GtkColorButton *color_button)
267 return color_button->priv->use_alpha &&
268 color_button->priv->rgba.alpha < 1;
271 static cairo_pattern_t *
272 gtk_color_button_get_checkered (void)
274 /* need to respect pixman's stride being a multiple of 4 */
275 static unsigned char data[8] = { 0xFF, 0x00, 0x00, 0x00,
276 0x00, 0xFF, 0x00, 0x00 };
277 static cairo_surface_t *checkered = NULL;
278 cairo_pattern_t *pattern;
280 if (checkered == NULL)
282 checkered = cairo_image_surface_create_for_data (data,
287 pattern = cairo_pattern_create_for_surface (checkered);
288 cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
289 cairo_pattern_set_filter (pattern, CAIRO_FILTER_NEAREST);
294 /* Handle exposure events for the color picker's drawing area */
296 gtk_color_button_draw_cb (GtkWidget *widget,
300 GtkColorButton *color_button = GTK_COLOR_BUTTON (data);
301 cairo_pattern_t *checkered;
303 if (gtk_color_button_has_alpha (color_button))
305 cairo_set_source_rgb (cr, CHECK_DARK, CHECK_DARK, CHECK_DARK);
308 cairo_set_source_rgb (cr, CHECK_LIGHT, CHECK_LIGHT, CHECK_LIGHT);
309 cairo_scale (cr, CHECK_SIZE, CHECK_SIZE);
311 checkered = gtk_color_button_get_checkered ();
312 cairo_mask (cr, checkered);
313 cairo_pattern_destroy (checkered);
315 gdk_cairo_set_source_rgba (cr, &color_button->priv->rgba);
319 cairo_set_source_rgb (cr,
320 color_button->priv->rgba.red,
321 color_button->priv->rgba.green,
322 color_button->priv->rgba.blue);
327 if (!gtk_widget_is_sensitive (GTK_WIDGET (color_button)))
329 GtkStyleContext *context;
332 context = gtk_widget_get_style_context (widget);
333 gtk_style_context_get_background_color (context, GTK_STATE_FLAG_INSENSITIVE, &color);
335 gdk_cairo_set_source_rgba (cr, &color);
336 checkered = gtk_color_button_get_checkered ();
337 cairo_mask (cr, checkered);
338 cairo_pattern_destroy (checkered);
345 gtk_color_button_state_changed (GtkWidget *widget,
346 GtkStateType previous_state)
348 gtk_widget_queue_draw (widget);
352 gtk_color_button_drag_data_received (GtkWidget *widget,
353 GdkDragContext *context,
356 GtkSelectionData *selection_data,
359 GtkColorButton *color_button)
364 length = gtk_selection_data_get_length (selection_data);
369 /* We accept drops with the wrong format, since the KDE color
370 * chooser incorrectly drops application/x-color with format 8.
374 g_warning ("%s: Received invalid color data", G_STRFUNC);
379 dropped = (guint16 *) gtk_selection_data_get_data (selection_data);
381 color_button->priv->rgba.red = dropped[0] / 65535.;
382 color_button->priv->rgba.green = dropped[1] / 65535.;
383 color_button->priv->rgba.blue = dropped[2] / 65535.;
384 color_button->priv->rgba.alpha = dropped[3] / 65535.;
386 gtk_widget_queue_draw (color_button->priv->draw_area);
388 g_signal_emit (color_button, color_button_signals[COLOR_SET], 0);
390 g_object_freeze_notify (G_OBJECT (color_button));
391 g_object_notify (G_OBJECT (color_button), "color");
392 g_object_notify (G_OBJECT (color_button), "alpha");
393 g_object_notify (G_OBJECT (color_button), "rgba");
394 g_object_thaw_notify (G_OBJECT (color_button));
398 set_color_icon (GdkDragContext *context,
401 cairo_surface_t *surface;
404 surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24,
406 cr = cairo_create (surface);
408 gdk_cairo_set_source_rgba (cr, rgba);
411 gtk_drag_set_icon_surface (context, surface);
414 cairo_surface_destroy (surface);
418 gtk_color_button_drag_begin (GtkWidget *widget,
419 GdkDragContext *context,
422 GtkColorButton *color_button = data;
424 set_color_icon (context, &color_button->priv->rgba);
428 gtk_color_button_drag_data_get (GtkWidget *widget,
429 GdkDragContext *context,
430 GtkSelectionData *selection_data,
433 GtkColorButton *color_button)
437 dropped[0] = (guint16) (color_button->priv->rgba.red * 65535);
438 dropped[1] = (guint16) (color_button->priv->rgba.green * 65535);
439 dropped[2] = (guint16) (color_button->priv->rgba.blue * 65535);
440 dropped[3] = (guint16) (color_button->priv->rgba.alpha * 65535);
442 gtk_selection_data_set (selection_data,
443 gtk_selection_data_get_target (selection_data),
444 16, (guchar *)dropped, 8);
448 gtk_color_button_init (GtkColorButton *color_button)
450 GtkWidget *alignment;
455 /* Create the widgets */
456 color_button->priv = G_TYPE_INSTANCE_GET_PRIVATE (color_button,
457 GTK_TYPE_COLOR_BUTTON,
458 GtkColorButtonPrivate);
460 gtk_widget_push_composite_child ();
462 alignment = gtk_alignment_new (0.5, 0.5, 0.5, 1.0);
463 gtk_container_set_border_width (GTK_CONTAINER (alignment), 1);
464 gtk_container_add (GTK_CONTAINER (color_button), alignment);
465 gtk_widget_show (alignment);
467 frame = gtk_frame_new (NULL);
468 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_OUT);
469 gtk_container_add (GTK_CONTAINER (alignment), frame);
470 gtk_widget_show (frame);
472 /* Just some widget we can hook to expose-event on */
473 color_button->priv->draw_area = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
475 layout = gtk_widget_create_pango_layout (GTK_WIDGET (color_button), "Black");
476 pango_layout_get_pixel_extents (layout, NULL, &rect);
477 g_object_unref (layout);
479 gtk_widget_set_size_request (color_button->priv->draw_area, rect.width - 2, rect.height - 2);
480 g_signal_connect (color_button->priv->draw_area, "draw",
481 G_CALLBACK (gtk_color_button_draw_cb), color_button);
482 gtk_container_add (GTK_CONTAINER (frame), color_button->priv->draw_area);
483 gtk_widget_show (color_button->priv->draw_area);
485 color_button->priv->title = g_strdup (_("Pick a Color")); /* default title */
487 /* Start with opaque black, alpha disabled */
489 color_button->priv->rgba.red = 0;
490 color_button->priv->rgba.green = 0;
491 color_button->priv->rgba.blue = 0;
492 color_button->priv->rgba.alpha = 1;
493 color_button->priv->use_alpha = FALSE;
495 gtk_drag_dest_set (GTK_WIDGET (color_button),
496 GTK_DEST_DEFAULT_MOTION |
497 GTK_DEST_DEFAULT_HIGHLIGHT |
498 GTK_DEST_DEFAULT_DROP,
499 drop_types, 1, GDK_ACTION_COPY);
500 gtk_drag_source_set (GTK_WIDGET(color_button),
501 GDK_BUTTON1_MASK|GDK_BUTTON3_MASK,
504 g_signal_connect (color_button, "drag-begin",
505 G_CALLBACK (gtk_color_button_drag_begin), color_button);
506 g_signal_connect (color_button, "drag-data-received",
507 G_CALLBACK (gtk_color_button_drag_data_received), color_button);
508 g_signal_connect (color_button, "drag-data-get",
509 G_CALLBACK (gtk_color_button_drag_data_get), color_button);
511 gtk_widget_pop_composite_child ();
515 gtk_color_button_finalize (GObject *object)
517 GtkColorButton *color_button = GTK_COLOR_BUTTON (object);
519 if (color_button->priv->cs_dialog != NULL)
520 gtk_widget_destroy (color_button->priv->cs_dialog);
521 color_button->priv->cs_dialog = NULL;
523 g_free (color_button->priv->title);
524 color_button->priv->title = NULL;
526 G_OBJECT_CLASS (gtk_color_button_parent_class)->finalize (object);
531 * gtk_color_button_new:
533 * Creates a new color button.
535 * This returns a widget in the form of a small button containing
536 * a swatch representing the current selected color. When the button
537 * is clicked, a color-selection dialog will open, allowing the user
538 * to select a color. The swatch will be updated to reflect the new
539 * color when the user finishes.
541 * Returns: a new color button
546 gtk_color_button_new (void)
548 return g_object_new (GTK_TYPE_COLOR_BUTTON, NULL);
552 * gtk_color_button_new_with_color:
553 * @color: A #GdkColor to set the current color with
555 * Creates a new color button.
557 * Returns: a new color button
561 * Deprecated: 3.4: Use gtk_color_button_new_with_rgba() instead.
564 gtk_color_button_new_with_color (const GdkColor *color)
566 return g_object_new (GTK_TYPE_COLOR_BUTTON, "color", color, NULL);
570 * gtk_color_button_new_with_rgba:
571 * @rgba: A #GdkRGBA to set the current color with
573 * Creates a new color button.
575 * Returns: a new color button
580 gtk_color_button_new_with_rgba (const GdkRGBA *rgba)
582 return g_object_new (GTK_TYPE_COLOR_BUTTON, "rgba", rgba, NULL);
586 dialog_ok_clicked (GtkWidget *widget,
589 GtkColorButton *color_button = GTK_COLOR_BUTTON (data);
590 GtkColorSelection *color_selection;
591 GtkColorSelectionDialog *selection_dialog;
593 selection_dialog = GTK_COLOR_SELECTION_DIALOG (color_button->priv->cs_dialog);
594 color_selection = GTK_COLOR_SELECTION (gtk_color_selection_dialog_get_color_selection (selection_dialog));
596 gtk_color_selection_get_current_rgba (color_selection, &color_button->priv->rgba);
598 gtk_widget_hide (color_button->priv->cs_dialog);
600 gtk_widget_queue_draw (color_button->priv->draw_area);
602 g_signal_emit (color_button, color_button_signals[COLOR_SET], 0);
604 g_object_freeze_notify (G_OBJECT (color_button));
605 g_object_notify (G_OBJECT (color_button), "color");
606 g_object_notify (G_OBJECT (color_button), "alpha");
607 g_object_notify (G_OBJECT (color_button), "rgba");
608 g_object_thaw_notify (G_OBJECT (color_button));
612 dialog_destroy (GtkWidget *widget,
615 GtkColorButton *color_button = GTK_COLOR_BUTTON (data);
617 color_button->priv->cs_dialog = NULL;
623 dialog_cancel_clicked (GtkWidget *widget,
626 GtkColorButton *color_button = GTK_COLOR_BUTTON (data);
628 gtk_widget_hide (color_button->priv->cs_dialog);
632 gtk_color_button_clicked (GtkButton *button)
634 GtkColorButton *color_button = GTK_COLOR_BUTTON (button);
635 GtkColorSelection *color_selection;
636 GtkColorSelectionDialog *color_dialog;
638 /* if dialog already exists, make sure it's shown and raised */
639 if (!color_button->priv->cs_dialog)
641 /* Create the dialog and connects its buttons */
643 GtkWidget *ok_button, *cancel_button;
645 parent = gtk_widget_get_toplevel (GTK_WIDGET (color_button));
647 color_button->priv->cs_dialog = gtk_color_selection_dialog_new (color_button->priv->title);
649 color_dialog = GTK_COLOR_SELECTION_DIALOG (color_button->priv->cs_dialog);
651 if (gtk_widget_is_toplevel (parent) && GTK_IS_WINDOW (parent))
653 if (GTK_WINDOW (parent) != gtk_window_get_transient_for (GTK_WINDOW (color_dialog)))
654 gtk_window_set_transient_for (GTK_WINDOW (color_dialog), GTK_WINDOW (parent));
656 gtk_window_set_modal (GTK_WINDOW (color_dialog),
657 gtk_window_get_modal (GTK_WINDOW (parent)));
660 g_object_get (color_dialog,
661 "ok-button", &ok_button,
662 "cancel-button", &cancel_button,
665 g_signal_connect (ok_button, "clicked",
666 G_CALLBACK (dialog_ok_clicked), color_button);
667 g_signal_connect (cancel_button, "clicked",
668 G_CALLBACK (dialog_cancel_clicked), color_button);
669 g_signal_connect (color_dialog, "destroy",
670 G_CALLBACK (dialog_destroy), color_button);
672 g_object_unref (ok_button);
673 g_object_unref (cancel_button);
676 color_dialog = GTK_COLOR_SELECTION_DIALOG (color_button->priv->cs_dialog);
677 color_selection = GTK_COLOR_SELECTION (gtk_color_selection_dialog_get_color_selection (color_dialog));
679 gtk_color_selection_set_has_opacity_control (color_selection,
680 color_button->priv->use_alpha);
682 gtk_color_selection_set_previous_rgba (color_selection,
683 &color_button->priv->rgba);
684 gtk_color_selection_set_current_rgba (color_selection,
685 &color_button->priv->rgba);
687 gtk_window_present (GTK_WINDOW (color_button->priv->cs_dialog));
691 * gtk_color_button_set_color:
692 * @color_button: a #GtkColorButton
693 * @color: A #GdkColor to set the current color with
695 * Sets the current color to be @color.
699 * Deprecated: Use gtk_color_button_set_rgba() instead.
702 gtk_color_button_set_color (GtkColorButton *color_button,
703 const GdkColor *color)
705 g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button));
706 g_return_if_fail (color != NULL);
708 color_button->priv->rgba.red = color->red / 65535.;
709 color_button->priv->rgba.green = color->green / 65535.;
710 color_button->priv->rgba.blue = color->blue / 65535.;
712 gtk_widget_queue_draw (color_button->priv->draw_area);
714 g_object_notify (G_OBJECT (color_button), "color");
715 g_object_notify (G_OBJECT (color_button), "rgba");
720 * gtk_color_button_set_alpha:
721 * @color_button: a #GtkColorButton
722 * @alpha: an integer between 0 and 65535
724 * Sets the current opacity to be @alpha.
729 gtk_color_button_set_alpha (GtkColorButton *color_button,
732 g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button));
734 color_button->priv->rgba.alpha = alpha / 65535.;
736 gtk_widget_queue_draw (color_button->priv->draw_area);
738 g_object_notify (G_OBJECT (color_button), "alpha");
739 g_object_notify (G_OBJECT (color_button), "rgba");
743 * gtk_color_button_get_color:
744 * @color_button: a #GtkColorButton
745 * @color: (out): a #GdkColor to fill in with the current color
747 * Sets @color to be the current color in the #GtkColorButton widget.
751 * Deprecated: 3.4: Use gtk_color_button_get_rgba() instead.
754 gtk_color_button_get_color (GtkColorButton *color_button,
757 g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button));
759 color->red = (guint16) (color_button->priv->rgba.red * 65535);
760 color->green = (guint16) (color_button->priv->rgba.green * 65535);
761 color->blue = (guint16) (color_button->priv->rgba.blue * 65535);
765 * gtk_color_button_get_alpha:
766 * @color_button: a #GtkColorButton
768 * Returns the current alpha value.
770 * Return value: an integer between 0 and 65535
775 gtk_color_button_get_alpha (GtkColorButton *color_button)
777 g_return_val_if_fail (GTK_IS_COLOR_BUTTON (color_button), 0);
779 return (guint16) (color_button->priv->rgba.alpha * 65535);
783 * gtk_color_button_set_rgba:
784 * @color_button: a #GtkColorButton
785 * @rgba: a #GdkRGBA to set the current color with
787 * Sets the current color to be @rgba.
792 gtk_color_button_set_rgba (GtkColorButton *color_button,
795 g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button));
796 g_return_if_fail (rgba != NULL);
798 color_button->priv->rgba = *rgba;
800 gtk_widget_queue_draw (color_button->priv->draw_area);
802 g_object_notify (G_OBJECT (color_button), "color");
803 g_object_notify (G_OBJECT (color_button), "alpha");
804 g_object_notify (G_OBJECT (color_button), "rgba");
808 * gtk_color_button_get_rgba:
809 * @color_button: a #GtkColorButton
810 * @rgba: (out): a #GdkRGBA to fill in with the current color
812 * Sets @rgba to be the current color in the #GtkColorButton widget.
817 gtk_color_button_get_rgba (GtkColorButton *color_button,
820 g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button));
821 g_return_if_fail (rgba != NULL);
823 *rgba = color_button->priv->rgba;
827 * gtk_color_button_set_use_alpha:
828 * @color_button: a #GtkColorButton
829 * @use_alpha: %TRUE if color button should use alpha channel, %FALSE if not
831 * Sets whether or not the color button should use the alpha channel.
836 gtk_color_button_set_use_alpha (GtkColorButton *color_button,
839 g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button));
841 use_alpha = (use_alpha != FALSE);
843 if (color_button->priv->use_alpha != use_alpha)
845 color_button->priv->use_alpha = use_alpha;
847 gtk_widget_queue_draw (color_button->priv->draw_area);
849 g_object_notify (G_OBJECT (color_button), "use-alpha");
854 * gtk_color_button_get_use_alpha:
855 * @color_button: a #GtkColorButton
857 * Does the color selection dialog use the alpha channel ?
859 * Returns: %TRUE if the color sample uses alpha channel, %FALSE if not
864 gtk_color_button_get_use_alpha (GtkColorButton *color_button)
866 g_return_val_if_fail (GTK_IS_COLOR_BUTTON (color_button), FALSE);
868 return color_button->priv->use_alpha;
873 * gtk_color_button_set_title:
874 * @color_button: a #GtkColorButton
875 * @title: String containing new window title
877 * Sets the title for the color selection dialog.
882 gtk_color_button_set_title (GtkColorButton *color_button,
887 g_return_if_fail (GTK_IS_COLOR_BUTTON (color_button));
889 old_title = color_button->priv->title;
890 color_button->priv->title = g_strdup (title);
893 if (color_button->priv->cs_dialog)
894 gtk_window_set_title (GTK_WINDOW (color_button->priv->cs_dialog),
895 color_button->priv->title);
897 g_object_notify (G_OBJECT (color_button), "title");
901 * gtk_color_button_get_title:
902 * @color_button: a #GtkColorButton
904 * Gets the title of the color selection dialog.
906 * Returns: An internal string, do not free the return value
911 gtk_color_button_get_title (GtkColorButton *color_button)
913 g_return_val_if_fail (GTK_IS_COLOR_BUTTON (color_button), NULL);
915 return color_button->priv->title;
919 gtk_color_button_set_property (GObject *object,
924 GtkColorButton *color_button = GTK_COLOR_BUTTON (object);
929 gtk_color_button_set_use_alpha (color_button, g_value_get_boolean (value));
932 gtk_color_button_set_title (color_button, g_value_get_string (value));
939 color = g_value_get_boxed (value);
941 rgba.red = color->red / 65535.0;
942 rgba.green = color->green / 65535.0;
943 rgba.blue = color->blue / 65535.0;
946 gtk_color_button_set_rgba (color_button, &rgba);
950 gtk_color_button_set_alpha (color_button, g_value_get_uint (value));
953 gtk_color_button_set_rgba (color_button, g_value_get_boxed (value));
956 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
962 gtk_color_button_get_property (GObject *object,
967 GtkColorButton *color_button = GTK_COLOR_BUTTON (object);
972 g_value_set_boolean (value, gtk_color_button_get_use_alpha (color_button));
975 g_value_set_string (value, gtk_color_button_get_title (color_button));
982 gtk_color_button_get_rgba (color_button, &rgba);
984 color.red = (guint16) (rgba.red * 65535 + 0.5);
985 color.green = (guint16) (rgba.green * 65535 + 0.5);
986 color.blue = (guint16) (rgba.blue * 65535 + 0.5);
988 g_value_set_boxed (value, &color);
992 g_value_set_uint (value, gtk_color_button_get_alpha (color_button));
998 gtk_color_button_get_rgba (color_button, &rgba);
999 g_value_set_boxed (value, &rgba);
1003 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);