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, see <http://www.gnu.org/licenses/>.
24 * @Short_description: An AtkState describes a component's particular state.
27 * An AtkState describes a component's particular state. The actual
28 * state of an component is described by its AtkStateSet, which is a
32 static guint last_type = ATK_STATE_LAST_DEFINED;
34 #define NUM_POSSIBLE_STATES (sizeof(AtkState)*8)
36 static gchar* state_names[NUM_POSSIBLE_STATES];
39 * atk_state_type_register:
40 * @name: a character string describing the new state.
42 * Register a new object state.
44 * Returns: an #AtkState value for the new state.
47 atk_state_type_register (const gchar *name)
49 g_return_val_if_fail (name, ATK_STATE_INVALID);
51 if (last_type < NUM_POSSIBLE_STATES -1)
53 state_names[++last_type] = g_strdup (name);
56 return ATK_STATE_INVALID; /* caller needs to check */
60 * atk_state_type_get_name:
61 * @type: The #AtkStateType whose name is required
63 * Gets the description string describing the #AtkStateType @type.
65 * Returns: the string describing the AtkStateType
68 atk_state_type_get_name (AtkStateType type)
70 GTypeClass *type_class;
72 const gchar *name = NULL;
74 type_class = g_type_class_ref (ATK_TYPE_STATE_TYPE);
75 g_return_val_if_fail (G_IS_ENUM_CLASS (type_class), NULL);
77 value = g_enum_get_value (G_ENUM_CLASS (type_class), type);
81 name = value->value_nick;
85 if (type <= last_type)
88 name = state_names[type];
96 * atk_state_type_for_name:
97 * @name: a character string state name
99 * Gets the #AtkStateType corresponding to the description string @name.
101 * Returns: an #AtkStateType corresponding to @name
104 atk_state_type_for_name (const gchar *name)
106 GTypeClass *type_class;
108 AtkStateType type = ATK_STATE_INVALID;
110 g_return_val_if_fail (name, ATK_STATE_INVALID);
112 type_class = g_type_class_ref (ATK_TYPE_STATE_TYPE);
113 g_return_val_if_fail (G_IS_ENUM_CLASS (type_class), ATK_STATE_INVALID);
115 value = g_enum_get_value_by_nick (G_ENUM_CLASS (type_class), name);
125 for (i = ATK_STATE_LAST_DEFINED + 1; i <= last_type; i++)
127 if (state_names[i] == NULL)
129 if (!strcmp(name, state_names[i]))