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"
22 #include "atk-enum-types.h"
28 * @Short_description: The ATK interface implemented by components
32 * #AtkText should be implemented by #AtkObjects on behalf of widgets
33 * that have text content which is either attributed or otherwise
34 * non-trivial. #AtkObjects whose text content is simple,
35 * unattributed, and very brief may expose that content via
36 * #atk_object_get_name instead; however if the text is editable,
37 * multi-line, typically longer than three or four words, attributed,
38 * selectable, or if the object already uses the 'name' ATK property
39 * for other information, the #AtkText interface should be used to
40 * expose the text content. In the case of editable text content,
41 * #AtkEditableText (a subtype of the #AtkText interface) should be
42 * implemented instead.
44 * #AtkText provides not only traversal facilities and change
45 * notification for text content, but also caret tracking and glyph
46 * bounding box calculations. Note that the text strings are exposed
47 * as UTF-8, and are therefore potentially multi-byte, and
48 * caret-to-byte offset mapping makes no assumptions about the
49 * character length; also bounding box glyph-to-offset mapping may be
50 * complex for languages which use ligatures.
53 static GPtrArray *extra_attributes = NULL;
58 TEXT_SELECTION_CHANGED,
59 TEXT_ATTRIBUTES_CHANGED,
65 static const char boolean[] =
68 static const guint8 boolean_offsets[] = {
72 static const char style[] =
76 static const guint8 style_offsets[] = {
80 static const char variant[] =
83 static const guint8 variant_offsets[] = {
87 static const char stretch[] =
97 static const guint8 stretch_offsets[] = {
98 0, 16, 32, 42, 57, 64, 78, 87, 102
101 static const char justification[] =
106 static const guint8 justification_offsets[] = {
110 static const char direction[] =
114 static const guint8 direction_offsets[] = {
118 static const char wrap_mode[] =
123 static const guint8 wrap_mode_offsets[] = {
127 static const char underline[] =
133 static const guint8 underline_offsets[] = {
137 static void atk_text_base_init (AtkTextIface *class);
139 static void atk_text_real_get_range_extents (AtkText *text,
142 AtkCoordType coord_type,
143 AtkTextRectangle *rect);
145 static AtkTextRange** atk_text_real_get_bounded_ranges (AtkText *text,
146 AtkTextRectangle *rect,
147 AtkCoordType coord_type,
148 AtkTextClipType x_clip_type,
149 AtkTextClipType y_clip_type);
151 static guint atk_text_signals[LAST_SIGNAL] = { 0 };
154 atk_text_get_type (void)
156 static GType type = 0;
160 static const GTypeInfo tinfo =
162 sizeof (AtkTextIface),
163 (GBaseInitFunc) atk_text_base_init,
164 (GBaseFinalizeFunc) NULL,
165 (GClassInitFunc) NULL /* atk_text_interface_init */ ,
166 (GClassFinalizeFunc) NULL,
170 type = g_type_register_static (G_TYPE_INTERFACE, "AtkText", &tinfo, 0);
177 atk_text_base_init (AtkTextIface *class)
179 static gboolean initialized = FALSE;
184 * Note that text_changed signal supports details "insert", "delete",
185 * possibly "replace".
188 class->get_range_extents = atk_text_real_get_range_extents;
189 class->get_bounded_ranges = atk_text_real_get_bounded_ranges;
192 * AtkText::text-changed:
193 * @atktext: the object which received the signal.
194 * @arg1: The position (character offset) of the insertion or deletion.
195 * @arg2: The length (in characters) of text inserted or deleted.
197 * The "text-changed" signal is emitted when the text of the
198 * object which implements the AtkText interface changes, This
199 * signal will have a detail which is either "insert" or
200 * "delete" which identifies whether the text change was an
201 * insertion or a deletion.
203 * Deprecated: Since 2.9.4. Use #AtkObject::text-insert or
204 * #AtkObject::text-remove instead.
206 atk_text_signals[TEXT_CHANGED] =
207 g_signal_new ("text_changed",
209 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
210 G_STRUCT_OFFSET (AtkTextIface, text_changed),
211 (GSignalAccumulator) NULL, NULL,
212 atk_marshal_VOID__INT_INT,
214 2, G_TYPE_INT, G_TYPE_INT);
217 * AtkText::text-insert:
218 * @atktext: the object which received the signal.
219 * @arg1: The position (character offset) of the insertion.
220 * @arg2: The length (in characters) of text inserted.
221 * @arg3: The new text inserted
223 * The "text-insert" signal is emitted when a new text is
226 atk_text_signals[TEXT_INSERT] =
227 g_signal_new ("text_insert",
229 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
231 (GSignalAccumulator) NULL, NULL,
232 atk_marshal_VOID__INT_INT_STRING,
234 3, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING);
237 * AtkText::text-remove:
238 * @atktext: the object which received the signal.
239 * @arg1: The position (character offset) of the removal.
240 * @arg2: The length (in characters) of text removed.
241 * @arg3: The old text removed
243 * The "text-remove" signal is emitted when a new text is
246 atk_text_signals[TEXT_REMOVE] =
247 g_signal_new ("text_remove",
249 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
251 (GSignalAccumulator) NULL, NULL,
252 atk_marshal_VOID__INT_INT_STRING,
254 3, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING);
257 * AtkText::text-caret-moved:
258 * @atktext: the object which received the signal.
259 * @arg1: The new position of the text caret.
261 * The "text-caret-moved" signal is emitted when the caret
262 * position of the text of an object which implements AtkText
265 atk_text_signals[TEXT_CARET_MOVED] =
266 g_signal_new ("text_caret_moved",
269 G_STRUCT_OFFSET (AtkTextIface, text_caret_moved),
270 (GSignalAccumulator) NULL, NULL,
271 g_cclosure_marshal_VOID__INT,
276 * AtkText::text-selection-changed:
277 * @atktext: the object which received the signal.
279 * The "text-selection-changed" signal is emitted when the
280 * selected text of an object which implements AtkText changes.
282 atk_text_signals[TEXT_SELECTION_CHANGED] =
283 g_signal_new ("text_selection_changed",
286 G_STRUCT_OFFSET (AtkTextIface, text_selection_changed),
287 (GSignalAccumulator) NULL, NULL,
288 g_cclosure_marshal_VOID__VOID,
291 * AtkText::text-attributes-changed:
292 * @atktext: the object which received the signal.
294 * The "text-attributes-changed" signal is emitted when the text
295 * attributes of the text of an object which implements AtkText
298 atk_text_signals[TEXT_ATTRIBUTES_CHANGED] =
299 g_signal_new ("text_attributes_changed",
302 G_STRUCT_OFFSET (AtkTextIface, text_attributes_changed),
303 (GSignalAccumulator) NULL, NULL,
304 g_cclosure_marshal_VOID__VOID,
315 * @start_offset: start position
316 * @end_offset: end position, or -1 for the end of the string.
318 * Gets the specified text.
320 * Returns: a newly allocated string containing the text from @start_offset up
321 * to, but not including @end_offset. Use g_free() to free the returned string.
324 atk_text_get_text (AtkText *text,
330 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
332 iface = ATK_TEXT_GET_IFACE (text);
334 if (start_offset < 0 || end_offset < -1 ||
335 (end_offset != -1 && end_offset < start_offset))
339 return (*(iface->get_text)) (text, start_offset, end_offset);
345 * atk_text_get_character_at_offset:
349 * Gets the specified text.
351 * Returns: the character at @offset.
354 atk_text_get_character_at_offset (AtkText *text,
359 g_return_val_if_fail (ATK_IS_TEXT (text), (gunichar) 0);
361 iface = ATK_TEXT_GET_IFACE (text);
363 if (iface->get_character_at_offset)
364 return (*(iface->get_character_at_offset)) (text, offset);
370 * atk_text_get_text_after_offset:
373 * @boundary_type: An #AtkTextBoundary
374 * @start_offset: (out): the start offset of the returned string
375 * @end_offset: (out): the offset of the first character after the
378 * Gets the specified text.
380 * Deprecated: This method is deprecated since ATK version
381 * 2.9.3. Please use atk_text_get_string_at_offset() instead.
383 * Returns: a newly allocated string containing the text after @offset bounded
384 * by the specified @boundary_type. Use g_free() to free the returned string.
387 atk_text_get_text_after_offset (AtkText *text,
389 AtkTextBoundary boundary_type,
394 gint local_start_offset, local_end_offset;
395 gint *real_start_offset, *real_end_offset;
397 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
400 real_start_offset = start_offset;
402 real_start_offset = &local_start_offset;
404 real_end_offset = end_offset;
406 real_end_offset = &local_end_offset;
411 iface = ATK_TEXT_GET_IFACE (text);
413 if (iface->get_text_after_offset)
414 return (*(iface->get_text_after_offset)) (text, offset, boundary_type, real_start_offset, real_end_offset);
420 * atk_text_get_text_at_offset:
423 * @boundary_type: An #AtkTextBoundary
424 * @start_offset: (out): the start offset of the returned string
425 * @end_offset: (out): the offset of the first character after the
428 * Gets the specified text.
430 * If the boundary_type if ATK_TEXT_BOUNDARY_CHAR the character at the
431 * offset is returned.
433 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START the returned string
434 * is from the word start at or before the offset to the word start after
437 * The returned string will contain the word at the offset if the offset
438 * is inside a word and will contain the word before the offset if the
439 * offset is not inside a word.
441 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the returned
442 * string is from the sentence start at or before the offset to the sentence
443 * start after the offset.
445 * The returned string will contain the sentence at the offset if the offset
446 * is inside a sentence and will contain the sentence before the offset
447 * if the offset is not inside a sentence.
449 * If the boundary type is ATK_TEXT_BOUNDARY_LINE_START the returned
450 * string is from the line start at or before the offset to the line
451 * start after the offset.
453 * Deprecated: This method is deprecated since ATK version
454 * 2.9.4. Please use atk_text_get_string_at_offset() instead.
456 * Returns: a newly allocated string containing the text at @offset bounded by
457 * the specified @boundary_type. Use g_free() to free the returned string.
460 atk_text_get_text_at_offset (AtkText *text,
462 AtkTextBoundary boundary_type,
467 gint local_start_offset, local_end_offset;
468 gint *real_start_offset, *real_end_offset;
470 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
473 real_start_offset = start_offset;
475 real_start_offset = &local_start_offset;
477 real_end_offset = end_offset;
479 real_end_offset = &local_end_offset;
481 iface = ATK_TEXT_GET_IFACE (text);
483 if (iface->get_text_at_offset)
484 return (*(iface->get_text_at_offset)) (text, offset, boundary_type, real_start_offset, real_end_offset);
490 * atk_text_get_text_before_offset:
493 * @boundary_type: An #AtkTextBoundary
494 * @start_offset: (out): the start offset of the returned string
495 * @end_offset: (out): the offset of the first character after the
498 * Gets the specified text.
500 * Deprecated: This method is deprecated since ATK version
501 * 2.9.3. Please use atk_text_get_string_at_offset() instead.
503 * Returns: a newly allocated string containing the text before @offset bounded
504 * by the specified @boundary_type. Use g_free() to free the returned string.
507 atk_text_get_text_before_offset (AtkText *text,
509 AtkTextBoundary boundary_type,
514 gint local_start_offset, local_end_offset;
515 gint *real_start_offset, *real_end_offset;
517 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
520 real_start_offset = start_offset;
522 real_start_offset = &local_start_offset;
524 real_end_offset = end_offset;
526 real_end_offset = &local_end_offset;
531 iface = ATK_TEXT_GET_IFACE (text);
533 if (iface->get_text_before_offset)
534 return (*(iface->get_text_before_offset)) (text, offset, boundary_type, real_start_offset, real_end_offset);
540 * atk_text_get_string_at_offset:
543 * @granularity: An #AtkTextGranularity
544 * @start_offset: (out): the start offset of the returned string, or -1
545 * if an error has occurred (e.g. invalid offset, not implemented)
546 * @end_offset: (out): the offset of the first character after the returned string,
547 * or -1 if an error has occurred (e.g. invalid offset, not implemented)
549 * Gets a portion of the text exposed through an #AtkText according to a given @offset
550 * and a specific @granularity, along with the start and end offsets defining the
551 * boundaries of such a portion of text.
553 * If @granularity is ATK_TEXT_GRANULARITY_CHAR the character at the
554 * offset is returned.
556 * If @granularity is ATK_TEXT_GRANULARITY_WORD the returned string
557 * is from the word start at or before the offset to the word start after
560 * The returned string will contain the word at the offset if the offset
561 * is inside a word and will contain the word before the offset if the
562 * offset is not inside a word.
564 * If @granularity is ATK_TEXT_GRANULARITY_SENTENCE the returned string
565 * is from the sentence start at or before the offset to the sentence
566 * start after the offset.
568 * The returned string will contain the sentence at the offset if the offset
569 * is inside a sentence and will contain the sentence before the offset
570 * if the offset is not inside a sentence.
572 * If @granularity is ATK_TEXT_GRANULARITY_LINE the returned string
573 * is from the line start at or before the offset to the line
574 * start after the offset.
576 * If @granularity is ATK_TEXT_GRANULARITY_PARAGRAPH the returned string
577 * is from the start of the paragraph at or before the offset to the start
578 * of the following paragraph after the offset.
582 * Returns: a newly allocated string containing the text at the @offset bounded
583 * by the specified @granularity. Use g_free() to free the returned string.
584 * Returns %NULL if the offset is invalid or no implementation is available.
586 gchar* atk_text_get_string_at_offset (AtkText *text,
588 AtkTextGranularity granularity,
593 gint local_start_offset, local_end_offset;
594 gint *real_start_offset, *real_end_offset;
596 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
601 real_start_offset = start_offset;
604 real_start_offset = &local_start_offset;
609 real_end_offset = end_offset;
612 real_end_offset = &local_end_offset;
617 iface = ATK_TEXT_GET_IFACE (text);
619 if (iface->get_string_at_offset)
620 return (*(iface->get_string_at_offset)) (text, offset, granularity, real_start_offset, real_end_offset);
626 * atk_text_get_caret_offset:
629 * Gets the offset position of the caret (cursor).
631 * Returns: the offset position of the caret (cursor).
634 atk_text_get_caret_offset (AtkText *text)
638 g_return_val_if_fail (ATK_IS_TEXT (text), 0);
640 iface = ATK_TEXT_GET_IFACE (text);
642 if (iface->get_caret_offset)
643 return (*(iface->get_caret_offset)) (text);
649 * atk_text_get_character_extents:
651 * @offset: The offset of the text character for which bounding information is required.
652 * @x: Pointer for the x cordinate of the bounding box
653 * @y: Pointer for the y cordinate of the bounding box
654 * @width: Pointer for the width of the bounding box
655 * @height: Pointer for the height of the bounding box
656 * @coords: specify whether coordinates are relative to the screen or widget window
658 * Get the bounding box containing the glyph representing the character at
659 * a particular text offset.
662 atk_text_get_character_extents (AtkText *text,
671 gint local_x, local_y, local_width, local_height;
672 gint *real_x, *real_y, *real_width, *real_height;
674 g_return_if_fail (ATK_IS_TEXT (text));
687 real_width = &local_width;
689 real_height = height;
691 real_height = &local_height;
701 iface = ATK_TEXT_GET_IFACE (text);
703 if (iface->get_character_extents)
704 (*(iface->get_character_extents)) (text, offset, real_x, real_y, real_width, real_height, coords);
708 *real_x = *real_x + *real_width;
714 * atk_text_get_run_attributes:
716 *@offset: the offset at which to get the attributes, -1 means the offset of
717 *the character to be inserted at the caret location.
718 *@start_offset: (out): the address to put the start offset of the range
719 *@end_offset: (out): the address to put the end offset of the range
721 *Creates an #AtkAttributeSet which consists of the attributes explicitly
722 *set at the position @offset in the text. @start_offset and @end_offset are
723 *set to the start and end of the range around @offset where the attributes are
724 *invariant. Note that @end_offset is the offset of the first character
725 *after the range. See the enum AtkTextAttribute for types of text
726 *attributes that can be returned. Note that other attributes may also be
729 *Returns: (transfer full): an #AtkAttributeSet which contains the attributes
730 * explicitly set at @offset. This #AtkAttributeSet should be freed by a call
731 * to atk_attribute_set_free().
734 atk_text_get_run_attributes (AtkText *text,
740 gint local_start_offset, local_end_offset;
741 gint *real_start_offset, *real_end_offset;
743 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
746 real_start_offset = start_offset;
748 real_start_offset = &local_start_offset;
750 real_end_offset = end_offset;
752 real_end_offset = &local_end_offset;
757 iface = ATK_TEXT_GET_IFACE (text);
759 if (iface->get_run_attributes)
760 return (*(iface->get_run_attributes)) (text, offset, real_start_offset, real_end_offset);
766 * atk_text_get_default_attributes:
769 *Creates an #AtkAttributeSet which consists of the default values of
770 *attributes for the text. See the enum AtkTextAttribute for types of text
771 *attributes that can be returned. Note that other attributes may also be
774 *Returns: (transfer full): an #AtkAttributeSet which contains the default
775 * values of attributes. at @offset. this #atkattributeset should be freed by
776 * a call to atk_attribute_set_free().
779 atk_text_get_default_attributes (AtkText *text)
783 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
785 iface = ATK_TEXT_GET_IFACE (text);
787 if (iface->get_default_attributes)
788 return (*(iface->get_default_attributes)) (text);
794 * atk_text_get_character_count:
797 * Gets the character count.
799 * Returns: the number of characters.
802 atk_text_get_character_count (AtkText *text)
806 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
808 iface = ATK_TEXT_GET_IFACE (text);
810 if (iface->get_character_count)
811 return (*(iface->get_character_count)) (text);
817 * atk_text_get_offset_at_point:
819 * @x: screen x-position of character
820 * @y: screen y-position of character
821 * @coords: specify whether coordinates are relative to the screen or
824 * Gets the offset of the character located at coordinates @x and @y. @x and @y
825 * are interpreted as being relative to the screen or this widget's window
826 * depending on @coords.
828 * Returns: the offset to the character which is located at
829 * the specified @x and @y coordinates.
832 atk_text_get_offset_at_point (AtkText *text,
839 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
841 iface = ATK_TEXT_GET_IFACE (text);
843 if (iface->get_offset_at_point)
844 return (*(iface->get_offset_at_point)) (text, x, y, coords);
850 * atk_text_get_n_selections:
853 * Gets the number of selected regions.
855 * Returns: The number of selected regions, or -1 if a failure
859 atk_text_get_n_selections (AtkText *text)
863 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
865 iface = ATK_TEXT_GET_IFACE (text);
867 if (iface->get_n_selections)
868 return (*(iface->get_n_selections)) (text);
874 * atk_text_get_selection:
876 * @selection_num: The selection number. The selected regions are
877 * assigned numbers that correspond to how far the region is from the
878 * start of the text. The selected region closest to the beginning
879 * of the text region is assigned the number 0, etc. Note that adding,
880 * moving or deleting a selected region can change the numbering.
881 * @start_offset: (out): passes back the start position of the selected region
882 * @end_offset: (out): passes back the end position of (e.g. offset immediately past)
883 * the selected region
885 * Gets the text from the specified selection.
887 * Returns: a newly allocated string containing the selected text. Use g_free()
888 * to free the returned string.
891 atk_text_get_selection (AtkText *text,
897 gint local_start_offset, local_end_offset;
898 gint *real_start_offset, *real_end_offset;
900 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
903 real_start_offset = start_offset;
905 real_start_offset = &local_start_offset;
907 real_end_offset = end_offset;
909 real_end_offset = &local_end_offset;
911 iface = ATK_TEXT_GET_IFACE (text);
913 if (iface->get_selection)
915 return (*(iface->get_selection)) (text, selection_num,
916 real_start_offset, real_end_offset);
923 * atk_text_add_selection:
925 * @start_offset: the start position of the selected region
926 * @end_offset: the offset of the first character after the selected region.
928 * Adds a selection bounded by the specified offsets.
930 * Returns: %TRUE if success, %FALSE otherwise
933 atk_text_add_selection (AtkText *text,
939 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
941 iface = ATK_TEXT_GET_IFACE (text);
943 if (iface->add_selection)
944 return (*(iface->add_selection)) (text, start_offset, end_offset);
950 * atk_text_remove_selection:
952 * @selection_num: The selection number. The selected regions are
953 * assigned numbers that correspond to how far the region is from the
954 * start of the text. The selected region closest to the beginning
955 * of the text region is assigned the number 0, etc. Note that adding,
956 * moving or deleting a selected region can change the numbering.
958 * Removes the specified selection.
960 * Returns: %TRUE if success, %FALSE otherwise
963 atk_text_remove_selection (AtkText *text,
968 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
970 iface = ATK_TEXT_GET_IFACE (text);
972 if (iface->remove_selection)
973 return (*(iface->remove_selection)) (text, selection_num);
979 * atk_text_set_selection:
981 * @selection_num: The selection number. The selected regions are
982 * assigned numbers that correspond to how far the region is from the
983 * start of the text. The selected region closest to the beginning
984 * of the text region is assigned the number 0, etc. Note that adding,
985 * moving or deleting a selected region can change the numbering.
986 * @start_offset: the new start position of the selection
987 * @end_offset: the new end position of (e.g. offset immediately past)
990 * Changes the start and end offset of the specified selection.
992 * Returns: %TRUE if success, %FALSE otherwise
995 atk_text_set_selection (AtkText *text,
1000 AtkTextIface *iface;
1002 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
1004 iface = ATK_TEXT_GET_IFACE (text);
1006 if (iface->set_selection)
1008 return (*(iface->set_selection)) (text, selection_num,
1009 start_offset, end_offset);
1016 * atk_text_set_caret_offset:
1017 * @text: an #AtkText
1020 * Sets the caret (cursor) position to the specified @offset.
1022 * Returns: %TRUE if success, %FALSE otherwise.
1025 atk_text_set_caret_offset (AtkText *text,
1028 AtkTextIface *iface;
1030 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
1032 iface = ATK_TEXT_GET_IFACE (text);
1034 if (iface->set_caret_offset)
1036 return (*(iface->set_caret_offset)) (text, offset);
1045 * atk_text_get_range_extents:
1046 * @text: an #AtkText
1047 * @start_offset: The offset of the first text character for which boundary
1048 * information is required.
1049 * @end_offset: The offset of the text character after the last character
1050 * for which boundary information is required.
1051 * @coord_type: Specify whether coordinates are relative to the screen or widget window.
1052 * @rect: A pointer to a AtkTextRectangle which is filled in by this function.
1054 * Get the bounding box for text within the specified range.
1059 atk_text_get_range_extents (AtkText *text,
1062 AtkCoordType coord_type,
1063 AtkTextRectangle *rect)
1065 AtkTextIface *iface;
1067 g_return_if_fail (ATK_IS_TEXT (text));
1068 g_return_if_fail (rect);
1070 if (start_offset < 0 || start_offset >= end_offset)
1073 iface = ATK_TEXT_GET_IFACE (text);
1075 if (iface->get_range_extents)
1076 (*(iface->get_range_extents)) (text, start_offset, end_offset, coord_type, rect);
1080 * atk_text_get_bounded_ranges:
1081 * @text: an #AtkText
1082 * @rect: An AtkTextRectangle giving the dimensions of the bounding box.
1083 * @coord_type: Specify whether coordinates are relative to the screen or widget window.
1084 * @x_clip_type: Specify the horizontal clip type.
1085 * @y_clip_type: Specify the vertical clip type.
1087 * Get the ranges of text in the specified bounding box.
1091 * Returns: (array zero-terminated=1): Array of AtkTextRange. The last
1092 * element of the array returned by this function will be NULL.
1093 * Virtual: get_bounded_ranges
1096 atk_text_get_bounded_ranges (AtkText *text,
1097 AtkTextRectangle *rect,
1098 AtkCoordType coord_type,
1099 AtkTextClipType x_clip_type,
1100 AtkTextClipType y_clip_type)
1102 AtkTextIface *iface;
1104 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
1105 g_return_val_if_fail (rect, NULL);
1107 iface = ATK_TEXT_GET_IFACE (text);
1109 if (iface->get_bounded_ranges)
1110 return (*(iface->get_bounded_ranges)) (text, rect, coord_type, x_clip_type, y_clip_type);
1116 * atk_attribute_set_free:
1117 * @attrib_set: The #AtkAttributeSet to free
1119 * Frees the memory used by an #AtkAttributeSet, including all its
1123 atk_attribute_set_free (AtkAttributeSet *attrib_set)
1129 while (temp != NULL)
1136 g_free (att->value);
1140 g_slist_free (attrib_set);
1144 * atk_text_attribute_register:
1145 * @name: a name string
1147 * Associate @name with a new #AtkTextAttribute
1149 * Returns: an #AtkTextAttribute associated with @name
1152 atk_text_attribute_register (const gchar *name)
1154 g_return_val_if_fail (name, ATK_TEXT_ATTR_INVALID);
1156 if (!extra_attributes)
1157 extra_attributes = g_ptr_array_new ();
1159 g_ptr_array_add (extra_attributes, g_strdup (name));
1160 return extra_attributes->len + ATK_TEXT_ATTR_LAST_DEFINED;
1164 * atk_text_attribute_get_name:
1165 * @attr: The #AtkTextAttribute whose name is required
1167 * Gets the name corresponding to the #AtkTextAttribute
1169 * Returns: a string containing the name; this string should not be freed
1172 atk_text_attribute_get_name (AtkTextAttribute attr)
1174 GTypeClass *type_class;
1176 const gchar *name = NULL;
1178 type_class = g_type_class_ref (ATK_TYPE_TEXT_ATTRIBUTE);
1179 g_return_val_if_fail (G_IS_ENUM_CLASS (type_class), NULL);
1181 value = g_enum_get_value (G_ENUM_CLASS (type_class), attr);
1185 name = value->value_nick;
1189 if (extra_attributes)
1193 n -= ATK_TEXT_ATTR_LAST_DEFINED + 1;
1195 if (n < extra_attributes->len)
1197 name = g_ptr_array_index (extra_attributes, n);
1200 g_type_class_unref (type_class);
1205 * atk_text_attribute_for_name:
1206 * @name: a string which is the (non-localized) name of an ATK text attribute.
1208 * Get the #AtkTextAttribute type corresponding to a text attribute name.
1210 * Returns: the #AtkTextAttribute enumerated type corresponding to the specified
1212 * or #ATK_TEXT_ATTRIBUTE_INVALID if no matching text attribute is found.
1215 atk_text_attribute_for_name (const gchar *name)
1217 GTypeClass *type_class;
1219 AtkTextAttribute type = ATK_TEXT_ATTR_INVALID;
1221 g_return_val_if_fail (name, ATK_TEXT_ATTR_INVALID);
1223 type_class = g_type_class_ref (ATK_TYPE_TEXT_ATTRIBUTE);
1224 g_return_val_if_fail (G_IS_ENUM_CLASS (type_class), ATK_TEXT_ATTR_INVALID);
1226 value = g_enum_get_value_by_nick (G_ENUM_CLASS (type_class), name);
1230 type = value->value;
1236 if (extra_attributes)
1238 for (i = 0; i < extra_attributes->len; i++)
1240 gchar *extra_attribute = (gchar *)g_ptr_array_index (extra_attributes, i);
1242 g_return_val_if_fail (extra_attribute, ATK_TEXT_ATTR_INVALID);
1244 if (strcmp (name, extra_attribute) == 0)
1246 type = i + 1 + ATK_TEXT_ATTR_LAST_DEFINED;
1252 g_type_class_unref (type_class);
1258 * atk_text_attribute_get_value:
1259 * @attr: The #AtkTextAttribute for which a value is required
1260 * @index_: The index of the required value
1262 * Gets the value for the index of the #AtkTextAttribute
1264 * Returns: a string containing the value; this string should not be freed;
1265 * NULL is returned if there are no values maintained for the attr value.
1268 atk_text_attribute_get_value (AtkTextAttribute attr,
1273 case ATK_TEXT_ATTR_INVISIBLE:
1274 case ATK_TEXT_ATTR_EDITABLE:
1275 case ATK_TEXT_ATTR_BG_FULL_HEIGHT:
1276 case ATK_TEXT_ATTR_STRIKETHROUGH:
1277 case ATK_TEXT_ATTR_BG_STIPPLE:
1278 case ATK_TEXT_ATTR_FG_STIPPLE:
1279 g_assert (index >= 0 && index < G_N_ELEMENTS (boolean_offsets));
1280 return boolean + boolean_offsets[index];
1281 case ATK_TEXT_ATTR_UNDERLINE:
1282 g_assert (index >= 0 && index < G_N_ELEMENTS (underline_offsets));
1283 return underline + underline_offsets[index];
1284 case ATK_TEXT_ATTR_WRAP_MODE:
1285 g_assert (index >= 0 && index < G_N_ELEMENTS (wrap_mode_offsets));
1286 return wrap_mode + wrap_mode_offsets[index];
1287 case ATK_TEXT_ATTR_DIRECTION:
1288 g_assert (index >= 0 && index < G_N_ELEMENTS (direction_offsets));
1289 return direction + direction_offsets[index];
1290 case ATK_TEXT_ATTR_JUSTIFICATION:
1291 g_assert (index >= 0 && index < G_N_ELEMENTS (justification_offsets));
1292 return justification + justification_offsets[index];
1293 case ATK_TEXT_ATTR_STRETCH:
1294 g_assert (index >= 0 && index < G_N_ELEMENTS (stretch_offsets));
1295 return stretch + stretch_offsets[index];
1296 case ATK_TEXT_ATTR_VARIANT:
1297 g_assert (index >= 0 && index < G_N_ELEMENTS (variant_offsets));
1298 return variant + variant_offsets[index];
1299 case ATK_TEXT_ATTR_STYLE:
1300 g_assert (index >= 0 && index < G_N_ELEMENTS (style_offsets));
1301 return style + style_offsets[index];
1308 atk_text_rectangle_union (AtkTextRectangle *src1,
1309 AtkTextRectangle *src2,
1310 AtkTextRectangle *dest)
1312 gint dest_x, dest_y;
1314 dest_x = MIN (src1->x, src2->x);
1315 dest_y = MIN (src1->y, src2->y);
1316 dest->width = MAX (src1->x + src1->width, src2->x + src2->width) - dest_x;
1317 dest->height = MAX (src1->y + src1->height, src2->y + src2->height) - dest_y;
1323 atk_text_rectangle_contain (AtkTextRectangle *clip,
1324 AtkTextRectangle *bounds,
1325 AtkTextClipType x_clip_type,
1326 AtkTextClipType y_clip_type)
1328 gboolean x_min_ok, x_max_ok, y_min_ok, y_max_ok;
1330 x_min_ok = (bounds->x >= clip->x) ||
1331 ((bounds->x + bounds->width >= clip->x) &&
1332 ((x_clip_type == ATK_TEXT_CLIP_NONE) ||
1333 (x_clip_type == ATK_TEXT_CLIP_MAX)));
1335 x_max_ok = (bounds->x + bounds->width <= clip->x + clip->width) ||
1336 ((bounds->x <= clip->x + clip->width) &&
1337 ((x_clip_type == ATK_TEXT_CLIP_NONE) ||
1338 (x_clip_type == ATK_TEXT_CLIP_MIN)));
1340 y_min_ok = (bounds->y >= clip->y) ||
1341 ((bounds->y + bounds->height >= clip->y) &&
1342 ((y_clip_type == ATK_TEXT_CLIP_NONE) ||
1343 (y_clip_type == ATK_TEXT_CLIP_MAX)));
1345 y_max_ok = (bounds->y + bounds->height <= clip->y + clip->height) ||
1346 ((bounds->y <= clip->y + clip->height) &&
1347 ((y_clip_type == ATK_TEXT_CLIP_NONE) ||
1348 (y_clip_type == ATK_TEXT_CLIP_MIN)));
1350 return (x_min_ok && x_max_ok && y_min_ok && y_max_ok);
1355 atk_text_real_get_range_extents (AtkText *text,
1358 AtkCoordType coord_type,
1359 AtkTextRectangle *rect)
1362 AtkTextRectangle cbounds, bounds;
1364 atk_text_get_character_extents (text, start_offset,
1365 &bounds.x, &bounds.y,
1366 &bounds.width, &bounds.height,
1369 for (i = start_offset + 1; i < end_offset; i++)
1371 atk_text_get_character_extents (text, i,
1372 &cbounds.x, &cbounds.y,
1373 &cbounds.width, &cbounds.height,
1375 atk_text_rectangle_union (&bounds, &cbounds, &bounds);
1380 rect->width = bounds.width;
1381 rect->height = bounds.height;
1384 static AtkTextRange**
1385 atk_text_real_get_bounded_ranges (AtkText *text,
1386 AtkTextRectangle *rect,
1387 AtkCoordType coord_type,
1388 AtkTextClipType x_clip_type,
1389 AtkTextClipType y_clip_type)
1391 gint bounds_min_offset, bounds_max_offset;
1392 gint min_line_start, min_line_end;
1393 gint max_line_start, max_line_end;
1397 gint num_ranges = 0;
1398 gint range_size = 1;
1399 AtkTextRectangle cbounds;
1400 AtkTextRange **range;
1403 bounds_min_offset = atk_text_get_offset_at_point (text, rect->x, rect->y, coord_type);
1404 bounds_max_offset = atk_text_get_offset_at_point (text, rect->x + rect->width, rect->y + rect->height, coord_type);
1406 if (bounds_min_offset == 0 &&
1407 bounds_min_offset == bounds_max_offset)
1410 line = atk_text_get_text_at_offset (text, bounds_min_offset,
1411 ATK_TEXT_BOUNDARY_LINE_START,
1412 &min_line_start, &min_line_end);
1414 line = atk_text_get_text_at_offset (text, bounds_max_offset,
1415 ATK_TEXT_BOUNDARY_LINE_START,
1416 &max_line_start, &max_line_end);
1418 bounds_min_offset = MIN (min_line_start, max_line_start);
1419 bounds_max_offset = MAX (min_line_end, max_line_end);
1421 curr_offset = bounds_min_offset;
1422 while (curr_offset < bounds_max_offset)
1424 offset = curr_offset;
1426 while (curr_offset < bounds_max_offset)
1428 atk_text_get_character_extents (text, curr_offset,
1429 &cbounds.x, &cbounds.y,
1430 &cbounds.width, &cbounds.height,
1432 if (!atk_text_rectangle_contain (rect, &cbounds, x_clip_type, y_clip_type))
1436 if (curr_offset > offset)
1438 AtkTextRange *one_range = g_new (AtkTextRange, 1);
1440 one_range->start_offset = offset;
1441 one_range->end_offset = curr_offset;
1442 one_range->content = atk_text_get_text (text, offset, curr_offset);
1443 atk_text_get_range_extents (text, offset, curr_offset, coord_type, &one_range->bounds);
1445 if (num_ranges >= range_size - 1)
1448 range = g_realloc (range, range_size * sizeof (gpointer));
1450 range[num_ranges] = one_range;
1455 range[num_ranges] = NULL;
1461 * atk_text_free_ranges:
1462 * @ranges: (array): A pointer to an array of #AtkTextRange which is
1465 * Frees the memory associated with an array of AtkTextRange. It is assumed
1466 * that the array was returned by the function atk_text_get_bounded_ranges
1467 * and is NULL terminated.
1472 atk_text_free_ranges (AtkTextRange **ranges)
1474 AtkTextRange **first = ranges;
1480 AtkTextRange *range;
1484 g_free (range->content);
1491 static AtkTextRange *
1492 atk_text_range_copy (AtkTextRange *src)
1494 AtkTextRange *dst = g_new0 (AtkTextRange, 1);
1495 dst->bounds = src->bounds;
1496 dst->start_offset = src->start_offset;
1497 dst->end_offset = src->end_offset;
1499 dst->content = g_strdup (src->content);
1504 atk_text_range_free (AtkTextRange *range)
1506 g_free (range->content);
1510 G_DEFINE_BOXED_TYPE (AtkTextRange, atk_text_range, atk_text_range_copy,
1511 atk_text_range_free)