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