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 struct _AtkTextIfaceClass
34 typedef struct _AtkTextIfaceClass AtkTextIfaceClass;
36 static void atk_text_base_init (gpointer *g_class);
38 static guint atk_text_signals[LAST_SIGNAL] = { 0 };
43 static GType type = 0;
47 static const GTypeInfo tinfo =
49 sizeof (AtkTextIface),
50 (GBaseInitFunc) atk_text_base_init,
51 (GBaseFinalizeFunc) NULL,
52 (GClassInitFunc) NULL /* atk_text_interface_init */ ,
53 (GClassFinalizeFunc) NULL,
57 type = g_type_register_static (G_TYPE_INTERFACE, "AtkText", &tinfo, 0);
64 atk_text_base_init (gpointer *g_class)
66 static gboolean initialized = FALSE;
71 * Note that text_changed signal supports details "insert", "delete",
75 atk_text_signals[TEXT_CHANGED] =
76 g_signal_newc ("text_changed",
78 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
79 G_STRUCT_OFFSET (AtkTextIface, text_changed),
80 (GSignalAccumulator) NULL, NULL,
81 atk_marshal_VOID__INT_INT,
83 2, G_TYPE_INT, G_TYPE_INT);
85 atk_text_signals[CARET_MOVED] =
86 g_signal_newc ("text_caret_moved",
89 G_STRUCT_OFFSET (AtkTextIface, caret_changed),
90 (GSignalAccumulator) NULL, NULL,
91 g_cclosure_marshal_VOID__INT,
102 * @start_offset: start position
103 * @end_offset: end position
105 * Gets the specified text.
107 * Returns: the text from @start_offset up to, but not including @end_offset.
110 atk_text_get_text (AtkText *text,
116 g_return_val_if_fail (text != NULL, NULL);
117 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
119 iface = ATK_TEXT_GET_IFACE (text);
122 return (*(iface->get_text)) (text, start_offset, end_offset);
128 * atk_text_get_character_at_offset
132 * Gets the specified text.
134 * Returns: the character at @offset.
137 atk_text_get_character_at_offset (AtkText *text,
142 g_return_val_if_fail (text != NULL, (gunichar) 0);
143 g_return_val_if_fail (ATK_IS_TEXT (text), (gunichar) 0);
145 iface = ATK_TEXT_GET_IFACE (text);
147 if (iface->get_character_at_offset)
148 return (*(iface->get_character_at_offset)) (text, offset);
154 * atk_text_get_text_after_offset
157 * @boundary_type: An #AtkTextBoundary
159 * Gets the specified text.
160 * If the boundary type is ATK_TEXT_BOUNDARY_WORD_START or
161 * ATK_TEXT_BOUNDARY_WORD_END part of a word may be returned.
162 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the start point
163 * will be the offset and will continue to the start of the next sentence.
164 * The first word may not be a complete word. Similarly for
165 * ATK_TEXT_BOUNDARY_SENTENCE_END, ATK_TEXT_BOUNDARY_LINE_START and
166 * ATK_TEXT_BOUNDARY_LINE_END
168 * Returns: the text after @offset up to the specified @boundary_type.
171 atk_text_get_text_after_offset (AtkText *text,
173 AtkTextBoundary boundary_type)
177 g_return_val_if_fail (text != NULL, NULL);
178 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
180 iface = ATK_TEXT_GET_IFACE (text);
182 if (iface->get_text_after_offset)
183 return (*(iface->get_text_after_offset)) (text, offset, boundary_type);
189 * atk_text_get_text_at_offset
192 * @boundary_type: An #AtkTextBoundary
194 * Gets the specified text.
195 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START or
196 * ATK_TEXT_BOUNDARY_WORD_END a complete word is returned;
197 * if the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START or
198 * ATK_TEXT_BOUNDARY_SENTENCE_END a complete sentence
199 * is returned; if the boundary type is ATK_TEXT_BOUNDARY_LINE_START or
200 * ATK_TEXT_BOUNDARY_LINE_END a complete line is returned.
202 * Returns: the text at @offset up to the specified @boundary_type.
205 atk_text_get_text_at_offset (AtkText *text,
207 AtkTextBoundary boundary_type)
211 g_return_val_if_fail (text != NULL, NULL);
212 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
214 iface = ATK_TEXT_GET_IFACE (text);
216 if (iface->get_text_at_offset)
217 return (*(iface->get_text_at_offset)) (text, offset, boundary_type);
223 * atk_text_get_text_before_offset
226 * @boundary_type: An #AtkTextBoundary
228 * Gets the specified text.
229 * If the boundary type is ATK_TEXT_BOUNDARY_WORD_START or
230 * ATK_TEXT_BOUNDARY_WORD_END part of a word may be returned.
231 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the start point
232 * will be at the start of the sentence, and will continue to the offset.
233 * The last word may not be a complete word. Similarly for
234 * ATK_TEXT_BOUNDARY_SENTENCE_END, ATK_TEXT_BOUNDARY_LINE_START and
235 * ATK_TEXT_BOUNDARY_LINE_END
237 * Returns: the text before @offset starting from the specified @boundary_type.
240 atk_text_get_text_before_offset (AtkText *text,
242 AtkTextBoundary boundary_type)
246 g_return_val_if_fail (text != NULL, NULL);
247 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
249 iface = ATK_TEXT_GET_IFACE (text);
251 if (iface->get_text_before_offset)
252 return (*(iface->get_text_before_offset)) (text, offset, boundary_type);
258 * atk_text_get_caret_offset
261 * Gets the offset position of the caret (cursor).
263 * Returns: the offset position of the caret (cursor).
266 atk_text_get_caret_offset (AtkText *text)
270 g_return_val_if_fail (text != NULL, -1);
271 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
273 iface = ATK_TEXT_GET_IFACE (text);
275 if (iface->get_caret_offset)
276 return (*(iface->get_caret_offset)) (text);
282 * atk_text_get_range_attributes
284 * @start_offset: start position
285 * @end_offset: end position
287 * Gets attributes over the specified range.
289 * Returns: a #PangoAttrList with the text attributes between the
290 * @start_offset and the @end_offset.
293 atk_text_get_range_attributes (AtkText *text,
299 g_return_val_if_fail (text != NULL, NULL);
300 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
302 iface = ATK_TEXT_GET_IFACE (text);
304 if (iface->get_range_attributes)
305 return (*(iface->get_range_attributes)) (text, start_offset, end_offset);
311 * atk_text_get_character_extents
314 * @x: x-position of character
315 * @y: y-position of character
316 * @length: length of character
317 * @width: width of character
319 * Given an @offset, the @x, @y, @length, and @width values are filled
323 atk_text_get_character_extents (AtkText *text,
332 g_return_if_fail (text != NULL);
333 g_return_if_fail (ATK_IS_TEXT (text));
335 iface = ATK_TEXT_GET_IFACE (text);
337 if (iface->get_character_extents)
338 (*(iface->get_character_extents)) (text, offset, x, y, length, width);
349 * atk_text_get_character_count
352 * Gets the character count.
354 * Returns: the number of characters.
357 atk_text_get_character_count (AtkText *text)
361 g_return_val_if_fail (text != NULL, -1);
362 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
364 iface = ATK_TEXT_GET_IFACE (text);
366 if (iface->get_character_count)
367 return (*(iface->get_character_count)) (text);
373 * atk_text_get_offset_at_point
375 * @x: screen x-position of character
376 * @y: screen y-position of character
378 * Gets the x,y screen coordinates of the specified character.
380 * Returns: the offset to the character which is located at
381 * the specified @x and @y coordinates.
384 atk_text_get_offset_at_point (AtkText *text,
390 g_return_val_if_fail (text != NULL, -1);
391 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
393 iface = ATK_TEXT_GET_IFACE (text);
395 if (iface->get_offset_at_point)
396 return (*(iface->get_offset_at_point)) (text, x, y);
402 * atk_text_get_n_selections
405 * Gets the number of selected regions.
407 * Returns: The number of selected regions, or -1 if a failure
411 atk_text_get_n_selections (AtkText *text)
415 g_return_val_if_fail (text != NULL, -1);
416 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
418 iface = ATK_TEXT_GET_IFACE (text);
420 if (iface->get_n_selections)
421 return (*(iface->get_n_selections)) (text);
427 * atk_text_get_selection
429 * @selection_num: The selection number. The selected regions are
430 * assigned numbers that corrispond to how far the region is from the
431 * start of the text. The selected region closest to the beginning
432 * of the text region is assigned the number 0, etc. Note that adding,
433 * moving or deleting a selected region can change the numbering.
434 * @start_offset: passes back the start position of the selected region
435 * @end_offset: passes back the end position of the selected region
437 * Gets the text from the specified selection.
439 * Returns: the selected text.
442 atk_text_get_selection (AtkText *text, gint selection_num,
443 gint *start_offset, gint *end_offset)
447 g_return_val_if_fail (text != NULL, NULL);
448 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
450 iface = ATK_TEXT_GET_IFACE (text);
452 if (iface->get_selection)
454 return (*(iface->get_selection)) (text, selection_num,
455 start_offset, end_offset);
462 * atk_text_add_selection
464 * @start_offset: the start position of the selected region
465 * @end_offset: the end position of the selected region
467 * Adds a selection bounded by the specified offsets.
469 * Returns: %TRUE if success, %FALSE otherwise
472 atk_text_add_selection (AtkText *text, gint start_offset,
477 g_return_val_if_fail (text != NULL, FALSE);
478 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
480 iface = ATK_TEXT_GET_IFACE (text);
482 if (iface->add_selection)
483 return (*(iface->add_selection)) (text, start_offset, end_offset);
489 * atk_text_remove_selection
491 * @selection_num: The selection number. The selected regions are
492 * assigned numbers that corrispond to how far the region is from the
493 * start of the text. The selected region closest to the beginning
494 * of the text region is assigned the number 0, etc. Note that adding,
495 * moving or deleting a selected region can change the numbering.
497 * Removes the specified selection
499 * Returns: %TRUE if success, %FALSE otherwise
502 atk_text_remove_selection (AtkText *text, gint selection_num)
506 g_return_val_if_fail (text != NULL, FALSE);
507 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
509 iface = ATK_TEXT_GET_IFACE (text);
511 if (iface->remove_selection)
512 return (*(iface->remove_selection)) (text, selection_num);
518 * atk_text_set_selection
520 * @selection_num: The selection number. The selected regions are
521 * assigned numbers that corrispond to how far the region is from the
522 * start of the text. The selected region closest to the beginning
523 * of the text region is assigned the number 0, etc. Note that adding,
524 * moving or deleting a selected region can change the numbering.
525 * @start_offset: the new start position of the selection
526 * @end_offset: the new end position of the selection
528 * Changes the start and end offset of the specified selection
530 * Returns: %TRUE if success, %FALSE otherwise
533 atk_text_set_selection (AtkText *text, gint selection_num,
534 gint start_offset, gint end_offset)
538 g_return_val_if_fail (text != NULL, FALSE);
539 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
541 iface = ATK_TEXT_GET_IFACE (text);
543 if (iface->set_selection)
545 return (*(iface->set_selection)) (text, selection_num,
546 start_offset, end_offset);
553 * atk_text_set_caret_offset
557 * Sets the caret (cursor) position to the specified @offset.
559 * Returns: %TRUE if success, %FALSE otherwise.
562 atk_text_set_caret_offset (AtkText *text,
567 g_return_val_if_fail (text != NULL, FALSE);
568 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
570 iface = ATK_TEXT_GET_IFACE (text);
572 if (iface->set_caret_offset)
574 return (*(iface->set_caret_offset)) (text, offset);