2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001 Sun Microsystems Inc.
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.
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.
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.
23 /* text.c : implements the Text interface */
28 #include <libspi/text.h>
30 /* Our parent Gtk object type */
31 #define PARENT_TYPE BONOBO_TYPE_OBJECT
33 /* A pointer to our parent object class */
34 static GObjectClass *spi_text_parent_class;
36 /* Static function declarations */
39 accessibility_text_class_init (SpiTextClass *klass);
42 accessibility_text_init (SpiText *text);
45 accessibility_text_object_finalize (GObject *obj);
48 impl_getText (PortableServer_Servant _servant,
49 const CORBA_long startOffset,
50 const CORBA_long endOffset,
51 CORBA_Environment * ev);
54 impl_getTextAfterOffset (PortableServer_Servant _servant,
55 const CORBA_long offset,
57 Accessibility_TEXT_BOUNDARY_TYPE
58 type, CORBA_long * startOffset,
59 CORBA_long * endOffset,
60 CORBA_Environment * ev);
62 impl_getTextAtOffset (PortableServer_Servant _servant,
63 const CORBA_long offset,
64 const Accessibility_TEXT_BOUNDARY_TYPE type,
65 CORBA_long * startOffset,
66 CORBA_long * endOffset,
67 CORBA_Environment * ev);
69 static CORBA_unsigned_long
70 impl_getCharacterAtOffset (PortableServer_Servant _servant,
71 const CORBA_long offset,
72 CORBA_Environment * ev);
75 impl_getTextBeforeOffset (PortableServer_Servant _servant,
76 const CORBA_long offset,
78 Accessibility_TEXT_BOUNDARY_TYPE
79 type, CORBA_long * startOffset,
80 CORBA_long * endOffset,
81 CORBA_Environment * ev);
84 impl__get_caretOffset (PortableServer_Servant _servant,
85 CORBA_Environment * ev);
88 impl_getAttributes (PortableServer_Servant _servant,
89 const CORBA_long offset,
90 CORBA_long * startOffset,
91 CORBA_long * endOffset,
92 CORBA_Environment * ev);
95 impl_getCharacterExtents (PortableServer_Servant _servant,
96 const CORBA_long offset, CORBA_long * x,
97 CORBA_long * y, CORBA_long * width,
99 const CORBA_short coordType,
100 CORBA_Environment * ev);
103 impl__get_characterCount (PortableServer_Servant _servant,
104 CORBA_Environment * ev);
107 impl_getOffsetAtPoint (PortableServer_Servant _servant,
108 const CORBA_long x, const CORBA_long y,
109 const CORBA_short coordType,
110 CORBA_Environment * ev);
113 impl_getNSelections (PortableServer_Servant _servant,
114 CORBA_Environment * ev);
117 impl_getSelection (PortableServer_Servant _servant,
118 const CORBA_long selectionNum,
119 CORBA_long * startOffset, CORBA_long * endOffset,
120 CORBA_Environment * ev);
123 impl_addSelection (PortableServer_Servant _servant,
124 const CORBA_long startOffset,
125 const CORBA_long endOffset,
126 CORBA_Environment * ev);
129 impl_removeSelection (PortableServer_Servant _servant,
130 const CORBA_long selectionNum,
131 CORBA_Environment * ev);
134 impl_setSelection (PortableServer_Servant _servant,
135 const CORBA_long selectionNum,
136 const CORBA_long startOffset,
137 const CORBA_long endOffset,
138 CORBA_Environment * ev);
141 impl_setCaretOffset (PortableServer_Servant _servant,
142 const CORBA_long value,
143 CORBA_Environment * ev);
146 accessibility_text_get_type (void)
148 static GType type = 0;
151 static const GTypeInfo tinfo = {
152 sizeof (SpiTextClass),
153 (GBaseInitFunc) NULL,
154 (GBaseFinalizeFunc) NULL,
155 (GClassInitFunc) accessibility_text_class_init,
156 (GClassFinalizeFunc) NULL,
157 NULL, /* class data */
160 (GInstanceInitFunc) accessibility_text_init,
161 NULL /* value table */
165 * Bonobo_type_unique auto-generates a load of
166 * CORBA structures for us. All derived types must
167 * use bonobo_type_unique.
169 type = bonobo_type_unique (
171 POA_Accessibility_Text__init,
173 G_STRUCT_OFFSET (SpiTextClass, epv),
175 "SpiAccessibleText");
182 accessibility_text_class_init (SpiTextClass *klass)
184 GObjectClass * object_class = (GObjectClass *) klass;
185 POA_Accessibility_Text__epv *epv = &klass->epv;
186 spi_text_parent_class = g_type_class_peek_parent (klass);
188 object_class->finalize = accessibility_text_object_finalize;
190 /* Initialize epv table */
192 epv->getText = impl_getText;
193 epv->getTextAfterOffset = impl_getTextAfterOffset;
194 epv->getCharacterAtOffset = impl_getCharacterAtOffset;
195 epv->getTextAtOffset = impl_getTextAtOffset;
196 epv->getTextBeforeOffset = impl_getTextBeforeOffset;
197 epv->_get_caretOffset = impl__get_caretOffset;
198 epv->getAttributes = impl_getAttributes;
199 epv->getCharacterExtents = impl_getCharacterExtents;
200 epv->_get_characterCount = impl__get_characterCount;
201 epv->getOffsetAtPoint = impl_getOffsetAtPoint;
202 epv->getNSelections = impl_getNSelections;
203 epv->getSelection = impl_getSelection;
204 epv->addSelection = impl_addSelection;
205 epv->removeSelection = impl_removeSelection;
206 epv->setSelection = impl_setSelection;
207 epv->setCaretOffset = impl_setCaretOffset;
211 accessibility_text_init (SpiText *text)
216 accessibility_text_object_finalize (GObject *obj)
218 SpiText *text = SPI_TEXT (obj);
219 g_object_unref (text->atko);
221 spi_text_parent_class->finalize (obj);
225 spi_text_interface_new (AtkObject *obj)
228 SPI_TEXT (g_object_new (accessibility_text_get_type (), NULL));
229 new_text->atko = obj;
237 impl_getText (PortableServer_Servant _servant,
238 const CORBA_long startOffset,
239 const CORBA_long endOffset,
240 CORBA_Environment * ev)
247 obj = (bonobo_object_from_servant (_servant));
248 g_return_val_if_fail (IS_TEXT (obj), (CORBA_char *)"");
249 text = SPI_TEXT (obj);
250 g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_char *)"");
252 txt = atk_text_get_text (ATK_TEXT(text->atko),
253 (gint) startOffset, (gint) endOffset);
256 rv = CORBA_string_dup (txt);
260 rv = CORBA_string_dup ("");
267 impl_getTextAfterOffset (PortableServer_Servant _servant,
268 const CORBA_long offset,
270 Accessibility_TEXT_BOUNDARY_TYPE
271 type, CORBA_long * startOffset,
272 CORBA_long * endOffset,
273 CORBA_Environment * ev)
278 gint intStartOffset, intEndOffset;
281 obj = (bonobo_object_from_servant (_servant));
282 g_return_val_if_fail (IS_TEXT (obj), (CORBA_char *)"");
283 text = SPI_TEXT (obj);
284 g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_char *)"");
286 txt = atk_text_get_text_after_offset (ATK_TEXT(text->atko),
287 (gint) offset, (AtkTextBoundary) type,
288 &intStartOffset, &intEndOffset);
289 *startOffset = (CORBA_long) intStartOffset;
290 *endOffset = (CORBA_long) intEndOffset;
294 rv = CORBA_string_dup (txt);
298 rv = CORBA_string_dup ("");
305 impl_getTextAtOffset (PortableServer_Servant _servant,
306 const CORBA_long offset,
307 const Accessibility_TEXT_BOUNDARY_TYPE type,
308 CORBA_long * startOffset,
309 CORBA_long * endOffset,
310 CORBA_Environment * ev)
315 gint intStartOffset, intEndOffset;
318 obj = (bonobo_object_from_servant (_servant));
319 g_return_val_if_fail (IS_TEXT (obj), (CORBA_char *)"");
320 text = SPI_TEXT (obj);
321 g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_char *)"");
323 txt = (CORBA_char *) atk_text_get_text_at_offset (ATK_TEXT (text->atko),
324 (gint) offset, (AtkTextBoundary) type,
325 &intStartOffset, &intEndOffset);
326 *startOffset = (CORBA_long) intStartOffset;
327 *endOffset = (CORBA_long) intEndOffset;
331 rv = CORBA_string_dup (txt);
335 rv = CORBA_string_dup ("");
341 static CORBA_unsigned_long
342 impl_getCharacterAtOffset (PortableServer_Servant _servant,
343 const CORBA_long offset,
344 CORBA_Environment * ev)
348 obj = (bonobo_object_from_servant (_servant));
350 g_return_val_if_fail (IS_TEXT (obj), (CORBA_unsigned_long)0);
351 text = SPI_TEXT (obj);
352 g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_unsigned_long)0);
354 return (CORBA_unsigned_long)
355 atk_text_get_character_at_offset (ATK_TEXT(text->atko), (gint) offset);
360 impl_getTextBeforeOffset (PortableServer_Servant _servant,
361 const CORBA_long offset,
363 Accessibility_TEXT_BOUNDARY_TYPE
364 type, CORBA_long * startOffset,
365 CORBA_long * endOffset,
366 CORBA_Environment * ev)
371 gint intStartOffset, intEndOffset;
374 obj = (bonobo_object_from_servant (_servant));
375 g_return_val_if_fail (IS_TEXT (obj), (CORBA_char *)"");
376 text = SPI_TEXT (obj);
377 g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_char *)"");
379 txt = atk_text_get_text_before_offset (ATK_TEXT(text->atko),
380 (gint) offset, (AtkTextBoundary) type,
381 &intStartOffset, &intEndOffset);
382 *startOffset = (CORBA_long) intStartOffset;
383 *endOffset = (CORBA_long) intEndOffset;
387 rv = CORBA_string_dup (txt);
391 rv = CORBA_string_dup ("");
397 impl__get_caretOffset (PortableServer_Servant _servant,
398 CORBA_Environment * ev)
403 obj = (bonobo_object_from_servant (_servant));
404 g_return_val_if_fail (IS_TEXT (obj), (CORBA_long)-1);
405 text = SPI_TEXT (obj);
406 g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_long)-1);
409 atk_text_get_caret_offset (ATK_TEXT(text->atko));
415 impl_getAttributes (PortableServer_Servant _servant,
416 const CORBA_long offset,
417 CORBA_long * startOffset,
418 CORBA_long * endOffset,
419 CORBA_Environment * ev)
424 obj = (bonobo_object_from_servant (_servant));
425 g_return_val_if_fail (IS_TEXT (obj), (CORBA_char *)"");
426 text = SPI_TEXT (obj);
427 g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_char *)"");
429 g_print ("getAttributes not yet implemented.\n");
431 return CORBA_string_dup ("");
435 impl_getCharacterExtents (PortableServer_Servant _servant,
436 const CORBA_long offset, CORBA_long * x,
437 CORBA_long * y, CORBA_long * width,
439 const CORBA_short coordType,
440 CORBA_Environment * ev)
445 obj = (bonobo_object_from_servant (_servant));
446 g_return_if_fail (IS_TEXT (obj));
447 text = SPI_TEXT (obj);
448 g_return_if_fail (ATK_IS_TEXT (text->atko));
450 atk_text_get_character_extents (ATK_TEXT(text->atko), (gint) offset,
451 (gint *) x, (gint *) y, (gint *) width, (gint *) height,
452 (AtkCoordType) coordType);
458 impl__get_characterCount (PortableServer_Servant _servant,
459 CORBA_Environment * ev)
465 obj = (bonobo_object_from_servant (_servant));
466 g_return_val_if_fail (IS_TEXT (obj), (CORBA_long)0);
467 text = SPI_TEXT (obj);
469 retval = (CORBA_long)
470 atk_text_get_character_count (ATK_TEXT(text->atko));
478 impl_getOffsetAtPoint (PortableServer_Servant _servant,
479 const CORBA_long x, const CORBA_long y,
480 const CORBA_short coordType,
481 CORBA_Environment * ev)
486 obj = (bonobo_object_from_servant (_servant));
487 g_return_val_if_fail (IS_TEXT (obj), (CORBA_long)-1);
488 text = SPI_TEXT (obj);
491 atk_text_get_offset_at_point (ATK_TEXT(text->atko),
492 (gint) x, (gint) y, (AtkCoordType) coordType);
498 impl_getNSelections (PortableServer_Servant _servant,
499 CORBA_Environment * ev)
504 obj = (bonobo_object_from_servant (_servant));
505 g_return_val_if_fail (IS_TEXT (obj), (CORBA_long)0);
506 text = SPI_TEXT (obj);
509 atk_text_get_n_selections (ATK_TEXT(text->atko));
515 impl_getSelection (PortableServer_Servant _servant,
516 const CORBA_long selectionNum,
517 CORBA_long * startOffset, CORBA_long * endOffset,
518 CORBA_Environment * ev)
523 obj = (bonobo_object_from_servant (_servant));
524 g_return_if_fail (IS_TEXT (obj));
525 text = SPI_TEXT (obj);
527 atk_text_get_selection (ATK_TEXT(text->atko), (gint) selectionNum,
528 (gint *) startOffset, (gint *) endOffset);
534 impl_addSelection (PortableServer_Servant _servant,
535 const CORBA_long startOffset,
536 const CORBA_long endOffset,
537 CORBA_Environment * ev)
542 obj = (bonobo_object_from_servant (_servant));
543 g_return_val_if_fail (IS_TEXT (obj), (CORBA_boolean)FALSE);
544 text = SPI_TEXT (obj);
546 return (CORBA_boolean)
547 atk_text_add_selection (ATK_TEXT(text->atko),
548 (gint) startOffset, (gint) endOffset);
554 impl_removeSelection (PortableServer_Servant _servant,
555 const CORBA_long selectionNum,
556 CORBA_Environment * ev)
561 obj = (bonobo_object_from_servant (_servant));
562 g_return_val_if_fail (IS_TEXT (obj), (CORBA_boolean)FALSE);
563 text = SPI_TEXT (obj);
565 return (CORBA_boolean)
566 atk_text_remove_selection (ATK_TEXT(text->atko), (gint) selectionNum);
572 impl_setSelection (PortableServer_Servant _servant,
573 const CORBA_long selectionNum,
574 const CORBA_long startOffset,
575 const CORBA_long endOffset,
576 CORBA_Environment * ev)
581 obj = (bonobo_object_from_servant (_servant));
582 g_return_val_if_fail (IS_TEXT (obj), (CORBA_boolean)FALSE);
583 text = SPI_TEXT (obj);
585 return (CORBA_boolean)
586 atk_text_set_selection (ATK_TEXT(text->atko),
587 (gint) selectionNum, (gint) startOffset, (gint) endOffset);
593 impl_setCaretOffset (PortableServer_Servant _servant,
594 const CORBA_long value,
595 CORBA_Environment * ev)
600 obj = (bonobo_object_from_servant (_servant));
601 g_return_val_if_fail (IS_TEXT (obj), (CORBA_boolean)FALSE);
602 text = SPI_TEXT (obj);
604 return (CORBA_boolean)
605 atk_text_set_caret_offset (ATK_TEXT(text->atko), (gint) value);
611 impl_getRowColAtOffset (PortableServer_Servant _servant,
612 const CORBA_long offset, CORBA_long * row,
613 CORBA_long * column, CORBA_Environment * ev)
618 obj = (bonobo_object_from_servant (_servant));
619 g_return_if_fail (IS_TEXT (obj));
620 text = SPI_TEXT (obj);
622 g_print ("getRowColAtOffset not yet implemented\n");