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.
22 #include <glib-object.h>
24 #include "atkobject.h"
25 #include "atkstateset.h"
29 * @Short_description: An AtkStateSet contains the states of an object.
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
46 typedef struct _AtkRealStateSet AtkRealStateSet
;
48 static void atk_state_set_class_init (AtkStateSetClass
*klass
);
51 atk_state_set_get_type (void)
53 static GType type
= 0;
57 static const GTypeInfo typeInfo
=
59 sizeof (AtkStateSetClass
),
61 (GBaseFinalizeFunc
) NULL
,
62 (GClassInitFunc
) atk_state_set_class_init
,
63 (GClassFinalizeFunc
) NULL
,
65 sizeof (AtkRealStateSet
),
67 (GInstanceInitFunc
) NULL
,
69 type
= g_type_register_static (G_TYPE_OBJECT
, "AtkStateSet", &typeInfo
, 0) ;
75 atk_state_set_class_init (AtkStateSetClass
*klass
)
82 * Creates a new empty state set.
84 * Returns: a new #AtkStateSet
87 atk_state_set_new (void)
89 return (AtkStateSet
*) g_object_new (ATK_TYPE_STATE_SET
, NULL
);
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
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
;
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
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.
130 atk_state_set_add_state (AtkStateSet
*set
,
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
))
142 real_set
->state
|= ATK_STATE (type
);
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.
160 atk_state_set_add_states (AtkStateSet
*set
,
164 AtkRealStateSet
*real_set
;
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.
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
;
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.
203 atk_state_set_contains_state (AtkStateSet
*set
,
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
))
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
226 * Returns: %TRUE if all the states for @type are in @set.
229 atk_state_set_contains_states (AtkStateSet
*set
,
233 AtkRealStateSet
*real_set
;
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
])))
248 * atk_state_set_remove_state:
249 * @set: an #AtkStateSet
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.
262 atk_state_set_remove_state (AtkStateSet
*set
,
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
);
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
291 atk_state_set_and_sets (AtkStateSet
*set
,
292 AtkStateSet
*compare_set
)
294 AtkRealStateSet
*real_set
, *real_compare_set
;
295 AtkStateSet
*return_set
= NULL
;
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
;
307 return_set
= atk_state_set_new();
308 ((AtkRealStateSet
*) return_set
)->state
= state
;
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.
324 atk_state_set_or_sets (AtkStateSet
*set
,
325 AtkStateSet
*compare_set
)
327 AtkRealStateSet
*real_set
, *real_compare_set
;
328 AtkStateSet
*return_set
= NULL
;
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
;
341 return_set
= atk_state_set_new();
342 ((AtkRealStateSet
*) return_set
)->state
= state
;
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.
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
;
380 return_set
= atk_state_set_new();
381 ((AtkRealStateSet
*) return_set
)->state
= state
;