* AT-SPI - Assistive Technology Service Provider Interface
* (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
*
- * Copyright 2001 Sun Microsystems Inc.
+ * Copyright 2008 Novell, 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
* Boston, MA 02111-1307, USA.
*/
-/* selection.c : implements the Selection interface */
-
-#include <config.h>
-#include <stdio.h>
-#include <libspi/accessible.h>
-#include <libspi/selection.h>
-
-/* Static function declarations */
-
-static void
-spi_selection_class_init (SpiSelectionClass *klass);
-static void
-spi_selection_init (SpiSelection *selection);
-static void
-spi_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);
-
-
-static GObjectClass *parent_class;
-
-GType
-spi_selection_get_type (void)
-{
- static GType type = 0;
-
- if (!type) {
- static const GTypeInfo tinfo = {
- sizeof (SpiSelectionClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) spi_selection_class_init,
- (GClassFinalizeFunc) NULL,
- NULL, /* class data */
- sizeof (SpiSelection),
- 0, /* n preallocs */
- (GInstanceInitFunc) spi_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_TYPE_OBJECT,
- POA_Accessibility_Selection__init,
- NULL,
- G_STRUCT_OFFSET (SpiSelectionClass, epv),
- &tinfo,
- "SpiAccessibleSelection");
- }
-
- return type;
-}
+#include "accessible.h"
-static void
-spi_selection_class_init (SpiSelectionClass *klass)
+static AtkSelection *
+get_selection (DBusMessage * message)
{
- 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;
+ AtkObject *obj = spi_dbus_get_object (dbus_message_get_path (message));
+ if (!obj)
+ return NULL;
+ return ATK_SELECTION (obj);
}
-static void
-spi_selection_init (SpiSelection *selection)
+static AtkSelection *
+get_selection_from_path (const char *path, void *user_data)
{
+ AtkObject *obj = spi_dbus_get_object (path);
+ if (!obj || ~ATK_IS_SELECTION(obj))
+ return NULL;
+ return ATK_SELECTION (obj);
}
-static void
-spi_selection_finalize (GObject *obj)
+static dbus_bool_t
+impl_get_nSelectedChildren (const char *path, DBusMessageIter * iter,
+ void *user_data)
{
- SpiSelection *selection = SPI_SELECTION (obj);
- g_object_unref (selection->atko);
- selection->atko = NULL;
- parent_class->finalize (obj);
+ AtkSelection *selection = get_selection_from_path (path, user_data);
+ if (!selection)
+ return FALSE;
+ return droute_return_v_int32 (iter,
+ atk_selection_get_selection_count
+ (selection));
}
-SpiSelection *
-spi_selection_interface_new (AtkObject *obj)
+static char *
+impl_get_nSelectedChildren_str (void *datum)
{
- SpiSelection *new_selection =
- SPI_SELECTION(g_object_new (SPI_SELECTION_TYPE, NULL));
- new_selection->atko = obj;
- g_object_ref (obj);
- return new_selection;
+ g_assert (ATK_IS_HYPERLINK (datum));
+ return g_strdup_printf ("%d",
+ atk_selection_get_selection_count ((AtkSelection *)
+ datum));
}
-
-
-static CORBA_long
-impl__get_nSelectedChildren (PortableServer_Servant _servant,
- CORBA_Environment * ev)
+static DBusMessage *
+impl_getSelectedChild (DBusConnection * bus, DBusMessage * message,
+ void *user_data)
{
- 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 (message);
+ DBusError error;
+ dbus_int32_t selectedChildIndex;
+ AtkObject *atk_object;
+ if (!selection)
+ return spi_dbus_general_error (message);
+ dbus_error_init (&error);
+ if (!dbus_message_get_args
+ (message, &error, DBUS_TYPE_INT32, &selectedChildIndex,
+ DBUS_TYPE_INVALID))
+ {
+ return SPI_DBUS_RETURN_ERROR (message, &error);
+ }
+ atk_object = atk_selection_ref_selection (selection, selectedChildIndex);
+ return spi_dbus_return_object (message, atk_object, TRUE);
+}
-static Accessibility_Accessible
-impl_getSelectedChild (PortableServer_Servant _servant,
- const CORBA_long selectedChildIndex,
- CORBA_Environment * ev)
+static DBusMessage *
+impl_selectChild (DBusConnection * bus, DBusMessage * message,
+ void *user_data)
{
- BonoboObject *obj = bonobo_object_from_servant (_servant);
- SpiSelection
- *selection;
- AtkObject *atk_object;
- Accessibility_Accessible 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);
+ AtkSelection *selection = get_selection (message);
+ DBusError error;
+ dbus_int32_t childIndex;
+ dbus_bool_t rv;
+ DBusMessage *reply;
+
+ if (!selection)
+ return spi_dbus_general_error (message);
+ dbus_error_init (&error);
+ if (!dbus_message_get_args
+ (message, &error, DBUS_TYPE_INT32, &childIndex, DBUS_TYPE_INVALID))
+ {
+ return SPI_DBUS_RETURN_ERROR (message, &error);
+ }
+ rv = atk_selection_add_selection (selection, childIndex);
+ reply = dbus_message_new_method_return (message);
+ if (reply)
+ {
+ dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
+ DBUS_TYPE_INVALID);
+ }
+ return reply;
}
-
-
-static CORBA_boolean
-impl_selectChild (PortableServer_Servant _servant,
- const CORBA_long childIndex,
- CORBA_Environment * ev)
+static DBusMessage *
+impl_deselectSelectedChild (DBusConnection * bus, DBusMessage * message,
+ void *user_data)
{
- 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 (message);
+ DBusError error;
+ dbus_int32_t selectedChildIndex;
+ dbus_bool_t rv;
+ DBusMessage *reply;
+
+ if (!selection)
+ return spi_dbus_general_error (message);
+ dbus_error_init (&error);
+ if (!dbus_message_get_args
+ (message, &error, DBUS_TYPE_INT32, &selectedChildIndex,
+ DBUS_TYPE_INVALID))
+ {
+ return SPI_DBUS_RETURN_ERROR (message, &error);
+ }
+ rv = atk_selection_remove_selection (selection, selectedChildIndex);
+ reply = dbus_message_new_method_return (message);
+ if (reply)
+ {
+ dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
+ DBUS_TYPE_INVALID);
+ }
+ return reply;
}
-
-
-
-static CORBA_boolean
-impl_deselectSelectedChild (PortableServer_Servant _servant,
- const CORBA_long selectedChildIndex,
- CORBA_Environment * ev)
+static DBusMessage *
+impl_isChildSelected (DBusConnection * bus, DBusMessage * message,
+ void *user_data)
{
- 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 (message);
+ DBusError error;
+ dbus_int32_t childIndex;
+ dbus_bool_t rv;
+ DBusMessage *reply;
+
+ if (!selection)
+ return spi_dbus_general_error (message);
+ dbus_error_init (&error);
+ if (!dbus_message_get_args
+ (message, &error, DBUS_TYPE_INT32, &childIndex, DBUS_TYPE_INVALID))
+ {
+ return SPI_DBUS_RETURN_ERROR (message, &error);
+ }
+ rv = atk_selection_is_child_selected (selection, childIndex);
+ reply = dbus_message_new_method_return (message);
+ if (reply)
+ {
+ dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
+ DBUS_TYPE_INVALID);
+ }
+ return reply;
}
-
-
-static CORBA_boolean
-impl_isChildSelected (PortableServer_Servant _servant,
- const CORBA_long childIndex,
- CORBA_Environment * ev)
+static DBusMessage *
+impl_selectAll (DBusConnection * bus, DBusMessage * message, void *user_data)
{
- 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 (message);
+ dbus_bool_t rv;
+ DBusMessage *reply;
+
+ if (!selection)
+ return spi_dbus_general_error (message);
+ rv = atk_selection_select_all_selection (selection);
+ reply = dbus_message_new_method_return (message);
+ if (reply)
+ {
+ dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
+ DBUS_TYPE_INVALID);
+ }
+ return reply;
}
-
-
-static void
-impl_selectAll (PortableServer_Servant _servant,
- CORBA_Environment * ev)
+static DBusMessage *
+impl_clearSelection (DBusConnection * bus, DBusMessage * message,
+ void *user_data)
{
- SpiSelection *selection = SPI_SELECTION (bonobo_object_from_servant (_servant));
- atk_selection_select_all_selection (ATK_SELECTION(selection->atko));
+ AtkSelection *selection = get_selection (message);
+ dbus_bool_t rv;
+ DBusMessage *reply;
+
+ if (!selection)
+ return spi_dbus_general_error (message);
+ rv = atk_selection_clear_selection (selection);
+ reply = dbus_message_new_method_return (message);
+ if (reply)
+ {
+ dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
+ DBUS_TYPE_INVALID);
+ }
+ return reply;
}
-
-
-static void
-impl_clearSelection (PortableServer_Servant _servant,
- CORBA_Environment * ev)
+static DBusMessage *
+impl_deselectChild (DBusConnection * bus, DBusMessage * message,
+ void *user_data)
{
- SpiSelection *selection = SPI_SELECTION (bonobo_object_from_servant (_servant));
- atk_selection_clear_selection (ATK_SELECTION(selection->atko));
+ AtkSelection *selection = get_selection (message);
+ DBusError error;
+ dbus_int32_t selectedChildIndex;
+ dbus_bool_t rv = FALSE;
+ gint i, nselected;
+ DBusMessage *reply;
+
+ if (!selection)
+ return spi_dbus_general_error (message);
+ dbus_error_init (&error);
+ if (!dbus_message_get_args
+ (message, &error, DBUS_TYPE_INT32, &selectedChildIndex,
+ DBUS_TYPE_INVALID))
+ {
+ return SPI_DBUS_RETURN_ERROR (message, &error);
+ }
+ 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));
+ rv = atk_selection_remove_selection (selection, i);
+ break;
+ }
+ g_object_unref (G_OBJECT (selected_obj));
+ }
+ reply = dbus_message_new_method_return (message);
+ if (reply)
+ {
+ dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
+ DBUS_TYPE_INVALID);
+ }
+ return reply;
}
+static DRouteMethod methods[] = {
+ {impl_getSelectedChild, "getSelectedChild"},
+ {impl_selectChild, "selectChild"},
+ {impl_deselectSelectedChild, "deselectSelectedChild"},
+ {impl_isChildSelected, "isChildSelected"},
+ {impl_selectAll, "selectAll"},
+ {impl_clearSelection, "clearSelection"},
+ {impl_deselectChild, "deselectChild"},
+ {NULL, NULL}
+};
+
+static DRouteProperty properties[] = {
+ {impl_get_nSelectedChildren, NULL, "nSelectedChildren"},
+ {NULL, NULL, NULL}
+};
+
+void
+spi_initialize_selection (DRouteData * data)
+{
+ droute_add_interface (data, "org.freedesktop.atspi.Selection",
+ methods, properties,
+ (DRouteGetDatumFunction) get_selection_from_path,
+ NULL);
+};