2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001, 2002 Sun Microsystems Inc.,
6 * Copyright 2001, 2002 Ximian, Inc.
7 * Copyright 2010, 2011 Novell, Inc.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
25 #include "atspi-private.h"
27 static void atspi_state_set_class_init (AtspiStateSetClass *klass);
29 G_DEFINE_TYPE (AtspiStateSet, atspi_state_set, G_TYPE_OBJECT)
32 atspi_state_set_init (AtspiStateSet *set)
38 atspi_state_set_class_init (AtspiStateSetClass* klass)
43 * atspi_state_set_new:
45 * @states: (element-type AtspiStateType): An array of states with which to initialize
48 * Returns: A new #AtspiStateSet with the given states.
51 atspi_state_set_new (GArray *states)
53 AtspiStateSet *set = g_object_new (ATSPI_TYPE_STATE_SET, NULL);
59 for (i = 0; i < states->len; i++)
60 atspi_state_set_add (set, g_array_index (states, AtspiStateType, i));
65 _atspi_state_set_new_internal (AtspiAccessible *accessible, gint64 states)
69 set = g_object_new (ATSPI_TYPE_STATE_SET, NULL);
70 g_return_val_if_fail (set != NULL, NULL);
72 set->accessible = accessible;
78 atspi_state_set_set_by_name (AtspiStateSet *set, const gchar *name, gboolean enabled)
80 GTypeClass *type_class;
83 type_class = g_type_class_ref (ATSPI_TYPE_STATE_TYPE);
85 if (set->accessible &&
86 !(set->accessible->cached_properties & ATSPI_CACHE_STATES))
89 value = g_enum_get_value_by_nick (G_ENUM_CLASS (type_class), name);
92 g_warning ("AT-SPI: Attempt to set unknown state '%s'", name);
96 set->states |= ((gint64)1 << value->value);
98 set->states &= ~((gint64)1 << value->value);
102 refresh_states (AtspiStateSet *set)
105 dbus_uint32_t *states;
107 if (!set->accessible ||
108 (set->accessible->cached_properties & ATSPI_CACHE_STATES))
111 if (!_atspi_dbus_call (set->accessible, atspi_interface_accessible, "GetState", NULL, "=>au", &state_array))
114 states = (dbus_uint32_t *) state_array->data;
116 set->states = ((gint64)states [1]) << 32;
117 set->states |= (gint64) states [0];
118 g_array_free (state_array, TRUE);
122 * atspi_state_set_add:
124 * @set: a pointer to the #AtspiStateSet object on which to operate.
125 * @state: an #AtspiStateType to be added to the specified #AtspiStateSet.
127 * Add a particular #AtspiState to an #AtspiStateSet (i.e. set the
128 * given state to #TRUE in the stateset.
132 atspi_state_set_add (AtspiStateSet *set, AtspiStateType state)
134 g_return_if_fail (set != NULL);
135 set->states |= (((gint64)1) << state);
139 * atspi_state_set_compare:
140 * @set: a pointer to the first #AtspiStateSet object on which to operate.
141 * @set: a pointer to the second #AtspiStateSet setect on which to operate.
143 * Determine the differences between two instances of #AtspiStateSet.
145 * @see AtspiStateSet_equals().
147 * Returns: (transfer full): an #AtspiStateSet object containing all states
148 * contained on one of the two sets but not the other.
152 atspi_state_set_compare (AtspiStateSet *set,
155 g_return_val_if_fail (set != NULL, NULL);
156 g_return_val_if_fail (set2 != NULL, NULL);
158 return _atspi_state_set_new_internal (NULL, set->states ^ set2->states);
162 * atspi_state_set_contains:
163 * @set: a pointer to the #AtspiStateSet object on which to operate.
164 * @state: an #AtspiStateType for which the specified #AtspiStateSet
167 * Determine whether a given #AtspiStateSet includes a given state; that is,
168 * whether @state is true for the stateset in question.
170 * Returns: #TRUE if @state is true/included in the given #AtspiStateSet,
175 atspi_state_set_contains (AtspiStateSet *set,
176 AtspiStateType state)
180 refresh_states (set);
181 return (set->states & ((gint64)1 << state)) ? TRUE : FALSE;
185 * atspi_state_set_equals:
186 * @set: a pointer to the first #AtspiStateSet object on which to operate.
187 * @set2: a pointer to the second #AtspiStateSet object on which to operate.
189 * Determine whether two instances of #AtspiStateSet are equivalent (i.e.
190 * consist of the same #AtspiStates). Useful for checking multiple
191 * state variables at once; construct the target state then compare against it.
193 * @see AtspiStateSet_compare().
195 * Returns: #TRUE if the two #AtspiStateSets are equivalent,
200 atspi_state_set_equals (AtspiStateSet *set,
205 if (set == NULL || set2 == NULL)
207 return (set->states == set2->states);
211 * atspi_state_set_get_states:
213 * @set: The #AtspiStateSet to be queried.
215 * Return the states in an #AtspiStateSet as an array.
217 * Returns: (element-type AtspiStateType) (transfer full): A #GArray of state
218 * types representing the current state.
221 atspi_state_set_get_states (AtspiStateSet *set)
227 g_return_val_if_fail (set != NULL, NULL);
228 refresh_states (set);
229 ret = g_array_new (TRUE, TRUE, sizeof (AtspiStateType));
232 for (i = 0; i < 64; i++)
234 if (set->states & val)
236 GArray *new_array = g_array_append_val (ret, i);
246 * atspi_state_set_is_empty:
248 * @set: The #AtspiStateSet to query.
250 * Returns: #TRUE if the state set contains no states; #FALSE otherwise.
253 atspi_state_set_is_empty (AtspiStateSet *set)
255 return (set->states == 0);
259 * atspi_state_set_remove:
261 * @set: a pointer to the #AtspiStateSet object on which to operate.
262 * @state: an #AtspiStateType to remove from the specifiedn state set.
264 * Remove a particular #AtspiState to an #AtspiStateSet (i.e. set the
265 * given state to #FALSE in the stateset.)
269 atspi_state_set_remove (AtspiStateSet *set, AtspiStateType state)
271 g_return_if_fail (set != NULL);
272 set->states &= ~((gint64)1 << state);