2001-12-10 Michael Meeks <michael@ximian.com>
[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
31 SpiSelection *
32 spi_selection_interface_new (AtkObject *obj)
33 {
34   SpiSelection *new_selection = g_object_new (SPI_SELECTION_TYPE, NULL);
35
36   spi_base_construct (SPI_BASE (new_selection), obj);
37
38   return new_selection;
39 }
40
41
42 static AtkSelection *
43 get_selection_from_servant (PortableServer_Servant servant)
44 {
45   SpiBase *object = SPI_BASE (bonobo_object_from_servant (servant));
46
47   if (!object)
48     {
49       return NULL;
50     }
51
52   return ATK_SELECTION (object->atko);
53 }
54
55
56 static CORBA_long
57 impl__get_nSelectedChildren (PortableServer_Servant servant,
58                              CORBA_Environment     *ev)
59 {
60   AtkSelection *selection = get_selection_from_servant (servant);
61
62   g_return_val_if_fail (selection != NULL, 0);
63
64   return (CORBA_long) atk_selection_get_selection_count (selection);
65 }
66
67
68 static Accessibility_Accessible
69 impl_getSelectedChild (PortableServer_Servant servant,
70                        const CORBA_long       selectedChildIndex,
71                        CORBA_Environment     *ev)
72 {
73   AtkObject    *atk_object;
74   AtkSelection *selection = get_selection_from_servant (servant);
75
76   g_return_val_if_fail (selection != NULL, CORBA_OBJECT_NIL);
77
78 #ifdef SPI_DEBUG
79   fprintf (stderr, "calling impl_getSelectedChild\n");
80 #endif
81
82   atk_object = atk_selection_ref_selection (selection,
83                                             (gint) selectedChildIndex);
84
85   g_return_val_if_fail (ATK_IS_OBJECT (atk_object), CORBA_OBJECT_NIL);
86
87 #ifdef SPI_DEBUG
88   fprintf (stderr, "child type is %s\n",
89            g_type_name (G_OBJECT_TYPE (atk_object)));
90 #endif
91
92   return spi_accessible_new_return (atk_object, TRUE, ev);
93 }
94
95
96 static CORBA_boolean
97 impl_selectChild (PortableServer_Servant servant,
98                   const CORBA_long       childIndex,
99                   CORBA_Environment     *ev)
100 {
101   AtkSelection *selection = get_selection_from_servant (servant);
102
103   g_return_val_if_fail (selection != NULL, FALSE);
104
105   return (CORBA_boolean)
106     atk_selection_add_selection (selection, (gint) childIndex);
107 }
108
109
110 static CORBA_boolean
111 impl_deselectSelectedChild (PortableServer_Servant servant,
112                             const CORBA_long       selectedChildIndex,
113                             CORBA_Environment     *ev)
114 {
115   AtkSelection *selection = get_selection_from_servant (servant);
116
117   g_return_val_if_fail (selection != NULL, FALSE);
118
119   return (CORBA_boolean)
120     atk_selection_remove_selection (selection, (gint) selectedChildIndex);
121 }
122
123
124 static CORBA_boolean
125 impl_isChildSelected (PortableServer_Servant servant,
126                       const CORBA_long       childIndex,
127                       CORBA_Environment     *ev)
128 {
129   AtkSelection *selection = get_selection_from_servant (servant);
130
131   g_return_val_if_fail (selection != NULL, FALSE);
132
133   return (CORBA_boolean)
134     atk_selection_is_child_selected (selection, (gint) childIndex);
135 }
136
137
138 static void 
139 impl_selectAll (PortableServer_Servant servant,
140                 CORBA_Environment     *ev)
141 {
142   AtkSelection *selection = get_selection_from_servant (servant);
143
144   g_return_if_fail (selection != NULL);
145
146   atk_selection_select_all_selection (selection);
147 }
148
149
150 static void 
151 impl_clearSelection (PortableServer_Servant servant,
152                      CORBA_Environment     *ev)
153 {
154   AtkSelection *selection = get_selection_from_servant (servant);
155
156   g_return_if_fail (selection != NULL);
157
158   atk_selection_clear_selection (selection);
159 }
160
161
162 static void
163 spi_selection_class_init (SpiSelectionClass *klass)
164 {
165   POA_Accessibility_Selection__epv *epv = &klass->epv;
166
167   /* Initialize epv table */
168
169   epv->_get_nSelectedChildren = impl__get_nSelectedChildren;
170   epv->getSelectedChild       = impl_getSelectedChild;
171   epv->selectChild            = impl_selectChild;
172   epv->deselectSelectedChild  = impl_deselectSelectedChild;
173   epv->isChildSelected        = impl_isChildSelected;
174   epv->selectAll              = impl_selectAll;
175   epv->clearSelection         = impl_clearSelection;
176 }
177
178
179 static void
180 spi_selection_init (SpiSelection *selection)
181 {
182 }
183
184
185 BONOBO_TYPE_FUNC_FULL (SpiSelection,
186                        Accessibility_Selection,
187                        SPI_TYPE_BASE,
188                        spi_selection);