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