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.
25 #include "gtkradiotoolbutton.h"
26 #include "gtkradiobutton.h"
34 static void gtk_radio_tool_button_init (GtkRadioToolButton *button);
35 static void gtk_radio_tool_button_class_init (GtkRadioToolButtonClass *klass);
36 static void gtk_radio_tool_button_set_property (GObject *object,
42 gtk_radio_tool_button_get_type (void)
44 static GType type = 0;
48 static const GTypeInfo type_info =
50 sizeof (GtkRadioToolButtonClass),
52 (GBaseFinalizeFunc) NULL,
53 (GClassInitFunc) gtk_radio_tool_button_class_init,
54 (GClassFinalizeFunc) NULL,
56 sizeof (GtkRadioToolButton),
58 (GInstanceInitFunc) gtk_radio_tool_button_init
61 type = g_type_register_static (GTK_TYPE_TOGGLE_TOOL_BUTTON,
62 "GtkRadioToolButton", &type_info, 0);
69 gtk_radio_tool_button_class_init (GtkRadioToolButtonClass *klass)
71 GObjectClass *object_class;
72 GtkToolButtonClass *toolbutton_class;
74 object_class = (GObjectClass *)klass;
75 toolbutton_class = (GtkToolButtonClass *)klass;
77 object_class->set_property = gtk_radio_tool_button_set_property;
79 toolbutton_class->button_type = GTK_TYPE_RADIO_BUTTON;
82 * GtkRadioToolButton:group:
84 * Sets a new group for a radio tool button.
88 g_object_class_install_property (object_class,
90 g_param_spec_object ("group",
92 _("The radio tool button whose group this button belongs to."),
93 GTK_TYPE_RADIO_TOOL_BUTTON,
99 gtk_radio_tool_button_init (GtkRadioToolButton *button)
101 GtkToolButton *tool_button = GTK_TOOL_BUTTON (button);
102 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (_gtk_tool_button_get_button (tool_button)), FALSE);
106 gtk_radio_tool_button_set_property (GObject *object,
111 GtkRadioToolButton *button;
113 button = GTK_RADIO_TOOL_BUTTON (object);
119 GtkRadioToolButton *arg;
120 GSList *slist = NULL;
121 if (G_VALUE_HOLDS_OBJECT (value))
123 arg = GTK_RADIO_TOOL_BUTTON (g_value_get_object (value));
125 slist = gtk_radio_tool_button_get_group (arg);
126 gtk_radio_tool_button_set_group (button, slist);
131 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
137 * gtk_radio_tool_button_new:
138 * @group: An existing radio button group, or %NULL if you are creating a new group
140 * Creates a new #GtkRadioToolButton, adding it to @group.
142 * Return value: The new #GtkRadioToolButton
147 gtk_radio_tool_button_new (GSList *group)
149 GtkRadioToolButton *button;
151 button = g_object_new (GTK_TYPE_RADIO_TOOL_BUTTON,
154 gtk_radio_tool_button_set_group (button, group);
156 return GTK_TOOL_ITEM (button);
160 * gtk_radio_tool_button_new_from_stock:
161 * @group: an existing radio button group, or %NULL if you are creating a new group
162 * @stock_id: the name of a stock item
164 * Creates a new #GtkRadioToolButton, adding it to @group.
165 * The new #GtkRadioToolButton will contain an icon and label from the
166 * stock item indicated by @stock_id.
168 * Return value: The new #GtkRadioToolItem
173 gtk_radio_tool_button_new_from_stock (GSList *group,
174 const gchar *stock_id)
176 GtkRadioToolButton *button;
178 g_return_val_if_fail (stock_id != NULL, NULL);
180 button = g_object_new (GTK_TYPE_RADIO_TOOL_BUTTON,
181 "stock_id", stock_id,
185 gtk_radio_tool_button_set_group (button, group);
187 return GTK_TOOL_ITEM (button);
191 * gtk_radio_tool_button_new_from_widget:
192 * @group: An existing #GtkRadioToolButton
194 * Creates a new #GtkRadioToolButton adding it to the same group as @gruup
196 * Return value: The new #GtkRadioToolButton
201 gtk_radio_tool_button_new_from_widget (GtkRadioToolButton *group)
205 g_return_val_if_fail (GTK_IS_RADIO_TOOL_BUTTON (group), NULL);
208 list = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (group));
210 return gtk_radio_tool_button_new (list);
214 * gtk_radio_tool_button_new_with_stock_from_widget:
215 * @group: An existing #GtkRadioToolButton.
216 * @stock_id: the name of a stock item
218 * Creates a new #GtkRadioToolButton adding it to the same group as @group.
219 * The new #GtkRadioToolButton will contain an icon and label from the
220 * stock item indicated by @stock_id.
222 * Return value: A new #GtkRadioToolButton
227 gtk_radio_tool_button_new_with_stock_from_widget (GtkRadioToolButton *group,
228 const gchar *stock_id)
232 g_return_val_if_fail (GTK_IS_RADIO_TOOL_BUTTON (group), NULL);
235 list = gtk_radio_tool_button_get_group (group);
237 return gtk_radio_tool_button_new_from_stock (list, stock_id);
240 static GtkRadioButton *
241 get_radio_button (GtkRadioToolButton *button)
243 return GTK_RADIO_BUTTON (_gtk_tool_button_get_button (GTK_TOOL_BUTTON (button)));
247 * gtk_radio_tool_button_get_group:
248 * @button: a #GtkRadioToolButton
250 * Returns the radio button group @button belongs to.
252 * Return value: The group @button belongs to.
257 gtk_radio_tool_button_get_group (GtkRadioToolButton *button)
259 g_return_val_if_fail (GTK_IS_RADIO_TOOL_BUTTON (button), NULL);
261 return gtk_radio_button_get_group (get_radio_button (button));
265 * gtk_radio_tool_button_set_group:
266 * @button: a #GtkRadioToolButton
267 * @group: an existing radio button group
269 * Adds @button to @group, removing it from the group it belonged to before.
274 gtk_radio_tool_button_set_group (GtkRadioToolButton *button,
277 g_return_if_fail (GTK_IS_RADIO_TOOL_BUTTON (button));
279 gtk_radio_button_set_group (get_radio_button (button), group);