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