2.34.0
[platform/upstream/at-spi2-core.git] / atspi / atspi-text.c
index 733260d..de99773 100644 (file)
@@ -7,19 +7,19 @@
  * Copyright 2010, 2011 Novell, Inc.
  *
  * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * version 2.1 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.
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU Library General Public
+ * You should have received a copy of the GNU Lesser 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.
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
  */
 
 #include "atspi-private.h"
@@ -138,7 +138,7 @@ atspi_text_get_caret_offset (AtspiText *obj, GError **error)
 }
 
 /**
- * atspi_text_get_attributes:
+ * atspi_text_get_attributes: (rename-to atspi_text_get_text_attributes)
  * @obj: a pointer to the #AtspiText object to query.
  * @offset: a #gint indicating the offset from which the attribute
  *        search is based.
@@ -154,6 +154,8 @@ atspi_text_get_caret_offset (AtspiText *obj, GError **error)
  *
  * Returns: (element-type gchar* gchar*) (transfer full): a #GHashTable
  * describing the attributes at the given character offset.
+ *
+ * Deprecated: 2.10: Use atspi_text_get_text_attributes instead.
  **/
 GHashTable *
 atspi_text_get_attributes (AtspiText *obj,
@@ -162,6 +164,34 @@ atspi_text_get_attributes (AtspiText *obj,
                           gint *end_offset,
                           GError **error)
 {
+  return atspi_text_get_text_attributes (obj, offset, start_offset, end_offset, error);
+}
+
+/**
+ * atspi_text_get_text_attributes:
+ * @obj: a pointer to the #AtspiText object to query.
+ * @offset: a #gint indicating the offset from which the attribute
+ *        search is based.
+ * @start_offset: (out): a #gint pointer indicating the start of the desired text
+ *                range.
+ * @end_offset: (out): a #gint pointer indicating the first character past the desired
+ *              range.
+ *
+ * Gets the attributes applied to a range of text from an #AtspiText
+ * object. The text attributes correspond to CSS attributes
+ * where possible.
+ * <em>DEPRECATED</em>
+ *
+ * Returns: (element-type gchar* gchar*) (transfer full): a #GHashTable
+ * describing the attributes at the given character offset.
+ **/
+GHashTable *
+atspi_text_get_text_attributes (AtspiText *obj,
+                          gint offset,
+                          gint *start_offset,
+                          gint *end_offset,
+                          GError **error)
+{
   dbus_int32_t d_offset = offset;
   dbus_int32_t d_start_offset, d_end_offset;
   DBusMessage *reply;
@@ -249,15 +279,17 @@ atspi_text_get_attribute_run (AtspiText *obj,
 }
 
 /**
- * atspi_text_get_attribute_value:
+ * atspi_text_get_attribute_value: (rename-to atspi_text_get_text_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.
  *
  * Gets the value of a named attribute at a given offset.
  *
- * Returns: the value of a given attribute at the given offset, or NULL if
- * not present.
+ * Returns: (nullable): the value of a given attribute at the given
+ * offset, or %NULL if not present.
+ *
+ * Deprecated: 2.10: Use atspi_text_get_text_attribute_value instead.
  **/
 gchar *
 atspi_text_get_attribute_value (AtspiText *obj,
@@ -265,11 +297,36 @@ atspi_text_get_attribute_value (AtspiText *obj,
                                 gchar *attribute_value,
                                 GError **error)
 {
+  return atspi_text_get_text_attribute_value (obj, offset, attribute_value,
+                                              error);
+}
+
+/**
+ * atspi_text_get_text_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.
+ *
+ * Gets the value of a named attribute at a given offset.
+ *
+ * Returns: (nullable): the value of a given attribute at the given offset, or %NULL if
+ * not present.
+ **/
+gchar *
+atspi_text_get_text_attribute_value (AtspiText *obj,
+                                     gint offset,
+                                     gchar *attribute_value,
+                                     GError **error)
+{
   gchar *retval = NULL;
+  dbus_int32_t d_i = offset;
 
   g_return_val_if_fail (obj != NULL, NULL);
 
-  _atspi_dbus_call (obj, atspi_interface_text, "GetAttributeValue", error, "i=>s", offset, &retval);
+  _atspi_dbus_call (obj, atspi_interface_text, "GetAttributeValue", error, "is=>s", d_i, (const gchar *)attribute_value, &retval);
+
+  if (!retval)
+    retval = g_strdup ("");
 
   return retval;
 }
@@ -367,6 +424,76 @@ atspi_text_get_text_before_offset (AtspiText *obj,
 }
 
 /**
+ * atspi_text_get_string_at_offset:
+ * @obj: an #AtspiText
+ * @offset: position
+ * @granularity: An #AtspiTextGranularity
+ *
+ * Gets a portion of the text exposed through an #AtspiText according to a given @offset
+ * and a specific @granularity, along with the start and end offsets defining the
+ * boundaries of such a portion of text.
+ *
+ * If @granularity is ATSPI_TEXT_GRANULARITY_CHAR the character at the
+ * offset is returned.
+ *
+ * If @granularity is ATSPI_TEXT_GRANULARITY_WORD the returned string
+ * is from the word start at or before the offset to the word start after
+ * the offset.
+ *
+ * The returned string will contain the word at the offset if the offset
+ * is inside a word and will contain the word before the offset if the
+ * offset is not inside a word.
+ *
+ * If @granularity is ATSPI_TEXT_GRANULARITY_SENTENCE the returned string
+ * is from the sentence start at or before the offset to the sentence
+ * start after the offset.
+ *
+ * The returned string will contain the sentence at the offset if the offset
+ * is inside a sentence and will contain the sentence before the offset
+ * if the offset is not inside a sentence.
+ *
+ * If @granularity is ATSPI_TEXT_GRANULARITY_LINE the returned string
+ * is from the line start at or before the offset to the line
+ * start after the offset.
+ *
+ * If @granularity is ATSPI_TEXT_GRANULARITY_PARAGRAPH the returned string
+ * is from the start of the paragraph at or before the offset to the start
+ * of the following paragraph after the offset.
+ *
+ * Since: 2.9.90
+ *
+ * Returns: a newly allocated string containing the text at the @offset bounded
+ *   by the specified @granularity. Use g_free() to free the returned string.
+ *   Returns %NULL if the offset is invalid or no implementation is available.
+ **/
+AtspiTextRange *
+atspi_text_get_string_at_offset (AtspiText *obj,
+                                 gint offset,
+                                 AtspiTextGranularity granularity,
+                                 GError **error)
+{
+  dbus_int32_t d_offset = offset;
+  dbus_uint32_t d_granularity = granularity;
+  dbus_int32_t d_start_offset = -1, d_end_offset = -1;
+  AtspiTextRange *range = g_new0 (AtspiTextRange, 1);
+
+  range->start_offset = range->end_offset = -1;
+  if (!obj)
+    return range;
+
+  _atspi_dbus_call (obj, atspi_interface_text, "GetStringAtOffset", error,
+                    "iu=>sii", d_offset, d_granularity, &range->content,
+                    &d_start_offset, &d_end_offset);
+
+  range->start_offset = d_start_offset;
+  range->end_offset = d_end_offset;
+  if (!range->content)
+    range->content = g_strdup ("");
+
+  return range;
+}
+
+/**
  * atspi_text_get_text_at_offset:
  * @obj: a pointer to the #AtspiText object on which to operate.
  * @offset: a #gint indicating the offset from which the delimiter
@@ -380,6 +507,8 @@ atspi_text_get_text_before_offset (AtspiText *obj,
  * 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.
+ *
+ * Deprecated: 2.10: Use atspi_text_get_string_at_offset.
  **/
 AtspiTextRange *
 atspi_text_get_text_at_offset (AtspiText *obj,
@@ -489,6 +618,8 @@ atspi_text_get_character_at_offset (AtspiText *obj,
  *
  * Gets a bounding box containing the glyph representing
  *        the character at a particular text offset.
+ * The returned values are meaningful only if the Text has both
+ * STATE_VISIBLE and STATE_SHOWING.
  *
  * Returns: An #AtspiRect specifying the position and size of the character.
  *
@@ -561,6 +692,8 @@ atspi_text_get_offset_at_point (AtspiText *obj,
  *        for the returned values.
  *
  * Gets the bounding box for text within a range in an  #AtspiText object.
+ * The returned values are meaningful only if the Text has both
+ * STATE_VISIBLE and STATE_SHOWING.
  *
  * Returns: An #AtspiRect giving the position and size of the specified range
  *          of text.
@@ -626,7 +759,7 @@ atspi_text_get_bounded_ranges (AtspiText *obj,
   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;
+  GArray *range_seq = NULL;
 
   g_return_val_if_fail (obj != NULL, NULL);
 
@@ -763,6 +896,72 @@ atspi_text_set_selection (AtspiText *obj,
   return retval;
 }
 
+/**
+ * atspi_text_scroll_substring_to:
+ * @obj: a pointer to the #AtspiText object on which to operate.
+ * @start_offset: a #gint indicating the start of the desired text range.
+ * @end_offset: a #gint indicating the first character past the desired range.
+ * @type: a #AtspiScrollType indicating where the object should be placed on the
+ *        screen.
+ *
+ * Scrolls whatever container of the #AtspiText text range so it becomes
+ * visible on the screen.
+ *
+ * Returns: #TRUE if successful, #FALSE otherwise.
+ **/
+gboolean
+atspi_text_scroll_substring_to (AtspiText *obj,
+                               gint start_offset,
+                               gint end_offset,
+                               AtspiScrollType type,
+                               GError **error)
+{
+  dbus_bool_t retval = FALSE;
+
+  g_return_val_if_fail (obj != NULL, FALSE);
+
+  _atspi_dbus_call (obj, atspi_interface_text, "ScrollSubstringTo",
+                    error, "iiu=>b",
+                    start_offset, end_offset, type, &retval);
+
+  return retval;
+}
+
+/**
+ * atspi_text_scroll_substring_to_point:
+ * @obj: a pointer to the #AtspiText object on which to operate.
+ * @start_offset: a #gint indicating the start of the desired text range.
+ * @end_offset: a #gint indicating the first character past the desired range.
+ * @coords: a #AtspiCoordType indicating whether the coordinates are relative to
+ *          the screen, to the window, or to the parent object.
+ * @x: the x coordinate of the point to reach
+ * @y: the y coordinate of the point to reach
+ *
+ * Scrolls whatever container of the #AtspiText text range so it becomes
+ * visible on the screen at a given position.
+ *
+ * Returns: #TRUE if successful, #FALSE otherwise.
+ **/
+gboolean
+atspi_text_scroll_substring_to_point (AtspiText *obj,
+                                     gint start_offset,
+                                     gint end_offset,
+                                     AtspiCoordType coords,
+                                     gint x,
+                                     gint y,
+                                     GError **error)
+{
+  dbus_bool_t retval = FALSE;
+
+  g_return_val_if_fail (obj != NULL, FALSE);
+
+  _atspi_dbus_call (obj, atspi_interface_text, "ScrollSubstringToPoint",
+                    error, "iiuii=>b",
+                    start_offset, end_offset, coords, x, y, &retval);
+
+  return retval;
+}
+
 static void
 atspi_text_base_init (AtspiText *klass)
 {