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