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"
29 static const gchar * text_attr_name[] = {
59 static const gchar *bool[] = {"false",
61 static const gchar *style[] = {"normal",
64 static const gchar *variant[] = {"normal",
66 static const gchar *stretch[] = {"ultra_condensed",
75 static const gchar *justification[] = {"left",
80 static const gchar *direction[] = {"none",
83 static const gchar *wrap_mode[] = {"none",
86 static const gchar *underline[] = {"none",
91 struct _AtkTextIfaceClass
96 typedef struct _AtkTextIfaceClass AtkTextIfaceClass;
98 static void atk_text_base_init (gpointer *g_class);
100 static guint atk_text_signals[LAST_SIGNAL] = { 0 };
105 static GType type = 0;
109 static const GTypeInfo tinfo =
111 sizeof (AtkTextIface),
112 (GBaseInitFunc) atk_text_base_init,
113 (GBaseFinalizeFunc) NULL,
114 (GClassInitFunc) NULL /* atk_text_interface_init */ ,
115 (GClassFinalizeFunc) NULL,
119 type = g_type_register_static (G_TYPE_INTERFACE, "AtkText", &tinfo, 0);
126 atk_text_base_init (gpointer *g_class)
128 static gboolean initialized = FALSE;
133 * Note that text_changed signal supports details "insert", "delete",
134 * possibly "replace".
137 atk_text_signals[TEXT_CHANGED] =
138 g_signal_new ("text_changed",
140 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
141 G_STRUCT_OFFSET (AtkTextIface, text_changed),
142 (GSignalAccumulator) NULL, NULL,
143 atk_marshal_VOID__INT_INT,
145 2, G_TYPE_INT, G_TYPE_INT);
147 atk_text_signals[CARET_MOVED] =
148 g_signal_new ("text_caret_moved",
151 G_STRUCT_OFFSET (AtkTextIface, caret_changed),
152 (GSignalAccumulator) NULL, NULL,
153 g_cclosure_marshal_VOID__INT,
164 * @start_offset: start position
165 * @end_offset: end position
167 * Gets the specified text.
169 * Returns: the text from @start_offset up to, but not including @end_offset.
172 atk_text_get_text (AtkText *text,
178 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
180 iface = ATK_TEXT_GET_IFACE (text);
183 return (*(iface->get_text)) (text, start_offset, end_offset);
189 * atk_text_get_character_at_offset:
193 * Gets the specified text.
195 * Returns: the character at @offset.
198 atk_text_get_character_at_offset (AtkText *text,
203 g_return_val_if_fail (ATK_IS_TEXT (text), (gunichar) 0);
205 iface = ATK_TEXT_GET_IFACE (text);
207 if (iface->get_character_at_offset)
208 return (*(iface->get_character_at_offset)) (text, offset);
214 * atk_text_get_text_after_offset:
217 * @boundary_type: An #AtkTextBoundary
218 * @start_offset: the start offset of the returned string.
219 * @end_offset: the end offset of the returned string.
221 * Gets the specified text.
222 * If the boundary type is ATK_TEXT_BOUNDARY_WORD_START or
223 * ATK_TEXT_BOUNDARY_WORD_END part of a word may be returned.
224 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the start point
225 * will be the offset and will continue to the start of the next sentence.
226 * The first word may not be a complete word. Similarly for
227 * ATK_TEXT_BOUNDARY_SENTENCE_END, ATK_TEXT_BOUNDARY_LINE_START and
228 * ATK_TEXT_BOUNDARY_LINE_END
230 * Returns: the text after @offset up to the specified @boundary_type.
233 atk_text_get_text_after_offset (AtkText *text,
235 AtkTextBoundary boundary_type,
240 gint local_start_offset, local_end_offset;
241 gint *real_start_offset, *real_end_offset;
243 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
246 real_start_offset = start_offset;
248 real_start_offset = &local_start_offset;
250 real_end_offset = end_offset;
252 real_end_offset = &local_end_offset;
254 iface = ATK_TEXT_GET_IFACE (text);
256 if (iface->get_text_after_offset)
257 return (*(iface->get_text_after_offset)) (text, offset, boundary_type, real_start_offset, real_end_offset);
263 * atk_text_get_text_at_offset:
266 * @boundary_type: An #AtkTextBoundary
267 * @start_offset: the start offset of the returned string.
268 * @end_offset: the end offset of the returned string.
270 * Gets the specified text.
271 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START or
272 * ATK_TEXT_BOUNDARY_WORD_END a complete word is returned;
273 * if the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START or
274 * ATK_TEXT_BOUNDARY_SENTENCE_END a complete sentence
275 * is returned; if the boundary type is ATK_TEXT_BOUNDARY_LINE_START or
276 * ATK_TEXT_BOUNDARY_LINE_END a complete line is returned.
278 * Returns: the text at @offset up to the specified @boundary_type.
281 atk_text_get_text_at_offset (AtkText *text,
283 AtkTextBoundary boundary_type,
288 gint local_start_offset, local_end_offset;
289 gint *real_start_offset, *real_end_offset;
291 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
294 real_start_offset = start_offset;
296 real_start_offset = &local_start_offset;
298 real_end_offset = end_offset;
300 real_end_offset = &local_end_offset;
302 iface = ATK_TEXT_GET_IFACE (text);
304 if (iface->get_text_at_offset)
305 return (*(iface->get_text_at_offset)) (text, offset, boundary_type, real_start_offset, real_end_offset);
311 * atk_text_get_text_before_offset:
314 * @boundary_type: An #AtkTextBoundary
315 * @start_offset: the start offset of the returned string.
316 * @end_offset: the end offset of the returned string.
318 * Gets the specified text.
319 * If the boundary type is ATK_TEXT_BOUNDARY_WORD_START or
320 * ATK_TEXT_BOUNDARY_WORD_END part of a word may be returned.
321 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the start point
322 * will be at the start of the sentence, and will continue to the offset.
323 * The last word may not be a complete word. Similarly for
324 * ATK_TEXT_BOUNDARY_SENTENCE_END, ATK_TEXT_BOUNDARY_LINE_START and
325 * ATK_TEXT_BOUNDARY_LINE_END
327 * Returns: the text before @offset starting from the specified @boundary_type.
330 atk_text_get_text_before_offset (AtkText *text,
332 AtkTextBoundary boundary_type,
337 gint local_start_offset, local_end_offset;
338 gint *real_start_offset, *real_end_offset;
340 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
343 real_start_offset = start_offset;
345 real_start_offset = &local_start_offset;
347 real_end_offset = end_offset;
349 real_end_offset = &local_end_offset;
351 iface = ATK_TEXT_GET_IFACE (text);
353 if (iface->get_text_before_offset)
354 return (*(iface->get_text_before_offset)) (text, offset, boundary_type, real_start_offset, real_end_offset);
360 * atk_text_get_caret_offset:
363 * Gets the offset position of the caret (cursor).
365 * Returns: the offset position of the caret (cursor).
368 atk_text_get_caret_offset (AtkText *text)
372 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
374 iface = ATK_TEXT_GET_IFACE (text);
376 if (iface->get_caret_offset)
377 return (*(iface->get_caret_offset)) (text);
383 * atk_text_get_character_extents:
386 * @x: x-position of character
387 * @y: y-position of character
388 * @width: width of character
389 * @height: height of character
390 * @coords: specify whether coordinates are relative to the screen or widget window
392 * Given an @offset, the @x, @y, @width, and @height values are filled
396 atk_text_get_character_extents (AtkText *text,
405 gint local_x, local_y, local_width, local_height;
406 gint *real_x, *real_y, *real_width, *real_height;
408 g_return_if_fail (ATK_IS_TEXT (text));
421 real_width = &local_width;
423 real_height = height;
425 real_height = &local_height;
427 iface = ATK_TEXT_GET_IFACE (text);
429 if (iface->get_character_extents)
430 (*(iface->get_character_extents)) (text, offset, real_x, real_y, real_width, real_height, coords);
441 *atk_text_get_run_attributes:
443 *@offset: the offset at which to get the attributes
444 *@start_offset: the address to put the start offset of the range
445 *@end_offset: the address to put the end offset of the range
447 *Creates an #AtkAttributeSet which consists of the attributes explicitly
448 *set at the position @offset in the text. @start_offset and @end_offset are
449 *set to the start and end of the range around @offset where the attributes are
450 *invariant. See the enum AtkTextAttribute for types of text attributes that
451 *can be returned. Note that other attributes may also be returned.
453 *Returns: an #AtkAttributeSet which contains the attributes explicitly set
454 *at @offset. This #AtkAttributeSet should be freed by a call to
455 *atk_attribute_set_free().
458 atk_text_get_run_attributes (AtkText *text,
464 gint local_start_offset, local_end_offset;
465 gint *real_start_offset, *real_end_offset;
467 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
470 real_start_offset = start_offset;
472 real_start_offset = &local_start_offset;
474 real_end_offset = end_offset;
476 real_end_offset = &local_end_offset;
478 iface = ATK_TEXT_GET_IFACE (text);
480 if (iface->get_run_attributes)
481 return (*(iface->get_run_attributes)) (text, offset, real_start_offset, real_end_offset);
487 *atk_text_get_default_attributes:
490 *Creates an #AtkAttributeSet which consists of the default values of
491 *attributes for the text. See the enum AtkTextAttribute for types of text
492 *attributes that can be returned. Note that other attributes may also be
495 *Returns: an #AtkAttributeSet which contains the default values of attributes.
496 *at @offset. This #AtkAttributeSet should be freed by a call to
497 *atk_attribute_set_free().
500 atk_text_get_default_attributes (AtkText *text)
504 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
506 iface = ATK_TEXT_GET_IFACE (text);
508 if (iface->get_default_attributes)
509 return (*(iface->get_default_attributes)) (text);
515 * atk_text_get_character_count:
518 * Gets the character count.
520 * Returns: the number of characters.
523 atk_text_get_character_count (AtkText *text)
527 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
529 iface = ATK_TEXT_GET_IFACE (text);
531 if (iface->get_character_count)
532 return (*(iface->get_character_count)) (text);
538 * atk_text_get_offset_at_point:
540 * @x: screen x-position of character
541 * @y: screen y-position of character
542 * @coords: specify whether coordinates are relative to the screen or
545 * Gets the offset of the character located at coordinates @x and @y. @x and @y
546 * are interpreted as being relative to the screen or this widget's window
547 * depending on @coords.
549 * Returns: the offset to the character which is located at
550 * the specified @x and @y coordinates.
553 atk_text_get_offset_at_point (AtkText *text,
560 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
562 iface = ATK_TEXT_GET_IFACE (text);
564 if (iface->get_offset_at_point)
565 return (*(iface->get_offset_at_point)) (text, x, y, coords);
571 * atk_text_get_n_selections:
574 * Gets the number of selected regions.
576 * Returns: The number of selected regions, or -1 if a failure
580 atk_text_get_n_selections (AtkText *text)
584 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
586 iface = ATK_TEXT_GET_IFACE (text);
588 if (iface->get_n_selections)
589 return (*(iface->get_n_selections)) (text);
595 * atk_text_get_selection:
597 * @selection_num: The selection number. The selected regions are
598 * assigned numbers that correspond to how far the region is from the
599 * start of the text. The selected region closest to the beginning
600 * of the text region is assigned the number 0, etc. Note that adding,
601 * moving or deleting a selected region can change the numbering.
602 * @start_offset: passes back the start position of the selected region
603 * @end_offset: passes back the end position of the selected region
605 * Gets the text from the specified selection.
607 * Returns: the selected text.
610 atk_text_get_selection (AtkText *text,
616 gint local_start_offset, local_end_offset;
617 gint *real_start_offset, *real_end_offset;
619 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
622 real_start_offset = start_offset;
624 real_start_offset = &local_start_offset;
626 real_end_offset = end_offset;
628 real_start_offset = &local_end_offset;
630 iface = ATK_TEXT_GET_IFACE (text);
632 if (iface->get_selection)
634 return (*(iface->get_selection)) (text, selection_num,
635 real_start_offset, real_end_offset);
642 * atk_text_add_selection:
644 * @start_offset: the start position of the selected region
645 * @end_offset: the end position of the selected region
647 * Adds a selection bounded by the specified offsets.
649 * Returns: %TRUE if success, %FALSE otherwise
652 atk_text_add_selection (AtkText *text,
658 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
660 iface = ATK_TEXT_GET_IFACE (text);
662 if (iface->add_selection)
663 return (*(iface->add_selection)) (text, start_offset, end_offset);
669 * atk_text_remove_selection:
671 * @selection_num: The selection number. The selected regions are
672 * assigned numbers that correspond to how far the region is from the
673 * start of the text. The selected region closest to the beginning
674 * of the text region is assigned the number 0, etc. Note that adding,
675 * moving or deleting a selected region can change the numbering.
677 * Removes the specified selection.
679 * Returns: %TRUE if success, %FALSE otherwise
682 atk_text_remove_selection (AtkText *text,
687 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
689 iface = ATK_TEXT_GET_IFACE (text);
691 if (iface->remove_selection)
692 return (*(iface->remove_selection)) (text, selection_num);
698 * atk_text_set_selection:
700 * @selection_num: The selection number. The selected regions are
701 * assigned numbers that correspond to how far the region is from the
702 * start of the text. The selected region closest to the beginning
703 * of the text region is assigned the number 0, etc. Note that adding,
704 * moving or deleting a selected region can change the numbering.
705 * @start_offset: the new start position of the selection
706 * @end_offset: the new end position of the selection
708 * Changes the start and end offset of the specified selection.
710 * Returns: %TRUE if success, %FALSE otherwise
713 atk_text_set_selection (AtkText *text,
720 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
722 iface = ATK_TEXT_GET_IFACE (text);
724 if (iface->set_selection)
726 return (*(iface->set_selection)) (text, selection_num,
727 start_offset, end_offset);
734 * atk_text_set_caret_offset:
738 * Sets the caret (cursor) position to the specified @offset.
740 * Returns: %TRUE if success, %FALSE otherwise.
743 atk_text_set_caret_offset (AtkText *text,
748 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
750 iface = ATK_TEXT_GET_IFACE (text);
752 if (iface->set_caret_offset)
754 return (*(iface->set_caret_offset)) (text, offset);
763 * atk_attribute_set_free:
764 * @attrib_set: The #AtkAttributeSet to free
766 * Frees the memory used by an #AtkAttributeSet, including all its
770 atk_attribute_set_free(AtkAttributeSet *attrib_set)
787 g_slist_free (attrib_set);
791 * atk_attribute_get_name:
792 * @attr: The #AtkTextAttribute whose name is required
794 * Returns the name corresponding to the attr value.
796 G_CONST_RETURN gchar*
797 atk_attribute_get_name (AtkTextAttribute attr)
799 g_assert (attr >= 0 && attr <= ATK_TEXT_ATTR_STYLE);
800 return text_attr_name[attr];
804 * atk_attribute_get_value:
805 * @attr: The #AtkTextAttribute for which a value is required
806 * @index: The index of the required value
808 * Returns the value corresponding to the attr value and index.
809 * NULL is returned if there are no values maintained for the attr value.
811 G_CONST_RETURN gchar*
812 atk_attribute_get_value (AtkTextAttribute attr,
817 case ATK_TEXT_ATTR_INVISIBLE:
818 case ATK_TEXT_ATTR_EDITABLE:
819 case ATK_TEXT_ATTR_BG_FULL_HEIGHT:
820 case ATK_TEXT_ATTR_STRIKETHROUGH:
821 case ATK_TEXT_ATTR_BG_STIPPLE:
822 case ATK_TEXT_ATTR_FG_STIPPLE:
823 g_assert (index >= 0 && index < 2);
825 case ATK_TEXT_ATTR_UNDERLINE:
826 g_assert (index >= 0 && index < 4);
827 return underline[index];
828 case ATK_TEXT_ATTR_WRAP_MODE:
829 g_assert (index >= 0 && index < 3);
830 return wrap_mode[index];
831 case ATK_TEXT_ATTR_DIRECTION:
832 g_assert (index >= 0 && index < 3);
833 return direction[index];
834 case ATK_TEXT_ATTR_JUSTIFICATION:
835 g_assert (index >= 0 && index < 3);
836 return justification[index];
837 case ATK_TEXT_ATTR_STRETCH:
838 g_assert (index >= 0 && index < 9);
839 return stretch[index];
840 case ATK_TEXT_ATTR_VARIANT:
841 g_assert (index >= 0 && index < 2);
842 return variant[index];
843 case ATK_TEXT_ATTR_STYLE:
844 g_assert (index >= 0 && index < 3);