Bump version number to 0.1.4 prior to release.
[platform/core/uifw/at-spi2-atk.git] / atk-adaptor / relation-adaptor.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2001, 2002 Sun Microsystems Inc.,
6  * Copyright 2001, 2002 Ximian, Inc.
7  *
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.
12  *
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.
17  *
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.
22  */
23
24 /* relation.c : implements the Relation interface */
25
26 #include <config.h>
27 #include <stdio.h>
28
29 #include <atk/atk.h>
30 #include <droute/droute.h>
31
32 #include "common/spi-types.h"
33 #include "common/spi-dbus.h"
34
35 static gboolean
36 spi_init_relation_type_table (Accessibility_RelationType *types)
37 {
38   gint i;
39
40   for (i = 0; i < ATK_RELATION_LAST_DEFINED; i++)
41     types[i] = Accessibility_RELATION_NULL;
42
43   types[ATK_RELATION_CONTROLLED_BY] = Accessibility_RELATION_CONTROLLED_BY;
44   types[ATK_RELATION_CONTROLLER_FOR] = Accessibility_RELATION_CONTROLLER_FOR;
45   types[ATK_RELATION_LABEL_FOR] = Accessibility_RELATION_LABEL_FOR;
46   types[ATK_RELATION_LABELLED_BY] = Accessibility_RELATION_LABELLED_BY;
47   types[ATK_RELATION_MEMBER_OF] = Accessibility_RELATION_MEMBER_OF;
48   types[ATK_RELATION_NODE_CHILD_OF] = Accessibility_RELATION_NODE_CHILD_OF;
49   types[ATK_RELATION_NODE_PARENT_OF] = Accessibility_RELATION_NODE_PARENT_OF;
50   types[ATK_RELATION_FLOWS_TO] = Accessibility_RELATION_FLOWS_TO;
51   types[ATK_RELATION_FLOWS_FROM] = Accessibility_RELATION_FLOWS_FROM;
52   types[ATK_RELATION_SUBWINDOW_OF] = Accessibility_RELATION_SUBWINDOW_OF;
53   types[ATK_RELATION_EMBEDS] = Accessibility_RELATION_EMBEDS;
54   types[ATK_RELATION_EMBEDDED_BY] = Accessibility_RELATION_EMBEDDED_BY;
55   types[ATK_RELATION_POPUP_FOR] = Accessibility_RELATION_POPUP_FOR;
56   types[ATK_RELATION_PARENT_WINDOW_OF] = Accessibility_RELATION_PARENT_WINDOW_OF;
57   types[ATK_RELATION_DESCRIPTION_FOR] = Accessibility_RELATION_DESCRIPTION_FOR;
58   types[ATK_RELATION_DESCRIBED_BY] = Accessibility_RELATION_DESCRIBED_BY;
59
60   return TRUE;
61 }
62
63
64
65 static Accessibility_RelationType
66 spi_relation_type_from_atk_relation_type (AtkRelationType type)
67 {
68   static gboolean is_initialized = FALSE;
69   static Accessibility_RelationType spi_relation_type_table [ATK_RELATION_LAST_DEFINED];
70   Accessibility_RelationType spi_type;
71
72   if (!is_initialized)
73     is_initialized = spi_init_relation_type_table (spi_relation_type_table);       
74
75   if (type > ATK_RELATION_NULL && type < ATK_RELATION_LAST_DEFINED)
76     spi_type = spi_relation_type_table[type];
77   else
78     spi_type = Accessibility_RELATION_EXTENDED;
79   return spi_type;
80 }
81
82
83
84 static AtkRelation *
85 get_relation_from_servant (PortableServer_Servant servant)
86 {
87   SpiBase *base = SPI_BASE (bonobo_object_from_servant(servant));
88
89   g_return_val_if_fail (base, NULL);
90   return  ATK_RELATION(base->gobj);
91 }
92
93
94
95 static Accessibility_RelationType
96 impl_getRelationType (PortableServer_Servant servant,
97                       CORBA_Environment * ev)
98 {
99   AtkRelation *relation = get_relation_from_servant (servant);
100   AtkRelationType type;
101
102   g_return_val_if_fail (relation != NULL, 0);
103   type = atk_relation_get_relation_type (relation);
104   return spi_relation_type_from_atk_relation_type (type);
105 }
106
107
108 static CORBA_short
109 impl_getNTargets (PortableServer_Servant servant,
110                   CORBA_Environment * ev)
111 {
112   AtkRelation *relation = get_relation_from_servant(servant);
113   g_return_val_if_fail (relation != NULL, 0);
114
115   return relation->target ? relation->target->len : 0;
116 }
117
118
119 static CORBA_Object
120 impl_getTarget (PortableServer_Servant servant,
121                 const CORBA_short index,
122                 CORBA_Environment * ev)
123 {
124   AtkObject *atk_object;
125   AtkRelation *relation = get_relation_from_servant (servant);
126   g_return_val_if_fail (relation, NULL);
127
128   if (!relation->target ||
129       index < 0 ||
130       index >= relation->target->len)
131     return CORBA_OBJECT_NIL;
132
133   atk_object = g_ptr_array_index (relation->target, index);
134   if (!atk_object)
135     return CORBA_OBJECT_NIL;
136
137   return spi_accessible_new_return (atk_object, FALSE, ev);
138 }
139
140
141 SpiRelation *
142 spi_relation_new (AtkRelation *obj)
143 {
144   SpiRelation *new_relation = g_object_new (SPI_RELATION_TYPE, NULL);
145   spi_base_construct (SPI_BASE (new_relation), G_OBJECT (obj));
146   return new_relation;
147 }
148
149
150 static void
151 spi_relation_class_init (SpiRelationClass *klass)
152 {
153   POA_Accessibility_Relation__epv *epv = &klass->epv;
154
155   epv->getRelationType  = impl_getRelationType;  
156   epv->getNTargets      = impl_getNTargets;
157   epv->getTarget        = impl_getTarget;
158 }
159
160
161 static void
162 spi_relation_init (SpiRelation *relation)
163 {
164 }
165
166
167 BONOBO_TYPE_FUNC_FULL (SpiRelation,
168                        Accessibility_Relation,
169                        SPI_TYPE_BASE,
170                        spi_relation)