Blame atk/atkselection.c

Packit d0bcc1
/* ATK -  Accessibility Toolkit
Packit d0bcc1
 * Copyright 2001 Sun Microsystems Inc.
Packit d0bcc1
 *
Packit d0bcc1
 * This library is free software; you can redistribute it and/or
Packit d0bcc1
 * modify it under the terms of the GNU Lesser General Public
Packit d0bcc1
 * License as published by the Free Software Foundation; either
Packit d0bcc1
 * version 2 of the License, or (at your option) any later version.
Packit d0bcc1
 *
Packit d0bcc1
 * This library is distributed in the hope that it will be useful,
Packit d0bcc1
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit d0bcc1
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit d0bcc1
 * Lesser General Public License for more details.
Packit d0bcc1
 *
Packit d0bcc1
 * You should have received a copy of the GNU Lesser General Public
Packit d0bcc1
 * License along with this library; if not, write to the
Packit d0bcc1
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Packit d0bcc1
 * Boston, MA 02111-1307, USA.
Packit d0bcc1
 */
Packit d0bcc1
Packit d0bcc1
#include "config.h"
Packit d0bcc1
Packit d0bcc1
#include "atkselection.h"
Packit d0bcc1
Packit d0bcc1
/**
Packit d0bcc1
 * SECTION:atkselection
Packit d0bcc1
 * @Short_description: The ATK interface implemented by container
Packit d0bcc1
 *  objects whose #AtkObject children can be selected.
Packit d0bcc1
 * @Title:AtkSelection
Packit d0bcc1
 *
Packit d0bcc1
 * #AtkSelection should be implemented by UI components with children
Packit d0bcc1
 * which are exposed by #atk_object_ref_child and
Packit d0bcc1
 * #atk_object_get_n_children, if the use of the parent UI component
Packit d0bcc1
 * ordinarily involves selection of one or more of the objects
Packit d0bcc1
 * corresponding to those #AtkObject children - for example,
Packit d0bcc1
 * selectable lists.
Packit d0bcc1
 *
Packit d0bcc1
 * Note that other types of "selection" (for instance text selection)
Packit d0bcc1
 * are accomplished a other ATK interfaces - #AtkSelection is limited
Packit d0bcc1
 * to the selection/deselection of children.
Packit d0bcc1
 */
Packit d0bcc1
Packit d0bcc1
Packit d0bcc1
enum {
Packit d0bcc1
  SELECTION_CHANGED,
Packit d0bcc1
  LAST_SIGNAL
Packit d0bcc1
};
Packit d0bcc1
Packit d0bcc1
static void atk_selection_base_init (gpointer *g_class);
Packit d0bcc1
Packit d0bcc1
static guint atk_selection_signals[LAST_SIGNAL] = { 0 };
Packit d0bcc1
Packit d0bcc1
GType
Packit d0bcc1
atk_selection_get_type (void)
Packit d0bcc1
{
Packit d0bcc1
  static GType type = 0;
Packit d0bcc1
Packit d0bcc1
  if (!type) {
Packit d0bcc1
    GTypeInfo tinfo =
Packit d0bcc1
    {
Packit d0bcc1
      sizeof (AtkSelectionIface),
Packit d0bcc1
      (GBaseInitFunc)atk_selection_base_init,
Packit d0bcc1
      (GBaseFinalizeFunc) NULL,
Packit d0bcc1
Packit d0bcc1
    };
Packit d0bcc1
Packit d0bcc1
    type = g_type_register_static (G_TYPE_INTERFACE, "AtkSelection", &tinfo, 0);
Packit d0bcc1
  }
Packit d0bcc1
Packit d0bcc1
  return type;
Packit d0bcc1
}
Packit d0bcc1
Packit d0bcc1
static void
Packit d0bcc1
atk_selection_base_init (gpointer *g_class)
Packit d0bcc1
{
Packit d0bcc1
  static gboolean initialized = FALSE;
Packit d0bcc1
Packit d0bcc1
  if (! initialized)
Packit d0bcc1
    {
Packit d0bcc1
      /**
Packit d0bcc1
       * AtkSelection::selection-changed:
Packit d0bcc1
       * @atkselection: the object which received the signal.
Packit d0bcc1
       *
Packit d0bcc1
       * The "selection-changed" signal is emitted by an object which
Packit d0bcc1
       * implements AtkSelection interface when the selection changes.
Packit d0bcc1
       */
Packit d0bcc1
      atk_selection_signals[SELECTION_CHANGED] =
Packit d0bcc1
        g_signal_new ("selection_changed",
Packit d0bcc1
                      ATK_TYPE_SELECTION,
Packit d0bcc1
                      G_SIGNAL_RUN_LAST,
Packit d0bcc1
                      G_STRUCT_OFFSET (AtkSelectionIface, selection_changed),
Packit d0bcc1
                      (GSignalAccumulator) NULL, NULL,
Packit d0bcc1
                      g_cclosure_marshal_VOID__VOID,
Packit d0bcc1
                      G_TYPE_NONE, 0);
Packit d0bcc1
Packit d0bcc1
Packit d0bcc1
      initialized = TRUE;
Packit d0bcc1
    }
Packit d0bcc1
}
Packit d0bcc1
Packit d0bcc1
/**
Packit d0bcc1
 * atk_selection_add_selection:
Packit d0bcc1
 * @selection: a #GObject instance that implements AtkSelectionIface
Packit d0bcc1
 * @i: a #gint specifying the child index.
Packit d0bcc1
 *
Packit d0bcc1
 * Adds the specified accessible child of the object to the
Packit d0bcc1
 * object's selection.
Packit d0bcc1
 *
Packit d0bcc1
 * Returns: TRUE if success, FALSE otherwise.
Packit d0bcc1
 **/
Packit d0bcc1
gboolean
Packit d0bcc1
atk_selection_add_selection (AtkSelection *obj,
Packit d0bcc1
                             gint         i)
Packit d0bcc1
{
Packit d0bcc1
  AtkSelectionIface *iface;
Packit d0bcc1
Packit d0bcc1
  g_return_val_if_fail (ATK_IS_SELECTION (obj), FALSE);
Packit d0bcc1
Packit d0bcc1
  iface = ATK_SELECTION_GET_IFACE (obj);
Packit d0bcc1
Packit d0bcc1
  if (iface->add_selection)
Packit d0bcc1
    return (iface->add_selection) (obj, i);
Packit d0bcc1
  else
Packit d0bcc1
    return FALSE;
Packit d0bcc1
}
Packit d0bcc1
Packit d0bcc1
/**
Packit d0bcc1
 * atk_selection_clear_selection:
Packit d0bcc1
 * @selection: a #GObject instance that implements AtkSelectionIface
Packit d0bcc1
 *
Packit d0bcc1
 * Clears the selection in the object so that no children in the object
Packit d0bcc1
 * are selected.
Packit d0bcc1
 *
Packit d0bcc1
 * Returns: TRUE if success, FALSE otherwise.
Packit d0bcc1
 **/
Packit d0bcc1
gboolean
Packit d0bcc1
atk_selection_clear_selection (AtkSelection *obj)
Packit d0bcc1
{
Packit d0bcc1
  AtkSelectionIface *iface;
Packit d0bcc1
Packit d0bcc1
  g_return_val_if_fail (ATK_IS_SELECTION (obj), FALSE);
Packit d0bcc1
Packit d0bcc1
  iface = ATK_SELECTION_GET_IFACE (obj);
Packit d0bcc1
Packit d0bcc1
  if (iface->clear_selection)
Packit d0bcc1
    return (iface->clear_selection) (obj);
Packit d0bcc1
  else
Packit d0bcc1
    return FALSE;
Packit d0bcc1
}
Packit d0bcc1
Packit d0bcc1
/**
Packit d0bcc1
 * atk_selection_ref_selection:
Packit d0bcc1
 * @selection: a #GObject instance that implements AtkSelectionIface
Packit d0bcc1
 * @i: a #gint specifying the index in the selection set.  (e.g. the
Packit d0bcc1
 * ith selection as opposed to the ith child).
Packit d0bcc1
 *
Packit d0bcc1
 * Gets a reference to the accessible object representing the specified 
Packit d0bcc1
 * selected child of the object.
Packit d0bcc1
 * Note: callers should not rely on %NULL or on a zero value for
Packit d0bcc1
 * indication of whether AtkSelectionIface is implemented, they should
Packit d0bcc1
 * use type checking/interface checking macros or the
Packit d0bcc1
 * atk_get_accessible_value() convenience method.
Packit d0bcc1
 *
Packit d0bcc1
 * Returns: (nullable) (transfer full): an #AtkObject representing the
Packit d0bcc1
 * selected accessible, or %NULL if @selection does not implement this
Packit d0bcc1
 * interface.
Packit d0bcc1
 **/
Packit d0bcc1
AtkObject*
Packit d0bcc1
atk_selection_ref_selection (AtkSelection *obj,
Packit d0bcc1
                             gint         i)
Packit d0bcc1
{
Packit d0bcc1
  AtkSelectionIface *iface;
Packit d0bcc1
Packit d0bcc1
  g_return_val_if_fail (ATK_IS_SELECTION (obj), NULL);
Packit d0bcc1
Packit d0bcc1
  iface = ATK_SELECTION_GET_IFACE (obj);
Packit d0bcc1
Packit d0bcc1
  if (iface->ref_selection)
Packit d0bcc1
    return (iface->ref_selection) (obj, i);
Packit d0bcc1
  else
Packit d0bcc1
    return NULL;
Packit d0bcc1
}
Packit d0bcc1
Packit d0bcc1
/**
Packit d0bcc1
 * atk_selection_get_selection_count:
Packit d0bcc1
 * @selection: a #GObject instance that implements AtkSelectionIface
Packit d0bcc1
 *
Packit d0bcc1
 * Gets the number of accessible children currently selected.
Packit d0bcc1
 * Note: callers should not rely on %NULL or on a zero value for
Packit d0bcc1
 * indication of whether AtkSelectionIface is implemented, they should
Packit d0bcc1
 * use type checking/interface checking macros or the
Packit d0bcc1
 * atk_get_accessible_value() convenience method.
Packit d0bcc1
 *
Packit d0bcc1
 * Returns: a gint representing the number of items selected, or 0
Packit d0bcc1
 * if @selection does not implement this interface.
Packit d0bcc1
 **/
Packit d0bcc1
gint
Packit d0bcc1
atk_selection_get_selection_count (AtkSelection *obj)
Packit d0bcc1
{
Packit d0bcc1
  AtkSelectionIface *iface;
Packit d0bcc1
Packit d0bcc1
  g_return_val_if_fail (ATK_IS_SELECTION (obj), 0);
Packit d0bcc1
Packit d0bcc1
  iface = ATK_SELECTION_GET_IFACE (obj);
Packit d0bcc1
Packit d0bcc1
  if (iface->get_selection_count)
Packit d0bcc1
    return (iface->get_selection_count) (obj);
Packit d0bcc1
  else
Packit d0bcc1
    return 0;
Packit d0bcc1
}
Packit d0bcc1
Packit d0bcc1
/**
Packit d0bcc1
 * atk_selection_is_child_selected:
Packit d0bcc1
 * @selection: a #GObject instance that implements AtkSelectionIface
Packit d0bcc1
 * @i: a #gint specifying the child index.
Packit d0bcc1
 *
Packit d0bcc1
 * Determines if the current child of this object is selected
Packit d0bcc1
 * Note: callers should not rely on %NULL or on a zero value for
Packit d0bcc1
 * indication of whether AtkSelectionIface is implemented, they should
Packit d0bcc1
 * use type checking/interface checking macros or the
Packit d0bcc1
 * atk_get_accessible_value() convenience method.
Packit d0bcc1
 *
Packit d0bcc1
 * Returns: a gboolean representing the specified child is selected, or 0
Packit d0bcc1
 * if @selection does not implement this interface.
Packit d0bcc1
 **/
Packit d0bcc1
gboolean
Packit d0bcc1
atk_selection_is_child_selected (AtkSelection *obj,
Packit d0bcc1
                                 gint         i)
Packit d0bcc1
{
Packit d0bcc1
  AtkSelectionIface *iface;
Packit d0bcc1
Packit d0bcc1
  g_return_val_if_fail (ATK_IS_SELECTION (obj), FALSE);
Packit d0bcc1
Packit d0bcc1
  iface = ATK_SELECTION_GET_IFACE (obj);
Packit d0bcc1
Packit d0bcc1
  if (iface->is_child_selected)
Packit d0bcc1
    return (iface->is_child_selected) (obj, i);
Packit d0bcc1
  else
Packit d0bcc1
    return FALSE;
Packit d0bcc1
}
Packit d0bcc1
Packit d0bcc1
/**
Packit d0bcc1
 * atk_selection_remove_selection:
Packit d0bcc1
 * @selection: a #GObject instance that implements AtkSelectionIface
Packit d0bcc1
 * @i: a #gint specifying the index in the selection set.  (e.g. the
Packit d0bcc1
 * ith selection as opposed to the ith child).
Packit d0bcc1
 *
Packit d0bcc1
 * Removes the specified child of the object from the object's selection.
Packit d0bcc1
 *
Packit d0bcc1
 * Returns: TRUE if success, FALSE otherwise.
Packit d0bcc1
 **/
Packit d0bcc1
gboolean
Packit d0bcc1
atk_selection_remove_selection (AtkSelection *obj,
Packit d0bcc1
                                gint         i)
Packit d0bcc1
{
Packit d0bcc1
  AtkSelectionIface *iface;
Packit d0bcc1
Packit d0bcc1
  g_return_val_if_fail (ATK_IS_SELECTION (obj), FALSE);
Packit d0bcc1
Packit d0bcc1
  iface = ATK_SELECTION_GET_IFACE (obj);
Packit d0bcc1
Packit d0bcc1
  if (iface->remove_selection)
Packit d0bcc1
    return (iface->remove_selection) (obj, i);
Packit d0bcc1
  else
Packit d0bcc1
    return FALSE;
Packit d0bcc1
}
Packit d0bcc1
Packit d0bcc1
/**
Packit d0bcc1
 * atk_selection_select_all_selection:
Packit d0bcc1
 * @selection: a #GObject instance that implements AtkSelectionIface
Packit d0bcc1
 *
Packit d0bcc1
 * Causes every child of the object to be selected if the object
Packit d0bcc1
 * supports multiple selections.
Packit d0bcc1
 *
Packit d0bcc1
 * Returns: TRUE if success, FALSE otherwise.
Packit d0bcc1
 **/
Packit d0bcc1
gboolean
Packit d0bcc1
atk_selection_select_all_selection (AtkSelection *obj)
Packit d0bcc1
{
Packit d0bcc1
  AtkSelectionIface *iface;
Packit d0bcc1
Packit d0bcc1
  g_return_val_if_fail (ATK_IS_SELECTION (obj), FALSE);
Packit d0bcc1
Packit d0bcc1
  iface = ATK_SELECTION_GET_IFACE (obj);
Packit d0bcc1
Packit d0bcc1
  if (iface->select_all_selection)
Packit d0bcc1
    return (iface->select_all_selection) (obj);
Packit d0bcc1
  else
Packit d0bcc1
    return FALSE;
Packit d0bcc1
}