]> Pileus Git - ~andy/gtk/blob - gtk/a11y/gtkradiobuttonaccessible.c
f7f150d40110ca546eb3ffe0033e1a0c2454baea
[~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, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include "config.h"
21
22 #include <gtk/gtk.h>
23 #include "gtkradiobuttonaccessible.h"
24
25
26 G_DEFINE_TYPE (GtkRadioButtonAccessible, _gtk_radio_button_accessible, GTK_TYPE_TOGGLE_BUTTON_ACCESSIBLE)
27
28 static void
29 gtk_radio_button_accessible_initialize (AtkObject *accessible,
30                                         gpointer   data)
31 {
32   ATK_OBJECT_CLASS (_gtk_radio_button_accessible_parent_class)->initialize (accessible, data);
33
34   accessible->role = ATK_ROLE_RADIO_BUTTON;
35 }
36
37 static AtkRelationSet *
38 gtk_radio_button_accessible_ref_relation_set (AtkObject *obj)
39 {
40   GtkWidget *widget;
41   AtkRelationSet *relation_set;
42   GSList *list;
43   GtkRadioButtonAccessible *radio_button;
44
45   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
46   if (widget == NULL)
47     return NULL;
48
49   radio_button = GTK_RADIO_BUTTON_ACCESSIBLE (obj);
50
51   relation_set = ATK_OBJECT_CLASS (_gtk_radio_button_accessible_parent_class)->ref_relation_set (obj);
52
53   /* If the radio button'group has changed remove the relation */
54   list = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget));
55
56   if (radio_button->old_group != list)
57     {
58       AtkRelation *relation;
59
60       relation = atk_relation_set_get_relation_by_type (relation_set, ATK_RELATION_MEMBER_OF);
61       atk_relation_set_remove (relation_set, relation);
62     }
63
64   if (!atk_relation_set_contains (relation_set, ATK_RELATION_MEMBER_OF))
65   {
66     /*
67      * Get the members of the button group
68      */
69     radio_button->old_group = list;
70     if (list)
71       {
72         AtkObject **accessible_array;
73         guint list_length;
74         AtkRelation* relation;
75         gint i = 0;
76
77         list_length = g_slist_length (list);
78         accessible_array = g_new (AtkObject *, list_length);
79         while (list != NULL)
80           {
81             GtkWidget* list_item = list->data;
82
83             accessible_array[i++] = gtk_widget_get_accessible (list_item);
84
85             list = list->next;
86           }
87         relation = atk_relation_new (accessible_array, list_length,
88                                      ATK_RELATION_MEMBER_OF);
89         g_free (accessible_array);
90
91         atk_relation_set_add (relation_set, relation);
92         /*
93          * Unref the relation so that it is not leaked.
94          */
95         g_object_unref (relation);
96       }
97     }
98
99   return relation_set;
100 }
101
102 static void
103 _gtk_radio_button_accessible_class_init (GtkRadioButtonAccessibleClass *klass)
104 {
105   AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
106
107   class->initialize = gtk_radio_button_accessible_initialize;
108   class->ref_relation_set = gtk_radio_button_accessible_ref_relation_set;
109 }
110
111 static void
112 _gtk_radio_button_accessible_init (GtkRadioButtonAccessible *radio_button)
113 {
114   radio_button->old_group = NULL;
115 }