]> Pileus Git - ~andy/gtk/blob - gtk/a11y/gtkradiobuttonaccessible.c
Change FSF Address
[~andy/gtk] / gtk / a11y / gtkradiobuttonaccessible.c
1 /* GAIL - The GNOME Accessibility Implementation Library
2  * Copyright 2001 Sun Microsystems Inc.
3  *
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.
8  *
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.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #include "config.h"
19
20 #include <gtk/gtk.h>
21 #include "gtkradiobuttonaccessible.h"
22
23
24 G_DEFINE_TYPE (GtkRadioButtonAccessible, _gtk_radio_button_accessible, GTK_TYPE_TOGGLE_BUTTON_ACCESSIBLE)
25
26 static void
27 gtk_radio_button_accessible_initialize (AtkObject *accessible,
28                                         gpointer   data)
29 {
30   ATK_OBJECT_CLASS (_gtk_radio_button_accessible_parent_class)->initialize (accessible, data);
31
32   accessible->role = ATK_ROLE_RADIO_BUTTON;
33 }
34
35 static AtkRelationSet *
36 gtk_radio_button_accessible_ref_relation_set (AtkObject *obj)
37 {
38   GtkWidget *widget;
39   AtkRelationSet *relation_set;
40   GSList *list;
41   GtkRadioButtonAccessible *radio_button;
42
43   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
44   if (widget == NULL)
45     return NULL;
46
47   radio_button = GTK_RADIO_BUTTON_ACCESSIBLE (obj);
48
49   relation_set = ATK_OBJECT_CLASS (_gtk_radio_button_accessible_parent_class)->ref_relation_set (obj);
50
51   /* If the radio button'group has changed remove the relation */
52   list = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget));
53
54   if (radio_button->old_group != list)
55     {
56       AtkRelation *relation;
57
58       relation = atk_relation_set_get_relation_by_type (relation_set, ATK_RELATION_MEMBER_OF);
59       atk_relation_set_remove (relation_set, relation);
60     }
61
62   if (!atk_relation_set_contains (relation_set, ATK_RELATION_MEMBER_OF))
63   {
64     /*
65      * Get the members of the button group
66      */
67     radio_button->old_group = list;
68     if (list)
69       {
70         AtkObject **accessible_array;
71         guint list_length;
72         AtkRelation* relation;
73         gint i = 0;
74
75         list_length = g_slist_length (list);
76         accessible_array = g_new (AtkObject *, list_length);
77         while (list != NULL)
78           {
79             GtkWidget* list_item = list->data;
80
81             accessible_array[i++] = gtk_widget_get_accessible (list_item);
82
83             list = list->next;
84           }
85         relation = atk_relation_new (accessible_array, list_length,
86                                      ATK_RELATION_MEMBER_OF);
87         g_free (accessible_array);
88
89         atk_relation_set_add (relation_set, relation);
90         /*
91          * Unref the relation so that it is not leaked.
92          */
93         g_object_unref (relation);
94       }
95     }
96
97   return relation_set;
98 }
99
100 static void
101 _gtk_radio_button_accessible_class_init (GtkRadioButtonAccessibleClass *klass)
102 {
103   AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
104
105   class->initialize = gtk_radio_button_accessible_initialize;
106   class->ref_relation_set = gtk_radio_button_accessible_ref_relation_set;
107 }
108
109 static void
110 _gtk_radio_button_accessible_init (GtkRadioButtonAccessible *radio_button)
111 {
112   radio_button->old_group = NULL;
113 }