Fix atspi_hyperlink_get_(start|end)_index
[platform/upstream/at-spi2-core.git] / atspi / atspi-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 #include "atspi-private.h"
25
26 G_DEFINE_TYPE (AtspiHyperlink, atspi_hyperlink, ATSPI_TYPE_OBJECT)
27
28 static void
29 atspi_hyperlink_init (AtspiHyperlink *hyperlink)
30 {
31 }
32
33 static void
34 atspi_hyperlink_finalize (GObject *obj)
35 {
36   /*AtspiHyperlink *hyperlink = ATSPI_HYPERLINK (obj); */
37
38   /* TODO: Unref parent/children, etc. */
39 }
40
41 static void
42 atspi_hyperlink_class_init (AtspiHyperlinkClass *klass)
43 {
44   GObjectClass *object_class = G_OBJECT_CLASS (klass);
45
46   object_class->finalize = atspi_hyperlink_finalize;
47 }
48
49 AtspiHyperlink *
50 atspi_hyperlink_new (AtspiApplication *app, const gchar *path)
51 {
52   AtspiHyperlink *hyperlink;
53   
54   hyperlink = g_object_new (ATSPI_TYPE_HYPERLINK, NULL);
55   g_return_val_if_fail (hyperlink != NULL, NULL);
56
57   hyperlink->parent.app = g_object_ref (app);
58   hyperlink->parent.path = g_strdup (path);
59
60   return hyperlink;
61 }
62
63 /**
64  * atspi_hyperlink_get_n_anchors:
65  * @obj: a pointer to the #AtspiHyperlink object on which to operate.
66  *
67  * Get the total number of anchors which an #AtspiHyperlink implementor has.
68  *       Though typical hyperlinks have only one anchor, client-side image maps and
69  *       other hypertext objects may potentially activate or refer to multiple
70  *       URIs.  For each anchor there is a corresponding URI and object.
71  * see atspi_hyperlink_get_uri() and atspi_hyperlink_get_object().
72  *
73  * Returns: a #gint indicating the number of anchors in this hyperlink.
74  **/
75 gint
76 atspi_hyperlink_get_n_anchors (AtspiHyperlink *obj, GError **error)
77 {
78   dbus_int32_t retval;
79
80   g_return_val_if_fail (obj != NULL, -1);
81
82   _atspi_dbus_get_property (obj, atspi_interface_hyperlink, "NAnchors", error, "i", &retval);
83
84   return retval;
85 }
86
87 /**
88  * atspi_hyperlink_get_uri:
89  * @obj: a pointer to the #AtspiHyperlink implementor on which to operate.
90  * @i: a (zero-index) integer indicating which hyperlink anchor to query.
91  *
92  * Get the URI associated with a particular hyperlink anchor.  
93  *
94  * Returns: a UTF-8 string giving the URI of the @ith hyperlink anchor.
95  **/
96 gchar *
97 atspi_hyperlink_get_uri (AtspiHyperlink *obj, int i, GError **error)
98 {
99   dbus_int32_t d_i = i;
100   char *retval;
101
102   g_return_val_if_fail (obj != NULL, NULL);
103
104   _atspi_dbus_call (obj, atspi_interface_hyperlink, "GetURI", error, "i=>s", d_i, &retval);
105
106   return retval;
107 }
108
109 /**
110  * atspi_hyperlink_get_object:
111  * @obj: a pointer to the #AtspiHyperlink implementor on which to operate.
112  * @i: a (zero-index) long integer indicating which hyperlink anchor to query.
113  *
114  * Get the object associated with a particular hyperlink anchor, as an #Accessible. 
115  *
116  * Returns: (transfer full): an #AtspiAccessible that represents the object
117  *        associated with the @ith anchor of the specified #AtspiHyperlink.
118  **/
119 AtspiAccessible*
120 atspi_hyperlink_get_object (AtspiHyperlink *obj, gint i, GError **error)
121 {
122   dbus_int32_t d_i = i;
123   DBusMessage *reply;
124
125   g_return_val_if_fail (obj != NULL, NULL);
126
127   reply = _atspi_dbus_call_partial (obj, atspi_interface_hyperlink, "GetObject", error, "i", d_i);
128
129   return _atspi_dbus_return_accessible_from_message (reply);
130 }
131
132 /**
133  * atspi_hyperlink_get_index_range:
134  * @obj: a pointer to the #AtspiHyperlink implementor on which to operate.
135  *
136  *
137  * Get the starting and ending character offsets of the text range associated with
138  *       a #AtspiHyperlink, in its originating #AtspiHypertext.
139  **/
140 AtspiRange *
141 atspi_hyperlink_get_index_range (AtspiHyperlink *obj, GError **error)
142 {
143   dbus_int32_t d_start_offset, d_end_offset;
144   AtspiRange *ret = g_new (AtspiRange, 1);
145
146   if (ret)
147     ret->start_offset = ret->end_offset = -1;
148
149   if (!obj || !ret)
150     return ret;
151
152   _atspi_dbus_call (obj, atspi_interface_hyperlink, "GetIndexRange", error, "=>ii", &d_start_offset, &d_end_offset);
153
154   ret->start_offset = d_start_offset;
155   ret->end_offset = d_end_offset;
156   return ret;
157 }
158
159 /**
160  * atspi_hyperlink_get_start_index:
161  * @obj: a pointer to the #AtspiHyperlink implementor on which to operate.
162  *
163  *
164  * Get the starting character offset of the text range associated with
165  *       a #AtspiHyperlink, in its originating #AtspiHypertext.
166  **/
167 gint
168 atspi_hyperlink_get_start_index (AtspiHyperlink *obj, GError **error)
169 {
170   dbus_int32_t d_start_offset = -1;
171
172   if (!obj)
173     return -1;
174
175   _atspi_dbus_get_property (obj, atspi_interface_hyperlink, "StartIndex",
176                             error, "i", &d_start_offset);
177
178   return d_start_offset;
179 }
180 /**
181  * atspi_hyperlink_get_end_index:
182  * @obj: a pointer to the #AtspiHyperlink implementor on which to operate.
183  *
184  *
185  * Get the ending character offset of the text range associated with
186  *       a #AtspiHyperlink, in its originating #AtspiHypertext.
187  **/
188 gint
189 atspi_hyperlink_get_end_index (AtspiHyperlink *obj, GError **error)
190 {
191   dbus_int32_t d_end_offset = -1;
192
193   if (!obj)
194     return -1;
195
196   _atspi_dbus_get_property (obj, atspi_interface_hyperlink, "EndIndex", error,
197                             "i", &d_end_offset);
198
199   return d_end_offset;
200 }
201
202
203 /**
204  * atspi_hyperlink_is_valid:
205  * @obj: a pointer to the #AtspiHyperlink on which to operate.
206  *
207  * Tell whether an #AtspiHyperlink object is still valid with respect to its
208  *          originating hypertext object.
209  *
210  * Returns: #TRUE of the specified #AtspiHyperlink is still valid with respect
211  *          to its originating #AtspiHypertext object, #FALSE otherwise.
212  **/
213 gboolean
214 atspi_hyperlink_is_valid (AtspiHyperlink *obj, GError **error)
215 {
216   dbus_bool_t retval;
217
218   g_return_val_if_fail (obj != NULL, FALSE);
219
220   _atspi_dbus_call (obj, atspi_interface_hyperlink, "IsValid", error, "=>b", &retval);
221
222   return retval;
223 }