1 /* GTK - The GIMP Toolkit
3 * Copyright (C) 2012, Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
23 #include "gtkcolorchooser.h"
24 #include "gtkcolorchooserprivate.h"
26 #include "gtktypebuiltins.h"
27 #include "gtkprivate.h"
35 static guint signals[LAST_SIGNAL];
37 G_DEFINE_INTERFACE (GtkColorChooser, gtk_color_chooser, G_TYPE_OBJECT);
40 gtk_color_chooser_default_init (GtkColorChooserInterface *iface)
42 g_object_interface_install_property (iface,
43 g_param_spec_boxed ("color",
45 P_("Current color, as a GdkRGBA"),
47 GTK_PARAM_READWRITE));
49 g_object_interface_install_property (iface,
50 g_param_spec_boolean ("show-alpha",
52 P_("Whether alpha should be shown"),
54 GTK_PARAM_READWRITE));
56 * GtkColorChooser::color-activated:
57 * @self: the object which received the signal
60 * Emitted when a color is activated from the color chooser.
61 * This usually happens when the user clicks a color swatch,
62 * or a color is selected and the user presses one of the keys
63 * Space, Shift+Space, Return or Enter.
65 signals[COLOR_ACTIVATED] =
66 g_signal_new ("color-activated",
67 GTK_TYPE_COLOR_CHOOSER,
69 G_STRUCT_OFFSET (GtkColorChooserInterface, color_activated),
77 * gtk_color_chooser_get_color:
78 * @chooser: a #GtkColorChooser
79 * @color: return location for the color
81 * Gets the currently-selected color.
84 gtk_color_chooser_get_color (GtkColorChooser *chooser,
87 g_return_if_fail (GTK_IS_COLOR_CHOOSER (chooser));
89 GTK_COLOR_CHOOSER_GET_IFACE (chooser)->get_color (chooser, color);
93 * gtk_color_chooser_set_color:
94 * @chooser: a #GtkColorChooser
95 * @color: the new color
97 * Sets the currently-selected color.
100 gtk_color_chooser_set_color (GtkColorChooser *chooser,
101 const GdkRGBA *color)
103 g_return_if_fail (GTK_IS_COLOR_CHOOSER (chooser));
104 g_return_if_fail (color != NULL);
106 GTK_COLOR_CHOOSER_GET_IFACE (chooser)->set_color (chooser, color);
110 _gtk_color_chooser_color_activated (GtkColorChooser *chooser,
111 const GdkRGBA *color)
113 g_return_if_fail (GTK_IS_COLOR_CHOOSER (chooser));
115 g_signal_emit (chooser, signals[COLOR_ACTIVATED], 0, color);
119 gtk_color_chooser_get_show_alpha (GtkColorChooser *chooser)
123 g_return_val_if_fail (GTK_IS_COLOR_CHOOSER (chooser), TRUE);
125 g_object_get (chooser, "show-alpha", &show_alpha, NULL);
131 gtk_color_chooser_set_show_alpha (GtkColorChooser *chooser,
135 g_return_if_fail (GTK_IS_COLOR_CHOOSER (chooser));
137 g_object_set (chooser, "show-alpha", show_alpha, NULL);