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