2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001, 2002 Sun Microsystems Inc.,
6 * Copyright 2001, 2002 Ximian, Inc.
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.
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.
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.
24 #include "atspi-private.h"
27 atspi_range_copy (AtspiRange *src)
29 AtspiRange *dst = g_new (AtspiRange, 1);
33 dst->start_offset = src->start_offset;
34 dst->end_offset = src->end_offset;
39 G_DEFINE_BOXED_TYPE (AtspiRange, atspi_range, atspi_range_copy, g_free)
41 static AtspiTextRange *
42 atspi_text_range_copy (AtspiTextRange *src)
44 AtspiTextRange *dst = g_new (AtspiTextRange, 1);
48 dst->content = g_strdup (src->content);
49 dst->start_offset = src->start_offset;
50 dst->end_offset = src->end_offset;
56 atspi_text_range_free (AtspiTextRange *range)
58 g_free (range->content);
62 G_DEFINE_BOXED_TYPE (AtspiTextRange, atspi_text_range, atspi_text_range_copy,
63 atspi_text_range_free)
66 * atspi_text_get_character_count:
67 * @obj: a pointer to the #AtspiText object to query.
69 * Get the character count of an #AccessibleText object.
71 * Returns: a long integer indicating the total number of
72 * characters in the #AccessibleText object.
75 atspi_text_get_character_count (AtspiText *obj, GError **error)
79 g_return_val_if_fail (obj != NULL, -1);
81 _atspi_dbus_get_property (obj, atspi_interface_text, "CharacterCount", error, "i", &retval);
87 * atspi_text_get_text:
88 * @obj: a pointer to the #AtspiText object to query.
89 * @start_offset: a #long indicating the start of the desired text range.
90 * @end_offset: a #long indicating the first character past the desired range.
92 * Get a range of text from an #AtspiText object. The number of bytes
93 * in the returned string may exceed end_offset-start_offset, since
94 * UTF-8 is a variable-width encoding.
96 * Returns: a text string containing characters from @start_offset
97 * to @end_offset-1, inclusive, encoded as UTF-8.
100 atspi_text_get_text (AtspiText *obj,
105 gchar *retval = NULL;
106 dbus_int32_t d_start_offset = start_offset, d_end_offset = end_offset;
108 g_return_val_if_fail (obj != NULL, g_strdup (""));
110 _atspi_dbus_call (obj, atspi_interface_text, "GetText", error, "ii=>s", d_start_offset, d_end_offset, &retval);
113 retval = g_strdup ("");
119 * atspi_text_get_caret_offset:
120 * @obj: a pointer to the #AtspiText object to query.
122 * Get the current offset of the text caret in an #AtspiText object.
124 * Returns: a long integer indicating the current position of the text caret.
127 atspi_text_get_caret_offset (AtspiText *obj, GError **error)
129 dbus_int32_t retval = -1;
131 g_return_val_if_fail (obj != NULL, -1);
133 _atspi_dbus_get_property (obj, atspi_interface_text, "CaretOffset", error, "i", &retval);
139 * atspi_text_get_attributes:
140 * @obj: a pointer to the #AtspiText object to query.
141 * @offset: a long integer indicating the offset from which the attribute
143 * @start_offset: (out): a #gint indicating the start of the desired text
145 * @end_offset: (out): a #gint indicating the first character past the desired
148 * Get the attributes applied to a range of text from an #AtspiText
149 * object, and the bounds of the range.
150 * The text attributes correspond to CSS attributes where possible,
152 * Returns: (element-type gchar* gchar*) (transfer full): a #GHashTable
153 * describing the attributes at the given character offset
156 atspi_text_get_attributes (AtspiText *obj,
162 dbus_int32_t d_offset = offset;
163 dbus_int32_t d_start_offset, d_end_offset;
165 DBusMessageIter iter;
166 GHashTable *ret = NULL;
171 reply = _atspi_dbus_call_partial (obj, atspi_interface_text, "GetAttributes", error, "i", d_offset);
172 _ATSPI_DBUS_CHECK_SIG (reply, "a{ss}ii", error, ret)
174 dbus_message_iter_init (reply, &iter);
175 ret = _atspi_dbus_hash_from_iter (&iter);
176 dbus_message_iter_next (&iter);
178 dbus_message_iter_get_basic (&iter, &d_start_offset);
180 *start_offset = d_start_offset;
181 dbus_message_iter_next (&iter);
182 dbus_message_iter_get_basic (&iter, &d_end_offset);
184 *end_offset = d_start_offset;
186 dbus_message_unref (reply);
191 * atspi_text_get_attribute_run:
192 * @obj: a pointer to the #AtspiText object to query.
193 * @offset: an integer indicating the offset from which the attribute
195 * @include_defaults: a #bool if False, the call should only return those
196 * attributes which are explicitly set on the current attribute
197 * run, omitting any attributes which are inherited from the
199 * @start_offset: (out): a #gint indicating the start of the desired text
201 * @end_offset: (out): a #gint indicating the first character past the desired
204 * Returns: (element-type gchar* gchar*) (transfer full): the AttributeSet
205 * defined at offset, optionally including the 'default' attributes.
208 atspi_text_get_attribute_run (AtspiText *obj,
210 gboolean include_defaults,
215 dbus_int32_t d_offset = offset;
216 dbus_int32_t d_start_offset, d_end_offset;
218 DBusMessageIter iter;
219 GHashTable *ret = NULL;
224 reply = _atspi_dbus_call_partial (obj, atspi_interface_text,
225 "GetAttributeRun", error, "ib", d_offset,
227 _ATSPI_DBUS_CHECK_SIG (reply, "a{ss}ii", error, ret)
229 dbus_message_iter_init (reply, &iter);
230 ret = _atspi_dbus_hash_from_iter (&iter);
231 dbus_message_iter_next (&iter);
233 dbus_message_iter_get_basic (&iter, &d_start_offset);
235 *start_offset = d_start_offset;
236 dbus_message_iter_next (&iter);
237 dbus_message_iter_get_basic (&iter, &d_end_offset);
239 *end_offset = d_end_offset;
241 dbus_message_unref (reply);
246 * atspi_text_get_attribute_value:
247 * @obj: a pointer to the #AtspiText object to query.
248 * @offset: The character offset at which to query the attribute.
249 * @attribute_name: The attribute to query.
251 * Returns: the value of a given attribute at the given offset, or NULL if
255 atspi_text_get_attribute_value (AtspiText *obj,
257 gchar *attribute_value,
260 gchar *retval = NULL;
262 g_return_val_if_fail (obj != NULL, NULL);
264 _atspi_dbus_call (obj, atspi_interface_text, "GetAttributeValue", error, "i=>s", offset, &retval);
270 * atspi_text_get_default_attributes:
271 * @obj: a pointer to the #AtspiText object to query.
273 * Get the default attributes applied to an #AtspiText
275 * The text attributes correspond to CSS attributes where possible,
276 * keys and values are delimited from one another via ":", and
277 * the delimiter between key/value pairs is ";". Thus
278 * "font-size:10;foreground-color:0,0,0" would be a valid
279 * return string. The combination of this attribute set and
280 * the attributes reported by #atspi_text_getAttributes
281 * describes the entire set of text attributes over a range.
283 * Returns: (element-type gchar* gchar*) (transfer full): a #GHashTable
284 * containing the default attributes applied to a text object,
285 * (exclusive of explicitly-set attributes), encoded as UTF-8.
288 atspi_text_get_default_attributes (AtspiText *obj, GError **error)
292 g_return_val_if_fail (obj != NULL, NULL);
294 reply = _atspi_dbus_call_partial (obj, atspi_interface_text, "GetDefaultAttributes", error, "");
295 return _atspi_dbus_return_hash_from_message (reply);
300 * atspi_text_set_caret_offset:
301 * @obj: a pointer to the #AtspiText object on which to operate.
302 * @new_offset: the offset to which the text caret is to be moved.
304 * Set the text caret position for an #AtspiText object.
306 * Returns: #TRUE if successful, #FALSE otherwise.
309 atspi_text_set_caret_offset (AtspiText *obj,
313 dbus_int32_t d_new_offset = new_offset;
314 dbus_bool_t retval = FALSE;
316 g_return_val_if_fail (obj != NULL, FALSE);
318 _atspi_dbus_call (obj, atspi_interface_text, "SetCaretOffset", error, "i=>b", d_new_offset, &retval);
324 * atspi_text_get_text_before_offset:
325 * @obj: a pointer to the #AtspiText object on which to operate.
326 * @offset: an integer indicating the offset from which the delimiter
328 * @type: an #AtspiTextBoundaryType indicating whether the desired
329 * text string is a word, sentence, line, or attribute run.
331 * Get delimited text from an #AtspiText object which precedes a given
334 * Returns: an #AtspiTextRange containing a UTF-8 string representing the
335 * delimited text, both of whose delimiting boundaries are before the
336 * current offset, or an empty string if no such text exists.
339 atspi_text_get_text_before_offset (AtspiText *obj,
341 AtspiTextBoundaryType type,
344 dbus_int32_t d_offset = offset;
345 dbus_uint32_t d_type = type;
346 dbus_int32_t d_start_offset = -1, d_end_offset = -1;
347 AtspiTextRange *range = g_new0 (AtspiTextRange, 1);
350 range->start_offset = range->end_offset = -1;
354 _atspi_dbus_call (obj, atspi_interface_text, "GetTextBeforeOffset", error,
355 "iu=>sii", d_offset, d_type, &range->content,
356 &d_start_offset, &d_end_offset);
358 range->start_offset = d_start_offset;
359 range->end_offset = d_end_offset;
361 range->content = g_strdup ("");
367 * atspi_text_get_text_at_offset:
368 * @obj: a pointer to the #AtspiText object on which to operate.
369 * @offset: a long integer indicating the offset from which the delimiter
371 * @type: an #AtspiTextBoundaryType indicating whether the desired
372 * text string is a word, sentence, line, or attribute run.
374 * Get delimited text from an #AtspiText object which includes a given
377 * Returns: an #AtspiTextRange containing a UTF-8 string representing the
378 * delimited text, whose delimiting boundaries bracket the
379 * current offset, or an empty string if no such text exists.
382 atspi_text_get_text_at_offset (AtspiText *obj,
384 AtspiTextBoundaryType type,
387 dbus_int32_t d_offset = offset;
388 dbus_uint32_t d_type = type;
389 dbus_int32_t d_start_offset = -1, d_end_offset = -1;
390 AtspiTextRange *range = g_new0 (AtspiTextRange, 1);
393 range->start_offset = range->end_offset = -1;
397 _atspi_dbus_call (obj, atspi_interface_text, "GetTextAtOffset", error,
398 "iu=>sii", d_offset, d_type, &range->content,
399 &d_start_offset, &d_end_offset);
401 range->start_offset = d_start_offset;
402 range->end_offset = d_end_offset;
404 range->content = g_strdup ("");
410 * atspi_text_get_text_after_offset:
411 * @obj: a pointer to the #AtspiText object on which to operate.
412 * @offset: an integer indicating the offset from which the delimiter
414 * @type: an #AtspiTextBoundaryType indicating whether the desired
415 * text string is a word, sentence, line, or attribute run.
417 * Get delimited text from an #AtspiText object which follows a given
420 * Returns: an #AtspiTextRange containing a UTF-8 string representing the
421 * delimited text, both of whose delimiting boundaries are after or
422 * inclusive of the current offset, or an empty string if no such
426 atspi_text_get_text_after_offset (AtspiText *obj,
428 AtspiTextBoundaryType type,
431 dbus_int32_t d_offset = offset;
432 dbus_uint32_t d_type = type;
433 dbus_int32_t d_start_offset = -1, d_end_offset = -1;
434 AtspiTextRange *range = g_new0 (AtspiTextRange, 1);
437 range->start_offset = range->end_offset = -1;
441 _atspi_dbus_call (obj, atspi_interface_text, "GetTextAfterOffset", error,
442 "iu=>sii", d_offset, d_type, &range->content,
443 &d_start_offset, &d_end_offset);
445 range->start_offset = d_start_offset;
446 range->end_offset = d_end_offset;
448 range->content = g_strdup ("");
454 * atspi_text_get_character_at_offset:
455 * @obj: a pointer to the #AtspiText object on which to operate.
456 * @offset: a long integer indicating the text offset where the desired
457 * character is located.
459 * Get the character at a given offset for an #AtspiText object.
461 * Returns: an #unsigned long integer which represents the
462 * UCS-4 unicode code point of the given character, or
463 * 0xFFFFFFFF if the character in question cannot be represented
464 * in the UCS-4 encoding.
467 atspi_text_get_character_at_offset (AtspiText *obj,
471 dbus_int32_t d_offset = offset;
472 dbus_int32_t retval = -1;
474 g_return_val_if_fail (obj != NULL, -1);
476 _atspi_dbus_call (obj, atspi_interface_text, "GetCharacterAtOffset", error, "i=>i", d_offset, &retval);
482 * atspi_text_get_character_extents:
483 * @obj: a pointer to the #AtspiText object on which to operate.
484 * @offset: an integer indicating the offset of the text character for
485 * whom boundary information is requested.
486 * @type: an #AccessibleCoordType indicating the coordinate system to use
487 * for the returned values.
489 * Returns: A #AtspiRect specifying the position and size of the character.
491 * Get the bounding box containing the glyph representing
492 * the character at a particular text offset.
495 atspi_text_get_character_extents (AtspiText *obj,
500 dbus_int32_t d_offset = offset;
501 dbus_uint32_t d_type = type;
502 dbus_int32_t d_x, d_y, d_width, d_height;
505 ret.x = ret.y = ret.width = ret.height = -1;
508 return atspi_rect_copy (&ret);
510 _atspi_dbus_call (obj, atspi_interface_text, "GetCharacterExtents", error, "iu=>iiii", d_offset, d_type, &d_x, &d_y, &d_width, &d_height);
515 ret.height = d_height;
516 return atspi_rect_copy (&ret);
520 * atspi_text_get_offset_at_point:
521 * @obj: a pointer to the #AtspiText object on which to operate.
522 * @x: the x coordinate of the point to be queried.
523 * @y: the y coordinate of the point to be queried.
524 * @type: an #AtspiCoordType indicating the coordinate system in which
525 * the values should be returned.
527 * Get the character offset into the text at a given point.
529 * Returns: the offset (as an integer) at the point (@x, @y)
530 * in the specified coordinate system.
534 atspi_text_get_offset_at_point (AtspiText *obj,
540 dbus_int32_t d_x = x, d_y = y;
541 dbus_uint32_t d_type = type;
542 dbus_int32_t retval = -1;
544 g_return_val_if_fail (obj != NULL, -1);
546 _atspi_dbus_call (obj, atspi_interface_text, "GetOffsetAtPoint", error, "iiu=>i", d_x, d_y, d_type, &retval);
552 * atspi_text_get_range_extents:
553 * @obj: a pointer to the #AtspiText object on which to operate.
554 * @start_offset: an integer indicating the offset of the first text character for
555 * whom boundary information is requested.
556 * @end_offset: an integer indicating the offset of the text character
557 * after the last character for whom boundary information is requested.
558 * @type: an #AtspiCoordType indicating the coordinate system to use
559 * for the returned values.
561 * Returns: A #AtspiRect giving the position and size of the specified range
564 * Get the bounding box for text within a range in an #AtspiText object.
567 atspi_text_get_range_extents (AtspiText *obj,
573 dbus_int32_t d_start_offset = start_offset, d_end_offset = end_offset;
574 dbus_uint32_t d_type = type;
575 dbus_int32_t d_x, d_y, d_width, d_height;
578 ret.x = ret.y = ret.width = ret.height = -1;
581 return atspi_rect_copy (&ret);
583 _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);
588 ret.height = d_height;
589 return atspi_rect_copy (&ret);
593 * atspi_text_get_bounded_ranges:
594 * @obj: a pointer to the #AtspiText object on which to operate.
595 * @x: the 'starting' x coordinate of the bounding box.
596 * @y: the 'starting' y coordinate of the bounding box.
597 * @width: the x extent of the bounding box.
598 * @height: the y extent of the bounding box.
599 * @type: an #AccessibleCoordType indicating the coordinate system to use
600 * for the returned values.
601 * @clipTypeX: an #AtspiTextClipType indicating how to treat characters that
602 * intersect the bounding box's x extents.
603 * @clipTypeY: an #AtspiTextClipType indicating how to treat characters that
604 * intersect the bounding box's y extents.
606 * Get the ranges of text from an #AtspiText object which lie within the
607 * bounds defined by (@x, @y) and (@x+@width, @y+@height).
609 * Returns: (transfer full) (element-type AtspiTextRange*): a null-terminated list of
610 * pointers to #AtspiTextRange structs detailing the bounded text.
613 atspi_text_get_bounded_ranges (AtspiText *obj,
619 AtspiTextClipType clipTypeX,
620 AtspiTextClipType clipTypeY,
623 dbus_int32_t d_x = x, d_y = y, d_width = width, d_height = height;
624 dbus_uint32_t d_type = type;
625 dbus_uint32_t d_clipTypeX = clipTypeX, d_clipTypeY = clipTypeY;
628 g_return_val_if_fail (obj != NULL, NULL);
630 _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);
636 * atspi_text_get_n_selections:
637 * @obj: a pointer to the #AtspiText object on which to operate.
639 * Get the number of active non-contiguous selections for an
642 * Returns: a long integer indicating the current
643 * number of non-contiguous text selections active
644 * within an #AtspiText object.
647 atspi_text_get_n_selections (AtspiText *obj, GError **error)
651 g_return_val_if_fail (obj != NULL, -1);
653 _atspi_dbus_call (obj, atspi_interface_text, "GetNSelections", error, "i", &retval);
659 * atspi_text_get_sSelection:
660 * @obj: a pointer to the #AtspiText object on which to operate.
661 * @selection_num: an integer indicating which selection to query.
662 * @start_offset: a pointer to a long integer into which the start offset
663 * of the selection will be returned.
664 * @end_offset: a pointer to a long integer into which the start offset
665 * of the selection will be returned.
667 * Get the bounds of the @selection_num-th active text selection for an
671 atspi_text_get_selection (AtspiText *obj,
675 dbus_int32_t d_selection_num = selection_num;
676 dbus_int32_t d_start_offset, d_end_offset;
677 AtspiRange *ret = g_new (AtspiRange, 1);
680 ret->start_offset = ret->end_offset = -1;
685 _atspi_dbus_call (obj, atspi_interface_text, "GetSelection", error, "i=>ii", d_selection_num, &d_start_offset, &d_end_offset);
687 ret->start_offset = d_start_offset;
688 ret->end_offset = d_end_offset;
693 * atspi_text_add_selection:
694 * @obj: a pointer to the #AtspiText object on which to operate.
695 * @start_offset: the starting offset of the desired new selection.
696 * @end_offset: the offset of the first character after the new selection.
698 * Select some text (add a text selection) in an #AtspiText object.
700 * Returns: #TRUE if successful, #FALSE otherwise.
703 atspi_text_add_selection (AtspiText *obj,
704 gint start_offset, gint end_offset,
707 dbus_int32_t d_start_offset = start_offset, d_end_offset = end_offset;
708 dbus_bool_t retval = FALSE;
710 _atspi_dbus_call (obj, atspi_interface_text, "AddSelection", error, "ii=>b", d_start_offset, d_end_offset, &retval);
716 * atspi_text_remove_selection:
717 * @obj: a pointer to the #AtspiText object on which to operate.
718 * @selection_num: an integer indicating which (possibly of several)
719 * text selection to remove.
721 * De-select a text selection.
723 * Returns: #TRUE if successful, #FALSE otherwise.
726 atspi_text_remove_selection (AtspiText *obj,
730 dbus_int32_t d_selection_num = selection_num;
731 dbus_bool_t retval = FALSE;
733 g_return_val_if_fail (obj != NULL, FALSE);
735 _atspi_dbus_call (obj, atspi_interface_text, "RemoveSelection", error, "i=>b", d_selection_num, &retval);
741 * atspi_text_set_selection:
742 * @obj: a pointer to the #AtspiText object on which to operate.
743 * @selection_num: a zero-offset index indicating which text selection to modify.
744 * @start_offset: a long int, the new starting offset for the selection.
745 * @end_offset: a long int, the desired new offset of the first character
746 * after the selection.
748 * Change the bounds of an existing #AtspiText text selection.
750 * Returns: #TRUE if successful, #FALSE otherwise.
753 atspi_text_set_selection (AtspiText *obj,
759 dbus_int32_t d_selection_num = selection_num, d_start_offset = start_offset, d_end_offset = end_offset;
760 dbus_bool_t retval = FALSE;
762 g_return_val_if_fail (obj != NULL, FALSE);
764 _atspi_dbus_call (obj, atspi_interface_text, "SetSelection", error, "iii=>b", d_selection_num, d_start_offset, d_end_offset, &retval);
770 atspi_text_base_init (AtspiText *klass)
775 atspi_text_get_type (void)
777 static GType type = 0;
780 static const GTypeInfo tinfo =
783 (GBaseInitFunc) atspi_text_base_init,
784 (GBaseFinalizeFunc) NULL,
787 type = g_type_register_static (G_TYPE_INTERFACE, "AtspiText", &tinfo, 0);