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 <atk/atktext.h>
29 #include <libspi/text.h>
31 /* Our parent Gtk object type */
32 #define PARENT_TYPE SPI_TYPE_BASE
35 get_text_from_servant (PortableServer_Servant servant)
37 SpiBase *object = SPI_BASE (bonobo_object_from_servant (servant));
39 g_return_val_if_fail (object, NULL);
40 g_return_val_if_fail (ATK_IS_OBJECT(object->gobj), NULL);
41 return ATK_TEXT (object->gobj);
45 impl_getText (PortableServer_Servant servant,
46 const CORBA_long startOffset,
47 const CORBA_long endOffset,
48 CORBA_Environment *ev)
52 AtkText *text = get_text_from_servant (servant);
54 g_return_val_if_fail (text != NULL, CORBA_string_dup (""));
56 txt = atk_text_get_text (text, (gint) startOffset, (gint) endOffset);
59 rv = CORBA_string_dup (txt);
63 rv = CORBA_string_dup ("");
70 impl_getTextAfterOffset (PortableServer_Servant servant,
71 const CORBA_long offset,
73 Accessibility_TEXT_BOUNDARY_TYPE
74 type, CORBA_long * startOffset,
75 CORBA_long * endOffset,
76 CORBA_Environment *ev)
80 gint intStartOffset, intEndOffset;
81 AtkText *text = get_text_from_servant (servant);
83 g_return_val_if_fail (text != NULL, CORBA_string_dup (""));
85 txt = atk_text_get_text_after_offset (text,
86 (gint) offset, (AtkTextBoundary) type,
87 &intStartOffset, &intEndOffset);
88 *startOffset = (CORBA_long) intStartOffset;
89 *endOffset = (CORBA_long) intEndOffset;
93 rv = CORBA_string_dup (txt);
97 rv = CORBA_string_dup ("");
104 impl_getTextAtOffset (PortableServer_Servant servant,
105 const CORBA_long offset,
106 const Accessibility_TEXT_BOUNDARY_TYPE type,
107 CORBA_long * startOffset,
108 CORBA_long * endOffset,
109 CORBA_Environment *ev)
113 gint intStartOffset, intEndOffset;
114 AtkText *text = get_text_from_servant (servant);
116 g_return_val_if_fail (text != NULL, CORBA_string_dup (""));
118 txt = (CORBA_char *) atk_text_get_text_at_offset (
120 (gint) offset, (AtkTextBoundary) type,
121 &intStartOffset, &intEndOffset);
123 *startOffset = (CORBA_long) intStartOffset;
124 *endOffset = (CORBA_long) intEndOffset;
128 rv = CORBA_string_dup (txt);
132 rv = CORBA_string_dup ("");
138 static CORBA_unsigned_long
139 impl_getCharacterAtOffset (PortableServer_Servant servant,
140 const CORBA_long offset,
141 CORBA_Environment *ev)
143 AtkText *text = get_text_from_servant (servant);
145 g_return_val_if_fail (text != NULL, 0);
147 return (CORBA_unsigned_long)
148 atk_text_get_character_at_offset (text, (gint) offset);
153 impl_getTextBeforeOffset (PortableServer_Servant servant,
154 const CORBA_long offset,
156 Accessibility_TEXT_BOUNDARY_TYPE
157 type, CORBA_long * startOffset,
158 CORBA_long * endOffset,
159 CORBA_Environment *ev)
163 gint intStartOffset, intEndOffset;
164 AtkText *text = get_text_from_servant (servant);
166 g_return_val_if_fail (text != NULL, CORBA_string_dup (""));
168 txt = atk_text_get_text_before_offset (text,
169 (gint) offset, (AtkTextBoundary) type,
170 &intStartOffset, &intEndOffset);
172 *startOffset = (CORBA_long) intStartOffset;
173 *endOffset = (CORBA_long) intEndOffset;
177 rv = CORBA_string_dup (txt);
181 rv = CORBA_string_dup ("");
188 impl__get_caretOffset (PortableServer_Servant servant,
189 CORBA_Environment *ev)
191 AtkText *text = get_text_from_servant (servant);
193 g_return_val_if_fail (text != NULL, -1);
195 return (CORBA_long) atk_text_get_caret_offset (text);
200 impl_getAttributes (PortableServer_Servant servant,
201 const CORBA_long offset,
202 CORBA_long * startOffset,
203 CORBA_long * endOffset,
204 CORBA_Environment *ev)
206 AtkText *text = get_text_from_servant (servant);
208 g_return_val_if_fail (text != NULL, CORBA_string_dup (""));
210 g_print ("getAttributes not yet implemented.\n");
212 return CORBA_string_dup ("");
217 impl_getCharacterExtents (PortableServer_Servant servant,
218 const CORBA_long offset, CORBA_long * x,
219 CORBA_long * y, CORBA_long * width,
221 const CORBA_short coordType,
222 CORBA_Environment *ev)
224 AtkText *text = get_text_from_servant (servant);
226 g_return_if_fail (text != NULL);
228 /* FIXME: Casting a CORBA_long to a gint * is inherantly risky */
229 atk_text_get_character_extents (
231 (gint *) x, (gint *) y, (gint *) width, (gint *) height,
232 (AtkCoordType) coordType);
237 impl__get_characterCount (PortableServer_Servant servant,
238 CORBA_Environment *ev)
241 AtkText *text = get_text_from_servant (servant);
243 g_return_val_if_fail (text != NULL, 0);
245 retval = (CORBA_long) atk_text_get_character_count (text);
252 impl_getOffsetAtPoint (PortableServer_Servant servant,
253 const CORBA_long x, const CORBA_long y,
254 const CORBA_short coordType,
255 CORBA_Environment *ev)
257 AtkText *text = get_text_from_servant (servant);
259 g_return_val_if_fail (text != NULL, -1);
262 atk_text_get_offset_at_point (text,
264 (AtkCoordType) coordType);
269 impl_getNSelections (PortableServer_Servant servant,
270 CORBA_Environment *ev)
272 AtkText *text = get_text_from_servant (servant);
274 g_return_val_if_fail (text != NULL, 0);
276 return (CORBA_long) atk_text_get_n_selections (text);
281 impl_getSelection (PortableServer_Servant servant,
282 const CORBA_long selectionNum,
283 CORBA_long * startOffset, CORBA_long * endOffset,
284 CORBA_Environment *ev)
286 AtkText *text = get_text_from_servant (servant);
288 g_return_if_fail (text != NULL);
290 atk_text_get_selection (text, (gint) selectionNum,
291 (gint *) startOffset, (gint *) endOffset);
296 impl_addSelection (PortableServer_Servant servant,
297 const CORBA_long startOffset,
298 const CORBA_long endOffset,
299 CORBA_Environment *ev)
301 AtkText *text = get_text_from_servant (servant);
303 g_return_val_if_fail (text != NULL, FALSE);
305 return (CORBA_boolean)
306 atk_text_add_selection (text,
307 (gint) startOffset, (gint) endOffset);
312 impl_removeSelection (PortableServer_Servant servant,
313 const CORBA_long selectionNum,
314 CORBA_Environment *ev)
316 AtkText *text = get_text_from_servant (servant);
318 g_return_val_if_fail (text != NULL, FALSE);
320 return (CORBA_boolean)
321 atk_text_remove_selection (text, (gint) selectionNum);
326 impl_setSelection (PortableServer_Servant servant,
327 const CORBA_long selectionNum,
328 const CORBA_long startOffset,
329 const CORBA_long endOffset,
330 CORBA_Environment *ev)
332 AtkText *text = get_text_from_servant (servant);
334 g_return_val_if_fail (text != NULL, FALSE);
336 return (CORBA_boolean)
337 atk_text_set_selection (text,
338 (gint) selectionNum, (gint) startOffset, (gint) endOffset);
343 impl_setCaretOffset (PortableServer_Servant servant,
344 const CORBA_long value,
345 CORBA_Environment *ev)
347 AtkText *text = get_text_from_servant (servant);
349 g_return_val_if_fail (text != NULL, FALSE);
351 return (CORBA_boolean)
352 atk_text_set_caret_offset (text, (gint) value);
357 impl_getRowColAtOffset (PortableServer_Servant servant,
358 const CORBA_long offset, CORBA_long * row,
359 CORBA_long * column, CORBA_Environment *ev)
361 AtkText *text = get_text_from_servant (servant);
363 g_return_if_fail (text != NULL);
365 g_print ("getRowColAtOffset not yet implemented\n");
369 spi_text_class_init (SpiTextClass *klass)
371 POA_Accessibility_Text__epv *epv = &klass->epv;
373 /* Initialize epv table */
375 epv->getText = impl_getText;
376 epv->getTextAfterOffset = impl_getTextAfterOffset;
377 epv->getCharacterAtOffset = impl_getCharacterAtOffset;
378 epv->getTextAtOffset = impl_getTextAtOffset;
379 epv->getTextBeforeOffset = impl_getTextBeforeOffset;
380 epv->_get_caretOffset = impl__get_caretOffset;
381 epv->getAttributes = impl_getAttributes;
382 epv->getCharacterExtents = impl_getCharacterExtents;
383 epv->_get_characterCount = impl__get_characterCount;
384 epv->getOffsetAtPoint = impl_getOffsetAtPoint;
385 epv->getNSelections = impl_getNSelections;
386 epv->getSelection = impl_getSelection;
387 epv->addSelection = impl_addSelection;
388 epv->removeSelection = impl_removeSelection;
389 epv->setSelection = impl_setSelection;
390 epv->setCaretOffset = impl_setCaretOffset;
394 spi_text_init (SpiText *text)
398 BONOBO_TYPE_FUNC_FULL (SpiText,
404 spi_text_construct (SpiText *text, AtkObject *obj)
406 spi_base_construct (SPI_BASE (text), G_OBJECT(obj));
411 spi_text_interface_new (AtkObject *obj)
415 g_return_val_if_fail (ATK_IS_TEXT (obj), NULL);
417 retval = g_object_new (SPI_TEXT_TYPE, NULL);
419 spi_text_construct (retval, obj);