c9553173c1eac7a55ab7aed3b3de3f09cbca860b
[platform/core/uifw/at-spi2-atk.git] / libspi / relation.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2001 Sun Microsystems Inc.
6  *
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.
11  *
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.
16  *
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.
21  */
22
23 /* relation.c : implements the Relation interface */
24
25 #include <config.h>
26 #include <stdio.h>
27 #include <libspi/relation.h>
28
29
30 static gboolean
31 spi_init_relation_type_table (Accessibility_RelationType *types)
32 {
33   gint i;
34
35   for (i = 0; i < ATK_RELATION_LAST_DEFINED; i++)
36     types[i] = ATK_RELATION_NULL;
37
38   types[ATK_RELATION_CONTROLLED_BY] = Accessibility_RELATION_CONTROLLED_BY;
39   types[ATK_RELATION_CONTROLLER_FOR] = Accessibility_RELATION_CONTROLLER_FOR;
40   types[ATK_RELATION_LABEL_FOR] = Accessibility_RELATION_LABEL_FOR;
41   types[ATK_RELATION_LABELLED_BY] = Accessibility_RELATION_LABELLED_BY;
42   types[ATK_RELATION_MEMBER_OF] = Accessibility_RELATION_MEMBER_OF;
43   types[ATK_RELATION_NODE_CHILD_OF] = Accessibility_RELATION_NODE_CHILD_OF;
44   return TRUE;
45 }
46
47
48
49 static Accessibility_RelationType
50 spi_relation_type_from_atk_relation_type (AtkRelationType type)
51 {
52   static gboolean is_initialized = FALSE;
53   static Accessibility_RelationType spi_relation_type_table [ATK_RELATION_LAST_DEFINED];
54   Accessibility_RelationType spi_type;
55
56   if (!is_initialized)
57     is_initialized = spi_init_relation_type_table (spi_relation_type_table);       
58
59   if (type > ATK_RELATION_NULL && type < ATK_RELATION_LAST_DEFINED)
60     spi_type = spi_relation_type_table[type];
61   else
62     spi_type = Accessibility_RELATION_EXTENDED;
63   return spi_type;
64 }
65
66
67
68 static AtkRelation *
69 get_relation_from_servant (PortableServer_Servant servant)
70 {
71   SpiBase *base = SPI_BASE (bonobo_object_from_servant(servant));
72
73   g_return_val_if_fail (base, NULL);
74   return  ATK_RELATION(base->gobj);
75 }
76
77
78
79 static Accessibility_RelationType
80 impl_getRelationType (PortableServer_Servant servant,
81                       CORBA_Environment * ev)
82 {
83   AtkRelation *relation = get_relation_from_servant (servant);
84   AtkRelationType type;
85
86   g_return_val_if_fail (relation, 0);
87   type = atk_relation_get_relation_type (relation);
88   return spi_relation_type_from_atk_relation_type (type);
89 }
90
91
92
93 static CORBA_short
94 impl_getNTargets (PortableServer_Servant servant,
95                   CORBA_Environment * ev)
96 {
97   AtkRelation *relation = get_relation_from_servant(servant);
98   g_return_val_if_fail (relation, 0);
99 }
100
101
102
103 static CORBA_Object
104 impl_getTarget (PortableServer_Servant servant,
105                 const CORBA_short index,
106                 CORBA_Environment * ev)
107 {
108   AtkRelation *relation = get_relation_from_servant (servant);
109   g_return_val_if_fail (relation, NULL);
110 }
111
112
113
114 SpiRelation *
115 spi_relation_new (AtkRelation *obj)
116 {
117   SpiRelation *new_relation = g_object_new (SPI_RELATION_TYPE, NULL);
118   spi_base_construct (SPI_BASE (new_relation), G_OBJECT (obj));
119   return new_relation;
120 }
121
122
123 static void
124 spi_relation_class_init (SpiRelationClass *klass)
125 {
126   POA_Accessibility_Relation__epv *epv = &klass->epv;
127
128   epv->getRelationType  = impl_getRelationType;  
129   epv->getNTargets      = impl_getNTargets;
130   epv->getTarget        = impl_getTarget;
131 }
132
133
134 static void
135 spi_relation_init (SpiRelation *relation)
136 {
137 }
138
139
140 BONOBO_TYPE_FUNC_FULL (SpiRelation,
141                        Accessibility_Relation,
142                        SPI_TYPE_BASE,
143                        spi_relation);