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