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