* accessible.py (_getAndCache): Cleaned up: Fixed indent width and
[platform/core/uifw/at-spi2-atk.git] / libspi / editabletext.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2001, 2002 Sun Microsystems Inc.,
6  * Copyright 2001, 2002 Ximian, Inc.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23
24 /* editabletext.c : implements the EditableText interface */
25
26 #include <config.h>
27 #include <stdio.h>
28 #include <atk/atkeditabletext.h>
29 #include <libspi/editabletext.h>
30
31 /* Static function declarations */
32
33 static void
34 spi_editable_text_class_init (SpiEditableTextClass *klass);
35 static void
36 spi_editable_text_init (SpiEditableText *editable);
37 static CORBA_boolean
38 impl_setAttributes (PortableServer_Servant servant,
39                        const CORBA_char * attributes,
40                        const CORBA_long startPos,
41                        const CORBA_long endPos,
42                        CORBA_Environment *ev);
43 static CORBA_boolean
44 impl_setTextContents (PortableServer_Servant servant,
45                       const CORBA_char * newContents,
46                       CORBA_Environment *ev);
47 static CORBA_boolean 
48 impl_insertText (PortableServer_Servant servant,
49                  const CORBA_long position,
50                  const CORBA_char * text,
51                  const CORBA_long length,
52                  CORBA_Environment *ev);
53 static void 
54 impl_copyText (PortableServer_Servant servant,
55                const CORBA_long startPos, const CORBA_long endPos,
56                CORBA_Environment *ev);
57 static CORBA_boolean
58 impl_cutText (PortableServer_Servant servant,
59               const CORBA_long startPos, const CORBA_long endPos,
60               CORBA_Environment *ev);
61 static CORBA_boolean
62 impl_deleteText (PortableServer_Servant servant,
63                  const CORBA_long startPos, const CORBA_long endPos,
64                  CORBA_Environment *ev);
65 static CORBA_boolean
66 impl_pasteText (PortableServer_Servant servant,
67                 const CORBA_long position, CORBA_Environment *ev);
68
69 BONOBO_TYPE_FUNC_FULL (SpiEditableText,
70                        Accessibility_EditableText,
71                        SPI_TEXT_TYPE,
72                        spi_editable_text)
73
74 static void
75 spi_editable_text_class_init (SpiEditableTextClass *klass)
76 {
77   POA_Accessibility_EditableText__epv *epv = &klass->epv;
78
79   /* Initialize epv table */
80
81   epv->setAttributes = impl_setAttributes;
82   epv->setTextContents = impl_setTextContents;
83   epv->insertText = impl_insertText;
84   epv->copyText = impl_copyText;
85   epv->cutText = impl_cutText;
86   epv->deleteText = impl_deleteText;
87   epv->pasteText = impl_pasteText;
88 }
89
90
91 static void
92 spi_editable_text_init (SpiEditableText *editable)
93 {
94 }
95
96
97 SpiEditableText *
98 spi_editable_text_interface_new (AtkObject *obj)
99 {
100   SpiEditableText *new_editable = g_object_new (
101           SPI_EDITABLE_TEXT_TYPE, NULL);
102
103   spi_text_construct (SPI_TEXT (new_editable), obj);
104
105   return new_editable;
106 }
107
108
109 static AtkEditableText *
110 get_editable_text_from_servant (PortableServer_Servant servant)
111 {
112   SpiBase *object = SPI_BASE (bonobo_object_from_servant (servant));
113
114   g_return_val_if_fail (object, NULL);
115   g_return_val_if_fail (ATK_IS_OBJECT(object->gobj), NULL);
116   return ATK_EDITABLE_TEXT (object->gobj);
117 }
118
119
120 static CORBA_boolean
121 impl_setAttributes (PortableServer_Servant servant,
122                     const CORBA_char * attributes,
123                     const CORBA_long startPos,
124                     const CORBA_long endPos,
125                     CORBA_Environment *ev)
126 {
127   AtkEditableText *editable = get_editable_text_from_servant (servant);
128
129   g_return_val_if_fail (editable != NULL, FALSE);
130
131   g_print ("setRunAttributes not implemented.\n");
132
133   return FALSE;
134 }
135
136
137 static CORBA_boolean
138 impl_setTextContents (PortableServer_Servant servant,
139                       const CORBA_char     *newContents,
140                       CORBA_Environment    *ev)
141 {
142   AtkEditableText *editable = get_editable_text_from_servant (servant);
143
144   g_return_val_if_fail (editable != NULL, FALSE);
145   
146   atk_editable_text_set_text_contents (editable, newContents);
147
148   return TRUE;
149 }
150
151
152 static CORBA_boolean
153 impl_insertText (PortableServer_Servant servant,
154                  const CORBA_long      position,
155                  const CORBA_char     *text,
156                  const CORBA_long      length,
157                  CORBA_Environment    *ev)
158 {
159   AtkEditableText *editable = get_editable_text_from_servant (servant);
160   gint ip;
161
162   g_return_val_if_fail (editable != NULL, FALSE);
163
164   ip = position;
165   atk_editable_text_insert_text (editable,
166                                  text,
167                                  length,
168                                  &ip);
169   return TRUE;
170 }
171
172
173 static void 
174 impl_copyText (PortableServer_Servant servant,
175                const CORBA_long startPos, const CORBA_long endPos,
176                CORBA_Environment *ev)
177 {
178   AtkEditableText *editable = get_editable_text_from_servant (servant);
179
180   g_return_if_fail (editable != NULL);
181
182   atk_editable_text_copy_text (editable, startPos, endPos);
183   
184 }
185
186
187 static CORBA_boolean
188 impl_cutText (PortableServer_Servant servant,
189               const CORBA_long startPos, const CORBA_long endPos,
190               CORBA_Environment *ev)
191 {
192   AtkEditableText *editable = get_editable_text_from_servant (servant);
193
194   g_return_val_if_fail (editable != NULL, FALSE);
195
196   atk_editable_text_cut_text (editable, startPos, endPos);
197
198   return TRUE;
199 }
200
201
202 static CORBA_boolean
203 impl_deleteText (PortableServer_Servant servant,
204                  const CORBA_long startPos, const CORBA_long endPos,
205                  CORBA_Environment *ev)
206 {
207   AtkEditableText *editable = get_editable_text_from_servant (servant);
208
209   g_return_val_if_fail (editable != NULL, FALSE);
210
211   atk_editable_text_delete_text (editable, startPos, endPos);
212
213   return TRUE;
214 }
215
216
217 static CORBA_boolean
218 impl_pasteText (PortableServer_Servant servant,
219                 const CORBA_long position, CORBA_Environment *ev)
220 {
221   AtkEditableText *editable = get_editable_text_from_servant (servant);
222
223   g_return_val_if_fail (editable != NULL, FALSE);
224
225   atk_editable_text_paste_text (editable, position);
226
227   return TRUE;
228 }