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