source: trunk/third/gail/gail/gailradiosubmenuitem.c @ 18341

Revision 18341, 4.6 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18340, which included commits to RCS files with non-trunk default branches.
Line 
1/* GAIL - The GNOME Accessibility Implementation Library
2 * Copyright 2002 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 <gtk/gtk.h>
21#include "gailradiosubmenuitem.h"
22
23static void      gail_radio_sub_menu_item_class_init        (GailRadioSubMenuItemClass *klass);
24static void      gail_radio_sub_menu_item_instance_init     (GailRadioSubMenuItem      *radio_menu_item);
25
26static AtkRelationSet* gail_radio_sub_menu_item_ref_relation_set (AtkObject       *obj)
27;
28
29static GailCheckSubMenuItemClass *parent_class = NULL;
30
31GType
32gail_radio_sub_menu_item_get_type (void)
33{
34  static GType type = 0;
35
36  if (!type)
37  {
38    static const GTypeInfo tinfo =
39    {
40      sizeof (GailRadioSubMenuItemClass),
41      (GBaseInitFunc) NULL, /* base init */
42      (GBaseFinalizeFunc) NULL, /* base finalize */
43      (GClassInitFunc) gail_radio_sub_menu_item_class_init, /* class init */
44      (GClassFinalizeFunc) NULL, /* class finalize */
45      NULL, /* class data */
46      sizeof (GailRadioSubMenuItem), /* instance size */
47      0, /* nb preallocs */
48      (GInstanceInitFunc) gail_radio_sub_menu_item_instance_init, /* instance init */
49      NULL /* value table */
50    };
51
52    type = g_type_register_static (GAIL_TYPE_CHECK_SUB_MENU_ITEM,
53                                   "GailRadioSubMenuItem", &tinfo, 0);
54  }
55
56  return type;
57}
58
59static void
60gail_radio_sub_menu_item_class_init (GailRadioSubMenuItemClass *klass)
61{
62  AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
63
64  parent_class = g_type_class_peek_parent (klass);
65
66  class->ref_relation_set = gail_radio_sub_menu_item_ref_relation_set;
67}
68
69AtkObject*
70gail_radio_sub_menu_item_new (GtkWidget *widget)
71{
72  GObject *object;
73  AtkObject *accessible;
74
75  g_return_val_if_fail (GTK_IS_RADIO_MENU_ITEM (widget), NULL);
76
77  object = g_object_new (GAIL_TYPE_RADIO_SUB_MENU_ITEM, NULL);
78
79  accessible = ATK_OBJECT (object);
80  atk_object_initialize (accessible, widget);
81
82  accessible->role = ATK_ROLE_RADIO_MENU_ITEM;
83  return accessible;
84}
85
86static void
87gail_radio_sub_menu_item_instance_init (GailRadioSubMenuItem *radio_menu_item)
88{
89  radio_menu_item->old_group = NULL;
90}
91
92AtkRelationSet*
93gail_radio_sub_menu_item_ref_relation_set (AtkObject *obj)
94{
95  GtkWidget *widget;
96  AtkRelationSet *relation_set;
97  GSList *list;
98  GailRadioSubMenuItem *radio_menu_item;
99
100  g_return_val_if_fail (GAIL_IS_RADIO_SUB_MENU_ITEM (obj), NULL);
101
102  widget = GTK_ACCESSIBLE (obj)->widget;
103  if (widget == NULL)
104  {
105    /*
106     * State is defunct
107     */
108    return NULL;
109  }
110  radio_menu_item = GAIL_RADIO_SUB_MENU_ITEM (obj);
111
112  relation_set = ATK_OBJECT_CLASS (parent_class)->ref_relation_set (obj);
113
114  /*
115   * If the radio menu_item'group has changed remove the relation
116   */
117  list = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (widget));
118 
119  if (radio_menu_item->old_group != list)
120    {
121      AtkRelation *relation;
122
123      relation = atk_relation_set_get_relation_by_type (relation_set, ATK_RELATION_MEMBER_OF);
124      atk_relation_set_remove (relation_set, relation);
125    }
126
127  if (!atk_relation_set_contains (relation_set, ATK_RELATION_MEMBER_OF))
128  {
129    /*
130     * Get the members of the menu_item group
131     */
132
133    radio_menu_item->old_group = list;
134    if (list)
135    {
136      AtkObject **accessible_array;
137      guint list_length;
138      AtkRelation* relation;
139      gint i = 0;
140
141      list_length = g_slist_length (list);
142      accessible_array = (AtkObject**) g_malloc (sizeof (AtkObject *) *
143                          list_length);
144      while (list != NULL)
145      {
146        GtkWidget* list_item = list->data;
147
148        accessible_array[i++] = gtk_widget_get_accessible (list_item);
149
150        list = list->next;
151      }
152      relation = atk_relation_new (accessible_array, list_length,
153                                   ATK_RELATION_MEMBER_OF);
154      atk_relation_set_add (relation_set, relation);
155      /*
156       * Unref the relation so that it is not leaked.
157       */
158      g_object_unref (relation);
159    }
160  }
161  return relation_set;
162}
Note: See TracBrowser for help on using the repository browser.