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.
24 * component.c : bonobo wrapper for accessible component implementation
28 #include <bonobo/Bonobo.h>
34 * This pulls the CORBA definitions for the "Accessibility::Accessible" server
36 #include <libspi/Accessibility.h>
39 * This pulls the definition of the SpiText bonobo object
44 * Our parent Gtk object type
46 #define PARENT_TYPE BONOBO_OBJECT_TYPE
50 * A pointer to our parent object class
52 static GObjectClass *spi_text_parent_class;
55 * Static function declarations
59 accessibility_text_class_init (SpiTextClass *klass);
62 accessibility_text_init (SpiText *text);
65 accessibility_text_object_finalize (GObject *obj);
68 impl_getText (PortableServer_Servant _servant,
69 const CORBA_long startOffset,
70 const CORBA_long endOffset,
71 CORBA_Environment * ev);
74 impl_getTextAfterOffset (PortableServer_Servant _servant,
75 const CORBA_long offset,
77 Accessibility_TEXT_BOUNDARY_TYPE
78 type, CORBA_long * startOffset,
79 CORBA_long * endOffset,
80 CORBA_Environment * ev);
82 impl_getTextAtOffset (PortableServer_Servant _servant,
83 const CORBA_long offset,
84 const Accessibility_TEXT_BOUNDARY_TYPE type,
85 CORBA_long * startOffset,
86 CORBA_long * endOffset,
87 CORBA_Environment * ev);
89 static CORBA_unsigned_long
90 impl_getCharacterAtOffset (PortableServer_Servant _servant,
91 const CORBA_long offset,
92 CORBA_Environment * ev);
95 impl_getTextBeforeOffset (PortableServer_Servant _servant,
96 const CORBA_long offset,
98 Accessibility_TEXT_BOUNDARY_TYPE
99 type, CORBA_long * startOffset,
100 CORBA_long * endOffset,
101 CORBA_Environment * ev);
104 impl__get_caretOffset (PortableServer_Servant _servant,
105 CORBA_Environment * ev);
108 impl_getAttributes (PortableServer_Servant _servant,
109 const CORBA_long offset,
110 CORBA_long * startOffset,
111 CORBA_long * endOffset,
112 CORBA_Environment * ev);
115 impl_getCharacterExtents (PortableServer_Servant _servant,
116 const CORBA_long offset, CORBA_long * x,
117 CORBA_long * y, CORBA_long * width,
119 const CORBA_short coordType,
120 CORBA_Environment * ev);
123 impl__get_characterCount (PortableServer_Servant _servant,
124 CORBA_Environment * ev);
127 impl_getOffsetAtPoint (PortableServer_Servant _servant,
128 const CORBA_long x, const CORBA_long y,
129 const CORBA_short coordType,
130 CORBA_Environment * ev);
133 impl_getNSelections (PortableServer_Servant _servant,
134 CORBA_Environment * ev);
137 impl_getSelection (PortableServer_Servant _servant,
138 const CORBA_long selectionNum,
139 CORBA_long * startOffset, CORBA_long * endOffset,
140 CORBA_Environment * ev);
143 impl_addSelection (PortableServer_Servant _servant,
144 const CORBA_long startOffset,
145 const CORBA_long endOffset,
146 CORBA_Environment * ev);
149 impl_removeSelection (PortableServer_Servant _servant,
150 const CORBA_long selectionNum,
151 CORBA_Environment * ev);
154 impl_setSelection (PortableServer_Servant _servant,
155 const CORBA_long selectionNum,
156 const CORBA_long startOffset,
157 const CORBA_long endOffset,
158 CORBA_Environment * ev);
161 impl_setCaretOffset (PortableServer_Servant _servant,
162 const CORBA_long value,
163 CORBA_Environment * ev);
166 accessibility_text_get_type (void)
168 static GType type = 0;
171 static const GTypeInfo tinfo = {
172 sizeof (SpiTextClass),
173 (GBaseInitFunc) NULL,
174 (GBaseFinalizeFunc) NULL,
175 (GClassInitFunc) accessibility_text_class_init,
176 (GClassFinalizeFunc) NULL,
177 NULL, /* class data */
180 (GInstanceInitFunc) accessibility_text_init,
181 NULL /* value table */
185 * Bonobo_type_unique auto-generates a load of
186 * CORBA structures for us. All derived types must
187 * use bonobo_type_unique.
189 type = bonobo_type_unique (
191 POA_Accessibility_Text__init,
193 G_STRUCT_OFFSET (SpiTextClass, epv),
195 "SpiAccessibleText");
202 accessibility_text_class_init (SpiTextClass *klass)
204 GObjectClass * object_class = (GObjectClass *) klass;
205 POA_Accessibility_Text__epv *epv = &klass->epv;
206 spi_text_parent_class = g_type_class_peek_parent (klass);
208 object_class->finalize = accessibility_text_object_finalize;
210 /* Initialize epv table */
212 epv->getText = impl_getText;
213 epv->getTextAfterOffset = impl_getTextAfterOffset;
214 epv->getCharacterAtOffset = impl_getCharacterAtOffset;
215 epv->getTextAtOffset = impl_getTextAtOffset;
216 epv->getTextBeforeOffset = impl_getTextBeforeOffset;
217 epv->_get_caretOffset = impl__get_caretOffset;
218 epv->getAttributes = impl_getAttributes;
219 epv->getCharacterExtents = impl_getCharacterExtents;
220 epv->_get_characterCount = impl__get_characterCount;
221 epv->getOffsetAtPoint = impl_getOffsetAtPoint;
222 epv->getNSelections = impl_getNSelections;
223 epv->getSelection = impl_getSelection;
224 epv->addSelection = impl_addSelection;
225 epv->removeSelection = impl_removeSelection;
226 epv->setSelection = impl_setSelection;
227 epv->setCaretOffset = impl_setCaretOffset;
231 accessibility_text_init (SpiText *text)
236 accessibility_text_object_finalize (GObject *obj)
238 SpiText *text = SPI_TEXT (obj);
239 g_object_unref (text->atko);
241 spi_text_parent_class->finalize (obj);
245 spi_text_interface_new (AtkObject *obj)
248 SPI_TEXT (g_object_new (accessibility_text_get_type (), NULL));
249 new_text->atko = obj;
257 impl_getText (PortableServer_Servant _servant,
258 const CORBA_long startOffset,
259 const CORBA_long endOffset,
260 CORBA_Environment * ev)
267 obj = (bonobo_object_from_servant (_servant));
268 g_return_val_if_fail (IS_TEXT (obj), (CORBA_char *)"");
269 text = SPI_TEXT (obj);
270 g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_char *)"");
272 txt = atk_text_get_text (ATK_TEXT(text->atko),
273 (gint) startOffset, (gint) endOffset);
276 rv = CORBA_string_dup (txt);
280 rv = CORBA_string_dup ("");
287 impl_getTextAfterOffset (PortableServer_Servant _servant,
288 const CORBA_long offset,
290 Accessibility_TEXT_BOUNDARY_TYPE
291 type, CORBA_long * startOffset,
292 CORBA_long * endOffset,
293 CORBA_Environment * ev)
298 gint intStartOffset, intEndOffset;
301 obj = (bonobo_object_from_servant (_servant));
302 g_return_val_if_fail (IS_TEXT (obj), (CORBA_char *)"");
303 text = SPI_TEXT (obj);
304 g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_char *)"");
306 txt = atk_text_get_text_after_offset (ATK_TEXT(text->atko),
307 (gint) offset, (AtkTextBoundary) type,
308 &intStartOffset, &intEndOffset);
309 *startOffset = (CORBA_long) intStartOffset;
310 *endOffset = (CORBA_long) intEndOffset;
314 rv = CORBA_string_dup (txt);
318 rv = CORBA_string_dup ("");
325 impl_getTextAtOffset (PortableServer_Servant _servant,
326 const CORBA_long offset,
327 const Accessibility_TEXT_BOUNDARY_TYPE type,
328 CORBA_long * startOffset,
329 CORBA_long * endOffset,
330 CORBA_Environment * ev)
335 gint intStartOffset, intEndOffset;
338 obj = (bonobo_object_from_servant (_servant));
339 g_return_val_if_fail (IS_TEXT (obj), (CORBA_char *)"");
340 text = SPI_TEXT (obj);
341 g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_char *)"");
343 txt = (CORBA_char *) atk_text_get_text_at_offset (ATK_TEXT (text->atko),
344 (gint) offset, (AtkTextBoundary) type,
345 &intStartOffset, &intEndOffset);
346 *startOffset = (CORBA_long) intStartOffset;
347 *endOffset = (CORBA_long) intEndOffset;
351 rv = CORBA_string_dup (txt);
355 rv = CORBA_string_dup ("");
361 static CORBA_unsigned_long
362 impl_getCharacterAtOffset (PortableServer_Servant _servant,
363 const CORBA_long offset,
364 CORBA_Environment * ev)
368 obj = (bonobo_object_from_servant (_servant));
370 g_return_val_if_fail (IS_TEXT (obj), (CORBA_unsigned_long)0);
371 text = SPI_TEXT (obj);
372 g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_unsigned_long)0);
374 return (CORBA_unsigned_long)
375 atk_text_get_character_at_offset (ATK_TEXT(text->atko), (gint) offset);
380 impl_getTextBeforeOffset (PortableServer_Servant _servant,
381 const CORBA_long offset,
383 Accessibility_TEXT_BOUNDARY_TYPE
384 type, CORBA_long * startOffset,
385 CORBA_long * endOffset,
386 CORBA_Environment * ev)
391 gint intStartOffset, intEndOffset;
394 obj = (bonobo_object_from_servant (_servant));
395 g_return_val_if_fail (IS_TEXT (obj), (CORBA_char *)"");
396 text = SPI_TEXT (obj);
397 g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_char *)"");
399 txt = atk_text_get_text_before_offset (ATK_TEXT(text->atko),
400 (gint) offset, (AtkTextBoundary) type,
401 &intStartOffset, &intEndOffset);
402 *startOffset = (CORBA_long) intStartOffset;
403 *endOffset = (CORBA_long) intEndOffset;
407 rv = CORBA_string_dup (txt);
411 rv = CORBA_string_dup ("");
417 impl__get_caretOffset (PortableServer_Servant _servant,
418 CORBA_Environment * ev)
423 obj = (bonobo_object_from_servant (_servant));
424 g_return_val_if_fail (IS_TEXT (obj), (CORBA_long)-1);
425 text = SPI_TEXT (obj);
426 g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_long)-1);
429 atk_text_get_caret_offset (ATK_TEXT(text->atko));
435 impl_getAttributes (PortableServer_Servant _servant,
436 const CORBA_long offset,
437 CORBA_long * startOffset,
438 CORBA_long * endOffset,
439 CORBA_Environment * ev)
444 obj = (bonobo_object_from_servant (_servant));
445 g_return_val_if_fail (IS_TEXT (obj), (CORBA_char *)"");
446 text = SPI_TEXT (obj);
447 g_return_val_if_fail (ATK_IS_TEXT (text->atko), (CORBA_char *)"");
449 g_print ("getAttributes not yet implemented.\n");
453 impl_getCharacterExtents (PortableServer_Servant _servant,
454 const CORBA_long offset, CORBA_long * x,
455 CORBA_long * y, CORBA_long * width,
457 const CORBA_short coordType,
458 CORBA_Environment * ev)
463 obj = (bonobo_object_from_servant (_servant));
464 g_return_if_fail (IS_TEXT (obj));
465 text = SPI_TEXT (obj);
466 g_return_if_fail (ATK_IS_TEXT (text->atko));
468 atk_text_get_character_extents (ATK_TEXT(text->atko), (gint) offset,
469 (gint *) x, (gint *) y, (gint *) width, (gint *) height,
470 (AtkCoordType) coordType);
476 impl__get_characterCount (PortableServer_Servant _servant,
477 CORBA_Environment * ev)
483 obj = (bonobo_object_from_servant (_servant));
484 g_return_val_if_fail (IS_TEXT (obj), (CORBA_long)0);
485 text = SPI_TEXT (obj);
487 retval = (CORBA_long)
488 atk_text_get_character_count (ATK_TEXT(text->atko));
496 impl_getOffsetAtPoint (PortableServer_Servant _servant,
497 const CORBA_long x, const CORBA_long y,
498 const CORBA_short coordType,
499 CORBA_Environment * ev)
504 obj = (bonobo_object_from_servant (_servant));
505 g_return_val_if_fail (IS_TEXT (obj), (CORBA_long)-1);
506 text = SPI_TEXT (obj);
509 atk_text_get_offset_at_point (ATK_TEXT(text->atko),
510 (gint) x, (gint) y, (AtkCoordType) coordType);
516 impl_getNSelections (PortableServer_Servant _servant,
517 CORBA_Environment * ev)
522 obj = (bonobo_object_from_servant (_servant));
523 g_return_val_if_fail (IS_TEXT (obj), (CORBA_long)0);
524 text = SPI_TEXT (obj);
527 atk_text_get_n_selections (ATK_TEXT(text->atko));
533 impl_getSelection (PortableServer_Servant _servant,
534 const CORBA_long selectionNum,
535 CORBA_long * startOffset, CORBA_long * endOffset,
536 CORBA_Environment * ev)
541 obj = (bonobo_object_from_servant (_servant));
542 g_return_if_fail (IS_TEXT (obj));
543 text = SPI_TEXT (obj);
545 atk_text_get_selection (ATK_TEXT(text->atko), (gint) selectionNum,
546 (gint *) startOffset, (gint *) endOffset);
552 impl_addSelection (PortableServer_Servant _servant,
553 const CORBA_long startOffset,
554 const CORBA_long endOffset,
555 CORBA_Environment * ev)
560 obj = (bonobo_object_from_servant (_servant));
561 g_return_val_if_fail (IS_TEXT (obj), (CORBA_boolean)FALSE);
562 text = SPI_TEXT (obj);
564 return (CORBA_boolean)
565 atk_text_add_selection (ATK_TEXT(text->atko),
566 (gint) startOffset, (gint) endOffset);
572 impl_removeSelection (PortableServer_Servant _servant,
573 const CORBA_long selectionNum,
574 CORBA_Environment * ev)
579 obj = (bonobo_object_from_servant (_servant));
580 g_return_val_if_fail (IS_TEXT (obj), (CORBA_boolean)FALSE);
581 text = SPI_TEXT (obj);
583 return (CORBA_boolean)
584 atk_text_remove_selection (ATK_TEXT(text->atko), (gint) selectionNum);
590 impl_setSelection (PortableServer_Servant _servant,
591 const CORBA_long selectionNum,
592 const CORBA_long startOffset,
593 const CORBA_long endOffset,
594 CORBA_Environment * ev)
599 obj = (bonobo_object_from_servant (_servant));
600 g_return_val_if_fail (IS_TEXT (obj), (CORBA_boolean)FALSE);
601 text = SPI_TEXT (obj);
603 return (CORBA_boolean)
604 atk_text_set_selection (ATK_TEXT(text->atko),
605 (gint) selectionNum, (gint) startOffset, (gint) endOffset);
611 impl_setCaretOffset (PortableServer_Servant _servant,
612 const CORBA_long value,
613 CORBA_Environment * ev)
618 obj = (bonobo_object_from_servant (_servant));
619 g_return_val_if_fail (IS_TEXT (obj), (CORBA_boolean)FALSE);
620 text = SPI_TEXT (obj);
622 return (CORBA_boolean)
623 atk_text_set_caret_offset (ATK_TEXT(text->atko), (gint) value);
629 impl_getRowColAtOffset (PortableServer_Servant _servant,
630 const CORBA_long offset, CORBA_long * row,
631 CORBA_long * column, CORBA_Environment * ev)
636 obj = (bonobo_object_from_servant (_servant));
637 g_return_if_fail (IS_TEXT (obj));
638 text = SPI_TEXT (obj);
640 g_print ("getRowColAtOffset not yet implemented\n");