Merge upstream branch 2.31.1 into branch origin/tizen
[platform/upstream/at-spi2-core.git] / atspi / atspi-component.c
index 574bb4a..f6f72f8 100644 (file)
  */
 
 #include "atspi-private.h"
+#include "atspi-accessible-private.h"
+
+void
+atspi_rect_free (AtspiRect *rect)
+{
+  g_free (rect);
+}
+
+AtspiRect *
+atspi_rect_copy (AtspiRect *src)
+{
+  AtspiRect *dst = g_new (AtspiRect, 1);
+  dst->x = src->x;
+  dst->y = src->y;
+  dst->height = src->height;
+  dst->width = src->width;
+  return dst;
+}
+
+G_DEFINE_BOXED_TYPE (AtspiRect, atspi_rect, atspi_rect_copy, atspi_rect_free)
+
+AtspiPoint *
+atspi_point_copy (AtspiPoint *src)
+{
+  AtspiPoint *dst = g_new (AtspiPoint, 1);
+  dst->x = src->x;
+  dst->y = src->y;
+  return dst;
+}
+
+G_DEFINE_BOXED_TYPE (AtspiPoint, atspi_point, atspi_point_copy, g_free)
 
 /**
  * atspi_component_contains:
  * @obj: a pointer to the #AtspiComponent to query.
- * @x: a #long specifying the x coordinate in question.
- * @y: a #long specifying the y coordinate in question.
+ * @x: a #gint specifying the x coordinate in question.
+ * @y: a #gint specifying the y coordinate in question.
  * @ctype: the desired coordinate system of the point (@x, @y)
  *         (e.g. CSPI_COORD_TYPE_WINDOW, CSPI_COORD_TYPE_SCREEN).
  *
- * Query whether a given #AtspiComponent contains a particular point.
+ * Queries whether a given #AtspiComponent contains a particular point.
  *
- * Returns: #TRUE if the specified component contains the point (@x, @y),
- *          otherwise #FALSE.
+ * Returns: #TRUE if the specified component contains the point (@x, @y),
+ *          #FALSE otherwise.
  **/
 gboolean
 atspi_component_contains (AtspiComponent *obj,
@@ -50,76 +81,81 @@ atspi_component_contains (AtspiComponent *obj,
 {
   dbus_bool_t retval = FALSE;
   dbus_int32_t d_x = x, d_y = y;
-  dbus_uint16_t d_ctype = ctype;
+  dbus_uint32_t d_ctype = ctype;
 
   g_return_val_if_fail (obj != NULL, FALSE);
 
-  _atspi_dbus_call (obj, atspi_interface_component, "Contains", error, "iin=>b", d_x, d_y, d_ctype, &retval);
+  _atspi_dbus_call (obj, atspi_interface_component, "Contains", error, "iiu=>b", d_x, d_y, d_ctype, &retval);
 
   return retval;
 }
 
 /**
- * atspi_component_ref_accessible_at_point:
+ * atspi_component_get_accessible_at_point:
  * @obj: a pointer to the #AtspiComponent to query.
  * @x: a #gint specifying the x coordinate of the point in question.
  * @y: a #gint specifying the y coordinate of the point in question.
  * @ctype: the coordinate system of the point (@x, @y)
  *         (e.g. ATSPI_COORD_TYPE_WINDOW, ATSPI_COORD_TYPE_SCREEN).
  *
- * Get the accessible child at a given coordinate within an #AtspiComponent.
+ * Gets the accessible child at a given coordinate within an #AtspiComponent.
  *
- * Returns: a pointer to an #AtspiAccessible child of the specified component
- *          which contains the point (@x, @y), or NULL of no child contains
- *         the point.
+ * Returns: (nullable) (transfer full): a pointer to an
+ *          #AtspiAccessible child of the specified component which
+ *          contains the point (@x, @y), or NULL if no child contains
+ *          the point.
  **/
 AtspiAccessible *
-atspi_component_ref_accessible_at_point (AtspiComponent *obj,
+atspi_component_get_accessible_at_point (AtspiComponent *obj,
                                           gint x,
                                           gint y,
                                           AtspiCoordType ctype, GError **error)
 {
   dbus_int32_t d_x = x, d_y = y;
-  dbus_uint16_t d_ctype = ctype;
+  dbus_uint32_t d_ctype = ctype;
   DBusMessage *reply;
-  char *path = NULL;
-  AtspiAccessible *retval = NULL;
 
   g_return_val_if_fail (obj != NULL, FALSE);
 
-  reply = _atspi_dbus_call_partial (obj, atspi_interface_component, "GetAccessibleAtPoint", error, "iin", d_x, d_y, d_ctype);
+  reply = _atspi_dbus_call_partial (obj, atspi_interface_component, "GetAccessibleAtPoint", error, "iiu", d_x, d_y, d_ctype);
 
   return _atspi_dbus_return_accessible_from_message (reply);
 }
 
+
 /**
  * atspi_component_get_extents:
  * @obj: a pointer to the #AtspiComponent to query.
- * @x: a pointer to a #int into which the minimum x coordinate will be returned.
- * @y: a pointer to a #int into which the minimum y coordinate will be returned.
- * @width: a pointer to a #int into which the x extents (width) will be returned.
- * @height: a pointer to a #int into which the y extents (height) will be returned.
  * @ctype: the desired coordinate system into which to return the results,
  *         (e.g. ATSPI_COORD_TYPE_WINDOW, ATSPI_COORD_TYPE_SCREEN).
  *
- * Get the bounding box of the specified #AtspiComponent.
+ * Gets the bounding box of the specified #AtspiComponent.
  *
+ * Returns: An #AtspiRect giving the accessible's extents.
  **/
-AtspiRect
+AtspiRect *
 atspi_component_get_extents (AtspiComponent *obj,
-                                gint *x,
-                                gint *y,
-                                gint *width,
-                                gint *height,
                                 AtspiCoordType ctype, GError **error)
 {
-  dbus_int16_t d_ctype = ctype;
+  dbus_uint32_t d_ctype = ctype;
   AtspiRect bbox;
+  AtspiAccessible *accessible;
 
-  g_return_if_fail (obj != NULL);
+  bbox.x = bbox.y = bbox.width = bbox.height = -1;
+  g_return_val_if_fail (obj != NULL, atspi_rect_copy (&bbox));
 
-  _atspi_dbus_call (obj, atspi_interface_component, "GetExtents", error, "n=>(iiii)", d_ctype, &bbox);
-  return bbox;
+  accessible = ATSPI_ACCESSIBLE (obj);
+  if (accessible->priv->cache && ctype == ATSPI_COORD_TYPE_SCREEN)
+  {
+    GValue *val = g_hash_table_lookup (accessible->priv->cache, "Component.ScreenExtents");
+    if (val)
+    {
+      return g_value_dup_boxed (val);
+    }
+  }
+
+  _atspi_dbus_call (obj, atspi_interface_component, "GetExtents", error, "u=>(iiii)", d_ctype, &bbox);
+  return atspi_rect_copy (&bbox);
 }
 
 /**
@@ -128,59 +164,59 @@ atspi_component_get_extents (AtspiComponent *obj,
  * @ctype: the desired coordinate system into which to return the results,
  *         (e.g. ATSPI_COORD_TYPE_WINDOW, ATSPI_COORD_TYPE_SCREEN).
  *
- * returns: A #AtspiPoint giving the position.
- * Get the minimum x and y coordinates of the specified #AtspiComponent.
+ * Gets the minimum x and y coordinates of the specified #AtspiComponent.
  *
+ * returns: An #AtspiPoint giving the @obj's position.
  **/
-AtspiPoint
+AtspiPoint *
 atspi_component_get_position (AtspiComponent *obj,
                                  AtspiCoordType ctype, GError **error)
 {
   dbus_int32_t d_x, d_y;
-  dbus_uint16_t d_ctype = ctype;
+  dbus_uint32_t d_ctype = ctype;
   AtspiPoint ret;
 
-  ret.x = ret.y = 0;
+  ret.x = ret.y = -1;
 
   if (!obj)
-    return ret;
+    return atspi_point_copy (&ret);
 
-  _atspi_dbus_call (obj, atspi_interface_component, "GetPosition", error, "n=>ii", d_ctype, &d_x, &d_y);
+  _atspi_dbus_call (obj, atspi_interface_component, "GetPosition", error, "u=>ii", d_ctype, &d_x, &d_y);
 
   ret.x = d_x;
   ret.y = d_y;
-  return ret;
+  return atspi_point_copy (&ret);
 }
 
 /**
  * atspi_component_get_size:
  * @obj: a pointer to the #AtspiComponent to query.
- * returns: A #AtspiPoint giving the siize.
  *
- * Get the size of the specified #AtspiComponent.
+ * Gets the size of the specified #AtspiComponent.
  *
+ * returns: An #AtspiPoint giving the @obj's size.
  **/
-AtspiPoint
+AtspiPoint *
 atspi_component_get_size (AtspiComponent *obj, GError **error)
 {
   dbus_int32_t d_w, d_h;
   AtspiPoint ret;
 
-  ret.x = ret.y = 0;
+  ret.x = ret.y = -1;
   if (!obj)
-    return ret;
+    return atspi_point_copy (&ret);
 
   _atspi_dbus_call (obj, atspi_interface_component, "GetSize", error, "=>ii", &d_w, &d_h);
   ret.x = d_w;
   ret.y = d_h;
-  return ret;
+  return atspi_point_copy (&ret);
 }
 
 /**
  * atspi_component_get_layer:
  * @obj: a pointer to the #AtspiComponent to query.
  *
- * Query which layer the component is painted into, to help determine its 
+ * Queries which layer the component is painted into, to help determine its
  *      visibility in terms of stacking order.
  *
  * Returns: the #AtspiComponentLayer into which this component is painted.
@@ -188,7 +224,7 @@ atspi_component_get_size (AtspiComponent *obj, GError **error)
 AtspiComponentLayer
 atspi_component_get_layer (AtspiComponent *obj, GError **error)
 {
-  dbus_uint32_t zlayer = 0;
+  dbus_uint32_t zlayer = -1;
 
   _atspi_dbus_call (obj, atspi_interface_component, "GetLayer", error, "=>u", &zlayer);
 
@@ -199,10 +235,10 @@ atspi_component_get_layer (AtspiComponent *obj, GError **error)
  * atspi_component_get_mdi_z_order:
  * @obj: a pointer to the #AtspiComponent to query.
  *
- * Query the z stacking order of a component which is in the MDI or window
+ * Queries the z stacking order of a component which is in the MDI or window
  *       layer. (Bigger z-order numbers mean nearer the top)
  *
- * Returns: a short integer indicating the stacking order of the component 
+ * Returns: a #gshort indicating the stacking order of the component
  *       in the MDI layer, or -1 if the component is not in the MDI layer.
  **/
 gshort
@@ -219,7 +255,7 @@ atspi_component_get_mdi_z_order (AtspiComponent *obj, GError **error)
  * atspi_component_grab_focus:
  * @obj: a pointer to the #AtspiComponent on which to operate.
  *
- * Attempt to set the keyboard input focus to the specified
+ * Attempts to set the keyboard input focus to the specified
  *         #AtspiComponent.
  *
  * Returns: #TRUE if successful, #FALSE otherwise.
@@ -236,14 +272,54 @@ atspi_component_grab_focus (AtspiComponent *obj, GError **error)
 }
 
 /**
+ * atspi_component_grab_highlight:
+ * @obj: a pointer to the #AtspiComponent on which to operate.
+ *
+ * Attempts to set highlight to the specified
+ *         #AtspiComponent.
+ *
+ * Returns: #TRUE if successful, #FALSE otherwise.
+ *
+ **/
+gboolean
+atspi_component_grab_highlight (AtspiComponent *obj, GError **error)
+{
+  dbus_bool_t retval = FALSE;
+
+  _atspi_dbus_call (obj, atspi_interface_component, "GrabHighlight", error, "=>b", &retval);
+
+  return retval;
+}
+
+/**
+ * atspi_component_clear_highlight:
+ * @obj: a pointer to the #AtspiComponent on which to operate.
+ *
+ * Attempts to clear highlight on the specified
+ *         #AtspiComponent.
+ *
+ * Returns: #TRUE if successful, #FALSE otherwise.
+ *
+ **/
+gboolean
+atspi_component_clear_highlight (AtspiComponent *obj, GError **error)
+{
+  dbus_bool_t retval = FALSE;
+
+  _atspi_dbus_call (obj, atspi_interface_component, "ClearHighlight", error, "=>b", &retval);
+
+  return retval;
+}
+
+/**
  * atspi_component_get_alpha:
  * @obj: The #AtspiComponent to be queried.
  *
- * Get the opacity/alpha value of a component, if alpha blending is in use.
+ * Gets the opacity/alpha value of a component, if alpha blending is in use.
  *
- * Returns: the opacity value of a component, as a double between 0.0 and 1.0. 
+ * Returns: the opacity value of a component, as a #gdouble between 0.0 and 1.0.
  **/
-gdouble      
+gdouble
 atspi_component_get_alpha    (AtspiComponent *obj, GError **error)
 {
   double retval = 1;
@@ -253,25 +329,208 @@ atspi_component_get_alpha    (AtspiComponent *obj, GError **error)
   return retval;
 }
 
-static void
-atspi_component_base_init (AtspiComponentIface *klass)
+/**
+ * atspi_component_set_extents:
+ * @obj: a pointer to the #AtspiComponent to move.
+ * @x: the new vertical position to which the component should be moved.
+ * @y: the new horizontal position to which the component should be moved.
+ * @width: the width to which the component should be resized.
+ * @height: the height to which the component should be resized.
+ * @ctype: the coordinate system in which the position is specified.
+ *         (e.g. ATSPI_COORD_TYPE_WINDOW, ATSPI_COORD_TYPE_SCREEN).
+ *
+ * Moves and resizes the specified component.
+ *
+ * Returns: #TRUE if successful; #FALSE otherwise.
+ **/
+gboolean
+atspi_component_set_extents (AtspiComponent *obj,
+                             gint x,
+                             gint y,
+                             gint width,
+                             gint height,
+                             AtspiCoordType ctype,
+                             GError **error)
 {
-  static gboolean initialized = FALSE;
+  dbus_int32_t d_x = x, d_y = y, d_width = width, d_height = height;
+  dbus_uint32_t d_ctype = ctype;
+  DBusMessageIter iter, iter_struct;
+  DBusMessage *message, *reply;
+  dbus_bool_t retval = FALSE;
+  AtspiAccessible *aobj = ATSPI_ACCESSIBLE (obj);
 
-  if (! initialized)
-    {
-      klass->contains = atspi_component_contains;
-      klass->ref_accessible_at_point = atspi_component_ref_accessible_at_point;
-  klass->get_extents = atspi_component_get_extents;
-      klass->get_position = atspi_component_get_position;
-      klass->get_size = atspi_component_get_size;
-      klass->get_layer = atspi_component_get_layer;
-      klass->get_mdi_z_order = atspi_component_get_mdi_z_order;
-      klass->grab_focus = atspi_component_grab_focus;
-      klass->get_alpha = atspi_component_get_alpha;
-
-      initialized = TRUE;
-    }
+  g_return_val_if_fail (obj != NULL, FALSE);
+
+  if (!aobj->parent.app || !aobj->parent.app->bus_name)
+  {
+    g_set_error_literal (error, ATSPI_ERROR, ATSPI_ERROR_APPLICATION_GONE,
+                          _("The application no longer exists"));
+    return FALSE;
+  }
+
+  message = dbus_message_new_method_call (aobj->parent.app->bus_name,
+                                          aobj->parent.path,
+                                          atspi_interface_component,
+                                          "SetExtents");
+  if (!message)
+    return FALSE;
+
+  dbus_message_iter_init_append (message, &iter);
+  if (!dbus_message_iter_open_container (&iter, DBUS_TYPE_STRUCT, NULL, &iter_struct))
+  {
+    dbus_message_unref (message);
+    return FALSE;
+  }
+  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_INT32, &d_x);
+  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_INT32, &d_y);
+  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_INT32, &d_width);
+  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_INT32, &d_height);
+  dbus_message_iter_close_container (&iter, &iter_struct);
+  dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &d_ctype);
+
+  reply = _atspi_dbus_send_with_reply_and_block (message, error);
+  dbus_message_get_args (reply, NULL, DBUS_TYPE_BOOLEAN, &retval,
+                              DBUS_TYPE_INVALID);
+  dbus_message_unref (reply);
+  return retval;
+}
+
+/**
+ * atspi_component_set_position:
+ * @obj: a pointer to the #AtspiComponent to move.
+ * @x: the new vertical position to which the component should be moved.
+ * @y: the new horizontal position to which the component should be moved.
+ * @ctype: the coordinate system in which the position is specified.
+ *         (e.g. ATSPI_COORD_TYPE_WINDOW, ATSPI_COORD_TYPE_SCREEN).
+ *
+ * Moves the component to the specified position.
+ *
+ * Returns: #TRUE if successful; #FALSE otherwise.
+ **/
+gboolean
+atspi_component_set_position (AtspiComponent *obj,
+                              gint x,
+                              gint y,
+                              AtspiCoordType ctype,
+                              GError **error)
+{
+  dbus_int32_t d_x = x, d_y = y;
+  dbus_uint32_t d_ctype = ctype;
+  dbus_bool_t ret = FALSE;
+
+  g_return_val_if_fail (obj != NULL, FALSE);
+
+  _atspi_dbus_call (obj, atspi_interface_component, "SetPosition", error,
+                    "iiu=>b", d_x, d_y, d_ctype, &ret);
+
+  return ret;
+}
+
+/**
+ * atspi_component_set_size:
+ * @obj: a pointer to the #AtspiComponent to query.
+ * @width: the width to which the component should be resized.
+ * @height: the height to which the component should be resized.
+ *
+ * Resizes the specified component to the given coordinates.
+ *
+ * Returns: #TRUE if successful; #FALSE otherwise.
+ **/
+gboolean
+atspi_component_set_size (AtspiComponent *obj,
+                          gint width,
+                          gint height,
+                          GError **error)
+{
+  dbus_int32_t d_width = width, d_height = height;
+  dbus_bool_t ret = FALSE;
+
+  g_return_val_if_fail (obj != NULL, FALSE);
+
+  _atspi_dbus_call (obj, atspi_interface_component, "SetSize", error, "ii=>b",
+                    d_width, d_height, &ret);
+
+  return ret;
+}
+
+/**
+<<<<<<< HEAD
+ * atspi_component_scroll_to:
+ * @obj: a pointer to the #AtspiComponent object on which to operate.
+ * @type: a #AtspiScrollType indicating where the object should be placed on the
+ *        screen.
+ *
+ * Scrolls whatever container of the #AtspiComponent object so it becomes
+ * visible on the screen.
+ *
+ * Returns: #TRUE if successful, #FALSE otherwise.
+ **/
+gboolean
+atspi_component_scroll_to (AtspiComponent *obj,
+                           AtspiScrollType type,
+                           GError **error)
+{
+  dbus_bool_t retval = FALSE;
+
+  g_return_val_if_fail (obj != NULL, FALSE);
+
+  _atspi_dbus_call (obj, atspi_interface_component,
+                    "ScrollTo", error, "u=>b", type, &retval);
+
+  return retval;
+}
+
+/**
+ * atspi_component_scroll_to_point:
+ * @obj: a pointer to the #AtspiComponent object on which to operate.
+ * @coords: a #AtspiCoordType indicating whether the coordinates are relative to
+ *          the screen, to the window, or to the parent object.
+ * @x: the x coordinate of the point to reach
+ * @y: the y coordinate of the point to reach
+ * @error: return location for a #GError
+ *
+ * Scrolls whatever container of the #AtspiComponent object so it becomes
+ * visible on the screen at a given position.
+ *
+ * Returns: #TRUE if successful, #FALSE otherwise.
+ **/
+gboolean
+atspi_component_scroll_to_point (AtspiComponent *obj,
+                                 AtspiCoordType coords,
+                                 gint x,
+                                 gint y,
+                                 GError **error)
+{
+  dbus_bool_t retval = FALSE;
+
+  g_return_val_if_fail (obj != NULL, FALSE);
+
+  _atspi_dbus_call (obj, atspi_interface_component,
+                    "ScrollToPoint", error, "uii=>b", coords, x, y, &retval);
+
+  return retval;
+}
+
+/**
+ * atspi_component_get_highlight_index
+ * @obj: a pointer to the #AtspiComponent to query.
+ *
+ * Returns: highlight index of object if (>0), 0 if highlight index is not set
+ *          or -1 if an error occured.
+ **/
+int
+atspi_component_get_highlight_index (AtspiComponent *obj, GError **error)
+{
+   gint ret = -1;
+   g_return_val_if_fail (obj != NULL, -1);
+   _atspi_dbus_get_property (obj, atspi_interface_component,
+                             "HighlightIndex", error, "i", &ret);
+   return ret;
+}
+
+static void
+atspi_component_base_init (AtspiComponent *klass)
+{
 }
 
 GType
@@ -282,10 +541,9 @@ atspi_component_get_type (void)
   if (!type) {
     static const GTypeInfo tinfo =
     {
-      sizeof (AtspiComponentIface),
+      sizeof (AtspiComponent),
       (GBaseInitFunc) atspi_component_base_init,
       (GBaseFinalizeFunc) NULL,
-
     };
 
     type = g_type_register_static (G_TYPE_INTERFACE, "AtspiComponent", &tinfo, 0);