2001-11-20 Michael Meeks <michael@ximian.com>
[platform/core/uifw/at-spi2-atk.git] / libspi / text.c
index 872f3d0..a1da102 100644 (file)
  * Boston, MA 02111-1307, USA.
  */
 
-/*
- * component.c : bonobo wrapper for accessible component implementation
- *
- */
-#include <config.h>
-#include <bonobo/Bonobo.h>
+/* text.c : implements the Text interface */
 
+#include <config.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <libspi/text.h>
 
-/*
- * This pulls the CORBA definitions for the "Accessibility::Accessible" server
- */
-#include <libspi/Accessibility.h>
+/* Our parent Gtk object type */
+#define PARENT_TYPE BONOBO_TYPE_OBJECT
 
-/*
- * This pulls the definition of the Text bonobo object
- */
-#include "text.h"
+/* A pointer to our parent object class */
+static GObjectClass *spi_text_parent_class;
 
-/*
- * Static function declarations
- */
+/* Static function declarations */
 
 static void
-text_class_init (TextClass *klass);
+accessibility_text_class_init (SpiTextClass *klass);
+
 static void
-text_init (Text *text);
+accessibility_text_init (SpiText *text);
+
 static void
-text_finalize (GObject *obj);
+accessibility_text_object_finalize (GObject *obj);
+
 static CORBA_string
 impl_getText (PortableServer_Servant _servant,
              const CORBA_long startOffset,
              const CORBA_long endOffset,
              CORBA_Environment * ev);
-CORBA_string
+
+static CORBA_string
 impl_getTextAfterOffset (PortableServer_Servant _servant,
                         const CORBA_long offset,
                         const
@@ -65,14 +61,16 @@ impl_getTextAfterOffset (PortableServer_Servant _servant,
 static CORBA_string
 impl_getTextAtOffset (PortableServer_Servant _servant,
                      const CORBA_long offset,
-                     const Accessibility_TEXT_BOUNDARY_TYPE
-                     type, CORBA_long * startOffset,
+                     const Accessibility_TEXT_BOUNDARY_TYPE type,
+                     CORBA_long * startOffset,
                      CORBA_long * endOffset,
                      CORBA_Environment * ev);
-static CORBA_wchar
+
+static CORBA_unsigned_long
 impl_getCharacterAtOffset (PortableServer_Servant _servant,
                           const CORBA_long offset,
                           CORBA_Environment * ev);
+
 static CORBA_string
 impl_getTextBeforeOffset (PortableServer_Servant _servant,
                          const CORBA_long offset,
@@ -81,15 +79,18 @@ impl_getTextBeforeOffset (PortableServer_Servant _servant,
                          type, CORBA_long * startOffset,
                          CORBA_long * endOffset,
                          CORBA_Environment * ev);
+
 static CORBA_long
 impl__get_caretOffset (PortableServer_Servant _servant,
                     CORBA_Environment * ev);
+
 static CORBA_string
 impl_getAttributes (PortableServer_Servant _servant,
                       const CORBA_long offset,
                       CORBA_long * startOffset,
                       CORBA_long * endOffset,
                       CORBA_Environment * ev);
+
 static void 
 impl_getCharacterExtents (PortableServer_Servant _servant,
                          const CORBA_long offset, CORBA_long * x,
@@ -97,63 +98,67 @@ impl_getCharacterExtents (PortableServer_Servant _servant,
                          CORBA_long * height,
                          const CORBA_short coordType,
                          CORBA_Environment * ev);
+
 static CORBA_long
 impl__get_characterCount (PortableServer_Servant _servant,
                        CORBA_Environment * ev);
+
 static CORBA_long
 impl_getOffsetAtPoint (PortableServer_Servant _servant,
                       const CORBA_long x, const CORBA_long y,
                       const CORBA_short coordType,
                       CORBA_Environment * ev);
+
 static CORBA_long
 impl_getNSelections (PortableServer_Servant _servant,
                     CORBA_Environment * ev);
+
 static void 
 impl_getSelection (PortableServer_Servant _servant,
                   const CORBA_long selectionNum,
                   CORBA_long * startOffset, CORBA_long * endOffset,
                   CORBA_Environment * ev);
+
 static CORBA_boolean
 impl_addSelection (PortableServer_Servant _servant,
                   const CORBA_long startOffset,
                   const CORBA_long endOffset,
                   CORBA_Environment * ev);
+
 static CORBA_boolean
 impl_removeSelection (PortableServer_Servant _servant,
                      const CORBA_long selectionNum,
                      CORBA_Environment * ev);
+
 static CORBA_boolean
 impl_setSelection (PortableServer_Servant _servant,
                   const CORBA_long selectionNum,
                   const CORBA_long startOffset,
                   const CORBA_long endOffset,
                   CORBA_Environment * ev);
+
 static CORBA_boolean
 impl_setCaretOffset (PortableServer_Servant _servant,
                     const CORBA_long value,
-                    CORBA_Environment * ev);
-  
-
-static GObjectClass *parent_class;
+                    CORBA_Environment * ev); 
 
 GType
-text_get_type (void)
+accessibility_text_get_type (void)
 {
   static GType type = 0;
 
   if (!type) {
     static const GTypeInfo tinfo = {
-      sizeof (TextClass),
+      sizeof (SpiTextClass),
       (GBaseInitFunc) NULL,
       (GBaseFinalizeFunc) NULL,
-      (GClassInitFunc) text_class_init,
+      (GClassInitFunc) accessibility_text_class_init,
       (GClassFinalizeFunc) NULL,
       NULL, /* class data */
-      sizeof (Text),
+      sizeof (SpiText),
       0, /* n preallocs */
-      (GInstanceInitFunc) text_init,
-                        NULL /* value table */
+      (GInstanceInitFunc) accessibility_text_init,
+      NULL /* value table */
     };
 
     /*
@@ -162,26 +167,25 @@ text_get_type (void)
      * use bonobo_type_unique.
      */
     type = bonobo_type_unique (
-                              BONOBO_OBJECT_TYPE,
+                              PARENT_TYPE,
                               POA_Accessibility_Text__init,
                               NULL,
-                              G_STRUCT_OFFSET (TextClass, epv),
+                              G_STRUCT_OFFSET (SpiTextClass, epv),
                               &tinfo,
-                              "AccessibleText");
+                              "SpiAccessibleText");
   }
 
   return type;
 }
 
 static void
-text_class_init (TextClass *klass)
+accessibility_text_class_init (SpiTextClass *klass)
 {
   GObjectClass * object_class = (GObjectClass *) klass;
   POA_Accessibility_Text__epv *epv = &klass->epv;
-  parent_class = g_type_class_peek_parent (klass);
-
-  object_class->finalize = text_finalize;
+  spi_text_parent_class = g_type_class_peek_parent (klass);
 
+  object_class->finalize = accessibility_text_object_finalize;
 
   /* Initialize epv table */
 
@@ -204,24 +208,24 @@ text_class_init (TextClass *klass)
 }
 
 static void
-text_init (Text *text)
+accessibility_text_init (SpiText *text)
 {
 }
 
 static void
-text_finalize (GObject *obj)
+accessibility_text_object_finalize (GObject *obj)
 {
-  Text *text = TEXT (obj);
+  SpiText *text = SPI_TEXT (obj);
   g_object_unref (text->atko);
   text->atko = NULL;
-  parent_class->finalize (obj);
+  spi_text_parent_class->finalize (obj);
 }
 
-Text *
-text_interface_new (AtkObject *obj)
+SpiText *
+spi_text_interface_new (AtkObject *obj)
 {
-  Text *new_text = 
-    TEXT(g_object_new (TEXT_TYPE, NULL));
+  SpiText *new_text = 
+    SPI_TEXT (g_object_new (accessibility_text_get_type (), NULL));
   new_text->atko = obj;
   g_object_ref (obj);
   return new_text;
@@ -235,14 +239,25 @@ impl_getText (PortableServer_Servant _servant,
              const CORBA_long endOffset,
              CORBA_Environment * ev)
 {
-  Text *text = TEXT (bonobo_object_from_servant (_servant));
+  SpiText *text;
   gchar *txt;
-  CORBA_char *rv;
-
+  CORBA_string rv;
+  BonoboObject *obj;
+  
+  obj = (bonobo_object_from_servant (_servant));
+  g_return_val_if_fail (IS_TEXT (obj), (CORBA_char *)"");
+  text = SPI_TEXT (obj);
+  g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_char *)"");
+  
   txt = atk_text_get_text (ATK_TEXT(text->atko),
                       (gint) startOffset, (gint) endOffset);
-  rv = CORBA_string_dup (txt);
-  g_free (txt);
+  if (txt)
+    {
+      rv = CORBA_string_dup (txt);
+      g_free (txt);
+    }
+  else
+    rv = CORBA_string_dup ("");
   return rv;
 }
 
@@ -257,15 +272,30 @@ impl_getTextAfterOffset (PortableServer_Servant _servant,
                         CORBA_long * endOffset,
                         CORBA_Environment * ev)
 {
-  Text *text = TEXT (bonobo_object_from_servant (_servant));
+  SpiText *text;
   gchar *txt;
   CORBA_char *rv;
+  gint intStartOffset, intEndOffset;
+  BonoboObject *obj;
 
+  obj = (bonobo_object_from_servant (_servant));
+  g_return_val_if_fail (IS_TEXT (obj), (CORBA_char *)"");
+  text = SPI_TEXT (obj);
+  g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_char *)"");
+  
   txt = atk_text_get_text_after_offset (ATK_TEXT(text->atko),
                                    (gint) offset, (AtkTextBoundary) type,
-                                   (gint *) startOffset, (gint *) endOffset);
-  rv = CORBA_string_dup (txt);
-  g_free (txt);
+                                   &intStartOffset, &intEndOffset);
+  *startOffset = (CORBA_long) intStartOffset;
+  *endOffset = (CORBA_long) intEndOffset;
+
+  if (txt)
+    {
+      rv = CORBA_string_dup (txt);
+      g_free (txt);
+      }
+  else
+    rv = CORBA_string_dup ("");
   return rv;
 }
 
@@ -274,32 +304,54 @@ impl_getTextAfterOffset (PortableServer_Servant _servant,
 static CORBA_string
 impl_getTextAtOffset (PortableServer_Servant _servant,
                      const CORBA_long offset,
-                     const Accessibility_TEXT_BOUNDARY_TYPE
-                     type, CORBA_long * startOffset,
+                     const Accessibility_TEXT_BOUNDARY_TYPE type,
+                     CORBA_long * startOffset,
                      CORBA_long * endOffset,
                      CORBA_Environment * ev)
 {
-  Text *text = TEXT (bonobo_object_from_servant (_servant));
-  gchar *txt;
+  SpiText *text;
+  CORBA_char *txt;
   CORBA_char *rv;
+  gint intStartOffset, intEndOffset;
+  BonoboObject *obj;
 
-  txt = atk_text_get_text_at_offset (ATK_TEXT(text->atko),
+  obj = (bonobo_object_from_servant (_servant));
+  g_return_val_if_fail (IS_TEXT (obj), (CORBA_char *)"");
+  text = SPI_TEXT (obj);
+  g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_char *)"");
+
+  txt = (CORBA_char *) atk_text_get_text_at_offset (ATK_TEXT (text->atko),
                                    (gint) offset, (AtkTextBoundary) type,
-                                   (gint *) startOffset, (gint *) endOffset);
-  rv = CORBA_string_dup (txt);
-  g_free (txt);
+                                   &intStartOffset, &intEndOffset);
+  *startOffset = (CORBA_long) intStartOffset;
+  *endOffset = (CORBA_long) intEndOffset;
+
+  if (txt)
+    {
+      rv = CORBA_string_dup (txt);
+      g_free (txt);
+    }
+  else
+    rv = CORBA_string_dup ("");
+
   return rv;
 }
 
 
-
-static CORBA_wchar
+static CORBA_unsigned_long
 impl_getCharacterAtOffset (PortableServer_Servant _servant,
                           const CORBA_long offset,
                           CORBA_Environment * ev)
 {
-  Text *text = TEXT (bonobo_object_from_servant (_servant));
-  return (CORBA_wchar)
+  SpiText *text;
+  BonoboObject *obj;
+  obj = (bonobo_object_from_servant (_servant));
+  
+  g_return_val_if_fail (IS_TEXT (obj), (CORBA_unsigned_long)0);
+  text = SPI_TEXT (obj);
+  g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_unsigned_long)0);
+
+  return (CORBA_unsigned_long)
     atk_text_get_character_at_offset (ATK_TEXT(text->atko), (gint) offset);
 }
 
@@ -313,15 +365,31 @@ impl_getTextBeforeOffset (PortableServer_Servant _servant,
                          CORBA_long * endOffset,
                          CORBA_Environment * ev)
 {
-  Text *text = TEXT (bonobo_object_from_servant (_servant));
+  SpiText *text;
   gchar *txt;
   CORBA_char *rv;
+  gint intStartOffset, intEndOffset;
+  BonoboObject *obj;
+
+  obj = (bonobo_object_from_servant (_servant));
+  g_return_val_if_fail (IS_TEXT (obj), (CORBA_char *)"");
+  text = SPI_TEXT (obj);
+  g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_char *)"");
 
   txt = atk_text_get_text_before_offset (ATK_TEXT(text->atko),
                                    (gint) offset, (AtkTextBoundary) type,
-                                   (gint *) startOffset, (gint *) endOffset);
-  rv = CORBA_string_dup (txt);
-  g_free (txt);
+                                   &intStartOffset, &intEndOffset);
+  *startOffset = (CORBA_long) intStartOffset;
+  *endOffset = (CORBA_long) intEndOffset;
+
+  if (txt)
+    {
+      rv = CORBA_string_dup (txt);
+      g_free (txt);
+    }
+  else
+    rv = CORBA_string_dup ("");
+  return rv;
 }
 
 
@@ -329,7 +397,14 @@ static CORBA_long
 impl__get_caretOffset (PortableServer_Servant _servant,
                     CORBA_Environment * ev)
 {
-  Text *text = TEXT (bonobo_object_from_servant (_servant));
+  SpiText *text;
+  BonoboObject *obj;
+
+  obj = (bonobo_object_from_servant (_servant));
+  g_return_val_if_fail (IS_TEXT (obj), (CORBA_long)-1);
+  text = SPI_TEXT (obj);
+  g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_long)-1);
+  
   return (CORBA_long)
     atk_text_get_caret_offset (ATK_TEXT(text->atko));
 }
@@ -343,11 +418,18 @@ impl_getAttributes (PortableServer_Servant _servant,
                       CORBA_long * endOffset,
                       CORBA_Environment * ev)
 {
-  Text *text = TEXT (bonobo_object_from_servant (_servant));
-  g_print ("getAttributes not implemented.\n");
-}
+  SpiText *text;
+  BonoboObject *obj;
 
+  obj = (bonobo_object_from_servant (_servant));
+  g_return_val_if_fail (IS_TEXT (obj), (CORBA_char *)"");
+  text = SPI_TEXT (obj);
+  g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_char *)"");
 
+  g_print ("getAttributes not yet implemented.\n");
+
+  return CORBA_string_dup ("");
+}
 
 static void 
 impl_getCharacterExtents (PortableServer_Servant _servant,
@@ -357,7 +439,14 @@ impl_getCharacterExtents (PortableServer_Servant _servant,
                          const CORBA_short coordType,
                          CORBA_Environment * ev)
 {
-  Text *text = TEXT (bonobo_object_from_servant (_servant));
+  SpiText *text;
+  BonoboObject *obj;
+
+  obj = (bonobo_object_from_servant (_servant));
+  g_return_if_fail (IS_TEXT (obj));
+  text = SPI_TEXT (obj);
+  g_return_if_fail (ATK_IS_TEXT (text->atko));
+
   atk_text_get_character_extents (ATK_TEXT(text->atko), (gint) offset,
                                  (gint *) x, (gint *) y, (gint *) width, (gint *) height,
                                  (AtkCoordType) coordType);
@@ -369,9 +458,18 @@ static CORBA_long
 impl__get_characterCount (PortableServer_Servant _servant,
                        CORBA_Environment * ev)
 {
-  Text *text = TEXT (bonobo_object_from_servant (_servant));
-  return (CORBA_long)
+  SpiText *text;
+  BonoboObject *obj;
+  CORBA_long retval;
+
+  obj = (bonobo_object_from_servant (_servant));
+  g_return_val_if_fail (IS_TEXT (obj), (CORBA_long)0);
+  text = SPI_TEXT (obj);
+
+  retval = (CORBA_long)
     atk_text_get_character_count (ATK_TEXT(text->atko));
+
+  return retval;
 }
 
 
@@ -382,7 +480,13 @@ impl_getOffsetAtPoint (PortableServer_Servant _servant,
                       const CORBA_short coordType,
                       CORBA_Environment * ev)
 {
-  Text *text = TEXT (bonobo_object_from_servant (_servant));
+  SpiText *text;
+  BonoboObject *obj;
+
+  obj = (bonobo_object_from_servant (_servant));
+  g_return_val_if_fail (IS_TEXT (obj), (CORBA_long)-1);
+  text = SPI_TEXT (obj);
+
   return (CORBA_long)
     atk_text_get_offset_at_point (ATK_TEXT(text->atko),
                                  (gint) x, (gint) y, (AtkCoordType) coordType);
@@ -394,7 +498,13 @@ static CORBA_long
 impl_getNSelections (PortableServer_Servant _servant,
                     CORBA_Environment * ev)
 {
-  Text *text = TEXT (bonobo_object_from_servant (_servant));
+  SpiText *text;
+  BonoboObject *obj;
+
+  obj = (bonobo_object_from_servant (_servant));
+  g_return_val_if_fail (IS_TEXT (obj), (CORBA_long)0);
+  text = SPI_TEXT (obj);
+
   return (CORBA_long)
     atk_text_get_n_selections (ATK_TEXT(text->atko));
 }
@@ -407,7 +517,13 @@ impl_getSelection (PortableServer_Servant _servant,
                   CORBA_long * startOffset, CORBA_long * endOffset,
                   CORBA_Environment * ev)
 {
-  Text *text = TEXT (bonobo_object_from_servant (_servant));
+  SpiText *text;
+  BonoboObject *obj;
+
+  obj = (bonobo_object_from_servant (_servant));
+  g_return_if_fail (IS_TEXT (obj));
+  text = SPI_TEXT (obj);
+
   atk_text_get_selection (ATK_TEXT(text->atko), (gint) selectionNum,
                          (gint *) startOffset, (gint *) endOffset);
 }
@@ -420,7 +536,13 @@ impl_addSelection (PortableServer_Servant _servant,
                   const CORBA_long endOffset,
                   CORBA_Environment * ev)
 {
-  Text *text = TEXT (bonobo_object_from_servant (_servant));
+  SpiText *text;
+  BonoboObject *obj;
+
+  obj = (bonobo_object_from_servant (_servant));
+  g_return_val_if_fail (IS_TEXT (obj), (CORBA_boolean)FALSE);
+  text = SPI_TEXT (obj);
+
   return (CORBA_boolean)
     atk_text_add_selection (ATK_TEXT(text->atko),
                            (gint) startOffset, (gint) endOffset);
@@ -433,7 +555,13 @@ impl_removeSelection (PortableServer_Servant _servant,
                      const CORBA_long selectionNum,
                      CORBA_Environment * ev)
 {
-  Text *text = TEXT (bonobo_object_from_servant (_servant));
+  SpiText *text;
+  BonoboObject *obj;
+
+  obj = (bonobo_object_from_servant (_servant));
+  g_return_val_if_fail (IS_TEXT (obj), (CORBA_boolean)FALSE);
+  text = SPI_TEXT (obj);
+
   return (CORBA_boolean)
     atk_text_remove_selection (ATK_TEXT(text->atko), (gint) selectionNum);
 }
@@ -447,7 +575,13 @@ impl_setSelection (PortableServer_Servant _servant,
                   const CORBA_long endOffset,
                   CORBA_Environment * ev)
 {
-  Text *text = TEXT (bonobo_object_from_servant (_servant));
+  SpiText *text;
+  BonoboObject *obj;
+
+  obj = (bonobo_object_from_servant (_servant));
+  g_return_val_if_fail (IS_TEXT (obj), (CORBA_boolean)FALSE);
+  text = SPI_TEXT (obj);
+
   return (CORBA_boolean)
     atk_text_set_selection (ATK_TEXT(text->atko),
                            (gint) selectionNum, (gint) startOffset, (gint) endOffset);
@@ -460,7 +594,13 @@ impl_setCaretOffset (PortableServer_Servant _servant,
                     const CORBA_long value,
                     CORBA_Environment * ev)
 {
-  Text *text = TEXT (bonobo_object_from_servant (_servant));
+  SpiText *text;
+  BonoboObject *obj;
+
+  obj = (bonobo_object_from_servant (_servant));
+  g_return_val_if_fail (IS_TEXT (obj), (CORBA_boolean)FALSE);
+  text = SPI_TEXT (obj);
+
   return (CORBA_boolean)
     atk_text_set_caret_offset (ATK_TEXT(text->atko), (gint) value);
 }
@@ -472,6 +612,13 @@ impl_getRowColAtOffset (PortableServer_Servant _servant,
                        const CORBA_long offset, CORBA_long * row,
                        CORBA_long * column, CORBA_Environment * ev)
 {
-  Text *text = TEXT (bonobo_object_from_servant (_servant));
+  SpiText *text;
+  BonoboObject *obj;
+
+  obj = (bonobo_object_from_servant (_servant));
+  g_return_if_fail (IS_TEXT (obj));
+  text = SPI_TEXT (obj);
+
+  g_print ("getRowColAtOffset not yet implemented\n");
 }