From: Mike Gorse Date: Thu, 17 Apr 2008 21:17:53 +0000 (-0400) Subject: Add Action interface. X-Git-Tag: AT_SPI2_ATK_2_12_0~760 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fat-spi2-atk.git;a=commitdiff_plain;h=6a248c59635aa47229959cf46f9a9917f2e4c245 Add Action interface. Add Action interface --- diff --git a/libspi/accessible.h b/libspi/accessible.h index 6227980..dbc5d54 100644 --- a/libspi/accessible.h +++ b/libspi/accessible.h @@ -34,6 +34,7 @@ G_BEGIN_DECLS Accessibility_Role spi_accessible_role_from_atk_role (AtkRole role); void spi_initialize_accessible(DRouteData *data); +void spi_initialize_action(DRouteData *data); void spi_initialize_application(DRouteData *data); void spi_initialize_component(DRouteData *data); void spi_initialize_document(DRouteData *data); diff --git a/libspi/action.c b/libspi/action.c index a60af42..4641086 100644 --- a/libspi/action.c +++ b/libspi/action.c @@ -1,7 +1,9 @@ + /* * AT-SPI - Assistive Technology Service Provider Interface * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap) * + * Copyright 2008 Novell, Inc. * Copyright 2001, 2002 Sun Microsystems Inc., * Copyright 2001, 2002 Ximian, Inc. * @@ -21,141 +23,102 @@ * Boston, MA 02111-1307, USA. */ -/* component.c : bonobo wrapper for accessible component implementation */ - -#include -#include -#include -#include - -/* - * Static function declarations - */ - -static void -spi_action_class_init (SpiActionClass *klass); -static void -spi_action_init (SpiAction *action); -static CORBA_long -impl__get_nActions(PortableServer_Servant servant, - CORBA_Environment * ev); -static CORBA_string -impl_getDescription (PortableServer_Servant servant, - const CORBA_long index, - CORBA_Environment * ev); -static CORBA_boolean -impl_doAction (PortableServer_Servant servant, - const CORBA_long index, CORBA_Environment * ev); -static CORBA_string -impl_getName (PortableServer_Servant servant, - const CORBA_long index, - CORBA_Environment * ev); -static CORBA_string -impl_getKeyBinding (PortableServer_Servant servant, - const CORBA_long index, - CORBA_Environment * ev); - -BONOBO_TYPE_FUNC_FULL (SpiAction, - Accessibility_Action, - SPI_TYPE_BASE, - spi_action) - -static void -spi_action_class_init (SpiActionClass *klass) -{ - POA_Accessibility_Action__epv *epv = &klass->epv; - - /* Initialize epv table */ - - epv->_get_nActions = impl__get_nActions; - epv->doAction = impl_doAction; - epv->getDescription = impl_getDescription; - epv->getName = impl_getName; - epv->getKeyBinding = impl_getKeyBinding; -} - -static void -spi_action_init (SpiAction *action) -{ -} - -SpiAction * -spi_action_interface_new (AtkObject *obj) -{ - SpiAction *new_action = g_object_new (SPI_ACTION_TYPE, NULL); - - spi_base_construct (SPI_BASE (new_action), G_OBJECT(obj)); - - return new_action; -} +#include "accessible.h" static AtkAction * -get_action_from_servant (PortableServer_Servant servant) +get_action (DBusMessage * message) { - SpiBase *object = SPI_BASE (bonobo_object_from_servant (servant)); - g_return_val_if_fail (object != NULL, NULL); - /* the convention of making hyperlinks actionable breaks the assertion below */ - /* g_return_val_if_fail (ATK_IS_OBJECT(object->gobj), NULL); */ - return ATK_ACTION (object->gobj); + AtkObject *obj = spi_dbus_get_object (dbus_message_get_path (message)); + if (!obj) + return NULL; + return ATK_ACTION (obj); } -static CORBA_long -impl__get_nActions (PortableServer_Servant servant, - CORBA_Environment *ev) +static AtkAction * +get_action_from_path (const char *path, void *user_data) { - AtkAction *action = get_action_from_servant (servant); - return atk_action_get_n_actions (action); + AtkObject *obj = spi_dbus_get_object (path); + if (!obj) + return NULL; + return ATK_ACTION (obj); } -static CORBA_boolean -impl_doAction (PortableServer_Servant servant, - const CORBA_long index, CORBA_Environment * ev) +static DBusMessage *impl_getActions(DBusConnection *bus, DBusMessage *message, void *user_data) { - AtkAction *action = get_action_from_servant (servant); - return atk_action_do_action (action, (gint) index); + AtkAction *action = get_action(message); + DBusMessage *reply; + gint count; + gint i; + DBusMessageIter iter, iter_array, iter_struct; + + if (!action) + return spi_dbus_general_error (message); + count = atk_action_get_n_actions(action); + reply = dbus_message_new_method_return (message); + if (!reply) goto oom; + dbus_message_iter_init_append (reply, &iter); + if (!dbus_message_iter_open_container + (&iter, DBUS_TYPE_ARRAY, "(sss)", &iter_array)) + goto oom; + for (i = 0; i < count; i++) + { + const char *name = atk_action_get_name(action, i); + const char *desc = atk_action_get_description(action, i); + const char *kb = atk_action_get_keybinding(action, i); + if (!name) name = ""; + if (!desc) desc = ""; + if (!kb) kb = ""; + if (!dbus_message_iter_open_container(&iter_array, DBUS_TYPE_STRUCT, NULL, &iter_struct)) goto oom; + dbus_message_iter_append_basic(&iter_struct, DBUS_TYPE_STRING, &name); + dbus_message_iter_append_basic(&iter_struct, DBUS_TYPE_STRING, &desc); + dbus_message_iter_append_basic(&iter_struct, DBUS_TYPE_STRING, &kb); + if (!dbus_message_iter_close_container(&iter_array, &iter_struct)) goto oom; + } + if (!dbus_message_iter_close_container (&iter, &iter_array)) + goto oom; + return reply; +oom: + // TODO: handle out-of-memory + return reply; } -static CORBA_string -impl_getDescription (PortableServer_Servant servant, - const CORBA_long index, - CORBA_Environment * ev) +static DBusMessage *impl_doAction(DBusConnection *bus, DBusMessage *message, void *user_data) { - AtkAction *action = get_action_from_servant (servant); - const gchar *rv; - - rv = atk_action_get_description (action, index); - if (rv) - return CORBA_string_dup (rv); - else - return CORBA_string_dup (""); + AtkAction *action = get_action(message); + DBusError error; + dbus_int32_t index; + dbus_bool_t rv; + DBusMessage *reply; + + if (!action) + return spi_dbus_general_error (message); + dbus_error_init (&error); + if (!dbus_message_get_args + (message, &error, DBUS_TYPE_INT32, &index, DBUS_TYPE_INVALID)) + { + return SPI_DBUS_RETURN_ERROR (message, &error); + } + rv = atk_action_do_action(action, index); + 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_string -impl_getName (PortableServer_Servant servant, - const CORBA_long index, - CORBA_Environment * ev) +DRouteMethod methods[] = { - AtkAction *action = get_action_from_servant (servant); - const gchar *rv; - - rv = atk_action_get_name (action, index); - if (rv) - return CORBA_string_dup (rv); - else - return CORBA_string_dup (""); -} + { DROUTE_METHOD, impl_getActions, "getActions", "a(sss),,o" }, + { DROUTE_METHOD, impl_doAction, "doAction", "i,index,i:b,,o" }, + { 0, NULL, NULL, NULL } +}; -static CORBA_string -impl_getKeyBinding (PortableServer_Servant servant, - const CORBA_long index, - CORBA_Environment * ev) +void +spi_initialize_action (DRouteData * data) { - AtkAction *action = get_action_from_servant (servant); - const gchar *rv; - - rv = atk_action_get_keybinding (action, index); - if (rv) - return CORBA_string_dup (rv); - else - return CORBA_string_dup (""); -} + droute_add_interface (data, "org.freedesktop.accessibility.Action", + methods, NULL, + (DRouteGetDatumFunction) get_action_from_path, + NULL); +}; diff --git a/xml/Accessibility_Action.xml b/xml/Accessibility_Action.xml index bdb4fae..4d7a51f 100644 --- a/xml/Accessibility_Action.xml +++ b/xml/Accessibility_Action.xml @@ -29,48 +29,37 @@ buttons), "menu" (for objects which have context menus invokable from mouse or keyboard), "open" for icons representing files folders, and others.

- - -

nActions: a \c long containing the number of actions this object supports.

-
-
- - - getDescription: - - - - the index of the action for which a description is desired.Get the description of the specified action. The description of an actionmay provide information about the result of action invocation, unlike theaction name.@see getName. - - - - + + + a \c string containing the description of the specified action. + + + + + the description of the specified action. The description of an actionmay provide information about the result of action invocation, unlike the action name. - - - - - getName: - - - - the index of the action whose name is requested.Get the name of the specified action. Action names generally describethe user action, i.e. "click" or "press", rather then the result of invoking the action. - - - + + + + a \c string containing the key binding for the specified action,or an empty string ("") if none exists. + + + + + - a \c string containing the name of the specified action. + Retrieves the actions associated with the object. - + - doAction: + Causes the object to perform the specified action. - the 0-based index of the action to perform.Causes the object to perform the specified action. + the 0-based index of the action to perform. @@ -79,34 +68,5 @@ - - - getKeyBinding: - - - - the 0-based index of the action for which a key binding is requested.Get the key binding associated with a specific action. - - - - - a \c string containing the key binding for the specified action,or an empty string ("") if none exists. - - - - - -

\cond - unImplemented:

- -

placeholders for future expansion.

-
-
- - - - - -