]> Pileus Git - ~andy/gtk/blob - gtk/deprecated/gtkcolorseldialog.c
772a8cb7ec7734ae0c4b0f4afc8e3abb0909099d
[~andy/gtk] / gtk / deprecated / gtkcolorseldialog.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /*
21  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
22  * file for a list of people on the GTK+ Team.  See the ChangeLog
23  * files for a list of changes.  These files are distributed with
24  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
25  */
26 #include "config.h"
27
28 #define GDK_DISABLE_DEPRECATION_WARNINGS
29
30
31 #include <string.h>
32 #include <glib.h>
33 #include "gtkcolorseldialog.h"
34 #include "gtkframe.h"
35 #include "gtkbutton.h"
36 #include "gtkstock.h"
37 #include "gtkintl.h"
38 #include "gtkbuildable.h"
39
40
41 /**
42  * SECTION:gtkcolorseldlg
43  * @Short_description: Deprecated dialog box for selecting a color
44  * @Title: GtkColorSelectionDialog
45  *
46  * The #GtkColorSelectionDialog provides a standard dialog which
47  * allows the user to select a color much like the #GtkFileSelection
48  * provides a standard dialog for file selection.
49  *
50  * Use gtk_color_selection_dialog_get_color_selection() to get the
51  * #GtkColorSelection widget contained within the dialog. Use this widget
52  * and its gtk_color_selection_get_current_color()
53  * function to gain access to the selected color.  Connect a handler
54  * for this widget's #GtkColorSelection::color-changed signal to be notified
55  * when the color changes.
56  *
57  * <refsect2 id="GtkColorSelectionDialog-BUILDER-UI">
58  * <title>GtkColorSelectionDialog as GtkBuildable</title>
59  * The GtkColorSelectionDialog implementation of the GtkBuildable interface
60  * exposes the embedded #GtkColorSelection as internal child with the
61  * name "color_selection". It also exposes the buttons with the names
62  * "ok_button", "cancel_button" and "help_button".
63  * </refsect2>
64  */
65
66
67 struct _GtkColorSelectionDialogPrivate
68 {
69   GtkWidget *colorsel;
70   GtkWidget *ok_button;
71   GtkWidget *cancel_button;
72   GtkWidget *help_button;
73 };
74
75 enum {
76   PROP_0,
77   PROP_COLOR_SELECTION,
78   PROP_OK_BUTTON,
79   PROP_CANCEL_BUTTON,
80   PROP_HELP_BUTTON
81 };
82
83
84 /***************************/
85 /* GtkColorSelectionDialog */
86 /***************************/
87
88 static void gtk_color_selection_dialog_buildable_interface_init     (GtkBuildableIface *iface);
89 static GObject * gtk_color_selection_dialog_buildable_get_internal_child (GtkBuildable *buildable,
90                                                                           GtkBuilder   *builder,
91                                                                           const gchar  *childname);
92
93 G_DEFINE_TYPE_WITH_CODE (GtkColorSelectionDialog, gtk_color_selection_dialog,
94            GTK_TYPE_DIALOG,
95            G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
96                       gtk_color_selection_dialog_buildable_interface_init))
97
98 static GtkBuildableIface *parent_buildable_iface;
99
100 static void
101 gtk_color_selection_dialog_get_property (GObject         *object,
102                                          guint            prop_id,
103                                          GValue          *value,
104                                          GParamSpec      *pspec)
105 {
106   GtkColorSelectionDialog *colorsel = GTK_COLOR_SELECTION_DIALOG (object);
107   GtkColorSelectionDialogPrivate *priv = colorsel->priv;
108
109   switch (prop_id)
110     {
111     case PROP_COLOR_SELECTION:
112       g_value_set_object (value, priv->colorsel);
113       break;
114     case PROP_OK_BUTTON:
115       g_value_set_object (value, priv->ok_button);
116       break;
117     case PROP_CANCEL_BUTTON:
118       g_value_set_object (value, priv->cancel_button);
119       break;
120     case PROP_HELP_BUTTON:
121       g_value_set_object (value, priv->help_button);
122       break;
123     default:
124       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
125       break;
126     }
127 }
128
129 static void
130 gtk_color_selection_dialog_class_init (GtkColorSelectionDialogClass *klass)
131 {
132   GObjectClass   *gobject_class = G_OBJECT_CLASS (klass);
133   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
134
135   gobject_class->get_property = gtk_color_selection_dialog_get_property;
136
137   g_object_class_install_property (gobject_class,
138                                    PROP_COLOR_SELECTION,
139                                    g_param_spec_object ("color-selection",
140                                                      P_("Color Selection"),
141                                                      P_("The color selection embedded in the dialog."),
142                                                      GTK_TYPE_WIDGET,
143                                                      G_PARAM_READABLE));
144   g_object_class_install_property (gobject_class,
145                                    PROP_OK_BUTTON,
146                                    g_param_spec_object ("ok-button",
147                                                      P_("OK Button"),
148                                                      P_("The OK button of the dialog."),
149                                                      GTK_TYPE_WIDGET,
150                                                      G_PARAM_READABLE));
151   g_object_class_install_property (gobject_class,
152                                    PROP_CANCEL_BUTTON,
153                                    g_param_spec_object ("cancel-button",
154                                                      P_("Cancel Button"),
155                                                      P_("The cancel button of the dialog."),
156                                                      GTK_TYPE_WIDGET,
157                                                      G_PARAM_READABLE));
158   g_object_class_install_property (gobject_class,
159                                    PROP_HELP_BUTTON,
160                                    g_param_spec_object ("help-button",
161                                                      P_("Help Button"),
162                                                      P_("The help button of the dialog."),
163                                                      GTK_TYPE_WIDGET,
164                                                      G_PARAM_READABLE));
165
166   gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_COLOR_CHOOSER);
167
168   g_type_class_add_private (klass, sizeof (GtkColorSelectionDialogPrivate));
169 }
170
171 static void
172 gtk_color_selection_dialog_init (GtkColorSelectionDialog *colorseldiag)
173 {
174   GtkColorSelectionDialogPrivate *priv;
175   GtkDialog *dialog = GTK_DIALOG (colorseldiag);
176   GtkWidget *action_area, *content_area;
177
178   colorseldiag->priv = G_TYPE_INSTANCE_GET_PRIVATE (colorseldiag,
179                                                     GTK_TYPE_COLOR_SELECTION_DIALOG,
180                                                     GtkColorSelectionDialogPrivate);
181   priv = colorseldiag->priv;
182
183   content_area = gtk_dialog_get_content_area (dialog);
184   action_area = gtk_dialog_get_action_area (dialog);
185
186   gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
187   gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
188   gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
189   gtk_box_set_spacing (GTK_BOX (action_area), 6);
190
191   priv->colorsel = gtk_color_selection_new ();
192   gtk_container_set_border_width (GTK_CONTAINER (priv->colorsel), 5);
193   gtk_color_selection_set_has_palette (GTK_COLOR_SELECTION (priv->colorsel), FALSE);
194   gtk_color_selection_set_has_opacity_control (GTK_COLOR_SELECTION (priv->colorsel), FALSE);
195   gtk_container_add (GTK_CONTAINER (content_area), priv->colorsel);
196   gtk_widget_show (priv->colorsel);
197
198   priv->cancel_button = gtk_dialog_add_button (dialog,
199                                                GTK_STOCK_CANCEL,
200                                                GTK_RESPONSE_CANCEL);
201
202   priv->ok_button = gtk_dialog_add_button (dialog,
203                                            _("_Select"),
204                                            GTK_RESPONSE_OK);
205
206   gtk_widget_grab_default (priv->ok_button);
207
208   priv->help_button = gtk_dialog_add_button (dialog,
209                                              GTK_STOCK_HELP,
210                                              GTK_RESPONSE_HELP);
211
212   gtk_widget_hide (priv->help_button);
213
214   gtk_dialog_set_alternative_button_order (dialog,
215                                            GTK_RESPONSE_OK,
216                                            GTK_RESPONSE_CANCEL,
217                                            GTK_RESPONSE_HELP,
218                                            -1);
219
220   gtk_window_set_title (GTK_WINDOW (colorseldiag),
221                         _("Color Selection"));
222 }
223
224 /**
225  * gtk_color_selection_dialog_new:
226  * @title: a string containing the title text for the dialog.
227  *
228  * Creates a new #GtkColorSelectionDialog.
229  *
230  * Returns: a #GtkColorSelectionDialog.
231  */
232 GtkWidget*
233 gtk_color_selection_dialog_new (const gchar *title)
234 {
235   GtkColorSelectionDialog *colorseldiag;
236   
237   colorseldiag = g_object_new (GTK_TYPE_COLOR_SELECTION_DIALOG, NULL);
238
239   if (title)
240     gtk_window_set_title (GTK_WINDOW (colorseldiag), title);
241
242   gtk_window_set_resizable (GTK_WINDOW (colorseldiag), FALSE);
243   
244   return GTK_WIDGET (colorseldiag);
245 }
246
247 /**
248  * gtk_color_selection_dialog_get_color_selection:
249  * @colorsel: a #GtkColorSelectionDialog
250  *
251  * Retrieves the #GtkColorSelection widget embedded in the dialog.
252  *
253  * Returns: (transfer none): the embedded #GtkColorSelection
254  *
255  * Since: 2.14
256  **/
257 GtkWidget*
258 gtk_color_selection_dialog_get_color_selection (GtkColorSelectionDialog *colorsel)
259 {
260   g_return_val_if_fail (GTK_IS_COLOR_SELECTION_DIALOG (colorsel), NULL);
261
262   return colorsel->priv->colorsel;
263 }
264
265 static void
266 gtk_color_selection_dialog_buildable_interface_init (GtkBuildableIface *iface)
267 {
268   parent_buildable_iface = g_type_interface_peek_parent (iface);
269   iface->get_internal_child = gtk_color_selection_dialog_buildable_get_internal_child;
270 }
271
272 static GObject *
273 gtk_color_selection_dialog_buildable_get_internal_child (GtkBuildable *buildable,
274                                                          GtkBuilder   *builder,
275                                                          const gchar  *childname)
276 {
277   GtkColorSelectionDialog *selection_dialog = GTK_COLOR_SELECTION_DIALOG (buildable);
278   GtkColorSelectionDialogPrivate *priv = selection_dialog->priv;
279
280   if (g_strcmp0 (childname, "ok_button") == 0)
281     return G_OBJECT (priv->ok_button);
282   else if (g_strcmp0 (childname, "cancel_button") == 0)
283     return G_OBJECT (priv->cancel_button);
284   else if (g_strcmp0 (childname, "help_button") == 0)
285     return G_OBJECT (priv->help_button);
286   else if (g_strcmp0 (childname, "color_selection") == 0)
287     return G_OBJECT (priv->colorsel);
288
289   return parent_buildable_iface->get_internal_child (buildable, builder, childname);
290 }