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_new ("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_new ("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 (ATK_IS_TEXT (text), NULL);
118 iface = ATK_TEXT_GET_IFACE (text);
121 return (*(iface->get_text)) (text, start_offset, end_offset);
127 * atk_text_get_character_at_offset:
131 * Gets the specified text.
133 * Returns: the character at @offset.
136 atk_text_get_character_at_offset (AtkText *text,
141 g_return_val_if_fail (ATK_IS_TEXT (text), (gunichar) 0);
143 iface = ATK_TEXT_GET_IFACE (text);
145 if (iface->get_character_at_offset)
146 return (*(iface->get_character_at_offset)) (text, offset);
152 * atk_text_get_text_after_offset:
155 * @boundary_type: An #AtkTextBoundary
156 * @start_offset: the start offset of the returned string.
157 * @end_offset: the end offset of the returned string.
159 * Gets the specified text.
160 * If the boundary type is ATK_TEXT_BOUNDARY_WORD_START or
161 * ATK_TEXT_BOUNDARY_WORD_END part of a word may be returned.
162 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the start point
163 * will be the offset and will continue to the start of the next sentence.
164 * The first word may not be a complete word. Similarly for
165 * ATK_TEXT_BOUNDARY_SENTENCE_END, ATK_TEXT_BOUNDARY_LINE_START and
166 * ATK_TEXT_BOUNDARY_LINE_END
168 * Returns: the text after @offset up to the specified @boundary_type.
171 atk_text_get_text_after_offset (AtkText *text,
173 AtkTextBoundary boundary_type,
178 gint local_start_offset, local_end_offset;
179 gint *real_start_offset, *real_end_offset;
181 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
184 real_start_offset = start_offset;
186 real_start_offset = &local_start_offset;
188 real_end_offset = end_offset;
190 real_end_offset = &local_end_offset;
192 iface = ATK_TEXT_GET_IFACE (text);
194 if (iface->get_text_after_offset)
195 return (*(iface->get_text_after_offset)) (text, offset, boundary_type, real_start_offset, real_end_offset);
201 * atk_text_get_text_at_offset:
204 * @boundary_type: An #AtkTextBoundary
205 * @start_offset: the start offset of the returned string.
206 * @end_offset: the end offset of the returned string.
208 * Gets the specified text.
209 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START or
210 * ATK_TEXT_BOUNDARY_WORD_END a complete word is returned;
211 * if the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START or
212 * ATK_TEXT_BOUNDARY_SENTENCE_END a complete sentence
213 * is returned; if the boundary type is ATK_TEXT_BOUNDARY_LINE_START or
214 * ATK_TEXT_BOUNDARY_LINE_END a complete line is returned.
216 * Returns: the text at @offset up to the specified @boundary_type.
219 atk_text_get_text_at_offset (AtkText *text,
221 AtkTextBoundary boundary_type,
226 gint local_start_offset, local_end_offset;
227 gint *real_start_offset, *real_end_offset;
229 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
232 real_start_offset = start_offset;
234 real_start_offset = &local_start_offset;
236 real_end_offset = end_offset;
238 real_end_offset = &local_end_offset;
240 iface = ATK_TEXT_GET_IFACE (text);
242 if (iface->get_text_at_offset)
243 return (*(iface->get_text_at_offset)) (text, offset, boundary_type, real_start_offset, real_end_offset);
249 * atk_text_get_text_before_offset:
252 * @boundary_type: An #AtkTextBoundary
253 * @start_offset: the start offset of the returned string.
254 * @end_offset: the end offset of the returned string.
256 * Gets the specified text.
257 * If the boundary type is ATK_TEXT_BOUNDARY_WORD_START or
258 * ATK_TEXT_BOUNDARY_WORD_END part of a word may be returned.
259 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the start point
260 * will be at the start of the sentence, and will continue to the offset.
261 * The last word may not be a complete word. Similarly for
262 * ATK_TEXT_BOUNDARY_SENTENCE_END, ATK_TEXT_BOUNDARY_LINE_START and
263 * ATK_TEXT_BOUNDARY_LINE_END
265 * Returns: the text before @offset starting from the specified @boundary_type.
268 atk_text_get_text_before_offset (AtkText *text,
270 AtkTextBoundary boundary_type,
275 gint local_start_offset, local_end_offset;
276 gint *real_start_offset, *real_end_offset;
278 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
281 real_start_offset = start_offset;
283 real_start_offset = &local_start_offset;
285 real_end_offset = end_offset;
287 real_end_offset = &local_end_offset;
289 iface = ATK_TEXT_GET_IFACE (text);
291 if (iface->get_text_before_offset)
292 return (*(iface->get_text_before_offset)) (text, offset, boundary_type, real_start_offset, real_end_offset);
298 * atk_text_get_caret_offset:
301 * Gets the offset position of the caret (cursor).
303 * Returns: the offset position of the caret (cursor).
306 atk_text_get_caret_offset (AtkText *text)
310 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
312 iface = ATK_TEXT_GET_IFACE (text);
314 if (iface->get_caret_offset)
315 return (*(iface->get_caret_offset)) (text);
321 * atk_text_get_character_extents:
324 * @x: x-position of character
325 * @y: y-position of character
326 * @width: width of character
327 * @height: height of character
328 * @coords: specify whether coordinates are relative to the screen or widget window
330 * Given an @offset, the @x, @y, @width, and @height values are filled
334 atk_text_get_character_extents (AtkText *text,
343 gint local_x, local_y, local_width, local_height;
344 gint *real_x, *real_y, *real_width, *real_height;
346 g_return_if_fail (ATK_IS_TEXT (text));
359 real_width = &local_width;
361 real_height = height;
363 real_height = &local_height;
365 iface = ATK_TEXT_GET_IFACE (text);
367 if (iface->get_character_extents)
368 (*(iface->get_character_extents)) (text, offset, real_x, real_y, real_width, real_height, coords);
379 *atk_text_get_run_attributes:
381 *@offset: the offset at which to get the attributes
382 *@start_offset: the address to put the start offset of the range
383 *@end_offset: the address to put the end offset of the range
385 *Creates an #AtkAttributeSet which consists of the attributes explicitly
386 *set at the position @offset in the text. @start_offset and @end_offset are
387 *set to the start and end of the range around @offset where the attributes are
388 *invariant. See the ATK_ATTRIBUTE macros, such as #ATK_ATTRIBUTE_LEFT_MARGIN
389 *for types of text attributes that can be returned. Note that other
390 *attributes that do not have corresponding macros may also be returned.
392 *Returns: an #AtkAttributeSet which contains the attributes explicitly set
393 *at @offset. This #AtkAttributeSet should be freed by a call to
394 *atk_attribute_set_free().
397 atk_text_get_run_attributes (AtkText *text,
403 gint local_start_offset, local_end_offset;
404 gint *real_start_offset, *real_end_offset;
406 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
409 real_start_offset = start_offset;
411 real_start_offset = &local_start_offset;
413 real_end_offset = end_offset;
415 real_end_offset = &local_end_offset;
417 iface = ATK_TEXT_GET_IFACE (text);
419 if (iface->get_run_attributes)
420 return (*(iface->get_run_attributes)) (text, offset, real_start_offset, real_end_offset);
426 *atk_text_get_default_attributes:
429 *Creates an #AtkAttributeSet which consists of the default values of
430 *attributes for the text. See the ATK_ATTRIBUTE macros, such as
431 *#ATK_ATTRIBUTE_LEFT_MARGIN for types of text attributes that can be
432 *returned. Note that other attributes that do not have corresponding macros
433 *may also be returned.
435 *Returns: an #AtkAttributeSet which contains the default values of attributes.
436 *at @offset. This #AtkAttributeSet should be freed by a call to
437 *atk_attribute_set_free().
440 atk_text_get_default_attributes (AtkText *text)
444 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
446 iface = ATK_TEXT_GET_IFACE (text);
448 if (iface->get_default_attributes)
449 return (*(iface->get_default_attributes)) (text);
455 * atk_text_get_character_count:
458 * Gets the character count.
460 * Returns: the number of characters.
463 atk_text_get_character_count (AtkText *text)
467 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
469 iface = ATK_TEXT_GET_IFACE (text);
471 if (iface->get_character_count)
472 return (*(iface->get_character_count)) (text);
478 * atk_text_get_offset_at_point:
480 * @x: screen x-position of character
481 * @y: screen y-position of character
482 * @coords: specify whether coordinates are relative to the screen or
485 * Gets the offset of the character located at coordinates @x and @y. @x and @y
486 * are interpreted as being relative to the screen or this widget's window
487 * depending on @coords.
489 * Returns: the offset to the character which is located at
490 * the specified @x and @y coordinates.
493 atk_text_get_offset_at_point (AtkText *text,
500 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
502 iface = ATK_TEXT_GET_IFACE (text);
504 if (iface->get_offset_at_point)
505 return (*(iface->get_offset_at_point)) (text, x, y, coords);
511 * atk_text_get_n_selections:
514 * Gets the number of selected regions.
516 * Returns: The number of selected regions, or -1 if a failure
520 atk_text_get_n_selections (AtkText *text)
524 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
526 iface = ATK_TEXT_GET_IFACE (text);
528 if (iface->get_n_selections)
529 return (*(iface->get_n_selections)) (text);
535 * atk_text_get_selection:
537 * @selection_num: The selection number. The selected regions are
538 * assigned numbers that correspond to how far the region is from the
539 * start of the text. The selected region closest to the beginning
540 * of the text region is assigned the number 0, etc. Note that adding,
541 * moving or deleting a selected region can change the numbering.
542 * @start_offset: passes back the start position of the selected region
543 * @end_offset: passes back the end position of the selected region
545 * Gets the text from the specified selection.
547 * Returns: the selected text.
550 atk_text_get_selection (AtkText *text,
556 gint local_start_offset, local_end_offset;
557 gint *real_start_offset, *real_end_offset;
559 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
562 real_start_offset = start_offset;
564 real_start_offset = &local_start_offset;
566 real_end_offset = end_offset;
568 real_start_offset = &local_end_offset;
570 iface = ATK_TEXT_GET_IFACE (text);
572 if (iface->get_selection)
574 return (*(iface->get_selection)) (text, selection_num,
575 real_start_offset, real_end_offset);
582 * atk_text_add_selection:
584 * @start_offset: the start position of the selected region
585 * @end_offset: the end position of the selected region
587 * Adds a selection bounded by the specified offsets.
589 * Returns: %TRUE if success, %FALSE otherwise
592 atk_text_add_selection (AtkText *text,
598 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
600 iface = ATK_TEXT_GET_IFACE (text);
602 if (iface->add_selection)
603 return (*(iface->add_selection)) (text, start_offset, end_offset);
609 * atk_text_remove_selection:
611 * @selection_num: The selection number. The selected regions are
612 * assigned numbers that correspond to how far the region is from the
613 * start of the text. The selected region closest to the beginning
614 * of the text region is assigned the number 0, etc. Note that adding,
615 * moving or deleting a selected region can change the numbering.
617 * Removes the specified selection.
619 * Returns: %TRUE if success, %FALSE otherwise
622 atk_text_remove_selection (AtkText *text,
627 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
629 iface = ATK_TEXT_GET_IFACE (text);
631 if (iface->remove_selection)
632 return (*(iface->remove_selection)) (text, selection_num);
638 * atk_text_set_selection:
640 * @selection_num: The selection number. The selected regions are
641 * assigned numbers that correspond to how far the region is from the
642 * start of the text. The selected region closest to the beginning
643 * of the text region is assigned the number 0, etc. Note that adding,
644 * moving or deleting a selected region can change the numbering.
645 * @start_offset: the new start position of the selection
646 * @end_offset: the new end position of the selection
648 * Changes the start and end offset of the specified selection.
650 * Returns: %TRUE if success, %FALSE otherwise
653 atk_text_set_selection (AtkText *text,
660 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
662 iface = ATK_TEXT_GET_IFACE (text);
664 if (iface->set_selection)
666 return (*(iface->set_selection)) (text, selection_num,
667 start_offset, end_offset);
674 * atk_text_set_caret_offset:
678 * Sets the caret (cursor) position to the specified @offset.
680 * Returns: %TRUE if success, %FALSE otherwise.
683 atk_text_set_caret_offset (AtkText *text,
688 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
690 iface = ATK_TEXT_GET_IFACE (text);
692 if (iface->set_caret_offset)
694 return (*(iface->set_caret_offset)) (text, offset);
703 * atk_attribute_set_free:
704 * @attrib_set: The #AtkAttributeSet to free
706 * Frees the memory used by an #AtkAttributeSet, including all its
710 atk_attribute_set_free(AtkAttributeSet *attrib_set)
727 g_slist_free (attrib_set);