2001-12-10 Michael Meeks <michael@ximian.com>
[platform/core/uifw/at-spi2-atk.git] / libspi / hyperlink.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 /* hyperlink.c : implements the Hyperlink interface */
24
25 #include <config.h>
26 #include <stdio.h>
27 #include <libspi/hyperlink.h>
28 #include <libspi/accessible.h>
29
30 /* Static function declarations */
31
32 static void
33 spi_hyperlink_class_init (SpiHyperlinkClass *klass);
34 static void
35 spi_hyperlink_init (SpiHyperlink *hyperlink);
36 static CORBA_string
37 impl_getURI (PortableServer_Servant _servant,
38              const CORBA_long i, CORBA_Environment * ev);
39 static CORBA_short
40 impl__get_n_anchors (PortableServer_Servant _servant,
41                      CORBA_Environment * ev);
42 static CORBA_long
43 impl__get_startIndex (PortableServer_Servant _servant,
44                       CORBA_Environment * ev);
45 static CORBA_long
46 impl__get_endIndex (PortableServer_Servant _servant,
47                     CORBA_Environment * ev);
48 static Accessibility_Accessible
49 impl_getObject (PortableServer_Servant _servant,
50                 const CORBA_long i,
51                 CORBA_Environment * ev);
52 static CORBA_boolean
53 impl_isValid (PortableServer_Servant _servant,
54               CORBA_Environment * ev);
55
56
57 BONOBO_TYPE_FUNC_FULL (SpiHyperlink,
58                        Accessibility_Hyperlink,
59                        SPI_TYPE_BASE,
60                        spi_hyperlink);
61
62
63 static void
64 spi_hyperlink_class_init (SpiHyperlinkClass *klass)
65 {
66   POA_Accessibility_Hyperlink__epv *epv = &klass->epv;
67
68   /* Initialize epv table */
69
70   epv->_get_nAnchors = impl__get_n_anchors;
71   epv->getURI = impl_getURI;
72   epv->_get_startIndex = impl__get_startIndex;
73   epv->_get_endIndex = impl__get_endIndex;
74   epv->getObject = impl_getObject;
75   epv->isValid = impl_isValid;
76 }
77
78
79 static void
80 spi_hyperlink_init (SpiHyperlink *hyperlink)
81 {
82 }
83
84
85 SpiHyperlink *
86 spi_hyperlink_new (AtkObject *object)
87 {
88   SpiHyperlink *new_hyperlink = g_object_new (
89           SPI_HYPERLINK_TYPE, NULL);
90
91   spi_base_construct (SPI_BASE (new_hyperlink), object);
92
93   return new_hyperlink;
94 }
95
96
97 static AtkHyperlink *
98 get_hyperlink_from_servant (PortableServer_Servant servant)
99 {
100   SpiBase *object = SPI_BASE (bonobo_object_from_servant (servant));
101
102   if (!object)
103     {
104       return NULL;
105     }
106
107   return ATK_HYPERLINK (object->atko);
108 }
109
110
111 static CORBA_short
112 impl__get_n_anchors (PortableServer_Servant servant,
113                      CORBA_Environment     *ev)
114 {
115   AtkHyperlink *link = get_hyperlink_from_servant (servant);
116
117   g_return_val_if_fail (link != NULL, 0);
118
119   return (CORBA_short) atk_hyperlink_get_n_anchors (link);
120 }
121
122
123 static CORBA_long
124 impl__get_startIndex (PortableServer_Servant servant,
125                       CORBA_Environment     *ev)
126 {
127   AtkHyperlink *link = get_hyperlink_from_servant (servant);
128
129   g_return_val_if_fail (link != NULL, -1);
130
131   return (CORBA_long) atk_hyperlink_get_start_index (link);
132 }
133
134
135 static CORBA_long
136 impl__get_endIndex (PortableServer_Servant servant,
137                     CORBA_Environment     *ev)
138 {
139   AtkHyperlink *link = get_hyperlink_from_servant (servant);
140
141   g_return_val_if_fail (link != NULL, -1);
142
143   return (CORBA_long) atk_hyperlink_get_end_index (link);
144 }
145
146
147 static CORBA_string
148 impl_getURI (PortableServer_Servant servant,
149              const CORBA_long i, CORBA_Environment *ev)
150 {
151   gchar *uri;
152   CORBA_char *rv;
153   AtkHyperlink *link = get_hyperlink_from_servant (servant);
154
155   g_return_val_if_fail (link != NULL, CORBA_string_dup (""));
156
157   uri = atk_hyperlink_get_uri (link, (gint) i);
158   if (uri)
159     {
160       rv = CORBA_string_dup (uri);
161       g_free (uri);
162     }
163   else
164     rv = CORBA_string_dup ("");
165
166   return rv;
167
168
169
170 static Accessibility_Accessible
171 impl_getObject (PortableServer_Servant servant,
172                 const CORBA_long       i,
173                 CORBA_Environment     *ev)
174 {
175   AtkObject    *atk_object;
176   AtkHyperlink *link = get_hyperlink_from_servant (servant);
177
178   g_return_val_if_fail (link != NULL, CORBA_OBJECT_NIL);
179
180   atk_object = atk_hyperlink_get_object (link, (gint) i);
181
182   return spi_accessible_new_return (atk_object, FALSE, ev);
183 }
184
185
186 static CORBA_boolean
187 impl_isValid (PortableServer_Servant servant,
188               CORBA_Environment     *ev)
189 {
190   AtkHyperlink *link = get_hyperlink_from_servant (servant);
191
192   g_return_val_if_fail (link != NULL, TRUE);
193
194   return (CORBA_boolean) atk_hyperlink_is_valid (link);
195 }
196