]> Pileus Git - ~andy/gtk/blob - modules/other/gail/gailradiobutton.c
46b85a002715224488680c3b430f6a03268f272b
[~andy/gtk] / modules / other / gail / gailradiobutton.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 "gailradiobutton.h"
24
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,
28                                                       gpointer              data);
29
30 static AtkRelationSet* gail_radio_button_ref_relation_set (AtkObject       *obj);
31
32 G_DEFINE_TYPE (GailRadioButton, gail_radio_button, GAIL_TYPE_TOGGLE_BUTTON)
33
34 static void
35 gail_radio_button_class_init (GailRadioButtonClass *klass)
36 {
37   AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
38
39   class->initialize = gail_radio_button_initialize;
40   class->ref_relation_set = gail_radio_button_ref_relation_set;
41 }
42
43 static void
44 gail_radio_button_init (GailRadioButton *radio_button)
45 {
46   radio_button->old_group = NULL;
47 }
48
49 static void
50 gail_radio_button_initialize (AtkObject *accessible,
51                               gpointer  data)
52 {
53   ATK_OBJECT_CLASS (gail_radio_button_parent_class)->initialize (accessible, data);
54
55   accessible->role = ATK_ROLE_RADIO_BUTTON;
56 }
57
58 AtkRelationSet*
59 gail_radio_button_ref_relation_set (AtkObject *obj)
60 {
61   GtkWidget *widget;
62   AtkRelationSet *relation_set;
63   GSList *list;
64   GailRadioButton *radio_button;
65
66   g_return_val_if_fail (GAIL_IS_RADIO_BUTTON (obj), NULL);
67
68   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
69   if (widget == NULL)
70   {
71     /*
72      * State is defunct
73      */
74     return NULL;
75   }
76   radio_button = GAIL_RADIO_BUTTON (obj);
77
78   relation_set = ATK_OBJECT_CLASS (gail_radio_button_parent_class)->ref_relation_set (obj);
79
80   /*
81    * If the radio button'group has changed remove the relation
82    */
83   list = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget));
84   
85   if (radio_button->old_group != list)
86     {
87       AtkRelation *relation;
88
89       relation = atk_relation_set_get_relation_by_type (relation_set, ATK_RELATION_MEMBER_OF);
90       atk_relation_set_remove (relation_set, relation);
91     }
92
93   if (!atk_relation_set_contains (relation_set, ATK_RELATION_MEMBER_OF))
94   {
95     /*
96      * Get the members of the button group
97      */
98
99     radio_button->old_group = list;
100     if (list)
101     {
102       AtkObject **accessible_array;
103       guint list_length;
104       AtkRelation* relation;
105       gint i = 0;
106
107       list_length = g_slist_length (list);
108       accessible_array = (AtkObject**) g_malloc (sizeof (AtkObject *) * 
109                           list_length);
110       while (list != NULL)
111       {
112         GtkWidget* list_item = list->data;
113
114         accessible_array[i++] = gtk_widget_get_accessible (list_item);
115
116         list = list->next;
117       }
118       relation = atk_relation_new (accessible_array, list_length,
119                                    ATK_RELATION_MEMBER_OF);
120       g_free (accessible_array);
121
122       atk_relation_set_add (relation_set, relation);
123       /*
124        * Unref the relation so that it is not leaked.
125        */
126       g_object_unref (relation);
127     }
128   }
129   return relation_set;
130 }