]> Pileus Git - ~andy/gtk/blob - gtk/a11y/gailadjustment.c
gail: No need to include modules/other in CFLAGS anymore
[~andy/gtk] / gtk / a11y / gailadjustment.c
1 /* GAIL - The GNOME Accessibility Implementation 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 "gailadjustment.h"
25
26 static void      gail_adjustment_class_init        (GailAdjustmentClass *klass);
27
28 static void      gail_adjustment_init              (GailAdjustment      *adjustment);
29
30 static void      gail_adjustment_real_initialize   (AtkObject           *obj,
31                                                     gpointer            data);
32
33 static void      atk_value_interface_init          (AtkValueIface       *iface);
34
35 static void      gail_adjustment_get_current_value (AtkValue            *obj,
36                                                     GValue              *value);
37 static void      gail_adjustment_get_maximum_value (AtkValue            *obj,
38                                                     GValue              *value);
39 static void      gail_adjustment_get_minimum_value (AtkValue            *obj,
40                                                     GValue              *value);
41 static void      gail_adjustment_get_minimum_increment (AtkValue        *obj,
42                                                     GValue              *value);
43 static gboolean  gail_adjustment_set_current_value (AtkValue            *obj,
44                                                     const GValue        *value);
45
46 G_DEFINE_TYPE_WITH_CODE (GailAdjustment, gail_adjustment, ATK_TYPE_OBJECT,
47                          G_IMPLEMENT_INTERFACE (ATK_TYPE_VALUE, atk_value_interface_init))
48
49 static void      
50 gail_adjustment_class_init (GailAdjustmentClass *klass)
51 {
52   AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
53
54   class->initialize = gail_adjustment_real_initialize;
55 }
56
57 static void
58 gail_adjustment_init (GailAdjustment *adjustment)
59 {
60 }
61
62 AtkObject* 
63 gail_adjustment_new (GtkAdjustment *adjustment)
64 {
65   GObject *object;
66   AtkObject *atk_object;
67
68   g_return_val_if_fail (GTK_IS_ADJUSTMENT (adjustment), NULL);
69
70   object = g_object_new (GAIL_TYPE_ADJUSTMENT, NULL);
71
72   atk_object = ATK_OBJECT (object);
73   atk_object_initialize (atk_object, adjustment);
74
75   return atk_object;
76 }
77
78 static void
79 gail_adjustment_real_initialize (AtkObject *obj,
80                                  gpointer  data)
81 {
82   GtkAdjustment *adjustment;
83   GailAdjustment *gail_adjustment;
84
85   ATK_OBJECT_CLASS (gail_adjustment_parent_class)->initialize (obj, data);
86
87   adjustment = GTK_ADJUSTMENT (data);
88
89   obj->role = ATK_ROLE_UNKNOWN;
90   gail_adjustment = GAIL_ADJUSTMENT (obj);
91   gail_adjustment->adjustment = adjustment;
92
93   g_object_add_weak_pointer (G_OBJECT (adjustment),
94                              (gpointer *) &gail_adjustment->adjustment);
95 }
96
97 static void      
98 atk_value_interface_init (AtkValueIface *iface)
99 {
100   iface->get_current_value = gail_adjustment_get_current_value;
101   iface->get_maximum_value = gail_adjustment_get_maximum_value;
102   iface->get_minimum_value = gail_adjustment_get_minimum_value;
103   iface->get_minimum_increment = gail_adjustment_get_minimum_increment;
104   iface->set_current_value = gail_adjustment_set_current_value;
105 }
106
107 static void      
108 gail_adjustment_get_current_value (AtkValue             *obj,
109                                    GValue               *value)
110 {
111   GtkAdjustment* adjustment;
112   gdouble current_value;
113  
114   adjustment = GAIL_ADJUSTMENT (obj)->adjustment;
115   if (adjustment == NULL)
116   {
117     /* State is defunct */
118     return;
119   }
120
121   current_value = gtk_adjustment_get_value (adjustment);
122   memset (value,  0, sizeof (GValue));
123   g_value_init (value, G_TYPE_DOUBLE);
124   g_value_set_double (value,current_value);
125 }
126
127 static void      
128 gail_adjustment_get_maximum_value (AtkValue             *obj,
129                                    GValue               *value)
130 {
131   GtkAdjustment* adjustment;
132   gdouble maximum_value;
133  
134   adjustment = GAIL_ADJUSTMENT (obj)->adjustment;
135   if (adjustment == NULL)
136   {
137     /* State is defunct */
138     return;
139   }
140
141   maximum_value = gtk_adjustment_get_upper (adjustment);
142   memset (value,  0, sizeof (GValue));
143   g_value_init (value, G_TYPE_DOUBLE);
144   g_value_set_double (value, maximum_value);
145 }
146
147 static void      
148 gail_adjustment_get_minimum_value (AtkValue             *obj,
149                                    GValue               *value)
150 {
151   GtkAdjustment* adjustment;
152   gdouble minimum_value;
153  
154   adjustment = GAIL_ADJUSTMENT (obj)->adjustment;
155   if (adjustment == NULL)
156   {
157     /* State is defunct */
158     return;
159   }
160
161   minimum_value = gtk_adjustment_get_lower (adjustment);
162   memset (value,  0, sizeof (GValue));
163   g_value_init (value, G_TYPE_DOUBLE);
164   g_value_set_double (value, minimum_value);
165 }
166
167 static void
168 gail_adjustment_get_minimum_increment (AtkValue        *obj,
169                                        GValue          *value)
170 {
171   GtkAdjustment* adjustment;
172   gdouble minimum_increment;
173  
174   adjustment = GAIL_ADJUSTMENT (obj)->adjustment;
175   if (adjustment == NULL)
176   {
177     /* State is defunct */
178     return;
179   }
180
181   if (gtk_adjustment_get_step_increment (adjustment) != 0 &&
182       gtk_adjustment_get_page_increment (adjustment) != 0)
183     {
184       if (ABS (gtk_adjustment_get_step_increment (adjustment)) < ABS (gtk_adjustment_get_page_increment (adjustment)))
185         minimum_increment = gtk_adjustment_get_step_increment (adjustment);
186       else
187         minimum_increment = gtk_adjustment_get_page_increment (adjustment);
188     }
189   else if (gtk_adjustment_get_step_increment (adjustment) == 0 &&
190            gtk_adjustment_get_page_increment (adjustment) == 0)
191     {
192       minimum_increment = 0;
193     }
194   else if (gtk_adjustment_get_step_increment (adjustment) == 0)
195     {
196       minimum_increment = gtk_adjustment_get_page_increment (adjustment);
197     }
198   else
199     {
200       minimum_increment = gtk_adjustment_get_step_increment (adjustment);
201     }
202
203   memset (value,  0, sizeof (GValue));
204   g_value_init (value, G_TYPE_DOUBLE);
205   g_value_set_double (value, minimum_increment);
206 }
207
208 static gboolean  
209 gail_adjustment_set_current_value (AtkValue             *obj,
210                                    const GValue         *value)
211 {
212   if (G_VALUE_HOLDS_DOUBLE (value))
213   {
214     GtkAdjustment* adjustment;
215     gdouble new_value;
216  
217     adjustment = GAIL_ADJUSTMENT (obj)->adjustment;
218     if (adjustment == NULL)
219     {
220       /* State is defunct */
221       return FALSE;
222     }
223     new_value = g_value_get_double (value);
224     gtk_adjustment_set_value (adjustment, new_value);
225
226     return TRUE;
227   }
228   else
229     return FALSE;
230 }