2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001, 2002 Sun Microsystems Inc.,
6 * Copyright 2001, 2002 Ximian, Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
24 /* text.c : implements the Text interface */
29 #include <atk/atktext.h>
30 #include <libspi/text.h>
32 /* Our parent Gtk object type */
33 #define PARENT_TYPE SPI_TYPE_BASE
36 get_text_from_servant (PortableServer_Servant servant)
38 SpiBase *object = SPI_BASE (bonobo_object_from_servant (servant));
40 g_return_val_if_fail (object, NULL);
41 g_return_val_if_fail (ATK_IS_OBJECT(object->gobj), NULL);
42 return ATK_TEXT (object->gobj);
46 impl_getText (PortableServer_Servant servant,
47 const CORBA_long startOffset,
48 const CORBA_long endOffset,
49 CORBA_Environment *ev)
53 AtkText *text = get_text_from_servant (servant);
55 g_return_val_if_fail (text != NULL, CORBA_string_dup (""));
57 txt = atk_text_get_text (text, startOffset, endOffset);
60 rv = CORBA_string_dup (txt);
64 rv = CORBA_string_dup ("");
71 impl_getTextAfterOffset (PortableServer_Servant servant,
72 const CORBA_long offset,
74 Accessibility_TEXT_BOUNDARY_TYPE
75 type, CORBA_long * startOffset,
76 CORBA_long * endOffset,
77 CORBA_Environment *ev)
81 gint intStartOffset, intEndOffset;
82 AtkText *text = get_text_from_servant (servant);
84 g_return_val_if_fail (text != NULL, CORBA_string_dup (""));
86 txt = atk_text_get_text_after_offset (text,
87 offset, (AtkTextBoundary) type,
88 &intStartOffset, &intEndOffset);
89 *startOffset = intStartOffset;
90 *endOffset = intEndOffset;
94 rv = CORBA_string_dup (txt);
98 rv = CORBA_string_dup ("");
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)
114 gint intStartOffset, intEndOffset;
115 AtkText *text = get_text_from_servant (servant);
117 g_return_val_if_fail (text != NULL, CORBA_string_dup (""));
119 txt = atk_text_get_text_at_offset (
121 offset, (AtkTextBoundary) type,
122 &intStartOffset, &intEndOffset);
124 *startOffset = intStartOffset;
125 *endOffset = intEndOffset;
129 rv = CORBA_string_dup (txt);
133 rv = CORBA_string_dup ("");
139 static CORBA_unsigned_long
140 impl_getCharacterAtOffset (PortableServer_Servant servant,
141 const CORBA_long offset,
142 CORBA_Environment *ev)
144 AtkText *text = get_text_from_servant (servant);
146 g_return_val_if_fail (text != NULL, 0);
148 return atk_text_get_character_at_offset (text, 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 offset, (AtkTextBoundary) type,
170 &intStartOffset, &intEndOffset);
172 *startOffset = intStartOffset;
173 *endOffset = 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 atk_text_get_caret_offset (text);
200 _string_from_attribute_set (AtkAttributeSet *set)
202 gchar *attributes, *tmp, *tmp2;
207 attributes = g_strdup ("");
208 cur_attr = (GSList *) set;
211 at = (AtkAttribute *) cur_attr->data;
212 tmp = g_strdup_printf ("%s%s:%s%s",
213 ((GSList *)(set) == cur_attr) ? "" : " ",
215 (cur_attr->next) ? ", " : "");
216 tmp2 = g_strconcat (attributes, tmp, NULL);
220 cur_attr = cur_attr->next;
222 rv = CORBA_string_dup (attributes);
230 impl_getAttributes (PortableServer_Servant servant,
231 const CORBA_long offset,
232 CORBA_long * startOffset,
233 CORBA_long * endOffset,
234 CORBA_Environment *ev)
236 AtkAttributeSet *set;
237 gint intstart_offset, intend_offset;
239 AtkText *text = get_text_from_servant (servant);
241 g_return_val_if_fail (text != NULL, CORBA_string_dup (""));
243 set = atk_text_get_run_attributes (text, offset,
244 &intstart_offset, &intend_offset);
245 *startOffset = intstart_offset;
246 *endOffset = intend_offset;
247 rv = _string_from_attribute_set (set);
248 atk_attribute_set_free (set);
254 impl_getCharacterExtents (PortableServer_Servant servant,
255 const CORBA_long offset, CORBA_long * x,
256 CORBA_long * y, CORBA_long * width,
258 const CORBA_short coordType,
259 CORBA_Environment *ev)
261 AtkText *text = get_text_from_servant (servant);
264 g_return_if_fail (text != NULL);
266 atk_text_get_character_extents (
269 (AtkCoordType) coordType);
278 impl__get_characterCount (PortableServer_Servant servant,
279 CORBA_Environment *ev)
281 AtkText *text = get_text_from_servant (servant);
283 g_return_val_if_fail (text != NULL, 0);
285 return atk_text_get_character_count (text);
290 impl_getOffsetAtPoint (PortableServer_Servant servant,
291 const CORBA_long x, const CORBA_long y,
292 const CORBA_short coordType,
293 CORBA_Environment *ev)
295 AtkText *text = get_text_from_servant (servant);
297 g_return_val_if_fail (text != NULL, -1);
299 return atk_text_get_offset_at_point (text,
301 (AtkCoordType) coordType);
306 impl_getNSelections (PortableServer_Servant servant,
307 CORBA_Environment *ev)
309 AtkText *text = get_text_from_servant (servant);
311 g_return_val_if_fail (text != NULL, 0);
313 return atk_text_get_n_selections (text);
318 impl_getSelection (PortableServer_Servant servant,
319 const CORBA_long selectionNum,
320 CORBA_long * startOffset, CORBA_long * endOffset,
321 CORBA_Environment *ev)
323 AtkText *text = get_text_from_servant (servant);
324 gint intStartOffset, intEndOffset;
326 g_return_if_fail (text != NULL);
328 /* atk_text_get_selection returns gchar* which we discard */
329 g_free (atk_text_get_selection (text, selectionNum,
330 &intStartOffset, &intEndOffset));
332 *startOffset = intStartOffset;
333 *endOffset = intEndOffset;
338 impl_addSelection (PortableServer_Servant servant,
339 const CORBA_long startOffset,
340 const CORBA_long endOffset,
341 CORBA_Environment *ev)
343 AtkText *text = get_text_from_servant (servant);
345 g_return_val_if_fail (text != NULL, FALSE);
347 return atk_text_add_selection (text,
348 startOffset, endOffset);
353 impl_removeSelection (PortableServer_Servant servant,
354 const CORBA_long selectionNum,
355 CORBA_Environment *ev)
357 AtkText *text = get_text_from_servant (servant);
359 g_return_val_if_fail (text != NULL, FALSE);
361 return atk_text_remove_selection (text, selectionNum);
366 impl_setSelection (PortableServer_Servant servant,
367 const CORBA_long selectionNum,
368 const CORBA_long startOffset,
369 const CORBA_long endOffset,
370 CORBA_Environment *ev)
372 AtkText *text = get_text_from_servant (servant);
374 g_return_val_if_fail (text != NULL, FALSE);
376 return atk_text_set_selection (text,
377 selectionNum, startOffset, endOffset);
382 impl_setCaretOffset (PortableServer_Servant servant,
383 const CORBA_long value,
384 CORBA_Environment *ev)
386 AtkText *text = get_text_from_servant (servant);
388 g_return_val_if_fail (text != NULL, FALSE);
390 return atk_text_set_caret_offset (text, value);
394 spi_text_class_init (SpiTextClass *klass)
396 POA_Accessibility_Text__epv *epv = &klass->epv;
398 /* Initialize epv table */
400 epv->getText = impl_getText;
401 epv->getTextAfterOffset = impl_getTextAfterOffset;
402 epv->getCharacterAtOffset = impl_getCharacterAtOffset;
403 epv->getTextAtOffset = impl_getTextAtOffset;
404 epv->getTextBeforeOffset = impl_getTextBeforeOffset;
405 epv->_get_caretOffset = impl__get_caretOffset;
406 epv->getAttributes = impl_getAttributes;
407 epv->getCharacterExtents = impl_getCharacterExtents;
408 epv->_get_characterCount = impl__get_characterCount;
409 epv->getOffsetAtPoint = impl_getOffsetAtPoint;
410 epv->getNSelections = impl_getNSelections;
411 epv->getSelection = impl_getSelection;
412 epv->addSelection = impl_addSelection;
413 epv->removeSelection = impl_removeSelection;
414 epv->setSelection = impl_setSelection;
415 epv->setCaretOffset = impl_setCaretOffset;
419 spi_text_init (SpiText *text)
423 BONOBO_TYPE_FUNC_FULL (SpiText,
429 spi_text_construct (SpiText *text, AtkObject *obj)
431 spi_base_construct (SPI_BASE (text), G_OBJECT(obj));
436 spi_text_interface_new (AtkObject *obj)
440 g_return_val_if_fail (ATK_IS_TEXT (obj), NULL);
442 retval = g_object_new (SPI_TEXT_TYPE, NULL);
444 spi_text_construct (retval, obj);