1 /* ATK - The Accessibility Toolkit for GTK+
2 * Copyright 2001 Sun Microsystems Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 #include "atkmarshal.h"
22 #include "atk-enum-types.h"
26 static GPtrArray *extra_attributes = NULL;
31 TEXT_SELECTION_CHANGED,
32 TEXT_ATTRIBUTES_CHANGED,
36 static const gchar * const bool[] = {"false",
38 static const gchar * const style[] = {"normal",
41 static const gchar * const variant[] = {"normal",
43 static const gchar * const stretch[] = {"ultra_condensed",
52 static const gchar * const justification[] = {"left",
56 static const gchar * const direction[] = {"none",
59 static const gchar * const wrap_mode[] = {"none",
62 static const gchar * const underline[] = {"none",
67 static void atk_text_base_init (AtkTextIface *class);
69 static void atk_text_real_get_range_extents (AtkText *text,
72 AtkCoordType coord_type,
73 AtkTextRectangle *rect);
75 static AtkTextRange** atk_text_real_get_bounded_ranges (AtkText *text,
76 AtkTextRectangle *rect,
77 AtkCoordType coord_type,
78 AtkTextClipType x_clip_type,
79 AtkTextClipType y_clip_type);
81 static guint atk_text_signals[LAST_SIGNAL] = { 0 };
84 atk_text_get_type (void)
86 static GType type = 0;
90 static const GTypeInfo tinfo =
92 sizeof (AtkTextIface),
93 (GBaseInitFunc) atk_text_base_init,
94 (GBaseFinalizeFunc) NULL,
95 (GClassInitFunc) NULL /* atk_text_interface_init */ ,
96 (GClassFinalizeFunc) NULL,
100 type = g_type_register_static (G_TYPE_INTERFACE, "AtkText", &tinfo, 0);
107 atk_text_base_init (AtkTextIface *class)
109 static gboolean initialized = FALSE;
114 * Note that text_changed signal supports details "insert", "delete",
115 * possibly "replace".
118 class->get_range_extents = atk_text_real_get_range_extents;
119 class->get_bounded_ranges = atk_text_real_get_bounded_ranges;
121 atk_text_signals[TEXT_CHANGED] =
122 g_signal_new ("text_changed",
124 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
125 G_STRUCT_OFFSET (AtkTextIface, text_changed),
126 (GSignalAccumulator) NULL, NULL,
127 atk_marshal_VOID__INT_INT,
129 2, G_TYPE_INT, G_TYPE_INT);
131 atk_text_signals[TEXT_CARET_MOVED] =
132 g_signal_new ("text_caret_moved",
135 G_STRUCT_OFFSET (AtkTextIface, text_caret_moved),
136 (GSignalAccumulator) NULL, NULL,
137 g_cclosure_marshal_VOID__INT,
140 atk_text_signals[TEXT_SELECTION_CHANGED] =
141 g_signal_new ("text_selection_changed",
144 G_STRUCT_OFFSET (AtkTextIface, text_selection_changed),
145 (GSignalAccumulator) NULL, NULL,
146 g_cclosure_marshal_VOID__VOID,
148 atk_text_signals[TEXT_ATTRIBUTES_CHANGED] =
149 g_signal_new ("text_attributes_changed",
152 G_STRUCT_OFFSET (AtkTextIface, text_attributes_changed),
153 (GSignalAccumulator) NULL, NULL,
154 g_cclosure_marshal_VOID__VOID,
165 * @start_offset: start position
166 * @end_offset: end position
168 * Gets the specified text.
170 * Returns: the text from @start_offset up to, but not including @end_offset.
173 atk_text_get_text (AtkText *text,
179 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
181 iface = ATK_TEXT_GET_IFACE (text);
183 if (start_offset < 0 || end_offset < -1)
187 return (*(iface->get_text)) (text, start_offset, end_offset);
193 * atk_text_get_character_at_offset:
197 * Gets the specified text.
199 * Returns: the character at @offset.
202 atk_text_get_character_at_offset (AtkText *text,
207 g_return_val_if_fail (ATK_IS_TEXT (text), (gunichar) 0);
212 iface = ATK_TEXT_GET_IFACE (text);
214 if (iface->get_character_at_offset)
215 return (*(iface->get_character_at_offset)) (text, offset);
221 * atk_text_get_text_after_offset:
224 * @boundary_type: An #AtkTextBoundary
225 * @start_offset: the start offset of the returned string
226 * @end_offset: the offset of the first character after the
229 * Gets the specified text.
231 * If the boundary_type if ATK_TEXT_BOUNDARY_CHAR the character after the
232 * offset is returned.
234 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START the returned string
235 * is from the word start after the offset to the next word start.
237 * The returned string will contain the word after the offset if the offset
238 * is inside a word or if the offset is not inside a word.
240 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_END the returned string
241 * is from the word end at or after the offset to the next work end.
243 * The returned string will contain the word after the offset if the offset
244 * is inside a word and will contain the word after the word after the offset
245 * if the offset is not inside a word.
247 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the returned
248 * string is from the sentence start after the offset to the next sentence
251 * The returned string will contain the sentence after the offset if the offset
252 * is inside a sentence or if the offset is not inside a sentence.
254 * If the boundary_type is ATK_TEXT_BOUNDARY_SENTENCE_END the returned string
255 * is from the sentence end at or after the offset to the next sentence end.
257 * The returned string will contain the sentence after the offset if the offset
258 * is inside a sentence and will contain the sentence after the sentence
259 * after the offset if the offset is not inside a sentence.
261 * If the boundary type is ATK_TEXT_BOUNDARY_LINE_START the returned
262 * string is from the line start after the offset to the next line start.
264 * If the boundary_type is ATK_TEXT_BOUNDARY_LINE_END the returned string
265 * is from the line end at or after the offset to the next line start.
267 * Returns: the text after @offset bounded by the specified @boundary_type.
270 atk_text_get_text_after_offset (AtkText *text,
272 AtkTextBoundary boundary_type,
277 gint local_start_offset, local_end_offset;
278 gint *real_start_offset, *real_end_offset;
280 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
283 real_start_offset = start_offset;
285 real_start_offset = &local_start_offset;
287 real_end_offset = end_offset;
289 real_end_offset = &local_end_offset;
294 iface = ATK_TEXT_GET_IFACE (text);
296 if (iface->get_text_after_offset)
297 return (*(iface->get_text_after_offset)) (text, offset, boundary_type, real_start_offset, real_end_offset);
303 * atk_text_get_text_at_offset:
306 * @boundary_type: An #AtkTextBoundary
307 * @start_offset: the start offset of the returned string
308 * @end_offset: the offset of the first character after the
311 * Gets the specified text.
313 * If the boundary_type if ATK_TEXT_BOUNDARY_CHAR the character at the
314 * offset is returned.
316 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START the returned string
317 * is from the word start at or before the offset to the word start after
320 * The returned string will contain the word at the offset if the offset
321 * is inside a word and will contain the word before the offset if the
322 * offset is not inside a word.
324 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_END the returned string
325 * is from the word end before the offset to the word end at or after the
328 * The returned string will contain the word at the offset if the offset
329 * is inside a word and will contain the word after to the offset if the
330 * offset is not inside a word.
332 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the returned
333 * string is from the sentence start at or before the offset to the sentence
334 * start after the offset.
336 * The returned string will contain the sentence at the offset if the offset
337 * is inside a sentence and will contain the sentence before the offset
338 * if the offset is not inside a sentence.
340 * If the boundary_type is ATK_TEXT_BOUNDARY_SENTENCE_END the returned string
341 * is from the sentence end before the offset to the sentence end at or
344 * The returned string will contain the sentence at the offset if the offset
345 * is inside a sentence and will contain the sentence after the offset
346 * if the offset is not inside a sentence.
348 * If the boundary type is ATK_TEXT_BOUNDARY_LINE_START the returned
349 * string is from the line start at or before the offset to the line
350 * start after the offset.
352 * If the boundary_type is ATK_TEXT_BOUNDARY_LINE_END the returned string
353 * is from the line end before the offset to the line end at or after
356 * Returns: the text at @offset bounded by the specified @boundary_type.
359 atk_text_get_text_at_offset (AtkText *text,
361 AtkTextBoundary boundary_type,
366 gint local_start_offset, local_end_offset;
367 gint *real_start_offset, *real_end_offset;
369 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
372 real_start_offset = start_offset;
374 real_start_offset = &local_start_offset;
376 real_end_offset = end_offset;
378 real_end_offset = &local_end_offset;
383 iface = ATK_TEXT_GET_IFACE (text);
385 if (iface->get_text_at_offset)
386 return (*(iface->get_text_at_offset)) (text, offset, boundary_type, real_start_offset, real_end_offset);
392 * atk_text_get_text_before_offset:
395 * @boundary_type: An #AtkTextBoundary
396 * @start_offset: the start offset of the returned string
397 * @end_offset: the offset of the first character after the
400 * Gets the specified text.
402 * If the boundary_type if ATK_TEXT_BOUNDARY_CHAR the character before the
403 * offset is returned.
405 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START the returned string
406 * is from the word start before the word start before the offset to
407 * the word start before the offset.
409 * The returned string will contain the word before the offset if the offset
410 * is inside a word and will contain the word before the word before the
411 * offset if the offset is not inside a word.
413 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_END the returned string
414 * is from the word end before the word end at or before the offset to the
415 * word end at or before the offset.
417 * The returned string will contain the word before the offset if the offset
418 * is inside a word or if the offset is not inside a word.
420 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the returned
421 * string is from the sentence start before the sentence start before
422 * the offset to the sentence start before the offset.
424 * The returned string will contain the sentence before the offset if the
425 * offset is inside a sentence and will contain the sentence before the
426 * sentence before the offset if the offset is not inside a sentence.
428 * If the boundary_type is ATK_TEXT_BOUNDARY_SENTENCE_END the returned string
429 * is from the sentence end before the sentence end at or before the offset to
430 * the sentence end at or before the offset.
432 * The returned string will contain the sentence before the offset if the
433 * offset is inside a sentence or if the offset is not inside a sentence.
435 * If the boundary type is ATK_TEXT_BOUNDARY_LINE_START the returned
436 * string is from the line start before the line start ar or before the offset
437 * to the line start ar or before the offset.
439 * If the boundary_type is ATK_TEXT_BOUNDARY_LINE_END the returned string
440 * is from the line end before the line end before the offset to the
441 * line end before the offset.
443 * Returns: the text before @offset bounded by the specified @boundary_type.
446 atk_text_get_text_before_offset (AtkText *text,
448 AtkTextBoundary boundary_type,
453 gint local_start_offset, local_end_offset;
454 gint *real_start_offset, *real_end_offset;
456 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
459 real_start_offset = start_offset;
461 real_start_offset = &local_start_offset;
463 real_end_offset = end_offset;
465 real_end_offset = &local_end_offset;
470 iface = ATK_TEXT_GET_IFACE (text);
472 if (iface->get_text_before_offset)
473 return (*(iface->get_text_before_offset)) (text, offset, boundary_type, real_start_offset, real_end_offset);
479 * atk_text_get_caret_offset:
482 * Gets the offset position of the caret (cursor).
484 * Returns: the offset position of the caret (cursor).
487 atk_text_get_caret_offset (AtkText *text)
491 g_return_val_if_fail (ATK_IS_TEXT (text), 0);
493 iface = ATK_TEXT_GET_IFACE (text);
495 if (iface->get_caret_offset)
496 return (*(iface->get_caret_offset)) (text);
502 * atk_text_get_character_extents:
504 * @offset: The offset of the text character for which bounding information is required.
505 * @x: Pointer for the x cordinate of the bounding box
506 * @y: Pointer for the y cordinate of the bounding box
507 * @width: Pointer for the width of the bounding box
508 * @height: Pointer for the height of the bounding box
509 * @coords: specify whether coordinates are relative to the screen or widget window
511 * Get the bounding box containing the glyph representing the character at
512 * a particular text offset.
515 atk_text_get_character_extents (AtkText *text,
524 gint local_x, local_y, local_width, local_height;
525 gint *real_x, *real_y, *real_width, *real_height;
527 g_return_if_fail (ATK_IS_TEXT (text));
540 real_width = &local_width;
542 real_height = height;
544 real_height = &local_height;
554 iface = ATK_TEXT_GET_IFACE (text);
556 if (iface->get_character_extents)
557 (*(iface->get_character_extents)) (text, offset, real_x, real_y, real_width, real_height, coords);
561 *real_x = *real_x + *real_width;
567 *atk_text_get_run_attributes:
569 *@offset: the offset at which to get the attributes
570 *@start_offset: the address to put the start offset of the range
571 *@end_offset: the address to put the end offset of the range
573 *Creates an #AtkAttributeSet which consists of the attributes explicitly
574 *set at the position @offset in the text. @start_offset and @end_offset are
575 *set to the start and end of the range around @offset where the attributes are
576 *invariant. Note that @end_offset is the offset of the first character
577 *after the range. See the enum AtkTextAttribute for types of text
578 *attributes that can be returned. Note that other attributes may also be
581 *Returns: an #AtkAttributeSet which contains the attributes explicitly set
582 *at @offset. This #AtkAttributeSet should be freed by a call to
583 *atk_attribute_set_free().
586 atk_text_get_run_attributes (AtkText *text,
592 gint local_start_offset, local_end_offset;
593 gint *real_start_offset, *real_end_offset;
595 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
598 real_start_offset = start_offset;
600 real_start_offset = &local_start_offset;
602 real_end_offset = end_offset;
604 real_end_offset = &local_end_offset;
609 iface = ATK_TEXT_GET_IFACE (text);
611 if (iface->get_run_attributes)
612 return (*(iface->get_run_attributes)) (text, offset, real_start_offset, real_end_offset);
618 *atk_text_get_default_attributes:
621 *Creates an #AtkAttributeSet which consists of the default values of
622 *attributes for the text. See the enum AtkTextAttribute for types of text
623 *attributes that can be returned. Note that other attributes may also be
626 *Returns: an #AtkAttributeSet which contains the default values of attributes.
627 *at @offset. This #AtkAttributeSet should be freed by a call to
628 *atk_attribute_set_free().
631 atk_text_get_default_attributes (AtkText *text)
635 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
637 iface = ATK_TEXT_GET_IFACE (text);
639 if (iface->get_default_attributes)
640 return (*(iface->get_default_attributes)) (text);
646 * atk_text_get_character_count:
649 * Gets the character count.
651 * Returns: the number of characters.
654 atk_text_get_character_count (AtkText *text)
658 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
660 iface = ATK_TEXT_GET_IFACE (text);
662 if (iface->get_character_count)
663 return (*(iface->get_character_count)) (text);
669 * atk_text_get_offset_at_point:
671 * @x: screen x-position of character
672 * @y: screen y-position of character
673 * @coords: specify whether coordinates are relative to the screen or
676 * Gets the offset of the character located at coordinates @x and @y. @x and @y
677 * are interpreted as being relative to the screen or this widget's window
678 * depending on @coords.
680 * Returns: the offset to the character which is located at
681 * the specified @x and @y coordinates.
684 atk_text_get_offset_at_point (AtkText *text,
691 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
693 iface = ATK_TEXT_GET_IFACE (text);
695 if (iface->get_offset_at_point)
696 return (*(iface->get_offset_at_point)) (text, x, y, coords);
702 * atk_text_get_n_selections:
705 * Gets the number of selected regions.
707 * Returns: The number of selected regions, or -1 if a failure
711 atk_text_get_n_selections (AtkText *text)
715 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
717 iface = ATK_TEXT_GET_IFACE (text);
719 if (iface->get_n_selections)
720 return (*(iface->get_n_selections)) (text);
726 * atk_text_get_selection:
728 * @selection_num: The selection number. The selected regions are
729 * assigned numbers that correspond to how far the region is from the
730 * start of the text. The selected region closest to the beginning
731 * of the text region is assigned the number 0, etc. Note that adding,
732 * moving or deleting a selected region can change the numbering.
733 * @start_offset: passes back the start position of the selected region
734 * @end_offset: passes back the end position of (e.g. offset immediately past)
735 * the selected region
737 * Gets the text from the specified selection.
739 * Returns: the selected text.
742 atk_text_get_selection (AtkText *text,
748 gint local_start_offset, local_end_offset;
749 gint *real_start_offset, *real_end_offset;
751 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
754 real_start_offset = start_offset;
756 real_start_offset = &local_start_offset;
758 real_end_offset = end_offset;
760 real_end_offset = &local_end_offset;
762 iface = ATK_TEXT_GET_IFACE (text);
764 if (iface->get_selection)
766 return (*(iface->get_selection)) (text, selection_num,
767 real_start_offset, real_end_offset);
774 * atk_text_add_selection:
776 * @start_offset: the start position of the selected region
777 * @end_offset: the offset of the first character after the selected region.
779 * Adds a selection bounded by the specified offsets.
781 * Returns: %TRUE if success, %FALSE otherwise
784 atk_text_add_selection (AtkText *text,
790 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
792 iface = ATK_TEXT_GET_IFACE (text);
794 if (iface->add_selection)
795 return (*(iface->add_selection)) (text, start_offset, end_offset);
801 * atk_text_remove_selection:
803 * @selection_num: The selection number. The selected regions are
804 * assigned numbers that correspond to how far the region is from the
805 * start of the text. The selected region closest to the beginning
806 * of the text region is assigned the number 0, etc. Note that adding,
807 * moving or deleting a selected region can change the numbering.
809 * Removes the specified selection.
811 * Returns: %TRUE if success, %FALSE otherwise
814 atk_text_remove_selection (AtkText *text,
819 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
821 iface = ATK_TEXT_GET_IFACE (text);
823 if (iface->remove_selection)
824 return (*(iface->remove_selection)) (text, selection_num);
830 * atk_text_set_selection:
832 * @selection_num: The selection number. The selected regions are
833 * assigned numbers that correspond to how far the region is from the
834 * start of the text. The selected region closest to the beginning
835 * of the text region is assigned the number 0, etc. Note that adding,
836 * moving or deleting a selected region can change the numbering.
837 * @start_offset: the new start position of the selection
838 * @end_offset: the new end position of (e.g. offset immediately past)
841 * Changes the start and end offset of the specified selection.
843 * Returns: %TRUE if success, %FALSE otherwise
846 atk_text_set_selection (AtkText *text,
853 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
855 iface = ATK_TEXT_GET_IFACE (text);
857 if (iface->set_selection)
859 return (*(iface->set_selection)) (text, selection_num,
860 start_offset, end_offset);
867 * atk_text_set_caret_offset:
871 * Sets the caret (cursor) position to the specified @offset.
873 * Returns: %TRUE if success, %FALSE otherwise.
876 atk_text_set_caret_offset (AtkText *text,
881 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
883 iface = ATK_TEXT_GET_IFACE (text);
885 if (iface->set_caret_offset)
887 return (*(iface->set_caret_offset)) (text, offset);
896 * atk_text_get_range_extents:
898 * @start_offset: The offset of the first text character for which boundary
899 * information is required.
900 * @end_offset: The offset of the text character after the last character
901 * for which boundary information is required.
902 * @coord_type: Specify whether coordinates are relative to the screen or widget window.
903 * @rect: A pointer to a AtkTextRectangle which is filled in by this function.
905 * Get the bounding box for text within the specified range.
910 atk_text_get_range_extents (AtkText *text,
913 AtkCoordType coord_type,
914 AtkTextRectangle *rect)
918 g_return_if_fail (ATK_IS_TEXT (text));
919 g_return_if_fail (rect);
921 if (start_offset < 0 || start_offset >= end_offset)
924 iface = ATK_TEXT_GET_IFACE (text);
926 if (iface->get_range_extents)
927 (*(iface->get_range_extents)) (text, start_offset, end_offset, coord_type, rect);
931 * atk_text_get_bounded_ranges:
933 * @rect: An AtkTextRectagle giving the dimensions of the bounding box.
934 * @coord_type: Specify whether coordinates are relative to the screen or widget window.
935 * @x_clip_type: Specify the horizontal clip type.
936 * @y_clip_type: Specify the vertical clip type.
938 * Get the ranges of text in the specified bounding box.
942 * Returns: Array of AtkTextRange. The last element of the array returned
943 * by this function will be NULL.
946 atk_text_get_bounded_ranges (AtkText *text,
947 AtkTextRectangle *rect,
948 AtkCoordType coord_type,
949 AtkTextClipType x_clip_type,
950 AtkTextClipType y_clip_type)
954 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
955 g_return_val_if_fail (rect, NULL);
957 iface = ATK_TEXT_GET_IFACE (text);
959 if (iface->get_bounded_ranges)
960 return (*(iface->get_bounded_ranges)) (text, rect, coord_type, x_clip_type, y_clip_type);
966 * atk_attribute_set_free:
967 * @attrib_set: The #AtkAttributeSet to free
969 * Frees the memory used by an #AtkAttributeSet, including all its
973 atk_attribute_set_free (AtkAttributeSet *attrib_set)
990 g_slist_free (attrib_set);
994 * atk_text_attribute_register:
995 * @name: a name string
997 * Associate @name with a new #AtkTextAttribute
999 * Returns: an #AtkTextAttribute associated with @name
1002 atk_text_attribute_register (const gchar *name)
1004 g_return_val_if_fail (name, ATK_TEXT_ATTR_INVALID);
1006 if (!extra_attributes)
1007 extra_attributes = g_ptr_array_new ();
1009 g_ptr_array_add (extra_attributes, g_strdup (name));
1010 return extra_attributes->len + ATK_TEXT_ATTR_LAST_DEFINED;
1014 * atk_text_attribute_get_name:
1015 * @attr: The #AtkTextAttribute whose name is required
1017 * Gets the name corresponding to the #AtkTextAttribute
1019 * Returns: a string containing the name; this string should not be freed
1021 G_CONST_RETURN gchar*
1022 atk_text_attribute_get_name (AtkTextAttribute attr)
1024 GTypeClass *type_class;
1028 type_class = g_type_class_ref (ATK_TYPE_TEXT_ATTRIBUTE);
1029 g_return_val_if_fail (G_IS_ENUM_CLASS (type_class), NULL);
1031 value = g_enum_get_value (G_ENUM_CLASS (type_class), attr);
1035 name = value->value_nick;
1039 if (extra_attributes)
1043 n -= ATK_TEXT_ATTR_LAST_DEFINED + 1;
1045 if (n < extra_attributes->len)
1047 name = g_ptr_array_index (extra_attributes, n);
1050 g_type_class_unref (type_class);
1055 * atk_text_attribute_for_name:
1056 * @name: a string which is the (non-localized) name of an ATK text attribute.
1058 * Get the #AtkTextAttribute type corresponding to a text attribute name.
1060 * Returns: the #AtkTextAttribute enumerated type corresponding to the specified
1062 * or #ATK_TEXT_ATTRIBUTE_INVALID if no matching text attribute is found.
1065 atk_text_attribute_for_name (const gchar *name)
1067 GTypeClass *type_class;
1069 AtkTextAttribute type = ATK_TEXT_ATTR_INVALID;
1071 g_return_val_if_fail (name, ATK_TEXT_ATTR_INVALID);
1073 type_class = g_type_class_ref (ATK_TYPE_TEXT_ATTRIBUTE);
1074 g_return_val_if_fail (G_IS_ENUM_CLASS (type_class), ATK_TEXT_ATTR_INVALID);
1076 value = g_enum_get_value_by_nick (G_ENUM_CLASS (type_class), name);
1080 type = value->value;
1086 if (extra_attributes)
1088 for (i = 0; i < extra_attributes->len; i++)
1090 gchar *extra_attribute = (gchar *)g_ptr_array_index (extra_attributes, i);
1092 g_return_val_if_fail (extra_attribute, ATK_TEXT_ATTR_INVALID);
1094 if (strcmp (name, extra_attribute) == 0)
1096 type = i + 1 + ATK_TEXT_ATTR_LAST_DEFINED;
1102 g_type_class_unref (type_class);
1108 * atk_text_attribute_get_value:
1109 * @attr: The #AtkTextAttribute for which a value is required
1110 * @index_: The index of the required value
1112 * Gets the value for the index of the #AtkTextAttribute
1114 * Returns: a string containing the value; this string should not be freed;
1115 * NULL is returned if there are no values maintained for the attr value.
1117 G_CONST_RETURN gchar*
1118 atk_text_attribute_get_value (AtkTextAttribute attr,
1123 case ATK_TEXT_ATTR_INVISIBLE:
1124 case ATK_TEXT_ATTR_EDITABLE:
1125 case ATK_TEXT_ATTR_BG_FULL_HEIGHT:
1126 case ATK_TEXT_ATTR_STRIKETHROUGH:
1127 case ATK_TEXT_ATTR_BG_STIPPLE:
1128 case ATK_TEXT_ATTR_FG_STIPPLE:
1129 g_assert (index >= 0 && index < 2);
1131 case ATK_TEXT_ATTR_UNDERLINE:
1132 g_assert (index >= 0 && index < 5);
1133 return underline[index];
1134 case ATK_TEXT_ATTR_WRAP_MODE:
1135 g_assert (index >= 0 && index < 4);
1136 return wrap_mode[index];
1137 case ATK_TEXT_ATTR_DIRECTION:
1138 g_assert (index >= 0 && index < 3);
1139 return direction[index];
1140 case ATK_TEXT_ATTR_JUSTIFICATION:
1141 g_assert (index >= 0 && index < 3);
1142 return justification[index];
1143 case ATK_TEXT_ATTR_STRETCH:
1144 g_assert (index >= 0 && index < 9);
1145 return stretch[index];
1146 case ATK_TEXT_ATTR_VARIANT:
1147 g_assert (index >= 0 && index < 2);
1148 return variant[index];
1149 case ATK_TEXT_ATTR_STYLE:
1150 g_assert (index >= 0 && index < 3);
1151 return style[index];
1158 atk_text_rectangle_union (AtkTextRectangle *src1,
1159 AtkTextRectangle *src2,
1160 AtkTextRectangle *dest)
1162 gint dest_x, dest_y;
1164 dest_x = MIN (src1->x, src2->x);
1165 dest_y = MIN (src1->y, src2->y);
1166 dest->width = MAX (src1->x + src1->width, src2->x + src2->width) - dest_x;
1167 dest->height = MAX (src1->y + src1->height, src2->y + src2->height) - dest_y;
1173 atk_text_rectangle_contain (AtkTextRectangle *clip,
1174 AtkTextRectangle *bounds,
1175 AtkTextClipType x_clip_type,
1176 AtkTextClipType y_clip_type)
1178 gboolean x_min_ok, x_max_ok, y_min_ok, y_max_ok;
1180 x_min_ok = (bounds->x >= clip->x) ||
1181 ((bounds->x + bounds->width >= clip->x) &&
1182 ((x_clip_type == ATK_TEXT_CLIP_NONE) ||
1183 (x_clip_type == ATK_TEXT_CLIP_MAX)));
1185 x_max_ok = (bounds->x + bounds->width <= clip->x + clip->width) ||
1186 ((bounds->x <= clip->x + clip->width) &&
1187 ((x_clip_type == ATK_TEXT_CLIP_NONE) ||
1188 (x_clip_type == ATK_TEXT_CLIP_MIN)));
1190 y_min_ok = (bounds->y >= clip->y) ||
1191 ((bounds->y + bounds->height >= clip->y) &&
1192 ((y_clip_type == ATK_TEXT_CLIP_NONE) ||
1193 (y_clip_type == ATK_TEXT_CLIP_MAX)));
1195 y_max_ok = (bounds->y + bounds->height <= clip->y + clip->height) ||
1196 ((bounds->y <= clip->y + clip->height) &&
1197 ((y_clip_type == ATK_TEXT_CLIP_NONE) ||
1198 (y_clip_type == ATK_TEXT_CLIP_MIN)));
1200 return (x_min_ok && x_max_ok && y_min_ok && y_max_ok);
1205 atk_text_real_get_range_extents (AtkText *text,
1208 AtkCoordType coord_type,
1209 AtkTextRectangle *rect)
1212 AtkTextRectangle cbounds, bounds;
1214 atk_text_get_character_extents (text, start_offset,
1215 &bounds.x, &bounds.y,
1216 &bounds.width, &bounds.height,
1219 for (i = start_offset + 1; i < end_offset; i++)
1221 atk_text_get_character_extents (text, i,
1222 &cbounds.x, &cbounds.y,
1223 &cbounds.width, &cbounds.height,
1225 atk_text_rectangle_union (&bounds, &cbounds, &bounds);
1230 rect->width = bounds.width;
1231 rect->height = bounds.height;
1234 static AtkTextRange**
1235 atk_text_real_get_bounded_ranges (AtkText *text,
1236 AtkTextRectangle *rect,
1237 AtkCoordType coord_type,
1238 AtkTextClipType x_clip_type,
1239 AtkTextClipType y_clip_type)
1241 gint bounds_min_offset, bounds_max_offset;
1242 gint min_line_start, min_line_end;
1243 gint max_line_start, max_line_end;
1247 gint num_ranges = 0;
1248 gint range_size = 1;
1249 AtkTextRectangle cbounds;
1250 AtkTextRange **range;
1253 bounds_min_offset = atk_text_get_offset_at_point (text, rect->x, rect->y, coord_type);
1254 bounds_max_offset = atk_text_get_offset_at_point (text, rect->x + rect->width, rect->y + rect->height, coord_type);
1256 if (bounds_min_offset == 0 &&
1257 bounds_min_offset == bounds_max_offset)
1260 line = atk_text_get_text_at_offset (text, bounds_min_offset,
1261 ATK_TEXT_BOUNDARY_LINE_START,
1262 &min_line_start, &min_line_end);
1264 line = atk_text_get_text_at_offset (text, bounds_max_offset,
1265 ATK_TEXT_BOUNDARY_LINE_START,
1266 &max_line_start, &max_line_end);
1268 bounds_min_offset = MIN (min_line_start, max_line_start);
1269 bounds_max_offset = MAX (min_line_end, max_line_end);
1271 curr_offset = bounds_min_offset;
1272 while (curr_offset < bounds_max_offset)
1274 offset = curr_offset;
1276 while (curr_offset < bounds_max_offset)
1278 atk_text_get_character_extents (text, curr_offset,
1279 &cbounds.x, &cbounds.y,
1280 &cbounds.width, &cbounds.height,
1282 if (!atk_text_rectangle_contain (rect, &cbounds, x_clip_type, y_clip_type))
1286 if (curr_offset > offset)
1288 AtkTextRange *one_range = g_new (AtkTextRange, 1);
1290 one_range->start_offset = offset;
1291 one_range->end_offset = curr_offset;
1292 one_range->content = atk_text_get_text (text, offset, curr_offset);
1293 atk_text_get_range_extents (text, offset, curr_offset, coord_type, &one_range->bounds);
1295 if (num_ranges >= range_size - 1)
1298 range = g_realloc (range, range_size * sizeof (gpointer));
1300 range[num_ranges] = one_range;
1305 range[num_ranges] = NULL;
1311 * atk_text_free_ranges:
1312 * @ranges: A pointer to an array of #AtkTextRange which is to be freed.
1314 * Frees the memory associated with an array of AtkTextRange. It is assumed
1315 * that the array was returned by the function atk_text_get_bounded_ranges
1316 * and is NULL terminated.
1321 atk_text_free_ranges (AtkTextRange **ranges)
1323 AtkTextRange **first = ranges;
1329 AtkTextRange *range;
1333 g_free (range->content);