Add first pass at text interface
authorMike Gorse <mgorse@novell.com>
Fri, 19 Nov 2010 05:06:37 +0000 (00:06 -0500)
committerMike Gorse <mgorse@novell.com>
Fri, 19 Nov 2010 05:06:37 +0000 (00:06 -0500)
atspi/Makefile.am
atspi/atspi-accessible.c
atspi/atspi-accessible.h
atspi/atspi-component.c
atspi/atspi-component.h
atspi/atspi-misc-private.h
atspi/atspi-misc.c
atspi/atspi-text.c [new file with mode: 0644]
atspi/atspi-text.h [new file with mode: 0644]
atspi/atspi-types.h
atspi/atspi.h

index 75ec719..fc8e401 100644 (file)
@@ -35,6 +35,8 @@ libatspi_la_SOURCES =         \
        atspi-registry.h \
        atspi-stateset.c \
        atspi-stateset.h \
+       atspi-text.c \
+       atspi-text.h \
        atspi-types.h
 
 #BUILT_SOURCES = atspi-constants.h
index 3e2bcb9..4dae651 100644 (file)
@@ -811,10 +811,10 @@ atspi_accessible_get_collection (AtspiAccessible *accessible)
  *          instance, or NULL if @obj does not implement #AtspiComponent.
  **/
 AtspiComponent *
-atspi_accessible_get_component (AtspiAccessible *accessible)
+atspi_accessible_get_component (AtspiAccessible *obj)
 {
-  return (_atspi_accessible_is_a (accessible, atspi_interface_component) ?
-          ATSPI_COMPONENT (accessible) : NULL);  
+  return (_atspi_accessible_is_a (obj, atspi_interface_component) ?
+          g_object_ref (ATSPI_COMPONENT (obj)) : NULL);
 }
 
 #if 0
@@ -929,6 +929,7 @@ atspi_accessible_get_table (AtspiAccessible *accessible)
   return (_atspi_accessible_is_a (accessible, atspi_interface_table) ?
           accessible : NULL);  
 }
+#endif
 
 /**
  * atspi_accessible_get_text:
@@ -936,16 +937,17 @@ atspi_accessible_get_table (AtspiAccessible *accessible)
  *
  * Get the #AtspiTable interface for an #AtspiAccessible.
  *
- * Returns: a pointer to an #AtspiTable interface instance, or
+ * Returns: (transfer full): a pointer to an #AtspiText interface instance, or
  *          NULL if @obj does not implement #AtspiTable.
  **/
-AtspiTable *
-atspi_accessible_get_text (AtspiAccessible *accessible)
+AtspiText *
+atspi_accessible_get_text (AtspiAccessible *obj)
 {
-  return (_atspi_accessible_is_a (accessible, atspi_interface_text) ?
-          accessible : NULL);  
+  return (_atspi_accessible_is_a (obj, atspi_interface_text) ?
+          g_object_ref (ATSPI_TEXT (obj)) : NULL);
 }
 
+#if 0
 /**
  * atspi_accessible_get_value:
  * @obj: a pointer to the #AtspiAccessible instance to query.
index ee9a776..8d70707 100644 (file)
@@ -95,5 +95,7 @@ GArray * atspi_accessible_get_attributes_as_array (AtspiAccessible *obj, GError
 
 AtspiAccessible * atspi_accessible_get_host_application (AtspiAccessible *obj, GError **error);
 
-AtspiComponent * atspi_accessible_get_component (AtspiAccessible *accessible);
+AtspiComponent * atspi_accessible_get_component (AtspiAccessible *obj);
+
+AtspiText * atspi_accessible_get_text (AtspiAccessible *obj);
 #endif /* _ATSPI_ACCESSIBLE_H_ */
index ca01586..ae51c34 100644 (file)
@@ -35,7 +35,7 @@ atspi_rect_free (AtspiRect *rect)
   g_free (rect);
 }
 
-static AtspiRect *
+AtspiRect *
 atspi_rect_copy (AtspiRect *src)
 {
   AtspiRect *dst = g_new (AtspiRect, 1);
index 1a0d5bd..257f3c3 100644 (file)
@@ -49,6 +49,8 @@ struct _AtspiRect
 
 GType atspi_rect_get_type ();
 
+AtspiRect *atspi_rect_copy (AtspiRect *src);
+
 typedef struct _AtspiPoint AtspiPoint;
 struct _AtspiPoint
 {
index 5440d47..6df407c 100644 (file)
@@ -127,5 +127,21 @@ DBusMessage * _atspi_dbus_send_with_reply_and_block (DBusMessage *message);
 
 GHashTable *_atspi_dbus_hash_from_message (DBusMessage *message);
 
+GHashTable *_atspi_dbus_hash_from_iter (DBusMessageIter *iter);
+
 GArray *_atspi_dbus_attribute_array_from_message (DBusMessage *message);
+
+GArray *_atspi_dbus_attribute_array_from_iter (DBusMessageIter *iter);
+
+#define _ATSPI_DBUS_CHECK_SIG(message, type, ret) \
+  if (!message) { \
+    g_warning ("at-spi: Got no message at %s line %d\n", __FILE__, __LINE__); \
+    return (ret); \
+  } \
+  if (strcmp (dbus_message_get_signature (message), type) != 0) \
+  { \
+    g_warning ("at-spi: Expected message signature %s but got %s at %s line %d", type, dbus_message_get_signature (message), __FILE__, __LINE__); \
+    dbus_message_unref (message); \
+    return (ret); \
+  }
 #endif /* _ATSPI_MISC_PRIVATE_H_ */
index 440c9d9..1dbd6fd 100644 (file)
@@ -869,7 +869,7 @@ _atspi_dbus_call_partial (gpointer obj, const char *interface, const char *metho
 
     p = type;
     dbus_message_iter_init_append (msg, &iter);
-    dbind_any_marshal_va (&iter, &p, args);
+    dbind_any_marshal_va (&iter, &p, &args);
 
     reply = dbind_send_and_allow_reentry (_atspi_bus(), msg, &err);
 out:
@@ -938,8 +938,7 @@ _atspi_dbus_send_with_reply_and_block (DBusMessage *message)
 GHashTable *
 _atspi_dbus_hash_from_message (DBusMessage *message)
 {
-  GHashTable *hash = g_hash_table_new (g_str_hash, g_str_equal);
-  DBusMessageIter iter, iter_array, iter_dict;
+  DBusMessageIter iter;
   const char *signature;
 
   signature = dbus_message_get_signature (message);
@@ -951,7 +950,16 @@ _atspi_dbus_hash_from_message (DBusMessage *message)
     }
 
   dbus_message_iter_init (message, &iter);
-  dbus_message_iter_recurse (&iter, &iter_array);
+  return _atspi_dbus_hash_from_iter (&iter);
+}
+
+GHashTable *
+_atspi_dbus_hash_from_iter (DBusMessageIter *iter)
+{
+  GHashTable *hash = g_hash_table_new (g_str_hash, g_str_equal);
+  DBusMessageIter iter_array, iter_dict;
+
+  dbus_message_iter_recurse (iter, &iter_array);
   while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
   {
     const char *name, *value;
@@ -967,10 +975,8 @@ _atspi_dbus_hash_from_message (DBusMessage *message)
 GArray *
 _atspi_dbus_attribute_array_from_message (DBusMessage *message)
 {
-  GArray *array = g_array_new (TRUE, TRUE, sizeof (gchar *));
-  DBusMessageIter iter, iter_array, iter_dict;
+  DBusMessageIter iter;
   const char *signature;
-  gint count = 0;
 
   signature = dbus_message_get_signature (message);
 
@@ -980,9 +986,17 @@ _atspi_dbus_attribute_array_from_message (DBusMessage *message)
       return NULL;
     }
 
-  dbus_message_iter_init (message, &iter);
+  return _atspi_dbus_attribute_array_from_iter (&iter);
+}
 
-  dbus_message_iter_recurse (&iter, &iter_array);
+GArray *
+_atspi_dbus_attribute_array_from_iter (DBusMessageIter *iter)
+{
+  DBusMessageIter iter_array, iter_dict;
+  GArray *array = g_array_new (TRUE, TRUE, sizeof (gchar *));
+  gint count = 0;
+
+  dbus_message_iter_recurse (iter, &iter_array);
   while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
   {
     const char *name, *value;
@@ -995,7 +1009,7 @@ _atspi_dbus_attribute_array_from_message (DBusMessage *message)
     new_array = g_array_append_val (array, str);
     if (new_array)
       array = new_array;
-    dbus_message_iter_next (&iter);;
+    dbus_message_iter_next (iter);;
   }
   return array;
 }
diff --git a/atspi/atspi-text.c b/atspi/atspi-text.c
new file mode 100644 (file)
index 0000000..914bee9
--- /dev/null
@@ -0,0 +1,803 @@
+/*
+ * AT-SPI - Assistive Technology Service Provider Interface
+ * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
+ *
+ * Copyright 2001, 2002 Sun Microsystems Inc.,
+ * Copyright 2001, 2002 Ximian, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "atspi-private.h"
+
+static AtspiRange *
+atspi_range_copy (AtspiRange *src)
+{
+  AtspiRange *dst = g_new (AtspiRange, 1);
+
+  if (dst)
+  {
+    dst->start_offset = src->start_offset;
+    dst->end_offset = src->end_offset;
+  }
+  return dst;
+}
+
+G_DEFINE_BOXED_TYPE (AtspiRange, atspi_range, atspi_range_copy, g_free)
+
+static AtspiRangedAttributeSet *
+atspi_ranged_attribute_set_copy (AtspiRangedAttributeSet *src)
+{
+  AtspiRangedAttributeSet *dst = g_new (AtspiRangedAttributeSet, 1);
+
+  if (dst)
+  {
+    dst->attributes = g_object_ref (src->attributes);
+    dst->start_offset = src->start_offset;
+    dst->end_offset = src->end_offset;
+  }
+  return dst;
+}
+
+static void
+atspi_ranged_attribute_set_free (AtspiRangedAttributeSet *set)
+{
+  g_object_unref (set->attributes);
+  g_free (set);
+}
+
+G_DEFINE_BOXED_TYPE (AtspiRangedAttributeSet, atspi_ranged_attribute_set,
+                    atspi_ranged_attribute_set_copy,
+                    atspi_ranged_attribute_set_free)
+
+static AtspiTextRange *
+atspi_text_range_copy (AtspiTextRange *src)
+{
+  AtspiTextRange *dst = g_new (AtspiTextRange, 1);
+
+  if (dst)
+  {
+    dst->text = g_strdup (src->text);
+    dst->start_offset = src->start_offset;
+    dst->end_offset = src->end_offset;
+  }
+  return dst;
+}
+
+static void
+atspi_text_range_free (AtspiTextRange *range)
+{
+  g_free (range->text);
+  g_free (range);
+}
+
+G_DEFINE_BOXED_TYPE (AtspiTextRange, atspi_text_range, atspi_text_range_copy,
+                     atspi_text_range_free)
+
+/**
+ * atspi_text_get_character_count:
+ * @obj: a pointer to the #AtspiText object to query.
+ *
+ * Get the character count of an #AccessibleText object.
+ *
+ * Returns: a long integer indicating the total number of
+ *              characters in the #AccessibleText object.
+ **/
+gint
+atspi_text_get_character_count (AtspiText *obj, GError **error)
+{
+  dbus_int32_t retval;
+
+  g_return_val_if_fail (obj != NULL, -1);
+
+  _atspi_dbus_get_property (obj, atspi_interface_text, "CharacterCount", error, "i", &retval);
+
+  return retval;
+}
+
+/**
+ * atspi_text_get_text:
+ * @obj: a pointer to the #AtspiText object to query.
+ * @start_offset: a #long indicating the start of the desired text range.
+ * @end_offset: a #long indicating the first character past the desired range.
+ *
+ * Get a range of text from an #AtspiText object.  The number of bytes
+ *          in the returned string may exceed end_offset-start_offset, since
+ *          UTF-8 is a variable-width encoding.
+ *
+ * Returns: a text string containing characters from @start_offset
+ *          to @end_offset-1, inclusive, encoded as UTF-8.
+ **/
+gchar *
+atspi_text_get_text (AtspiText *obj,
+                        gint start_offset,
+                        gint end_offset,
+                        GError **error)
+{
+  gchar *retval;
+  dbus_int32_t d_start_offset = start_offset, d_end_offset = end_offset;
+
+  g_return_val_if_fail (obj != NULL, NULL);
+
+  _atspi_dbus_call (obj, atspi_interface_text, "GetText", error, "ii=>s", start_offset, end_offset, &retval);
+
+  return retval;
+}
+
+/**
+ * atspi_text_get_caret_offset:
+ * @obj: a pointer to the #AtspiText object to query.
+ *
+ * Get the current offset of the text caret in an #AtspiText object.
+ *
+ * Returns: a long integer indicating the current position of the text caret.
+ **/
+gint
+atspi_text_get_caret_offset (AtspiText *obj, GError **error)
+{
+  dbus_int32_t retval = -1;
+
+  g_return_val_if_fail (obj != NULL, -1);
+
+  _atspi_dbus_get_property (obj, atspi_interface_text, "CaretOffset", error, "i", &retval);
+
+  return retval;
+}
+
+/**
+ * atspi_text_get_attributes:
+ * @obj: a pointer to the #AtspiText object to query.
+ * @offset: a long integer indicating the offset from which the attribute
+ *        search is based.
+ *
+ * Get the attributes applied to a range of text from an #AtspiText
+ *          object, and the bounds of the range.
+ *          The text attributes correspond to CSS attributes where possible,
+ *
+ * Returns: an #AtspiRangedAttributeSet describing the attributes at the
+ * given character offset
+ **/
+AtspiRangedAttributeSet *
+atspi_text_get_attributes (AtspiText *obj,
+                             gint offset,
+                             GError **error)
+{
+  dbus_int32_t d_offset = offset;
+  dbus_int32_t d_start_offset, d_end_offset;
+  GHashTable *hash;
+  DBusMessage *reply;
+  DBusMessageIter iter;
+  AtspiRangedAttributeSet *ret = g_new0 (AtspiRangedAttributeSet, 1);
+
+  if (!ret)
+    return NULL;
+  ret->start_offset = ret->end_offset = -1;
+
+  if (obj == NULL)
+   return ret;
+
+  reply = _atspi_dbus_call_partial (obj, atspi_interface_text, "GetAttributes", error, "i", d_offset);
+  _ATSPI_DBUS_CHECK_SIG (reply, "{ss}ii", ret)
+
+  dbus_message_iter_init (reply, &iter);
+  ret->attributes = _atspi_dbus_hash_from_iter (&iter);
+  dbus_message_iter_next (&iter);
+
+  dbus_message_iter_get_basic (&iter, &d_start_offset);
+  ret->start_offset = d_start_offset;
+  dbus_message_iter_next (&iter);
+  dbus_message_iter_get_basic (&iter, &d_end_offset);
+  ret->end_offset = d_end_offset;
+
+  dbus_message_unref (reply);
+  return ret;
+}
+
+/**
+ * atspi_text_get_attribute_run:
+ * @obj: a pointer to the #AtspiText object to query.
+ * @offset: an integer indicating the offset from which the attribute
+ *        search is based.
+ * @include_defaults: a #bool if False, the call should only return those 
+ *                 attributes which are explicitly set on the current attribute 
+ *                 run, omitting any attributes which are inherited from the 
+ *                 default values.
+ *
+ * Returns: the AttributeSet defined at offset, optionally including the 'default' attributes.
+ **/
+AtspiRangedAttributeSet *
+atspi_text_get_attribute_run (AtspiText *obj,
+                             gint offset,
+                             gboolean include_defaults,
+                             GError **error)
+{
+  dbus_int32_t d_offset = offset;
+  dbus_int32_t d_start_offset, d_end_offset;
+  GHashTable *hash;
+  DBusMessage *reply;
+  DBusMessageIter iter;
+  AtspiRangedAttributeSet *ret = g_new0 (AtspiRangedAttributeSet, 1);
+
+  if (!ret)
+    return NULL;
+  ret->start_offset = ret->end_offset = -1;
+
+  if (obj == NULL)
+   return ret;
+
+  reply = _atspi_dbus_call_partial (obj, atspi_interface_text,
+                                    "GetAttributeRun", error, "ib", d_offset,
+                                    include_defaults);
+  _ATSPI_DBUS_CHECK_SIG (reply, "{ss}ii", ret)
+
+  dbus_message_iter_init (reply, &iter);
+  ret->attributes = _atspi_dbus_hash_from_iter (&iter);
+  dbus_message_iter_next (&iter);
+
+  dbus_message_iter_get_basic (&iter, &d_start_offset);
+  ret->start_offset = d_start_offset;
+  dbus_message_iter_next (&iter);
+  dbus_message_iter_get_basic (&iter, &d_end_offset);
+  ret->end_offset = d_end_offset;
+
+  dbus_message_unref (reply);
+  return ret;
+}
+
+/**
+ * atspi_text_get_attribute_value:
+ * @obj: a pointer to the #AtspiText object to query.
+ * @offset: The character offset at which to query the attribute.
+ * @attribute_name: The attribute to query.
+ *
+ * Returns: the value of a given attribute at the given offset, or NULL if
+ *          not present.
+ **/
+gchar *
+atspi_text_get_attribute_value (AtspiText *obj,
+                                gint offset,
+                                gchar *attribute_value,
+                                GError **error)
+{
+  gchar *retval = NULL;
+
+  g_return_val_if_fail (obj != NULL, NULL);
+
+  _atspi_dbus_call (obj, atspi_interface_text, "GetAttributeValue", error, "i=>s", offset, &retval);
+
+  return retval;
+}
+
+/**
+ * atspi_text_get_default_attributes:
+ * @obj: a pointer to the #AtspiText object to query.
+ *
+ * Get the default attributes applied to an #AtspiText
+ *          object.
+ *          The text attributes correspond to CSS attributes where possible,
+ *          keys and values are delimited from one another via ":", and
+ *          the delimiter between key/value pairs is ";". Thus
+ *          "font-size:10;foreground-color:0,0,0" would be a valid
+ *          return string.  The combination of this attribute set and
+ *          the attributes reported by #atspi_text_getAttributes
+ *          describes the entire set of text attributes over a range.
+ *
+ * Returns: (element-type gchar* gchar*) (transfer full): a #GHashTable
+ *          containing the default attributes applied to a text object,
+ *          (exclusive of explicitly-set attributes), encoded as UTF-8.
+ **/
+GHashTable *
+atspi_text_get_default_attributes (AtspiAccessible *obj, GError **error)
+{
+  DBusMessage *reply;
+  GHashTable *ret;
+
+    g_return_val_if_fail (obj != NULL, NULL);
+
+  reply = _atspi_dbus_call_partial (obj, atspi_interface_text, "GetDefaultAttributes", error, "");
+  ret = _atspi_dbus_hash_from_message (reply);
+  dbus_message_unref (reply);
+  return ret;
+}
+
+
+/**
+ * atspi_text_set_caret_offset:
+ * @obj: a pointer to the #AtspiText object on which to operate.
+ * @new_offset: the offset to which the text caret is to be moved.
+ *
+ * Set the text caret position for an #AtspiText object.
+ *
+ * Returns: #TRUE if successful, #FALSE otherwise.
+ **/
+gboolean
+atspi_text_set_caret_offset (AtspiText *obj,
+                               gint new_offset,
+                               GError **error)
+{
+  dbus_int32_t d_new_offset = new_offset;
+  dbus_bool_t retval = FALSE;
+
+  g_return_val_if_fail (obj != NULL, FALSE);
+
+  _atspi_dbus_call (obj, atspi_interface_text, "SetCaretOffset", error, "i=>b", d_new_offset, &retval);
+
+  return retval;
+}
+
+/**
+ * atspi_text_get_text_before_offset:
+ * @obj: a pointer to the #AtspiText object on which to operate.
+ * @offset: an integer indicating the offset from which the delimiter
+ *        search is based.
+ * @type: an #AtspiTextBoundaryType indicating whether the desired
+ *       text string is a word, sentence, line, or attribute run.
+ *
+ * Get delimited text from an #AtspiText object which precedes a given
+ *          text offset.
+ *
+ * Returns: an #AtspiTextRange containing a UTF-8 string representing the
+ *          delimited text, both of whose delimiting boundaries are before the
+ *          current offset, or an empty string if no such text exists.
+ **/
+AtspiTextRange *
+atspi_text_get_text_before_offset (AtspiText *obj,
+                                    gint offset,
+                                    AtspiTextBoundaryType type,
+                                    GError **error)
+{
+  dbus_int32_t d_offset = offset;
+  dbus_uint32_t d_type = type;
+  dbus_int32_t d_start_offset = -1, d_end_offset = -1;
+  AtspiTextRange *range = g_new0 (AtspiTextRange, 1);
+
+  if (range)
+    range->start_offset = range->end_offset = -1;
+  if (!obj || !range)
+    return range;
+
+  _atspi_dbus_call (obj, atspi_interface_text, "GetTextBeforeOffset", error,
+                    "iu=>sii", d_offset, d_type, &range->text,
+                    &d_start_offset, &d_end_offset);
+
+  range->start_offset = d_start_offset;
+  range->end_offset = d_end_offset;
+
+  return range;
+}
+
+/**
+ * atspi_text_get_text_at_offset:
+ * @obj: a pointer to the #AtspiText object on which to operate.
+ * @offset: a long integer indicating the offset from which the delimiter
+ *        search is based.
+ * @type: an #AtspiTextBoundaryType indicating whether the desired
+ *       text string is a word, sentence, line, or attribute run.
+ *
+ * Get delimited text from an #AtspiText object which includes a given
+ *          text offset.
+ *
+ * Returns: an #AtspiTextRange containing a UTF-8 string representing the
+ *          delimited text, whose delimiting boundaries bracket the
+ *          current offset, or an empty string if no such text exists.
+ **/
+AtspiTextRange *
+atspi_text_get_text_at_offset (AtspiText *obj,
+                                    gint offset,
+                                    AtspiTextBoundaryType type,
+                                    GError **error)
+{
+  dbus_int32_t d_offset = offset;
+  dbus_uint32_t d_type = type;
+  dbus_int32_t d_start_offset = -1, d_end_offset = -1;
+  AtspiTextRange *range = g_new0 (AtspiTextRange, 1);
+
+  if (range)
+    range->start_offset = range->end_offset = -1;
+  if (!obj || !range)
+    return range;
+
+  _atspi_dbus_call (obj, atspi_interface_text, "GetTextAtOffset", error,
+                    "iu=>sii", d_offset, d_type, &range->text,
+                    &d_start_offset, &d_end_offset);
+
+  range->start_offset = d_start_offset;
+  range->end_offset = d_end_offset;
+
+  return range;
+}
+
+/**
+ * atspi_text_get_text_after_offset:
+ * @obj: a pointer to the #AtspiText object on which to operate.
+ * @offset: an integer indicating the offset from which the delimiter
+ *        search is based.
+ * @type: an #AtspiTextBoundaryType indicating whether the desired
+ *       text string is a word, sentence, line, or attribute run.
+ *
+ * Get delimited text from an #AtspiText object which follows a given
+ *          text offset.
+ *
+ * Returns: an #AtspiTextRange containing a UTF-8 string representing the
+ *          delimited text, both of whose delimiting boundaries are after or
+ *          inclusive of the current offset, or an empty string if no such
+ *          text exists.
+ **/
+AtspiTextRange *
+atspi_text_get_text_after_offset (AtspiText *obj,
+                                    gint offset,
+                                    AtspiTextBoundaryType type,
+                                    GError **error)
+{
+  dbus_int32_t d_offset = offset;
+  dbus_uint32_t d_type = type;
+  dbus_int32_t d_start_offset = -1, d_end_offset = -1;
+  AtspiTextRange *range = g_new0 (AtspiTextRange, 1);
+
+  if (range)
+    range->start_offset = range->end_offset = -1;
+  if (!obj || !range)
+    return range;
+
+  _atspi_dbus_call (obj, atspi_interface_text, "GetTextAfterOffset", error,
+                    "iu=>sii", d_offset, d_type, &range->text,
+                    &d_start_offset, &d_end_offset);
+
+  range->start_offset = d_start_offset;
+  range->end_offset = d_end_offset;
+
+  return range;
+}
+
+/**
+ * atspi_text_get_character_at_offset:
+ * @obj: a pointer to the #AtspiText object on which to operate.
+ * @offset: a long integer indicating the text offset where the desired
+ *          character is located.
+ *
+ * Get the character at a given offset for an #AtspiText object.
+ *
+ * Returns: an #unsigned long integer which represents the
+ *        UCS-4 unicode code point of the given character, or
+ *        0xFFFFFFFF if the character in question cannot be represented
+ *        in the UCS-4 encoding.
+ **/
+guint
+atspi_text_get_character_at_offset (AtspiText *obj,
+                                     gint offset,
+                                     GError **error)
+{
+  dbus_int32_t d_offset = offset;
+  dbus_int32_t retval = -1;
+
+  g_return_val_if_fail (obj != NULL, -1);
+
+  _atspi_dbus_call (obj, atspi_interface_text, "GetCharacterAtOffset", error, "i=>i", d_offset, &retval);
+
+  return retval;
+}
+
+/**
+ * atspi_text_get_character_extents:
+ * @obj: a pointer to the #AtspiText object on which to operate.
+ * @offset: an integer indicating the offset of the text character for
+ *        whom boundary information is requested.
+ * @type: an #AccessibleCoordType indicating the coordinate system to use
+ *        for the returned values.
+ *
+ * Returns: A #AtspiRect specifying the position and size of the character.
+ *
+ * Get the bounding box containing the glyph representing
+ *        the character at a particular text offset.
+ **/
+AtspiRect *
+atspi_text_get_character_extents (AtspiText *obj,
+                                    gint offset,
+                                   AtspiCoordType type,
+                                   GError **error)
+{
+  dbus_int32_t d_offset = offset;
+  dbus_uint32_t d_type = type;
+  dbus_int32_t d_x, d_y, d_width, d_height;
+  AtspiRect ret;
+
+  ret.x = ret.y = ret.width = ret.height = -1;
+
+  if (obj == NULL)
+    return atspi_rect_copy (&ret);
+
+  _atspi_dbus_call (obj, atspi_interface_text, "GetCharacterExtents", error, "iu=>iiii", d_offset, d_type, &d_x, &d_y, &d_width, &d_height);
+
+  ret.x = d_x;
+  ret.y = d_y;
+  ret.width = d_width;
+  ret.height = d_height;
+  return atspi_rect_copy (&ret);
+}
+
+/**
+ * atspi_text_get_offset_at_point:
+ * @obj: a pointer to the #AtspiText object on which to operate.
+ * @x: the x coordinate of the point to be queried.
+ * @y: the y coordinate of the point to be queried.
+ * @type: an #AtspiCoordType indicating the coordinate system in which
+ *       the values should be returned.
+ *
+ * Get the character offset into the text at a given point.
+ *
+ * Returns: the offset (as an integer) at the point (@x, @y)
+ *       in the specified coordinate system.
+ *
+ **/
+gint
+atspi_text_get_offset_at_point (AtspiText *obj,
+                                 gint x,
+                                 gint y,
+                                AtspiCoordType type,
+                                GError **error)
+{
+  dbus_int32_t d_x = x, d_y = y;
+  dbus_uint16_t d_type = type;
+  dbus_int32_t retval = -1;
+
+  g_return_val_if_fail (obj != NULL, -1);
+
+  _atspi_dbus_call (obj, atspi_interface_text, "GetOffsetAtPoint", error, "iin=>i", d_x, d_y, d_type, &retval);
+
+  return retval;
+}
+
+/**
+ * atspi_text_get_range_extents:
+ * @obj: a pointer to the #AtspiText object on which to operate.
+ * @start_offset: an integer indicating the offset of the first text character for
+ *        whom boundary information is requested.
+ * @end_offset: an integer indicating the offset of the text character
+ *        after the last character for whom boundary information is requested.
+ * @type: an #AtspiCoordType indicating the coordinate system to use
+ *        for the returned values.
+ *
+ * Returns: A #AtspiRect giving the position and size of the specified range
+ *          of text.
+ *
+ * Get the bounding box for text within a range in an  #AtspiText object.
+ **/
+AtspiRect *
+atspi_text_get_range_extents (AtspiText *obj,
+                               gint start_offset,
+                               gint end_offset,
+                               AtspiCoordType type,
+                               GError **error)
+{
+  dbus_int32_t d_start_offset = start_offset, d_end_offset = end_offset;
+  dbus_int16_t d_type = type;
+  dbus_int32_t d_x, d_y, d_width, d_height;
+  AtspiRect ret;
+
+  ret.x = ret.y = ret.width = ret.height = -1;
+
+  if (obj == NULL)
+    return atspi_rect_copy (&ret);
+
+  _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);
+
+  ret.x = d_x;
+  ret.y = d_y;
+  ret.width = d_width;
+  ret.height = d_height;
+  return atspi_rect_copy (&ret);
+}
+
+/**
+ * atspi_text_get_bounded_ranges:
+ * @obj: a pointer to the #AtspiText object on which to operate.
+ * @x: the 'starting' x coordinate of the bounding box.
+ * @y: the 'starting' y coordinate of the bounding box.
+ * @width: the x extent of the bounding box.
+ * @height: the y extent of the bounding box.
+ * @type: an #AccessibleCoordType indicating the coordinate system to use
+ *        for the returned values.
+ * @clipTypeX: an #AtspiTextClipType indicating how to treat characters that
+ *        intersect the bounding box's x extents.
+ * @clipTypeY: an #AtspiTextClipType indicating how to treat characters that
+ *        intersect the bounding box's y extents.
+ *
+ * Get the ranges of text from an #AtspiText object which lie within the
+ *          bounds defined by (@x, @y) and (@x+@width, @y+@height).
+ *
+ * Returns: (transfer full) (element-type AtspiTextRange*): a null-terminated list of
+ *          pointers to #AtspiTextRange structs detailing the bounded text.
+ **/
+GArray *
+atspi_text_get_bounded_ranges (AtspiText *obj,
+                                gint x,
+                                gint y,
+                                gint width,
+                                gint height,
+                                AtspiCoordType type,
+                                AtspiTextClipType clipTypeX,
+                                AtspiTextClipType clipTypeY,
+                                GError **error)
+{
+  dbus_int32_t d_x = x, d_y = y, d_width = width, d_height = height;
+  dbus_uint32_t d_type = type;
+  dbus_uint32_t d_clipTypeX = clipTypeX, d_clipTypeY = clipTypeY;
+  GArray *range_seq;
+
+  g_return_val_if_fail (obj != NULL, NULL);
+
+  _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);
+
+  return range_seq;
+}
+
+/**
+ * atspi_text_get_n_selections:
+ * @obj: a pointer to the #AtspiText object on which to operate.
+ *
+ * Get the number of active non-contiguous selections for an
+ *          #AtspiText object.
+ *
+ * Returns: a long integer indicating the current
+ *          number of non-contiguous text selections active
+ *          within an #AtspiText object.
+ **/
+gint
+atspi_text_get_n_selections (AtspiText *obj, GError **error)
+{
+  dbus_int32_t retval;
+
+  g_return_val_if_fail (obj != NULL, -1);
+
+  _atspi_dbus_call (obj, atspi_interface_text, "GetNSelections", error, "i", &retval);
+
+  return retval;
+}
+
+/**
+ * atspi_text_get_sSelection:
+ * @obj: a pointer to the #AtspiText object on which to operate.
+ * @selection_num: an integer indicating which selection to query.
+ * @start_offset: a pointer to a long integer into which the start offset
+ *           of the selection will be returned.
+ * @end_offset: a pointer to a long integer into which the start offset
+ *           of the selection will be returned.
+ *
+ * Get the bounds of the @selection_num-th active text selection for an
+ *         #AtspiText object.
+ **/
+AtspiRange *
+atspi_text_get_selection (AtspiText *obj,
+                            gint selection_num,
+                            GError **error)
+{
+  dbus_int32_t d_selection_num = selection_num;
+  dbus_int32_t d_start_offset, d_end_offset;
+  AtspiRange *ret = g_new (AtspiRange, 1);
+
+  if (ret)
+    ret->start_offset = ret->end_offset = -1;
+
+  if (!obj || !ret)
+    return ret;
+
+  _atspi_dbus_call (obj, atspi_interface_text, "GetSelection", error, "i=>ii", d_selection_num, &d_start_offset, &d_end_offset);
+
+  ret->start_offset = d_start_offset;
+  ret->end_offset = d_end_offset;
+  return ret;
+}
+
+/**
+ * atspi_text_add_selection:
+ * @obj: a pointer to the #AtspiText object on which to operate.
+ * @start_offset: the starting offset of the desired new selection.
+ * @end_offset: the offset of the first character after the new selection.
+ *
+ * Select some text (add a text selection) in an #AtspiText object.
+ *
+ * Returns: #TRUE if successful, #FALSE otherwise.
+ **/
+gboolean
+atspi_text_add_selection (AtspiText *obj,
+                            gint start_offset, gint end_offset,
+                            GError **error)
+{
+  dbus_int32_t d_start_offset = start_offset, d_end_offset = end_offset;
+  dbus_bool_t retval = FALSE;
+
+  _atspi_dbus_call (obj, atspi_interface_text, "AddSelection", error, "ii=>b", d_start_offset, d_end_offset, &retval);
+
+  return retval;
+}
+
+/**
+ * atspi_text_remove_selection:
+ * @obj: a pointer to the #AtspiText object on which to operate.
+ * @selection_num: an integer indicating which (possibly of several)
+ *         text selection to remove.
+ *
+ * De-select a text selection.
+ *
+ * Returns: #TRUE if successful, #FALSE otherwise.
+ **/
+gboolean
+atspi_text_remove_selection (AtspiText *obj,
+                               gint selection_num,
+                               GError **error)
+{
+  dbus_int32_t d_selection_num = selection_num;
+  dbus_bool_t retval = FALSE;
+
+  g_return_val_if_fail (obj != NULL, FALSE);
+
+  _atspi_dbus_call (obj, atspi_interface_text, "RemoveSelection", error, "i=>b", d_selection_num, &retval);
+
+  return retval;
+}
+
+/**
+ * atspi_text_set_selection:
+ * @obj: a pointer to the #AtspiText object on which to operate.
+ * @selection_num: a zero-offset index indicating which text selection to modify.
+ * @start_offset: a long int, the new starting offset for the selection.
+ * @end_offset: a long int, the desired new offset of the first character
+ *             after the selection.
+ *
+ * Change the bounds of an existing #AtspiText text selection.
+ *
+ * Returns: #TRUE if successful, #FALSE otherwise.
+ **/
+gboolean
+atspi_text_set_selection (AtspiText *obj,
+                            gint selection_num,
+                            gint start_offset,
+                            gint end_offset,
+                            GError **error)
+{
+  dbus_int32_t d_selection_num = selection_num, d_start_offset = start_offset, d_end_offset = end_offset;
+  dbus_bool_t retval = FALSE;
+
+  g_return_val_if_fail (obj != NULL, FALSE);
+
+  _atspi_dbus_call (obj, atspi_interface_text, "SetSelection", error, "iii=>b", d_selection_num, d_start_offset, d_end_offset, &retval);
+
+  return retval;
+}
+
+static void
+atspi_text_base_init (AtspiText *klass)
+{
+}
+
+GType
+atspi_text_get_type (void)
+{
+  static GType type = 0;
+
+  if (!type) {
+    static const GTypeInfo tinfo =
+    {
+      sizeof (AtspiText),
+      (GBaseInitFunc) atspi_text_base_init,
+      (GBaseFinalizeFunc) NULL,
+    };
+
+    type = g_type_register_static (G_TYPE_INTERFACE, "AtspiText", &tinfo, 0);
+
+  }
+  return type;
+}
diff --git a/atspi/atspi-text.h b/atspi/atspi-text.h
new file mode 100644 (file)
index 0000000..6c6add1
--- /dev/null
@@ -0,0 +1,138 @@
+/*
+ * AT-SPI - Assistive Technology Service Provider Interface
+ * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
+ *
+ * Copyright 2002 Ximian, Inc.
+ *           2002 Sun Microsystems Inc.
+ *           
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef _ATSPI_TEXT_H_
+#define _ATSPI_TEXT_H_
+
+#include "glib-object.h"
+
+#include "atspi-constants.h"
+
+#include "atspi-types.h"
+
+typedef struct _AtspiRange AtspiRange;
+struct _AtspiRange
+{
+  gint start_offset;
+  gint end_offset;
+};
+
+/**
+ * ATSPI_TYPE_RANGE:
+ * 
+ * The #GType for a boxed type holding a range within a text bock.
+ */
+#define        ATSPI_TYPE_RANGE atspi_range_get_type ()
+
+GType atspi_range_get_type ();
+
+typedef struct _AtspiRangedAttributeSet AtspiRangedAttributeSet;
+struct _AtspiRangedAttributeSet
+{
+  GHashTable *attributes;
+  gint start_offset;
+  gint end_offset;
+};
+
+/**
+ * ATSPI_TYPE_RANGED_ATTRIBUTE_SET:
+ * 
+ * The #GType for a boxed type holding an attribute set within a text block.
+ */
+#define        ATSPI_TYPE_RANGED_ATTRIBUTE_SET atspi_ranged_attribute_set_get_type ()
+
+GType atspi_ranged_attribute_set_get_type ();
+
+typedef struct _AtspiTextRange AtspiTextRange;
+struct _AtspiTextRange
+{
+  gint start_offset;
+  gint end_offset;
+  gchar *text;
+};
+
+/**
+ * ATSPI_TYPE_TEXT_RANGE:
+ * 
+ * The #GType for a boxed type holding a range within a text bock.
+ */
+#define        ATSPI_TYPE_TEXT_RANGE atspi_text_range_get_type ()
+
+#define ATSPI_TYPE_TEXT                    (atspi_text_get_type ())
+#define ATSPI_IS_TEXT(obj)                 G_TYPE_CHECK_INSTANCE_TYPE ((obj), ATSPI_TYPE_TEXT)
+#define ATSPI_TEXT(obj)                    G_TYPE_CHECK_INSTANCE_CAST ((obj), ATSPI_TYPE_TEXT, AtspiText)
+#define ATSPI_TEXT_GET_IFACE(obj)          (G_TYPE_INSTANCE_GET_INTERFACE ((obj), ATSPI_TYPE_TEXT, AtspiText))
+
+GType atspi_text_get_type ();
+
+struct _AtspiText
+{
+  GTypeInterface parent;
+};
+
+
+GType atspi_text_range_get_type ();
+
+gint atspi_text_get_character_count (AtspiText *obj, GError **error);
+
+gchar * atspi_text_get_text (AtspiText *obj, gint start_offset, gint end_offset, GError **error);
+
+gint atspi_text_get_caret_offset (AtspiText *obj, GError **error);
+
+AtspiRangedAttributeSet * atspi_text_get_attributes (AtspiText *obj, gint offset, GError **error);
+
+AtspiRangedAttributeSet * atspi_text_get_attribute_run (AtspiText *obj, gint offset, gboolean include_defaults, GError **error);
+
+gchar * atspi_text_get_attribute_value (AtspiText *obj, gint offset, gchar *attribute_value, GError **error);
+
+GHashTable * atspi_text_get_default_attributes (AtspiAccessible *obj, GError **error);
+
+gboolean atspi_text_set_caret_offset (AtspiText *obj, gint new_offset, GError **error);
+
+AtspiTextRange * atspi_text_get_text_before_offset (AtspiText *obj, gint offset, AtspiTextBoundaryType type, GError **error);
+
+AtspiTextRange * atspi_text_get_text_at_offset (AtspiText *obj, gint offset, AtspiTextBoundaryType type, GError **error);
+
+AtspiTextRange * atspi_text_get_text_after_offset (AtspiText *obj, gint offset, AtspiTextBoundaryType type, GError **error);
+
+guint atspi_text_get_character_at_offset (AtspiText *obj, gint offset, GError **error);
+
+AtspiRect * atspi_text_get_character_extents (AtspiText *obj, gint offset, AtspiCoordType type, GError **error);
+
+gint atspi_text_get_offset_at_point (AtspiText *obj, gint x, gint y, AtspiCoordType type, GError **error);
+
+AtspiRect * atspi_text_get_range_extents (AtspiText *obj, gint start_offset, gint end_offset, AtspiCoordType type, GError **error);
+
+GArray * atspi_text_get_bounded_ranges (AtspiText *obj, gint x, gint y, gint width, gint height, AtspiCoordType type, AtspiTextClipType clipTypeX, AtspiTextClipType clipTypeY, GError **error);
+
+gint atspi_text_get_n_selections (AtspiText *obj, GError **error);
+
+AtspiRange * atspi_text_get_selection (AtspiText *obj, gint selection_num, GError **error);
+
+gboolean atspi_text_add_selection (AtspiText *obj, gint start_offset, gint end_offset, GError **error);
+
+gboolean atspi_text_remove_selection (AtspiText *obj, gint selection_num, GError **error);
+
+gboolean atspi_text_set_selection (AtspiText *obj, gint selection_num, gint start_offset, gint end_offset, GError **error);
+#endif /* _ATSPI_TEXT_H_ */
index 076019e..0dc4f1a 100644 (file)
@@ -38,7 +38,7 @@ typedef struct _AtspiAccessible AtspiEditableText;
 typedef struct _AtspiAccessible AtspiHypertext;
 typedef struct _AtspiAccessible AtspiSelection;
 typedef struct _AtspiAccessible AtspiTable;
-typedef struct _AtspiAccessible AtspiText;
+typedef struct _AtspiText AtspiText;
 typedef struct _AtspiAccessible AtspiValue;
 
 typedef guint AtspiControllerEventMask;
index a6119a8..c5d8fac 100644 (file)
@@ -34,5 +34,6 @@
 #include "atspi-event-listener.h"
 #include "atspi-misc.h"
 #include "atspi-registry.h"
+#include "atspi-text.h"
 
 #endif