1 /* gtkradiotoolbutton.c
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>
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.
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.
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.
24 #include "gtkradiotoolbutton.h"
25 #include "gtkradiobutton.h"
33 static void gtk_radio_tool_button_init (GtkRadioToolButton *button);
34 static void gtk_radio_tool_button_class_init (GtkRadioToolButtonClass *klass);
35 static void gtk_radio_tool_button_set_property (GObject *object,
41 gtk_radio_tool_button_get_type (void)
43 static GType type = 0;
47 static const GTypeInfo type_info =
49 sizeof (GtkRadioToolButtonClass),
51 (GBaseFinalizeFunc) NULL,
52 (GClassInitFunc) gtk_radio_tool_button_class_init,
53 (GClassFinalizeFunc) NULL,
55 sizeof (GtkRadioToolButton),
57 (GInstanceInitFunc) gtk_radio_tool_button_init
60 type = g_type_register_static (GTK_TYPE_TOGGLE_TOOL_BUTTON,
61 "GtkRadioToolButton", &type_info, 0);
68 gtk_radio_tool_button_class_init (GtkRadioToolButtonClass *klass)
70 GObjectClass *object_class;
71 GtkToolButtonClass *toolbutton_class;
73 object_class = (GObjectClass *)klass;
74 toolbutton_class = (GtkToolButtonClass *)klass;
76 object_class->set_property = gtk_radio_tool_button_set_property;
78 toolbutton_class->button_type = GTK_TYPE_RADIO_BUTTON;
81 * GtkRadioToolButton:group:
83 * Sets a new group for a radio tool button.
87 g_object_class_install_property (object_class,
89 g_param_spec_object ("group",
91 _("The radio tool button whose group this button belongs to."),
92 GTK_TYPE_RADIO_TOOL_BUTTON,
98 gtk_radio_tool_button_init (GtkRadioToolButton *button)
100 GtkToolButton *tool_button = GTK_TOOL_BUTTON (button);
101 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (_gtk_tool_button_get_button (tool_button)), FALSE);
105 gtk_radio_tool_button_set_property (GObject *object,
110 GtkRadioToolButton *button;
112 button = GTK_RADIO_TOOL_BUTTON (object);
118 GtkRadioToolButton *arg;
119 GSList *slist = NULL;
120 if (G_VALUE_HOLDS_OBJECT (value))
122 arg = GTK_RADIO_TOOL_BUTTON (g_value_get_object (value));
124 slist = gtk_radio_tool_button_get_group (arg);
125 gtk_radio_tool_button_set_group (button, slist);
130 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
136 * gtk_radio_tool_button_new:
137 * @group: An existing radio button group, or %NULL if you are creating a new group
139 * Creates a new #GtkRadioToolButton, adding it to @group.
141 * Return value: The new #GtkRadioToolButton
146 gtk_radio_tool_button_new (GSList *group)
148 GtkRadioToolButton *button;
150 button = g_object_new (GTK_TYPE_RADIO_TOOL_BUTTON,
153 gtk_radio_tool_button_set_group (button, group);
155 return GTK_TOOL_ITEM (button);
159 * gtk_radio_tool_button_new_from_stock:
160 * @group: an existing radio button group, or %NULL if you are creating a new group
161 * @stock_id: the name of a stock item
163 * Creates a new #GtkRadioToolButton, adding it to @group.
164 * The new #GtkRadioToolButton will contain an icon and label from the
165 * stock item indicated by @stock_id.
167 * Return value: The new #GtkRadioToolItem
172 gtk_radio_tool_button_new_from_stock (GSList *group,
173 const gchar *stock_id)
175 GtkRadioToolButton *button;
177 g_return_val_if_fail (stock_id != NULL, NULL);
179 button = g_object_new (GTK_TYPE_RADIO_TOOL_BUTTON,
180 "stock_id", stock_id,
184 gtk_radio_tool_button_set_group (button, group);
186 return GTK_TOOL_ITEM (button);
190 * gtk_radio_tool_button_new_from_widget:
191 * @group: An existing #GtkRadioToolButton
193 * Creates a new #GtkRadioToolButton adding it to the same group as @gruup
195 * Return value: The new #GtkRadioToolButton
200 gtk_radio_tool_button_new_from_widget (GtkRadioToolButton *group)
204 g_return_val_if_fail (GTK_IS_RADIO_TOOL_BUTTON (group), NULL);
207 list = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (group));
209 return gtk_radio_tool_button_new (list);
213 * gtk_radio_tool_button_new_with_stock_from_widget:
214 * @group: An existing #GtkRadioToolButton.
215 * @stock_id: the name of a stock item
217 * Creates a new #GtkRadioToolButton adding it to the same group as @group.
218 * The new #GtkRadioToolButton will contain an icon and label from the
219 * stock item indicated by @stock_id.
221 * Return value: A new #GtkRadioToolButton
226 gtk_radio_tool_button_new_with_stock_from_widget (GtkRadioToolButton *group,
227 const gchar *stock_id)
231 g_return_val_if_fail (GTK_IS_RADIO_TOOL_BUTTON (group), NULL);
234 list = gtk_radio_tool_button_get_group (group);
236 return gtk_radio_tool_button_new_from_stock (list, stock_id);
239 static GtkRadioButton *
240 get_radio_button (GtkRadioToolButton *button)
242 return GTK_RADIO_BUTTON (_gtk_tool_button_get_button (GTK_TOOL_BUTTON (button)));
246 * gtk_radio_tool_button_get_group:
247 * @button: a #GtkRadioToolButton
249 * Returns the radio button group @button belongs to.
251 * Return value: The group @button belongs to.
256 gtk_radio_tool_button_get_group (GtkRadioToolButton *button)
258 g_return_val_if_fail (GTK_IS_RADIO_TOOL_BUTTON (button), NULL);
260 return gtk_radio_button_get_group (get_radio_button (button));
264 * gtk_radio_tool_button_set_group:
265 * @button: a #GtkRadioToolButton
266 * @group: an existing radio button group
268 * Adds @button to @group, removing it from the group it belonged to before.
273 gtk_radio_tool_button_set_group (GtkRadioToolButton *button,
276 g_return_if_fail (GTK_IS_RADIO_TOOL_BUTTON (button));
278 gtk_radio_button_set_group (get_radio_button (button), group);