X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=atspi%2Fatspi-stateset.c;h=366c48b41ee5004eb8e535daef681e5933ecc203;hb=e1d5412b33463fd2f45dea400c45b107d0c78f42;hp=a5bcc51ce4016c6462459b4071d37de46eb8ad96;hpb=65caa813eda92711d4d6f37f9f2d0709fab35e92;p=platform%2Fupstream%2Fat-spi2-core.git diff --git a/atspi/atspi-stateset.c b/atspi/atspi-stateset.c index a5bcc51..366c48b 100644 --- a/atspi/atspi-stateset.c +++ b/atspi/atspi-stateset.c @@ -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) { @@ -85,11 +39,12 @@ 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. * - * @states: (element-type AtspiStateType): An array of states with which to initialize - * the state set. + * Generates an #AtspiStateSet with the given @states. * * Returns: A new #AtspiStateSet with the given states. **/ @@ -120,28 +75,40 @@ _atspi_state_set_new_internal (AtspiAccessible *accessible, gint64 states) return set; } +/** + * 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. + * + * 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; if (set->accessible && !(set->accessible->cached_properties & ATSPI_CACHE_STATES)) return; - /* TODO: This could perhaps be optimized */ - for (i = 0; state_names [i]; i++) + type_class = g_type_class_ref (ATSPI_TYPE_STATE_TYPE); + + 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); + else + if (enabled) + set->states |= ((gint64)1 << value->value); + else + set->states &= ~((gint64)1 << value->value); + + g_type_class_unref (type_class); } static void @@ -166,12 +133,11 @@ 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. * - * Add a particular #AtspiState to an #AtspiStateSet (i.e. set the - * given state to #TRUE in the stateset. + * Adds a particular #AtspiState to an #AtspiStateSet (i.e. sets the + * given state to #TRUE in the stateset). * **/ void @@ -184,14 +150,14 @@ atspi_state_set_add (AtspiStateSet *set, AtspiStateType state) /** * atspi_state_set_compare: * @set: a pointer to the first #AtspiStateSet object on which to operate. - * @set: a pointer to the second #AtspiStateSet setect on which to operate. + * @set2: a pointer to the second #AtspiStateSet object on which to operate. + * + * Determines the differences between two instances of #AtspiStateSet. * - * Determine the differences between two instances of #AtspiStateSet. - *. - * @see AtspiStateSet_equals(). + * @see #atspi_state_set_equals. * * Returns: (transfer full): an #AtspiStateSet object containing all states - * contained on one of the two sets but not the other. + * contained on one of the two sets but not the other. * **/ AtspiStateSet * @@ -208,10 +174,10 @@ 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. * - * Determine whether a given #AtspiStateSet includes a given state; that is, - * whether @state is true for the stateset in question. + * Determines whether a given #AtspiStateSet includes a given state; that is, + * whether @state is true for the @set in question. * * Returns: #TRUE if @state is true/included in the given #AtspiStateSet, * otherwise #FALSE. @@ -232,14 +198,14 @@ atspi_state_set_contains (AtspiStateSet *set, * @set: a pointer to the first #AtspiStateSet object on which to operate. * @set2: a pointer to the second #AtspiStateSet object on which to operate. * - * Determine whether two instances of #AtspiStateSet are equivalent (i.e. - * consist of the same #AtspiStates). Useful for checking multiple - * state variables at once; construct the target state then compare against it. + * Determines whether two instances of #AtspiStateSet are equivalent (i.e. + * consist of the same #AtspiStates). Useful for checking multiple + * state variables at once. * - * @see AtspiStateSet_compare(). + * @see #atspi_state_set_compare. * * Returns: #TRUE if the two #AtspiStateSets are equivalent, - * otherwise #FALSE. + * otherwise #FALSE. * **/ gboolean @@ -255,10 +221,9 @@ atspi_state_set_equals (AtspiStateSet *set, /** * atspi_state_set_get_states: - * * @set: The #AtspiStateSet to be queried. * - * Return the states in an #AtspiStateSet as an array. + * Returns the states in an #AtspiStateSet as an array. * * Returns: (element-type AtspiStateType) (transfer full): A #GArray of state * types representing the current state. @@ -278,11 +243,7 @@ atspi_state_set_get_states (AtspiStateSet *set) for (i = 0; i < 64; i++) { if (set->states & val) - { - GArray *new_array = g_array_append_val (ret, i); - if (new_array) - ret = new_array; - } + ret = g_array_append_val (ret, i); val <<= 1; } return ret; @@ -290,7 +251,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. @@ -303,11 +263,10 @@ 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 specifiedn state set. + * @state: an #AtspiStateType to remove from the specified @set. * - * Remove a particular #AtspiState to an #AtspiStateSet (i.e. set the + * Removes a particular #AtspiState to an #AtspiStateSet (i.e. sets the * given state to #FALSE in the stateset.) * **/ @@ -317,4 +276,3 @@ atspi_state_set_remove (AtspiStateSet *set, AtspiStateType state) g_return_if_fail (set != NULL); set->states &= ~((gint64)1 << state); } -