Version 0.7
[atk.git] / atk / atkstate.c
blobd56b14ef5d5ea4b6ac8d6237325d77cfced2b0e9
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 "atkstate.h"
22 #include <string.h>
24 static guint last_type = ATK_STATE_LAST_DEFINED;
26 #define NUM_POSSIBLE_STATES (sizeof(AtkState)*8)
28 static gchar* state_names[NUM_POSSIBLE_STATES] = {
29 "invalid",
30 "active",
31 "armed",
32 "busy",
33 "checked",
34 "defunct",
35 "editable",
36 "enabled",
37 "expandable",
38 "expanded",
39 "focusable",
40 "focused",
41 "horizontal",
42 "iconified",
43 "modal",
44 "multi-line",
45 "multiselectable",
46 "opaque",
47 "pressed",
48 "resizeable",
49 "selectable",
50 "selected",
51 "sensitive",
52 "showing",
53 "single-line",
54 "stale",
55 "transient",
56 "vertical",
57 "visible"
60 /**
61 * atk_state_type_register:
62 * @name: a character string describing the new state.
64 * Register a new object state.
66 * Returns: an #AtkState value for the new state.
67 **/
68 AtkStateType
69 atk_state_type_register (const gchar *name)
71 g_return_val_if_fail (name, ATK_STATE_INVALID);
73 if (last_type < NUM_POSSIBLE_STATES -1)
75 state_names[++last_type] = g_strdup (name);
76 return (last_type);
78 return ATK_STATE_INVALID; /* caller needs to check */
81 /**
82 * atk_state_type_get_name:
83 * @type: The #AtkStateType whose name is required
85 * Gets the description string describing the #AtkStateType @type.
87 * Returns: the string describing the AtkStateType
89 G_CONST_RETURN gchar*
90 atk_state_type_get_name (AtkStateType type)
92 gint n;
94 if (type < last_type)
96 n = type;
97 if (n >= 0)
98 return state_names[n];
101 return NULL;
105 * atk_state_type_for_name:
106 * @name: a character string state name
108 * Gets the #AtkStateType corresponding to the description string @name.
110 * Returns: an #AtkStateType corresponding to @name
112 AtkStateType
113 atk_state_type_for_name (const gchar *name)
115 gint i;
117 g_return_val_if_fail (name != NULL, 0);
118 g_return_val_if_fail (strlen (name) > 0, 0);
120 for (i = 0; i < last_type; i++)
122 if (state_names[i] == NULL)
123 continue;
124 if (!strcmp(name, state_names[i]))
125 return i;
127 return 0;