e633a54921dd169bb84b2e36e5021981a2a3276c
[platform/core/uifw/at-spi2-atk.git] / atk-adaptor / adaptors / 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 #include "introspection.h"
28
29 #include "common/spi-dbus.h"
30
31 static DBusMessage *
32 impl_SetTextContents (DBusConnection * bus, DBusMessage * message,
33                       void *user_data)
34 {
35   AtkEditableText *editable = (AtkEditableText *) user_data;
36   const char *newContents;
37   dbus_bool_t rv;
38   DBusError error;
39   DBusMessage *reply;
40
41   g_return_val_if_fail (ATK_IS_EDITABLE_TEXT (user_data),
42                         droute_not_yet_handled_error (message));
43   dbus_error_init (&error);
44   if (!dbus_message_get_args
45       (message, &error, DBUS_TYPE_STRING, &newContents, DBUS_TYPE_INVALID))
46     {
47       return droute_invalid_arguments_error (message);
48     }
49   atk_editable_text_set_text_contents (editable, newContents);
50   rv = TRUE;
51   // TODO decide if we really need this return value
52   reply = dbus_message_new_method_return (message);
53   if (reply)
54     {
55       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
56                                 DBUS_TYPE_INVALID);
57     }
58   return reply;
59 }
60
61 static DBusMessage *
62 impl_InsertText (DBusConnection * bus, DBusMessage * message, void *user_data)
63 {
64   AtkEditableText *editable = (AtkEditableText *) user_data;
65   dbus_int32_t position, length;
66   char *text;
67   dbus_bool_t rv;
68   DBusError error;
69   DBusMessage *reply;
70   gint ip;
71
72   g_return_val_if_fail (ATK_IS_EDITABLE_TEXT (user_data),
73                         droute_not_yet_handled_error (message));
74   dbus_error_init (&error);
75   if (!dbus_message_get_args
76       (message, &error, DBUS_TYPE_INT32, &position, DBUS_TYPE_STRING, &text,
77        DBUS_TYPE_INT32, &length, DBUS_TYPE_INVALID))
78     {
79       return droute_invalid_arguments_error (message);
80     }
81   ip = position;
82   atk_editable_text_insert_text (editable, text, length, &ip);
83   rv = TRUE;
84   // TODO decide if we really need this return value
85   reply = dbus_message_new_method_return (message);
86   if (reply)
87     {
88       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
89                                 DBUS_TYPE_INVALID);
90     }
91   return reply;
92 }
93
94 static DBusMessage *
95 impl_CopyText (DBusConnection * bus, DBusMessage * message, void *user_data)
96 {
97   AtkEditableText *editable = (AtkEditableText *) user_data;
98   dbus_int32_t startPos, endPos;
99   DBusError error;
100
101   g_return_val_if_fail (ATK_IS_EDITABLE_TEXT (user_data),
102                         droute_not_yet_handled_error (message));
103   dbus_error_init (&error);
104   if (!dbus_message_get_args
105       (message, &error, DBUS_TYPE_INT32, &startPos, DBUS_TYPE_INT32, &endPos,
106        DBUS_TYPE_INVALID))
107     {
108       return droute_invalid_arguments_error (message);
109     }
110   atk_editable_text_copy_text (editable, startPos, endPos);
111   return dbus_message_new_method_return (message);
112 }
113
114 static DBusMessage *
115 impl_CutText (DBusConnection * bus, DBusMessage * message, void *user_data)
116 {
117   AtkEditableText *editable = (AtkEditableText *) user_data;
118   dbus_int32_t startPos, endPos;
119   DBusError error;
120   dbus_bool_t rv;
121   DBusMessage *reply;
122
123   g_return_val_if_fail (ATK_IS_EDITABLE_TEXT (user_data),
124                         droute_not_yet_handled_error (message));
125   dbus_error_init (&error);
126   if (!dbus_message_get_args
127       (message, &error, DBUS_TYPE_INT32, &startPos, DBUS_TYPE_INT32, &endPos,
128        DBUS_TYPE_INVALID))
129     {
130       return droute_invalid_arguments_error (message);
131     }
132   atk_editable_text_cut_text (editable, startPos, endPos);
133   rv = TRUE;
134   // TODO decide if we really need this return value
135   reply = dbus_message_new_method_return (message);
136   if (reply)
137     {
138       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
139                                 DBUS_TYPE_INVALID);
140     }
141   return reply;
142 }
143
144 static DBusMessage *
145 impl_DeleteText (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 droute_invalid_arguments_error (message);
161     }
162   atk_editable_text_delete_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_PasteText (DBusConnection * bus, DBusMessage * message, void *user_data)
176 {
177   AtkEditableText *editable = (AtkEditableText *) user_data;
178   dbus_int32_t position;
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, &position, DBUS_TYPE_INVALID))
188     {
189       return droute_invalid_arguments_error (message);
190     }
191   atk_editable_text_paste_text (editable, position);
192   rv = TRUE;
193   // TODO decide if we really need this return value
194   reply = dbus_message_new_method_return (message);
195   if (reply)
196     {
197       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
198                                 DBUS_TYPE_INVALID);
199     }
200   return reply;
201 }
202
203 static DRouteMethod methods[] = {
204   {impl_SetTextContents, "SetTextContents"},
205   {impl_InsertText, "InsertText"},
206   {impl_CopyText, "CopyText"},
207   {impl_CutText, "CutText"},
208   {impl_DeleteText, "DeleteText"},
209   {impl_PasteText, "PasteText"},
210   {NULL, NULL}
211 };
212
213 void
214 spi_initialize_editabletext (DRoutePath * path)
215 {
216   droute_path_add_interface (path,
217                              SPI_DBUS_INTERFACE_EDITABLE_TEXT, spi_org_a11y_atspi_EditableText, methods, NULL);
218 };