]> Pileus Git - ~andy/gtk/blob - gtk/gtkradiotoolbutton.c
Define macros GTK_PARAM_READABLE, GTK_PARAM_WRITABLE, GTK_PARAM_READWRITE
[~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 "gtkprivate.h"
28 #include "gtkalias.h"
29
30 enum {
31   PROP_0,
32   PROP_GROUP
33 };
34
35 static void gtk_radio_tool_button_init         (GtkRadioToolButton      *button);
36 static void gtk_radio_tool_button_class_init   (GtkRadioToolButtonClass *klass);
37 static void gtk_radio_tool_button_set_property (GObject         *object,
38                                                 guint            prop_id,
39                                                 const GValue    *value,
40                                                 GParamSpec      *pspec);
41
42 GType
43 gtk_radio_tool_button_get_type (void)
44 {
45   static GType type = 0;
46
47   if (!type)
48     {
49       static const GTypeInfo type_info =
50         {
51           sizeof (GtkRadioToolButtonClass),
52           (GBaseInitFunc) NULL,
53           (GBaseFinalizeFunc) NULL,
54           (GClassInitFunc) gtk_radio_tool_button_class_init,
55           (GClassFinalizeFunc) NULL,
56           NULL,
57           sizeof (GtkRadioToolButton),
58           0, /* n_preallocs */
59           (GInstanceInitFunc) gtk_radio_tool_button_init
60         };
61
62       type = g_type_register_static (GTK_TYPE_TOGGLE_TOOL_BUTTON,
63                                      "GtkRadioToolButton", &type_info, 0);
64     }
65   return type;
66 }
67
68      
69 static void
70 gtk_radio_tool_button_class_init (GtkRadioToolButtonClass *klass)
71 {
72   GObjectClass *object_class;
73   GtkToolButtonClass *toolbutton_class;
74
75   object_class = (GObjectClass *)klass;
76   toolbutton_class = (GtkToolButtonClass *)klass;
77
78   object_class->set_property = gtk_radio_tool_button_set_property;
79   
80   toolbutton_class->button_type = GTK_TYPE_RADIO_BUTTON;  
81
82   /**
83    * GtkRadioToolButton:group:
84    *
85    * Sets a new group for a radio tool button.
86    *
87    * Since: 2.4
88    */
89   g_object_class_install_property (object_class,
90                                    PROP_GROUP,
91                                    g_param_spec_object ("group",
92                                                         _("Group"),
93                                                         _("The radio tool button whose group this button belongs to."),
94                                                         GTK_TYPE_RADIO_TOOL_BUTTON,
95                                                         GTK_PARAM_WRITABLE));
96
97 }
98
99 static void
100 gtk_radio_tool_button_init (GtkRadioToolButton *button)
101 {
102   GtkToolButton *tool_button = GTK_TOOL_BUTTON (button);
103   gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (_gtk_tool_button_get_button (tool_button)), FALSE);
104 }
105
106 static void
107 gtk_radio_tool_button_set_property (GObject         *object,
108                                     guint            prop_id,
109                                     const GValue    *value,
110                                     GParamSpec      *pspec)
111 {
112   GtkRadioToolButton *button;
113
114   button = GTK_RADIO_TOOL_BUTTON (object);
115
116   switch (prop_id)
117     {
118     case PROP_GROUP:
119       {
120         GtkRadioToolButton *arg;
121         GSList *slist = NULL;
122         if (G_VALUE_HOLDS_OBJECT (value)) 
123           {
124             arg = GTK_RADIO_TOOL_BUTTON (g_value_get_object (value));
125             if (arg)
126               slist = gtk_radio_tool_button_get_group (arg);
127             gtk_radio_tool_button_set_group (button, slist);
128           }
129       }
130       break;
131     default:
132       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
133       break;
134     }
135 }
136
137 /**
138  * gtk_radio_tool_button_new:
139  * @group: An existing radio button group, or %NULL if you are creating a new group
140  * 
141  * Creates a new #GtkRadioToolButton, adding it to @group.
142  * 
143  * Return value: The new #GtkRadioToolButton
144  * 
145  * Since: 2.4
146  **/
147 GtkToolItem *
148 gtk_radio_tool_button_new (GSList *group)
149 {
150   GtkRadioToolButton *button;
151   
152   button = g_object_new (GTK_TYPE_RADIO_TOOL_BUTTON,
153                          NULL);
154
155   gtk_radio_tool_button_set_group (button, group);
156   
157   return GTK_TOOL_ITEM (button);
158 }
159
160 /**
161  * gtk_radio_tool_button_new_from_stock:
162  * @group: an existing radio button group, or %NULL if you are creating a new group
163  * @stock_id: the name of a stock item
164  * 
165  * Creates a new #GtkRadioToolButton, adding it to @group. 
166  * The new #GtkRadioToolButton will contain an icon and label from the
167  * stock item indicated by @stock_id.
168  * 
169  * Return value: The new #GtkRadioToolItem
170  * 
171  * Since: 2.4
172  **/
173 GtkToolItem *
174 gtk_radio_tool_button_new_from_stock (GSList      *group,
175                                       const gchar *stock_id)
176 {
177   GtkRadioToolButton *button;
178
179   g_return_val_if_fail (stock_id != NULL, NULL);
180   
181   button = g_object_new (GTK_TYPE_RADIO_TOOL_BUTTON,
182                          "stock_id", stock_id,
183                          NULL);
184
185
186   gtk_radio_tool_button_set_group (button, group);
187   
188   return GTK_TOOL_ITEM (button);
189 }
190
191 /**
192  * gtk_radio_tool_button_new_from_widget:
193  * @group: An existing #GtkRadioToolButton
194  * 
195  * Creates a new #GtkRadioToolButton adding it to the same group as @gruup
196  * 
197  * Return value: The new #GtkRadioToolButton
198  * 
199  * Since: 2.4
200  **/
201 GtkToolItem *
202 gtk_radio_tool_button_new_from_widget (GtkRadioToolButton *group)
203 {
204   GSList *list = NULL;
205   
206   g_return_val_if_fail (GTK_IS_RADIO_TOOL_BUTTON (group), NULL);
207
208   if (group)
209     list = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (group));
210   
211   return gtk_radio_tool_button_new (list);
212 }
213
214 /**
215  * gtk_radio_tool_button_new_with_stock_from_widget:
216  * @group: An existing #GtkRadioToolButton.
217  * @stock_id: the name of a stock item 
218  * 
219  * Creates a new #GtkRadioToolButton adding it to the same group as @group.
220  * The new #GtkRadioToolButton will contain an icon and label from the
221  * stock item indicated by @stock_id.
222  * 
223  * Return value: A new #GtkRadioToolButton
224  * 
225  * Since: 2.4
226  **/
227 GtkToolItem *
228 gtk_radio_tool_button_new_with_stock_from_widget (GtkRadioToolButton *group,
229                                                   const gchar        *stock_id)
230 {
231   GSList *list = NULL;
232   
233   g_return_val_if_fail (GTK_IS_RADIO_TOOL_BUTTON (group), NULL);
234
235   if (group)
236     list = gtk_radio_tool_button_get_group (group);
237   
238   return gtk_radio_tool_button_new_from_stock (list, stock_id);
239 }
240
241 static GtkRadioButton *
242 get_radio_button (GtkRadioToolButton *button)
243 {
244   return GTK_RADIO_BUTTON (_gtk_tool_button_get_button (GTK_TOOL_BUTTON (button)));
245 }
246
247 /**
248  * gtk_radio_tool_button_get_group:
249  * @button: a #GtkRadioToolButton
250  *
251  * Returns the radio button group @button belongs to.
252  * 
253  * Return value: The group @button belongs to.
254  * 
255  * Since: 2.4
256  **/
257 GSList *
258 gtk_radio_tool_button_get_group (GtkRadioToolButton *button)
259 {
260   g_return_val_if_fail (GTK_IS_RADIO_TOOL_BUTTON (button), NULL);
261
262   return gtk_radio_button_get_group (get_radio_button (button));
263 }
264
265 /**
266  * gtk_radio_tool_button_set_group:
267  * @button: a #GtkRadioToolButton
268  * @group: an existing radio button group
269  * 
270  * Adds @button to @group, removing it from the group it belonged to before.
271  * 
272  * Since: 2.4
273  **/
274 void
275 gtk_radio_tool_button_set_group (GtkRadioToolButton *button,
276                                  GSList             *group)
277 {
278   g_return_if_fail (GTK_IS_RADIO_TOOL_BUTTON (button));
279
280   gtk_radio_button_set_group (get_radio_button (button), group);
281 }
282
283 #define __GTK_RADIO_TOOL_BUTTON_C__
284 #include "gtkaliasdef.c"