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
 * Copyright 2010, 2011 Novell, 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 "atspi-private.h"
26

            
27
/**
28
 * AtspiText:
29
 *
30
 * An interface implemented by objects which place textual
31
 * information onscreen.
32
 *
33
 * The text interface should be implemented by objects which place textual
34
 * information onscreen as character strings or glyphs. The text interface
35
 * allows access to textual content including display attributes and
36
 * semantic hints associated with runs of text, and to bounding
37
 * information for glyphs and substrings. It also allows portions of text to
38
 * be selected, if the objects StateSet includes STATE_SELECTABLE_TEXT.
39
 */
40

            
41
/**
42
 * atspi_range_copy:
43
 * @src: a pointer to the source #AtspiRange object that will be copied.
44
 *
45
 * Gets a copy of an #AtspiRange object.
46
 *
47
 * Returns: the #AtspiRange copy of an #AtspiRange object.
48
 **/
49
AtspiRange *
50
atspi_range_copy (AtspiRange *src)
51
{
52
  AtspiRange *dst = g_new (AtspiRange, 1);
53

            
54
  dst->start_offset = src->start_offset;
55
  dst->end_offset = src->end_offset;
56
  return dst;
57
}
58

            
59
G_DEFINE_BOXED_TYPE (AtspiRange, atspi_range, atspi_range_copy, g_free)
60

            
61
static AtspiTextRange *
62
atspi_text_range_copy (AtspiTextRange *src)
63
{
64
  AtspiTextRange *dst = g_new (AtspiTextRange, 1);
65

            
66
  dst->content = g_strdup (src->content);
67
  dst->start_offset = src->start_offset;
68
  dst->end_offset = src->end_offset;
69
  return dst;
70
}
71

            
72
static void
73
5
atspi_text_range_free (AtspiTextRange *range)
74
{
75
5
  g_free (range->content);
76
5
  g_free (range);
77
5
}
78

            
79
5
G_DEFINE_BOXED_TYPE (AtspiTextRange, atspi_text_range, atspi_text_range_copy, atspi_text_range_free)
80

            
81
/**
82
 * atspi_text_get_character_count:
83
 * @obj: a pointer to the #AtspiText object to query.
84
 *
85
 * Gets the character count of an #AccessibleText object.
86
 *
87
 * Returns: a #gint indicating the total number of
88
 *              characters in the #AccessibleText object.
89
 **/
90
gint
91
1
atspi_text_get_character_count (AtspiText *obj, GError **error)
92
{
93
1
  dbus_int32_t retval = 0;
94

            
95
1
  g_return_val_if_fail (obj != NULL, -1);
96

            
97
1
  _atspi_dbus_get_property (obj, atspi_interface_text, "CharacterCount", error, "i", &retval);
98

            
99
1
  return retval;
100
}
101

            
102
/**
103
 * atspi_text_get_text:
104
 * @obj: a pointer to the #AtspiText object to query.
105
 * @start_offset: a #gint indicating the start of the desired text range.
106
 * @end_offset: a #gint indicating the first character past the desired range.
107
 *
108
 * Gets a range of text from an #AtspiText object.  The number of bytes
109
 *          in the returned string may exceed either end_offset or start_offset, since
110
 *          UTF-8 is a variable-width encoding.
111
 *
112
 * Returns: a text string containing characters from @start_offset
113
 *          to @end_offset-1, inclusive, encoded as UTF-8.
114
 **/
115
gchar *
116
2
atspi_text_get_text (AtspiText *obj,
117
                     gint start_offset,
118
                     gint end_offset,
119
                     GError **error)
120
{
121
2
  gchar *retval = NULL;
122
2
  dbus_int32_t d_start_offset = start_offset, d_end_offset = end_offset;
123

            
124
2
  g_return_val_if_fail (obj != NULL, g_strdup (""));
125

            
126
2
  _atspi_dbus_call (obj, atspi_interface_text, "GetText", error, "ii=>s", d_start_offset, d_end_offset, &retval);
127

            
128
2
  if (!retval)
129
    retval = g_strdup ("");
130

            
131
2
  return retval;
132
}
133

            
134
/**
135
 * atspi_text_get_caret_offset:
136
 * @obj: a pointer to the #AtspiText object to query.
137
 *
138
 * Gets the current offset of the text caret in an #AtspiText object.
139
 *
140
 * Returns: a #gint indicating the current position of the text caret.
141
 **/
142
gint
143
2
atspi_text_get_caret_offset (AtspiText *obj, GError **error)
144
{
145
2
  dbus_int32_t retval = -1;
146

            
147
2
  g_return_val_if_fail (obj != NULL, -1);
148

            
149
2
  _atspi_dbus_get_property (obj, atspi_interface_text, "CaretOffset", error, "i", &retval);
150

            
151
2
  return retval;
152
}
153

            
154
/**
155
 * atspi_text_get_attributes: (rename-to atspi_text_get_text_attributes)
156
 * @obj: a pointer to the #AtspiText object to query.
157
 * @offset: a #gint indicating the offset from which the attribute
158
 *        search is based.
159
 * @start_offset: (out): a #gint pointer indicating the start of the desired text
160
 *                range.
161
 * @end_offset: (out): a #gint pointer indicating the first character past the desired
162
 *              range.
163
 *
164
 * Gets the attributes applied to a range of text from an #AtspiText
165
 * object. The text attributes correspond to CSS attributes
166
 * where possible.
167
 *
168
 * Returns: (element-type gchar* gchar*) (transfer full): a #GHashTable
169
 * describing the attributes at the given character offset.
170
 *
171
 * Deprecated: 2.10: Use atspi_text_get_text_attributes instead.
172
 **/
173
GHashTable *
174
atspi_text_get_attributes (AtspiText *obj,
175
                           gint offset,
176
                           gint *start_offset,
177
                           gint *end_offset,
178
                           GError **error)
179
{
180
  return atspi_text_get_text_attributes (obj, offset, start_offset, end_offset, error);
181
}
182

            
183
/**
184
 * atspi_text_get_text_attributes:
185
 * @obj: a pointer to the #AtspiText object to query.
186
 * @offset: a #gint indicating the offset from which the attribute
187
 *        search is based.
188
 * @start_offset: (out): a #gint pointer indicating the start of the desired text
189
 *                range.
190
 * @end_offset: (out): a #gint pointer indicating the first character past the desired
191
 *              range.
192
 *
193
 * Gets the attributes applied to a range of text from an #AtspiText
194
 * object. The text attributes correspond to CSS attributes
195
 * where possible.
196
 *
197
 * Returns: (element-type gchar* gchar*) (transfer full): a #GHashTable
198
 * describing the attributes at the given character offset.
199
 **/
200
GHashTable *
201
1
atspi_text_get_text_attributes (AtspiText *obj,
202
                                gint offset,
203
                                gint *start_offset,
204
                                gint *end_offset,
205
                                GError **error)
206
{
207
1
  dbus_int32_t d_offset = offset;
208
  dbus_int32_t d_start_offset, d_end_offset;
209
  DBusMessage *reply;
210
  DBusMessageIter iter;
211
1
  GHashTable *ret = NULL;
212

            
213
1
  if (obj == NULL)
214
    return NULL;
215

            
216
1
  reply = _atspi_dbus_call_partial (obj, atspi_interface_text, "GetAttributes", error, "i", d_offset);
217
1
  _ATSPI_DBUS_CHECK_SIG (reply, "a{ss}ii", error, ret)
218

            
219
1
  dbus_message_iter_init (reply, &iter);
220
1
  ret = _atspi_dbus_hash_from_iter (&iter);
221
1
  dbus_message_iter_next (&iter);
222

            
223
1
  dbus_message_iter_get_basic (&iter, &d_start_offset);
224
1
  if (start_offset)
225
1
    *start_offset = d_start_offset;
226
1
  dbus_message_iter_next (&iter);
227
1
  dbus_message_iter_get_basic (&iter, &d_end_offset);
228
1
  if (end_offset)
229
1
    *end_offset = d_end_offset;
230

            
231
1
  dbus_message_unref (reply);
232
1
  return ret;
233
}
234

            
235
/**
236
 * atspi_text_get_attribute_run:
237
 * @obj: a pointer to the #AtspiText object to query.
238
 * @offset: a #gint indicating the offset from which the attribute
239
 *        search is based.
240
 * @include_defaults: a #bool that, when set as #FALSE, indicates the call
241
 * should only return those attributes which are explicitly set on the current
242
 * attribute run, omitting any attributes which are inherited from the
243
 * default values.
244
 * @start_offset: (out): a #gint pointer indicating the start of the desired text
245
 *                range.
246
 * @end_offset: (out): a #gint pointer indicating the first character past the desired
247
 *              range.
248
 *
249
 * Gets a set of attributes applied to a range of text from an #AtspiText object, optionally
250
 * including its 'default' attributes.
251
 *
252
 * Returns: (element-type gchar* gchar*) (transfer full): a #GHashTable with attributes
253
 *          defined at the indicated offset, optionally including the 'default' ones.
254
 **/
255
GHashTable *
256
1
atspi_text_get_attribute_run (AtspiText *obj,
257
                              gint offset,
258
                              gboolean include_defaults,
259
                              gint *start_offset,
260
                              gint *end_offset,
261
                              GError **error)
262
{
263
1
  dbus_int32_t d_offset = offset;
264
  dbus_int32_t d_start_offset, d_end_offset;
265
  DBusMessage *reply;
266
  DBusMessageIter iter;
267
1
  GHashTable *ret = NULL;
268

            
269
1
  if (obj == NULL)
270
    return NULL;
271

            
272
1
  reply = _atspi_dbus_call_partial (obj, atspi_interface_text,
273
                                    "GetAttributeRun", error, "ib", d_offset,
274
                                    include_defaults);
275
1
  _ATSPI_DBUS_CHECK_SIG (reply, "a{ss}ii", error, ret)
276

            
277
1
  dbus_message_iter_init (reply, &iter);
278
1
  ret = _atspi_dbus_hash_from_iter (&iter);
279
1
  dbus_message_iter_next (&iter);
280

            
281
1
  dbus_message_iter_get_basic (&iter, &d_start_offset);
282
1
  if (start_offset)
283
1
    *start_offset = d_start_offset;
284
1
  dbus_message_iter_next (&iter);
285
1
  dbus_message_iter_get_basic (&iter, &d_end_offset);
286
1
  if (end_offset)
287
1
    *end_offset = d_end_offset;
288

            
289
1
  dbus_message_unref (reply);
290
1
  return ret;
291
}
292

            
293
/**
294
 * atspi_text_get_attribute_value: (rename-to atspi_text_get_text_attribute_value)
295
 * @obj: a pointer to the #AtspiText object to query.
296
 * @offset: The character offset at which to query the attribute.
297
 * @attribute_name: The attribute to query.
298
 *
299
 * Gets the value of a named attribute at a given offset.
300
 *
301
 * Returns: (nullable): the value of a given attribute at the given
302
 * offset, or %NULL if not present.
303
 *
304
 * Deprecated: 2.10: Use atspi_text_get_text_attribute_value instead.
305
 **/
306
gchar *
307
atspi_text_get_attribute_value (AtspiText *obj,
308
                                gint offset,
309
                                const gchar *attribute_name,
310
                                GError **error)
311
{
312
  return atspi_text_get_text_attribute_value (obj, offset, attribute_name,
313
                                              error);
314
}
315

            
316
/**
317
 * atspi_text_get_text_attribute_value:
318
 * @obj: a pointer to the #AtspiText object to query.
319
 * @offset: The character offset at which to query the attribute.
320
 * @attribute_name: The attribute to query.
321
 *
322
 * Gets the value of a named attribute at a given offset.
323
 *
324
 * Returns: (nullable): the value of a given attribute at the given offset, or %NULL if
325
 * not present.
326
 **/
327
gchar *
328
2
atspi_text_get_text_attribute_value (AtspiText *obj,
329
                                     gint offset,
330
                                     const gchar *attribute_name,
331
                                     GError **error)
332
{
333
2
  gchar *retval = NULL;
334
2
  dbus_int32_t d_i = offset;
335

            
336
2
  g_return_val_if_fail (obj != NULL, NULL);
337

            
338
2
  _atspi_dbus_call (obj, atspi_interface_text, "GetAttributeValue", error, "is=>s", d_i, attribute_name, &retval);
339

            
340
2
  if (!retval)
341
    retval = g_strdup ("");
342

            
343
2
  return retval;
344
}
345

            
346
/**
347
 * atspi_text_get_default_attributes:
348
 * @obj: a pointer to the #AtspiText object to query.
349
 *
350
 * Gets the default attributes applied to an #AtspiText
351
 * object. The text attributes correspond to CSS attributes
352
 * where possible. The combination of this attribute set and
353
 * the attributes reported by #atspi_text_get_attributes
354
 * describes the entire set of text attributes over a range.
355
 *
356
 * Returns: (element-type gchar* gchar*) (transfer full): a #GHashTable
357
 *          containing the default attributes applied to a text object,
358
 *          (exclusive of explicitly-set attributes), encoded as UTF-8.
359
 **/
360
GHashTable *
361
1
atspi_text_get_default_attributes (AtspiText *obj, GError **error)
362
{
363
  DBusMessage *reply;
364

            
365
1
  g_return_val_if_fail (obj != NULL, NULL);
366

            
367
1
  reply = _atspi_dbus_call_partial (obj, atspi_interface_text, "GetDefaultAttributes", error, "");
368
1
  return _atspi_dbus_return_hash_from_message (reply);
369
}
370

            
371
/**
372
 * atspi_text_set_caret_offset:
373
 * @obj: a pointer to the #AtspiText object on which to operate.
374
 * @new_offset: the offset to which the text caret is to be moved.
375
 *
376
 * Moves the text caret to a given position.
377
 *
378
 * Returns: #TRUE if successful, #FALSE otherwise.
379
 **/
380
gboolean
381
2
atspi_text_set_caret_offset (AtspiText *obj,
382
                             gint new_offset,
383
                             GError **error)
384
{
385
2
  dbus_int32_t d_new_offset = new_offset;
386
2
  dbus_bool_t retval = FALSE;
387

            
388
2
  g_return_val_if_fail (obj != NULL, FALSE);
389

            
390
2
  _atspi_dbus_call (obj, atspi_interface_text, "SetCaretOffset", error, "i=>b", d_new_offset, &retval);
391

            
392
2
  return retval;
393
}
394

            
395
/**
396
 * atspi_text_get_text_before_offset:
397
 * @obj: a pointer to the #AtspiText object on which to operate.
398
 * @offset: a #gint indicating the offset from which the delimiter
399
 *        search is based.
400
 * @type: an #AtspiTextBoundaryType indicating whether the desired
401
 *       text string is a word, sentence, line, or attribute run.
402
 *
403
 * Gets delimited text from an #AtspiText object which precedes a given
404
 *          text offset.
405
 *
406
 * Returns: an #AtspiTextRange containing a UTF-8 string representing the
407
 *          delimited text, both of whose delimiting boundaries are before the
408
 *          current offset, or an empty string if no such text exists.
409
 **/
410
AtspiTextRange *
411
atspi_text_get_text_before_offset (AtspiText *obj,
412
                                   gint offset,
413
                                   AtspiTextBoundaryType type,
414
                                   GError **error)
415
{
416
  dbus_int32_t d_offset = offset;
417
  dbus_uint32_t d_type = type;
418
  dbus_int32_t d_start_offset = -1, d_end_offset = -1;
419
  AtspiTextRange *range = g_new0 (AtspiTextRange, 1);
420

            
421
  range->start_offset = range->end_offset = -1;
422
  if (!obj)
423
    return range;
424

            
425
  _atspi_dbus_call (obj, atspi_interface_text, "GetTextBeforeOffset", error,
426
                    "iu=>sii", d_offset, d_type, &range->content,
427
                    &d_start_offset, &d_end_offset);
428

            
429
  range->start_offset = d_start_offset;
430
  range->end_offset = d_end_offset;
431
  if (!range->content)
432
    range->content = g_strdup ("");
433

            
434
  return range;
435
}
436

            
437
static AtspiTextBoundaryType
438
get_legacy_boundary_type (AtspiTextGranularity granularity)
439
{
440
  switch (granularity)
441
    {
442
    case ATSPI_TEXT_GRANULARITY_CHAR:
443
      return ATSPI_TEXT_BOUNDARY_CHAR;
444
    case ATSPI_TEXT_GRANULARITY_WORD:
445
      return ATSPI_TEXT_BOUNDARY_WORD_START;
446
    case ATSPI_TEXT_GRANULARITY_SENTENCE:
447
      return ATSPI_TEXT_BOUNDARY_SENTENCE_START;
448
    case ATSPI_TEXT_GRANULARITY_LINE:
449
      return ATSPI_TEXT_BOUNDARY_LINE_START;
450
    case ATSPI_TEXT_GRANULARITY_PARAGRAPH:
451
      /* This is not implemented in previous versions of ATSPI */
452
      /* fall through to default case */
453
    default:
454
      return -1;
455
    }
456
}
457

            
458
/**
459
 * atspi_text_get_string_at_offset:
460
 * @obj: an #AtspiText
461
 * @offset: position
462
 * @granularity: An #AtspiTextGranularity
463
 *
464
 * Gets a portion of the text exposed through an #AtspiText according to a given @offset
465
 * and a specific @granularity, along with the start and end offsets defining the
466
 * boundaries of such a portion of text.
467
 *
468
 * If @granularity is ATSPI_TEXT_GRANULARITY_CHAR the character at the
469
 * offset is returned.
470
 *
471
 * If @granularity is ATSPI_TEXT_GRANULARITY_WORD the returned string
472
 * is from the word start at or before the offset to the word start after
473
 * the offset.
474
 *
475
 * The returned string will contain the word at the offset if the offset
476
 * is inside a word and will contain the word before the offset if the
477
 * offset is not inside a word.
478
 *
479
 * If @granularity is ATSPI_TEXT_GRANULARITY_SENTENCE the returned string
480
 * is from the sentence start at or before the offset to the sentence
481
 * start after the offset.
482
 *
483
 * The returned string will contain the sentence at the offset if the offset
484
 * is inside a sentence and will contain the sentence before the offset
485
 * if the offset is not inside a sentence.
486
 *
487
 * If @granularity is ATSPI_TEXT_GRANULARITY_LINE the returned string
488
 * is from the line start at or before the offset to the line
489
 * start after the offset.
490
 *
491
 * If @granularity is ATSPI_TEXT_GRANULARITY_PARAGRAPH the returned string
492
 * is from the start of the paragraph at or before the offset to the start
493
 * of the following paragraph after the offset.
494
 *
495
 * Since: 2.9.90
496
 *
497
 * Returns: a newly allocated string containing the text at the @offset bounded
498
 *   by the specified @granularity. Use g_free() to free the returned string.
499
 *   Returns %NULL if the offset is invalid or no implementation is available.
500
 **/
501
AtspiTextRange *
502
5
atspi_text_get_string_at_offset (AtspiText *obj,
503
                                 gint offset,
504
                                 AtspiTextGranularity granularity,
505
                                 GError **error)
506
{
507
5
  dbus_int32_t d_offset = offset;
508
5
  dbus_uint32_t d_granularity = granularity;
509
5
  dbus_int32_t d_start_offset = -1, d_end_offset = -1;
510
5
  AtspiTextRange *range = g_new0 (AtspiTextRange, 1);
511
5
  GError *local_error = NULL;
512

            
513
5
  range->start_offset = range->end_offset = -1;
514
5
  if (!obj)
515
    return range;
516

            
517
5
  _atspi_dbus_call (obj, atspi_interface_text, "GetStringAtOffset", &local_error,
518
                    "iu=>sii", d_offset, d_granularity, &range->content,
519
                    &d_start_offset, &d_end_offset);
520

            
521
5
  if (local_error)
522
    {
523
      AtspiTextBoundaryType boundary = get_legacy_boundary_type (granularity);
524
      if (boundary == -1)
525
        {
526
          g_propagate_error (error, local_error);
527
          return range;
528
        }
529

            
530
      g_clear_error (&local_error);
531
      atspi_text_range_free (range);
532
      return atspi_text_get_text_at_offset (obj, offset, boundary, error);
533
    }
534

            
535
5
  range->start_offset = d_start_offset;
536
5
  range->end_offset = d_end_offset;
537
5
  if (!range->content)
538
    range->content = g_strdup ("");
539

            
540
5
  return range;
541
}
542

            
543
/**
544
 * atspi_text_get_text_at_offset:
545
 * @obj: a pointer to the #AtspiText object on which to operate.
546
 * @offset: a #gint indicating the offset from which the delimiter
547
 *        search is based.
548
 * @type: an #AtspiTextBoundaryType indicating whether the desired
549
 *       text string is a word, sentence, line, or attribute run.
550
 *
551
 * Gets delimited text from an #AtspiText object which includes a given
552
 *          text offset.
553
 *
554
 * Returns: an #AtspiTextRange containing a UTF-8 string representing the
555
 *          delimited text, whose delimiting boundaries bracket the
556
 *          current offset, or an empty string if no such text exists.
557
 *
558
 * Deprecated: 2.10: Use atspi_text_get_string_at_offset.
559
 **/
560
AtspiTextRange *
561
atspi_text_get_text_at_offset (AtspiText *obj,
562
                               gint offset,
563
                               AtspiTextBoundaryType type,
564
                               GError **error)
565
{
566
  dbus_int32_t d_offset = offset;
567
  dbus_uint32_t d_type = type;
568
  dbus_int32_t d_start_offset = -1, d_end_offset = -1;
569
  AtspiTextRange *range = g_new0 (AtspiTextRange, 1);
570

            
571
  range->start_offset = range->end_offset = -1;
572
  if (!obj)
573
    return range;
574

            
575
  _atspi_dbus_call (obj, atspi_interface_text, "GetTextAtOffset", error,
576
                    "iu=>sii", d_offset, d_type, &range->content,
577
                    &d_start_offset, &d_end_offset);
578

            
579
  range->start_offset = d_start_offset;
580
  range->end_offset = d_end_offset;
581
  if (!range->content)
582
    range->content = g_strdup ("");
583

            
584
  return range;
585
}
586

            
587
/**
588
 * atspi_text_get_text_after_offset:
589
 * @obj: a pointer to the #AtspiText object on which to operate.
590
 * @offset: a #gint indicating the offset from which the delimiter
591
 *        search is based.
592
 * @type: an #AtspiTextBoundaryType indicating whether the desired
593
 *       text string is a word, sentence, line, or attribute run.
594
 *
595
 * Gets delimited text from an #AtspiText object which follows a given
596
 *          text offset.
597
 *
598
 * Returns: an #AtspiTextRange containing a UTF-8 string representing the
599
 *          delimited text, both of whose delimiting boundaries are after or
600
 *          inclusive of the current offset, or an empty string if no such
601
 *          text exists.
602
 **/
603
AtspiTextRange *
604
atspi_text_get_text_after_offset (AtspiText *obj,
605
                                  gint offset,
606
                                  AtspiTextBoundaryType type,
607
                                  GError **error)
608
{
609
  dbus_int32_t d_offset = offset;
610
  dbus_uint32_t d_type = type;
611
  dbus_int32_t d_start_offset = -1, d_end_offset = -1;
612
  AtspiTextRange *range = g_new0 (AtspiTextRange, 1);
613

            
614
  range->start_offset = range->end_offset = -1;
615
  if (!obj)
616
    return range;
617

            
618
  _atspi_dbus_call (obj, atspi_interface_text, "GetTextAfterOffset", error,
619
                    "iu=>sii", d_offset, d_type, &range->content,
620
                    &d_start_offset, &d_end_offset);
621

            
622
  range->start_offset = d_start_offset;
623
  range->end_offset = d_end_offset;
624
  if (!range->content)
625
    range->content = g_strdup ("");
626

            
627
  return range;
628
}
629

            
630
/**
631
 * atspi_text_get_character_at_offset:
632
 * @obj: a pointer to the #AtspiText object on which to operate.
633
 * @offset: a #gint indicating the text offset where the desired
634
 *          character is located.
635
 *
636
 * Gets the character at a given offset for an #AtspiText object.
637
 *
638
 * Returns: a #guint  representing the
639
 *        UCS-4 unicode code point of the given character, or
640
 *        0xFFFFFFFF if the character in question cannot be represented
641
 *        in the UCS-4 encoding.
642
 **/
643
guint
644
1
atspi_text_get_character_at_offset (AtspiText *obj,
645
                                    gint offset,
646
                                    GError **error)
647
{
648
1
  dbus_int32_t d_offset = offset;
649
1
  dbus_int32_t retval = -1;
650

            
651
1
  g_return_val_if_fail (obj != NULL, -1);
652

            
653
1
  _atspi_dbus_call (obj, atspi_interface_text, "GetCharacterAtOffset", error, "i=>i", d_offset, &retval);
654

            
655
1
  return retval;
656
}
657

            
658
/**
659
 * atspi_text_get_character_extents:
660
 * @obj: a pointer to the #AtspiText object on which to operate.
661
 * @offset: a #gint indicating the offset of the text character for
662
 *        whom boundary information is requested.
663
 * @type: an #AccessibleCoordType indicating the coordinate system to use
664
 *        for the returned values.
665
 *
666
 * Gets a bounding box containing the glyph representing
667
 *        the character at a particular text offset.
668
 * The returned values are meaningful only if the Text has both
669
 * STATE_VISIBLE and STATE_SHOWING.
670
 *
671
 * Returns: An #AtspiRect specifying the position and size of the character.
672
 *
673
 **/
674
AtspiRect *
675
1
atspi_text_get_character_extents (AtspiText *obj,
676
                                  gint offset,
677
                                  AtspiCoordType type,
678
                                  GError **error)
679
{
680
1
  dbus_int32_t d_offset = offset;
681
1
  dbus_uint32_t d_type = type;
682
  dbus_int32_t d_x, d_y, d_width, d_height;
683
  AtspiRect ret;
684

            
685
1
  ret.x = ret.y = ret.width = ret.height = -1;
686

            
687
1
  if (obj == NULL)
688
    return atspi_rect_copy (&ret);
689

            
690
1
  _atspi_dbus_call (obj, atspi_interface_text, "GetCharacterExtents", error, "iu=>iiii", d_offset, d_type, &d_x, &d_y, &d_width, &d_height);
691

            
692
1
  ret.x = d_x;
693
1
  ret.y = d_y;
694
1
  ret.width = d_width;
695
1
  ret.height = d_height;
696
1
  return atspi_rect_copy (&ret);
697
}
698

            
699
/**
700
 * atspi_text_get_offset_at_point:
701
 * @obj: a pointer to the #AtspiText object on which to operate.
702
 * @x: the x coordinate of the point to be queried.
703
 * @y: the y coordinate of the point to be queried.
704
 * @type: an #AtspiCoordType indicating the coordinate system in which
705
 *       the values should be returned.
706
 *
707
 * Gets the character offset into the text at a given point.
708
 *
709
 * Returns: the offset (as a #gint) at the point (@x, @y)
710
 *       in the specified coordinate system.
711
 *
712
 **/
713
gint
714
1
atspi_text_get_offset_at_point (AtspiText *obj,
715
                                gint x,
716
                                gint y,
717
                                AtspiCoordType type,
718
                                GError **error)
719
{
720
1
  dbus_int32_t d_x = x, d_y = y;
721
1
  dbus_uint32_t d_type = type;
722
1
  dbus_int32_t retval = -1;
723

            
724
1
  g_return_val_if_fail (obj != NULL, -1);
725

            
726
1
  _atspi_dbus_call (obj, atspi_interface_text, "GetOffsetAtPoint", error, "iiu=>i", d_x, d_y, d_type, &retval);
727

            
728
1
  return retval;
729
}
730

            
731
/**
732
 * atspi_text_get_range_extents:
733
 * @obj: a pointer to the #AtspiText object on which to operate.
734
 * @start_offset: a #gint indicating the offset of the first text character for
735
 *        whom boundary information is requested.
736
 * @end_offset: a #gint indicating the offset of the text character
737
 *        after the last character for whom boundary information is requested.
738
 * @type: an #AtspiCoordType indicating the coordinate system to use
739
 *        for the returned values.
740
 *
741
 * Gets the bounding box for text within a range in an  #AtspiText object.
742
 * The returned values are meaningful only if the Text has both
743
 * STATE_VISIBLE and STATE_SHOWING.
744
 *
745
 * Returns: An #AtspiRect giving the position and size of the specified range
746
 *          of text.
747
 *
748
 **/
749
AtspiRect *
750
1
atspi_text_get_range_extents (AtspiText *obj,
751
                              gint start_offset,
752
                              gint end_offset,
753
                              AtspiCoordType type,
754
                              GError **error)
755
{
756
1
  dbus_int32_t d_start_offset = start_offset, d_end_offset = end_offset;
757
1
  dbus_uint32_t d_type = type;
758
  dbus_int32_t d_x, d_y, d_width, d_height;
759
  AtspiRect ret;
760

            
761
1
  ret.x = ret.y = ret.width = ret.height = -1;
762

            
763
1
  if (obj == NULL)
764
    return atspi_rect_copy (&ret);
765

            
766
1
  _atspi_dbus_call (obj, atspi_interface_text, "GetRangeExtents", error, "iiu=>iiii", d_start_offset, d_end_offset, d_type, &d_x, &d_y, &d_width, &d_height);
767

            
768
1
  ret.x = d_x;
769
1
  ret.y = d_y;
770
1
  ret.width = d_width;
771
1
  ret.height = d_height;
772
1
  return atspi_rect_copy (&ret);
773
}
774

            
775
/**
776
 * atspi_text_get_bounded_ranges:
777
 * @obj: a pointer to the #AtspiText object on which to operate.
778
 * @x: the 'starting' x coordinate of the bounding box.
779
 * @y: the 'starting' y coordinate of the bounding box.
780
 * @width: the x extent of the bounding box.
781
 * @height: the y extent of the bounding box.
782
 * @type: an #AccessibleCoordType indicating the coordinate system to use
783
 *        for the returned values.
784
 * @clipTypeX: an #AtspiTextClipType indicating how to treat characters that
785
 *        intersect the bounding box's x extents.
786
 * @clipTypeY: an #AtspiTextClipType indicating how to treat characters that
787
 *        intersect the bounding box's y extents.
788
 *
789
 * Gets the ranges of text from an #AtspiText object which lie within the
790
 *          bounds defined by (@x, @y) and (@x+@width, @y+@height).
791
 *
792
 * Returns: (transfer full) (element-type AtspiTextRange*): a null-terminated list of
793
 *          pointers to #AtspiTextRange structs detailing the bounded text.
794
 **/
795
GArray *
796
1
atspi_text_get_bounded_ranges (AtspiText *obj,
797
                               gint x,
798
                               gint y,
799
                               gint width,
800
                               gint height,
801
                               AtspiCoordType type,
802
                               AtspiTextClipType clipTypeX,
803
                               AtspiTextClipType clipTypeY,
804
                               GError **error)
805
{
806
1
  dbus_int32_t d_x = x, d_y = y, d_width = width, d_height = height;
807
1
  dbus_uint32_t d_type = type;
808
1
  dbus_uint32_t d_clipTypeX = clipTypeX, d_clipTypeY = clipTypeY;
809
1
  GArray *range_seq = NULL;
810

            
811
1
  g_return_val_if_fail (obj != NULL, NULL);
812

            
813
1
  _atspi_dbus_call (obj, atspi_interface_text, "GetBoundedRanges", error, "iiiiuuu=>a(iisv)", d_x, d_y, d_width, d_height, d_type, d_clipTypeX, d_clipTypeY, &range_seq);
814

            
815
1
  return range_seq;
816
}
817

            
818
/**
819
 * atspi_text_get_n_selections:
820
 * @obj: a pointer to the #AtspiText object on which to operate.
821
 *
822
 * Gets the number of active non-contiguous selections for an
823
 *          #AtspiText object.
824
 *
825
 * Returns: a #gint indicating the current
826
 *          number of non-contiguous text selections active
827
 *          within an #AtspiText object.
828
 **/
829
gint
830
6
atspi_text_get_n_selections (AtspiText *obj, GError **error)
831
{
832
6
  dbus_int32_t retval = 0;
833

            
834
6
  g_return_val_if_fail (obj != NULL, -1);
835

            
836
6
  _atspi_dbus_call (obj, atspi_interface_text, "GetNSelections", error, "=>i", &retval);
837

            
838
6
  return retval;
839
}
840

            
841
/**
842
 * atspi_text_get_selection:
843
 * @obj: a pointer to the #AtspiText object on which to operate.
844
 * @selection_num: a #gint indicating which selection to query.
845
 *
846
 * Gets the bounds of the @selection_num-th active text selection for an
847
 *         #AtspiText object.
848
 **/
849
AtspiRange *
850
4
atspi_text_get_selection (AtspiText *obj,
851
                          gint selection_num,
852
                          GError **error)
853
{
854
4
  dbus_int32_t d_selection_num = selection_num;
855
  dbus_int32_t d_start_offset, d_end_offset;
856
4
  AtspiRange *ret = g_new (AtspiRange, 1);
857

            
858
4
  ret->start_offset = ret->end_offset = -1;
859

            
860
4
  if (!obj)
861
    return ret;
862

            
863
4
  _atspi_dbus_call (obj, atspi_interface_text, "GetSelection", error, "i=>ii", d_selection_num, &d_start_offset, &d_end_offset);
864

            
865
4
  ret->start_offset = d_start_offset;
866
4
  ret->end_offset = d_end_offset;
867
4
  return ret;
868
}
869

            
870
/**
871
 * atspi_text_add_selection:
872
 * @obj: a pointer to the #AtspiText object on which to operate.
873
 * @start_offset: the starting offset of the desired new selection.
874
 * @end_offset: the offset of the first character after the new selection.
875
 *
876
 * Selects some text (adds a text selection) in an #AtspiText object.
877
 *
878
 * Returns: #TRUE if successful, #FALSE otherwise.
879
 **/
880
gboolean
881
10
atspi_text_add_selection (AtspiText *obj,
882
                          gint start_offset,
883
                          gint end_offset,
884
                          GError **error)
885
{
886
10
  dbus_int32_t d_start_offset = start_offset, d_end_offset = end_offset;
887
10
  dbus_bool_t retval = FALSE;
888

            
889
10
  _atspi_dbus_call (obj, atspi_interface_text, "AddSelection", error, "ii=>b", d_start_offset, d_end_offset, &retval);
890

            
891
10
  return retval;
892
}
893

            
894
/**
895
 * atspi_text_remove_selection:
896
 * @obj: a pointer to the #AtspiText object on which to operate.
897
 * @selection_num: a #gint indicating which text selection to remove.
898
 *
899
 * De-selects a text selection.
900
 *
901
 * Returns: #TRUE if successful, #FALSE otherwise.
902
 **/
903
gboolean
904
2
atspi_text_remove_selection (AtspiText *obj,
905
                             gint selection_num,
906
                             GError **error)
907
{
908
2
  dbus_int32_t d_selection_num = selection_num;
909
2
  dbus_bool_t retval = FALSE;
910

            
911
2
  g_return_val_if_fail (obj != NULL, FALSE);
912

            
913
2
  _atspi_dbus_call (obj, atspi_interface_text, "RemoveSelection", error, "i=>b", d_selection_num, &retval);
914

            
915
2
  return retval;
916
}
917

            
918
/**
919
 * atspi_text_set_selection:
920
 * @obj: a pointer to the #AtspiText object on which to operate.
921
 * @selection_num: a zero-offset index indicating which text selection to modify.
922
 * @start_offset: a #gint indicating the new starting offset for the selection.
923
 * @end_offset: a #gint indicating the desired new offset of the first character
924
 *             after the selection.
925
 *
926
 * Changes the bounds of an existing #AtspiText text selection.
927
 *
928
 * Returns: #TRUE if successful, #FALSE otherwise.
929
 **/
930
gboolean
931
2
atspi_text_set_selection (AtspiText *obj,
932
                          gint selection_num,
933
                          gint start_offset,
934
                          gint end_offset,
935
                          GError **error)
936
{
937
2
  dbus_int32_t d_selection_num = selection_num, d_start_offset = start_offset, d_end_offset = end_offset;
938
2
  dbus_bool_t retval = FALSE;
939

            
940
2
  g_return_val_if_fail (obj != NULL, FALSE);
941

            
942
2
  _atspi_dbus_call (obj, atspi_interface_text, "SetSelection", error, "iii=>b", d_selection_num, d_start_offset, d_end_offset, &retval);
943

            
944
2
  return retval;
945
}
946

            
947
/**
948
 * atspi_text_scroll_substring_to:
949
 * @obj: a pointer to the #AtspiText object on which to operate.
950
 * @start_offset: a #gint indicating the start of the desired text range.
951
 * @end_offset: a #gint indicating the first character past the desired range.
952
 * @type: a #AtspiScrollType indicating where the object should be placed on the
953
 *        screen.
954
 *
955
 * Scrolls whatever container of the #AtspiText text range so it becomes
956
 * visible on the screen.
957
 *
958
 * Returns: #TRUE if successful, #FALSE otherwise.
959
 **/
960
gboolean
961
atspi_text_scroll_substring_to (AtspiText *obj,
962
                                gint start_offset,
963
                                gint end_offset,
964
                                AtspiScrollType type,
965
                                GError **error)
966
{
967
  dbus_bool_t retval = FALSE;
968

            
969
  g_return_val_if_fail (obj != NULL, FALSE);
970

            
971
  _atspi_dbus_call (obj, atspi_interface_text, "ScrollSubstringTo",
972
                    error, "iiu=>b",
973
                    start_offset, end_offset, type, &retval);
974

            
975
  return retval;
976
}
977

            
978
/**
979
 * atspi_text_scroll_substring_to_point:
980
 * @obj: a pointer to the #AtspiText object on which to operate.
981
 * @start_offset: a #gint indicating the start of the desired text range.
982
 * @end_offset: a #gint indicating the first character past the desired range.
983
 * @coords: a #AtspiCoordType indicating whether the coordinates are relative to
984
 *          the screen, to the window, or to the parent object.
985
 * @x: the x coordinate of the point to reach
986
 * @y: the y coordinate of the point to reach
987
 *
988
 * Scrolls whatever container of the #AtspiText text range so it becomes
989
 * visible on the screen at a given position.
990
 *
991
 * Returns: #TRUE if successful, #FALSE otherwise.
992
 **/
993
gboolean
994
atspi_text_scroll_substring_to_point (AtspiText *obj,
995
                                      gint start_offset,
996
                                      gint end_offset,
997
                                      AtspiCoordType coords,
998
                                      gint x,
999
                                      gint y,
                                      GError **error)
{
  dbus_bool_t retval = FALSE;
  g_return_val_if_fail (obj != NULL, FALSE);
  _atspi_dbus_call (obj, atspi_interface_text, "ScrollSubstringToPoint",
                    error, "iiuii=>b",
                    start_offset, end_offset, coords, x, y, &retval);
  return retval;
}
static void
4
atspi_text_base_init (AtspiText *klass)
{
4
}
GType
23
atspi_text_get_type (void)
{
  static GType type = 0;
23
  if (!type)
    {
      static const GTypeInfo tinfo = {
        sizeof (AtspiText),
        (GBaseInitFunc) atspi_text_base_init,
        (GBaseFinalizeFunc) NULL,
      };
2
      type = g_type_register_static (G_TYPE_INTERFACE, "AtspiText", &tinfo, 0);
    }
23
  return type;
}