Started fixing IDL docs.
[platform/core/uifw/at-spi2-atk.git] / libspi / text.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2001 Sun Microsystems Inc.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 /* text.c : implements the Text interface */
24
25 #include <config.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <libspi/text.h>
29
30 /* Our parent Gtk object type */
31 #define PARENT_TYPE BONOBO_TYPE_OBJECT
32
33 /* A pointer to our parent object class */
34 static GObjectClass *spi_text_parent_class;
35
36 static CORBA_string
37 impl_getText (PortableServer_Servant _servant,
38               const CORBA_long startOffset,
39               const CORBA_long endOffset,
40               CORBA_Environment * ev)
41 {
42   SpiText *text;
43   gchar *txt;
44   CORBA_string rv;
45   BonoboObject *obj;
46   
47   obj = (bonobo_object_from_servant (_servant));
48   g_return_val_if_fail (IS_TEXT (obj), (CORBA_char *)"");
49   text = SPI_TEXT (obj);
50   g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_char *)"");
51   
52   txt = atk_text_get_text (ATK_TEXT(text->atko),
53                        (gint) startOffset, (gint) endOffset);
54   if (txt)
55     {
56       rv = CORBA_string_dup (txt);
57       g_free (txt);
58     }
59   else
60     rv = CORBA_string_dup ("");
61   return rv;
62 }
63
64
65
66 CORBA_string
67 impl_getTextAfterOffset (PortableServer_Servant _servant,
68                          const CORBA_long offset,
69                          const
70                          Accessibility_TEXT_BOUNDARY_TYPE
71                          type, CORBA_long * startOffset,
72                          CORBA_long * endOffset,
73                          CORBA_Environment * ev)
74 {
75   SpiText *text;
76   gchar *txt;
77   CORBA_char *rv;
78   gint intStartOffset, intEndOffset;
79   BonoboObject *obj;
80
81   obj = (bonobo_object_from_servant (_servant));
82   g_return_val_if_fail (IS_TEXT (obj), (CORBA_char *)"");
83   text = SPI_TEXT (obj);
84   g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_char *)"");
85   
86   txt = atk_text_get_text_after_offset (ATK_TEXT(text->atko),
87                                     (gint) offset, (AtkTextBoundary) type,
88                                     &intStartOffset, &intEndOffset);
89   *startOffset = (CORBA_long) intStartOffset;
90   *endOffset = (CORBA_long) intEndOffset;
91
92   if (txt)
93     {
94       rv = CORBA_string_dup (txt);
95       g_free (txt);
96       }
97   else
98     rv = CORBA_string_dup ("");
99   return rv;
100 }
101
102
103
104 static CORBA_string
105 impl_getTextAtOffset (PortableServer_Servant _servant,
106                       const CORBA_long offset,
107                       const Accessibility_TEXT_BOUNDARY_TYPE type,
108                       CORBA_long * startOffset,
109                       CORBA_long * endOffset,
110                       CORBA_Environment * ev)
111 {
112   SpiText *text;
113   CORBA_char *txt;
114   CORBA_char *rv;
115   gint intStartOffset, intEndOffset;
116   BonoboObject *obj;
117
118   obj = (bonobo_object_from_servant (_servant));
119   g_return_val_if_fail (IS_TEXT (obj), (CORBA_char *)"");
120   text = SPI_TEXT (obj);
121   g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_char *)"");
122
123   txt = (CORBA_char *) atk_text_get_text_at_offset (ATK_TEXT (text->atko),
124                                     (gint) offset, (AtkTextBoundary) type,
125                                     &intStartOffset, &intEndOffset);
126   *startOffset = (CORBA_long) intStartOffset;
127   *endOffset = (CORBA_long) intEndOffset;
128
129   if (txt)
130     {
131       rv = CORBA_string_dup (txt);
132       g_free (txt);
133     }
134   else
135     rv = CORBA_string_dup ("");
136
137   return rv;
138 }
139
140
141 static CORBA_unsigned_long
142 impl_getCharacterAtOffset (PortableServer_Servant _servant,
143                            const CORBA_long offset,
144                            CORBA_Environment * ev)
145 {
146   SpiText *text;
147   BonoboObject *obj;
148   obj = (bonobo_object_from_servant (_servant));
149   
150   g_return_val_if_fail (IS_TEXT (obj), (CORBA_unsigned_long)0);
151   text = SPI_TEXT (obj);
152   g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_unsigned_long)0);
153
154   return (CORBA_unsigned_long)
155     atk_text_get_character_at_offset (ATK_TEXT(text->atko), (gint) offset);
156 }
157
158
159 static CORBA_string
160 impl_getTextBeforeOffset (PortableServer_Servant _servant,
161                           const CORBA_long offset,
162                           const
163                           Accessibility_TEXT_BOUNDARY_TYPE
164                           type, CORBA_long * startOffset,
165                           CORBA_long * endOffset,
166                           CORBA_Environment * ev)
167 {
168   SpiText *text;
169   gchar *txt;
170   CORBA_char *rv;
171   gint intStartOffset, intEndOffset;
172   BonoboObject *obj;
173
174   obj = (bonobo_object_from_servant (_servant));
175   g_return_val_if_fail (IS_TEXT (obj), (CORBA_char *)"");
176   text = SPI_TEXT (obj);
177   g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_char *)"");
178
179   txt = atk_text_get_text_before_offset (ATK_TEXT(text->atko),
180                                     (gint) offset, (AtkTextBoundary) type,
181                                     &intStartOffset, &intEndOffset);
182   *startOffset = (CORBA_long) intStartOffset;
183   *endOffset = (CORBA_long) intEndOffset;
184
185   if (txt)
186     {
187       rv = CORBA_string_dup (txt);
188       g_free (txt);
189     }
190   else
191     rv = CORBA_string_dup ("");
192   return rv;
193 }
194
195
196 static CORBA_long
197 impl__get_caretOffset (PortableServer_Servant _servant,
198                      CORBA_Environment * ev)
199 {
200   SpiText *text;
201   BonoboObject *obj;
202
203   obj = (bonobo_object_from_servant (_servant));
204   g_return_val_if_fail (IS_TEXT (obj), (CORBA_long)-1);
205   text = SPI_TEXT (obj);
206   g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_long)-1);
207   
208   return (CORBA_long)
209     atk_text_get_caret_offset (ATK_TEXT(text->atko));
210 }
211
212
213
214 static CORBA_string
215 impl_getAttributes (PortableServer_Servant _servant,
216                        const CORBA_long offset,
217                        CORBA_long * startOffset,
218                        CORBA_long * endOffset,
219                        CORBA_Environment * ev)
220 {
221   SpiText *text;
222   BonoboObject *obj;
223
224   obj = (bonobo_object_from_servant (_servant));
225   g_return_val_if_fail (IS_TEXT (obj), (CORBA_char *)"");
226   text = SPI_TEXT (obj);
227   g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_char *)"");
228
229   g_print ("getAttributes not yet implemented.\n");
230
231   return CORBA_string_dup ("");
232 }
233
234 static void 
235 impl_getCharacterExtents (PortableServer_Servant _servant,
236                           const CORBA_long offset, CORBA_long * x,
237                           CORBA_long * y, CORBA_long * width,
238                           CORBA_long * height,
239                           const CORBA_short coordType,
240                           CORBA_Environment * ev)
241 {
242   SpiText *text;
243   BonoboObject *obj;
244
245   obj = (bonobo_object_from_servant (_servant));
246   g_return_if_fail (IS_TEXT (obj));
247   text = SPI_TEXT (obj);
248   g_return_if_fail (ATK_IS_TEXT (text->atko));
249
250   atk_text_get_character_extents (ATK_TEXT(text->atko), (gint) offset,
251                                   (gint *) x, (gint *) y, (gint *) width, (gint *) height,
252                                   (AtkCoordType) coordType);
253 }
254
255
256
257 static CORBA_long
258 impl__get_characterCount (PortableServer_Servant _servant,
259                         CORBA_Environment * ev)
260 {
261   SpiText *text;
262   BonoboObject *obj;
263   CORBA_long retval;
264
265   obj = (bonobo_object_from_servant (_servant));
266   g_return_val_if_fail (IS_TEXT (obj), (CORBA_long)0);
267   text = SPI_TEXT (obj);
268
269   retval = (CORBA_long)
270     atk_text_get_character_count (ATK_TEXT(text->atko));
271
272   return retval;
273 }
274
275
276
277 static CORBA_long
278 impl_getOffsetAtPoint (PortableServer_Servant _servant,
279                        const CORBA_long x, const CORBA_long y,
280                        const CORBA_short coordType,
281                        CORBA_Environment * ev)
282 {
283   SpiText *text;
284   BonoboObject *obj;
285
286   obj = (bonobo_object_from_servant (_servant));
287   g_return_val_if_fail (IS_TEXT (obj), (CORBA_long)-1);
288   text = SPI_TEXT (obj);
289
290   return (CORBA_long)
291     atk_text_get_offset_at_point (ATK_TEXT(text->atko),
292                                   (gint) x, (gint) y, (AtkCoordType) coordType);
293 }
294
295
296
297 static CORBA_long
298 impl_getNSelections (PortableServer_Servant _servant,
299                      CORBA_Environment * ev)
300 {
301   SpiText *text;
302   BonoboObject *obj;
303
304   obj = (bonobo_object_from_servant (_servant));
305   g_return_val_if_fail (IS_TEXT (obj), (CORBA_long)0);
306   text = SPI_TEXT (obj);
307
308   return (CORBA_long)
309     atk_text_get_n_selections (ATK_TEXT(text->atko));
310 }
311
312
313
314 static void 
315 impl_getSelection (PortableServer_Servant _servant,
316                    const CORBA_long selectionNum,
317                    CORBA_long * startOffset, CORBA_long * endOffset,
318                    CORBA_Environment * ev)
319 {
320   SpiText *text;
321   BonoboObject *obj;
322
323   obj = (bonobo_object_from_servant (_servant));
324   g_return_if_fail (IS_TEXT (obj));
325   text = SPI_TEXT (obj);
326
327   atk_text_get_selection (ATK_TEXT(text->atko), (gint) selectionNum,
328                           (gint *) startOffset, (gint *) endOffset);
329 }
330
331
332
333 static CORBA_boolean
334 impl_addSelection (PortableServer_Servant _servant,
335                    const CORBA_long startOffset,
336                    const CORBA_long endOffset,
337                    CORBA_Environment * ev)
338 {
339   SpiText *text;
340   BonoboObject *obj;
341
342   obj = (bonobo_object_from_servant (_servant));
343   g_return_val_if_fail (IS_TEXT (obj), (CORBA_boolean)FALSE);
344   text = SPI_TEXT (obj);
345
346   return (CORBA_boolean)
347     atk_text_add_selection (ATK_TEXT(text->atko),
348                             (gint) startOffset, (gint) endOffset);
349 }
350
351
352
353 static CORBA_boolean
354 impl_removeSelection (PortableServer_Servant _servant,
355                       const CORBA_long selectionNum,
356                       CORBA_Environment * ev)
357 {
358   SpiText *text;
359   BonoboObject *obj;
360
361   obj = (bonobo_object_from_servant (_servant));
362   g_return_val_if_fail (IS_TEXT (obj), (CORBA_boolean)FALSE);
363   text = SPI_TEXT (obj);
364
365   return (CORBA_boolean)
366     atk_text_remove_selection (ATK_TEXT(text->atko), (gint) selectionNum);
367 }
368
369
370
371 static CORBA_boolean
372 impl_setSelection (PortableServer_Servant _servant,
373                    const CORBA_long selectionNum,
374                    const CORBA_long startOffset,
375                    const CORBA_long endOffset,
376                    CORBA_Environment * ev)
377 {
378   SpiText *text;
379   BonoboObject *obj;
380
381   obj = (bonobo_object_from_servant (_servant));
382   g_return_val_if_fail (IS_TEXT (obj), (CORBA_boolean)FALSE);
383   text = SPI_TEXT (obj);
384
385   return (CORBA_boolean)
386     atk_text_set_selection (ATK_TEXT(text->atko),
387                             (gint) selectionNum, (gint) startOffset, (gint) endOffset);
388 }
389
390
391
392 static CORBA_boolean
393 impl_setCaretOffset (PortableServer_Servant _servant,
394                      const CORBA_long value,
395                      CORBA_Environment * ev)
396 {
397   SpiText *text;
398   BonoboObject *obj;
399
400   obj = (bonobo_object_from_servant (_servant));
401   g_return_val_if_fail (IS_TEXT (obj), (CORBA_boolean)FALSE);
402   text = SPI_TEXT (obj);
403
404   return (CORBA_boolean)
405     atk_text_set_caret_offset (ATK_TEXT(text->atko), (gint) value);
406 }
407
408
409
410 static void 
411 impl_getRowColAtOffset (PortableServer_Servant _servant,
412                         const CORBA_long offset, CORBA_long * row,
413                         CORBA_long * column, CORBA_Environment * ev)
414 {
415   SpiText *text;
416   BonoboObject *obj;
417
418   obj = (bonobo_object_from_servant (_servant));
419   g_return_if_fail (IS_TEXT (obj));
420   text = SPI_TEXT (obj);
421
422   g_print ("getRowColAtOffset not yet implemented\n");
423 }
424
425 static void
426 spi_text_object_finalize (GObject *obj)
427 {
428   SpiText *text = SPI_TEXT (obj);
429   g_object_unref (text->atko);
430   text->atko = NULL;
431   spi_text_parent_class->finalize (obj);
432 }
433
434 static void
435 spi_text_class_init (SpiTextClass *klass)
436 {
437   GObjectClass * object_class = (GObjectClass *) klass;
438   POA_Accessibility_Text__epv *epv = &klass->epv;
439   spi_text_parent_class = g_type_class_peek_parent (klass);
440
441   object_class->finalize = spi_text_object_finalize;
442
443   /* Initialize epv table */
444
445   epv->getText = impl_getText;
446   epv->getTextAfterOffset = impl_getTextAfterOffset;
447   epv->getCharacterAtOffset = impl_getCharacterAtOffset;
448   epv->getTextAtOffset = impl_getTextAtOffset;
449   epv->getTextBeforeOffset = impl_getTextBeforeOffset;
450   epv->_get_caretOffset = impl__get_caretOffset;
451   epv->getAttributes = impl_getAttributes;
452   epv->getCharacterExtents = impl_getCharacterExtents;
453   epv->_get_characterCount = impl__get_characterCount;
454   epv->getOffsetAtPoint = impl_getOffsetAtPoint;
455   epv->getNSelections = impl_getNSelections;
456   epv->getSelection = impl_getSelection;
457   epv->addSelection = impl_addSelection;
458   epv->removeSelection = impl_removeSelection;
459   epv->setSelection = impl_setSelection;
460   epv->setCaretOffset = impl_setCaretOffset;
461 }
462
463 static void
464 spi_text_init (SpiText *text)
465 {
466 }
467
468 BONOBO_TYPE_FUNC_FULL (SpiText,
469                        Accessibility_Text,
470                        PARENT_TYPE,
471                        spi_text);
472
473 SpiText *
474 spi_text_interface_new (AtkObject *obj)
475 {
476   SpiText *new_text = g_object_new (SPI_TEXT_TYPE, NULL);
477   new_text->atko = obj;
478   g_object_ref (obj);
479   return new_text;
480 }