1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
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.
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.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
20 * file for a list of people on the GTK+ Team. See the ChangeLog
21 * files for a list of changes. These files are distributed with
22 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
26 #define GDK_DISABLE_DEPRECATION_WARNINGS
31 #include "gtkcolorseldialog.h"
33 #include "gtkbutton.h"
36 #include "gtkbuildable.h"
40 * SECTION:gtkcolorseldlg
41 * @Short_description: Deprecated dialog box for selecting a color
42 * @Title: GtkColorSelectionDialog
44 * The #GtkColorSelectionDialog provides a standard dialog which
45 * allows the user to select a color much like the #GtkFileChooserDialog
46 * provides a standard dialog for file selection.
48 * Use gtk_color_selection_dialog_get_color_selection() to get the
49 * #GtkColorSelection widget contained within the dialog. Use this widget
50 * and its gtk_color_selection_get_current_color()
51 * function to gain access to the selected color. Connect a handler
52 * for this widget's #GtkColorSelection::color-changed signal to be notified
53 * when the color changes.
55 * <refsect2 id="GtkColorSelectionDialog-BUILDER-UI">
56 * <title>GtkColorSelectionDialog as GtkBuildable</title>
57 * The GtkColorSelectionDialog implementation of the GtkBuildable interface
58 * exposes the embedded #GtkColorSelection as internal child with the
59 * name "color_selection". It also exposes the buttons with the names
60 * "ok_button", "cancel_button" and "help_button".
65 struct _GtkColorSelectionDialogPrivate
69 GtkWidget *cancel_button;
70 GtkWidget *help_button;
82 /***************************/
83 /* GtkColorSelectionDialog */
84 /***************************/
86 static void gtk_color_selection_dialog_buildable_interface_init (GtkBuildableIface *iface);
87 static GObject * gtk_color_selection_dialog_buildable_get_internal_child (GtkBuildable *buildable,
89 const gchar *childname);
91 G_DEFINE_TYPE_WITH_CODE (GtkColorSelectionDialog, gtk_color_selection_dialog,
93 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
94 gtk_color_selection_dialog_buildable_interface_init))
96 static GtkBuildableIface *parent_buildable_iface;
99 gtk_color_selection_dialog_get_property (GObject *object,
104 GtkColorSelectionDialog *colorsel = GTK_COLOR_SELECTION_DIALOG (object);
105 GtkColorSelectionDialogPrivate *priv = colorsel->priv;
109 case PROP_COLOR_SELECTION:
110 g_value_set_object (value, priv->colorsel);
113 g_value_set_object (value, priv->ok_button);
115 case PROP_CANCEL_BUTTON:
116 g_value_set_object (value, priv->cancel_button);
118 case PROP_HELP_BUTTON:
119 g_value_set_object (value, priv->help_button);
122 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
128 gtk_color_selection_dialog_class_init (GtkColorSelectionDialogClass *klass)
130 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
131 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
133 gobject_class->get_property = gtk_color_selection_dialog_get_property;
135 g_object_class_install_property (gobject_class,
136 PROP_COLOR_SELECTION,
137 g_param_spec_object ("color-selection",
138 P_("Color Selection"),
139 P_("The color selection embedded in the dialog."),
142 g_object_class_install_property (gobject_class,
144 g_param_spec_object ("ok-button",
146 P_("The OK button of the dialog."),
149 g_object_class_install_property (gobject_class,
151 g_param_spec_object ("cancel-button",
153 P_("The cancel button of the dialog."),
156 g_object_class_install_property (gobject_class,
158 g_param_spec_object ("help-button",
160 P_("The help button of the dialog."),
164 gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_COLOR_CHOOSER);
166 g_type_class_add_private (klass, sizeof (GtkColorSelectionDialogPrivate));
170 gtk_color_selection_dialog_init (GtkColorSelectionDialog *colorseldiag)
172 GtkColorSelectionDialogPrivate *priv;
173 GtkDialog *dialog = GTK_DIALOG (colorseldiag);
174 GtkWidget *action_area, *content_area;
176 colorseldiag->priv = G_TYPE_INSTANCE_GET_PRIVATE (colorseldiag,
177 GTK_TYPE_COLOR_SELECTION_DIALOG,
178 GtkColorSelectionDialogPrivate);
179 priv = colorseldiag->priv;
181 content_area = gtk_dialog_get_content_area (dialog);
182 action_area = gtk_dialog_get_action_area (dialog);
184 gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
185 gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
186 gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
187 gtk_box_set_spacing (GTK_BOX (action_area), 6);
189 priv->colorsel = gtk_color_selection_new ();
190 gtk_container_set_border_width (GTK_CONTAINER (priv->colorsel), 5);
191 gtk_color_selection_set_has_palette (GTK_COLOR_SELECTION (priv->colorsel), FALSE);
192 gtk_color_selection_set_has_opacity_control (GTK_COLOR_SELECTION (priv->colorsel), FALSE);
193 gtk_container_add (GTK_CONTAINER (content_area), priv->colorsel);
194 gtk_widget_show (priv->colorsel);
196 priv->cancel_button = gtk_dialog_add_button (dialog,
198 GTK_RESPONSE_CANCEL);
200 priv->ok_button = gtk_dialog_add_button (dialog,
204 gtk_widget_grab_default (priv->ok_button);
206 priv->help_button = gtk_dialog_add_button (dialog,
210 gtk_widget_hide (priv->help_button);
212 gtk_dialog_set_alternative_button_order (dialog,
218 gtk_window_set_title (GTK_WINDOW (colorseldiag),
219 _("Color Selection"));
223 * gtk_color_selection_dialog_new:
224 * @title: a string containing the title text for the dialog.
226 * Creates a new #GtkColorSelectionDialog.
228 * Returns: a #GtkColorSelectionDialog.
231 gtk_color_selection_dialog_new (const gchar *title)
233 GtkColorSelectionDialog *colorseldiag;
235 colorseldiag = g_object_new (GTK_TYPE_COLOR_SELECTION_DIALOG, NULL);
238 gtk_window_set_title (GTK_WINDOW (colorseldiag), title);
240 gtk_window_set_resizable (GTK_WINDOW (colorseldiag), FALSE);
242 return GTK_WIDGET (colorseldiag);
246 * gtk_color_selection_dialog_get_color_selection:
247 * @colorsel: a #GtkColorSelectionDialog
249 * Retrieves the #GtkColorSelection widget embedded in the dialog.
251 * Returns: (transfer none): the embedded #GtkColorSelection
256 gtk_color_selection_dialog_get_color_selection (GtkColorSelectionDialog *colorsel)
258 g_return_val_if_fail (GTK_IS_COLOR_SELECTION_DIALOG (colorsel), NULL);
260 return colorsel->priv->colorsel;
264 gtk_color_selection_dialog_buildable_interface_init (GtkBuildableIface *iface)
266 parent_buildable_iface = g_type_interface_peek_parent (iface);
267 iface->get_internal_child = gtk_color_selection_dialog_buildable_get_internal_child;
271 gtk_color_selection_dialog_buildable_get_internal_child (GtkBuildable *buildable,
273 const gchar *childname)
275 GtkColorSelectionDialog *selection_dialog = GTK_COLOR_SELECTION_DIALOG (buildable);
276 GtkColorSelectionDialogPrivate *priv = selection_dialog->priv;
278 if (g_strcmp0 (childname, "ok_button") == 0)
279 return G_OBJECT (priv->ok_button);
280 else if (g_strcmp0 (childname, "cancel_button") == 0)
281 return G_OBJECT (priv->cancel_button);
282 else if (g_strcmp0 (childname, "help_button") == 0)
283 return G_OBJECT (priv->help_button);
284 else if (g_strcmp0 (childname, "color_selection") == 0)
285 return G_OBJECT (priv->colorsel);
287 return parent_buildable_iface->get_internal_child (buildable, builder, childname);