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 char boolean[] =
39 static const guint8 boolean_offsets[] = {
43 static const char style[] =
47 static const guint8 style_offsets[] = {
51 static const char variant[] =
54 static const guint8 variant_offsets[] = {
58 static const char stretch[] =
68 static const guint8 stretch_offsets[] = {
69 0, 16, 32, 42, 57, 64, 78, 87, 102
72 static const char justification[] =
77 static const guint8 justification_offsets[] = {
81 static const char direction[] =
85 static const guint8 direction_offsets[] = {
89 static const char wrap_mode[] =
94 static const guint8 wrap_mode_offsets[] = {
98 static const char underline[] =
103 static const guint8 underline_offsets[] = {
107 static void atk_text_base_init (AtkTextIface *class);
109 static void atk_text_real_get_range_extents (AtkText *text,
112 AtkCoordType coord_type,
113 AtkTextRectangle *rect);
115 static AtkTextRange** atk_text_real_get_bounded_ranges (AtkText *text,
116 AtkTextRectangle *rect,
117 AtkCoordType coord_type,
118 AtkTextClipType x_clip_type,
119 AtkTextClipType y_clip_type);
121 static guint atk_text_signals[LAST_SIGNAL] = { 0 };
124 atk_text_get_type (void)
126 static GType type = 0;
130 static const GTypeInfo tinfo =
132 sizeof (AtkTextIface),
133 (GBaseInitFunc) atk_text_base_init,
134 (GBaseFinalizeFunc) NULL,
135 (GClassInitFunc) NULL /* atk_text_interface_init */ ,
136 (GClassFinalizeFunc) NULL,
140 type = g_type_register_static (G_TYPE_INTERFACE, "AtkText", &tinfo, 0);
147 atk_text_base_init (AtkTextIface *class)
149 static gboolean initialized = FALSE;
154 * Note that text_changed signal supports details "insert", "delete",
155 * possibly "replace".
158 class->get_range_extents = atk_text_real_get_range_extents;
159 class->get_bounded_ranges = atk_text_real_get_bounded_ranges;
161 atk_text_signals[TEXT_CHANGED] =
162 g_signal_new ("text_changed",
164 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
165 G_STRUCT_OFFSET (AtkTextIface, text_changed),
166 (GSignalAccumulator) NULL, NULL,
167 atk_marshal_VOID__INT_INT,
169 2, G_TYPE_INT, G_TYPE_INT);
171 atk_text_signals[TEXT_CARET_MOVED] =
172 g_signal_new ("text_caret_moved",
175 G_STRUCT_OFFSET (AtkTextIface, text_caret_moved),
176 (GSignalAccumulator) NULL, NULL,
177 g_cclosure_marshal_VOID__INT,
180 atk_text_signals[TEXT_SELECTION_CHANGED] =
181 g_signal_new ("text_selection_changed",
184 G_STRUCT_OFFSET (AtkTextIface, text_selection_changed),
185 (GSignalAccumulator) NULL, NULL,
186 g_cclosure_marshal_VOID__VOID,
188 atk_text_signals[TEXT_ATTRIBUTES_CHANGED] =
189 g_signal_new ("text_attributes_changed",
192 G_STRUCT_OFFSET (AtkTextIface, text_attributes_changed),
193 (GSignalAccumulator) NULL, NULL,
194 g_cclosure_marshal_VOID__VOID,
205 * @start_offset: start position
206 * @end_offset: end position
208 * Gets the specified text.
210 * Returns: the text from @start_offset up to, but not including @end_offset.
213 atk_text_get_text (AtkText *text,
219 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
221 iface = ATK_TEXT_GET_IFACE (text);
223 if (start_offset < 0 || end_offset < -1)
227 return (*(iface->get_text)) (text, start_offset, end_offset);
233 * atk_text_get_character_at_offset:
237 * Gets the specified text.
239 * Returns: the character at @offset.
242 atk_text_get_character_at_offset (AtkText *text,
247 g_return_val_if_fail (ATK_IS_TEXT (text), (gunichar) 0);
249 iface = ATK_TEXT_GET_IFACE (text);
251 if (iface->get_character_at_offset)
252 return (*(iface->get_character_at_offset)) (text, offset);
258 * atk_text_get_text_after_offset:
261 * @boundary_type: An #AtkTextBoundary
262 * @start_offset: the start offset of the returned string
263 * @end_offset: the offset of the first character after the
266 * Gets the specified text.
268 * If the boundary_type if ATK_TEXT_BOUNDARY_CHAR the character after the
269 * offset is returned.
271 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START the returned string
272 * is from the word start after the offset to the next word start.
274 * The returned string will contain the word after the offset if the offset
275 * is inside a word or if the offset is not inside a word.
277 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_END the returned string
278 * is from the word end at or after the offset to the next work end.
280 * The returned string will contain the word after the offset if the offset
281 * is inside a word and will contain the word after the word after the offset
282 * if the offset is not inside a word.
284 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the returned
285 * string is from the sentence start after the offset to the next sentence
288 * The returned string will contain the sentence after the offset if the offset
289 * is inside a sentence or if the offset is not inside a sentence.
291 * If the boundary_type is ATK_TEXT_BOUNDARY_SENTENCE_END the returned string
292 * is from the sentence end at or after the offset to the next sentence end.
294 * The returned string will contain the sentence after the offset if the offset
295 * is inside a sentence and will contain the sentence after the sentence
296 * after the offset if the offset is not inside a sentence.
298 * If the boundary type is ATK_TEXT_BOUNDARY_LINE_START the returned
299 * string is from the line start after the offset to the next line start.
301 * If the boundary_type is ATK_TEXT_BOUNDARY_LINE_END the returned string
302 * is from the line end at or after the offset to the next line start.
304 * Returns: the text after @offset bounded by the specified @boundary_type.
307 atk_text_get_text_after_offset (AtkText *text,
309 AtkTextBoundary boundary_type,
314 gint local_start_offset, local_end_offset;
315 gint *real_start_offset, *real_end_offset;
317 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
320 real_start_offset = start_offset;
322 real_start_offset = &local_start_offset;
324 real_end_offset = end_offset;
326 real_end_offset = &local_end_offset;
331 iface = ATK_TEXT_GET_IFACE (text);
333 if (iface->get_text_after_offset)
334 return (*(iface->get_text_after_offset)) (text, offset, boundary_type, real_start_offset, real_end_offset);
340 * atk_text_get_text_at_offset:
343 * @boundary_type: An #AtkTextBoundary
344 * @start_offset: the start offset of the returned string
345 * @end_offset: the offset of the first character after the
348 * Gets the specified text.
350 * If the boundary_type if ATK_TEXT_BOUNDARY_CHAR the character at the
351 * offset is returned.
353 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START the returned string
354 * is from the word start at or before the offset to the word start after
357 * The returned string will contain the word at the offset if the offset
358 * is inside a word and will contain the word before the offset if the
359 * offset is not inside a word.
361 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_END the returned string
362 * is from the word end before the offset to the word end at or after the
365 * The returned string will contain the word at the offset if the offset
366 * is inside a word and will contain the word after to the offset if the
367 * offset is not inside a word.
369 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the returned
370 * string is from the sentence start at or before the offset to the sentence
371 * start after the offset.
373 * The returned string will contain the sentence at the offset if the offset
374 * is inside a sentence and will contain the sentence before the offset
375 * if the offset is not inside a sentence.
377 * If the boundary_type is ATK_TEXT_BOUNDARY_SENTENCE_END the returned string
378 * is from the sentence end before the offset to the sentence end at or
381 * The returned string will contain the sentence at the offset if the offset
382 * is inside a sentence and will contain the sentence after the offset
383 * if the offset is not inside a sentence.
385 * If the boundary type is ATK_TEXT_BOUNDARY_LINE_START the returned
386 * string is from the line start at or before the offset to the line
387 * start after the offset.
389 * If the boundary_type is ATK_TEXT_BOUNDARY_LINE_END the returned string
390 * is from the line end before the offset to the line end at or after
393 * Returns: the text at @offset bounded by the specified @boundary_type.
396 atk_text_get_text_at_offset (AtkText *text,
398 AtkTextBoundary boundary_type,
403 gint local_start_offset, local_end_offset;
404 gint *real_start_offset, *real_end_offset;
406 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
409 real_start_offset = start_offset;
411 real_start_offset = &local_start_offset;
413 real_end_offset = end_offset;
415 real_end_offset = &local_end_offset;
417 iface = ATK_TEXT_GET_IFACE (text);
419 if (iface->get_text_at_offset)
420 return (*(iface->get_text_at_offset)) (text, offset, boundary_type, real_start_offset, real_end_offset);
426 * atk_text_get_text_before_offset:
429 * @boundary_type: An #AtkTextBoundary
430 * @start_offset: the start offset of the returned string
431 * @end_offset: the offset of the first character after the
434 * Gets the specified text.
436 * If the boundary_type if ATK_TEXT_BOUNDARY_CHAR the character before the
437 * offset is returned.
439 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START the returned string
440 * is from the word start before the word start before the offset to
441 * the word start before the offset.
443 * The returned string will contain the word before the offset if the offset
444 * is inside a word and will contain the word before the word before the
445 * offset if the offset is not inside a word.
447 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_END the returned string
448 * is from the word end before the word end at or before the offset to the
449 * word end at or before the offset.
451 * The returned string will contain the word before the offset if the offset
452 * is inside a word or if the offset is not inside a word.
454 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the returned
455 * string is from the sentence start before the sentence start before
456 * the offset to the sentence start before the offset.
458 * The returned string will contain the sentence before the offset if the
459 * offset is inside a sentence and will contain the sentence before the
460 * sentence before the offset if the offset is not inside a sentence.
462 * If the boundary_type is ATK_TEXT_BOUNDARY_SENTENCE_END the returned string
463 * is from the sentence end before the sentence end at or before the offset to
464 * the sentence end at or before the offset.
466 * The returned string will contain the sentence before the offset if the
467 * offset is inside a sentence or if the offset is not inside a sentence.
469 * If the boundary type is ATK_TEXT_BOUNDARY_LINE_START the returned
470 * string is from the line start before the line start ar or before the offset
471 * to the line start ar or before the offset.
473 * If the boundary_type is ATK_TEXT_BOUNDARY_LINE_END the returned string
474 * is from the line end before the line end before the offset to the
475 * line end before the offset.
477 * Returns: the text before @offset bounded by the specified @boundary_type.
480 atk_text_get_text_before_offset (AtkText *text,
482 AtkTextBoundary boundary_type,
487 gint local_start_offset, local_end_offset;
488 gint *real_start_offset, *real_end_offset;
490 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
493 real_start_offset = start_offset;
495 real_start_offset = &local_start_offset;
497 real_end_offset = end_offset;
499 real_end_offset = &local_end_offset;
504 iface = ATK_TEXT_GET_IFACE (text);
506 if (iface->get_text_before_offset)
507 return (*(iface->get_text_before_offset)) (text, offset, boundary_type, real_start_offset, real_end_offset);
513 * atk_text_get_caret_offset:
516 * Gets the offset position of the caret (cursor).
518 * Returns: the offset position of the caret (cursor).
521 atk_text_get_caret_offset (AtkText *text)
525 g_return_val_if_fail (ATK_IS_TEXT (text), 0);
527 iface = ATK_TEXT_GET_IFACE (text);
529 if (iface->get_caret_offset)
530 return (*(iface->get_caret_offset)) (text);
536 * atk_text_get_character_extents:
538 * @offset: The offset of the text character for which bounding information is required.
539 * @x: Pointer for the x cordinate of the bounding box
540 * @y: Pointer for the y cordinate of the bounding box
541 * @width: Pointer for the width of the bounding box
542 * @height: Pointer for the height of the bounding box
543 * @coords: specify whether coordinates are relative to the screen or widget window
545 * Get the bounding box containing the glyph representing the character at
546 * a particular text offset.
549 atk_text_get_character_extents (AtkText *text,
558 gint local_x, local_y, local_width, local_height;
559 gint *real_x, *real_y, *real_width, *real_height;
561 g_return_if_fail (ATK_IS_TEXT (text));
574 real_width = &local_width;
576 real_height = height;
578 real_height = &local_height;
588 iface = ATK_TEXT_GET_IFACE (text);
590 if (iface->get_character_extents)
591 (*(iface->get_character_extents)) (text, offset, real_x, real_y, real_width, real_height, coords);
595 *real_x = *real_x + *real_width;
601 *atk_text_get_run_attributes:
603 *@offset: the offset at which to get the attributes, -1 means the offset of
604 *the character to be inserted at the caret location.
605 *@start_offset: the address to put the start offset of the range
606 *@end_offset: the address to put the end offset of the range
608 *Creates an #AtkAttributeSet which consists of the attributes explicitly
609 *set at the position @offset in the text. @start_offset and @end_offset are
610 *set to the start and end of the range around @offset where the attributes are
611 *invariant. Note that @end_offset is the offset of the first character
612 *after the range. See the enum AtkTextAttribute for types of text
613 *attributes that can be returned. Note that other attributes may also be
616 *Returns: an #AtkAttributeSet which contains the attributes explicitly set
617 *at @offset. This #AtkAttributeSet should be freed by a call to
618 *atk_attribute_set_free().
621 atk_text_get_run_attributes (AtkText *text,
627 gint local_start_offset, local_end_offset;
628 gint *real_start_offset, *real_end_offset;
630 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
633 real_start_offset = start_offset;
635 real_start_offset = &local_start_offset;
637 real_end_offset = end_offset;
639 real_end_offset = &local_end_offset;
644 iface = ATK_TEXT_GET_IFACE (text);
646 if (iface->get_run_attributes)
647 return (*(iface->get_run_attributes)) (text, offset, real_start_offset, real_end_offset);
653 *atk_text_get_default_attributes:
656 *Creates an #AtkAttributeSet which consists of the default values of
657 *attributes for the text. See the enum AtkTextAttribute for types of text
658 *attributes that can be returned. Note that other attributes may also be
661 *Returns: an #AtkAttributeSet which contains the default values of attributes.
662 *at @offset. This #AtkAttributeSet should be freed by a call to
663 *atk_attribute_set_free().
666 atk_text_get_default_attributes (AtkText *text)
670 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
672 iface = ATK_TEXT_GET_IFACE (text);
674 if (iface->get_default_attributes)
675 return (*(iface->get_default_attributes)) (text);
681 * atk_text_get_character_count:
684 * Gets the character count.
686 * Returns: the number of characters.
689 atk_text_get_character_count (AtkText *text)
693 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
695 iface = ATK_TEXT_GET_IFACE (text);
697 if (iface->get_character_count)
698 return (*(iface->get_character_count)) (text);
704 * atk_text_get_offset_at_point:
706 * @x: screen x-position of character
707 * @y: screen y-position of character
708 * @coords: specify whether coordinates are relative to the screen or
711 * Gets the offset of the character located at coordinates @x and @y. @x and @y
712 * are interpreted as being relative to the screen or this widget's window
713 * depending on @coords.
715 * Returns: the offset to the character which is located at
716 * the specified @x and @y coordinates.
719 atk_text_get_offset_at_point (AtkText *text,
726 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
728 iface = ATK_TEXT_GET_IFACE (text);
730 if (iface->get_offset_at_point)
731 return (*(iface->get_offset_at_point)) (text, x, y, coords);
737 * atk_text_get_n_selections:
740 * Gets the number of selected regions.
742 * Returns: The number of selected regions, or -1 if a failure
746 atk_text_get_n_selections (AtkText *text)
750 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
752 iface = ATK_TEXT_GET_IFACE (text);
754 if (iface->get_n_selections)
755 return (*(iface->get_n_selections)) (text);
761 * atk_text_get_selection:
763 * @selection_num: The selection number. The selected regions are
764 * assigned numbers that correspond to how far the region is from the
765 * start of the text. The selected region closest to the beginning
766 * of the text region is assigned the number 0, etc. Note that adding,
767 * moving or deleting a selected region can change the numbering.
768 * @start_offset: passes back the start position of the selected region
769 * @end_offset: passes back the end position of (e.g. offset immediately past)
770 * the selected region
772 * Gets the text from the specified selection.
774 * Returns: the selected text.
777 atk_text_get_selection (AtkText *text,
783 gint local_start_offset, local_end_offset;
784 gint *real_start_offset, *real_end_offset;
786 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
789 real_start_offset = start_offset;
791 real_start_offset = &local_start_offset;
793 real_end_offset = end_offset;
795 real_end_offset = &local_end_offset;
797 iface = ATK_TEXT_GET_IFACE (text);
799 if (iface->get_selection)
801 return (*(iface->get_selection)) (text, selection_num,
802 real_start_offset, real_end_offset);
809 * atk_text_add_selection:
811 * @start_offset: the start position of the selected region
812 * @end_offset: the offset of the first character after the selected region.
814 * Adds a selection bounded by the specified offsets.
816 * Returns: %TRUE if success, %FALSE otherwise
819 atk_text_add_selection (AtkText *text,
825 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
827 iface = ATK_TEXT_GET_IFACE (text);
829 if (iface->add_selection)
830 return (*(iface->add_selection)) (text, start_offset, end_offset);
836 * atk_text_remove_selection:
838 * @selection_num: The selection number. The selected regions are
839 * assigned numbers that correspond to how far the region is from the
840 * start of the text. The selected region closest to the beginning
841 * of the text region is assigned the number 0, etc. Note that adding,
842 * moving or deleting a selected region can change the numbering.
844 * Removes the specified selection.
846 * Returns: %TRUE if success, %FALSE otherwise
849 atk_text_remove_selection (AtkText *text,
854 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
856 iface = ATK_TEXT_GET_IFACE (text);
858 if (iface->remove_selection)
859 return (*(iface->remove_selection)) (text, selection_num);
865 * atk_text_set_selection:
867 * @selection_num: The selection number. The selected regions are
868 * assigned numbers that correspond to how far the region is from the
869 * start of the text. The selected region closest to the beginning
870 * of the text region is assigned the number 0, etc. Note that adding,
871 * moving or deleting a selected region can change the numbering.
872 * @start_offset: the new start position of the selection
873 * @end_offset: the new end position of (e.g. offset immediately past)
876 * Changes the start and end offset of the specified selection.
878 * Returns: %TRUE if success, %FALSE otherwise
881 atk_text_set_selection (AtkText *text,
888 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
890 iface = ATK_TEXT_GET_IFACE (text);
892 if (iface->set_selection)
894 return (*(iface->set_selection)) (text, selection_num,
895 start_offset, end_offset);
902 * atk_text_set_caret_offset:
906 * Sets the caret (cursor) position to the specified @offset.
908 * Returns: %TRUE if success, %FALSE otherwise.
911 atk_text_set_caret_offset (AtkText *text,
916 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
918 iface = ATK_TEXT_GET_IFACE (text);
920 if (iface->set_caret_offset)
922 return (*(iface->set_caret_offset)) (text, offset);
931 * atk_text_get_range_extents:
933 * @start_offset: The offset of the first text character for which boundary
934 * information is required.
935 * @end_offset: The offset of the text character after the last character
936 * for which boundary information is required.
937 * @coord_type: Specify whether coordinates are relative to the screen or widget window.
938 * @rect: A pointer to a AtkTextRectangle which is filled in by this function.
940 * Get the bounding box for text within the specified range.
945 atk_text_get_range_extents (AtkText *text,
948 AtkCoordType coord_type,
949 AtkTextRectangle *rect)
953 g_return_if_fail (ATK_IS_TEXT (text));
954 g_return_if_fail (rect);
956 if (start_offset < 0 || start_offset >= end_offset)
959 iface = ATK_TEXT_GET_IFACE (text);
961 if (iface->get_range_extents)
962 (*(iface->get_range_extents)) (text, start_offset, end_offset, coord_type, rect);
966 * atk_text_get_bounded_ranges:
968 * @rect: An AtkTextRectagle giving the dimensions of the bounding box.
969 * @coord_type: Specify whether coordinates are relative to the screen or widget window.
970 * @x_clip_type: Specify the horizontal clip type.
971 * @y_clip_type: Specify the vertical clip type.
973 * Get the ranges of text in the specified bounding box.
977 * Returns: Array of AtkTextRange. The last element of the array returned
978 * by this function will be NULL.
981 atk_text_get_bounded_ranges (AtkText *text,
982 AtkTextRectangle *rect,
983 AtkCoordType coord_type,
984 AtkTextClipType x_clip_type,
985 AtkTextClipType y_clip_type)
989 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
990 g_return_val_if_fail (rect, NULL);
992 iface = ATK_TEXT_GET_IFACE (text);
994 if (iface->get_bounded_ranges)
995 return (*(iface->get_bounded_ranges)) (text, rect, coord_type, x_clip_type, y_clip_type);
1001 * atk_attribute_set_free:
1002 * @attrib_set: The #AtkAttributeSet to free
1004 * Frees the memory used by an #AtkAttributeSet, including all its
1008 atk_attribute_set_free (AtkAttributeSet *attrib_set)
1014 while (temp != NULL)
1021 g_free (att->value);
1025 g_slist_free (attrib_set);
1029 * atk_text_attribute_register:
1030 * @name: a name string
1032 * Associate @name with a new #AtkTextAttribute
1034 * Returns: an #AtkTextAttribute associated with @name
1037 atk_text_attribute_register (const gchar *name)
1039 g_return_val_if_fail (name, ATK_TEXT_ATTR_INVALID);
1041 if (!extra_attributes)
1042 extra_attributes = g_ptr_array_new ();
1044 g_ptr_array_add (extra_attributes, g_strdup (name));
1045 return extra_attributes->len + ATK_TEXT_ATTR_LAST_DEFINED;
1049 * atk_text_attribute_get_name:
1050 * @attr: The #AtkTextAttribute whose name is required
1052 * Gets the name corresponding to the #AtkTextAttribute
1054 * Returns: a string containing the name; this string should not be freed
1056 G_CONST_RETURN gchar*
1057 atk_text_attribute_get_name (AtkTextAttribute attr)
1059 GTypeClass *type_class;
1061 const gchar *name = NULL;
1063 type_class = g_type_class_ref (ATK_TYPE_TEXT_ATTRIBUTE);
1064 g_return_val_if_fail (G_IS_ENUM_CLASS (type_class), NULL);
1066 value = g_enum_get_value (G_ENUM_CLASS (type_class), attr);
1070 name = value->value_nick;
1074 if (extra_attributes)
1078 n -= ATK_TEXT_ATTR_LAST_DEFINED + 1;
1080 if (n < extra_attributes->len)
1082 name = g_ptr_array_index (extra_attributes, n);
1085 g_type_class_unref (type_class);
1090 * atk_text_attribute_for_name:
1091 * @name: a string which is the (non-localized) name of an ATK text attribute.
1093 * Get the #AtkTextAttribute type corresponding to a text attribute name.
1095 * Returns: the #AtkTextAttribute enumerated type corresponding to the specified
1097 * or #ATK_TEXT_ATTRIBUTE_INVALID if no matching text attribute is found.
1100 atk_text_attribute_for_name (const gchar *name)
1102 GTypeClass *type_class;
1104 AtkTextAttribute type = ATK_TEXT_ATTR_INVALID;
1106 g_return_val_if_fail (name, ATK_TEXT_ATTR_INVALID);
1108 type_class = g_type_class_ref (ATK_TYPE_TEXT_ATTRIBUTE);
1109 g_return_val_if_fail (G_IS_ENUM_CLASS (type_class), ATK_TEXT_ATTR_INVALID);
1111 value = g_enum_get_value_by_nick (G_ENUM_CLASS (type_class), name);
1115 type = value->value;
1121 if (extra_attributes)
1123 for (i = 0; i < extra_attributes->len; i++)
1125 gchar *extra_attribute = (gchar *)g_ptr_array_index (extra_attributes, i);
1127 g_return_val_if_fail (extra_attribute, ATK_TEXT_ATTR_INVALID);
1129 if (strcmp (name, extra_attribute) == 0)
1131 type = i + 1 + ATK_TEXT_ATTR_LAST_DEFINED;
1137 g_type_class_unref (type_class);
1143 * atk_text_attribute_get_value:
1144 * @attr: The #AtkTextAttribute for which a value is required
1145 * @index_: The index of the required value
1147 * Gets the value for the index of the #AtkTextAttribute
1149 * Returns: a string containing the value; this string should not be freed;
1150 * NULL is returned if there are no values maintained for the attr value.
1152 G_CONST_RETURN gchar*
1153 atk_text_attribute_get_value (AtkTextAttribute attr,
1158 case ATK_TEXT_ATTR_INVISIBLE:
1159 case ATK_TEXT_ATTR_EDITABLE:
1160 case ATK_TEXT_ATTR_BG_FULL_HEIGHT:
1161 case ATK_TEXT_ATTR_STRIKETHROUGH:
1162 case ATK_TEXT_ATTR_BG_STIPPLE:
1163 case ATK_TEXT_ATTR_FG_STIPPLE:
1164 g_assert (index >= 0 && index < G_N_ELEMENTS (boolean_offsets));
1165 return boolean + boolean_offsets[index];
1166 case ATK_TEXT_ATTR_UNDERLINE:
1167 g_assert (index >= 0 && index < G_N_ELEMENTS (underline_offsets));
1168 return underline + underline_offsets[index];
1169 case ATK_TEXT_ATTR_WRAP_MODE:
1170 g_assert (index >= 0 && index < G_N_ELEMENTS (wrap_mode_offsets));
1171 return wrap_mode + wrap_mode_offsets[index];
1172 case ATK_TEXT_ATTR_DIRECTION:
1173 g_assert (index >= 0 && index < G_N_ELEMENTS (direction_offsets));
1174 return direction + direction_offsets[index];
1175 case ATK_TEXT_ATTR_JUSTIFICATION:
1176 g_assert (index >= 0 && index < G_N_ELEMENTS (justification_offsets));
1177 return justification + justification_offsets[index];
1178 case ATK_TEXT_ATTR_STRETCH:
1179 g_assert (index >= 0 && index < G_N_ELEMENTS (stretch_offsets));
1180 return stretch + stretch_offsets[index];
1181 case ATK_TEXT_ATTR_VARIANT:
1182 g_assert (index >= 0 && index < G_N_ELEMENTS (variant_offsets));
1183 return variant + variant_offsets[index];
1184 case ATK_TEXT_ATTR_STYLE:
1185 g_assert (index >= 0 && index < G_N_ELEMENTS (style_offsets));
1186 return style + style_offsets[index];
1193 atk_text_rectangle_union (AtkTextRectangle *src1,
1194 AtkTextRectangle *src2,
1195 AtkTextRectangle *dest)
1197 gint dest_x, dest_y;
1199 dest_x = MIN (src1->x, src2->x);
1200 dest_y = MIN (src1->y, src2->y);
1201 dest->width = MAX (src1->x + src1->width, src2->x + src2->width) - dest_x;
1202 dest->height = MAX (src1->y + src1->height, src2->y + src2->height) - dest_y;
1208 atk_text_rectangle_contain (AtkTextRectangle *clip,
1209 AtkTextRectangle *bounds,
1210 AtkTextClipType x_clip_type,
1211 AtkTextClipType y_clip_type)
1213 gboolean x_min_ok, x_max_ok, y_min_ok, y_max_ok;
1215 x_min_ok = (bounds->x >= clip->x) ||
1216 ((bounds->x + bounds->width >= clip->x) &&
1217 ((x_clip_type == ATK_TEXT_CLIP_NONE) ||
1218 (x_clip_type == ATK_TEXT_CLIP_MAX)));
1220 x_max_ok = (bounds->x + bounds->width <= clip->x + clip->width) ||
1221 ((bounds->x <= clip->x + clip->width) &&
1222 ((x_clip_type == ATK_TEXT_CLIP_NONE) ||
1223 (x_clip_type == ATK_TEXT_CLIP_MIN)));
1225 y_min_ok = (bounds->y >= clip->y) ||
1226 ((bounds->y + bounds->height >= clip->y) &&
1227 ((y_clip_type == ATK_TEXT_CLIP_NONE) ||
1228 (y_clip_type == ATK_TEXT_CLIP_MAX)));
1230 y_max_ok = (bounds->y + bounds->height <= clip->y + clip->height) ||
1231 ((bounds->y <= clip->y + clip->height) &&
1232 ((y_clip_type == ATK_TEXT_CLIP_NONE) ||
1233 (y_clip_type == ATK_TEXT_CLIP_MIN)));
1235 return (x_min_ok && x_max_ok && y_min_ok && y_max_ok);
1240 atk_text_real_get_range_extents (AtkText *text,
1243 AtkCoordType coord_type,
1244 AtkTextRectangle *rect)
1247 AtkTextRectangle cbounds, bounds;
1249 atk_text_get_character_extents (text, start_offset,
1250 &bounds.x, &bounds.y,
1251 &bounds.width, &bounds.height,
1254 for (i = start_offset + 1; i < end_offset; i++)
1256 atk_text_get_character_extents (text, i,
1257 &cbounds.x, &cbounds.y,
1258 &cbounds.width, &cbounds.height,
1260 atk_text_rectangle_union (&bounds, &cbounds, &bounds);
1265 rect->width = bounds.width;
1266 rect->height = bounds.height;
1269 static AtkTextRange**
1270 atk_text_real_get_bounded_ranges (AtkText *text,
1271 AtkTextRectangle *rect,
1272 AtkCoordType coord_type,
1273 AtkTextClipType x_clip_type,
1274 AtkTextClipType y_clip_type)
1276 gint bounds_min_offset, bounds_max_offset;
1277 gint min_line_start, min_line_end;
1278 gint max_line_start, max_line_end;
1282 gint num_ranges = 0;
1283 gint range_size = 1;
1284 AtkTextRectangle cbounds;
1285 AtkTextRange **range;
1288 bounds_min_offset = atk_text_get_offset_at_point (text, rect->x, rect->y, coord_type);
1289 bounds_max_offset = atk_text_get_offset_at_point (text, rect->x + rect->width, rect->y + rect->height, coord_type);
1291 if (bounds_min_offset == 0 &&
1292 bounds_min_offset == bounds_max_offset)
1295 line = atk_text_get_text_at_offset (text, bounds_min_offset,
1296 ATK_TEXT_BOUNDARY_LINE_START,
1297 &min_line_start, &min_line_end);
1299 line = atk_text_get_text_at_offset (text, bounds_max_offset,
1300 ATK_TEXT_BOUNDARY_LINE_START,
1301 &max_line_start, &max_line_end);
1303 bounds_min_offset = MIN (min_line_start, max_line_start);
1304 bounds_max_offset = MAX (min_line_end, max_line_end);
1306 curr_offset = bounds_min_offset;
1307 while (curr_offset < bounds_max_offset)
1309 offset = curr_offset;
1311 while (curr_offset < bounds_max_offset)
1313 atk_text_get_character_extents (text, curr_offset,
1314 &cbounds.x, &cbounds.y,
1315 &cbounds.width, &cbounds.height,
1317 if (!atk_text_rectangle_contain (rect, &cbounds, x_clip_type, y_clip_type))
1321 if (curr_offset > offset)
1323 AtkTextRange *one_range = g_new (AtkTextRange, 1);
1325 one_range->start_offset = offset;
1326 one_range->end_offset = curr_offset;
1327 one_range->content = atk_text_get_text (text, offset, curr_offset);
1328 atk_text_get_range_extents (text, offset, curr_offset, coord_type, &one_range->bounds);
1330 if (num_ranges >= range_size - 1)
1333 range = g_realloc (range, range_size * sizeof (gpointer));
1335 range[num_ranges] = one_range;
1340 range[num_ranges] = NULL;
1346 * atk_text_free_ranges:
1347 * @ranges: A pointer to an array of #AtkTextRange which is to be freed.
1349 * Frees the memory associated with an array of AtkTextRange. It is assumed
1350 * that the array was returned by the function atk_text_get_bounded_ranges
1351 * and is NULL terminated.
1356 atk_text_free_ranges (AtkTextRange **ranges)
1358 AtkTextRange **first = ranges;
1364 AtkTextRange *range;
1368 g_free (range->content);