]> Pileus Git - ~andy/gtk/blob - gtk/gtkcolorseldialog.c
GailEntry: remove idle if cell editing is canceled
[~andy/gtk] / gtk / 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 #include <string.h>
28 #include <glib.h>
29 #include "gtkcolorseldialog.h"
30 #include "gtkframe.h"
31 #include "gtkhbbox.h"
32 #include "gtkbutton.h"
33 #include "gtkstock.h"
34 #include "gtkintl.h"
35 #include "gtkbuildable.h"
36
37
38
39 struct _GtkColorSelectionDialogPrivate
40 {
41   GtkWidget *colorsel;
42   GtkWidget *ok_button;
43   GtkWidget *cancel_button;
44   GtkWidget *help_button;
45 };
46
47 enum {
48   PROP_0,
49   PROP_COLOR_SELECTION,
50   PROP_OK_BUTTON,
51   PROP_CANCEL_BUTTON,
52   PROP_HELP_BUTTON
53 };
54
55
56 /***************************/
57 /* GtkColorSelectionDialog */
58 /***************************/
59
60 static void gtk_color_selection_dialog_buildable_interface_init     (GtkBuildableIface *iface);
61 static GObject * gtk_color_selection_dialog_buildable_get_internal_child (GtkBuildable *buildable,
62                                                                           GtkBuilder   *builder,
63                                                                           const gchar  *childname);
64
65 G_DEFINE_TYPE_WITH_CODE (GtkColorSelectionDialog, gtk_color_selection_dialog,
66            GTK_TYPE_DIALOG,
67            G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
68                       gtk_color_selection_dialog_buildable_interface_init))
69
70 static GtkBuildableIface *parent_buildable_iface;
71
72 static void
73 gtk_color_selection_dialog_get_property (GObject         *object,
74                                          guint            prop_id,
75                                          GValue          *value,
76                                          GParamSpec      *pspec)
77 {
78   GtkColorSelectionDialog *colorsel = GTK_COLOR_SELECTION_DIALOG (object);
79   GtkColorSelectionDialogPrivate *priv = colorsel->priv;
80
81   switch (prop_id)
82     {
83     case PROP_COLOR_SELECTION:
84       g_value_set_object (value, priv->colorsel);
85       break;
86     case PROP_OK_BUTTON:
87       g_value_set_object (value, priv->ok_button);
88       break;
89     case PROP_CANCEL_BUTTON:
90       g_value_set_object (value, priv->cancel_button);
91       break;
92     case PROP_HELP_BUTTON:
93       g_value_set_object (value, priv->help_button);
94       break;
95     default:
96       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
97       break;
98     }
99 }
100
101 static void
102 gtk_color_selection_dialog_class_init (GtkColorSelectionDialogClass *klass)
103 {
104   GObjectClass   *gobject_class = G_OBJECT_CLASS (klass);
105   gobject_class->get_property = gtk_color_selection_dialog_get_property;
106
107   g_object_class_install_property (gobject_class,
108                                    PROP_COLOR_SELECTION,
109                                    g_param_spec_object ("color-selection",
110                                                      P_("Color Selection"),
111                                                      P_("The color selection embedded in the dialog."),
112                                                      GTK_TYPE_WIDGET,
113                                                      G_PARAM_READABLE));
114   g_object_class_install_property (gobject_class,
115                                    PROP_OK_BUTTON,
116                                    g_param_spec_object ("ok-button",
117                                                      P_("OK Button"),
118                                                      P_("The OK button of the dialog."),
119                                                      GTK_TYPE_WIDGET,
120                                                      G_PARAM_READABLE));
121   g_object_class_install_property (gobject_class,
122                                    PROP_CANCEL_BUTTON,
123                                    g_param_spec_object ("cancel-button",
124                                                      P_("Cancel Button"),
125                                                      P_("The cancel button of the dialog."),
126                                                      GTK_TYPE_WIDGET,
127                                                      G_PARAM_READABLE));
128   g_object_class_install_property (gobject_class,
129                                    PROP_HELP_BUTTON,
130                                    g_param_spec_object ("help-button",
131                                                      P_("Help Button"),
132                                                      P_("The help button of the dialog."),
133                                                      GTK_TYPE_WIDGET,
134                                                      G_PARAM_READABLE));
135
136   g_type_class_add_private (klass, sizeof (GtkColorSelectionDialogPrivate));
137 }
138
139 static void
140 gtk_color_selection_dialog_init (GtkColorSelectionDialog *colorseldiag)
141 {
142   GtkColorSelectionDialogPrivate *priv;
143   GtkDialog *dialog = GTK_DIALOG (colorseldiag);
144   GtkWidget *action_area, *content_area;
145
146   colorseldiag->priv = G_TYPE_INSTANCE_GET_PRIVATE (colorseldiag,
147                                                     GTK_TYPE_COLOR_SELECTION_DIALOG,
148                                                     GtkColorSelectionDialogPrivate);
149   priv = colorseldiag->priv;
150
151   content_area = gtk_dialog_get_content_area (dialog);
152   action_area = gtk_dialog_get_action_area (dialog);
153
154   gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
155   gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
156   gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
157   gtk_box_set_spacing (GTK_BOX (action_area), 6);
158
159   priv->colorsel = gtk_color_selection_new ();
160   gtk_container_set_border_width (GTK_CONTAINER (priv->colorsel), 5);
161   gtk_color_selection_set_has_palette (GTK_COLOR_SELECTION (priv->colorsel), FALSE);
162   gtk_color_selection_set_has_opacity_control (GTK_COLOR_SELECTION (priv->colorsel), FALSE);
163   gtk_container_add (GTK_CONTAINER (content_area), priv->colorsel);
164   gtk_widget_show (priv->colorsel);
165   
166   priv->cancel_button = gtk_dialog_add_button (dialog,
167                                                GTK_STOCK_CANCEL,
168                                                GTK_RESPONSE_CANCEL);
169
170   priv->ok_button = gtk_dialog_add_button (dialog,
171                                            GTK_STOCK_OK,
172                                            GTK_RESPONSE_OK);
173                                                    
174   gtk_widget_grab_default (priv->ok_button);
175   
176   priv->help_button = gtk_dialog_add_button (dialog,
177                                              GTK_STOCK_HELP,
178                                              GTK_RESPONSE_HELP);
179
180   gtk_widget_hide (priv->help_button);
181
182   gtk_dialog_set_alternative_button_order (dialog,
183                                            GTK_RESPONSE_OK,
184                                            GTK_RESPONSE_CANCEL,
185                                            GTK_RESPONSE_HELP,
186                                            -1);
187
188   gtk_window_set_title (GTK_WINDOW (colorseldiag),
189                         _("Color Selection"));
190 }
191
192 GtkWidget*
193 gtk_color_selection_dialog_new (const gchar *title)
194 {
195   GtkColorSelectionDialog *colorseldiag;
196   
197   colorseldiag = g_object_new (GTK_TYPE_COLOR_SELECTION_DIALOG, NULL);
198
199   if (title)
200     gtk_window_set_title (GTK_WINDOW (colorseldiag), title);
201
202   gtk_window_set_resizable (GTK_WINDOW (colorseldiag), FALSE);
203   
204   return GTK_WIDGET (colorseldiag);
205 }
206
207 /**
208  * gtk_color_selection_dialog_get_color_selection:
209  * @colorsel: a #GtkColorSelectionDialog
210  *
211  * Retrieves the #GtkColorSelection widget embedded in the dialog.
212  *
213  * Returns: (transfer none): the embedded #GtkColorSelection
214  *
215  * Since: 2.14
216  **/
217 GtkWidget*
218 gtk_color_selection_dialog_get_color_selection (GtkColorSelectionDialog *colorsel)
219 {
220   g_return_val_if_fail (GTK_IS_COLOR_SELECTION_DIALOG (colorsel), NULL);
221
222   return colorsel->priv->colorsel;
223 }
224
225 static void
226 gtk_color_selection_dialog_buildable_interface_init (GtkBuildableIface *iface)
227 {
228   parent_buildable_iface = g_type_interface_peek_parent (iface);
229   iface->get_internal_child = gtk_color_selection_dialog_buildable_get_internal_child;
230 }
231
232 static GObject *
233 gtk_color_selection_dialog_buildable_get_internal_child (GtkBuildable *buildable,
234                                                          GtkBuilder   *builder,
235                                                          const gchar  *childname)
236 {
237   GtkColorSelectionDialog *selection_dialog = GTK_COLOR_SELECTION_DIALOG (buildable);
238   GtkColorSelectionDialogPrivate *priv = selection_dialog->priv;
239
240   if (g_strcmp0 (childname, "ok_button") == 0)
241     return G_OBJECT (priv->ok_button);
242   else if (g_strcmp0 (childname, "cancel_button") == 0)
243     return G_OBJECT (priv->cancel_button);
244   else if (g_strcmp0 (childname, "help_button") == 0)
245     return G_OBJECT (priv->help_button);
246   else if (g_strcmp0 (childname, "color_selection") == 0)
247     return G_OBJECT (priv->colorsel);
248
249   return parent_buildable_iface->get_internal_child (buildable, builder, childname);
250 }