1
/*
2
 * AT-SPI - Assistive Technology Service Provider Interface
3
 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4
 *
5
 * Copyright 2001, 2002 Sun Microsystems Inc.,
6
 * Copyright 2001, 2002 Ximian, Inc.
7
 *
8
 * This library is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11
 * version 2.1 of the License, or (at your option) any later version.
12
 *
13
 * This library is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19
 * License along with this library; if not, write to the
20
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21
 * Boston, MA 02110-1301, USA.
22
 */
23

            
24
#include "atspi-private.h"
25

            
26
/**
27
 * AtspiEditabletext:
28
 *
29
 * An interface that provides methods for modifying textual content
30
 * of components which support editing.
31
 *
32
 * Derived from atspi-text, the atspi-editabletext interface
33
 * provides methods for modifying textual content of components
34
 * which support editing. EditableText also interacts with the
35
 * system clipboard via copy, cut, and paste methods.
36
 */
37

            
38
#if 0
39
/* TODO: implement */
40
/**
41
 * atspi_editable_text_set_attributes:
42
 * @obj: a pointer to the #AtspiEditableText object to modify.
43
 * @attributes: a string indicating the attributes to apply to the range,
44
 *        delimited by ':'.
45
 * @startOffset: a #gint indicating the start of the desired text range.
46
 * @endOffset: a #gint indicating the first character past the desired range.
47
 *
48
 * Sets the attributes applied to a range of text from an #AtspiEditableText
49
 *          object, and the bounds of the range.
50
 *
51
 * Returns: #TRUE if the operation was successful, otherwise #FALSE.
52
 **/
53
gboolean
54
atspi_editable_text_set_attributes (AtspiEditableText *obj,
55
				    const char *attributes,
56
				    gint start_pos,
57
				    gint end_pos,
58
				    GError **error
59
{
60
  dbus_int32_t d_start_pos = start_pos, d_end_pos = end_pos;
61
  dbus_bool_t retval = FALSE;
62

            
63
  cspi_return_val_if_fail (obj != NULL, FALSE);
64

            
65
  _atspi_dbus_call (obj, atspi_interface_editable_text, "SetAttributes", error, "sii=>b", attributes, d_start_pos, d_end_pos, &retval);
66

            
67
  return retval;
68
}
69
#endif
70

            
71
/**
72
 * atspi_editable_text_set_text_contents:
73
 * @obj: a pointer to the #AtspiEditableText object to modify.
74
 * @new_contents: a character string, encoded in UTF-8, which is to
75
 *      become the new text contents of the #AtspiEditableText object.
76
 *
77
 * Replace the entire text contents of an #AtspiEditableText object.
78
 *
79
 * Returns: #TRUE if the operation was successful, otherwise #FALSE.
80
 **/
81
gboolean
82
atspi_editable_text_set_text_contents (AtspiEditableText *obj,
83
                                       const gchar *new_contents,
84
                                       GError **error)
85
{
86
  dbus_bool_t retval = FALSE;
87

            
88
  g_return_val_if_fail (obj != NULL, FALSE);
89

            
90
  _atspi_dbus_call (obj, atspi_interface_editable_text, "SetTextContents", error, "s=>b", new_contents, &retval);
91

            
92
  return retval;
93
}
94

            
95
/**
96
 * atspi_editable_text_insert_text:
97
 * @obj: a pointer to the #AtspiEditableText object to modify.
98
 * @position: a #gint indicating the character offset at which to insert
99
 *       the new text.
100
 * @text: a string representing the text to insert, in UTF-8 encoding.
101
 * @length:  the number of characters of text to insert, in bytes. If the
102
 * byte count of text is less than or equal to length, the entire contents
103
 * of text will be inserted.
104
 *
105
 * Inserts text into an #AtspiEditableText object.
106
 * As with all character offsets, the specified @position may not be the
107
 * same as the resulting byte offset, since the text is in a
108
 * variable-width encoding.
109
 *
110
 * Returns: #TRUE if the operation was successful, otherwise #FALSE.
111
 **/
112
gboolean
113
1
atspi_editable_text_insert_text (AtspiEditableText *obj,
114
                                 gint position,
115
                                 const gchar *text,
116
                                 gint length,
117
                                 GError **error)
118
{
119
1
  dbus_int32_t d_position = position, d_length = length;
120
1
  dbus_bool_t retval = FALSE;
121

            
122
1
  g_return_val_if_fail (obj != NULL, FALSE);
123

            
124
1
  _atspi_dbus_call (obj, atspi_interface_editable_text, "InsertText", error, "isi=>b", d_position, text, d_length, &retval);
125

            
126
1
  return retval;
127
}
128

            
129
/**
130
 * atspi_editable_text_copy_text:
131
 * @obj: a pointer to the #AtspiEditableText object to modify.
132
 * @start_pos: a #gint indicating the starting character offset
133
 *       of the text to copy.
134
 * @end_pos: a #gint indicating the offset of the first character
135
 *       past the end of the text section to be copied.
136
 *
137
 * Copies text from an #AtspiEditableText object into the system clipboard.
138
 *
139
 * see: #atspi_editable_text_paste_text
140
 *
141
 * Returns: #TRUE if the operation was successful, otherwise #FALSE.
142
 **/
143
gboolean
144
1
atspi_editable_text_copy_text (AtspiEditableText *obj,
145
                               gint start_pos,
146
                               gint end_pos,
147
                               GError **error)
148
{
149
1
  dbus_int32_t d_start_pos = start_pos, d_end_pos = end_pos;
150

            
151
1
  g_return_val_if_fail (obj != NULL, FALSE);
152

            
153
1
  _atspi_dbus_call (obj, atspi_interface_editable_text, "CopyText", error, "ii", d_start_pos, d_end_pos);
154

            
155
1
  return TRUE;
156
}
157

            
158
/**
159
 * atspi_editable_text_cut_text:
160
 * @obj: a pointer to the #AtspiEditableText object to modify.
161
 * @start_pos: a #gint indicating the starting character offset
162
 *       of the text to cut.
163
 * @end_pos: a #gint indicating the offset of the first character
164
 *       past the end of the text section to be cut.
165
 *
166
 * Deletes text from an #AtspiEditableText object, copying the
167
 *       excised portion into the system clipboard.
168
 *
169
 * see: #atspi_editable_text_paste_text
170
 *
171
 * Returns: #TRUE if operation was successful, #FALSE otherwise.
172
 **/
173
gboolean
174
1
atspi_editable_text_cut_text (AtspiEditableText *obj,
175
                              gint start_pos,
176
                              gint end_pos,
177
                              GError **error)
178
{
179
1
  dbus_int32_t d_start_pos = start_pos, d_end_pos = end_pos;
180
1
  dbus_bool_t retval = FALSE;
181

            
182
1
  g_return_val_if_fail (obj != NULL, FALSE);
183

            
184
1
  _atspi_dbus_call (obj, atspi_interface_editable_text, "CutText", error, "ii=>b", d_start_pos, d_end_pos, &retval);
185

            
186
1
  return retval;
187
}
188

            
189
/**
190
 * atspi_editable_text_delete_text:
191
 * @obj: a pointer to the #AtspiEditableText object to modify.
192
 * @start_pos: a #gint indicating the starting character offset
193
 *       of the text to delete.
194
 * @end_pos: a #gint indicating the offset of the first character
195
 *       past the end of the text section to be deleted.
196
 *
197
 * Deletes text from an #AtspiEditableText object, without copying the
198
 *       excised portion into the system clipboard.
199
 *
200
 * see: #atspi_editable_text_cut_text
201
 *
202
 * Returns: #TRUE if the operation was successful, otherwise #FALSE.
203
 **/
204
gboolean
205
1
atspi_editable_text_delete_text (AtspiEditableText *obj,
206
                                 gint start_pos,
207
                                 gint end_pos,
208
                                 GError **error)
209
{
210
1
  dbus_int32_t d_start_pos = start_pos, d_end_pos = end_pos;
211
1
  dbus_bool_t retval = FALSE;
212

            
213
1
  g_return_val_if_fail (obj != NULL, FALSE);
214

            
215
1
  _atspi_dbus_call (obj, atspi_interface_editable_text, "DeleteText", error, "ii=>b", d_start_pos, d_end_pos, &retval);
216

            
217
1
  return retval;
218
}
219

            
220
/**
221
 * atspi_editable_text_paste_text:
222
 * @obj: a pointer to the #AtspiEditableText object to modify.
223
 * @position: a #gint indicating the character offset at which to insert
224
 *       the new text.
225
 *
226
 * Inserts text from the system clipboard into an #AtspiEditableText object.
227
 * As with all character offsets, the specified @position may not be the
228
 *       same as the resulting byte offset, since the text is in a
229
 *       variable-width encoding.
230
 *
231
 * Returns: #TRUE if the operation was successful, otherwise #FALSE.
232
 **/
233
gboolean
234
1
atspi_editable_text_paste_text (AtspiEditableText *obj,
235
                                gint position,
236
                                GError **error)
237
{
238
1
  dbus_int32_t d_position = position;
239
1
  dbus_bool_t retval = FALSE;
240

            
241
1
  g_return_val_if_fail (obj != NULL, FALSE);
242

            
243
1
  _atspi_dbus_call (obj, atspi_interface_editable_text, "PasteText", error, "i=>b", d_position, &retval);
244

            
245
1
  return retval;
246
}
247

            
248
static void
249
4
atspi_editable_text_base_init (AtspiEditableText *klass)
250
{
251
4
}
252

            
253
GType
254
8
atspi_editable_text_get_type (void)
255
{
256
  static GType type = 0;
257

            
258
8
  if (!type)
259
    {
260
      static const GTypeInfo tinfo = {
261
        sizeof (AtspiEditableText),
262
        (GBaseInitFunc) atspi_editable_text_base_init,
263
        (GBaseFinalizeFunc) NULL,
264
      };
265

            
266
2
      type = g_type_register_static (G_TYPE_INTERFACE, "AtspiEditableText", &tinfo, 0);
267
    }
268
8
  return type;
269
}