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