]> Pileus Git - ~andy/gtk/blob - modules/other/gail/gailpaned.c
7f91f13b05581ea886613c6503ffd2fa46e2881b
[~andy/gtk] / modules / other / gail / gailpaned.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 "gailpaned.h"
25
26 static void         gail_paned_class_init          (GailPanedClass *klass); 
27
28 static void         gail_paned_init                (GailPaned      *paned);
29
30 static void         gail_paned_real_initialize     (AtkObject      *obj,
31                                                     gpointer       data);
32 static void         gail_paned_size_allocate_gtk   (GtkWidget      *widget,
33                                                     GtkAllocation  *allocation);
34 static void         atk_value_interface_init       (AtkValueIface  *iface);
35 static void         gail_paned_get_current_value   (AtkValue       *obj,
36                                                     GValue         *value);
37 static void         gail_paned_get_maximum_value   (AtkValue       *obj,
38                                                     GValue         *value);
39 static void         gail_paned_get_minimum_value   (AtkValue       *obj,
40                                                     GValue         *value);
41 static gboolean     gail_paned_set_current_value   (AtkValue       *obj,
42                                                     const GValue   *value);
43
44 G_DEFINE_TYPE_WITH_CODE (GailPaned, gail_paned, GAIL_TYPE_CONTAINER,
45                          G_IMPLEMENT_INTERFACE (ATK_TYPE_VALUE, atk_value_interface_init))
46
47 static void
48 gail_paned_class_init (GailPanedClass *klass)
49 {
50   AtkObjectClass  *class = ATK_OBJECT_CLASS (klass);
51
52   class->initialize = gail_paned_real_initialize;
53 }
54
55 static void
56 gail_paned_init (GailPaned *paned)
57 {
58 }
59
60 static void
61 gail_paned_real_initialize (AtkObject *obj,
62                             gpointer  data)
63 {
64   ATK_OBJECT_CLASS (gail_paned_parent_class)->initialize (obj, data);
65
66   g_signal_connect (data,
67                     "size_allocate",
68                     G_CALLBACK (gail_paned_size_allocate_gtk),
69                     NULL);
70
71   obj->role = ATK_ROLE_SPLIT_PANE;
72 }
73  
74 static void
75 gail_paned_size_allocate_gtk (GtkWidget      *widget,
76                               GtkAllocation  *allocation)
77 {
78   AtkObject *obj = gtk_widget_get_accessible (widget);
79
80   g_object_notify (G_OBJECT (obj), "accessible-value");
81 }
82
83
84 static void
85 atk_value_interface_init (AtkValueIface *iface)
86 {
87   iface->get_current_value = gail_paned_get_current_value;
88   iface->get_maximum_value = gail_paned_get_maximum_value;
89   iface->get_minimum_value = gail_paned_get_minimum_value;
90   iface->set_current_value = gail_paned_set_current_value;
91 }
92
93 static void
94 gail_paned_get_current_value (AtkValue             *obj,
95                               GValue               *value)
96 {
97   GtkWidget* widget;
98   gint current_value;
99
100   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
101   if (widget == NULL)
102     /* State is defunct */
103     return;
104
105   current_value = gtk_paned_get_position (GTK_PANED (widget));
106   memset (value,  0, sizeof (GValue));
107   g_value_init (value, G_TYPE_INT);
108   g_value_set_int (value,current_value);
109 }
110
111 static void
112 gail_paned_get_maximum_value (AtkValue             *obj,
113                               GValue               *value)
114 {
115   GtkWidget* widget;
116   gint maximum_value;
117
118   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
119   if (widget == NULL)
120     /* State is defunct */
121     return;
122
123   g_object_get (GTK_PANED (widget),
124                 "max-position", &maximum_value,
125                 NULL);
126   memset (value,  0, sizeof (GValue));
127   g_value_init (value, G_TYPE_INT);
128   g_value_set_int (value, maximum_value);
129 }
130
131 static void
132 gail_paned_get_minimum_value (AtkValue             *obj,
133                               GValue               *value)
134 {
135   GtkWidget* widget;
136   gint minimum_value;
137
138   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
139   if (widget == NULL)
140     /* State is defunct */
141     return;
142
143   g_object_get (GTK_PANED (widget),
144                 "min-position", &minimum_value,
145                 NULL);
146   memset (value,  0, sizeof (GValue));
147   g_value_init (value, G_TYPE_INT);
148   g_value_set_int (value, minimum_value);
149 }
150
151 /*
152  * Calling atk_value_set_current_value() is no guarantee that the value is
153  * acceptable; it is necessary to listen for accessible-value signals
154  * and check whether the current value has been changed or check what the 
155  * maximum and minimum values are.
156  */
157
158 static gboolean
159 gail_paned_set_current_value (AtkValue             *obj,
160                               const GValue         *value)
161 {
162   GtkWidget* widget;
163   gint new_value;
164
165   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
166   if (widget == NULL)
167     /* State is defunct */
168     return FALSE;
169
170   if (G_VALUE_HOLDS_INT (value))
171     {
172       new_value = g_value_get_int (value);
173       gtk_paned_set_position (GTK_PANED (widget), new_value);
174
175       return TRUE;
176     }
177   else
178     return FALSE;
179 }