]> Pileus Git - ~andy/gtk/blob - gtk/a11y/gtkpanedaccessible.c
gtkenums: correct various documentation typos
[~andy/gtk] / gtk / a11y / gtkpanedaccessible.c
1 /* GTK+ - accessibility implementations
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, see <http://www.gnu.org/licenses/>.
16  */
17
18 #include "config.h"
19
20 #include <string.h>
21 #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 gtk_paned_accessible_size_allocate_gtk (GtkWidget     *widget,
31                                         GtkAllocation *allocation)
32 {
33   AtkObject *obj = gtk_widget_get_accessible (widget);
34
35   g_object_notify (G_OBJECT (obj), "accessible-value");
36 }
37
38 static void
39 gtk_paned_accessible_initialize (AtkObject *obj,
40                                  gpointer   data)
41 {
42   ATK_OBJECT_CLASS (gtk_paned_accessible_parent_class)->initialize (obj, data);
43
44   g_signal_connect (data, "size-allocate",
45                     G_CALLBACK (gtk_paned_accessible_size_allocate_gtk), NULL);
46
47   obj->role = ATK_ROLE_SPLIT_PANE;
48 }
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 gtk_paned_accessible_get_current_value (AtkValue *obj,
65                                         GValue   *value)
66 {
67   GtkWidget* widget;
68   gint current_value;
69
70   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
71   if (widget == NULL)
72     return;
73
74   current_value = gtk_paned_get_position (GTK_PANED (widget));
75   memset (value,  0, sizeof (GValue));
76   g_value_init (value, G_TYPE_INT);
77   g_value_set_int (value,current_value);
78 }
79
80 static void
81 gtk_paned_accessible_get_maximum_value (AtkValue *obj,
82                                         GValue   *value)
83 {
84   GtkWidget* widget;
85   gint maximum_value;
86
87   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
88   if (widget == NULL)
89     return;
90
91   g_object_get (GTK_PANED (widget),
92                 "max-position", &maximum_value,
93                 NULL);
94   memset (value,  0, sizeof (GValue));
95   g_value_init (value, G_TYPE_INT);
96   g_value_set_int (value, maximum_value);
97 }
98
99 static void
100 gtk_paned_accessible_get_minimum_value (AtkValue *obj,
101                                         GValue   *value)
102 {
103   GtkWidget* widget;
104   gint minimum_value;
105
106   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
107   if (widget == NULL)
108     return;
109
110   g_object_get (GTK_PANED (widget),
111                 "min-position", &minimum_value,
112                 NULL);
113   memset (value,  0, sizeof (GValue));
114   g_value_init (value, G_TYPE_INT);
115   g_value_set_int (value, minimum_value);
116 }
117
118 /* Calling atk_value_set_current_value() is no guarantee that the value
119  * is acceptable; it is necessary to listen for accessible-value signals
120  * and check whether the current value has been changed or check what the
121  * maximum and minimum values are.
122  */
123 static gboolean
124 gtk_paned_accessible_set_current_value (AtkValue     *obj,
125                                         const GValue *value)
126 {
127   GtkWidget* widget;
128   gint new_value;
129
130   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
131   if (widget == NULL)
132     return FALSE;
133
134   if (G_VALUE_HOLDS_INT (value))
135     {
136       new_value = g_value_get_int (value);
137       gtk_paned_set_position (GTK_PANED (widget), new_value);
138
139       return TRUE;
140     }
141   else
142     return FALSE;
143 }
144
145 static void
146 atk_value_interface_init (AtkValueIface *iface)
147 {
148   iface->get_current_value = gtk_paned_accessible_get_current_value;
149   iface->get_maximum_value = gtk_paned_accessible_get_maximum_value;
150   iface->get_minimum_value = gtk_paned_accessible_get_minimum_value;
151   iface->set_current_value = gtk_paned_accessible_set_current_value;
152 }