gtkcontainercellaccessible.c 5.42 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* GAIL - The GNOME Accessibility Enabling Library
 * Copyright 2001 Sun Microsystems Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
Javier Jardón's avatar
Javier Jardón committed
15
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 17 18 19 20 21 22
 */

#include "config.h"

#include <gtk/gtk.h>
#include "gtkcontainercellaccessible.h"

23 24 25 26 27
struct _GtkContainerCellAccessiblePrivate
{
  GList *children;
  gint n_children;
};
28 29 30 31 32 33 34 35 36

G_DEFINE_TYPE (GtkContainerCellAccessible, _gtk_container_cell_accessible, GTK_TYPE_CELL_ACCESSIBLE)


static void
gtk_container_cell_accessible_finalize (GObject *obj)
{
  GtkContainerCellAccessible *container = GTK_CONTAINER_CELL_ACCESSIBLE (obj);

37
  g_list_free_full (container->priv->children, g_object_unref);
38 39 40 41 42 43 44 45 46 47

  G_OBJECT_CLASS (_gtk_container_cell_accessible_parent_class)->finalize (obj);
}


static gint
gtk_container_cell_accessible_get_n_children (AtkObject *obj)
{
  GtkContainerCellAccessible *cell = GTK_CONTAINER_CELL_ACCESSIBLE (obj);

48
  return cell->priv->n_children;
49 50 51 52 53 54 55 56 57
}

static AtkObject *
gtk_container_cell_accessible_ref_child (AtkObject *obj,
                                         gint       child)
{
  GtkContainerCellAccessible *cell = GTK_CONTAINER_CELL_ACCESSIBLE (obj);
  GList *l;

58
  l = g_list_nth (cell->priv->children, child);
59 60 61 62 63 64
  if (l == NULL)
    return NULL;

  return g_object_ref (ATK_OBJECT (l->data));
}

65 66 67 68 69 70
static void
gtk_container_cell_accessible_update_cache (GtkCellAccessible *cell)
{
  GtkContainerCellAccessible *container = GTK_CONTAINER_CELL_ACCESSIBLE (cell);
  GList *l;

71
  for (l = container->priv->children; l; l = l->next)
72 73 74 75 76
    {
      _gtk_cell_accessible_update_cache (l->data);
    }
}

77 78 79 80 81 82
static void
gtk_container_cell_widget_set (GtkAccessible *accessible)
{
  GtkContainerCellAccessible *container = GTK_CONTAINER_CELL_ACCESSIBLE (accessible);
  GList *l;

83
  for (l = container->priv->children; l; l = l->next)
84 85 86 87 88 89 90 91 92 93 94 95 96
    {
      gtk_accessible_set_widget (l->data, gtk_accessible_get_widget (accessible));
    }

  GTK_ACCESSIBLE_CLASS (_gtk_container_cell_accessible_parent_class)->widget_unset (accessible);
}

static void
gtk_container_cell_widget_unset (GtkAccessible *accessible)
{
  GtkContainerCellAccessible *container = GTK_CONTAINER_CELL_ACCESSIBLE (accessible);
  GList *l;

97
  for (l = container->priv->children; l; l = l->next)
98 99 100 101 102 103 104
    {
      gtk_accessible_set_widget (l->data, NULL);
    }

  GTK_ACCESSIBLE_CLASS (_gtk_container_cell_accessible_parent_class)->widget_unset (accessible);
}

105 106 107
static void
_gtk_container_cell_accessible_class_init (GtkContainerCellAccessibleClass *klass)
{
108
  GtkCellAccessibleClass *cell_class = GTK_CELL_ACCESSIBLE_CLASS (klass);
109
  GtkAccessibleClass *accessible_class = GTK_ACCESSIBLE_CLASS (klass);
110
  AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
111 112 113 114 115 116
  GObjectClass *g_object_class = G_OBJECT_CLASS (klass);

  g_object_class->finalize = gtk_container_cell_accessible_finalize;

  class->get_n_children = gtk_container_cell_accessible_get_n_children;
  class->ref_child = gtk_container_cell_accessible_ref_child;
117

118 119 120
  accessible_class->widget_unset = gtk_container_cell_widget_set;
  accessible_class->widget_unset = gtk_container_cell_widget_unset;

121
  cell_class->update_cache = gtk_container_cell_accessible_update_cache;
122 123

  g_type_class_add_private (g_object_class, sizeof (GtkContainerCellAccessiblePrivate));
124 125 126 127 128
}

static void
_gtk_container_cell_accessible_init (GtkContainerCellAccessible *cell)
{
129 130 131
  cell->priv = G_TYPE_INSTANCE_GET_PRIVATE (cell,
                                            GTK_TYPE_CONTAINER_CELL_ACCESSIBLE,
                                            GtkContainerCellAccessiblePrivate);
132 133 134 135 136 137 138 139 140
}

GtkContainerCellAccessible *
_gtk_container_cell_accessible_new (void)
{
  GObject *object;

  object = g_object_new (GTK_TYPE_CONTAINER_CELL_ACCESSIBLE, NULL);

141
  ATK_OBJECT (object)->role = ATK_ROLE_TABLE_CELL;
142

143
  return GTK_CONTAINER_CELL_ACCESSIBLE (object);
144 145 146 147 148 149 150 151 152
}

void
_gtk_container_cell_accessible_add_child (GtkContainerCellAccessible *container,
                                          GtkCellAccessible          *child)
{
  g_return_if_fail (GTK_IS_CONTAINER_CELL_ACCESSIBLE (container));
  g_return_if_fail (GTK_IS_CELL_ACCESSIBLE (child));

153 154
  container->priv->n_children++;
  container->priv->children = g_list_append (container->priv->children, child);
155 156 157 158 159 160 161 162 163
  atk_object_set_parent (ATK_OBJECT (child), ATK_OBJECT (container));
}

void
_gtk_container_cell_accessible_remove_child (GtkContainerCellAccessible *container,
                                             GtkCellAccessible          *child)
{
  g_return_if_fail (GTK_IS_CONTAINER_CELL_ACCESSIBLE (container));
  g_return_if_fail (GTK_IS_CELL_ACCESSIBLE (child));
164 165 166 167 168 169 170
  g_return_if_fail (container->priv->n_children > 0);

  container->priv->children = g_list_remove (container->priv->children, child);
  container->priv->n_children--;
}

GList *
Cosimo Cecchi's avatar
Cosimo Cecchi committed
171
_gtk_container_cell_accessible_get_children (GtkContainerCellAccessible *container)
172 173
{
  g_return_val_if_fail (GTK_IS_CONTAINER_CELL_ACCESSIBLE (container), NULL);
174

175
  return container->priv->children;
176
}