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
[] =
104 static const guint8 underline_offsets
[] = {
108 static void atk_text_base_init (AtkTextIface
*class);
110 static void atk_text_real_get_range_extents (AtkText
*text
,
113 AtkCoordType coord_type
,
114 AtkTextRectangle
*rect
);
116 static AtkTextRange
** atk_text_real_get_bounded_ranges (AtkText
*text
,
117 AtkTextRectangle
*rect
,
118 AtkCoordType coord_type
,
119 AtkTextClipType x_clip_type
,
120 AtkTextClipType y_clip_type
);
122 static guint atk_text_signals
[LAST_SIGNAL
] = { 0 };
125 atk_text_get_type (void)
127 static GType type
= 0;
131 static const GTypeInfo tinfo
=
133 sizeof (AtkTextIface
),
134 (GBaseInitFunc
) atk_text_base_init
,
135 (GBaseFinalizeFunc
) NULL
,
136 (GClassInitFunc
) NULL
/* atk_text_interface_init */ ,
137 (GClassFinalizeFunc
) NULL
,
141 type
= g_type_register_static (G_TYPE_INTERFACE
, "AtkText", &tinfo
, 0);
148 atk_text_base_init (AtkTextIface
*class)
150 static gboolean initialized
= FALSE
;
155 * Note that text_changed signal supports details "insert", "delete",
156 * possibly "replace".
159 class->get_range_extents
= atk_text_real_get_range_extents
;
160 class->get_bounded_ranges
= atk_text_real_get_bounded_ranges
;
162 atk_text_signals
[TEXT_CHANGED
] =
163 g_signal_new ("text_changed",
165 G_SIGNAL_RUN_LAST
| G_SIGNAL_DETAILED
,
166 G_STRUCT_OFFSET (AtkTextIface
, text_changed
),
167 (GSignalAccumulator
) NULL
, NULL
,
168 atk_marshal_VOID__INT_INT
,
170 2, G_TYPE_INT
, G_TYPE_INT
);
172 atk_text_signals
[TEXT_CARET_MOVED
] =
173 g_signal_new ("text_caret_moved",
176 G_STRUCT_OFFSET (AtkTextIface
, text_caret_moved
),
177 (GSignalAccumulator
) NULL
, NULL
,
178 g_cclosure_marshal_VOID__INT
,
181 atk_text_signals
[TEXT_SELECTION_CHANGED
] =
182 g_signal_new ("text_selection_changed",
185 G_STRUCT_OFFSET (AtkTextIface
, text_selection_changed
),
186 (GSignalAccumulator
) NULL
, NULL
,
187 g_cclosure_marshal_VOID__VOID
,
189 atk_text_signals
[TEXT_ATTRIBUTES_CHANGED
] =
190 g_signal_new ("text_attributes_changed",
193 G_STRUCT_OFFSET (AtkTextIface
, text_attributes_changed
),
194 (GSignalAccumulator
) NULL
, NULL
,
195 g_cclosure_marshal_VOID__VOID
,
206 * @start_offset: start position
207 * @end_offset: end position
209 * Gets the specified text.
211 * Returns: the text from @start_offset up to, but not including @end_offset.
214 atk_text_get_text (AtkText
*text
,
220 g_return_val_if_fail (ATK_IS_TEXT (text
), NULL
);
222 iface
= ATK_TEXT_GET_IFACE (text
);
224 if (start_offset
< 0 || end_offset
< -1)
228 return (*(iface
->get_text
)) (text
, start_offset
, end_offset
);
234 * atk_text_get_character_at_offset:
238 * Gets the specified text.
240 * Returns: the character at @offset.
243 atk_text_get_character_at_offset (AtkText
*text
,
248 g_return_val_if_fail (ATK_IS_TEXT (text
), (gunichar
) 0);
250 iface
= ATK_TEXT_GET_IFACE (text
);
252 if (iface
->get_character_at_offset
)
253 return (*(iface
->get_character_at_offset
)) (text
, offset
);
259 * atk_text_get_text_after_offset:
262 * @boundary_type: An #AtkTextBoundary
263 * @start_offset: the start offset of the returned string
264 * @end_offset: the offset of the first character after the
267 * Gets the specified text.
269 * If the boundary_type if ATK_TEXT_BOUNDARY_CHAR the character after the
270 * offset is returned.
272 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START the returned string
273 * is from the word start after the offset to the next word start.
275 * The returned string will contain the word after the offset if the offset
276 * is inside a word or if the offset is not inside a word.
278 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_END the returned string
279 * is from the word end at or after the offset to the next work end.
281 * The returned string will contain the word after the offset if the offset
282 * is inside a word and will contain the word after the word after the offset
283 * if the offset is not inside a word.
285 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the returned
286 * string is from the sentence start after the offset to the next sentence
289 * The returned string will contain the sentence after the offset if the offset
290 * is inside a sentence or if the offset is not inside a sentence.
292 * If the boundary_type is ATK_TEXT_BOUNDARY_SENTENCE_END the returned string
293 * is from the sentence end at or after the offset to the next sentence end.
295 * The returned string will contain the sentence after the offset if the offset
296 * is inside a sentence and will contain the sentence after the sentence
297 * after the offset if the offset is not inside a sentence.
299 * If the boundary type is ATK_TEXT_BOUNDARY_LINE_START the returned
300 * string is from the line start after the offset to the next line start.
302 * If the boundary_type is ATK_TEXT_BOUNDARY_LINE_END the returned string
303 * is from the line end at or after the offset to the next line end.
305 * Returns: the text after @offset bounded by the specified @boundary_type.
308 atk_text_get_text_after_offset (AtkText
*text
,
310 AtkTextBoundary boundary_type
,
315 gint local_start_offset
, local_end_offset
;
316 gint
*real_start_offset
, *real_end_offset
;
318 g_return_val_if_fail (ATK_IS_TEXT (text
), NULL
);
321 real_start_offset
= start_offset
;
323 real_start_offset
= &local_start_offset
;
325 real_end_offset
= end_offset
;
327 real_end_offset
= &local_end_offset
;
332 iface
= ATK_TEXT_GET_IFACE (text
);
334 if (iface
->get_text_after_offset
)
335 return (*(iface
->get_text_after_offset
)) (text
, offset
, boundary_type
, real_start_offset
, real_end_offset
);
341 * atk_text_get_text_at_offset:
344 * @boundary_type: An #AtkTextBoundary
345 * @start_offset: the start offset of the returned string
346 * @end_offset: the offset of the first character after the
349 * Gets the specified text.
351 * If the boundary_type if ATK_TEXT_BOUNDARY_CHAR the character at the
352 * offset is returned.
354 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START the returned string
355 * is from the word start at or before the offset to the word start after
358 * The returned string will contain the word at the offset if the offset
359 * is inside a word and will contain the word before the offset if the
360 * offset is not inside a word.
362 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_END the returned string
363 * is from the word end before the offset to the word end at or after the
366 * The returned string will contain the word at the offset if the offset
367 * is inside a word and will contain the word after to the offset if the
368 * offset is not inside a word.
370 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the returned
371 * string is from the sentence start at or before the offset to the sentence
372 * start after the offset.
374 * The returned string will contain the sentence at the offset if the offset
375 * is inside a sentence and will contain the sentence before the offset
376 * if the offset is not inside a sentence.
378 * If the boundary_type is ATK_TEXT_BOUNDARY_SENTENCE_END the returned string
379 * is from the sentence end before the offset to the sentence end at or
382 * The returned string will contain the sentence at the offset if the offset
383 * is inside a sentence and will contain the sentence after the offset
384 * if the offset is not inside a sentence.
386 * If the boundary type is ATK_TEXT_BOUNDARY_LINE_START the returned
387 * string is from the line start at or before the offset to the line
388 * start after the offset.
390 * If the boundary_type is ATK_TEXT_BOUNDARY_LINE_END the returned string
391 * is from the line end before the offset to the line end at or after
394 * Returns: the text at @offset bounded by the specified @boundary_type.
397 atk_text_get_text_at_offset (AtkText
*text
,
399 AtkTextBoundary boundary_type
,
404 gint local_start_offset
, local_end_offset
;
405 gint
*real_start_offset
, *real_end_offset
;
407 g_return_val_if_fail (ATK_IS_TEXT (text
), NULL
);
410 real_start_offset
= start_offset
;
412 real_start_offset
= &local_start_offset
;
414 real_end_offset
= end_offset
;
416 real_end_offset
= &local_end_offset
;
418 iface
= ATK_TEXT_GET_IFACE (text
);
420 if (iface
->get_text_at_offset
)
421 return (*(iface
->get_text_at_offset
)) (text
, offset
, boundary_type
, real_start_offset
, real_end_offset
);
427 * atk_text_get_text_before_offset:
430 * @boundary_type: An #AtkTextBoundary
431 * @start_offset: the start offset of the returned string
432 * @end_offset: the offset of the first character after the
435 * Gets the specified text.
437 * If the boundary_type if ATK_TEXT_BOUNDARY_CHAR the character before the
438 * offset is returned.
440 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START the returned string
441 * is from the word start before the word start before the offset to
442 * the word start before the offset.
444 * The returned string will contain the word before the offset if the offset
445 * is inside a word and will contain the word before the word before the
446 * offset if the offset is not inside a word.
448 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_END the returned string
449 * is from the word end before the word end at or before the offset to the
450 * word end at or before the offset.
452 * The returned string will contain the word before the offset if the offset
453 * is inside a word or if the offset is not inside a word.
455 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the returned
456 * string is from the sentence start before the sentence start before
457 * the offset to the sentence start before the offset.
459 * The returned string will contain the sentence before the offset if the
460 * offset is inside a sentence and will contain the sentence before the
461 * sentence before the offset if the offset is not inside a sentence.
463 * If the boundary_type is ATK_TEXT_BOUNDARY_SENTENCE_END the returned string
464 * is from the sentence end before the sentence end at or before the offset to
465 * the sentence end at or before the offset.
467 * The returned string will contain the sentence before the offset if the
468 * offset is inside a sentence or if the offset is not inside a sentence.
470 * If the boundary type is ATK_TEXT_BOUNDARY_LINE_START the returned
471 * string is from the line start before the line start ar or before the offset
472 * to the line start ar or before the offset.
474 * If the boundary_type is ATK_TEXT_BOUNDARY_LINE_END the returned string
475 * is from the line end before the line end before the offset to the
476 * line end before the offset.
478 * Returns: the text before @offset bounded by the specified @boundary_type.
481 atk_text_get_text_before_offset (AtkText
*text
,
483 AtkTextBoundary boundary_type
,
488 gint local_start_offset
, local_end_offset
;
489 gint
*real_start_offset
, *real_end_offset
;
491 g_return_val_if_fail (ATK_IS_TEXT (text
), NULL
);
494 real_start_offset
= start_offset
;
496 real_start_offset
= &local_start_offset
;
498 real_end_offset
= end_offset
;
500 real_end_offset
= &local_end_offset
;
505 iface
= ATK_TEXT_GET_IFACE (text
);
507 if (iface
->get_text_before_offset
)
508 return (*(iface
->get_text_before_offset
)) (text
, offset
, boundary_type
, real_start_offset
, real_end_offset
);
514 * atk_text_get_caret_offset:
517 * Gets the offset position of the caret (cursor).
519 * Returns: the offset position of the caret (cursor).
522 atk_text_get_caret_offset (AtkText
*text
)
526 g_return_val_if_fail (ATK_IS_TEXT (text
), 0);
528 iface
= ATK_TEXT_GET_IFACE (text
);
530 if (iface
->get_caret_offset
)
531 return (*(iface
->get_caret_offset
)) (text
);
537 * atk_text_get_character_extents:
539 * @offset: The offset of the text character for which bounding information is required.
540 * @x: Pointer for the x cordinate of the bounding box
541 * @y: Pointer for the y cordinate of the bounding box
542 * @width: Pointer for the width of the bounding box
543 * @height: Pointer for the height of the bounding box
544 * @coords: specify whether coordinates are relative to the screen or widget window
546 * Get the bounding box containing the glyph representing the character at
547 * a particular text offset.
550 atk_text_get_character_extents (AtkText
*text
,
559 gint local_x
, local_y
, local_width
, local_height
;
560 gint
*real_x
, *real_y
, *real_width
, *real_height
;
562 g_return_if_fail (ATK_IS_TEXT (text
));
575 real_width
= &local_width
;
577 real_height
= height
;
579 real_height
= &local_height
;
589 iface
= ATK_TEXT_GET_IFACE (text
);
591 if (iface
->get_character_extents
)
592 (*(iface
->get_character_extents
)) (text
, offset
, real_x
, real_y
, real_width
, real_height
, coords
);
596 *real_x
= *real_x
+ *real_width
;
602 * atk_text_get_run_attributes:
604 *@offset: the offset at which to get the attributes, -1 means the offset of
605 *the character to be inserted at the caret location.
606 *@start_offset: the address to put the start offset of the range
607 *@end_offset: the address to put the end offset of the range
609 *Creates an #AtkAttributeSet which consists of the attributes explicitly
610 *set at the position @offset in the text. @start_offset and @end_offset are
611 *set to the start and end of the range around @offset where the attributes are
612 *invariant. Note that @end_offset is the offset of the first character
613 *after the range. See the enum AtkTextAttribute for types of text
614 *attributes that can be returned. Note that other attributes may also be
617 *Returns: (transfer full): an #AtkAttributeSet which contains the attributes
618 * explicitly set at @offset. This #AtkAttributeSet should be freed by a call
619 * to atk_attribute_set_free().
622 atk_text_get_run_attributes (AtkText
*text
,
628 gint local_start_offset
, local_end_offset
;
629 gint
*real_start_offset
, *real_end_offset
;
631 g_return_val_if_fail (ATK_IS_TEXT (text
), NULL
);
634 real_start_offset
= start_offset
;
636 real_start_offset
= &local_start_offset
;
638 real_end_offset
= end_offset
;
640 real_end_offset
= &local_end_offset
;
645 iface
= ATK_TEXT_GET_IFACE (text
);
647 if (iface
->get_run_attributes
)
648 return (*(iface
->get_run_attributes
)) (text
, offset
, real_start_offset
, real_end_offset
);
654 * atk_text_get_default_attributes:
657 *Creates an #AtkAttributeSet which consists of the default values of
658 *attributes for the text. See the enum AtkTextAttribute for types of text
659 *attributes that can be returned. Note that other attributes may also be
662 *Returns: (transfer full): an #AtkAttributeSet which contains the default
663 * values of attributes. at @offset. this #atkattributeset should be freed by
664 * a call to atk_attribute_set_free().
667 atk_text_get_default_attributes (AtkText
*text
)
671 g_return_val_if_fail (ATK_IS_TEXT (text
), NULL
);
673 iface
= ATK_TEXT_GET_IFACE (text
);
675 if (iface
->get_default_attributes
)
676 return (*(iface
->get_default_attributes
)) (text
);
682 * atk_text_get_character_count:
685 * Gets the character count.
687 * Returns: the number of characters.
690 atk_text_get_character_count (AtkText
*text
)
694 g_return_val_if_fail (ATK_IS_TEXT (text
), -1);
696 iface
= ATK_TEXT_GET_IFACE (text
);
698 if (iface
->get_character_count
)
699 return (*(iface
->get_character_count
)) (text
);
705 * atk_text_get_offset_at_point:
707 * @x: screen x-position of character
708 * @y: screen y-position of character
709 * @coords: specify whether coordinates are relative to the screen or
712 * Gets the offset of the character located at coordinates @x and @y. @x and @y
713 * are interpreted as being relative to the screen or this widget's window
714 * depending on @coords.
716 * Returns: the offset to the character which is located at
717 * the specified @x and @y coordinates.
720 atk_text_get_offset_at_point (AtkText
*text
,
727 g_return_val_if_fail (ATK_IS_TEXT (text
), -1);
729 iface
= ATK_TEXT_GET_IFACE (text
);
731 if (iface
->get_offset_at_point
)
732 return (*(iface
->get_offset_at_point
)) (text
, x
, y
, coords
);
738 * atk_text_get_n_selections:
741 * Gets the number of selected regions.
743 * Returns: The number of selected regions, or -1 if a failure
747 atk_text_get_n_selections (AtkText
*text
)
751 g_return_val_if_fail (ATK_IS_TEXT (text
), -1);
753 iface
= ATK_TEXT_GET_IFACE (text
);
755 if (iface
->get_n_selections
)
756 return (*(iface
->get_n_selections
)) (text
);
762 * atk_text_get_selection:
764 * @selection_num: The selection number. The selected regions are
765 * assigned numbers that correspond to how far the region is from the
766 * start of the text. The selected region closest to the beginning
767 * of the text region is assigned the number 0, etc. Note that adding,
768 * moving or deleting a selected region can change the numbering.
769 * @start_offset: passes back the start position of the selected region
770 * @end_offset: passes back the end position of (e.g. offset immediately past)
771 * the selected region
773 * Gets the text from the specified selection.
775 * Returns: the selected text.
778 atk_text_get_selection (AtkText
*text
,
784 gint local_start_offset
, local_end_offset
;
785 gint
*real_start_offset
, *real_end_offset
;
787 g_return_val_if_fail (ATK_IS_TEXT (text
), NULL
);
790 real_start_offset
= start_offset
;
792 real_start_offset
= &local_start_offset
;
794 real_end_offset
= end_offset
;
796 real_end_offset
= &local_end_offset
;
798 iface
= ATK_TEXT_GET_IFACE (text
);
800 if (iface
->get_selection
)
802 return (*(iface
->get_selection
)) (text
, selection_num
,
803 real_start_offset
, real_end_offset
);
810 * atk_text_add_selection:
812 * @start_offset: the start position of the selected region
813 * @end_offset: the offset of the first character after the selected region.
815 * Adds a selection bounded by the specified offsets.
817 * Returns: %TRUE if success, %FALSE otherwise
820 atk_text_add_selection (AtkText
*text
,
826 g_return_val_if_fail (ATK_IS_TEXT (text
), FALSE
);
828 iface
= ATK_TEXT_GET_IFACE (text
);
830 if (iface
->add_selection
)
831 return (*(iface
->add_selection
)) (text
, start_offset
, end_offset
);
837 * atk_text_remove_selection:
839 * @selection_num: The selection number. The selected regions are
840 * assigned numbers that correspond to how far the region is from the
841 * start of the text. The selected region closest to the beginning
842 * of the text region is assigned the number 0, etc. Note that adding,
843 * moving or deleting a selected region can change the numbering.
845 * Removes the specified selection.
847 * Returns: %TRUE if success, %FALSE otherwise
850 atk_text_remove_selection (AtkText
*text
,
855 g_return_val_if_fail (ATK_IS_TEXT (text
), FALSE
);
857 iface
= ATK_TEXT_GET_IFACE (text
);
859 if (iface
->remove_selection
)
860 return (*(iface
->remove_selection
)) (text
, selection_num
);
866 * atk_text_set_selection:
868 * @selection_num: The selection number. The selected regions are
869 * assigned numbers that correspond to how far the region is from the
870 * start of the text. The selected region closest to the beginning
871 * of the text region is assigned the number 0, etc. Note that adding,
872 * moving or deleting a selected region can change the numbering.
873 * @start_offset: the new start position of the selection
874 * @end_offset: the new end position of (e.g. offset immediately past)
877 * Changes the start and end offset of the specified selection.
879 * Returns: %TRUE if success, %FALSE otherwise
882 atk_text_set_selection (AtkText
*text
,
889 g_return_val_if_fail (ATK_IS_TEXT (text
), FALSE
);
891 iface
= ATK_TEXT_GET_IFACE (text
);
893 if (iface
->set_selection
)
895 return (*(iface
->set_selection
)) (text
, selection_num
,
896 start_offset
, end_offset
);
903 * atk_text_set_caret_offset:
907 * Sets the caret (cursor) position to the specified @offset.
909 * Returns: %TRUE if success, %FALSE otherwise.
912 atk_text_set_caret_offset (AtkText
*text
,
917 g_return_val_if_fail (ATK_IS_TEXT (text
), FALSE
);
919 iface
= ATK_TEXT_GET_IFACE (text
);
921 if (iface
->set_caret_offset
)
923 return (*(iface
->set_caret_offset
)) (text
, offset
);
932 * atk_text_get_range_extents:
934 * @start_offset: The offset of the first text character for which boundary
935 * information is required.
936 * @end_offset: The offset of the text character after the last character
937 * for which boundary information is required.
938 * @coord_type: Specify whether coordinates are relative to the screen or widget window.
939 * @rect: A pointer to a AtkTextRectangle which is filled in by this function.
941 * Get the bounding box for text within the specified range.
946 atk_text_get_range_extents (AtkText
*text
,
949 AtkCoordType coord_type
,
950 AtkTextRectangle
*rect
)
954 g_return_if_fail (ATK_IS_TEXT (text
));
955 g_return_if_fail (rect
);
957 if (start_offset
< 0 || start_offset
>= end_offset
)
960 iface
= ATK_TEXT_GET_IFACE (text
);
962 if (iface
->get_range_extents
)
963 (*(iface
->get_range_extents
)) (text
, start_offset
, end_offset
, coord_type
, rect
);
967 * atk_text_get_bounded_ranges:
969 * @rect: An AtkTextRectangle giving the dimensions of the bounding box.
970 * @coord_type: Specify whether coordinates are relative to the screen or widget window.
971 * @x_clip_type: Specify the horizontal clip type.
972 * @y_clip_type: Specify the vertical clip type.
974 * Get the ranges of text in the specified bounding box.
978 * Returns: (array zero-terminated=1): Array of AtkTextRange. The last
979 * element of the array returned by this function will be NULL.
982 atk_text_get_bounded_ranges (AtkText
*text
,
983 AtkTextRectangle
*rect
,
984 AtkCoordType coord_type
,
985 AtkTextClipType x_clip_type
,
986 AtkTextClipType y_clip_type
)
990 g_return_val_if_fail (ATK_IS_TEXT (text
), NULL
);
991 g_return_val_if_fail (rect
, NULL
);
993 iface
= ATK_TEXT_GET_IFACE (text
);
995 if (iface
->get_bounded_ranges
)
996 return (*(iface
->get_bounded_ranges
)) (text
, rect
, coord_type
, x_clip_type
, y_clip_type
);
1002 * atk_attribute_set_free:
1003 * @attrib_set: The #AtkAttributeSet to free
1005 * Frees the memory used by an #AtkAttributeSet, including all its
1009 atk_attribute_set_free (AtkAttributeSet
*attrib_set
)
1015 while (temp
!= NULL
)
1022 g_free (att
->value
);
1026 g_slist_free (attrib_set
);
1030 * atk_text_attribute_register:
1031 * @name: a name string
1033 * Associate @name with a new #AtkTextAttribute
1035 * Returns: an #AtkTextAttribute associated with @name
1038 atk_text_attribute_register (const gchar
*name
)
1040 g_return_val_if_fail (name
, ATK_TEXT_ATTR_INVALID
);
1042 if (!extra_attributes
)
1043 extra_attributes
= g_ptr_array_new ();
1045 g_ptr_array_add (extra_attributes
, g_strdup (name
));
1046 return extra_attributes
->len
+ ATK_TEXT_ATTR_LAST_DEFINED
;
1050 * atk_text_attribute_get_name:
1051 * @attr: The #AtkTextAttribute whose name is required
1053 * Gets the name corresponding to the #AtkTextAttribute
1055 * Returns: a string containing the name; this string should not be freed
1057 G_CONST_RETURN gchar
*
1058 atk_text_attribute_get_name (AtkTextAttribute attr
)
1060 GTypeClass
*type_class
;
1062 const gchar
*name
= NULL
;
1064 type_class
= g_type_class_ref (ATK_TYPE_TEXT_ATTRIBUTE
);
1065 g_return_val_if_fail (G_IS_ENUM_CLASS (type_class
), NULL
);
1067 value
= g_enum_get_value (G_ENUM_CLASS (type_class
), attr
);
1071 name
= value
->value_nick
;
1075 if (extra_attributes
)
1079 n
-= ATK_TEXT_ATTR_LAST_DEFINED
+ 1;
1081 if (n
< extra_attributes
->len
)
1083 name
= g_ptr_array_index (extra_attributes
, n
);
1086 g_type_class_unref (type_class
);
1091 * atk_text_attribute_for_name:
1092 * @name: a string which is the (non-localized) name of an ATK text attribute.
1094 * Get the #AtkTextAttribute type corresponding to a text attribute name.
1096 * Returns: the #AtkTextAttribute enumerated type corresponding to the specified
1098 * or #ATK_TEXT_ATTRIBUTE_INVALID if no matching text attribute is found.
1101 atk_text_attribute_for_name (const gchar
*name
)
1103 GTypeClass
*type_class
;
1105 AtkTextAttribute type
= ATK_TEXT_ATTR_INVALID
;
1107 g_return_val_if_fail (name
, ATK_TEXT_ATTR_INVALID
);
1109 type_class
= g_type_class_ref (ATK_TYPE_TEXT_ATTRIBUTE
);
1110 g_return_val_if_fail (G_IS_ENUM_CLASS (type_class
), ATK_TEXT_ATTR_INVALID
);
1112 value
= g_enum_get_value_by_nick (G_ENUM_CLASS (type_class
), name
);
1116 type
= value
->value
;
1122 if (extra_attributes
)
1124 for (i
= 0; i
< extra_attributes
->len
; i
++)
1126 gchar
*extra_attribute
= (gchar
*)g_ptr_array_index (extra_attributes
, i
);
1128 g_return_val_if_fail (extra_attribute
, ATK_TEXT_ATTR_INVALID
);
1130 if (strcmp (name
, extra_attribute
) == 0)
1132 type
= i
+ 1 + ATK_TEXT_ATTR_LAST_DEFINED
;
1138 g_type_class_unref (type_class
);
1144 * atk_text_attribute_get_value:
1145 * @attr: The #AtkTextAttribute for which a value is required
1146 * @index_: The index of the required value
1148 * Gets the value for the index of the #AtkTextAttribute
1150 * Returns: a string containing the value; this string should not be freed;
1151 * NULL is returned if there are no values maintained for the attr value.
1153 G_CONST_RETURN gchar
*
1154 atk_text_attribute_get_value (AtkTextAttribute attr
,
1159 case ATK_TEXT_ATTR_INVISIBLE
:
1160 case ATK_TEXT_ATTR_EDITABLE
:
1161 case ATK_TEXT_ATTR_BG_FULL_HEIGHT
:
1162 case ATK_TEXT_ATTR_STRIKETHROUGH
:
1163 case ATK_TEXT_ATTR_BG_STIPPLE
:
1164 case ATK_TEXT_ATTR_FG_STIPPLE
:
1165 g_assert (index
>= 0 && index
< G_N_ELEMENTS (boolean_offsets
));
1166 return boolean
+ boolean_offsets
[index
];
1167 case ATK_TEXT_ATTR_UNDERLINE
:
1168 g_assert (index
>= 0 && index
< G_N_ELEMENTS (underline_offsets
));
1169 return underline
+ underline_offsets
[index
];
1170 case ATK_TEXT_ATTR_WRAP_MODE
:
1171 g_assert (index
>= 0 && index
< G_N_ELEMENTS (wrap_mode_offsets
));
1172 return wrap_mode
+ wrap_mode_offsets
[index
];
1173 case ATK_TEXT_ATTR_DIRECTION
:
1174 g_assert (index
>= 0 && index
< G_N_ELEMENTS (direction_offsets
));
1175 return direction
+ direction_offsets
[index
];
1176 case ATK_TEXT_ATTR_JUSTIFICATION
:
1177 g_assert (index
>= 0 && index
< G_N_ELEMENTS (justification_offsets
));
1178 return justification
+ justification_offsets
[index
];
1179 case ATK_TEXT_ATTR_STRETCH
:
1180 g_assert (index
>= 0 && index
< G_N_ELEMENTS (stretch_offsets
));
1181 return stretch
+ stretch_offsets
[index
];
1182 case ATK_TEXT_ATTR_VARIANT
:
1183 g_assert (index
>= 0 && index
< G_N_ELEMENTS (variant_offsets
));
1184 return variant
+ variant_offsets
[index
];
1185 case ATK_TEXT_ATTR_STYLE
:
1186 g_assert (index
>= 0 && index
< G_N_ELEMENTS (style_offsets
));
1187 return style
+ style_offsets
[index
];
1194 atk_text_rectangle_union (AtkTextRectangle
*src1
,
1195 AtkTextRectangle
*src2
,
1196 AtkTextRectangle
*dest
)
1198 gint dest_x
, dest_y
;
1200 dest_x
= MIN (src1
->x
, src2
->x
);
1201 dest_y
= MIN (src1
->y
, src2
->y
);
1202 dest
->width
= MAX (src1
->x
+ src1
->width
, src2
->x
+ src2
->width
) - dest_x
;
1203 dest
->height
= MAX (src1
->y
+ src1
->height
, src2
->y
+ src2
->height
) - dest_y
;
1209 atk_text_rectangle_contain (AtkTextRectangle
*clip
,
1210 AtkTextRectangle
*bounds
,
1211 AtkTextClipType x_clip_type
,
1212 AtkTextClipType y_clip_type
)
1214 gboolean x_min_ok
, x_max_ok
, y_min_ok
, y_max_ok
;
1216 x_min_ok
= (bounds
->x
>= clip
->x
) ||
1217 ((bounds
->x
+ bounds
->width
>= clip
->x
) &&
1218 ((x_clip_type
== ATK_TEXT_CLIP_NONE
) ||
1219 (x_clip_type
== ATK_TEXT_CLIP_MAX
)));
1221 x_max_ok
= (bounds
->x
+ bounds
->width
<= clip
->x
+ clip
->width
) ||
1222 ((bounds
->x
<= clip
->x
+ clip
->width
) &&
1223 ((x_clip_type
== ATK_TEXT_CLIP_NONE
) ||
1224 (x_clip_type
== ATK_TEXT_CLIP_MIN
)));
1226 y_min_ok
= (bounds
->y
>= clip
->y
) ||
1227 ((bounds
->y
+ bounds
->height
>= clip
->y
) &&
1228 ((y_clip_type
== ATK_TEXT_CLIP_NONE
) ||
1229 (y_clip_type
== ATK_TEXT_CLIP_MAX
)));
1231 y_max_ok
= (bounds
->y
+ bounds
->height
<= clip
->y
+ clip
->height
) ||
1232 ((bounds
->y
<= clip
->y
+ clip
->height
) &&
1233 ((y_clip_type
== ATK_TEXT_CLIP_NONE
) ||
1234 (y_clip_type
== ATK_TEXT_CLIP_MIN
)));
1236 return (x_min_ok
&& x_max_ok
&& y_min_ok
&& y_max_ok
);
1241 atk_text_real_get_range_extents (AtkText
*text
,
1244 AtkCoordType coord_type
,
1245 AtkTextRectangle
*rect
)
1248 AtkTextRectangle cbounds
, bounds
;
1250 atk_text_get_character_extents (text
, start_offset
,
1251 &bounds
.x
, &bounds
.y
,
1252 &bounds
.width
, &bounds
.height
,
1255 for (i
= start_offset
+ 1; i
< end_offset
; i
++)
1257 atk_text_get_character_extents (text
, i
,
1258 &cbounds
.x
, &cbounds
.y
,
1259 &cbounds
.width
, &cbounds
.height
,
1261 atk_text_rectangle_union (&bounds
, &cbounds
, &bounds
);
1266 rect
->width
= bounds
.width
;
1267 rect
->height
= bounds
.height
;
1270 static AtkTextRange
**
1271 atk_text_real_get_bounded_ranges (AtkText
*text
,
1272 AtkTextRectangle
*rect
,
1273 AtkCoordType coord_type
,
1274 AtkTextClipType x_clip_type
,
1275 AtkTextClipType y_clip_type
)
1277 gint bounds_min_offset
, bounds_max_offset
;
1278 gint min_line_start
, min_line_end
;
1279 gint max_line_start
, max_line_end
;
1283 gint num_ranges
= 0;
1284 gint range_size
= 1;
1285 AtkTextRectangle cbounds
;
1286 AtkTextRange
**range
;
1289 bounds_min_offset
= atk_text_get_offset_at_point (text
, rect
->x
, rect
->y
, coord_type
);
1290 bounds_max_offset
= atk_text_get_offset_at_point (text
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
, coord_type
);
1292 if (bounds_min_offset
== 0 &&
1293 bounds_min_offset
== bounds_max_offset
)
1296 line
= atk_text_get_text_at_offset (text
, bounds_min_offset
,
1297 ATK_TEXT_BOUNDARY_LINE_START
,
1298 &min_line_start
, &min_line_end
);
1300 line
= atk_text_get_text_at_offset (text
, bounds_max_offset
,
1301 ATK_TEXT_BOUNDARY_LINE_START
,
1302 &max_line_start
, &max_line_end
);
1304 bounds_min_offset
= MIN (min_line_start
, max_line_start
);
1305 bounds_max_offset
= MAX (min_line_end
, max_line_end
);
1307 curr_offset
= bounds_min_offset
;
1308 while (curr_offset
< bounds_max_offset
)
1310 offset
= curr_offset
;
1312 while (curr_offset
< bounds_max_offset
)
1314 atk_text_get_character_extents (text
, curr_offset
,
1315 &cbounds
.x
, &cbounds
.y
,
1316 &cbounds
.width
, &cbounds
.height
,
1318 if (!atk_text_rectangle_contain (rect
, &cbounds
, x_clip_type
, y_clip_type
))
1322 if (curr_offset
> offset
)
1324 AtkTextRange
*one_range
= g_new (AtkTextRange
, 1);
1326 one_range
->start_offset
= offset
;
1327 one_range
->end_offset
= curr_offset
;
1328 one_range
->content
= atk_text_get_text (text
, offset
, curr_offset
);
1329 atk_text_get_range_extents (text
, offset
, curr_offset
, coord_type
, &one_range
->bounds
);
1331 if (num_ranges
>= range_size
- 1)
1334 range
= g_realloc (range
, range_size
* sizeof (gpointer
));
1336 range
[num_ranges
] = one_range
;
1341 range
[num_ranges
] = NULL
;
1347 * atk_text_free_ranges:
1348 * @ranges: A pointer to an array of #AtkTextRange which is to be freed.
1350 * Frees the memory associated with an array of AtkTextRange. It is assumed
1351 * that the array was returned by the function atk_text_get_bounded_ranges
1352 * and is NULL terminated.
1357 atk_text_free_ranges (AtkTextRange
**ranges
)
1359 AtkTextRange
**first
= ranges
;
1365 AtkTextRange
*range
;
1369 g_free (range
->content
);
1376 static AtkTextRange
*
1377 atk_text_range_copy (AtkTextRange
*src
)
1379 AtkTextRange
*dst
= g_new0 (AtkTextRange
, 1);
1380 dst
->bounds
= src
->bounds
;
1381 dst
->start_offset
= src
->start_offset
;
1382 dst
->end_offset
= src
->end_offset
;
1384 dst
->content
= g_strdup (src
->content
);
1389 atk_text_range_free (AtkTextRange
*range
)
1391 g_free (range
->content
);
1395 G_DEFINE_BOXED_TYPE (AtkTextRange
, atk_text_range
, atk_text_range_copy
,
1396 atk_text_range_free
)