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[] =
93 static const guint8 wrap_mode_offsets[] = {
97 static const char underline[] =
102 static const guint8 underline_offsets[] = {
106 static void atk_text_base_init (AtkTextIface *class);
108 static void atk_text_real_get_range_extents (AtkText *text,
111 AtkCoordType coord_type,
112 AtkTextRectangle *rect);
114 static AtkTextRange** atk_text_real_get_bounded_ranges (AtkText *text,
115 AtkTextRectangle *rect,
116 AtkCoordType coord_type,
117 AtkTextClipType x_clip_type,
118 AtkTextClipType y_clip_type);
120 static guint atk_text_signals[LAST_SIGNAL] = { 0 };
123 atk_text_get_type (void)
125 static GType type = 0;
129 static const GTypeInfo tinfo =
131 sizeof (AtkTextIface),
132 (GBaseInitFunc) atk_text_base_init,
133 (GBaseFinalizeFunc) NULL,
134 (GClassInitFunc) NULL /* atk_text_interface_init */ ,
135 (GClassFinalizeFunc) NULL,
139 type = g_type_register_static (G_TYPE_INTERFACE, "AtkText", &tinfo, 0);
146 atk_text_base_init (AtkTextIface *class)
148 static gboolean initialized = FALSE;
153 * Note that text_changed signal supports details "insert", "delete",
154 * possibly "replace".
157 class->get_range_extents = atk_text_real_get_range_extents;
158 class->get_bounded_ranges = atk_text_real_get_bounded_ranges;
160 atk_text_signals[TEXT_CHANGED] =
161 g_signal_new ("text_changed",
163 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
164 G_STRUCT_OFFSET (AtkTextIface, text_changed),
165 (GSignalAccumulator) NULL, NULL,
166 atk_marshal_VOID__INT_INT,
168 2, G_TYPE_INT, G_TYPE_INT);
170 atk_text_signals[TEXT_CARET_MOVED] =
171 g_signal_new ("text_caret_moved",
174 G_STRUCT_OFFSET (AtkTextIface, text_caret_moved),
175 (GSignalAccumulator) NULL, NULL,
176 g_cclosure_marshal_VOID__INT,
179 atk_text_signals[TEXT_SELECTION_CHANGED] =
180 g_signal_new ("text_selection_changed",
183 G_STRUCT_OFFSET (AtkTextIface, text_selection_changed),
184 (GSignalAccumulator) NULL, NULL,
185 g_cclosure_marshal_VOID__VOID,
187 atk_text_signals[TEXT_ATTRIBUTES_CHANGED] =
188 g_signal_new ("text_attributes_changed",
191 G_STRUCT_OFFSET (AtkTextIface, text_attributes_changed),
192 (GSignalAccumulator) NULL, NULL,
193 g_cclosure_marshal_VOID__VOID,
204 * @start_offset: start position
205 * @end_offset: end position
207 * Gets the specified text.
209 * Returns: the text from @start_offset up to, but not including @end_offset.
212 atk_text_get_text (AtkText *text,
218 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
220 iface = ATK_TEXT_GET_IFACE (text);
222 if (start_offset < 0 || end_offset < -1)
226 return (*(iface->get_text)) (text, start_offset, end_offset);
232 * atk_text_get_character_at_offset:
236 * Gets the specified text.
238 * Returns: the character at @offset.
241 atk_text_get_character_at_offset (AtkText *text,
246 g_return_val_if_fail (ATK_IS_TEXT (text), (gunichar) 0);
248 iface = ATK_TEXT_GET_IFACE (text);
250 if (iface->get_character_at_offset)
251 return (*(iface->get_character_at_offset)) (text, offset);
257 * atk_text_get_text_after_offset:
260 * @boundary_type: An #AtkTextBoundary
261 * @start_offset: the start offset of the returned string
262 * @end_offset: the offset of the first character after the
265 * Gets the specified text.
267 * If the boundary_type if ATK_TEXT_BOUNDARY_CHAR the character after the
268 * offset is returned.
270 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START the returned string
271 * is from the word start after the offset to the next word start.
273 * The returned string will contain the word after the offset if the offset
274 * is inside a word or if the offset is not inside a word.
276 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_END the returned string
277 * is from the word end at or after the offset to the next work end.
279 * The returned string will contain the word after the offset if the offset
280 * is inside a word and will contain the word after the word after the offset
281 * if the offset is not inside a word.
283 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the returned
284 * string is from the sentence start after the offset to the next sentence
287 * The returned string will contain the sentence after the offset if the offset
288 * is inside a sentence or if the offset is not inside a sentence.
290 * If the boundary_type is ATK_TEXT_BOUNDARY_SENTENCE_END the returned string
291 * is from the sentence end at or after the offset to the next sentence end.
293 * The returned string will contain the sentence after the offset if the offset
294 * is inside a sentence and will contain the sentence after the sentence
295 * after the offset if the offset is not inside a sentence.
297 * If the boundary type is ATK_TEXT_BOUNDARY_LINE_START the returned
298 * string is from the line start after the offset to the next line start.
300 * If the boundary_type is ATK_TEXT_BOUNDARY_LINE_END the returned string
301 * is from the line end at or after the offset to the next line start.
303 * Returns: the text after @offset bounded by the specified @boundary_type.
306 atk_text_get_text_after_offset (AtkText *text,
308 AtkTextBoundary boundary_type,
313 gint local_start_offset, local_end_offset;
314 gint *real_start_offset, *real_end_offset;
316 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
319 real_start_offset = start_offset;
321 real_start_offset = &local_start_offset;
323 real_end_offset = end_offset;
325 real_end_offset = &local_end_offset;
330 iface = ATK_TEXT_GET_IFACE (text);
332 if (iface->get_text_after_offset)
333 return (*(iface->get_text_after_offset)) (text, offset, boundary_type, real_start_offset, real_end_offset);
339 * atk_text_get_text_at_offset:
342 * @boundary_type: An #AtkTextBoundary
343 * @start_offset: the start offset of the returned string
344 * @end_offset: the offset of the first character after the
347 * Gets the specified text.
349 * If the boundary_type if ATK_TEXT_BOUNDARY_CHAR the character at the
350 * offset is returned.
352 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START the returned string
353 * is from the word start at or before the offset to the word start after
356 * The returned string will contain the word at the offset if the offset
357 * is inside a word and will contain the word before the offset if the
358 * offset is not inside a word.
360 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_END the returned string
361 * is from the word end before the offset to the word end at or after the
364 * The returned string will contain the word at the offset if the offset
365 * is inside a word and will contain the word after to the offset if the
366 * offset is not inside a word.
368 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the returned
369 * string is from the sentence start at or before the offset to the sentence
370 * start after the offset.
372 * The returned string will contain the sentence at the offset if the offset
373 * is inside a sentence and will contain the sentence before the offset
374 * if the offset is not inside a sentence.
376 * If the boundary_type is ATK_TEXT_BOUNDARY_SENTENCE_END the returned string
377 * is from the sentence end before the offset to the sentence end at or
380 * The returned string will contain the sentence at the offset if the offset
381 * is inside a sentence and will contain the sentence after the offset
382 * if the offset is not inside a sentence.
384 * If the boundary type is ATK_TEXT_BOUNDARY_LINE_START the returned
385 * string is from the line start at or before the offset to the line
386 * start after the offset.
388 * If the boundary_type is ATK_TEXT_BOUNDARY_LINE_END the returned string
389 * is from the line end before the offset to the line end at or after
392 * Returns: the text at @offset bounded by the specified @boundary_type.
395 atk_text_get_text_at_offset (AtkText *text,
397 AtkTextBoundary boundary_type,
402 gint local_start_offset, local_end_offset;
403 gint *real_start_offset, *real_end_offset;
405 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
408 real_start_offset = start_offset;
410 real_start_offset = &local_start_offset;
412 real_end_offset = end_offset;
414 real_end_offset = &local_end_offset;
416 iface = ATK_TEXT_GET_IFACE (text);
418 if (iface->get_text_at_offset)
419 return (*(iface->get_text_at_offset)) (text, offset, boundary_type, real_start_offset, real_end_offset);
425 * atk_text_get_text_before_offset:
428 * @boundary_type: An #AtkTextBoundary
429 * @start_offset: the start offset of the returned string
430 * @end_offset: the offset of the first character after the
433 * Gets the specified text.
435 * If the boundary_type if ATK_TEXT_BOUNDARY_CHAR the character before the
436 * offset is returned.
438 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START the returned string
439 * is from the word start before the word start before the offset to
440 * the word start before the offset.
442 * The returned string will contain the word before the offset if the offset
443 * is inside a word and will contain the word before the word before the
444 * offset if the offset is not inside a word.
446 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_END the returned string
447 * is from the word end before the word end at or before the offset to the
448 * word end at or before the offset.
450 * The returned string will contain the word before the offset if the offset
451 * is inside a word or if the offset is not inside a word.
453 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the returned
454 * string is from the sentence start before the sentence start before
455 * the offset to the sentence start before the offset.
457 * The returned string will contain the sentence before the offset if the
458 * offset is inside a sentence and will contain the sentence before the
459 * sentence before the offset if the offset is not inside a sentence.
461 * If the boundary_type is ATK_TEXT_BOUNDARY_SENTENCE_END the returned string
462 * is from the sentence end before the sentence end at or before the offset to
463 * the sentence end at or before the offset.
465 * The returned string will contain the sentence before the offset if the
466 * offset is inside a sentence or if the offset is not inside a sentence.
468 * If the boundary type is ATK_TEXT_BOUNDARY_LINE_START the returned
469 * string is from the line start before the line start ar or before the offset
470 * to the line start ar or before the offset.
472 * If the boundary_type is ATK_TEXT_BOUNDARY_LINE_END the returned string
473 * is from the line end before the line end before the offset to the
474 * line end before the offset.
476 * Returns: the text before @offset bounded by the specified @boundary_type.
479 atk_text_get_text_before_offset (AtkText *text,
481 AtkTextBoundary boundary_type,
486 gint local_start_offset, local_end_offset;
487 gint *real_start_offset, *real_end_offset;
489 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
492 real_start_offset = start_offset;
494 real_start_offset = &local_start_offset;
496 real_end_offset = end_offset;
498 real_end_offset = &local_end_offset;
503 iface = ATK_TEXT_GET_IFACE (text);
505 if (iface->get_text_before_offset)
506 return (*(iface->get_text_before_offset)) (text, offset, boundary_type, real_start_offset, real_end_offset);
512 * atk_text_get_caret_offset:
515 * Gets the offset position of the caret (cursor).
517 * Returns: the offset position of the caret (cursor).
520 atk_text_get_caret_offset (AtkText *text)
524 g_return_val_if_fail (ATK_IS_TEXT (text), 0);
526 iface = ATK_TEXT_GET_IFACE (text);
528 if (iface->get_caret_offset)
529 return (*(iface->get_caret_offset)) (text);
535 * atk_text_get_character_extents:
537 * @offset: The offset of the text character for which bounding information is required.
538 * @x: Pointer for the x cordinate of the bounding box
539 * @y: Pointer for the y cordinate of the bounding box
540 * @width: Pointer for the width of the bounding box
541 * @height: Pointer for the height of the bounding box
542 * @coords: specify whether coordinates are relative to the screen or widget window
544 * Get the bounding box containing the glyph representing the character at
545 * a particular text offset.
548 atk_text_get_character_extents (AtkText *text,
557 gint local_x, local_y, local_width, local_height;
558 gint *real_x, *real_y, *real_width, *real_height;
560 g_return_if_fail (ATK_IS_TEXT (text));
573 real_width = &local_width;
575 real_height = height;
577 real_height = &local_height;
587 iface = ATK_TEXT_GET_IFACE (text);
589 if (iface->get_character_extents)
590 (*(iface->get_character_extents)) (text, offset, real_x, real_y, real_width, real_height, coords);
594 *real_x = *real_x + *real_width;
600 *atk_text_get_run_attributes:
602 *@offset: the offset at which to get the attributes
603 *@start_offset: the address to put the start offset of the range
604 *@end_offset: the address to put the end offset of the range
606 *Creates an #AtkAttributeSet which consists of the attributes explicitly
607 *set at the position @offset in the text. @start_offset and @end_offset are
608 *set to the start and end of the range around @offset where the attributes are
609 *invariant. Note that @end_offset is the offset of the first character
610 *after the range. See the enum AtkTextAttribute for types of text
611 *attributes that can be returned. Note that other attributes may also be
614 *Returns: an #AtkAttributeSet which contains the attributes explicitly set
615 *at @offset. This #AtkAttributeSet should be freed by a call to
616 *atk_attribute_set_free().
619 atk_text_get_run_attributes (AtkText *text,
625 gint local_start_offset, local_end_offset;
626 gint *real_start_offset, *real_end_offset;
628 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
631 real_start_offset = start_offset;
633 real_start_offset = &local_start_offset;
635 real_end_offset = end_offset;
637 real_end_offset = &local_end_offset;
642 iface = ATK_TEXT_GET_IFACE (text);
644 if (iface->get_run_attributes)
645 return (*(iface->get_run_attributes)) (text, offset, real_start_offset, real_end_offset);
651 *atk_text_get_default_attributes:
654 *Creates an #AtkAttributeSet which consists of the default values of
655 *attributes for the text. See the enum AtkTextAttribute for types of text
656 *attributes that can be returned. Note that other attributes may also be
659 *Returns: an #AtkAttributeSet which contains the default values of attributes.
660 *at @offset. This #AtkAttributeSet should be freed by a call to
661 *atk_attribute_set_free().
664 atk_text_get_default_attributes (AtkText *text)
668 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
670 iface = ATK_TEXT_GET_IFACE (text);
672 if (iface->get_default_attributes)
673 return (*(iface->get_default_attributes)) (text);
679 * atk_text_get_character_count:
682 * Gets the character count.
684 * Returns: the number of characters.
687 atk_text_get_character_count (AtkText *text)
691 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
693 iface = ATK_TEXT_GET_IFACE (text);
695 if (iface->get_character_count)
696 return (*(iface->get_character_count)) (text);
702 * atk_text_get_offset_at_point:
704 * @x: screen x-position of character
705 * @y: screen y-position of character
706 * @coords: specify whether coordinates are relative to the screen or
709 * Gets the offset of the character located at coordinates @x and @y. @x and @y
710 * are interpreted as being relative to the screen or this widget's window
711 * depending on @coords.
713 * Returns: the offset to the character which is located at
714 * the specified @x and @y coordinates.
717 atk_text_get_offset_at_point (AtkText *text,
724 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
726 iface = ATK_TEXT_GET_IFACE (text);
728 if (iface->get_offset_at_point)
729 return (*(iface->get_offset_at_point)) (text, x, y, coords);
735 * atk_text_get_n_selections:
738 * Gets the number of selected regions.
740 * Returns: The number of selected regions, or -1 if a failure
744 atk_text_get_n_selections (AtkText *text)
748 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
750 iface = ATK_TEXT_GET_IFACE (text);
752 if (iface->get_n_selections)
753 return (*(iface->get_n_selections)) (text);
759 * atk_text_get_selection:
761 * @selection_num: The selection number. The selected regions are
762 * assigned numbers that correspond to how far the region is from the
763 * start of the text. The selected region closest to the beginning
764 * of the text region is assigned the number 0, etc. Note that adding,
765 * moving or deleting a selected region can change the numbering.
766 * @start_offset: passes back the start position of the selected region
767 * @end_offset: passes back the end position of (e.g. offset immediately past)
768 * the selected region
770 * Gets the text from the specified selection.
772 * Returns: the selected text.
775 atk_text_get_selection (AtkText *text,
781 gint local_start_offset, local_end_offset;
782 gint *real_start_offset, *real_end_offset;
784 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
787 real_start_offset = start_offset;
789 real_start_offset = &local_start_offset;
791 real_end_offset = end_offset;
793 real_end_offset = &local_end_offset;
795 iface = ATK_TEXT_GET_IFACE (text);
797 if (iface->get_selection)
799 return (*(iface->get_selection)) (text, selection_num,
800 real_start_offset, real_end_offset);
807 * atk_text_add_selection:
809 * @start_offset: the start position of the selected region
810 * @end_offset: the offset of the first character after the selected region.
812 * Adds a selection bounded by the specified offsets.
814 * Returns: %TRUE if success, %FALSE otherwise
817 atk_text_add_selection (AtkText *text,
823 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
825 iface = ATK_TEXT_GET_IFACE (text);
827 if (iface->add_selection)
828 return (*(iface->add_selection)) (text, start_offset, end_offset);
834 * atk_text_remove_selection:
836 * @selection_num: The selection number. The selected regions are
837 * assigned numbers that correspond to how far the region is from the
838 * start of the text. The selected region closest to the beginning
839 * of the text region is assigned the number 0, etc. Note that adding,
840 * moving or deleting a selected region can change the numbering.
842 * Removes the specified selection.
844 * Returns: %TRUE if success, %FALSE otherwise
847 atk_text_remove_selection (AtkText *text,
852 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
854 iface = ATK_TEXT_GET_IFACE (text);
856 if (iface->remove_selection)
857 return (*(iface->remove_selection)) (text, selection_num);
863 * atk_text_set_selection:
865 * @selection_num: The selection number. The selected regions are
866 * assigned numbers that correspond to how far the region is from the
867 * start of the text. The selected region closest to the beginning
868 * of the text region is assigned the number 0, etc. Note that adding,
869 * moving or deleting a selected region can change the numbering.
870 * @start_offset: the new start position of the selection
871 * @end_offset: the new end position of (e.g. offset immediately past)
874 * Changes the start and end offset of the specified selection.
876 * Returns: %TRUE if success, %FALSE otherwise
879 atk_text_set_selection (AtkText *text,
886 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
888 iface = ATK_TEXT_GET_IFACE (text);
890 if (iface->set_selection)
892 return (*(iface->set_selection)) (text, selection_num,
893 start_offset, end_offset);
900 * atk_text_set_caret_offset:
904 * Sets the caret (cursor) position to the specified @offset.
906 * Returns: %TRUE if success, %FALSE otherwise.
909 atk_text_set_caret_offset (AtkText *text,
914 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
916 iface = ATK_TEXT_GET_IFACE (text);
918 if (iface->set_caret_offset)
920 return (*(iface->set_caret_offset)) (text, offset);
929 * atk_text_get_range_extents:
931 * @start_offset: The offset of the first text character for which boundary
932 * information is required.
933 * @end_offset: The offset of the text character after the last character
934 * for which boundary information is required.
935 * @coord_type: Specify whether coordinates are relative to the screen or widget window.
936 * @rect: A pointer to a AtkTextRectangle which is filled in by this function.
938 * Get the bounding box for text within the specified range.
943 atk_text_get_range_extents (AtkText *text,
946 AtkCoordType coord_type,
947 AtkTextRectangle *rect)
951 g_return_if_fail (ATK_IS_TEXT (text));
952 g_return_if_fail (rect);
954 if (start_offset < 0 || start_offset >= end_offset)
957 iface = ATK_TEXT_GET_IFACE (text);
959 if (iface->get_range_extents)
960 (*(iface->get_range_extents)) (text, start_offset, end_offset, coord_type, rect);
964 * atk_text_get_bounded_ranges:
966 * @rect: An AtkTextRectagle giving the dimensions of the bounding box.
967 * @coord_type: Specify whether coordinates are relative to the screen or widget window.
968 * @x_clip_type: Specify the horizontal clip type.
969 * @y_clip_type: Specify the vertical clip type.
971 * Get the ranges of text in the specified bounding box.
975 * Returns: Array of AtkTextRange. The last element of the array returned
976 * by this function will be NULL.
979 atk_text_get_bounded_ranges (AtkText *text,
980 AtkTextRectangle *rect,
981 AtkCoordType coord_type,
982 AtkTextClipType x_clip_type,
983 AtkTextClipType y_clip_type)
987 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
988 g_return_val_if_fail (rect, NULL);
990 iface = ATK_TEXT_GET_IFACE (text);
992 if (iface->get_bounded_ranges)
993 return (*(iface->get_bounded_ranges)) (text, rect, coord_type, x_clip_type, y_clip_type);
999 * atk_attribute_set_free:
1000 * @attrib_set: The #AtkAttributeSet to free
1002 * Frees the memory used by an #AtkAttributeSet, including all its
1006 atk_attribute_set_free (AtkAttributeSet *attrib_set)
1012 while (temp != NULL)
1019 g_free (att->value);
1023 g_slist_free (attrib_set);
1027 * atk_text_attribute_register:
1028 * @name: a name string
1030 * Associate @name with a new #AtkTextAttribute
1032 * Returns: an #AtkTextAttribute associated with @name
1035 atk_text_attribute_register (const gchar *name)
1037 g_return_val_if_fail (name, ATK_TEXT_ATTR_INVALID);
1039 if (!extra_attributes)
1040 extra_attributes = g_ptr_array_new ();
1042 g_ptr_array_add (extra_attributes, g_strdup (name));
1043 return extra_attributes->len + ATK_TEXT_ATTR_LAST_DEFINED;
1047 * atk_text_attribute_get_name:
1048 * @attr: The #AtkTextAttribute whose name is required
1050 * Gets the name corresponding to the #AtkTextAttribute
1052 * Returns: a string containing the name; this string should not be freed
1054 G_CONST_RETURN gchar*
1055 atk_text_attribute_get_name (AtkTextAttribute attr)
1057 GTypeClass *type_class;
1059 const gchar *name = NULL;
1061 type_class = g_type_class_ref (ATK_TYPE_TEXT_ATTRIBUTE);
1062 g_return_val_if_fail (G_IS_ENUM_CLASS (type_class), NULL);
1064 value = g_enum_get_value (G_ENUM_CLASS (type_class), attr);
1068 name = value->value_nick;
1072 if (extra_attributes)
1076 n -= ATK_TEXT_ATTR_LAST_DEFINED + 1;
1078 if (n < extra_attributes->len)
1080 name = g_ptr_array_index (extra_attributes, n);
1083 g_type_class_unref (type_class);
1088 * atk_text_attribute_for_name:
1089 * @name: a string which is the (non-localized) name of an ATK text attribute.
1091 * Get the #AtkTextAttribute type corresponding to a text attribute name.
1093 * Returns: the #AtkTextAttribute enumerated type corresponding to the specified
1095 * or #ATK_TEXT_ATTRIBUTE_INVALID if no matching text attribute is found.
1098 atk_text_attribute_for_name (const gchar *name)
1100 GTypeClass *type_class;
1102 AtkTextAttribute type = ATK_TEXT_ATTR_INVALID;
1104 g_return_val_if_fail (name, ATK_TEXT_ATTR_INVALID);
1106 type_class = g_type_class_ref (ATK_TYPE_TEXT_ATTRIBUTE);
1107 g_return_val_if_fail (G_IS_ENUM_CLASS (type_class), ATK_TEXT_ATTR_INVALID);
1109 value = g_enum_get_value_by_nick (G_ENUM_CLASS (type_class), name);
1113 type = value->value;
1119 if (extra_attributes)
1121 for (i = 0; i < extra_attributes->len; i++)
1123 gchar *extra_attribute = (gchar *)g_ptr_array_index (extra_attributes, i);
1125 g_return_val_if_fail (extra_attribute, ATK_TEXT_ATTR_INVALID);
1127 if (strcmp (name, extra_attribute) == 0)
1129 type = i + 1 + ATK_TEXT_ATTR_LAST_DEFINED;
1135 g_type_class_unref (type_class);
1141 * atk_text_attribute_get_value:
1142 * @attr: The #AtkTextAttribute for which a value is required
1143 * @index_: The index of the required value
1145 * Gets the value for the index of the #AtkTextAttribute
1147 * Returns: a string containing the value; this string should not be freed;
1148 * NULL is returned if there are no values maintained for the attr value.
1150 G_CONST_RETURN gchar*
1151 atk_text_attribute_get_value (AtkTextAttribute attr,
1156 case ATK_TEXT_ATTR_INVISIBLE:
1157 case ATK_TEXT_ATTR_EDITABLE:
1158 case ATK_TEXT_ATTR_BG_FULL_HEIGHT:
1159 case ATK_TEXT_ATTR_STRIKETHROUGH:
1160 case ATK_TEXT_ATTR_BG_STIPPLE:
1161 case ATK_TEXT_ATTR_FG_STIPPLE:
1162 g_assert (index >= 0 && index < G_N_ELEMENTS (boolean_offsets));
1163 return boolean + boolean_offsets[index];
1164 case ATK_TEXT_ATTR_UNDERLINE:
1165 g_assert (index >= 0 && index < G_N_ELEMENTS (underline_offsets));
1166 return underline + underline_offsets[index];
1167 case ATK_TEXT_ATTR_WRAP_MODE:
1168 g_assert (index >= 0 && index < G_N_ELEMENTS (wrap_mode_offsets));
1169 return wrap_mode + wrap_mode_offsets[index];
1170 case ATK_TEXT_ATTR_DIRECTION:
1171 g_assert (index >= 0 && index < G_N_ELEMENTS (direction_offsets));
1172 return direction + direction_offsets[index];
1173 case ATK_TEXT_ATTR_JUSTIFICATION:
1174 g_assert (index >= 0 && index < G_N_ELEMENTS (justification_offsets));
1175 return justification + justification_offsets[index];
1176 case ATK_TEXT_ATTR_STRETCH:
1177 g_assert (index >= 0 && index < G_N_ELEMENTS (stretch_offsets));
1178 return stretch + stretch_offsets[index];
1179 case ATK_TEXT_ATTR_VARIANT:
1180 g_assert (index >= 0 && index < G_N_ELEMENTS (variant_offsets));
1181 return variant + variant_offsets[index];
1182 case ATK_TEXT_ATTR_STYLE:
1183 g_assert (index >= 0 && index < G_N_ELEMENTS (style_offsets));
1184 return style + style_offsets[index];
1191 atk_text_rectangle_union (AtkTextRectangle *src1,
1192 AtkTextRectangle *src2,
1193 AtkTextRectangle *dest)
1195 gint dest_x, dest_y;
1197 dest_x = MIN (src1->x, src2->x);
1198 dest_y = MIN (src1->y, src2->y);
1199 dest->width = MAX (src1->x + src1->width, src2->x + src2->width) - dest_x;
1200 dest->height = MAX (src1->y + src1->height, src2->y + src2->height) - dest_y;
1206 atk_text_rectangle_contain (AtkTextRectangle *clip,
1207 AtkTextRectangle *bounds,
1208 AtkTextClipType x_clip_type,
1209 AtkTextClipType y_clip_type)
1211 gboolean x_min_ok, x_max_ok, y_min_ok, y_max_ok;
1213 x_min_ok = (bounds->x >= clip->x) ||
1214 ((bounds->x + bounds->width >= clip->x) &&
1215 ((x_clip_type == ATK_TEXT_CLIP_NONE) ||
1216 (x_clip_type == ATK_TEXT_CLIP_MAX)));
1218 x_max_ok = (bounds->x + bounds->width <= clip->x + clip->width) ||
1219 ((bounds->x <= clip->x + clip->width) &&
1220 ((x_clip_type == ATK_TEXT_CLIP_NONE) ||
1221 (x_clip_type == ATK_TEXT_CLIP_MIN)));
1223 y_min_ok = (bounds->y >= clip->y) ||
1224 ((bounds->y + bounds->height >= clip->y) &&
1225 ((y_clip_type == ATK_TEXT_CLIP_NONE) ||
1226 (y_clip_type == ATK_TEXT_CLIP_MAX)));
1228 y_max_ok = (bounds->y + bounds->height <= clip->y + clip->height) ||
1229 ((bounds->y <= clip->y + clip->height) &&
1230 ((y_clip_type == ATK_TEXT_CLIP_NONE) ||
1231 (y_clip_type == ATK_TEXT_CLIP_MIN)));
1233 return (x_min_ok && x_max_ok && y_min_ok && y_max_ok);
1238 atk_text_real_get_range_extents (AtkText *text,
1241 AtkCoordType coord_type,
1242 AtkTextRectangle *rect)
1245 AtkTextRectangle cbounds, bounds;
1247 atk_text_get_character_extents (text, start_offset,
1248 &bounds.x, &bounds.y,
1249 &bounds.width, &bounds.height,
1252 for (i = start_offset + 1; i < end_offset; i++)
1254 atk_text_get_character_extents (text, i,
1255 &cbounds.x, &cbounds.y,
1256 &cbounds.width, &cbounds.height,
1258 atk_text_rectangle_union (&bounds, &cbounds, &bounds);
1263 rect->width = bounds.width;
1264 rect->height = bounds.height;
1267 static AtkTextRange**
1268 atk_text_real_get_bounded_ranges (AtkText *text,
1269 AtkTextRectangle *rect,
1270 AtkCoordType coord_type,
1271 AtkTextClipType x_clip_type,
1272 AtkTextClipType y_clip_type)
1274 gint bounds_min_offset, bounds_max_offset;
1275 gint min_line_start, min_line_end;
1276 gint max_line_start, max_line_end;
1280 gint num_ranges = 0;
1281 gint range_size = 1;
1282 AtkTextRectangle cbounds;
1283 AtkTextRange **range;
1286 bounds_min_offset = atk_text_get_offset_at_point (text, rect->x, rect->y, coord_type);
1287 bounds_max_offset = atk_text_get_offset_at_point (text, rect->x + rect->width, rect->y + rect->height, coord_type);
1289 if (bounds_min_offset == 0 &&
1290 bounds_min_offset == bounds_max_offset)
1293 line = atk_text_get_text_at_offset (text, bounds_min_offset,
1294 ATK_TEXT_BOUNDARY_LINE_START,
1295 &min_line_start, &min_line_end);
1297 line = atk_text_get_text_at_offset (text, bounds_max_offset,
1298 ATK_TEXT_BOUNDARY_LINE_START,
1299 &max_line_start, &max_line_end);
1301 bounds_min_offset = MIN (min_line_start, max_line_start);
1302 bounds_max_offset = MAX (min_line_end, max_line_end);
1304 curr_offset = bounds_min_offset;
1305 while (curr_offset < bounds_max_offset)
1307 offset = curr_offset;
1309 while (curr_offset < bounds_max_offset)
1311 atk_text_get_character_extents (text, curr_offset,
1312 &cbounds.x, &cbounds.y,
1313 &cbounds.width, &cbounds.height,
1315 if (!atk_text_rectangle_contain (rect, &cbounds, x_clip_type, y_clip_type))
1319 if (curr_offset > offset)
1321 AtkTextRange *one_range = g_new (AtkTextRange, 1);
1323 one_range->start_offset = offset;
1324 one_range->end_offset = curr_offset;
1325 one_range->content = atk_text_get_text (text, offset, curr_offset);
1326 atk_text_get_range_extents (text, offset, curr_offset, coord_type, &one_range->bounds);
1328 if (num_ranges >= range_size - 1)
1331 range = g_realloc (range, range_size * sizeof (gpointer));
1333 range[num_ranges] = one_range;
1338 range[num_ranges] = NULL;
1344 * atk_text_free_ranges:
1345 * @ranges: A pointer to an array of #AtkTextRange which is to be freed.
1347 * Frees the memory associated with an array of AtkTextRange. It is assumed
1348 * that the array was returned by the function atk_text_get_bounded_ranges
1349 * and is NULL terminated.
1354 atk_text_free_ranges (AtkTextRange **ranges)
1356 AtkTextRange **first = ranges;
1362 AtkTextRange *range;
1366 g_free (range->content);