gtkpanedaccessible.c 5.64 KB
Newer Older
Matthias Clasen's avatar
Matthias Clasen committed
1
/* GTK+ - accessibility implementations
2 3 4 5 6 7 8 9 10 11 12 13 14
 * Copyright 2001, 2002, 2003 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
#include "config.h"
19

20 21
#include <string.h>
#include <gtk/gtk.h>
22
#include "gtkpanedaccessible.h"
23

24
static void atk_value_interface_init (AtkValueIface *iface);
25

26
G_DEFINE_TYPE_WITH_CODE (GtkPanedAccessible, gtk_paned_accessible, GTK_TYPE_CONTAINER_ACCESSIBLE,
27
                         G_IMPLEMENT_INTERFACE (ATK_TYPE_VALUE, atk_value_interface_init))
28

29
static void
30 31
gtk_paned_accessible_size_allocate_gtk (GtkWidget     *widget,
                                        GtkAllocation *allocation)
32
{
33 34 35
  AtkObject *obj = gtk_widget_get_accessible (widget);

  g_object_notify (G_OBJECT (obj), "accessible-value");
36 37
}

38
static void
39 40
gtk_paned_accessible_initialize (AtkObject *obj,
                                 gpointer   data)
41
{
42
  ATK_OBJECT_CLASS (gtk_paned_accessible_parent_class)->initialize (obj, data);
43

Matthias Clasen's avatar
Matthias Clasen committed
44
  g_signal_connect (data, "size-allocate",
45
                    G_CALLBACK (gtk_paned_accessible_size_allocate_gtk), NULL);
46 47 48

  obj->role = ATK_ROLE_SPLIT_PANE;
}
49

50
static void
51
gtk_paned_accessible_class_init (GtkPanedAccessibleClass *klass)
52
{
53
  AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
54

55
  class->initialize = gtk_paned_accessible_initialize;
56 57 58
}

static void
59
gtk_paned_accessible_init (GtkPanedAccessible *paned)
60 61 62 63
{
}

static void
64 65
gtk_paned_accessible_get_current_value (AtkValue *obj,
                                        GValue   *value)
66 67 68 69
{
  GtkWidget* widget;
  gint current_value;

70
  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
71 72 73 74 75 76
  if (widget == NULL)
    return;

  current_value = gtk_paned_get_position (GTK_PANED (widget));
  memset (value,  0, sizeof (GValue));
  g_value_init (value, G_TYPE_INT);
Matthias Clasen's avatar
Matthias Clasen committed
77
  g_value_set_int (value, current_value);
78 79 80
}

static void
81 82
gtk_paned_accessible_get_maximum_value (AtkValue *obj,
                                        GValue   *value)
83 84 85 86
{
  GtkWidget* widget;
  gint maximum_value;

87
  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
88 89 90
  if (widget == NULL)
    return;

91 92 93
  g_object_get (GTK_PANED (widget),
                "max-position", &maximum_value,
                NULL);
94 95 96 97 98 99
  memset (value,  0, sizeof (GValue));
  g_value_init (value, G_TYPE_INT);
  g_value_set_int (value, maximum_value);
}

static void
100 101
gtk_paned_accessible_get_minimum_value (AtkValue *obj,
                                        GValue   *value)
102 103 104 105
{
  GtkWidget* widget;
  gint minimum_value;

106
  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
107 108 109
  if (widget == NULL)
    return;

110 111 112
  g_object_get (GTK_PANED (widget),
                "min-position", &minimum_value,
                NULL);
113 114 115 116 117
  memset (value,  0, sizeof (GValue));
  g_value_init (value, G_TYPE_INT);
  g_value_set_int (value, minimum_value);
}

118
/* Calling atk_value_set_current_value() is no guarantee that the value
119 120
 * is acceptable; it is necessary to listen for accessible-value signals
 * and check whether the current value has been changed or check what the
121 122 123
 * maximum and minimum values are.
 */
static gboolean
124 125
gtk_paned_accessible_set_current_value (AtkValue     *obj,
                                        const GValue *value)
126 127 128 129
{
  GtkWidget* widget;
  gint new_value;

130
  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
131 132 133 134 135 136 137 138 139 140 141 142 143
  if (widget == NULL)
    return FALSE;

  if (G_VALUE_HOLDS_INT (value))
    {
      new_value = g_value_get_int (value);
      gtk_paned_set_position (GTK_PANED (widget), new_value);

      return TRUE;
    }
  else
    return FALSE;
}
144

145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
static void
gtk_paned_accessible_get_value_and_text (AtkValue  *obj,
                                         gdouble   *value,
                                         gchar    **text)
{
  GtkWidget *widget;
  GtkPaned *paned;

  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
  paned = GTK_PANED (widget);

  *value = gtk_paned_get_position (paned);
  *text = NULL;
}

static AtkRange *
gtk_paned_accessible_get_range (AtkValue *obj)
{
  GtkWidget *widget;
  gint minimum_value;
  gint maximum_value;

  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));

  g_object_get (widget,
                "min-position", &minimum_value,
                "max-position", &maximum_value,
                NULL);

  return atk_range_new (minimum_value, maximum_value, NULL);
}

static void
gtk_paned_accessible_set_value (AtkValue      *obj,
                                const gdouble  value)
{
  GtkWidget *widget;
  GtkPaned *paned;

  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
  paned = GTK_PANED (widget);

  gtk_paned_set_position (paned, (gint)(value + 0.5));
}

190 191 192 193 194 195 196
static void
atk_value_interface_init (AtkValueIface *iface)
{
  iface->get_current_value = gtk_paned_accessible_get_current_value;
  iface->get_maximum_value = gtk_paned_accessible_get_maximum_value;
  iface->get_minimum_value = gtk_paned_accessible_get_minimum_value;
  iface->set_current_value = gtk_paned_accessible_set_current_value;
197 198 199 200

  iface->get_value_and_text = gtk_paned_accessible_get_value_and_text;
  iface->get_range = gtk_paned_accessible_get_range;
  iface->set_value = gtk_paned_accessible_set_value;
201
}