Released 0.1
[atk.git] / atk / atktext.c
blob16abdea2a6726ed168d26541a2ed727d4e05834f
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.
20 #include "atktext.h"
22 struct _AtkTextIfaceClass
24 GObjectClass parent;
27 typedef struct _AtkTextIfaceClass AtkTextIfaceClass;
30 GType
31 atk_text_get_type ()
33 static GType type = 0;
35 if (!type) {
36 static const GTypeInfo tinfo =
38 sizeof (AtkTextIface),
39 NULL,
40 NULL,
44 type = g_type_register_static (G_TYPE_INTERFACE, "AtkText", &tinfo, 0);
47 return type;
50 gchar*
51 atk_text_get_text (AtkText *text,
52 gint start_offset,
53 gint end_offset)
55 AtkTextIface *iface;
57 g_return_val_if_fail (text != NULL, NULL);
58 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
60 iface = ATK_TEXT_GET_IFACE (text);
62 if (iface->get_text)
63 return (*(iface->get_text)) (text, start_offset, end_offset);
64 else
65 return NULL;
68 gunichar
69 atk_text_get_character_at_offset (AtkText *text,
70 gint offset)
72 AtkTextIface *iface;
74 g_return_val_if_fail (text != NULL, (gunichar) 0);
75 g_return_val_if_fail (ATK_IS_TEXT (text), (gunichar) 0);
77 iface = ATK_TEXT_GET_IFACE (text);
79 if (iface->get_character_at_offset)
80 return (*(iface->get_character_at_offset)) (text, offset);
81 else
82 return (gunichar) 0;
85 gchar*
86 atk_text_get_text_after_offset (AtkText *text,
87 gint offset,
88 AtkTextBoundary boundary_type)
90 AtkTextIface *iface;
92 g_return_val_if_fail (text != NULL, NULL);
93 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
95 iface = ATK_TEXT_GET_IFACE (text);
97 if (iface->get_text_after_offset)
98 return (*(iface->get_text_after_offset)) (text, offset, boundary_type);
99 else
100 return NULL;
103 gchar*
104 atk_text_get_text_at_offset (AtkText *text,
105 gint offset,
106 AtkTextBoundary boundary_type)
108 AtkTextIface *iface;
110 g_return_val_if_fail (text != NULL, NULL);
111 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
113 iface = ATK_TEXT_GET_IFACE (text);
115 if (iface->get_text_at_offset)
116 return (*(iface->get_text_at_offset)) (text, offset, boundary_type);
117 else
118 return NULL;
121 gchar*
122 atk_text_get_text_before_offset (AtkText *text,
123 gint offset,
124 AtkTextBoundary boundary_type)
126 AtkTextIface *iface;
128 g_return_val_if_fail (text != NULL, NULL);
129 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
131 iface = ATK_TEXT_GET_IFACE (text);
133 if (iface->get_text_before_offset)
134 return (*(iface->get_text_before_offset)) (text, offset, boundary_type);
135 else
136 return NULL;
139 gint
140 atk_text_get_caret_offset (AtkText *text)
142 AtkTextIface *iface;
144 g_return_val_if_fail (text != NULL, -1);
145 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
147 iface = ATK_TEXT_GET_IFACE (text);
149 if (iface->get_caret_offset)
150 return (*(iface->get_caret_offset)) (text);
151 else
152 return -1;
155 void
156 atk_text_get_row_col_at_offset (AtkText *text,
157 gint offset,
158 gint *row,
159 gint *col)
161 AtkTextIface *iface;
163 g_return_if_fail (text != NULL);
164 g_return_if_fail (ATK_IS_TEXT (text));
166 iface = ATK_TEXT_GET_IFACE (text);
168 if (iface->get_row_col_at_offset)
169 (*(iface->get_row_col_at_offset)) (text, offset, row, col);
170 else
172 *row = 0;
173 *col = 0;
177 PangoAttrList*
178 atk_text_get_range_attributes (AtkText *text,
179 gint start_offset,
180 gint end_offset)
182 AtkTextIface *iface;
184 g_return_val_if_fail (text != NULL, NULL);
185 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
187 iface = ATK_TEXT_GET_IFACE (text);
189 if (iface->get_range_attributes)
190 return (*(iface->get_range_attributes)) (text, start_offset, end_offset);
191 else
192 return NULL;
195 void
196 atk_text_get_character_extents (AtkText *text,
197 gint offset,
198 gint *x,
199 gint *y,
200 gint *length,
201 gint *width)
203 AtkTextIface *iface;
205 g_return_if_fail (text != NULL);
206 g_return_if_fail (ATK_IS_TEXT (text));
208 iface = ATK_TEXT_GET_IFACE (text);
210 if (iface->get_character_extents)
211 (*(iface->get_character_extents)) (text, offset, x, y, length, width);
212 else
214 *x = 0;
215 *x = 0;
216 *length = 0;
217 *width = 0;
221 gint
222 atk_text_get_character_count (AtkText *text)
224 AtkTextIface *iface;
226 g_return_val_if_fail (text != NULL, -1);
227 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
229 iface = ATK_TEXT_GET_IFACE (text);
231 if (iface->get_character_count)
232 return (*(iface->get_character_count)) (text);
233 else
234 return -1;
237 gint
238 atk_text_get_offset_at_point (AtkText *text,
239 gint x,
240 gint y)
242 AtkTextIface *iface;
244 g_return_val_if_fail (text != NULL, -1);
245 g_return_val_if_fail (ATK_IS_TEXT (text), -1);
247 iface = ATK_TEXT_GET_IFACE (text);
249 if (iface->get_offset_at_point)
250 return (*(iface->get_offset_at_point)) (text, x, y);
251 else
252 return -1;
255 gchar*
256 atk_text_get_selected_text (AtkText *text)
258 AtkTextIface *iface;
260 g_return_val_if_fail (text != NULL, NULL);
261 g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
263 iface = ATK_TEXT_GET_IFACE (text);
265 if (iface->get_selected_text)
266 return (*(iface->get_selected_text)) (text);
267 else
268 return NULL;
271 void
272 atk_text_get_selection_bounds (AtkText *text,
273 gint *start_offset,
274 gint *end_offset)
276 AtkTextIface *iface;
278 g_return_if_fail (text != NULL);
279 g_return_if_fail (ATK_IS_TEXT (text));
281 iface = ATK_TEXT_GET_IFACE (text);
283 if (iface->get_selection_bounds)
284 (*(iface->get_selection_bounds)) (text, start_offset, end_offset);
285 else
287 *start_offset = 0;
288 *end_offset = 0;
292 gboolean
293 atk_text_set_selection_bounds (AtkText *text,
294 gint start_offset,
295 gint end_offset)
297 AtkTextIface *iface;
299 g_return_val_if_fail (text != NULL, FALSE);
300 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
302 iface = ATK_TEXT_GET_IFACE (text);
304 if (iface->set_selection_bounds)
306 return (*(iface->set_selection_bounds)) (text, start_offset, end_offset);
308 else
310 return FALSE;
314 gboolean
315 atk_text_set_caret_offset (AtkText *text,
316 gint offset)
318 AtkTextIface *iface;
320 g_return_val_if_fail (text != NULL, FALSE);
321 g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
323 iface = ATK_TEXT_GET_IFACE (text);
325 if (iface->set_caret_offset)
327 return (*(iface->set_caret_offset)) (text, offset);
329 else
331 return FALSE;