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));
44 return ATK_TEXT (object->atko);
48 impl_getText (PortableServer_Servant servant,
49 const CORBA_long startOffset,
50 const CORBA_long endOffset,
51 CORBA_Environment *ev)
55 AtkText *text = get_text_from_servant (servant);
57 g_return_val_if_fail (text != NULL, CORBA_string_dup (""));
59 txt = atk_text_get_text (text, (gint) startOffset, (gint) endOffset);
62 rv = CORBA_string_dup (txt);
66 rv = CORBA_string_dup ("");
73 impl_getTextAfterOffset (PortableServer_Servant servant,
74 const CORBA_long offset,
76 Accessibility_TEXT_BOUNDARY_TYPE
77 type, CORBA_long * startOffset,
78 CORBA_long * endOffset,
79 CORBA_Environment *ev)
83 gint intStartOffset, intEndOffset;
84 AtkText *text = get_text_from_servant (servant);
86 g_return_val_if_fail (text != NULL, CORBA_string_dup (""));
88 txt = atk_text_get_text_after_offset (text,
89 (gint) offset, (AtkTextBoundary) type,
90 &intStartOffset, &intEndOffset);
91 *startOffset = (CORBA_long) intStartOffset;
92 *endOffset = (CORBA_long) intEndOffset;
96 rv = CORBA_string_dup (txt);
100 rv = CORBA_string_dup ("");
107 impl_getTextAtOffset (PortableServer_Servant servant,
108 const CORBA_long offset,
109 const Accessibility_TEXT_BOUNDARY_TYPE type,
110 CORBA_long * startOffset,
111 CORBA_long * endOffset,
112 CORBA_Environment *ev)
116 gint intStartOffset, intEndOffset;
117 AtkText *text = get_text_from_servant (servant);
119 g_return_val_if_fail (text != NULL, CORBA_string_dup (""));
121 txt = (CORBA_char *) atk_text_get_text_at_offset (
123 (gint) offset, (AtkTextBoundary) type,
124 &intStartOffset, &intEndOffset);
126 *startOffset = (CORBA_long) intStartOffset;
127 *endOffset = (CORBA_long) intEndOffset;
131 rv = CORBA_string_dup (txt);
135 rv = CORBA_string_dup ("");
141 static CORBA_unsigned_long
142 impl_getCharacterAtOffset (PortableServer_Servant servant,
143 const CORBA_long offset,
144 CORBA_Environment *ev)
146 AtkText *text = get_text_from_servant (servant);
148 g_return_val_if_fail (text != NULL, 0);
150 return (CORBA_unsigned_long)
151 atk_text_get_character_at_offset (text, (gint) offset);
156 impl_getTextBeforeOffset (PortableServer_Servant servant,
157 const CORBA_long offset,
159 Accessibility_TEXT_BOUNDARY_TYPE
160 type, CORBA_long * startOffset,
161 CORBA_long * endOffset,
162 CORBA_Environment *ev)
166 gint intStartOffset, intEndOffset;
167 AtkText *text = get_text_from_servant (servant);
169 g_return_val_if_fail (text != NULL, CORBA_string_dup (""));
171 txt = atk_text_get_text_before_offset (text,
172 (gint) offset, (AtkTextBoundary) type,
173 &intStartOffset, &intEndOffset);
175 *startOffset = (CORBA_long) intStartOffset;
176 *endOffset = (CORBA_long) intEndOffset;
180 rv = CORBA_string_dup (txt);
184 rv = CORBA_string_dup ("");
191 impl__get_caretOffset (PortableServer_Servant servant,
192 CORBA_Environment *ev)
194 AtkText *text = get_text_from_servant (servant);
196 g_return_val_if_fail (text != NULL, -1);
198 return (CORBA_long) atk_text_get_caret_offset (text);
203 impl_getAttributes (PortableServer_Servant servant,
204 const CORBA_long offset,
205 CORBA_long * startOffset,
206 CORBA_long * endOffset,
207 CORBA_Environment *ev)
209 AtkText *text = get_text_from_servant (servant);
211 g_return_val_if_fail (text != NULL, CORBA_string_dup (""));
213 g_print ("getAttributes not yet implemented.\n");
215 return CORBA_string_dup ("");
220 impl_getCharacterExtents (PortableServer_Servant servant,
221 const CORBA_long offset, CORBA_long * x,
222 CORBA_long * y, CORBA_long * width,
224 const CORBA_short coordType,
225 CORBA_Environment *ev)
227 AtkText *text = get_text_from_servant (servant);
229 g_return_if_fail (text != NULL);
231 /* FIXME: Casting a CORBA_long to a gint * is inherantly risky */
232 atk_text_get_character_extents (
234 (gint *) x, (gint *) y, (gint *) width, (gint *) height,
235 (AtkCoordType) coordType);
240 impl__get_characterCount (PortableServer_Servant servant,
241 CORBA_Environment *ev)
244 AtkText *text = get_text_from_servant (servant);
246 g_return_val_if_fail (text != NULL, 0);
248 retval = (CORBA_long) atk_text_get_character_count (text);
255 impl_getOffsetAtPoint (PortableServer_Servant servant,
256 const CORBA_long x, const CORBA_long y,
257 const CORBA_short coordType,
258 CORBA_Environment *ev)
260 AtkText *text = get_text_from_servant (servant);
262 g_return_val_if_fail (text != NULL, -1);
265 atk_text_get_offset_at_point (text,
267 (AtkCoordType) coordType);
272 impl_getNSelections (PortableServer_Servant servant,
273 CORBA_Environment *ev)
275 AtkText *text = get_text_from_servant (servant);
277 g_return_val_if_fail (text != NULL, 0);
279 return (CORBA_long) atk_text_get_n_selections (text);
284 impl_getSelection (PortableServer_Servant servant,
285 const CORBA_long selectionNum,
286 CORBA_long * startOffset, CORBA_long * endOffset,
287 CORBA_Environment *ev)
289 AtkText *text = get_text_from_servant (servant);
291 g_return_if_fail (text != NULL);
293 atk_text_get_selection (text, (gint) selectionNum,
294 (gint *) startOffset, (gint *) endOffset);
299 impl_addSelection (PortableServer_Servant servant,
300 const CORBA_long startOffset,
301 const CORBA_long endOffset,
302 CORBA_Environment *ev)
304 AtkText *text = get_text_from_servant (servant);
306 g_return_val_if_fail (text != NULL, FALSE);
308 return (CORBA_boolean)
309 atk_text_add_selection (text,
310 (gint) startOffset, (gint) endOffset);
315 impl_removeSelection (PortableServer_Servant servant,
316 const CORBA_long selectionNum,
317 CORBA_Environment *ev)
319 AtkText *text = get_text_from_servant (servant);
321 g_return_val_if_fail (text != NULL, FALSE);
323 return (CORBA_boolean)
324 atk_text_remove_selection (text, (gint) selectionNum);
329 impl_setSelection (PortableServer_Servant servant,
330 const CORBA_long selectionNum,
331 const CORBA_long startOffset,
332 const CORBA_long endOffset,
333 CORBA_Environment *ev)
335 AtkText *text = get_text_from_servant (servant);
337 g_return_val_if_fail (text != NULL, FALSE);
339 return (CORBA_boolean)
340 atk_text_set_selection (text,
341 (gint) selectionNum, (gint) startOffset, (gint) endOffset);
346 impl_setCaretOffset (PortableServer_Servant servant,
347 const CORBA_long value,
348 CORBA_Environment *ev)
350 AtkText *text = get_text_from_servant (servant);
352 g_return_val_if_fail (text != NULL, FALSE);
354 return (CORBA_boolean)
355 atk_text_set_caret_offset (text, (gint) value);
360 impl_getRowColAtOffset (PortableServer_Servant servant,
361 const CORBA_long offset, CORBA_long * row,
362 CORBA_long * column, CORBA_Environment *ev)
364 AtkText *text = get_text_from_servant (servant);
366 g_return_if_fail (text != NULL);
368 g_print ("getRowColAtOffset not yet implemented\n");
372 spi_text_class_init (SpiTextClass *klass)
374 POA_Accessibility_Text__epv *epv = &klass->epv;
376 /* Initialize epv table */
378 epv->getText = impl_getText;
379 epv->getTextAfterOffset = impl_getTextAfterOffset;
380 epv->getCharacterAtOffset = impl_getCharacterAtOffset;
381 epv->getTextAtOffset = impl_getTextAtOffset;
382 epv->getTextBeforeOffset = impl_getTextBeforeOffset;
383 epv->_get_caretOffset = impl__get_caretOffset;
384 epv->getAttributes = impl_getAttributes;
385 epv->getCharacterExtents = impl_getCharacterExtents;
386 epv->_get_characterCount = impl__get_characterCount;
387 epv->getOffsetAtPoint = impl_getOffsetAtPoint;
388 epv->getNSelections = impl_getNSelections;
389 epv->getSelection = impl_getSelection;
390 epv->addSelection = impl_addSelection;
391 epv->removeSelection = impl_removeSelection;
392 epv->setSelection = impl_setSelection;
393 epv->setCaretOffset = impl_setCaretOffset;
397 spi_text_init (SpiText *text)
401 BONOBO_TYPE_FUNC_FULL (SpiText,
407 spi_text_construct (SpiText *text, AtkObject *obj)
409 spi_base_construct (SPI_BASE (text), obj);
413 spi_text_interface_new (AtkObject *obj)
417 g_return_val_if_fail (ATK_IS_TEXT (obj), NULL);
419 retval = g_object_new (SPI_TEXT_TYPE, NULL);
421 spi_text_construct (retval, obj);