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"
27 * @Short_description: The ATK interface implemented by components
31 * #AtkText should be implemented by #AtkObjects on behalf of widgets
32 * that have text content which is either attributed or otherwise
33 * non-trivial. #AtkObjects whose text content is simple,
34 * unattributed, and very brief may expose that content via
35 * #atk_object_get_name instead; however if the text is editable,
36 * multi-line, typically longer than three or four words, attributed,
37 * selectable, or if the object already uses the 'name' ATK property
38 * for other information, the #AtkText interface should be used to
39 * expose the text content. In the case of editable text content,
40 * #AtkEditableText (a subtype of the #AtkText interface) should be
41 * implemented instead.
43 * #AtkText provides not only traversal facilities and change
44 * notification for text content, but also caret tracking and glyph
45 * bounding box calculations. Note that the text strings are exposed
46 * as UTF-8, and are therefore potentially multi-byte, and
47 * caret-to-byte offset mapping makes no assumptions about the
48 * character length; also bounding box glyph-to-offset mapping may be
49 * complex for languages which use ligatures.
52 static GPtrArray
*extra_attributes
= NULL
;
57 TEXT_SELECTION_CHANGED
,
58 TEXT_ATTRIBUTES_CHANGED
,
64 static const char boolean
[] =
67 static const guint8 boolean_offsets
[] = {
71 static const char style
[] =
75 static const guint8 style_offsets
[] = {
79 static const char variant
[] =
82 static const guint8 variant_offsets
[] = {
86 static const char stretch
[] =
96 static const guint8 stretch_offsets
[] = {
97 0, 16, 32, 42, 57, 64, 78, 87, 102
100 static const char justification
[] =
105 static const guint8 justification_offsets
[] = {
109 static const char direction
[] =
113 static const guint8 direction_offsets
[] = {
117 static const char wrap_mode
[] =
122 static const guint8 wrap_mode_offsets
[] = {
126 static const char underline
[] =
132 static const guint8 underline_offsets
[] = {
136 static void atk_text_base_init (AtkTextIface
*class);
138 static void atk_text_real_get_range_extents (AtkText
*text
,
141 AtkCoordType coord_type
,
142 AtkTextRectangle
*rect
);
144 static AtkTextRange
** atk_text_real_get_bounded_ranges (AtkText
*text
,
145 AtkTextRectangle
*rect
,
146 AtkCoordType coord_type
,
147 AtkTextClipType x_clip_type
,
148 AtkTextClipType y_clip_type
);
150 static guint atk_text_signals
[LAST_SIGNAL
] = { 0 };
153 atk_text_get_type (void)
155 static GType type
= 0;
159 static const GTypeInfo tinfo
=
161 sizeof (AtkTextIface
),
162 (GBaseInitFunc
) atk_text_base_init
,
163 (GBaseFinalizeFunc
) NULL
,
164 (GClassInitFunc
) NULL
/* atk_text_interface_init */ ,
165 (GClassFinalizeFunc
) NULL
,
169 type
= g_type_register_static (G_TYPE_INTERFACE
, "AtkText", &tinfo
, 0);
176 atk_text_base_init (AtkTextIface
*class)
178 static gboolean initialized
= FALSE
;
183 * Note that text_changed signal supports details "insert", "delete",
184 * possibly "replace".
187 class->get_range_extents
= atk_text_real_get_range_extents
;
188 class->get_bounded_ranges
= atk_text_real_get_bounded_ranges
;
191 * AtkText::text-changed:
192 * @atktext: the object which received the signal.
193 * @arg1: The position (character offset) of the insertion or deletion.
194 * @arg2: The length (in characters) of text inserted or deleted.
196 * The "text-changed" signal is emitted when the text of the
197 * object which implements the AtkText interface changes, This
198 * signal will have a detail which is either "insert" or
199 * "delete" which identifies whether the text change was an
200 * insertion or a deletion.
202 * Deprecated: Since 2.9.4. Use #AtkObject::text-insert or
203 * #AtkObject::text-remove instead.
205 atk_text_signals
[TEXT_CHANGED
] =
206 g_signal_new ("text_changed",
208 G_SIGNAL_RUN_LAST
| G_SIGNAL_DETAILED
,
209 G_STRUCT_OFFSET (AtkTextIface
, text_changed
),
210 (GSignalAccumulator
) NULL
, NULL
,
211 atk_marshal_VOID__INT_INT
,
213 2, G_TYPE_INT
, G_TYPE_INT
);
216 * AtkText::text-insert:
217 * @atktext: the object which received the signal.
218 * @arg1: The position (character offset) of the insertion.
219 * @arg2: The length (in characters) of text inserted.
220 * @arg3: The new text inserted
222 * The "text-insert" signal is emitted when a new text is
223 * inserted. If the signal was not triggered by the user
224 * (e.g. typing or pasting text), the "system" detail should be
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 old text removed
244 * The "text-remove" signal is emitted when a new text is
245 * removed. If the signal was not triggered by the user
246 * (e.g. typing or pasting text), the "system" detail should be
249 atk_text_signals
[TEXT_REMOVE
] =
250 g_signal_new ("text_remove",
252 G_SIGNAL_RUN_LAST
| G_SIGNAL_DETAILED
,
254 (GSignalAccumulator
) NULL
, NULL
,
255 atk_marshal_VOID__INT_INT_STRING
,
257 3, G_TYPE_INT
, G_TYPE_INT
, G_TYPE_STRING
);
260 * AtkText::text-caret-moved:
261 * @atktext: the object which received the signal.
262 * @arg1: The new position of the text caret.
264 * The "text-caret-moved" signal is emitted when the caret
265 * position of the text of an object which implements AtkText
268 atk_text_signals
[TEXT_CARET_MOVED
] =
269 g_signal_new ("text_caret_moved",
272 G_STRUCT_OFFSET (AtkTextIface
, text_caret_moved
),
273 (GSignalAccumulator
) NULL
, NULL
,
274 g_cclosure_marshal_VOID__INT
,
279 * AtkText::text-selection-changed:
280 * @atktext: the object which received the signal.
282 * The "text-selection-changed" signal is emitted when the
283 * selected text of an object which implements AtkText changes.
285 atk_text_signals
[TEXT_SELECTION_CHANGED
] =
286 g_signal_new ("text_selection_changed",
289 G_STRUCT_OFFSET (AtkTextIface
, text_selection_changed
),
290 (GSignalAccumulator
) NULL
, NULL
,
291 g_cclosure_marshal_VOID__VOID
,
294 * AtkText::text-attributes-changed:
295 * @atktext: the object which received the signal.
297 * The "text-attributes-changed" signal is emitted when the text
298 * attributes of the text of an object which implements AtkText
301 atk_text_signals
[TEXT_ATTRIBUTES_CHANGED
] =
302 g_signal_new ("text_attributes_changed",
305 G_STRUCT_OFFSET (AtkTextIface
, text_attributes_changed
),
306 (GSignalAccumulator
) NULL
, NULL
,
307 g_cclosure_marshal_VOID__VOID
,
318 * @start_offset: start position
319 * @end_offset: end position, or -1 for the end of the string.
321 * Gets the specified text.
323 * Returns: a newly allocated string containing the text from @start_offset up
324 * to, but not including @end_offset. Use g_free() to free the returned string.
327 atk_text_get_text (AtkText
*text
,
333 g_return_val_if_fail (ATK_IS_TEXT (text
), NULL
);
335 iface
= ATK_TEXT_GET_IFACE (text
);
337 if (start_offset
< 0 || end_offset
< -1 ||
338 (end_offset
!= -1 && end_offset
< start_offset
))
342 return (*(iface
->get_text
)) (text
, start_offset
, end_offset
);
348 * atk_text_get_character_at_offset:
352 * Gets the specified text.
354 * Returns: the character at @offset.
357 atk_text_get_character_at_offset (AtkText
*text
,
362 g_return_val_if_fail (ATK_IS_TEXT (text
), (gunichar
) 0);
364 iface
= ATK_TEXT_GET_IFACE (text
);
366 if (iface
->get_character_at_offset
)
367 return (*(iface
->get_character_at_offset
)) (text
, offset
);
373 * atk_text_get_text_after_offset:
376 * @boundary_type: An #AtkTextBoundary
377 * @start_offset: (out): the start offset of the returned string
378 * @end_offset: (out): the offset of the first character after the
381 * Gets the specified text.
383 * Deprecated: This method is deprecated since ATK version
384 * 2.9.3. Please use atk_text_get_string_at_offset() instead.
386 * Returns: a newly allocated string containing the text after @offset bounded
387 * by the specified @boundary_type. Use g_free() to free the returned string.
390 atk_text_get_text_after_offset (AtkText
*text
,
392 AtkTextBoundary boundary_type
,
397 gint local_start_offset
, local_end_offset
;
398 gint
*real_start_offset
, *real_end_offset
;
400 g_return_val_if_fail (ATK_IS_TEXT (text
), NULL
);
403 real_start_offset
= start_offset
;
405 real_start_offset
= &local_start_offset
;
407 real_end_offset
= end_offset
;
409 real_end_offset
= &local_end_offset
;
414 iface
= ATK_TEXT_GET_IFACE (text
);
416 if (iface
->get_text_after_offset
)
417 return (*(iface
->get_text_after_offset
)) (text
, offset
, boundary_type
, real_start_offset
, real_end_offset
);
423 * atk_text_get_text_at_offset:
426 * @boundary_type: An #AtkTextBoundary
427 * @start_offset: (out): the start offset of the returned string
428 * @end_offset: (out): the offset of the first character after the
431 * Gets the specified text.
433 * If the boundary_type if ATK_TEXT_BOUNDARY_CHAR the character at the
434 * offset is returned.
436 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START the returned string
437 * is from the word start at or before the offset to the word start after
440 * The returned string will contain the word at the offset if the offset
441 * is inside a word and will contain the word before the offset if the
442 * offset is not inside a word.
444 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the returned
445 * string is from the sentence start at or before the offset to the sentence
446 * start after the offset.
448 * The returned string will contain the sentence at the offset if the offset
449 * is inside a sentence and will contain the sentence before the offset
450 * if the offset is not inside a sentence.
452 * If the boundary type is ATK_TEXT_BOUNDARY_LINE_START the returned
453 * string is from the line start at or before the offset to the line
454 * start after the offset.
456 * Deprecated: This method is deprecated since ATK version
457 * 2.9.4. Please use atk_text_get_string_at_offset() instead.
459 * Returns: a newly allocated string containing the text at @offset bounded by
460 * the specified @boundary_type. Use g_free() to free the returned string.
463 atk_text_get_text_at_offset (AtkText
*text
,
465 AtkTextBoundary boundary_type
,
470 gint local_start_offset
, local_end_offset
;
471 gint
*real_start_offset
, *real_end_offset
;
473 g_return_val_if_fail (ATK_IS_TEXT (text
), NULL
);
476 real_start_offset
= start_offset
;
478 real_start_offset
= &local_start_offset
;
480 real_end_offset
= end_offset
;
482 real_end_offset
= &local_end_offset
;
484 iface
= ATK_TEXT_GET_IFACE (text
);
486 if (iface
->get_text_at_offset
)
487 return (*(iface
->get_text_at_offset
)) (text
, offset
, boundary_type
, real_start_offset
, real_end_offset
);
493 * atk_text_get_text_before_offset:
496 * @boundary_type: An #AtkTextBoundary
497 * @start_offset: (out): the start offset of the returned string
498 * @end_offset: (out): the offset of the first character after the
501 * Gets the specified text.
503 * Deprecated: This method is deprecated since ATK version
504 * 2.9.3. Please use atk_text_get_string_at_offset() instead.
506 * Returns: a newly allocated string containing the text before @offset bounded
507 * by the specified @boundary_type. Use g_free() to free the returned string.
510 atk_text_get_text_before_offset (AtkText
*text
,
512 AtkTextBoundary boundary_type
,
517 gint local_start_offset
, local_end_offset
;
518 gint
*real_start_offset
, *real_end_offset
;
520 g_return_val_if_fail (ATK_IS_TEXT (text
), NULL
);
523 real_start_offset
= start_offset
;
525 real_start_offset
= &local_start_offset
;
527 real_end_offset
= end_offset
;
529 real_end_offset
= &local_end_offset
;
534 iface
= ATK_TEXT_GET_IFACE (text
);
536 if (iface
->get_text_before_offset
)
537 return (*(iface
->get_text_before_offset
)) (text
, offset
, boundary_type
, real_start_offset
, real_end_offset
);
543 * atk_text_get_string_at_offset:
546 * @granularity: An #AtkTextGranularity
547 * @start_offset: (out): the start offset of the returned string, or -1
548 * if an error has occurred (e.g. invalid offset, not implemented)
549 * @end_offset: (out): the offset of the first character after the returned string,
550 * or -1 if an error has occurred (e.g. invalid offset, not implemented)
552 * Gets a portion of the text exposed through an #AtkText according to a given @offset
553 * and a specific @granularity, along with the start and end offsets defining the
554 * boundaries of such a portion of text.
556 * If @granularity is ATK_TEXT_GRANULARITY_CHAR the character at the
557 * offset is returned.
559 * If @granularity is ATK_TEXT_GRANULARITY_WORD the returned string
560 * is from the word start at or before the offset to the word start after
563 * The returned string will contain the word at the offset if the offset
564 * is inside a word and will contain the word before the offset if the
565 * offset is not inside a word.
567 * If @granularity is ATK_TEXT_GRANULARITY_SENTENCE the returned string
568 * is from the sentence start at or before the offset to the sentence
569 * start after the offset.
571 * The returned string will contain the sentence at the offset if the offset
572 * is inside a sentence and will contain the sentence before the offset
573 * if the offset is not inside a sentence.
575 * If @granularity is ATK_TEXT_GRANULARITY_LINE the returned string
576 * is from the line start at or before the offset to the line
577 * start after the offset.
579 * If @granularity is ATK_TEXT_GRANULARITY_PARAGRAPH the returned string
580 * is from the start of the paragraph at or before the offset to the start
581 * of the following paragraph after the offset.
585 * Returns: a newly allocated string containing the text at the @offset bounded
586 * by the specified @granularity. Use g_free() to free the returned string.
587 * Returns %NULL if the offset is invalid or no implementation is available.
589 gchar
* atk_text_get_string_at_offset (AtkText
*text
,
591 AtkTextGranularity granularity
,
596 gint local_start_offset
, local_end_offset
;
597 gint
*real_start_offset
, *real_end_offset
;
599 g_return_val_if_fail (ATK_IS_TEXT (text
), NULL
);
604 real_start_offset
= start_offset
;
607 real_start_offset
= &local_start_offset
;
612 real_end_offset
= end_offset
;
615 real_end_offset
= &local_end_offset
;
620 iface
= ATK_TEXT_GET_IFACE (text
);
622 if (iface
->get_string_at_offset
)
623 return (*(iface
->get_string_at_offset
)) (text
, offset
, granularity
, real_start_offset
, real_end_offset
);
629 * atk_text_get_caret_offset:
632 * Gets the offset position of the caret (cursor).
634 * Returns: the offset position of the caret (cursor).
637 atk_text_get_caret_offset (AtkText
*text
)
641 g_return_val_if_fail (ATK_IS_TEXT (text
), 0);
643 iface
= ATK_TEXT_GET_IFACE (text
);
645 if (iface
->get_caret_offset
)
646 return (*(iface
->get_caret_offset
)) (text
);
652 * atk_text_get_character_extents:
654 * @offset: The offset of the text character for which bounding information is required.
655 * @x: Pointer for the x cordinate of the bounding box
656 * @y: Pointer for the y cordinate of the bounding box
657 * @width: Pointer for the width of the bounding box
658 * @height: Pointer for the height of the bounding box
659 * @coords: specify whether coordinates are relative to the screen or widget window
661 * Get the bounding box containing the glyph representing the character at
662 * a particular text offset.
665 atk_text_get_character_extents (AtkText
*text
,
674 gint local_x
, local_y
, local_width
, local_height
;
675 gint
*real_x
, *real_y
, *real_width
, *real_height
;
677 g_return_if_fail (ATK_IS_TEXT (text
));
690 real_width
= &local_width
;
692 real_height
= height
;
694 real_height
= &local_height
;
704 iface
= ATK_TEXT_GET_IFACE (text
);
706 if (iface
->get_character_extents
)
707 (*(iface
->get_character_extents
)) (text
, offset
, real_x
, real_y
, real_width
, real_height
, coords
);
711 *real_x
= *real_x
+ *real_width
;
717 * atk_text_get_run_attributes:
719 *@offset: the offset at which to get the attributes, -1 means the offset of
720 *the character to be inserted at the caret location.
721 *@start_offset: (out): the address to put the start offset of the range
722 *@end_offset: (out): the address to put the end offset of the range
724 *Creates an #AtkAttributeSet which consists of the attributes explicitly
725 *set at the position @offset in the text. @start_offset and @end_offset are
726 *set to the start and end of the range around @offset where the attributes are
727 *invariant. Note that @end_offset is the offset of the first character
728 *after the range. See the enum AtkTextAttribute for types of text
729 *attributes that can be returned. Note that other attributes may also be
732 *Returns: (transfer full): an #AtkAttributeSet which contains the attributes
733 * explicitly set at @offset. This #AtkAttributeSet should be freed by a call
734 * to atk_attribute_set_free().
737 atk_text_get_run_attributes (AtkText
*text
,
743 gint local_start_offset
, local_end_offset
;
744 gint
*real_start_offset
, *real_end_offset
;
746 g_return_val_if_fail (ATK_IS_TEXT (text
), NULL
);
749 real_start_offset
= start_offset
;
751 real_start_offset
= &local_start_offset
;
753 real_end_offset
= end_offset
;
755 real_end_offset
= &local_end_offset
;
760 iface
= ATK_TEXT_GET_IFACE (text
);
762 if (iface
->get_run_attributes
)
763 return (*(iface
->get_run_attributes
)) (text
, offset
, real_start_offset
, real_end_offset
);
769 * atk_text_get_default_attributes:
772 *Creates an #AtkAttributeSet which consists of the default values of
773 *attributes for the text. See the enum AtkTextAttribute for types of text
774 *attributes that can be returned. Note that other attributes may also be
777 *Returns: (transfer full): an #AtkAttributeSet which contains the default
778 * values of attributes. at @offset. this #atkattributeset should be freed by
779 * a call to atk_attribute_set_free().
782 atk_text_get_default_attributes (AtkText
*text
)
786 g_return_val_if_fail (ATK_IS_TEXT (text
), NULL
);
788 iface
= ATK_TEXT_GET_IFACE (text
);
790 if (iface
->get_default_attributes
)
791 return (*(iface
->get_default_attributes
)) (text
);
797 * atk_text_get_character_count:
800 * Gets the character count.
802 * Returns: the number of characters.
805 atk_text_get_character_count (AtkText
*text
)
809 g_return_val_if_fail (ATK_IS_TEXT (text
), -1);
811 iface
= ATK_TEXT_GET_IFACE (text
);
813 if (iface
->get_character_count
)
814 return (*(iface
->get_character_count
)) (text
);
820 * atk_text_get_offset_at_point:
822 * @x: screen x-position of character
823 * @y: screen y-position of character
824 * @coords: specify whether coordinates are relative to the screen or
827 * Gets the offset of the character located at coordinates @x and @y. @x and @y
828 * are interpreted as being relative to the screen or this widget's window
829 * depending on @coords.
831 * Returns: the offset to the character which is located at
832 * the specified @x and @y coordinates.
835 atk_text_get_offset_at_point (AtkText
*text
,
842 g_return_val_if_fail (ATK_IS_TEXT (text
), -1);
844 iface
= ATK_TEXT_GET_IFACE (text
);
846 if (iface
->get_offset_at_point
)
847 return (*(iface
->get_offset_at_point
)) (text
, x
, y
, coords
);
853 * atk_text_get_n_selections:
856 * Gets the number of selected regions.
858 * Returns: The number of selected regions, or -1 if a failure
862 atk_text_get_n_selections (AtkText
*text
)
866 g_return_val_if_fail (ATK_IS_TEXT (text
), -1);
868 iface
= ATK_TEXT_GET_IFACE (text
);
870 if (iface
->get_n_selections
)
871 return (*(iface
->get_n_selections
)) (text
);
877 * atk_text_get_selection:
879 * @selection_num: The selection number. The selected regions are
880 * assigned numbers that correspond to how far the region is from the
881 * start of the text. The selected region closest to the beginning
882 * of the text region is assigned the number 0, etc. Note that adding,
883 * moving or deleting a selected region can change the numbering.
884 * @start_offset: (out): passes back the start position of the selected region
885 * @end_offset: (out): passes back the end position of (e.g. offset immediately past)
886 * the selected region
888 * Gets the text from the specified selection.
890 * Returns: a newly allocated string containing the selected text. Use g_free()
891 * to free the returned string.
894 atk_text_get_selection (AtkText
*text
,
900 gint local_start_offset
, local_end_offset
;
901 gint
*real_start_offset
, *real_end_offset
;
903 g_return_val_if_fail (ATK_IS_TEXT (text
), NULL
);
906 real_start_offset
= start_offset
;
908 real_start_offset
= &local_start_offset
;
910 real_end_offset
= end_offset
;
912 real_end_offset
= &local_end_offset
;
914 iface
= ATK_TEXT_GET_IFACE (text
);
916 if (iface
->get_selection
)
918 return (*(iface
->get_selection
)) (text
, selection_num
,
919 real_start_offset
, real_end_offset
);
926 * atk_text_add_selection:
928 * @start_offset: the start position of the selected region
929 * @end_offset: the offset of the first character after the selected region.
931 * Adds a selection bounded by the specified offsets.
933 * Returns: %TRUE if success, %FALSE otherwise
936 atk_text_add_selection (AtkText
*text
,
942 g_return_val_if_fail (ATK_IS_TEXT (text
), FALSE
);
944 iface
= ATK_TEXT_GET_IFACE (text
);
946 if (iface
->add_selection
)
947 return (*(iface
->add_selection
)) (text
, start_offset
, end_offset
);
953 * atk_text_remove_selection:
955 * @selection_num: The selection number. The selected regions are
956 * assigned numbers that correspond to how far the region is from the
957 * start of the text. The selected region closest to the beginning
958 * of the text region is assigned the number 0, etc. Note that adding,
959 * moving or deleting a selected region can change the numbering.
961 * Removes the specified selection.
963 * Returns: %TRUE if success, %FALSE otherwise
966 atk_text_remove_selection (AtkText
*text
,
971 g_return_val_if_fail (ATK_IS_TEXT (text
), FALSE
);
973 iface
= ATK_TEXT_GET_IFACE (text
);
975 if (iface
->remove_selection
)
976 return (*(iface
->remove_selection
)) (text
, selection_num
);
982 * atk_text_set_selection:
984 * @selection_num: The selection number. The selected regions are
985 * assigned numbers that correspond to how far the region is from the
986 * start of the text. The selected region closest to the beginning
987 * of the text region is assigned the number 0, etc. Note that adding,
988 * moving or deleting a selected region can change the numbering.
989 * @start_offset: the new start position of the selection
990 * @end_offset: the new end position of (e.g. offset immediately past)
993 * Changes the start and end offset of the specified selection.
995 * Returns: %TRUE if success, %FALSE otherwise
998 atk_text_set_selection (AtkText
*text
,
1003 AtkTextIface
*iface
;
1005 g_return_val_if_fail (ATK_IS_TEXT (text
), FALSE
);
1007 iface
= ATK_TEXT_GET_IFACE (text
);
1009 if (iface
->set_selection
)
1011 return (*(iface
->set_selection
)) (text
, selection_num
,
1012 start_offset
, end_offset
);
1019 * atk_text_set_caret_offset:
1020 * @text: an #AtkText
1023 * Sets the caret (cursor) position to the specified @offset.
1025 * Returns: %TRUE if success, %FALSE otherwise.
1028 atk_text_set_caret_offset (AtkText
*text
,
1031 AtkTextIface
*iface
;
1033 g_return_val_if_fail (ATK_IS_TEXT (text
), FALSE
);
1035 iface
= ATK_TEXT_GET_IFACE (text
);
1037 if (iface
->set_caret_offset
)
1039 return (*(iface
->set_caret_offset
)) (text
, offset
);
1048 * atk_text_get_range_extents:
1049 * @text: an #AtkText
1050 * @start_offset: The offset of the first text character for which boundary
1051 * information is required.
1052 * @end_offset: The offset of the text character after the last character
1053 * for which boundary information is required.
1054 * @coord_type: Specify whether coordinates are relative to the screen or widget window.
1055 * @rect: A pointer to a AtkTextRectangle which is filled in by this function.
1057 * Get the bounding box for text within the specified range.
1062 atk_text_get_range_extents (AtkText
*text
,
1065 AtkCoordType coord_type
,
1066 AtkTextRectangle
*rect
)
1068 AtkTextIface
*iface
;
1070 g_return_if_fail (ATK_IS_TEXT (text
));
1071 g_return_if_fail (rect
);
1072 g_return_if_fail (start_offset
>= 0 && start_offset
< end_offset
);
1074 iface
= ATK_TEXT_GET_IFACE (text
);
1076 if (iface
->get_range_extents
)
1077 (*(iface
->get_range_extents
)) (text
, start_offset
, end_offset
, coord_type
, rect
);
1081 * atk_text_get_bounded_ranges:
1082 * @text: an #AtkText
1083 * @rect: An AtkTextRectangle giving the dimensions of the bounding box.
1084 * @coord_type: Specify whether coordinates are relative to the screen or widget window.
1085 * @x_clip_type: Specify the horizontal clip type.
1086 * @y_clip_type: Specify the vertical clip type.
1088 * Get the ranges of text in the specified bounding box.
1092 * Returns: (array zero-terminated=1): Array of AtkTextRange. The last
1093 * element of the array returned by this function will be NULL.
1096 atk_text_get_bounded_ranges (AtkText
*text
,
1097 AtkTextRectangle
*rect
,
1098 AtkCoordType coord_type
,
1099 AtkTextClipType x_clip_type
,
1100 AtkTextClipType y_clip_type
)
1102 AtkTextIface
*iface
;
1104 g_return_val_if_fail (ATK_IS_TEXT (text
), NULL
);
1105 g_return_val_if_fail (rect
, NULL
);
1107 iface
= ATK_TEXT_GET_IFACE (text
);
1109 if (iface
->get_bounded_ranges
)
1110 return (*(iface
->get_bounded_ranges
)) (text
, rect
, coord_type
, x_clip_type
, y_clip_type
);
1116 * atk_attribute_set_free:
1117 * @attrib_set: The #AtkAttributeSet to free
1119 * Frees the memory used by an #AtkAttributeSet, including all its
1123 atk_attribute_set_free (AtkAttributeSet
*attrib_set
)
1129 while (temp
!= NULL
)
1136 g_free (att
->value
);
1140 g_slist_free (attrib_set
);
1144 * atk_text_attribute_register:
1145 * @name: a name string
1147 * Associate @name with a new #AtkTextAttribute
1149 * Returns: an #AtkTextAttribute associated with @name
1152 atk_text_attribute_register (const gchar
*name
)
1154 g_return_val_if_fail (name
, ATK_TEXT_ATTR_INVALID
);
1156 if (!extra_attributes
)
1157 extra_attributes
= g_ptr_array_new ();
1159 g_ptr_array_add (extra_attributes
, g_strdup (name
));
1160 return extra_attributes
->len
+ ATK_TEXT_ATTR_LAST_DEFINED
;
1164 * atk_text_attribute_get_name:
1165 * @attr: The #AtkTextAttribute whose name is required
1167 * Gets the name corresponding to the #AtkTextAttribute
1169 * Returns: a string containing the name; this string should not be freed
1172 atk_text_attribute_get_name (AtkTextAttribute attr
)
1174 GTypeClass
*type_class
;
1176 const gchar
*name
= NULL
;
1178 type_class
= g_type_class_ref (ATK_TYPE_TEXT_ATTRIBUTE
);
1179 g_return_val_if_fail (G_IS_ENUM_CLASS (type_class
), NULL
);
1181 value
= g_enum_get_value (G_ENUM_CLASS (type_class
), attr
);
1185 name
= value
->value_nick
;
1189 if (extra_attributes
)
1193 n
-= ATK_TEXT_ATTR_LAST_DEFINED
+ 1;
1195 if (n
< extra_attributes
->len
)
1197 name
= g_ptr_array_index (extra_attributes
, n
);
1200 g_type_class_unref (type_class
);
1205 * atk_text_attribute_for_name:
1206 * @name: a string which is the (non-localized) name of an ATK text attribute.
1208 * Get the #AtkTextAttribute type corresponding to a text attribute name.
1210 * Returns: the #AtkTextAttribute enumerated type corresponding to the specified
1212 * or #ATK_TEXT_ATTRIBUTE_INVALID if no matching text attribute is found.
1215 atk_text_attribute_for_name (const gchar
*name
)
1217 GTypeClass
*type_class
;
1219 AtkTextAttribute type
= ATK_TEXT_ATTR_INVALID
;
1221 g_return_val_if_fail (name
, ATK_TEXT_ATTR_INVALID
);
1223 type_class
= g_type_class_ref (ATK_TYPE_TEXT_ATTRIBUTE
);
1224 g_return_val_if_fail (G_IS_ENUM_CLASS (type_class
), ATK_TEXT_ATTR_INVALID
);
1226 value
= g_enum_get_value_by_nick (G_ENUM_CLASS (type_class
), name
);
1230 type
= value
->value
;
1236 if (extra_attributes
)
1238 for (i
= 0; i
< extra_attributes
->len
; i
++)
1240 gchar
*extra_attribute
= (gchar
*)g_ptr_array_index (extra_attributes
, i
);
1242 g_return_val_if_fail (extra_attribute
, ATK_TEXT_ATTR_INVALID
);
1244 if (strcmp (name
, extra_attribute
) == 0)
1246 type
= i
+ 1 + ATK_TEXT_ATTR_LAST_DEFINED
;
1252 g_type_class_unref (type_class
);
1258 * atk_text_attribute_get_value:
1259 * @attr: The #AtkTextAttribute for which a value is required
1260 * @index_: The index of the required value
1262 * Gets the value for the index of the #AtkTextAttribute
1264 * Returns: a string containing the value; this string should not be freed;
1265 * NULL is returned if there are no values maintained for the attr value.
1268 atk_text_attribute_get_value (AtkTextAttribute attr
,
1273 case ATK_TEXT_ATTR_INVISIBLE
:
1274 case ATK_TEXT_ATTR_EDITABLE
:
1275 case ATK_TEXT_ATTR_BG_FULL_HEIGHT
:
1276 case ATK_TEXT_ATTR_STRIKETHROUGH
:
1277 case ATK_TEXT_ATTR_BG_STIPPLE
:
1278 case ATK_TEXT_ATTR_FG_STIPPLE
:
1279 g_assert (index
>= 0 && index
< G_N_ELEMENTS (boolean_offsets
));
1280 return boolean
+ boolean_offsets
[index
];
1281 case ATK_TEXT_ATTR_UNDERLINE
:
1282 g_assert (index
>= 0 && index
< G_N_ELEMENTS (underline_offsets
));
1283 return underline
+ underline_offsets
[index
];
1284 case ATK_TEXT_ATTR_WRAP_MODE
:
1285 g_assert (index
>= 0 && index
< G_N_ELEMENTS (wrap_mode_offsets
));
1286 return wrap_mode
+ wrap_mode_offsets
[index
];
1287 case ATK_TEXT_ATTR_DIRECTION
:
1288 g_assert (index
>= 0 && index
< G_N_ELEMENTS (direction_offsets
));
1289 return direction
+ direction_offsets
[index
];
1290 case ATK_TEXT_ATTR_JUSTIFICATION
:
1291 g_assert (index
>= 0 && index
< G_N_ELEMENTS (justification_offsets
));
1292 return justification
+ justification_offsets
[index
];
1293 case ATK_TEXT_ATTR_STRETCH
:
1294 g_assert (index
>= 0 && index
< G_N_ELEMENTS (stretch_offsets
));
1295 return stretch
+ stretch_offsets
[index
];
1296 case ATK_TEXT_ATTR_VARIANT
:
1297 g_assert (index
>= 0 && index
< G_N_ELEMENTS (variant_offsets
));
1298 return variant
+ variant_offsets
[index
];
1299 case ATK_TEXT_ATTR_STYLE
:
1300 g_assert (index
>= 0 && index
< G_N_ELEMENTS (style_offsets
));
1301 return style
+ style_offsets
[index
];
1308 atk_text_rectangle_union (AtkTextRectangle
*src1
,
1309 AtkTextRectangle
*src2
,
1310 AtkTextRectangle
*dest
)
1312 gint dest_x
, dest_y
;
1314 dest_x
= MIN (src1
->x
, src2
->x
);
1315 dest_y
= MIN (src1
->y
, src2
->y
);
1316 dest
->width
= MAX (src1
->x
+ src1
->width
, src2
->x
+ src2
->width
) - dest_x
;
1317 dest
->height
= MAX (src1
->y
+ src1
->height
, src2
->y
+ src2
->height
) - dest_y
;
1323 atk_text_rectangle_contain (AtkTextRectangle
*clip
,
1324 AtkTextRectangle
*bounds
,
1325 AtkTextClipType x_clip_type
,
1326 AtkTextClipType y_clip_type
)
1328 gboolean x_min_ok
, x_max_ok
, y_min_ok
, y_max_ok
;
1330 x_min_ok
= (bounds
->x
>= clip
->x
) ||
1331 ((bounds
->x
+ bounds
->width
>= clip
->x
) &&
1332 ((x_clip_type
== ATK_TEXT_CLIP_NONE
) ||
1333 (x_clip_type
== ATK_TEXT_CLIP_MAX
)));
1335 x_max_ok
= (bounds
->x
+ bounds
->width
<= clip
->x
+ clip
->width
) ||
1336 ((bounds
->x
<= clip
->x
+ clip
->width
) &&
1337 ((x_clip_type
== ATK_TEXT_CLIP_NONE
) ||
1338 (x_clip_type
== ATK_TEXT_CLIP_MIN
)));
1340 y_min_ok
= (bounds
->y
>= clip
->y
) ||
1341 ((bounds
->y
+ bounds
->height
>= clip
->y
) &&
1342 ((y_clip_type
== ATK_TEXT_CLIP_NONE
) ||
1343 (y_clip_type
== ATK_TEXT_CLIP_MAX
)));
1345 y_max_ok
= (bounds
->y
+ bounds
->height
<= clip
->y
+ clip
->height
) ||
1346 ((bounds
->y
<= clip
->y
+ clip
->height
) &&
1347 ((y_clip_type
== ATK_TEXT_CLIP_NONE
) ||
1348 (y_clip_type
== ATK_TEXT_CLIP_MIN
)));
1350 return (x_min_ok
&& x_max_ok
&& y_min_ok
&& y_max_ok
);
1355 atk_text_real_get_range_extents (AtkText
*text
,
1358 AtkCoordType coord_type
,
1359 AtkTextRectangle
*rect
)
1362 AtkTextRectangle cbounds
, bounds
;
1364 atk_text_get_character_extents (text
, start_offset
,
1365 &bounds
.x
, &bounds
.y
,
1366 &bounds
.width
, &bounds
.height
,
1369 for (i
= start_offset
+ 1; i
< end_offset
; i
++)
1371 atk_text_get_character_extents (text
, i
,
1372 &cbounds
.x
, &cbounds
.y
,
1373 &cbounds
.width
, &cbounds
.height
,
1375 atk_text_rectangle_union (&bounds
, &cbounds
, &bounds
);
1380 rect
->width
= bounds
.width
;
1381 rect
->height
= bounds
.height
;
1384 static AtkTextRange
**
1385 atk_text_real_get_bounded_ranges (AtkText
*text
,
1386 AtkTextRectangle
*rect
,
1387 AtkCoordType coord_type
,
1388 AtkTextClipType x_clip_type
,
1389 AtkTextClipType y_clip_type
)
1391 gint bounds_min_offset
, bounds_max_offset
;
1392 gint min_line_start
, min_line_end
;
1393 gint max_line_start
, max_line_end
;
1397 gint num_ranges
= 0;
1398 gint range_size
= 1;
1399 AtkTextRectangle cbounds
;
1400 AtkTextRange
**range
;
1403 bounds_min_offset
= atk_text_get_offset_at_point (text
, rect
->x
, rect
->y
, coord_type
);
1404 bounds_max_offset
= atk_text_get_offset_at_point (text
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
, coord_type
);
1406 if (bounds_min_offset
== 0 &&
1407 bounds_min_offset
== bounds_max_offset
)
1410 line
= atk_text_get_text_at_offset (text
, bounds_min_offset
,
1411 ATK_TEXT_BOUNDARY_LINE_START
,
1412 &min_line_start
, &min_line_end
);
1414 line
= atk_text_get_text_at_offset (text
, bounds_max_offset
,
1415 ATK_TEXT_BOUNDARY_LINE_START
,
1416 &max_line_start
, &max_line_end
);
1418 bounds_min_offset
= MIN (min_line_start
, max_line_start
);
1419 bounds_max_offset
= MAX (min_line_end
, max_line_end
);
1421 curr_offset
= bounds_min_offset
;
1422 while (curr_offset
< bounds_max_offset
)
1424 offset
= curr_offset
;
1426 while (curr_offset
< bounds_max_offset
)
1428 atk_text_get_character_extents (text
, curr_offset
,
1429 &cbounds
.x
, &cbounds
.y
,
1430 &cbounds
.width
, &cbounds
.height
,
1432 if (!atk_text_rectangle_contain (rect
, &cbounds
, x_clip_type
, y_clip_type
))
1436 if (curr_offset
> offset
)
1438 AtkTextRange
*one_range
= g_new (AtkTextRange
, 1);
1440 one_range
->start_offset
= offset
;
1441 one_range
->end_offset
= curr_offset
;
1442 one_range
->content
= atk_text_get_text (text
, offset
, curr_offset
);
1443 atk_text_get_range_extents (text
, offset
, curr_offset
, coord_type
, &one_range
->bounds
);
1445 if (num_ranges
>= range_size
- 1)
1448 range
= g_realloc (range
, range_size
* sizeof (gpointer
));
1450 range
[num_ranges
] = one_range
;
1455 range
[num_ranges
] = NULL
;
1461 * atk_text_free_ranges:
1462 * @ranges: (array): A pointer to an array of #AtkTextRange which is
1465 * Frees the memory associated with an array of AtkTextRange. It is assumed
1466 * that the array was returned by the function atk_text_get_bounded_ranges
1467 * and is NULL terminated.
1472 atk_text_free_ranges (AtkTextRange
**ranges
)
1474 AtkTextRange
**first
= ranges
;
1480 AtkTextRange
*range
;
1484 g_free (range
->content
);
1491 static AtkTextRange
*
1492 atk_text_range_copy (AtkTextRange
*src
)
1494 AtkTextRange
*dst
= g_new0 (AtkTextRange
, 1);
1495 dst
->bounds
= src
->bounds
;
1496 dst
->start_offset
= src
->start_offset
;
1497 dst
->end_offset
= src
->end_offset
;
1499 dst
->content
= g_strdup (src
->content
);
1504 atk_text_range_free (AtkTextRange
*range
)
1506 g_free (range
->content
);
1510 G_DEFINE_BOXED_TYPE (AtkTextRange
, atk_text_range
, atk_text_range_copy
,
1511 atk_text_range_free
)