<commit_before>/*
 * AT-SPI - Assistive Technology Service Provider Interface
 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
 *
 * Copyright 2001, 2002 Sun Microsystems Inc.,
 * Copyright 2001, 2002 Ximian, Inc.
 * Copyright 2013 SUSE LLC.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include <stdlib.h> /* for malloc */
#include "atspi-private.h"

static GPtrArray *
get_object_array_and_unref (DBusMessage *reply)
{
  DBusMessageIter iter, iter_array;
  GPtrArray *array;

  if (!reply)
    return NULL;

  if (strcmp (dbus_message_get_signature (reply), "(so)") != 0)
  {
    dbus_message_unref (reply);
    return NULL;
  }

  array = g_ptr_array_new ();

  dbus_message_iter_init (reply, &iter);
  dbus_message_iter_recurse (&iter, &iter_array);
  while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
  {
    AtspiAccessible *accessible = _atspi_dbus_return_accessible_from_iter (&iter_array);
    g_ptr_array_add (array, accessible);
  }
  dbus_message_unref (reply);
  return array;
}

/**
 * atspi_table_cell_get_column_span:
 * @obj: a GObject instance that implements AtspiTableCellIface
 *
 * Returns the number of columns occupied by this cell accessible.
 *
 * Returns: a gint representing the number of columns occupied by this cell,
 * or 0 if the cell does not implement this method.
 */
gint
atspi_table_cell_get_column_span (AtspiTableCell *obj, GError **error)
{
  dbus_int32_t retval = -1;

  g_return_val_if_fail (obj != NULL, -1);

  _atspi_dbus_get_property (obj, atspi_interface_table_cell, "ColumnSpan",
                            error, "i", &retval);
	  
  return retval;
}

/**
 * atspi_table_cell_get_column_header_cells:
 * @obj: a GObject instance that implements AtspiTableCellIface
 *
 * Returns the column headers as an array of cell accessibles.
 *
 * Returns: (element-type AtspiAccessible) (transfer full): a GPtrArray of
 * AtspiAccessibles representing the column header cells.
  */
GPtrArray *
atspi_table_cell_get_column_header_cells (AtspiTableCell *obj, GError **error)
{
  DBusMessage *reply;

  g_return_val_if_fail (obj != NULL, NULL);

  reply = _atspi_dbus_call_partial (obj, atspi_interface_table_cell, "GetColumnHeaderCells", error, "");
	  
  return get_object_array_and_unref (reply);
}

/**
 * atspi_table_cell_get_column_index:
 * @obj: a GObject instance that implements AtspiTableCellIface
 *
 * Translates this cell accessible into the corresponding column index.
 *
 * Returns: the column index for this cell, or -1 if unimplemented.
 */
gint
atspi_table_cell_get_column_index (AtspiTableCell *obj, GError **error)
{
  dbus_int32_t retval = -1;

  g_return_val_if_fail (obj != NULL, -1);

  _atspi_dbus_get_property (obj, atspi_interface_table_cell, "ColumnIndex",
                            error, "i", &retval);
	  
  return retval;
}

/**
 * atspi_table_cell_get_row_span:
 * @obj: a GObject instance that implements AtspiTableCellIface
 *
 * Returns the number of rows occupied by this cell accessible.
 *
 * Returns: a gint representing the number of rows occupied by this cell,
 * or 0 if the cell does not implement this method.
 */
gint
atspi_table_cell_get_row_span (AtspiTableCell *obj, GError **error)
{
  dbus_int32_t retval = -1;

  g_return_val_if_fail (obj != NULL, -1);

  _atspi_dbus_get_property (obj, atspi_interface_table_cell, "RowSpan",
                            error, "i", &retval);
	  
  return retval;
}

/**
 * atspi_table_cell_get_row_header_cells:
 * @obj: a GObject instance that implements AtspiTableCellIface
 *
 * Returns the row headers as an array of cell accessibles.
 *
 * Returns: (element-type AtspiAccessible) (transfer full): a GPtrArray of
 * AtspiAccessibles representing the row header cells.
 */
GPtrArray *
atspi_table_cell_get_row_header_cells (AtspiTableCell *obj, GError **error)
{
  DBusMessage *reply;

  g_return_val_if_fail (obj != NULL, NULL);

  reply = _atspi_dbus_call_partial (obj, atspi_interface_table_cell, "GetRowHeaderCells", error, "");
	  
  return get_object_array_and_unref (reply);
}

/**
 * atspi_table_cell_get_position:
 * @obj: a GObject instance that implements AtspiTableCellIface
 * @row: (out): the row of the given cell.
 * @column: (out): the column of the given cell.
 *
 * Retrieves the tabular position of this cell.
 *
 * Returns: TRUE if successful, FALSE otherwise.
 */
gint
atspi_table_cell_get_position (AtspiTableCell *obj,
                               gint *row,
                               gint *column,
                               GError *error)
{
  DBusMessage *reply;
  DBusMessageIter iter, iter_struct, iter_variant;
  dbus_int32_t d_row = -1, d_column = -1;
  char *iter_sig;

  g_return_val_if_fail (obj != NULL, -1);

  reply = _atspi_dbus_call_partial (obj, "org.freedesktop.DBuss.Properties",
                                    "Get", atspi_interface_table_cell,
                                    "Position");
	  
  dbus_message_iter_init (reply, &iter);

  /* TODO: Return error here */
  if (dbus_message_iter_get_arg_type (&iter) != 'v')
    return FALSE;

  dbus_message_iter_recurse (&iter, &iter_variant);
  iter_sig = dbus_message_iter_get_signature (&iter_variant);
  /* TODO: Also report error here */
  if (strcmp (iter_sig, "(ii)") != 0)
  {
    dbus_free (iter_sig);
    return FALSE;
  }
  dbus_free (iter_sig);

  dbus_message_iter_recurse (&iter_variant, &iter_struct);
  dbus_message_iter_get_basic (&iter_struct, &d_row);
  if (row)
    *row = d_row;
  dbus_message_iter_next (&iter_struct);
  dbus_message_iter_get_basic (&iter_struct, &d_column);<commit_msg>Fix atspi_table_cell_get_position<commit_after>/*
 * AT-SPI - Assistive Technology Service Provider Interface
 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
 *
 * Copyright 2001, 2002 Sun Microsystems Inc.,
 * Copyright 2001, 2002 Ximian, Inc.
 * Copyright 2013 SUSE LLC.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include <stdlib.h> /* for malloc */
#include "atspi-private.h"

static GPtrArray *
get_object_array_and_unref (DBusMessage *reply)
{
  DBusMessageIter iter, iter_array;
  GPtrArray *array;

  if (!reply)
    return NULL;

  if (strcmp (dbus_message_get_signature (reply), "(so)") != 0)
  {
    dbus_message_unref (reply);
    return NULL;
  }

  array = g_ptr_array_new ();

  dbus_message_iter_init (reply, &iter);
  dbus_message_iter_recurse (&iter, &iter_array);
  while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
  {
    AtspiAccessible *accessible = _atspi_dbus_return_accessible_from_iter (&iter_array);
    g_ptr_array_add (array, accessible);
  }
  dbus_message_unref (reply);
  return array;
}

/**
 * atspi_table_cell_get_column_span:
 * @obj: a GObject instance that implements AtspiTableCellIface
 *
 * Returns the number of columns occupied by this cell accessible.
 *
 * Returns: a gint representing the number of columns occupied by this cell,
 * or 0 if the cell does not implement this method.
 */
gint
atspi_table_cell_get_column_span (AtspiTableCell *obj, GError **error)
{
  dbus_int32_t retval = -1;

  g_return_val_if_fail (obj != NULL, -1);

  _atspi_dbus_get_property (obj, atspi_interface_table_cell, "ColumnSpan",
                            error, "i", &retval);
	  
  return retval;
}

/**
 * atspi_table_cell_get_column_header_cells:
 * @obj: a GObject instance that implements AtspiTableCellIface
 *
 * Returns the column headers as an array of cell accessibles.
 *
 * Returns: (element-type AtspiAccessible) (transfer full): a GPtrArray of
 * AtspiAccessibles representing the column header cells.
  */
GPtrArray *
atspi_table_cell_get_column_header_cells (AtspiTableCell *obj, GError **error)
{
  DBusMessage *reply;

  g_return_val_if_fail (obj != NULL, NULL);

  reply = _atspi_dbus_call_partial (obj, atspi_interface_table_cell, "GetColumnHeaderCells", error, "");
	  
  return get_object_array_and_unref (reply);
}

/**
 * atspi_table_cell_get_column_index:
 * @obj: a GObject instance that implements AtspiTableCellIface
 *
 * Translates this cell accessible into the corresponding column index.
 *
 * Returns: the column index for this cell, or -1 if unimplemented.
 */
gint
atspi_table_cell_get_column_index (AtspiTableCell *obj, GError **error)
{
  dbus_int32_t retval = -1;

  g_return_val_if_fail (obj != NULL, -1);

  _atspi_dbus_get_property (obj, atspi_interface_table_cell, "ColumnIndex",
                            error, "i", &retval);
	  
  return retval;
}

/**
 * atspi_table_cell_get_row_span:
 * @obj: a GObject instance that implements AtspiTableCellIface
 *
 * Returns the number of rows occupied by this cell accessible.
 *
 * Returns: a gint representing the number of rows occupied by this cell,
 * or 0 if the cell does not implement this method.
 */
gint
atspi_table_cell_get_row_span (AtspiTableCell *obj, GError **error)
{
  dbus_int32_t retval = -1;

  g_return_val_if_fail (obj != NULL, -1);

  _atspi_dbus_get_property (obj, atspi_interface_table_cell, "RowSpan",
                            error, "i", &retval);
	  
  return retval;
}

/**
 * atspi_table_cell_get_row_header_cells:
 * @obj: a GObject instance that implements AtspiTableCellIface
 *
 * Returns the row headers as an array of cell accessibles.
 *
 * Returns: (element-type AtspiAccessible) (transfer full): a GPtrArray of
 * AtspiAccessibles representing the row header cells.
 */
GPtrArray *
atspi_table_cell_get_row_header_cells (AtspiTableCell *obj, GError **error)
{
  DBusMessage *reply;

  g_return_val_if_fail (obj != NULL, NULL);

  reply = _atspi_dbus_call_partial (obj, atspi_interface_table_cell, "GetRowHeaderCells", error, "");
	  
  return get_object_array_and_unref (reply);
}

/**
 * atspi_table_cell_get_position:
 * @obj: a GObject instance that implements AtspiTableCellIface
 * @row: (out): the row of the given cell.
 * @column: (out): the column of the given cell.
 *
 * Retrieves the tabular position of this cell.
 *
 * Returns: TRUE if successful, FALSE otherwise.
 */
gint
atspi_table_cell_get_position (AtspiTableCell *obj,
                               gint *row,
                               gint *column,
                               GError *error)
{
  DBusMessage *reply;
  DBusMessageIter iter, iter_struct, iter_variant;
  dbus_int32_t d_row = -1, d_column = -1;
  char *iter_sig;

  g_return_val_if_fail (obj != NULL, -1);

  reply = _atspi_dbus_call_partial (obj, "org.freedesktop.DBus.Properties",
                                    "Get", NULL, "ss",
                                    atspi_interface_table_cell, "Position");
	  
  dbus_message_iter_init (reply, &iter);

  /* TODO: Return error here */
  if (dbus_message_iter_get_arg_type (&iter) != 'v')
    return FALSE;

  dbus_message_iter_recurse (&iter, &iter_variant);
  iter_sig = dbus_message_iter_get_signature (&iter_variant);
  /* TODO: Also report error here */
  if (strcmp (iter_sig, "(ii)") != 0)
  {
    dbus_free (iter_sig);
    return FALSE;
  }
  dbus_free (iter_sig);

  dbus_message_iter_recurse (&iter_variant, &iter_struct);
  dbus_message_iter_get_basic (&iter_struct, &d_row);
  if (row)
    *row = d_row;
  dbus_message_iter_next (&iter_struct);
  dbus_message_iter_get_basic (&iter_struct, &d_column);
{'fraction_non_alphanumeric': 0.09212504946576969, 'fraction_numerical': 0.009022556390977444, 'mean_word_length': 3.797266514806378, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6309851', 'n_tokens_mistral': 4254, 'n_tokens_neox': 4099, 'n_words': 1194}