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: (out): the start offset of the returned string
299 * @end_offset: (out): 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 * Deprecated: This method is deprecated since ATK version
341 * 2.9.3. Please use atk_text_get_at_offset() instead.
343 * Returns: a newly allocated string containing the text after @offset bounded
344 * by the specified @boundary_type. Use g_free() to free the returned string.
347 atk_text_get_text_after_offset (AtkText *text,
349 AtkTextBoundary boundary_type,
354 gint local_start_offset, local_end_offset;
355 gint *real_start_offset, *real_end_offset;
357 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
360 real_start_offset = start_offset;
362 real_start_offset = &local_start_offset;
364 real_end_offset = end_offset;
366 real_end_offset = &local_end_offset;
371 iface = ATK_TEXT_GET_IFACE (text);
373 if (iface->get_text_after_offset)
374 return (*(iface->get_text_after_offset)) (text, offset, boundary_type, real_start_offset, real_end_offset);
380 * atk_text_get_text_at_offset:
383 * @boundary_type: An #AtkTextBoundary
384 * @start_offset: (out): the start offset of the returned string
385 * @end_offset: (out): the offset of the first character after the
388 * Gets the specified text.
390 * If the boundary_type if ATK_TEXT_BOUNDARY_CHAR the character at the
391 * offset is returned.
393 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START the returned string
394 * is from the word start at or before the offset to the word start after
397 * The returned string will contain the word at the offset if the offset
398 * is inside a word and will contain the word before the offset if the
399 * offset is not inside a word.
401 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_END the returned string
402 * is from the word end before the offset to the word end at or after the
405 * The returned string will contain the word at the offset if the offset
406 * is inside a word and will contain the word after to the offset if the
407 * offset is not inside a word.
409 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the returned
410 * string is from the sentence start at or before the offset to the sentence
411 * start after the offset.
413 * The returned string will contain the sentence at the offset if the offset
414 * is inside a sentence and will contain the sentence before the offset
415 * if the offset is not inside a sentence.
417 * If the boundary_type is ATK_TEXT_BOUNDARY_SENTENCE_END the returned string
418 * is from the sentence end before the offset to the sentence end at or
421 * The returned string will contain the sentence at the offset if the offset
422 * is inside a sentence and will contain the sentence after the offset
423 * if the offset is not inside a sentence.
425 * If the boundary type is ATK_TEXT_BOUNDARY_LINE_START the returned
426 * string is from the line start at or before the offset to the line
427 * start after the offset.
429 * If the boundary_type is ATK_TEXT_BOUNDARY_LINE_END the returned string
430 * is from the line end before the offset to the line end at or after
433 * Returns: a newly allocated string containing the text at @offset bounded by
434 * the specified @boundary_type. Use g_free() to free the returned string.
437 atk_text_get_text_at_offset (AtkText *text,
439 AtkTextBoundary boundary_type,
444 gint local_start_offset, local_end_offset;
445 gint *real_start_offset, *real_end_offset;
447 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
450 real_start_offset = start_offset;
452 real_start_offset = &local_start_offset;
454 real_end_offset = end_offset;
456 real_end_offset = &local_end_offset;
458 iface = ATK_TEXT_GET_IFACE (text);
460 if (iface->get_text_at_offset)
461 return (*(iface->get_text_at_offset)) (text, offset, boundary_type, real_start_offset, real_end_offset);
467 * atk_text_get_text_before_offset:
470 * @boundary_type: An #AtkTextBoundary
471 * @start_offset: (out): the start offset of the returned string
472 * @end_offset: (out): the offset of the first character after the
475 * Gets the specified text.
477 * If the boundary_type if ATK_TEXT_BOUNDARY_CHAR the character before the
478 * offset is returned.
480 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START the returned string
481 * is from the word start before the word start before or at the offset to
482 * the word start before or at the offset.
484 * The returned string will contain the word before the offset if the offset
485 * is inside a word and will contain the word before the word before the
486 * offset if the offset is not inside a word.
488 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_END the returned string
489 * is from the word end before the word end before the offset to the word
490 * end before the offset.
492 * The returned string will contain the word before the offset if the offset
493 * is inside a word or if the offset is not inside a word.
495 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the returned
496 * string is from the sentence start before the sentence start before
497 * the offset to the sentence start before the offset.
499 * The returned string will contain the sentence before the offset if the
500 * offset is inside a sentence and will contain the sentence before the
501 * sentence before the offset if the offset is not inside a sentence.
503 * If the boundary_type is ATK_TEXT_BOUNDARY_SENTENCE_END the returned string
504 * is from the sentence end before the sentence end at or before the offset to
505 * the sentence end at or before the offset.
507 * The returned string will contain the sentence before the offset if the
508 * offset is inside a sentence or if the offset is not inside a sentence.
510 * If the boundary type is ATK_TEXT_BOUNDARY_LINE_START the returned
511 * string is from the line start before the line start ar or before the offset
512 * to the line start ar or before the offset.
514 * If the boundary_type is ATK_TEXT_BOUNDARY_LINE_END the returned string
515 * is from the line end before the line end before the offset to the
516 * line end before the offset.
518 * Deprecated: This method is deprecated since ATK version
519 * 2.9.3. Please use atk_text_get_at_offset() instead.
521 * Returns: a newly allocated string containing the text before @offset bounded
522 * by the specified @boundary_type. Use g_free() to free the returned string.
525 atk_text_get_text_before_offset (AtkText *text,
527 AtkTextBoundary boundary_type,
532 gint local_start_offset, local_end_offset;
533 gint *real_start_offset, *real_end_offset;
535 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
538 real_start_offset = start_offset;
540 real_start_offset = &local_start_offset;
542 real_end_offset = end_offset;
544 real_end_offset = &local_end_offset;
549 iface = ATK_TEXT_GET_IFACE (text);
551 if (iface->get_text_before_offset)
552 return (*(iface->get_text_before_offset)) (text, offset, boundary_type, real_start_offset, real_end_offset);
558 * atk_text_get_caret_offset:
561 * Gets the offset position of the caret (cursor).
563 * Returns: the offset position of the caret (cursor).
566 atk_text_get_caret_offset (AtkText *text)
570 g_return_val_if_fail (ATK_IS_TEXT (text), 0);
572 iface = ATK_TEXT_GET_IFACE (text);
574 if (iface->get_caret_offset)
575 return (*(iface->get_caret_offset)) (text);
581 * atk_text_get_character_extents:
583 * @offset: The offset of the text character for which bounding information is required.
584 * @x: Pointer for the x cordinate of the bounding box
585 * @y: Pointer for the y cordinate of the bounding box
586 * @width: Pointer for the width of the bounding box
587 * @height: Pointer for the height of the bounding box
588 * @coords: specify whether coordinates are relative to the screen or widget window
590 * Get the bounding box containing the glyph representing the character at
591 * a particular text offset.
594 atk_text_get_character_extents (AtkText *text,
603 gint local_x, local_y, local_width, local_height;
604 gint *real_x, *real_y, *real_width, *real_height;
606 g_return_if_fail (ATK_IS_TEXT (text));
619 real_width = &local_width;
621 real_height = height;
623 real_height = &local_height;
633 iface = ATK_TEXT_GET_IFACE (text);
635 if (iface->get_character_extents)
636 (*(iface->get_character_extents)) (text, offset, real_x, real_y, real_width, real_height, coords);
640 *real_x = *real_x + *real_width;
646 * atk_text_get_run_attributes:
648 *@offset: the offset at which to get the attributes, -1 means the offset of
649 *the character to be inserted at the caret location.
650 *@start_offset: (out): the address to put the start offset of the range
651 *@end_offset: (out): the address to put the end offset of the range
653 *Creates an #AtkAttributeSet which consists of the attributes explicitly
654 *set at the position @offset in the text. @start_offset and @end_offset are
655 *set to the start and end of the range around @offset where the attributes are
656 *invariant. Note that @end_offset is the offset of the first character
657 *after the range. See the enum AtkTextAttribute for types of text
658 *attributes that can be returned. Note that other attributes may also be
661 *Returns: (transfer full): an #AtkAttributeSet which contains the attributes
662 * explicitly set at @offset. This #AtkAttributeSet should be freed by a call
663 * to atk_attribute_set_free().
666 atk_text_get_run_attributes (AtkText *text,
672 gint local_start_offset, local_end_offset;
673 gint *real_start_offset, *real_end_offset;
675 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
678 real_start_offset = start_offset;
680 real_start_offset = &local_start_offset;
682 real_end_offset = end_offset;
684 real_end_offset = &local_end_offset;
689 iface = ATK_TEXT_GET_IFACE (text);
691 if (iface->get_run_attributes)
692 return (*(iface->get_run_attributes)) (text, offset, real_start_offset, real_end_offset);
698 * atk_text_get_default_attributes:
701 *Creates an #AtkAttributeSet which consists of the default values of
702 *attributes for the text. See the enum AtkTextAttribute for types of text
703 *attributes that can be returned. Note that other attributes may also be
706 *Returns: (transfer full): an #AtkAttributeSet which contains the default
707 * values of attributes. at @offset. this #atkattributeset should be freed by
708 * a call to atk_attribute_set_free().
711 atk_text_get_default_attributes (AtkText *text)
715 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
717 iface = ATK_TEXT_GET_IFACE (text);
719 if (iface->get_default_attributes)
720 return (*(iface->get_default_attributes)) (text);
726 * atk_text_get_character_count:
729 * Gets the character count.
731 * Returns: the number of characters.
734 atk_text_get_character_count (AtkText *text)
738 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
740 iface = ATK_TEXT_GET_IFACE (text);
742 if (iface->get_character_count)
743 return (*(iface->get_character_count)) (text);
749 * atk_text_get_offset_at_point:
751 * @x: screen x-position of character
752 * @y: screen y-position of character
753 * @coords: specify whether coordinates are relative to the screen or
756 * Gets the offset of the character located at coordinates @x and @y. @x and @y
757 * are interpreted as being relative to the screen or this widget's window
758 * depending on @coords.
760 * Returns: the offset to the character which is located at
761 * the specified @x and @y coordinates.
764 atk_text_get_offset_at_point (AtkText *text,
771 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
773 iface = ATK_TEXT_GET_IFACE (text);
775 if (iface->get_offset_at_point)
776 return (*(iface->get_offset_at_point)) (text, x, y, coords);
782 * atk_text_get_n_selections:
785 * Gets the number of selected regions.
787 * Returns: The number of selected regions, or -1 if a failure
791 atk_text_get_n_selections (AtkText *text)
795 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
797 iface = ATK_TEXT_GET_IFACE (text);
799 if (iface->get_n_selections)
800 return (*(iface->get_n_selections)) (text);
806 * atk_text_get_selection:
808 * @selection_num: The selection number. The selected regions are
809 * assigned numbers that correspond to how far the region is from the
810 * start of the text. The selected region closest to the beginning
811 * of the text region is assigned the number 0, etc. Note that adding,
812 * moving or deleting a selected region can change the numbering.
813 * @start_offset: (out): passes back the start position of the selected region
814 * @end_offset: (out): passes back the end position of (e.g. offset immediately past)
815 * the selected region
817 * Gets the text from the specified selection.
819 * Returns: a newly allocated string containing the selected text. Use g_free()
820 * to free the returned string.
823 atk_text_get_selection (AtkText *text,
829 gint local_start_offset, local_end_offset;
830 gint *real_start_offset, *real_end_offset;
832 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
835 real_start_offset = start_offset;
837 real_start_offset = &local_start_offset;
839 real_end_offset = end_offset;
841 real_end_offset = &local_end_offset;
843 iface = ATK_TEXT_GET_IFACE (text);
845 if (iface->get_selection)
847 return (*(iface->get_selection)) (text, selection_num,
848 real_start_offset, real_end_offset);
855 * atk_text_add_selection:
857 * @start_offset: the start position of the selected region
858 * @end_offset: the offset of the first character after the selected region.
860 * Adds a selection bounded by the specified offsets.
862 * Returns: %TRUE if success, %FALSE otherwise
865 atk_text_add_selection (AtkText *text,
871 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
873 iface = ATK_TEXT_GET_IFACE (text);
875 if (iface->add_selection)
876 return (*(iface->add_selection)) (text, start_offset, end_offset);
882 * atk_text_remove_selection:
884 * @selection_num: The selection number. The selected regions are
885 * assigned numbers that correspond to how far the region is from the
886 * start of the text. The selected region closest to the beginning
887 * of the text region is assigned the number 0, etc. Note that adding,
888 * moving or deleting a selected region can change the numbering.
890 * Removes the specified selection.
892 * Returns: %TRUE if success, %FALSE otherwise
895 atk_text_remove_selection (AtkText *text,
900 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
902 iface = ATK_TEXT_GET_IFACE (text);
904 if (iface->remove_selection)
905 return (*(iface->remove_selection)) (text, selection_num);
911 * atk_text_set_selection:
913 * @selection_num: The selection number. The selected regions are
914 * assigned numbers that correspond to how far the region is from the
915 * start of the text. The selected region closest to the beginning
916 * of the text region is assigned the number 0, etc. Note that adding,
917 * moving or deleting a selected region can change the numbering.
918 * @start_offset: the new start position of the selection
919 * @end_offset: the new end position of (e.g. offset immediately past)
922 * Changes the start and end offset of the specified selection.
924 * Returns: %TRUE if success, %FALSE otherwise
927 atk_text_set_selection (AtkText *text,
934 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
936 iface = ATK_TEXT_GET_IFACE (text);
938 if (iface->set_selection)
940 return (*(iface->set_selection)) (text, selection_num,
941 start_offset, end_offset);
948 * atk_text_set_caret_offset:
952 * Sets the caret (cursor) position to the specified @offset.
954 * Returns: %TRUE if success, %FALSE otherwise.
957 atk_text_set_caret_offset (AtkText *text,
962 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
964 iface = ATK_TEXT_GET_IFACE (text);
966 if (iface->set_caret_offset)
968 return (*(iface->set_caret_offset)) (text, offset);
977 * atk_text_get_range_extents:
979 * @start_offset: The offset of the first text character for which boundary
980 * information is required.
981 * @end_offset: The offset of the text character after the last character
982 * for which boundary information is required.
983 * @coord_type: Specify whether coordinates are relative to the screen or widget window.
984 * @rect: A pointer to a AtkTextRectangle which is filled in by this function.
986 * Get the bounding box for text within the specified range.
991 atk_text_get_range_extents (AtkText *text,
994 AtkCoordType coord_type,
995 AtkTextRectangle *rect)
999 g_return_if_fail (ATK_IS_TEXT (text));
1000 g_return_if_fail (rect);
1002 if (start_offset < 0 || start_offset >= end_offset)
1005 iface = ATK_TEXT_GET_IFACE (text);
1007 if (iface->get_range_extents)
1008 (*(iface->get_range_extents)) (text, start_offset, end_offset, coord_type, rect);
1012 * atk_text_get_bounded_ranges:
1013 * @text: an #AtkText
1014 * @rect: An AtkTextRectangle giving the dimensions of the bounding box.
1015 * @coord_type: Specify whether coordinates are relative to the screen or widget window.
1016 * @x_clip_type: Specify the horizontal clip type.
1017 * @y_clip_type: Specify the vertical clip type.
1019 * Get the ranges of text in the specified bounding box.
1023 * Returns: (array zero-terminated=1): Array of AtkTextRange. The last
1024 * element of the array returned by this function will be NULL.
1025 * Virtual: get_bounded_ranges
1028 atk_text_get_bounded_ranges (AtkText *text,
1029 AtkTextRectangle *rect,
1030 AtkCoordType coord_type,
1031 AtkTextClipType x_clip_type,
1032 AtkTextClipType y_clip_type)
1034 AtkTextIface *iface;
1036 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
1037 g_return_val_if_fail (rect, NULL);
1039 iface = ATK_TEXT_GET_IFACE (text);
1041 if (iface->get_bounded_ranges)
1042 return (*(iface->get_bounded_ranges)) (text, rect, coord_type, x_clip_type, y_clip_type);
1048 * atk_attribute_set_free:
1049 * @attrib_set: The #AtkAttributeSet to free
1051 * Frees the memory used by an #AtkAttributeSet, including all its
1055 atk_attribute_set_free (AtkAttributeSet *attrib_set)
1061 while (temp != NULL)
1068 g_free (att->value);
1072 g_slist_free (attrib_set);
1076 * atk_text_attribute_register:
1077 * @name: a name string
1079 * Associate @name with a new #AtkTextAttribute
1081 * Returns: an #AtkTextAttribute associated with @name
1084 atk_text_attribute_register (const gchar *name)
1086 g_return_val_if_fail (name, ATK_TEXT_ATTR_INVALID);
1088 if (!extra_attributes)
1089 extra_attributes = g_ptr_array_new ();
1091 g_ptr_array_add (extra_attributes, g_strdup (name));
1092 return extra_attributes->len + ATK_TEXT_ATTR_LAST_DEFINED;
1096 * atk_text_attribute_get_name:
1097 * @attr: The #AtkTextAttribute whose name is required
1099 * Gets the name corresponding to the #AtkTextAttribute
1101 * Returns: a string containing the name; this string should not be freed
1104 atk_text_attribute_get_name (AtkTextAttribute attr)
1106 GTypeClass *type_class;
1108 const gchar *name = NULL;
1110 type_class = g_type_class_ref (ATK_TYPE_TEXT_ATTRIBUTE);
1111 g_return_val_if_fail (G_IS_ENUM_CLASS (type_class), NULL);
1113 value = g_enum_get_value (G_ENUM_CLASS (type_class), attr);
1117 name = value->value_nick;
1121 if (extra_attributes)
1125 n -= ATK_TEXT_ATTR_LAST_DEFINED + 1;
1127 if (n < extra_attributes->len)
1129 name = g_ptr_array_index (extra_attributes, n);
1132 g_type_class_unref (type_class);
1137 * atk_text_attribute_for_name:
1138 * @name: a string which is the (non-localized) name of an ATK text attribute.
1140 * Get the #AtkTextAttribute type corresponding to a text attribute name.
1142 * Returns: the #AtkTextAttribute enumerated type corresponding to the specified
1144 * or #ATK_TEXT_ATTRIBUTE_INVALID if no matching text attribute is found.
1147 atk_text_attribute_for_name (const gchar *name)
1149 GTypeClass *type_class;
1151 AtkTextAttribute type = ATK_TEXT_ATTR_INVALID;
1153 g_return_val_if_fail (name, ATK_TEXT_ATTR_INVALID);
1155 type_class = g_type_class_ref (ATK_TYPE_TEXT_ATTRIBUTE);
1156 g_return_val_if_fail (G_IS_ENUM_CLASS (type_class), ATK_TEXT_ATTR_INVALID);
1158 value = g_enum_get_value_by_nick (G_ENUM_CLASS (type_class), name);
1162 type = value->value;
1168 if (extra_attributes)
1170 for (i = 0; i < extra_attributes->len; i++)
1172 gchar *extra_attribute = (gchar *)g_ptr_array_index (extra_attributes, i);
1174 g_return_val_if_fail (extra_attribute, ATK_TEXT_ATTR_INVALID);
1176 if (strcmp (name, extra_attribute) == 0)
1178 type = i + 1 + ATK_TEXT_ATTR_LAST_DEFINED;
1184 g_type_class_unref (type_class);
1190 * atk_text_attribute_get_value:
1191 * @attr: The #AtkTextAttribute for which a value is required
1192 * @index_: The index of the required value
1194 * Gets the value for the index of the #AtkTextAttribute
1196 * Returns: a string containing the value; this string should not be freed;
1197 * NULL is returned if there are no values maintained for the attr value.
1200 atk_text_attribute_get_value (AtkTextAttribute attr,
1205 case ATK_TEXT_ATTR_INVISIBLE:
1206 case ATK_TEXT_ATTR_EDITABLE:
1207 case ATK_TEXT_ATTR_BG_FULL_HEIGHT:
1208 case ATK_TEXT_ATTR_STRIKETHROUGH:
1209 case ATK_TEXT_ATTR_BG_STIPPLE:
1210 case ATK_TEXT_ATTR_FG_STIPPLE:
1211 g_assert (index >= 0 && index < G_N_ELEMENTS (boolean_offsets));
1212 return boolean + boolean_offsets[index];
1213 case ATK_TEXT_ATTR_UNDERLINE:
1214 g_assert (index >= 0 && index < G_N_ELEMENTS (underline_offsets));
1215 return underline + underline_offsets[index];
1216 case ATK_TEXT_ATTR_WRAP_MODE:
1217 g_assert (index >= 0 && index < G_N_ELEMENTS (wrap_mode_offsets));
1218 return wrap_mode + wrap_mode_offsets[index];
1219 case ATK_TEXT_ATTR_DIRECTION:
1220 g_assert (index >= 0 && index < G_N_ELEMENTS (direction_offsets));
1221 return direction + direction_offsets[index];
1222 case ATK_TEXT_ATTR_JUSTIFICATION:
1223 g_assert (index >= 0 && index < G_N_ELEMENTS (justification_offsets));
1224 return justification + justification_offsets[index];
1225 case ATK_TEXT_ATTR_STRETCH:
1226 g_assert (index >= 0 && index < G_N_ELEMENTS (stretch_offsets));
1227 return stretch + stretch_offsets[index];
1228 case ATK_TEXT_ATTR_VARIANT:
1229 g_assert (index >= 0 && index < G_N_ELEMENTS (variant_offsets));
1230 return variant + variant_offsets[index];
1231 case ATK_TEXT_ATTR_STYLE:
1232 g_assert (index >= 0 && index < G_N_ELEMENTS (style_offsets));
1233 return style + style_offsets[index];
1240 atk_text_rectangle_union (AtkTextRectangle *src1,
1241 AtkTextRectangle *src2,
1242 AtkTextRectangle *dest)
1244 gint dest_x, dest_y;
1246 dest_x = MIN (src1->x, src2->x);
1247 dest_y = MIN (src1->y, src2->y);
1248 dest->width = MAX (src1->x + src1->width, src2->x + src2->width) - dest_x;
1249 dest->height = MAX (src1->y + src1->height, src2->y + src2->height) - dest_y;
1255 atk_text_rectangle_contain (AtkTextRectangle *clip,
1256 AtkTextRectangle *bounds,
1257 AtkTextClipType x_clip_type,
1258 AtkTextClipType y_clip_type)
1260 gboolean x_min_ok, x_max_ok, y_min_ok, y_max_ok;
1262 x_min_ok = (bounds->x >= clip->x) ||
1263 ((bounds->x + bounds->width >= clip->x) &&
1264 ((x_clip_type == ATK_TEXT_CLIP_NONE) ||
1265 (x_clip_type == ATK_TEXT_CLIP_MAX)));
1267 x_max_ok = (bounds->x + bounds->width <= clip->x + clip->width) ||
1268 ((bounds->x <= clip->x + clip->width) &&
1269 ((x_clip_type == ATK_TEXT_CLIP_NONE) ||
1270 (x_clip_type == ATK_TEXT_CLIP_MIN)));
1272 y_min_ok = (bounds->y >= clip->y) ||
1273 ((bounds->y + bounds->height >= clip->y) &&
1274 ((y_clip_type == ATK_TEXT_CLIP_NONE) ||
1275 (y_clip_type == ATK_TEXT_CLIP_MAX)));
1277 y_max_ok = (bounds->y + bounds->height <= clip->y + clip->height) ||
1278 ((bounds->y <= clip->y + clip->height) &&
1279 ((y_clip_type == ATK_TEXT_CLIP_NONE) ||
1280 (y_clip_type == ATK_TEXT_CLIP_MIN)));
1282 return (x_min_ok && x_max_ok && y_min_ok && y_max_ok);
1287 atk_text_real_get_range_extents (AtkText *text,
1290 AtkCoordType coord_type,
1291 AtkTextRectangle *rect)
1294 AtkTextRectangle cbounds, bounds;
1296 atk_text_get_character_extents (text, start_offset,
1297 &bounds.x, &bounds.y,
1298 &bounds.width, &bounds.height,
1301 for (i = start_offset + 1; i < end_offset; i++)
1303 atk_text_get_character_extents (text, i,
1304 &cbounds.x, &cbounds.y,
1305 &cbounds.width, &cbounds.height,
1307 atk_text_rectangle_union (&bounds, &cbounds, &bounds);
1312 rect->width = bounds.width;
1313 rect->height = bounds.height;
1316 static AtkTextRange**
1317 atk_text_real_get_bounded_ranges (AtkText *text,
1318 AtkTextRectangle *rect,
1319 AtkCoordType coord_type,
1320 AtkTextClipType x_clip_type,
1321 AtkTextClipType y_clip_type)
1323 gint bounds_min_offset, bounds_max_offset;
1324 gint min_line_start, min_line_end;
1325 gint max_line_start, max_line_end;
1329 gint num_ranges = 0;
1330 gint range_size = 1;
1331 AtkTextRectangle cbounds;
1332 AtkTextRange **range;
1335 bounds_min_offset = atk_text_get_offset_at_point (text, rect->x, rect->y, coord_type);
1336 bounds_max_offset = atk_text_get_offset_at_point (text, rect->x + rect->width, rect->y + rect->height, coord_type);
1338 if (bounds_min_offset == 0 &&
1339 bounds_min_offset == bounds_max_offset)
1342 line = atk_text_get_text_at_offset (text, bounds_min_offset,
1343 ATK_TEXT_BOUNDARY_LINE_START,
1344 &min_line_start, &min_line_end);
1346 line = atk_text_get_text_at_offset (text, bounds_max_offset,
1347 ATK_TEXT_BOUNDARY_LINE_START,
1348 &max_line_start, &max_line_end);
1350 bounds_min_offset = MIN (min_line_start, max_line_start);
1351 bounds_max_offset = MAX (min_line_end, max_line_end);
1353 curr_offset = bounds_min_offset;
1354 while (curr_offset < bounds_max_offset)
1356 offset = curr_offset;
1358 while (curr_offset < bounds_max_offset)
1360 atk_text_get_character_extents (text, curr_offset,
1361 &cbounds.x, &cbounds.y,
1362 &cbounds.width, &cbounds.height,
1364 if (!atk_text_rectangle_contain (rect, &cbounds, x_clip_type, y_clip_type))
1368 if (curr_offset > offset)
1370 AtkTextRange *one_range = g_new (AtkTextRange, 1);
1372 one_range->start_offset = offset;
1373 one_range->end_offset = curr_offset;
1374 one_range->content = atk_text_get_text (text, offset, curr_offset);
1375 atk_text_get_range_extents (text, offset, curr_offset, coord_type, &one_range->bounds);
1377 if (num_ranges >= range_size - 1)
1380 range = g_realloc (range, range_size * sizeof (gpointer));
1382 range[num_ranges] = one_range;
1387 range[num_ranges] = NULL;
1393 * atk_text_free_ranges:
1394 * @ranges: (array): A pointer to an array of #AtkTextRange which is
1397 * Frees the memory associated with an array of AtkTextRange. It is assumed
1398 * that the array was returned by the function atk_text_get_bounded_ranges
1399 * and is NULL terminated.
1404 atk_text_free_ranges (AtkTextRange **ranges)
1406 AtkTextRange **first = ranges;
1412 AtkTextRange *range;
1416 g_free (range->content);
1423 static AtkTextRange *
1424 atk_text_range_copy (AtkTextRange *src)
1426 AtkTextRange *dst = g_new0 (AtkTextRange, 1);
1427 dst->bounds = src->bounds;
1428 dst->start_offset = src->start_offset;
1429 dst->end_offset = src->end_offset;
1431 dst->content = g_strdup (src->content);
1436 atk_text_range_free (AtkTextRange *range)
1438 g_free (range->content);
1442 G_DEFINE_BOXED_TYPE (AtkTextRange, atk_text_range, atk_text_range_copy,
1443 atk_text_range_free)