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