ecc8eddadf981b1bf3892c0c134a3ab76091b85c
[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 Sun Microsystems Inc.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 /*
24  * component.c : bonobo wrapper for accessible component implementation
25  *
26  */
27 #include <config.h>
28 #include <bonobo/Bonobo.h>
29
30 #include <stdio.h>
31
32 /*
33  * This pulls the CORBA definitions for the "Accessibility::Accessible" server
34  */
35 #include <libspi/Accessibility.h>
36
37 /*
38  * This pulls the definition of the EditableText bonobo object
39  */
40 #include "editabletext.h"
41
42 /*
43  * Static function declarations
44  */
45
46 static void
47 editable_text_class_init (EditableTextClass *klass);
48 static void
49 editable_text_init (EditableText *editable);
50 static void
51 editable_text_finalize (GObject *obj);
52 static CORBA_boolean
53 impl_setAttributes (PortableServer_Servant _servant,
54                        const CORBA_char * attributes,
55                        const CORBA_long startPos,
56                        const CORBA_long endPos,
57                        CORBA_Environment * ev);
58 static void
59 impl_setTextContents (PortableServer_Servant _servant,
60                       const CORBA_char * newContents,
61                       CORBA_Environment * ev);
62 static void 
63 impl_insertText (PortableServer_Servant _servant,
64                  const CORBA_long position,
65                  const CORBA_char * text,
66                  const CORBA_long length,
67                  CORBA_Environment * ev);
68 static void 
69 impl_copyText (PortableServer_Servant _servant,
70                const CORBA_long startPos, const CORBA_long endPos,
71                CORBA_Environment * ev);
72 static void 
73 impl_cutText (PortableServer_Servant _servant,
74               const CORBA_long startPos, const CORBA_long endPos,
75               CORBA_Environment * ev);
76 static void 
77 impl_deleteText (PortableServer_Servant _servant,
78                  const CORBA_long startPos, const CORBA_long endPos,
79                  CORBA_Environment * ev);
80 static void
81 impl_pasteText (PortableServer_Servant _servant,
82                 const CORBA_long position, CORBA_Environment * ev);
83
84 static GObjectClass *parent_class;
85
86 GType
87 editable_text_get_type (void)
88 {
89   static GType type = 0;
90
91   if (!type) {
92     static const GTypeInfo tinfo = {
93       sizeof (EditableTextClass),
94       (GBaseInitFunc) NULL,
95       (GBaseFinalizeFunc) NULL,
96       (GClassInitFunc) editable_text_class_init,
97       (GClassFinalizeFunc) NULL,
98       NULL, /* class data */
99       sizeof (EditableText),
100       0, /* n preallocs */
101       (GInstanceInitFunc) editable_text_init,
102                         NULL /* value table */
103     };
104
105     /*
106      * Bonobo_type_unique auto-generates a load of
107      * CORBA structures for us. All derived types must
108      * use bonobo_type_unique.
109      */
110     type = bonobo_type_unique (
111                                BONOBO_OBJECT_TYPE,
112                                POA_Accessibility_EditableText__init,
113                                NULL,
114                                G_STRUCT_OFFSET (EditableTextClass, epv),
115                                &tinfo,
116                                "AccessibleEditableText");
117   }
118
119   return type;
120 }
121
122 static void
123 editable_text_class_init (EditableTextClass *klass)
124 {
125   GObjectClass * object_class = (GObjectClass *) klass;
126   POA_Accessibility_EditableText__epv *epv = &klass->epv;
127   parent_class = g_type_class_peek_parent (klass);
128
129   object_class->finalize = editable_text_finalize;
130
131
132   /* Initialize epv table */
133
134   epv->setAttributes = impl_setAttributes;
135   epv->setTextContents = impl_setTextContents;
136   epv->insertText = impl_insertText;
137   epv->copyText = impl_copyText;
138   epv->cutText = impl_cutText;
139   epv->deleteText = impl_deleteText;
140   epv->pasteText = impl_pasteText;
141 }
142
143 static void
144 editable_text_init (EditableText *editable)
145 {
146 }
147
148 static void
149 editable_text_finalize (GObject *obj)
150 {
151   EditableText *editable = EDITABLE_TEXT(obj);
152   editable->atk_editable_text = NULL;
153   parent_class->finalize (obj);
154 }
155
156 EditableText *
157 editable_text_new (AtkEditableText *editable)
158 {
159   EditableText *new_editable =
160     EDITABLE_TEXT(g_object_new (EDITABLE_TEXT_TYPE, NULL));
161   new_editable->atk_editable_text = editable;
162   return new_editable;
163 }
164
165
166
167 static CORBA_boolean
168 impl_setAttributes (PortableServer_Servant _servant,
169                        const CORBA_char * attributes,
170                        const CORBA_long startPos,
171                        const CORBA_long endPos,
172                                          CORBA_Environment * ev)
173 {
174   g_print ("setRunAttributes not implemented.\n");
175 }
176
177
178
179 static void
180 impl_setTextContents (PortableServer_Servant _servant,
181                       const CORBA_char * newContents,
182                       CORBA_Environment * ev)
183 {
184   EditableText *editable = EDITABLE_TEXT(bonobo_object_from_servant (_servant));
185   atk_editable_text_set_text_contents (editable->atk_editable_text,
186                                        (gchar *) newContents);
187 }
188
189
190
191 static void 
192 impl_insertText (PortableServer_Servant _servant,
193                  const CORBA_long position,
194                  const CORBA_char * text,
195                  const CORBA_long length,
196                  CORBA_Environment * ev)
197 {
198   EditableText *editable = EDITABLE_TEXT (bonobo_object_from_servant(_servant));
199   atk_editable_text_insert_text (editable->atk_editable_text,
200                                  (gchar *) text,
201                                  (gint) length,
202                                  (gint *) &position);
203 }
204
205
206 static void 
207 impl_copyText (PortableServer_Servant _servant,
208                const CORBA_long startPos, const CORBA_long endPos,
209                CORBA_Environment * ev)
210 {
211   EditableText *editable = EDITABLE_TEXT (bonobo_object_from_servant(_servant));
212   atk_editable_text_copy_text (editable->atk_editable_text,
213                                (gint) startPos, (gint) endPos);
214 }
215
216
217
218 static void 
219 impl_cutText (PortableServer_Servant _servant,
220               const CORBA_long startPos, const CORBA_long endPos,
221               CORBA_Environment * ev)
222 {
223   EditableText *editable = EDITABLE_TEXT (bonobo_object_from_servant(_servant));
224   atk_editable_text_cut_text (editable->atk_editable_text,
225                                  (gint) startPos, (gint) endPos);
226 }
227
228
229
230
231 static void 
232 impl_deleteText (PortableServer_Servant _servant,
233                  const CORBA_long startPos, const CORBA_long endPos,
234                  CORBA_Environment * ev)
235 {
236   EditableText *editable = EDITABLE_TEXT (bonobo_object_from_servant(_servant));
237   atk_editable_text_delete_text (editable->atk_editable_text,
238                                  (gint) startPos, (gint) endPos);
239 }
240
241
242 static void
243 impl_pasteText (PortableServer_Servant _servant,
244                 const CORBA_long position, CORBA_Environment * ev)
245 {
246   EditableText *editable = EDITABLE_TEXT (bonobo_object_from_servant(_servant));
247   atk_editable_text_paste_text (editable->atk_editable_text, position);
248 }
249