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
 * Copyright 2010, 2011 Novell, Inc.
8
 *
9
 * This library is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU Lesser General Public
11
 * License as published by the Free Software Foundation; either
12
 * version 2.1 of the License, or (at your option) any later version.
13
 *
14
 * This library is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
 * Lesser General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Lesser General Public
20
 * License along with this library; if not, write to the
21
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22
 * Boston, MA 02110-1301, USA.
23
 */
24

            
25
#include "atspi-private.h"
26

            
27
/**
28
 * AtspiHyperlink:
29
 *
30
 * Instances of atspi-hyperlink are the means by which end users
31
 * and clients interact with linked content.
32
 *
33
 *  Instances of atspi-hyperlink are returned by
34
 * atspi-hypertext objects, and are the means by
35
 * which end users and clients interact with linked,
36
 * and in some cases embedded, content. These instances
37
 * may have multiple "anchors", where an anchor corresponds to a
38
 * reference to a particular resource with a corresponding resource
39
 * identified (URI).
40
 */
41

            
42
1
G_DEFINE_TYPE (AtspiHyperlink, atspi_hyperlink, ATSPI_TYPE_OBJECT)
43

            
44
static void
45
9
atspi_hyperlink_init (AtspiHyperlink *hyperlink)
46
{
47
9
}
48

            
49
static void
50
1
atspi_hyperlink_class_init (AtspiHyperlinkClass *klass)
51
{
52
1
}
53

            
54
AtspiHyperlink *
55
9
_atspi_hyperlink_new (AtspiApplication *app, const gchar *path)
56
{
57
  AtspiHyperlink *hyperlink;
58

            
59
9
  hyperlink = g_object_new (ATSPI_TYPE_HYPERLINK, NULL);
60
9
  hyperlink->parent.app = g_object_ref (app);
61
9
  hyperlink->parent.path = g_strdup (path);
62

            
63
9
  return hyperlink;
64
}
65

            
66
/**
67
 * atspi_hyperlink_get_n_anchors:
68
 * @obj: a pointer to the #AtspiHyperlink object on which to operate.
69
 *
70
 * Gets the total number of anchors which an #AtspiHyperlink implementor has.
71
 * Though typical hyperlinks have only one anchor, client-side image maps and
72
 * other hypertext objects may potentially activate or refer to multiple
73
 * URIs.  For each anchor there is a corresponding URI and object.
74
 *
75
 * see: #atspi_hyperlink_get_uri and #atspi_hyperlink_get_object.
76
 *
77
 * Returns: a #gint indicating the number of anchors in this hyperlink.
78
 **/
79
gint
80
1
atspi_hyperlink_get_n_anchors (AtspiHyperlink *obj, GError **error)
81
{
82
1
  dbus_int32_t retval = -1;
83

            
84
1
  g_return_val_if_fail (obj != NULL, -1);
85

            
86
1
  _atspi_dbus_get_property (obj, atspi_interface_hyperlink, "NAnchors", error, "i", &retval);
87

            
88
1
  return retval;
89
}
90

            
91
/**
92
 * atspi_hyperlink_get_uri:
93
 * @obj: a pointer to the #AtspiHyperlink implementor on which to operate.
94
 * @i: a (zero-index) integer indicating which hyperlink anchor to query.
95
 *
96
 * Gets the URI associated with a particular hyperlink anchor.
97
 *
98
 * Returns: a UTF-8 string giving the URI of the @ith hyperlink anchor.
99
 **/
100
gchar *
101
3
atspi_hyperlink_get_uri (AtspiHyperlink *obj, int i, GError **error)
102
{
103
3
  dbus_int32_t d_i = i;
104
3
  char *retval = NULL;
105

            
106
3
  g_return_val_if_fail (obj != NULL, NULL);
107

            
108
3
  _atspi_dbus_call (obj, atspi_interface_hyperlink, "GetURI", error, "i=>s", d_i, &retval);
109

            
110
3
  if (!retval)
111
    retval = g_strdup ("");
112

            
113
3
  return retval;
114
}
115

            
116
/**
117
 * atspi_hyperlink_get_object:
118
 * @obj: a pointer to the #AtspiHyperlink implementor on which to operate.
119
 * @i: a (zero-index) #gint indicating which hyperlink anchor to query.
120
 *
121
 * Gets the object associated with a particular hyperlink anchor, as an
122
 * #AtspiAccessible.
123
 *
124
 * Returns: (transfer full): an #AtspiAccessible that represents the object
125
 *        associated with the @ith anchor of the specified #AtspiHyperlink.
126
 **/
127
AtspiAccessible *
128
1
atspi_hyperlink_get_object (AtspiHyperlink *obj, gint i, GError **error)
129
{
130
1
  dbus_int32_t d_i = i;
131
  DBusMessage *reply;
132

            
133
1
  g_return_val_if_fail (obj != NULL, NULL);
134

            
135
1
  reply = _atspi_dbus_call_partial (obj, atspi_interface_hyperlink, "GetObject", error, "i", d_i);
136

            
137
1
  return _atspi_dbus_return_accessible_from_message (reply);
138
}
139

            
140
/**
141
 * atspi_hyperlink_get_index_range:
142
 * @obj: a pointer to the #AtspiHyperlink implementor on which to operate.
143
 *
144
 *
145
 * Gets the starting and ending character offsets of the text range
146
 * associated with an #AtspiHyperlink, in its originating #AtspiHypertext.
147
 **/
148
AtspiRange *
149
1
atspi_hyperlink_get_index_range (AtspiHyperlink *obj, GError **error)
150
{
151
1
  dbus_int32_t d_start_offset = -1;
152
1
  dbus_int32_t d_end_offset = -1;
153
1
  AtspiRange *ret = g_new (AtspiRange, 1);
154

            
155
1
  ret->start_offset = ret->end_offset = -1;
156

            
157
1
  if (!obj)
158
    return ret;
159

            
160
1
  _atspi_dbus_call (obj, atspi_interface_hyperlink, "GetIndexRange", error, "=>ii", &d_start_offset, &d_end_offset);
161

            
162
1
  ret->start_offset = d_start_offset;
163
1
  ret->end_offset = d_end_offset;
164
1
  return ret;
165
}
166

            
167
/**
168
 * atspi_hyperlink_get_start_index:
169
 * @obj: a pointer to the #AtspiHyperlink implementor on which to operate.
170
 *
171
 *
172
 * Gets the starting character offset of the text range associated with
173
 *       an #AtspiHyperlink, in its originating #AtspiHypertext.
174
 **/
175
gint
176
1
atspi_hyperlink_get_start_index (AtspiHyperlink *obj, GError **error)
177
{
178
1
  dbus_int32_t d_start_offset = -1;
179

            
180
1
  if (!obj)
181
    return -1;
182

            
183
1
  _atspi_dbus_get_property (obj, atspi_interface_hyperlink, "StartIndex",
184
                            error, "i", &d_start_offset);
185

            
186
1
  return d_start_offset;
187
}
188
/**
189
 * atspi_hyperlink_get_end_index:
190
 * @obj: a pointer to the #AtspiHyperlink implementor on which to operate.
191
 *
192
 *
193
 * Gets the ending character offset of the text range associated with
194
 *       an #AtspiHyperlink, in its originating #AtspiHypertext.
195
 **/
196
gint
197
1
atspi_hyperlink_get_end_index (AtspiHyperlink *obj, GError **error)
198
{
199
1
  dbus_int32_t d_end_offset = -1;
200

            
201
1
  if (!obj)
202
    return -1;
203

            
204
1
  _atspi_dbus_get_property (obj, atspi_interface_hyperlink, "EndIndex", error,
205
                            "i", &d_end_offset);
206

            
207
1
  return d_end_offset;
208
}
209

            
210
/**
211
 * atspi_hyperlink_is_valid:
212
 * @obj: a pointer to the #AtspiHyperlink on which to operate.
213
 *
214
 * Tells whether an #AtspiHyperlink object is still valid with respect to its
215
 *          originating hypertext object.
216
 *
217
 * Returns: #TRUE if the specified #AtspiHyperlink is still valid with respect
218
 *          to its originating #AtspiHypertext object, #FALSE otherwise.
219
 **/
220
gboolean
221
1
atspi_hyperlink_is_valid (AtspiHyperlink *obj, GError **error)
222
{
223
1
  dbus_bool_t retval = FALSE;
224

            
225
1
  g_return_val_if_fail (obj != NULL, FALSE);
226

            
227
1
  _atspi_dbus_call (obj, atspi_interface_hyperlink, "IsValid", error, "=>b", &retval);
228

            
229
1
  return retval;
230
}