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, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 #include <glib-object.h>
22 #include "atkobject.h"
23 #include "atkstateset.h"
25 #define ATK_STATE(state_enum) ((AtkState)(1 << ((guint64)(state_enum)%64)))
27 struct _AtkRealStateSet
34 typedef struct _AtkRealStateSet AtkRealStateSet;
36 static void atk_state_set_class_init (AtkStateSetClass *klass);
39 atk_state_set_get_type (void)
41 static GType type = 0;
45 static const GTypeInfo typeInfo =
47 sizeof (AtkStateSetClass),
49 (GBaseFinalizeFunc) NULL,
50 (GClassInitFunc) atk_state_set_class_init,
51 (GClassFinalizeFunc) NULL,
53 sizeof (AtkRealStateSet),
55 (GInstanceInitFunc) NULL,
57 type = g_type_register_static (G_TYPE_OBJECT, "AtkStateSet", &typeInfo, 0) ;
63 atk_state_set_class_init (AtkStateSetClass *klass)
70 * Creates a new empty state set.
72 * Returns: a new #AtkStateSet
75 atk_state_set_new (void)
77 return (AtkStateSet*) g_object_new (ATK_TYPE_STATE_SET, NULL);
81 * atk_state_set_is_empty:
82 * @set: an #AtkStateType
84 * Checks whether the state set is empty, i.e. has no states set.
86 * Returns: %TRUE if @set has no states set, otherwise %FALSE
89 atk_state_set_is_empty (AtkStateSet *set)
91 AtkRealStateSet *real_set;
92 g_return_val_if_fail (set != NULL, FALSE);
93 g_return_val_if_fail (ATK_IS_STATE_SET (set), FALSE);
95 real_set = (AtkRealStateSet *)set;
104 * atk_state_set_add_state:
105 * @set: an #AtkStateSet
106 * @type: an #AtkStateType
108 * Add a new state for the specified type to the current state set if
109 * it is not already present.
111 * Returns: %TRUE if the state for @type is not already in @set.
114 atk_state_set_add_state (AtkStateSet *set,
117 AtkRealStateSet *real_set;
118 g_return_val_if_fail (set != NULL, FALSE);
119 g_return_val_if_fail (ATK_IS_STATE_SET (set), FALSE);
121 real_set = (AtkRealStateSet *)set;
123 if (real_set->state & ATK_STATE (type))
127 real_set->state |= ATK_STATE (type);
132 * atk_state_set_add_states:
133 * @set: an #AtkStateSet
134 * @types: an array of #AtkStateType
135 * @n_types: The number of elements in the array
137 * Add the states for the specified types to the current state set.
140 atk_state_set_add_states (AtkStateSet *set,
144 AtkRealStateSet *real_set;
146 g_return_if_fail (set != NULL);
147 g_return_if_fail (ATK_IS_STATE_SET (set));
149 real_set = (AtkRealStateSet *)set;
151 for (i = 0; i < n_types; i++)
153 real_set->state |= ATK_STATE (types[i]);
158 * atk_state_set_clear_states:
159 * @set: an #AtkStateSet
161 * Removes all states from the state set.
164 atk_state_set_clear_states (AtkStateSet *set)
166 AtkRealStateSet *real_set;
167 g_return_if_fail (set != NULL);
168 g_return_if_fail (ATK_IS_STATE_SET (set));
170 real_set = (AtkRealStateSet *)set;
176 * atk_state_set_contains_state:
177 * @set: an #AtkStateSet
178 * @type: an #AtkStateType
180 * Checks whether the state for the specified type is in the specified set.
182 * Returns: %TRUE if @type is the state type is in @set.
185 atk_state_set_contains_state (AtkStateSet *set,
188 AtkRealStateSet *real_set;
189 g_return_val_if_fail (set != NULL, FALSE);
190 g_return_val_if_fail (ATK_IS_STATE_SET (set), FALSE);
192 real_set = (AtkRealStateSet *)set;
194 if (real_set->state & ATK_STATE (type))
201 * atk_state_set_contains_states:
202 * @set: an #AtkStateSet
203 * @types: an array of #AtkStateType
204 * @n_types: The number of elements in the array
206 * Checks whether the states for all the specified types are in the
209 * Returns: %TRUE if all the states for @type are in @set.
212 atk_state_set_contains_states (AtkStateSet *set,
216 AtkRealStateSet *real_set;
218 g_return_val_if_fail (set != NULL, FALSE);
219 g_return_val_if_fail (ATK_IS_STATE_SET (set), FALSE);
221 real_set = (AtkRealStateSet *)set;
223 for (i = 0; i < n_types; i++)
225 if (!(real_set->state & ATK_STATE (types[i])))
232 * atk_state_set_remove_state:
233 * @set: an #AtkStateSet
236 * Removes the state for the specified type from the state set.
238 * Returns: %TRUE if @type was the state type is in @set.
241 atk_state_set_remove_state (AtkStateSet *set,
244 AtkRealStateSet *real_set;
245 g_return_val_if_fail (set != NULL, FALSE);
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: a new #AtkStateSet which is the intersection of the two sets.
270 atk_state_set_and_sets (AtkStateSet *set,
271 AtkStateSet *compare_set)
273 AtkRealStateSet *real_set, *real_compare_set;
274 AtkStateSet *return_set = NULL;
277 g_return_val_if_fail (set != NULL, FALSE);
278 g_return_val_if_fail (ATK_IS_STATE_SET (set), FALSE);
279 g_return_val_if_fail (compare_set != NULL, FALSE);
280 g_return_val_if_fail (ATK_IS_STATE_SET (compare_set), FALSE);
282 real_set = (AtkRealStateSet *)set;
283 real_compare_set = (AtkRealStateSet *)compare_set;
285 state = real_set->state & real_compare_set->state;
288 return_set = atk_state_set_new();
289 ((AtkRealStateSet *) return_set)->state = state;
295 * atk_state_set_or_sets:
296 * @set: an #AtkStateSet
297 * @compare_set: another #AtkStateSet
299 * Constructs the union of the two sets.
301 * Returns: a new #AtkStateSet which is the union of the two sets,
302 * returning %NULL is empty.
305 atk_state_set_or_sets (AtkStateSet *set,
306 AtkStateSet *compare_set)
308 AtkRealStateSet *real_set, *real_compare_set;
309 AtkStateSet *return_set = NULL;
312 g_return_val_if_fail (set != NULL, FALSE);
313 g_return_val_if_fail (ATK_IS_STATE_SET (set), FALSE);
314 g_return_val_if_fail (compare_set != NULL, FALSE);
315 g_return_val_if_fail (ATK_IS_STATE_SET (compare_set), FALSE);
317 real_set = (AtkRealStateSet *)set;
318 real_compare_set = (AtkRealStateSet *)compare_set;
320 state = real_set->state | real_compare_set->state;
322 return_set = atk_state_set_new();
323 ((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: a new #AtkStateSet which contains the states which are
338 * 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 (set != NULL, FALSE);
349 g_return_val_if_fail (ATK_IS_STATE_SET (set), FALSE);
350 g_return_val_if_fail (compare_set != NULL, FALSE);
351 g_return_val_if_fail (ATK_IS_STATE_SET (compare_set), FALSE);
353 real_set = (AtkRealStateSet *)set;
354 real_compare_set = (AtkRealStateSet *)compare_set;
356 state1 = real_set->state & (~real_compare_set->state);
357 state2 = (~real_set->state) & real_compare_set->state;
358 state = state1 | state2;
362 return_set = atk_state_set_new();
363 ((AtkRealStateSet *) return_set)->state = state;