1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
#include "egg-radio-action.h"
static void egg_radio_action_init (EggRadioAction *action);
static void egg_radio_action_class_init (EggRadioActionClass *class);
GType
egg_radio_action_get_type (void)
{
static GtkType type = 0;
if (!type)
{
static const GTypeInfo type_info =
{
sizeof (EggRadioActionClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) egg_radio_action_class_init,
(GClassFinalizeFunc) NULL,
NULL,
sizeof (EggRadioAction),
0, /* n_preallocs */
(GInstanceInitFunc) egg_radio_action_init,
};
type = g_type_register_static (EGG_TYPE_TOGGLE_ACTION,
"EggRadioAction",
&type_info, 0);
}
return type;
}
static void egg_radio_action_finalize (GObject *object);
static void egg_radio_action_activate (EggAction *action);
static GObjectClass *parent_class = NULL;
static void
egg_radio_action_class_init (EggRadioActionClass *class)
{
GObjectClass *object_class;
EggActionClass *action_class;
parent_class = g_type_class_peek_parent (class);
object_class = G_OBJECT_CLASS (class);
action_class = EGG_ACTION_CLASS (class);
object_class->finalize = egg_radio_action_finalize;
action_class->activate = egg_radio_action_activate;
}
static void
egg_radio_action_init (EggRadioAction *action)
{
action->group = g_slist_prepend (NULL, action);
}
static void
egg_radio_action_finalize (GObject *object)
{
EggRadioAction *action;
GSList *tmp_list;
g_return_if_fail (EGG_IS_RADIO_ACTION (object));
action = EGG_RADIO_ACTION (object);
action->group = g_slist_remove (action->group, action);
tmp_list = action->group;
while (tmp_list)
{
EggRadioAction *tmp_action = tmp_list->data;
tmp_list = tmp_list->next;
tmp_action->group = action->group;
}
if (parent_class->finalize)
(* parent_class->finalize) (object);
}
static void
egg_radio_action_activate (EggAction *action)
{
EggRadioAction *radio_action;
EggToggleAction *toggle_action;
EggToggleAction *tmp_action;
GSList *tmp_list;
g_return_if_fail (EGG_IS_RADIO_ACTION (action));
radio_action = EGG_RADIO_ACTION (action);
toggle_action = EGG_TOGGLE_ACTION (action);
if (toggle_action->active)
{
tmp_list = radio_action->group;
while (tmp_list)
{
tmp_action = tmp_list->data;
tmp_list = tmp_list->next;
if (tmp_action->active && (tmp_action != toggle_action))
{
toggle_action->active = !toggle_action->active;
break;
}
}
}
else
{
toggle_action->active = !toggle_action->active;
tmp_list = radio_action->group;
while (tmp_list)
{
tmp_action = tmp_list->data;
tmp_list = tmp_list->next;
if (tmp_action->active && (tmp_action != toggle_action))
{
egg_action_activate (EGG_ACTION (tmp_action));
break;
}
}
}
egg_toggle_action_toggled (toggle_action);
}
/**
* egg_radio_action_get_group:
* @action: the action object
*
* Returns: the list representing the radio group for this object
*/
GSList *
egg_radio_action_get_group (EggRadioAction *action)
{
g_return_val_if_fail (EGG_IS_RADIO_ACTION (action), NULL);
return action->group;
}
/**
* egg_radio_action_set_group:
* @action: the action object
* @group: a list representing a radio group
*
* Sets the radio group for the radio action object.
*/
void
egg_radio_action_set_group (EggRadioAction *action, GSList *group)
{
g_return_if_fail (EGG_IS_RADIO_ACTION (action));
g_return_if_fail (!g_slist_find (group, action));
if (action->group)
{
GSList *slist;
action->group = g_slist_remove (action->group, action);
for (slist = action->group; slist; slist = slist->next)
{
EggRadioAction *tmp_action = slist->data;
tmp_action->group = action->group;
}
}
action->group = g_slist_prepend (group, action);
if (group)
{
GSList *slist;
for (slist = action->group; slist; slist = slist->next)
{
EggRadioAction *tmp_action = slist->data;
tmp_action->group = action->group;
}
}
else
{
EGG_TOGGLE_ACTION (action)->active = TRUE;
}
}
|