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