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 determines a component's state set.
32 * An AtkStateSet determines a component's state set. It is composed
33 * of a set of AtkStates.
36 #define ATK_STATE(state_enum) ((AtkState)((guint64)1 << ((state_enum)%64)))
38 struct _AtkRealStateSet
45 typedef struct _AtkRealStateSet AtkRealStateSet
;
47 static void atk_state_set_class_init (AtkStateSetClass
*klass
);
50 atk_state_set_get_type (void)
52 static GType type
= 0;
56 static const GTypeInfo typeInfo
=
58 sizeof (AtkStateSetClass
),
60 (GBaseFinalizeFunc
) NULL
,
61 (GClassInitFunc
) atk_state_set_class_init
,
62 (GClassFinalizeFunc
) NULL
,
64 sizeof (AtkRealStateSet
),
66 (GInstanceInitFunc
) NULL
,
68 type
= g_type_register_static (G_TYPE_OBJECT
, "AtkStateSet", &typeInfo
, 0) ;
74 atk_state_set_class_init (AtkStateSetClass
*klass
)
81 * Creates a new empty state set.
83 * Returns: a new #AtkStateSet
86 atk_state_set_new (void)
88 return (AtkStateSet
*) g_object_new (ATK_TYPE_STATE_SET
, NULL
);
92 * atk_state_set_is_empty:
93 * @set: an #AtkStateType
95 * Checks whether the state set is empty, i.e. has no states set.
97 * Returns: %TRUE if @set has no states set, otherwise %FALSE
100 atk_state_set_is_empty (AtkStateSet
*set
)
102 AtkRealStateSet
*real_set
;
103 g_return_val_if_fail (ATK_IS_STATE_SET (set
), FALSE
);
105 real_set
= (AtkRealStateSet
*)set
;
114 * atk_state_set_add_state:
115 * @set: an #AtkStateSet
116 * @type: an #AtkStateType
118 * Add a new state for the specified type to the current state set if
119 * it is not already present.
121 * Returns: %TRUE if the state for @type is not already in @set.
124 atk_state_set_add_state (AtkStateSet
*set
,
127 AtkRealStateSet
*real_set
;
128 g_return_val_if_fail (ATK_IS_STATE_SET (set
), FALSE
);
130 real_set
= (AtkRealStateSet
*)set
;
132 if (real_set
->state
& ATK_STATE (type
))
136 real_set
->state
|= ATK_STATE (type
);
141 * atk_state_set_add_states:
142 * @set: an #AtkStateSet
143 * @types: (array length=n_types): an array of #AtkStateType
144 * @n_types: The number of elements in the array
146 * Add the states for the specified types to the current state set.
149 atk_state_set_add_states (AtkStateSet
*set
,
153 AtkRealStateSet
*real_set
;
155 g_return_if_fail (ATK_IS_STATE_SET (set
));
157 real_set
= (AtkRealStateSet
*)set
;
159 for (i
= 0; i
< n_types
; i
++)
161 real_set
->state
|= ATK_STATE (types
[i
]);
166 * atk_state_set_clear_states:
167 * @set: an #AtkStateSet
169 * Removes all states from the state set.
172 atk_state_set_clear_states (AtkStateSet
*set
)
174 AtkRealStateSet
*real_set
;
175 g_return_if_fail (ATK_IS_STATE_SET (set
));
177 real_set
= (AtkRealStateSet
*)set
;
183 * atk_state_set_contains_state:
184 * @set: an #AtkStateSet
185 * @type: an #AtkStateType
187 * Checks whether the state for the specified type is in the specified set.
189 * Returns: %TRUE if @type is the state type is in @set.
192 atk_state_set_contains_state (AtkStateSet
*set
,
195 AtkRealStateSet
*real_set
;
196 g_return_val_if_fail (ATK_IS_STATE_SET (set
), FALSE
);
198 real_set
= (AtkRealStateSet
*)set
;
200 if (real_set
->state
& ATK_STATE (type
))
207 * atk_state_set_contains_states:
208 * @set: an #AtkStateSet
209 * @types: (array length=n_types): an array of #AtkStateType
210 * @n_types: The number of elements in the array
212 * Checks whether the states for all the specified types are in the
215 * Returns: %TRUE if all the states for @type are in @set.
218 atk_state_set_contains_states (AtkStateSet
*set
,
222 AtkRealStateSet
*real_set
;
224 g_return_val_if_fail (ATK_IS_STATE_SET (set
), FALSE
);
226 real_set
= (AtkRealStateSet
*)set
;
228 for (i
= 0; i
< n_types
; i
++)
230 if (!(real_set
->state
& ATK_STATE (types
[i
])))
237 * atk_state_set_remove_state:
238 * @set: an #AtkStateSet
241 * Removes the state for the specified type from the state set.
243 * Returns: %TRUE if @type was the state type is in @set.
246 atk_state_set_remove_state (AtkStateSet
*set
,
249 AtkRealStateSet
*real_set
;
250 g_return_val_if_fail (ATK_IS_STATE_SET (set
), FALSE
);
252 real_set
= (AtkRealStateSet
*)set
;
254 if (real_set
->state
& ATK_STATE (type
))
256 real_set
->state
^= ATK_STATE (type
);
264 * atk_state_set_and_sets:
265 * @set: an #AtkStateSet
266 * @compare_set: another #AtkStateSet
268 * Constructs the intersection of the two sets, returning %NULL if the
269 * intersection is empty.
271 * Returns: (transfer full): a new #AtkStateSet which is the intersection of
275 atk_state_set_and_sets (AtkStateSet
*set
,
276 AtkStateSet
*compare_set
)
278 AtkRealStateSet
*real_set
, *real_compare_set
;
279 AtkStateSet
*return_set
= NULL
;
282 g_return_val_if_fail (ATK_IS_STATE_SET (set
), NULL
);
283 g_return_val_if_fail (ATK_IS_STATE_SET (compare_set
), NULL
);
285 real_set
= (AtkRealStateSet
*)set
;
286 real_compare_set
= (AtkRealStateSet
*)compare_set
;
288 state
= real_set
->state
& real_compare_set
->state
;
291 return_set
= atk_state_set_new();
292 ((AtkRealStateSet
*) return_set
)->state
= state
;
298 * atk_state_set_or_sets:
299 * @set: an #AtkStateSet
300 * @compare_set: another #AtkStateSet
302 * Constructs the union of the two sets.
304 * Returns: (nullable) (transfer full): a new #AtkStateSet which is
305 * the union of the two sets, returning %NULL is empty.
308 atk_state_set_or_sets (AtkStateSet
*set
,
309 AtkStateSet
*compare_set
)
311 AtkRealStateSet
*real_set
, *real_compare_set
;
312 AtkStateSet
*return_set
= NULL
;
315 g_return_val_if_fail (ATK_IS_STATE_SET (set
), NULL
);
316 g_return_val_if_fail (ATK_IS_STATE_SET (compare_set
), NULL
);
318 real_set
= (AtkRealStateSet
*)set
;
319 real_compare_set
= (AtkRealStateSet
*)compare_set
;
321 state
= real_set
->state
| real_compare_set
->state
;
325 return_set
= atk_state_set_new();
326 ((AtkRealStateSet
*) return_set
)->state
= state
;
333 * atk_state_set_xor_sets:
334 * @set: an #AtkStateSet
335 * @compare_set: another #AtkStateSet
337 * Constructs the exclusive-or of the two sets, returning %NULL is empty.
338 * The set returned by this operation contains the states in exactly
339 * one of the two sets.
341 * Returns: (transfer full): a new #AtkStateSet which contains the states
342 * which are in exactly one of the two sets.
345 atk_state_set_xor_sets (AtkStateSet
*set
,
346 AtkStateSet
*compare_set
)
348 AtkRealStateSet
*real_set
, *real_compare_set
;
349 AtkStateSet
*return_set
= NULL
;
350 AtkState state
, state1
, state2
;
352 g_return_val_if_fail (ATK_IS_STATE_SET (set
), NULL
);
353 g_return_val_if_fail (ATK_IS_STATE_SET (compare_set
), NULL
);
355 real_set
= (AtkRealStateSet
*)set
;
356 real_compare_set
= (AtkRealStateSet
*)compare_set
;
358 state1
= real_set
->state
& (~real_compare_set
->state
);
359 state2
= (~real_set
->state
) & real_compare_set
->state
;
360 state
= state1
| state2
;
364 return_set
= atk_state_set_new();
365 ((AtkRealStateSet
*) return_set
)->state
= state
;