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