summaryrefslogtreecommitdiff
path: root/gtk/a11y/gtkscrollbaraccessible.c
blob: 9193cd4e5ff4c77ee0f1ecdfd888936e8fce444a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* GAIL - The GNOME Accessibility Implementation 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
 * 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 "config.h"

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


G_DEFINE_TYPE (GtkScrollbarAccessible, gtk_scrollbar_accessible, GAIL_TYPE_RANGE)

static void
gtk_scrollbar_accessible_init (GtkScrollbarAccessible *accessible)
{
}

static void
gtk_scrollbar_accessible_initialize (AtkObject *accessible,
                           gpointer  data)
{
  ATK_OBJECT_CLASS (gtk_scrollbar_accessible_parent_class)->initialize (accessible, data);

  accessible->role = ATK_ROLE_SCROLL_BAR;
}

static gint
gtk_scrollbar_accessible_get_index_in_parent (AtkObject *accessible)
{
  GtkWidget *widget;
  GtkWidget *parent;
  GtkWidget *child;
  GtkScrolledWindow *scrolled_window;
  gint id;

  widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
  if (widget == NULL)
    return -1;

  parent = gtk_widget_get_parent (widget);
  if (!GTK_IS_SCROLLED_WINDOW (parent))
    return ATK_OBJECT_CLASS (gtk_scrollbar_accessible_parent_class)->get_index_in_parent (accessible);

  scrolled_window = GTK_SCROLLED_WINDOW (parent);
  id = 0;
  child = gtk_bin_get_child (GTK_BIN (scrolled_window));
  if (child)
    {
      if (widget == child)
        return id;
      id++;
    }

  child = gtk_scrolled_window_get_hscrollbar (scrolled_window);
  if (child)
    {
      if (widget == child)
        return id;
      id++;
    }
  child = gtk_scrolled_window_get_vscrollbar (scrolled_window);
  if (child)
    {
      if (widget == child)
        return id;
    }

  return -1;
}

static void
gtk_scrollbar_accessible_class_init (GtkScrollbarAccessibleClass *klass)
{
  AtkObjectClass *class = ATK_OBJECT_CLASS (klass);

  class->initialize = gtk_scrollbar_accessible_initialize;
  class->get_index_in_parent = gtk_scrollbar_accessible_get_index_in_parent;
}