]> Pileus Git - ~andy/gtk/blob - gtk/gtkradiotoolbutton.c
Change API so group is a GtkRadioButton, not a GtkWidget.
[~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 "gtkradiotoolbutton.h"
24 #include "gtkradiobutton.h"
25 #include "gtkintl.h"
26
27 static void gtk_radio_tool_button_init       (GtkRadioToolButton      *button);
28 static void gtk_radio_tool_button_class_init (GtkRadioToolButtonClass *klass);
29
30 GType
31 gtk_radio_tool_button_get_type (void)
32 {
33   static GType type = 0;
34
35   if (!type)
36     {
37       static const GTypeInfo type_info =
38         {
39           sizeof (GtkRadioToolButtonClass),
40           (GBaseInitFunc) NULL,
41           (GBaseFinalizeFunc) NULL,
42           (GClassInitFunc) gtk_radio_tool_button_class_init,
43           (GClassFinalizeFunc) NULL,
44           NULL,
45           sizeof (GtkRadioToolButton),
46           0, /* n_preallocs */
47           (GInstanceInitFunc) gtk_radio_tool_button_init
48         };
49
50       type = g_type_register_static (GTK_TYPE_TOGGLE_TOOL_BUTTON,
51                                      "GtkRadioToolButton", &type_info, 0);
52     }
53   return type;
54 }
55
56      
57 static void
58 gtk_radio_tool_button_class_init (GtkRadioToolButtonClass *klass)
59 {
60   GtkToolButtonClass *toolbutton_class;
61
62   toolbutton_class = (GtkToolButtonClass *)klass;
63   
64   toolbutton_class->button_type = GTK_TYPE_RADIO_BUTTON;  
65 }
66
67 static void
68 gtk_radio_tool_button_init (GtkRadioToolButton *button)
69 {
70   GtkToolButton *tool_button = GTK_TOOL_BUTTON (button);
71   gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (_gtk_tool_button_get_button (tool_button)), FALSE);
72 }
73
74 /**
75  * gtk_radio_tool_button_new:
76  * @group: An existing radio button group, or %NULL if you are creating a new group
77  * 
78  * Creates a new #GtkRadioToolButton, adding it to @group.
79  * 
80  * Return value: The new #GtkRadioToolButton
81  * 
82  * Since: 2.4
83  **/
84 GtkToolItem *
85 gtk_radio_tool_button_new (GSList *group)
86 {
87   GtkRadioToolButton *button;
88   
89   button = g_object_new (GTK_TYPE_RADIO_TOOL_BUTTON,
90                          NULL);
91
92   gtk_radio_tool_button_set_group (button, group);
93   
94   return GTK_TOOL_ITEM (button);
95 }
96
97 /**
98  * gtk_radio_tool_button_new_from_stock:
99  * @group: an existing radio button group, or %NULL if you are creating a new group
100  * @stock_id: the name of a stock item
101  * 
102  * Creates a new #GtkRadioToolButton, adding it to @group. 
103  * The new #GtkRadioToolButton will contain an icon and label from the
104  * stock item indicated by @stock_id.
105  * 
106  * Return value: The new #GtkRadioToolItem
107  * 
108  * Since: 2.4
109  **/
110 GtkToolItem *
111 gtk_radio_tool_button_new_from_stock (GSList      *group,
112                                       const gchar *stock_id)
113 {
114   GtkRadioToolButton *button;
115
116   g_return_val_if_fail (stock_id != NULL, NULL);
117   
118   button = g_object_new (GTK_TYPE_RADIO_TOOL_BUTTON,
119                          "stock_id", stock_id,
120                          NULL);
121
122
123   gtk_radio_tool_button_set_group (button, group);
124   
125   return GTK_TOOL_ITEM (button);
126 }
127
128 /**
129  * gtk_radio_tool_button_new_from_widget:
130  * @group: An existing #GtkRadioToolButton
131  * 
132  * Creates a new #GtkRadioToolButton adding it to the same group as @gruup
133  * 
134  * Return value: The new #GtkRadioToolButton
135  * 
136  * Since: 2.4
137  **/
138 GtkToolItem *
139 gtk_radio_tool_button_new_from_widget (GtkRadioToolButton *group)
140 {
141   GSList *list = NULL;
142   
143   g_return_val_if_fail (GTK_IS_RADIO_TOOL_BUTTON (group), NULL);
144
145   if (group)
146     list = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (group));
147   
148   return gtk_radio_tool_button_new (list);
149 }
150
151 /**
152  * gtk_radio_tool_button_new_with_stock_from_widget:
153  * @group: An existing #GtkRadioToolButton.
154  * @stock_id: the name of a stock item 
155  * 
156  * Creates a new #GtkRadioToolButton adding it to the same group as @group.
157  * The new #GtkRadioToolButton will contain an icon and label from the
158  * stock item indicated by @stock_id.
159  * 
160  * Return value: A new #GtkRadioToolButton
161  * 
162  * Since: 2.4
163  **/
164 GtkToolItem *
165 gtk_radio_tool_button_new_with_stock_from_widget (GtkRadioToolButton *group,
166                                                   const gchar        *stock_id)
167 {
168   GSList *list = NULL;
169   
170   g_return_val_if_fail (GTK_IS_RADIO_TOOL_BUTTON (group), NULL);
171
172   if (group)
173     list = gtk_radio_tool_button_get_group (group);
174   
175   return gtk_radio_tool_button_new_from_stock (list, stock_id);
176 }
177
178 static GtkRadioButton *
179 get_radio_button (GtkRadioToolButton *button)
180 {
181   return GTK_RADIO_BUTTON (_gtk_tool_button_get_button (GTK_TOOL_BUTTON (button)));
182 }
183
184 /**
185  * gtk_radio_tool_button_get_group:
186  * @button: a #GtkRadioToolButton
187  *
188  * Returns the radio button group @button belongs to.
189  * 
190  * Return value: The group @button belongs to.
191  * 
192  * Since: 2.4
193  **/
194 GSList *
195 gtk_radio_tool_button_get_group (GtkRadioToolButton *button)
196 {
197   g_return_val_if_fail (GTK_IS_RADIO_TOOL_BUTTON (button), NULL);
198
199   return gtk_radio_button_get_group (get_radio_button (button));
200 }
201
202 /**
203  * gtk_radio_tool_button_set_group:
204  * @button: a #GtkRadioToolButton
205  * @group: an existing radio button group
206  * 
207  * Adds @button to @group, removing it from the group it belonged to before.
208  * 
209  * Since: 2.4
210  **/
211 void
212 gtk_radio_tool_button_set_group (GtkRadioToolButton *button,
213                                  GSList             *group)
214 {
215   g_return_if_fail (GTK_IS_RADIO_TOOL_BUTTON (button));
216
217   gtk_radio_button_set_group (get_radio_button (button), group);
218 }
219