From 6f0884d36ef773439675a36090711071c4030ffd Mon Sep 17 00:00:00 2001 From: Mike Gorse Date: Wed, 24 Nov 2010 14:40:21 -0500 Subject: State and action fixes --- atspi/atspi-accessible.c | 4 +- atspi/atspi-misc.c | 4 +- atspi/atspi-stateset.c | 165 +++++++++++++++++++++++++++++++++++++++++++++-- atspi/atspi-stateset.h | 20 +++++- atspi/atspi-table.c | 2 +- 5 files changed, 183 insertions(+), 12 deletions(-) diff --git a/atspi/atspi-accessible.c b/atspi/atspi-accessible.c index 356e7fe0..e7ff0229 100644 --- a/atspi/atspi-accessible.c +++ b/atspi/atspi-accessible.c @@ -806,7 +806,6 @@ atspi_accessible_get_application (AtspiAccessible *accessible) g_object_ref (ATSPI_ACTION (accessible)) : NULL); } -#if 0 /** * atspi_accessible_get_action: * @obj: a pointer to the #AtspiAccessible instance to query. @@ -820,7 +819,7 @@ AtspiAction * atspi_accessible_get_action (AtspiAccessible *accessible) { return (_atspi_accessible_is_a (accessible, atspi_interface_action) ? - accessible : NULL); + g_object_ref (ATSPI_ACTION (accessible)) : NULL); } /** @@ -838,7 +837,6 @@ atspi_accessible_get_collection (AtspiAccessible *accessible) return (_atspi_accessible_is_a (accessible, atspi_interface_collection) ? g_object_ref (ATSPI_COLLECTION (accessible)) : NULL); } -#endif /** * atspi_accessible_get_component: diff --git a/atspi/atspi-misc.c b/atspi/atspi-misc.c index eeea8766..2523e65b 100644 --- a/atspi/atspi-misc.c +++ b/atspi/atspi-misc.c @@ -424,13 +424,13 @@ add_accessible_from_iter (DBusMessageIter *iter) if (count != 2) { g_warning ("at-spi: expected 2 values in states array; got %d\n", count); - accessible->states = atspi_state_set_new (accessible, 0); + accessible->states = _atspi_state_set_new_internal (accessible, 0); } else { guint64 val = ((guint64)states [1]) << 32; val += states [0]; - accessible->states = atspi_state_set_new (accessible, val); + accessible->states = _atspi_state_set_new_internal (accessible, val); } dbus_message_iter_next (&iter_struct); diff --git a/atspi/atspi-stateset.c b/atspi/atspi-stateset.c index 0da98b02..4cba34e2 100644 --- a/atspi/atspi-stateset.c +++ b/atspi/atspi-stateset.c @@ -61,8 +61,30 @@ atspi_state_set_class_init (AtspiStateSetClass* klass) { } +/* + * atspi_state_set_new: + * + * @states: (element-type AtspiStateType): An array of states with which to initialize + * the state set. + * + * Returns: A new #AtspiStateSet with the given states. + **/ +AtspiStateSet * +atspi_state_set_new (GArray *states) +{ + AtspiStateSet *set = g_object_new (ATSPI_TYPE_STATE_SET, NULL); + gint i; + + if (!set || !states) + return set; + + for (i = 0; i < states->len; i++) + atspi_state_set_add (set, g_array_index (states, AtspiStateType, i)); + return states; +} + AtspiStateSet * -atspi_state_set_new (AtspiAccessible *accessible, gint64 states) +_atspi_state_set_new_internal (AtspiAccessible *accessible, gint64 states) { AtspiStateSet *set; @@ -74,11 +96,13 @@ atspi_state_set_new (AtspiAccessible *accessible, gint64 states) return set; } -void atspi_state_set_set_by_name (AtspiStateSet *set, const gchar *name, gboolean enabled) +void +atspi_state_set_set_by_name (AtspiStateSet *set, const gchar *name, gboolean enabled) { gint i = 0; - if (!(set->accessible->cached_properties & ATSPI_CACHE_STATES)) + if (set->accessible && + !(set->accessible->cached_properties & ATSPI_CACHE_STATES)) return; /* TODO: This could perhaps be optimized */ @@ -102,7 +126,8 @@ refresh_states (AtspiStateSet *set) GArray *state_array; dbus_uint32_t *states; - if ((set->accessible->cached_properties & ATSPI_CACHE_STATES)) + if (!set->accessible || + (set->accessible->cached_properties & ATSPI_CACHE_STATES)) return; if (!_atspi_dbus_call (set->accessible, atspi_interface_accessible, "GetState", NULL, "=>au", &state_array)) @@ -115,6 +140,46 @@ refresh_states (AtspiStateSet *set) g_array_free (state_array, TRUE); } +/** + * 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. + * + **/ +void +atspi_state_set_add (AtspiStateSet *set, AtspiStateType state) +{ + g_return_if_fail (set != NULL); + set->states |= (1 << 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. + * + * Determine the differences between two instances of #AtspiStateSet. + *. + * @see AtspiStateSet_equals(). + * + * Returns: (transfer full): an #AtspiStateSet object containing all states + * contained on one of the two sets but not the other. + * + **/ +AtspiStateSet * +atspi_state_set_compare (AtspiStateSet *set, + AtspiStateSet *set2) +{ + g_return_val_if_fail (set != NULL, NULL); + g_return_val_if_fail (set2 != NULL, NULL); + + return _atspi_state_set_new_internal (NULL, set->states ^ set2->states); +} + /** * atspi_state_set_contains: * @set: a pointer to the #AtspiStateSet object on which to operate. @@ -135,3 +200,95 @@ atspi_state_set_contains (AtspiStateSet *set, refresh_states (set); return (set->states & (1 << state)) ? TRUE : FALSE; } + +/** + * 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. + * + * 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. + * + * @see AtspiStateSet_compare(). + * + * Returns: #TRUE if the two #AtspiStateSets are equivalent, + * otherwise #FALSE. + * + **/ +gboolean +atspi_state_set_equals (AtspiStateSet *set, + AtspiStateSet *set2) +{ + if (set == set2) + return TRUE; + if (set == NULL || set2 == NULL) + return FALSE; + return (set->states == set2->states); +} + +/** + * atspi_state_set_get_states: + * + * @set: The #AtspiStateSet to be queried. + * + * Return the states in an #AtspiStateSet as an array. + * + * Returns: (element-type AtspiStateType) (transfer full): A #GArray of state + * types representing the current state. + **/ +GArray * +atspi_state_set_get_states (AtspiStateSet *set) +{ + gint i = 0; + guint64 val = 1; + GArray *ret; + + g_return_val_if_fail (set != NULL, NULL); + refresh_states (set); + ret = g_array_new (TRUE, TRUE, sizeof (AtspiStateType)); + if (!ret) + return NULL; + 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; + } + val <<= 1; + } + return ret; +} + +/** + * atspi_state_set_is_empty: + * + * @set: The #AtspiStateSet to query. + * + * Returns: #TRUE if the state set contains no states; #FALSE otherwise. + **/ +gboolean +atspi_state_set_is_empty (AtspiStateSet *set) +{ + return (set->states == 0); +} + +/** + * 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. + * + * Remove a particular #AtspiState to an #AtspiStateSet (i.e. set the + * given state to #FALSE in the stateset.) + * + **/ +void +atspi_state_set_remove (AtspiStateSet *set, AtspiStateType state) +{ + g_return_if_fail (set != NULL); + set->states &= ~(1 << state); +} + diff --git a/atspi/atspi-stateset.h b/atspi/atspi-stateset.h index 6b674e42..948b3ee4 100644 --- a/atspi/atspi-stateset.h +++ b/atspi/atspi-stateset.h @@ -24,8 +24,24 @@ struct _AtspiStateSetClass GType atspi_state_set_get_type (void); -AtspiStateSet * -atspi_state_set_new (struct _AtspiAccessible *accessible, gint64 states); +AtspiStateSet * atspi_state_set_new (GArray *states); + +void atspi_state_set_set_by_name (AtspiStateSet *set, const gchar *name, gboolean enabled); + +void atspi_state_set_add (AtspiStateSet *set, AtspiStateType state); + +AtspiStateSet * atspi_state_set_compare (AtspiStateSet *set, AtspiStateSet *set2); gboolean atspi_state_set_contains (AtspiStateSet *set, AtspiStateType state); + +gboolean atspi_state_set_equals (AtspiStateSet *set, AtspiStateSet *set2); + +GArray * atspi_state_set_get_states (AtspiStateSet *set); + +gboolean atspi_state_set_is_empty (AtspiStateSet *set); + +void atspi_state_set_remove (AtspiStateSet *set, AtspiStateType state); + +AtspiStateSet * _atspi_state_set_new_internal (struct _AtspiAccessible *accessible, gint64 states); + #endif /* _ATSPI_STATE_SET_H_ */ diff --git a/atspi/atspi-table.c b/atspi/atspi-table.c index 03524a7c..9e28b810 100644 --- a/atspi/atspi-table.c +++ b/atspi/atspi-table.c @@ -374,7 +374,7 @@ atspi_table_get_column_header (AtspiTable *obj, g_return_val_if_fail (obj != NULL, NULL); - reply = !_atspi_dbus_call (obj, atspi_interface_table, "GetCoumnHeader", error, "i", d_column); + reply = !_atspi_dbus_call (obj, atspi_interface_table, "GetCoumnHeader", error, "i", &d_column); return _atspi_dbus_return_accessible_from_message (reply); } -- cgit v1.2.1