Added C binding for key synthesis, and a new test/demo program
[platform/core/uifw/at-spi2-atk.git] / libspi / text.c
index afb4a7e..f7302fc 100644 (file)
@@ -28,6 +28,7 @@
 #include <bonobo/Bonobo.h>
 
 #include <stdio.h>
+#include <stdlib.h>
 
 /*
  * This pulls the CORBA definitions for the "Accessibility::Accessible" server
 #include "text.h"
 
 /*
+ * Our parent Gtk object type
+ */
+#define PARENT_TYPE BONOBO_OBJECT_TYPE
+
+
+/*
+ * A pointer to our parent object class
+ */
+static GObjectClass *text_parent_class;
+
+/*
  * Static function declarations
  */
 
 static void
-text_class_init (TextClass *klass);
+accessibility_text_class_init (TextClass *klass);
+
 static void
-text_init (Text *text);
+accessibility_text_init (Text *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 +81,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 +99,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,48 +118,52 @@ 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;
 
@@ -147,13 +172,13 @@ text_get_type (void)
       sizeof (TextClass),
       (GBaseInitFunc) NULL,
       (GBaseFinalizeFunc) NULL,
-      (GClassInitFunc) text_class_init,
+      (GClassInitFunc) accessibility_text_class_init,
       (GClassFinalizeFunc) NULL,
       NULL, /* class data */
       sizeof (Text),
       0, /* n preallocs */
-      (GInstanceInitFunc) text_init,
-                        NULL /* value table */
+      (GInstanceInitFunc) accessibility_text_init,
+      NULL /* value table */
     };
 
     /*
@@ -162,7 +187,7 @@ 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),
@@ -174,14 +199,13 @@ text_get_type (void)
 }
 
 static void
-text_class_init (TextClass *klass)
+accessibility_text_class_init (TextClass *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;
+  text_parent_class = g_type_class_peek_parent (klass);
 
+  object_class->finalize = accessibility_text_object_finalize;
 
   /* Initialize epv table */
 
@@ -204,24 +228,24 @@ text_class_init (TextClass *klass)
 }
 
 static void
-text_init (Text *text)
+accessibility_text_init (Text *text)
 {
 }
 
 static void
-text_finalize (GObject *obj)
+accessibility_text_object_finalize (GObject *obj)
 {
   Text *text = TEXT (obj);
   g_object_unref (text->atko);
   text->atko = NULL;
-  parent_class->finalize (obj);
+  text_parent_class->finalize (obj);
 }
 
 Text *
 text_interface_new (AtkObject *obj)
 {
   Text *new_text = 
-    TEXT(g_object_new (TEXT_TYPE, NULL));
+    TEXT (g_object_new (accessibility_text_get_type (), NULL));
   new_text->atko = obj;
   g_object_ref (obj);
   return new_text;
@@ -235,10 +259,16 @@ impl_getText (PortableServer_Servant _servant,
              const CORBA_long endOffset,
              CORBA_Environment * ev)
 {
-  Text *text = TEXT (bonobo_object_from_servant (_servant));
+  Text *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 = 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);
   if (txt)
@@ -262,14 +292,23 @@ impl_getTextAfterOffset (PortableServer_Servant _servant,
                         CORBA_long * endOffset,
                         CORBA_Environment * ev)
 {
-  Text *text = TEXT (bonobo_object_from_servant (_servant));
+  Text *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 = 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);
+                                   &intStartOffset, &intEndOffset);
+  *startOffset = (CORBA_long) intStartOffset;
+  *endOffset = (CORBA_long) intEndOffset;
+
   if (txt)
     {
       rv = CORBA_string_dup (txt);
@@ -285,18 +324,28 @@ 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;
+  Text *text;
+  CORBA_char *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 = TEXT (obj);
+  g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_char *)"");
 
-  txt = atk_text_get_text_at_offset (ATK_TEXT(text->atko),
+  txt = (CORBA_char *) atk_text_get_text_at_offset (ATK_TEXT (text->atko),
                                    (gint) offset, (AtkTextBoundary) type,
-                                   (gint *) startOffset, (gint *) endOffset);
+                                   &intStartOffset, &intEndOffset);
+  *startOffset = (CORBA_long) intStartOffset;
+  *endOffset = (CORBA_long) intEndOffset;
+
   if (txt)
     {
       rv = CORBA_string_dup (txt);
@@ -304,18 +353,25 @@ impl_getTextAtOffset (PortableServer_Servant _servant,
     }
   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)
+  Text *text;
+  BonoboObject *obj;
+  obj = (bonobo_object_from_servant (_servant));
+  
+  g_return_val_if_fail (IS_TEXT (obj), (CORBA_unsigned_long)0);
+  text = 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);
 }
 
@@ -329,13 +385,23 @@ impl_getTextBeforeOffset (PortableServer_Servant _servant,
                          CORBA_long * endOffset,
                          CORBA_Environment * ev)
 {
-  Text *text = TEXT (bonobo_object_from_servant (_servant));
+  Text *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 = 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);
+                                   &intStartOffset, &intEndOffset);
+  *startOffset = (CORBA_long) intStartOffset;
+  *endOffset = (CORBA_long) intEndOffset;
+
   if (txt)
     {
       rv = CORBA_string_dup (txt);
@@ -351,7 +417,14 @@ static CORBA_long
 impl__get_caretOffset (PortableServer_Servant _servant,
                     CORBA_Environment * ev)
 {
-  Text *text = TEXT (bonobo_object_from_servant (_servant));
+  Text *text;
+  BonoboObject *obj;
+
+  obj = (bonobo_object_from_servant (_servant));
+  g_return_val_if_fail (IS_TEXT (obj), (CORBA_long)-1);
+  text = 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));
 }
@@ -365,11 +438,16 @@ 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");
-}
+  Text *text;
+  BonoboObject *obj;
 
+  obj = (bonobo_object_from_servant (_servant));
+  g_return_val_if_fail (IS_TEXT (obj), (CORBA_char *)"");
+  text = TEXT (obj);
+  g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_char *)"");
 
+  g_print ("getAttributes not yet implemented.\n");
+}
 
 static void 
 impl_getCharacterExtents (PortableServer_Servant _servant,
@@ -379,7 +457,14 @@ impl_getCharacterExtents (PortableServer_Servant _servant,
                          const CORBA_short coordType,
                          CORBA_Environment * ev)
 {
-  Text *text = TEXT (bonobo_object_from_servant (_servant));
+  Text *text;
+  BonoboObject *obj;
+
+  obj = (bonobo_object_from_servant (_servant));
+  g_return_if_fail (IS_TEXT (obj));
+  text = 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);
@@ -391,9 +476,18 @@ static CORBA_long
 impl__get_characterCount (PortableServer_Servant _servant,
                        CORBA_Environment * ev)
 {
-  Text *text = TEXT (bonobo_object_from_servant (_servant));
-  return (CORBA_long)
+  Text *text;
+  BonoboObject *obj;
+  CORBA_long retval;
+
+  obj = (bonobo_object_from_servant (_servant));
+  g_return_val_if_fail (IS_TEXT (obj), (CORBA_long)0);
+  text = TEXT (obj);
+
+  retval = (CORBA_long)
     atk_text_get_character_count (ATK_TEXT(text->atko));
+
+  return retval;
 }
 
 
@@ -404,7 +498,13 @@ impl_getOffsetAtPoint (PortableServer_Servant _servant,
                       const CORBA_short coordType,
                       CORBA_Environment * ev)
 {
-  Text *text = TEXT (bonobo_object_from_servant (_servant));
+  Text *text;
+  BonoboObject *obj;
+
+  obj = (bonobo_object_from_servant (_servant));
+  g_return_val_if_fail (IS_TEXT (obj), (CORBA_long)-1);
+  text = TEXT (obj);
+
   return (CORBA_long)
     atk_text_get_offset_at_point (ATK_TEXT(text->atko),
                                  (gint) x, (gint) y, (AtkCoordType) coordType);
@@ -416,7 +516,13 @@ static CORBA_long
 impl_getNSelections (PortableServer_Servant _servant,
                     CORBA_Environment * ev)
 {
-  Text *text = TEXT (bonobo_object_from_servant (_servant));
+  Text *text;
+  BonoboObject *obj;
+
+  obj = (bonobo_object_from_servant (_servant));
+  g_return_val_if_fail (IS_TEXT (obj), (CORBA_long)0);
+  text = TEXT (obj);
+
   return (CORBA_long)
     atk_text_get_n_selections (ATK_TEXT(text->atko));
 }
@@ -429,7 +535,13 @@ impl_getSelection (PortableServer_Servant _servant,
                   CORBA_long * startOffset, CORBA_long * endOffset,
                   CORBA_Environment * ev)
 {
-  Text *text = TEXT (bonobo_object_from_servant (_servant));
+  Text *text;
+  BonoboObject *obj;
+
+  obj = (bonobo_object_from_servant (_servant));
+  g_return_if_fail (IS_TEXT (obj));
+  text = TEXT (obj);
+
   atk_text_get_selection (ATK_TEXT(text->atko), (gint) selectionNum,
                          (gint *) startOffset, (gint *) endOffset);
 }
@@ -442,7 +554,13 @@ impl_addSelection (PortableServer_Servant _servant,
                   const CORBA_long endOffset,
                   CORBA_Environment * ev)
 {
-  Text *text = TEXT (bonobo_object_from_servant (_servant));
+  Text *text;
+  BonoboObject *obj;
+
+  obj = (bonobo_object_from_servant (_servant));
+  g_return_val_if_fail (IS_TEXT (obj), (CORBA_boolean)FALSE);
+  text = TEXT (obj);
+
   return (CORBA_boolean)
     atk_text_add_selection (ATK_TEXT(text->atko),
                            (gint) startOffset, (gint) endOffset);
@@ -455,7 +573,13 @@ impl_removeSelection (PortableServer_Servant _servant,
                      const CORBA_long selectionNum,
                      CORBA_Environment * ev)
 {
-  Text *text = TEXT (bonobo_object_from_servant (_servant));
+  Text *text;
+  BonoboObject *obj;
+
+  obj = (bonobo_object_from_servant (_servant));
+  g_return_val_if_fail (IS_TEXT (obj), (CORBA_boolean)FALSE);
+  text = TEXT (obj);
+
   return (CORBA_boolean)
     atk_text_remove_selection (ATK_TEXT(text->atko), (gint) selectionNum);
 }
@@ -469,7 +593,13 @@ impl_setSelection (PortableServer_Servant _servant,
                   const CORBA_long endOffset,
                   CORBA_Environment * ev)
 {
-  Text *text = TEXT (bonobo_object_from_servant (_servant));
+  Text *text;
+  BonoboObject *obj;
+
+  obj = (bonobo_object_from_servant (_servant));
+  g_return_val_if_fail (IS_TEXT (obj), (CORBA_boolean)FALSE);
+  text = TEXT (obj);
+
   return (CORBA_boolean)
     atk_text_set_selection (ATK_TEXT(text->atko),
                            (gint) selectionNum, (gint) startOffset, (gint) endOffset);
@@ -482,7 +612,13 @@ impl_setCaretOffset (PortableServer_Servant _servant,
                     const CORBA_long value,
                     CORBA_Environment * ev)
 {
-  Text *text = TEXT (bonobo_object_from_servant (_servant));
+  Text *text;
+  BonoboObject *obj;
+
+  obj = (bonobo_object_from_servant (_servant));
+  g_return_val_if_fail (IS_TEXT (obj), (CORBA_boolean)FALSE);
+  text = TEXT (obj);
+
   return (CORBA_boolean)
     atk_text_set_caret_offset (ATK_TEXT(text->atko), (gint) value);
 }
@@ -494,6 +630,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));
+  Text *text;
+  BonoboObject *obj;
+
+  obj = (bonobo_object_from_servant (_servant));
+  g_return_if_fail (IS_TEXT (obj));
+  text = TEXT (obj);
+
+  g_print ("getRowColAtOffset not yet implemented\n");
 }