2008-05-16 Mark Doffman <mark.doffman@codethink.co.uk>
[platform/core/uifw/at-spi2-atk.git] / atk-adaptor / image.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2008 Novell, Inc.
6  * Copyright 2001, 2002 Sun Microsystems Inc.,
7  * Copyright 2001, 2002 Ximian, Inc.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Library General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Library General Public License for more details.
18  *
19  * You should have received a copy of the GNU Library General Public
20  * License along with this library; if not, write to the
21  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22  * Boston, MA 02111-1307, USA.
23  */
24
25 #include "accessible.h"
26
27 static AtkImage *
28 get_image (DBusMessage * message)
29 {
30   AtkObject *obj = spi_dbus_get_object (dbus_message_get_path (message));
31   if (!obj)
32     return NULL;
33   return ATK_IMAGE (obj);
34 }
35
36 static AtkImage *
37 get_image_from_path (const char *path, void *user_data)
38 {
39   AtkObject *obj = spi_dbus_get_object (path);
40   if (!obj || !ATK_IS_IMAGE(obj))
41     return NULL;
42   return ATK_IMAGE (obj);
43 }
44
45 static dbus_bool_t
46 impl_get_imageDescription (const char *path, DBusMessageIter * iter,
47                            void *user_data)
48 {
49   AtkImage *image = get_image_from_path (path, user_data);
50   if (!image)
51     return FALSE;
52   return droute_return_v_string (iter,
53                                  atk_image_get_image_description (image));
54 }
55
56 static dbus_bool_t
57 impl_get_imageLocale (const char *path, DBusMessageIter * iter,
58                       void *user_data)
59 {
60   AtkImage *image = get_image_from_path (path, user_data);
61   if (!image)
62     return FALSE;
63   return droute_return_v_string (iter, atk_image_get_image_locale (image));
64 }
65
66 static DBusMessage *
67 impl_getImageExtents (DBusConnection * bus, DBusMessage * message,
68                       void *user_data)
69 {
70   AtkImage *image = get_image (message);
71   DBusError error;
72   dbus_uint32_t coordType;
73   gint ix, iy, iwidth, iheight;
74
75   if (!image)
76     return spi_dbus_general_error (message);
77   dbus_error_init (&error);
78   if (!dbus_message_get_args
79       (message, &error, DBUS_TYPE_UINT32, &coordType, DBUS_TYPE_INVALID))
80     {
81       return SPI_DBUS_RETURN_ERROR (message, &error);
82     }
83   atk_image_get_image_size (image, &iwidth, &iheight);
84   atk_image_get_image_position (image, &ix, &iy, (AtkCoordType) coordType);
85   return spi_dbus_return_rect (message, ix, iy, iwidth, iheight);
86 }
87
88 static DBusMessage *
89 impl_getImagePosition (DBusConnection * bus, DBusMessage * message,
90                        void *user_data)
91 {
92   AtkImage *image = get_image (message);
93   DBusError error;
94   dbus_uint32_t coord_type;
95   gint ix = 0, iy = 0;
96   dbus_int32_t x, y;
97   DBusMessage *reply;
98
99   if (!image)
100     return spi_dbus_general_error (message);
101   dbus_error_init (&error);
102   if (!dbus_message_get_args
103       (message, &error, DBUS_TYPE_UINT32, &coord_type, DBUS_TYPE_INVALID))
104     {
105       return SPI_DBUS_RETURN_ERROR (message, &error);
106     }
107   atk_image_get_image_position (image, &ix, &iy, (AtkCoordType) coord_type);
108   x = ix;
109   y = iy;
110   reply = dbus_message_new_method_return (message);
111   if (reply)
112     {
113       dbus_message_append_args (reply, DBUS_TYPE_INT32, &x, DBUS_TYPE_INT32,
114                                 &y, DBUS_TYPE_INVALID);
115     }
116   return reply;
117 }
118
119 static DBusMessage *
120 impl_getImageSize (DBusConnection * bus, DBusMessage * message,
121                    void *user_data)
122 {
123   AtkImage *image = get_image (message);
124   gint iwidth = 0, iheight = 0;
125   dbus_int32_t width, height;
126   DBusMessage *reply;
127
128   if (!image)
129     return spi_dbus_general_error (message);
130   atk_image_get_image_size (image, &iwidth, &iheight);
131   width = iwidth;
132   height = iheight;
133   reply = dbus_message_new_method_return (message);
134   if (reply)
135     {
136       dbus_message_append_args (reply, DBUS_TYPE_INT32, &width,
137                                 DBUS_TYPE_INT32, &height, DBUS_TYPE_INVALID);
138     }
139   return reply;
140 }
141
142 static DRouteMethod methods[] = {
143   {impl_getImageExtents, "getImageExtents"},
144   {impl_getImagePosition, "getImagePosition"},
145   {impl_getImageSize, "getImageSize"},
146   {NULL, NULL}
147 };
148
149 static DRouteProperty properties[] = {
150   {impl_get_imageDescription, NULL, "imageDescription"},
151   {impl_get_imageLocale, NULL, "imageLocale"},
152   {NULL, NULL, NULL}
153 };
154
155 void
156 spi_initialize_image (DRouteData * data)
157 {
158   droute_add_interface (data, "org.freedesktop.atspi.Image", methods,
159                         properties,
160                         (DRouteGetDatumFunction) get_image_from_path, NULL);
161 };