atk/atkaction.c, atk/atkcomponent.c, atk/atkeditabletext.c,
[platform/upstream/atk.git] / atk / atkeditabletext.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 "atkeditabletext.h"
21
22
23 struct _AtkEditableTextIfaceClass
24 {
25   GObjectClass parent;
26 };
27
28 typedef struct _AtkEditableTextIfaceClass AtkEditableTextIfaceClass;
29
30 GType
31 atk_editable_text_get_type ()
32 {
33   static GType type = 0;
34
35   if (!type) {
36     static const GTypeInfo tinfo =
37     {
38       sizeof (AtkEditableTextIface),
39       (GBaseInitFunc) NULL,
40       (GBaseFinalizeFunc) NULL,
41
42     };
43
44     type = g_type_register_static (G_TYPE_INTERFACE, "AtkEditableText", &tinfo, 0);
45   }
46
47   return type;
48 }
49
50
51 /**
52  * atk_editable_text_select_text:
53  * @text: an #AtkEditableText
54  * @start_pos: start position
55  * @end_pos: end position
56  *
57  * Select text between @start_pos and @end_pos. The characters that are selected
58  * are those characters at positions from @start_pos up to, but not including
59  * @end_pos. If @end_pos is negative, then the characters selected 
60  * will be those characters from start_pos to the end of the text.
61  **/
62 void 
63 atk_editable_text_select_text (AtkEditableText  *text,
64                                gint             start_pos,
65                                gint             end_pos)
66 {
67   AtkEditableTextIface *iface;
68
69   g_return_if_fail (text != NULL);
70   g_return_if_fail (ATK_IS_EDITABLE_TEXT (text));
71
72   iface = ATK_EDITABLE_TEXT_GET_IFACE (text);
73
74   if (iface->select_text)
75     (*(iface->select_text)) (text, start_pos, end_pos);
76 }
77
78 /**
79  * atk_editable_text_set_attributes:
80  * @text: an #AtkEditableText
81  * @start_pos: start position
82  * @end_pos: end position
83  * @attributes: a #PangoAttrList to set for text between @start_pos and @end_pos
84  *
85  * Set attributes for text between @start_pos and @end_pos.  The characters
86  * whose attributes are set are those characters at positions from @start_pos
87  * up to, but not including @end_pos. If @end_pos is negative, then the
88  * characters selected will be those characters from start_pos to 
89  * the end of the text.
90  **/
91 void 
92 atk_editable_text_set_attributes (AtkEditableText  *text,
93                                   gint             start_pos,
94                                   gint             end_pos,
95                                   PangoAttrList    *attributes)
96 {
97   AtkEditableTextIface *iface;
98
99   g_return_if_fail (text != NULL);
100   g_return_if_fail (ATK_IS_EDITABLE_TEXT (text));
101
102   iface = ATK_EDITABLE_TEXT_GET_IFACE (text);
103
104   if (iface->set_attributes)
105     (*(iface->set_attributes)) (text, start_pos, end_pos, attributes);
106 }
107
108 /**
109  * atk_editable_text_set_text_contents:
110  * @text: an #AtkEditableText
111  * @string: string to set for text contents of @text
112  *
113  * Set text contents of @text
114  **/
115 void 
116 atk_editable_text_set_text_contents (AtkEditableText  *text,
117                                      const gchar      *string)
118 {
119   AtkEditableTextIface *iface;
120
121   g_return_if_fail (text != NULL);
122   g_return_if_fail (ATK_IS_EDITABLE_TEXT (text));
123
124   iface = ATK_EDITABLE_TEXT_GET_IFACE (text);
125
126   if (iface->set_text_contents)
127     (*(iface->set_text_contents)) (text, string);
128 }
129
130 /**
131  * atk_editable_text_insert_text:
132  * @text: an #AtkEditableText
133  * @string: the text to insert
134  * @length: the length of text to insert, in bytes
135  * @position: The caller initializes this to 
136  * the position at which to insert the text. After the call it
137  * points at the position after the newly inserted text.
138  *
139  * Insert text at a given position
140  **/
141 void 
142 atk_editable_text_insert_text (AtkEditableText  *text,
143                                const gchar      *string,
144                                gint             length,
145                                gint             *position)
146 {
147   AtkEditableTextIface *iface;
148
149   g_return_if_fail (text != NULL);
150   g_return_if_fail (ATK_IS_EDITABLE_TEXT (text));
151
152   iface = ATK_EDITABLE_TEXT_GET_IFACE (text);
153
154   if (iface->insert_text)
155     (*(iface->insert_text)) (text, string, length, position);
156 }
157
158 /**
159  * atk_editable_text_copy_text:
160  * @text: an #AtkEditableText
161  * @start_pos: start position
162  * @end_pos: end position
163  *
164  * Copy text from @start_pos up to, but not including @end_pos 
165  * to the clipboard.
166  **/
167 void 
168 atk_editable_text_copy_text (AtkEditableText  *text,
169                              gint             start_pos,
170                              gint             end_pos)
171 {
172   AtkEditableTextIface *iface;
173
174   g_return_if_fail (text != NULL);
175   g_return_if_fail (ATK_IS_EDITABLE_TEXT (text));
176
177   iface = ATK_EDITABLE_TEXT_GET_IFACE (text);
178
179   if (iface->copy_text)
180     (*(iface->copy_text)) (text, start_pos, end_pos);
181 }
182
183 /**
184  * atk_editable_text_cut_text:
185  * @text: an #AtkEditableText
186  * @start_pos: start position
187  * @end_pos: end position
188  *
189  * Copy text from @start_pos up to, but not including @end_pos
190  * to the clipboard and then delete from the widget.
191  **/
192 void 
193 atk_editable_text_cut_text  (AtkEditableText  *text,
194                              gint             start_pos,
195                              gint             end_pos)
196 {
197   AtkEditableTextIface *iface;
198
199   g_return_if_fail (text != NULL);
200   g_return_if_fail (ATK_IS_EDITABLE_TEXT (text));
201
202   iface = ATK_EDITABLE_TEXT_GET_IFACE (text);
203
204   if (iface->cut_text)
205     (*(iface->cut_text)) (text, start_pos, end_pos);
206 }
207
208 /**
209  * atk_editable_text_delete_text:
210  * @text: an #AtkEditableText
211  * @start_pos: start position
212  * @end_pos: end position
213  *
214  * Delete text @start_pos up to, but not including @end_pos
215  **/
216 void 
217 atk_editable_text_delete_text (AtkEditableText  *text,
218                                gint             start_pos,
219                                gint             end_pos)
220 {
221   AtkEditableTextIface *iface;
222
223   g_return_if_fail (text != NULL);
224   g_return_if_fail (ATK_IS_EDITABLE_TEXT (text));
225
226   iface = ATK_EDITABLE_TEXT_GET_IFACE (text);
227
228   if (iface->delete_text)
229     (*(iface->delete_text)) (text, start_pos, end_pos);
230 }
231
232 /**
233  * atk_editable_text_paste_text:
234  * @text: an #AtkEditableText
235  * @position: position to paste
236  *
237  * Paste text from clipboard to specified @position 
238  **/
239 void 
240 atk_editable_text_paste_text (AtkEditableText  *text,
241                               gint             position)
242 {
243   AtkEditableTextIface *iface;
244
245   g_return_if_fail (text != NULL);
246   g_return_if_fail (ATK_IS_EDITABLE_TEXT (text));
247
248   iface = ATK_EDITABLE_TEXT_GET_IFACE (text);
249
250   if (iface->paste_text)
251     (*(iface->paste_text)) (text, position);
252 }