atk/atkstate.[c|h] Add ATK_STATE_ENABLED so we can distinguish between a
[platform/upstream/atk.git] / atk / atkstate.c
1 /* ATK -  Accessibility Toolkit
2  * Copyright 2001 Sun Microsystems Inc.
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #include "atkstate.h"
21
22 #include <string.h>
23
24 #define NUM_POSSIBLE_STATES               (sizeof(AtkState)*8)
25
26 static gchar* state_names[NUM_POSSIBLE_STATES] = {
27  "invalid",
28  "active",
29  "armed",
30  "busy",
31  "checked",
32  "collapsed",
33  "defunct",
34  "editable",
35  "enabled",
36  "expandable",
37  "expanded",
38  "focusable",
39  "focused",
40  "horizontal",
41  "iconified",
42  "modal",
43  "multi-line",
44  "multiselectable",
45  "opaque",
46  "pressed",
47  "resizeable",
48  "selectable",
49  "selected",
50  "sensitive",
51  "showing",
52  "single-line",
53  "stale",
54  "transient",
55  "vertical",
56  "visible"
57 };
58
59 /**
60  * atk_state_type_register:
61  * @name: a character string describing the new state.
62  *
63  * Register a new object state.
64  *
65  * Returns: an #AtkState value for the new state.
66  **/
67 AtkStateType
68 atk_state_type_register (const gchar *name)
69 {
70   static guint type = ATK_STATE_LAST_DEFINED;
71   if (type < NUM_POSSIBLE_STATES)
72   {
73     state_names[++type] = g_strdup (name); 
74     return (type);
75   }
76   return ATK_STATE_INVALID; /* caller needs to check */
77 }
78
79 /**
80  * atk_state_type_get_name:
81  * @type: The #AtkStateType whose name is required
82  *
83  * Gets the description string describing the #AtkStateType @type.
84  *
85  * Returns: the string describing the state
86  */
87 G_CONST_RETURN gchar*
88 atk_state_type_get_name (AtkStateType state)
89 {
90   gint n;
91
92   if (state == 0)
93     return NULL;
94
95   for (n=0; n<NUM_POSSIBLE_STATES; n++)
96   {
97     if (state == n) 
98       return state_names[n];
99   }
100
101   return NULL;
102 }
103
104 /**
105  * atk_state_type_for_name:
106  * @name: a character string state name
107  *
108  * Gets the #AtkStateType corresponding to the description string @name.
109  *
110  * Returns: an #AtkStateType corresponding to @name 
111  */
112 AtkStateType
113 atk_state_type_for_name (const gchar *name)
114 {
115   gint i;
116
117   g_return_val_if_fail (name != NULL, 0);
118   g_return_val_if_fail (strlen (name) > 0, 0);
119
120   for (i = 0; i < NUM_POSSIBLE_STATES; i++)
121   {
122     if (state_names[i] == NULL)
123       continue; 
124     if (!strcmp(name, state_names[i])) 
125       return i;
126   }
127   return 0;
128 }