Fix atspi_text_get_bounded_ranges
[platform/upstream/at-spi2-core.git] / atspi / atspi-stateset.c
index fd6fc0c..33c28a7 100644 (file)
@@ -28,52 +28,6 @@ static void atspi_state_set_class_init (AtspiStateSetClass *klass);
 
 G_DEFINE_TYPE (AtspiStateSet, atspi_state_set, G_TYPE_OBJECT)
 
-static const char *state_names [] =
-{
-  "invalid",
-  "active",
-  "armed",
-  "busy",
-  "checked",
-  "collapsed",
-  "defunct",
-  "editable",
-  "enabled",
-  "expandable",
-  "expanded",
-  "focusable",
-  "focused",
-  "has-tool-tip",
-  "horizontal",
-  "iconified",
-  "modal",
-  "multi-line",
-  "multiselectable",
-  "opaque",
-  "pressed",
-  "resizable",
-  "selectable",
-  "selected",
-  "sensitive",
-  "showing",
-  "singleLine",
-  "stale",
-  "transient",
-  "vertical",
-  "visible",
-  "manages-descendants",
-  "indeterminate",
-  "required",
-  "truncated",
-  "animated",
-  "invalid-entry",
-  "supports-autocompletion",
-  "selectable-text",
-  "is-default",
-  "visited",
-  NULL
-};
-
 static void
 atspi_state_set_init (AtspiStateSet *set)
 {
@@ -133,25 +87,25 @@ _atspi_state_set_new_internal (AtspiAccessible *accessible, gint64 states)
 void
 atspi_state_set_set_by_name (AtspiStateSet *set, const gchar *name, gboolean enabled)
 {
-  gint i = 0;
+  GTypeClass *type_class;
+  GEnumValue *value;
+
+  type_class = g_type_class_ref (ATSPI_TYPE_STATE_TYPE);
 
   if (set->accessible &&
       !(set->accessible->cached_properties & ATSPI_CACHE_STATES))
     return;
 
-  /* TODO: This could perhaps be optimized */
-  for (i = 0; state_names [i]; i++)
+  value = g_enum_get_value_by_nick (G_ENUM_CLASS (type_class), name);
+  if (!value)
   {
-    if (!strcmp (state_names [i], name))
-    {
-      if (enabled)
-        set->states |= ((gint64)1 << i);
-      else
-        set->states &= ~((gint64)1 << i);
-      return;
-    }
+    g_warning ("AT-SPI: Attempt to set unknown state '%s'", name);
   }
-  g_warning ("at-spi: Attempt to set unknown state '%s'", name);
+
+  if (enabled)
+    set->states |= ((gint64)1 << value->value);
+  else
+    set->states &= ~((gint64)1 << value->value);
 }
 
 static void
@@ -319,4 +273,3 @@ atspi_state_set_remove (AtspiStateSet *set, AtspiStateType state)
   g_return_if_fail (set != NULL);
   set->states &= ~((gint64)1 << state);
 }
-