API revisions: tweaks to key event API, added some reserved slots for
[platform/core/uifw/at-spi2-atk.git] / libspi / image.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2001 Sun Microsystems Inc.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 /* image.c : implements the Image interface */
24
25 #include <config.h>
26 #include <stdio.h>
27 #include <libspi/image.h>
28
29
30 SpiImage *
31 spi_image_interface_new (AtkObject *obj)
32 {
33   SpiImage *new_image = g_object_new (SPI_IMAGE_TYPE, NULL);
34
35   spi_base_construct (SPI_BASE (new_image), G_OBJECT(obj));
36
37   return new_image;
38 }
39
40 static AtkImage *
41 get_image_from_servant (PortableServer_Servant servant)
42 {
43   SpiBase *object = SPI_BASE (bonobo_object_from_servant (servant));
44
45   g_return_val_if_fail (object, NULL);
46   g_return_val_if_fail (ATK_IS_OBJECT(object->gobj), NULL);
47   return ATK_IMAGE (object->gobj);
48 }
49
50 static void 
51 impl_getImagePosition (PortableServer_Servant servant,
52                        CORBA_long * x, CORBA_long * y,
53                        const CORBA_short coordType,
54                        CORBA_Environment *ev)
55 {
56   AtkImage *image = get_image_from_servant (servant);
57
58   g_return_if_fail (image != NULL);
59
60   atk_image_get_image_position (image,
61                                 (gint *) x, (gint *) y,
62                                 (AtkCoordType) coordType);
63 }
64
65 static void 
66 impl_getImageSize (PortableServer_Servant servant,
67                    CORBA_long * width, CORBA_long * height,
68                    CORBA_Environment *ev)
69 {
70   AtkImage *image = get_image_from_servant (servant);
71
72   g_return_if_fail (image != NULL);
73
74   atk_image_get_image_size (image,
75                             (gint *) width, (gint *) height);
76 }
77
78 static Accessibility_BoundingBox
79 impl_getImageExtents (PortableServer_Servant servant,
80                       const CORBA_short      coordType,
81                       CORBA_Environment     *ev)
82 {
83   AtkImage *image;
84   gint x, y, width, height;
85   Accessibility_BoundingBox bbox;
86
87   image = get_image_from_servant (servant);
88
89   atk_image_get_image_size (image, &width, &height);
90   atk_image_get_image_position (image, &x, &y, coordType);
91
92   bbox.x = x;
93   bbox.y = y;
94   bbox.width = width;
95   bbox.height = height;
96
97   return bbox;
98 }
99
100 static CORBA_string 
101 impl__get_imageDescription (PortableServer_Servant servant,
102                             CORBA_Environment     *ev)
103 {
104   const char *rv;
105   AtkImage   *image = get_image_from_servant (servant);
106
107   g_return_val_if_fail (image != NULL, CORBA_string_dup (""));
108
109   rv = atk_image_get_image_description (image);
110
111   if (rv)
112     {
113       return CORBA_string_dup (rv);
114     }
115   else
116     {
117       return CORBA_string_dup ("");
118     }
119 }
120
121 static void
122 spi_image_class_init (SpiImageClass *klass)
123 {
124   POA_Accessibility_Image__epv *epv = &klass->epv;
125
126   /* Initialize epv table */
127   epv->getImagePosition      = impl_getImagePosition;
128   epv->getImageSize          = impl_getImageSize;
129   epv->getImageExtents       = impl_getImageExtents;
130   epv->_get_imageDescription = impl__get_imageDescription;
131 }
132
133 static void
134 spi_image_init (SpiImage *image)
135 {
136 }
137
138 BONOBO_TYPE_FUNC_FULL (SpiImage,
139                        Accessibility_Image,
140                        SPI_TYPE_BASE,
141                        spi_image);