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 * atspi_range_copy:
28 * @src: a pointer to the source #AtspiRange object that will be copied.
29 *
30 * Gets a copy of an #AtspiRange object.
31 *
32 * Returns: the #AtspiRange copy of an #AtspiRange object.
33 **/
34 AtspiRange *
atspi_range_copy(AtspiRange * src)35 atspi_range_copy (AtspiRange *src)
36 {
37 AtspiRange *dst = g_new (AtspiRange, 1);
38
39 dst->start_offset = src->start_offset;
40 dst->end_offset = src->end_offset;
41 return dst;
42 }
43
G_DEFINE_BOXED_TYPE(AtspiRange,atspi_range,atspi_range_copy,g_free)44 G_DEFINE_BOXED_TYPE (AtspiRange, atspi_range, atspi_range_copy, g_free)
45
46 static AtspiTextRange *
47 atspi_text_range_copy (AtspiTextRange *src)
48 {
49 AtspiTextRange *dst = g_new (AtspiTextRange, 1);
50
51 dst->content = g_strdup (src->content);
52 dst->start_offset = src->start_offset;
53 dst->end_offset = src->end_offset;
54 return dst;
55 }
56
57 static void
atspi_text_range_free(AtspiTextRange * range)58 atspi_text_range_free (AtspiTextRange *range)
59 {
60 g_free (range->content);
61 g_free (range);
62 }
63
G_DEFINE_BOXED_TYPE(AtspiTextRange,atspi_text_range,atspi_text_range_copy,atspi_text_range_free)64 G_DEFINE_BOXED_TYPE (AtspiTextRange, atspi_text_range, atspi_text_range_copy,
65 atspi_text_range_free)
66
67 /**
68 * atspi_text_get_character_count:
69 * @obj: a pointer to the #AtspiText object to query.
70 *
71 * Gets the character count of an #AccessibleText object.
72 *
73 * Returns: a #gint indicating the total number of
74 * characters in the #AccessibleText object.
75 **/
76 gint
77 atspi_text_get_character_count (AtspiText *obj, GError **error)
78 {
79 dbus_int32_t retval = 0;
80
81 g_return_val_if_fail (obj != NULL, -1);
82
83 _atspi_dbus_get_property (obj, atspi_interface_text, "CharacterCount", error, "i", &retval);
84
85 return retval;
86 }
87
88 /**
89 * atspi_text_get_text:
90 * @obj: a pointer to the #AtspiText object to query.
91 * @start_offset: a #gint indicating the start of the desired text range.
92 * @end_offset: a #gint indicating the first character past the desired range.
93 *
94 * Gets a range of text from an #AtspiText object. The number of bytes
95 * in the returned string may exceed either end_offset or start_offset, since
96 * UTF-8 is a variable-width encoding.
97 *
98 * Returns: a text string containing characters from @start_offset
99 * to @end_offset-1, inclusive, encoded as UTF-8.
100 **/
101 gchar *
atspi_text_get_text(AtspiText * obj,gint start_offset,gint end_offset,GError ** error)102 atspi_text_get_text (AtspiText *obj,
103 gint start_offset,
104 gint end_offset,
105 GError **error)
106 {
107 gchar *retval = NULL;
108 dbus_int32_t d_start_offset = start_offset, d_end_offset = end_offset;
109
110 g_return_val_if_fail (obj != NULL, g_strdup (""));
111
112 _atspi_dbus_call (obj, atspi_interface_text, "GetText", error, "ii=>s", d_start_offset, d_end_offset, &retval);
113
114 if (!retval)
115 retval = g_strdup ("");
116
117 return retval;
118 }
119
120 /**
121 * atspi_text_get_caret_offset:
122 * @obj: a pointer to the #AtspiText object to query.
123 *
124 * Gets the current offset of the text caret in an #AtspiText object.
125 *
126 * Returns: a #gint indicating the current position of the text caret.
127 **/
128 gint
atspi_text_get_caret_offset(AtspiText * obj,GError ** error)129 atspi_text_get_caret_offset (AtspiText *obj, GError **error)
130 {
131 dbus_int32_t retval = -1;
132
133 g_return_val_if_fail (obj != NULL, -1);
134
135 _atspi_dbus_get_property (obj, atspi_interface_text, "CaretOffset", error, "i", &retval);
136
137 return retval;
138 }
139
140 /**
141 * atspi_text_get_attributes: (rename-to atspi_text_get_text_attributes)
142 * @obj: a pointer to the #AtspiText object to query.
143 * @offset: a #gint indicating the offset from which the attribute
144 * search is based.
145 * @start_offset: (out): a #gint pointer indicating the start of the desired text
146 * range.
147 * @end_offset: (out): a #gint pointer indicating the first character past the desired
148 * range.
149 *
150 * Gets the attributes applied to a range of text from an #AtspiText
151 * object. The text attributes correspond to CSS attributes
152 * where possible.
153 * <em>DEPRECATED</em>
154 *
155 * Returns: (element-type gchar* gchar*) (transfer full): a #GHashTable
156 * describing the attributes at the given character offset.
157 *
158 * Deprecated: 2.10: Use atspi_text_get_text_attributes instead.
159 **/
160 GHashTable *
atspi_text_get_attributes(AtspiText * obj,gint offset,gint * start_offset,gint * end_offset,GError ** error)161 atspi_text_get_attributes (AtspiText *obj,
162 gint offset,
163 gint *start_offset,
164 gint *end_offset,
165 GError **error)
166 {
167 return atspi_text_get_text_attributes (obj, offset, start_offset, end_offset, error);
168 }
169
170 /**
171 * atspi_text_get_text_attributes:
172 * @obj: a pointer to the #AtspiText object to query.
173 * @offset: a #gint indicating the offset from which the attribute
174 * search is based.
175 * @start_offset: (out): a #gint pointer indicating the start of the desired text
176 * range.
177 * @end_offset: (out): a #gint pointer indicating the first character past the desired
178 * range.
179 *
180 * Gets the attributes applied to a range of text from an #AtspiText
181 * object. The text attributes correspond to CSS attributes
182 * where possible.
183 * <em>DEPRECATED</em>
184 *
185 * Returns: (element-type gchar* gchar*) (transfer full): a #GHashTable
186 * describing the attributes at the given character offset.
187 **/
188 GHashTable *
atspi_text_get_text_attributes(AtspiText * obj,gint offset,gint * start_offset,gint * end_offset,GError ** error)189 atspi_text_get_text_attributes (AtspiText *obj,
190 gint offset,
191 gint *start_offset,
192 gint *end_offset,
193 GError **error)
194 {
195 dbus_int32_t d_offset = offset;
196 dbus_int32_t d_start_offset, d_end_offset;
197 DBusMessage *reply;
198 DBusMessageIter iter;
199 GHashTable *ret = NULL;
200
201 if (obj == NULL)
202 return NULL;
203
204 reply = _atspi_dbus_call_partial (obj, atspi_interface_text, "GetAttributes", error, "i", d_offset);
205 _ATSPI_DBUS_CHECK_SIG (reply, "a{ss}ii", error, ret)
206
207 dbus_message_iter_init (reply, &iter);
208 ret = _atspi_dbus_hash_from_iter (&iter);
209 dbus_message_iter_next (&iter);
210
211 dbus_message_iter_get_basic (&iter, &d_start_offset);
212 if (start_offset)
213 *start_offset = d_start_offset;
214 dbus_message_iter_next (&iter);
215 dbus_message_iter_get_basic (&iter, &d_end_offset);
216 if (end_offset)
217 *end_offset = d_end_offset;
218
219 dbus_message_unref (reply);
220 return ret;
221 }
222
223 /**
224 * atspi_text_get_attribute_run:
225 * @obj: a pointer to the #AtspiText object to query.
226 * @offset: a #gint indicating the offset from which the attribute
227 * search is based.
228 * @include_defaults: a #bool that, when set as #FALSE, indicates the call
229 * should only return those attributes which are explicitly set on the current
230 * attribute run, omitting any attributes which are inherited from the
231 * default values.
232 * @start_offset: (out): a #gint pointer indicating the start of the desired text
233 * range.
234 * @end_offset: (out): a #gint pointer indicating the first character past the desired
235 * range.
236 *
237 * Gets a set of attributes applied to a range of text from an #AtspiText object, optionally
238 * including its 'default' attributes.
239 *
240 * Returns: (element-type gchar* gchar*) (transfer full): a #GHashTable with attributes
241 * defined at the indicated offset, optionally including the 'default' ones.
242 **/
243 GHashTable *
atspi_text_get_attribute_run(AtspiText * obj,gint offset,gboolean include_defaults,gint * start_offset,gint * end_offset,GError ** error)244 atspi_text_get_attribute_run (AtspiText *obj,
245 gint offset,
246 gboolean include_defaults,
247 gint *start_offset,
248 gint *end_offset,
249 GError **error)
250 {
251 dbus_int32_t d_offset = offset;
252 dbus_int32_t d_start_offset, d_end_offset;
253 DBusMessage *reply;
254 DBusMessageIter iter;
255 GHashTable *ret = NULL;
256
257 if (obj == NULL)
258 return NULL;
259
260 reply = _atspi_dbus_call_partial (obj, atspi_interface_text,
261 "GetAttributeRun", error, "ib", d_offset,
262 include_defaults);
263 _ATSPI_DBUS_CHECK_SIG (reply, "a{ss}ii", error, ret)
264
265 dbus_message_iter_init (reply, &iter);
266 ret = _atspi_dbus_hash_from_iter (&iter);
267 dbus_message_iter_next (&iter);
268
269 dbus_message_iter_get_basic (&iter, &d_start_offset);
270 if (start_offset)
271 *start_offset = d_start_offset;
272 dbus_message_iter_next (&iter);
273 dbus_message_iter_get_basic (&iter, &d_end_offset);
274 if (end_offset)
275 *end_offset = d_end_offset;
276
277 dbus_message_unref (reply);
278 return ret;
279 }
280
281 /**
282 * atspi_text_get_attribute_value: (rename-to atspi_text_get_text_attribute_value)
283 * @obj: a pointer to the #AtspiText object to query.
284 * @offset: The character offset at which to query the attribute.
285 * @attribute_name: The attribute to query.
286 *
287 * Gets the value of a named attribute at a given offset.
288 *
289 * Returns: (nullable): the value of a given attribute at the given
290 * offset, or %NULL if not present.
291 *
292 * Deprecated: 2.10: Use atspi_text_get_text_attribute_value instead.
293 **/
294 gchar *
atspi_text_get_attribute_value(AtspiText * obj,gint offset,gchar * attribute_value,GError ** error)295 atspi_text_get_attribute_value (AtspiText *obj,
296 gint offset,
297 gchar *attribute_value,
298 GError **error)
299 {
300 return atspi_text_get_text_attribute_value (obj, offset, attribute_value,
301 error);
302 }
303
304 /**
305 * atspi_text_get_text_attribute_value:
306 * @obj: a pointer to the #AtspiText object to query.
307 * @offset: The character offset at which to query the attribute.
308 * @attribute_name: The attribute to query.
309 *
310 * Gets the value of a named attribute at a given offset.
311 *
312 * Returns: (nullable): the value of a given attribute at the given offset, or %NULL if
313 * not present.
314 **/
315 gchar *
atspi_text_get_text_attribute_value(AtspiText * obj,gint offset,gchar * attribute_value,GError ** error)316 atspi_text_get_text_attribute_value (AtspiText *obj,
317 gint offset,
318 gchar *attribute_value,
319 GError **error)
320 {
321 gchar *retval = NULL;
322 dbus_int32_t d_i = offset;
323
324 g_return_val_if_fail (obj != NULL, NULL);
325
326 _atspi_dbus_call (obj, atspi_interface_text, "GetAttributeValue", error, "is=>s", d_i, (const gchar *)attribute_value, &retval);
327
328 if (!retval)
329 retval = g_strdup ("");
330
331 return retval;
332 }
333
334 /**
335 * atspi_text_get_default_attributes:
336 * @obj: a pointer to the #AtspiText object to query.
337 *
338 * Gets the default attributes applied to an #AtspiText
339 * object. The text attributes correspond to CSS attributes
340 * where possible. The combination of this attribute set and
341 * the attributes reported by #atspi_text_get_attributes
342 * describes the entire set of text attributes over a range.
343 *
344 * Returns: (element-type gchar* gchar*) (transfer full): a #GHashTable
345 * containing the default attributes applied to a text object,
346 * (exclusive of explicitly-set attributes), encoded as UTF-8.
347 **/
348 GHashTable *
atspi_text_get_default_attributes(AtspiText * obj,GError ** error)349 atspi_text_get_default_attributes (AtspiText *obj, GError **error)
350 {
351 DBusMessage *reply;
352
353 g_return_val_if_fail (obj != NULL, NULL);
354
355 reply = _atspi_dbus_call_partial (obj, atspi_interface_text, "GetDefaultAttributes", error, "");
356 return _atspi_dbus_return_hash_from_message (reply);
357 }
358
359
360 /**
361 * atspi_text_set_caret_offset:
362 * @obj: a pointer to the #AtspiText object on which to operate.
363 * @new_offset: the offset to which the text caret is to be moved.
364 *
365 * Moves the text caret to a given position.
366 *
367 * Returns: #TRUE if successful, #FALSE otherwise.
368 **/
369 gboolean
atspi_text_set_caret_offset(AtspiText * obj,gint new_offset,GError ** error)370 atspi_text_set_caret_offset (AtspiText *obj,
371 gint new_offset,
372 GError **error)
373 {
374 dbus_int32_t d_new_offset = new_offset;
375 dbus_bool_t retval = FALSE;
376
377 g_return_val_if_fail (obj != NULL, FALSE);
378
379 _atspi_dbus_call (obj, atspi_interface_text, "SetCaretOffset", error, "i=>b", d_new_offset, &retval);
380
381 return retval;
382 }
383
384 /**
385 * atspi_text_get_text_before_offset:
386 * @obj: a pointer to the #AtspiText object on which to operate.
387 * @offset: a #gint indicating the offset from which the delimiter
388 * search is based.
389 * @type: an #AtspiTextBoundaryType indicating whether the desired
390 * text string is a word, sentence, line, or attribute run.
391 *
392 * Gets delimited text from an #AtspiText object which precedes a given
393 * text offset.
394 *
395 * Returns: an #AtspiTextRange containing a UTF-8 string representing the
396 * delimited text, both of whose delimiting boundaries are before the
397 * current offset, or an empty string if no such text exists.
398 **/
399 AtspiTextRange *
atspi_text_get_text_before_offset(AtspiText * obj,gint offset,AtspiTextBoundaryType type,GError ** error)400 atspi_text_get_text_before_offset (AtspiText *obj,
401 gint offset,
402 AtspiTextBoundaryType type,
403 GError **error)
404 {
405 dbus_int32_t d_offset = offset;
406 dbus_uint32_t d_type = type;
407 dbus_int32_t d_start_offset = -1, d_end_offset = -1;
408 AtspiTextRange *range = g_new0 (AtspiTextRange, 1);
409
410 range->start_offset = range->end_offset = -1;
411 if (!obj)
412 return range;
413
414 _atspi_dbus_call (obj, atspi_interface_text, "GetTextBeforeOffset", error,
415 "iu=>sii", d_offset, d_type, &range->content,
416 &d_start_offset, &d_end_offset);
417
418 range->start_offset = d_start_offset;
419 range->end_offset = d_end_offset;
420 if (!range->content)
421 range->content = g_strdup ("");
422
423 return range;
424 }
425
426 /**
427 * atspi_text_get_string_at_offset:
428 * @obj: an #AtspiText
429 * @offset: position
430 * @granularity: An #AtspiTextGranularity
431 *
432 * Gets a portion of the text exposed through an #AtspiText according to a given @offset
433 * and a specific @granularity, along with the start and end offsets defining the
434 * boundaries of such a portion of text.
435 *
436 * If @granularity is ATSPI_TEXT_GRANULARITY_CHAR the character at the
437 * offset is returned.
438 *
439 * If @granularity is ATSPI_TEXT_GRANULARITY_WORD the returned string
440 * is from the word start at or before the offset to the word start after
441 * the offset.
442 *
443 * The returned string will contain the word at the offset if the offset
444 * is inside a word and will contain the word before the offset if the
445 * offset is not inside a word.
446 *
447 * If @granularity is ATSPI_TEXT_GRANULARITY_SENTENCE the returned string
448 * is from the sentence start at or before the offset to the sentence
449 * start after the offset.
450 *
451 * The returned string will contain the sentence at the offset if the offset
452 * is inside a sentence and will contain the sentence before the offset
453 * if the offset is not inside a sentence.
454 *
455 * If @granularity is ATSPI_TEXT_GRANULARITY_LINE the returned string
456 * is from the line start at or before the offset to the line
457 * start after the offset.
458 *
459 * If @granularity is ATSPI_TEXT_GRANULARITY_PARAGRAPH the returned string
460 * is from the start of the paragraph at or before the offset to the start
461 * of the following paragraph after the offset.
462 *
463 * Since: 2.9.90
464 *
465 * Returns: a newly allocated string containing the text at the @offset bounded
466 * by the specified @granularity. Use g_free() to free the returned string.
467 * Returns %NULL if the offset is invalid or no implementation is available.
468 **/
469 AtspiTextRange *
atspi_text_get_string_at_offset(AtspiText * obj,gint offset,AtspiTextGranularity granularity,GError ** error)470 atspi_text_get_string_at_offset (AtspiText *obj,
471 gint offset,
472 AtspiTextGranularity granularity,
473 GError **error)
474 {
475 dbus_int32_t d_offset = offset;
476 dbus_uint32_t d_granularity = granularity;
477 dbus_int32_t d_start_offset = -1, d_end_offset = -1;
478 AtspiTextRange *range = g_new0 (AtspiTextRange, 1);
479
480 range->start_offset = range->end_offset = -1;
481 if (!obj)
482 return range;
483
484 _atspi_dbus_call (obj, atspi_interface_text, "GetStringAtOffset", error,
485 "iu=>sii", d_offset, d_granularity, &range->content,
486 &d_start_offset, &d_end_offset);
487
488 range->start_offset = d_start_offset;
489 range->end_offset = d_end_offset;
490 if (!range->content)
491 range->content = g_strdup ("");
492
493 return range;
494 }
495
496 /**
497 * atspi_text_get_text_at_offset:
498 * @obj: a pointer to the #AtspiText object on which to operate.
499 * @offset: a #gint indicating the offset from which the delimiter
500 * search is based.
501 * @type: an #AtspiTextBoundaryType indicating whether the desired
502 * text string is a word, sentence, line, or attribute run.
503 *
504 * Gets delimited text from an #AtspiText object which includes a given
505 * text offset.
506 *
507 * Returns: an #AtspiTextRange containing a UTF-8 string representing the
508 * delimited text, whose delimiting boundaries bracket the
509 * current offset, or an empty string if no such text exists.
510 *
511 * Deprecated: 2.10: Use atspi_text_get_string_at_offset.
512 **/
513 AtspiTextRange *
atspi_text_get_text_at_offset(AtspiText * obj,gint offset,AtspiTextBoundaryType type,GError ** error)514 atspi_text_get_text_at_offset (AtspiText *obj,
515 gint offset,
516 AtspiTextBoundaryType type,
517 GError **error)
518 {
519 dbus_int32_t d_offset = offset;
520 dbus_uint32_t d_type = type;
521 dbus_int32_t d_start_offset = -1, d_end_offset = -1;
522 AtspiTextRange *range = g_new0 (AtspiTextRange, 1);
523
524 range->start_offset = range->end_offset = -1;
525 if (!obj)
526 return range;
527
528 _atspi_dbus_call (obj, atspi_interface_text, "GetTextAtOffset", error,
529 "iu=>sii", d_offset, d_type, &range->content,
530 &d_start_offset, &d_end_offset);
531
532 range->start_offset = d_start_offset;
533 range->end_offset = d_end_offset;
534 if (!range->content)
535 range->content = g_strdup ("");
536
537 return range;
538 }
539
540 /**
541 * atspi_text_get_text_after_offset:
542 * @obj: a pointer to the #AtspiText object on which to operate.
543 * @offset: a #gint indicating the offset from which the delimiter
544 * search is based.
545 * @type: an #AtspiTextBoundaryType indicating whether the desired
546 * text string is a word, sentence, line, or attribute run.
547 *
548 * Gets delimited text from an #AtspiText object which follows a given
549 * text offset.
550 *
551 * Returns: an #AtspiTextRange containing a UTF-8 string representing the
552 * delimited text, both of whose delimiting boundaries are after or
553 * inclusive of the current offset, or an empty string if no such
554 * text exists.
555 **/
556 AtspiTextRange *
atspi_text_get_text_after_offset(AtspiText * obj,gint offset,AtspiTextBoundaryType type,GError ** error)557 atspi_text_get_text_after_offset (AtspiText *obj,
558 gint offset,
559 AtspiTextBoundaryType type,
560 GError **error)
561 {
562 dbus_int32_t d_offset = offset;
563 dbus_uint32_t d_type = type;
564 dbus_int32_t d_start_offset = -1, d_end_offset = -1;
565 AtspiTextRange *range = g_new0 (AtspiTextRange, 1);
566
567 range->start_offset = range->end_offset = -1;
568 if (!obj)
569 return range;
570
571 _atspi_dbus_call (obj, atspi_interface_text, "GetTextAfterOffset", error,
572 "iu=>sii", d_offset, d_type, &range->content,
573 &d_start_offset, &d_end_offset);
574
575 range->start_offset = d_start_offset;
576 range->end_offset = d_end_offset;
577 if (!range->content)
578 range->content = g_strdup ("");
579
580 return range;
581 }
582
583 /**
584 * atspi_text_get_character_at_offset:
585 * @obj: a pointer to the #AtspiText object on which to operate.
586 * @offset: a #gint indicating the text offset where the desired
587 * character is located.
588 *
589 * Gets the character at a given offset for an #AtspiText object.
590 *
591 * Returns: a #guint representing the
592 * UCS-4 unicode code point of the given character, or
593 * 0xFFFFFFFF if the character in question cannot be represented
594 * in the UCS-4 encoding.
595 **/
596 guint
atspi_text_get_character_at_offset(AtspiText * obj,gint offset,GError ** error)597 atspi_text_get_character_at_offset (AtspiText *obj,
598 gint offset,
599 GError **error)
600 {
601 dbus_int32_t d_offset = offset;
602 dbus_int32_t retval = -1;
603
604 g_return_val_if_fail (obj != NULL, -1);
605
606 _atspi_dbus_call (obj, atspi_interface_text, "GetCharacterAtOffset", error, "i=>i", d_offset, &retval);
607
608 return retval;
609 }
610
611 /**
612 * atspi_text_get_character_extents:
613 * @obj: a pointer to the #AtspiText object on which to operate.
614 * @offset: a #gint indicating the offset of the text character for
615 * whom boundary information is requested.
616 * @type: an #AccessibleCoordType indicating the coordinate system to use
617 * for the returned values.
618 *
619 * Gets a bounding box containing the glyph representing
620 * the character at a particular text offset.
621 * The returned values are meaningful only if the Text has both
622 * STATE_VISIBLE and STATE_SHOWING.
623 *
624 * Returns: An #AtspiRect specifying the position and size of the character.
625 *
626 **/
627 AtspiRect *
atspi_text_get_character_extents(AtspiText * obj,gint offset,AtspiCoordType type,GError ** error)628 atspi_text_get_character_extents (AtspiText *obj,
629 gint offset,
630 AtspiCoordType type,
631 GError **error)
632 {
633 dbus_int32_t d_offset = offset;
634 dbus_uint32_t d_type = type;
635 dbus_int32_t d_x, d_y, d_width, d_height;
636 AtspiRect ret;
637
638 ret.x = ret.y = ret.width = ret.height = -1;
639
640 if (obj == NULL)
641 return atspi_rect_copy (&ret);
642
643 _atspi_dbus_call (obj, atspi_interface_text, "GetCharacterExtents", error, "iu=>iiii", d_offset, d_type, &d_x, &d_y, &d_width, &d_height);
644
645 ret.x = d_x;
646 ret.y = d_y;
647 ret.width = d_width;
648 ret.height = d_height;
649 return atspi_rect_copy (&ret);
650 }
651
652 /**
653 * atspi_text_get_offset_at_point:
654 * @obj: a pointer to the #AtspiText object on which to operate.
655 * @x: the x coordinate of the point to be queried.
656 * @y: the y coordinate of the point to be queried.
657 * @type: an #AtspiCoordType indicating the coordinate system in which
658 * the values should be returned.
659 *
660 * Gets the character offset into the text at a given point.
661 *
662 * Returns: the offset (as a #gint) at the point (@x, @y)
663 * in the specified coordinate system.
664 *
665 **/
666 gint
atspi_text_get_offset_at_point(AtspiText * obj,gint x,gint y,AtspiCoordType type,GError ** error)667 atspi_text_get_offset_at_point (AtspiText *obj,
668 gint x,
669 gint y,
670 AtspiCoordType type,
671 GError **error)
672 {
673 dbus_int32_t d_x = x, d_y = y;
674 dbus_uint32_t d_type = type;
675 dbus_int32_t retval = -1;
676
677 g_return_val_if_fail (obj != NULL, -1);
678
679 _atspi_dbus_call (obj, atspi_interface_text, "GetOffsetAtPoint", error, "iiu=>i", d_x, d_y, d_type, &retval);
680
681 return retval;
682 }
683
684 /**
685 * atspi_text_get_range_extents:
686 * @obj: a pointer to the #AtspiText object on which to operate.
687 * @start_offset: a #gint indicating the offset of the first text character for
688 * whom boundary information is requested.
689 * @end_offset: a #gint indicating the offset of the text character
690 * after the last character for whom boundary information is requested.
691 * @type: an #AtspiCoordType indicating the coordinate system to use
692 * for the returned values.
693 *
694 * Gets the bounding box for text within a range in an #AtspiText object.
695 * The returned values are meaningful only if the Text has both
696 * STATE_VISIBLE and STATE_SHOWING.
697 *
698 * Returns: An #AtspiRect giving the position and size of the specified range
699 * of text.
700 *
701 **/
702 AtspiRect *
atspi_text_get_range_extents(AtspiText * obj,gint start_offset,gint end_offset,AtspiCoordType type,GError ** error)703 atspi_text_get_range_extents (AtspiText *obj,
704 gint start_offset,
705 gint end_offset,
706 AtspiCoordType type,
707 GError **error)
708 {
709 dbus_int32_t d_start_offset = start_offset, d_end_offset = end_offset;
710 dbus_uint32_t d_type = type;
711 dbus_int32_t d_x, d_y, d_width, d_height;
712 AtspiRect ret;
713
714 ret.x = ret.y = ret.width = ret.height = -1;
715
716 if (obj == NULL)
717 return atspi_rect_copy (&ret);
718
719 _atspi_dbus_call (obj, atspi_interface_text, "GetRangeExtents", error, "iiu=>iiii", d_start_offset, d_end_offset, d_type, &d_x, &d_y, &d_width, &d_height);
720
721 ret.x = d_x;
722 ret.y = d_y;
723 ret.width = d_width;
724 ret.height = d_height;
725 return atspi_rect_copy (&ret);
726 }
727
728 /**
729 * atspi_text_get_bounded_ranges:
730 * @obj: a pointer to the #AtspiText object on which to operate.
731 * @x: the 'starting' x coordinate of the bounding box.
732 * @y: the 'starting' y coordinate of the bounding box.
733 * @width: the x extent of the bounding box.
734 * @height: the y extent of the bounding box.
735 * @type: an #AccessibleCoordType indicating the coordinate system to use
736 * for the returned values.
737 * @clipTypeX: an #AtspiTextClipType indicating how to treat characters that
738 * intersect the bounding box's x extents.
739 * @clipTypeY: an #AtspiTextClipType indicating how to treat characters that
740 * intersect the bounding box's y extents.
741 *
742 * Gets the ranges of text from an #AtspiText object which lie within the
743 * bounds defined by (@x, @y) and (@x+@width, @y+@height).
744 *
745 * Returns: (transfer full) (element-type AtspiTextRange*): a null-terminated list of
746 * pointers to #AtspiTextRange structs detailing the bounded text.
747 **/
748 GArray *
atspi_text_get_bounded_ranges(AtspiText * obj,gint x,gint y,gint width,gint height,AtspiCoordType type,AtspiTextClipType clipTypeX,AtspiTextClipType clipTypeY,GError ** error)749 atspi_text_get_bounded_ranges (AtspiText *obj,
750 gint x,
751 gint y,
752 gint width,
753 gint height,
754 AtspiCoordType type,
755 AtspiTextClipType clipTypeX,
756 AtspiTextClipType clipTypeY,
757 GError **error)
758 {
759 dbus_int32_t d_x = x, d_y = y, d_width = width, d_height = height;
760 dbus_uint32_t d_type = type;
761 dbus_uint32_t d_clipTypeX = clipTypeX, d_clipTypeY = clipTypeY;
762 GArray *range_seq = NULL;
763
764 g_return_val_if_fail (obj != NULL, NULL);
765
766 _atspi_dbus_call (obj, atspi_interface_text, "GetBoundedRanges", error, "iiiiuuu=>a(iisv)", d_x, d_y, d_width, d_height, d_type, d_clipTypeX, d_clipTypeY, &range_seq);
767
768 return range_seq;
769 }
770
771 /**
772 * atspi_text_get_n_selections:
773 * @obj: a pointer to the #AtspiText object on which to operate.
774 *
775 * Gets the number of active non-contiguous selections for an
776 * #AtspiText object.
777 *
778 * Returns: a #gint indicating the current
779 * number of non-contiguous text selections active
780 * within an #AtspiText object.
781 **/
782 gint
atspi_text_get_n_selections(AtspiText * obj,GError ** error)783 atspi_text_get_n_selections (AtspiText *obj, GError **error)
784 {
785 dbus_int32_t retval = 0;
786
787 g_return_val_if_fail (obj != NULL, -1);
788
789 _atspi_dbus_call (obj, atspi_interface_text, "GetNSelections", error, "=>i", &retval);
790
791 return retval;
792 }
793
794 /**
795 * atspi_text_get_selection:
796 * @obj: a pointer to the #AtspiText object on which to operate.
797 * @selection_num: a #gint indicating which selection to query.
798 *
799 * Gets the bounds of the @selection_num-th active text selection for an
800 * #AtspiText object.
801 **/
802 AtspiRange *
atspi_text_get_selection(AtspiText * obj,gint selection_num,GError ** error)803 atspi_text_get_selection (AtspiText *obj,
804 gint selection_num,
805 GError **error)
806 {
807 dbus_int32_t d_selection_num = selection_num;
808 dbus_int32_t d_start_offset, d_end_offset;
809 AtspiRange *ret = g_new (AtspiRange, 1);
810
811 ret->start_offset = ret->end_offset = -1;
812
813 if (!obj)
814 return ret;
815
816 _atspi_dbus_call (obj, atspi_interface_text, "GetSelection", error, "i=>ii", d_selection_num, &d_start_offset, &d_end_offset);
817
818 ret->start_offset = d_start_offset;
819 ret->end_offset = d_end_offset;
820 return ret;
821 }
822
823 /**
824 * atspi_text_add_selection:
825 * @obj: a pointer to the #AtspiText object on which to operate.
826 * @start_offset: the starting offset of the desired new selection.
827 * @end_offset: the offset of the first character after the new selection.
828 *
829 * Selects some text (adds a text selection) in an #AtspiText object.
830 *
831 * Returns: #TRUE if successful, #FALSE otherwise.
832 **/
833 gboolean
atspi_text_add_selection(AtspiText * obj,gint start_offset,gint end_offset,GError ** error)834 atspi_text_add_selection (AtspiText *obj,
835 gint start_offset, gint end_offset,
836 GError **error)
837 {
838 dbus_int32_t d_start_offset = start_offset, d_end_offset = end_offset;
839 dbus_bool_t retval = FALSE;
840
841 _atspi_dbus_call (obj, atspi_interface_text, "AddSelection", error, "ii=>b", d_start_offset, d_end_offset, &retval);
842
843 return retval;
844 }
845
846 /**
847 * atspi_text_remove_selection:
848 * @obj: a pointer to the #AtspiText object on which to operate.
849 * @selection_num: a #gint indicating which text selection to remove.
850 *
851 * De-selects a text selection.
852 *
853 * Returns: #TRUE if successful, #FALSE otherwise.
854 **/
855 gboolean
atspi_text_remove_selection(AtspiText * obj,gint selection_num,GError ** error)856 atspi_text_remove_selection (AtspiText *obj,
857 gint selection_num,
858 GError **error)
859 {
860 dbus_int32_t d_selection_num = selection_num;
861 dbus_bool_t retval = FALSE;
862
863 g_return_val_if_fail (obj != NULL, FALSE);
864
865 _atspi_dbus_call (obj, atspi_interface_text, "RemoveSelection", error, "i=>b", d_selection_num, &retval);
866
867 return retval;
868 }
869
870 /**
871 * atspi_text_set_selection:
872 * @obj: a pointer to the #AtspiText object on which to operate.
873 * @selection_num: a zero-offset index indicating which text selection to modify.
874 * @start_offset: a #gint indicating the new starting offset for the selection.
875 * @end_offset: a #gint indicating the desired new offset of the first character
876 * after the selection.
877 *
878 * Changes the bounds of an existing #AtspiText text selection.
879 *
880 * Returns: #TRUE if successful, #FALSE otherwise.
881 **/
882 gboolean
atspi_text_set_selection(AtspiText * obj,gint selection_num,gint start_offset,gint end_offset,GError ** error)883 atspi_text_set_selection (AtspiText *obj,
884 gint selection_num,
885 gint start_offset,
886 gint end_offset,
887 GError **error)
888 {
889 dbus_int32_t d_selection_num = selection_num, d_start_offset = start_offset, d_end_offset = end_offset;
890 dbus_bool_t retval = FALSE;
891
892 g_return_val_if_fail (obj != NULL, FALSE);
893
894 _atspi_dbus_call (obj, atspi_interface_text, "SetSelection", error, "iii=>b", d_selection_num, d_start_offset, d_end_offset, &retval);
895
896 return retval;
897 }
898
899 /**
900 * atspi_text_scroll_substring_to:
901 * @obj: a pointer to the #AtspiText object on which to operate.
902 * @start_offset: a #gint indicating the start of the desired text range.
903 * @end_offset: a #gint indicating the first character past the desired range.
904 * @type: a #AtspiScrollType indicating where the object should be placed on the
905 * screen.
906 *
907 * Scrolls whatever container of the #AtspiText text range so it becomes
908 * visible on the screen.
909 *
910 * Returns: #TRUE if successful, #FALSE otherwise.
911 **/
912 gboolean
atspi_text_scroll_substring_to(AtspiText * obj,gint start_offset,gint end_offset,AtspiScrollType type,GError ** error)913 atspi_text_scroll_substring_to (AtspiText *obj,
914 gint start_offset,
915 gint end_offset,
916 AtspiScrollType type,
917 GError **error)
918 {
919 dbus_bool_t retval = FALSE;
920
921 g_return_val_if_fail (obj != NULL, FALSE);
922
923 _atspi_dbus_call (obj, atspi_interface_text, "ScrollSubstringTo",
924 error, "iiu=>b",
925 start_offset, end_offset, type, &retval);
926
927 return retval;
928 }
929
930 /**
931 * atspi_text_scroll_substring_to_point:
932 * @obj: a pointer to the #AtspiText object on which to operate.
933 * @start_offset: a #gint indicating the start of the desired text range.
934 * @end_offset: a #gint indicating the first character past the desired range.
935 * @coords: a #AtspiCoordType indicating whether the coordinates are relative to
936 * the screen, to the window, or to the parent object.
937 * @x: the x coordinate of the point to reach
938 * @y: the y coordinate of the point to reach
939 *
940 * Scrolls whatever container of the #AtspiText text range so it becomes
941 * visible on the screen at a given position.
942 *
943 * Returns: #TRUE if successful, #FALSE otherwise.
944 **/
945 gboolean
atspi_text_scroll_substring_to_point(AtspiText * obj,gint start_offset,gint end_offset,AtspiCoordType coords,gint x,gint y,GError ** error)946 atspi_text_scroll_substring_to_point (AtspiText *obj,
947 gint start_offset,
948 gint end_offset,
949 AtspiCoordType coords,
950 gint x,
951 gint y,
952 GError **error)
953 {
954 dbus_bool_t retval = FALSE;
955
956 g_return_val_if_fail (obj != NULL, FALSE);
957
958 _atspi_dbus_call (obj, atspi_interface_text, "ScrollSubstringToPoint",
959 error, "iiuii=>b",
960 start_offset, end_offset, coords, x, y, &retval);
961
962 return retval;
963 }
964
965 static void
atspi_text_base_init(AtspiText * klass)966 atspi_text_base_init (AtspiText *klass)
967 {
968 }
969
970 GType
atspi_text_get_type(void)971 atspi_text_get_type (void)
972 {
973 static GType type = 0;
974
975 if (!type) {
976 static const GTypeInfo tinfo =
977 {
978 sizeof (AtspiText),
979 (GBaseInitFunc) atspi_text_base_init,
980 (GBaseFinalizeFunc) NULL,
981 };
982
983 type = g_type_register_static (G_TYPE_INTERFACE, "AtspiText", &tinfo, 0);
984
985 }
986 return type;
987 }
988