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