2008-12-17 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 <atk/atk.h>
26 #include <droute/droute.h>
27
28 #include "spi-common/spi-dbus.h"
29
30 static dbus_bool_t
31 impl_get_imageDescription (DBusMessageIter * iter,
32                            void *user_data)
33 {
34   AtkImage *image = (AtkImage *) user_data;
35   g_return_val_if_fail (ATK_IS_IMAGE (user_data), FALSE);
36   return droute_return_v_string (iter,
37                                  atk_image_get_image_description (image));
38 }
39
40 static dbus_bool_t
41 impl_get_imageLocale (DBusMessageIter * iter,
42                       void *user_data)
43 {
44   AtkImage *image = (AtkImage *) user_data;
45   g_return_val_if_fail (ATK_IS_IMAGE (user_data), FALSE);
46   return droute_return_v_string (iter, atk_image_get_image_locale (image));
47 }
48
49 static DBusMessage *
50 impl_getImageExtents (DBusConnection * bus, DBusMessage * message,
51                       void *user_data)
52 {
53   AtkImage *image = (AtkImage *) user_data;
54   DBusError error;
55   dbus_int16_t coordType;
56   gint ix, iy, iwidth, iheight;
57
58   g_return_val_if_fail (ATK_IS_IMAGE (user_data),
59                         droute_not_yet_handled_error (message));
60   dbus_error_init (&error);
61   if (!dbus_message_get_args
62       (message, &error, DBUS_TYPE_INT16, &coordType, DBUS_TYPE_INVALID))
63     {
64       return SPI_DBUS_RETURN_ERROR (message, &error);
65     }
66   atk_image_get_image_size (image, &iwidth, &iheight);
67   atk_image_get_image_position (image, &ix, &iy, (AtkCoordType) coordType);
68   return spi_dbus_return_rect (message, ix, iy, iwidth, iheight);
69 }
70
71 static DBusMessage *
72 impl_getImagePosition (DBusConnection * bus, DBusMessage * message,
73                        void *user_data)
74 {
75   AtkImage *image = (AtkImage *) user_data;
76   DBusError error;
77   dbus_int16_t coord_type;
78   gint ix = 0, iy = 0;
79   dbus_int32_t x, y;
80   DBusMessage *reply;
81
82   g_return_val_if_fail (ATK_IS_IMAGE (user_data),
83                         droute_not_yet_handled_error (message));
84   dbus_error_init (&error);
85   if (!dbus_message_get_args
86       (message, &error, DBUS_TYPE_INT16, &coord_type, DBUS_TYPE_INVALID))
87     {
88       return SPI_DBUS_RETURN_ERROR (message, &error);
89     }
90   atk_image_get_image_position (image, &ix, &iy, (AtkCoordType) coord_type);
91   x = ix;
92   y = iy;
93   reply = dbus_message_new_method_return (message);
94   if (reply)
95     {
96       dbus_message_append_args (reply, DBUS_TYPE_INT32, &x, DBUS_TYPE_INT32,
97                                 &y, DBUS_TYPE_INVALID);
98     }
99   return reply;
100 }
101
102 static DBusMessage *
103 impl_getImageSize (DBusConnection * bus, DBusMessage * message,
104                    void *user_data)
105 {
106   AtkImage *image = (AtkImage *) user_data;
107   gint iwidth = 0, iheight = 0;
108   dbus_int32_t width, height;
109   DBusMessage *reply;
110
111   g_return_val_if_fail (ATK_IS_IMAGE (user_data),
112                         droute_not_yet_handled_error (message));
113   atk_image_get_image_size (image, &iwidth, &iheight);
114   width = iwidth;
115   height = iheight;
116   reply = dbus_message_new_method_return (message);
117   if (reply)
118     {
119       dbus_message_append_args (reply, DBUS_TYPE_INT32, &width,
120                                 DBUS_TYPE_INT32, &height, DBUS_TYPE_INVALID);
121     }
122   return reply;
123 }
124
125 static DRouteMethod methods[] = {
126   {impl_getImageExtents, "getImageExtents"},
127   {impl_getImagePosition, "getImagePosition"},
128   {impl_getImageSize, "getImageSize"},
129   {NULL, NULL}
130 };
131
132 static DRouteProperty properties[] = {
133   {impl_get_imageDescription, NULL, "imageDescription"},
134   {impl_get_imageLocale, NULL, "imageLocale"},
135   {NULL, NULL, NULL}
136 };
137
138 void
139 spi_initialize_image (DRoutePath *path)
140 {
141   droute_path_add_interface (path,
142                              SPI_DBUS_INTERFACE_IMAGE,
143                              methods,
144                              properties);
145 };