1 /* GAIL - The GNOME Accessibility Implementation Library
2 * Copyright 2001, 2002, 2003 Sun Microsystems Inc.
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.
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.
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.
24 #include "gailadjustment.h"
26 static void gail_adjustment_class_init (GailAdjustmentClass *klass);
28 static void gail_adjustment_init (GailAdjustment *adjustment);
30 static void gail_adjustment_real_initialize (AtkObject *obj,
33 static void atk_value_interface_init (AtkValueIface *iface);
35 static void gail_adjustment_get_current_value (AtkValue *obj,
37 static void gail_adjustment_get_maximum_value (AtkValue *obj,
39 static void gail_adjustment_get_minimum_value (AtkValue *obj,
41 static void gail_adjustment_get_minimum_increment (AtkValue *obj,
43 static gboolean gail_adjustment_set_current_value (AtkValue *obj,
46 G_DEFINE_TYPE_WITH_CODE (GailAdjustment, gail_adjustment, ATK_TYPE_OBJECT,
47 G_IMPLEMENT_INTERFACE (ATK_TYPE_VALUE, atk_value_interface_init))
50 gail_adjustment_class_init (GailAdjustmentClass *klass)
52 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
54 class->initialize = gail_adjustment_real_initialize;
58 gail_adjustment_init (GailAdjustment *adjustment)
63 gail_adjustment_new (GtkAdjustment *adjustment)
66 AtkObject *atk_object;
68 g_return_val_if_fail (GTK_IS_ADJUSTMENT (adjustment), NULL);
70 object = g_object_new (GAIL_TYPE_ADJUSTMENT, NULL);
72 atk_object = ATK_OBJECT (object);
73 atk_object_initialize (atk_object, adjustment);
79 gail_adjustment_real_initialize (AtkObject *obj,
82 GtkAdjustment *adjustment;
83 GailAdjustment *gail_adjustment;
85 ATK_OBJECT_CLASS (gail_adjustment_parent_class)->initialize (obj, data);
87 adjustment = GTK_ADJUSTMENT (data);
89 obj->role = ATK_ROLE_UNKNOWN;
90 gail_adjustment = GAIL_ADJUSTMENT (obj);
91 gail_adjustment->adjustment = adjustment;
93 g_object_add_weak_pointer (G_OBJECT (adjustment),
94 (gpointer *) &gail_adjustment->adjustment);
98 atk_value_interface_init (AtkValueIface *iface)
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;
108 gail_adjustment_get_current_value (AtkValue *obj,
111 GtkAdjustment* adjustment;
112 gdouble current_value;
114 adjustment = GAIL_ADJUSTMENT (obj)->adjustment;
115 if (adjustment == NULL)
117 /* State is defunct */
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);
128 gail_adjustment_get_maximum_value (AtkValue *obj,
131 GtkAdjustment* adjustment;
132 gdouble maximum_value;
134 adjustment = GAIL_ADJUSTMENT (obj)->adjustment;
135 if (adjustment == NULL)
137 /* State is defunct */
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);
148 gail_adjustment_get_minimum_value (AtkValue *obj,
151 GtkAdjustment* adjustment;
152 gdouble minimum_value;
154 adjustment = GAIL_ADJUSTMENT (obj)->adjustment;
155 if (adjustment == NULL)
157 /* State is defunct */
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);
168 gail_adjustment_get_minimum_increment (AtkValue *obj,
171 GtkAdjustment* adjustment;
172 gdouble minimum_increment;
174 adjustment = GAIL_ADJUSTMENT (obj)->adjustment;
175 if (adjustment == NULL)
177 /* State is defunct */
181 if (gtk_adjustment_get_step_increment (adjustment) != 0 &&
182 gtk_adjustment_get_page_increment (adjustment) != 0)
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);
187 minimum_increment = gtk_adjustment_get_page_increment (adjustment);
189 else if (gtk_adjustment_get_step_increment (adjustment) == 0 &&
190 gtk_adjustment_get_page_increment (adjustment) == 0)
192 minimum_increment = 0;
194 else if (gtk_adjustment_get_step_increment (adjustment) == 0)
196 minimum_increment = gtk_adjustment_get_page_increment (adjustment);
200 minimum_increment = gtk_adjustment_get_step_increment (adjustment);
203 memset (value, 0, sizeof (GValue));
204 g_value_init (value, G_TYPE_DOUBLE);
205 g_value_set_double (value, minimum_increment);
209 gail_adjustment_set_current_value (AtkValue *obj,
212 if (G_VALUE_HOLDS_DOUBLE (value))
214 GtkAdjustment* adjustment;
217 adjustment = GAIL_ADJUSTMENT (obj)->adjustment;
218 if (adjustment == NULL)
220 /* State is defunct */
223 new_value = g_value_get_double (value);
224 gtk_adjustment_set_value (adjustment, new_value);