Added Li Yuan <li.yuan@sun.com> to MAINTAINERS list for atk, gail,
[platform/core/uifw/at-spi2-atk.git] / libspi / selection.c
index f51c360..42fafe1 100644 (file)
@@ -2,7 +2,8 @@
  * AT-SPI - Assistive Technology Service Provider Interface
  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
  *
- * Copyright 2001 Sun Microsystems Inc.
+ * Copyright 2001, 2002 Sun Microsystems Inc.,
+ * Copyright 2001, 2002 Ximian, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
 #include <libspi/accessible.h>
 #include <libspi/selection.h>
 
-/* A pointer to our parent object class */
-static GObjectClass *parent_class;
-
-static void
-spi_selection_finalize (GObject *obj)
-{
-  SpiSelection *selection = SPI_SELECTION (obj);
-  g_object_unref (selection->atko);
-  selection->atko = NULL;
-  parent_class->finalize (obj);
-}
 
 SpiSelection *
 spi_selection_interface_new (AtkObject *obj)
 {
   SpiSelection *new_selection = g_object_new (SPI_SELECTION_TYPE, NULL);
-  new_selection->atko = obj;
-  g_object_ref (obj);
+
+  spi_base_construct (SPI_BASE (new_selection), G_OBJECT(obj));
+
   return new_selection;
 }
 
 
+static AtkSelection *
+get_selection_from_servant (PortableServer_Servant servant)
+{
+  SpiBase *object = SPI_BASE (bonobo_object_from_servant (servant));
+
+  g_return_val_if_fail (object, NULL);
+  g_return_val_if_fail (ATK_IS_OBJECT(object->gobj), NULL);
+  return ATK_SELECTION (object->gobj);
+}
+
 
 static CORBA_long
-impl__get_nSelectedChildren (PortableServer_Servant _servant,
-                            CORBA_Environment ev)
+impl__get_nSelectedChildren (PortableServer_Servant servant,
+                            CORBA_Environment     *ev)
 {
-  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 (ATK_SELECTION(selection->atko));
+  AtkSelection *selection = get_selection_from_servant (servant);
+
+  g_return_val_if_fail (selection != NULL, 0);
+
+  return atk_selection_get_selection_count (selection);
 }
 
 
 static Accessibility_Accessible
-impl_getSelectedChild (PortableServer_Servant _servant,
-                      const CORBA_long selectedChildIndex,
-                      CORBA_Environment ev)
+impl_getSelectedChild (PortableServer_Servant servant,
+                      const CORBA_long       selectedChildIndex,
+                      CORBA_Environment     *ev)
 {
-  BonoboObject *obj = bonobo_object_from_servant (_servant);
-  SpiSelection
-         *selection;
-  AtkObject *atk_object;
-  Accessibility_Accessible rv;
+  AtkObject    *atk_object;
+  AtkSelection *selection = get_selection_from_servant (servant);
+
+  g_return_val_if_fail (selection != NULL, CORBA_OBJECT_NIL);
+
 #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);
+  atk_object = atk_selection_ref_selection (selection,
+                                           selectedChildIndex);
+
+  g_return_val_if_fail (ATK_IS_OBJECT (atk_object), CORBA_OBJECT_NIL);
+
 #ifdef SPI_DEBUG
-  fprintf (stderr, "child type is %s\n", g_type_name (G_OBJECT_TYPE (atk_object)));
+  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);
-}
 
+  return spi_accessible_new_return (atk_object, TRUE, ev);
+}
 
 
 static CORBA_boolean
-impl_selectChild (PortableServer_Servant _servant,
-                 const CORBA_long childIndex,
-                 CORBA_Environment ev)
+impl_selectChild (PortableServer_Servant servant,
+                 const CORBA_long       childIndex,
+                 CORBA_Environment     *ev)
 {
-  SpiSelection *selection = SPI_SELECTION (bonobo_object_from_servant (_servant));
-  return (CORBA_boolean)
-    atk_selection_add_selection (ATK_SELECTION(selection->atko), (gint) childIndex);
-}
+  AtkSelection *selection = get_selection_from_servant (servant);
 
+  g_return_val_if_fail (selection != NULL, FALSE);
 
+  return atk_selection_add_selection (selection, childIndex);
+}
 
 
 static CORBA_boolean
-impl_deselectSelectedChild (PortableServer_Servant _servant,
-                           const CORBA_long selectedChildIndex,
-                           CORBA_Environment ev)
+impl_deselectSelectedChild (PortableServer_Servant servant,
+                           const CORBA_long       selectedChildIndex,
+                           CORBA_Environment     *ev)
 {
-  SpiSelection *selection = SPI_SELECTION (bonobo_object_from_servant (_servant));
-  return (CORBA_boolean)
-    atk_selection_remove_selection (ATK_SELECTION(selection->atko), (gint) selectedChildIndex);
+  AtkSelection *selection = get_selection_from_servant (servant);
+
+  g_return_val_if_fail (selection != NULL, FALSE);
+
+  return atk_selection_remove_selection (selection, selectedChildIndex);
 }
 
 
 
 static CORBA_boolean
-impl_isChildSelected (PortableServer_Servant _servant,
-                     const CORBA_long childIndex,
-                     CORBA_Environment * ev)
+impl_deselectChild (PortableServer_Servant servant,
+                   const CORBA_long       selectedChildIndex,
+                   CORBA_Environment     *ev)
 {
-  SpiSelection *selection = SPI_SELECTION (bonobo_object_from_servant (_servant));
-  return (CORBA_boolean)
-    atk_selection_is_child_selected (ATK_SELECTION(selection->atko), (gint) childIndex);
+  AtkSelection *selection = get_selection_from_servant (servant);
+  gint i, nselected;
+
+  g_return_val_if_fail (selection != NULL, FALSE);
+  nselected = atk_selection_get_selection_count (selection);
+  for (i=0; i<nselected; ++i)
+  {
+      AtkObject *selected_obj = atk_selection_ref_selection (selection, i);
+      if (atk_object_get_index_in_parent (selected_obj) == selectedChildIndex)
+      {
+         g_object_unref (G_OBJECT (selected_obj));
+         return atk_selection_remove_selection (selection, i);
+      }
+      g_object_unref (G_OBJECT (selected_obj));
+  }
+  return FALSE;
 }
 
 
-
-static void 
-impl_selectAll (PortableServer_Servant _servant,
-               CORBA_Environment * ev)
+static CORBA_boolean
+impl_isChildSelected (PortableServer_Servant servant,
+                     const CORBA_long       childIndex,
+                     CORBA_Environment     *ev)
 {
-  SpiSelection *selection = SPI_SELECTION (bonobo_object_from_servant (_servant));
-  atk_selection_select_all_selection (ATK_SELECTION(selection->atko));
+  AtkSelection *selection = get_selection_from_servant (servant);
+
+  g_return_val_if_fail (selection != NULL, FALSE);
+
+  return atk_selection_is_child_selected (selection, childIndex);
 }
 
 
+static CORBA_boolean 
+impl_selectAll (PortableServer_Servant servant,
+               CORBA_Environment     *ev)
+{
+  AtkSelection *selection = get_selection_from_servant (servant);
+
+  g_return_val_if_fail (selection != NULL, FALSE);
 
-static void 
-impl_clearSelection (PortableServer_Servant _servant,
-                    CORBA_Environment * ev)
+  return atk_selection_select_all_selection (selection);
+
+}
+
+
+static CORBA_boolean
+impl_clearSelection (PortableServer_Servant servant,
+                    CORBA_Environment     *ev)
 {
-  SpiSelection *selection = SPI_SELECTION (bonobo_object_from_servant (_servant));
-  atk_selection_clear_selection (ATK_SELECTION(selection->atko));
+  AtkSelection *selection = get_selection_from_servant (servant);
+
+  g_return_val_if_fail (selection != NULL, FALSE);
+
+  return atk_selection_clear_selection (selection);
 }
 
+
 static void
 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 = spi_selection_finalize;
-
 
   /* Initialize epv table */
 
   epv->_get_nSelectedChildren = impl__get_nSelectedChildren;
-  epv->getSelectedChild = impl_getSelectedChild;
-  epv->selectChild = impl_selectChild;
-  epv->deselectSelectedChild = impl_deselectSelectedChild;
-  epv->isChildSelected = impl_isChildSelected;
-  epv->selectAll = impl_selectAll;
-  epv->clearSelection = impl_clearSelection;
+  epv->getSelectedChild       = impl_getSelectedChild;
+  epv->selectChild            = impl_selectChild;
+  epv->deselectSelectedChild  = impl_deselectSelectedChild;
+  epv->deselectChild          = impl_deselectChild;
+  epv->isChildSelected        = impl_isChildSelected;
+  epv->selectAll              = impl_selectAll;
+  epv->clearSelection         = impl_clearSelection;
 }
 
+
 static void
 spi_selection_init (SpiSelection *selection)
 {
 }
 
+
 BONOBO_TYPE_FUNC_FULL (SpiSelection,
                       Accessibility_Selection,
-                      BONOBO_TYPE_OBJECT,
-                      spi_selection);
+                      SPI_TYPE_BASE,
+                      spi_selection)