* Boston, MA 02111-1307, USA.
*/
-#include "atkstate.h"
+#include "config.h"
+
+#include "atk.h"
+
+#include <string.h>
+
+/**
+ * SECTION:atkstate
+ * @Short_description: An AtkState describes a single state of an object.
+ * @Title:AtkState
+ *
+ * An AtkState describes a single state of an object. The full set of states
+ * that apply to an object at a given time are contained in its #AtkStateSet.
+ * See also #atk_object_ref_state_set and #atk_object_notify_state_change.
+ */
+
+static guint last_type = ATK_STATE_LAST_DEFINED;
#define NUM_POSSIBLE_STATES (sizeof(AtkState)*8)
-static gchar* state_names[NUM_POSSIBLE_STATES] = {
- "invalid",
- "active",
- "armed",
- "busy",
- "checked",
- "collapsed",
- "defunct",
- "editable",
- "expandable",
- "expanded",
- "focusable",
- "focused",
- "horizontal",
- "iconified",
- "modal",
- "multi-line",
- "multiselect,ble",
- "opaque",
- "pressed",
- "resizeable",
- "selectable",
- "selected",
- "sensitive",
- "showing",
- "single-line",
- "transient",
- "vertical",
- "visible"
-};
+static gchar* state_names[NUM_POSSIBLE_STATES];
/**
* atk_state_type_register:
* @name: a character string describing the new state.
*
- * Register a new object state
+ * Register a new object state.
*
* Returns: an #AtkState value for the new state.
**/
AtkStateType
atk_state_type_register (const gchar *name)
{
- static guint type = ATK_STATE_LAST_DEFINED;
- if (type < NUM_POSSIBLE_STATES)
- {
- state_names[++type] = g_strdup (name);
- return (type);
- }
+ g_return_val_if_fail (name, ATK_STATE_INVALID);
+
+ if (last_type < NUM_POSSIBLE_STATES -1)
+ {
+ state_names[++last_type] = g_strdup (name);
+ return (last_type);
+ }
return ATK_STATE_INVALID; /* caller needs to check */
}
* atk_state_type_get_name:
* @type: The #AtkStateType whose name is required
*
- * Gets the description string describing the #AtkStateType @type
+ * Gets the description string describing the #AtkStateType @type.
*
- * Returns: the string describing the state
+ * Returns: the string describing the AtkStateType
*/
-G_CONST_RETURN gchar*
-atk_state_type_get_name (AtkStateType state)
+const gchar*
+atk_state_type_get_name (AtkStateType type)
{
- gint n;
+ GTypeClass *type_class;
+ GEnumValue *value;
+ const gchar *name = NULL;
- if (state == 0)
- return NULL;
+ type_class = g_type_class_ref (ATK_TYPE_STATE_TYPE);
+ g_return_val_if_fail (G_IS_ENUM_CLASS (type_class), NULL);
- for (n=0; n<NUM_POSSIBLE_STATES; n++)
- {
- if (state == n)
- return state_names[n];
- }
+ value = g_enum_get_value (G_ENUM_CLASS (type_class), type);
- return NULL;
+ if (value)
+ {
+ name = value->value_nick;
+ }
+ else
+ {
+ if (type <= last_type)
+ {
+ if (type >= 0)
+ name = state_names[type];
+ }
+ }
+
+ g_type_class_unref (type_class);
+
+ return name;
}
/**
* atk_state_type_for_name:
* @name: a character string state name
*
- * Gets the #AtkStateType corresponding to the description string @name
+ * Gets the #AtkStateType corresponding to the description string @name.
*
* Returns: an #AtkStateType corresponding to @name
*/
AtkStateType
atk_state_type_for_name (const gchar *name)
{
- gint i;
-
- g_return_val_if_fail (name != NULL, 0);
- g_return_val_if_fail (strlen (name) > 0, 0);
-
- for (i = 0; i < NUM_POSSIBLE_STATES; i++)
- {
- if (state_names[i] == NULL)
- continue;
- if (!strcmp(name, state_names[i]))
- return i;
- }
- return 0;
+ GTypeClass *type_class;
+ GEnumValue *value;
+ AtkStateType type = ATK_STATE_INVALID;
+
+ g_return_val_if_fail (name, ATK_STATE_INVALID);
+
+ type_class = g_type_class_ref (ATK_TYPE_STATE_TYPE);
+ g_return_val_if_fail (G_IS_ENUM_CLASS (type_class), ATK_STATE_INVALID);
+
+ value = g_enum_get_value_by_nick (G_ENUM_CLASS (type_class), name);
+
+ if (value)
+ {
+ type = value->value;
+ }
+ else
+ {
+ gint i;
+
+ for (i = ATK_STATE_LAST_DEFINED + 1; i <= last_type; i++)
+ {
+ if (state_names[i] == NULL)
+ continue;
+ if (!strcmp(name, state_names[i]))
+ {
+ type = i;
+ break;
+ }
+ }
+ }
+ return type;
}