[at-spi2-core] Some attribute-related fixes



commit f0d109c0b784e2554b0e3410310e9ee5221d7dee
Author: Mike Gorse <mgorse novell com>
Date:   Thu Dec 9 16:13:11 2010 -0500

    Some attribute-related fixes

 atspi/atspi-accessible.c   |   13 +-----
 atspi/atspi-document.c     |    5 +--
 atspi/atspi-misc-private.h |    4 +-
 atspi/atspi-misc.c         |   14 +++++--
 atspi/atspi-text.c         |   93 +++++++++++++++++--------------------------
 atspi/atspi-text.h         |   21 +---------
 6 files changed, 55 insertions(+), 95 deletions(-)
---
diff --git a/atspi/atspi-accessible.c b/atspi/atspi-accessible.c
index c4927bd..70ec533 100644
--- a/atspi/atspi-accessible.c
+++ b/atspi/atspi-accessible.c
@@ -585,14 +585,11 @@ GHashTable *
 atspi_accessible_get_attributes (AtspiAccessible *obj, GError **error)
 {
   DBusMessage *message;
-  GHashTable *ret;
 
     g_return_val_if_fail (obj != NULL, NULL);
 
   message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
-  ret = _atspi_dbus_hash_from_message (message);
-  dbus_message_unref (message);
-  return ret;
+  return _atspi_dbus_return_hash_from_message (message);
 }
 
 /**
@@ -611,15 +608,11 @@ GArray *
 atspi_accessible_get_attributes_as_array (AtspiAccessible *obj, GError **error)
 {
   DBusMessage *message;
-  GArray *ret;
 
     g_return_val_if_fail (obj != NULL, NULL);
 
   message = _atspi_dbus_call_partial (obj, atspi_interface_accessible, "GetAttributes", error, "");
-  ret = _atspi_dbus_attribute_array_from_message (message);
-  if (message)
-    dbus_message_unref (message);
-  return ret;
+  return _atspi_dbus_return_attribute_array_from_message (message);
 }
 
 /**
@@ -646,7 +639,7 @@ atspi_accessible_get_application (AtspiAccessible *obj, GError **error)
   }
 }
 
-/* Applicatio-specific methods */
+/* Application-specific methods */
 
 /**
  * atspi_accessible_get_toolkit_name:
diff --git a/atspi/atspi-document.c b/atspi/atspi-document.c
index be742b4..87feb04 100644
--- a/atspi/atspi-document.c
+++ b/atspi/atspi-document.c
@@ -90,14 +90,11 @@ GHashTable *
 atspi_document_get_attributes (AtspiDocument *obj, GError **error)
 {
   DBusMessage *message;
-  GHashTable *ret;
 
     g_return_val_if_fail (obj != NULL, NULL);
 
   message = _atspi_dbus_call_partial (obj, atspi_interface_document, "GetAttributes", error, "");
-  ret = _atspi_dbus_hash_from_message (message);
-  dbus_message_unref (message);
-  return ret;
+  return _atspi_dbus_return_hash_from_message (message);
 }
 
 static void
diff --git a/atspi/atspi-misc-private.h b/atspi/atspi-misc-private.h
index 133e032..ec87049 100644
--- a/atspi/atspi-misc-private.h
+++ b/atspi/atspi-misc-private.h
@@ -133,11 +133,11 @@ dbus_bool_t _atspi_dbus_get_property (gpointer obj, const char *interface, const
 
 DBusMessage * _atspi_dbus_send_with_reply_and_block (DBusMessage *message);
 
-GHashTable *_atspi_dbus_hash_from_message (DBusMessage *message);
+GHashTable *_atspi_dbus_return_hash_from_message (DBusMessage *message);
 
 GHashTable *_atspi_dbus_hash_from_iter (DBusMessageIter *iter);
 
-GArray *_atspi_dbus_attribute_array_from_message (DBusMessage *message);
+GArray *_atspi_dbus_return_attribute_array_from_message (DBusMessage *message);
 
 GArray *_atspi_dbus_attribute_array_from_iter (DBusMessageIter *iter);
 
diff --git a/atspi/atspi-misc.c b/atspi/atspi-misc.c
index 38087a0..8976abe 100644
--- a/atspi/atspi-misc.c
+++ b/atspi/atspi-misc.c
@@ -1141,14 +1141,17 @@ _atspi_dbus_send_with_reply_and_block (DBusMessage *message)
 }
 
 GHashTable *
-_atspi_dbus_hash_from_message (DBusMessage *message)
+_atspi_dbus_return_hash_from_message (DBusMessage *message)
 {
   DBusMessageIter iter;
+  GHashTable *ret;
 
   _ATSPI_DBUS_CHECK_SIG (message, "a{ss}", NULL);
 
   dbus_message_iter_init (message, &iter);
-  return _atspi_dbus_hash_from_iter (&iter);
+  ret = _atspi_dbus_hash_from_iter (&iter);
+  dbus_message_unref (message);
+  return ret;
 }
 
 GHashTable *
@@ -1172,15 +1175,18 @@ _atspi_dbus_hash_from_iter (DBusMessageIter *iter)
 }
 
 GArray *
-_atspi_dbus_attribute_array_from_message (DBusMessage *message)
+_atspi_dbus_return_attribute_array_from_message (DBusMessage *message)
 {
   DBusMessageIter iter;
+  GArray *ret;
 
   _ATSPI_DBUS_CHECK_SIG (message, "a{ss}", NULL);
 
   dbus_message_iter_init (message, &iter);
 
-  return _atspi_dbus_attribute_array_from_iter (&iter);
+  ret = _atspi_dbus_attribute_array_from_iter (&iter);
+  dbus_message_unref (message);
+  return ret;
 }
 
 GArray *
diff --git a/atspi/atspi-text.c b/atspi/atspi-text.c
index 41d9743..88ac10a 100644
--- a/atspi/atspi-text.c
+++ b/atspi/atspi-text.c
@@ -38,31 +38,6 @@ atspi_range_copy (AtspiRange *src)
 
 G_DEFINE_BOXED_TYPE (AtspiRange, atspi_range, atspi_range_copy, g_free)
 
-static AtspiRangedAttributeSet *
-atspi_ranged_attribute_set_copy (AtspiRangedAttributeSet *src)
-{
-  AtspiRangedAttributeSet *dst = g_new (AtspiRangedAttributeSet, 1);
-
-  if (dst)
-  {
-    dst->attributes = g_object_ref (src->attributes);
-    dst->start_offset = src->start_offset;
-    dst->end_offset = src->end_offset;
-  }
-  return dst;
-}
-
-static void
-atspi_ranged_attribute_set_free (AtspiRangedAttributeSet *set)
-{
-  g_object_unref (set->attributes);
-  g_free (set);
-}
-
-G_DEFINE_BOXED_TYPE (AtspiRangedAttributeSet, atspi_ranged_attribute_set,
-                    atspi_ranged_attribute_set_copy,
-                    atspi_ranged_attribute_set_free)
-
 static AtspiTextRange *
 atspi_text_range_copy (AtspiTextRange *src)
 {
@@ -162,45 +137,49 @@ atspi_text_get_caret_offset (AtspiText *obj, GError **error)
  * @obj: a pointer to the #AtspiText object to query.
  * @offset: a long integer indicating the offset from which the attribute
  *        search is based.
+ * @start_offset: (out): a #gint indicating the start of the desired text
+ *                range.
+ * @end_offset: (out): a #gint indicating the first character past the desired
+ *              range.
  *
  * Get the attributes applied to a range of text from an #AtspiText
  *          object, and the bounds of the range.
  *          The text attributes correspond to CSS attributes where possible,
  *
- * Returns: an #AtspiRangedAttributeSet describing the attributes at the
- * given character offset
+ * Returns: (element-type gchar* gchar*) (transfer full): a #GHashTable
+ *          describing the attributes at the given character offset
  **/
-AtspiRangedAttributeSet *
+GHashTable *
 atspi_text_get_attributes (AtspiText *obj,
-			      gint offset,
-			      GError **error)
+			   gint offset,
+			   gint *start_offset,
+			   gint *end_offset,
+			   GError **error)
 {
   dbus_int32_t d_offset = offset;
   dbus_int32_t d_start_offset, d_end_offset;
   GHashTable *hash;
   DBusMessage *reply;
   DBusMessageIter iter;
-  AtspiRangedAttributeSet *ret = g_new0 (AtspiRangedAttributeSet, 1);
-
-  if (!ret)
-    return NULL;
-  ret->start_offset = ret->end_offset = -1;
+  GHashTable *ret;
 
   if (obj == NULL)
-   return ret;
+   return NULL;
 
   reply = _atspi_dbus_call_partial (obj, atspi_interface_text, "GetAttributes", error, "i", d_offset);
-  _ATSPI_DBUS_CHECK_SIG (reply, "{ss}ii", ret)
+  _ATSPI_DBUS_CHECK_SIG (reply, "a{ss}ii", ret)
 
   dbus_message_iter_init (reply, &iter);
-  ret->attributes = _atspi_dbus_hash_from_iter (&iter);
+  ret = _atspi_dbus_hash_from_iter (&iter);
   dbus_message_iter_next (&iter);
 
   dbus_message_iter_get_basic (&iter, &d_start_offset);
-  ret->start_offset = d_start_offset;
+  if (start_offset)
+    *start_offset = d_start_offset;
   dbus_message_iter_next (&iter);
   dbus_message_iter_get_basic (&iter, &d_end_offset);
-  ret->end_offset = d_end_offset;
+  if (end_offset)
+    *end_offset = d_start_offset;
 
   dbus_message_unref (reply);
   return ret;
@@ -215,13 +194,20 @@ atspi_text_get_attributes (AtspiText *obj,
  *                 attributes which are explicitly set on the current attribute 
  *                 run, omitting any attributes which are inherited from the 
  *                 default values.
+ * @start_offset: (out): a #gint indicating the start of the desired text
+ *                range.
+ * @end_offset: (out): a #gint indicating the first character past the desired
+ *              range.
  *
- * Returns: the AttributeSet defined at offset, optionally including the 'default' attributes.
+ * Returns: (element-type gchar* gchar*) (transfer full): the AttributeSet
+ *          defined at offset, optionally including the 'default' attributes.
  **/
-AtspiRangedAttributeSet *
+GHashTable *
 atspi_text_get_attribute_run (AtspiText *obj,
 			      gint offset,
 			      gboolean include_defaults,
+			      gint *start_offset,
+			      gint *end_offset,
 			      GError **error)
 {
   dbus_int32_t d_offset = offset;
@@ -229,29 +215,27 @@ atspi_text_get_attribute_run (AtspiText *obj,
   GHashTable *hash;
   DBusMessage *reply;
   DBusMessageIter iter;
-  AtspiRangedAttributeSet *ret = g_new0 (AtspiRangedAttributeSet, 1);
-
-  if (!ret)
-    return NULL;
-  ret->start_offset = ret->end_offset = -1;
+  GHashTable *ret;
 
   if (obj == NULL)
-   return ret;
+   return NULL;
 
   reply = _atspi_dbus_call_partial (obj, atspi_interface_text,
                                     "GetAttributeRun", error, "ib", d_offset,
                                     include_defaults);
-  _ATSPI_DBUS_CHECK_SIG (reply, "{ss}ii", ret)
+  _ATSPI_DBUS_CHECK_SIG (reply, "a{ss}ii", ret)
 
   dbus_message_iter_init (reply, &iter);
-  ret->attributes = _atspi_dbus_hash_from_iter (&iter);
+  ret = _atspi_dbus_hash_from_iter (&iter);
   dbus_message_iter_next (&iter);
 
   dbus_message_iter_get_basic (&iter, &d_start_offset);
-  ret->start_offset = d_start_offset;
+  if (start_offset)
+    *start_offset = d_start_offset;
   dbus_message_iter_next (&iter);
   dbus_message_iter_get_basic (&iter, &d_end_offset);
-  ret->end_offset = d_end_offset;
+  if (end_offset)
+    *end_offset = d_end_offset;
 
   dbus_message_unref (reply);
   return ret;
@@ -303,14 +287,11 @@ GHashTable *
 atspi_text_get_default_attributes (AtspiText *obj, GError **error)
 {
   DBusMessage *reply;
-  GHashTable *ret;
 
     g_return_val_if_fail (obj != NULL, NULL);
 
   reply = _atspi_dbus_call_partial (obj, atspi_interface_text, "GetDefaultAttributes", error, "");
-  ret = _atspi_dbus_hash_from_message (reply);
-  dbus_message_unref (reply);
-  return ret;
+  return _atspi_dbus_return_hash_from_message (reply);
 }
 
 
diff --git a/atspi/atspi-text.h b/atspi/atspi-text.h
index 2c045d9..e4ff6de 100644
--- a/atspi/atspi-text.h
+++ b/atspi/atspi-text.h
@@ -50,23 +50,6 @@ GType atspi_range_get_type ();
 AtspiRange *
 atspi_range_copy (AtspiRange *src);
 
-typedef struct _AtspiRangedAttributeSet AtspiRangedAttributeSet;
-struct _AtspiRangedAttributeSet
-{
-  GHashTable *attributes;
-  gint start_offset;
-  gint end_offset;
-};
-
-/**
- * ATSPI_TYPE_RANGED_ATTRIBUTE_SET:
- * 
- * The #GType for a boxed type holding an attribute set within a text block.
- */
-#define	ATSPI_TYPE_RANGED_ATTRIBUTE_SET atspi_ranged_attribute_set_get_type ()
-
-GType atspi_ranged_attribute_set_get_type ();
-
 typedef struct _AtspiTextRange AtspiTextRange;
 struct _AtspiTextRange
 {
@@ -103,9 +86,9 @@ gchar * atspi_text_get_text (AtspiText *obj, gint start_offset, gint end_offset,
 
 gint atspi_text_get_caret_offset (AtspiText *obj, GError **error);
 
-AtspiRangedAttributeSet * atspi_text_get_attributes (AtspiText *obj, gint offset, GError **error);
+GHashTable *atspi_text_get_attributes (AtspiText *obj, gint offset, gint *start_offset, gint *end_offset, GError **error);
 
-AtspiRangedAttributeSet * atspi_text_get_attribute_run (AtspiText *obj, gint offset, gboolean include_defaults, GError **error);
+GHashTable *atspi_text_get_attribute_run (AtspiText *obj, gint offset, gboolean include_defaults, gint *start_offset, gint *end_offset, GError **error);
 
 gchar * atspi_text_get_attribute_value (AtspiText *obj, gint offset, gchar *attribute_name, GError **error);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]