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)((guint64)1 << ((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 (ATK_IS_STATE_SET (set), FALSE);
94 real_set = (AtkRealStateSet *)set;
103 * atk_state_set_add_state:
104 * @set: an #AtkStateSet
105 * @type: an #AtkStateType
107 * Add a new state for the specified type to the current state set if
108 * it is not already present.
110 * Returns: %TRUE if the state for @type is not already in @set.
113 atk_state_set_add_state (AtkStateSet *set,
116 AtkRealStateSet *real_set;
117 g_return_val_if_fail (ATK_IS_STATE_SET (set), FALSE);
119 real_set = (AtkRealStateSet *)set;
121 if (real_set->state & ATK_STATE (type))
125 real_set->state |= ATK_STATE (type);
130 * atk_state_set_add_states:
131 * @set: an #AtkStateSet
132 * @types: an array of #AtkStateType
133 * @n_types: The number of elements in the array
135 * Add the states for the specified types to the current state set.
138 atk_state_set_add_states (AtkStateSet *set,
142 AtkRealStateSet *real_set;
144 g_return_if_fail (ATK_IS_STATE_SET (set));
146 real_set = (AtkRealStateSet *)set;
148 for (i = 0; i < n_types; i++)
150 real_set->state |= ATK_STATE (types[i]);
155 * atk_state_set_clear_states:
156 * @set: an #AtkStateSet
158 * Removes all states from the state set.
161 atk_state_set_clear_states (AtkStateSet *set)
163 AtkRealStateSet *real_set;
164 g_return_if_fail (ATK_IS_STATE_SET (set));
166 real_set = (AtkRealStateSet *)set;
172 * atk_state_set_contains_state:
173 * @set: an #AtkStateSet
174 * @type: an #AtkStateType
176 * Checks whether the state for the specified type is in the specified set.
178 * Returns: %TRUE if @type is the state type is in @set.
181 atk_state_set_contains_state (AtkStateSet *set,
184 AtkRealStateSet *real_set;
185 g_return_val_if_fail (ATK_IS_STATE_SET (set), FALSE);
187 real_set = (AtkRealStateSet *)set;
189 if (real_set->state & ATK_STATE (type))
196 * atk_state_set_contains_states:
197 * @set: an #AtkStateSet
198 * @types: an array of #AtkStateType
199 * @n_types: The number of elements in the array
201 * Checks whether the states for all the specified types are in the
204 * Returns: %TRUE if all the states for @type are in @set.
207 atk_state_set_contains_states (AtkStateSet *set,
211 AtkRealStateSet *real_set;
213 g_return_val_if_fail (ATK_IS_STATE_SET (set), FALSE);
215 real_set = (AtkRealStateSet *)set;
217 for (i = 0; i < n_types; i++)
219 if (!(real_set->state & ATK_STATE (types[i])))
226 * atk_state_set_remove_state:
227 * @set: an #AtkStateSet
230 * Removes the state for the specified type from the state set.
232 * Returns: %TRUE if @type was the state type is in @set.
235 atk_state_set_remove_state (AtkStateSet *set,
238 AtkRealStateSet *real_set;
239 g_return_val_if_fail (ATK_IS_STATE_SET (set), FALSE);
241 real_set = (AtkRealStateSet *)set;
243 if (real_set->state & ATK_STATE (type))
245 real_set->state ^= ATK_STATE (type);
253 * atk_state_set_and_sets:
254 * @set: an #AtkStateSet
255 * @compare_set: another #AtkStateSet
257 * Constructs the intersection of the two sets, returning %NULL if the
258 * intersection is empty.
260 * Returns: a new #AtkStateSet which is the intersection of the two sets.
263 atk_state_set_and_sets (AtkStateSet *set,
264 AtkStateSet *compare_set)
266 AtkRealStateSet *real_set, *real_compare_set;
267 AtkStateSet *return_set = NULL;
270 g_return_val_if_fail (ATK_IS_STATE_SET (set), NULL);
271 g_return_val_if_fail (ATK_IS_STATE_SET (compare_set), NULL);
273 real_set = (AtkRealStateSet *)set;
274 real_compare_set = (AtkRealStateSet *)compare_set;
276 state = real_set->state & real_compare_set->state;
279 return_set = atk_state_set_new();
280 ((AtkRealStateSet *) return_set)->state = state;
286 * atk_state_set_or_sets:
287 * @set: an #AtkStateSet
288 * @compare_set: another #AtkStateSet
290 * Constructs the union of the two sets.
292 * Returns: a new #AtkStateSet which is the union of the two sets,
293 * returning %NULL is empty.
296 atk_state_set_or_sets (AtkStateSet *set,
297 AtkStateSet *compare_set)
299 AtkRealStateSet *real_set, *real_compare_set;
300 AtkStateSet *return_set = NULL;
303 g_return_val_if_fail (ATK_IS_STATE_SET (set), NULL);
304 g_return_val_if_fail (ATK_IS_STATE_SET (compare_set), NULL);
306 real_set = (AtkRealStateSet *)set;
307 real_compare_set = (AtkRealStateSet *)compare_set;
309 state = real_set->state | real_compare_set->state;
311 return_set = atk_state_set_new();
312 ((AtkRealStateSet *) return_set)->state = state;
318 * atk_state_set_xor_sets:
319 * @set: an #AtkStateSet
320 * @compare_set: another #AtkStateSet
322 * Constructs the exclusive-or of the two sets, returning %NULL is empty.
323 * The set returned by this operation contains the states in exactly
324 * one of the two sets.
326 * Returns: a new #AtkStateSet which contains the states which are
327 * in exactly one of the two sets.
330 atk_state_set_xor_sets (AtkStateSet *set,
331 AtkStateSet *compare_set)
333 AtkRealStateSet *real_set, *real_compare_set;
334 AtkStateSet *return_set = NULL;
335 AtkState state, state1, state2;
337 g_return_val_if_fail (ATK_IS_STATE_SET (set), NULL);
338 g_return_val_if_fail (ATK_IS_STATE_SET (compare_set), NULL);
340 real_set = (AtkRealStateSet *)set;
341 real_compare_set = (AtkRealStateSet *)compare_set;
343 state1 = real_set->state & (~real_compare_set->state);
344 state2 = (~real_set->state) & real_compare_set->state;
345 state = state1 | state2;
349 return_set = atk_state_set_new();
350 ((AtkRealStateSet *) return_set)->state = state;