2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001, 2002 Sun Microsystems Inc.,
6 * Copyright 2001, 2002 Ximian, Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
24 /* relation.c : implements the Relation interface */
28 #include <libspi/accessible.h>
29 #include <libspi/relation.h>
33 spi_init_relation_type_table (Accessibility_RelationType *types)
37 for (i = 0; i < ATK_RELATION_LAST_DEFINED; i++)
38 types[i] = Accessibility_RELATION_NULL;
40 types[ATK_RELATION_CONTROLLED_BY] = Accessibility_RELATION_CONTROLLED_BY;
41 types[ATK_RELATION_CONTROLLER_FOR] = Accessibility_RELATION_CONTROLLER_FOR;
42 types[ATK_RELATION_LABEL_FOR] = Accessibility_RELATION_LABEL_FOR;
43 types[ATK_RELATION_LABELLED_BY] = Accessibility_RELATION_LABELLED_BY;
44 types[ATK_RELATION_MEMBER_OF] = Accessibility_RELATION_MEMBER_OF;
45 types[ATK_RELATION_NODE_CHILD_OF] = Accessibility_RELATION_NODE_CHILD_OF;
46 types[ATK_RELATION_FLOWS_TO] = Accessibility_RELATION_FLOWS_TO;
47 types[ATK_RELATION_FLOWS_FROM] = Accessibility_RELATION_FLOWS_FROM;
48 types[ATK_RELATION_SUBWINDOW_OF] = Accessibility_RELATION_SUBWINDOW_OF;
49 types[ATK_RELATION_EMBEDS] = Accessibility_RELATION_EMBEDS;
50 types[ATK_RELATION_EMBEDDED_BY] = Accessibility_RELATION_EMBEDDED_BY;
51 types[ATK_RELATION_POPUP_FOR] = Accessibility_RELATION_POPUP_FOR;
52 types[ATK_RELATION_PARENT_WINDOW_OF] = Accessibility_RELATION_PARENT_WINDOW_OF;
53 types[ATK_RELATION_DESCRIPTION_FOR] = Accessibility_RELATION_DESCRIPTION_FOR;
54 types[ATK_RELATION_DESCRIBED_BY] = Accessibility_RELATION_DESCRIBED_BY;
61 static Accessibility_RelationType
62 spi_relation_type_from_atk_relation_type (AtkRelationType type)
64 static gboolean is_initialized = FALSE;
65 static Accessibility_RelationType spi_relation_type_table [ATK_RELATION_LAST_DEFINED];
66 Accessibility_RelationType spi_type;
69 is_initialized = spi_init_relation_type_table (spi_relation_type_table);
71 if (type > ATK_RELATION_NULL && type < ATK_RELATION_LAST_DEFINED)
72 spi_type = spi_relation_type_table[type];
74 spi_type = Accessibility_RELATION_EXTENDED;
81 get_relation_from_servant (PortableServer_Servant servant)
83 SpiBase *base = SPI_BASE (bonobo_object_from_servant(servant));
85 g_return_val_if_fail (base, NULL);
86 return ATK_RELATION(base->gobj);
91 static Accessibility_RelationType
92 impl_getRelationType (PortableServer_Servant servant,
93 CORBA_Environment * ev)
95 AtkRelation *relation = get_relation_from_servant (servant);
98 g_return_val_if_fail (relation != NULL, 0);
99 type = atk_relation_get_relation_type (relation);
100 return spi_relation_type_from_atk_relation_type (type);
105 impl_getNTargets (PortableServer_Servant servant,
106 CORBA_Environment * ev)
108 AtkRelation *relation = get_relation_from_servant(servant);
109 g_return_val_if_fail (relation != NULL, 0);
111 return relation->target ? relation->target->len : 0;
116 impl_getTarget (PortableServer_Servant servant,
117 const CORBA_short index,
118 CORBA_Environment * ev)
120 AtkObject *atk_object;
121 AtkRelation *relation = get_relation_from_servant (servant);
122 g_return_val_if_fail (relation, NULL);
124 if (!relation->target ||
126 index >= relation->target->len)
127 return CORBA_OBJECT_NIL;
129 atk_object = g_ptr_array_index (relation->target, index);
131 return CORBA_OBJECT_NIL;
133 return spi_accessible_new_return (atk_object, FALSE, ev);
138 spi_relation_new (AtkRelation *obj)
140 SpiRelation *new_relation = g_object_new (SPI_RELATION_TYPE, NULL);
141 spi_base_construct (SPI_BASE (new_relation), G_OBJECT (obj));
147 spi_relation_class_init (SpiRelationClass *klass)
149 POA_Accessibility_Relation__epv *epv = &klass->epv;
151 epv->getRelationType = impl_getRelationType;
152 epv->getNTargets = impl_getNTargets;
153 epv->getTarget = impl_getTarget;
158 spi_relation_init (SpiRelation *relation)
163 BONOBO_TYPE_FUNC_FULL (SpiRelation,
164 Accessibility_Relation,