Fixed refcounting issues with interface server
[platform/core/uifw/at-spi2-atk.git] / libspi / accessible.c
index c8493c6..575ead9 100644 (file)
  * This pulls the definition for the BonoboObject (Gtk Type)
  */
 #include "accessible.h"
+#include "component.h"
+#include "editabletext.h"
+#include "hyperlink.h"
+#include "hypertext.h"
+#include "image.h"
+#include "selection.h"
+#include "table.h"
+#include "text.h"
+#include "value.h"
 
 /*
  * Our parent Gtk object type
@@ -74,7 +83,7 @@ impl_accessibility_accessible_get_name (PortableServer_Servant servant,
 {
   CORBA_char * retval;
   Accessible *accessible = ACCESSIBLE (bonobo_object_from_servant (servant));
-  retval = atk_object_get_name (accessible->atko);
+  retval = (CORBA_char *) atk_object_get_name (accessible->atko);
   if (retval )
     retval = CORBA_string_dup (retval);
   else
@@ -123,6 +132,66 @@ impl_accessibility_accessible_set_description (PortableServer_Servant servant,
   printf ("Accessible set_description called: %s\n", name);
 }
 
+/*
+ * CORBA Accessibility::Accessible::get_parent method implementation
+ */
+static Accessibility_Accessible
+impl_accessibility_accessible_get_parent (PortableServer_Servant servant,
+                                          CORBA_Environment     *ev)
+{
+  Accessibility_Accessible retval;
+  Accessible *accessible = ACCESSIBLE (bonobo_object_from_servant (servant));
+  AtkObject *parent;
+  parent = atk_object_get_parent (accessible->atko);
+  retval = bonobo_object_corba_objref (bonobo_object (accessible_new (parent)));
+  printf ("Accessible get_parent called\n");
+  return retval;
+}
+
+/*
+ * CORBA Accessibility::Accessible::get_IndexInParent method implementation
+ */
+static CORBA_long
+impl_accessibility_accessible_get_index_in_parent (PortableServer_Servant servant,
+                                                   CORBA_Environment     *ev)
+{
+  CORBA_long retval;
+  Accessible *accessible = ACCESSIBLE (bonobo_object_from_servant (servant));
+  retval = (CORBA_long) atk_object_get_index_in_parent (accessible->atko);
+  printf ("Accessible get_index_in_parent called\n");
+  return retval;
+}
+
+/*
+ * CORBA Accessibility::Accessible::get_childCount method implementation
+ */
+static CORBA_long
+impl_accessibility_accessible_get_child_count (PortableServer_Servant servant,
+                                               CORBA_Environment     *ev)
+{
+  CORBA_long retval;
+  Accessible *accessible = ACCESSIBLE (bonobo_object_from_servant (servant));
+  retval = (CORBA_long) atk_object_get_n_accessible_children (accessible->atko);
+  printf ("Accessible get_childCount called: %d\n", (int) retval);
+  return retval;
+}
+
+/*
+ * CORBA Accessibility::Accessible::getChildAtIndex method implementation
+ */
+static Accessibility_Accessible
+impl_accessibility_accessible_get_child_at_index (PortableServer_Servant servant,
+                                                  const CORBA_long      index,
+                                                  CORBA_Environment     *ev)
+{
+  Accessibility_Accessible retval;
+  Accessible *accessible = ACCESSIBLE (bonobo_object_from_servant (servant));
+  AtkObject *child = atk_object_ref_accessible_child (accessible->atko, (gint) index);
+  retval = bonobo_object_corba_objref ( bonobo_object (accessible_new (child)));
+  printf ("Accessible get_child_at_index called.\n");
+  return retval;
+}
+
 static void
 accessible_class_init (AccessibleClass *klass)
 {
@@ -137,10 +206,11 @@ accessible_class_init (AccessibleClass *klass)
         epv->_get_description = impl_accessibility_accessible_get_description;
         epv->_set_description = impl_accessibility_accessible_set_description;
 
-        /* epv->_get_parent = impl_accessibility_accessible_get_parent;               */
-        /* epv->_get_childCount = impl_accessibility_accessible_get_child_count;      */
-        /* epv->getChildAtIndex = impl_accessibility_accessible_get_child_at_index;   */
-        /* epv->getIndexInParent = impl_accessibility_accessible_get_index_in_parent; */
+        epv->_get_parent = impl_accessibility_accessible_get_parent;
+        epv->_get_childCount = impl_accessibility_accessible_get_child_count;
+        epv->getChildAtIndex = impl_accessibility_accessible_get_child_at_index;
+        epv->getIndexInParent = impl_accessibility_accessible_get_index_in_parent;
+
         /* epv->getRelationSet = impl_accessibility_accessible_get_relation_set;      */
         /* epv->getState = impl_accessibility_accessible_get_state;                   */
         /* epv->getRole = impl_accessibility_accessible_get_role;                     */
@@ -191,6 +261,76 @@ accessible_new (AtkObject *o)
 {
     Accessible *retval =
                ACCESSIBLE (g_object_new (accessible_get_type (), NULL));
+    g_object_ref (o);
     retval->atko = ATK_OBJECT (o);
+
+    /*
+     * TODO: add interface containers/constructors for EDITABLE_TEXT, HYPERTEXT,
+     *  IMAGE, SELECTION, TABLE, TEXT, VALUE.
+     */
+
+    /* add appropriate ATK interfaces */
+
+    if (ATK_IS_ACTION (o))
+      {
+        bonobo_object_add_interface (bonobo_object (retval),
+                                     BONOBO_OBJECT (action_interface_new (o)));
+      }
+
+    if (ATK_IS_COMPONENT (o))
+      {
+        bonobo_object_add_interface (bonobo_object (retval),
+                                     BONOBO_OBJECT (component_interface_new (o)));
+      }
+
+    if (ATK_IS_EDITABLE_TEXT (o))
+      {
+        bonobo_object_add_interface (bonobo_object (retval),
+                                     BONOBO_OBJECT(editable_text_interface_new (o)));
+      }
+
+    else if (ATK_IS_HYPERTEXT (o))
+      {
+        bonobo_object_add_interface (bonobo_object (retval),
+                                     BONOBO_OBJECT (hypertext_interface_new (o)));
+      }
+
+    else if (ATK_IS_TEXT (o))
+      {
+        bonobo_object_add_interface (bonobo_object (retval),
+                                     BONOBO_OBJECT (text_interface_new (o)));
+      }
+
+    if (ATK_IS_HYPERLINK (o))
+      {
+       bonobo_object_add_interface (bonobo_object (retval),
+                                    BONOBO_OBJECT (hyperlink_interface_new(o)));
+      }
+
+    if (ATK_IS_IMAGE (o))
+      {
+        bonobo_object_add_interface (bonobo_object (retval),
+                                     BONOBO_OBJECT (image_interface_new (o)));
+      }
+
+    if (ATK_IS_SELECTION (o))
+      {
+        bonobo_object_add_interface (bonobo_object (retval),
+                                     BONOBO_OBJECT (selection_interface_new (o)));
+      }
+
+    if (ATK_IS_TABLE (o))
+      {
+        bonobo_object_add_interface (bonobo_object (retval),
+                                     BONOBO_OBJECT (table_interface_new (o)));
+      }
+
+    if (ATK_IS_VALUE (o))
+      {
+        bonobo_object_add_interface (bonobo_object (retval),
+                                     BONOBO_OBJECT (value_interface_new (o)));
+      }
+
+
     return retval;
 }