Cleaned up some suspect int* casts, and added assertions to text calls in libspi
[platform/core/uifw/at-spi2-atk.git] / libspi / selection.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 selection bonobo object
39  */
40 #include "selection.h"
41
42 /*
43  * Static function declarations
44  */
45
46 static void
47 selection_class_init (SelectionClass *klass);
48 static void
49 selection_init (Selection *selection);
50 static void
51 selection_finalize (GObject *obj);
52 static CORBA_long
53 impl__get_nSelectedChildren (PortableServer_Servant _servant,
54                              CORBA_Environment * ev);
55 static Accessibility_Accessible
56 impl_getSelectedChild (PortableServer_Servant _servant,
57                        const CORBA_long selectedChildIndex,
58                        CORBA_Environment * ev);
59 static CORBA_boolean
60 impl_selectChild (PortableServer_Servant _servant,
61                   const CORBA_long childIndex,
62                   CORBA_Environment * ev);
63 static CORBA_boolean
64 impl_deselectSelectedChild (PortableServer_Servant _servant,
65                             const CORBA_long selectedChildIndex,
66                             CORBA_Environment * ev);
67 static CORBA_boolean
68 impl_isChildSelected (PortableServer_Servant _servant,
69                       const CORBA_long childIndex,
70                       CORBA_Environment * ev);
71 static void 
72 impl_selectAll (PortableServer_Servant _servant,
73                 CORBA_Environment * ev);
74 static void 
75 impl_clearSelection (PortableServer_Servant _servant,
76                      CORBA_Environment * ev);
77
78
79 static GObjectClass *parent_class;
80
81 GType
82 selection_get_type (void)
83 {
84   static GType type = 0;
85
86   if (!type) {
87     static const GTypeInfo tinfo = {
88       sizeof (SelectionClass),
89       (GBaseInitFunc) NULL,
90       (GBaseFinalizeFunc) NULL,
91       (GClassInitFunc) selection_class_init,
92       (GClassFinalizeFunc) NULL,
93       NULL, /* class data */
94       sizeof (Selection),
95       0, /* n preallocs */
96       (GInstanceInitFunc) selection_init,
97                         NULL /* value table */
98     };
99
100     /*
101      * Bonobo_type_unique auto-generates a load of
102      * CORBA structures for us. All derived types must
103      * use bonobo_type_unique.
104      */
105     type = bonobo_type_unique (
106                                BONOBO_OBJECT_TYPE,
107                                POA_Accessibility_Selection__init,
108                                NULL,
109                                G_STRUCT_OFFSET (SelectionClass, epv),
110                                &tinfo,
111                                "AccessibleSelection");
112   }
113
114   return type;
115 }
116
117 static void
118 selection_class_init (SelectionClass *klass)
119 {
120   GObjectClass * object_class = (GObjectClass *) klass;
121   POA_Accessibility_Selection__epv *epv = &klass->epv;
122   parent_class = g_type_class_peek_parent (klass);
123
124   object_class->finalize = selection_finalize;
125
126
127   /* Initialize epv table */
128
129   epv->_get_nSelectedChildren = impl__get_nSelectedChildren;
130   epv->getSelectedChild = impl_getSelectedChild;
131   epv->selectChild = impl_selectChild;
132   epv->deselectSelectedChild = impl_deselectSelectedChild;
133   epv->isChildSelected = impl_isChildSelected;
134   epv->selectAll = impl_selectAll;
135   epv->clearSelection = impl_clearSelection;
136 }
137
138 static void
139 selection_init (Selection *selection)
140 {
141 }
142
143 static void
144 selection_finalize (GObject *obj)
145 {
146   Selection *selection = SELECTION (obj);
147   g_object_unref (selection->atko);
148   selection->atko = NULL;
149   parent_class->finalize (obj);
150 }
151
152 Selection *
153 selection_interface_new (AtkObject *obj)
154 {
155   Selection *new_selection = 
156     SELECTION(g_object_new (SELECTION_TYPE, NULL));
157   new_selection->atko = obj;
158   g_object_ref (obj);
159   return new_selection;
160 }
161
162
163
164 static CORBA_long
165 impl__get_nSelectedChildren (PortableServer_Servant _servant,
166                              CORBA_Environment * ev)
167 {
168   Selection *selection = SELECTION (bonobo_object_from_servant (_servant));
169   return (CORBA_long)
170     atk_selection_get_selection_count (ATK_SELECTION(selection->atko));
171
172
173
174
175
176 static Accessibility_Accessible
177 impl_getSelectedChild (PortableServer_Servant _servant,
178                        const CORBA_long selectedChildIndex,
179                        CORBA_Environment * ev)
180 {
181   Selection *selection = SELECTION (bonobo_object_from_servant (_servant));
182   AtkObject *atk_object;
183   Accessibility_Accessible rv;
184
185   atk_object = atk_selection_ref_selection (ATK_SELECTION(selection->atko), (gint) selectedChildIndex);
186   rv = bonobo_object_corba_objref (BONOBO_OBJECT(accessible_new(atk_object)));
187   return rv;
188 }
189
190
191
192 static CORBA_boolean
193 impl_selectChild (PortableServer_Servant _servant,
194                   const CORBA_long childIndex,
195                   CORBA_Environment * ev)
196 {
197   Selection *selection = SELECTION (bonobo_object_from_servant (_servant));
198   return (CORBA_boolean)
199     atk_selection_add_selection (ATK_SELECTION(selection->atko), (gint) childIndex);
200 }
201
202
203
204
205 static CORBA_boolean
206 impl_deselectSelectedChild (PortableServer_Servant _servant,
207                             const CORBA_long selectedChildIndex,
208                             CORBA_Environment * ev)
209 {
210   Selection *selection = SELECTION (bonobo_object_from_servant (_servant));
211   return (CORBA_boolean)
212     atk_selection_remove_selection (ATK_SELECTION(selection->atko), (gint) selectedChildIndex);
213 }
214
215
216
217 static CORBA_boolean
218 impl_isChildSelected (PortableServer_Servant _servant,
219                       const CORBA_long childIndex,
220                       CORBA_Environment * ev)
221 {
222   Selection *selection = SELECTION (bonobo_object_from_servant (_servant));
223   return (CORBA_boolean)
224     atk_selection_is_child_selected (ATK_SELECTION(selection->atko), (gint) childIndex);
225 }
226
227
228
229 static void 
230 impl_selectAll (PortableServer_Servant _servant,
231                 CORBA_Environment * ev)
232 {
233   Selection *selection = SELECTION (bonobo_object_from_servant (_servant));
234   atk_selection_select_all_selection (ATK_SELECTION(selection->atko));
235 }
236
237
238
239 static void 
240 impl_clearSelection (PortableServer_Servant _servant,
241                      CORBA_Environment * ev)
242 {
243   Selection *selection = SELECTION (bonobo_object_from_servant (_servant));
244   atk_selection_clear_selection (ATK_SELECTION(selection->atko));
245 }
246