Initial commit.
[platform/core/uifw/at-spi2-atk.git] / libspi / component.c
index 3c9ff9a..7526dc4 100644 (file)
@@ -2,7 +2,9 @@
  * 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.
  */
 
-/*
- * component.c : bonobo wrapper for accessible component implementation
- *
- */
-#include <config.h>
-#include <bonobo/Bonobo.h>
-
-#include <stdio.h>
-
-/*
- * This pulls the CORBA definitions for the "Accessibility::Accessible" server
- */
-#include <libspi/Accessibility.h>
-
-/*
- * This pulls the definition for the BonoboObject (Gtk Type)
- */
-#include "component.h"
 #include "accessible.h"
 
-/*
- * Our parent Gtk object type
- */
-#define PARENT_TYPE BONOBO_OBJECT_TYPE
-
-/*
- * A pointer to our parent object class
- */
-static GObjectClass *component_parent_class;
+static AtkComponent *
+get_component (DBusMessage * message)
+{
+  AtkObject *obj = spi_dbus_get_object (dbus_message_get_path (message));
+  if (!obj)
+    return NULL;
+  return ATK_COMPONENT (obj);
+}
 
-/*
- * Implemented GObject::finalize
- */
-static void
-accessibility_component_object_finalize (GObject *object)
+static AtkComponent *
+get_component_from_path (const char *path, void *user_data)
 {
-        Component *component = COMPONENT (object);
+  AtkObject *obj = spi_dbus_get_object (path);
+  if (!obj)
+    return NULL;
+  return ATK_COMPONENT (obj);
+}
 
-        printf("accessible_component_object_finalize called\n");
-        g_object_unref (component->atko);
-       component->atko = NULL;
+static DBusMessage *
+impl_contains (DBusConnection * bus, DBusMessage * message, void *user_data)
+{
+  AtkComponent *component = get_component (message);
+  dbus_int32_t x, y;
+  dbus_uint32_t coord_type;
+  DBusError error;
+  dbus_bool_t retval;
+  DBusMessage *reply;
 
-        printf("atko freed, calling parent finalize\n");
-        component_parent_class->finalize (object);
+  if (!component)
+    return spi_dbus_general_error (message);
+  dbus_error_init (&error);
+  if (!dbus_message_get_args
+      (message, &error, DBUS_TYPE_INT32, &x, DBUS_TYPE_UINT32, &y,
+       DBUS_TYPE_INT32, &coord_type, DBUS_TYPE_INVALID))
+    {
+      return SPI_DBUS_RETURN_ERROR (message, &error);
+    }
+  retval =
+    atk_component_contains (component, x, y, (AtkCoordType) coord_type);
+  reply = dbus_message_new_method_return (message);
+  if (reply)
+    {
+      dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &retval,
+                               DBUS_TYPE_INVALID);
+    }
+  return reply;
 }
 
-/*
- * CORBA Accessibility::Component::contains method implementation
- */
-static CORBA_boolean
-impl_accessibility_component_contains (PortableServer_Servant servant,
-                                       const CORBA_long x,
-                                       const CORBA_long y,
-                                       CORBA_short coord_type,
-                                       CORBA_Environment     *ev)
+static DBusMessage *
+impl_getAccessibleAtPoint (DBusConnection * bus, DBusMessage * message,
+                          void *user_data)
 {
-  CORBA_boolean retval;
-  Component *component = COMPONENT (bonobo_object_from_servant (servant));
-  retval = atk_component_contains (ATK_COMPONENT (component->atko), (gint) x, (gint) y,
-                                  (AtkCoordType) coord_type);
-  fprintf (stderr, "Component contains() called: %s\n", retval ? "true" : "false" );
-  return retval;
+  AtkComponent *component = get_component (message);
+  dbus_int32_t x, y;
+  dbus_uint32_t coord_type;
+  DBusError error;
+  AtkObject *child;
+
+  if (!component)
+    return spi_dbus_general_error (message);
+  dbus_error_init (&error);
+  if (!dbus_message_get_args
+      (message, &error, DBUS_TYPE_INT32, &x, DBUS_TYPE_INT32, &y,
+       DBUS_TYPE_UINT32, &coord_type, DBUS_TYPE_INVALID))
+    {
+      return SPI_DBUS_RETURN_ERROR (message, &error);
+    }
+  child =
+    atk_component_ref_accessible_at_point (component, x, y,
+                                          (AtkCoordType) coord_type);
+  return spi_dbus_return_object (message, child, TRUE);
 }
 
-/*
- * CORBA Accessibility::Component::getAccessibleAtPoint method implementation
- */
-static Accessibility_Accessible
-impl_accessibility_component_get_accessible_at_point (PortableServer_Servant servant,
-                                                      const CORBA_long x,
-                                                      const CORBA_long y,
-                                                      CORBA_short coord_type,
-                                                      CORBA_Environment     *ev)
+static DBusMessage *
+impl_getExtents (DBusConnection * bus, DBusMessage * message, void *user_data)
 {
-  Accessibility_Accessible retval;
-  Component *component = COMPONENT (bonobo_object_from_servant (servant));
-  AtkObject *child;
-  child = atk_component_ref_accessible_at_point (ATK_COMPONENT (component->atko),
-                                                  (gint) x, (gint) y,
-                                                  (AtkCoordType) coord_type);
-  retval = bonobo_object_corba_objref (bonobo_object (accessible_new (child)));
-  return retval;
+  AtkComponent *component = get_component (message);
+  DBusError error;
+  dbus_uint32_t coord_type;
+  gint ix, iy, iwidth, iheight;
+
+  if (!component)
+    return spi_dbus_general_error (message);
+  dbus_error_init (&error);
+  if (!dbus_message_get_args
+      (message, &error, DBUS_TYPE_UINT32, &coord_type, DBUS_TYPE_INVALID))
+    {
+      return SPI_DBUS_RETURN_ERROR (message, &error);
+    }
+  atk_component_get_extents (component, &ix, &iy, &iwidth, &iheight,
+                            (AtkCoordType) coord_type);
+  return spi_dbus_return_rect (message, ix, iy, iwidth, iheight);
 }
 
-/*
- * CORBA Accessibility::Component::getExtents method implementation
- */
-static void
-impl_accessibility_component_get_extents (PortableServer_Servant servant,
-                                          CORBA_long * x,
-                                          CORBA_long * y,
-                                          CORBA_long * width,
-                                          CORBA_long * height,
-                                          const CORBA_short coord_type,
-                                          CORBA_Environment     *ev)
+static DBusMessage *
+impl_getPosition (DBusConnection * bus, DBusMessage * message,
+                 void *user_data)
 {
-  Component *component = COMPONENT (bonobo_object_from_servant (servant));
-  gint ix, iy, iw, ih;
-  atk_component_get_extents (ATK_COMPONENT (component->atko), &ix, &iy, &iw, &ih,
-                                  (AtkCoordType) coord_type);
-  *x = (CORBA_long) ix;
-  *y = (CORBA_long) iy;
-  *width = (CORBA_long) iw;
-  *height = (CORBA_long) ih;
+  AtkComponent *component = get_component (message);
+  DBusError error;
+  dbus_uint32_t coord_type;
+  gint ix = 0, iy = 0;
+  dbus_int32_t x, y;
+  DBusMessage *reply;
+
+  if (!component)
+    return spi_dbus_general_error (message);
+  dbus_error_init (&error);
+  if (!dbus_message_get_args
+      (message, &error, DBUS_TYPE_UINT32, &coord_type, DBUS_TYPE_INVALID))
+    {
+      return SPI_DBUS_RETURN_ERROR (message, &error);
+    }
+  atk_component_get_position (component, &ix, &iy, (AtkCoordType) coord_type);
+  x = ix;
+  y = iy;
+  reply = dbus_message_new_method_return (message);
+  if (reply)
+    {
+      dbus_message_append_args (reply, DBUS_TYPE_INT32, &x, DBUS_TYPE_INT32,
+                               &y, DBUS_TYPE_INVALID);
+    }
+  return reply;
 }
 
-/*
- * CORBA Accessibility::Component::getPosition method implementation
- */
-static void
-impl_accessibility_component_get_position (PortableServer_Servant servant,
-                                           CORBA_long * x,
-                                           CORBA_long * y,
-                                           const CORBA_short coord_type,
-                                           CORBA_Environment     *ev)
+static DBusMessage *
+impl_getSize (DBusConnection * bus, DBusMessage * message, void *user_data)
 {
-  Component *component = COMPONENT (bonobo_object_from_servant (servant));
-  gint ix, iy;
-  atk_component_get_position (ATK_COMPONENT (component->atko), &ix, &iy,
-                              (AtkCoordType) coord_type);
-  *x = (CORBA_long) ix;
-  *y = (CORBA_long) iy;
+  AtkComponent *component = get_component (message);
+  gint iwidth = 0, iheight = 0;
+  dbus_int32_t width, height;
+  DBusMessage *reply;
+
+  if (!component)
+    return spi_dbus_general_error (message);
+  atk_component_get_size (component, &iwidth, &iheight);
+  width = iwidth;
+  height = iheight;
+  reply = dbus_message_new_method_return (message);
+  if (reply)
+    {
+      dbus_message_append_args (reply, DBUS_TYPE_INT32, &width,
+                               DBUS_TYPE_INT32, &height, DBUS_TYPE_INVALID);
+    }
+  return reply;
 }
 
-/*
- * CORBA Accessibility::Component::getSize method implementation
- */
-static void
-impl_accessibility_component_get_size (PortableServer_Servant servant,
-                                       CORBA_long * width,
-                                       CORBA_long * height,
-                                       CORBA_Environment     *ev)
+static DBusMessage *
+impl_getLayer (DBusConnection * bus, DBusMessage * message, void *user_data)
 {
-  Component *component = COMPONENT (bonobo_object_from_servant (servant));
-  gint iw, ih;
-  atk_component_get_size (ATK_COMPONENT (component->atko), &iw, &ih);
-  *width = (CORBA_long) iw;
-  *height = (CORBA_long) ih;
+  AtkComponent *component = get_component (message);
+  AtkLayer atklayer;
+  dbus_uint32_t rv;
+  DBusMessage *reply;
+
+  if (!component)
+    return spi_dbus_general_error (message);
+  atklayer = atk_component_get_layer (component);
+
+  switch (atklayer)
+    {
+    case ATK_LAYER_BACKGROUND:
+      rv = Accessibility_LAYER_BACKGROUND;
+      break;
+    case ATK_LAYER_CANVAS:
+      rv = Accessibility_LAYER_CANVAS;
+      break;
+    case ATK_LAYER_WIDGET:
+      rv = Accessibility_LAYER_WIDGET;
+      break;
+    case ATK_LAYER_MDI:
+      rv = Accessibility_LAYER_MDI;
+      break;
+    case ATK_LAYER_POPUP:
+      rv = Accessibility_LAYER_POPUP;
+      break;
+    case ATK_LAYER_OVERLAY:
+      rv = Accessibility_LAYER_OVERLAY;
+      break;
+    case ATK_LAYER_WINDOW:
+      rv = Accessibility_LAYER_WINDOW;
+      break;
+    default:
+      rv = Accessibility_LAYER_INVALID;
+      break;
+    }
+  reply = dbus_message_new_method_return (message);
+  if (reply)
+    {
+      dbus_message_append_args (reply, DBUS_TYPE_UINT32, &rv,
+                               DBUS_TYPE_INVALID);
+    }
+  return reply;
 }
 
-static void
-accessibility_component_class_init (ComponentClass *klass)
+static DBusMessage *
+impl_getMDIZOrder (DBusConnection * bus, DBusMessage * message,
+                  void *user_data)
 {
-        GObjectClass * object_class = (GObjectClass *) klass;
-        POA_Accessibility_Component__epv *epv = &klass->epv;
-        component_parent_class = g_type_class_peek_parent (klass);
+  AtkComponent *component = get_component (message);
+  dbus_int16_t rv;
+  DBusMessage *reply;
 
-        object_class->finalize = accessibility_component_object_finalize;
+  if (!component)
+    return spi_dbus_general_error (message);
+  rv = atk_component_get_mdi_zorder (component);
+  reply = dbus_message_new_method_return (message);
+  if (reply)
+    {
+      dbus_message_append_args (reply, DBUS_TYPE_UINT32, &rv,
+                               DBUS_TYPE_INVALID);
+    }
+  return reply;
+}
 
-        epv->contains = impl_accessibility_component_contains;
-        epv->getAccessibleAtPoint = impl_accessibility_component_get_accessible_at_point;
-        epv->getExtents = impl_accessibility_component_get_extents;
-        epv->getPosition = impl_accessibility_component_get_position;
-        epv->getSize = impl_accessibility_component_get_size;
+static DBusMessage *
+impl_grabFocus (DBusConnection * bus, DBusMessage * message, void *user_data)
+{
+  AtkComponent *component = get_component (message);
+  dbus_bool_t rv;
+  DBusMessage *reply;
+
+  if (!component)
+    return spi_dbus_general_error (message);
+  rv = atk_component_grab_focus (component);
+  reply = dbus_message_new_method_return (message);
+  if (reply)
+    {
+      dbus_message_append_args (reply, DBUS_TYPE_UINT32, &rv,
+                               DBUS_TYPE_INVALID);
+    }
+  return reply;
 }
 
-static void
-accessibility_component_init (Component *component)
+#if 0
+static DBusMessage *
+impl_registerFocusHandler (DBusConnection * bus, DBusMessage * message,
+                          void *user_data)
 {
 }
 
-GType
-accessibility_component_get_type (void)
+static DBusMessage *
+impl_deregisterFocusHandler (DBusConnection * bus, DBusMessage * message,
+                            void *user_data)
 {
-        static GType type = 0;
-
-        if (!type) {
-                static const GTypeInfo tinfo = {
-                        sizeof (ComponentClass),
-                        (GBaseInitFunc) NULL,
-                        (GBaseFinalizeFunc) NULL,
-                        (GClassInitFunc) accessibility_component_class_init,
-                        (GClassFinalizeFunc) NULL,
-                        NULL, /* class data */
-                        sizeof (Component),
-                        0, /* n preallocs */
-                        (GInstanceInitFunc) accessibility_component_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 (
-                        PARENT_TYPE,
-                        POA_Accessibility_Component__init,
-                        NULL,
-                        G_STRUCT_OFFSET (ComponentClass, epv),
-                        &tinfo,
-                        "AccessibleComponent");
-        }
-
-        return type;
 }
+#endif
 
-Component *
-component_interface_new (AtkObject *o)
+static DBusMessage *
+impl_getAlpha (DBusConnection * bus, DBusMessage * message, void *user_data)
 {
-    Component *retval =
-               COMPONENT (g_object_new (accessibility_component_get_type (), NULL));
-    retval->atko = o;
-    g_object_ref (o);
-return retval;
+  AtkComponent *component = get_component (message);
+  double rv;
+  DBusMessage *reply;
+
+  if (!component)
+    return spi_dbus_general_error (message);
+  rv = atk_component_get_alpha (component);
+  reply = dbus_message_new_method_return (message);
+  if (reply)
+    {
+      dbus_message_append_args (reply, DBUS_TYPE_DOUBLE, &rv,
+                               DBUS_TYPE_INVALID);
+    }
+  return reply;
 }
+
+static DRouteMethod methods[] = {
+  {DROUTE_METHOD, impl_contains, "contains",
+   "i,x,i:i,y,i:u,coord_type,i:b,,o"},
+  {DROUTE_METHOD, impl_getAccessibleAtPoint, "getAccessibleAtPoint",
+   "i,x,i:i,y,i:u,coord_type,i:o,,o"},
+  {DROUTE_METHOD, impl_getExtents, "getExtents", "u,coord_type,i:(uuuu),,o"},
+  {DROUTE_METHOD, impl_getPosition, "getPosition",
+   "i,x,o:i,y,o:u,coord_type,i"},
+  {DROUTE_METHOD, impl_getSize, "getSize", "i,width,o:i,height,o"},
+  {DROUTE_METHOD, impl_getLayer, "getLayer", "g,,o"},
+  {DROUTE_METHOD, impl_getMDIZOrder, "getMDIZOrder", "n,,o"},
+  {DROUTE_METHOD, impl_grabFocus, "grabFocus", "b,,o"},
+  //{ DROUTE_METHOD, impl_registerFocusHandler, "registerFocusHandler", "o,handler,i" },
+  //{ DROUTE_METHOD, impl_deregisterFocusHandler, "deregisterFocusHandler", "o,handler,i" },
+  {DROUTE_METHOD, impl_getAlpha, "getAlpha", "d,,o"},
+  {0, NULL, NULL, NULL}
+};
+
+void
+spi_initialize_component (DRouteData * data)
+{
+  droute_add_interface (data, "org.freedesktop.accessibility.Component",
+                       methods, NULL,
+                       (DRouteGetDatumFunction) get_component_from_path,
+                       NULL);
+};