Add missing <string.h> include. Add missing <string.h> include
[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  "expandable",
36  "expanded",
37  "focusable",
38  "focused",
39  "horizontal",
40  "iconified",
41  "modal",
42  "multi-line",
43  "multiselectable",
44  "opaque",
45  "pressed",
46  "resizeable",
47  "selectable",
48  "selected",
49  "sensitive",
50  "showing",
51  "single-line",
52  "stale",
53  "transient",
54  "vertical",
55  "visible"
56 };
57
58 /**
59  * atk_state_type_register:
60  * @name: a character string describing the new state.
61  *
62  * Register a new object state.
63  *
64  * Returns: an #AtkState value for the new state.
65  **/
66 AtkStateType
67 atk_state_type_register (const gchar *name)
68 {
69   static guint type = ATK_STATE_LAST_DEFINED;
70   if (type < NUM_POSSIBLE_STATES)
71   {
72     state_names[++type] = g_strdup (name); 
73     return (type);
74   }
75   return ATK_STATE_INVALID; /* caller needs to check */
76 }
77
78 /**
79  * atk_state_type_get_name:
80  * @type: The #AtkStateType whose name is required
81  *
82  * Gets the description string describing the #AtkStateType @type.
83  *
84  * Returns: the string describing the state
85  */
86 G_CONST_RETURN gchar*
87 atk_state_type_get_name (AtkStateType state)
88 {
89   gint n;
90
91   if (state == 0)
92     return NULL;
93
94   for (n=0; n<NUM_POSSIBLE_STATES; n++)
95   {
96     if (state == n) 
97       return state_names[n];
98   }
99
100   return NULL;
101 }
102
103 /**
104  * atk_state_type_for_name:
105  * @name: a character string state name
106  *
107  * Gets the #AtkStateType corresponding to the description string @name.
108  *
109  * Returns: an #AtkStateType corresponding to @name 
110  */
111 AtkStateType
112 atk_state_type_for_name (const gchar *name)
113 {
114   gint i;
115
116   g_return_val_if_fail (name != NULL, 0);
117   g_return_val_if_fail (strlen (name) > 0, 0);
118
119   for (i = 0; i < NUM_POSSIBLE_STATES; i++)
120   {
121     if (state_names[i] == NULL)
122       continue; 
123     if (!strcmp(name, state_names[i])) 
124       return i;
125   }
126   return 0;
127 }