2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001 Sun Microsystems Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 /* relation.c : implements the Relation interface */
27 #include <libspi/accessible.h>
28 #include <libspi/relation.h>
32 spi_init_relation_type_table (Accessibility_RelationType *types)
36 for (i = 0; i < ATK_RELATION_LAST_DEFINED; i++)
37 types[i] = ATK_RELATION_NULL;
39 types[ATK_RELATION_CONTROLLED_BY] = Accessibility_RELATION_CONTROLLED_BY;
40 types[ATK_RELATION_CONTROLLER_FOR] = Accessibility_RELATION_CONTROLLER_FOR;
41 types[ATK_RELATION_LABEL_FOR] = Accessibility_RELATION_LABEL_FOR;
42 types[ATK_RELATION_LABELLED_BY] = Accessibility_RELATION_LABELLED_BY;
43 types[ATK_RELATION_MEMBER_OF] = Accessibility_RELATION_MEMBER_OF;
44 types[ATK_RELATION_NODE_CHILD_OF] = Accessibility_RELATION_NODE_CHILD_OF;
50 static Accessibility_RelationType
51 spi_relation_type_from_atk_relation_type (AtkRelationType type)
53 static gboolean is_initialized = FALSE;
54 static Accessibility_RelationType spi_relation_type_table [ATK_RELATION_LAST_DEFINED];
55 Accessibility_RelationType spi_type;
58 is_initialized = spi_init_relation_type_table (spi_relation_type_table);
60 if (type > ATK_RELATION_NULL && type < ATK_RELATION_LAST_DEFINED)
61 spi_type = spi_relation_type_table[type];
63 spi_type = Accessibility_RELATION_EXTENDED;
70 get_relation_from_servant (PortableServer_Servant servant)
72 SpiBase *base = SPI_BASE (bonobo_object_from_servant(servant));
74 g_return_val_if_fail (base, NULL);
75 return ATK_RELATION(base->gobj);
80 static Accessibility_RelationType
81 impl_getRelationType (PortableServer_Servant servant,
82 CORBA_Environment * ev)
84 AtkRelation *relation = get_relation_from_servant (servant);
87 g_return_val_if_fail (relation != NULL, 0);
88 type = atk_relation_get_relation_type (relation);
89 return spi_relation_type_from_atk_relation_type (type);
94 impl_getNTargets (PortableServer_Servant servant,
95 CORBA_Environment * ev)
97 AtkRelation *relation = get_relation_from_servant(servant);
98 g_return_val_if_fail (relation != NULL, 0);
100 return relation->target ? relation->target->len : 0;
105 impl_getTarget (PortableServer_Servant servant,
106 const CORBA_short index,
107 CORBA_Environment * ev)
109 AtkObject *atk_object;
110 AtkRelation *relation = get_relation_from_servant (servant);
111 g_return_val_if_fail (relation, NULL);
113 if (!relation->target ||
115 index >= relation->target->len)
116 return CORBA_OBJECT_NIL;
118 atk_object = g_ptr_array_index (relation->target, index);
120 return CORBA_OBJECT_NIL;
122 return spi_accessible_new_return (atk_object, FALSE, ev);
127 spi_relation_new (AtkRelation *obj)
129 SpiRelation *new_relation = g_object_new (SPI_RELATION_TYPE, NULL);
130 spi_base_construct (SPI_BASE (new_relation), G_OBJECT (obj));
136 spi_relation_class_init (SpiRelationClass *klass)
138 POA_Accessibility_Relation__epv *epv = &klass->epv;
140 epv->getRelationType = impl_getRelationType;
141 epv->getNTargets = impl_getNTargets;
142 epv->getTarget = impl_getTarget;
147 spi_relation_init (SpiRelation *relation)
152 BONOBO_TYPE_FUNC_FULL (SpiRelation,
153 Accessibility_Relation,