X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=atk%2Fatkstate.c;h=581b64194bd4bfa0abd1e34c4c90474a307e69e1;hb=de851d88f8e37557f436452fe1e669b8f9ee2bca;hp=bf8d7aa9353a5a1a47096b03aa2eb4999c67b1c0;hpb=0fbca6aea104c85ea30edf4037dc5566be3b8c91;p=platform%2Fupstream%2Fatk.git diff --git a/atk/atkstate.c b/atk/atkstate.c index bf8d7aa..581b641 100755 --- a/atk/atkstate.c +++ b/atk/atkstate.c @@ -17,59 +17,44 @@ * Boston, MA 02111-1307, USA. */ -#include "atkstate.h" +#include "atk.h" + +#include + +/** + * SECTION:atkstate + * @Short_description: An AtkState describes a component's particular state. + * @Title:AtkState + * + * An AtkState describes a component's particular state. The actual + * state of an component is described by its AtkStateSet, which is a + * set of AtkStates. + */ + +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", - "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: * @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 */ } @@ -77,49 +62,78 @@ atk_state_type_register (const gchar *name) * 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; nvalue_nick; + } + else + { + if (type <= last_type) + { + if (type >= 0) + name = state_names[type]; + } + } + + 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; }