From e689f7a2522ed2b860a6978af71bca34f1a55870 Mon Sep 17 00:00:00 2001 From: Padraig O'Briain Date: Mon, 3 Dec 2001 09:07:05 +0000 Subject: Use ATK_TYPE_RELATION_TYPE in atk_relation_type_get_name() and * atk/atkrelation.c: Use ATK_TYPE_RELATION_TYPE in atk_relation_type_get_name() and atk_relation_type_for_name() * atk/atkstate.c: Use ATK_TYPE_STATE_TYPE in atk_state_type_get_name() and atk_state_type_for_name() * tests/testrelation.c, tests/teststateset.c: Update tests as name componenets are separated by hyphen (-) rather than underline (_) --- atk/atkstate.c | 94 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 48 insertions(+), 46 deletions(-) (limited to 'atk/atkstate.c') diff --git a/atk/atkstate.c b/atk/atkstate.c index d56b14e..8dbb495 100755 --- a/atk/atkstate.c +++ b/atk/atkstate.c @@ -18,6 +18,7 @@ */ #include "atkstate.h" +#include "atk-enum-types.h" #include @@ -25,37 +26,7 @@ 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", - "defunct", - "editable", - "enabled", - "expandable", - "expanded", - "focusable", - "focused", - "horizontal", - "iconified", - "modal", - "multi-line", - "multiselectable", - "opaque", - "pressed", - "resizeable", - "selectable", - "selected", - "sensitive", - "showing", - "single-line", - "stale", - "transient", - "vertical", - "visible" -}; +static gchar* state_names[NUM_POSSIBLE_STATES]; /** * atk_state_type_register: @@ -89,16 +60,29 @@ atk_state_type_register (const gchar *name) G_CONST_RETURN gchar* atk_state_type_get_name (AtkStateType type) { - gint n; + GTypeClass *type_class; + GEnumValue *value; + gchar *name = NULL; - if (type < last_type) + type_class = g_type_class_ref (ATK_TYPE_STATE_TYPE); + g_return_val_if_fail (G_IS_ENUM_CLASS (type_class), NULL); + + value = g_enum_get_value (G_ENUM_CLASS (type_class), type); + + if (value) { - n = type; - if (n >= 0) - return state_names[n]; + name = value->value_nick; + } + else + { + if (type <= last_type) + { + if (type >= 0) + name = state_names[type]; + } } - return NULL; + return name; } /** @@ -112,17 +96,35 @@ atk_state_type_get_name (AtkStateType type) AtkStateType atk_state_type_for_name (const gchar *name) { - gint i; + 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); - g_return_val_if_fail (name != NULL, 0); - g_return_val_if_fail (strlen (name) > 0, 0); + value = g_enum_get_value_by_nick (G_ENUM_CLASS (type_class), name); - for (i = 0; i < last_type; i++) + if (value) { - if (state_names[i] == NULL) - continue; - if (!strcmp(name, state_names[i])) - return i; + 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 0; + return type; } -- cgit v1.2.1