]> Pileus Git - ~andy/gtk/blob - gtk/gtkradiotoolbutton.c
remove correction on x when detail is "menuitem". With the new menu look
[~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   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 GtkToolItem *
75 gtk_radio_tool_button_new (GSList *group)
76 {
77   GtkRadioToolButton *button;
78   
79   button = g_object_new (GTK_TYPE_RADIO_TOOL_BUTTON,
80                          NULL);
81
82   gtk_radio_tool_button_set_group (button, group);
83   
84   return GTK_TOOL_ITEM (button);
85 }
86
87 GtkToolItem *
88 gtk_radio_tool_button_new_from_stock (GSList      *group,
89                                       const gchar *stock_id)
90 {
91   GtkRadioToolButton *button;
92
93   g_return_val_if_fail (stock_id != NULL, NULL);
94   
95   button = g_object_new (GTK_TYPE_RADIO_TOOL_BUTTON,
96                          "stock_id", stock_id,
97                          NULL);
98
99
100   gtk_radio_tool_button_set_group (button, group);
101   
102   return GTK_TOOL_ITEM (button);
103 }
104
105 GtkToolItem *
106 gtk_radio_tool_button_new_from_widget (GtkWidget   *group,
107                                        const gchar *stock_id)
108 {
109   GSList *list = NULL;
110   
111   g_return_val_if_fail (GTK_IS_RADIO_TOOL_BUTTON (group), NULL);
112
113   if (group)
114     list = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (group));
115   
116   return gtk_radio_tool_button_new_from_stock (list, stock_id);
117 }
118
119 GtkToolItem *
120 gtk_radio_tool_button_new_with_stock_from_widget (GtkWidget *group)
121 {
122   GSList *list = NULL;
123   
124   g_return_val_if_fail (GTK_IS_RADIO_TOOL_BUTTON (group), NULL);
125
126   if (group)
127     list = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (group));
128   
129   return gtk_radio_tool_button_new (list);
130 }
131
132 static GtkRadioButton *
133 get_radio_button (GtkRadioToolButton *button)
134 {
135   return GTK_RADIO_BUTTON (_gtk_tool_button_get_button (GTK_TOOL_BUTTON (button)));
136 }
137
138 GSList *
139 gtk_radio_tool_button_get_group (GtkRadioToolButton *button)
140 {
141   g_return_val_if_fail (GTK_IS_RADIO_TOOL_BUTTON (button), NULL);
142
143   return gtk_radio_button_get_group (get_radio_button (button));
144 }
145
146 void
147 gtk_radio_tool_button_set_group (GtkRadioToolButton *button,
148                                  GSList             *group)
149 {
150   g_return_if_fail (GTK_IS_RADIO_TOOL_BUTTON (button));
151
152   gtk_radio_button_set_group (get_radio_button (button), group);
153 }
154