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", start_offset, 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;
166 DBusMessageIter iter;
172 reply = _atspi_dbus_call_partial (obj, atspi_interface_text, "GetAttributes", error, "i", d_offset);
173 _ATSPI_DBUS_CHECK_SIG (reply, "a{ss}ii", error, ret)
175 dbus_message_iter_init (reply, &iter);
176 ret = _atspi_dbus_hash_from_iter (&iter);
177 dbus_message_iter_next (&iter);
179 dbus_message_iter_get_basic (&iter, &d_start_offset);
181 *start_offset = d_start_offset;
182 dbus_message_iter_next (&iter);
183 dbus_message_iter_get_basic (&iter, &d_end_offset);
185 *end_offset = d_start_offset;
187 dbus_message_unref (reply);
192 * atspi_text_get_attribute_run:
193 * @obj: a pointer to the #AtspiText object to query.
194 * @offset: an integer indicating the offset from which the attribute
196 * @include_defaults: a #bool if False, the call should only return those
197 * attributes which are explicitly set on the current attribute
198 * run, omitting any attributes which are inherited from the
200 * @start_offset: (out): a #gint indicating the start of the desired text
202 * @end_offset: (out): a #gint indicating the first character past the desired
205 * Returns: (element-type gchar* gchar*) (transfer full): the AttributeSet
206 * defined at offset, optionally including the 'default' attributes.
209 atspi_text_get_attribute_run (AtspiText *obj,
211 gboolean include_defaults,
216 dbus_int32_t d_offset = offset;
217 dbus_int32_t d_start_offset, d_end_offset;
220 DBusMessageIter iter;
226 reply = _atspi_dbus_call_partial (obj, atspi_interface_text,
227 "GetAttributeRun", error, "ib", d_offset,
229 _ATSPI_DBUS_CHECK_SIG (reply, "a{ss}ii", error, ret)
231 dbus_message_iter_init (reply, &iter);
232 ret = _atspi_dbus_hash_from_iter (&iter);
233 dbus_message_iter_next (&iter);
235 dbus_message_iter_get_basic (&iter, &d_start_offset);
237 *start_offset = d_start_offset;
238 dbus_message_iter_next (&iter);
239 dbus_message_iter_get_basic (&iter, &d_end_offset);
241 *end_offset = d_end_offset;
243 dbus_message_unref (reply);
248 * atspi_text_get_attribute_value:
249 * @obj: a pointer to the #AtspiText object to query.
250 * @offset: The character offset at which to query the attribute.
251 * @attribute_name: The attribute to query.
253 * Returns: the value of a given attribute at the given offset, or NULL if
257 atspi_text_get_attribute_value (AtspiText *obj,
259 gchar *attribute_value,
262 gchar *retval = NULL;
264 g_return_val_if_fail (obj != NULL, NULL);
266 _atspi_dbus_call (obj, atspi_interface_text, "GetAttributeValue", error, "i=>s", offset, &retval);
272 * atspi_text_get_default_attributes:
273 * @obj: a pointer to the #AtspiText object to query.
275 * Get the default attributes applied to an #AtspiText
277 * The text attributes correspond to CSS attributes where possible,
278 * keys and values are delimited from one another via ":", and
279 * the delimiter between key/value pairs is ";". Thus
280 * "font-size:10;foreground-color:0,0,0" would be a valid
281 * return string. The combination of this attribute set and
282 * the attributes reported by #atspi_text_getAttributes
283 * describes the entire set of text attributes over a range.
285 * Returns: (element-type gchar* gchar*) (transfer full): a #GHashTable
286 * containing the default attributes applied to a text object,
287 * (exclusive of explicitly-set attributes), encoded as UTF-8.
290 atspi_text_get_default_attributes (AtspiText *obj, GError **error)
294 g_return_val_if_fail (obj != NULL, NULL);
296 reply = _atspi_dbus_call_partial (obj, atspi_interface_text, "GetDefaultAttributes", error, "");
297 return _atspi_dbus_return_hash_from_message (reply);
302 * atspi_text_set_caret_offset:
303 * @obj: a pointer to the #AtspiText object on which to operate.
304 * @new_offset: the offset to which the text caret is to be moved.
306 * Set the text caret position for an #AtspiText object.
308 * Returns: #TRUE if successful, #FALSE otherwise.
311 atspi_text_set_caret_offset (AtspiText *obj,
315 dbus_int32_t d_new_offset = new_offset;
316 dbus_bool_t retval = FALSE;
318 g_return_val_if_fail (obj != NULL, FALSE);
320 _atspi_dbus_call (obj, atspi_interface_text, "SetCaretOffset", error, "i=>b", d_new_offset, &retval);
326 * atspi_text_get_text_before_offset:
327 * @obj: a pointer to the #AtspiText object on which to operate.
328 * @offset: an integer indicating the offset from which the delimiter
330 * @type: an #AtspiTextBoundaryType indicating whether the desired
331 * text string is a word, sentence, line, or attribute run.
333 * Get delimited text from an #AtspiText object which precedes a given
336 * Returns: an #AtspiTextRange containing a UTF-8 string representing the
337 * delimited text, both of whose delimiting boundaries are before the
338 * current offset, or an empty string if no such text exists.
341 atspi_text_get_text_before_offset (AtspiText *obj,
343 AtspiTextBoundaryType type,
346 dbus_int32_t d_offset = offset;
347 dbus_uint32_t d_type = type;
348 dbus_int32_t d_start_offset = -1, d_end_offset = -1;
349 AtspiTextRange *range = g_new0 (AtspiTextRange, 1);
352 range->start_offset = range->end_offset = -1;
356 _atspi_dbus_call (obj, atspi_interface_text, "GetTextBeforeOffset", error,
357 "iu=>sii", d_offset, d_type, &range->content,
358 &d_start_offset, &d_end_offset);
360 range->start_offset = d_start_offset;
361 range->end_offset = d_end_offset;
363 range->content = g_strdup ("");
369 * atspi_text_get_text_at_offset:
370 * @obj: a pointer to the #AtspiText object on which to operate.
371 * @offset: a long integer indicating the offset from which the delimiter
373 * @type: an #AtspiTextBoundaryType indicating whether the desired
374 * text string is a word, sentence, line, or attribute run.
376 * Get delimited text from an #AtspiText object which includes a given
379 * Returns: an #AtspiTextRange containing a UTF-8 string representing the
380 * delimited text, whose delimiting boundaries bracket the
381 * current offset, or an empty string if no such text exists.
384 atspi_text_get_text_at_offset (AtspiText *obj,
386 AtspiTextBoundaryType type,
389 dbus_int32_t d_offset = offset;
390 dbus_uint32_t d_type = type;
391 dbus_int32_t d_start_offset = -1, d_end_offset = -1;
392 AtspiTextRange *range = g_new0 (AtspiTextRange, 1);
395 range->start_offset = range->end_offset = -1;
399 _atspi_dbus_call (obj, atspi_interface_text, "GetTextAtOffset", error,
400 "iu=>sii", d_offset, d_type, &range->content,
401 &d_start_offset, &d_end_offset);
403 range->start_offset = d_start_offset;
404 range->end_offset = d_end_offset;
406 range->content = g_strdup ("");
412 * atspi_text_get_text_after_offset:
413 * @obj: a pointer to the #AtspiText object on which to operate.
414 * @offset: an integer indicating the offset from which the delimiter
416 * @type: an #AtspiTextBoundaryType indicating whether the desired
417 * text string is a word, sentence, line, or attribute run.
419 * Get delimited text from an #AtspiText object which follows a given
422 * Returns: an #AtspiTextRange containing a UTF-8 string representing the
423 * delimited text, both of whose delimiting boundaries are after or
424 * inclusive of the current offset, or an empty string if no such
428 atspi_text_get_text_after_offset (AtspiText *obj,
430 AtspiTextBoundaryType type,
433 dbus_int32_t d_offset = offset;
434 dbus_uint32_t d_type = type;
435 dbus_int32_t d_start_offset = -1, d_end_offset = -1;
436 AtspiTextRange *range = g_new0 (AtspiTextRange, 1);
439 range->start_offset = range->end_offset = -1;
443 _atspi_dbus_call (obj, atspi_interface_text, "GetTextAfterOffset", error,
444 "iu=>sii", d_offset, d_type, &range->content,
445 &d_start_offset, &d_end_offset);
447 range->start_offset = d_start_offset;
448 range->end_offset = d_end_offset;
450 range->content = g_strdup ("");
456 * atspi_text_get_character_at_offset:
457 * @obj: a pointer to the #AtspiText object on which to operate.
458 * @offset: a long integer indicating the text offset where the desired
459 * character is located.
461 * Get the character at a given offset for an #AtspiText object.
463 * Returns: an #unsigned long integer which represents the
464 * UCS-4 unicode code point of the given character, or
465 * 0xFFFFFFFF if the character in question cannot be represented
466 * in the UCS-4 encoding.
469 atspi_text_get_character_at_offset (AtspiText *obj,
473 dbus_int32_t d_offset = offset;
474 dbus_int32_t retval = -1;
476 g_return_val_if_fail (obj != NULL, -1);
478 _atspi_dbus_call (obj, atspi_interface_text, "GetCharacterAtOffset", error, "i=>i", d_offset, &retval);
484 * atspi_text_get_character_extents:
485 * @obj: a pointer to the #AtspiText object on which to operate.
486 * @offset: an integer indicating the offset of the text character for
487 * whom boundary information is requested.
488 * @type: an #AccessibleCoordType indicating the coordinate system to use
489 * for the returned values.
491 * Returns: A #AtspiRect specifying the position and size of the character.
493 * Get the bounding box containing the glyph representing
494 * the character at a particular text offset.
497 atspi_text_get_character_extents (AtspiText *obj,
502 dbus_int32_t d_offset = offset;
503 dbus_uint32_t d_type = type;
504 dbus_int32_t d_x, d_y, d_width, d_height;
507 ret.x = ret.y = ret.width = ret.height = -1;
510 return atspi_rect_copy (&ret);
512 _atspi_dbus_call (obj, atspi_interface_text, "GetCharacterExtents", error, "iu=>iiii", d_offset, d_type, &d_x, &d_y, &d_width, &d_height);
517 ret.height = d_height;
518 return atspi_rect_copy (&ret);
522 * atspi_text_get_offset_at_point:
523 * @obj: a pointer to the #AtspiText object on which to operate.
524 * @x: the x coordinate of the point to be queried.
525 * @y: the y coordinate of the point to be queried.
526 * @type: an #AtspiCoordType indicating the coordinate system in which
527 * the values should be returned.
529 * Get the character offset into the text at a given point.
531 * Returns: the offset (as an integer) at the point (@x, @y)
532 * in the specified coordinate system.
536 atspi_text_get_offset_at_point (AtspiText *obj,
542 dbus_int32_t d_x = x, d_y = y;
543 dbus_uint32_t d_type = type;
544 dbus_int32_t retval = -1;
546 g_return_val_if_fail (obj != NULL, -1);
548 _atspi_dbus_call (obj, atspi_interface_text, "GetOffsetAtPoint", error, "iiu=>i", d_x, d_y, d_type, &retval);
554 * atspi_text_get_range_extents:
555 * @obj: a pointer to the #AtspiText object on which to operate.
556 * @start_offset: an integer indicating the offset of the first text character for
557 * whom boundary information is requested.
558 * @end_offset: an integer indicating the offset of the text character
559 * after the last character for whom boundary information is requested.
560 * @type: an #AtspiCoordType indicating the coordinate system to use
561 * for the returned values.
563 * Returns: A #AtspiRect giving the position and size of the specified range
566 * Get the bounding box for text within a range in an #AtspiText object.
569 atspi_text_get_range_extents (AtspiText *obj,
575 dbus_int32_t d_start_offset = start_offset, d_end_offset = end_offset;
576 dbus_uint32_t d_type = type;
577 dbus_int32_t d_x, d_y, d_width, d_height;
580 ret.x = ret.y = ret.width = ret.height = -1;
583 return atspi_rect_copy (&ret);
585 _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);
590 ret.height = d_height;
591 return atspi_rect_copy (&ret);
595 * atspi_text_get_bounded_ranges:
596 * @obj: a pointer to the #AtspiText object on which to operate.
597 * @x: the 'starting' x coordinate of the bounding box.
598 * @y: the 'starting' y coordinate of the bounding box.
599 * @width: the x extent of the bounding box.
600 * @height: the y extent of the bounding box.
601 * @type: an #AccessibleCoordType indicating the coordinate system to use
602 * for the returned values.
603 * @clipTypeX: an #AtspiTextClipType indicating how to treat characters that
604 * intersect the bounding box's x extents.
605 * @clipTypeY: an #AtspiTextClipType indicating how to treat characters that
606 * intersect the bounding box's y extents.
608 * Get the ranges of text from an #AtspiText object which lie within the
609 * bounds defined by (@x, @y) and (@x+@width, @y+@height).
611 * Returns: (transfer full) (element-type AtspiTextRange*): a null-terminated list of
612 * pointers to #AtspiTextRange structs detailing the bounded text.
615 atspi_text_get_bounded_ranges (AtspiText *obj,
621 AtspiTextClipType clipTypeX,
622 AtspiTextClipType clipTypeY,
625 dbus_int32_t d_x = x, d_y = y, d_width = width, d_height = height;
626 dbus_uint32_t d_type = type;
627 dbus_uint32_t d_clipTypeX = clipTypeX, d_clipTypeY = clipTypeY;
630 g_return_val_if_fail (obj != NULL, NULL);
632 _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);
638 * atspi_text_get_n_selections:
639 * @obj: a pointer to the #AtspiText object on which to operate.
641 * Get the number of active non-contiguous selections for an
644 * Returns: a long integer indicating the current
645 * number of non-contiguous text selections active
646 * within an #AtspiText object.
649 atspi_text_get_n_selections (AtspiText *obj, GError **error)
653 g_return_val_if_fail (obj != NULL, -1);
655 _atspi_dbus_call (obj, atspi_interface_text, "GetNSelections", error, "i", &retval);
661 * atspi_text_get_sSelection:
662 * @obj: a pointer to the #AtspiText object on which to operate.
663 * @selection_num: an integer indicating which selection to query.
664 * @start_offset: a pointer to a long integer into which the start offset
665 * of the selection will be returned.
666 * @end_offset: a pointer to a long integer into which the start offset
667 * of the selection will be returned.
669 * Get the bounds of the @selection_num-th active text selection for an
673 atspi_text_get_selection (AtspiText *obj,
677 dbus_int32_t d_selection_num = selection_num;
678 dbus_int32_t d_start_offset, d_end_offset;
679 AtspiRange *ret = g_new (AtspiRange, 1);
682 ret->start_offset = ret->end_offset = -1;
687 _atspi_dbus_call (obj, atspi_interface_text, "GetSelection", error, "i=>ii", d_selection_num, &d_start_offset, &d_end_offset);
689 ret->start_offset = d_start_offset;
690 ret->end_offset = d_end_offset;
695 * atspi_text_add_selection:
696 * @obj: a pointer to the #AtspiText object on which to operate.
697 * @start_offset: the starting offset of the desired new selection.
698 * @end_offset: the offset of the first character after the new selection.
700 * Select some text (add a text selection) in an #AtspiText object.
702 * Returns: #TRUE if successful, #FALSE otherwise.
705 atspi_text_add_selection (AtspiText *obj,
706 gint start_offset, gint end_offset,
709 dbus_int32_t d_start_offset = start_offset, d_end_offset = end_offset;
710 dbus_bool_t retval = FALSE;
712 _atspi_dbus_call (obj, atspi_interface_text, "AddSelection", error, "ii=>b", d_start_offset, d_end_offset, &retval);
718 * atspi_text_remove_selection:
719 * @obj: a pointer to the #AtspiText object on which to operate.
720 * @selection_num: an integer indicating which (possibly of several)
721 * text selection to remove.
723 * De-select a text selection.
725 * Returns: #TRUE if successful, #FALSE otherwise.
728 atspi_text_remove_selection (AtspiText *obj,
732 dbus_int32_t d_selection_num = selection_num;
733 dbus_bool_t retval = FALSE;
735 g_return_val_if_fail (obj != NULL, FALSE);
737 _atspi_dbus_call (obj, atspi_interface_text, "RemoveSelection", error, "i=>b", d_selection_num, &retval);
743 * atspi_text_set_selection:
744 * @obj: a pointer to the #AtspiText object on which to operate.
745 * @selection_num: a zero-offset index indicating which text selection to modify.
746 * @start_offset: a long int, the new starting offset for the selection.
747 * @end_offset: a long int, the desired new offset of the first character
748 * after the selection.
750 * Change the bounds of an existing #AtspiText text selection.
752 * Returns: #TRUE if successful, #FALSE otherwise.
755 atspi_text_set_selection (AtspiText *obj,
761 dbus_int32_t d_selection_num = selection_num, d_start_offset = start_offset, d_end_offset = end_offset;
762 dbus_bool_t retval = FALSE;
764 g_return_val_if_fail (obj != NULL, FALSE);
766 _atspi_dbus_call (obj, atspi_interface_text, "SetSelection", error, "iii=>b", d_selection_num, d_start_offset, d_end_offset, &retval);
772 atspi_text_base_init (AtspiText *klass)
777 atspi_text_get_type (void)
779 static GType type = 0;
782 static const GTypeInfo tinfo =
785 (GBaseInitFunc) atspi_text_base_init,
786 (GBaseFinalizeFunc) NULL,
789 type = g_type_register_static (G_TYPE_INTERFACE, "AtspiText", &tinfo, 0);