2.51.90
[platform/upstream/at-spi2-core.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 "config.h"
21
22 #include "atkeditabletext.h"
23
24 /**
25  * AtkEditableText:
26  *
27  * The ATK interface implemented by components containing user-editable text content.
28  *
29  * #AtkEditableText should be implemented by UI components which
30  * contain text which the user can edit, via the #AtkObject
31  * corresponding to that component (see #AtkObject).
32  *
33  * #AtkEditableText is a subclass of #AtkText, and as such, an object
34  * which implements #AtkEditableText is by definition an #AtkText
35  * implementor as well.
36  *
37  * See [iface@AtkText]
38  */
39
40 GType
41 atk_editable_text_get_type (void)
42 {
43   static GType type = 0;
44
45   if (!type)
46     {
47       static const GTypeInfo tinfo = {
48         sizeof (AtkEditableTextIface),
49         (GBaseInitFunc) NULL,
50         (GBaseFinalizeFunc) NULL,
51
52       };
53
54       type = g_type_register_static (G_TYPE_INTERFACE, "AtkEditableText", &tinfo, 0);
55     }
56
57   return type;
58 }
59
60 /**
61  *atk_editable_text_set_run_attributes:
62  *@text: an #AtkEditableText
63  *@attrib_set: an #AtkAttributeSet
64  *@start_offset: start of range in which to set attributes
65  *@end_offset: end of range in which to set attributes
66  *
67  *Sets the attributes for a specified range. See the ATK_ATTRIBUTE
68  *macros (such as #ATK_ATTRIBUTE_LEFT_MARGIN) for examples of attributes
69  *that can be set. Note that other attributes that do not have corresponding
70  *ATK_ATTRIBUTE macros may also be set for certain text widgets.
71  *
72  *Returns: %TRUE if attributes successfully set for the specified
73  *range, otherwise %FALSE
74  **/
75 gboolean
76 atk_editable_text_set_run_attributes (AtkEditableText *text,
77                                       AtkAttributeSet *attrib_set,
78                                       gint start_offset,
79                                       gint end_offset)
80 {
81   AtkEditableTextIface *iface;
82
83   g_return_val_if_fail (ATK_IS_EDITABLE_TEXT (text), FALSE);
84
85   iface = ATK_EDITABLE_TEXT_GET_IFACE (text);
86
87   if (iface->set_run_attributes)
88     {
89       return (*(iface->set_run_attributes)) (text, attrib_set, start_offset, end_offset);
90     }
91   else
92     {
93       return FALSE;
94     }
95 }
96
97 /**
98  * atk_editable_text_set_text_contents:
99  * @text: an #AtkEditableText
100  * @string: string to set for text contents of @text
101  *
102  * Set text contents of @text.
103  **/
104 void
105 atk_editable_text_set_text_contents (AtkEditableText *text,
106                                      const gchar *string)
107 {
108   AtkEditableTextIface *iface;
109
110   g_return_if_fail (ATK_IS_EDITABLE_TEXT (text));
111
112   iface = ATK_EDITABLE_TEXT_GET_IFACE (text);
113
114   if (iface->set_text_contents)
115     (*(iface->set_text_contents)) (text, string);
116 }
117
118 /**
119  * atk_editable_text_insert_text:
120  * @text: an #AtkEditableText
121  * @string: the text to insert
122  * @length: the length of text to insert, in bytes
123  * @position: The caller initializes this to
124  * the position at which to insert the text. After the call it
125  * points at the position after the newly inserted text.
126  *
127  * Insert text at a given position.
128  **/
129 void
130 atk_editable_text_insert_text (AtkEditableText *text,
131                                const gchar *string,
132                                gint length,
133                                gint *position)
134 {
135   AtkEditableTextIface *iface;
136
137   g_return_if_fail (ATK_IS_EDITABLE_TEXT (text));
138
139   iface = ATK_EDITABLE_TEXT_GET_IFACE (text);
140
141   if (iface->insert_text)
142     (*(iface->insert_text)) (text, string, length, position);
143 }
144
145 /**
146  * atk_editable_text_copy_text:
147  * @text: an #AtkEditableText
148  * @start_pos: start position
149  * @end_pos: end position
150  *
151  * Copy text from @start_pos up to, but not including @end_pos
152  * to the clipboard.
153  **/
154 void
155 atk_editable_text_copy_text (AtkEditableText *text,
156                              gint start_pos,
157                              gint end_pos)
158 {
159   AtkEditableTextIface *iface;
160
161   g_return_if_fail (ATK_IS_EDITABLE_TEXT (text));
162
163   iface = ATK_EDITABLE_TEXT_GET_IFACE (text);
164
165   if (iface->copy_text)
166     (*(iface->copy_text)) (text, start_pos, end_pos);
167 }
168
169 /**
170  * atk_editable_text_cut_text:
171  * @text: an #AtkEditableText
172  * @start_pos: start position
173  * @end_pos: end position
174  *
175  * Copy text from @start_pos up to, but not including @end_pos
176  * to the clipboard and then delete from the widget.
177  **/
178 void
179 atk_editable_text_cut_text (AtkEditableText *text,
180                             gint start_pos,
181                             gint end_pos)
182 {
183   AtkEditableTextIface *iface;
184
185   g_return_if_fail (ATK_IS_EDITABLE_TEXT (text));
186
187   iface = ATK_EDITABLE_TEXT_GET_IFACE (text);
188
189   if (iface->cut_text)
190     (*(iface->cut_text)) (text, start_pos, end_pos);
191 }
192
193 /**
194  * atk_editable_text_delete_text:
195  * @text: an #AtkEditableText
196  * @start_pos: start position
197  * @end_pos: end position
198  *
199  * Delete text @start_pos up to, but not including @end_pos.
200  **/
201 void
202 atk_editable_text_delete_text (AtkEditableText *text,
203                                gint start_pos,
204                                gint end_pos)
205 {
206   AtkEditableTextIface *iface;
207
208   g_return_if_fail (ATK_IS_EDITABLE_TEXT (text));
209
210   iface = ATK_EDITABLE_TEXT_GET_IFACE (text);
211
212   if (iface->delete_text)
213     (*(iface->delete_text)) (text, start_pos, end_pos);
214 }
215
216 /**
217  * atk_editable_text_paste_text:
218  * @text: an #AtkEditableText
219  * @position: position to paste
220  *
221  * Paste text from clipboard to specified @position.
222  **/
223 void
224 atk_editable_text_paste_text (AtkEditableText *text,
225                               gint position)
226 {
227   AtkEditableTextIface *iface;
228
229   g_return_if_fail (ATK_IS_EDITABLE_TEXT (text));
230
231   iface = ATK_EDITABLE_TEXT_GET_IFACE (text);
232
233   if (iface->paste_text)
234     (*(iface->paste_text)) (text, position);
235 }