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