2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001 Sun Microsystems Inc.
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.
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.
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.
23 /* selection.c : implements the Selection interface */
27 #include <libspi/accessible.h>
28 #include <libspi/selection.h>
30 /* Static function declarations */
33 spi_selection_class_init (SpiSelectionClass *klass);
35 spi_selection_init (SpiSelection *selection);
37 spi_selection_finalize (GObject *obj);
39 impl__get_nSelectedChildren (PortableServer_Servant _servant,
40 CORBA_Environment * ev);
41 static Accessibility_Accessible
42 impl_getSelectedChild (PortableServer_Servant _servant,
43 const CORBA_long selectedChildIndex,
44 CORBA_Environment * ev);
46 impl_selectChild (PortableServer_Servant _servant,
47 const CORBA_long childIndex,
48 CORBA_Environment * ev);
50 impl_deselectSelectedChild (PortableServer_Servant _servant,
51 const CORBA_long selectedChildIndex,
52 CORBA_Environment * ev);
54 impl_isChildSelected (PortableServer_Servant _servant,
55 const CORBA_long childIndex,
56 CORBA_Environment * ev);
58 impl_selectAll (PortableServer_Servant _servant,
59 CORBA_Environment * ev);
61 impl_clearSelection (PortableServer_Servant _servant,
62 CORBA_Environment * ev);
65 static GObjectClass *parent_class;
68 spi_selection_get_type (void)
70 static GType type = 0;
73 static const GTypeInfo tinfo = {
74 sizeof (SpiSelectionClass),
76 (GBaseFinalizeFunc) NULL,
77 (GClassInitFunc) spi_selection_class_init,
78 (GClassFinalizeFunc) NULL,
79 NULL, /* class data */
80 sizeof (SpiSelection),
82 (GInstanceInitFunc) spi_selection_init,
83 NULL /* value table */
87 * Bonobo_type_unique auto-generates a load of
88 * CORBA structures for us. All derived types must
89 * use bonobo_type_unique.
91 type = bonobo_type_unique (
93 POA_Accessibility_Selection__init,
95 G_STRUCT_OFFSET (SpiSelectionClass, epv),
97 "SpiAccessibleSelection");
104 spi_selection_class_init (SpiSelectionClass *klass)
106 GObjectClass * object_class = (GObjectClass *) klass;
107 POA_Accessibility_Selection__epv *epv = &klass->epv;
108 parent_class = g_type_class_peek_parent (klass);
110 object_class->finalize = spi_selection_finalize;
113 /* Initialize epv table */
115 epv->_get_nSelectedChildren = impl__get_nSelectedChildren;
116 epv->getSelectedChild = impl_getSelectedChild;
117 epv->selectChild = impl_selectChild;
118 epv->deselectSelectedChild = impl_deselectSelectedChild;
119 epv->isChildSelected = impl_isChildSelected;
120 epv->selectAll = impl_selectAll;
121 epv->clearSelection = impl_clearSelection;
125 spi_selection_init (SpiSelection *selection)
130 spi_selection_finalize (GObject *obj)
132 SpiSelection *selection = SPI_SELECTION (obj);
133 g_object_unref (selection->atko);
134 selection->atko = NULL;
135 parent_class->finalize (obj);
139 spi_selection_interface_new (AtkObject *obj)
141 SpiSelection *new_selection =
142 SPI_SELECTION(g_object_new (SPI_SELECTION_TYPE, NULL));
143 new_selection->atko = obj;
145 return new_selection;
151 impl__get_nSelectedChildren (PortableServer_Servant _servant,
152 CORBA_Environment * ev)
154 BonoboObject *obj = bonobo_object_from_servant (_servant);
155 SpiSelection *selection;
157 fprintf (stderr, "calling impl__get_nSelectedChildren\n");
159 g_return_val_if_fail (IS_SPI_SELECTION (obj), 0);
160 selection = SPI_SELECTION (obj);
161 g_return_val_if_fail (ATK_IS_SELECTION (selection->atko), 0);
163 atk_selection_get_selection_count (ATK_SELECTION(selection->atko));
167 static Accessibility_Accessible
168 impl_getSelectedChild (PortableServer_Servant _servant,
169 const CORBA_long selectedChildIndex,
170 CORBA_Environment * ev)
172 BonoboObject *obj = bonobo_object_from_servant (_servant);
175 AtkObject *atk_object;
176 Accessibility_Accessible rv;
178 fprintf (stderr, "calling impl_getSelectedChild\n");
180 g_return_val_if_fail (IS_SPI_SELECTION (obj), 0);
181 selection = SPI_SELECTION (obj);
182 g_return_val_if_fail (ATK_IS_SELECTION (selection->atko), 0);
184 atk_object = atk_selection_ref_selection (ATK_SELECTION (selection->atko),
185 (gint) selectedChildIndex);
186 g_return_val_if_fail (ATK_IS_OBJECT (atk_object), NULL);
188 fprintf (stderr, "child type is %s\n", g_type_name (G_OBJECT_TYPE (atk_object)));
190 rv = bonobo_object_corba_objref (bonobo_object (spi_accessible_new (atk_object)));
191 g_object_unref (atk_object);
192 return CORBA_Object_duplicate (rv, ev);
198 impl_selectChild (PortableServer_Servant _servant,
199 const CORBA_long childIndex,
200 CORBA_Environment * ev)
202 SpiSelection *selection = SPI_SELECTION (bonobo_object_from_servant (_servant));
203 return (CORBA_boolean)
204 atk_selection_add_selection (ATK_SELECTION(selection->atko), (gint) childIndex);
211 impl_deselectSelectedChild (PortableServer_Servant _servant,
212 const CORBA_long selectedChildIndex,
213 CORBA_Environment * ev)
215 SpiSelection *selection = SPI_SELECTION (bonobo_object_from_servant (_servant));
216 return (CORBA_boolean)
217 atk_selection_remove_selection (ATK_SELECTION(selection->atko), (gint) selectedChildIndex);
223 impl_isChildSelected (PortableServer_Servant _servant,
224 const CORBA_long childIndex,
225 CORBA_Environment * ev)
227 SpiSelection *selection = SPI_SELECTION (bonobo_object_from_servant (_servant));
228 return (CORBA_boolean)
229 atk_selection_is_child_selected (ATK_SELECTION(selection->atko), (gint) childIndex);
235 impl_selectAll (PortableServer_Servant _servant,
236 CORBA_Environment * ev)
238 SpiSelection *selection = SPI_SELECTION (bonobo_object_from_servant (_servant));
239 atk_selection_select_all_selection (ATK_SELECTION(selection->atko));
245 impl_clearSelection (PortableServer_Servant _servant,
246 CORBA_Environment * ev)
248 SpiSelection *selection = SPI_SELECTION (bonobo_object_from_servant (_servant));
249 atk_selection_clear_selection (ATK_SELECTION(selection->atko));