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"
27 #include "gtkprivate.h"
35 static void gtk_radio_tool_button_init (GtkRadioToolButton *button);
36 static void gtk_radio_tool_button_class_init (GtkRadioToolButtonClass *klass);
37 static void gtk_radio_tool_button_set_property (GObject *object,
43 gtk_radio_tool_button_get_type (void)
45 static GType type = 0;
49 static const GTypeInfo type_info =
51 sizeof (GtkRadioToolButtonClass),
53 (GBaseFinalizeFunc) NULL,
54 (GClassInitFunc) gtk_radio_tool_button_class_init,
55 (GClassFinalizeFunc) NULL,
57 sizeof (GtkRadioToolButton),
59 (GInstanceInitFunc) gtk_radio_tool_button_init
62 type = g_type_register_static (GTK_TYPE_TOGGLE_TOOL_BUTTON,
63 "GtkRadioToolButton", &type_info, 0);
70 gtk_radio_tool_button_class_init (GtkRadioToolButtonClass *klass)
72 GObjectClass *object_class;
73 GtkToolButtonClass *toolbutton_class;
75 object_class = (GObjectClass *)klass;
76 toolbutton_class = (GtkToolButtonClass *)klass;
78 object_class->set_property = gtk_radio_tool_button_set_property;
80 toolbutton_class->button_type = GTK_TYPE_RADIO_BUTTON;
83 * GtkRadioToolButton:group:
85 * Sets a new group for a radio tool button.
89 g_object_class_install_property (object_class,
91 g_param_spec_object ("group",
93 _("The radio tool button whose group this button belongs to."),
94 GTK_TYPE_RADIO_TOOL_BUTTON,
100 gtk_radio_tool_button_init (GtkRadioToolButton *button)
102 GtkToolButton *tool_button = GTK_TOOL_BUTTON (button);
103 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (_gtk_tool_button_get_button (tool_button)), FALSE);
107 gtk_radio_tool_button_set_property (GObject *object,
112 GtkRadioToolButton *button;
114 button = GTK_RADIO_TOOL_BUTTON (object);
120 GtkRadioToolButton *arg;
121 GSList *slist = NULL;
122 if (G_VALUE_HOLDS_OBJECT (value))
124 arg = GTK_RADIO_TOOL_BUTTON (g_value_get_object (value));
126 slist = gtk_radio_tool_button_get_group (arg);
127 gtk_radio_tool_button_set_group (button, slist);
132 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
138 * gtk_radio_tool_button_new:
139 * @group: An existing radio button group, or %NULL if you are creating a new group
141 * Creates a new #GtkRadioToolButton, adding it to @group.
143 * Return value: The new #GtkRadioToolButton
148 gtk_radio_tool_button_new (GSList *group)
150 GtkRadioToolButton *button;
152 button = g_object_new (GTK_TYPE_RADIO_TOOL_BUTTON,
155 gtk_radio_tool_button_set_group (button, group);
157 return GTK_TOOL_ITEM (button);
161 * gtk_radio_tool_button_new_from_stock:
162 * @group: an existing radio button group, or %NULL if you are creating a new group
163 * @stock_id: the name of a stock item
165 * Creates a new #GtkRadioToolButton, adding it to @group.
166 * The new #GtkRadioToolButton will contain an icon and label from the
167 * stock item indicated by @stock_id.
169 * Return value: The new #GtkRadioToolItem
174 gtk_radio_tool_button_new_from_stock (GSList *group,
175 const gchar *stock_id)
177 GtkRadioToolButton *button;
179 g_return_val_if_fail (stock_id != NULL, NULL);
181 button = g_object_new (GTK_TYPE_RADIO_TOOL_BUTTON,
182 "stock_id", stock_id,
186 gtk_radio_tool_button_set_group (button, group);
188 return GTK_TOOL_ITEM (button);
192 * gtk_radio_tool_button_new_from_widget:
193 * @group: An existing #GtkRadioToolButton
195 * Creates a new #GtkRadioToolButton adding it to the same group as @gruup
197 * Return value: The new #GtkRadioToolButton
202 gtk_radio_tool_button_new_from_widget (GtkRadioToolButton *group)
206 g_return_val_if_fail (GTK_IS_RADIO_TOOL_BUTTON (group), NULL);
209 list = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (group));
211 return gtk_radio_tool_button_new (list);
215 * gtk_radio_tool_button_new_with_stock_from_widget:
216 * @group: An existing #GtkRadioToolButton.
217 * @stock_id: the name of a stock item
219 * Creates a new #GtkRadioToolButton adding it to the same group as @group.
220 * The new #GtkRadioToolButton will contain an icon and label from the
221 * stock item indicated by @stock_id.
223 * Return value: A new #GtkRadioToolButton
228 gtk_radio_tool_button_new_with_stock_from_widget (GtkRadioToolButton *group,
229 const gchar *stock_id)
233 g_return_val_if_fail (GTK_IS_RADIO_TOOL_BUTTON (group), NULL);
236 list = gtk_radio_tool_button_get_group (group);
238 return gtk_radio_tool_button_new_from_stock (list, stock_id);
241 static GtkRadioButton *
242 get_radio_button (GtkRadioToolButton *button)
244 return GTK_RADIO_BUTTON (_gtk_tool_button_get_button (GTK_TOOL_BUTTON (button)));
248 * gtk_radio_tool_button_get_group:
249 * @button: a #GtkRadioToolButton
251 * Returns the radio button group @button belongs to.
253 * Return value: The group @button belongs to.
258 gtk_radio_tool_button_get_group (GtkRadioToolButton *button)
260 g_return_val_if_fail (GTK_IS_RADIO_TOOL_BUTTON (button), NULL);
262 return gtk_radio_button_get_group (get_radio_button (button));
266 * gtk_radio_tool_button_set_group:
267 * @button: a #GtkRadioToolButton
268 * @group: an existing radio button group
270 * Adds @button to @group, removing it from the group it belonged to before.
275 gtk_radio_tool_button_set_group (GtkRadioToolButton *button,
278 g_return_if_fail (GTK_IS_RADIO_TOOL_BUTTON (button));
280 gtk_radio_button_set_group (get_radio_button (button), group);
283 #define __GTK_RADIO_TOOL_BUTTON_C__
284 #include "gtkaliasdef.c"