]> Pileus Git - ~andy/gtk/blob - gtk/a11y/gtkpanedaccessible.c
a0b8f37b565c63105efedfd6b81e9a9ddc09ec45
[~andy/gtk] / gtk / a11y / gtkpanedaccessible.c
1 /* GAIL - The GNOME Accessibility Enabling Library
2  * Copyright 2001, 2002, 2003 Sun Microsystems Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include "config.h"
21
22 #include <string.h>
23 #include <gtk/gtk.h>
24 #include "gtkpanedaccessible.h"
25
26 static void atk_value_interface_init (AtkValueIface *iface);
27
28 G_DEFINE_TYPE_WITH_CODE (GtkPanedAccessible, _gtk_paned_accessible, GTK_TYPE_CONTAINER_ACCESSIBLE,
29                          G_IMPLEMENT_INTERFACE (ATK_TYPE_VALUE, atk_value_interface_init))
30
31 static void
32 gtk_paned_accessible_size_allocate_gtk (GtkWidget     *widget,
33                                         GtkAllocation *allocation)
34 {
35   AtkObject *obj = gtk_widget_get_accessible (widget);
36
37   g_object_notify (G_OBJECT (obj), "accessible-value");
38 }
39
40 static void
41 gtk_paned_accessible_initialize (AtkObject *obj,
42                                  gpointer   data)
43 {
44   ATK_OBJECT_CLASS (_gtk_paned_accessible_parent_class)->initialize (obj, data);
45
46   g_signal_connect (data, "size-allocate",
47                     G_CALLBACK (gtk_paned_accessible_size_allocate_gtk), NULL);
48
49   obj->role = ATK_ROLE_SPLIT_PANE;
50 }
51
52 static void
53 _gtk_paned_accessible_class_init (GtkPanedAccessibleClass *klass)
54 {
55   AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
56
57   class->initialize = gtk_paned_accessible_initialize;
58 }
59
60 static void
61 _gtk_paned_accessible_init (GtkPanedAccessible *paned)
62 {
63 }
64
65 static void
66 gtk_paned_accessible_get_current_value (AtkValue *obj,
67                                         GValue   *value)
68 {
69   GtkWidget* widget;
70   gint current_value;
71
72   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
73   if (widget == NULL)
74     return;
75
76   current_value = gtk_paned_get_position (GTK_PANED (widget));
77   memset (value,  0, sizeof (GValue));
78   g_value_init (value, G_TYPE_INT);
79   g_value_set_int (value,current_value);
80 }
81
82 static void
83 gtk_paned_accessible_get_maximum_value (AtkValue *obj,
84                                         GValue   *value)
85 {
86   GtkWidget* widget;
87   gint maximum_value;
88
89   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
90   if (widget == NULL)
91     return;
92
93   g_object_get (GTK_PANED (widget),
94                 "max-position", &maximum_value,
95                 NULL);
96   memset (value,  0, sizeof (GValue));
97   g_value_init (value, G_TYPE_INT);
98   g_value_set_int (value, maximum_value);
99 }
100
101 static void
102 gtk_paned_accessible_get_minimum_value (AtkValue *obj,
103                                         GValue   *value)
104 {
105   GtkWidget* widget;
106   gint minimum_value;
107
108   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
109   if (widget == NULL)
110     return;
111
112   g_object_get (GTK_PANED (widget),
113                 "min-position", &minimum_value,
114                 NULL);
115   memset (value,  0, sizeof (GValue));
116   g_value_init (value, G_TYPE_INT);
117   g_value_set_int (value, minimum_value);
118 }
119
120 /* Calling atk_value_set_current_value() is no guarantee that the value
121  * is acceptable; it is necessary to listen for accessible-value signals
122  * and check whether the current value has been changed or check what the
123  * maximum and minimum values are.
124  */
125 static gboolean
126 gtk_paned_accessible_set_current_value (AtkValue     *obj,
127                                         const GValue *value)
128 {
129   GtkWidget* widget;
130   gint new_value;
131
132   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
133   if (widget == NULL)
134     return FALSE;
135
136   if (G_VALUE_HOLDS_INT (value))
137     {
138       new_value = g_value_get_int (value);
139       gtk_paned_set_position (GTK_PANED (widget), new_value);
140
141       return TRUE;
142     }
143   else
144     return FALSE;
145 }
146
147 static void
148 atk_value_interface_init (AtkValueIface *iface)
149 {
150   iface->get_current_value = gtk_paned_accessible_get_current_value;
151   iface->get_maximum_value = gtk_paned_accessible_get_maximum_value;
152   iface->get_minimum_value = gtk_paned_accessible_get_minimum_value;
153   iface->set_current_value = gtk_paned_accessible_set_current_value;
154 }