Renamed SpiAccessibleEventListener to (just) SpiEventListener.
[platform/core/uifw/at-spi2-atk.git] / cspi / spi_text.c
1 /**
2  * AccessibleText_ref:
3  * @obj: a pointer to the #AccessibleText object on which to operate.
4  *
5  * Increment the reference count for an #AccessibleText object.
6  *
7  * Returns: (no return code implemented yet).
8  *
9  **/
10 int
11 AccessibleText_ref (AccessibleText *obj)
12 {
13   Accessibility_Text_ref (*obj, &ev);
14   return 0;
15 }
16
17
18
19 /**
20  * AccessibleText_unref:
21  * @obj: a pointer to the #Accessible object on which to operate.
22  *
23  * Decrement the reference count for an #AccessibleText object.
24  *
25  * Returns: (no return code implemented yet).
26  *
27  **/
28 int
29 AccessibleText_unref (AccessibleText *obj)
30 {
31   Accessibility_Text_unref (*obj, &ev);
32   return 0;
33 }
34
35
36 /**
37  * AccessibleText_getCharacterCount:
38  * @obj: a pointer to the #AccessibleText object to query.
39  *
40  * Get the character count of an #AccessibleText object.
41  *
42  * Returns: a long integer indicating the total number of
43  *              characters in the #AccessibleText object.
44  *
45  **/
46 long
47 AccessibleText_getCharacterCount (AccessibleText *obj)
48 {
49   long retval;
50
51   CORBA_exception_init (&ev);
52   retval = (long)
53     Accessibility_Text__get_characterCount (*obj, &ev);
54
55   spi_check_ev (&ev, "SpiAccessibleText_getCharacterCount");
56
57   return retval;
58 }
59
60
61
62 /**
63  * AccessibleText_getText:
64  * @obj: a pointer to the #AccessibleText object to query.
65  * @startOffset: a #long indicating the start of the desired text range.
66  * @endOffset: a #long indicating the first character past the desired range.
67  *
68  * Get a range of text from an #AccessibleText object.  The number of bytes
69  *          in the returned string may exceed endOffset-startOffset, since
70  *          UTF-8 is a variable-width encoding.
71  *
72  * Returns: a text string containing characters from @startOffset
73  *          to @endOffset-1, inclusive, encoded as UTF-8.
74  *
75  **/
76 char *
77 AccessibleText_getText (AccessibleText *obj,
78                         long int startOffset,
79                         long int endOffset)
80 {
81   return (char *)
82     Accessibility_Text_getText (*obj,
83                                 (CORBA_long) startOffset, (CORBA_long) endOffset, &ev);
84 }
85
86 /**
87  * AccessibleText_getCaretOffset:
88  * @obj: a pointer to the #AccessibleText object to query.
89  *
90  * Get the current offset of the text caret in an #AccessibleText object.
91  *
92  * Returns: a long integer indicating the current position of the text caret.
93  *
94  **/
95 long
96 AccessibleText_getCaretOffset (AccessibleText *obj)
97 {
98   return (long)
99     Accessibility_Text__get_caretOffset (*obj, &ev);
100 }
101
102
103 /**
104  * AccessibleText_getAttributes:
105  * @obj: a pointer to the #AccessibleText object to query.
106  * @offset: a long integer indicating the offset from which the attribute
107  *        search is based.
108  * @startOffset: a #long indicating the start of the desired text range.
109  * @endOffset: a #long indicating the first character past the desired range.
110  *
111  * Get the attributes applied to a range of text from an #AccessibleText
112  *          object, and the bounds of the range.
113  *
114  * Returns: a text string describing the attributes occurring within the
115  *          attribute run containing @offset, encoded as UTF-8 and
116  *          delimited by ':'
117  *
118  **/
119 char *
120 AccessibleText_getAttributes (AccessibleText *obj,
121                               long int offset,
122                               long int *startOffset,
123                               long int *endOffset)
124 {
125   CORBA_long retStartOffset, retEndOffset;
126   char *retval; 
127   retval = (char *)
128     Accessibility_Text_getAttributes (*obj,
129                                       (CORBA_long) offset,
130                                       &retStartOffset,
131                                       &retEndOffset,
132                                       &ev);
133   *startOffset = (long) retStartOffset;
134   *endOffset = (long) retEndOffset;
135   return retval;
136 }
137
138
139
140 /**
141  * AccessibleText_setCaretOffset:
142  * @obj: a pointer to the #AccessibleText object on which to operate.
143  * @newOffset: the offset to which the text caret is to be moved.
144  *
145  * Set the text caret position for an #AccessibleText object.
146  *
147  * Returns: #TRUE if successful, #FALSE otherwise.
148  *
149  **/
150 boolean
151 AccessibleText_setCaretOffset (AccessibleText *obj,
152                                long int newOffset)
153 {
154   return (boolean)
155     Accessibility_Text_setCaretOffset (*obj,
156                                        (CORBA_long) newOffset, &ev);
157 }
158
159 /**
160  * AccessibleText_getTextBeforeOffset:
161  * @obj: a pointer to the #AccessibleText object on which to operate.
162  * @offset: a long integer indicating the offset from which the delimiter
163  *        search is based.
164  * @type: an #AccessibleTextBoundaryType indicating whether the desired
165  *       text string is a word, sentence, line, or attribute run.
166  * @startOffset: a pointer to a long integer which is assigned the
167  *       starting offset of the returned string, relative to the
168  *       original #AccessibleText.
169  * @endOffset: a pointer to a long integer which is assigned the
170  *       ending offset of the returned string, relative to the original
171  *       #AccessibleText.
172  *
173  * Get delimited text from an #AccessibleText object which precedes a given
174  *          text offset.
175  *
176  * Returns: a UTF-8 string representing the delimited text, both of whose
177  *          delimiting boundaries are before the current offset, or
178  *          an empty string if no such text exists.
179  *
180  **/
181 char *
182 AccessibleText_getTextBeforeOffset (AccessibleText *obj,
183                                     long int offset,
184                                     AccessibleTextBoundaryType type,
185                                     long int *startOffset,
186                                     long int *endOffset)
187 {
188   char *retval;
189   CORBA_long retStartOffset, retEndOffset;
190   retval = (char *)
191     Accessibility_Text_getTextBeforeOffset (*obj,
192                                            (CORBA_long) offset, (Accessibility_TEXT_BOUNDARY_TYPE) type,
193                                            &retStartOffset, &retEndOffset,
194                                            &ev);
195   *startOffset = (long) retStartOffset;
196   *endOffset = (long) retEndOffset;
197   return retval;
198 }
199
200 /**
201  * AccessibleText_getTextAtOffset:
202  * @obj: a pointer to the #AccessibleText object on which to operate.
203  * @offset: a long integer indicating the offset from which the delimiter
204  *        search is based.
205  * @type: an #AccessibleTextBoundaryType indicating whether the desired
206  *       text string is a word, sentence, line, or attribute run.
207  * @startOffset: a pointer to a long integer which is assigned the
208  *       starting offset of the returned string, relative to the
209  *       original #AccessibleText.
210  * @endOffset: a pointer to a long integer which is assigned the
211  *       ending offset of the returned string, relative to the original
212  *       #AccessibleText.
213  *
214  * Get delimited text from an #AccessibleText object which includes a given
215  *          text offset.
216  *
217  * Returns: a UTF-8 string representing the delimited text, whose
218  *          delimiting boundaries bracket the current offset, or
219  *          an empty string if no such text exists.
220  *
221  **/
222 char *
223 AccessibleText_getTextAtOffset (AccessibleText *obj,
224                                 long int offset,
225                                 AccessibleTextBoundaryType type,
226                                 long int *startOffset, long int *endOffset)
227 {
228   CORBA_long corbaStartOffset;
229   CORBA_long corbaEndOffset;
230   char *retval = "";
231   retval = Accessibility_Text_getTextAtOffset (*obj,
232                                                (CORBA_long) offset,
233                                                (Accessibility_TEXT_BOUNDARY_TYPE) type,
234                                                &corbaStartOffset,
235                                                &corbaEndOffset,
236                                                &ev);
237   *startOffset = (long) corbaStartOffset;
238   *endOffset = (long) corbaEndOffset;
239 #ifdef SPI_DEBUG
240   fprintf (stderr, "text offsets %ld to %ld\n", *startOffset, *endOffset);
241 #endif
242   return retval;
243 }
244
245
246 /**
247  * AccessibleText_getTextAfterOffset:
248  * @obj: a pointer to the #AccessibleText object on which to operate.
249  * @offset: a long integer indicating the offset from which the delimiter
250  *        search is based.
251  * @type: an #AccessibleTextBoundaryType indicating whether the desired
252  *       text string is a word, sentence, line, or attribute run.
253  * @startOffset: a pointer to a long integer which is assigned the
254  *       starting offset of the returned string, relative to the
255  *       original #AccessibleText.
256  * @endOffset: a pointer to a long integer which is assigned the
257  *       ending offset of the returned string, relative to the original
258  *       #AccessibleText.
259  *
260  * Get delimited text from an #AccessibleText object which follows a given
261  *          text offset.
262  *
263  * Returns: a UTF-8 string representing the delimited text, both of whose
264  *          delimiting boundaries are after or inclusive of the current
265  *          offset, or an empty string if no such text exists.
266  *
267  **/
268 char *
269 AccessibleText_getTextAfterOffset (AccessibleText *obj,
270                                    long int offset,
271                                    AccessibleTextBoundaryType type,
272                                    long int *startOffset, long int *endOffset)
273 {
274   char *retval;
275   CORBA_long retStartOffset, retEndOffset;
276   retval = (char *)
277     Accessibility_Text_getTextAfterOffset (*obj,
278                                            (CORBA_long) offset, (Accessibility_TEXT_BOUNDARY_TYPE) type,
279                                            &retStartOffset, &retEndOffset,
280                                            &ev);
281   *startOffset = (long) retStartOffset;
282   *endOffset = (long) retEndOffset;
283   return retval;
284 }
285
286
287
288 /**
289  * AccessibleText_getCharacterAtOffset:
290  * @obj: a pointer to the #AccessibleText object on which to operate.
291  * @offset: a long integer indicating the text offset where the desired
292  *          character is located.
293  *
294  * Get the character at a given offset for an #AccessibleText object.
295  *
296  * Returns: an #unsigned long integer which represents the
297  *        UCS-4 unicode code point of the given character, or
298  *        0xFFFFFFFF if the character in question cannot be represented
299  *        in the UCS-4 encoding.
300  *
301  **/
302 unsigned long
303 AccessibleText_getCharacterAtOffset (AccessibleText *obj,
304                                      long int offset)
305 {
306   return (unsigned long)
307     Accessibility_Text_getCharacterAtOffset (*obj,
308                                              (CORBA_long) offset, &ev);
309 }
310
311 /**
312  * AccessibleText_getCharacterExtents:
313  * @obj: a pointer to the #AccessibleText object on which to operate.
314  * @offset: an integer indicating the offset of the text character for
315  *        whom boundary information is requested.
316  * @x: a pointer to a long integer into which the nominal x coordinate
317  *     of the corresponding glyph will be returned.
318  * @y:a pointer to a long integer into which the nominal y coordinate
319  *     of the corresponding glyph will be returned.
320  * @width:a pointer to a long integer into which the width
321  *     of the corresponding glyph will be returned.
322  * @height: a pointer to a long integer into which the height
323  *     of the corresponding glyph will be returned.
324  * @type: an #AccessibleCoordType indicating the coordinate system to use
325  *        for the returned values.
326  *
327  * Get the bounding box containing the glyph representing
328  *        the character at a particular text offset.
329  *
330  **/
331 void
332 AccessibleText_getCharacterExtents (AccessibleText *obj,
333                                     long int offset,
334                                     long int *x,
335                                     long int *y,
336                                     long int *width,
337                                     long int *height,
338                                     AccessibleCoordType type)
339 {
340   CORBA_long retX, retY, retWidth, retHeight;
341   Accessibility_Text_getCharacterExtents (*obj,
342                                           (CORBA_long) offset,
343                                           &retX,
344                                           &retY,
345                                           &retWidth,
346                                           &retHeight,
347                                           (CORBA_short) type, &ev);
348   *x = (long) retX;
349   *y = (long) retY;
350   *width = (long) retWidth;
351   *height = (long) retHeight;
352 }
353
354
355 /**
356  * AccessibleText_getOffsetAtPoint:
357  * @obj: a pointer to the #AccessibleText object on which to operate.
358  * @x: the x coordinate of the point to be queried.
359  * @y: the y coordinate of the point to be queried.
360  * @type: an #AccessibleCoordType indicating the coordinate system in which
361  *       the values should be returned.
362  *
363  * Get the bounding box for a glyph at a certain #AccessibleText offset.
364  *
365  * Returns: the offset (as a long integer) at the point (@x, @y)
366  *       in the specified coordinate system.
367  *
368  **/
369 long
370 AccessibleText_getOffsetAtPoint (AccessibleText *obj,
371                                  long int x,
372                                  long int y,
373                                  AccessibleCoordType type)
374 {
375   return (long)
376     Accessibility_Text_getOffsetAtPoint (*obj,
377                                          (CORBA_long) x, (CORBA_long) y, (CORBA_short) type, &ev);
378 }
379
380
381 /**
382  * AccessibleText_getNSelections:
383  * @obj: a pointer to the #AccessibleText object on which to operate.
384  *
385  * Get the number of active non-contiguous selections for an
386  *          #AccessibleText object.
387  *
388  * Returns: a long integer indicating the current
389  *          number of non-contiguous text selections active
390  *          within an #AccessibleText object.
391  *
392  **/
393 long
394 AccessibleText_getNSelections (AccessibleText *obj)
395 {
396   return (long)
397     Accessibility_Text_getNSelections (*obj, &ev);
398 }
399
400
401
402 /**
403  * AccessibleText_getSelection:
404  * @obj: a pointer to the #AccessibleText object on which to operate.
405  * @selectionNum: an integer indicating which selection to query.
406  * @startOffset: a pointer to a long integer into which the start offset
407  *           of the selection will be returned.
408  * @endOffset: a pointer to a long integer into which the start offset
409  *           of the selection will be returned.
410  *
411  * Get the bounds of the @selectionNum-th active text selection for an
412  *         #AccessibleText object.
413  *
414  **/
415 void
416 AccessibleText_getSelection (AccessibleText *obj,
417                              long int selectionNum,
418                              long int *startOffset,
419                              long int *endOffset)
420 {
421   CORBA_long retStartOffset, retEndOffset;
422   Accessibility_Text_getSelection (*obj,
423                                    (CORBA_long) selectionNum,
424                                    &retStartOffset, &retEndOffset, &ev);
425   
426   *startOffset = (long) retStartOffset;
427   *endOffset = (long) retEndOffset;
428 }
429
430
431
432 /**
433  * AccessibleText_addSelection:
434  * @obj: a pointer to the #AccessibleText object on which to operate.
435  * @startOffset: the starting offset of the desired new selection.
436  * @endOffset: the offset of the first character after the new selection.
437  *
438  * Select some text (add a text selection) in an #AccessibleText object.
439  *
440  * Returns: #TRUE if successful, #FALSE otherwise.
441  *
442  **/
443 boolean
444 AccessibleText_addSelection (AccessibleText *obj,
445                              long int startOffset, long int endOffset)
446 {
447   return (boolean)
448     Accessibility_Text_addSelection (*obj,
449                                      (CORBA_long) startOffset, (CORBA_long) endOffset,
450                                      &ev);
451 }
452
453
454 /**
455  * AccessibleText_removeSelection:
456  * @obj: a pointer to the #AccessibleText object on which to operate.
457  * @selectionNum: an integer indicating which (possibly of several)
458  *         text selection to remove.
459  *
460  * De-select a text selection.
461  *
462  * Returns: #TRUE if successful, #FALSE otherwise.
463  *
464  **/
465 boolean
466 AccessibleText_removeSelection (AccessibleText *obj,
467                                 long int selectionNum)
468 {
469   return (boolean)
470     Accessibility_Text_removeSelection (*obj,
471                                         (CORBA_long) selectionNum, &ev);
472 }
473
474 /**
475  * AccessibleText_setSelection:
476  * @obj: a pointer to the #AccessibleText object on which to operate.
477  * @selectionNum: a zero-offset index indicating which text selection to modify.
478  * @startOffset: a long int, the new starting offset for the selection.
479  * @endOffset: a long int, the desired new offset of the first character
480  *             after the selection.
481  *
482  * Change the bounds of an existing #AccessibleText text selection.
483  *
484  * Returns: #TRUE if successful, #FALSE otherwise.
485  *
486  **/
487 boolean
488 AccessibleText_setSelection (AccessibleText *obj,
489                              long int selectionNum,
490                              long int startOffset,
491                              long int endOffset)
492 {
493   return (boolean)
494     Accessibility_Text_setSelection (*obj,
495                                      (CORBA_long) selectionNum,
496                                      (CORBA_long) startOffset,
497                                      (CORBA_long) endOffset, &ev);
498 }
499
500
501