MSVC Introspection Build: Fix build
[atk.git] / atk / atkstateset.c
blob1497bed9586aabb0e62229371d4eda140cbf451d
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 /**
26 * SECTION:atkstateset
27 * @Short_description: An AtkStateSet determines a component's state set.
28 * @Title:AtkStateSet
30 * An AtkStateSet determines a component's state set. It is composed
31 * of a set of AtkStates.
34 #define ATK_STATE(state_enum) ((AtkState)((guint64)1 << ((state_enum)%64)))
36 struct _AtkRealStateSet
38 GObject parent;
40 AtkState state;
43 typedef struct _AtkRealStateSet AtkRealStateSet;
45 static void atk_state_set_class_init (AtkStateSetClass *klass);
47 GType
48 atk_state_set_get_type (void)
50 static GType type = 0;
52 if (!type)
54 static const GTypeInfo typeInfo =
56 sizeof (AtkStateSetClass),
57 (GBaseInitFunc) NULL,
58 (GBaseFinalizeFunc) NULL,
59 (GClassInitFunc) atk_state_set_class_init,
60 (GClassFinalizeFunc) NULL,
61 NULL,
62 sizeof (AtkRealStateSet),
64 (GInstanceInitFunc) NULL,
65 } ;
66 type = g_type_register_static (G_TYPE_OBJECT, "AtkStateSet", &typeInfo, 0) ;
68 return type;
71 static void
72 atk_state_set_class_init (AtkStateSetClass *klass)
76 /**
77 * atk_state_set_new:
79 * Creates a new empty state set.
81 * Returns: a new #AtkStateSet
82 **/
83 AtkStateSet*
84 atk_state_set_new (void)
86 return (AtkStateSet*) g_object_new (ATK_TYPE_STATE_SET, NULL);
89 /**
90 * atk_state_set_is_empty:
91 * @set: an #AtkStateType
93 * Checks whether the state set is empty, i.e. has no states set.
95 * Returns: %TRUE if @set has no states set, otherwise %FALSE
96 **/
97 gboolean
98 atk_state_set_is_empty (AtkStateSet *set)
100 AtkRealStateSet *real_set;
101 g_return_val_if_fail (ATK_IS_STATE_SET (set), FALSE);
103 real_set = (AtkRealStateSet *)set;
105 if (real_set->state)
106 return FALSE;
107 else
108 return TRUE;
112 * atk_state_set_add_state:
113 * @set: an #AtkStateSet
114 * @type: an #AtkStateType
116 * Add a new state for the specified type to the current state set if
117 * it is not already present.
119 * Returns: %TRUE if the state for @type is not already in @set.
121 gboolean
122 atk_state_set_add_state (AtkStateSet *set,
123 AtkStateType type)
125 AtkRealStateSet *real_set;
126 g_return_val_if_fail (ATK_IS_STATE_SET (set), FALSE);
128 real_set = (AtkRealStateSet *)set;
130 if (real_set->state & ATK_STATE (type))
131 return FALSE;
132 else
134 real_set->state |= ATK_STATE (type);
135 return TRUE;
139 * atk_state_set_add_states:
140 * @set: an #AtkStateSet
141 * @types: (array length=n_types): an array of #AtkStateType
142 * @n_types: The number of elements in the array
144 * Add the states for the specified types to the current state set.
146 void
147 atk_state_set_add_states (AtkStateSet *set,
148 AtkStateType *types,
149 gint n_types)
151 AtkRealStateSet *real_set;
152 gint i;
153 g_return_if_fail (ATK_IS_STATE_SET (set));
155 real_set = (AtkRealStateSet *)set;
157 for (i = 0; i < n_types; i++)
159 real_set->state |= ATK_STATE (types[i]);
164 * atk_state_set_clear_states:
165 * @set: an #AtkStateSet
167 * Removes all states from the state set.
169 void
170 atk_state_set_clear_states (AtkStateSet *set)
172 AtkRealStateSet *real_set;
173 g_return_if_fail (ATK_IS_STATE_SET (set));
175 real_set = (AtkRealStateSet *)set;
177 real_set->state = 0;
181 * atk_state_set_contains_state:
182 * @set: an #AtkStateSet
183 * @type: an #AtkStateType
185 * Checks whether the state for the specified type is in the specified set.
187 * Returns: %TRUE if @type is the state type is in @set.
189 gboolean
190 atk_state_set_contains_state (AtkStateSet *set,
191 AtkStateType type)
193 AtkRealStateSet *real_set;
194 g_return_val_if_fail (ATK_IS_STATE_SET (set), FALSE);
196 real_set = (AtkRealStateSet *)set;
198 if (real_set->state & ATK_STATE (type))
199 return TRUE;
200 else
201 return FALSE;
205 * atk_state_set_contains_states:
206 * @set: an #AtkStateSet
207 * @types: (array length=n_types): an array of #AtkStateType
208 * @n_types: The number of elements in the array
210 * Checks whether the states for all the specified types are in the
211 * specified set.
213 * Returns: %TRUE if all the states for @type are in @set.
215 gboolean
216 atk_state_set_contains_states (AtkStateSet *set,
217 AtkStateType *types,
218 gint n_types)
220 AtkRealStateSet *real_set;
221 gint i;
222 g_return_val_if_fail (ATK_IS_STATE_SET (set), FALSE);
224 real_set = (AtkRealStateSet *)set;
226 for (i = 0; i < n_types; i++)
228 if (!(real_set->state & ATK_STATE (types[i])))
229 return FALSE;
231 return TRUE;
235 * atk_state_set_remove_state:
236 * @set: an #AtkStateSet
237 * @type: an #AtkType
239 * Removes the state for the specified type from the state set.
241 * Returns: %TRUE if @type was the state type is in @set.
243 gboolean
244 atk_state_set_remove_state (AtkStateSet *set,
245 AtkStateType type)
247 AtkRealStateSet *real_set;
248 g_return_val_if_fail (ATK_IS_STATE_SET (set), FALSE);
250 real_set = (AtkRealStateSet *)set;
252 if (real_set->state & ATK_STATE (type))
254 real_set->state ^= ATK_STATE (type);
255 return TRUE;
257 else
258 return FALSE;
262 * atk_state_set_and_sets:
263 * @set: an #AtkStateSet
264 * @compare_set: another #AtkStateSet
266 * Constructs the intersection of the two sets, returning %NULL if the
267 * intersection is empty.
269 * Returns: (transfer full): a new #AtkStateSet which is the intersection of
270 * the two sets.
272 AtkStateSet*
273 atk_state_set_and_sets (AtkStateSet *set,
274 AtkStateSet *compare_set)
276 AtkRealStateSet *real_set, *real_compare_set;
277 AtkStateSet *return_set = NULL;
278 AtkState state;
280 g_return_val_if_fail (ATK_IS_STATE_SET (set), NULL);
281 g_return_val_if_fail (ATK_IS_STATE_SET (compare_set), NULL);
283 real_set = (AtkRealStateSet *)set;
284 real_compare_set = (AtkRealStateSet *)compare_set;
286 state = real_set->state & real_compare_set->state;
287 if (state)
289 return_set = atk_state_set_new();
290 ((AtkRealStateSet *) return_set)->state = state;
292 return return_set;
296 * atk_state_set_or_sets:
297 * @set: an #AtkStateSet
298 * @compare_set: another #AtkStateSet
300 * Constructs the union of the two sets.
302 * Returns: (transfer full): a new #AtkStateSet which is the union of the two
303 * sets, returning %NULL is empty.
305 AtkStateSet*
306 atk_state_set_or_sets (AtkStateSet *set,
307 AtkStateSet *compare_set)
309 AtkRealStateSet *real_set, *real_compare_set;
310 AtkStateSet *return_set = NULL;
311 AtkState state;
313 g_return_val_if_fail (ATK_IS_STATE_SET (set), NULL);
314 g_return_val_if_fail (ATK_IS_STATE_SET (compare_set), NULL);
316 real_set = (AtkRealStateSet *)set;
317 real_compare_set = (AtkRealStateSet *)compare_set;
319 state = real_set->state | real_compare_set->state;
321 if (state)
323 return_set = atk_state_set_new();
324 ((AtkRealStateSet *) return_set)->state = state;
327 return return_set;
331 * atk_state_set_xor_sets:
332 * @set: an #AtkStateSet
333 * @compare_set: another #AtkStateSet
335 * Constructs the exclusive-or of the two sets, returning %NULL is empty.
336 * The set returned by this operation contains the states in exactly
337 * one of the two sets.
339 * Returns: (transfer full): a new #AtkStateSet which contains the states
340 * which are in exactly one of the two sets.
342 AtkStateSet*
343 atk_state_set_xor_sets (AtkStateSet *set,
344 AtkStateSet *compare_set)
346 AtkRealStateSet *real_set, *real_compare_set;
347 AtkStateSet *return_set = NULL;
348 AtkState state, state1, state2;
350 g_return_val_if_fail (ATK_IS_STATE_SET (set), NULL);
351 g_return_val_if_fail (ATK_IS_STATE_SET (compare_set), NULL);
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;
360 if (state)
362 return_set = atk_state_set_new();
363 ((AtkRealStateSet *) return_set)->state = state;
365 return return_set;