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 "bridge.h"
26
#include "introspection.h"
27
#include <atk/atk.h>
28
#include <droute/droute.h>
29

            
30
#include "spi-dbus.h"
31

            
32
static DBusMessage *
33
impl_SetTextContents (DBusConnection *bus, DBusMessage *message, 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 (message, NULL, DBUS_TYPE_STRING, &newContents, DBUS_TYPE_INVALID))
43
    {
44
      return droute_invalid_arguments_error (message);
45
    }
46
  atk_editable_text_set_text_contents (editable, newContents);
47
  rv = TRUE;
48
  // TODO decide if we really need this return value
49
  reply = dbus_message_new_method_return (message);
50
  if (reply)
51
    {
52
      dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
53
                                DBUS_TYPE_INVALID);
54
    }
55
  return reply;
56
}
57

            
58
static DBusMessage *
59
1
impl_InsertText (DBusConnection *bus, DBusMessage *message, void *user_data)
60
{
61
1
  AtkEditableText *editable = (AtkEditableText *) user_data;
62
  dbus_int32_t position, length;
63
  char *text;
64
  dbus_bool_t rv;
65
  DBusMessage *reply;
66
  gint ip;
67

            
68
1
  g_return_val_if_fail (ATK_IS_EDITABLE_TEXT (user_data),
69
                        droute_not_yet_handled_error (message));
70
1
  if (!dbus_message_get_args (message, NULL, DBUS_TYPE_INT32, &position, DBUS_TYPE_STRING, &text,
71
                              DBUS_TYPE_INT32, &length, DBUS_TYPE_INVALID))
72
    {
73
      return droute_invalid_arguments_error (message);
74
    }
75
1
  ip = position;
76
1
  atk_editable_text_insert_text (editable, text, length, &ip);
77
1
  rv = TRUE;
78
  // TODO decide if we really need this return value
79
1
  reply = dbus_message_new_method_return (message);
80
1
  if (reply)
81
    {
82
1
      dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
83
                                DBUS_TYPE_INVALID);
84
    }
85
1
  return reply;
86
}
87

            
88
static DBusMessage *
89
1
impl_CopyText (DBusConnection *bus, DBusMessage *message, void *user_data)
90
{
91
1
  AtkEditableText *editable = (AtkEditableText *) user_data;
92
  dbus_int32_t startPos, endPos;
93

            
94
1
  g_return_val_if_fail (ATK_IS_EDITABLE_TEXT (user_data),
95
                        droute_not_yet_handled_error (message));
96
1
  if (!dbus_message_get_args (message, NULL, DBUS_TYPE_INT32, &startPos, DBUS_TYPE_INT32, &endPos,
97
                              DBUS_TYPE_INVALID))
98
    {
99
      return droute_invalid_arguments_error (message);
100
    }
101
1
  atk_editable_text_copy_text (editable, startPos, endPos);
102
1
  return dbus_message_new_method_return (message);
103
}
104

            
105
static DBusMessage *
106
1
impl_CutText (DBusConnection *bus, DBusMessage *message, void *user_data)
107
{
108
1
  AtkEditableText *editable = (AtkEditableText *) user_data;
109
  dbus_int32_t startPos, endPos;
110
  dbus_bool_t rv;
111
  DBusMessage *reply;
112

            
113
1
  g_return_val_if_fail (ATK_IS_EDITABLE_TEXT (user_data),
114
                        droute_not_yet_handled_error (message));
115
1
  if (!dbus_message_get_args (message, NULL, DBUS_TYPE_INT32, &startPos, DBUS_TYPE_INT32, &endPos,
116
                              DBUS_TYPE_INVALID))
117
    {
118
      return droute_invalid_arguments_error (message);
119
    }
120
1
  atk_editable_text_cut_text (editable, startPos, endPos);
121
1
  rv = TRUE;
122
  // TODO decide if we really need this return value
123
1
  reply = dbus_message_new_method_return (message);
124
1
  if (reply)
125
    {
126
1
      dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
127
                                DBUS_TYPE_INVALID);
128
    }
129
1
  return reply;
130
}
131

            
132
static DBusMessage *
133
1
impl_DeleteText (DBusConnection *bus, DBusMessage *message, void *user_data)
134
{
135
1
  AtkEditableText *editable = (AtkEditableText *) user_data;
136
  dbus_int32_t startPos, endPos;
137
  dbus_bool_t rv;
138
  DBusMessage *reply;
139

            
140
1
  g_return_val_if_fail (ATK_IS_EDITABLE_TEXT (user_data),
141
                        droute_not_yet_handled_error (message));
142
1
  if (!dbus_message_get_args (message, NULL, DBUS_TYPE_INT32, &startPos, DBUS_TYPE_INT32, &endPos,
143
                              DBUS_TYPE_INVALID))
144
    {
145
      return droute_invalid_arguments_error (message);
146
    }
147
1
  atk_editable_text_delete_text (editable, startPos, endPos);
148
1
  rv = TRUE;
149
  // TODO decide if we really need this return value
150
1
  reply = dbus_message_new_method_return (message);
151
1
  if (reply)
152
    {
153
1
      dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
154
                                DBUS_TYPE_INVALID);
155
    }
156
1
  return reply;
157
}
158

            
159
static DBusMessage *
160
1
impl_PasteText (DBusConnection *bus, DBusMessage *message, void *user_data)
161
{
162
1
  AtkEditableText *editable = (AtkEditableText *) user_data;
163
  dbus_int32_t position;
164
  dbus_bool_t rv;
165
  DBusMessage *reply;
166

            
167
1
  g_return_val_if_fail (ATK_IS_EDITABLE_TEXT (user_data),
168
                        droute_not_yet_handled_error (message));
169
1
  if (!dbus_message_get_args (message, NULL, DBUS_TYPE_INT32, &position, DBUS_TYPE_INVALID))
170
    {
171
      return droute_invalid_arguments_error (message);
172
    }
173
1
  atk_editable_text_paste_text (editable, position);
174
1
  rv = TRUE;
175
  // TODO decide if we really need this return value
176
1
  reply = dbus_message_new_method_return (message);
177
1
  if (reply)
178
    {
179
1
      dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
180
                                DBUS_TYPE_INVALID);
181
    }
182
1
  return reply;
183
}
184

            
185
static DRouteMethod methods[] = {
186
  { impl_SetTextContents, "SetTextContents" },
187
  { impl_InsertText, "InsertText" },
188
  { impl_CopyText, "CopyText" },
189
  { impl_CutText, "CutText" },
190
  { impl_DeleteText, "DeleteText" },
191
  { impl_PasteText, "PasteText" },
192
  { NULL, NULL }
193
};
194

            
195
void
196
161
spi_initialize_editabletext (DRoutePath *path)
197
{
198
161
  spi_atk_add_interface (path,
199
                         ATSPI_DBUS_INTERFACE_EDITABLE_TEXT, spi_org_a11y_atspi_EditableText, methods, NULL);
200
161
};