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