Fix deadlock with key event listeners in our own process
[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 "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   DBusMessage *reply;
39
40   g_return_val_if_fail (ATK_IS_EDITABLE_TEXT (user_data),
41                         droute_not_yet_handled_error (message));
42   if (!dbus_message_get_args
43       (message, NULL, DBUS_TYPE_STRING, &newContents, DBUS_TYPE_INVALID))
44     {
45       return droute_invalid_arguments_error (message);
46     }
47   atk_editable_text_set_text_contents (editable, newContents);
48   rv = TRUE;
49   // TODO decide if we really need this return value
50   reply = dbus_message_new_method_return (message);
51   if (reply)
52     {
53       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
54                                 DBUS_TYPE_INVALID);
55     }
56   return reply;
57 }
58
59 static DBusMessage *
60 impl_InsertText (DBusConnection * bus, DBusMessage * message, void *user_data)
61 {
62   AtkEditableText *editable = (AtkEditableText *) user_data;
63   dbus_int32_t position, length;
64   char *text;
65   dbus_bool_t rv;
66   DBusMessage *reply;
67   gint ip;
68
69   g_return_val_if_fail (ATK_IS_EDITABLE_TEXT (user_data),
70                         droute_not_yet_handled_error (message));
71   if (!dbus_message_get_args
72       (message, NULL, DBUS_TYPE_INT32, &position, DBUS_TYPE_STRING, &text,
73        DBUS_TYPE_INT32, &length, DBUS_TYPE_INVALID))
74     {
75       return droute_invalid_arguments_error (message);
76     }
77   ip = position;
78   atk_editable_text_insert_text (editable, text, length, &ip);
79   rv = TRUE;
80   // TODO decide if we really need this return value
81   reply = dbus_message_new_method_return (message);
82   if (reply)
83     {
84       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
85                                 DBUS_TYPE_INVALID);
86     }
87   return reply;
88 }
89
90 static DBusMessage *
91 impl_CopyText (DBusConnection * bus, DBusMessage * message, void *user_data)
92 {
93   AtkEditableText *editable = (AtkEditableText *) user_data;
94   dbus_int32_t startPos, endPos;
95
96   g_return_val_if_fail (ATK_IS_EDITABLE_TEXT (user_data),
97                         droute_not_yet_handled_error (message));
98   if (!dbus_message_get_args
99       (message, NULL, DBUS_TYPE_INT32, &startPos, DBUS_TYPE_INT32, &endPos,
100        DBUS_TYPE_INVALID))
101     {
102       return droute_invalid_arguments_error (message);
103     }
104   atk_editable_text_copy_text (editable, startPos, endPos);
105   return dbus_message_new_method_return (message);
106 }
107
108 static DBusMessage *
109 impl_CutText (DBusConnection * bus, DBusMessage * message, void *user_data)
110 {
111   AtkEditableText *editable = (AtkEditableText *) user_data;
112   dbus_int32_t startPos, endPos;
113   dbus_bool_t rv;
114   DBusMessage *reply;
115
116   g_return_val_if_fail (ATK_IS_EDITABLE_TEXT (user_data),
117                         droute_not_yet_handled_error (message));
118   if (!dbus_message_get_args
119       (message, NULL, DBUS_TYPE_INT32, &startPos, DBUS_TYPE_INT32, &endPos,
120        DBUS_TYPE_INVALID))
121     {
122       return droute_invalid_arguments_error (message);
123     }
124   atk_editable_text_cut_text (editable, startPos, endPos);
125   rv = TRUE;
126   // TODO decide if we really need this return value
127   reply = dbus_message_new_method_return (message);
128   if (reply)
129     {
130       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
131                                 DBUS_TYPE_INVALID);
132     }
133   return reply;
134 }
135
136 static DBusMessage *
137 impl_DeleteText (DBusConnection * bus, DBusMessage * message, void *user_data)
138 {
139   AtkEditableText *editable = (AtkEditableText *) user_data;
140   dbus_int32_t startPos, endPos;
141   dbus_bool_t rv;
142   DBusMessage *reply;
143
144   g_return_val_if_fail (ATK_IS_EDITABLE_TEXT (user_data),
145                         droute_not_yet_handled_error (message));
146   if (!dbus_message_get_args
147       (message, NULL, DBUS_TYPE_INT32, &startPos, DBUS_TYPE_INT32, &endPos,
148        DBUS_TYPE_INVALID))
149     {
150       return droute_invalid_arguments_error (message);
151     }
152   atk_editable_text_delete_text (editable, startPos, endPos);
153   rv = TRUE;
154   // TODO decide if we really need this return value
155   reply = dbus_message_new_method_return (message);
156   if (reply)
157     {
158       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
159                                 DBUS_TYPE_INVALID);
160     }
161   return reply;
162 }
163
164 static DBusMessage *
165 impl_PasteText (DBusConnection * bus, DBusMessage * message, void *user_data)
166 {
167   AtkEditableText *editable = (AtkEditableText *) user_data;
168   dbus_int32_t position;
169   dbus_bool_t rv;
170   DBusMessage *reply;
171
172   g_return_val_if_fail (ATK_IS_EDITABLE_TEXT (user_data),
173                         droute_not_yet_handled_error (message));
174   if (!dbus_message_get_args
175       (message, NULL, DBUS_TYPE_INT32, &position, DBUS_TYPE_INVALID))
176     {
177       return droute_invalid_arguments_error (message);
178     }
179   atk_editable_text_paste_text (editable, position);
180   rv = TRUE;
181   // TODO decide if we really need this return value
182   reply = dbus_message_new_method_return (message);
183   if (reply)
184     {
185       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
186                                 DBUS_TYPE_INVALID);
187     }
188   return reply;
189 }
190
191 static DRouteMethod methods[] = {
192   {impl_SetTextContents, "SetTextContents"},
193   {impl_InsertText, "InsertText"},
194   {impl_CopyText, "CopyText"},
195   {impl_CutText, "CutText"},
196   {impl_DeleteText, "DeleteText"},
197   {impl_PasteText, "PasteText"},
198   {NULL, NULL}
199 };
200
201 void
202 spi_initialize_editabletext (DRoutePath * path)
203 {
204   droute_path_add_interface (path,
205                              ATSPI_DBUS_INTERFACE_EDITABLE_TEXT, spi_org_a11y_atspi_EditableText, methods, NULL);
206 };