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, startOffset, 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 offset, (AtkTextBoundary) type,
87 &intStartOffset, &intEndOffset);
88 *startOffset = intStartOffset;
89 *endOffset = 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 = atk_text_get_text_at_offset (
120 offset, (AtkTextBoundary) type,
121 &intStartOffset, &intEndOffset);
123 *startOffset = intStartOffset;
124 *endOffset = 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 atk_text_get_character_at_offset (text, offset);
152 impl_getTextBeforeOffset (PortableServer_Servant servant,
153 const CORBA_long offset,
155 Accessibility_TEXT_BOUNDARY_TYPE
156 type, CORBA_long * startOffset,
157 CORBA_long * endOffset,
158 CORBA_Environment *ev)
162 gint intStartOffset, intEndOffset;
163 AtkText *text = get_text_from_servant (servant);
165 g_return_val_if_fail (text != NULL, CORBA_string_dup (""));
167 txt = atk_text_get_text_before_offset (text,
168 offset, (AtkTextBoundary) type,
169 &intStartOffset, &intEndOffset);
171 *startOffset = intStartOffset;
172 *endOffset = intEndOffset;
176 rv = CORBA_string_dup (txt);
180 rv = CORBA_string_dup ("");
187 impl__get_caretOffset (PortableServer_Servant servant,
188 CORBA_Environment *ev)
190 AtkText *text = get_text_from_servant (servant);
192 g_return_val_if_fail (text != NULL, -1);
194 return atk_text_get_caret_offset (text);
199 _string_from_attribute_set (AtkAttributeSet *set)
201 gchar *attributes, *tmp, *tmp2;
206 attributes = g_strdup ("");
207 cur_attr = (GSList *) set;
210 at = (AtkAttribute *) cur_attr->data;
211 tmp = g_strdup_printf ("%s%s:%s%s",
212 ((GSList *)(set) == cur_attr) ? "" : " ",
214 (cur_attr->next) ? ", " : "");
215 tmp2 = g_strconcat (attributes, tmp, NULL);
219 cur_attr = cur_attr->next;
221 rv = CORBA_string_dup (attributes);
229 impl_getAttributes (PortableServer_Servant servant,
230 const CORBA_long offset,
231 CORBA_long * startOffset,
232 CORBA_long * endOffset,
233 CORBA_Environment *ev)
235 AtkAttributeSet *set;
236 gint intstart_offset, intend_offset;
238 AtkText *text = get_text_from_servant (servant);
240 g_return_val_if_fail (text != NULL, CORBA_string_dup (""));
242 set = atk_text_get_run_attributes (text, offset,
243 &intstart_offset, &intend_offset);
244 *startOffset = intstart_offset;
245 *endOffset = intend_offset;
246 rv = _string_from_attribute_set (set);
247 atk_attribute_set_free (set);
253 impl_getCharacterExtents (PortableServer_Servant servant,
254 const CORBA_long offset, CORBA_long * x,
255 CORBA_long * y, CORBA_long * width,
257 const CORBA_short coordType,
258 CORBA_Environment *ev)
260 AtkText *text = get_text_from_servant (servant);
263 g_return_if_fail (text != NULL);
265 atk_text_get_character_extents (
268 (AtkCoordType) coordType);
277 impl__get_characterCount (PortableServer_Servant servant,
278 CORBA_Environment *ev)
280 AtkText *text = get_text_from_servant (servant);
282 g_return_val_if_fail (text != NULL, 0);
284 return atk_text_get_character_count (text);
289 impl_getOffsetAtPoint (PortableServer_Servant servant,
290 const CORBA_long x, const CORBA_long y,
291 const CORBA_short coordType,
292 CORBA_Environment *ev)
294 AtkText *text = get_text_from_servant (servant);
296 g_return_val_if_fail (text != NULL, -1);
298 return atk_text_get_offset_at_point (text,
300 (AtkCoordType) coordType);
305 impl_getNSelections (PortableServer_Servant servant,
306 CORBA_Environment *ev)
308 AtkText *text = get_text_from_servant (servant);
310 g_return_val_if_fail (text != NULL, 0);
312 return atk_text_get_n_selections (text);
317 impl_getSelection (PortableServer_Servant servant,
318 const CORBA_long selectionNum,
319 CORBA_long * startOffset, CORBA_long * endOffset,
320 CORBA_Environment *ev)
322 AtkText *text = get_text_from_servant (servant);
323 gint intStartOffset, intEndOffset;
325 g_return_if_fail (text != NULL);
327 atk_text_get_selection (text, selectionNum,
328 &intStartOffset, &intEndOffset);
329 *startOffset = intStartOffset;
330 *endOffset = intEndOffset;
335 impl_addSelection (PortableServer_Servant servant,
336 const CORBA_long startOffset,
337 const CORBA_long endOffset,
338 CORBA_Environment *ev)
340 AtkText *text = get_text_from_servant (servant);
342 g_return_val_if_fail (text != NULL, FALSE);
344 return atk_text_add_selection (text,
345 startOffset, endOffset);
350 impl_removeSelection (PortableServer_Servant servant,
351 const CORBA_long selectionNum,
352 CORBA_Environment *ev)
354 AtkText *text = get_text_from_servant (servant);
356 g_return_val_if_fail (text != NULL, FALSE);
358 return atk_text_remove_selection (text, selectionNum);
363 impl_setSelection (PortableServer_Servant servant,
364 const CORBA_long selectionNum,
365 const CORBA_long startOffset,
366 const CORBA_long endOffset,
367 CORBA_Environment *ev)
369 AtkText *text = get_text_from_servant (servant);
371 g_return_val_if_fail (text != NULL, FALSE);
373 return atk_text_set_selection (text,
374 selectionNum, startOffset, endOffset);
379 impl_setCaretOffset (PortableServer_Servant servant,
380 const CORBA_long value,
381 CORBA_Environment *ev)
383 AtkText *text = get_text_from_servant (servant);
385 g_return_val_if_fail (text != NULL, FALSE);
387 return atk_text_set_caret_offset (text, value);
391 spi_text_class_init (SpiTextClass *klass)
393 POA_Accessibility_Text__epv *epv = &klass->epv;
395 /* Initialize epv table */
397 epv->getText = impl_getText;
398 epv->getTextAfterOffset = impl_getTextAfterOffset;
399 epv->getCharacterAtOffset = impl_getCharacterAtOffset;
400 epv->getTextAtOffset = impl_getTextAtOffset;
401 epv->getTextBeforeOffset = impl_getTextBeforeOffset;
402 epv->_get_caretOffset = impl__get_caretOffset;
403 epv->getAttributes = impl_getAttributes;
404 epv->getCharacterExtents = impl_getCharacterExtents;
405 epv->_get_characterCount = impl__get_characterCount;
406 epv->getOffsetAtPoint = impl_getOffsetAtPoint;
407 epv->getNSelections = impl_getNSelections;
408 epv->getSelection = impl_getSelection;
409 epv->addSelection = impl_addSelection;
410 epv->removeSelection = impl_removeSelection;
411 epv->setSelection = impl_setSelection;
412 epv->setCaretOffset = impl_setCaretOffset;
416 spi_text_init (SpiText *text)
420 BONOBO_TYPE_FUNC_FULL (SpiText,
426 spi_text_construct (SpiText *text, AtkObject *obj)
428 spi_base_construct (SPI_BASE (text), G_OBJECT(obj));
433 spi_text_interface_new (AtkObject *obj)
437 g_return_val_if_fail (ATK_IS_TEXT (obj), NULL);
439 retval = g_object_new (SPI_TEXT_TYPE, NULL);
441 spi_text_construct (retval, obj);