6f726b2c1f49ed3a1b64ea17eba3aad9828458c9
[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   selection->atk_selection = NULL;
148   parent_class->finalize (obj);
149 }
150
151 Selection *
152 selection_new (AtkSelection *selection)
153 {
154   Selection *new_selection = 
155     SELECTION(g_object_new (SELECTION_TYPE, NULL));
156   new_selection->atk_selection = selection;
157   return new_selection;
158 }
159
160
161
162 static CORBA_long
163 impl__get_nSelectedChildren (PortableServer_Servant _servant,
164                              CORBA_Environment * ev)
165 {
166   Selection *selection = SELECTION (bonobo_object_from_servant (_servant));
167   return (CORBA_long)
168     atk_selection_get_selection_count (selection->atk_selection);
169
170
171
172
173
174 static Accessibility_Accessible
175 impl_getSelectedChild (PortableServer_Servant _servant,
176                        const CORBA_long selectedChildIndex,
177                        CORBA_Environment * ev)
178 {
179   Selection *selection = SELECTION (bonobo_object_from_servant (_servant));
180   AtkObject *atk_object;
181   Accessibility_Accessible rv;
182
183   atk_object = atk_selection_ref_selection (selection->atk_selection, (gint) selectedChildIndex);
184   rv = bonobo_object_corba_objref (BONOBO_OBJECT(accessible_new(atk_object)));
185   return rv;
186 }
187
188
189
190 static CORBA_boolean
191 impl_selectChild (PortableServer_Servant _servant,
192                   const CORBA_long childIndex,
193                   CORBA_Environment * ev)
194 {
195   Selection *selection = SELECTION (bonobo_object_from_servant (_servant));
196   return (CORBA_boolean)
197     atk_selection_add_selection (selection->atk_selection, (gint) childIndex);
198 }
199
200
201
202
203 static CORBA_boolean
204 impl_deselectSelectedChild (PortableServer_Servant _servant,
205                             const CORBA_long selectedChildIndex,
206                             CORBA_Environment * ev)
207 {
208   Selection *selection = SELECTION (bonobo_object_from_servant (_servant));
209   return (CORBA_boolean)
210     atk_selection_remove_selection (selection->atk_selection, (gint) selectedChildIndex);
211 }
212
213
214
215 static CORBA_boolean
216 impl_isChildSelected (PortableServer_Servant _servant,
217                       const CORBA_long childIndex,
218                       CORBA_Environment * ev)
219 {
220   Selection *selection = SELECTION (bonobo_object_from_servant (_servant));
221   return (CORBA_boolean)
222     atk_selection_is_child_selected (selection->atk_selection, (gint) childIndex);
223 }
224
225
226
227 static void 
228 impl_selectAll (PortableServer_Servant _servant,
229                 CORBA_Environment * ev)
230 {
231   Selection *selection = SELECTION (bonobo_object_from_servant (_servant));
232   atk_selection_select_all_selection (selection->atk_selection);
233 }
234
235
236
237 static void 
238 impl_clearSelection (PortableServer_Servant _servant,
239                      CORBA_Environment * ev)
240 {
241   Selection *selection = SELECTION (bonobo_object_from_servant (_servant));
242   atk_selection_clear_selection (selection->atk_selection);
243 }
244