]> Pileus Git - ~andy/gtk/blob - gtk/gtkcolorchooser.c
Make alpha optional
[~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   g_object_interface_install_property (iface,
50       g_param_spec_boolean ("show-alpha",
51                             P_("Show alpha"),
52                             P_("Whether alpha should be shown"),
53                             TRUE,
54                             GTK_PARAM_READWRITE));
55   /**
56    * GtkColorChooser::color-activated:
57    * @self: the object which received the signal
58    * @color: the color
59    *
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.
64     */
65   signals[COLOR_ACTIVATED] =
66     g_signal_new ("color-activated",
67                   GTK_TYPE_COLOR_CHOOSER,
68                   G_SIGNAL_RUN_FIRST,
69                   G_STRUCT_OFFSET (GtkColorChooserInterface, color_activated),
70                   NULL, NULL,
71                   NULL,
72                   G_TYPE_NONE,
73                   1, G_TYPE_STRING);
74 }
75
76 /**
77  * gtk_color_chooser_get_color:
78  * @chooser: a #GtkColorChooser
79  * @color: return location for the color
80  *
81  * Gets the currently-selected color.
82  */
83 void
84 gtk_color_chooser_get_color (GtkColorChooser *chooser,
85                              GdkRGBA         *color)
86 {
87   g_return_if_fail (GTK_IS_COLOR_CHOOSER (chooser));
88
89   GTK_COLOR_CHOOSER_GET_IFACE (chooser)->get_color (chooser, color);
90 }
91
92 /**
93  * gtk_color_chooser_set_color:
94  * @chooser: a #GtkColorChooser
95  * @color: the new color
96  *
97  * Sets the currently-selected color.
98  */
99 void
100 gtk_color_chooser_set_color (GtkColorChooser *chooser,
101                              const GdkRGBA   *color)
102 {
103   g_return_if_fail (GTK_IS_COLOR_CHOOSER (chooser));
104   g_return_if_fail (color != NULL);
105
106   GTK_COLOR_CHOOSER_GET_IFACE (chooser)->set_color (chooser, color);
107 }
108
109 void
110 _gtk_color_chooser_color_activated (GtkColorChooser *chooser,
111                                     const GdkRGBA   *color)
112 {
113   g_return_if_fail (GTK_IS_COLOR_CHOOSER (chooser));
114
115   g_signal_emit (chooser, signals[COLOR_ACTIVATED], 0, color);
116 }
117
118 gboolean
119 gtk_color_chooser_get_show_alpha (GtkColorChooser *chooser)
120 {
121   gboolean show_alpha;
122
123   g_return_val_if_fail (GTK_IS_COLOR_CHOOSER (chooser), TRUE);
124
125   g_object_get (chooser, "show-alpha", &show_alpha, NULL);
126
127   return show_alpha;
128 }
129
130 void
131 gtk_color_chooser_set_show_alpha (GtkColorChooser *chooser,
132                                   gboolean         show_alpha)
133 {
134
135   g_return_if_fail (GTK_IS_COLOR_CHOOSER (chooser));
136
137   g_object_set (chooser, "show-alpha", show_alpha, NULL);
138 }