[at-spi2-core] Add a Text property to AtspiValue



commit 0944cff6d17e7b3e7b9c687f02c84f0e8c8d63a4
Author: Mike Gorse <mgorse suse com>
Date:   Fri Jun 17 15:51:21 2022 -0500

    Add a Text property to AtspiValue
    
    This allows an application to expose a textual representation of the value.
    A similar API was added to atk a few years ago, but it was never exposed
    via AT-SPI.
    
    See https://bugzilla.gnome.org/show_bug.cgi?id=684576

 atk-adaptor/adaptors/value-adaptor.c | 23 +++++++++++++++++++++++
 atspi/atspi-value.c                  | 23 +++++++++++++++++++++++
 atspi/atspi-value.h                  |  1 +
 doc/libatspi/libatspi-sections.txt   |  1 +
 tests/at-spi2-atk/atk_test_value.c   | 15 +++++++++++++++
 xml/Value.xml                        |  2 ++
 6 files changed, 65 insertions(+)
---
diff --git a/atk-adaptor/adaptors/value-adaptor.c b/atk-adaptor/adaptors/value-adaptor.c
index 7166d3b3..55f6ba49 100644
--- a/atk-adaptor/adaptors/value-adaptor.c
+++ b/atk-adaptor/adaptors/value-adaptor.c
@@ -227,6 +227,28 @@ impl_SetCurrentValue (DBusConnection * bus, DBusMessage * message,
   return reply;
 }
 
+static dbus_bool_t
+impl_get_Text (DBusMessageIter * iter, void *user_data)
+{
+  AtkValue *value = (AtkValue *) user_data;
+  gdouble dub;
+  gchar *text = NULL;
+  dbus_bool_t ret;
+
+  g_return_val_if_fail (ATK_IS_VALUE (user_data), FALSE);
+
+  AtkValueIface *iface = ATK_VALUE_GET_IFACE (value);
+  if (iface->get_value_and_text)
+    {
+      atk_value_get_value_and_text (value, &dub, &text);
+      ret = droute_return_v_string (iter, text);
+      g_free (text);
+      return ret;
+    }
+
+  return droute_return_v_string (iter, "");
+}
+
 static DRouteMethod methods[] = {
   {impl_SetCurrentValue, "SetCurrentValue"},
   {NULL, NULL}
@@ -237,6 +259,7 @@ static DRouteProperty properties[] = {
   {impl_get_MaximumValue, NULL, "MaximumValue"},
   {impl_get_MinimumIncrement, NULL, "MinimumIncrement"},
   {impl_get_CurrentValue, impl_set_CurrentValue, "CurrentValue"},
+  {impl_get_Text, NULL, "Text"},
   {NULL, NULL, NULL}
 };
 
diff --git a/atspi/atspi-value.c b/atspi/atspi-value.c
index 28acade9..6317fc8c 100644
--- a/atspi/atspi-value.c
+++ b/atspi/atspi-value.c
@@ -152,6 +152,28 @@ atspi_value_get_minimum_increment (AtspiValue *obj, GError **error)
   return retval;
 }
 
+/**
+ * atspi_value_get_text:
+ * @obj: a pointer to the #AtspiValue implementor on which to operate. 
+ *
+ * Gets the human readable text alternative associated with the value.
+ * @text is a newly created string, that must be freed by the
+ * caller. Can be NULL if no descriptor is available.
+ *
+ * Since: 2.44
+ **/
+gchar *
+atspi_value_get_text (AtspiValue *obj, GError **error)
+{
+  gchar *retval = NULL;
+
+  g_return_if_fail (obj != NULL);
+
+  _atspi_dbus_get_property (obj, atspi_interface_value, "Text", error, "s", &retval);
+  
+  return retval;
+}
+
 static void
 atspi_value_base_init (AtspiValue *klass)
 {
@@ -175,3 +197,4 @@ atspi_value_get_type (void)
   }
   return type;
 }
+
diff --git a/atspi/atspi-value.h b/atspi/atspi-value.h
index a012793b..478ea951 100644
--- a/atspi/atspi-value.h
+++ b/atspi/atspi-value.h
@@ -56,6 +56,7 @@ gboolean atspi_value_set_current_value (AtspiValue *obj, gdouble new_value, GErr
 
 gdouble atspi_value_get_minimum_increment (AtspiValue *obj, GError **error);
 
+gchar *atspi_value_get_text (AtspiValue *obj, GError **error);
 G_END_DECLS
 
 #endif /* _ATSPI_VALUE_H_ */
diff --git a/doc/libatspi/libatspi-sections.txt b/doc/libatspi/libatspi-sections.txt
index d7bfc103..f8c407fb 100644
--- a/doc/libatspi/libatspi-sections.txt
+++ b/doc/libatspi/libatspi-sections.txt
@@ -349,6 +349,7 @@ atspi_value_get_current_value
 atspi_value_get_maximum_value
 atspi_value_set_current_value
 atspi_value_get_minimum_increment
+atspi_value_get_text
 <SUBSECTION Standard>
 ATSPI_VALUE
 ATSPI_IS_VALUE
diff --git a/tests/at-spi2-atk/atk_test_value.c b/tests/at-spi2-atk/atk_test_value.c
index 08021e24..b6fc4224 100644
--- a/tests/at-spi2-atk/atk_test_value.c
+++ b/tests/at-spi2-atk/atk_test_value.c
@@ -95,6 +95,19 @@ atk_test_value_get_minimum_increment (gpointer fixture, gconstpointer user_data)
   g_assert_cmpfloat (val, ==, 0.25);
 }
 
+static void
+atk_test_value_get_text (gpointer fixture, gconstpointer user_data)
+{
+  AtspiAccessible *_obj = get_root_obj (DATA_FILE);
+  g_assert (_obj);
+  AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
+  g_assert (child);
+  AtspiValue *obj = atspi_accessible_get_value_iface (child);
+  gchar *text = atspi_value_get_text (obj, NULL);
+  g_assert_cmpstr (text, ==, "2.250000");
+  g_free (text);
+}
+
 static void
 teardown_value_test (gpointer fixture, gconstpointer user_data)
 {
@@ -116,4 +129,6 @@ atk_test_value (void)
                      0, NULL, NULL, atk_test_value_set_current_value, teardown_value_test );
   g_test_add_vtable (ATK_TEST_PATH_VALUE "/atk_test_value_get_minimum_increment",
                      0, NULL, NULL, atk_test_value_get_minimum_increment, teardown_value_test );
+  g_test_add_vtable (ATK_TEST_PATH_VALUE "/atk_test_value_get_text",
+                     0, NULL, NULL, atk_test_value_get_text, teardown_value_test );
 }
diff --git a/xml/Value.xml b/xml/Value.xml
index ccd6c7aa..4995124e 100644
--- a/xml/Value.xml
+++ b/xml/Value.xml
@@ -10,5 +10,7 @@
 
         <property name="CurrentValue" type="d" access="readwrite"/>
 
+        <property name="Text" type="s" access="read"/>
+
 </interface>
 </node>


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