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"
27 * @Short_description: An AtkStateSet determines a component's state set.
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
43 typedef struct _AtkRealStateSet AtkRealStateSet
;
45 static void atk_state_set_class_init (AtkStateSetClass
*klass
);
48 atk_state_set_get_type (void)
50 static GType type
= 0;
54 static const GTypeInfo typeInfo
=
56 sizeof (AtkStateSetClass
),
58 (GBaseFinalizeFunc
) NULL
,
59 (GClassInitFunc
) atk_state_set_class_init
,
60 (GClassFinalizeFunc
) NULL
,
62 sizeof (AtkRealStateSet
),
64 (GInstanceInitFunc
) NULL
,
66 type
= g_type_register_static (G_TYPE_OBJECT
, "AtkStateSet", &typeInfo
, 0) ;
72 atk_state_set_class_init (AtkStateSetClass
*klass
)
79 * Creates a new empty state set.
81 * Returns: a new #AtkStateSet
84 atk_state_set_new (void)
86 return (AtkStateSet
*) g_object_new (ATK_TYPE_STATE_SET
, NULL
);
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
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
;
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.
122 atk_state_set_add_state (AtkStateSet
*set
,
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
))
134 real_set
->state
|= ATK_STATE (type
);
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.
147 atk_state_set_add_states (AtkStateSet
*set
,
151 AtkRealStateSet
*real_set
;
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.
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
;
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.
190 atk_state_set_contains_state (AtkStateSet
*set
,
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
))
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
213 * Returns: %TRUE if all the states for @type are in @set.
216 atk_state_set_contains_states (AtkStateSet
*set
,
220 AtkRealStateSet
*real_set
;
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
])))
235 * atk_state_set_remove_state:
236 * @set: an #AtkStateSet
239 * Removes the state for the specified type from the state set.
241 * Returns: %TRUE if @type was the state type is in @set.
244 atk_state_set_remove_state (AtkStateSet
*set
,
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
);
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
273 atk_state_set_and_sets (AtkStateSet
*set
,
274 AtkStateSet
*compare_set
)
276 AtkRealStateSet
*real_set
, *real_compare_set
;
277 AtkStateSet
*return_set
= NULL
;
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
;
289 return_set
= atk_state_set_new();
290 ((AtkRealStateSet
*) return_set
)->state
= state
;
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.
306 atk_state_set_or_sets (AtkStateSet
*set
,
307 AtkStateSet
*compare_set
)
309 AtkRealStateSet
*real_set
, *real_compare_set
;
310 AtkStateSet
*return_set
= NULL
;
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
;
323 return_set
= atk_state_set_new();
324 ((AtkRealStateSet
*) return_set
)->state
= state
;
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.
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
;
362 return_set
= atk_state_set_new();
363 ((AtkRealStateSet
*) return_set
)->state
= state
;