1 /* GAIL - The GNOME Accessibility Implementation Library
2 * Copyright 2001 Sun Microsystems Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
23 #include "gailradiobutton.h"
25 static void gail_radio_button_class_init (GailRadioButtonClass *klass);
26 static void gail_radio_button_init (GailRadioButton *radio_button);
27 static void gail_radio_button_initialize (AtkObject *accessible,
30 static AtkRelationSet* gail_radio_button_ref_relation_set (AtkObject *obj);
32 G_DEFINE_TYPE (GailRadioButton, gail_radio_button, GAIL_TYPE_TOGGLE_BUTTON)
35 gail_radio_button_class_init (GailRadioButtonClass *klass)
37 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
39 class->initialize = gail_radio_button_initialize;
40 class->ref_relation_set = gail_radio_button_ref_relation_set;
44 gail_radio_button_init (GailRadioButton *radio_button)
46 radio_button->old_group = NULL;
50 gail_radio_button_initialize (AtkObject *accessible,
53 ATK_OBJECT_CLASS (gail_radio_button_parent_class)->initialize (accessible, data);
55 accessible->role = ATK_ROLE_RADIO_BUTTON;
59 gail_radio_button_ref_relation_set (AtkObject *obj)
62 AtkRelationSet *relation_set;
64 GailRadioButton *radio_button;
66 g_return_val_if_fail (GAIL_IS_RADIO_BUTTON (obj), NULL);
68 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
76 radio_button = GAIL_RADIO_BUTTON (obj);
78 relation_set = ATK_OBJECT_CLASS (gail_radio_button_parent_class)->ref_relation_set (obj);
81 * If the radio button'group has changed remove the relation
83 list = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget));
85 if (radio_button->old_group != list)
87 AtkRelation *relation;
89 relation = atk_relation_set_get_relation_by_type (relation_set, ATK_RELATION_MEMBER_OF);
90 atk_relation_set_remove (relation_set, relation);
93 if (!atk_relation_set_contains (relation_set, ATK_RELATION_MEMBER_OF))
96 * Get the members of the button group
99 radio_button->old_group = list;
102 AtkObject **accessible_array;
104 AtkRelation* relation;
107 list_length = g_slist_length (list);
108 accessible_array = (AtkObject**) g_malloc (sizeof (AtkObject *) *
112 GtkWidget* list_item = list->data;
114 accessible_array[i++] = gtk_widget_get_accessible (list_item);
118 relation = atk_relation_new (accessible_array, list_length,
119 ATK_RELATION_MEMBER_OF);
120 g_free (accessible_array);
122 atk_relation_set_add (relation_set, relation);
124 * Unref the relation so that it is not leaked.
126 g_object_unref (relation);