Fix atspi_text_get_bounded_ranges
[platform/upstream/at-spi2-core.git] / atspi / atspi-stateset.c
index b5619e8..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)
 {
@@ -87,9 +41,8 @@ atspi_state_set_class_init (AtspiStateSetClass* klass)
 
 /**
  * atspi_state_set_new:
- *
  * @states: (element-type AtspiStateType): An array of states with which the
- * method initializes the state set.
+ *          method initializes the state set.
  *
  * Generates an #AtspiStateSet with the given @states.
  *
@@ -124,38 +77,35 @@ _atspi_state_set_new_internal (AtspiAccessible *accessible, gint64 states)
 
 /**
  * atspi_state_set_set_by_name:
- *
  * @set: a pointer to the #AtspiStateSet object on which to operate.
- *
  * @name: a string corresponding to a state name.
- * 
- * @enabled: if #TRUE, @name should be enabled in the @set in question; otherwise, it
- * should be disabled. 
+ * @enabled: if #TRUE, @name should be enabled in the @set in question;
+ *          otherwise, it should be disabled.
  *
  * Enables/disables a state in an #AtspiStateSet according to its @name.
  **/
 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
@@ -180,9 +130,7 @@ refresh_states (AtspiStateSet *set)
 
 /**
  * atspi_state_set_add:
- *
  * @set: a pointer to the #AtspiStateSet object on which to operate.
- *
  * @state: an #AtspiStateType to be added to the specified #AtspiStateSet.
  *
  * Adds a particular #AtspiState to an #AtspiStateSet (i.e. sets the
@@ -198,9 +146,7 @@ atspi_state_set_add (AtspiStateSet *set, AtspiStateType state)
 
 /**
  * atspi_state_set_compare:
- *
  * @set: a pointer to the first #AtspiStateSet object on which to operate.
- *
  * @set2: a pointer to the second #AtspiStateSet object on which to operate.
  *
  * Determines the differences between two instances of #AtspiStateSet.
@@ -223,14 +169,12 @@ atspi_state_set_compare (AtspiStateSet *set,
 
 /**
  * atspi_state_set_contains:
- *
  * @set: a pointer to the #AtspiStateSet object on which to operate.
- *
  * @state: an #AtspiStateType for which the specified #AtspiStateSet
- *       will be queried.
+ *          will be queried.
  *
  * Determines whether a given #AtspiStateSet includes a given state; that is,
- *       whether @state is true for the @set in question.
+ *          whether @state is true for the @set in question.
  *
  * Returns: #TRUE if @state is true/included in the given #AtspiStateSet,
  *          otherwise #FALSE.
@@ -248,14 +192,12 @@ atspi_state_set_contains (AtspiStateSet *set,
 
 /**
  * atspi_state_set_equals:
- *
  * @set: a pointer to the first #AtspiStateSet object on which to operate.
- *
  * @set2: a pointer to the second #AtspiStateSet object on which to operate.
  *
  * Determines whether two instances of #AtspiStateSet are equivalent (i.e.
- *         consist of the same #AtspiStates).  Useful for checking multiple
- *         state variables at once.
+ *          consist of the same #AtspiStates).  Useful for checking multiple
+ *          state variables at once.
  *
  * @see #atspi_state_set_compare.
  *
@@ -276,7 +218,6 @@ atspi_state_set_equals (AtspiStateSet *set,
 
 /**
  * atspi_state_set_get_states:
- *
  * @set: The #AtspiStateSet to be queried.
  *
  * Returns the states in an #AtspiStateSet as an array.
@@ -307,7 +248,6 @@ atspi_state_set_get_states (AtspiStateSet *set)
 
 /**
  * atspi_state_set_is_empty:
- *
  * @set: The #AtspiStateSet to query.
  *
  * Returns: #TRUE if the state set contains no states; #FALSE otherwise.
@@ -320,9 +260,7 @@ atspi_state_set_is_empty (AtspiStateSet *set)
 
 /**
  * atspi_state_set_remove:
- *
  * @set: a pointer to the #AtspiStateSet object on which to operate.
- *
  * @state: an #AtspiStateType to remove from the specified @set.
  *
  * Removes a particular #AtspiState to an #AtspiStateSet (i.e. sets the
@@ -335,4 +273,3 @@ atspi_state_set_remove (AtspiStateSet *set, AtspiStateType state)
   g_return_if_fail (set != NULL);
   set->states &= ~((gint64)1 << state);
 }
-