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 /* stateset.c : implements the StateSet interface */
27 #include <libspi/stateset.h>
30 static Accessibility_StateType *accessible_state_types = NULL;
31 static AtkStateType *atk_state_types = NULL;
35 spi_init_state_type_tables (void)
39 if (accessible_state_types || atk_state_types)
41 if (!accessible_state_types)
42 accessible_state_types = g_new (Accessibility_StateType, Accessibility_STATE_LAST_DEFINED);
44 atk_state_types = g_new (AtkStateType, ATK_STATE_LAST_DEFINED);
45 g_return_val_if_fail (accessible_state_types, FALSE);
46 g_return_val_if_fail (atk_state_types, FALSE);
48 accessible_state_types = g_new (Accessibility_StateType, ATK_STATE_LAST_DEFINED);
49 atk_state_types = g_new (AtkStateType, ATK_STATE_LAST_DEFINED);
51 for (i = 0; i < ATK_STATE_LAST_DEFINED; i++)
53 atk_state_types[i] = ATK_STATE_INVALID;
54 accessible_state_types[i] = Accessibility_STATE_INVALID;
57 accessible_state_types[ATK_STATE_ACTIVE] = Accessibility_STATE_ACTIVE;
58 atk_state_types[Accessibility_STATE_ACTIVE] = ATK_STATE_ACTIVE;
59 accessible_state_types[ATK_STATE_ARMED] = Accessibility_STATE_ARMED;
60 atk_state_types[Accessibility_STATE_ARMED] = ATK_STATE_ARMED;
61 accessible_state_types[ATK_STATE_BUSY] = Accessibility_STATE_BUSY;
62 atk_state_types[Accessibility_STATE_BUSY] = ATK_STATE_BUSY;
63 accessible_state_types[ATK_STATE_CHECKED] = Accessibility_STATE_CHECKED;
64 atk_state_types[Accessibility_STATE_CHECKED] = ATK_STATE_CHECKED;
65 accessible_state_types[ATK_STATE_DEFUNCT] = Accessibility_STATE_DEFUNCT;
66 atk_state_types[Accessibility_STATE_DEFUNCT] = ATK_STATE_DEFUNCT;
67 accessible_state_types[ATK_STATE_EDITABLE] = Accessibility_STATE_EDITABLE;
68 atk_state_types[Accessibility_STATE_EDITABLE] = ATK_STATE_EDITABLE;
69 accessible_state_types[ATK_STATE_ENABLED] = Accessibility_STATE_ENABLED;
70 atk_state_types[Accessibility_STATE_ENABLED] = ATK_STATE_ENABLED;
71 accessible_state_types[ATK_STATE_EXPANDABLE] = Accessibility_STATE_EXPANDABLE;
72 atk_state_types[Accessibility_STATE_EXPANDABLE] = ATK_STATE_EXPANDABLE;
73 accessible_state_types[ATK_STATE_EXPANDED] = Accessibility_STATE_EXPANDED;
74 atk_state_types[Accessibility_STATE_EXPANDED] = ATK_STATE_EXPANDED;
75 accessible_state_types[ATK_STATE_FOCUSABLE] = Accessibility_STATE_FOCUSABLE;
76 atk_state_types[Accessibility_STATE_FOCUSABLE] = ATK_STATE_FOCUSABLE;
77 accessible_state_types[ATK_STATE_FOCUSED] = Accessibility_STATE_FOCUSED;
78 atk_state_types[Accessibility_STATE_FOCUSED] = ATK_STATE_FOCUSED;
79 accessible_state_types[ATK_STATE_HORIZONTAL] = Accessibility_STATE_HORIZONTAL;
80 atk_state_types[Accessibility_STATE_HORIZONTAL] = ATK_STATE_HORIZONTAL;
81 accessible_state_types[ATK_STATE_ICONIFIED] = Accessibility_STATE_ICONIFIED;
82 atk_state_types[Accessibility_STATE_ICONIFIED] = ATK_STATE_ICONIFIED;
83 accessible_state_types[ATK_STATE_MODAL] = Accessibility_STATE_MODAL;
84 atk_state_types[Accessibility_STATE_MODAL] = ATK_STATE_MODAL;
85 accessible_state_types[ATK_STATE_MULTI_LINE] = Accessibility_STATE_MULTI_LINE;
86 atk_state_types[Accessibility_STATE_MULTI_LINE] = ATK_STATE_MULTI_LINE;
87 accessible_state_types[ATK_STATE_MULTISELECTABLE] = Accessibility_STATE_MULTISELECTABLE;
88 atk_state_types[Accessibility_STATE_MULTISELECTABLE] = ATK_STATE_MULTISELECTABLE;
89 accessible_state_types[ATK_STATE_OPAQUE] = Accessibility_STATE_OPAQUE;
90 atk_state_types[Accessibility_STATE_OPAQUE] = ATK_STATE_OPAQUE;
91 accessible_state_types[ATK_STATE_PRESSED] = Accessibility_STATE_PRESSED;
92 atk_state_types[Accessibility_STATE_PRESSED] = ATK_STATE_PRESSED;
93 accessible_state_types[ATK_STATE_RESIZABLE] = Accessibility_STATE_RESIZABLE;
94 atk_state_types[Accessibility_STATE_RESIZABLE] = ATK_STATE_RESIZABLE;
95 accessible_state_types[ATK_STATE_SELECTABLE] = Accessibility_STATE_SELECTABLE;
96 atk_state_types[Accessibility_STATE_SELECTABLE] = ATK_STATE_SELECTABLE;
97 accessible_state_types[ATK_STATE_SELECTED] = Accessibility_STATE_SELECTED;
98 atk_state_types[Accessibility_STATE_SELECTED] = ATK_STATE_SELECTED;
99 accessible_state_types[ATK_STATE_SENSITIVE] = Accessibility_STATE_SENSITIVE;
100 atk_state_types[Accessibility_STATE_SENSITIVE] = ATK_STATE_SENSITIVE;
101 accessible_state_types[ATK_STATE_SHOWING] = Accessibility_STATE_SHOWING;
102 atk_state_types[Accessibility_STATE_SHOWING] = ATK_STATE_SHOWING;
103 accessible_state_types[ATK_STATE_SINGLE_LINE] = Accessibility_STATE_SINGLE_LINE;
104 atk_state_types[Accessibility_STATE_SINGLE_LINE] = ATK_STATE_SINGLE_LINE;
105 accessible_state_types[ATK_STATE_STALE] = Accessibility_STATE_STALE;
106 atk_state_types[Accessibility_STATE_STALE] = ATK_STATE_STALE;
107 accessible_state_types[ATK_STATE_TRANSIENT] = Accessibility_STATE_TRANSIENT;
108 atk_state_types[Accessibility_STATE_TRANSIENT] = ATK_STATE_TRANSIENT;
109 accessible_state_types[ATK_STATE_VERTICAL] = Accessibility_STATE_VERTICAL;
110 atk_state_types[Accessibility_STATE_VERTICAL] = ATK_STATE_VERTICAL;
111 accessible_state_types[ATK_STATE_VISIBLE] = Accessibility_STATE_VISIBLE;
112 atk_state_types[Accessibility_STATE_VISIBLE] = ATK_STATE_VISIBLE;
120 atk_state_set_from_servant (PortableServer_Servant servant)
122 SpiBase *base = SPI_BASE (bonobo_object_from_servant(servant));
124 g_return_val_if_fail (base, NULL);
125 return ATK_STATE_SET(base->gobj);
131 atk_state_set_from_accessibility_state_set (Accessibility_StateSet set, CORBA_Environment *ev)
133 AtkStateType *states, *tmp;
136 Accessibility_StateSeq *seq;
138 seq = Accessibility_StateSet_getStates (set, ev);
139 states = tmp = g_new (AtkStateType, seq->_length);
140 for (i = 0; i < seq->_length; i++)
141 *tmp++ = atk_state_types[seq->_buffer[i]];
142 rv = atk_state_set_new ();
143 atk_state_set_add_states (rv, states, seq->_length);
152 spi_state_set_new (AtkStateSet *obj)
154 SpiStateSet *new_set = g_object_new (SPI_STATE_SET_TYPE, NULL);
155 spi_base_construct (SPI_BASE (new_set), G_OBJECT (obj));
162 impl_contains (PortableServer_Servant servant,
163 const Accessibility_StateType state,
164 CORBA_Environment * ev)
166 AtkStateSet *set = atk_state_set_from_servant (servant);
168 g_return_val_if_fail (set, FALSE);
169 return (CORBA_boolean)
170 atk_state_set_contains_state (set, atk_state_types[state]);
176 impl_add(PortableServer_Servant servant,
177 const Accessibility_StateType state,
178 CORBA_Environment * ev)
180 AtkStateSet *set = atk_state_set_from_servant (servant);
182 g_return_if_fail (set);
183 atk_state_set_add_state (set, atk_state_types[state]);
189 impl_remove (PortableServer_Servant servant,
190 const Accessibility_StateType state,
191 CORBA_Environment * ev)
193 AtkStateSet *set = atk_state_set_from_servant (servant);
195 g_return_if_fail (set);
196 atk_state_set_remove_state (set, atk_state_types[state]);
202 impl_equals (PortableServer_Servant servant,
203 const Accessibility_StateSet stateSet,
204 CORBA_Environment * ev)
206 AtkStateSet *set = atk_state_set_from_servant (servant);
207 AtkStateSet *set2, *return_set;
210 g_return_val_if_fail (set, FALSE);
212 set2 = atk_state_set_from_accessibility_state_set (stateSet, ev);
213 g_return_val_if_fail (set2, FALSE);
215 return_set = atk_state_set_xor_sets (set, set2);
216 g_object_unref (G_OBJECT(set2));
220 atk_state_set_is_empty (return_set);
221 g_object_unref (G_OBJECT(return_set));
230 static Accessibility_StateSet
231 impl_compare (PortableServer_Servant servant,
232 const Accessibility_StateSet compareState,
233 CORBA_Environment * ev)
235 AtkStateSet *set = atk_state_set_from_servant (servant);
236 AtkStateSet *set2, *return_set;
237 SpiStateSet *spi_set;
239 g_return_val_if_fail (set, FALSE);
241 set2 = atk_state_set_from_accessibility_state_set (compareState, ev);
242 g_return_val_if_fail (set2, CORBA_OBJECT_NIL);
244 return_set = atk_state_set_xor_sets (set, set2);
245 g_object_unref (G_OBJECT(set2));
246 spi_set = spi_state_set_new (return_set);
247 return bonobo_object_corba_objref (BONOBO_OBJECT(spi_set));
253 impl_isEmpty (PortableServer_Servant servant,
254 CORBA_Environment * ev)
256 AtkStateSet *set = atk_state_set_from_servant (servant);
258 g_return_val_if_fail (set, TRUE);
259 return (CORBA_boolean)
260 atk_state_set_is_empty (set);
265 static Accessibility_StateSeq *
266 impl_getStates (PortableServer_Servant servant,
267 CORBA_Environment * ev)
269 AtkStateSet *set = atk_state_set_from_servant (servant);
270 GSList *states = NULL;
273 Accessibility_StateSeq *rv;
275 g_return_val_if_fail (set, CORBA_OBJECT_NIL);
277 /* Argh-- this is bad!!! */
279 if (atk_state_set_contains_state (set, ATK_STATE_ACTIVE))
280 states = g_slist_append (states, (gpointer) Accessibility_STATE_ACTIVE);
281 if (atk_state_set_contains_state (set, ATK_STATE_ARMED))
282 states = g_slist_append (states, (gpointer) Accessibility_STATE_ARMED);
283 if (atk_state_set_contains_state (set, ATK_STATE_BUSY))
284 states = g_slist_append (states, (gpointer) Accessibility_STATE_BUSY);
285 if (atk_state_set_contains_state (set, ATK_STATE_CHECKED))
286 states = g_slist_append (states, (gpointer) Accessibility_STATE_CHECKED);
287 if (atk_state_set_contains_state (set, ATK_STATE_DEFUNCT))
288 states = g_slist_append (states, (gpointer) Accessibility_STATE_DEFUNCT);
289 if (atk_state_set_contains_state (set, ATK_STATE_EDITABLE))
290 states = g_slist_append (states, (gpointer) Accessibility_STATE_EDITABLE);
291 if (atk_state_set_contains_state (set, ATK_STATE_ENABLED))
292 states = g_slist_append (states, (gpointer) Accessibility_STATE_ENABLED);
293 if (atk_state_set_contains_state (set, ATK_STATE_EXPANDABLE))
294 states = g_slist_append (states, (gpointer) Accessibility_STATE_EXPANDABLE);
295 if (atk_state_set_contains_state (set, ATK_STATE_EXPANDED))
296 states = g_slist_append (states, (gpointer) Accessibility_STATE_EXPANDED);
297 if (atk_state_set_contains_state (set, ATK_STATE_FOCUSABLE))
298 states = g_slist_append (states, (gpointer) Accessibility_STATE_FOCUSABLE);
299 if (atk_state_set_contains_state (set, ATK_STATE_FOCUSED))
300 states = g_slist_append (states, (gpointer) Accessibility_STATE_FOCUSED);
301 if (atk_state_set_contains_state (set, ATK_STATE_HORIZONTAL))
302 states = g_slist_append (states, (gpointer) Accessibility_STATE_HORIZONTAL);
303 if (atk_state_set_contains_state (set, ATK_STATE_ICONIFIED))
304 states = g_slist_append (states, (gpointer) Accessibility_STATE_ICONIFIED);
305 if (atk_state_set_contains_state (set, ATK_STATE_MODAL))
306 states = g_slist_append (states, (gpointer) Accessibility_STATE_MODAL);
307 if (atk_state_set_contains_state (set, ATK_STATE_MULTI_LINE))
308 states = g_slist_append (states, (gpointer) Accessibility_STATE_MULTI_LINE);
309 if (atk_state_set_contains_state (set, ATK_STATE_MULTISELECTABLE))
310 states = g_slist_append (states, (gpointer) Accessibility_STATE_MULTISELECTABLE);
311 if (atk_state_set_contains_state (set, ATK_STATE_OPAQUE))
312 states = g_slist_append (states, (gpointer) Accessibility_STATE_OPAQUE);
313 if (atk_state_set_contains_state (set, ATK_STATE_PRESSED))
314 states = g_slist_append (states, (gpointer) Accessibility_STATE_PRESSED);
315 if (atk_state_set_contains_state (set, ATK_STATE_RESIZABLE))
316 states = g_slist_append (states, (gpointer) Accessibility_STATE_RESIZABLE);
317 if (atk_state_set_contains_state (set, ATK_STATE_SELECTABLE))
318 states = g_slist_append (states, (gpointer) Accessibility_STATE_SELECTABLE);
319 if (atk_state_set_contains_state (set, ATK_STATE_SELECTED))
320 states = g_slist_append (states, (gpointer) Accessibility_STATE_SELECTED);
321 if (atk_state_set_contains_state (set, ATK_STATE_SENSITIVE))
322 states = g_slist_append (states, (gpointer) Accessibility_STATE_SENSITIVE);
323 if (atk_state_set_contains_state (set, ATK_STATE_SHOWING))
324 states = g_slist_append (states, (gpointer) Accessibility_STATE_SHOWING);
325 if (atk_state_set_contains_state (set, ATK_STATE_SINGLE_LINE))
326 states = g_slist_append (states, (gpointer) Accessibility_STATE_SINGLE_LINE);
327 if (atk_state_set_contains_state (set, ATK_STATE_STALE))
328 states = g_slist_append (states, (gpointer) Accessibility_STATE_STALE);
329 if (atk_state_set_contains_state (set, ATK_STATE_TRANSIENT))
330 states = g_slist_append (states, (gpointer) Accessibility_STATE_TRANSIENT);
331 if (atk_state_set_contains_state (set, ATK_STATE_VERTICAL))
332 states = g_slist_append (states, (gpointer) Accessibility_STATE_VERTICAL);
333 if (atk_state_set_contains_state (set, ATK_STATE_VISIBLE))
334 states = g_slist_append (states, (gpointer) Accessibility_STATE_VISIBLE);
336 rv = Accessibility_StateSeq__alloc ();
337 rv->_length = rv->_maximum = g_slist_length (states);
338 rv->_buffer = Accessibility_StateSeq_allocbuf (rv->_length);
342 rv->_buffer[i++] = (Accessibility_StateType) tmp->data;
345 g_slist_free (states);
352 spi_state_set_class_init (SpiStateSetClass *klass)
354 POA_Accessibility_StateSet__epv *epv = &klass->epv;
356 spi_init_state_type_tables ();
357 epv->contains = impl_contains;
359 epv->remove = impl_remove;
360 epv->equals = impl_equals;
361 epv->compare = impl_compare;
362 epv->isEmpty = impl_isEmpty;
363 epv->getStates = impl_getStates;
368 spi_state_set_init (SpiStateSet *set)
373 BONOBO_TYPE_FUNC_FULL (SpiStateSet,
374 Accessibility_StateSet,