Changes to introspection generation to remove DOCTYPE and XML
[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 "accessible.h"
26
27 static AtkEditableText *
28 get_editable (DBusMessage * message)
29 {
30   AtkObject *obj = spi_dbus_get_object (dbus_message_get_path (message));
31   if (!obj)
32     return NULL;
33   return ATK_EDITABLE_TEXT (obj);
34 }
35
36 static AtkEditableText *
37 get_editable_from_path (const char *path, void *user_data)
38 {
39   AtkObject *obj = spi_dbus_get_object (path);
40   if (!obj || !ATK_IS_EDITABLE_TEXT(obj))
41     return NULL;
42   return ATK_EDITABLE_TEXT (obj);
43 }
44
45 static DBusMessage *
46 impl_setTextContents (DBusConnection * bus, DBusMessage * message,
47                       void *user_data)
48 {
49   AtkEditableText *editable = get_editable (message);
50   const char *newContents;
51   dbus_bool_t rv;
52   DBusError error;
53   DBusMessage *reply;
54
55   if (!editable)
56     return spi_dbus_general_error (message);
57   dbus_error_init (&error);
58   if (!dbus_message_get_args
59       (message, &error, DBUS_TYPE_STRING, &newContents, DBUS_TYPE_INVALID))
60     {
61       return SPI_DBUS_RETURN_ERROR (message, &error);
62     }
63   atk_editable_text_set_text_contents (editable, newContents);
64   rv = TRUE;
65   // TODO decide if we really need this return value
66   reply = dbus_message_new_method_return (message);
67   if (reply)
68     {
69       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
70                                 DBUS_TYPE_INVALID);
71     }
72   return reply;
73 }
74
75 static DBusMessage *
76 impl_insertText (DBusConnection * bus, DBusMessage * message, void *user_data)
77 {
78   AtkEditableText *editable = get_editable (message);
79   dbus_int32_t position, length;
80   char *text;
81   dbus_bool_t rv;
82   DBusError error;
83   DBusMessage *reply;
84   gint ip;
85
86   if (!editable)
87     return spi_dbus_general_error (message);
88   dbus_error_init (&error);
89   if (!dbus_message_get_args
90       (message, &error, DBUS_TYPE_INT32, &position, DBUS_TYPE_STRING, &text,
91        DBUS_TYPE_INT32, &length, DBUS_TYPE_INVALID))
92     {
93       return SPI_DBUS_RETURN_ERROR (message, &error);
94     }
95   ip = position;
96   atk_editable_text_insert_text (editable, text, length, &ip);
97   rv = TRUE;
98   // TODO decide if we really need this return value
99   reply = dbus_message_new_method_return (message);
100   if (reply)
101     {
102       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
103                                 DBUS_TYPE_INVALID);
104     }
105   return reply;
106 }
107
108 static DBusMessage *
109 impl_setAttributes (DBusConnection * bus, DBusMessage * message,
110                     void *user_data)
111 {
112   AtkEditableText *editable = get_editable (message);
113   const char *attributes;
114   dbus_int32_t startPos, endPos;
115   dbus_bool_t rv;
116   DBusError error;
117   DBusMessage *reply;
118
119   if (!editable)
120     return spi_dbus_general_error (message);
121   dbus_error_init (&error);
122   if (!dbus_message_get_args
123       (message, &error, DBUS_TYPE_STRING, &attributes, DBUS_TYPE_INT32,
124        &startPos, DBUS_TYPE_INT32, &endPos, DBUS_TYPE_INVALID))
125     {
126       return SPI_DBUS_RETURN_ERROR (message, &error);
127     }
128   // TODO implement
129   rv = FALSE;
130   reply = dbus_message_new_method_return (message);
131   if (reply)
132     {
133       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
134                                 DBUS_TYPE_INVALID);
135     }
136   return reply;
137 }
138
139 static DBusMessage *
140 impl_copyText (DBusConnection * bus, DBusMessage * message, void *user_data)
141 {
142   AtkEditableText *editable = get_editable (message);
143   dbus_int32_t startPos, endPos;
144   DBusError error;
145
146   if (!editable)
147     return spi_dbus_general_error (message);
148   dbus_error_init (&error);
149   if (!dbus_message_get_args
150       (message, &error, DBUS_TYPE_INT32, &startPos, DBUS_TYPE_INT32, &endPos,
151        DBUS_TYPE_INVALID))
152     {
153       return SPI_DBUS_RETURN_ERROR (message, &error);
154     }
155   atk_editable_text_copy_text (editable, startPos, endPos);
156   return NULL;
157 }
158
159 static DBusMessage *
160 impl_cutText (DBusConnection * bus, DBusMessage * message, void *user_data)
161 {
162   AtkEditableText *editable = get_editable (message);
163   dbus_int32_t startPos, endPos;
164   DBusError error;
165   dbus_bool_t rv;
166   DBusMessage *reply;
167
168   if (!editable)
169     return spi_dbus_general_error (message);
170   dbus_error_init (&error);
171   if (!dbus_message_get_args
172       (message, &error, DBUS_TYPE_INT32, &startPos, DBUS_TYPE_INT32, &endPos,
173        DBUS_TYPE_INVALID))
174     {
175       return SPI_DBUS_RETURN_ERROR (message, &error);
176     }
177   atk_editable_text_cut_text (editable, startPos, endPos);
178   rv = TRUE;
179   // TODO decide if we really need this return value
180   reply = dbus_message_new_method_return (message);
181   if (reply)
182     {
183       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
184                                 DBUS_TYPE_INVALID);
185     }
186   return reply;
187 }
188
189 static DBusMessage *
190 impl_deleteText (DBusConnection * bus, DBusMessage * message, void *user_data)
191 {
192   AtkEditableText *editable = get_editable (message);
193   dbus_int32_t startPos, endPos;
194   DBusError error;
195   dbus_bool_t rv;
196   DBusMessage *reply;
197
198   if (!editable)
199     return spi_dbus_general_error (message);
200   dbus_error_init (&error);
201   if (!dbus_message_get_args
202       (message, &error, DBUS_TYPE_INT32, &startPos, DBUS_TYPE_INT32, &endPos,
203        DBUS_TYPE_INVALID))
204     {
205       return SPI_DBUS_RETURN_ERROR (message, &error);
206     }
207   atk_editable_text_delete_text (editable, startPos, endPos);
208   rv = TRUE;
209   // TODO decide if we really need this return value
210   reply = dbus_message_new_method_return (message);
211   if (reply)
212     {
213       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
214                                 DBUS_TYPE_INVALID);
215     }
216   return reply;
217 }
218
219 static DBusMessage *
220 impl_pasteText (DBusConnection * bus, DBusMessage * message, void *user_data)
221 {
222   AtkEditableText *editable = get_editable (message);
223   dbus_int32_t position;
224   DBusError error;
225   dbus_bool_t rv;
226   DBusMessage *reply;
227
228   if (!editable)
229     return spi_dbus_general_error (message);
230   dbus_error_init (&error);
231   if (!dbus_message_get_args
232       (message, &error, DBUS_TYPE_INT32, &position, DBUS_TYPE_INVALID))
233     {
234       return SPI_DBUS_RETURN_ERROR (message, &error);
235     }
236   atk_editable_text_paste_text (editable, position);
237   rv = TRUE;
238   // TODO decide if we really need this return value
239   reply = dbus_message_new_method_return (message);
240   if (reply)
241     {
242       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
243                                 DBUS_TYPE_INVALID);
244     }
245   return reply;
246 }
247
248 static DRouteMethod methods[] = {
249   {impl_setTextContents, "setTextContents"},
250   {impl_insertText, "insertText"},
251   {impl_setAttributes, "setAttributes"},
252   {impl_copyText, "copyText"},
253   {impl_cutText, "cutText"},
254   {impl_deleteText, "deleteText"},
255   {impl_pasteText, "pasteText"},
256   {NULL, NULL}
257 };
258
259 void
260 spi_initialize_editabletext (DRouteData * data)
261 {
262   droute_add_interface (data, "org.freedesktop.atspi.EditableText",
263                         methods, NULL,
264                         (DRouteGetDatumFunction) get_editable_from_path,
265                         NULL);
266 };