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