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, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
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/.
29 #include "gtkcolorseldialog.h"
31 #include "gtkbutton.h"
34 #include "gtkbuildable.h"
38 * SECTION:gtkcolorseldlg
39 * @Short_description: A standard dialog box for selecting a color
40 * @Title: GtkColorSelectionDialog
42 * The #GtkColorSelectionDialog provides a standard dialog which
43 * allows the user to select a color much like the #GtkFileSelection
44 * provides a standard dialog for file selection.
46 * Use gtk_color_selection_dialog_get_color_selection() to get the
47 * #GtkColorSelection widget contained within the dialog. Use this widget
48 * and its gtk_color_selection_get_current_color()
49 * function to gain access to the selected color. Connect a handler
50 * for this widget's #GtkColorSelection::color-changed signal to be notified
51 * when the color changes.
53 * <refsect2 id="GtkColorSelectionDialog-BUILDER-UI">
54 * <title>GtkColorSelectionDialog as GtkBuildable</title>
55 * The GtkColorSelectionDialog implementation of the GtkBuildable interface
56 * exposes the embedded #GtkColorSelection as internal child with the
57 * name "color_selection". It also exposes the buttons with the names
58 * "ok_button", "cancel_button" and "help_button".
63 struct _GtkColorSelectionDialogPrivate
67 GtkWidget *cancel_button;
68 GtkWidget *help_button;
80 /***************************/
81 /* GtkColorSelectionDialog */
82 /***************************/
84 static void gtk_color_selection_dialog_buildable_interface_init (GtkBuildableIface *iface);
85 static GObject * gtk_color_selection_dialog_buildable_get_internal_child (GtkBuildable *buildable,
87 const gchar *childname);
89 G_DEFINE_TYPE_WITH_CODE (GtkColorSelectionDialog, gtk_color_selection_dialog,
91 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
92 gtk_color_selection_dialog_buildable_interface_init))
94 static GtkBuildableIface *parent_buildable_iface;
97 gtk_color_selection_dialog_get_property (GObject *object,
102 GtkColorSelectionDialog *colorsel = GTK_COLOR_SELECTION_DIALOG (object);
103 GtkColorSelectionDialogPrivate *priv = colorsel->priv;
107 case PROP_COLOR_SELECTION:
108 g_value_set_object (value, priv->colorsel);
111 g_value_set_object (value, priv->ok_button);
113 case PROP_CANCEL_BUTTON:
114 g_value_set_object (value, priv->cancel_button);
116 case PROP_HELP_BUTTON:
117 g_value_set_object (value, priv->help_button);
120 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
126 gtk_color_selection_dialog_class_init (GtkColorSelectionDialogClass *klass)
128 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
129 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
131 gobject_class->get_property = gtk_color_selection_dialog_get_property;
133 g_object_class_install_property (gobject_class,
134 PROP_COLOR_SELECTION,
135 g_param_spec_object ("color-selection",
136 P_("Color Selection"),
137 P_("The color selection embedded in the dialog."),
140 g_object_class_install_property (gobject_class,
142 g_param_spec_object ("ok-button",
144 P_("The OK button of the dialog."),
147 g_object_class_install_property (gobject_class,
149 g_param_spec_object ("cancel-button",
151 P_("The cancel button of the dialog."),
154 g_object_class_install_property (gobject_class,
156 g_param_spec_object ("help-button",
158 P_("The help button of the dialog."),
162 gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_COLOR_CHOOSER);
164 g_type_class_add_private (klass, sizeof (GtkColorSelectionDialogPrivate));
168 gtk_color_selection_dialog_init (GtkColorSelectionDialog *colorseldiag)
170 GtkColorSelectionDialogPrivate *priv;
171 GtkDialog *dialog = GTK_DIALOG (colorseldiag);
172 GtkWidget *action_area, *content_area;
174 colorseldiag->priv = G_TYPE_INSTANCE_GET_PRIVATE (colorseldiag,
175 GTK_TYPE_COLOR_SELECTION_DIALOG,
176 GtkColorSelectionDialogPrivate);
177 priv = colorseldiag->priv;
179 content_area = gtk_dialog_get_content_area (dialog);
180 action_area = gtk_dialog_get_action_area (dialog);
182 gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
183 gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
184 gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
185 gtk_box_set_spacing (GTK_BOX (action_area), 6);
187 priv->colorsel = gtk_color_selection_new ();
188 gtk_container_set_border_width (GTK_CONTAINER (priv->colorsel), 5);
189 gtk_color_selection_set_has_palette (GTK_COLOR_SELECTION (priv->colorsel), FALSE);
190 gtk_color_selection_set_has_opacity_control (GTK_COLOR_SELECTION (priv->colorsel), FALSE);
191 gtk_container_add (GTK_CONTAINER (content_area), priv->colorsel);
192 gtk_widget_show (priv->colorsel);
194 priv->cancel_button = gtk_dialog_add_button (dialog,
196 GTK_RESPONSE_CANCEL);
198 priv->ok_button = gtk_dialog_add_button (dialog,
202 gtk_widget_grab_default (priv->ok_button);
204 priv->help_button = gtk_dialog_add_button (dialog,
208 gtk_widget_hide (priv->help_button);
210 gtk_dialog_set_alternative_button_order (dialog,
216 gtk_window_set_title (GTK_WINDOW (colorseldiag),
217 _("Color Selection"));
221 * gtk_color_selection_dialog_new:
222 * @title: a string containing the title text for the dialog.
224 * Creates a new #GtkColorSelectionDialog.
226 * Returns: a #GtkColorSelectionDialog.
229 gtk_color_selection_dialog_new (const gchar *title)
231 GtkColorSelectionDialog *colorseldiag;
233 colorseldiag = g_object_new (GTK_TYPE_COLOR_SELECTION_DIALOG, NULL);
236 gtk_window_set_title (GTK_WINDOW (colorseldiag), title);
238 gtk_window_set_resizable (GTK_WINDOW (colorseldiag), FALSE);
240 return GTK_WIDGET (colorseldiag);
244 * gtk_color_selection_dialog_get_color_selection:
245 * @colorsel: a #GtkColorSelectionDialog
247 * Retrieves the #GtkColorSelection widget embedded in the dialog.
249 * Returns: (transfer none): the embedded #GtkColorSelection
254 gtk_color_selection_dialog_get_color_selection (GtkColorSelectionDialog *colorsel)
256 g_return_val_if_fail (GTK_IS_COLOR_SELECTION_DIALOG (colorsel), NULL);
258 return colorsel->priv->colorsel;
262 gtk_color_selection_dialog_buildable_interface_init (GtkBuildableIface *iface)
264 parent_buildable_iface = g_type_interface_peek_parent (iface);
265 iface->get_internal_child = gtk_color_selection_dialog_buildable_get_internal_child;
269 gtk_color_selection_dialog_buildable_get_internal_child (GtkBuildable *buildable,
271 const gchar *childname)
273 GtkColorSelectionDialog *selection_dialog = GTK_COLOR_SELECTION_DIALOG (buildable);
274 GtkColorSelectionDialogPrivate *priv = selection_dialog->priv;
276 if (g_strcmp0 (childname, "ok_button") == 0)
277 return G_OBJECT (priv->ok_button);
278 else if (g_strcmp0 (childname, "cancel_button") == 0)
279 return G_OBJECT (priv->cancel_button);
280 else if (g_strcmp0 (childname, "help_button") == 0)
281 return G_OBJECT (priv->help_button);
282 else if (g_strcmp0 (childname, "color_selection") == 0)
283 return G_OBJECT (priv->colorsel);
285 return parent_buildable_iface->get_internal_child (buildable, builder, childname);