2008-07-21 Mark Doffman <mark.doffman@codethink.co.uk>
[platform/core/uifw/at-spi2-atk.git] / cspi / spi_text.c
index c63c116..5339a39 100644 (file)
@@ -82,28 +82,37 @@ get_accessible_text_clip_type (AccessibleTextClipType type)
     }
 }
 
+typedef struct
+{
+  dbus_int32_t startOffset;
+  dbus_int32_t endOffset;
+  char *content;
+} Accessibility_Range;
+
 static AccessibleTextRange **
-get_accessible_text_ranges_from_range_seq (Accessibility_Text_RangeList *range_seq)
+get_accessible_text_ranges_from_range_seq (GArray *range_seq)
 {
   AccessibleTextRange **ranges = NULL;
   AccessibleTextRange *array = NULL;
   int i;
-  if (range_seq && range_seq->_length > 0) 
+  if (range_seq && range_seq->len > 0) 
     {
-      ranges = g_new0 (AccessibleTextRange *, range_seq->_length + 1);
+      ranges = g_new0 (AccessibleTextRange *, range_seq->len + 1);
     }
-  array = g_new0 (AccessibleTextRange, range_seq->_length);
-  for (i = 0; i < range_seq->_length; i++) 
+  array = g_new0 (AccessibleTextRange, range_seq->len);
+  for (i = 0; i < range_seq->len; i++) 
     {
+      Accessibility_Range *r = g_array_index (range_seq, Accessibility_Range *, i);
       AccessibleTextRange *range;
       range = &array[i];
-      range->start = range_seq->_buffer[i].startOffset;
-      range->end = range_seq->_buffer[i].endOffset;
-      range->contents = CORBA_string_dup (range_seq->_buffer[i].content);
+      range->start = r->startOffset;
+      range->end = r->endOffset;
+      range->contents = g_strdup (r->content);
       ranges[i] = range;
     }
   ranges[i] = NULL; /* null-terminated list! */
-  CORBA_free (range_seq);
+  // TODO: Figure out whether we're leaking strings
+  g_array_free (range_seq, TRUE);
 
   return ranges;
 }
@@ -145,11 +154,11 @@ AccessibleText_unref (AccessibleText *obj)
 long
 AccessibleText_getCharacterCount (AccessibleText *obj)
 {
-  long retval;
+  dbus_int32_t retval;
 
   cspi_return_val_if_fail (obj != NULL, -1);
 
-  retval = Accessibility_Text__get_characterCount (CSPI_OBJREF (obj), cspi_ev ());
+  cspi_dbus_get_property (obj, spi_interface_text, "characterCount", NULL, "i", &retval);
 
   cspi_return_val_if_ev ("getCharacterCount", -1);
 
@@ -175,14 +184,11 @@ AccessibleText_getText (AccessibleText *obj,
                         long int endOffset)
 {
   char *retval;
+  dbus_int32_t d_startOffset = startOffset, d_endOffset = endOffset;
 
   cspi_return_val_if_fail (obj != NULL, NULL);
 
-  retval =
-    Accessibility_Text_getText (CSPI_OBJREF (obj),
-                               startOffset,
-                               endOffset,
-                               cspi_ev ());
+  cspi_dbus_call (obj, spi_interface_text, "getText", NULL, "ii=>s", startOffset, endOffset, &retval);
 
   cspi_return_val_if_ev ("getText", NULL);
 
@@ -200,12 +206,11 @@ AccessibleText_getText (AccessibleText *obj,
 long
 AccessibleText_getCaretOffset (AccessibleText *obj)
 {
-  long retval;
+  dbus_int32_t retval;
 
   cspi_return_val_if_fail (obj != NULL, -1);
 
-  retval =
-    Accessibility_Text__get_caretOffset (CSPI_OBJREF (obj), cspi_ev ());
+  cspi_dbus_get_property (obj, spi_interface_text, "caretOffset", NULL, "i", &retval);
 
   cspi_return_val_if_ev ("getCaretOffset", -1);
 
@@ -237,7 +242,8 @@ AccessibleText_getAttributes (AccessibleText *obj,
                              long int *startOffset,
                              long int *endOffset)
 {
-  CORBA_long retStartOffset, retEndOffset;
+  dbus_int32_t d_offset = offset;
+  dbus_int32_t retStartOffset, retEndOffset;
   char *retval;        
 
   if (obj == NULL)
@@ -246,11 +252,7 @@ AccessibleText_getAttributes (AccessibleText *obj,
       return NULL;
     }
 
-  retval = Accessibility_Text_getAttributes (CSPI_OBJREF (obj),
-                                     offset,
-                                     &retStartOffset,
-                                     &retEndOffset,
-                                     cspi_ev ());
+  cspi_dbus_call (obj, spi_interface_text, "getAttributes", NULL, "i=>iis", d_offset, &retStartOffset, &retEndOffset, &retval);
 
   if (!cspi_check_ev ("getAttributes"))
     {
@@ -267,6 +269,46 @@ AccessibleText_getAttributes (AccessibleText *obj,
 }
 
 /**
+ * AccessibleText_getDefaultAttributes:
+ * @obj: a pointer to the #AccessibleText object to query.
+ *
+ * Get the default attributes applied to an #AccessibleText
+ *          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 #AccessibleText_getAttributes
+ *          describes the entire set of text attributes over a range.
+ *
+ * @Since: AT-SPI 1.4
+ *
+ * Returns: a text string describing the default attributes 
+ *          applied to a text object, (exclusive of explicitly-set
+ *          attributes), encoded as UTF-8.
+ **/
+char *
+AccessibleText_getDefaultAttributes (AccessibleText *obj)
+{
+  char *retval;        
+
+  if (obj == NULL)
+    {
+      return NULL;
+    }
+
+  cspi_dbus_call (obj, spi_interface_text, "getAttributes", NULL, "=>s", &retval);
+
+  if (!cspi_check_ev ("getAttributes"))
+    {
+      retval = NULL;
+    }
+
+  return retval;
+}
+
+/**
  * AccessibleText_setCaretOffset:
  * @obj: a pointer to the #AccessibleText object on which to operate.
  * @newOffset: the offset to which the text caret is to be moved.
@@ -279,13 +321,12 @@ SPIBoolean
 AccessibleText_setCaretOffset (AccessibleText *obj,
                                long int newOffset)
 {
-  SPIBoolean retval;
+  dbus_int32_t d_newOffset = newOffset;
+  dbus_bool_t retval;
 
   cspi_return_val_if_fail (obj != NULL, FALSE);
 
-  retval =
-    Accessibility_Text_setCaretOffset (CSPI_OBJREF (obj),
-                                      newOffset, cspi_ev ());
+  cspi_dbus_call (obj, spi_interface_text, "setCaretOffset", NULL, "i=>b", d_newOffset, &retval);
 
   cspi_return_val_if_ev ("setCaretOffset", FALSE);
 
@@ -320,8 +361,10 @@ AccessibleText_getTextBeforeOffset (AccessibleText *obj,
                                    long int *startOffset,
                                    long int *endOffset)
 {
+  dbus_int32_t d_offset = offset;
+  dbus_uint32_t d_type = type;
+  dbus_int32_t retStartOffset, retEndOffset;
   char *retval;
-  CORBA_long retStartOffset, retEndOffset;
 
   if (obj == NULL)
     {
@@ -329,11 +372,7 @@ AccessibleText_getTextBeforeOffset (AccessibleText *obj,
       return NULL;
     }
 
-  retval = Accessibility_Text_getTextBeforeOffset (CSPI_OBJREF (obj),
-                                          offset,
-                       get_accessible_text_boundary_type (type),
-                                          &retStartOffset, &retEndOffset,
-                                          cspi_ev ());
+  cspi_dbus_call (obj, spi_interface_text, "getTextBeforeOffset", NULL, "iu=>iis", d_offset, d_type, &retStartOffset, &retEndOffset, &retval);
   if (!cspi_check_ev ("getTextBeforeOffset"))
     {
       *startOffset = *endOffset = -1;
@@ -374,9 +413,10 @@ AccessibleText_getTextAtOffset (AccessibleText *obj,
                                AccessibleTextBoundaryType type,
                                long int *startOffset, long int *endOffset)
 {
-  CORBA_long corbaStartOffset;
-  CORBA_long corbaEndOffset;
-  char      *retval;
+  dbus_int32_t d_offset = offset;
+  dbus_uint32_t d_type = type;
+  dbus_int32_t retStartOffset, retEndOffset;
+  char *retval;
 
   if (obj == NULL)
     {
@@ -384,12 +424,7 @@ AccessibleText_getTextAtOffset (AccessibleText *obj,
       return NULL;
     }
 
-  retval = Accessibility_Text_getTextAtOffset (CSPI_OBJREF (obj),
-                                              offset,
-                         get_accessible_text_boundary_type (type),
-                                              &corbaStartOffset,
-                                              &corbaEndOffset,
-                                              cspi_ev ());
+  cspi_dbus_call (obj, spi_interface_text, "getTextAtOffset", NULL, "iu=>iis", d_offset, d_type, &retStartOffset, &retEndOffset, &retval);
 
   if (!cspi_check_ev ("getTextAtOffset"))
     {
@@ -398,8 +433,8 @@ AccessibleText_getTextAtOffset (AccessibleText *obj,
     }
   else
     {
-      *startOffset = corbaStartOffset;
-      *endOffset   = corbaEndOffset;
+      *startOffset = retStartOffset;
+      *endOffset   = retEndOffset;
     }
   return retval;
 }
@@ -431,8 +466,10 @@ AccessibleText_getTextAfterOffset (AccessibleText *obj,
                                   AccessibleTextBoundaryType type,
                                   long int *startOffset, long int *endOffset)
 {
+  dbus_int32_t d_offset = offset;
+  dbus_uint32_t d_type = type;
+  dbus_int32_t retStartOffset, retEndOffset;
   char *retval;
-  CORBA_long retStartOffset, retEndOffset;
 
   if (obj == NULL)
     {
@@ -440,11 +477,7 @@ AccessibleText_getTextAfterOffset (AccessibleText *obj,
       return NULL;
     }
 
-  retval = Accessibility_Text_getTextAfterOffset (CSPI_OBJREF (obj),
-                                          offset,
-                            get_accessible_text_boundary_type (type),
-                                          &retStartOffset, &retEndOffset,
-                                          cspi_ev ());
+  cspi_dbus_call (obj, spi_interface_text, "getTextAfterOffset", NULL, "iu=>iis", d_offset, d_type, &retStartOffset, &retEndOffset, &retval);
 
   if (!cspi_check_ev ("getTextAfterOffset"))
     {
@@ -476,14 +509,12 @@ unsigned long
 AccessibleText_getCharacterAtOffset (AccessibleText *obj,
                                      long int offset)
 {
-  long retval;
+  dbus_int32_t d_offset = offset;
+  dbus_int32_t retval;
 
   cspi_return_val_if_fail (obj != NULL, -1);
 
-  retval =
-    Accessibility_Text_getCharacterAtOffset (CSPI_OBJREF (obj),
-                                            offset,
-                                            cspi_ev ());
+  cspi_dbus_call (obj, spi_interface_text, "getCharacterAtOffset", NULL, "i=>i", d_offset, &retval);
 
   cspi_return_val_if_ev ("getCharacterAtOffset", -1);
 
@@ -518,7 +549,9 @@ AccessibleText_getCharacterExtents (AccessibleText *obj,
                                     long int *height,
                                    AccessibleCoordType type)
 {
-  CORBA_long retX, retY, retWidth, retHeight;
+  dbus_int32_t d_offset = offset;
+  dbus_uint16_t d_type = type;
+  dbus_int32_t retX, retY, retWidth, retHeight;
 
   if (obj == NULL)
     {
@@ -527,13 +560,7 @@ AccessibleText_getCharacterExtents (AccessibleText *obj,
       return;
     }
 
-  Accessibility_Text_getCharacterExtents (CSPI_OBJREF (obj),
-                                         offset,
-                                         &retX,
-                                         &retY,
-                                         &retWidth,
-                                         &retHeight,
-                                         type, cspi_ev ());
+  cspi_dbus_call (obj, spi_interface_text, "getCharacterExtents", NULL, "in=>iiii", d_offset, d_type, &retX, &retY, &retWidth, &retHeight);
 
   if (!cspi_check_ev ("getCharacterExtents"))
     {
@@ -569,15 +596,13 @@ AccessibleText_getOffsetAtPoint (AccessibleText *obj,
                                  long int y,
                                 AccessibleCoordType type)
 {
-  long retval;
+  dbus_int32_t d_x = x, d_y = y;
+  dbus_uint16_t d_type = type;
+  dbus_int32_t retval;
 
   cspi_return_val_if_fail (obj != NULL, -1);
 
-  retval =
-    Accessibility_Text_getOffsetAtPoint (CSPI_OBJREF (obj),
-                                        x,
-                                        y,
-                                        type, cspi_ev ());
+  cspi_dbus_call (obj, spi_interface_text, "getOffsetAtPoint", NULL, "iin=>i", d_x, d_y, d_type, &retval);
 
   cspi_return_val_if_ev ("getOffsetAtPoint", -1);
 
@@ -604,6 +629,7 @@ AccessibleText_getOffsetAtPoint (AccessibleText *obj,
  *
  * Get the bounding box for text within a range in an  #AccessibleText object.
  *
+ * @Since: AT-SPI 1.2
  **/
 void
 AccessibleText_getRangeExtents (AccessibleText *obj,
@@ -615,7 +641,9 @@ AccessibleText_getRangeExtents (AccessibleText *obj,
                                long int *height,
                                AccessibleCoordType type)
 {
-  CORBA_long retX, retY, retWidth, retHeight;
+  dbus_int32_t d_startOffset = startOffset, d_endOffset = endOffset;
+  dbus_int16_t d_type = type;
+  dbus_int32_t retX, retY, retWidth, retHeight;
 
   if (obj == NULL)
     {
@@ -624,14 +652,7 @@ AccessibleText_getRangeExtents (AccessibleText *obj,
       return;
     }
 
-  Accessibility_Text_getRangeExtents (CSPI_OBJREF (obj),
-                                     startOffset,
-                                     endOffset,
-                                     &retX,
-                                     &retY,
-                                     &retWidth,
-                                     &retHeight,
-                                     type, cspi_ev ());
+  cspi_dbus_call (obj, spi_interface_text, "getRangeExtents", NULL, "iin=>iiii", d_startOffset, d_endOffset, d_type, &retX, &retY, &retWidth, &retHeight);
 
   if (!cspi_check_ev ("getRangeExtents"))
     {
@@ -664,6 +685,8 @@ AccessibleText_getRangeExtents (AccessibleText *obj,
  * Get the ranges of text from an #AccessibleText object which lie within the
  *          bounds defined by (@x, @y) and (@x+@width, @y+@height).  
  *
+ * @Since: AT-SPI 1.2
+ *
  * Returns: a null-terminated list of pointers to AccessibleTextRange structs 
  *          detailing the bounded text.
  **/
@@ -677,17 +700,14 @@ AccessibleText_getBoundedRanges (AccessibleText *obj,
                                 AccessibleTextClipType clipTypeX,
                                 AccessibleTextClipType clipTypeY)
 {
-  Accessibility_Text_RangeList *range_seq;
+  dbus_int32_t d_x = x, d_y = y, d_width = width, d_height = height;
+  dbus_uint16_t d_type = type;
+  dbus_uint32_t d_clipTypeX = clipTypeX, d_clipTypeY = clipTypeY;
+  GArray *range_seq;
 
   cspi_return_val_if_fail (obj != NULL, NULL);
 
-  range_seq =
-    Accessibility_Text_getBoundedRanges (CSPI_OBJREF (obj), 
-                                        x, y, width, height,
-                                        type, 
-                                        get_accessible_text_clip_type (clipTypeX), 
-                                        get_accessible_text_clip_type (clipTypeY),
-                                        cspi_ev ());
+  cspi_dbus_call (obj, spi_interface_text, "getBoundedRanges", NULL, "iiiinuu=>a(iisv)", d_x, d_y, d_width, d_height, d_type, d_clipTypeX, d_clipTypeY, &range_seq);
 
   cspi_return_val_if_ev ("getBoundedRanges", NULL); 
  
@@ -701,6 +721,8 @@ AccessibleText_getBoundedRanges (AccessibleText *obj,
  * Free the memory used by a list of AccessibleTextRange structs.
  * The argument passed in should be an array of pointers 
  * AccessibleTextRange structs.  
+ *
+ * @Since: AT-SPI 1.2
  **/
 void
 AccessibleTextRange_freeRanges (AccessibleTextRange **ranges)
@@ -724,12 +746,11 @@ AccessibleTextRange_freeRanges (AccessibleTextRange **ranges)
 long
 AccessibleText_getNSelections (AccessibleText *obj)
 {
-  long retval;
+  dbus_int32_t retval;
 
   cspi_return_val_if_fail (obj != NULL, -1);
 
-  retval =
-    Accessibility_Text_getNSelections (CSPI_OBJREF (obj), cspi_ev ());
+  cspi_dbus_call (obj, spi_interface_text, "getNSelections", NULL, "i", &retval);
 
   cspi_return_val_if_ev ("getNSelections", -1);
 
@@ -754,7 +775,8 @@ AccessibleText_getSelection (AccessibleText *obj,
                             long int *startOffset,
                             long int *endOffset)
 {
-  CORBA_long retStartOffset, retEndOffset;
+  dbus_int32_t d_selectionNum = selectionNum;
+  dbus_int32_t retStartOffset, retEndOffset;
 
   if (obj == NULL)
     {
@@ -762,10 +784,7 @@ AccessibleText_getSelection (AccessibleText *obj,
       return;
     }
 
-  Accessibility_Text_getSelection (CSPI_OBJREF (obj),
-                                  selectionNum,
-                                  &retStartOffset, &retEndOffset,
-                                  cspi_ev ());
+  cspi_dbus_call (obj, spi_interface_text, "getSelection", NULL, "i=>ii", d_selectionNum, &retStartOffset, &retEndOffset);
 
   if (!cspi_check_ev ("getSelection"))
     {
@@ -792,14 +811,12 @@ SPIBoolean
 AccessibleText_addSelection (AccessibleText *obj,
                             long int startOffset, long int endOffset)
 {
-  SPIBoolean retval;
+  dbus_int32_t d_startOffset = startOffset, d_endOffset = endOffset;
+  dbus_bool_t retval;
 
   cspi_return_val_if_fail (obj != NULL, FALSE);
 
-  retval =
-    Accessibility_Text_addSelection (
-      CSPI_OBJREF (obj), startOffset,
-      endOffset, cspi_ev ());
+  cspi_dbus_call (obj, spi_interface_text, "addSelection", NULL, "ii=>b", d_startOffset, d_endOffset, &retval);
 
   cspi_return_val_if_ev ("addSelection", FALSE);
 
@@ -820,13 +837,12 @@ SPIBoolean
 AccessibleText_removeSelection (AccessibleText *obj,
                                long int selectionNum)
 {
-  SPIBoolean retval;
+  dbus_int32_t d_selectionNum = selectionNum;
+  dbus_bool_t retval;
 
   cspi_return_val_if_fail (obj != NULL, FALSE);
 
-  retval =
-    Accessibility_Text_removeSelection (
-      CSPI_OBJREF (obj), selectionNum, cspi_ev ());
+  cspi_dbus_call (obj, spi_interface_text, "removeSelection", NULL, "i=>b", d_selectionNum, &retval);
 
   cspi_return_val_if_ev ("removeSelection", FALSE);
 
@@ -851,14 +867,12 @@ AccessibleText_setSelection (AccessibleText *obj,
                             long int startOffset,
                             long int endOffset)
 {
-  SPIBoolean retval;
+  dbus_int32_t d_selectionNum = selectionNum, d_startOffset = startOffset, d_endOffset = endOffset;
+  dbus_bool_t retval;
 
   cspi_return_val_if_fail (obj != NULL, FALSE);
 
-  retval = Accessibility_Text_setSelection (CSPI_OBJREF (obj),
-                                  selectionNum,
-                                  startOffset,
-                                  endOffset, cspi_ev ());
+  cspi_dbus_call (obj, spi_interface_text, "setSelection", NULL, "iii=>b", d_selectionNum, d_startOffset, d_endOffset, &retval);
 
   cspi_return_val_if_ev ("setSelection", FALSE);
 
@@ -866,4 +880,88 @@ AccessibleText_setSelection (AccessibleText *obj,
 }
 
 
+/**
+ * AccessibleText_getAttributeRun:
+ * @obj: a pointer to the #AccessibleText object to query.
+ * @offset: a long integer indicating the offset from which the attribute
+ *        search is based.
+ * @startOffset: a #long indicating the start of the desired text range.
+ * @endOffset: a #long indicating the first character past the desired range.
+ * @includeDefaults: 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.
+ *
+ *  @Since: AT-SPI 1.7
+ *
+ * Returns: the AttributeSet defined at offset, optionally including the 'default' attributes.
+ **/
+
+AccessibleAttributeSet *
+AccessibleText_getAttributeRun (AccessibleText *obj,
+                               long int offset,
+                               long int *startOffset,
+                               long int *endOffset,
+                               long int includeDefaults){
+
+  dbus_int32_t d_offset = offset;
+  dbus_bool_t d_includeDefaults = includeDefaults;
+  dbus_int32_t retStartOffset, retEndOffset;
+  AccessibleAttributeSet *retval;
+  GArray *attributes;
+
+  if (obj == NULL)
+  {
+       *startOffset = *endOffset = -1;
+       return NULL;
+  }
+
+  cspi_dbus_call (obj, spi_interface_text, "getAttributeRun", NULL, "ib=>iias", d_offset, d_includeDefaults, &retStartOffset, &retEndOffset, &attributes);
+
+  if (!cspi_check_ev ("getAttributeRun"))
+    {
+      *startOffset = *endOffset = -1;
+      retval = NULL;
+    }
+  else 
+  {
+      *startOffset = retStartOffset;
+      *endOffset   = retEndOffset;
+      retval =  _cspi_attribute_set_from_sequence (attributes);
+  }
+
+  return retval;
+                                    
+}
+
+/**
+ * AccessibleText_getDefaultAttributeSet:
+ * @obj: a pointer to the #AccessibleText object to query.
+ *
+ *
+ *  @Since: AT-SPI 1.7
+ *
+ * Returns: an AttributeSet containing the text attributes 
+ * which apply to all text in the object by virtue of the
+ * default settings of the document, view, or user agent; e.g.
+ * those attributes which are implied rather than explicitly 
+ * applied to the text object. For instance, an object whose 
+ * entire text content has been explicitly marked as 'bold' 
+ * will report the 'bold' attribute via getAttributeRun(), 
+ * whereas an object whose text weight is inspecified may 
+ * report the default or implied text weight in the default AttributeSet.
+ *
+ **/
+
+AccessibleAttributeSet *
+AccessibleText_getDefaultAttributeSet (AccessibleText *obj){
+   AccessibleAttributeSet *retval;
+   GArray *attributes;
+
+   cspi_return_val_if_fail (obj != NULL, NULL);
 
+  cspi_dbus_call (obj, spi_interface_text, "getDefaultAttributes", NULL, "as", &attributes);
+  
+  retval = _cspi_attribute_set_from_sequence (attributes);
+  return retval;
+}