Debian Codegraph @

gtk/a11y/gtkradiobuttonaccessible.c

raw
1 /* GTK+ - accessibility implementations
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 struct _GtkRadioButtonAccessiblePrivate
24 {
25 GSList *old_group;
26 };
27
28
29 G_DEFINE_TYPE_WITH_PRIVATE (GtkRadioButtonAccessible, gtk_radio_button_accessible, GTK_TYPE_TOGGLE_BUTTON_ACCESSIBLE)
30
31 static void
32 gtk_radio_button_accessible_initialize (AtkObject *accessible,
33 gpointer data)
34 {
35 ATK_OBJECT_CLASS (gtk_radio_button_accessible_parent_class)->initialize (accessible, data);
36
37 accessible->role = ATK_ROLE_RADIO_BUTTON;
38 }
39
40 static AtkRelationSet *
41 gtk_radio_button_accessible_ref_relation_set (AtkObject *obj)
42 {
43 GtkWidget *widget;
44 AtkRelationSet *relation_set;
45 GSList *list;
46 GtkRadioButtonAccessible *radio_button;
47
48 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
49 if (widget == NULL)
50 return NULL;
51
52 radio_button = GTK_RADIO_BUTTON_ACCESSIBLE (obj);
53
54 relation_set = ATK_OBJECT_CLASS (gtk_radio_button_accessible_parent_class)->ref_relation_set (obj);
55
56 /* If the radio button'group has changed remove the relation */
57 list = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget));
58
59 if (radio_button->priv->old_group != list)
60 {
61 AtkRelation *relation;
62
63 relation = atk_relation_set_get_relation_by_type (relation_set, ATK_RELATION_MEMBER_OF);
64 atk_relation_set_remove (relation_set, relation);
65 }
66
67 if (!atk_relation_set_contains (relation_set, ATK_RELATION_MEMBER_OF))
68 {
69 /*
70 * Get the members of the button group
71 */
72 radio_button->priv->old_group = list;
73 if (list)
74 {
75 AtkObject **accessible_array;
76 guint list_length;
77 AtkRelation* relation;
78 gint i = 0;
79
80 list_length = g_slist_length (list);
81 accessible_array = g_new (AtkObject *, list_length);
82 while (list != NULL)
83 {
84 GtkWidget* list_item = list->data;
85
86 accessible_array[i++] = gtk_widget_get_accessible (list_item);
87
88 list = list->next;
89 }
90 relation = atk_relation_new (accessible_array, list_length,
91 ATK_RELATION_MEMBER_OF);
92 g_free (accessible_array);
93
94 atk_relation_set_add (relation_set, relation);
95 /*
96 * Unref the relation so that it is not leaked.
97 */
98 g_object_unref (relation);
99 }
100 }
101
102 return relation_set;
103 }
104
105 static void
106 gtk_radio_button_accessible_class_init (GtkRadioButtonAccessibleClass *klass)
107 {
108 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
109
110 class->initialize = gtk_radio_button_accessible_initialize;
111 class->ref_relation_set = gtk_radio_button_accessible_ref_relation_set;
112 }
113
114 static void
115 gtk_radio_button_accessible_init (GtkRadioButtonAccessible *radio_button)
116 {
117 radio_button->priv = gtk_radio_button_accessible_get_instance_private (radio_button);
118 }