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,
39 static const char boolean[] =
42 static const guint8 boolean_offsets[] = {
46 static const char style[] =
50 static const guint8 style_offsets[] = {
54 static const char variant[] =
57 static const guint8 variant_offsets[] = {
61 static const char stretch[] =
71 static const guint8 stretch_offsets[] = {
72 0, 16, 32, 42, 57, 64, 78, 87, 102
75 static const char justification[] =
80 static const guint8 justification_offsets[] = {
84 static const char direction[] =
88 static const guint8 direction_offsets[] = {
92 static const char wrap_mode[] =
97 static const guint8 wrap_mode_offsets[] = {
101 static const char underline[] =
107 static const guint8 underline_offsets[] = {
111 static void atk_text_base_init (AtkTextIface *class);
113 static void atk_text_real_get_range_extents (AtkText *text,
116 AtkCoordType coord_type,
117 AtkTextRectangle *rect);
119 static AtkTextRange** atk_text_real_get_bounded_ranges (AtkText *text,
120 AtkTextRectangle *rect,
121 AtkCoordType coord_type,
122 AtkTextClipType x_clip_type,
123 AtkTextClipType y_clip_type);
125 static guint atk_text_signals[LAST_SIGNAL] = { 0 };
128 atk_text_get_type (void)
130 static GType type = 0;
134 static const GTypeInfo tinfo =
136 sizeof (AtkTextIface),
137 (GBaseInitFunc) atk_text_base_init,
138 (GBaseFinalizeFunc) NULL,
139 (GClassInitFunc) NULL /* atk_text_interface_init */ ,
140 (GClassFinalizeFunc) NULL,
144 type = g_type_register_static (G_TYPE_INTERFACE, "AtkText", &tinfo, 0);
151 atk_text_base_init (AtkTextIface *class)
153 static gboolean initialized = FALSE;
158 * Note that text_changed signal supports details "insert", "delete",
159 * possibly "replace".
162 class->get_range_extents = atk_text_real_get_range_extents;
163 class->get_bounded_ranges = atk_text_real_get_bounded_ranges;
165 atk_text_signals[TEXT_CHANGED] =
166 g_signal_new ("text_changed",
168 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
169 G_STRUCT_OFFSET (AtkTextIface, text_changed),
170 (GSignalAccumulator) NULL, NULL,
171 atk_marshal_VOID__INT_INT,
173 2, G_TYPE_INT, G_TYPE_INT);
175 atk_text_signals[TEXT_INSERT] =
176 g_signal_new ("text_insert",
178 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
180 (GSignalAccumulator) NULL, NULL,
181 atk_marshal_VOID__INT_INT_STRING,
183 3, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING);
185 atk_text_signals[TEXT_REMOVE] =
186 g_signal_new ("text_remove",
188 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
190 (GSignalAccumulator) NULL, NULL,
191 atk_marshal_VOID__INT_INT_STRING,
193 3, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING);
195 atk_text_signals[TEXT_UPDATE] =
196 g_signal_new ("text_update",
198 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
200 (GSignalAccumulator) NULL, NULL,
201 atk_marshal_VOID__INT_INT_INT_STRING,
203 4, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING);
205 atk_text_signals[TEXT_CARET_MOVED] =
206 g_signal_new ("text_caret_moved",
209 G_STRUCT_OFFSET (AtkTextIface, text_caret_moved),
210 (GSignalAccumulator) NULL, NULL,
211 g_cclosure_marshal_VOID__INT,
214 atk_text_signals[TEXT_SELECTION_CHANGED] =
215 g_signal_new ("text_selection_changed",
218 G_STRUCT_OFFSET (AtkTextIface, text_selection_changed),
219 (GSignalAccumulator) NULL, NULL,
220 g_cclosure_marshal_VOID__VOID,
222 atk_text_signals[TEXT_ATTRIBUTES_CHANGED] =
223 g_signal_new ("text_attributes_changed",
226 G_STRUCT_OFFSET (AtkTextIface, text_attributes_changed),
227 (GSignalAccumulator) NULL, NULL,
228 g_cclosure_marshal_VOID__VOID,
239 * @start_offset: start position
240 * @end_offset: end position, or -1 for the end of the string.
242 * Gets the specified text.
244 * Returns: a newly allocated string containing the text from @start_offset up
245 * to, but not including @end_offset. Use g_free() to free the returned string.
248 atk_text_get_text (AtkText *text,
254 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
256 iface = ATK_TEXT_GET_IFACE (text);
258 if (start_offset < 0 || end_offset < -1 ||
259 (end_offset != -1 && end_offset < start_offset))
263 return (*(iface->get_text)) (text, start_offset, end_offset);
269 * atk_text_get_character_at_offset:
273 * Gets the specified text.
275 * Returns: the character at @offset.
278 atk_text_get_character_at_offset (AtkText *text,
283 g_return_val_if_fail (ATK_IS_TEXT (text), (gunichar) 0);
285 iface = ATK_TEXT_GET_IFACE (text);
287 if (iface->get_character_at_offset)
288 return (*(iface->get_character_at_offset)) (text, offset);
294 * atk_text_get_text_after_offset:
297 * @boundary_type: An #AtkTextBoundary
298 * @start_offset: the start offset of the returned string
299 * @end_offset: the offset of the first character after the
302 * Gets the specified text.
304 * If the boundary_type if ATK_TEXT_BOUNDARY_CHAR the character after the
305 * offset is returned.
307 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START the returned string
308 * is from the word start after the offset to the next word start.
310 * The returned string will contain the word after the offset if the offset
311 * is inside a word or if the offset is not inside a word.
313 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_END the returned string
314 * is from the word end at or after the offset to the next work end.
316 * The returned string will contain the word after the offset if the offset
317 * is inside a word and will contain the word after the word after the offset
318 * if the offset is not inside a word.
320 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the returned
321 * string is from the sentence start after the offset to the next sentence
324 * The returned string will contain the sentence after the offset if the offset
325 * is inside a sentence or if the offset is not inside a sentence.
327 * If the boundary_type is ATK_TEXT_BOUNDARY_SENTENCE_END the returned string
328 * is from the sentence end at or after the offset to the next sentence end.
330 * The returned string will contain the sentence after the offset if the offset
331 * is inside a sentence and will contain the sentence after the sentence
332 * after the offset if the offset is not inside a sentence.
334 * If the boundary type is ATK_TEXT_BOUNDARY_LINE_START the returned
335 * string is from the line start after the offset to the next line start.
337 * If the boundary_type is ATK_TEXT_BOUNDARY_LINE_END the returned string
338 * is from the line end at or after the offset to the next line end.
340 * Returns: a newly allocated string containing the text after @offset bounded
341 * by the specified @boundary_type. Use g_free() to free the returned string.
344 atk_text_get_text_after_offset (AtkText *text,
346 AtkTextBoundary boundary_type,
351 gint local_start_offset, local_end_offset;
352 gint *real_start_offset, *real_end_offset;
354 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
357 real_start_offset = start_offset;
359 real_start_offset = &local_start_offset;
361 real_end_offset = end_offset;
363 real_end_offset = &local_end_offset;
368 iface = ATK_TEXT_GET_IFACE (text);
370 if (iface->get_text_after_offset)
371 return (*(iface->get_text_after_offset)) (text, offset, boundary_type, real_start_offset, real_end_offset);
377 * atk_text_get_text_at_offset:
380 * @boundary_type: An #AtkTextBoundary
381 * @start_offset: the start offset of the returned string
382 * @end_offset: the offset of the first character after the
385 * Gets the specified text.
387 * If the boundary_type if ATK_TEXT_BOUNDARY_CHAR the character at the
388 * offset is returned.
390 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START the returned string
391 * is from the word start at or before the offset to the word start after
394 * The returned string will contain the word at the offset if the offset
395 * is inside a word and will contain the word before the offset if the
396 * offset is not inside a word.
398 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_END the returned string
399 * is from the word end before the offset to the word end at or after the
402 * The returned string will contain the word at the offset if the offset
403 * is inside a word and will contain the word after to the offset if the
404 * offset is not inside a word.
406 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the returned
407 * string is from the sentence start at or before the offset to the sentence
408 * start after the offset.
410 * The returned string will contain the sentence at the offset if the offset
411 * is inside a sentence and will contain the sentence before the offset
412 * if the offset is not inside a sentence.
414 * If the boundary_type is ATK_TEXT_BOUNDARY_SENTENCE_END the returned string
415 * is from the sentence end before the offset to the sentence end at or
418 * The returned string will contain the sentence at the offset if the offset
419 * is inside a sentence and will contain the sentence after the offset
420 * if the offset is not inside a sentence.
422 * If the boundary type is ATK_TEXT_BOUNDARY_LINE_START the returned
423 * string is from the line start at or before the offset to the line
424 * start after the offset.
426 * If the boundary_type is ATK_TEXT_BOUNDARY_LINE_END the returned string
427 * is from the line end before the offset to the line end at or after
430 * Returns: a newly allocated string containing the text at @offset bounded by
431 * the specified @boundary_type. Use g_free() to free the returned string.
434 atk_text_get_text_at_offset (AtkText *text,
436 AtkTextBoundary boundary_type,
441 gint local_start_offset, local_end_offset;
442 gint *real_start_offset, *real_end_offset;
444 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
447 real_start_offset = start_offset;
449 real_start_offset = &local_start_offset;
451 real_end_offset = end_offset;
453 real_end_offset = &local_end_offset;
455 iface = ATK_TEXT_GET_IFACE (text);
457 if (iface->get_text_at_offset)
458 return (*(iface->get_text_at_offset)) (text, offset, boundary_type, real_start_offset, real_end_offset);
464 * atk_text_get_text_before_offset:
467 * @boundary_type: An #AtkTextBoundary
468 * @start_offset: the start offset of the returned string
469 * @end_offset: the offset of the first character after the
472 * Gets the specified text.
474 * If the boundary_type if ATK_TEXT_BOUNDARY_CHAR the character before the
475 * offset is returned.
477 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START the returned string
478 * is from the word start before the word start before or at the offset to
479 * the word start before or at the offset.
481 * The returned string will contain the word before the offset if the offset
482 * is inside a word and will contain the word before the word before the
483 * offset if the offset is not inside a word.
485 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_END the returned string
486 * is from the word end before the word end before the offset to the word
487 * end before the offset.
489 * The returned string will contain the word before the offset if the offset
490 * is inside a word or if the offset is not inside a word.
492 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the returned
493 * string is from the sentence start before the sentence start before
494 * the offset to the sentence start before the offset.
496 * The returned string will contain the sentence before the offset if the
497 * offset is inside a sentence and will contain the sentence before the
498 * sentence before the offset if the offset is not inside a sentence.
500 * If the boundary_type is ATK_TEXT_BOUNDARY_SENTENCE_END the returned string
501 * is from the sentence end before the sentence end at or before the offset to
502 * the sentence end at or before the offset.
504 * The returned string will contain the sentence before the offset if the
505 * offset is inside a sentence or if the offset is not inside a sentence.
507 * If the boundary type is ATK_TEXT_BOUNDARY_LINE_START the returned
508 * string is from the line start before the line start ar or before the offset
509 * to the line start ar or before the offset.
511 * If the boundary_type is ATK_TEXT_BOUNDARY_LINE_END the returned string
512 * is from the line end before the line end before the offset to the
513 * line end before the offset.
515 * Returns: a newly allocated string containing the text before @offset bounded
516 * by the specified @boundary_type. Use g_free() to free the returned string.
519 atk_text_get_text_before_offset (AtkText *text,
521 AtkTextBoundary boundary_type,
526 gint local_start_offset, local_end_offset;
527 gint *real_start_offset, *real_end_offset;
529 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
532 real_start_offset = start_offset;
534 real_start_offset = &local_start_offset;
536 real_end_offset = end_offset;
538 real_end_offset = &local_end_offset;
543 iface = ATK_TEXT_GET_IFACE (text);
545 if (iface->get_text_before_offset)
546 return (*(iface->get_text_before_offset)) (text, offset, boundary_type, real_start_offset, real_end_offset);
552 * atk_text_get_caret_offset:
555 * Gets the offset position of the caret (cursor).
557 * Returns: the offset position of the caret (cursor).
560 atk_text_get_caret_offset (AtkText *text)
564 g_return_val_if_fail (ATK_IS_TEXT (text), 0);
566 iface = ATK_TEXT_GET_IFACE (text);
568 if (iface->get_caret_offset)
569 return (*(iface->get_caret_offset)) (text);
575 * atk_text_get_character_extents:
577 * @offset: The offset of the text character for which bounding information is required.
578 * @x: Pointer for the x cordinate of the bounding box
579 * @y: Pointer for the y cordinate of the bounding box
580 * @width: Pointer for the width of the bounding box
581 * @height: Pointer for the height of the bounding box
582 * @coords: specify whether coordinates are relative to the screen or widget window
584 * Get the bounding box containing the glyph representing the character at
585 * a particular text offset.
588 atk_text_get_character_extents (AtkText *text,
597 gint local_x, local_y, local_width, local_height;
598 gint *real_x, *real_y, *real_width, *real_height;
600 g_return_if_fail (ATK_IS_TEXT (text));
613 real_width = &local_width;
615 real_height = height;
617 real_height = &local_height;
627 iface = ATK_TEXT_GET_IFACE (text);
629 if (iface->get_character_extents)
630 (*(iface->get_character_extents)) (text, offset, real_x, real_y, real_width, real_height, coords);
634 *real_x = *real_x + *real_width;
640 * atk_text_get_run_attributes:
642 *@offset: the offset at which to get the attributes, -1 means the offset of
643 *the character to be inserted at the caret location.
644 *@start_offset: the address to put the start offset of the range
645 *@end_offset: the address to put the end offset of the range
647 *Creates an #AtkAttributeSet which consists of the attributes explicitly
648 *set at the position @offset in the text. @start_offset and @end_offset are
649 *set to the start and end of the range around @offset where the attributes are
650 *invariant. Note that @end_offset is the offset of the first character
651 *after the range. See the enum AtkTextAttribute for types of text
652 *attributes that can be returned. Note that other attributes may also be
655 *Returns: (transfer full): an #AtkAttributeSet which contains the attributes
656 * explicitly set at @offset. This #AtkAttributeSet should be freed by a call
657 * to atk_attribute_set_free().
660 atk_text_get_run_attributes (AtkText *text,
666 gint local_start_offset, local_end_offset;
667 gint *real_start_offset, *real_end_offset;
669 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
672 real_start_offset = start_offset;
674 real_start_offset = &local_start_offset;
676 real_end_offset = end_offset;
678 real_end_offset = &local_end_offset;
683 iface = ATK_TEXT_GET_IFACE (text);
685 if (iface->get_run_attributes)
686 return (*(iface->get_run_attributes)) (text, offset, real_start_offset, real_end_offset);
692 * atk_text_get_default_attributes:
695 *Creates an #AtkAttributeSet which consists of the default values of
696 *attributes for the text. See the enum AtkTextAttribute for types of text
697 *attributes that can be returned. Note that other attributes may also be
700 *Returns: (transfer full): an #AtkAttributeSet which contains the default
701 * values of attributes. at @offset. this #atkattributeset should be freed by
702 * a call to atk_attribute_set_free().
705 atk_text_get_default_attributes (AtkText *text)
709 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
711 iface = ATK_TEXT_GET_IFACE (text);
713 if (iface->get_default_attributes)
714 return (*(iface->get_default_attributes)) (text);
720 * atk_text_get_character_count:
723 * Gets the character count.
725 * Returns: the number of characters.
728 atk_text_get_character_count (AtkText *text)
732 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
734 iface = ATK_TEXT_GET_IFACE (text);
736 if (iface->get_character_count)
737 return (*(iface->get_character_count)) (text);
743 * atk_text_get_offset_at_point:
745 * @x: screen x-position of character
746 * @y: screen y-position of character
747 * @coords: specify whether coordinates are relative to the screen or
750 * Gets the offset of the character located at coordinates @x and @y. @x and @y
751 * are interpreted as being relative to the screen or this widget's window
752 * depending on @coords.
754 * Returns: the offset to the character which is located at
755 * the specified @x and @y coordinates.
758 atk_text_get_offset_at_point (AtkText *text,
765 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
767 iface = ATK_TEXT_GET_IFACE (text);
769 if (iface->get_offset_at_point)
770 return (*(iface->get_offset_at_point)) (text, x, y, coords);
776 * atk_text_get_n_selections:
779 * Gets the number of selected regions.
781 * Returns: The number of selected regions, or -1 if a failure
785 atk_text_get_n_selections (AtkText *text)
789 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
791 iface = ATK_TEXT_GET_IFACE (text);
793 if (iface->get_n_selections)
794 return (*(iface->get_n_selections)) (text);
800 * atk_text_get_selection:
802 * @selection_num: The selection number. The selected regions are
803 * assigned numbers that correspond to how far the region is from the
804 * start of the text. The selected region closest to the beginning
805 * of the text region is assigned the number 0, etc. Note that adding,
806 * moving or deleting a selected region can change the numbering.
807 * @start_offset: passes back the start position of the selected region
808 * @end_offset: passes back the end position of (e.g. offset immediately past)
809 * the selected region
811 * Gets the text from the specified selection.
813 * Returns: a newly allocated string containing the selected text. Use g_free()
814 * to free the returned string.
817 atk_text_get_selection (AtkText *text,
823 gint local_start_offset, local_end_offset;
824 gint *real_start_offset, *real_end_offset;
826 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
829 real_start_offset = start_offset;
831 real_start_offset = &local_start_offset;
833 real_end_offset = end_offset;
835 real_end_offset = &local_end_offset;
837 iface = ATK_TEXT_GET_IFACE (text);
839 if (iface->get_selection)
841 return (*(iface->get_selection)) (text, selection_num,
842 real_start_offset, real_end_offset);
849 * atk_text_add_selection:
851 * @start_offset: the start position of the selected region
852 * @end_offset: the offset of the first character after the selected region.
854 * Adds a selection bounded by the specified offsets.
856 * Returns: %TRUE if success, %FALSE otherwise
859 atk_text_add_selection (AtkText *text,
865 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
867 iface = ATK_TEXT_GET_IFACE (text);
869 if (iface->add_selection)
870 return (*(iface->add_selection)) (text, start_offset, end_offset);
876 * atk_text_remove_selection:
878 * @selection_num: The selection number. The selected regions are
879 * assigned numbers that correspond to how far the region is from the
880 * start of the text. The selected region closest to the beginning
881 * of the text region is assigned the number 0, etc. Note that adding,
882 * moving or deleting a selected region can change the numbering.
884 * Removes the specified selection.
886 * Returns: %TRUE if success, %FALSE otherwise
889 atk_text_remove_selection (AtkText *text,
894 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
896 iface = ATK_TEXT_GET_IFACE (text);
898 if (iface->remove_selection)
899 return (*(iface->remove_selection)) (text, selection_num);
905 * atk_text_set_selection:
907 * @selection_num: The selection number. The selected regions are
908 * assigned numbers that correspond to how far the region is from the
909 * start of the text. The selected region closest to the beginning
910 * of the text region is assigned the number 0, etc. Note that adding,
911 * moving or deleting a selected region can change the numbering.
912 * @start_offset: the new start position of the selection
913 * @end_offset: the new end position of (e.g. offset immediately past)
916 * Changes the start and end offset of the specified selection.
918 * Returns: %TRUE if success, %FALSE otherwise
921 atk_text_set_selection (AtkText *text,
928 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
930 iface = ATK_TEXT_GET_IFACE (text);
932 if (iface->set_selection)
934 return (*(iface->set_selection)) (text, selection_num,
935 start_offset, end_offset);
942 * atk_text_set_caret_offset:
946 * Sets the caret (cursor) position to the specified @offset.
948 * Returns: %TRUE if success, %FALSE otherwise.
951 atk_text_set_caret_offset (AtkText *text,
956 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
958 iface = ATK_TEXT_GET_IFACE (text);
960 if (iface->set_caret_offset)
962 return (*(iface->set_caret_offset)) (text, offset);
971 * atk_text_get_range_extents:
973 * @start_offset: The offset of the first text character for which boundary
974 * information is required.
975 * @end_offset: The offset of the text character after the last character
976 * for which boundary information is required.
977 * @coord_type: Specify whether coordinates are relative to the screen or widget window.
978 * @rect: A pointer to a AtkTextRectangle which is filled in by this function.
980 * Get the bounding box for text within the specified range.
985 atk_text_get_range_extents (AtkText *text,
988 AtkCoordType coord_type,
989 AtkTextRectangle *rect)
993 g_return_if_fail (ATK_IS_TEXT (text));
994 g_return_if_fail (rect);
996 if (start_offset < 0 || start_offset >= end_offset)
999 iface = ATK_TEXT_GET_IFACE (text);
1001 if (iface->get_range_extents)
1002 (*(iface->get_range_extents)) (text, start_offset, end_offset, coord_type, rect);
1006 * atk_text_get_bounded_ranges:
1007 * @text: an #AtkText
1008 * @rect: An AtkTextRectangle giving the dimensions of the bounding box.
1009 * @coord_type: Specify whether coordinates are relative to the screen or widget window.
1010 * @x_clip_type: Specify the horizontal clip type.
1011 * @y_clip_type: Specify the vertical clip type.
1013 * Get the ranges of text in the specified bounding box.
1017 * Returns: (array zero-terminated=1): Array of AtkTextRange. The last
1018 * element of the array returned by this function will be NULL.
1021 atk_text_get_bounded_ranges (AtkText *text,
1022 AtkTextRectangle *rect,
1023 AtkCoordType coord_type,
1024 AtkTextClipType x_clip_type,
1025 AtkTextClipType y_clip_type)
1027 AtkTextIface *iface;
1029 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
1030 g_return_val_if_fail (rect, NULL);
1032 iface = ATK_TEXT_GET_IFACE (text);
1034 if (iface->get_bounded_ranges)
1035 return (*(iface->get_bounded_ranges)) (text, rect, coord_type, x_clip_type, y_clip_type);
1041 * atk_attribute_set_free:
1042 * @attrib_set: The #AtkAttributeSet to free
1044 * Frees the memory used by an #AtkAttributeSet, including all its
1048 atk_attribute_set_free (AtkAttributeSet *attrib_set)
1054 while (temp != NULL)
1061 g_free (att->value);
1065 g_slist_free (attrib_set);
1069 * atk_text_attribute_register:
1070 * @name: a name string
1072 * Associate @name with a new #AtkTextAttribute
1074 * Returns: an #AtkTextAttribute associated with @name
1077 atk_text_attribute_register (const gchar *name)
1079 g_return_val_if_fail (name, ATK_TEXT_ATTR_INVALID);
1081 if (!extra_attributes)
1082 extra_attributes = g_ptr_array_new ();
1084 g_ptr_array_add (extra_attributes, g_strdup (name));
1085 return extra_attributes->len + ATK_TEXT_ATTR_LAST_DEFINED;
1089 * atk_text_attribute_get_name:
1090 * @attr: The #AtkTextAttribute whose name is required
1092 * Gets the name corresponding to the #AtkTextAttribute
1094 * Returns: a string containing the name; this string should not be freed
1097 atk_text_attribute_get_name (AtkTextAttribute attr)
1099 GTypeClass *type_class;
1101 const gchar *name = NULL;
1103 type_class = g_type_class_ref (ATK_TYPE_TEXT_ATTRIBUTE);
1104 g_return_val_if_fail (G_IS_ENUM_CLASS (type_class), NULL);
1106 value = g_enum_get_value (G_ENUM_CLASS (type_class), attr);
1110 name = value->value_nick;
1114 if (extra_attributes)
1118 n -= ATK_TEXT_ATTR_LAST_DEFINED + 1;
1120 if (n < extra_attributes->len)
1122 name = g_ptr_array_index (extra_attributes, n);
1125 g_type_class_unref (type_class);
1130 * atk_text_attribute_for_name:
1131 * @name: a string which is the (non-localized) name of an ATK text attribute.
1133 * Get the #AtkTextAttribute type corresponding to a text attribute name.
1135 * Returns: the #AtkTextAttribute enumerated type corresponding to the specified
1137 * or #ATK_TEXT_ATTRIBUTE_INVALID if no matching text attribute is found.
1140 atk_text_attribute_for_name (const gchar *name)
1142 GTypeClass *type_class;
1144 AtkTextAttribute type = ATK_TEXT_ATTR_INVALID;
1146 g_return_val_if_fail (name, ATK_TEXT_ATTR_INVALID);
1148 type_class = g_type_class_ref (ATK_TYPE_TEXT_ATTRIBUTE);
1149 g_return_val_if_fail (G_IS_ENUM_CLASS (type_class), ATK_TEXT_ATTR_INVALID);
1151 value = g_enum_get_value_by_nick (G_ENUM_CLASS (type_class), name);
1155 type = value->value;
1161 if (extra_attributes)
1163 for (i = 0; i < extra_attributes->len; i++)
1165 gchar *extra_attribute = (gchar *)g_ptr_array_index (extra_attributes, i);
1167 g_return_val_if_fail (extra_attribute, ATK_TEXT_ATTR_INVALID);
1169 if (strcmp (name, extra_attribute) == 0)
1171 type = i + 1 + ATK_TEXT_ATTR_LAST_DEFINED;
1177 g_type_class_unref (type_class);
1183 * atk_text_attribute_get_value:
1184 * @attr: The #AtkTextAttribute for which a value is required
1185 * @index_: The index of the required value
1187 * Gets the value for the index of the #AtkTextAttribute
1189 * Returns: a string containing the value; this string should not be freed;
1190 * NULL is returned if there are no values maintained for the attr value.
1193 atk_text_attribute_get_value (AtkTextAttribute attr,
1198 case ATK_TEXT_ATTR_INVISIBLE:
1199 case ATK_TEXT_ATTR_EDITABLE:
1200 case ATK_TEXT_ATTR_BG_FULL_HEIGHT:
1201 case ATK_TEXT_ATTR_STRIKETHROUGH:
1202 case ATK_TEXT_ATTR_BG_STIPPLE:
1203 case ATK_TEXT_ATTR_FG_STIPPLE:
1204 g_assert (index >= 0 && index < G_N_ELEMENTS (boolean_offsets));
1205 return boolean + boolean_offsets[index];
1206 case ATK_TEXT_ATTR_UNDERLINE:
1207 g_assert (index >= 0 && index < G_N_ELEMENTS (underline_offsets));
1208 return underline + underline_offsets[index];
1209 case ATK_TEXT_ATTR_WRAP_MODE:
1210 g_assert (index >= 0 && index < G_N_ELEMENTS (wrap_mode_offsets));
1211 return wrap_mode + wrap_mode_offsets[index];
1212 case ATK_TEXT_ATTR_DIRECTION:
1213 g_assert (index >= 0 && index < G_N_ELEMENTS (direction_offsets));
1214 return direction + direction_offsets[index];
1215 case ATK_TEXT_ATTR_JUSTIFICATION:
1216 g_assert (index >= 0 && index < G_N_ELEMENTS (justification_offsets));
1217 return justification + justification_offsets[index];
1218 case ATK_TEXT_ATTR_STRETCH:
1219 g_assert (index >= 0 && index < G_N_ELEMENTS (stretch_offsets));
1220 return stretch + stretch_offsets[index];
1221 case ATK_TEXT_ATTR_VARIANT:
1222 g_assert (index >= 0 && index < G_N_ELEMENTS (variant_offsets));
1223 return variant + variant_offsets[index];
1224 case ATK_TEXT_ATTR_STYLE:
1225 g_assert (index >= 0 && index < G_N_ELEMENTS (style_offsets));
1226 return style + style_offsets[index];
1233 atk_text_rectangle_union (AtkTextRectangle *src1,
1234 AtkTextRectangle *src2,
1235 AtkTextRectangle *dest)
1237 gint dest_x, dest_y;
1239 dest_x = MIN (src1->x, src2->x);
1240 dest_y = MIN (src1->y, src2->y);
1241 dest->width = MAX (src1->x + src1->width, src2->x + src2->width) - dest_x;
1242 dest->height = MAX (src1->y + src1->height, src2->y + src2->height) - dest_y;
1248 atk_text_rectangle_contain (AtkTextRectangle *clip,
1249 AtkTextRectangle *bounds,
1250 AtkTextClipType x_clip_type,
1251 AtkTextClipType y_clip_type)
1253 gboolean x_min_ok, x_max_ok, y_min_ok, y_max_ok;
1255 x_min_ok = (bounds->x >= clip->x) ||
1256 ((bounds->x + bounds->width >= clip->x) &&
1257 ((x_clip_type == ATK_TEXT_CLIP_NONE) ||
1258 (x_clip_type == ATK_TEXT_CLIP_MAX)));
1260 x_max_ok = (bounds->x + bounds->width <= clip->x + clip->width) ||
1261 ((bounds->x <= clip->x + clip->width) &&
1262 ((x_clip_type == ATK_TEXT_CLIP_NONE) ||
1263 (x_clip_type == ATK_TEXT_CLIP_MIN)));
1265 y_min_ok = (bounds->y >= clip->y) ||
1266 ((bounds->y + bounds->height >= clip->y) &&
1267 ((y_clip_type == ATK_TEXT_CLIP_NONE) ||
1268 (y_clip_type == ATK_TEXT_CLIP_MAX)));
1270 y_max_ok = (bounds->y + bounds->height <= clip->y + clip->height) ||
1271 ((bounds->y <= clip->y + clip->height) &&
1272 ((y_clip_type == ATK_TEXT_CLIP_NONE) ||
1273 (y_clip_type == ATK_TEXT_CLIP_MIN)));
1275 return (x_min_ok && x_max_ok && y_min_ok && y_max_ok);
1280 atk_text_real_get_range_extents (AtkText *text,
1283 AtkCoordType coord_type,
1284 AtkTextRectangle *rect)
1287 AtkTextRectangle cbounds, bounds;
1289 atk_text_get_character_extents (text, start_offset,
1290 &bounds.x, &bounds.y,
1291 &bounds.width, &bounds.height,
1294 for (i = start_offset + 1; i < end_offset; i++)
1296 atk_text_get_character_extents (text, i,
1297 &cbounds.x, &cbounds.y,
1298 &cbounds.width, &cbounds.height,
1300 atk_text_rectangle_union (&bounds, &cbounds, &bounds);
1305 rect->width = bounds.width;
1306 rect->height = bounds.height;
1309 static AtkTextRange**
1310 atk_text_real_get_bounded_ranges (AtkText *text,
1311 AtkTextRectangle *rect,
1312 AtkCoordType coord_type,
1313 AtkTextClipType x_clip_type,
1314 AtkTextClipType y_clip_type)
1316 gint bounds_min_offset, bounds_max_offset;
1317 gint min_line_start, min_line_end;
1318 gint max_line_start, max_line_end;
1322 gint num_ranges = 0;
1323 gint range_size = 1;
1324 AtkTextRectangle cbounds;
1325 AtkTextRange **range;
1328 bounds_min_offset = atk_text_get_offset_at_point (text, rect->x, rect->y, coord_type);
1329 bounds_max_offset = atk_text_get_offset_at_point (text, rect->x + rect->width, rect->y + rect->height, coord_type);
1331 if (bounds_min_offset == 0 &&
1332 bounds_min_offset == bounds_max_offset)
1335 line = atk_text_get_text_at_offset (text, bounds_min_offset,
1336 ATK_TEXT_BOUNDARY_LINE_START,
1337 &min_line_start, &min_line_end);
1339 line = atk_text_get_text_at_offset (text, bounds_max_offset,
1340 ATK_TEXT_BOUNDARY_LINE_START,
1341 &max_line_start, &max_line_end);
1343 bounds_min_offset = MIN (min_line_start, max_line_start);
1344 bounds_max_offset = MAX (min_line_end, max_line_end);
1346 curr_offset = bounds_min_offset;
1347 while (curr_offset < bounds_max_offset)
1349 offset = curr_offset;
1351 while (curr_offset < bounds_max_offset)
1353 atk_text_get_character_extents (text, curr_offset,
1354 &cbounds.x, &cbounds.y,
1355 &cbounds.width, &cbounds.height,
1357 if (!atk_text_rectangle_contain (rect, &cbounds, x_clip_type, y_clip_type))
1361 if (curr_offset > offset)
1363 AtkTextRange *one_range = g_new (AtkTextRange, 1);
1365 one_range->start_offset = offset;
1366 one_range->end_offset = curr_offset;
1367 one_range->content = atk_text_get_text (text, offset, curr_offset);
1368 atk_text_get_range_extents (text, offset, curr_offset, coord_type, &one_range->bounds);
1370 if (num_ranges >= range_size - 1)
1373 range = g_realloc (range, range_size * sizeof (gpointer));
1375 range[num_ranges] = one_range;
1380 range[num_ranges] = NULL;
1386 * atk_text_free_ranges:
1387 * @ranges: A pointer to an array of #AtkTextRange which is to be freed.
1389 * Frees the memory associated with an array of AtkTextRange. It is assumed
1390 * that the array was returned by the function atk_text_get_bounded_ranges
1391 * and is NULL terminated.
1396 atk_text_free_ranges (AtkTextRange **ranges)
1398 AtkTextRange **first = ranges;
1404 AtkTextRange *range;
1408 g_free (range->content);
1415 static AtkTextRange *
1416 atk_text_range_copy (AtkTextRange *src)
1418 AtkTextRange *dst = g_new0 (AtkTextRange, 1);
1419 dst->bounds = src->bounds;
1420 dst->start_offset = src->start_offset;
1421 dst->end_offset = src->end_offset;
1423 dst->content = g_strdup (src->content);
1428 atk_text_range_free (AtkTextRange *range)
1430 g_free (range->content);
1434 G_DEFINE_BOXED_TYPE (AtkTextRange, atk_text_range, atk_text_range_copy,
1435 atk_text_range_free)