2008-12-17 Mark Doffman <mark.doffman@codethink.co.uk>
[platform/core/uifw/at-spi2-atk.git] / atk-adaptor / editabletext.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 SPI_DBUS_RETURN_ERROR (message, &error);
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 SPI_DBUS_RETURN_ERROR (message, &error);
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_setAttributes (DBusConnection * bus, DBusMessage * message,
95                     void *user_data)
96 {
97   AtkEditableText *editable = (AtkEditableText *) user_data;
98   const char *attributes;
99   dbus_int32_t startPos, endPos;
100   dbus_bool_t rv;
101   DBusError error;
102   DBusMessage *reply;
103
104   g_return_val_if_fail (ATK_IS_EDITABLE_TEXT (user_data),
105                         droute_not_yet_handled_error (message));
106   dbus_error_init (&error);
107   if (!dbus_message_get_args
108       (message, &error, DBUS_TYPE_STRING, &attributes, DBUS_TYPE_INT32,
109        &startPos, DBUS_TYPE_INT32, &endPos, DBUS_TYPE_INVALID))
110     {
111       return SPI_DBUS_RETURN_ERROR (message, &error);
112     }
113   // TODO implement
114   rv = FALSE;
115   reply = dbus_message_new_method_return (message);
116   if (reply)
117     {
118       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
119                                 DBUS_TYPE_INVALID);
120     }
121   return reply;
122 }
123
124 static DBusMessage *
125 impl_copyText (DBusConnection * bus, DBusMessage * message, void *user_data)
126 {
127   AtkEditableText *editable = (AtkEditableText *) user_data;
128   dbus_int32_t startPos, endPos;
129   DBusError error;
130
131   g_return_val_if_fail (ATK_IS_EDITABLE_TEXT (user_data),
132                         droute_not_yet_handled_error (message));
133   dbus_error_init (&error);
134   if (!dbus_message_get_args
135       (message, &error, DBUS_TYPE_INT32, &startPos, DBUS_TYPE_INT32, &endPos,
136        DBUS_TYPE_INVALID))
137     {
138       return SPI_DBUS_RETURN_ERROR (message, &error);
139     }
140   atk_editable_text_copy_text (editable, startPos, endPos);
141   return NULL;
142 }
143
144 static DBusMessage *
145 impl_cutText (DBusConnection * bus, DBusMessage * message, void *user_data)
146 {
147   AtkEditableText *editable = (AtkEditableText *) user_data;
148   dbus_int32_t startPos, endPos;
149   DBusError error;
150   dbus_bool_t rv;
151   DBusMessage *reply;
152
153   g_return_val_if_fail (ATK_IS_EDITABLE_TEXT (user_data),
154                         droute_not_yet_handled_error (message));
155   dbus_error_init (&error);
156   if (!dbus_message_get_args
157       (message, &error, DBUS_TYPE_INT32, &startPos, DBUS_TYPE_INT32, &endPos,
158        DBUS_TYPE_INVALID))
159     {
160       return SPI_DBUS_RETURN_ERROR (message, &error);
161     }
162   atk_editable_text_cut_text (editable, startPos, endPos);
163   rv = TRUE;
164   // TODO decide if we really need this return value
165   reply = dbus_message_new_method_return (message);
166   if (reply)
167     {
168       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
169                                 DBUS_TYPE_INVALID);
170     }
171   return reply;
172 }
173
174 static DBusMessage *
175 impl_deleteText (DBusConnection * bus, DBusMessage * message, void *user_data)
176 {
177   AtkEditableText *editable = (AtkEditableText *) user_data;
178   dbus_int32_t startPos, endPos;
179   DBusError error;
180   dbus_bool_t rv;
181   DBusMessage *reply;
182
183   g_return_val_if_fail (ATK_IS_EDITABLE_TEXT (user_data),
184                         droute_not_yet_handled_error (message));
185   dbus_error_init (&error);
186   if (!dbus_message_get_args
187       (message, &error, DBUS_TYPE_INT32, &startPos, DBUS_TYPE_INT32, &endPos,
188        DBUS_TYPE_INVALID))
189     {
190       return SPI_DBUS_RETURN_ERROR (message, &error);
191     }
192   atk_editable_text_delete_text (editable, startPos, endPos);
193   rv = TRUE;
194   // TODO decide if we really need this return value
195   reply = dbus_message_new_method_return (message);
196   if (reply)
197     {
198       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
199                                 DBUS_TYPE_INVALID);
200     }
201   return reply;
202 }
203
204 static DBusMessage *
205 impl_pasteText (DBusConnection * bus, DBusMessage * message, void *user_data)
206 {
207   AtkEditableText *editable = (AtkEditableText *) user_data;
208   dbus_int32_t position;
209   DBusError error;
210   dbus_bool_t rv;
211   DBusMessage *reply;
212
213   g_return_val_if_fail (ATK_IS_EDITABLE_TEXT (user_data),
214                         droute_not_yet_handled_error (message));
215   dbus_error_init (&error);
216   if (!dbus_message_get_args
217       (message, &error, DBUS_TYPE_INT32, &position, DBUS_TYPE_INVALID))
218     {
219       return SPI_DBUS_RETURN_ERROR (message, &error);
220     }
221   atk_editable_text_paste_text (editable, position);
222   rv = TRUE;
223   // TODO decide if we really need this return value
224   reply = dbus_message_new_method_return (message);
225   if (reply)
226     {
227       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
228                                 DBUS_TYPE_INVALID);
229     }
230   return reply;
231 }
232
233 static DRouteMethod methods[] = {
234   {impl_setTextContents, "setTextContents"},
235   {impl_insertText, "insertText"},
236   {impl_setAttributes, "setAttributes"},
237   {impl_copyText, "copyText"},
238   {impl_cutText, "cutText"},
239   {impl_deleteText, "deleteText"},
240   {impl_pasteText, "pasteText"},
241   {NULL, NULL}
242 };
243
244 void
245 spi_initialize_editabletext (DRoutePath *path)
246 {
247   droute_path_add_interface (path,
248                              SPI_DBUS_INTERFACE_EDITABLE_TEXT,
249                              methods,
250                              NULL);
251 };