]> Pileus Git - ~andy/gtk/blob - gtk/gtkradiotoolbutton.c
46cb83801cd9c40f577332f8312a241d044537b3
[~andy/gtk] / gtk / gtkradiotoolbutton.c
1 /* gtkradiotoolbutton.c
2  *
3  * Copyright (C) 2002 Anders Carlsson <andersca@codefactory.se>
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   gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (GTK_TOOL_BUTTON (button)->button), FALSE);
71 }
72
73 GtkToolItem *
74 gtk_radio_tool_button_new (GSList *group)
75 {
76   GtkRadioToolButton *button;
77   
78   button = g_object_new (GTK_TYPE_RADIO_TOOL_BUTTON,
79                          NULL);
80
81   gtk_radio_tool_button_set_group (button, group);
82   
83   return GTK_TOOL_ITEM (button);
84 }
85
86 GtkToolItem *
87 gtk_radio_tool_button_new_from_stock (GSList      *group,
88                                       const gchar *stock_id)
89 {
90   GtkRadioToolButton *button;
91
92   g_return_val_if_fail (stock_id != NULL, NULL);
93   
94   button = g_object_new (GTK_TYPE_RADIO_TOOL_BUTTON,
95                          "stock_id", stock_id,
96                          NULL);
97
98
99   gtk_radio_tool_button_set_group (button, group);
100   
101   return GTK_TOOL_ITEM (button);
102 }
103
104 GtkToolItem *
105 gtk_radio_tool_button_new_from_widget (GtkWidget   *group,
106                                        const gchar *stock_id)
107 {
108   GSList *list = NULL;
109   
110   g_return_val_if_fail (GTK_IS_RADIO_TOOL_BUTTON (group), NULL);
111
112   if (group)
113     list = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (group));
114   
115   return gtk_radio_tool_button_new_from_stock (list, stock_id);
116 }
117
118 GtkToolItem *
119 gtk_radio_tool_button_new_with_stock_from_widget (GtkWidget *group)
120 {
121   GSList *list = NULL;
122   
123   g_return_val_if_fail (GTK_IS_RADIO_TOOL_BUTTON (group), NULL);
124
125   if (group)
126     list = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (group));
127   
128   return gtk_radio_tool_button_new (list);
129 }
130
131 GSList *
132 gtk_radio_tool_button_get_group (GtkRadioToolButton *button)
133 {
134   g_return_val_if_fail (GTK_IS_RADIO_TOOL_BUTTON (button), NULL);
135
136   return gtk_radio_button_get_group (GTK_RADIO_BUTTON (GTK_TOOL_BUTTON (button)->button));
137 }
138
139 void
140 gtk_radio_tool_button_set_group (GtkRadioToolButton *button,
141                                  GSList             *group)
142 {
143   g_return_if_fail (GTK_IS_RADIO_TOOL_BUTTON (button));
144
145   gtk_radio_button_set_group (GTK_RADIO_BUTTON (GTK_TOOL_BUTTON (button)->button), group);
146 }
147