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 ATK_ATTRIBUTE macros, such as #ATK_ATTRIBUTE_LEFT_MARGIN
451 *for types of text attributes that can be returned. Note that other
452 *attributes that do not have corresponding macros may also be returned.
454 *Returns: an #AtkAttributeSet which contains the attributes explicitly set
455 *at @offset. This #AtkAttributeSet should be freed by a call to
456 *atk_attribute_set_free().
459 atk_text_get_run_attributes (AtkText *text,
465 gint local_start_offset, local_end_offset;
466 gint *real_start_offset, *real_end_offset;
468 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
471 real_start_offset = start_offset;
473 real_start_offset = &local_start_offset;
475 real_end_offset = end_offset;
477 real_end_offset = &local_end_offset;
479 iface = ATK_TEXT_GET_IFACE (text);
481 if (iface->get_run_attributes)
482 return (*(iface->get_run_attributes)) (text, offset, real_start_offset, real_end_offset);
488 *atk_text_get_default_attributes:
491 *Creates an #AtkAttributeSet which consists of the default values of
492 *attributes for the text. See the ATK_ATTRIBUTE macros, such as
493 *#ATK_ATTRIBUTE_LEFT_MARGIN for types of text attributes that can be
494 *returned. Note that other attributes that do not have corresponding macros
495 *may also be returned.
497 *Returns: an #AtkAttributeSet which contains the default values of attributes.
498 *at @offset. This #AtkAttributeSet should be freed by a call to
499 *atk_attribute_set_free().
502 atk_text_get_default_attributes (AtkText *text)
506 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
508 iface = ATK_TEXT_GET_IFACE (text);
510 if (iface->get_default_attributes)
511 return (*(iface->get_default_attributes)) (text);
517 * atk_text_get_character_count:
520 * Gets the character count.
522 * Returns: the number of characters.
525 atk_text_get_character_count (AtkText *text)
529 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
531 iface = ATK_TEXT_GET_IFACE (text);
533 if (iface->get_character_count)
534 return (*(iface->get_character_count)) (text);
540 * atk_text_get_offset_at_point:
542 * @x: screen x-position of character
543 * @y: screen y-position of character
544 * @coords: specify whether coordinates are relative to the screen or
547 * Gets the offset of the character located at coordinates @x and @y. @x and @y
548 * are interpreted as being relative to the screen or this widget's window
549 * depending on @coords.
551 * Returns: the offset to the character which is located at
552 * the specified @x and @y coordinates.
555 atk_text_get_offset_at_point (AtkText *text,
562 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
564 iface = ATK_TEXT_GET_IFACE (text);
566 if (iface->get_offset_at_point)
567 return (*(iface->get_offset_at_point)) (text, x, y, coords);
573 * atk_text_get_n_selections:
576 * Gets the number of selected regions.
578 * Returns: The number of selected regions, or -1 if a failure
582 atk_text_get_n_selections (AtkText *text)
586 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
588 iface = ATK_TEXT_GET_IFACE (text);
590 if (iface->get_n_selections)
591 return (*(iface->get_n_selections)) (text);
597 * atk_text_get_selection:
599 * @selection_num: The selection number. The selected regions are
600 * assigned numbers that correspond to how far the region is from the
601 * start of the text. The selected region closest to the beginning
602 * of the text region is assigned the number 0, etc. Note that adding,
603 * moving or deleting a selected region can change the numbering.
604 * @start_offset: passes back the start position of the selected region
605 * @end_offset: passes back the end position of the selected region
607 * Gets the text from the specified selection.
609 * Returns: the selected text.
612 atk_text_get_selection (AtkText *text,
618 gint local_start_offset, local_end_offset;
619 gint *real_start_offset, *real_end_offset;
621 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
624 real_start_offset = start_offset;
626 real_start_offset = &local_start_offset;
628 real_end_offset = end_offset;
630 real_start_offset = &local_end_offset;
632 iface = ATK_TEXT_GET_IFACE (text);
634 if (iface->get_selection)
636 return (*(iface->get_selection)) (text, selection_num,
637 real_start_offset, real_end_offset);
644 * atk_text_add_selection:
646 * @start_offset: the start position of the selected region
647 * @end_offset: the end position of the selected region
649 * Adds a selection bounded by the specified offsets.
651 * Returns: %TRUE if success, %FALSE otherwise
654 atk_text_add_selection (AtkText *text,
660 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
662 iface = ATK_TEXT_GET_IFACE (text);
664 if (iface->add_selection)
665 return (*(iface->add_selection)) (text, start_offset, end_offset);
671 * atk_text_remove_selection:
673 * @selection_num: The selection number. The selected regions are
674 * assigned numbers that correspond to how far the region is from the
675 * start of the text. The selected region closest to the beginning
676 * of the text region is assigned the number 0, etc. Note that adding,
677 * moving or deleting a selected region can change the numbering.
679 * Removes the specified selection.
681 * Returns: %TRUE if success, %FALSE otherwise
684 atk_text_remove_selection (AtkText *text,
689 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
691 iface = ATK_TEXT_GET_IFACE (text);
693 if (iface->remove_selection)
694 return (*(iface->remove_selection)) (text, selection_num);
700 * atk_text_set_selection:
702 * @selection_num: The selection number. The selected regions are
703 * assigned numbers that correspond to how far the region is from the
704 * start of the text. The selected region closest to the beginning
705 * of the text region is assigned the number 0, etc. Note that adding,
706 * moving or deleting a selected region can change the numbering.
707 * @start_offset: the new start position of the selection
708 * @end_offset: the new end position of the selection
710 * Changes the start and end offset of the specified selection.
712 * Returns: %TRUE if success, %FALSE otherwise
715 atk_text_set_selection (AtkText *text,
722 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
724 iface = ATK_TEXT_GET_IFACE (text);
726 if (iface->set_selection)
728 return (*(iface->set_selection)) (text, selection_num,
729 start_offset, end_offset);
736 * atk_text_set_caret_offset:
740 * Sets the caret (cursor) position to the specified @offset.
742 * Returns: %TRUE if success, %FALSE otherwise.
745 atk_text_set_caret_offset (AtkText *text,
750 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
752 iface = ATK_TEXT_GET_IFACE (text);
754 if (iface->set_caret_offset)
756 return (*(iface->set_caret_offset)) (text, offset);
765 * atk_attribute_set_free:
766 * @attrib_set: The #AtkAttributeSet to free
768 * Frees the memory used by an #AtkAttributeSet, including all its
772 atk_attribute_set_free(AtkAttributeSet *attrib_set)
789 g_slist_free (attrib_set);
793 * atk_attribute_get_name:
794 * @attr: The #AtkTextAttribute whose name is required
796 * Returns the name corresponding to the attr value.
798 G_CONST_RETURN gchar*
799 atk_attribute_get_name (AtkTextAttribute attr)
801 g_assert (attr >= 0 && attr <= ATK_TEXT_ATTR_STYLE);
802 return text_attr_name[attr];
806 * atk_attribute_get_value:
807 * @attr: The #AtkTextAttribute for which a value is required
808 * @index: The index of the required value
810 * Returns the value corresponding to the attr value and index.
811 * NULL is returned if there are no values maintained for the attr value.
813 G_CONST_RETURN gchar*
814 atk_attribute_get_value (AtkTextAttribute attr,
819 case ATK_TEXT_ATTR_INVISIBLE:
820 case ATK_TEXT_ATTR_EDITABLE:
821 case ATK_TEXT_ATTR_BG_FULL_HEIGHT:
822 case ATK_TEXT_ATTR_STRIKETHROUGH:
823 case ATK_TEXT_ATTR_BG_STIPPLE:
824 case ATK_TEXT_ATTR_FG_STIPPLE:
825 g_assert (index >= 0 && index < 2);
827 case ATK_TEXT_ATTR_UNDERLINE:
828 g_assert (index >= 0 && index < 4);
829 return underline[index];
830 case ATK_TEXT_ATTR_WRAP_MODE:
831 g_assert (index >= 0 && index < 3);
832 return wrap_mode[index];
833 case ATK_TEXT_ATTR_DIRECTION:
834 g_assert (index >= 0 && index < 3);
835 return direction[index];
836 case ATK_TEXT_ATTR_JUSTIFICATION:
837 g_assert (index >= 0 && index < 3);
838 return justification[index];
839 case ATK_TEXT_ATTR_STRETCH:
840 g_assert (index >= 0 && index < 9);
841 return stretch[index];
842 case ATK_TEXT_ATTR_VARIANT:
843 g_assert (index >= 0 && index < 2);
844 return variant[index];
845 case ATK_TEXT_ATTR_STYLE:
846 g_assert (index >= 0 && index < 3);