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 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 (gpointer *g_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 };
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 (gpointer *g_class)
109 static gboolean initialized = FALSE;
114 * Note that text_changed signal supports details "insert", "delete",
115 * possibly "replace".
118 atk_text_signals[TEXT_CHANGED] =
119 g_signal_new ("text_changed",
121 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
122 G_STRUCT_OFFSET (AtkTextIface, text_changed),
123 (GSignalAccumulator) NULL, NULL,
124 atk_marshal_VOID__INT_INT,
126 2, G_TYPE_INT, G_TYPE_INT);
128 atk_text_signals[TEXT_CARET_MOVED] =
129 g_signal_new ("text_caret_moved",
132 G_STRUCT_OFFSET (AtkTextIface, text_caret_moved),
133 (GSignalAccumulator) NULL, NULL,
134 g_cclosure_marshal_VOID__INT,
137 atk_text_signals[TEXT_SELECTION_CHANGED] =
138 g_signal_new ("text_selection_changed",
141 G_STRUCT_OFFSET (AtkTextIface, text_selection_changed),
142 (GSignalAccumulator) NULL, NULL,
143 g_cclosure_marshal_VOID__VOID,
145 atk_text_signals[TEXT_ATTRIBUTES_CHANGED] =
146 g_signal_new ("text_attributes_changed",
149 G_STRUCT_OFFSET (AtkTextIface, text_attributes_changed),
150 (GSignalAccumulator) NULL, NULL,
151 g_cclosure_marshal_VOID__VOID,
162 * @start_offset: start position
163 * @end_offset: end position
165 * Gets the specified text.
167 * Returns: the text from @start_offset up to, but not including @end_offset.
170 atk_text_get_text (AtkText *text,
176 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
178 iface = ATK_TEXT_GET_IFACE (text);
180 if (start_offset < 0 || end_offset < -1)
184 return (*(iface->get_text)) (text, start_offset, end_offset);
190 * atk_text_get_character_at_offset:
194 * Gets the specified text.
196 * Returns: the character at @offset.
199 atk_text_get_character_at_offset (AtkText *text,
204 g_return_val_if_fail (ATK_IS_TEXT (text), (gunichar) 0);
209 iface = ATK_TEXT_GET_IFACE (text);
211 if (iface->get_character_at_offset)
212 return (*(iface->get_character_at_offset)) (text, offset);
218 * atk_text_get_text_after_offset:
221 * @boundary_type: An #AtkTextBoundary
222 * @start_offset: the start offset of the returned string.
223 * @end_offset: the end offset of the returned string.
225 * Gets the specified text.
227 * If the boundary_type if ATK_TEXT_BOUNDARY_CHAR the character after the
228 * offset is returned.
230 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START the returned string
231 * is from the word start after the offset to the next word start.
233 * The returned string will contain the word after the offset if the offset
234 * is inside a word or if the offset is not inside a word.
236 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_END the returned string
237 * is from the word end at or after the offset to the next work end.
239 * The returned string will contain the word after the offset if the offset
240 * is inside a word and will contain the word after the word after the offset
241 * if the offset is not inside a word.
243 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the returned
244 * string is from the sentence start after the offset to the next sentence
247 * The returned string will contain the sentence after the offset if the offset
248 * is inside a sentence or if the offset is not inside a sentence.
250 * If the boundary_type is ATK_TEXT_BOUNDARY_SENTENCE_END the returned string
251 * is from the sentence end at or after the offset to the next sentence end.
253 * The returned string will contain the sentence after the offset if the offset
254 * is inside a sentence and will contain the sentence after the sentence
255 * after the offset if the offset is not inside a sentence.
257 * If the boundary type is ATK_TEXT_BOUNDARY_LINE_START the returned
258 * string is from the line start after the offset to the next line start.
260 * If the boundary_type is ATK_TEXT_BOUNDARY_LINE_END the returned string
261 * is from the line end at or after the offset to the next line start.
263 * Returns: the text after @offset bounded by the specified @boundary_type.
266 atk_text_get_text_after_offset (AtkText *text,
268 AtkTextBoundary boundary_type,
273 gint local_start_offset, local_end_offset;
274 gint *real_start_offset, *real_end_offset;
276 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
279 real_start_offset = start_offset;
281 real_start_offset = &local_start_offset;
283 real_end_offset = end_offset;
285 real_end_offset = &local_end_offset;
290 iface = ATK_TEXT_GET_IFACE (text);
292 if (iface->get_text_after_offset)
293 return (*(iface->get_text_after_offset)) (text, offset, boundary_type, real_start_offset, real_end_offset);
299 * atk_text_get_text_at_offset:
302 * @boundary_type: An #AtkTextBoundary
303 * @start_offset: the start offset of the returned string.
304 * @end_offset: the end offset of the returned string.
306 * Gets the specified text.
308 * If the boundary_type if ATK_TEXT_BOUNDARY_CHAR the character at the
309 * offset is returned.
311 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START the returned string
312 * is from the word start at or before the offset to the word start after
315 * The returned string will contain the word at the offset if the offset
316 * is inside a word and will contain the word before the offset if the
317 * offset is not inside a word.
319 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_END the returned string
320 * is from the word end before the offset to the word end at or after the
323 * The returned string will contain the word at the offset if the offset
324 * is inside a word and will contain the word after to the offset if the
325 * offset is not inside a word.
327 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the returned
328 * string is from the sentence start at or before the offset to the sentence
329 * start after the offset.
331 * The returned string will contain the sentence at the offset if the offset
332 * is inside a sentence and will contain the sentence before the offset
333 * if the offset is not inside a sentence.
335 * If the boundary_type is ATK_TEXT_BOUNDARY_SENTENCE_END the returned string
336 * is from the sentence end before the offset to the sentence end at or
339 * The returned string will contain the sentence at the offset if the offset
340 * is inside a sentence and will contain the sentence after the offset
341 * if the offset is not inside a sentence.
343 * If the boundary type is ATK_TEXT_BOUNDARY_LINE_START the returned
344 * string is from the line start at or before the offset to the line
345 * start after the offset.
347 * If the boundary_type is ATK_TEXT_BOUNDARY_LINE_END the returned string
348 * is from the line end before the offset to the line end at or after
351 * Returns: the text at @offset bounded by the specified @boundary_type.
354 atk_text_get_text_at_offset (AtkText *text,
356 AtkTextBoundary boundary_type,
361 gint local_start_offset, local_end_offset;
362 gint *real_start_offset, *real_end_offset;
364 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
367 real_start_offset = start_offset;
369 real_start_offset = &local_start_offset;
371 real_end_offset = end_offset;
373 real_end_offset = &local_end_offset;
378 iface = ATK_TEXT_GET_IFACE (text);
380 if (iface->get_text_at_offset)
381 return (*(iface->get_text_at_offset)) (text, offset, boundary_type, real_start_offset, real_end_offset);
387 * atk_text_get_text_before_offset:
390 * @boundary_type: An #AtkTextBoundary
391 * @start_offset: the start offset of the returned string.
392 * @end_offset: the end offset of the returned string.
394 * Gets the specified text.
396 * If the boundary_type if ATK_TEXT_BOUNDARY_CHAR the character before the
397 * offset is returned.
399 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START the returned string
400 * is from the word start before the word start before the offset to
401 * the word start before the offset.
403 * The returned string will contain the word before the offset if the offset
404 * is inside a word and will contain the word before the word before the
405 * offset if the offset is not inside a word.
407 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_END the returned string
408 * is from the word end before the word end at or before the offset to the
409 * word end at or before the offset.
411 * The returned string will contain the word before the offset if the offset
412 * is inside a word or if the offset is not inside a word.
414 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the returned
415 * string is from the sentence start before the sentence start before
416 * the offset to the sentence start before the offset.
418 * The returned string will contain the sentence before the offset if the
419 * offset is inside a sentence and will contain the sentence before the
420 * sentence before the offset if the offset is not inside a sentence.
422 * If the boundary_type is ATK_TEXT_BOUNDARY_SENTENCE_END the returned string
423 * is from the sentence end before the sentence end at or before the offset to
424 * the sentence end at or before the offset.
426 * The returned string will contain the sentence before the offset if the
427 * offset is inside a sentence or if the offset is not inside a sentence.
429 * If the boundary type is ATK_TEXT_BOUNDARY_LINE_START the returned
430 * string is from the line start before the line start ar or before the offset
431 * to the line start ar or before the offset.
433 * If the boundary_type is ATK_TEXT_BOUNDARY_LINE_END the returned string
434 * is from the line end before the line end before the offset to the
435 * line end before the offset.
437 * Returns: the text before @offset bounded by the specified @boundary_type.
440 atk_text_get_text_before_offset (AtkText *text,
442 AtkTextBoundary boundary_type,
447 gint local_start_offset, local_end_offset;
448 gint *real_start_offset, *real_end_offset;
450 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
453 real_start_offset = start_offset;
455 real_start_offset = &local_start_offset;
457 real_end_offset = end_offset;
459 real_end_offset = &local_end_offset;
464 iface = ATK_TEXT_GET_IFACE (text);
466 if (iface->get_text_before_offset)
467 return (*(iface->get_text_before_offset)) (text, offset, boundary_type, real_start_offset, real_end_offset);
473 * atk_text_get_caret_offset:
476 * Gets the offset position of the caret (cursor).
478 * Returns: the offset position of the caret (cursor).
481 atk_text_get_caret_offset (AtkText *text)
485 g_return_val_if_fail (ATK_IS_TEXT (text), 0);
487 iface = ATK_TEXT_GET_IFACE (text);
489 if (iface->get_caret_offset)
490 return (*(iface->get_caret_offset)) (text);
496 * atk_text_get_character_extents:
498 * @offset: The offset of the text character for which bounding information is required.
499 * @x: Pointer for the x cordinate of the bounding box.
500 * @y: Pointer for the y cordinate of the bounding box.
501 * @width: Pointer for the width of the bounding box
502 * @height: Pointer for the height of the bounding box.
503 * @coords: specify whether coordinates are relative to the screen or widget window
505 * Get the bounding box containing the glyph representing the character at
506 * a particular text offset.
509 atk_text_get_character_extents (AtkText *text,
518 gint local_x, local_y, local_width, local_height;
519 gint *real_x, *real_y, *real_width, *real_height;
521 g_return_if_fail (ATK_IS_TEXT (text));
534 real_width = &local_width;
536 real_height = height;
538 real_height = &local_height;
548 iface = ATK_TEXT_GET_IFACE (text);
550 if (iface->get_character_extents)
551 (*(iface->get_character_extents)) (text, offset, real_x, real_y, real_width, real_height, coords);
555 *real_x = *real_x + *real_width;
561 *atk_text_get_run_attributes:
563 *@offset: the offset at which to get the attributes
564 *@start_offset: the address to put the start offset of the range
565 *@end_offset: the address to put the end offset of the range
567 *Creates an #AtkAttributeSet which consists of the attributes explicitly
568 *set at the position @offset in the text. @start_offset and @end_offset are
569 *set to the start and end of the range around @offset where the attributes are
570 *invariant. See the enum AtkTextAttribute for types of text attributes that
571 *can be returned. Note that other attributes may also be returned.
573 *Returns: an #AtkAttributeSet which contains the attributes explicitly set
574 *at @offset. This #AtkAttributeSet should be freed by a call to
575 *atk_attribute_set_free().
578 atk_text_get_run_attributes (AtkText *text,
584 gint local_start_offset, local_end_offset;
585 gint *real_start_offset, *real_end_offset;
587 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
590 real_start_offset = start_offset;
592 real_start_offset = &local_start_offset;
594 real_end_offset = end_offset;
596 real_end_offset = &local_end_offset;
601 iface = ATK_TEXT_GET_IFACE (text);
603 if (iface->get_run_attributes)
604 return (*(iface->get_run_attributes)) (text, offset, real_start_offset, real_end_offset);
610 *atk_text_get_default_attributes:
613 *Creates an #AtkAttributeSet which consists of the default values of
614 *attributes for the text. See the enum AtkTextAttribute for types of text
615 *attributes that can be returned. Note that other attributes may also be
618 *Returns: an #AtkAttributeSet which contains the default values of attributes.
619 *at @offset. This #AtkAttributeSet should be freed by a call to
620 *atk_attribute_set_free().
623 atk_text_get_default_attributes (AtkText *text)
627 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
629 iface = ATK_TEXT_GET_IFACE (text);
631 if (iface->get_default_attributes)
632 return (*(iface->get_default_attributes)) (text);
638 * atk_text_get_character_count:
641 * Gets the character count.
643 * Returns: the number of characters.
646 atk_text_get_character_count (AtkText *text)
650 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
652 iface = ATK_TEXT_GET_IFACE (text);
654 if (iface->get_character_count)
655 return (*(iface->get_character_count)) (text);
661 * atk_text_get_offset_at_point:
663 * @x: screen x-position of character
664 * @y: screen y-position of character
665 * @coords: specify whether coordinates are relative to the screen or
668 * Gets the offset of the character located at coordinates @x and @y. @x and @y
669 * are interpreted as being relative to the screen or this widget's window
670 * depending on @coords.
672 * Returns: the offset to the character which is located at
673 * the specified @x and @y coordinates.
676 atk_text_get_offset_at_point (AtkText *text,
683 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
685 iface = ATK_TEXT_GET_IFACE (text);
687 if (iface->get_offset_at_point)
688 return (*(iface->get_offset_at_point)) (text, x, y, coords);
694 * atk_text_get_n_selections:
697 * Gets the number of selected regions.
699 * Returns: The number of selected regions, or -1 if a failure
703 atk_text_get_n_selections (AtkText *text)
707 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
709 iface = ATK_TEXT_GET_IFACE (text);
711 if (iface->get_n_selections)
712 return (*(iface->get_n_selections)) (text);
718 * atk_text_get_selection:
720 * @selection_num: The selection number. The selected regions are
721 * assigned numbers that correspond to how far the region is from the
722 * start of the text. The selected region closest to the beginning
723 * of the text region is assigned the number 0, etc. Note that adding,
724 * moving or deleting a selected region can change the numbering.
725 * @start_offset: passes back the start position of the selected region
726 * @end_offset: passes back the end position of the selected region
728 * Gets the text from the specified selection.
730 * Returns: the selected text.
733 atk_text_get_selection (AtkText *text,
739 gint local_start_offset, local_end_offset;
740 gint *real_start_offset, *real_end_offset;
742 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
745 real_start_offset = start_offset;
747 real_start_offset = &local_start_offset;
749 real_end_offset = end_offset;
751 real_end_offset = &local_end_offset;
753 iface = ATK_TEXT_GET_IFACE (text);
755 if (iface->get_selection)
757 return (*(iface->get_selection)) (text, selection_num,
758 real_start_offset, real_end_offset);
765 * atk_text_add_selection:
767 * @start_offset: the start position of the selected region
768 * @end_offset: the end position of the selected region
770 * Adds a selection bounded by the specified offsets.
772 * Returns: %TRUE if success, %FALSE otherwise
775 atk_text_add_selection (AtkText *text,
781 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
783 iface = ATK_TEXT_GET_IFACE (text);
785 if (iface->add_selection)
786 return (*(iface->add_selection)) (text, start_offset, end_offset);
792 * atk_text_remove_selection:
794 * @selection_num: The selection number. The selected regions are
795 * assigned numbers that correspond to how far the region is from the
796 * start of the text. The selected region closest to the beginning
797 * of the text region is assigned the number 0, etc. Note that adding,
798 * moving or deleting a selected region can change the numbering.
800 * Removes the specified selection.
802 * Returns: %TRUE if success, %FALSE otherwise
805 atk_text_remove_selection (AtkText *text,
810 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
812 iface = ATK_TEXT_GET_IFACE (text);
814 if (iface->remove_selection)
815 return (*(iface->remove_selection)) (text, selection_num);
821 * atk_text_set_selection:
823 * @selection_num: The selection number. The selected regions are
824 * assigned numbers that correspond to how far the region is from the
825 * start of the text. The selected region closest to the beginning
826 * of the text region is assigned the number 0, etc. Note that adding,
827 * moving or deleting a selected region can change the numbering.
828 * @start_offset: the new start position of the selection
829 * @end_offset: the new end position of the selection
831 * Changes the start and end offset of the specified selection.
833 * Returns: %TRUE if success, %FALSE otherwise
836 atk_text_set_selection (AtkText *text,
843 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
845 iface = ATK_TEXT_GET_IFACE (text);
847 if (iface->set_selection)
849 return (*(iface->set_selection)) (text, selection_num,
850 start_offset, end_offset);
857 * atk_text_set_caret_offset:
861 * Sets the caret (cursor) position to the specified @offset.
863 * Returns: %TRUE if success, %FALSE otherwise.
866 atk_text_set_caret_offset (AtkText *text,
871 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
873 iface = ATK_TEXT_GET_IFACE (text);
875 if (iface->set_caret_offset)
877 return (*(iface->set_caret_offset)) (text, offset);
886 * atk_text_get_range_extents:
888 * @start_offset: The offset of the first text character for which boundary
889 * information is required.
890 * @end_offset: The offset of the text character after the last character
891 * for which boundary information is required.
892 * @coord_type: Specify whether coordinates are relative to the screen or widget window.
893 * @rect: A pointer to a AtkTextRectangle which is filled in by this function.
895 * Get the bounding box for text within the specified range.
898 atk_text_get_range_extents (AtkText *text,
901 AtkCoordType coord_type,
902 AtkTextRectangle *rect)
906 g_return_if_fail (ATK_IS_TEXT (text));
907 g_return_if_fail (rect);
909 if (start_offset < 0 || start_offset >= end_offset)
912 iface = ATK_TEXT_GET_IFACE (text);
914 if (iface->get_range_extents)
915 (*(iface->get_range_extents)) (text, start_offset, end_offset, coord_type, rect);
917 atk_text_real_get_range_extents (text, start_offset, end_offset, coord_type, rect);
921 * atk_text_get_bounded_ranges:
923 * @rect: An AtkTextRectagle giving the dimensions of the bounding box.
924 * @coord_type: Specify whether coordinates are relative to the screen or widget window.
925 * @x_clip_type: Specify the horizontal clip type.
926 * @y_clip_type: Specify the vertical clip type.
928 * Get the ranges of text in the specified bounding box.
930 * Returns: Array of AtkTextRange. The last element of the array returned
931 * by this function will be NULL.
934 atk_text_get_bounded_ranges (AtkText *text,
935 AtkTextRectangle *rect,
936 AtkCoordType coord_type,
937 AtkTextClipType x_clip_type,
938 AtkTextClipType y_clip_type)
942 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
943 g_return_val_if_fail (rect, NULL);
945 iface = ATK_TEXT_GET_IFACE (text);
947 if (iface->get_bounded_ranges)
948 return (*(iface->get_bounded_ranges)) (text, rect, coord_type, x_clip_type, y_clip_type);
950 return atk_text_real_get_bounded_ranges (text, rect, coord_type, x_clip_type, y_clip_type);
954 * atk_attribute_set_free:
955 * @attrib_set: The #AtkAttributeSet to free
957 * Frees the memory used by an #AtkAttributeSet, including all its
961 atk_attribute_set_free (AtkAttributeSet *attrib_set)
978 g_slist_free (attrib_set);
982 * atk_text_attribute_register:
983 * @name: a name string
985 * Associate @name with a new #AtkTextAttribute
987 * Returns: an #AtkTextAttribute associated with @name
990 atk_text_attribute_register (const gchar *name)
992 g_return_val_if_fail (name, ATK_TEXT_ATTR_INVALID);
994 if (!extra_attributes)
995 extra_attributes = g_ptr_array_new ();
997 g_ptr_array_add (extra_attributes, g_strdup (name));
998 return extra_attributes->len + ATK_TEXT_ATTR_LAST_DEFINED;
1002 * atk_text_attribute_get_name:
1003 * @attr: The #AtkTextAttribute whose name is required
1005 * Gets the name corresponding to the #AtkTextAttribute
1007 * Returns: a string containing the name; this string should not be freed
1009 G_CONST_RETURN gchar*
1010 atk_text_attribute_get_name (AtkTextAttribute attr)
1012 GTypeClass *type_class;
1016 type_class = g_type_class_ref (ATK_TYPE_TEXT_ATTRIBUTE);
1017 g_return_val_if_fail (G_IS_ENUM_CLASS (type_class), NULL);
1019 value = g_enum_get_value (G_ENUM_CLASS (type_class), attr);
1023 name = value->value_nick;
1027 if (extra_attributes)
1031 n -= ATK_TEXT_ATTR_LAST_DEFINED + 1;
1033 if (n < extra_attributes->len)
1035 name = g_ptr_array_index (extra_attributes, n);
1038 g_type_class_unref (type_class);
1043 * atk_text_attribute_for_name:
1044 * @name: a string which is the (non-localized) name of an ATK text attribute.
1046 * Get the #AtkTextAttribute type corresponding to a text attribute name.
1048 * Returns: the #AtkTextAttribute enumerated type corresponding to the specified
1050 * or #ATK_TEXT_ATTRIBUTE_INVALID if no matching text attribute is found.
1053 atk_text_attribute_for_name (const gchar *name)
1055 GTypeClass *type_class;
1057 AtkTextAttribute type = ATK_TEXT_ATTR_INVALID;
1059 g_return_val_if_fail (name, ATK_TEXT_ATTR_INVALID);
1061 type_class = g_type_class_ref (ATK_TYPE_TEXT_ATTRIBUTE);
1062 g_return_val_if_fail (G_IS_ENUM_CLASS (type_class), ATK_TEXT_ATTR_INVALID);
1064 value = g_enum_get_value_by_nick (G_ENUM_CLASS (type_class), name);
1068 type = value->value;
1074 if (extra_attributes)
1076 for (i = 0; i < extra_attributes->len; i++)
1078 gchar *extra_attribute = (gchar *)g_ptr_array_index (extra_attributes, i);
1080 g_return_val_if_fail (extra_attribute, ATK_TEXT_ATTR_INVALID);
1082 if (strcmp (name, extra_attribute) == 0)
1084 type = i + 1 + ATK_TEXT_ATTR_LAST_DEFINED;
1090 g_type_class_unref (type_class);
1096 * atk_text_attribute_get_value:
1097 * @attr: The #AtkTextAttribute for which a value is required
1098 * @index_: The index of the required value
1100 * Gets the value for the index of the #AtkTextAttribute
1102 * Returns: a string containing the value; this string should not be freed;
1103 * NULL is returned if there are no values maintained for the attr value.
1105 G_CONST_RETURN gchar*
1106 atk_text_attribute_get_value (AtkTextAttribute attr,
1111 case ATK_TEXT_ATTR_INVISIBLE:
1112 case ATK_TEXT_ATTR_EDITABLE:
1113 case ATK_TEXT_ATTR_BG_FULL_HEIGHT:
1114 case ATK_TEXT_ATTR_STRIKETHROUGH:
1115 case ATK_TEXT_ATTR_BG_STIPPLE:
1116 case ATK_TEXT_ATTR_FG_STIPPLE:
1117 g_assert (index >= 0 && index < 2);
1119 case ATK_TEXT_ATTR_UNDERLINE:
1120 g_assert (index >= 0 && index < 4);
1121 return underline[index];
1122 case ATK_TEXT_ATTR_WRAP_MODE:
1123 g_assert (index >= 0 && index < 3);
1124 return wrap_mode[index];
1125 case ATK_TEXT_ATTR_DIRECTION:
1126 g_assert (index >= 0 && index < 3);
1127 return direction[index];
1128 case ATK_TEXT_ATTR_JUSTIFICATION:
1129 g_assert (index >= 0 && index < 3);
1130 return justification[index];
1131 case ATK_TEXT_ATTR_STRETCH:
1132 g_assert (index >= 0 && index < 9);
1133 return stretch[index];
1134 case ATK_TEXT_ATTR_VARIANT:
1135 g_assert (index >= 0 && index < 2);
1136 return variant[index];
1137 case ATK_TEXT_ATTR_STYLE:
1138 g_assert (index >= 0 && index < 3);
1139 return style[index];
1146 atk_text_rectangle_union (AtkTextRectangle *src1,
1147 AtkTextRectangle *src2,
1148 AtkTextRectangle *dest)
1150 gint dest_x, dest_y;
1152 dest_x = MIN (src1->x, src2->x);
1153 dest_y = MIN (src1->y, src2->y);
1154 dest->width = MAX (src1->x + src1->width, src2->x + src2->width) - dest_x;
1155 dest->height = MAX (src1->y + src1->height, src2->y + src2->height) - dest_y;
1161 atk_text_rectangle_contain (AtkTextRectangle *clip,
1162 AtkTextRectangle *bounds,
1163 AtkTextClipType x_clip_type,
1164 AtkTextClipType y_clip_type)
1166 gboolean x_min_ok, x_max_ok, y_min_ok, y_max_ok;
1168 x_min_ok = (bounds->x >= clip->x) ||
1169 ((bounds->x + bounds->width >= clip->x) &&
1170 ((x_clip_type == ATK_TEXT_CLIP_NONE) ||
1171 (x_clip_type == ATK_TEXT_CLIP_MAX)));
1173 x_max_ok = (bounds->x + bounds->width <= clip->x + clip->width) ||
1174 ((bounds->x <= clip->x + clip->width) &&
1175 ((x_clip_type == ATK_TEXT_CLIP_NONE) ||
1176 (x_clip_type == ATK_TEXT_CLIP_MIN)));
1178 y_min_ok = (bounds->y >= clip->y) ||
1179 ((bounds->y + bounds->height >= clip->y) &&
1180 ((y_clip_type == ATK_TEXT_CLIP_NONE) ||
1181 (y_clip_type == ATK_TEXT_CLIP_MAX)));
1183 y_max_ok = (bounds->y + bounds->height <= clip->y + clip->height) ||
1184 ((bounds->y <= clip->y + clip->height) &&
1185 ((y_clip_type == ATK_TEXT_CLIP_NONE) ||
1186 (y_clip_type == ATK_TEXT_CLIP_MIN)));
1188 return (x_min_ok && x_max_ok && y_min_ok && y_max_ok);
1193 atk_text_real_get_range_extents (AtkText *text,
1196 AtkCoordType coord_type,
1197 AtkTextRectangle *rect)
1200 AtkTextRectangle cbounds, bounds;
1202 atk_text_get_character_extents (text, start_offset,
1203 &bounds.x, &bounds.y,
1204 &bounds.width, &bounds.height,
1207 for (i = start_offset + 1; i < end_offset; i++)
1209 atk_text_get_character_extents (text, i,
1210 &cbounds.x, &cbounds.y,
1211 &cbounds.width, &cbounds.height,
1213 atk_text_rectangle_union (&bounds, &cbounds, &bounds);
1218 rect->width = bounds.width;
1219 rect->height = bounds.height;
1222 static AtkTextRange**
1223 atk_text_real_get_bounded_ranges (AtkText *text,
1224 AtkTextRectangle *rect,
1225 AtkCoordType coord_type,
1226 AtkTextClipType x_clip_type,
1227 AtkTextClipType y_clip_type)
1229 gint bounds_min_offset, bounds_max_offset;
1230 gint min_line_start, min_line_end;
1231 gint max_line_start, max_line_end;
1235 gint num_ranges = 0;
1236 gint range_size = 1;
1237 AtkTextRectangle cbounds;
1238 AtkTextRange **range;
1241 bounds_min_offset = atk_text_get_offset_at_point (text, rect->x, rect->y, coord_type);
1242 bounds_max_offset = atk_text_get_offset_at_point (text, rect->x + rect->width, rect->y + rect->height, coord_type);
1244 if (bounds_min_offset == 0 &&
1245 bounds_min_offset == bounds_max_offset)
1248 line = atk_text_get_text_at_offset (text, bounds_min_offset,
1249 ATK_TEXT_BOUNDARY_LINE_START,
1250 &min_line_start, &min_line_end);
1252 line = atk_text_get_text_at_offset (text, bounds_max_offset,
1253 ATK_TEXT_BOUNDARY_LINE_START,
1254 &max_line_start, &max_line_end);
1256 bounds_min_offset = MIN (min_line_start, max_line_start);
1257 bounds_max_offset = MAX (min_line_end, max_line_end);
1259 curr_offset = bounds_min_offset;
1260 while (curr_offset < bounds_max_offset)
1262 offset = curr_offset;
1264 while (curr_offset < bounds_max_offset)
1266 atk_text_get_character_extents (text, curr_offset,
1267 &cbounds.x, &cbounds.y,
1268 &cbounds.width, &cbounds.height,
1270 if (!atk_text_rectangle_contain (rect, &cbounds, x_clip_type, y_clip_type))
1274 if (curr_offset > offset)
1276 AtkTextRange *one_range = g_new (AtkTextRange, 1);
1278 one_range->start_offset = offset;
1279 one_range->end_offset = curr_offset;
1280 one_range->content = atk_text_get_text (text, offset, curr_offset);
1281 atk_text_get_range_extents (text, offset, curr_offset, coord_type, &one_range->bounds);
1283 if (num_ranges >= range_size - 1)
1286 range = g_realloc (range, range_size * sizeof (gpointer));
1288 range[num_ranges] = one_range;
1293 range[num_ranges] = NULL;
1299 * atk_text_free_ranges:
1300 * @ranges: A pointer to an array of #AtkTextRange which is to be freed.
1302 * Frees the memory associated with an array of AtkTextRange. It is assumed
1303 * that the array was returned by the function atk_text_get_bounded_ranges
1304 * and is NULL terminated.
1307 atk_text_free_ranges (AtkTextRange **ranges)
1313 AtkTextRange *range;
1317 g_free (range->content);