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 Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 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 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
23 */
24
25 #include <atk/atk.h>
26 #include <droute/droute.h>
27 #include "bridge.h"
28 #include "introspection.h"
29
30 #include "spi-dbus.h"
31
32 static DBusMessage *
impl_SetTextContents(DBusConnection * bus,DBusMessage * message,void * user_data)33 impl_SetTextContents (DBusConnection * bus, DBusMessage * message,
34 void *user_data)
35 {
36 AtkEditableText *editable = (AtkEditableText *) user_data;
37 const char *newContents;
38 dbus_bool_t rv;
39 DBusMessage *reply;
40
41 g_return_val_if_fail (ATK_IS_EDITABLE_TEXT (user_data),
42 droute_not_yet_handled_error (message));
43 if (!dbus_message_get_args
44 (message, NULL, 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 *
impl_InsertText(DBusConnection * bus,DBusMessage * message,void * user_data)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 DBusMessage *reply;
68 gint ip;
69
70 g_return_val_if_fail (ATK_IS_EDITABLE_TEXT (user_data),
71 droute_not_yet_handled_error (message));
72 if (!dbus_message_get_args
73 (message, NULL, DBUS_TYPE_INT32, &position, DBUS_TYPE_STRING, &text,
74 DBUS_TYPE_INT32, &length, DBUS_TYPE_INVALID))
75 {
76 return droute_invalid_arguments_error (message);
77 }
78 ip = position;
79 atk_editable_text_insert_text (editable, text, length, &ip);
80 rv = TRUE;
81 // TODO decide if we really need this return value
82 reply = dbus_message_new_method_return (message);
83 if (reply)
84 {
85 dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
86 DBUS_TYPE_INVALID);
87 }
88 return reply;
89 }
90
91 static DBusMessage *
impl_CopyText(DBusConnection * bus,DBusMessage * message,void * user_data)92 impl_CopyText (DBusConnection * bus, DBusMessage * message, void *user_data)
93 {
94 AtkEditableText *editable = (AtkEditableText *) user_data;
95 dbus_int32_t startPos, endPos;
96
97 g_return_val_if_fail (ATK_IS_EDITABLE_TEXT (user_data),
98 droute_not_yet_handled_error (message));
99 if (!dbus_message_get_args
100 (message, NULL, DBUS_TYPE_INT32, &startPos, DBUS_TYPE_INT32, &endPos,
101 DBUS_TYPE_INVALID))
102 {
103 return droute_invalid_arguments_error (message);
104 }
105 atk_editable_text_copy_text (editable, startPos, endPos);
106 return dbus_message_new_method_return (message);
107 }
108
109 static DBusMessage *
impl_CutText(DBusConnection * bus,DBusMessage * message,void * user_data)110 impl_CutText (DBusConnection * bus, DBusMessage * message, void *user_data)
111 {
112 AtkEditableText *editable = (AtkEditableText *) user_data;
113 dbus_int32_t startPos, endPos;
114 dbus_bool_t rv;
115 DBusMessage *reply;
116
117 g_return_val_if_fail (ATK_IS_EDITABLE_TEXT (user_data),
118 droute_not_yet_handled_error (message));
119 if (!dbus_message_get_args
120 (message, NULL, DBUS_TYPE_INT32, &startPos, DBUS_TYPE_INT32, &endPos,
121 DBUS_TYPE_INVALID))
122 {
123 return droute_invalid_arguments_error (message);
124 }
125 atk_editable_text_cut_text (editable, startPos, endPos);
126 rv = TRUE;
127 // TODO decide if we really need this return value
128 reply = dbus_message_new_method_return (message);
129 if (reply)
130 {
131 dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
132 DBUS_TYPE_INVALID);
133 }
134 return reply;
135 }
136
137 static DBusMessage *
impl_DeleteText(DBusConnection * bus,DBusMessage * message,void * user_data)138 impl_DeleteText (DBusConnection * bus, DBusMessage * message, void *user_data)
139 {
140 AtkEditableText *editable = (AtkEditableText *) user_data;
141 dbus_int32_t startPos, endPos;
142 dbus_bool_t rv;
143 DBusMessage *reply;
144
145 g_return_val_if_fail (ATK_IS_EDITABLE_TEXT (user_data),
146 droute_not_yet_handled_error (message));
147 if (!dbus_message_get_args
148 (message, NULL, DBUS_TYPE_INT32, &startPos, DBUS_TYPE_INT32, &endPos,
149 DBUS_TYPE_INVALID))
150 {
151 return droute_invalid_arguments_error (message);
152 }
153 atk_editable_text_delete_text (editable, startPos, endPos);
154 rv = TRUE;
155 // TODO decide if we really need this return value
156 reply = dbus_message_new_method_return (message);
157 if (reply)
158 {
159 dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
160 DBUS_TYPE_INVALID);
161 }
162 return reply;
163 }
164
165 static DBusMessage *
impl_PasteText(DBusConnection * bus,DBusMessage * message,void * user_data)166 impl_PasteText (DBusConnection * bus, DBusMessage * message, void *user_data)
167 {
168 AtkEditableText *editable = (AtkEditableText *) user_data;
169 dbus_int32_t position;
170 dbus_bool_t rv;
171 DBusMessage *reply;
172
173 g_return_val_if_fail (ATK_IS_EDITABLE_TEXT (user_data),
174 droute_not_yet_handled_error (message));
175 if (!dbus_message_get_args
176 (message, NULL, DBUS_TYPE_INT32, &position, DBUS_TYPE_INVALID))
177 {
178 return droute_invalid_arguments_error (message);
179 }
180 atk_editable_text_paste_text (editable, position);
181 rv = TRUE;
182 // TODO decide if we really need this return value
183 reply = dbus_message_new_method_return (message);
184 if (reply)
185 {
186 dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
187 DBUS_TYPE_INVALID);
188 }
189 return reply;
190 }
191
192 static DRouteMethod methods[] = {
193 {impl_SetTextContents, "SetTextContents"},
194 {impl_InsertText, "InsertText"},
195 {impl_CopyText, "CopyText"},
196 {impl_CutText, "CutText"},
197 {impl_DeleteText, "DeleteText"},
198 {impl_PasteText, "PasteText"},
199 {NULL, NULL}
200 };
201
202 void
spi_initialize_editabletext(DRoutePath * path)203 spi_initialize_editabletext (DRoutePath * path)
204 {
205 spi_atk_add_interface (path,
206 ATSPI_DBUS_INTERFACE_EDITABLE_TEXT, spi_org_a11y_atspi_EditableText, methods, NULL);
207 };
208