2001-11-20 Michael Meeks <michael@ximian.com>
[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 /* Static function declarations */
30
31 static void
32 spi_image_class_init (SpiImageClass *klass);
33 static void
34 spi_image_init (SpiImage *image);
35 static void
36 spi_image_finalize (GObject *obj);
37 static void 
38 impl_getImagePosition (PortableServer_Servant _servant,
39                        CORBA_long * x, CORBA_long * y,
40                        const CORBA_short coordType,
41                        CORBA_Environment * ev);
42 static void 
43 impl_getImageSize (PortableServer_Servant _servant,
44                    CORBA_long * width, CORBA_long * height,
45                    CORBA_Environment * ev);
46 static CORBA_string 
47 impl__get_imageDescription (PortableServer_Servant _servant,
48                           CORBA_Environment * ev);
49
50
51 static GObjectClass *parent_class;
52
53 GType
54 spi_image_get_type (void)
55 {
56   static GType type = 0;
57
58   if (!type) {
59     static const GTypeInfo tinfo = {
60       sizeof (SpiImageClass),
61       (GBaseInitFunc) NULL,
62       (GBaseFinalizeFunc) NULL,
63       (GClassInitFunc) spi_image_class_init,
64       (GClassFinalizeFunc) NULL,
65       NULL, /* class data */
66       sizeof (SpiImage),
67       0, /* n preallocs */
68       (GInstanceInitFunc) spi_image_init,
69                         NULL /* value table */
70     };
71
72     /*
73      * Bonobo_type_unique auto-generates a load of
74      * CORBA structures for us. All derived types must
75      * use bonobo_type_unique.
76      */
77     type = bonobo_type_unique (
78                                BONOBO_OBJECT_TYPE,
79                                POA_Accessibility_Image__init,
80                                NULL,
81                                G_STRUCT_OFFSET (SpiImageClass, epv),
82                                &tinfo,
83                                "SpiAccessibleImage");
84   }
85
86   return type;
87 }
88
89 static void
90 spi_image_class_init (SpiImageClass *klass)
91 {
92   GObjectClass * object_class = (GObjectClass *) klass;
93   POA_Accessibility_Image__epv *epv = &klass->epv;
94   parent_class = g_type_class_peek_parent (klass);
95
96   object_class->finalize = spi_image_finalize;
97
98
99   /* Initialize epv table */
100
101   epv->getImagePosition = impl_getImagePosition;
102   epv->getImageSize = impl_getImageSize;
103   epv->_get_imageDescription = impl__get_imageDescription;
104 }
105
106 static void
107 spi_image_init (SpiImage *image)
108 {
109 }
110
111 static void
112 spi_image_finalize (GObject *obj)
113 {
114   SpiImage *image = SPI_IMAGE (obj);
115   g_object_unref (image->atko);
116   image->atko = NULL;
117   parent_class->finalize (obj);
118 }
119
120 SpiImage *
121 spi_image_interface_new (AtkObject *obj)
122 {
123   SpiImage *new_image = 
124     SPI_IMAGE(g_object_new (SPI_IMAGE_TYPE, NULL));
125   new_image->atko = obj;
126   g_object_ref (obj);
127   return new_image;
128 }
129
130
131
132 static void 
133 impl_getImagePosition (PortableServer_Servant _servant,
134                        CORBA_long * x, CORBA_long * y,
135                        const CORBA_short coordType,
136                        CORBA_Environment * ev)
137 {
138   SpiImage *image = SPI_IMAGE (bonobo_object_from_servant(_servant));
139   atk_image_get_image_position (ATK_IMAGE(image->atko),
140                                 (gint *) x, (gint *) y,
141                                 (AtkCoordType) coordType);
142 }
143
144
145
146 static void 
147 impl_getImageSize (PortableServer_Servant _servant,
148                    CORBA_long * width, CORBA_long * height,
149                             CORBA_Environment * ev)
150 {
151   SpiImage *image = SPI_IMAGE (bonobo_object_from_servant(_servant));
152   atk_image_get_image_size (ATK_IMAGE(image->atko),
153                             (gint *) width, (gint *) height);
154 }
155
156
157
158 static CORBA_string 
159 impl__get_imageDescription (PortableServer_Servant servant,
160                             CORBA_Environment     *ev)
161 {
162   SpiImage *image;
163   const char *rv;
164
165   image = SPI_IMAGE (bonobo_object_from_servant (servant));
166
167   rv = atk_image_get_image_description (ATK_IMAGE (image->atko));
168   if (rv)
169     return CORBA_string_dup (rv);
170   else
171     return CORBA_string_dup ("");
172 }
173
174
175