2001-11-20 Michael Meeks <michael@ximian.com>
[platform/core/uifw/at-spi2-atk.git] / libspi / selection.c
index 6f726b2..aa0ff47 100644 (file)
  * Boston, MA 02111-1307, USA.
  */
 
-/*
- * component.c : bonobo wrapper for accessible component implementation
- *
- */
-#include <config.h>
-#include <bonobo/Bonobo.h>
+/* selection.c : implements the Selection interface */
 
+#include <config.h>
 #include <stdio.h>
+#include <libspi/accessible.h>
+#include <libspi/selection.h>
 
-/*
- * This pulls the CORBA definitions for the "Accessibility::Accessible" server
- */
-#include <libspi/Accessibility.h>
-
-/*
- * This pulls the definition of the selection bonobo object
- */
-#include "selection.h"
-
-/*
- * Static function declarations
- */
+/* Static function declarations */
 
 static void
-selection_class_init (SelectionClass *klass);
+spi_selection_class_init (SpiSelectionClass *klass);
 static void
-selection_init (Selection *selection);
+spi_selection_init (SpiSelection *selection);
 static void
-selection_finalize (GObject *obj);
+spi_selection_finalize (GObject *obj);
 static CORBA_long
 impl__get_nSelectedChildren (PortableServer_Servant _servant,
                             CORBA_Environment * ev);
@@ -79,21 +65,21 @@ impl_clearSelection (PortableServer_Servant _servant,
 static GObjectClass *parent_class;
 
 GType
-selection_get_type (void)
+spi_selection_get_type (void)
 {
   static GType type = 0;
 
   if (!type) {
     static const GTypeInfo tinfo = {
-      sizeof (SelectionClass),
+      sizeof (SpiSelectionClass),
       (GBaseInitFunc) NULL,
       (GBaseFinalizeFunc) NULL,
-      (GClassInitFunc) selection_class_init,
+      (GClassInitFunc) spi_selection_class_init,
       (GClassFinalizeFunc) NULL,
       NULL, /* class data */
-      sizeof (Selection),
+      sizeof (SpiSelection),
       0, /* n preallocs */
-      (GInstanceInitFunc) selection_init,
+      (GInstanceInitFunc) spi_selection_init,
                         NULL /* value table */
     };
 
@@ -106,22 +92,22 @@ selection_get_type (void)
                               BONOBO_OBJECT_TYPE,
                               POA_Accessibility_Selection__init,
                               NULL,
-                              G_STRUCT_OFFSET (SelectionClass, epv),
+                              G_STRUCT_OFFSET (SpiSelectionClass, epv),
                               &tinfo,
-                              "AccessibleSelection");
+                              "SpiAccessibleSelection");
   }
 
   return type;
 }
 
 static void
-selection_class_init (SelectionClass *klass)
+spi_selection_class_init (SpiSelectionClass *klass)
 {
   GObjectClass * object_class = (GObjectClass *) klass;
   POA_Accessibility_Selection__epv *epv = &klass->epv;
   parent_class = g_type_class_peek_parent (klass);
 
-  object_class->finalize = selection_finalize;
+  object_class->finalize = spi_selection_finalize;
 
 
   /* Initialize epv table */
@@ -136,24 +122,26 @@ selection_class_init (SelectionClass *klass)
 }
 
 static void
-selection_init (Selection *selection)
+spi_selection_init (SpiSelection *selection)
 {
 }
 
 static void
-selection_finalize (GObject *obj)
+spi_selection_finalize (GObject *obj)
 {
-  Selection *selection = SELECTION (obj);
-  selection->atk_selection = NULL;
+  SpiSelection *selection = SPI_SELECTION (obj);
+  g_object_unref (selection->atko);
+  selection->atko = NULL;
   parent_class->finalize (obj);
 }
 
-Selection *
-selection_new (AtkSelection *selection)
+SpiSelection *
+spi_selection_interface_new (AtkObject *obj)
 {
-  Selection *new_selection = 
-    SELECTION(g_object_new (SELECTION_TYPE, NULL));
-  new_selection->atk_selection = selection;
+  SpiSelection *new_selection = 
+    SPI_SELECTION(g_object_new (SPI_SELECTION_TYPE, NULL));
+  new_selection->atko = obj;
+  g_object_ref (obj);
   return new_selection;
 }
 
@@ -163,12 +151,17 @@ static CORBA_long
 impl__get_nSelectedChildren (PortableServer_Servant _servant,
                             CORBA_Environment * ev)
 {
-  Selection *selection = SELECTION (bonobo_object_from_servant (_servant));
+  BonoboObject *obj = bonobo_object_from_servant (_servant);
+  SpiSelection *selection;
+#ifdef SPI_DEBUG
+  fprintf (stderr, "calling impl__get_nSelectedChildren\n");
+#endif
+  g_return_val_if_fail (IS_SPI_SELECTION (obj), 0);
+  selection = SPI_SELECTION (obj);
+  g_return_val_if_fail (ATK_IS_SELECTION (selection->atko), 0);
   return (CORBA_long)
-    atk_selection_get_selection_count (selection->atk_selection);
-} 
-
-
+    atk_selection_get_selection_count (ATK_SELECTION(selection->atko));
+}
 
 
 static Accessibility_Accessible
@@ -176,13 +169,27 @@ impl_getSelectedChild (PortableServer_Servant _servant,
                       const CORBA_long selectedChildIndex,
                       CORBA_Environment * ev)
 {
-  Selection *selection = SELECTION (bonobo_object_from_servant (_servant));
+  BonoboObject *obj = bonobo_object_from_servant (_servant);
+  SpiSelection
+         *selection;
   AtkObject *atk_object;
   Accessibility_Accessible rv;
-
-  atk_object = atk_selection_ref_selection (selection->atk_selection, (gint) selectedChildIndex);
-  rv = bonobo_object_corba_objref (BONOBO_OBJECT(accessible_new(atk_object)));
-  return rv;
+#ifdef SPI_DEBUG
+  fprintf (stderr, "calling impl_getSelectedChild\n");
+#endif
+  g_return_val_if_fail (IS_SPI_SELECTION (obj), 0);
+  selection = SPI_SELECTION (obj);
+  g_return_val_if_fail (ATK_IS_SELECTION (selection->atko), 0);
+
+  atk_object = atk_selection_ref_selection (ATK_SELECTION (selection->atko),
+                                           (gint) selectedChildIndex);
+  g_return_val_if_fail (ATK_IS_OBJECT (atk_object), NULL);
+#ifdef SPI_DEBUG
+  fprintf (stderr, "child type is %s\n", g_type_name (G_OBJECT_TYPE (atk_object)));
+#endif
+  rv = bonobo_object_corba_objref (bonobo_object (spi_accessible_new (atk_object)));
+  g_object_unref (atk_object);
+  return CORBA_Object_duplicate (rv, ev);
 }
 
 
@@ -192,9 +199,9 @@ impl_selectChild (PortableServer_Servant _servant,
                  const CORBA_long childIndex,
                  CORBA_Environment * ev)
 {
-  Selection *selection = SELECTION (bonobo_object_from_servant (_servant));
+  SpiSelection *selection = SPI_SELECTION (bonobo_object_from_servant (_servant));
   return (CORBA_boolean)
-    atk_selection_add_selection (selection->atk_selection, (gint) childIndex);
+    atk_selection_add_selection (ATK_SELECTION(selection->atko), (gint) childIndex);
 }
 
 
@@ -205,9 +212,9 @@ impl_deselectSelectedChild (PortableServer_Servant _servant,
                            const CORBA_long selectedChildIndex,
                            CORBA_Environment * ev)
 {
-  Selection *selection = SELECTION (bonobo_object_from_servant (_servant));
+  SpiSelection *selection = SPI_SELECTION (bonobo_object_from_servant (_servant));
   return (CORBA_boolean)
-    atk_selection_remove_selection (selection->atk_selection, (gint) selectedChildIndex);
+    atk_selection_remove_selection (ATK_SELECTION(selection->atko), (gint) selectedChildIndex);
 }
 
 
@@ -217,9 +224,9 @@ impl_isChildSelected (PortableServer_Servant _servant,
                      const CORBA_long childIndex,
                      CORBA_Environment * ev)
 {
-  Selection *selection = SELECTION (bonobo_object_from_servant (_servant));
+  SpiSelection *selection = SPI_SELECTION (bonobo_object_from_servant (_servant));
   return (CORBA_boolean)
-    atk_selection_is_child_selected (selection->atk_selection, (gint) childIndex);
+    atk_selection_is_child_selected (ATK_SELECTION(selection->atko), (gint) childIndex);
 }
 
 
@@ -228,8 +235,8 @@ static void
 impl_selectAll (PortableServer_Servant _servant,
                CORBA_Environment * ev)
 {
-  Selection *selection = SELECTION (bonobo_object_from_servant (_servant));
-  atk_selection_select_all_selection (selection->atk_selection);
+  SpiSelection *selection = SPI_SELECTION (bonobo_object_from_servant (_servant));
+  atk_selection_select_all_selection (ATK_SELECTION(selection->atko));
 }
 
 
@@ -238,7 +245,7 @@ static void
 impl_clearSelection (PortableServer_Servant _servant,
                     CORBA_Environment * ev)
 {
-  Selection *selection = SELECTION (bonobo_object_from_servant (_servant));
-  atk_selection_clear_selection (selection->atk_selection);
+  SpiSelection *selection = SPI_SELECTION (bonobo_object_from_servant (_servant));
+  atk_selection_clear_selection (ATK_SELECTION(selection->atko));
 }