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