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"
28 * @Short_description: The ATK interface implemented by components
32 * #AtkText should be implemented by #AtkObjects on behalf of widgets
33 * that have text content which is either attributed or otherwise
34 * non-trivial. #AtkObjects whose text content is simple,
35 * unattributed, and very brief may expose that content via
36 * #atk_object_get_name instead; however if the text is editable,
37 * multi-line, typically longer than three or four words, attributed,
38 * selectable, or if the object already uses the 'name' ATK property
39 * for other information, the #AtkText interface should be used to
40 * expose the text content. In the case of editable text content,
41 * #AtkEditableText (a subtype of the #AtkText interface) should be
42 * implemented instead.
44 * #AtkText provides not only traversal facilities and change
45 * notification for text content, but also caret tracking and glyph
46 * bounding box calculations. Note that the text strings are exposed
47 * as UTF-8, and are therefore potentially multi-byte, and
48 * caret-to-byte offset mapping makes no assumptions about the
49 * character length; also bounding box glyph-to-offset mapping may be
50 * complex for languages which use ligatures.
53 static GPtrArray
*extra_attributes
= NULL
;
58 TEXT_SELECTION_CHANGED
,
59 TEXT_ATTRIBUTES_CHANGED
,
66 static const char boolean
[] =
69 static const guint8 boolean_offsets
[] = {
73 static const char style
[] =
77 static const guint8 style_offsets
[] = {
81 static const char variant
[] =
84 static const guint8 variant_offsets
[] = {
88 static const char stretch
[] =
98 static const guint8 stretch_offsets
[] = {
99 0, 16, 32, 42, 57, 64, 78, 87, 102
102 static const char justification
[] =
107 static const guint8 justification_offsets
[] = {
111 static const char direction
[] =
115 static const guint8 direction_offsets
[] = {
119 static const char wrap_mode
[] =
124 static const guint8 wrap_mode_offsets
[] = {
128 static const char underline
[] =
134 static const guint8 underline_offsets
[] = {
138 static void atk_text_base_init (AtkTextIface
*class);
140 static void atk_text_real_get_range_extents (AtkText
*text
,
143 AtkCoordType coord_type
,
144 AtkTextRectangle
*rect
);
146 static AtkTextRange
** atk_text_real_get_bounded_ranges (AtkText
*text
,
147 AtkTextRectangle
*rect
,
148 AtkCoordType coord_type
,
149 AtkTextClipType x_clip_type
,
150 AtkTextClipType y_clip_type
);
152 static guint atk_text_signals
[LAST_SIGNAL
] = { 0 };
155 atk_text_get_type (void)
157 static GType type
= 0;
161 static const GTypeInfo tinfo
=
163 sizeof (AtkTextIface
),
164 (GBaseInitFunc
) atk_text_base_init
,
165 (GBaseFinalizeFunc
) NULL
,
166 (GClassInitFunc
) NULL
/* atk_text_interface_init */ ,
167 (GClassFinalizeFunc
) NULL
,
171 type
= g_type_register_static (G_TYPE_INTERFACE
, "AtkText", &tinfo
, 0);
178 atk_text_base_init (AtkTextIface
*class)
180 static gboolean initialized
= FALSE
;
185 * Note that text_changed signal supports details "insert", "delete",
186 * possibly "replace".
189 class->get_range_extents
= atk_text_real_get_range_extents
;
190 class->get_bounded_ranges
= atk_text_real_get_bounded_ranges
;
193 * AtkText::text-changed:
194 * @atktext: the object which received the signal.
195 * @arg1: The position (character offset) of the insertion or deletion.
196 * @arg2: The length (in characters) of text inserted or deleted.
198 * The "text-changed" signal is emitted when the text of the
199 * object which implements the AtkText interface changes, This
200 * signal will have a detail which is either "insert" or
201 * "delete" which identifies whether the text change was an
202 * insertion or a deletion.
204 * Deprecated: Since 2.9.4. Use #AtkObject::text-insert or
205 * #AtkObject::text-remove instead.
207 atk_text_signals
[TEXT_CHANGED
] =
208 g_signal_new ("text_changed",
210 G_SIGNAL_RUN_LAST
| G_SIGNAL_DETAILED
,
211 G_STRUCT_OFFSET (AtkTextIface
, text_changed
),
212 (GSignalAccumulator
) NULL
, NULL
,
213 atk_marshal_VOID__INT_INT
,
215 2, G_TYPE_INT
, G_TYPE_INT
);
218 * AtkText::text-insert:
219 * @atktext: the object which received the signal.
220 * @arg1: The position (character offset) of the insertion.
221 * @arg2: The length (in characters) of text inserted.
222 * @arg3: The text inserted
224 * The "text-insert" signal is emitted when a new text is
227 atk_text_signals
[TEXT_INSERT
] =
228 g_signal_new ("text_insert",
230 G_SIGNAL_RUN_LAST
| G_SIGNAL_DETAILED
,
232 (GSignalAccumulator
) NULL
, NULL
,
233 atk_marshal_VOID__INT_INT_STRING
,
235 3, G_TYPE_INT
, G_TYPE_INT
, G_TYPE_STRING
);
238 * AtkText::text-remove:
239 * @atktext: the object which received the signal.
240 * @arg1: The position (character offset) of the removal.
241 * @arg2: The length (in characters) of text removed.
242 * @arg3: The text inserted
244 * The "text-remove" signal is emitted when a new text is
247 atk_text_signals
[TEXT_REMOVE
] =
248 g_signal_new ("text_remove",
250 G_SIGNAL_RUN_LAST
| G_SIGNAL_DETAILED
,
252 (GSignalAccumulator
) NULL
, NULL
,
253 atk_marshal_VOID__INT_INT_STRING
,
255 3, G_TYPE_INT
, G_TYPE_INT
, G_TYPE_STRING
);
258 * AtkText::text-update:
259 * @atktext: the object which received the signal.
265 * The "text-update" signal is emitted when a new text is
268 atk_text_signals
[TEXT_UPDATE
] =
269 g_signal_new ("text_update",
271 G_SIGNAL_RUN_LAST
| G_SIGNAL_DETAILED
,
273 (GSignalAccumulator
) NULL
, NULL
,
274 atk_marshal_VOID__INT_INT_INT_STRING
,
276 4, G_TYPE_INT
, G_TYPE_INT
, G_TYPE_INT
, G_TYPE_STRING
);
280 * AtkText::text-caret-moved:
281 * @atktext: the object which received the signal.
282 * @arg1: The new position of the text caret.
284 * The "text-caret-moved" signal is emitted when the caret
285 * position of the text of an object which implements AtkText
288 atk_text_signals
[TEXT_CARET_MOVED
] =
289 g_signal_new ("text_caret_moved",
292 G_STRUCT_OFFSET (AtkTextIface
, text_caret_moved
),
293 (GSignalAccumulator
) NULL
, NULL
,
294 g_cclosure_marshal_VOID__INT
,
299 * AtkText::text-selection-changed:
300 * @atktext: the object which received the signal.
302 * The "text-selection-changed" signal is emitted when the
303 * selected text of an object which implements AtkText changes.
305 atk_text_signals
[TEXT_SELECTION_CHANGED
] =
306 g_signal_new ("text_selection_changed",
309 G_STRUCT_OFFSET (AtkTextIface
, text_selection_changed
),
310 (GSignalAccumulator
) NULL
, NULL
,
311 g_cclosure_marshal_VOID__VOID
,
314 * AtkText::text-attributes-changed:
315 * @atktext: the object which received the signal.
317 * The "text-attributes-changed" signal is emitted when the text
318 * attributes of the text of an object which implements AtkText
321 atk_text_signals
[TEXT_ATTRIBUTES_CHANGED
] =
322 g_signal_new ("text_attributes_changed",
325 G_STRUCT_OFFSET (AtkTextIface
, text_attributes_changed
),
326 (GSignalAccumulator
) NULL
, NULL
,
327 g_cclosure_marshal_VOID__VOID
,
338 * @start_offset: start position
339 * @end_offset: end position, or -1 for the end of the string.
341 * Gets the specified text.
343 * Returns: a newly allocated string containing the text from @start_offset up
344 * to, but not including @end_offset. Use g_free() to free the returned string.
347 atk_text_get_text (AtkText
*text
,
353 g_return_val_if_fail (ATK_IS_TEXT (text
), NULL
);
355 iface
= ATK_TEXT_GET_IFACE (text
);
357 if (start_offset
< 0 || end_offset
< -1 ||
358 (end_offset
!= -1 && end_offset
< start_offset
))
362 return (*(iface
->get_text
)) (text
, start_offset
, end_offset
);
368 * atk_text_get_character_at_offset:
372 * Gets the specified text.
374 * Returns: the character at @offset.
377 atk_text_get_character_at_offset (AtkText
*text
,
382 g_return_val_if_fail (ATK_IS_TEXT (text
), (gunichar
) 0);
384 iface
= ATK_TEXT_GET_IFACE (text
);
386 if (iface
->get_character_at_offset
)
387 return (*(iface
->get_character_at_offset
)) (text
, offset
);
393 * atk_text_get_text_after_offset:
396 * @boundary_type: An #AtkTextBoundary
397 * @start_offset: (out): the start offset of the returned string
398 * @end_offset: (out): the offset of the first character after the
401 * Gets the specified text.
403 * Deprecated: This method is deprecated since ATK version
404 * 2.9.3. Please use atk_text_get_at_offset() instead.
406 * Returns: a newly allocated string containing the text after @offset bounded
407 * by the specified @boundary_type. Use g_free() to free the returned string.
410 atk_text_get_text_after_offset (AtkText
*text
,
412 AtkTextBoundary boundary_type
,
417 gint local_start_offset
, local_end_offset
;
418 gint
*real_start_offset
, *real_end_offset
;
420 g_return_val_if_fail (ATK_IS_TEXT (text
), NULL
);
423 real_start_offset
= start_offset
;
425 real_start_offset
= &local_start_offset
;
427 real_end_offset
= end_offset
;
429 real_end_offset
= &local_end_offset
;
434 iface
= ATK_TEXT_GET_IFACE (text
);
436 if (iface
->get_text_after_offset
)
437 return (*(iface
->get_text_after_offset
)) (text
, offset
, boundary_type
, real_start_offset
, real_end_offset
);
443 * atk_text_get_text_at_offset:
446 * @boundary_type: An #AtkTextBoundary
447 * @start_offset: (out): the start offset of the returned string
448 * @end_offset: (out): the offset of the first character after the
451 * Gets the specified text.
453 * If the boundary_type if ATK_TEXT_BOUNDARY_CHAR the character at the
454 * offset is returned.
456 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START the returned string
457 * is from the word start at or before the offset to the word start after
460 * The returned string will contain the word at the offset if the offset
461 * is inside a word and will contain the word before the offset if the
462 * offset is not inside a word.
464 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the returned
465 * string is from the sentence start at or before the offset to the sentence
466 * start after the offset.
468 * The returned string will contain the sentence at the offset if the offset
469 * is inside a sentence and will contain the sentence before the offset
470 * if the offset is not inside a sentence.
472 * If the boundary type is ATK_TEXT_BOUNDARY_LINE_START the returned
473 * string is from the line start at or before the offset to the line
474 * start after the offset.
476 * Returns: a newly allocated string containing the text at @offset bounded by
477 * the specified @boundary_type. Use g_free() to free the returned string.
480 atk_text_get_text_at_offset (AtkText
*text
,
482 AtkTextBoundary boundary_type
,
487 gint local_start_offset
, local_end_offset
;
488 gint
*real_start_offset
, *real_end_offset
;
490 g_return_val_if_fail (ATK_IS_TEXT (text
), NULL
);
493 real_start_offset
= start_offset
;
495 real_start_offset
= &local_start_offset
;
497 real_end_offset
= end_offset
;
499 real_end_offset
= &local_end_offset
;
501 iface
= ATK_TEXT_GET_IFACE (text
);
503 if (iface
->get_text_at_offset
)
504 return (*(iface
->get_text_at_offset
)) (text
, offset
, boundary_type
, real_start_offset
, real_end_offset
);
510 * atk_text_get_text_before_offset:
513 * @boundary_type: An #AtkTextBoundary
514 * @start_offset: (out): the start offset of the returned string
515 * @end_offset: (out): the offset of the first character after the
518 * Gets the specified text.
520 * Deprecated: This method is deprecated since ATK version
521 * 2.9.3. Please use atk_text_get_at_offset() instead.
523 * Returns: a newly allocated string containing the text before @offset bounded
524 * by the specified @boundary_type. Use g_free() to free the returned string.
527 atk_text_get_text_before_offset (AtkText
*text
,
529 AtkTextBoundary boundary_type
,
534 gint local_start_offset
, local_end_offset
;
535 gint
*real_start_offset
, *real_end_offset
;
537 g_return_val_if_fail (ATK_IS_TEXT (text
), NULL
);
540 real_start_offset
= start_offset
;
542 real_start_offset
= &local_start_offset
;
544 real_end_offset
= end_offset
;
546 real_end_offset
= &local_end_offset
;
551 iface
= ATK_TEXT_GET_IFACE (text
);
553 if (iface
->get_text_before_offset
)
554 return (*(iface
->get_text_before_offset
)) (text
, offset
, boundary_type
, real_start_offset
, real_end_offset
);
560 * atk_text_get_caret_offset:
563 * Gets the offset position of the caret (cursor).
565 * Returns: the offset position of the caret (cursor).
568 atk_text_get_caret_offset (AtkText
*text
)
572 g_return_val_if_fail (ATK_IS_TEXT (text
), 0);
574 iface
= ATK_TEXT_GET_IFACE (text
);
576 if (iface
->get_caret_offset
)
577 return (*(iface
->get_caret_offset
)) (text
);
583 * atk_text_get_character_extents:
585 * @offset: The offset of the text character for which bounding information is required.
586 * @x: Pointer for the x cordinate of the bounding box
587 * @y: Pointer for the y cordinate of the bounding box
588 * @width: Pointer for the width of the bounding box
589 * @height: Pointer for the height of the bounding box
590 * @coords: specify whether coordinates are relative to the screen or widget window
592 * Get the bounding box containing the glyph representing the character at
593 * a particular text offset.
596 atk_text_get_character_extents (AtkText
*text
,
605 gint local_x
, local_y
, local_width
, local_height
;
606 gint
*real_x
, *real_y
, *real_width
, *real_height
;
608 g_return_if_fail (ATK_IS_TEXT (text
));
621 real_width
= &local_width
;
623 real_height
= height
;
625 real_height
= &local_height
;
635 iface
= ATK_TEXT_GET_IFACE (text
);
637 if (iface
->get_character_extents
)
638 (*(iface
->get_character_extents
)) (text
, offset
, real_x
, real_y
, real_width
, real_height
, coords
);
642 *real_x
= *real_x
+ *real_width
;
648 * atk_text_get_run_attributes:
650 *@offset: the offset at which to get the attributes, -1 means the offset of
651 *the character to be inserted at the caret location.
652 *@start_offset: (out): the address to put the start offset of the range
653 *@end_offset: (out): the address to put the end offset of the range
655 *Creates an #AtkAttributeSet which consists of the attributes explicitly
656 *set at the position @offset in the text. @start_offset and @end_offset are
657 *set to the start and end of the range around @offset where the attributes are
658 *invariant. Note that @end_offset is the offset of the first character
659 *after the range. See the enum AtkTextAttribute for types of text
660 *attributes that can be returned. Note that other attributes may also be
663 *Returns: (transfer full): an #AtkAttributeSet which contains the attributes
664 * explicitly set at @offset. This #AtkAttributeSet should be freed by a call
665 * to atk_attribute_set_free().
668 atk_text_get_run_attributes (AtkText
*text
,
674 gint local_start_offset
, local_end_offset
;
675 gint
*real_start_offset
, *real_end_offset
;
677 g_return_val_if_fail (ATK_IS_TEXT (text
), NULL
);
680 real_start_offset
= start_offset
;
682 real_start_offset
= &local_start_offset
;
684 real_end_offset
= end_offset
;
686 real_end_offset
= &local_end_offset
;
691 iface
= ATK_TEXT_GET_IFACE (text
);
693 if (iface
->get_run_attributes
)
694 return (*(iface
->get_run_attributes
)) (text
, offset
, real_start_offset
, real_end_offset
);
700 * atk_text_get_default_attributes:
703 *Creates an #AtkAttributeSet which consists of the default values of
704 *attributes for the text. See the enum AtkTextAttribute for types of text
705 *attributes that can be returned. Note that other attributes may also be
708 *Returns: (transfer full): an #AtkAttributeSet which contains the default
709 * values of attributes. at @offset. this #atkattributeset should be freed by
710 * a call to atk_attribute_set_free().
713 atk_text_get_default_attributes (AtkText
*text
)
717 g_return_val_if_fail (ATK_IS_TEXT (text
), NULL
);
719 iface
= ATK_TEXT_GET_IFACE (text
);
721 if (iface
->get_default_attributes
)
722 return (*(iface
->get_default_attributes
)) (text
);
728 * atk_text_get_character_count:
731 * Gets the character count.
733 * Returns: the number of characters.
736 atk_text_get_character_count (AtkText
*text
)
740 g_return_val_if_fail (ATK_IS_TEXT (text
), -1);
742 iface
= ATK_TEXT_GET_IFACE (text
);
744 if (iface
->get_character_count
)
745 return (*(iface
->get_character_count
)) (text
);
751 * atk_text_get_offset_at_point:
753 * @x: screen x-position of character
754 * @y: screen y-position of character
755 * @coords: specify whether coordinates are relative to the screen or
758 * Gets the offset of the character located at coordinates @x and @y. @x and @y
759 * are interpreted as being relative to the screen or this widget's window
760 * depending on @coords.
762 * Returns: the offset to the character which is located at
763 * the specified @x and @y coordinates.
766 atk_text_get_offset_at_point (AtkText
*text
,
773 g_return_val_if_fail (ATK_IS_TEXT (text
), -1);
775 iface
= ATK_TEXT_GET_IFACE (text
);
777 if (iface
->get_offset_at_point
)
778 return (*(iface
->get_offset_at_point
)) (text
, x
, y
, coords
);
784 * atk_text_get_n_selections:
787 * Gets the number of selected regions.
789 * Returns: The number of selected regions, or -1 if a failure
793 atk_text_get_n_selections (AtkText
*text
)
797 g_return_val_if_fail (ATK_IS_TEXT (text
), -1);
799 iface
= ATK_TEXT_GET_IFACE (text
);
801 if (iface
->get_n_selections
)
802 return (*(iface
->get_n_selections
)) (text
);
808 * atk_text_get_selection:
810 * @selection_num: The selection number. The selected regions are
811 * assigned numbers that correspond to how far the region is from the
812 * start of the text. The selected region closest to the beginning
813 * of the text region is assigned the number 0, etc. Note that adding,
814 * moving or deleting a selected region can change the numbering.
815 * @start_offset: (out): passes back the start position of the selected region
816 * @end_offset: (out): passes back the end position of (e.g. offset immediately past)
817 * the selected region
819 * Gets the text from the specified selection.
821 * Returns: a newly allocated string containing the selected text. Use g_free()
822 * to free the returned string.
825 atk_text_get_selection (AtkText
*text
,
831 gint local_start_offset
, local_end_offset
;
832 gint
*real_start_offset
, *real_end_offset
;
834 g_return_val_if_fail (ATK_IS_TEXT (text
), NULL
);
837 real_start_offset
= start_offset
;
839 real_start_offset
= &local_start_offset
;
841 real_end_offset
= end_offset
;
843 real_end_offset
= &local_end_offset
;
845 iface
= ATK_TEXT_GET_IFACE (text
);
847 if (iface
->get_selection
)
849 return (*(iface
->get_selection
)) (text
, selection_num
,
850 real_start_offset
, real_end_offset
);
857 * atk_text_add_selection:
859 * @start_offset: the start position of the selected region
860 * @end_offset: the offset of the first character after the selected region.
862 * Adds a selection bounded by the specified offsets.
864 * Returns: %TRUE if success, %FALSE otherwise
867 atk_text_add_selection (AtkText
*text
,
873 g_return_val_if_fail (ATK_IS_TEXT (text
), FALSE
);
875 iface
= ATK_TEXT_GET_IFACE (text
);
877 if (iface
->add_selection
)
878 return (*(iface
->add_selection
)) (text
, start_offset
, end_offset
);
884 * atk_text_remove_selection:
886 * @selection_num: The selection number. The selected regions are
887 * assigned numbers that correspond to how far the region is from the
888 * start of the text. The selected region closest to the beginning
889 * of the text region is assigned the number 0, etc. Note that adding,
890 * moving or deleting a selected region can change the numbering.
892 * Removes the specified selection.
894 * Returns: %TRUE if success, %FALSE otherwise
897 atk_text_remove_selection (AtkText
*text
,
902 g_return_val_if_fail (ATK_IS_TEXT (text
), FALSE
);
904 iface
= ATK_TEXT_GET_IFACE (text
);
906 if (iface
->remove_selection
)
907 return (*(iface
->remove_selection
)) (text
, selection_num
);
913 * atk_text_set_selection:
915 * @selection_num: The selection number. The selected regions are
916 * assigned numbers that correspond to how far the region is from the
917 * start of the text. The selected region closest to the beginning
918 * of the text region is assigned the number 0, etc. Note that adding,
919 * moving or deleting a selected region can change the numbering.
920 * @start_offset: the new start position of the selection
921 * @end_offset: the new end position of (e.g. offset immediately past)
924 * Changes the start and end offset of the specified selection.
926 * Returns: %TRUE if success, %FALSE otherwise
929 atk_text_set_selection (AtkText
*text
,
936 g_return_val_if_fail (ATK_IS_TEXT (text
), FALSE
);
938 iface
= ATK_TEXT_GET_IFACE (text
);
940 if (iface
->set_selection
)
942 return (*(iface
->set_selection
)) (text
, selection_num
,
943 start_offset
, end_offset
);
950 * atk_text_set_caret_offset:
954 * Sets the caret (cursor) position to the specified @offset.
956 * Returns: %TRUE if success, %FALSE otherwise.
959 atk_text_set_caret_offset (AtkText
*text
,
964 g_return_val_if_fail (ATK_IS_TEXT (text
), FALSE
);
966 iface
= ATK_TEXT_GET_IFACE (text
);
968 if (iface
->set_caret_offset
)
970 return (*(iface
->set_caret_offset
)) (text
, offset
);
979 * atk_text_get_range_extents:
981 * @start_offset: The offset of the first text character for which boundary
982 * information is required.
983 * @end_offset: The offset of the text character after the last character
984 * for which boundary information is required.
985 * @coord_type: Specify whether coordinates are relative to the screen or widget window.
986 * @rect: A pointer to a AtkTextRectangle which is filled in by this function.
988 * Get the bounding box for text within the specified range.
993 atk_text_get_range_extents (AtkText
*text
,
996 AtkCoordType coord_type
,
997 AtkTextRectangle
*rect
)
1001 g_return_if_fail (ATK_IS_TEXT (text
));
1002 g_return_if_fail (rect
);
1004 if (start_offset
< 0 || start_offset
>= end_offset
)
1007 iface
= ATK_TEXT_GET_IFACE (text
);
1009 if (iface
->get_range_extents
)
1010 (*(iface
->get_range_extents
)) (text
, start_offset
, end_offset
, coord_type
, rect
);
1014 * atk_text_get_bounded_ranges:
1015 * @text: an #AtkText
1016 * @rect: An AtkTextRectangle giving the dimensions of the bounding box.
1017 * @coord_type: Specify whether coordinates are relative to the screen or widget window.
1018 * @x_clip_type: Specify the horizontal clip type.
1019 * @y_clip_type: Specify the vertical clip type.
1021 * Get the ranges of text in the specified bounding box.
1025 * Returns: (array zero-terminated=1): Array of AtkTextRange. The last
1026 * element of the array returned by this function will be NULL.
1027 * Virtual: get_bounded_ranges
1030 atk_text_get_bounded_ranges (AtkText
*text
,
1031 AtkTextRectangle
*rect
,
1032 AtkCoordType coord_type
,
1033 AtkTextClipType x_clip_type
,
1034 AtkTextClipType y_clip_type
)
1036 AtkTextIface
*iface
;
1038 g_return_val_if_fail (ATK_IS_TEXT (text
), NULL
);
1039 g_return_val_if_fail (rect
, NULL
);
1041 iface
= ATK_TEXT_GET_IFACE (text
);
1043 if (iface
->get_bounded_ranges
)
1044 return (*(iface
->get_bounded_ranges
)) (text
, rect
, coord_type
, x_clip_type
, y_clip_type
);
1050 * atk_attribute_set_free:
1051 * @attrib_set: The #AtkAttributeSet to free
1053 * Frees the memory used by an #AtkAttributeSet, including all its
1057 atk_attribute_set_free (AtkAttributeSet
*attrib_set
)
1063 while (temp
!= NULL
)
1070 g_free (att
->value
);
1074 g_slist_free (attrib_set
);
1078 * atk_text_attribute_register:
1079 * @name: a name string
1081 * Associate @name with a new #AtkTextAttribute
1083 * Returns: an #AtkTextAttribute associated with @name
1086 atk_text_attribute_register (const gchar
*name
)
1088 g_return_val_if_fail (name
, ATK_TEXT_ATTR_INVALID
);
1090 if (!extra_attributes
)
1091 extra_attributes
= g_ptr_array_new ();
1093 g_ptr_array_add (extra_attributes
, g_strdup (name
));
1094 return extra_attributes
->len
+ ATK_TEXT_ATTR_LAST_DEFINED
;
1098 * atk_text_attribute_get_name:
1099 * @attr: The #AtkTextAttribute whose name is required
1101 * Gets the name corresponding to the #AtkTextAttribute
1103 * Returns: a string containing the name; this string should not be freed
1106 atk_text_attribute_get_name (AtkTextAttribute attr
)
1108 GTypeClass
*type_class
;
1110 const gchar
*name
= NULL
;
1112 type_class
= g_type_class_ref (ATK_TYPE_TEXT_ATTRIBUTE
);
1113 g_return_val_if_fail (G_IS_ENUM_CLASS (type_class
), NULL
);
1115 value
= g_enum_get_value (G_ENUM_CLASS (type_class
), attr
);
1119 name
= value
->value_nick
;
1123 if (extra_attributes
)
1127 n
-= ATK_TEXT_ATTR_LAST_DEFINED
+ 1;
1129 if (n
< extra_attributes
->len
)
1131 name
= g_ptr_array_index (extra_attributes
, n
);
1134 g_type_class_unref (type_class
);
1139 * atk_text_attribute_for_name:
1140 * @name: a string which is the (non-localized) name of an ATK text attribute.
1142 * Get the #AtkTextAttribute type corresponding to a text attribute name.
1144 * Returns: the #AtkTextAttribute enumerated type corresponding to the specified
1146 * or #ATK_TEXT_ATTRIBUTE_INVALID if no matching text attribute is found.
1149 atk_text_attribute_for_name (const gchar
*name
)
1151 GTypeClass
*type_class
;
1153 AtkTextAttribute type
= ATK_TEXT_ATTR_INVALID
;
1155 g_return_val_if_fail (name
, ATK_TEXT_ATTR_INVALID
);
1157 type_class
= g_type_class_ref (ATK_TYPE_TEXT_ATTRIBUTE
);
1158 g_return_val_if_fail (G_IS_ENUM_CLASS (type_class
), ATK_TEXT_ATTR_INVALID
);
1160 value
= g_enum_get_value_by_nick (G_ENUM_CLASS (type_class
), name
);
1164 type
= value
->value
;
1170 if (extra_attributes
)
1172 for (i
= 0; i
< extra_attributes
->len
; i
++)
1174 gchar
*extra_attribute
= (gchar
*)g_ptr_array_index (extra_attributes
, i
);
1176 g_return_val_if_fail (extra_attribute
, ATK_TEXT_ATTR_INVALID
);
1178 if (strcmp (name
, extra_attribute
) == 0)
1180 type
= i
+ 1 + ATK_TEXT_ATTR_LAST_DEFINED
;
1186 g_type_class_unref (type_class
);
1192 * atk_text_attribute_get_value:
1193 * @attr: The #AtkTextAttribute for which a value is required
1194 * @index_: The index of the required value
1196 * Gets the value for the index of the #AtkTextAttribute
1198 * Returns: a string containing the value; this string should not be freed;
1199 * NULL is returned if there are no values maintained for the attr value.
1202 atk_text_attribute_get_value (AtkTextAttribute attr
,
1207 case ATK_TEXT_ATTR_INVISIBLE
:
1208 case ATK_TEXT_ATTR_EDITABLE
:
1209 case ATK_TEXT_ATTR_BG_FULL_HEIGHT
:
1210 case ATK_TEXT_ATTR_STRIKETHROUGH
:
1211 case ATK_TEXT_ATTR_BG_STIPPLE
:
1212 case ATK_TEXT_ATTR_FG_STIPPLE
:
1213 g_assert (index
>= 0 && index
< G_N_ELEMENTS (boolean_offsets
));
1214 return boolean
+ boolean_offsets
[index
];
1215 case ATK_TEXT_ATTR_UNDERLINE
:
1216 g_assert (index
>= 0 && index
< G_N_ELEMENTS (underline_offsets
));
1217 return underline
+ underline_offsets
[index
];
1218 case ATK_TEXT_ATTR_WRAP_MODE
:
1219 g_assert (index
>= 0 && index
< G_N_ELEMENTS (wrap_mode_offsets
));
1220 return wrap_mode
+ wrap_mode_offsets
[index
];
1221 case ATK_TEXT_ATTR_DIRECTION
:
1222 g_assert (index
>= 0 && index
< G_N_ELEMENTS (direction_offsets
));
1223 return direction
+ direction_offsets
[index
];
1224 case ATK_TEXT_ATTR_JUSTIFICATION
:
1225 g_assert (index
>= 0 && index
< G_N_ELEMENTS (justification_offsets
));
1226 return justification
+ justification_offsets
[index
];
1227 case ATK_TEXT_ATTR_STRETCH
:
1228 g_assert (index
>= 0 && index
< G_N_ELEMENTS (stretch_offsets
));
1229 return stretch
+ stretch_offsets
[index
];
1230 case ATK_TEXT_ATTR_VARIANT
:
1231 g_assert (index
>= 0 && index
< G_N_ELEMENTS (variant_offsets
));
1232 return variant
+ variant_offsets
[index
];
1233 case ATK_TEXT_ATTR_STYLE
:
1234 g_assert (index
>= 0 && index
< G_N_ELEMENTS (style_offsets
));
1235 return style
+ style_offsets
[index
];
1242 atk_text_rectangle_union (AtkTextRectangle
*src1
,
1243 AtkTextRectangle
*src2
,
1244 AtkTextRectangle
*dest
)
1246 gint dest_x
, dest_y
;
1248 dest_x
= MIN (src1
->x
, src2
->x
);
1249 dest_y
= MIN (src1
->y
, src2
->y
);
1250 dest
->width
= MAX (src1
->x
+ src1
->width
, src2
->x
+ src2
->width
) - dest_x
;
1251 dest
->height
= MAX (src1
->y
+ src1
->height
, src2
->y
+ src2
->height
) - dest_y
;
1257 atk_text_rectangle_contain (AtkTextRectangle
*clip
,
1258 AtkTextRectangle
*bounds
,
1259 AtkTextClipType x_clip_type
,
1260 AtkTextClipType y_clip_type
)
1262 gboolean x_min_ok
, x_max_ok
, y_min_ok
, y_max_ok
;
1264 x_min_ok
= (bounds
->x
>= clip
->x
) ||
1265 ((bounds
->x
+ bounds
->width
>= clip
->x
) &&
1266 ((x_clip_type
== ATK_TEXT_CLIP_NONE
) ||
1267 (x_clip_type
== ATK_TEXT_CLIP_MAX
)));
1269 x_max_ok
= (bounds
->x
+ bounds
->width
<= clip
->x
+ clip
->width
) ||
1270 ((bounds
->x
<= clip
->x
+ clip
->width
) &&
1271 ((x_clip_type
== ATK_TEXT_CLIP_NONE
) ||
1272 (x_clip_type
== ATK_TEXT_CLIP_MIN
)));
1274 y_min_ok
= (bounds
->y
>= clip
->y
) ||
1275 ((bounds
->y
+ bounds
->height
>= clip
->y
) &&
1276 ((y_clip_type
== ATK_TEXT_CLIP_NONE
) ||
1277 (y_clip_type
== ATK_TEXT_CLIP_MAX
)));
1279 y_max_ok
= (bounds
->y
+ bounds
->height
<= clip
->y
+ clip
->height
) ||
1280 ((bounds
->y
<= clip
->y
+ clip
->height
) &&
1281 ((y_clip_type
== ATK_TEXT_CLIP_NONE
) ||
1282 (y_clip_type
== ATK_TEXT_CLIP_MIN
)));
1284 return (x_min_ok
&& x_max_ok
&& y_min_ok
&& y_max_ok
);
1289 atk_text_real_get_range_extents (AtkText
*text
,
1292 AtkCoordType coord_type
,
1293 AtkTextRectangle
*rect
)
1296 AtkTextRectangle cbounds
, bounds
;
1298 atk_text_get_character_extents (text
, start_offset
,
1299 &bounds
.x
, &bounds
.y
,
1300 &bounds
.width
, &bounds
.height
,
1303 for (i
= start_offset
+ 1; i
< end_offset
; i
++)
1305 atk_text_get_character_extents (text
, i
,
1306 &cbounds
.x
, &cbounds
.y
,
1307 &cbounds
.width
, &cbounds
.height
,
1309 atk_text_rectangle_union (&bounds
, &cbounds
, &bounds
);
1314 rect
->width
= bounds
.width
;
1315 rect
->height
= bounds
.height
;
1318 static AtkTextRange
**
1319 atk_text_real_get_bounded_ranges (AtkText
*text
,
1320 AtkTextRectangle
*rect
,
1321 AtkCoordType coord_type
,
1322 AtkTextClipType x_clip_type
,
1323 AtkTextClipType y_clip_type
)
1325 gint bounds_min_offset
, bounds_max_offset
;
1326 gint min_line_start
, min_line_end
;
1327 gint max_line_start
, max_line_end
;
1331 gint num_ranges
= 0;
1332 gint range_size
= 1;
1333 AtkTextRectangle cbounds
;
1334 AtkTextRange
**range
;
1337 bounds_min_offset
= atk_text_get_offset_at_point (text
, rect
->x
, rect
->y
, coord_type
);
1338 bounds_max_offset
= atk_text_get_offset_at_point (text
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
, coord_type
);
1340 if (bounds_min_offset
== 0 &&
1341 bounds_min_offset
== bounds_max_offset
)
1344 line
= atk_text_get_text_at_offset (text
, bounds_min_offset
,
1345 ATK_TEXT_BOUNDARY_LINE_START
,
1346 &min_line_start
, &min_line_end
);
1348 line
= atk_text_get_text_at_offset (text
, bounds_max_offset
,
1349 ATK_TEXT_BOUNDARY_LINE_START
,
1350 &max_line_start
, &max_line_end
);
1352 bounds_min_offset
= MIN (min_line_start
, max_line_start
);
1353 bounds_max_offset
= MAX (min_line_end
, max_line_end
);
1355 curr_offset
= bounds_min_offset
;
1356 while (curr_offset
< bounds_max_offset
)
1358 offset
= curr_offset
;
1360 while (curr_offset
< bounds_max_offset
)
1362 atk_text_get_character_extents (text
, curr_offset
,
1363 &cbounds
.x
, &cbounds
.y
,
1364 &cbounds
.width
, &cbounds
.height
,
1366 if (!atk_text_rectangle_contain (rect
, &cbounds
, x_clip_type
, y_clip_type
))
1370 if (curr_offset
> offset
)
1372 AtkTextRange
*one_range
= g_new (AtkTextRange
, 1);
1374 one_range
->start_offset
= offset
;
1375 one_range
->end_offset
= curr_offset
;
1376 one_range
->content
= atk_text_get_text (text
, offset
, curr_offset
);
1377 atk_text_get_range_extents (text
, offset
, curr_offset
, coord_type
, &one_range
->bounds
);
1379 if (num_ranges
>= range_size
- 1)
1382 range
= g_realloc (range
, range_size
* sizeof (gpointer
));
1384 range
[num_ranges
] = one_range
;
1389 range
[num_ranges
] = NULL
;
1395 * atk_text_free_ranges:
1396 * @ranges: (array): A pointer to an array of #AtkTextRange which is
1399 * Frees the memory associated with an array of AtkTextRange. It is assumed
1400 * that the array was returned by the function atk_text_get_bounded_ranges
1401 * and is NULL terminated.
1406 atk_text_free_ranges (AtkTextRange
**ranges
)
1408 AtkTextRange
**first
= ranges
;
1414 AtkTextRange
*range
;
1418 g_free (range
->content
);
1425 static AtkTextRange
*
1426 atk_text_range_copy (AtkTextRange
*src
)
1428 AtkTextRange
*dst
= g_new0 (AtkTextRange
, 1);
1429 dst
->bounds
= src
->bounds
;
1430 dst
->start_offset
= src
->start_offset
;
1431 dst
->end_offset
= src
->end_offset
;
1433 dst
->content
= g_strdup (src
->content
);
1438 atk_text_range_free (AtkTextRange
*range
)
1440 g_free (range
->content
);
1444 G_DEFINE_BOXED_TYPE (AtkTextRange
, atk_text_range
, atk_text_range_copy
,
1445 atk_text_range_free
)