Started fixing IDL docs.
[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 /* selection.c : implements the Selection interface */
24
25 #include <config.h>
26 #include <stdio.h>
27 #include <libspi/accessible.h>
28 #include <libspi/selection.h>
29
30 /* A pointer to our parent object class */
31 static GObjectClass *parent_class;
32
33 static void
34 spi_selection_finalize (GObject *obj)
35 {
36   SpiSelection *selection = SPI_SELECTION (obj);
37   g_object_unref (selection->atko);
38   selection->atko = NULL;
39   parent_class->finalize (obj);
40 }
41
42 SpiSelection *
43 spi_selection_interface_new (AtkObject *obj)
44 {
45   SpiSelection *new_selection = g_object_new (SPI_SELECTION_TYPE, NULL);
46   new_selection->atko = obj;
47   g_object_ref (obj);
48   return new_selection;
49 }
50
51
52
53 static CORBA_long
54 impl__get_nSelectedChildren (PortableServer_Servant _servant,
55                              CORBA_Environment * ev)
56 {
57   BonoboObject *obj = bonobo_object_from_servant (_servant);
58   SpiSelection *selection;
59 #ifdef SPI_DEBUG
60   fprintf (stderr, "calling impl__get_nSelectedChildren\n");
61 #endif
62   g_return_val_if_fail (IS_SPI_SELECTION (obj), 0);
63   selection = SPI_SELECTION (obj);
64   g_return_val_if_fail (ATK_IS_SELECTION (selection->atko), 0);
65   return (CORBA_long)
66     atk_selection_get_selection_count (ATK_SELECTION(selection->atko));
67 }
68
69
70 static Accessibility_Accessible
71 impl_getSelectedChild (PortableServer_Servant _servant,
72                        const CORBA_long selectedChildIndex,
73                        CORBA_Environment * ev)
74 {
75   BonoboObject *obj = bonobo_object_from_servant (_servant);
76   SpiSelection
77           *selection;
78   AtkObject *atk_object;
79   Accessibility_Accessible rv;
80 #ifdef SPI_DEBUG
81   fprintf (stderr, "calling impl_getSelectedChild\n");
82 #endif
83   g_return_val_if_fail (IS_SPI_SELECTION (obj), 0);
84   selection = SPI_SELECTION (obj);
85   g_return_val_if_fail (ATK_IS_SELECTION (selection->atko), 0);
86
87   atk_object = atk_selection_ref_selection (ATK_SELECTION (selection->atko),
88                                             (gint) selectedChildIndex);
89   g_return_val_if_fail (ATK_IS_OBJECT (atk_object), NULL);
90 #ifdef SPI_DEBUG
91   fprintf (stderr, "child type is %s\n", g_type_name (G_OBJECT_TYPE (atk_object)));
92 #endif
93   rv = bonobo_object_corba_objref (bonobo_object (spi_accessible_new (atk_object)));
94   g_object_unref (atk_object);
95   return CORBA_Object_duplicate (rv, ev);
96 }
97
98
99
100 static CORBA_boolean
101 impl_selectChild (PortableServer_Servant _servant,
102                   const CORBA_long childIndex,
103                   CORBA_Environment * ev)
104 {
105   SpiSelection *selection = SPI_SELECTION (bonobo_object_from_servant (_servant));
106   return (CORBA_boolean)
107     atk_selection_add_selection (ATK_SELECTION(selection->atko), (gint) childIndex);
108 }
109
110
111
112
113 static CORBA_boolean
114 impl_deselectSelectedChild (PortableServer_Servant _servant,
115                             const CORBA_long selectedChildIndex,
116                             CORBA_Environment * ev)
117 {
118   SpiSelection *selection = SPI_SELECTION (bonobo_object_from_servant (_servant));
119   return (CORBA_boolean)
120     atk_selection_remove_selection (ATK_SELECTION(selection->atko), (gint) selectedChildIndex);
121 }
122
123
124
125 static CORBA_boolean
126 impl_isChildSelected (PortableServer_Servant _servant,
127                       const CORBA_long childIndex,
128                       CORBA_Environment * ev)
129 {
130   SpiSelection *selection = SPI_SELECTION (bonobo_object_from_servant (_servant));
131   return (CORBA_boolean)
132     atk_selection_is_child_selected (ATK_SELECTION(selection->atko), (gint) childIndex);
133 }
134
135
136
137 static void 
138 impl_selectAll (PortableServer_Servant _servant,
139                 CORBA_Environment * ev)
140 {
141   SpiSelection *selection = SPI_SELECTION (bonobo_object_from_servant (_servant));
142   atk_selection_select_all_selection (ATK_SELECTION(selection->atko));
143 }
144
145
146
147 static void 
148 impl_clearSelection (PortableServer_Servant _servant,
149                      CORBA_Environment * ev)
150 {
151   SpiSelection *selection = SPI_SELECTION (bonobo_object_from_servant (_servant));
152   atk_selection_clear_selection (ATK_SELECTION(selection->atko));
153 }
154
155 static void
156 spi_selection_class_init (SpiSelectionClass *klass)
157 {
158   GObjectClass * object_class = (GObjectClass *) klass;
159   POA_Accessibility_Selection__epv *epv = &klass->epv;
160   parent_class = g_type_class_peek_parent (klass);
161
162   object_class->finalize = spi_selection_finalize;
163
164
165   /* Initialize epv table */
166
167   epv->_get_nSelectedChildren = impl__get_nSelectedChildren;
168   epv->getSelectedChild = impl_getSelectedChild;
169   epv->selectChild = impl_selectChild;
170   epv->deselectSelectedChild = impl_deselectSelectedChild;
171   epv->isChildSelected = impl_isChildSelected;
172   epv->selectAll = impl_selectAll;
173   epv->clearSelection = impl_clearSelection;
174 }
175
176 static void
177 spi_selection_init (SpiSelection *selection)
178 {
179 }
180
181 BONOBO_TYPE_FUNC_FULL (SpiSelection,
182                        Accessibility_Selection,
183                        BONOBO_TYPE_OBJECT,
184                        spi_selection);