Add property accessible-table-caption-object. This addresses bug #74814.
[platform/upstream/atk.git] / atk / atktext.c
index ee4cc0b..bf2a814 100755 (executable)
 
 #include "atktext.h"
 #include "atkmarshal.h"
+#include "atk-enum-types.h"
+
+#include <string.h>
+
+GPtrArray *extra_attributes = NULL;
 
 enum {
   TEXT_CHANGED,
-  CARET_MOVED,
+  TEXT_CARET_MOVED,
+  TEXT_SELECTION_CHANGED,
+  TEXT_ATTRIBUTES_CHANGED,
   LAST_SIGNAL
 };
 
-struct _AtkTextIfaceClass
-{
-  GObjectClass parent;
-};
-
-typedef struct _AtkTextIfaceClass AtkTextIfaceClass;
+static const gchar *bool[] = {"false",
+                              "true"};
+static const gchar *style[] = {"normal",
+                               "oblique",
+                               "italic"};
+static const gchar *variant[] = {"normal",
+                                 "small_caps"};
+static const gchar *stretch[] = {"ultra_condensed",
+                                 "extra_condensed",
+                                 "condensed",
+                                 "semi_condensed",
+                                 "normal",
+                                 "semi_expanded",
+                                 "expanded",
+                                 "extra_expanded",
+                                 "ultra_expanded"};
+static const gchar *justification[] = {"left",
+                                       "right",
+                                       "center",
+                                       "fill"};
+static const gchar *direction[] = {"none",
+                                   "ltr",
+                                   "rtl"};
+static const gchar *wrap_mode[] = {"none",
+                                   "char",
+                                   "word"};
+static const gchar *underline[] = {"none",
+                                   "single",
+                                   "double",
+                                   "low"};
 
 static void atk_text_base_init (gpointer *g_class);
 
+static void atk_text_real_get_range_extents  (AtkText          *text,
+                                              gint             start_offset,
+                                              gint             end_offset,
+                                              AtkCoordType     coord_type,
+                                              AtkTextRectangle *rect);
+
+static AtkTextRange** atk_text_real_get_bounded_ranges (AtkText          *text,
+                                                        AtkTextRectangle *rect,
+                                                        AtkCoordType     coord_type,
+                                                        AtkTextClipType  x_clip_type,
+                                                        AtkTextClipType  y_clip_type);
+
 static guint atk_text_signals[LAST_SIGNAL] = { 0 };
 
 GType
@@ -82,15 +125,32 @@ atk_text_base_init (gpointer *g_class)
                      G_TYPE_NONE,
                      2, G_TYPE_INT, G_TYPE_INT);
       
-      atk_text_signals[CARET_MOVED] =
+      atk_text_signals[TEXT_CARET_MOVED] =
        g_signal_new ("text_caret_moved",
                      ATK_TYPE_TEXT,
                      G_SIGNAL_RUN_LAST,
-                     G_STRUCT_OFFSET (AtkTextIface, caret_changed),
+                     G_STRUCT_OFFSET (AtkTextIface, text_caret_moved),
                      (GSignalAccumulator) NULL, NULL,
                      g_cclosure_marshal_VOID__INT,
                      G_TYPE_NONE,
                      1, G_TYPE_INT);
+      atk_text_signals[TEXT_SELECTION_CHANGED] =
+        g_signal_new ("text_selection_changed",
+                      ATK_TYPE_TEXT,
+                      G_SIGNAL_RUN_LAST,
+                      G_STRUCT_OFFSET (AtkTextIface, text_selection_changed),
+                      (GSignalAccumulator) NULL, NULL,
+                      g_cclosure_marshal_VOID__VOID,
+                      G_TYPE_NONE, 0);
+      atk_text_signals[TEXT_ATTRIBUTES_CHANGED] =
+        g_signal_new ("text_attributes_changed",
+                      ATK_TYPE_TEXT,
+                      G_SIGNAL_RUN_LAST,
+                      G_STRUCT_OFFSET (AtkTextIface, text_attributes_changed),
+                      (GSignalAccumulator) NULL, NULL,
+                      g_cclosure_marshal_VOID__VOID,
+                      G_TYPE_NONE, 0);
+
       
       initialized = TRUE;
     }
@@ -112,12 +172,14 @@ atk_text_get_text (AtkText      *text,
                    gint         end_offset)
 {
   AtkTextIface *iface;
-
-  g_return_val_if_fail (text != NULL, NULL);
+  
   g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
 
   iface = ATK_TEXT_GET_IFACE (text);
 
+  if (start_offset < 0 || end_offset < -1)
+    return NULL;
+
   if (iface->get_text)
     return (*(iface->get_text)) (text, start_offset, end_offset);
   else
@@ -139,9 +201,11 @@ atk_text_get_character_at_offset (AtkText      *text,
 {
   AtkTextIface *iface;
 
-  g_return_val_if_fail (text != NULL, (gunichar) 0);
   g_return_val_if_fail (ATK_IS_TEXT (text), (gunichar) 0);
 
+  if (offset < 0)
+    return (gunichar) 0;
+
   iface = ATK_TEXT_GET_IFACE (text);
 
   if (iface->get_character_at_offset)
@@ -155,36 +219,78 @@ atk_text_get_character_at_offset (AtkText      *text,
  * @text: an #AtkText
  * @offset: position
  * @boundary_type: An #AtkTextBoundary
- * @startOffset: the start offset of the returned string.
- * @endOffset: the end offset of the returned string.
+ * @start_offset: the start offset of the returned string.
+ * @end_offset: the end offset of the returned string.
  *
  * Gets the specified text.
- * If the boundary type is ATK_TEXT_BOUNDARY_WORD_START or
- * ATK_TEXT_BOUNDARY_WORD_END part of a word may be returned.
- * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the start point 
- * will be the offset and will continue to the start of the next sentence. 
- * The first word may not be a complete word. Similarly for 
- * ATK_TEXT_BOUNDARY_SENTENCE_END, ATK_TEXT_BOUNDARY_LINE_START and
- * ATK_TEXT_BOUNDARY_LINE_END
- *
- * Returns: the text after @offset up to the specified @boundary_type.
+ *
+ * If the boundary_type if ATK_TEXT_BOUNDARY_CHAR the character after the 
+ * offset is returned.
+ *
+ * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START the returned string
+ * is from the word start after the offset to the next word start.
+ *
+ * The returned string will contain the word after the offset if the offset 
+ * is inside a word or if the offset is not inside a word.
+ *
+ * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_END the returned string
+ * is from the word end at or after the offset to the next work end.
+ *
+ * The returned string will contain the word after the offset if the offset
+ * is inside a word and will contain the word after the word after the offset
+ * if the offset is not inside a word.
+ *
+ * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the returned
+ * string is from the sentence start after the offset to the next sentence
+ * start.
+ *
+ * The returned string will contain the sentence after the offset if the offset
+ * is inside a sentence or if the offset is not inside a sentence.
+ *
+ * If the boundary_type is ATK_TEXT_BOUNDARY_SENTENCE_END the returned string
+ * is from the sentence end at or after the offset to the next sentence end.
+ *
+ * The returned string will contain the sentence after the offset if the offset
+ * is inside a sentence and will contain the sentence after the sentence
+ * after the offset if the offset is not inside a sentence.
+ *
+ * If the boundary type is ATK_TEXT_BOUNDARY_LINE_START the returned
+ * string is from the line start after the offset to the next line start.
+ *
+ * If the boundary_type is ATK_TEXT_BOUNDARY_LINE_END the returned string
+ * is from the line end at or after the offset to the next line start.
+ *
+ * Returns: the text after @offset bounded by the specified @boundary_type.
  **/
 gchar*
 atk_text_get_text_after_offset (AtkText          *text,
                                 gint             offset,
                                 AtkTextBoundary  boundary_type,
-                               gint             *startOffset,
-                               gint             *endOffset)
+                               gint             *start_offset,
+                               gint             *end_offset)
 {
   AtkTextIface *iface;
+  gint local_start_offset, local_end_offset;
+  gint *real_start_offset, *real_end_offset;
 
-  g_return_val_if_fail (text != NULL, NULL);
   g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
 
+  if (start_offset)
+    real_start_offset = start_offset;
+  else
+    real_start_offset = &local_start_offset;
+  if (end_offset)
+    real_end_offset = end_offset;
+  else
+    real_end_offset = &local_end_offset;
+
+  if (offset < 0)
+    return NULL;
+
   iface = ATK_TEXT_GET_IFACE (text);
 
   if (iface->get_text_after_offset)
-    return (*(iface->get_text_after_offset)) (text, offset, boundary_type, startOffset, endOffset);
+    return (*(iface->get_text_after_offset)) (text, offset, boundary_type, real_start_offset, real_end_offset);
   else
     return NULL;
 }
@@ -194,35 +300,85 @@ atk_text_get_text_after_offset (AtkText          *text,
  * @text: an #AtkText
  * @offset: position
  * @boundary_type: An #AtkTextBoundary
- * @startOffset: the start offset of the returned string.
- * @endOffset: the end offset of the returned string.
+ * @start_offset: the start offset of the returned string.
+ * @end_offset: the end offset of the returned string.
  *
  * Gets the specified text.
- * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START or 
- * ATK_TEXT_BOUNDARY_WORD_END a complete word is returned; 
- * if the boundary type is  ATK_TEXT_BOUNDARY_SENTENCE_START or 
- * ATK_TEXT_BOUNDARY_SENTENCE_END a complete sentence
- * is returned; if the boundary type is ATK_TEXT_BOUNDARY_LINE_START or
- * ATK_TEXT_BOUNDARY_LINE_END a complete line is returned.
- *
- * Returns: the text at @offset up to the specified @boundary_type.
+ *
+ * If the boundary_type if ATK_TEXT_BOUNDARY_CHAR the character at the
+ * offset is returned.
+ *
+ * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START 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 the boundary_type is ATK_TEXT_BOUNDARY_WORD_END the returned string
+ * is from the word end before the offset to the word end at or 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 after to the offset if the 
+ * offset is not inside a word.
+ *
+ * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START 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 the boundary_type is ATK_TEXT_BOUNDARY_SENTENCE_END the returned string
+ * is from the sentence end before the offset to the sentence end at or
+ * 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 after the offset 
+ * if the offset is not inside a sentence.
+ *
+ * If the boundary type is ATK_TEXT_BOUNDARY_LINE_START the returned
+ * string is from the line start at or before the offset to the line
+ * start after the offset.
+ *
+ * If the boundary_type is ATK_TEXT_BOUNDARY_LINE_END the returned string
+ * is from the line end before the offset to the line end at or after
+ * the offset.
+ *
+ * Returns: the text at @offset bounded by the specified @boundary_type.
  **/
 gchar*
 atk_text_get_text_at_offset (AtkText          *text,
                              gint             offset,
                              AtkTextBoundary  boundary_type,
-                            gint             *startOffset,
-                            gint             *endOffset)
+                            gint             *start_offset,
+                            gint             *end_offset)
 {
   AtkTextIface *iface;
+  gint local_start_offset, local_end_offset;
+  gint *real_start_offset, *real_end_offset;
 
-  g_return_val_if_fail (text != NULL, NULL);
   g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
 
+  if (start_offset)
+    real_start_offset = start_offset;
+  else
+    real_start_offset = &local_start_offset;
+  if (end_offset)
+    real_end_offset = end_offset;
+  else
+    real_end_offset = &local_end_offset;
+
+  if (offset < 0)
+    return NULL;
+
   iface = ATK_TEXT_GET_IFACE (text);
 
   if (iface->get_text_at_offset)
-    return (*(iface->get_text_at_offset)) (text, offset, boundary_type, startOffset, endOffset);
+    return (*(iface->get_text_at_offset)) (text, offset, boundary_type, real_start_offset, real_end_offset);
   else
     return NULL;
 }
@@ -232,36 +388,83 @@ atk_text_get_text_at_offset (AtkText          *text,
  * @text: an #AtkText
  * @offset: position
  * @boundary_type: An #AtkTextBoundary
- * @startOffset: the start offset of the returned string.
- * @endOffset: the end offset of the returned string.
+ * @start_offset: the start offset of the returned string.
+ * @end_offset: the end offset of the returned string.
  *
  * Gets the specified text.
- * If the boundary type is ATK_TEXT_BOUNDARY_WORD_START or
- * ATK_TEXT_BOUNDARY_WORD_END part of a word may be returned.
- * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the start point 
- * will be at the start of the sentence, and will continue to the offset. 
- * The last word may not be a complete word. Similarly for 
- * ATK_TEXT_BOUNDARY_SENTENCE_END, ATK_TEXT_BOUNDARY_LINE_START and
- * ATK_TEXT_BOUNDARY_LINE_END
- *
- * Returns: the text before @offset starting from the specified @boundary_type.
+ *
+ * If the boundary_type if ATK_TEXT_BOUNDARY_CHAR the character before the
+ * offset is returned.
+ *
+ * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START the returned string
+ * is from the word start before the word start before the offset to 
+ * the word start before the offset.
+ *
+ * The returned string will contain the word before the offset if the offset
+ * is inside a word and will contain the word before the word before the 
+ * offset if the offset is not inside a word.
+ *
+ * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_END the returned string
+ * is from the word end before the word end at or before the offset to the 
+ * word end at or before the offset.
+ *
+ * The returned string will contain the word before the offset if the offset
+ * is inside a word or if the offset is not inside a word.
+ *
+ * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the returned
+ * string is from the sentence start before the sentence start before 
+ * the offset to the sentence start before the offset.
+ *
+ * The returned string will contain the sentence before the offset if the 
+ * offset is inside a sentence and will contain the sentence before the 
+ * sentence before the offset if the offset is not inside a sentence.
+ *
+ * If the boundary_type is ATK_TEXT_BOUNDARY_SENTENCE_END the returned string
+ * is from the sentence end before the sentence end at or before the offset to 
+ * the sentence end at or before the offset.
+ *
+ * The returned string will contain the sentence before the offset if the 
+ * offset is inside a sentence or if the offset is not inside a sentence.
+ *
+ * If the boundary type is ATK_TEXT_BOUNDARY_LINE_START the returned
+ * string is from the line start before the line start ar or before the offset 
+ * to the line start ar or before the offset.
+ *
+ * If the boundary_type is ATK_TEXT_BOUNDARY_LINE_END the returned string
+ * is from the line end before the line end before the offset to the 
+ * line end before the offset.
+ *
+ * Returns: the text before @offset bounded by the specified @boundary_type.
  **/
 gchar*
 atk_text_get_text_before_offset (AtkText          *text,
                                  gint             offset,
                                  AtkTextBoundary  boundary_type,
-                                gint             *startOffset,
-                                gint             *endOffset)
+                                gint             *start_offset,
+                                gint             *end_offset)
 {
   AtkTextIface *iface;
+  gint local_start_offset, local_end_offset;
+  gint *real_start_offset, *real_end_offset;
 
-  g_return_val_if_fail (text != NULL, NULL);
   g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
 
+  if (start_offset)
+    real_start_offset = start_offset;
+  else
+    real_start_offset = &local_start_offset;
+  if (end_offset)
+    real_end_offset = end_offset;
+  else
+    real_end_offset = &local_end_offset;
+
+  if (offset < 0)
+    return NULL;
+
   iface = ATK_TEXT_GET_IFACE (text);
 
   if (iface->get_text_before_offset)
-    return (*(iface->get_text_before_offset)) (text, offset, boundary_type, startOffset, endOffset);
+    return (*(iface->get_text_before_offset)) (text, offset, boundary_type, real_start_offset, real_end_offset);
   else
     return NULL;
 }
@@ -279,59 +482,83 @@ atk_text_get_caret_offset (AtkText *text)
 {
   AtkTextIface *iface;
 
-  g_return_val_if_fail (text != NULL, -1);
-  g_return_val_if_fail (ATK_IS_TEXT (text), -1);
+  g_return_val_if_fail (ATK_IS_TEXT (text), 0);
 
   iface = ATK_TEXT_GET_IFACE (text);
 
   if (iface->get_caret_offset)
     return (*(iface->get_caret_offset)) (text);
   else
-    return -1;
+    return 0;
 }
 
 /**
  * atk_text_get_character_extents:
  * @text: an #AtkText
- * @offset: position
- * @x: x-position of character
- * @y: y-position of character
- * @length: length of character
- * @width: width of character
+ * @offset: The offset of the text character for which bounding information is required.
+ * @x: Pointer for the x cordinate of the bounding box.
+ * @y: Pointer for the y cordinate of the bounding box.
+ * @width: Pointer for the width of the bounding box
+ * @height: Pointer for the height of the bounding box.
  * @coords: specify whether coordinates are relative to the screen or widget window 
  *
- * Given an @offset, the @x, @y, @length, and @width values are filled
- * appropriately
+ * Get the bounding box containing the glyph representing the character at 
+ *     a particular text offset
  **/
 void
 atk_text_get_character_extents (AtkText *text,
                                 gint offset,
                                 gint *x,
                                 gint *y,
-                                gint *length,
                                 gint *width,
+                                gint *height,
                                AtkCoordType coords)
 {
   AtkTextIface *iface;
+  gint local_x, local_y, local_width, local_height;
+  gint *real_x, *real_y, *real_width, *real_height;
 
-  g_return_if_fail (text != NULL);
   g_return_if_fail (ATK_IS_TEXT (text));
 
+  if (x)
+    real_x = x;
+  else
+    real_x = &local_x;
+  if (y)
+    real_y = y;
+  else
+    real_y = &local_y;
+  if (width)
+    real_width = width;
+  else
+    real_width = &local_width;
+  if (height)
+    real_height = height;
+  else
+    real_height = &local_height;
+
+  *real_x = 0;
+  *real_y = 0;
+  *real_width = 0;
+  *real_height = 0;
+
+  if (offset < 0)
+    return;
   iface = ATK_TEXT_GET_IFACE (text);
 
   if (iface->get_character_extents)
-    (*(iface->get_character_extents)) (text, offset, x, y, length, width, coords);
-  else
+    (*(iface->get_character_extents)) (text, offset, real_x, real_y, real_width, real_height, coords);
+
+  if (*real_width <0)
     {
-      *x = 0;
-      *x = 0;
-      *length = 0;
-      *width = 0;
+      *real_x = *real_x + *real_width;
+      *real_width *= -1;
     }
 }
 
 /**
- *atk_text_ref_run_attributes:
+ *atk_text_get_run_attributes:
  *@text: an #AtkText
  *@offset: the offset at which to get the attributes
  *@start_offset: the address to put the start offset of the range
@@ -340,25 +567,69 @@ atk_text_get_character_extents (AtkText *text,
  *Creates an #AtkAttributeSet which consists of the attributes explicitly
  *set at the position @offset in the text. @start_offset and @end_offset are
  *set to the start and end of the range around @offset where the attributes are
- *invariant.
+ *invariant. See the enum AtkTextAttribute for types of text attributes that 
+ *can be returned. Note that other attributes may also be returned.
  *
  *Returns: an #AtkAttributeSet which contains the attributes explicitly set
- *at @offset
+ *at @offset. This #AtkAttributeSet should be freed by a call to
+ *atk_attribute_set_free().
  **/
-AtkAttributeSet* atk_text_ref_run_attributes              (AtkText          *text,
-                                                           gint             offset,
-                                                           gint             *start_offset,
-                                                           gint             *end_offset)
+AtkAttributeSet* 
+atk_text_get_run_attributes (AtkText          *text,
+                             gint             offset,
+                             gint             *start_offset,
+                             gint             *end_offset)
+{
+  AtkTextIface *iface;
+  gint local_start_offset, local_end_offset;
+  gint *real_start_offset, *real_end_offset;
+
+  g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
+
+  if (start_offset)
+    real_start_offset = start_offset;
+  else
+    real_start_offset = &local_start_offset;
+  if (end_offset)
+    real_end_offset = end_offset;
+  else
+    real_end_offset = &local_end_offset;
+
+  if (offset < 0)
+    return NULL;
+
+  iface = ATK_TEXT_GET_IFACE (text);
+
+  if (iface->get_run_attributes)
+    return (*(iface->get_run_attributes)) (text, offset, real_start_offset, real_end_offset);
+  else
+    return NULL;
+}
+
+/**
+ *atk_text_get_default_attributes:
+ *@text: an #AtkText
+ *
+ *Creates an #AtkAttributeSet which consists of the default values of
+ *attributes for the text. See the enum AtkTextAttribute for types of text 
+ *attributes that can be returned. Note that other attributes may also be 
+ *returned.
+ *
+ *Returns: an #AtkAttributeSet which contains the default values of attributes.
+ *at @offset. This #AtkAttributeSet should be freed by a call to
+ *atk_attribute_set_free().
+ */
+AtkAttributeSet* 
+atk_text_get_default_attributes (AtkText          *text)
 {
   AtkTextIface *iface;
 
-  g_return_val_if_fail (text != NULL, NULL);
   g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
 
   iface = ATK_TEXT_GET_IFACE (text);
 
-  if (iface->ref_run_attributes)
-    return (*(iface->ref_run_attributes)) (text, offset, start_offset, end_offset);
+  if (iface->get_default_attributes)
+    return (*(iface->get_default_attributes)) (text);
   else
     return NULL;
 }
@@ -376,7 +647,6 @@ atk_text_get_character_count (AtkText *text)
 {
   AtkTextIface *iface;
 
-  g_return_val_if_fail (text != NULL, -1);
   g_return_val_if_fail (ATK_IS_TEXT (text), -1);
 
   iface = ATK_TEXT_GET_IFACE (text);
@@ -410,7 +680,6 @@ atk_text_get_offset_at_point (AtkText *text,
 {
   AtkTextIface *iface;
 
-  g_return_val_if_fail (text != NULL, -1);
   g_return_val_if_fail (ATK_IS_TEXT (text), -1);
 
   iface = ATK_TEXT_GET_IFACE (text);
@@ -435,7 +704,6 @@ atk_text_get_n_selections (AtkText *text)
 {
   AtkTextIface *iface;
 
-  g_return_val_if_fail (text != NULL, -1);
   g_return_val_if_fail (ATK_IS_TEXT (text), -1);
 
   iface = ATK_TEXT_GET_IFACE (text);
@@ -462,20 +730,32 @@ atk_text_get_n_selections (AtkText *text)
  * Returns: the selected text.
  **/
 gchar*
-atk_text_get_selection (AtkText *text, gint selection_num,
-   gint *start_offset, gint *end_offset)
+atk_text_get_selection (AtkText *text, 
+                        gint    selection_num,
+                        gint    *start_offset,
+                        gint    *end_offset)
 {
   AtkTextIface *iface;
+  gint local_start_offset, local_end_offset;
+  gint *real_start_offset, *real_end_offset;
 
-  g_return_val_if_fail (text != NULL, NULL);
   g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
 
+  if (start_offset)
+    real_start_offset = start_offset;
+  else
+    real_start_offset = &local_start_offset;
+  if (end_offset)
+    real_end_offset = end_offset;
+  else
+    real_end_offset = &local_end_offset;
+
   iface = ATK_TEXT_GET_IFACE (text);
 
   if (iface->get_selection)
   {
     return (*(iface->get_selection)) (text, selection_num,
-       start_offset, end_offset);
+       real_start_offset, real_end_offset);
   }
   else
     return NULL;
@@ -492,12 +772,12 @@ atk_text_get_selection (AtkText *text, gint selection_num,
  * Returns: %TRUE if success, %FALSE otherwise
  **/
 gboolean
-atk_text_add_selection (AtkText *text, gint start_offset,
-   gint end_offset)
+atk_text_add_selection (AtkText *text, 
+                        gint    start_offset,
+                        gint    end_offset)
 {
   AtkTextIface *iface;
 
-  g_return_val_if_fail (text != NULL, FALSE);
   g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
 
   iface = ATK_TEXT_GET_IFACE (text);
@@ -522,11 +802,11 @@ atk_text_add_selection (AtkText *text, gint start_offset,
  * Returns: %TRUE if success, %FALSE otherwise
  **/
 gboolean
-atk_text_remove_selection (AtkText *text, gint selection_num)
+atk_text_remove_selection (AtkText *text, 
+                           gint    selection_num)
 {
   AtkTextIface *iface;
 
-  g_return_val_if_fail (text != NULL, FALSE);
   g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
 
   iface = ATK_TEXT_GET_IFACE (text);
@@ -553,12 +833,13 @@ atk_text_remove_selection (AtkText *text, gint selection_num)
  * Returns: %TRUE if success, %FALSE otherwise
  **/
 gboolean
-atk_text_set_selection (AtkText *text, gint selection_num,
-   gint start_offset, gint end_offset)
+atk_text_set_selection (AtkText *text, 
+                        gint    selection_num,
+                        gint    start_offset, 
+                        gint    end_offset)
 {
   AtkTextIface *iface;
 
-  g_return_val_if_fail (text != NULL, FALSE);
   g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
 
   iface = ATK_TEXT_GET_IFACE (text);
@@ -587,7 +868,6 @@ atk_text_set_caret_offset (AtkText *text,
 {
   AtkTextIface *iface;
 
-  g_return_val_if_fail (text != NULL, FALSE);
   g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
 
   iface = ATK_TEXT_GET_IFACE (text);
@@ -603,24 +883,440 @@ atk_text_set_caret_offset (AtkText *text,
 }
 
 /**
- * AtkAttributeSet_free:
+ * atk_text_get_range_extents:
+ * @text: an #AtkText
+ * @start_offset: The offset of the first text character for which boundary 
+ *        information is required.
+ * @end_offset: The offset of the text character after the last character 
+ *        for which boundary information is required.
+ * @coord_type: Specify whether coordinates are relative to the screen or widget window.
+ * @rect: A pointer to a AtkTextRectangle which is filled in by this function.
+ *
+ * Get the bounding box for text within the specified range.
+ **/
+void
+atk_text_get_range_extents (AtkText          *text,
+                            gint             start_offset,
+                            gint             end_offset,
+                            AtkCoordType     coord_type,
+                            AtkTextRectangle *rect)
+{
+  AtkTextIface *iface;
+
+  g_return_if_fail (ATK_IS_TEXT (text));
+  g_return_if_fail (rect);
+
+  if (start_offset < 0 || start_offset >= end_offset)
+    return;
+  iface = ATK_TEXT_GET_IFACE (text);
+
+  if (iface->get_range_extents)
+    (*(iface->get_range_extents)) (text, start_offset, end_offset, coord_type, rect);
+  else
+    atk_text_real_get_range_extents (text, start_offset, end_offset, coord_type, rect);
+}
+
+/**
+ * atk_text_get_bounded_ranges:
+ * @text: an #AtkText
+ * @rect: An AtkTextRectagle giving the dimensions of the bounding box.
+ * @coord_type: Specify whether coordinates are relative to the screen or widget window.
+ * @x_clip_type: Specify the horizontal clip type.
+ * @y_clip_type: Specify the vertical clip type.
+ *
+ * Get the ranges of text in the specified bounding box.
+ *
+ * Returns: Array of AtkTextRange. The last element of the array returned 
+ *          by this function will be NULL.
+ **/
+AtkTextRange**
+atk_text_get_bounded_ranges (AtkText          *text,
+                             AtkTextRectangle *rect,
+                             AtkCoordType      coord_type,
+                             AtkTextClipType   x_clip_type,
+                             AtkTextClipType   y_clip_type)
+{
+  AtkTextIface *iface;
+
+  g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
+  g_return_val_if_fail (rect, NULL);
+
+  iface = ATK_TEXT_GET_IFACE (text);
+
+  if (iface->get_bounded_ranges)
+    return (*(iface->get_bounded_ranges)) (text, rect, coord_type, x_clip_type, y_clip_type);
+  else
+    return atk_text_real_get_bounded_ranges (text, rect, coord_type, x_clip_type, y_clip_type);
+}
+
+/**
+ * atk_attribute_set_free:
  * @attrib_set: The #AtkAttributeSet to free
  *
  * Frees the memory used by an #AtkAttributeSet, including all its
  * #AtkAttributes.
  **/
 void
-AtkAttributeSet_free(AtkAttributeSet *attrib_set)
+atk_attribute_set_free (AtkAttributeSet *attrib_set)
 {
-  gint index;
+  GSList *temp;
 
-  if (attrib_set == NULL)
-    return;
+  temp = attrib_set;
 
-  for (index = 0; index < g_slist_length(attrib_set); index++)
-  {
-    g_free(((AtkAttribute*) (g_slist_nth(attrib_set,index)->data))->name);
-    g_free(((AtkAttribute*) (g_slist_nth(attrib_set,index)->data))->value);
-  }
-  g_slist_free(attrib_set);
+  while (temp != NULL)
+    {
+      AtkAttribute *att;
+
+      att = temp->data;
+
+      g_free (att->name);
+      g_free (att->value);
+      g_free (att);
+      temp = temp->next;
+    }
+  g_slist_free (attrib_set);
+}
+
+/**
+ * atk_text_attribute_register:
+ * @name: a name string
+ *
+ * Associate @name with a new #AtkTextAttribute
+ *
+ * Returns: an #AtkTextAttribute associated with @name
+ **/
+AtkTextAttribute
+atk_text_attribute_register (const gchar *name)
+{
+  g_return_val_if_fail (name, ATK_TEXT_ATTR_INVALID);
+
+  if (!extra_attributes)
+    extra_attributes = g_ptr_array_new ();
+
+  g_ptr_array_add (extra_attributes, g_strdup (name));
+  return extra_attributes->len + ATK_TEXT_ATTR_LAST_DEFINED;
+}
+
+/**
+ * atk_text_attribute_get_name:
+ * @attr: The #AtkTextAttribute whose name is required
+ *
+ * Gets the name corresponding to the #AtkTextAttribute
+ *
+ * Returns: a string containing the name; this string should not be freed
+ **/
+G_CONST_RETURN gchar*
+atk_text_attribute_get_name (AtkTextAttribute attr)
+{
+  GTypeClass *type_class;
+  GEnumValue *value;
+  gchar *name = NULL;
+
+  type_class = g_type_class_ref (ATK_TYPE_TEXT_ATTRIBUTE);
+  g_return_val_if_fail (G_IS_ENUM_CLASS (type_class), NULL);
+
+  value = g_enum_get_value (G_ENUM_CLASS (type_class), attr);
+
+  if (value)
+    {
+      name = value->value_nick;
+    }
+  else
+    {
+      if (extra_attributes)
+        {
+          gint n = attr;
+
+          n -= ATK_TEXT_ATTR_LAST_DEFINED + 1;
+
+          if (n < extra_attributes->len)
+
+            name = g_ptr_array_index (extra_attributes, n);
+        }
+    }
+  g_type_class_unref (type_class);
+  return name;
+}
+
+/**
+ * atk_text_attribute_for_name:
+ * @name: a string which is the (non-localized) name of an ATK text attribute.
+ *
+ * Get the #AtkTextAttribute type corresponding to a text attribute name.
+ *
+ * Returns: the #AtkTextAttribute enumerated type corresponding to the specified
+name,
+ *          or #ATK_TEXT_ATTRIBUTE_INVALID if no matching text attribute is found.
+ **/
+AtkTextAttribute
+atk_text_attribute_for_name (const gchar *name)
+{
+  GTypeClass *type_class;
+  GEnumValue *value;
+  AtkTextAttribute type = ATK_TEXT_ATTR_INVALID;
+
+  g_return_val_if_fail (name, ATK_TEXT_ATTR_INVALID);
+
+  type_class = g_type_class_ref (ATK_TYPE_TEXT_ATTRIBUTE);
+  g_return_val_if_fail (G_IS_ENUM_CLASS (type_class), ATK_TEXT_ATTR_INVALID);
+
+  value = g_enum_get_value_by_nick (G_ENUM_CLASS (type_class), name);
+
+  if (value)
+    {
+      type = value->value;
+    }
+  else
+    {
+      gint i;
+
+      if (extra_attributes)
+        {
+          for (i = 0; i < extra_attributes->len; i++)
+            {
+              gchar *extra_attribute = (gchar *)g_ptr_array_index (extra_attributes, i);
+
+              g_return_val_if_fail (extra_attribute, ATK_TEXT_ATTR_INVALID);
+
+              if (strcmp (name, extra_attribute) == 0)
+                {
+                  type = i + 1 + ATK_TEXT_ATTR_LAST_DEFINED;
+                  break;
+                }
+            }
+        }
+    }
+  g_type_class_unref (type_class);
+
+  return type;
+}
+
+/**
+ * atk_text_attribute_get_value:
+ * @attr: The #AtkTextAttribute for which a value is required
+ * @index_: The index of the required value
+ *
+ * Gets the value for the index of the #AtkTextAttribute
+ *
+ * Returns: a string containing the value; this string should not be freed;
+ * NULL is returned if there are no values maintained for the attr value. 
+ **/
+G_CONST_RETURN gchar*
+atk_text_attribute_get_value (AtkTextAttribute attr,
+                              gint             index)
+{
+  switch (attr)
+    {
+    case ATK_TEXT_ATTR_INVISIBLE:
+    case ATK_TEXT_ATTR_EDITABLE:
+    case ATK_TEXT_ATTR_BG_FULL_HEIGHT:
+    case ATK_TEXT_ATTR_STRIKETHROUGH:
+    case ATK_TEXT_ATTR_BG_STIPPLE:
+    case ATK_TEXT_ATTR_FG_STIPPLE:
+      g_assert (index >= 0 && index < 2);
+      return bool[index];
+    case ATK_TEXT_ATTR_UNDERLINE:
+      g_assert (index >= 0 && index < 4);
+      return underline[index];
+    case ATK_TEXT_ATTR_WRAP_MODE:
+      g_assert (index >= 0 && index < 3);
+      return wrap_mode[index];
+    case ATK_TEXT_ATTR_DIRECTION:
+      g_assert (index >= 0 && index < 3);
+      return direction[index];
+    case ATK_TEXT_ATTR_JUSTIFICATION:
+      g_assert (index >= 0 && index < 3);
+      return justification[index];
+    case ATK_TEXT_ATTR_STRETCH:
+      g_assert (index >= 0 && index < 9);
+      return stretch[index];
+    case ATK_TEXT_ATTR_VARIANT:
+      g_assert (index >= 0 && index < 2);
+      return variant[index];
+    case ATK_TEXT_ATTR_STYLE:
+      g_assert (index >= 0 && index < 3);
+      return style[index];
+    default:
+      return NULL;
+   }
+}
+
+static void
+atk_text_rectangle_union (AtkTextRectangle *src1,
+                          AtkTextRectangle *src2,
+                          AtkTextRectangle *dest)
+{
+  gint dest_x, dest_y;
+
+  dest_x = MIN (src1->x, src2->x);
+  dest_y = MIN (src1->y, src2->y);
+  dest->width = MAX (src1->x + src1->width, src2->x + src2->width) - dest_x;
+  dest->height = MAX (src1->y + src1->height, src2->y + src2->height) - dest_y;
+  dest->x = dest_x;
+  dest->y = dest_y;
+}
+
+static gboolean
+atk_text_rectangle_contain (AtkTextRectangle *clip,
+                            AtkTextRectangle *bounds,
+                            AtkTextClipType  x_clip_type,
+                            AtkTextClipType  y_clip_type)
+{
+  gboolean x_min_ok, x_max_ok, y_min_ok, y_max_ok;
+
+  x_min_ok = (bounds->x >= clip->x) ||
+             ((bounds->x + bounds->width >= clip->x) &&
+              ((x_clip_type == ATK_TEXT_CLIP_NONE) ||
+               (x_clip_type == ATK_TEXT_CLIP_MAX)));
+
+  x_max_ok = (bounds->x + bounds->width <= clip->x + clip->width) ||
+             ((bounds->x <= clip->x + clip->width) &&
+              ((x_clip_type == ATK_TEXT_CLIP_NONE) ||
+               (x_clip_type == ATK_TEXT_CLIP_MIN)));
+
+  y_min_ok = (bounds->y >= clip->y) ||
+             ((bounds->y + bounds->height >= clip->y) &&
+              ((y_clip_type == ATK_TEXT_CLIP_NONE) ||
+               (y_clip_type == ATK_TEXT_CLIP_MAX)));
+
+  y_max_ok = (bounds->y + bounds->height <= clip->y + clip->height) ||
+             ((bounds->y <= clip->y + clip->height) &&
+              ((y_clip_type == ATK_TEXT_CLIP_NONE) ||
+               (y_clip_type == ATK_TEXT_CLIP_MIN)));
+
+  return (x_min_ok && x_max_ok && y_min_ok && y_max_ok);
+  
+}
+
+static void 
+atk_text_real_get_range_extents (AtkText           *text,
+                                 gint              start_offset,
+                                 gint              end_offset,
+                                 AtkCoordType      coord_type,
+                                 AtkTextRectangle  *rect)
+{
+  gint i;
+  AtkTextRectangle cbounds, bounds;
+
+  atk_text_get_character_extents (text, start_offset,
+                                  &bounds.x, &bounds.y,
+                                  &bounds.width, &bounds.height,
+                                  coord_type);
+
+  for (i = start_offset + 1; i < end_offset; i++)
+    {
+      atk_text_get_character_extents (text, i,
+                                      &cbounds.x, &cbounds.y, 
+                                      &cbounds.width, &cbounds.height, 
+                                      coord_type);
+      atk_text_rectangle_union (&bounds, &cbounds, &bounds);
+    }
+
+  rect->x = bounds.x;
+  rect->y = bounds.y;
+  rect->width = bounds.width;
+  rect->height = bounds.height;
+}
+
+static AtkTextRange**
+atk_text_real_get_bounded_ranges (AtkText          *text,
+                                  AtkTextRectangle *rect,
+                                  AtkCoordType     coord_type,
+                                  AtkTextClipType  x_clip_type,
+                                  AtkTextClipType  y_clip_type)
+{
+  gint bounds_min_offset, bounds_max_offset;
+  gint min_line_start, min_line_end;
+  gint max_line_start, max_line_end;
+  gchar *line;
+  gint curr_offset;
+  gint offset;
+  gint num_ranges = 0;
+  gint range_size = 1;
+  AtkTextRectangle cbounds;
+  AtkTextRange **range;
+
+  range = NULL;
+  bounds_min_offset = atk_text_get_offset_at_point (text, rect->x, rect->y, coord_type);
+  bounds_max_offset = atk_text_get_offset_at_point (text, rect->x + rect->width, rect->y + rect->height, coord_type);
+
+  if (bounds_min_offset == 0 &&
+      bounds_min_offset == bounds_max_offset)
+    return NULL;
+
+  line = atk_text_get_text_at_offset (text, bounds_min_offset, 
+                                      ATK_TEXT_BOUNDARY_LINE_START,
+                                      &min_line_start, &min_line_end);
+  g_free (line);
+  line = atk_text_get_text_at_offset (text, bounds_max_offset, 
+                                      ATK_TEXT_BOUNDARY_LINE_START,
+                                      &max_line_start, &max_line_end);
+  g_free (line);
+  bounds_min_offset = MIN (min_line_start, max_line_start);
+  bounds_max_offset = MAX (min_line_end, max_line_end);
+
+  curr_offset = bounds_min_offset;
+  while (curr_offset < bounds_max_offset)
+    {
+      offset = curr_offset;
+
+      while (curr_offset < bounds_max_offset)
+        {
+          atk_text_get_character_extents (text, curr_offset,
+                                          &cbounds.x, &cbounds.y,
+                                          &cbounds.width, &cbounds.height,
+                                          coord_type);
+          if (!atk_text_rectangle_contain (rect, &cbounds, x_clip_type, y_clip_type))
+           break;
+          curr_offset++;
+        }
+      if (curr_offset > offset)
+        {
+          AtkTextRange *one_range = g_new (AtkTextRange, 1);
+
+          one_range->start_offset = offset;
+          one_range->end_offset = curr_offset;
+          one_range->content = atk_text_get_text (text, offset, curr_offset);
+          atk_text_get_range_extents (text, offset, curr_offset, coord_type, &one_range->bounds);
+
+          if (num_ranges >= range_size - 1)
+            {
+              range_size *= 2;
+              range = g_realloc (range, range_size * sizeof (gpointer));
+            }
+          range[num_ranges] = one_range;
+          num_ranges++; 
+        }   
+      curr_offset++;
+      if (range)
+        range[num_ranges] = NULL;
+    }
+  return range;
+}
+
+/**
+ * atk_text_free_ranges:
+ * @ranges: A pointer to an array of  #AtkTextRange which is to be freed.
+ *
+ * Frees the memory associated with an array of AtkTextRange. It is assumed
+ * that the array was returned by the function atk_text_get_bounded_ranges
+ * and is NULL terminated.
+ **/
+void
+atk_text_free_ranges (AtkTextRange **ranges)
+{
+  if (ranges)
+    {
+      while (*ranges)
+        {
+          AtkTextRange *range;
+
+          range = *ranges;
+          *ranges++;
+          g_free (range->content);
+          g_free (ranges);
+        }
+      g_free (ranges);
+    }
 }