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"
26 static GPtrArray *extra_attributes = NULL;
31 TEXT_SELECTION_CHANGED,
32 TEXT_ATTRIBUTES_CHANGED,
36 static const gchar *bool[] = {"false",
38 static const gchar *style[] = {"normal",
41 static const gchar *variant[] = {"normal",
43 static const gchar *stretch[] = {"ultra_condensed",
52 static const gchar *justification[] = {"left",
56 static const gchar *direction[] = {"none",
59 static const gchar *wrap_mode[] = {"none",
62 static const gchar *underline[] = {"none",
67 static void atk_text_base_init (AtkTextIface *class);
69 static void atk_text_real_get_range_extents (AtkText *text,
72 AtkCoordType coord_type,
73 AtkTextRectangle *rect);
75 static AtkTextRange** atk_text_real_get_bounded_ranges (AtkText *text,
76 AtkTextRectangle *rect,
77 AtkCoordType coord_type,
78 AtkTextClipType x_clip_type,
79 AtkTextClipType y_clip_type);
81 static guint atk_text_signals[LAST_SIGNAL] = { 0 };
84 atk_text_get_type (void)
86 static GType type = 0;
90 static const GTypeInfo tinfo =
92 sizeof (AtkTextIface),
93 (GBaseInitFunc) atk_text_base_init,
94 (GBaseFinalizeFunc) NULL,
95 (GClassInitFunc) NULL /* atk_text_interface_init */ ,
96 (GClassFinalizeFunc) NULL,
100 type = g_type_register_static (G_TYPE_INTERFACE, "AtkText", &tinfo, 0);
107 atk_text_base_init (AtkTextIface *class)
109 static gboolean initialized = FALSE;
114 * Note that text_changed signal supports details "insert", "delete",
115 * possibly "replace".
118 class->get_range_extents = atk_text_real_get_range_extents;
119 class->get_bounded_ranges = atk_text_real_get_bounded_ranges;
121 atk_text_signals[TEXT_CHANGED] =
122 g_signal_new ("text_changed",
124 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
125 G_STRUCT_OFFSET (AtkTextIface, text_changed),
126 (GSignalAccumulator) NULL, NULL,
127 atk_marshal_VOID__INT_INT,
129 2, G_TYPE_INT, G_TYPE_INT);
131 atk_text_signals[TEXT_CARET_MOVED] =
132 g_signal_new ("text_caret_moved",
135 G_STRUCT_OFFSET (AtkTextIface, text_caret_moved),
136 (GSignalAccumulator) NULL, NULL,
137 g_cclosure_marshal_VOID__INT,
140 atk_text_signals[TEXT_SELECTION_CHANGED] =
141 g_signal_new ("text_selection_changed",
144 G_STRUCT_OFFSET (AtkTextIface, text_selection_changed),
145 (GSignalAccumulator) NULL, NULL,
146 g_cclosure_marshal_VOID__VOID,
148 atk_text_signals[TEXT_ATTRIBUTES_CHANGED] =
149 g_signal_new ("text_attributes_changed",
152 G_STRUCT_OFFSET (AtkTextIface, text_attributes_changed),
153 (GSignalAccumulator) NULL, NULL,
154 g_cclosure_marshal_VOID__VOID,
165 * @start_offset: start position
166 * @end_offset: end position
168 * Gets the specified text.
170 * Returns: the text from @start_offset up to, but not including @end_offset.
173 atk_text_get_text (AtkText *text,
179 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
181 iface = ATK_TEXT_GET_IFACE (text);
183 if (start_offset < 0 || end_offset < -1)
187 return (*(iface->get_text)) (text, start_offset, end_offset);
193 * atk_text_get_character_at_offset:
197 * Gets the specified text.
199 * Returns: the character at @offset.
202 atk_text_get_character_at_offset (AtkText *text,
207 g_return_val_if_fail (ATK_IS_TEXT (text), (gunichar) 0);
212 iface = ATK_TEXT_GET_IFACE (text);
214 if (iface->get_character_at_offset)
215 return (*(iface->get_character_at_offset)) (text, offset);
221 * atk_text_get_text_after_offset:
224 * @boundary_type: An #AtkTextBoundary
225 * @start_offset: the start offset of the returned string.
226 * @end_offset: the end offset of the returned string.
228 * Gets the specified text.
230 * If the boundary_type if ATK_TEXT_BOUNDARY_CHAR the character after the
231 * offset is returned.
233 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START the returned string
234 * is from the word start after the offset to the next word start.
236 * The returned string will contain the word after the offset if the offset
237 * is inside a word or if the offset is not inside a word.
239 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_END the returned string
240 * is from the word end at or after the offset to the next work end.
242 * The returned string will contain the word after the offset if the offset
243 * is inside a word and will contain the word after the word after the offset
244 * if the offset is not inside a word.
246 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the returned
247 * string is from the sentence start after the offset to the next sentence
250 * The returned string will contain the sentence after the offset if the offset
251 * is inside a sentence or if the offset is not inside a sentence.
253 * If the boundary_type is ATK_TEXT_BOUNDARY_SENTENCE_END the returned string
254 * is from the sentence end at or after the offset to the next sentence end.
256 * The returned string will contain the sentence after the offset if the offset
257 * is inside a sentence and will contain the sentence after the sentence
258 * after the offset if the offset is not inside a sentence.
260 * If the boundary type is ATK_TEXT_BOUNDARY_LINE_START the returned
261 * string is from the line start after the offset to the next line start.
263 * If the boundary_type is ATK_TEXT_BOUNDARY_LINE_END the returned string
264 * is from the line end at or after the offset to the next line start.
266 * Returns: the text after @offset bounded by the specified @boundary_type.
269 atk_text_get_text_after_offset (AtkText *text,
271 AtkTextBoundary boundary_type,
276 gint local_start_offset, local_end_offset;
277 gint *real_start_offset, *real_end_offset;
279 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
282 real_start_offset = start_offset;
284 real_start_offset = &local_start_offset;
286 real_end_offset = end_offset;
288 real_end_offset = &local_end_offset;
293 iface = ATK_TEXT_GET_IFACE (text);
295 if (iface->get_text_after_offset)
296 return (*(iface->get_text_after_offset)) (text, offset, boundary_type, real_start_offset, real_end_offset);
302 * atk_text_get_text_at_offset:
305 * @boundary_type: An #AtkTextBoundary
306 * @start_offset: the start offset of the returned string.
307 * @end_offset: the end offset of the returned string.
309 * Gets the specified text.
311 * If the boundary_type if ATK_TEXT_BOUNDARY_CHAR the character at the
312 * offset is returned.
314 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START the returned string
315 * is from the word start at or before the offset to the word start after
318 * The returned string will contain the word at the offset if the offset
319 * is inside a word and will contain the word before the offset if the
320 * offset is not inside a word.
322 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_END the returned string
323 * is from the word end before the offset to the word end at or after the
326 * The returned string will contain the word at the offset if the offset
327 * is inside a word and will contain the word after to the offset if the
328 * offset is not inside a word.
330 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the returned
331 * string is from the sentence start at or before the offset to the sentence
332 * start after the offset.
334 * The returned string will contain the sentence at the offset if the offset
335 * is inside a sentence and will contain the sentence before the offset
336 * if the offset is not inside a sentence.
338 * If the boundary_type is ATK_TEXT_BOUNDARY_SENTENCE_END the returned string
339 * is from the sentence end before the offset to the sentence end at or
342 * The returned string will contain the sentence at the offset if the offset
343 * is inside a sentence and will contain the sentence after the offset
344 * if the offset is not inside a sentence.
346 * If the boundary type is ATK_TEXT_BOUNDARY_LINE_START the returned
347 * string is from the line start at or before the offset to the line
348 * start after the offset.
350 * If the boundary_type is ATK_TEXT_BOUNDARY_LINE_END the returned string
351 * is from the line end before the offset to the line end at or after
354 * Returns: the text at @offset bounded by the specified @boundary_type.
357 atk_text_get_text_at_offset (AtkText *text,
359 AtkTextBoundary boundary_type,
364 gint local_start_offset, local_end_offset;
365 gint *real_start_offset, *real_end_offset;
367 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
370 real_start_offset = start_offset;
372 real_start_offset = &local_start_offset;
374 real_end_offset = end_offset;
376 real_end_offset = &local_end_offset;
381 iface = ATK_TEXT_GET_IFACE (text);
383 if (iface->get_text_at_offset)
384 return (*(iface->get_text_at_offset)) (text, offset, boundary_type, real_start_offset, real_end_offset);
390 * atk_text_get_text_before_offset:
393 * @boundary_type: An #AtkTextBoundary
394 * @start_offset: the start offset of the returned string.
395 * @end_offset: the end offset of the returned string.
397 * Gets the specified text.
399 * If the boundary_type if ATK_TEXT_BOUNDARY_CHAR the character before the
400 * offset is returned.
402 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START the returned string
403 * is from the word start before the word start before the offset to
404 * the word start before the offset.
406 * The returned string will contain the word before the offset if the offset
407 * is inside a word and will contain the word before the word before the
408 * offset if the offset is not inside a word.
410 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_END the returned string
411 * is from the word end before the word end at or before the offset to the
412 * word end at or before the offset.
414 * The returned string will contain the word before the offset if the offset
415 * is inside a word or if the offset is not inside a word.
417 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the returned
418 * string is from the sentence start before the sentence start before
419 * the offset to the sentence start before the offset.
421 * The returned string will contain the sentence before the offset if the
422 * offset is inside a sentence and will contain the sentence before the
423 * sentence before the offset if the offset is not inside a sentence.
425 * If the boundary_type is ATK_TEXT_BOUNDARY_SENTENCE_END the returned string
426 * is from the sentence end before the sentence end at or before the offset to
427 * the sentence end at or before the offset.
429 * The returned string will contain the sentence before the offset if the
430 * offset is inside a sentence or if the offset is not inside a sentence.
432 * If the boundary type is ATK_TEXT_BOUNDARY_LINE_START the returned
433 * string is from the line start before the line start ar or before the offset
434 * to the line start ar or before the offset.
436 * If the boundary_type is ATK_TEXT_BOUNDARY_LINE_END the returned string
437 * is from the line end before the line end before the offset to the
438 * line end before the offset.
440 * Returns: the text before @offset bounded by the specified @boundary_type.
443 atk_text_get_text_before_offset (AtkText *text,
445 AtkTextBoundary boundary_type,
450 gint local_start_offset, local_end_offset;
451 gint *real_start_offset, *real_end_offset;
453 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
456 real_start_offset = start_offset;
458 real_start_offset = &local_start_offset;
460 real_end_offset = end_offset;
462 real_end_offset = &local_end_offset;
467 iface = ATK_TEXT_GET_IFACE (text);
469 if (iface->get_text_before_offset)
470 return (*(iface->get_text_before_offset)) (text, offset, boundary_type, real_start_offset, real_end_offset);
476 * atk_text_get_caret_offset:
479 * Gets the offset position of the caret (cursor).
481 * Returns: the offset position of the caret (cursor).
484 atk_text_get_caret_offset (AtkText *text)
488 g_return_val_if_fail (ATK_IS_TEXT (text), 0);
490 iface = ATK_TEXT_GET_IFACE (text);
492 if (iface->get_caret_offset)
493 return (*(iface->get_caret_offset)) (text);
499 * atk_text_get_character_extents:
501 * @offset: The offset of the text character for which bounding information is required.
502 * @x: Pointer for the x cordinate of the bounding box.
503 * @y: Pointer for the y cordinate of the bounding box.
504 * @width: Pointer for the width of the bounding box
505 * @height: Pointer for the height of the bounding box.
506 * @coords: specify whether coordinates are relative to the screen or widget window
508 * Get the bounding box containing the glyph representing the character at
509 * a particular text offset.
512 atk_text_get_character_extents (AtkText *text,
521 gint local_x, local_y, local_width, local_height;
522 gint *real_x, *real_y, *real_width, *real_height;
524 g_return_if_fail (ATK_IS_TEXT (text));
537 real_width = &local_width;
539 real_height = height;
541 real_height = &local_height;
551 iface = ATK_TEXT_GET_IFACE (text);
553 if (iface->get_character_extents)
554 (*(iface->get_character_extents)) (text, offset, real_x, real_y, real_width, real_height, coords);
558 *real_x = *real_x + *real_width;
564 *atk_text_get_run_attributes:
566 *@offset: the offset at which to get the attributes
567 *@start_offset: the address to put the start offset of the range
568 *@end_offset: the address to put the end offset of the range
570 *Creates an #AtkAttributeSet which consists of the attributes explicitly
571 *set at the position @offset in the text. @start_offset and @end_offset are
572 *set to the start and end of the range around @offset where the attributes are
573 *invariant. See the enum AtkTextAttribute for types of text attributes that
574 *can be returned. Note that other attributes may also be returned.
576 *Returns: an #AtkAttributeSet which contains the attributes explicitly set
577 *at @offset. This #AtkAttributeSet should be freed by a call to
578 *atk_attribute_set_free().
581 atk_text_get_run_attributes (AtkText *text,
587 gint local_start_offset, local_end_offset;
588 gint *real_start_offset, *real_end_offset;
590 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
593 real_start_offset = start_offset;
595 real_start_offset = &local_start_offset;
597 real_end_offset = end_offset;
599 real_end_offset = &local_end_offset;
604 iface = ATK_TEXT_GET_IFACE (text);
606 if (iface->get_run_attributes)
607 return (*(iface->get_run_attributes)) (text, offset, real_start_offset, real_end_offset);
613 *atk_text_get_default_attributes:
616 *Creates an #AtkAttributeSet which consists of the default values of
617 *attributes for the text. See the enum AtkTextAttribute for types of text
618 *attributes that can be returned. Note that other attributes may also be
621 *Returns: an #AtkAttributeSet which contains the default values of attributes.
622 *at @offset. This #AtkAttributeSet should be freed by a call to
623 *atk_attribute_set_free().
626 atk_text_get_default_attributes (AtkText *text)
630 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
632 iface = ATK_TEXT_GET_IFACE (text);
634 if (iface->get_default_attributes)
635 return (*(iface->get_default_attributes)) (text);
641 * atk_text_get_character_count:
644 * Gets the character count.
646 * Returns: the number of characters.
649 atk_text_get_character_count (AtkText *text)
653 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
655 iface = ATK_TEXT_GET_IFACE (text);
657 if (iface->get_character_count)
658 return (*(iface->get_character_count)) (text);
664 * atk_text_get_offset_at_point:
666 * @x: screen x-position of character
667 * @y: screen y-position of character
668 * @coords: specify whether coordinates are relative to the screen or
671 * Gets the offset of the character located at coordinates @x and @y. @x and @y
672 * are interpreted as being relative to the screen or this widget's window
673 * depending on @coords.
675 * Returns: the offset to the character which is located at
676 * the specified @x and @y coordinates.
679 atk_text_get_offset_at_point (AtkText *text,
686 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
688 iface = ATK_TEXT_GET_IFACE (text);
690 if (iface->get_offset_at_point)
691 return (*(iface->get_offset_at_point)) (text, x, y, coords);
697 * atk_text_get_n_selections:
700 * Gets the number of selected regions.
702 * Returns: The number of selected regions, or -1 if a failure
706 atk_text_get_n_selections (AtkText *text)
710 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
712 iface = ATK_TEXT_GET_IFACE (text);
714 if (iface->get_n_selections)
715 return (*(iface->get_n_selections)) (text);
721 * atk_text_get_selection:
723 * @selection_num: The selection number. The selected regions are
724 * assigned numbers that correspond to how far the region is from the
725 * start of the text. The selected region closest to the beginning
726 * of the text region is assigned the number 0, etc. Note that adding,
727 * moving or deleting a selected region can change the numbering.
728 * @start_offset: passes back the start position of the selected region
729 * @end_offset: passes back the end position of the selected region
731 * Gets the text from the specified selection.
733 * Returns: the selected text.
736 atk_text_get_selection (AtkText *text,
742 gint local_start_offset, local_end_offset;
743 gint *real_start_offset, *real_end_offset;
745 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
748 real_start_offset = start_offset;
750 real_start_offset = &local_start_offset;
752 real_end_offset = end_offset;
754 real_end_offset = &local_end_offset;
756 iface = ATK_TEXT_GET_IFACE (text);
758 if (iface->get_selection)
760 return (*(iface->get_selection)) (text, selection_num,
761 real_start_offset, real_end_offset);
768 * atk_text_add_selection:
770 * @start_offset: the start position of the selected region
771 * @end_offset: the end position of the selected region
773 * Adds a selection bounded by the specified offsets.
775 * Returns: %TRUE if success, %FALSE otherwise
778 atk_text_add_selection (AtkText *text,
784 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
786 iface = ATK_TEXT_GET_IFACE (text);
788 if (iface->add_selection)
789 return (*(iface->add_selection)) (text, start_offset, end_offset);
795 * atk_text_remove_selection:
797 * @selection_num: The selection number. The selected regions are
798 * assigned numbers that correspond to how far the region is from the
799 * start of the text. The selected region closest to the beginning
800 * of the text region is assigned the number 0, etc. Note that adding,
801 * moving or deleting a selected region can change the numbering.
803 * Removes the specified selection.
805 * Returns: %TRUE if success, %FALSE otherwise
808 atk_text_remove_selection (AtkText *text,
813 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
815 iface = ATK_TEXT_GET_IFACE (text);
817 if (iface->remove_selection)
818 return (*(iface->remove_selection)) (text, selection_num);
824 * atk_text_set_selection:
826 * @selection_num: The selection number. The selected regions are
827 * assigned numbers that correspond to how far the region is from the
828 * start of the text. The selected region closest to the beginning
829 * of the text region is assigned the number 0, etc. Note that adding,
830 * moving or deleting a selected region can change the numbering.
831 * @start_offset: the new start position of the selection
832 * @end_offset: the new end position of the selection
834 * Changes the start and end offset of the specified selection.
836 * Returns: %TRUE if success, %FALSE otherwise
839 atk_text_set_selection (AtkText *text,
846 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
848 iface = ATK_TEXT_GET_IFACE (text);
850 if (iface->set_selection)
852 return (*(iface->set_selection)) (text, selection_num,
853 start_offset, end_offset);
860 * atk_text_set_caret_offset:
864 * Sets the caret (cursor) position to the specified @offset.
866 * Returns: %TRUE if success, %FALSE otherwise.
869 atk_text_set_caret_offset (AtkText *text,
874 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
876 iface = ATK_TEXT_GET_IFACE (text);
878 if (iface->set_caret_offset)
880 return (*(iface->set_caret_offset)) (text, offset);
889 * atk_text_get_range_extents:
891 * @start_offset: The offset of the first text character for which boundary
892 * information is required.
893 * @end_offset: The offset of the text character after the last character
894 * for which boundary information is required.
895 * @coord_type: Specify whether coordinates are relative to the screen or widget window.
896 * @rect: A pointer to a AtkTextRectangle which is filled in by this function.
898 * Get the bounding box for text within the specified range.
901 atk_text_get_range_extents (AtkText *text,
904 AtkCoordType coord_type,
905 AtkTextRectangle *rect)
909 g_return_if_fail (ATK_IS_TEXT (text));
910 g_return_if_fail (rect);
912 if (start_offset < 0 || start_offset >= end_offset)
915 iface = ATK_TEXT_GET_IFACE (text);
917 if (iface->get_range_extents)
918 (*(iface->get_range_extents)) (text, start_offset, end_offset, coord_type, rect);
922 * atk_text_get_bounded_ranges:
924 * @rect: An AtkTextRectagle giving the dimensions of the bounding box.
925 * @coord_type: Specify whether coordinates are relative to the screen or widget window.
926 * @x_clip_type: Specify the horizontal clip type.
927 * @y_clip_type: Specify the vertical clip type.
929 * Get the ranges of text in the specified bounding box.
931 * Returns: Array of AtkTextRange. The last element of the array returned
932 * by this function will be NULL.
935 atk_text_get_bounded_ranges (AtkText *text,
936 AtkTextRectangle *rect,
937 AtkCoordType coord_type,
938 AtkTextClipType x_clip_type,
939 AtkTextClipType y_clip_type)
943 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
944 g_return_val_if_fail (rect, NULL);
946 iface = ATK_TEXT_GET_IFACE (text);
948 if (iface->get_bounded_ranges)
949 return (*(iface->get_bounded_ranges)) (text, rect, coord_type, x_clip_type, y_clip_type);
955 * atk_attribute_set_free:
956 * @attrib_set: The #AtkAttributeSet to free
958 * Frees the memory used by an #AtkAttributeSet, including all its
962 atk_attribute_set_free (AtkAttributeSet *attrib_set)
979 g_slist_free (attrib_set);
983 * atk_text_attribute_register:
984 * @name: a name string
986 * Associate @name with a new #AtkTextAttribute
988 * Returns: an #AtkTextAttribute associated with @name
991 atk_text_attribute_register (const gchar *name)
993 g_return_val_if_fail (name, ATK_TEXT_ATTR_INVALID);
995 if (!extra_attributes)
996 extra_attributes = g_ptr_array_new ();
998 g_ptr_array_add (extra_attributes, g_strdup (name));
999 return extra_attributes->len + ATK_TEXT_ATTR_LAST_DEFINED;
1003 * atk_text_attribute_get_name:
1004 * @attr: The #AtkTextAttribute whose name is required
1006 * Gets the name corresponding to the #AtkTextAttribute
1008 * Returns: a string containing the name; this string should not be freed
1010 G_CONST_RETURN gchar*
1011 atk_text_attribute_get_name (AtkTextAttribute attr)
1013 GTypeClass *type_class;
1017 type_class = g_type_class_ref (ATK_TYPE_TEXT_ATTRIBUTE);
1018 g_return_val_if_fail (G_IS_ENUM_CLASS (type_class), NULL);
1020 value = g_enum_get_value (G_ENUM_CLASS (type_class), attr);
1024 name = value->value_nick;
1028 if (extra_attributes)
1032 n -= ATK_TEXT_ATTR_LAST_DEFINED + 1;
1034 if (n < extra_attributes->len)
1036 name = g_ptr_array_index (extra_attributes, n);
1039 g_type_class_unref (type_class);
1044 * atk_text_attribute_for_name:
1045 * @name: a string which is the (non-localized) name of an ATK text attribute.
1047 * Get the #AtkTextAttribute type corresponding to a text attribute name.
1049 * Returns: the #AtkTextAttribute enumerated type corresponding to the specified
1051 * or #ATK_TEXT_ATTRIBUTE_INVALID if no matching text attribute is found.
1054 atk_text_attribute_for_name (const gchar *name)
1056 GTypeClass *type_class;
1058 AtkTextAttribute type = ATK_TEXT_ATTR_INVALID;
1060 g_return_val_if_fail (name, ATK_TEXT_ATTR_INVALID);
1062 type_class = g_type_class_ref (ATK_TYPE_TEXT_ATTRIBUTE);
1063 g_return_val_if_fail (G_IS_ENUM_CLASS (type_class), ATK_TEXT_ATTR_INVALID);
1065 value = g_enum_get_value_by_nick (G_ENUM_CLASS (type_class), name);
1069 type = value->value;
1075 if (extra_attributes)
1077 for (i = 0; i < extra_attributes->len; i++)
1079 gchar *extra_attribute = (gchar *)g_ptr_array_index (extra_attributes, i);
1081 g_return_val_if_fail (extra_attribute, ATK_TEXT_ATTR_INVALID);
1083 if (strcmp (name, extra_attribute) == 0)
1085 type = i + 1 + ATK_TEXT_ATTR_LAST_DEFINED;
1091 g_type_class_unref (type_class);
1097 * atk_text_attribute_get_value:
1098 * @attr: The #AtkTextAttribute for which a value is required
1099 * @index_: The index of the required value
1101 * Gets the value for the index of the #AtkTextAttribute
1103 * Returns: a string containing the value; this string should not be freed;
1104 * NULL is returned if there are no values maintained for the attr value.
1106 G_CONST_RETURN gchar*
1107 atk_text_attribute_get_value (AtkTextAttribute attr,
1112 case ATK_TEXT_ATTR_INVISIBLE:
1113 case ATK_TEXT_ATTR_EDITABLE:
1114 case ATK_TEXT_ATTR_BG_FULL_HEIGHT:
1115 case ATK_TEXT_ATTR_STRIKETHROUGH:
1116 case ATK_TEXT_ATTR_BG_STIPPLE:
1117 case ATK_TEXT_ATTR_FG_STIPPLE:
1118 g_assert (index >= 0 && index < 2);
1120 case ATK_TEXT_ATTR_UNDERLINE:
1121 g_assert (index >= 0 && index < 4);
1122 return underline[index];
1123 case ATK_TEXT_ATTR_WRAP_MODE:
1124 g_assert (index >= 0 && index < 3);
1125 return wrap_mode[index];
1126 case ATK_TEXT_ATTR_DIRECTION:
1127 g_assert (index >= 0 && index < 3);
1128 return direction[index];
1129 case ATK_TEXT_ATTR_JUSTIFICATION:
1130 g_assert (index >= 0 && index < 3);
1131 return justification[index];
1132 case ATK_TEXT_ATTR_STRETCH:
1133 g_assert (index >= 0 && index < 9);
1134 return stretch[index];
1135 case ATK_TEXT_ATTR_VARIANT:
1136 g_assert (index >= 0 && index < 2);
1137 return variant[index];
1138 case ATK_TEXT_ATTR_STYLE:
1139 g_assert (index >= 0 && index < 3);
1140 return style[index];
1147 atk_text_rectangle_union (AtkTextRectangle *src1,
1148 AtkTextRectangle *src2,
1149 AtkTextRectangle *dest)
1151 gint dest_x, dest_y;
1153 dest_x = MIN (src1->x, src2->x);
1154 dest_y = MIN (src1->y, src2->y);
1155 dest->width = MAX (src1->x + src1->width, src2->x + src2->width) - dest_x;
1156 dest->height = MAX (src1->y + src1->height, src2->y + src2->height) - dest_y;
1162 atk_text_rectangle_contain (AtkTextRectangle *clip,
1163 AtkTextRectangle *bounds,
1164 AtkTextClipType x_clip_type,
1165 AtkTextClipType y_clip_type)
1167 gboolean x_min_ok, x_max_ok, y_min_ok, y_max_ok;
1169 x_min_ok = (bounds->x >= clip->x) ||
1170 ((bounds->x + bounds->width >= clip->x) &&
1171 ((x_clip_type == ATK_TEXT_CLIP_NONE) ||
1172 (x_clip_type == ATK_TEXT_CLIP_MAX)));
1174 x_max_ok = (bounds->x + bounds->width <= clip->x + clip->width) ||
1175 ((bounds->x <= clip->x + clip->width) &&
1176 ((x_clip_type == ATK_TEXT_CLIP_NONE) ||
1177 (x_clip_type == ATK_TEXT_CLIP_MIN)));
1179 y_min_ok = (bounds->y >= clip->y) ||
1180 ((bounds->y + bounds->height >= clip->y) &&
1181 ((y_clip_type == ATK_TEXT_CLIP_NONE) ||
1182 (y_clip_type == ATK_TEXT_CLIP_MAX)));
1184 y_max_ok = (bounds->y + bounds->height <= clip->y + clip->height) ||
1185 ((bounds->y <= clip->y + clip->height) &&
1186 ((y_clip_type == ATK_TEXT_CLIP_NONE) ||
1187 (y_clip_type == ATK_TEXT_CLIP_MIN)));
1189 return (x_min_ok && x_max_ok && y_min_ok && y_max_ok);
1194 atk_text_real_get_range_extents (AtkText *text,
1197 AtkCoordType coord_type,
1198 AtkTextRectangle *rect)
1201 AtkTextRectangle cbounds, bounds;
1203 atk_text_get_character_extents (text, start_offset,
1204 &bounds.x, &bounds.y,
1205 &bounds.width, &bounds.height,
1208 for (i = start_offset + 1; i < end_offset; i++)
1210 atk_text_get_character_extents (text, i,
1211 &cbounds.x, &cbounds.y,
1212 &cbounds.width, &cbounds.height,
1214 atk_text_rectangle_union (&bounds, &cbounds, &bounds);
1219 rect->width = bounds.width;
1220 rect->height = bounds.height;
1223 static AtkTextRange**
1224 atk_text_real_get_bounded_ranges (AtkText *text,
1225 AtkTextRectangle *rect,
1226 AtkCoordType coord_type,
1227 AtkTextClipType x_clip_type,
1228 AtkTextClipType y_clip_type)
1230 gint bounds_min_offset, bounds_max_offset;
1231 gint min_line_start, min_line_end;
1232 gint max_line_start, max_line_end;
1236 gint num_ranges = 0;
1237 gint range_size = 1;
1238 AtkTextRectangle cbounds;
1239 AtkTextRange **range;
1242 bounds_min_offset = atk_text_get_offset_at_point (text, rect->x, rect->y, coord_type);
1243 bounds_max_offset = atk_text_get_offset_at_point (text, rect->x + rect->width, rect->y + rect->height, coord_type);
1245 if (bounds_min_offset == 0 &&
1246 bounds_min_offset == bounds_max_offset)
1249 line = atk_text_get_text_at_offset (text, bounds_min_offset,
1250 ATK_TEXT_BOUNDARY_LINE_START,
1251 &min_line_start, &min_line_end);
1253 line = atk_text_get_text_at_offset (text, bounds_max_offset,
1254 ATK_TEXT_BOUNDARY_LINE_START,
1255 &max_line_start, &max_line_end);
1257 bounds_min_offset = MIN (min_line_start, max_line_start);
1258 bounds_max_offset = MAX (min_line_end, max_line_end);
1260 curr_offset = bounds_min_offset;
1261 while (curr_offset < bounds_max_offset)
1263 offset = curr_offset;
1265 while (curr_offset < bounds_max_offset)
1267 atk_text_get_character_extents (text, curr_offset,
1268 &cbounds.x, &cbounds.y,
1269 &cbounds.width, &cbounds.height,
1271 if (!atk_text_rectangle_contain (rect, &cbounds, x_clip_type, y_clip_type))
1275 if (curr_offset > offset)
1277 AtkTextRange *one_range = g_new (AtkTextRange, 1);
1279 one_range->start_offset = offset;
1280 one_range->end_offset = curr_offset;
1281 one_range->content = atk_text_get_text (text, offset, curr_offset);
1282 atk_text_get_range_extents (text, offset, curr_offset, coord_type, &one_range->bounds);
1284 if (num_ranges >= range_size - 1)
1287 range = g_realloc (range, range_size * sizeof (gpointer));
1289 range[num_ranges] = one_range;
1294 range[num_ranges] = NULL;
1300 * atk_text_free_ranges:
1301 * @ranges: A pointer to an array of #AtkTextRange which is to be freed.
1303 * Frees the memory associated with an array of AtkTextRange. It is assumed
1304 * that the array was returned by the function atk_text_get_bounded_ranges
1305 * and is NULL terminated.
1308 atk_text_free_ranges (AtkTextRange **ranges)
1310 AtkTextRange **first = ranges;
1316 AtkTextRange *range;
1320 g_free (range->content);