Fixed refcounting issues with interface server
[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   g_object_unref (editable->atko);
153   editable->atko = NULL;
154   parent_class->finalize (obj);
155 }
156
157 EditableText *
158 editable_text_interface_new (AtkObject *obj)
159 {
160   EditableText *new_editable =
161     EDITABLE_TEXT(g_object_new (EDITABLE_TEXT_TYPE, NULL));
162   new_editable->atko = obj;
163   g_object_ref (obj);
164 return new_editable;
165 }
166
167
168
169 static CORBA_boolean
170 impl_setAttributes (PortableServer_Servant _servant,
171                        const CORBA_char * attributes,
172                        const CORBA_long startPos,
173                        const CORBA_long endPos,
174                                          CORBA_Environment * ev)
175 {
176   g_print ("setRunAttributes not implemented.\n");
177 }
178
179
180
181 static void
182 impl_setTextContents (PortableServer_Servant _servant,
183                       const CORBA_char * newContents,
184                       CORBA_Environment * ev)
185 {
186   EditableText *editable = EDITABLE_TEXT(bonobo_object_from_servant (_servant));
187   atk_editable_text_set_text_contents (ATK_EDITABLE_TEXT(editable->atko),
188                                        (gchar *) newContents);
189 }
190
191
192
193 static void 
194 impl_insertText (PortableServer_Servant _servant,
195                  const CORBA_long position,
196                  const CORBA_char * text,
197                  const CORBA_long length,
198                  CORBA_Environment * ev)
199 {
200   EditableText *editable = EDITABLE_TEXT (bonobo_object_from_servant(_servant));
201   atk_editable_text_insert_text (ATK_EDITABLE_TEXT(editable->atko),
202                                  (gchar *) text,
203                                  (gint) length,
204                                  (gint *) &position);
205 }
206
207
208 static void 
209 impl_copyText (PortableServer_Servant _servant,
210                const CORBA_long startPos, const CORBA_long endPos,
211                CORBA_Environment * ev)
212 {
213   EditableText *editable = EDITABLE_TEXT (bonobo_object_from_servant(_servant));
214   atk_editable_text_copy_text (ATK_EDITABLE_TEXT(editable->atko),
215                                (gint) startPos, (gint) endPos);
216 }
217
218
219
220 static void 
221 impl_cutText (PortableServer_Servant _servant,
222               const CORBA_long startPos, const CORBA_long endPos,
223               CORBA_Environment * ev)
224 {
225   EditableText *editable = EDITABLE_TEXT (bonobo_object_from_servant(_servant));
226   atk_editable_text_cut_text (ATK_EDITABLE_TEXT(editable->atko),
227                                  (gint) startPos, (gint) endPos);
228 }
229
230
231
232
233 static void 
234 impl_deleteText (PortableServer_Servant _servant,
235                  const CORBA_long startPos, const CORBA_long endPos,
236                  CORBA_Environment * ev)
237 {
238   EditableText *editable = EDITABLE_TEXT (bonobo_object_from_servant(_servant));
239   atk_editable_text_delete_text (ATK_EDITABLE_TEXT(editable->atko),
240                                  (gint) startPos, (gint) endPos);
241 }
242
243
244 static void
245 impl_pasteText (PortableServer_Servant _servant,
246                 const CORBA_long position, CORBA_Environment * ev)
247 {
248   EditableText *editable = EDITABLE_TEXT (bonobo_object_from_servant(_servant));
249   atk_editable_text_paste_text (ATK_EDITABLE_TEXT(editable->atko), position);
250 }
251