Temporarily removed class initializer for AtkText from type_info struct, awaiting
[platform/upstream/atk.git] / atk / atktext.c
1 /* ATK - The Accessibility Toolkit for GTK+
2  * Copyright 2001 Sun Microsystems Inc.
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #include "atktext.h"
21
22 enum {
23   TEXT_CHANGED,
24   CARET_MOVED,
25   LAST_SIGNAL
26 };
27
28 struct _AtkTextIfaceClass
29 {
30   GObjectClass parent;
31 };
32
33 typedef struct _AtkTextIfaceClass AtkTextIfaceClass;
34
35 static void atk_text_interface_init (AtkTextIfaceClass *klass);
36
37 static gpointer parent_class = NULL;
38
39 static guint atk_text_signals[LAST_SIGNAL] = { 0, 0, 0};
40
41 GType
42 atk_text_get_type ()
43 {
44   static GType type = 0;
45
46   if (!type) 
47     {
48       static const GTypeInfo tinfo =
49       {
50         sizeof (AtkTextIface),
51         (GBaseInitFunc) NULL,
52         (GBaseFinalizeFunc) NULL,
53         (GClassInitFunc) NULL /* atk_text_interface_init */ ,
54         (GClassFinalizeFunc) NULL,
55
56       };
57
58       type = g_type_register_static (G_TYPE_INTERFACE, "AtkText", &tinfo, 0);
59     }
60
61   return type;
62 }
63
64 /*
65  * Additional GObject properties exported by AtkText:
66  *    "accessible_text" (accessible text has changed)
67  *    "accessible_caret" (accessible text cursor position changed:
68  *                         editable text only)
69  */
70
71 static void
72 atk_text_interface_init (AtkTextIfaceClass *klass)
73 {
74   parent_class = g_type_class_ref (G_TYPE_OBJECT);
75
76   /* 
77    * Note that text_changed signal supports details "insert", "delete", 
78    * possibly "replace". 
79    */
80
81   atk_text_signals[TEXT_CHANGED] =
82     g_signal_newc ("text_changed",
83                    G_TYPE_FROM_CLASS (klass),
84                    G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
85                    G_STRUCT_OFFSET (AtkTextIface, text_changed), 
86                    NULL,
87                    g_cclosure_marshal_VOID__VOID,
88                    G_TYPE_NONE,
89                    0, G_TYPE_NONE);
90
91   atk_text_signals[CARET_MOVED] =
92     g_signal_newc ("text_caret_moved",
93                    G_TYPE_FROM_CLASS (klass),
94                    G_SIGNAL_RUN_LAST,
95                    G_STRUCT_OFFSET (AtkTextIface, caret_changed),
96                    NULL,
97                    g_cclosure_marshal_VOID__INT,
98                    G_TYPE_NONE,
99                    1, G_TYPE_INT);
100 }
101
102 gchar*
103 atk_text_get_text (AtkText      *text,
104                    gint         start_offset,
105                    gint         end_offset)
106 {
107   AtkTextIface *iface;
108
109   g_return_val_if_fail (text != NULL, NULL);
110   g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
111
112   iface = ATK_TEXT_GET_IFACE (text);
113
114   if (iface->get_text)
115     return (*(iface->get_text)) (text, start_offset, end_offset);
116   else
117     return NULL;
118 }
119
120 gunichar
121 atk_text_get_character_at_offset (AtkText      *text,
122                                   gint         offset)
123 {
124   AtkTextIface *iface;
125
126   g_return_val_if_fail (text != NULL, (gunichar) 0);
127   g_return_val_if_fail (ATK_IS_TEXT (text), (gunichar) 0);
128
129   iface = ATK_TEXT_GET_IFACE (text);
130
131   if (iface->get_character_at_offset)
132     return (*(iface->get_character_at_offset)) (text, offset);
133   else
134     return (gunichar) 0;
135 }
136
137 gchar*
138 atk_text_get_text_after_offset (AtkText          *text,
139                                 gint             offset,
140                                 AtkTextBoundary  boundary_type)
141 {
142   AtkTextIface *iface;
143
144   g_return_val_if_fail (text != NULL, NULL);
145   g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
146
147   iface = ATK_TEXT_GET_IFACE (text);
148
149   if (iface->get_text_after_offset)
150     return (*(iface->get_text_after_offset)) (text, offset, boundary_type);
151   else
152     return NULL;
153 }
154
155 gchar*
156 atk_text_get_text_at_offset (AtkText          *text,
157                              gint             offset,
158                              AtkTextBoundary  boundary_type)
159 {
160   AtkTextIface *iface;
161
162   g_return_val_if_fail (text != NULL, NULL);
163   g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
164
165   iface = ATK_TEXT_GET_IFACE (text);
166
167   if (iface->get_text_at_offset)
168     return (*(iface->get_text_at_offset)) (text, offset, boundary_type);
169   else
170     return NULL;
171 }
172
173 gchar*
174 atk_text_get_text_before_offset (AtkText          *text,
175                                  gint             offset,
176                                  AtkTextBoundary  boundary_type)
177 {
178   AtkTextIface *iface;
179
180   g_return_val_if_fail (text != NULL, NULL);
181   g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
182
183   iface = ATK_TEXT_GET_IFACE (text);
184
185   if (iface->get_text_before_offset)
186     return (*(iface->get_text_before_offset)) (text, offset, boundary_type);
187   else
188     return NULL;
189 }
190
191 gint
192 atk_text_get_caret_offset (AtkText *text)
193 {
194   AtkTextIface *iface;
195
196   g_return_val_if_fail (text != NULL, -1);
197   g_return_val_if_fail (ATK_IS_TEXT (text), -1);
198
199   iface = ATK_TEXT_GET_IFACE (text);
200
201   if (iface->get_caret_offset)
202     return (*(iface->get_caret_offset)) (text);
203   else
204     return -1;
205 }
206
207 void
208 atk_text_get_row_col_at_offset (AtkText *text,
209                                 gint offset,
210                                 gint *row,
211                                 gint *col)
212 {
213   AtkTextIface *iface;
214
215   g_return_if_fail (text != NULL);
216   g_return_if_fail (ATK_IS_TEXT (text));
217
218   iface = ATK_TEXT_GET_IFACE (text);
219
220   if (iface->get_row_col_at_offset)
221     (*(iface->get_row_col_at_offset)) (text, offset, row, col);
222   else
223     {
224       *row = 0;
225       *col = 0;
226     }
227 }
228
229 PangoAttrList*
230 atk_text_get_range_attributes (AtkText *text,
231                                gint start_offset,
232                                gint end_offset)
233 {
234   AtkTextIface *iface;
235
236   g_return_val_if_fail (text != NULL, NULL);
237   g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
238
239   iface = ATK_TEXT_GET_IFACE (text);
240
241   if (iface->get_range_attributes)
242     return (*(iface->get_range_attributes)) (text, start_offset, end_offset);
243   else
244     return NULL;
245 }
246
247 void
248 atk_text_get_character_extents (AtkText *text,
249                                 gint offset,
250                                 gint *x,
251                                 gint *y,
252                                 gint *length,
253                                 gint *width)
254 {
255   AtkTextIface *iface;
256
257   g_return_if_fail (text != NULL);
258   g_return_if_fail (ATK_IS_TEXT (text));
259
260   iface = ATK_TEXT_GET_IFACE (text);
261
262   if (iface->get_character_extents)
263     (*(iface->get_character_extents)) (text, offset, x, y, length, width);
264   else
265     {
266       *x = 0;
267       *x = 0;
268       *length = 0;
269       *width = 0;
270     }
271 }
272
273 gint
274 atk_text_get_character_count (AtkText *text)
275 {
276   AtkTextIface *iface;
277
278   g_return_val_if_fail (text != NULL, -1);
279   g_return_val_if_fail (ATK_IS_TEXT (text), -1);
280
281   iface = ATK_TEXT_GET_IFACE (text);
282
283   if (iface->get_character_count)
284     return (*(iface->get_character_count)) (text);
285   else
286     return -1;
287 }
288
289 gint
290 atk_text_get_offset_at_point (AtkText *text,
291                               gint x,
292                               gint y)
293 {
294   AtkTextIface *iface;
295
296   g_return_val_if_fail (text != NULL, -1);
297   g_return_val_if_fail (ATK_IS_TEXT (text), -1);
298
299   iface = ATK_TEXT_GET_IFACE (text);
300
301   if (iface->get_offset_at_point)
302     return (*(iface->get_offset_at_point)) (text, x, y);
303   else
304     return -1;
305 }
306
307 gchar*
308 atk_text_get_selected_text (AtkText *text)
309 {
310   AtkTextIface *iface;
311
312   g_return_val_if_fail (text != NULL, NULL);
313   g_return_val_if_fail (ATK_IS_TEXT (text), NULL);
314
315   iface = ATK_TEXT_GET_IFACE (text);
316
317   if (iface->get_selected_text)
318     return (*(iface->get_selected_text)) (text);
319   else
320     return NULL;
321 }
322
323 void
324 atk_text_get_selection_bounds (AtkText *text,
325                                gint    *start_offset,
326                                gint    *end_offset)
327 {
328   AtkTextIface *iface;
329
330   g_return_if_fail (text != NULL);
331   g_return_if_fail (ATK_IS_TEXT (text));
332
333   iface = ATK_TEXT_GET_IFACE (text);
334
335   if (iface->get_selection_bounds)
336     (*(iface->get_selection_bounds)) (text, start_offset, end_offset);
337   else
338   {
339     *start_offset = 0;
340     *end_offset = 0;
341   }
342 }
343
344 gboolean
345 atk_text_set_selection_bounds (AtkText *text,
346                                gint    start_offset,
347                                gint    end_offset)
348 {
349   AtkTextIface *iface;
350
351   g_return_val_if_fail (text != NULL, FALSE);
352   g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
353
354   iface = ATK_TEXT_GET_IFACE (text);
355
356   if (iface->set_selection_bounds)
357     {
358       return (*(iface->set_selection_bounds)) (text, start_offset, end_offset);
359     }
360   else
361     {
362       return FALSE;
363     }
364 }
365
366 gboolean
367 atk_text_set_caret_offset (AtkText *text,
368                            gint    offset)
369 {
370   AtkTextIface *iface;
371
372   g_return_val_if_fail (text != NULL, FALSE);
373   g_return_val_if_fail (ATK_IS_TEXT (text), FALSE);
374
375   iface = ATK_TEXT_GET_IFACE (text);
376
377   if (iface->set_caret_offset)
378     {
379       return (*(iface->set_caret_offset)) (text, offset);
380     }
381   else
382     {
383       return FALSE;
384     }
385 }