1 /* ATK - Accessibility Toolkit
2 * Copyright 2001 Sun Microsystems Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 #include <glib-object.h>
20 #include "atkobject.h"
21 #include "atkstateset.h"
25 * @Short_description: An AtkStateSet determines a component's state set.
28 * An AtkStateSet determines a component's state set. It is composed
29 * of a set of AtkStates.
32 #define ATK_STATE(state_enum) ((AtkState)((guint64)1 << ((state_enum)%64)))
34 struct _AtkRealStateSet
41 typedef struct _AtkRealStateSet AtkRealStateSet;
43 static void atk_state_set_class_init (AtkStateSetClass *klass);
46 atk_state_set_get_type (void)
48 static GType type = 0;
52 static const GTypeInfo typeInfo =
54 sizeof (AtkStateSetClass),
56 (GBaseFinalizeFunc) NULL,
57 (GClassInitFunc) atk_state_set_class_init,
58 (GClassFinalizeFunc) NULL,
60 sizeof (AtkRealStateSet),
62 (GInstanceInitFunc) NULL,
64 type = g_type_register_static (G_TYPE_OBJECT, "AtkStateSet", &typeInfo, 0) ;
70 atk_state_set_class_init (AtkStateSetClass *klass)
77 * Creates a new empty state set.
79 * Returns: a new #AtkStateSet
82 atk_state_set_new (void)
84 return (AtkStateSet*) g_object_new (ATK_TYPE_STATE_SET, NULL);
88 * atk_state_set_is_empty:
89 * @set: an #AtkStateType
91 * Checks whether the state set is empty, i.e. has no states set.
93 * Returns: %TRUE if @set has no states set, otherwise %FALSE
96 atk_state_set_is_empty (AtkStateSet *set)
98 AtkRealStateSet *real_set;
99 g_return_val_if_fail (ATK_IS_STATE_SET (set), FALSE);
101 real_set = (AtkRealStateSet *)set;
110 * atk_state_set_add_state:
111 * @set: an #AtkStateSet
112 * @type: an #AtkStateType
114 * Add a new state for the specified type to the current state set if
115 * it is not already present.
117 * Returns: %TRUE if the state for @type is not already in @set.
120 atk_state_set_add_state (AtkStateSet *set,
123 AtkRealStateSet *real_set;
124 g_return_val_if_fail (ATK_IS_STATE_SET (set), FALSE);
126 real_set = (AtkRealStateSet *)set;
128 if (real_set->state & ATK_STATE (type))
132 real_set->state |= ATK_STATE (type);
137 * atk_state_set_add_states:
138 * @set: an #AtkStateSet
139 * @types: (array length=n_types): an array of #AtkStateType
140 * @n_types: The number of elements in the array
142 * Add the states for the specified types to the current state set.
145 atk_state_set_add_states (AtkStateSet *set,
149 AtkRealStateSet *real_set;
151 g_return_if_fail (ATK_IS_STATE_SET (set));
153 real_set = (AtkRealStateSet *)set;
155 for (i = 0; i < n_types; i++)
157 real_set->state |= ATK_STATE (types[i]);
162 * atk_state_set_clear_states:
163 * @set: an #AtkStateSet
165 * Removes all states from the state set.
168 atk_state_set_clear_states (AtkStateSet *set)
170 AtkRealStateSet *real_set;
171 g_return_if_fail (ATK_IS_STATE_SET (set));
173 real_set = (AtkRealStateSet *)set;
179 * atk_state_set_contains_state:
180 * @set: an #AtkStateSet
181 * @type: an #AtkStateType
183 * Checks whether the state for the specified type is in the specified set.
185 * Returns: %TRUE if @type is the state type is in @set.
188 atk_state_set_contains_state (AtkStateSet *set,
191 AtkRealStateSet *real_set;
192 g_return_val_if_fail (ATK_IS_STATE_SET (set), FALSE);
194 real_set = (AtkRealStateSet *)set;
196 if (real_set->state & ATK_STATE (type))
203 * atk_state_set_contains_states:
204 * @set: an #AtkStateSet
205 * @types: (array length=n_types): an array of #AtkStateType
206 * @n_types: The number of elements in the array
208 * Checks whether the states for all the specified types are in the
211 * Returns: %TRUE if all the states for @type are in @set.
214 atk_state_set_contains_states (AtkStateSet *set,
218 AtkRealStateSet *real_set;
220 g_return_val_if_fail (ATK_IS_STATE_SET (set), FALSE);
222 real_set = (AtkRealStateSet *)set;
224 for (i = 0; i < n_types; i++)
226 if (!(real_set->state & ATK_STATE (types[i])))
233 * atk_state_set_remove_state:
234 * @set: an #AtkStateSet
237 * Removes the state for the specified type from the state set.
239 * Returns: %TRUE if @type was the state type is in @set.
242 atk_state_set_remove_state (AtkStateSet *set,
245 AtkRealStateSet *real_set;
246 g_return_val_if_fail (ATK_IS_STATE_SET (set), FALSE);
248 real_set = (AtkRealStateSet *)set;
250 if (real_set->state & ATK_STATE (type))
252 real_set->state ^= ATK_STATE (type);
260 * atk_state_set_and_sets:
261 * @set: an #AtkStateSet
262 * @compare_set: another #AtkStateSet
264 * Constructs the intersection of the two sets, returning %NULL if the
265 * intersection is empty.
267 * Returns: (transfer full): a new #AtkStateSet which is the intersection of
271 atk_state_set_and_sets (AtkStateSet *set,
272 AtkStateSet *compare_set)
274 AtkRealStateSet *real_set, *real_compare_set;
275 AtkStateSet *return_set = NULL;
278 g_return_val_if_fail (ATK_IS_STATE_SET (set), NULL);
279 g_return_val_if_fail (ATK_IS_STATE_SET (compare_set), NULL);
281 real_set = (AtkRealStateSet *)set;
282 real_compare_set = (AtkRealStateSet *)compare_set;
284 state = real_set->state & real_compare_set->state;
287 return_set = atk_state_set_new();
288 ((AtkRealStateSet *) return_set)->state = state;
294 * atk_state_set_or_sets:
295 * @set: an #AtkStateSet
296 * @compare_set: another #AtkStateSet
298 * Constructs the union of the two sets.
300 * Returns: (transfer full): a new #AtkStateSet which is the union of the two
301 * sets, returning %NULL is empty.
304 atk_state_set_or_sets (AtkStateSet *set,
305 AtkStateSet *compare_set)
307 AtkRealStateSet *real_set, *real_compare_set;
308 AtkStateSet *return_set = NULL;
311 g_return_val_if_fail (ATK_IS_STATE_SET (set), NULL);
312 g_return_val_if_fail (ATK_IS_STATE_SET (compare_set), NULL);
314 real_set = (AtkRealStateSet *)set;
315 real_compare_set = (AtkRealStateSet *)compare_set;
317 state = real_set->state | real_compare_set->state;
321 return_set = atk_state_set_new();
322 ((AtkRealStateSet *) return_set)->state = state;
329 * atk_state_set_xor_sets:
330 * @set: an #AtkStateSet
331 * @compare_set: another #AtkStateSet
333 * Constructs the exclusive-or of the two sets, returning %NULL is empty.
334 * The set returned by this operation contains the states in exactly
335 * one of the two sets.
337 * Returns: (transfer full): a new #AtkStateSet which contains the states
338 * which are in exactly one of the two sets.
341 atk_state_set_xor_sets (AtkStateSet *set,
342 AtkStateSet *compare_set)
344 AtkRealStateSet *real_set, *real_compare_set;
345 AtkStateSet *return_set = NULL;
346 AtkState state, state1, state2;
348 g_return_val_if_fail (ATK_IS_STATE_SET (set), NULL);
349 g_return_val_if_fail (ATK_IS_STATE_SET (compare_set), NULL);
351 real_set = (AtkRealStateSet *)set;
352 real_compare_set = (AtkRealStateSet *)compare_set;
354 state1 = real_set->state & (~real_compare_set->state);
355 state2 = (~real_set->state) & real_compare_set->state;
356 state = state1 | state2;
360 return_set = atk_state_set_new();
361 ((AtkRealStateSet *) return_set)->state = state;