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