Added new logic for handling multiple select regions to atktext.[ch].
[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_attributes:
52  * @text: an #AtkEditableText
53  * @start_pos: start position
54  * @end_pos: end position
55  * @attributes: a #PangoAttrList to set for text between @start_pos and @end_pos
56  *
57  * Set attributes for text between @start_pos and @end_pos.  The characters
58  * whose attributes are set are those characters at positions from @start_pos
59  * up to, but not including @end_pos. If @end_pos is negative, then the
60  * characters selected will be those characters from start_pos to 
61  * the end of the text.
62  **/
63 void 
64 atk_editable_text_set_attributes (AtkEditableText  *text,
65                                   gint             start_pos,
66                                   gint             end_pos,
67                                   PangoAttrList    *attributes)
68 {
69   AtkEditableTextIface *iface;
70
71   g_return_if_fail (text != NULL);
72   g_return_if_fail (ATK_IS_EDITABLE_TEXT (text));
73
74   iface = ATK_EDITABLE_TEXT_GET_IFACE (text);
75
76   if (iface->set_attributes)
77     (*(iface->set_attributes)) (text, start_pos, end_pos, attributes);
78 }
79
80 /**
81  * atk_editable_text_set_text_contents:
82  * @text: an #AtkEditableText
83  * @string: string to set for text contents of @text
84  *
85  * Set text contents of @text
86  **/
87 void 
88 atk_editable_text_set_text_contents (AtkEditableText  *text,
89                                      const gchar      *string)
90 {
91   AtkEditableTextIface *iface;
92
93   g_return_if_fail (text != NULL);
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 (text != NULL);
122   g_return_if_fail (ATK_IS_EDITABLE_TEXT (text));
123
124   iface = ATK_EDITABLE_TEXT_GET_IFACE (text);
125
126   if (iface->insert_text)
127     (*(iface->insert_text)) (text, string, length, position);
128 }
129
130 /**
131  * atk_editable_text_copy_text:
132  * @text: an #AtkEditableText
133  * @start_pos: start position
134  * @end_pos: end position
135  *
136  * Copy text from @start_pos up to, but not including @end_pos 
137  * to the clipboard.
138  **/
139 void 
140 atk_editable_text_copy_text (AtkEditableText  *text,
141                              gint             start_pos,
142                              gint             end_pos)
143 {
144   AtkEditableTextIface *iface;
145
146   g_return_if_fail (text != NULL);
147   g_return_if_fail (ATK_IS_EDITABLE_TEXT (text));
148
149   iface = ATK_EDITABLE_TEXT_GET_IFACE (text);
150
151   if (iface->copy_text)
152     (*(iface->copy_text)) (text, start_pos, end_pos);
153 }
154
155 /**
156  * atk_editable_text_cut_text:
157  * @text: an #AtkEditableText
158  * @start_pos: start position
159  * @end_pos: end position
160  *
161  * Copy text from @start_pos up to, but not including @end_pos
162  * to the clipboard and then delete from the widget.
163  **/
164 void 
165 atk_editable_text_cut_text  (AtkEditableText  *text,
166                              gint             start_pos,
167                              gint             end_pos)
168 {
169   AtkEditableTextIface *iface;
170
171   g_return_if_fail (text != NULL);
172   g_return_if_fail (ATK_IS_EDITABLE_TEXT (text));
173
174   iface = ATK_EDITABLE_TEXT_GET_IFACE (text);
175
176   if (iface->cut_text)
177     (*(iface->cut_text)) (text, start_pos, end_pos);
178 }
179
180 /**
181  * atk_editable_text_delete_text:
182  * @text: an #AtkEditableText
183  * @start_pos: start position
184  * @end_pos: end position
185  *
186  * Delete text @start_pos up to, but not including @end_pos
187  **/
188 void 
189 atk_editable_text_delete_text (AtkEditableText  *text,
190                                gint             start_pos,
191                                gint             end_pos)
192 {
193   AtkEditableTextIface *iface;
194
195   g_return_if_fail (text != NULL);
196   g_return_if_fail (ATK_IS_EDITABLE_TEXT (text));
197
198   iface = ATK_EDITABLE_TEXT_GET_IFACE (text);
199
200   if (iface->delete_text)
201     (*(iface->delete_text)) (text, start_pos, end_pos);
202 }
203
204 /**
205  * atk_editable_text_paste_text:
206  * @text: an #AtkEditableText
207  * @position: position to paste
208  *
209  * Paste text from clipboard to specified @position 
210  **/
211 void 
212 atk_editable_text_paste_text (AtkEditableText  *text,
213                               gint             position)
214 {
215   AtkEditableTextIface *iface;
216
217   g_return_if_fail (text != NULL);
218   g_return_if_fail (ATK_IS_EDITABLE_TEXT (text));
219
220   iface = ATK_EDITABLE_TEXT_GET_IFACE (text);
221
222   if (iface->paste_text)
223     (*(iface->paste_text)) (text, position);
224 }