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,
106 dbus_int32_t d_start_offset = start_offset, d_end_offset = end_offset;
108 g_return_val_if_fail (obj != NULL, NULL);
110 _atspi_dbus_call (obj, atspi_interface_text, "GetText", error, "ii=>s", start_offset, end_offset, &retval);
116 * atspi_text_get_caret_offset:
117 * @obj: a pointer to the #AtspiText object to query.
119 * Get the current offset of the text caret in an #AtspiText object.
121 * Returns: a long integer indicating the current position of the text caret.
124 atspi_text_get_caret_offset (AtspiText *obj, GError **error)
126 dbus_int32_t retval = -1;
128 g_return_val_if_fail (obj != NULL, -1);
130 _atspi_dbus_get_property (obj, atspi_interface_text, "CaretOffset", error, "i", &retval);
136 * atspi_text_get_attributes:
137 * @obj: a pointer to the #AtspiText object to query.
138 * @offset: a long integer indicating the offset from which the attribute
140 * @start_offset: (out): a #gint indicating the start of the desired text
142 * @end_offset: (out): a #gint indicating the first character past the desired
145 * Get the attributes applied to a range of text from an #AtspiText
146 * object, and the bounds of the range.
147 * The text attributes correspond to CSS attributes where possible,
149 * Returns: (element-type gchar* gchar*) (transfer full): a #GHashTable
150 * describing the attributes at the given character offset
153 atspi_text_get_attributes (AtspiText *obj,
159 dbus_int32_t d_offset = offset;
160 dbus_int32_t d_start_offset, d_end_offset;
163 DBusMessageIter iter;
169 reply = _atspi_dbus_call_partial (obj, atspi_interface_text, "GetAttributes", error, "i", d_offset);
170 _ATSPI_DBUS_CHECK_SIG (reply, "a{ss}ii", ret)
172 dbus_message_iter_init (reply, &iter);
173 ret = _atspi_dbus_hash_from_iter (&iter);
174 dbus_message_iter_next (&iter);
176 dbus_message_iter_get_basic (&iter, &d_start_offset);
178 *start_offset = d_start_offset;
179 dbus_message_iter_next (&iter);
180 dbus_message_iter_get_basic (&iter, &d_end_offset);
182 *end_offset = d_start_offset;
184 dbus_message_unref (reply);
189 * atspi_text_get_attribute_run:
190 * @obj: a pointer to the #AtspiText object to query.
191 * @offset: an integer indicating the offset from which the attribute
193 * @include_defaults: a #bool if False, the call should only return those
194 * attributes which are explicitly set on the current attribute
195 * run, omitting any attributes which are inherited from the
197 * @start_offset: (out): a #gint indicating the start of the desired text
199 * @end_offset: (out): a #gint indicating the first character past the desired
202 * Returns: (element-type gchar* gchar*) (transfer full): the AttributeSet
203 * defined at offset, optionally including the 'default' attributes.
206 atspi_text_get_attribute_run (AtspiText *obj,
208 gboolean include_defaults,
213 dbus_int32_t d_offset = offset;
214 dbus_int32_t d_start_offset, d_end_offset;
217 DBusMessageIter iter;
223 reply = _atspi_dbus_call_partial (obj, atspi_interface_text,
224 "GetAttributeRun", error, "ib", d_offset,
226 _ATSPI_DBUS_CHECK_SIG (reply, "a{ss}ii", ret)
228 dbus_message_iter_init (reply, &iter);
229 ret = _atspi_dbus_hash_from_iter (&iter);
230 dbus_message_iter_next (&iter);
232 dbus_message_iter_get_basic (&iter, &d_start_offset);
234 *start_offset = d_start_offset;
235 dbus_message_iter_next (&iter);
236 dbus_message_iter_get_basic (&iter, &d_end_offset);
238 *end_offset = d_end_offset;
240 dbus_message_unref (reply);
245 * atspi_text_get_attribute_value:
246 * @obj: a pointer to the #AtspiText object to query.
247 * @offset: The character offset at which to query the attribute.
248 * @attribute_name: The attribute to query.
250 * Returns: the value of a given attribute at the given offset, or NULL if
254 atspi_text_get_attribute_value (AtspiText *obj,
256 gchar *attribute_value,
259 gchar *retval = NULL;
261 g_return_val_if_fail (obj != NULL, NULL);
263 _atspi_dbus_call (obj, atspi_interface_text, "GetAttributeValue", error, "i=>s", offset, &retval);
269 * atspi_text_get_default_attributes:
270 * @obj: a pointer to the #AtspiText object to query.
272 * Get the default attributes applied to an #AtspiText
274 * The text attributes correspond to CSS attributes where possible,
275 * keys and values are delimited from one another via ":", and
276 * the delimiter between key/value pairs is ";". Thus
277 * "font-size:10;foreground-color:0,0,0" would be a valid
278 * return string. The combination of this attribute set and
279 * the attributes reported by #atspi_text_getAttributes
280 * describes the entire set of text attributes over a range.
282 * Returns: (element-type gchar* gchar*) (transfer full): a #GHashTable
283 * containing the default attributes applied to a text object,
284 * (exclusive of explicitly-set attributes), encoded as UTF-8.
287 atspi_text_get_default_attributes (AtspiText *obj, GError **error)
291 g_return_val_if_fail (obj != NULL, NULL);
293 reply = _atspi_dbus_call_partial (obj, atspi_interface_text, "GetDefaultAttributes", error, "");
294 return _atspi_dbus_return_hash_from_message (reply);
299 * atspi_text_set_caret_offset:
300 * @obj: a pointer to the #AtspiText object on which to operate.
301 * @new_offset: the offset to which the text caret is to be moved.
303 * Set the text caret position for an #AtspiText object.
305 * Returns: #TRUE if successful, #FALSE otherwise.
308 atspi_text_set_caret_offset (AtspiText *obj,
312 dbus_int32_t d_new_offset = new_offset;
313 dbus_bool_t retval = FALSE;
315 g_return_val_if_fail (obj != NULL, FALSE);
317 _atspi_dbus_call (obj, atspi_interface_text, "SetCaretOffset", error, "i=>b", d_new_offset, &retval);
323 * atspi_text_get_text_before_offset:
324 * @obj: a pointer to the #AtspiText object on which to operate.
325 * @offset: an integer indicating the offset from which the delimiter
327 * @type: an #AtspiTextBoundaryType indicating whether the desired
328 * text string is a word, sentence, line, or attribute run.
330 * Get delimited text from an #AtspiText object which precedes a given
333 * Returns: an #AtspiTextRange containing a UTF-8 string representing the
334 * delimited text, both of whose delimiting boundaries are before the
335 * current offset, or an empty string if no such text exists.
338 atspi_text_get_text_before_offset (AtspiText *obj,
340 AtspiTextBoundaryType type,
343 dbus_int32_t d_offset = offset;
344 dbus_uint32_t d_type = type;
345 dbus_int32_t d_start_offset = -1, d_end_offset = -1;
346 AtspiTextRange *range = g_new0 (AtspiTextRange, 1);
349 range->start_offset = range->end_offset = -1;
353 _atspi_dbus_call (obj, atspi_interface_text, "GetTextBeforeOffset", error,
354 "iu=>sii", d_offset, d_type, &range->content,
355 &d_start_offset, &d_end_offset);
357 range->start_offset = d_start_offset;
358 range->end_offset = d_end_offset;
364 * atspi_text_get_text_at_offset:
365 * @obj: a pointer to the #AtspiText object on which to operate.
366 * @offset: a long integer indicating the offset from which the delimiter
368 * @type: an #AtspiTextBoundaryType indicating whether the desired
369 * text string is a word, sentence, line, or attribute run.
371 * Get delimited text from an #AtspiText object which includes a given
374 * Returns: an #AtspiTextRange containing a UTF-8 string representing the
375 * delimited text, whose delimiting boundaries bracket the
376 * current offset, or an empty string if no such text exists.
379 atspi_text_get_text_at_offset (AtspiText *obj,
381 AtspiTextBoundaryType type,
384 dbus_int32_t d_offset = offset;
385 dbus_uint32_t d_type = type;
386 dbus_int32_t d_start_offset = -1, d_end_offset = -1;
387 AtspiTextRange *range = g_new0 (AtspiTextRange, 1);
390 range->start_offset = range->end_offset = -1;
394 _atspi_dbus_call (obj, atspi_interface_text, "GetTextAtOffset", error,
395 "iu=>sii", d_offset, d_type, &range->content,
396 &d_start_offset, &d_end_offset);
398 range->start_offset = d_start_offset;
399 range->end_offset = d_end_offset;
405 * atspi_text_get_text_after_offset:
406 * @obj: a pointer to the #AtspiText object on which to operate.
407 * @offset: an integer indicating the offset from which the delimiter
409 * @type: an #AtspiTextBoundaryType indicating whether the desired
410 * text string is a word, sentence, line, or attribute run.
412 * Get delimited text from an #AtspiText object which follows a given
415 * Returns: an #AtspiTextRange containing a UTF-8 string representing the
416 * delimited text, both of whose delimiting boundaries are after or
417 * inclusive of the current offset, or an empty string if no such
421 atspi_text_get_text_after_offset (AtspiText *obj,
423 AtspiTextBoundaryType type,
426 dbus_int32_t d_offset = offset;
427 dbus_uint32_t d_type = type;
428 dbus_int32_t d_start_offset = -1, d_end_offset = -1;
429 AtspiTextRange *range = g_new0 (AtspiTextRange, 1);
432 range->start_offset = range->end_offset = -1;
436 _atspi_dbus_call (obj, atspi_interface_text, "GetTextAfterOffset", error,
437 "iu=>sii", d_offset, d_type, &range->content,
438 &d_start_offset, &d_end_offset);
440 range->start_offset = d_start_offset;
441 range->end_offset = d_end_offset;
447 * atspi_text_get_character_at_offset:
448 * @obj: a pointer to the #AtspiText object on which to operate.
449 * @offset: a long integer indicating the text offset where the desired
450 * character is located.
452 * Get the character at a given offset for an #AtspiText object.
454 * Returns: an #unsigned long integer which represents the
455 * UCS-4 unicode code point of the given character, or
456 * 0xFFFFFFFF if the character in question cannot be represented
457 * in the UCS-4 encoding.
460 atspi_text_get_character_at_offset (AtspiText *obj,
464 dbus_int32_t d_offset = offset;
465 dbus_int32_t retval = -1;
467 g_return_val_if_fail (obj != NULL, -1);
469 _atspi_dbus_call (obj, atspi_interface_text, "GetCharacterAtOffset", error, "i=>i", d_offset, &retval);
475 * atspi_text_get_character_extents:
476 * @obj: a pointer to the #AtspiText object on which to operate.
477 * @offset: an integer indicating the offset of the text character for
478 * whom boundary information is requested.
479 * @type: an #AccessibleCoordType indicating the coordinate system to use
480 * for the returned values.
482 * Returns: A #AtspiRect specifying the position and size of the character.
484 * Get the bounding box containing the glyph representing
485 * the character at a particular text offset.
488 atspi_text_get_character_extents (AtspiText *obj,
493 dbus_int32_t d_offset = offset;
494 dbus_uint32_t d_type = type;
495 dbus_int32_t d_x, d_y, d_width, d_height;
498 ret.x = ret.y = ret.width = ret.height = -1;
501 return atspi_rect_copy (&ret);
503 _atspi_dbus_call (obj, atspi_interface_text, "GetCharacterExtents", error, "iu=>iiii", d_offset, d_type, &d_x, &d_y, &d_width, &d_height);
508 ret.height = d_height;
509 return atspi_rect_copy (&ret);
513 * atspi_text_get_offset_at_point:
514 * @obj: a pointer to the #AtspiText object on which to operate.
515 * @x: the x coordinate of the point to be queried.
516 * @y: the y coordinate of the point to be queried.
517 * @type: an #AtspiCoordType indicating the coordinate system in which
518 * the values should be returned.
520 * Get the character offset into the text at a given point.
522 * Returns: the offset (as an integer) at the point (@x, @y)
523 * in the specified coordinate system.
527 atspi_text_get_offset_at_point (AtspiText *obj,
533 dbus_int32_t d_x = x, d_y = y;
534 dbus_uint16_t d_type = type;
535 dbus_int32_t retval = -1;
537 g_return_val_if_fail (obj != NULL, -1);
539 _atspi_dbus_call (obj, atspi_interface_text, "GetOffsetAtPoint", error, "iin=>i", d_x, d_y, d_type, &retval);
545 * atspi_text_get_range_extents:
546 * @obj: a pointer to the #AtspiText object on which to operate.
547 * @start_offset: an integer indicating the offset of the first text character for
548 * whom boundary information is requested.
549 * @end_offset: an integer indicating the offset of the text character
550 * after the last character for whom boundary information is requested.
551 * @type: an #AtspiCoordType indicating the coordinate system to use
552 * for the returned values.
554 * Returns: A #AtspiRect giving the position and size of the specified range
557 * Get the bounding box for text within a range in an #AtspiText object.
560 atspi_text_get_range_extents (AtspiText *obj,
566 dbus_int32_t d_start_offset = start_offset, d_end_offset = end_offset;
567 dbus_int16_t d_type = type;
568 dbus_int32_t d_x, d_y, d_width, d_height;
571 ret.x = ret.y = ret.width = ret.height = -1;
574 return atspi_rect_copy (&ret);
576 _atspi_dbus_call (obj, atspi_interface_text, "GetRangeExtents", error, "iin=>iiii", d_start_offset, d_end_offset, d_type, &d_x, &d_y, &d_width, &d_height);
581 ret.height = d_height;
582 return atspi_rect_copy (&ret);
586 * atspi_text_get_bounded_ranges:
587 * @obj: a pointer to the #AtspiText object on which to operate.
588 * @x: the 'starting' x coordinate of the bounding box.
589 * @y: the 'starting' y coordinate of the bounding box.
590 * @width: the x extent of the bounding box.
591 * @height: the y extent of the bounding box.
592 * @type: an #AccessibleCoordType indicating the coordinate system to use
593 * for the returned values.
594 * @clipTypeX: an #AtspiTextClipType indicating how to treat characters that
595 * intersect the bounding box's x extents.
596 * @clipTypeY: an #AtspiTextClipType indicating how to treat characters that
597 * intersect the bounding box's y extents.
599 * Get the ranges of text from an #AtspiText object which lie within the
600 * bounds defined by (@x, @y) and (@x+@width, @y+@height).
602 * Returns: (transfer full) (element-type AtspiTextRange*): a null-terminated list of
603 * pointers to #AtspiTextRange structs detailing the bounded text.
606 atspi_text_get_bounded_ranges (AtspiText *obj,
612 AtspiTextClipType clipTypeX,
613 AtspiTextClipType clipTypeY,
616 dbus_int32_t d_x = x, d_y = y, d_width = width, d_height = height;
617 dbus_uint32_t d_type = type;
618 dbus_uint32_t d_clipTypeX = clipTypeX, d_clipTypeY = clipTypeY;
621 g_return_val_if_fail (obj != NULL, NULL);
623 _atspi_dbus_call (obj, atspi_interface_text, "GetBoundedRanges", error, "iiiinuu=>a(iisv)", d_x, d_y, d_width, d_height, d_type, d_clipTypeX, d_clipTypeY, &range_seq);
629 * atspi_text_get_n_selections:
630 * @obj: a pointer to the #AtspiText object on which to operate.
632 * Get the number of active non-contiguous selections for an
635 * Returns: a long integer indicating the current
636 * number of non-contiguous text selections active
637 * within an #AtspiText object.
640 atspi_text_get_n_selections (AtspiText *obj, GError **error)
644 g_return_val_if_fail (obj != NULL, -1);
646 _atspi_dbus_call (obj, atspi_interface_text, "GetNSelections", error, "i", &retval);
652 * atspi_text_get_sSelection:
653 * @obj: a pointer to the #AtspiText object on which to operate.
654 * @selection_num: an integer indicating which selection to query.
655 * @start_offset: a pointer to a long integer into which the start offset
656 * of the selection will be returned.
657 * @end_offset: a pointer to a long integer into which the start offset
658 * of the selection will be returned.
660 * Get the bounds of the @selection_num-th active text selection for an
664 atspi_text_get_selection (AtspiText *obj,
668 dbus_int32_t d_selection_num = selection_num;
669 dbus_int32_t d_start_offset, d_end_offset;
670 AtspiRange *ret = g_new (AtspiRange, 1);
673 ret->start_offset = ret->end_offset = -1;
678 _atspi_dbus_call (obj, atspi_interface_text, "GetSelection", error, "i=>ii", d_selection_num, &d_start_offset, &d_end_offset);
680 ret->start_offset = d_start_offset;
681 ret->end_offset = d_end_offset;
686 * atspi_text_add_selection:
687 * @obj: a pointer to the #AtspiText object on which to operate.
688 * @start_offset: the starting offset of the desired new selection.
689 * @end_offset: the offset of the first character after the new selection.
691 * Select some text (add a text selection) in an #AtspiText object.
693 * Returns: #TRUE if successful, #FALSE otherwise.
696 atspi_text_add_selection (AtspiText *obj,
697 gint start_offset, gint end_offset,
700 dbus_int32_t d_start_offset = start_offset, d_end_offset = end_offset;
701 dbus_bool_t retval = FALSE;
703 _atspi_dbus_call (obj, atspi_interface_text, "AddSelection", error, "ii=>b", d_start_offset, d_end_offset, &retval);
709 * atspi_text_remove_selection:
710 * @obj: a pointer to the #AtspiText object on which to operate.
711 * @selection_num: an integer indicating which (possibly of several)
712 * text selection to remove.
714 * De-select a text selection.
716 * Returns: #TRUE if successful, #FALSE otherwise.
719 atspi_text_remove_selection (AtspiText *obj,
723 dbus_int32_t d_selection_num = selection_num;
724 dbus_bool_t retval = FALSE;
726 g_return_val_if_fail (obj != NULL, FALSE);
728 _atspi_dbus_call (obj, atspi_interface_text, "RemoveSelection", error, "i=>b", d_selection_num, &retval);
734 * atspi_text_set_selection:
735 * @obj: a pointer to the #AtspiText object on which to operate.
736 * @selection_num: a zero-offset index indicating which text selection to modify.
737 * @start_offset: a long int, the new starting offset for the selection.
738 * @end_offset: a long int, the desired new offset of the first character
739 * after the selection.
741 * Change the bounds of an existing #AtspiText text selection.
743 * Returns: #TRUE if successful, #FALSE otherwise.
746 atspi_text_set_selection (AtspiText *obj,
752 dbus_int32_t d_selection_num = selection_num, d_start_offset = start_offset, d_end_offset = end_offset;
753 dbus_bool_t retval = FALSE;
755 g_return_val_if_fail (obj != NULL, FALSE);
757 _atspi_dbus_call (obj, atspi_interface_text, "SetSelection", error, "iii=>b", d_selection_num, d_start_offset, d_end_offset, &retval);
763 atspi_text_base_init (AtspiText *klass)
768 atspi_text_get_type (void)
770 static GType type = 0;
773 static const GTypeInfo tinfo =
776 (GBaseInitFunc) atspi_text_base_init,
777 (GBaseFinalizeFunc) NULL,
780 type = g_type_register_static (G_TYPE_INTERFACE, "AtspiText", &tinfo, 0);