]> Pileus Git - ~andy/gtk/blob - gtk/gtkcolorchooser.c
Initial cut at implementing a new color chooser
[~andy/gtk] / gtk / gtkcolorchooser.c
1 /* GTK - The GIMP Toolkit
2  *
3  * Copyright (C) 2012, Red Hat, Inc.
4  *
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.
9  *
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.
14  *
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.
19  */
20
21 #include "config.h"
22
23 #include "gtkcolorchooser.h"
24 #include "gtkcolorchooserprivate.h"
25 #include "gtkintl.h"
26 #include "gtktypebuiltins.h"
27 #include "gtkprivate.h"
28
29 enum
30 {
31   COLOR_ACTIVATED,
32   LAST_SIGNAL
33 };
34
35 static guint signals[LAST_SIGNAL];
36
37 G_DEFINE_INTERFACE (GtkColorChooser, gtk_color_chooser, G_TYPE_OBJECT);
38
39 static void
40 gtk_color_chooser_default_init (GtkColorChooserInterface *iface)
41 {
42   g_object_interface_install_property (iface,
43       g_param_spec_boxed ("color",
44                           P_("Color"),
45                           P_("Current color, as a GdkRGBA"),
46                           GDK_TYPE_RGBA,
47                           GTK_PARAM_READWRITE));
48
49   /**
50    * GtkColorChooser::color-activated:
51    * @self: the object which received the signal
52    * @color: the color
53    *
54    * Emitted when a color is activated from the color chooser.
55    * This usually happens when the user clicks a color swatch,
56    * or a color is selected and the user presses one of the keys
57    * Space, Shift+Space, Return or Enter.
58     */
59   signals[COLOR_ACTIVATED] =
60     g_signal_new ("color-activated",
61                   GTK_TYPE_COLOR_CHOOSER,
62                   G_SIGNAL_RUN_FIRST,
63                   G_STRUCT_OFFSET (GtkColorChooserInterface, color_activated),
64                   NULL, NULL,
65                   NULL,
66                   G_TYPE_NONE,
67                   1, G_TYPE_STRING);
68 }
69
70 /**
71  * gtk_color_chooser_get_color:
72  * @chooser: a #GtkColorChooser
73  * @color: return location for the color
74  *
75  * Gets the currently-selected color.
76  */
77 void
78 gtk_color_chooser_get_color (GtkColorChooser *chooser,
79                              GdkRGBA         *color)
80 {
81   g_return_if_fail (GTK_IS_COLOR_CHOOSER (chooser));
82
83   GTK_COLOR_CHOOSER_GET_IFACE (chooser)->get_color (chooser, color);
84 }
85
86 /**
87  * gtk_color_chooser_set_color:
88  * @chooser: a #GtkColorChooser
89  * @color: the new color
90  *
91  * Sets the currently-selected color.
92  */
93 void
94 gtk_color_chooser_set_color (GtkColorChooser *chooser,
95                              const GdkRGBA   *color)
96 {
97   g_return_if_fail (GTK_IS_COLOR_CHOOSER (chooser));
98   g_return_if_fail (color != NULL);
99
100   GTK_COLOR_CHOOSER_GET_IFACE (chooser)->set_color (chooser, color);
101 }
102
103 void
104 _gtk_color_chooser_color_activated (GtkColorChooser *chooser,
105                                     const GdkRGBA   *color)
106 {
107   g_return_if_fail (GTK_IS_COLOR_CHOOSER (chooser));
108
109   g_signal_emit (chooser, signals[COLOR_ACTIVATED], 0, color);
110 }