* 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 void
-selection_class_init (SelectionClass *klass);
-static void
-selection_init (Selection *selection);
-static void
-selection_finalize (GObject *obj);
-static CORBA_long
-impl__get_nSelectedChildren (PortableServer_Servant _servant,
- CORBA_Environment * ev);
-static Accessibility_Accessible
-impl_getSelectedChild (PortableServer_Servant _servant,
- const CORBA_long selectedChildIndex,
- CORBA_Environment * ev);
-static CORBA_boolean
-impl_selectChild (PortableServer_Servant _servant,
- const CORBA_long childIndex,
- CORBA_Environment * ev);
-static CORBA_boolean
-impl_deselectSelectedChild (PortableServer_Servant _servant,
- const CORBA_long selectedChildIndex,
- CORBA_Environment * ev);
-static CORBA_boolean
-impl_isChildSelected (PortableServer_Servant _servant,
- const CORBA_long childIndex,
- CORBA_Environment * ev);
-static void
-impl_selectAll (PortableServer_Servant _servant,
- CORBA_Environment * ev);
-static void
-impl_clearSelection (PortableServer_Servant _servant,
- CORBA_Environment * ev);
+SpiSelection *
+spi_selection_interface_new (AtkObject *obj)
+{
+ SpiSelection *new_selection = g_object_new (SPI_SELECTION_TYPE, NULL);
-static GObjectClass *parent_class;
+ spi_base_construct (SPI_BASE (new_selection), obj);
-GType
-selection_get_type (void)
-{
- static GType type = 0;
-
- if (!type) {
- static const GTypeInfo tinfo = {
- sizeof (SelectionClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) selection_class_init,
- (GClassFinalizeFunc) NULL,
- NULL, /* class data */
- sizeof (Selection),
- 0, /* n preallocs */
- (GInstanceInitFunc) selection_init,
- NULL /* value table */
- };
-
- /*
- * Bonobo_type_unique auto-generates a load of
- * CORBA structures for us. All derived types must
- * use bonobo_type_unique.
- */
- type = bonobo_type_unique (
- BONOBO_OBJECT_TYPE,
- POA_Accessibility_Selection__init,
- NULL,
- G_STRUCT_OFFSET (SelectionClass, epv),
- &tinfo,
- "AccessibleSelection");
- }
-
- return type;
+ return new_selection;
}
-static void
-selection_class_init (SelectionClass *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;
+static AtkSelection *
+get_selection_from_servant (PortableServer_Servant servant)
+{
+ SpiBase *object = SPI_BASE (bonobo_object_from_servant (servant));
- /* Initialize epv table */
+ if (!object)
+ {
+ return NULL;
+ }
- 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;
+ return ATK_SELECTION (object->atko);
}
-static void
-selection_init (Selection *selection)
-{
-}
-static void
-selection_finalize (GObject *obj)
+static CORBA_long
+impl__get_nSelectedChildren (PortableServer_Servant servant,
+ CORBA_Environment *ev)
{
- Selection *selection = SELECTION (obj);
- g_object_unref (selection->atko);
- selection->atko = NULL;
- parent_class->finalize (obj);
-}
+ AtkSelection *selection = get_selection_from_servant (servant);
-Selection *
-selection_interface_new (AtkObject *obj)
-{
- Selection *new_selection =
- SELECTION(g_object_new (SELECTION_TYPE, NULL));
- new_selection->atko = obj;
- g_object_ref (obj);
- return new_selection;
-}
+ g_return_val_if_fail (selection != NULL, 0);
+ return (CORBA_long) atk_selection_get_selection_count (selection);
+}
-static CORBA_long
-impl__get_nSelectedChildren (PortableServer_Servant _servant,
- CORBA_Environment * ev)
+static Accessibility_Accessible
+impl_getSelectedChild (PortableServer_Servant servant,
+ const CORBA_long selectedChildIndex,
+ CORBA_Environment *ev)
{
- Selection *selection = SELECTION (bonobo_object_from_servant (_servant));
- return (CORBA_long)
- atk_selection_get_selection_count (ATK_SELECTION(selection->atko));
-}
+ 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
+ atk_object = atk_selection_ref_selection (selection,
+ (gint) selectedChildIndex);
-static Accessibility_Accessible
-impl_getSelectedChild (PortableServer_Servant _servant,
- const CORBA_long selectedChildIndex,
- CORBA_Environment * ev)
-{
- Selection *selection = SELECTION (bonobo_object_from_servant (_servant));
- AtkObject *atk_object;
- Accessibility_Accessible rv;
+ g_return_val_if_fail (ATK_IS_OBJECT (atk_object), CORBA_OBJECT_NIL);
- atk_object = atk_selection_ref_selection (ATK_SELECTION(selection->atko), (gint) selectedChildIndex);
- rv = bonobo_object_corba_objref (BONOBO_OBJECT(accessible_new(atk_object)));
- return rv;
-}
+#ifdef SPI_DEBUG
+ fprintf (stderr, "child type is %s\n",
+ g_type_name (G_OBJECT_TYPE (atk_object)));
+#endif
+ 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)
{
- Selection *selection = 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 (CORBA_boolean)
+ atk_selection_add_selection (selection, (gint) 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)
{
- Selection *selection = SELECTION (bonobo_object_from_servant (_servant));
+ AtkSelection *selection = get_selection_from_servant (servant);
+
+ g_return_val_if_fail (selection != NULL, FALSE);
+
return (CORBA_boolean)
- atk_selection_remove_selection (ATK_SELECTION(selection->atko), (gint) selectedChildIndex);
+ atk_selection_remove_selection (selection, (gint) selectedChildIndex);
}
-
static CORBA_boolean
-impl_isChildSelected (PortableServer_Servant _servant,
- const CORBA_long childIndex,
- CORBA_Environment * ev)
+impl_isChildSelected (PortableServer_Servant servant,
+ const CORBA_long childIndex,
+ CORBA_Environment *ev)
{
- Selection *selection = SELECTION (bonobo_object_from_servant (_servant));
+ AtkSelection *selection = get_selection_from_servant (servant);
+
+ g_return_val_if_fail (selection != NULL, FALSE);
+
return (CORBA_boolean)
- atk_selection_is_child_selected (ATK_SELECTION(selection->atko), (gint) childIndex);
+ atk_selection_is_child_selected (selection, (gint) childIndex);
}
+static void
+impl_selectAll (PortableServer_Servant servant,
+ CORBA_Environment *ev)
+{
+ AtkSelection *selection = get_selection_from_servant (servant);
+
+ g_return_if_fail (selection != NULL);
+
+ atk_selection_select_all_selection (selection);
+}
+
static void
-impl_selectAll (PortableServer_Servant _servant,
- CORBA_Environment * ev)
+impl_clearSelection (PortableServer_Servant servant,
+ CORBA_Environment *ev)
{
- Selection *selection = SELECTION (bonobo_object_from_servant (_servant));
- atk_selection_select_all_selection (ATK_SELECTION(selection->atko));
+ AtkSelection *selection = get_selection_from_servant (servant);
+
+ g_return_if_fail (selection != NULL);
+
+ atk_selection_clear_selection (selection);
}
+static void
+spi_selection_class_init (SpiSelectionClass *klass)
+{
+ POA_Accessibility_Selection__epv *epv = &klass->epv;
-static void
-impl_clearSelection (PortableServer_Servant _servant,
- CORBA_Environment * ev)
+ /* 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;
+}
+
+
+static void
+spi_selection_init (SpiSelection *selection)
{
- Selection *selection = SELECTION (bonobo_object_from_servant (_servant));
- atk_selection_clear_selection (ATK_SELECTION(selection->atko));
}
+
+BONOBO_TYPE_FUNC_FULL (SpiSelection,
+ Accessibility_Selection,
+ SPI_TYPE_BASE,
+ spi_selection);