1 /* ATK - The Accessibility Toolkit for GTK+
2 * Copyright 2001 Sun Microsystems Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 #include "atkmarshal.h"
29 struct _AtkTextIfaceClass
34 typedef struct _AtkTextIfaceClass AtkTextIfaceClass;
36 static void atk_text_base_init (gpointer *g_class);
38 static guint atk_text_signals[LAST_SIGNAL] = { 0 };
43 static GType type = 0;
47 static const GTypeInfo tinfo =
49 sizeof (AtkTextIface),
50 (GBaseInitFunc) atk_text_base_init,
51 (GBaseFinalizeFunc) NULL,
52 (GClassInitFunc) NULL /* atk_text_interface_init */ ,
53 (GClassFinalizeFunc) NULL,
57 type = g_type_register_static (G_TYPE_INTERFACE, "AtkText", &tinfo, 0);
64 atk_text_base_init (gpointer *g_class)
66 static gboolean initialized = FALSE;
71 * Note that text_changed signal supports details "insert", "delete",
75 atk_text_signals[TEXT_CHANGED] =
76 g_signal_newc ("text_changed",
78 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
79 G_STRUCT_OFFSET (AtkTextIface, text_changed),
80 (GSignalAccumulator) NULL, NULL,
81 atk_marshal_VOID__INT_INT,
83 2, G_TYPE_INT, G_TYPE_INT);
85 atk_text_signals[CARET_MOVED] =
86 g_signal_newc ("text_caret_moved",
89 G_STRUCT_OFFSET (AtkTextIface, caret_changed),
90 (GSignalAccumulator) NULL, NULL,
91 g_cclosure_marshal_VOID__INT,
102 * @start_offset: start position
103 * @end_offset: end position
105 * Gets the specified text.
107 * Returns: the text from @start_offset up to, but not including @end_offset.
110 atk_text_get_text (AtkText *text,
116 g_return_val_if_fail (text != NULL, NULL);
117 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
119 iface = ATK_TEXT_GET_IFACE (text);
122 return (*(iface->get_text)) (text, start_offset, end_offset);
128 * atk_text_get_character_at_offset:
132 * Gets the specified text.
134 * Returns: the character at @offset.
137 atk_text_get_character_at_offset (AtkText *text,
142 g_return_val_if_fail (text != NULL, (gunichar) 0);
143 g_return_val_if_fail (ATK_IS_TEXT (text), (gunichar) 0);
145 iface = ATK_TEXT_GET_IFACE (text);
147 if (iface->get_character_at_offset)
148 return (*(iface->get_character_at_offset)) (text, offset);
154 * atk_text_get_text_after_offset:
157 * @boundary_type: An #AtkTextBoundary
158 * @startOffset: the start offset of the returned string.
159 * @endOffset: the end offset of the returned string.
161 * Gets the specified text.
162 * If the boundary type is ATK_TEXT_BOUNDARY_WORD_START or
163 * ATK_TEXT_BOUNDARY_WORD_END part of a word may be returned.
164 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the start point
165 * will be the offset and will continue to the start of the next sentence.
166 * The first word may not be a complete word. Similarly for
167 * ATK_TEXT_BOUNDARY_SENTENCE_END, ATK_TEXT_BOUNDARY_LINE_START and
168 * ATK_TEXT_BOUNDARY_LINE_END
170 * Returns: the text after @offset up to the specified @boundary_type.
173 atk_text_get_text_after_offset (AtkText *text,
175 AtkTextBoundary boundary_type,
181 g_return_val_if_fail (text != NULL, NULL);
182 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
184 iface = ATK_TEXT_GET_IFACE (text);
186 if (iface->get_text_after_offset)
187 return (*(iface->get_text_after_offset)) (text, offset, boundary_type, startOffset, endOffset);
193 * atk_text_get_text_at_offset:
196 * @boundary_type: An #AtkTextBoundary
197 * @startOffset: the start offset of the returned string.
198 * @endOffset: the end offset of the returned string.
200 * Gets the specified text.
201 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START or
202 * ATK_TEXT_BOUNDARY_WORD_END a complete word is returned;
203 * if the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START or
204 * ATK_TEXT_BOUNDARY_SENTENCE_END a complete sentence
205 * is returned; if the boundary type is ATK_TEXT_BOUNDARY_LINE_START or
206 * ATK_TEXT_BOUNDARY_LINE_END a complete line is returned.
208 * Returns: the text at @offset up to the specified @boundary_type.
211 atk_text_get_text_at_offset (AtkText *text,
213 AtkTextBoundary boundary_type,
219 g_return_val_if_fail (text != NULL, NULL);
220 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
222 iface = ATK_TEXT_GET_IFACE (text);
224 if (iface->get_text_at_offset)
225 return (*(iface->get_text_at_offset)) (text, offset, boundary_type, startOffset, endOffset);
231 * atk_text_get_text_before_offset:
234 * @boundary_type: An #AtkTextBoundary
235 * @startOffset: the start offset of the returned string.
236 * @endOffset: the end offset of the returned string.
238 * Gets the specified text.
239 * If the boundary type is ATK_TEXT_BOUNDARY_WORD_START or
240 * ATK_TEXT_BOUNDARY_WORD_END part of a word may be returned.
241 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the start point
242 * will be at the start of the sentence, and will continue to the offset.
243 * The last word may not be a complete word. Similarly for
244 * ATK_TEXT_BOUNDARY_SENTENCE_END, ATK_TEXT_BOUNDARY_LINE_START and
245 * ATK_TEXT_BOUNDARY_LINE_END
247 * Returns: the text before @offset starting from the specified @boundary_type.
250 atk_text_get_text_before_offset (AtkText *text,
252 AtkTextBoundary boundary_type,
258 g_return_val_if_fail (text != NULL, NULL);
259 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
261 iface = ATK_TEXT_GET_IFACE (text);
263 if (iface->get_text_before_offset)
264 return (*(iface->get_text_before_offset)) (text, offset, boundary_type, startOffset, endOffset);
270 * atk_text_get_caret_offset:
273 * Gets the offset position of the caret (cursor).
275 * Returns: the offset position of the caret (cursor).
278 atk_text_get_caret_offset (AtkText *text)
282 g_return_val_if_fail (text != NULL, -1);
283 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
285 iface = ATK_TEXT_GET_IFACE (text);
287 if (iface->get_caret_offset)
288 return (*(iface->get_caret_offset)) (text);
294 * atk_text_get_character_extents:
297 * @x: x-position of character
298 * @y: y-position of character
299 * @length: length of character
300 * @width: width of character
301 * @coords: specify whether coordinates are relative to the screen or widget window
303 * Given an @offset, the @x, @y, @length, and @width values are filled
307 atk_text_get_character_extents (AtkText *text,
317 g_return_if_fail (text != NULL);
318 g_return_if_fail (ATK_IS_TEXT (text));
320 iface = ATK_TEXT_GET_IFACE (text);
322 if (iface->get_character_extents)
323 (*(iface->get_character_extents)) (text, offset, x, y, length, width, coords);
334 *atk_text_ref_run_attributes:
336 *@offset: the offset at which to get the attributes
337 *@start_offset: the address to put the start offset of the range
338 *@end_offset: the address to put the end offset of the range
340 *Creates an #AtkAttributeSet which consists of the attributes explicitly
341 *set at the position @offset in the text. @start_offset and @end_offset are
342 *set to the start and end of the range around @offset where the attributes are
345 *Returns: an #AtkAttributeSet which contains the attributes explicitly set
348 AtkAttributeSet* atk_text_ref_run_attributes (AtkText *text,
355 g_return_val_if_fail (text != NULL, NULL);
356 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
358 iface = ATK_TEXT_GET_IFACE (text);
360 if (iface->ref_run_attributes)
361 return (*(iface->ref_run_attributes)) (text, offset, start_offset, end_offset);
367 * atk_text_get_character_count:
370 * Gets the character count.
372 * Returns: the number of characters.
375 atk_text_get_character_count (AtkText *text)
379 g_return_val_if_fail (text != NULL, -1);
380 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
382 iface = ATK_TEXT_GET_IFACE (text);
384 if (iface->get_character_count)
385 return (*(iface->get_character_count)) (text);
391 * atk_text_get_offset_at_point:
393 * @x: screen x-position of character
394 * @y: screen y-position of character
395 * @coords: specify whether coordinates are relative to the screen or widget window
397 * Gets the offset of the character located at coordinates @x and @y. @x and @y are
398 * interpreted as being relative to the screen or this widget's window depending
401 * Returns: the offset to the character which is located at
402 * the specified @x and @y coordinates.
405 atk_text_get_offset_at_point (AtkText *text,
412 g_return_val_if_fail (text != NULL, -1);
413 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
415 iface = ATK_TEXT_GET_IFACE (text);
417 if (iface->get_offset_at_point)
418 return (*(iface->get_offset_at_point)) (text, x, y, coords);
424 * atk_text_get_n_selections:
427 * Gets the number of selected regions.
429 * Returns: The number of selected regions, or -1 if a failure
433 atk_text_get_n_selections (AtkText *text)
437 g_return_val_if_fail (text != NULL, -1);
438 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
440 iface = ATK_TEXT_GET_IFACE (text);
442 if (iface->get_n_selections)
443 return (*(iface->get_n_selections)) (text);
449 * atk_text_get_selection:
451 * @selection_num: The selection number. The selected regions are
452 * assigned numbers that correspond to how far the region is from the
453 * start of the text. The selected region closest to the beginning
454 * of the text region is assigned the number 0, etc. Note that adding,
455 * moving or deleting a selected region can change the numbering.
456 * @start_offset: passes back the start position of the selected region
457 * @end_offset: passes back the end position of the selected region
459 * Gets the text from the specified selection.
461 * Returns: the selected text.
464 atk_text_get_selection (AtkText *text, gint selection_num,
465 gint *start_offset, gint *end_offset)
469 g_return_val_if_fail (text != NULL, NULL);
470 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
472 iface = ATK_TEXT_GET_IFACE (text);
474 if (iface->get_selection)
476 return (*(iface->get_selection)) (text, selection_num,
477 start_offset, end_offset);
484 * atk_text_add_selection:
486 * @start_offset: the start position of the selected region
487 * @end_offset: the end position of the selected region
489 * Adds a selection bounded by the specified offsets.
491 * Returns: %TRUE if success, %FALSE otherwise
494 atk_text_add_selection (AtkText *text, gint start_offset,
499 g_return_val_if_fail (text != NULL, FALSE);
500 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
502 iface = ATK_TEXT_GET_IFACE (text);
504 if (iface->add_selection)
505 return (*(iface->add_selection)) (text, start_offset, end_offset);
511 * atk_text_remove_selection:
513 * @selection_num: The selection number. The selected regions are
514 * assigned numbers that correspond to how far the region is from the
515 * start of the text. The selected region closest to the beginning
516 * of the text region is assigned the number 0, etc. Note that adding,
517 * moving or deleting a selected region can change the numbering.
519 * Removes the specified selection
521 * Returns: %TRUE if success, %FALSE otherwise
524 atk_text_remove_selection (AtkText *text, gint selection_num)
528 g_return_val_if_fail (text != NULL, FALSE);
529 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
531 iface = ATK_TEXT_GET_IFACE (text);
533 if (iface->remove_selection)
534 return (*(iface->remove_selection)) (text, selection_num);
540 * atk_text_set_selection:
542 * @selection_num: The selection number. The selected regions are
543 * assigned numbers that correspond to how far the region is from the
544 * start of the text. The selected region closest to the beginning
545 * of the text region is assigned the number 0, etc. Note that adding,
546 * moving or deleting a selected region can change the numbering.
547 * @start_offset: the new start position of the selection
548 * @end_offset: the new end position of the selection
550 * Changes the start and end offset of the specified selection
552 * Returns: %TRUE if success, %FALSE otherwise
555 atk_text_set_selection (AtkText *text, gint selection_num,
556 gint start_offset, gint end_offset)
560 g_return_val_if_fail (text != NULL, FALSE);
561 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
563 iface = ATK_TEXT_GET_IFACE (text);
565 if (iface->set_selection)
567 return (*(iface->set_selection)) (text, selection_num,
568 start_offset, end_offset);
575 * atk_text_set_caret_offset:
579 * Sets the caret (cursor) position to the specified @offset.
581 * Returns: %TRUE if success, %FALSE otherwise.
584 atk_text_set_caret_offset (AtkText *text,
589 g_return_val_if_fail (text != NULL, FALSE);
590 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
592 iface = ATK_TEXT_GET_IFACE (text);
594 if (iface->set_caret_offset)
596 return (*(iface->set_caret_offset)) (text, offset);
605 * AtkAttributeSet_free:
606 * @attrib_set: The #AtkAttributeSet to free
608 * Frees the memory used by an #AtkAttributeSet, including all its
613 AtkAttributeSet_free(AtkAttributeSet *attrib_set)
617 if (attrib_set == NULL)
620 for (index = 0; index < g_slist_length(attrib_set); index++)
622 g_free(((AtkAttribute*) (g_slist_nth(attrib_set,index)->data))->name);
623 g_free(((AtkAttribute*) (g_slist_nth(attrib_set,index)->data))->value);
625 g_slist_free(attrib_set);