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