Cleaned up some suspect int* casts, and added assertions to text calls in libspi
[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 /*
24  * component.c : bonobo wrapper for accessible component implementation
25  *
26  */
27 #include <config.h>
28 #include <bonobo/Bonobo.h>
29
30 #include <stdio.h>
31
32 /*
33  * This pulls the CORBA definitions for the "Accessibility::Accessible" server
34  */
35 #include <libspi/Accessibility.h>
36
37 /*
38  * This pulls the definition of the image bonobo object
39  */
40 #include "image.h"
41
42 /*
43  * Static function declarations
44  */
45
46 static void
47 image_class_init (ImageClass *klass);
48 static void
49 image_init (Image *image);
50 static void
51 image_finalize (GObject *obj);
52 static void 
53 impl_getImagePosition (PortableServer_Servant _servant,
54                        CORBA_long * x, CORBA_long * y,
55                        const CORBA_short coordType,
56                        CORBA_Environment * ev);
57 static void 
58 impl_getImageSize (PortableServer_Servant _servant,
59                    CORBA_long * width, CORBA_long * height,
60                    CORBA_Environment * ev);
61 static CORBA_string 
62 impl__get_imageDescription (PortableServer_Servant _servant,
63                           CORBA_Environment * ev);
64
65
66 static GObjectClass *parent_class;
67
68 GType
69 image_get_type (void)
70 {
71   static GType type = 0;
72
73   if (!type) {
74     static const GTypeInfo tinfo = {
75       sizeof (ImageClass),
76       (GBaseInitFunc) NULL,
77       (GBaseFinalizeFunc) NULL,
78       (GClassInitFunc) image_class_init,
79       (GClassFinalizeFunc) NULL,
80       NULL, /* class data */
81       sizeof (Image),
82       0, /* n preallocs */
83       (GInstanceInitFunc) image_init,
84                         NULL /* value table */
85     };
86
87     /*
88      * Bonobo_type_unique auto-generates a load of
89      * CORBA structures for us. All derived types must
90      * use bonobo_type_unique.
91      */
92     type = bonobo_type_unique (
93                                BONOBO_OBJECT_TYPE,
94                                POA_Accessibility_Image__init,
95                                NULL,
96                                G_STRUCT_OFFSET (ImageClass, epv),
97                                &tinfo,
98                                "AccessibleImage");
99   }
100
101   return type;
102 }
103
104 static void
105 image_class_init (ImageClass *klass)
106 {
107   GObjectClass * object_class = (GObjectClass *) klass;
108   POA_Accessibility_Image__epv *epv = &klass->epv;
109   parent_class = g_type_class_peek_parent (klass);
110
111   object_class->finalize = image_finalize;
112
113
114   /* Initialize epv table */
115
116   epv->getImagePosition = impl_getImagePosition;
117   epv->getImageSize = impl_getImageSize;
118   epv->_get_imageDescription = impl__get_imageDescription;
119 }
120
121 static void
122 image_init (Image *image)
123 {
124 }
125
126 static void
127 image_finalize (GObject *obj)
128 {
129   Image *image = IMAGE (obj);
130   g_object_unref (image->atko);
131   image->atko = NULL;
132   parent_class->finalize (obj);
133 }
134
135 Image *
136 image_interface_new (AtkObject *obj)
137 {
138   Image *new_image = 
139     IMAGE(g_object_new (IMAGE_TYPE, NULL));
140   new_image->atko = obj;
141   g_object_ref (obj);
142   return new_image;
143 }
144
145
146
147 static void 
148 impl_getImagePosition (PortableServer_Servant _servant,
149                        CORBA_long * x, CORBA_long * y,
150                        const CORBA_short coordType,
151                        CORBA_Environment * ev)
152 {
153   Image *image = IMAGE (bonobo_object_from_servant(_servant));
154   atk_image_get_image_position (ATK_IMAGE(image->atko),
155                                 (gint *) x, (gint *) y,
156                                 (AtkCoordType) coordType);
157 }
158
159
160
161 static void 
162 impl_getImageSize (PortableServer_Servant _servant,
163                    CORBA_long * width, CORBA_long * height,
164                             CORBA_Environment * ev)
165 {
166   Image *image = IMAGE (bonobo_object_from_servant(_servant));
167   atk_image_get_image_size (ATK_IMAGE(image->atko),
168                             (gint *) width, (gint *) height);
169 }
170
171
172
173 static CORBA_string 
174 impl__get_imageDescription (PortableServer_Servant _servant,
175                           CORBA_Environment * ev)
176 {
177   Image *image = IMAGE (bonobo_object_from_servant(_servant));
178   CORBA_char *rv;
179
180   rv = atk_image_get_image_description (ATK_IMAGE(image->atko));
181   if (rv)
182     return CORBA_string_dup (rv);
183   else
184     return CORBA_string_dup ("");
185 }
186
187
188