Remove property accessible-state; use signal state-change instead Change
[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 static guint type = ATK_STATE_LAST_DEFINED;
25
26 #define NUM_POSSIBLE_STATES               (sizeof(AtkState)*8)
27
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"
58 };
59
60 /**
61  * atk_state_type_register:
62  * @name: a character string describing the new state.
63  *
64  * Register a new object state.
65  *
66  * Returns: an #AtkState value for the new state.
67  **/
68 AtkStateType
69 atk_state_type_register (const gchar *name)
70 {
71
72   if (type < NUM_POSSIBLE_STATES -1)
73   {
74     state_names[++type] = g_strdup (name); 
75     return (type);
76   }
77   return ATK_STATE_INVALID; /* caller needs to check */
78 }
79
80 /**
81  * atk_state_type_get_name:
82  * @type: The #AtkStateType whose name is required
83  *
84  * Gets the description string describing the #AtkStateType @type.
85  *
86  * Returns: the string describing the state
87  */
88 G_CONST_RETURN gchar*
89 atk_state_type_get_name (AtkStateType state)
90 {
91   gint n;
92
93   if (state < type)
94     {
95       n = state; 
96       return state_names[n];
97     }
98
99   return NULL;
100 }
101
102 /**
103  * atk_state_type_for_name:
104  * @name: a character string state name
105  *
106  * Gets the #AtkStateType corresponding to the description string @name.
107  *
108  * Returns: an #AtkStateType corresponding to @name 
109  */
110 AtkStateType
111 atk_state_type_for_name (const gchar *name)
112 {
113   gint i;
114
115   g_return_val_if_fail (name != NULL, 0);
116   g_return_val_if_fail (strlen (name) > 0, 0);
117
118   for (i = 0; i < type; i++)
119   {
120     if (state_names[i] == NULL)
121       continue; 
122     if (!strcmp(name, state_names[i])) 
123       return i;
124   }
125   return 0;
126 }