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