Fix crash in atspi_image_get_image_description
[platform/upstream/at-spi2-core.git] / atspi / atspi-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 #include "atspi-private.h"
25
26 /**
27  * atspi_image_get_image_description:
28  * @obj: a pointer to the #AtspiImage implementor on which to operate.
29  *
30  * Get the description of the image displayed in an #AtspiImage object.
31  *
32  * Returns: a UTF-8 string describing the image.
33  **/
34 gchar *
35 atspi_image_get_image_description (AtspiImage *obj, GError **error)
36 {
37   char *retval = NULL;
38
39   g_return_val_if_fail (obj != NULL, NULL);
40
41   _atspi_dbus_get_property (obj, atspi_interface_image, "ImageDescription", error, "s", &retval);
42
43   return retval;
44 }
45
46 /**
47  * atspi_image_get_image_size:
48  * @obj: a pointer to the #AtspiImage to query.
49  *
50  * Get the size of the image displayed in a specified #AtspiImage object.
51  **/
52 AtspiPoint *
53 atspi_image_get_image_size (AtspiImage *obj, GError **error)
54 {
55   dbus_int32_t d_w, d_h;
56   AtspiPoint ret;
57
58   ret.x = ret.y = -1;
59   if (!obj)
60     return atspi_point_copy (&ret);
61
62   _atspi_dbus_call (obj, atspi_interface_image, "GetImageSize", error, "=>ii", &d_w, &d_h);
63   ret.x = d_w;
64   ret.y = d_h;
65   return atspi_point_copy (&ret);
66 }
67
68 /**
69  * atspi_image_get_image_position:
70  * @obj: a pointer to the #AtspiImage implementor to query.
71  * @ctype: the desired coordinate system into which to return the results,
72  *         (e.g. ATSPI_COORD_TYPE_WINDOW, ATSPI_COORD_TYPE_SCREEN).
73  *
74  * Get the minimum x and y coordinates of the image displayed in a
75  *         specified #AtspiImage implementor.
76  **/
77 AtspiPoint *
78 atspi_image_get_image_position (AtspiImage *obj,
79                                 AtspiCoordType ctype,
80                                 GError **error)
81 {
82   dbus_int32_t d_x, d_y;
83   dbus_uint16_t d_ctype = ctype;
84   AtspiPoint ret;
85
86   ret.x = ret.y = 0;
87
88   if (!obj)
89     return atspi_point_copy (&ret);
90
91   _atspi_dbus_call (obj, atspi_interface_image, "GetImagePosition", error, "u=>ii", d_ctype, &d_x, &d_y);
92
93   ret.x = d_x;
94   ret.y = d_y;
95   return atspi_point_copy (&ret);
96 }
97
98 /**
99  * atspi_image_get_image_extents:
100  * @obj: a pointer to the #AtspiImage implementor to query.
101  * @ctype: the desired coordinate system into which to return the results,
102  *         (e.g. ATSPI_COORD_TYPE_WINDOW, ATSPI_COORD_TYPE_SCREEN).
103  *
104  * Get the bounding box of the image displayed in a
105  *         specified #AtspiImage implementor.
106  **/
107 AtspiRect *
108 atspi_image_get_image_extents (AtspiImage *obj,
109                                AtspiCoordType ctype,
110                                GError **error)
111 {
112   dbus_uint32_t d_ctype = ctype;
113   AtspiRect bbox;
114
115   bbox.x = bbox.y = bbox.width = bbox.height = -1;
116   g_return_val_if_fail (obj != NULL, atspi_rect_copy (&bbox));
117
118   _atspi_dbus_call (obj, atspi_interface_image, "GetImageExtents", error, "u=>(iiii)", d_ctype, &bbox);
119
120   return atspi_rect_copy (&bbox);
121 }
122
123 /**
124  * atspi_image_get_image_locale:
125  * @obj: The #AtspiImage being queried.
126  *
127  * Get the locale associated with an image and its textual representation.
128  *
129  * Returns: A POSIX LC_MESSAGES-style Locale value for image description and text.
130  **/
131 gchar *
132 atspi_image_get_image_locale  (AtspiImage *obj, GError **error)
133 {
134   gchar *retval = NULL;
135
136   g_return_val_if_fail (obj != NULL, g_strdup ("C"));
137
138   _atspi_dbus_get_property (obj, atspi_interface_image, "ImageLocale", error, "s", &retval);
139
140   return retval;
141 }
142
143 static void
144 atspi_image_base_init (AtspiImage *klass)
145 {
146 }
147
148 GType
149 atspi_image_get_type (void)
150 {
151   static GType type = 0;
152
153   if (!type) {
154     static const GTypeInfo tinfo =
155     {
156       sizeof (AtspiImage),
157       (GBaseInitFunc) atspi_image_base_init,
158       (GBaseFinalizeFunc) NULL,
159     };
160
161     type = g_type_register_static (G_TYPE_INTERFACE, "AtspiImage", &tinfo, 0);
162
163   }
164   return type;
165 }