2002-05-02 Marc Mulcahy <marc.mulcahy@sun.com>
[platform/core/uifw/at-spi2-atk.git] / libspi / image.c
index f1c9893..cfa0586 100644 (file)
  * Boston, MA 02111-1307, USA.
  */
 
-/*
- * component.c : bonobo wrapper for accessible component implementation
- *
- */
-#include <config.h>
-#include <bonobo/Bonobo.h>
+/* image.c : implements the Image interface */
 
+#include <config.h>
 #include <stdio.h>
-
-/*
- * This pulls the CORBA definitions for the "Accessibility::Accessible" server
- */
-#include <libspi/Accessibility.h>
-
-/*
- * This pulls the definition of the image bonobo object
- */
-#include "image.h"
-
-/*
- * Static function declarations
- */
-
-static void
-image_class_init (ImageClass *klass);
-static void
-image_init (Image *image);
-static void
-image_finalize (GObject *obj);
-static void 
-impl_getImagePosition (PortableServer_Servant _servant,
-                      CORBA_long * x, CORBA_long * y,
-                      const CORBA_short coordType,
-                      CORBA_Environment * ev);
-static void 
-impl_getImageSize (PortableServer_Servant _servant,
-                  CORBA_long * width, CORBA_long * height,
-                  CORBA_Environment * ev);
-static CORBA_string 
-impl__get_imageDescription (PortableServer_Servant _servant,
-                         CORBA_Environment * ev);
+#include <libspi/image.h>
 
 
-static GObjectClass *parent_class;
-
-GType
-image_get_type (void)
+SpiImage *
+spi_image_interface_new (AtkObject *obj)
 {
-  static GType type = 0;
-
-  if (!type) {
-    static const GTypeInfo tinfo = {
-      sizeof (ImageClass),
-      (GBaseInitFunc) NULL,
-      (GBaseFinalizeFunc) NULL,
-      (GClassInitFunc) image_class_init,
-      (GClassFinalizeFunc) NULL,
-      NULL, /* class data */
-      sizeof (Image),
-      0, /* n preallocs */
-      (GInstanceInitFunc) image_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_Image__init,
-                              NULL,
-                              G_STRUCT_OFFSET (ImageClass, epv),
-                              &tinfo,
-                              "AccessibleImage");
-  }
-
-  return type;
-}
+  SpiImage *new_image = g_object_new (SPI_IMAGE_TYPE, NULL);
 
-static void
-image_class_init (ImageClass *klass)
-{
-  GObjectClass * object_class = (GObjectClass *) klass;
-  POA_Accessibility_Image__epv *epv = &klass->epv;
-  parent_class = g_type_class_peek_parent (klass);
-
-  object_class->finalize = image_finalize;
+  spi_base_construct (SPI_BASE (new_image), G_OBJECT(obj));
 
-
-  /* Initialize epv table */
-
-  epv->getImagePosition = impl_getImagePosition;
-  epv->getImageSize = impl_getImageSize;
-  epv->_get_imageDescription = impl__get_imageDescription;
+  return new_image;
 }
 
-static void
-image_init (Image *image)
+static AtkImage *
+get_image_from_servant (PortableServer_Servant servant)
 {
-}
+  SpiBase *object = SPI_BASE (bonobo_object_from_servant (servant));
 
-static void
-image_finalize (GObject *obj)
-{
-  Image *image = IMAGE (obj);
-  g_object_unref (image->atko);
-  image->atko = NULL;
-  parent_class->finalize (obj);
-}
-
-Image *
-image_interface_new (AtkObject *obj)
-{
-  Image *new_image = 
-    IMAGE(g_object_new (IMAGE_TYPE, NULL));
-  new_image->atko = obj;
-  g_object_ref (obj);
-  return new_image;
+  g_return_val_if_fail (object, NULL);
+  g_return_val_if_fail (ATK_IS_OBJECT(object->gobj), NULL);
+  return ATK_IMAGE (object->gobj);
 }
 
-
-
 static void 
-impl_getImagePosition (PortableServer_Servant _servant,
+impl_getImagePosition (PortableServer_Servant servant,
                       CORBA_long * x, CORBA_long * y,
                       const CORBA_short coordType,
-                      CORBA_Environment * ev)
+                      CORBA_Environment *ev)
 {
-  Image *image = IMAGE (bonobo_object_from_servant(_servant));
-  atk_image_get_image_position (ATK_IMAGE(image->atko),
-                               (gint *) x, (gint *) y,
-                               (AtkCoordType) coordType);
-}
+  AtkImage *image = get_image_from_servant (servant);
+  gint ix, iy;
 
+  g_return_if_fail (image != NULL);
 
+  atk_image_get_image_position (image,
+                               &ix, &iy,
+                               (AtkCoordType) coordType);
+  *x = ix;
+  *y = iy;
+}
 
 static void 
-impl_getImageSize (PortableServer_Servant _servant,
+impl_getImageSize (PortableServer_Servant servant,
                   CORBA_long * width, CORBA_long * height,
-                           CORBA_Environment * ev)
+                  CORBA_Environment *ev)
 {
-  Image *image = IMAGE (bonobo_object_from_servant(_servant));
-  atk_image_get_image_size (ATK_IMAGE(image->atko),
-                           (gint *) width, (gint *) height);
+  AtkImage *image = get_image_from_servant (servant);
+  gint iw, ih;
+  
+  g_return_if_fail (image != NULL);
+
+  atk_image_get_image_size (image,
+                           &iw, &ih);
+  *width = iw;
+  *height = ih;
 }
 
+static Accessibility_BoundingBox
+impl_getImageExtents (PortableServer_Servant servant,
+                     const CORBA_short      coordType,
+                     CORBA_Environment     *ev)
+{
+  AtkImage *image;
+  gint x, y, width, height;
+  Accessibility_BoundingBox bbox;
+
+  bbox.x = bbox.y = bbox.width = bbox.height = -1;
 
+  image = get_image_from_servant (servant);
+
+  if (image)
+    {
+      atk_image_get_image_size (image, &width, &height);
+      atk_image_get_image_position (image, &x, &y, coordType);
+
+      bbox.x = x;
+      bbox.y = y;
+      bbox.width = width;
+      bbox.height = height;
+    }
+
+  return bbox;
+}
 
 static CORBA_string 
-impl__get_imageDescription (PortableServer_Servant _servant,
-                         CORBA_Environment * ev)
+impl__get_imageDescription (PortableServer_Servant servant,
+                           CORBA_Environment     *ev)
 {
-  Image *image = IMAGE (bonobo_object_from_servant(_servant));
-  CORBA_char *rv;
+  const char *rv;
+  AtkImage   *image = get_image_from_servant (servant);
+
+  g_return_val_if_fail (image != NULL, CORBA_string_dup (""));
+
+  rv = atk_image_get_image_description (image);
 
-  rv = atk_image_get_image_description (ATK_IMAGE(image->atko));
   if (rv)
-    return CORBA_string_dup (rv);
+    {
+      return CORBA_string_dup (rv);
+    }
   else
-    return CORBA_string_dup ("");
+    {
+      return CORBA_string_dup ("");
+    }
 }
 
+static void
+spi_image_class_init (SpiImageClass *klass)
+{
+  POA_Accessibility_Image__epv *epv = &klass->epv;
+
+  /* Initialize epv table */
+  epv->getImagePosition      = impl_getImagePosition;
+  epv->getImageSize          = impl_getImageSize;
+  epv->getImageExtents       = impl_getImageExtents;
+  epv->_get_imageDescription = impl__get_imageDescription;
+}
 
+static void
+spi_image_init (SpiImage *image)
+{
+}
 
+BONOBO_TYPE_FUNC_FULL (SpiImage,
+                      Accessibility_Image,
+                      SPI_TYPE_BASE,
+                      spi_image);