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"
32 #include "gtkbutton.h"
35 #include "gtkbuildable.h"
39 struct _GtkColorSelectionDialogPrivate
43 GtkWidget *cancel_button;
44 GtkWidget *help_button;
56 /***************************/
57 /* GtkColorSelectionDialog */
58 /***************************/
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,
63 const gchar *childname);
65 G_DEFINE_TYPE_WITH_CODE (GtkColorSelectionDialog, gtk_color_selection_dialog,
67 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
68 gtk_color_selection_dialog_buildable_interface_init))
70 static GtkBuildableIface *parent_buildable_iface;
73 gtk_color_selection_dialog_get_property (GObject *object,
78 GtkColorSelectionDialog *colorsel = GTK_COLOR_SELECTION_DIALOG (object);
79 GtkColorSelectionDialogPrivate *priv = colorsel->priv;
83 case PROP_COLOR_SELECTION:
84 g_value_set_object (value, priv->colorsel);
87 g_value_set_object (value, priv->ok_button);
89 case PROP_CANCEL_BUTTON:
90 g_value_set_object (value, priv->cancel_button);
92 case PROP_HELP_BUTTON:
93 g_value_set_object (value, priv->help_button);
96 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
102 gtk_color_selection_dialog_class_init (GtkColorSelectionDialogClass *klass)
104 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
105 gobject_class->get_property = gtk_color_selection_dialog_get_property;
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."),
114 g_object_class_install_property (gobject_class,
116 g_param_spec_object ("ok-button",
118 P_("The OK button of the dialog."),
121 g_object_class_install_property (gobject_class,
123 g_param_spec_object ("cancel-button",
125 P_("The cancel button of the dialog."),
128 g_object_class_install_property (gobject_class,
130 g_param_spec_object ("help-button",
132 P_("The help button of the dialog."),
136 g_type_class_add_private (klass, sizeof (GtkColorSelectionDialogPrivate));
140 gtk_color_selection_dialog_init (GtkColorSelectionDialog *colorseldiag)
142 GtkColorSelectionDialogPrivate *priv;
143 GtkDialog *dialog = GTK_DIALOG (colorseldiag);
144 GtkWidget *action_area, *content_area;
146 colorseldiag->priv = G_TYPE_INSTANCE_GET_PRIVATE (colorseldiag,
147 GTK_TYPE_COLOR_SELECTION_DIALOG,
148 GtkColorSelectionDialogPrivate);
149 priv = colorseldiag->priv;
151 content_area = gtk_dialog_get_content_area (dialog);
152 action_area = gtk_dialog_get_action_area (dialog);
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);
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);
166 priv->cancel_button = gtk_dialog_add_button (dialog,
168 GTK_RESPONSE_CANCEL);
170 priv->ok_button = gtk_dialog_add_button (dialog,
174 gtk_widget_grab_default (priv->ok_button);
176 priv->help_button = gtk_dialog_add_button (dialog,
180 gtk_widget_hide (priv->help_button);
182 gtk_dialog_set_alternative_button_order (dialog,
188 gtk_window_set_title (GTK_WINDOW (colorseldiag),
189 _("Color Selection"));
193 gtk_color_selection_dialog_new (const gchar *title)
195 GtkColorSelectionDialog *colorseldiag;
197 colorseldiag = g_object_new (GTK_TYPE_COLOR_SELECTION_DIALOG, NULL);
200 gtk_window_set_title (GTK_WINDOW (colorseldiag), title);
202 gtk_window_set_resizable (GTK_WINDOW (colorseldiag), FALSE);
204 return GTK_WIDGET (colorseldiag);
208 * gtk_color_selection_dialog_get_color_selection:
209 * @colorsel: a #GtkColorSelectionDialog
211 * Retrieves the #GtkColorSelection widget embedded in the dialog.
213 * Returns: (transfer none): the embedded #GtkColorSelection
218 gtk_color_selection_dialog_get_color_selection (GtkColorSelectionDialog *colorsel)
220 g_return_val_if_fail (GTK_IS_COLOR_SELECTION_DIALOG (colorsel), NULL);
222 return colorsel->priv->colorsel;
226 gtk_color_selection_dialog_buildable_interface_init (GtkBuildableIface *iface)
228 parent_buildable_iface = g_type_interface_peek_parent (iface);
229 iface->get_internal_child = gtk_color_selection_dialog_buildable_get_internal_child;
233 gtk_color_selection_dialog_buildable_get_internal_child (GtkBuildable *buildable,
235 const gchar *childname)
237 GtkColorSelectionDialog *selection_dialog = GTK_COLOR_SELECTION_DIALOG (buildable);
238 GtkColorSelectionDialogPrivate *priv = selection_dialog->priv;
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);
249 return parent_buildable_iface->get_internal_child (buildable, builder, childname);