417b24d50e773f4704e4b03a885dd5e3066bbaa7
[platform/core/uifw/at-spi2-atk.git] / atk-adaptor / editabletext-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 "spi-common/spi-dbus.h"
29
30 static DBusMessage *
31 impl_setTextContents (DBusConnection * bus, DBusMessage * message,
32                       void *user_data)
33 {
34   AtkEditableText *editable = (AtkEditableText *) user_data;
35   const char *newContents;
36   dbus_bool_t rv;
37   DBusError error;
38   DBusMessage *reply;
39
40   g_return_val_if_fail (ATK_IS_EDITABLE_TEXT (user_data),
41                         droute_not_yet_handled_error (message));
42   dbus_error_init (&error);
43   if (!dbus_message_get_args
44       (message, &error, DBUS_TYPE_STRING, &newContents, DBUS_TYPE_INVALID))
45     {
46       return droute_invalid_arguments_error (message);
47     }
48   atk_editable_text_set_text_contents (editable, newContents);
49   rv = TRUE;
50   // TODO decide if we really need this return value
51   reply = dbus_message_new_method_return (message);
52   if (reply)
53     {
54       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
55                                 DBUS_TYPE_INVALID);
56     }
57   return reply;
58 }
59
60 static DBusMessage *
61 impl_insertText (DBusConnection * bus, DBusMessage * message, void *user_data)
62 {
63   AtkEditableText *editable = (AtkEditableText *) user_data;
64   dbus_int32_t position, length;
65   char *text;
66   dbus_bool_t rv;
67   DBusError error;
68   DBusMessage *reply;
69   gint ip;
70
71   g_return_val_if_fail (ATK_IS_EDITABLE_TEXT (user_data),
72                         droute_not_yet_handled_error (message));
73   dbus_error_init (&error);
74   if (!dbus_message_get_args
75       (message, &error, DBUS_TYPE_INT32, &position, DBUS_TYPE_STRING, &text,
76        DBUS_TYPE_INT32, &length, DBUS_TYPE_INVALID))
77     {
78       return droute_invalid_arguments_error (message);
79     }
80   ip = position;
81   atk_editable_text_insert_text (editable, text, length, &ip);
82   rv = TRUE;
83   // TODO decide if we really need this return value
84   reply = dbus_message_new_method_return (message);
85   if (reply)
86     {
87       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
88                                 DBUS_TYPE_INVALID);
89     }
90   return reply;
91 }
92
93 static DBusMessage *
94 impl_copyText (DBusConnection * bus, DBusMessage * message, void *user_data)
95 {
96   AtkEditableText *editable = (AtkEditableText *) user_data;
97   dbus_int32_t startPos, endPos;
98   DBusError error;
99
100   g_return_val_if_fail (ATK_IS_EDITABLE_TEXT (user_data),
101                         droute_not_yet_handled_error (message));
102   dbus_error_init (&error);
103   if (!dbus_message_get_args
104       (message, &error, DBUS_TYPE_INT32, &startPos, DBUS_TYPE_INT32, &endPos,
105        DBUS_TYPE_INVALID))
106     {
107       return droute_invalid_arguments_error (message);
108     }
109   atk_editable_text_copy_text (editable, startPos, endPos);
110   return dbus_message_new_method_return (message);
111 }
112
113 static DBusMessage *
114 impl_cutText (DBusConnection * bus, DBusMessage * message, void *user_data)
115 {
116   AtkEditableText *editable = (AtkEditableText *) user_data;
117   dbus_int32_t startPos, endPos;
118   DBusError error;
119   dbus_bool_t rv;
120   DBusMessage *reply;
121
122   g_return_val_if_fail (ATK_IS_EDITABLE_TEXT (user_data),
123                         droute_not_yet_handled_error (message));
124   dbus_error_init (&error);
125   if (!dbus_message_get_args
126       (message, &error, DBUS_TYPE_INT32, &startPos, DBUS_TYPE_INT32, &endPos,
127        DBUS_TYPE_INVALID))
128     {
129       return droute_invalid_arguments_error (message);
130     }
131   atk_editable_text_cut_text (editable, startPos, endPos);
132   rv = TRUE;
133   // TODO decide if we really need this return value
134   reply = dbus_message_new_method_return (message);
135   if (reply)
136     {
137       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
138                                 DBUS_TYPE_INVALID);
139     }
140   return reply;
141 }
142
143 static DBusMessage *
144 impl_deleteText (DBusConnection * bus, DBusMessage * message, void *user_data)
145 {
146   AtkEditableText *editable = (AtkEditableText *) user_data;
147   dbus_int32_t startPos, endPos;
148   DBusError error;
149   dbus_bool_t rv;
150   DBusMessage *reply;
151
152   g_return_val_if_fail (ATK_IS_EDITABLE_TEXT (user_data),
153                         droute_not_yet_handled_error (message));
154   dbus_error_init (&error);
155   if (!dbus_message_get_args
156       (message, &error, DBUS_TYPE_INT32, &startPos, DBUS_TYPE_INT32, &endPos,
157        DBUS_TYPE_INVALID))
158     {
159       return droute_invalid_arguments_error (message);
160     }
161   atk_editable_text_delete_text (editable, startPos, endPos);
162   rv = TRUE;
163   // TODO decide if we really need this return value
164   reply = dbus_message_new_method_return (message);
165   if (reply)
166     {
167       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
168                                 DBUS_TYPE_INVALID);
169     }
170   return reply;
171 }
172
173 static DBusMessage *
174 impl_pasteText (DBusConnection * bus, DBusMessage * message, void *user_data)
175 {
176   AtkEditableText *editable = (AtkEditableText *) user_data;
177   dbus_int32_t position;
178   DBusError error;
179   dbus_bool_t rv;
180   DBusMessage *reply;
181
182   g_return_val_if_fail (ATK_IS_EDITABLE_TEXT (user_data),
183                         droute_not_yet_handled_error (message));
184   dbus_error_init (&error);
185   if (!dbus_message_get_args
186       (message, &error, DBUS_TYPE_INT32, &position, DBUS_TYPE_INVALID))
187     {
188       return droute_invalid_arguments_error (message);
189     }
190   atk_editable_text_paste_text (editable, position);
191   rv = TRUE;
192   // TODO decide if we really need this return value
193   reply = dbus_message_new_method_return (message);
194   if (reply)
195     {
196       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
197                                 DBUS_TYPE_INVALID);
198     }
199   return reply;
200 }
201
202 static DRouteMethod methods[] = {
203   {impl_setTextContents, "setTextContents"},
204   {impl_insertText, "insertText"},
205   {impl_copyText, "copyText"},
206   {impl_cutText, "cutText"},
207   {impl_deleteText, "deleteText"},
208   {impl_pasteText, "pasteText"},
209   {NULL, NULL}
210 };
211
212 void
213 spi_initialize_editabletext (DRoutePath *path)
214 {
215   droute_path_add_interface (path,
216                              SPI_DBUS_INTERFACE_EDITABLE_TEXT,
217                              methods,
218                              NULL);
219 };