gobject-introspection: fix virtual annotations and missing type descriptions
[atk.git] / atk / atkstateset.c
blobd240ee6e10fc8ce7699f8ab965adde15ae40a86a
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 "config.h"
22 #include <glib-object.h>
24 #include "atkobject.h"
25 #include "atkstateset.h"
27 /**
28 * SECTION:atkstateset
29 * @Short_description: An AtkStateSet contains the states of an object.
30 * @Title:AtkStateSet
32 * An AtkStateSet is a read-only representation of the full set of #AtkStates
33 * that apply to an object at a given time. This set is not meant to be
34 * modified, but rather created when #atk_object_ref_state_set() is called.
37 #define ATK_STATE(state_enum) ((AtkState)((guint64)1 << ((state_enum)%64)))
39 struct _AtkRealStateSet
41 GObject parent;
43 AtkState state;
46 typedef struct _AtkRealStateSet AtkRealStateSet;
48 static void atk_state_set_class_init (AtkStateSetClass *klass);
50 GType
51 atk_state_set_get_type (void)
53 static GType type = 0;
55 if (!type)
57 static const GTypeInfo typeInfo =
59 sizeof (AtkStateSetClass),
60 (GBaseInitFunc) NULL,
61 (GBaseFinalizeFunc) NULL,
62 (GClassInitFunc) atk_state_set_class_init,
63 (GClassFinalizeFunc) NULL,
64 NULL,
65 sizeof (AtkRealStateSet),
67 (GInstanceInitFunc) NULL,
68 } ;
69 type = g_type_register_static (G_TYPE_OBJECT, "AtkStateSet", &typeInfo, 0) ;
71 return type;
74 static void
75 atk_state_set_class_init (AtkStateSetClass *klass)
79 /**
80 * atk_state_set_new:
82 * Creates a new empty state set.
84 * Returns: a new #AtkStateSet
85 **/
86 AtkStateSet*
87 atk_state_set_new (void)
89 return (AtkStateSet*) g_object_new (ATK_TYPE_STATE_SET, NULL);
92 /**
93 * atk_state_set_is_empty:
94 * @set: an #AtkStateType
96 * Checks whether the state set is empty, i.e. has no states set.
98 * Returns: %TRUE if @set has no states set, otherwise %FALSE
99 **/
100 gboolean
101 atk_state_set_is_empty (AtkStateSet *set)
103 AtkRealStateSet *real_set;
104 g_return_val_if_fail (ATK_IS_STATE_SET (set), FALSE);
106 real_set = (AtkRealStateSet *)set;
108 if (real_set->state)
109 return FALSE;
110 else
111 return TRUE;
115 * atk_state_set_add_state:
116 * @set: an #AtkStateSet
117 * @type: an #AtkStateType
119 * Adds the state of the specified type to the state set if it is not already
120 * present.
122 * Note that because an #AtkStateSet is a read-only object, this method should
123 * be used to add a state to a newly-created set which will then be returned by
124 * #atk_object_ref_state_set. It should not be used to modify the existing state
125 * of an object. See also #atk_object_notify_state_change.
127 * Returns: %TRUE if the state for @type is not already in @set.
129 gboolean
130 atk_state_set_add_state (AtkStateSet *set,
131 AtkStateType type)
133 AtkRealStateSet *real_set;
134 g_return_val_if_fail (ATK_IS_STATE_SET (set), FALSE);
136 real_set = (AtkRealStateSet *)set;
138 if (real_set->state & ATK_STATE (type))
139 return FALSE;
140 else
142 real_set->state |= ATK_STATE (type);
143 return TRUE;
147 * atk_state_set_add_states:
148 * @set: an #AtkStateSet
149 * @types: (array length=n_types): an array of #AtkStateType
150 * @n_types: The number of elements in the array
152 * Adds the states of the specified types to the state set.
154 * Note that because an #AtkStateSet is a read-only object, this method should
155 * be used to add states to a newly-created set which will then be returned by
156 * #atk_object_ref_state_set. It should not be used to modify the existing state
157 * of an object. See also #atk_object_notify_state_change.
159 void
160 atk_state_set_add_states (AtkStateSet *set,
161 AtkStateType *types,
162 gint n_types)
164 AtkRealStateSet *real_set;
165 gint i;
166 g_return_if_fail (ATK_IS_STATE_SET (set));
168 real_set = (AtkRealStateSet *)set;
170 for (i = 0; i < n_types; i++)
172 real_set->state |= ATK_STATE (types[i]);
177 * atk_state_set_clear_states:
178 * @set: an #AtkStateSet
180 * Removes all states from the state set.
182 void
183 atk_state_set_clear_states (AtkStateSet *set)
185 AtkRealStateSet *real_set;
186 g_return_if_fail (ATK_IS_STATE_SET (set));
188 real_set = (AtkRealStateSet *)set;
190 real_set->state = 0;
194 * atk_state_set_contains_state:
195 * @set: an #AtkStateSet
196 * @type: an #AtkStateType
198 * Checks whether the state for the specified type is in the specified set.
200 * Returns: %TRUE if @type is the state type is in @set.
202 gboolean
203 atk_state_set_contains_state (AtkStateSet *set,
204 AtkStateType type)
206 AtkRealStateSet *real_set;
207 g_return_val_if_fail (ATK_IS_STATE_SET (set), FALSE);
209 real_set = (AtkRealStateSet *)set;
211 if (real_set->state & ATK_STATE (type))
212 return TRUE;
213 else
214 return FALSE;
218 * atk_state_set_contains_states:
219 * @set: an #AtkStateSet
220 * @types: (array length=n_types): an array of #AtkStateType
221 * @n_types: The number of elements in the array
223 * Checks whether the states for all the specified types are in the
224 * specified set.
226 * Returns: %TRUE if all the states for @type are in @set.
228 gboolean
229 atk_state_set_contains_states (AtkStateSet *set,
230 AtkStateType *types,
231 gint n_types)
233 AtkRealStateSet *real_set;
234 gint i;
235 g_return_val_if_fail (ATK_IS_STATE_SET (set), FALSE);
237 real_set = (AtkRealStateSet *)set;
239 for (i = 0; i < n_types; i++)
241 if (!(real_set->state & ATK_STATE (types[i])))
242 return FALSE;
244 return TRUE;
248 * atk_state_set_remove_state:
249 * @set: an #AtkStateSet
250 * @type: an #AtkType
252 * Removes the state for the specified type from the state set.
254 * Note that because an #AtkStateSet is a read-only object, this method should
255 * be used to remove a state to a newly-created set which will then be returned
256 * by #atk_object_ref_state_set. It should not be used to modify the existing
257 * state of an object. See also #atk_object_notify_state_change.
259 * Returns: %TRUE if @type was the state type is in @set.
261 gboolean
262 atk_state_set_remove_state (AtkStateSet *set,
263 AtkStateType type)
265 AtkRealStateSet *real_set;
266 g_return_val_if_fail (ATK_IS_STATE_SET (set), FALSE);
268 real_set = (AtkRealStateSet *)set;
270 if (real_set->state & ATK_STATE (type))
272 real_set->state ^= ATK_STATE (type);
273 return TRUE;
275 else
276 return FALSE;
280 * atk_state_set_and_sets:
281 * @set: an #AtkStateSet
282 * @compare_set: another #AtkStateSet
284 * Constructs the intersection of the two sets, returning %NULL if the
285 * intersection is empty.
287 * Returns: (transfer full): a new #AtkStateSet which is the intersection of
288 * the two sets.
290 AtkStateSet*
291 atk_state_set_and_sets (AtkStateSet *set,
292 AtkStateSet *compare_set)
294 AtkRealStateSet *real_set, *real_compare_set;
295 AtkStateSet *return_set = NULL;
296 AtkState state;
298 g_return_val_if_fail (ATK_IS_STATE_SET (set), NULL);
299 g_return_val_if_fail (ATK_IS_STATE_SET (compare_set), NULL);
301 real_set = (AtkRealStateSet *)set;
302 real_compare_set = (AtkRealStateSet *)compare_set;
304 state = real_set->state & real_compare_set->state;
305 if (state)
307 return_set = atk_state_set_new();
308 ((AtkRealStateSet *) return_set)->state = state;
310 return return_set;
314 * atk_state_set_or_sets:
315 * @set: an #AtkStateSet
316 * @compare_set: another #AtkStateSet
318 * Constructs the union of the two sets.
320 * Returns: (nullable) (transfer full): a new #AtkStateSet which is
321 * the union of the two sets, returning %NULL is empty.
323 AtkStateSet*
324 atk_state_set_or_sets (AtkStateSet *set,
325 AtkStateSet *compare_set)
327 AtkRealStateSet *real_set, *real_compare_set;
328 AtkStateSet *return_set = NULL;
329 AtkState state;
331 g_return_val_if_fail (ATK_IS_STATE_SET (set), NULL);
332 g_return_val_if_fail (ATK_IS_STATE_SET (compare_set), NULL);
334 real_set = (AtkRealStateSet *)set;
335 real_compare_set = (AtkRealStateSet *)compare_set;
337 state = real_set->state | real_compare_set->state;
339 if (state)
341 return_set = atk_state_set_new();
342 ((AtkRealStateSet *) return_set)->state = state;
345 return return_set;
349 * atk_state_set_xor_sets:
350 * @set: an #AtkStateSet
351 * @compare_set: another #AtkStateSet
353 * Constructs the exclusive-or of the two sets, returning %NULL is empty.
354 * The set returned by this operation contains the states in exactly
355 * one of the two sets.
357 * Returns: (transfer full): a new #AtkStateSet which contains the states
358 * which are in exactly one of the two sets.
360 AtkStateSet*
361 atk_state_set_xor_sets (AtkStateSet *set,
362 AtkStateSet *compare_set)
364 AtkRealStateSet *real_set, *real_compare_set;
365 AtkStateSet *return_set = NULL;
366 AtkState state, state1, state2;
368 g_return_val_if_fail (ATK_IS_STATE_SET (set), NULL);
369 g_return_val_if_fail (ATK_IS_STATE_SET (compare_set), NULL);
371 real_set = (AtkRealStateSet *)set;
372 real_compare_set = (AtkRealStateSet *)compare_set;
374 state1 = real_set->state & (~real_compare_set->state);
375 state2 = (~real_set->state) & real_compare_set->state;
376 state = state1 | state2;
378 if (state)
380 return_set = atk_state_set_new();
381 ((AtkRealStateSet *) return_set)->state = state;
383 return return_set;