]> Pileus Git - ~andy/gtk/blob - gtk/gtkradiotoolbutton.c
Make PLT-reduction work with gcc4, and don't include everything in
[~andy/gtk] / gtk / gtkradiotoolbutton.c
1 /* gtkradiotoolbutton.c
2  *
3  * Copyright (C) 2002 Anders Carlsson <andersca@gnome.og>
4  * Copyright (C) 2002 James Henstridge <james@daa.com.au>
5  * Copyright (C) 2003 Soeren Sandmann <sandmann@daimi.au.dk>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #include <config.h>
24 #include "gtkradiotoolbutton.h"
25 #include "gtkradiobutton.h"
26 #include "gtkintl.h"
27 #include "gtkalias.h"
28
29 enum {
30   PROP_0,
31   PROP_GROUP
32 };
33
34 static void gtk_radio_tool_button_init         (GtkRadioToolButton      *button);
35 static void gtk_radio_tool_button_class_init   (GtkRadioToolButtonClass *klass);
36 static void gtk_radio_tool_button_set_property (GObject         *object,
37                                                 guint            prop_id,
38                                                 const GValue    *value,
39                                                 GParamSpec      *pspec);
40
41 GType
42 gtk_radio_tool_button_get_type (void)
43 {
44   static GType type = 0;
45
46   if (!type)
47     {
48       static const GTypeInfo type_info =
49         {
50           sizeof (GtkRadioToolButtonClass),
51           (GBaseInitFunc) NULL,
52           (GBaseFinalizeFunc) NULL,
53           (GClassInitFunc) gtk_radio_tool_button_class_init,
54           (GClassFinalizeFunc) NULL,
55           NULL,
56           sizeof (GtkRadioToolButton),
57           0, /* n_preallocs */
58           (GInstanceInitFunc) gtk_radio_tool_button_init
59         };
60
61       type = g_type_register_static (GTK_TYPE_TOGGLE_TOOL_BUTTON,
62                                      "GtkRadioToolButton", &type_info, 0);
63     }
64   return type;
65 }
66
67      
68 static void
69 gtk_radio_tool_button_class_init (GtkRadioToolButtonClass *klass)
70 {
71   GObjectClass *object_class;
72   GtkToolButtonClass *toolbutton_class;
73
74   object_class = (GObjectClass *)klass;
75   toolbutton_class = (GtkToolButtonClass *)klass;
76
77   object_class->set_property = gtk_radio_tool_button_set_property;
78   
79   toolbutton_class->button_type = GTK_TYPE_RADIO_BUTTON;  
80
81   /**
82    * GtkRadioToolButton:group:
83    *
84    * Sets a new group for a radio tool button.
85    *
86    * Since: 2.4
87    */
88   g_object_class_install_property (object_class,
89                                    PROP_GROUP,
90                                    g_param_spec_object ("group",
91                                                         _("Group"),
92                                                         _("The radio tool button whose group this button belongs to."),
93                                                         GTK_TYPE_RADIO_TOOL_BUTTON,
94                                                         G_PARAM_WRITABLE));
95
96 }
97
98 static void
99 gtk_radio_tool_button_init (GtkRadioToolButton *button)
100 {
101   GtkToolButton *tool_button = GTK_TOOL_BUTTON (button);
102   gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (_gtk_tool_button_get_button (tool_button)), FALSE);
103 }
104
105 static void
106 gtk_radio_tool_button_set_property (GObject         *object,
107                                     guint            prop_id,
108                                     const GValue    *value,
109                                     GParamSpec      *pspec)
110 {
111   GtkRadioToolButton *button;
112
113   button = GTK_RADIO_TOOL_BUTTON (object);
114
115   switch (prop_id)
116     {
117     case PROP_GROUP:
118       {
119         GtkRadioToolButton *arg;
120         GSList *slist = NULL;
121         if (G_VALUE_HOLDS_OBJECT (value)) 
122           {
123             arg = GTK_RADIO_TOOL_BUTTON (g_value_get_object (value));
124             if (arg)
125               slist = gtk_radio_tool_button_get_group (arg);
126             gtk_radio_tool_button_set_group (button, slist);
127           }
128       }
129       break;
130     default:
131       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
132       break;
133     }
134 }
135
136 /**
137  * gtk_radio_tool_button_new:
138  * @group: An existing radio button group, or %NULL if you are creating a new group
139  * 
140  * Creates a new #GtkRadioToolButton, adding it to @group.
141  * 
142  * Return value: The new #GtkRadioToolButton
143  * 
144  * Since: 2.4
145  **/
146 GtkToolItem *
147 gtk_radio_tool_button_new (GSList *group)
148 {
149   GtkRadioToolButton *button;
150   
151   button = g_object_new (GTK_TYPE_RADIO_TOOL_BUTTON,
152                          NULL);
153
154   gtk_radio_tool_button_set_group (button, group);
155   
156   return GTK_TOOL_ITEM (button);
157 }
158
159 /**
160  * gtk_radio_tool_button_new_from_stock:
161  * @group: an existing radio button group, or %NULL if you are creating a new group
162  * @stock_id: the name of a stock item
163  * 
164  * Creates a new #GtkRadioToolButton, adding it to @group. 
165  * The new #GtkRadioToolButton will contain an icon and label from the
166  * stock item indicated by @stock_id.
167  * 
168  * Return value: The new #GtkRadioToolItem
169  * 
170  * Since: 2.4
171  **/
172 GtkToolItem *
173 gtk_radio_tool_button_new_from_stock (GSList      *group,
174                                       const gchar *stock_id)
175 {
176   GtkRadioToolButton *button;
177
178   g_return_val_if_fail (stock_id != NULL, NULL);
179   
180   button = g_object_new (GTK_TYPE_RADIO_TOOL_BUTTON,
181                          "stock_id", stock_id,
182                          NULL);
183
184
185   gtk_radio_tool_button_set_group (button, group);
186   
187   return GTK_TOOL_ITEM (button);
188 }
189
190 /**
191  * gtk_radio_tool_button_new_from_widget:
192  * @group: An existing #GtkRadioToolButton
193  * 
194  * Creates a new #GtkRadioToolButton adding it to the same group as @gruup
195  * 
196  * Return value: The new #GtkRadioToolButton
197  * 
198  * Since: 2.4
199  **/
200 GtkToolItem *
201 gtk_radio_tool_button_new_from_widget (GtkRadioToolButton *group)
202 {
203   GSList *list = NULL;
204   
205   g_return_val_if_fail (GTK_IS_RADIO_TOOL_BUTTON (group), NULL);
206
207   if (group)
208     list = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (group));
209   
210   return gtk_radio_tool_button_new (list);
211 }
212
213 /**
214  * gtk_radio_tool_button_new_with_stock_from_widget:
215  * @group: An existing #GtkRadioToolButton.
216  * @stock_id: the name of a stock item 
217  * 
218  * Creates a new #GtkRadioToolButton adding it to the same group as @group.
219  * The new #GtkRadioToolButton will contain an icon and label from the
220  * stock item indicated by @stock_id.
221  * 
222  * Return value: A new #GtkRadioToolButton
223  * 
224  * Since: 2.4
225  **/
226 GtkToolItem *
227 gtk_radio_tool_button_new_with_stock_from_widget (GtkRadioToolButton *group,
228                                                   const gchar        *stock_id)
229 {
230   GSList *list = NULL;
231   
232   g_return_val_if_fail (GTK_IS_RADIO_TOOL_BUTTON (group), NULL);
233
234   if (group)
235     list = gtk_radio_tool_button_get_group (group);
236   
237   return gtk_radio_tool_button_new_from_stock (list, stock_id);
238 }
239
240 static GtkRadioButton *
241 get_radio_button (GtkRadioToolButton *button)
242 {
243   return GTK_RADIO_BUTTON (_gtk_tool_button_get_button (GTK_TOOL_BUTTON (button)));
244 }
245
246 /**
247  * gtk_radio_tool_button_get_group:
248  * @button: a #GtkRadioToolButton
249  *
250  * Returns the radio button group @button belongs to.
251  * 
252  * Return value: The group @button belongs to.
253  * 
254  * Since: 2.4
255  **/
256 GSList *
257 gtk_radio_tool_button_get_group (GtkRadioToolButton *button)
258 {
259   g_return_val_if_fail (GTK_IS_RADIO_TOOL_BUTTON (button), NULL);
260
261   return gtk_radio_button_get_group (get_radio_button (button));
262 }
263
264 /**
265  * gtk_radio_tool_button_set_group:
266  * @button: a #GtkRadioToolButton
267  * @group: an existing radio button group
268  * 
269  * Adds @button to @group, removing it from the group it belonged to before.
270  * 
271  * Since: 2.4
272  **/
273 void
274 gtk_radio_tool_button_set_group (GtkRadioToolButton *button,
275                                  GSList             *group)
276 {
277   g_return_if_fail (GTK_IS_RADIO_TOOL_BUTTON (button));
278
279   gtk_radio_button_set_group (get_radio_button (button), group);
280 }
281
282 #define __GTK_RADIO_TOOL_BUTTON_C__
283 #include "gtkaliasdef.c"