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 "gailspinbutton.h"
25 #include "gailadjustment.h"
26 #include "gail-private-macros.h"
28 static void gail_spin_button_class_init (GailSpinButtonClass *klass);
29 static void gail_spin_button_init (GailSpinButton *button);
30 static void gail_spin_button_real_initialize (AtkObject *obj,
32 static void gail_spin_button_finalize (GObject *object);
34 static void atk_value_interface_init (AtkValueIface *iface);
36 static void gail_spin_button_real_notify_gtk (GObject *obj,
39 static void gail_spin_button_get_current_value (AtkValue *obj,
41 static void gail_spin_button_get_maximum_value (AtkValue *obj,
43 static void gail_spin_button_get_minimum_value (AtkValue *obj,
45 static void gail_spin_button_get_minimum_increment (AtkValue *obj,
47 static gboolean gail_spin_button_set_current_value (AtkValue *obj,
49 static void gail_spin_button_value_changed (GtkAdjustment *adjustment,
52 G_DEFINE_TYPE_WITH_CODE (GailSpinButton, gail_spin_button, GAIL_TYPE_ENTRY,
53 G_IMPLEMENT_INTERFACE (ATK_TYPE_VALUE, atk_value_interface_init))
56 gail_spin_button_class_init (GailSpinButtonClass *klass)
58 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
59 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
60 GailWidgetClass *widget_class;
62 widget_class = (GailWidgetClass*)klass;
64 widget_class->notify_gtk = gail_spin_button_real_notify_gtk;
66 class->initialize = gail_spin_button_real_initialize;
68 gobject_class->finalize = gail_spin_button_finalize;
72 gail_spin_button_init (GailSpinButton *button)
77 gail_spin_button_real_initialize (AtkObject *obj,
80 GtkAdjustment *adjustment;
81 GailSpinButton *spin_button = GAIL_SPIN_BUTTON (obj);
82 GtkSpinButton *gtk_spin_button;
84 ATK_OBJECT_CLASS (gail_spin_button_parent_class)->initialize (obj, data);
86 gtk_spin_button = GTK_SPIN_BUTTON (data);
88 * If a GtkAdjustment already exists for the spin_button,
89 * create the GailAdjustment
91 adjustment = gtk_spin_button_get_adjustment (gtk_spin_button);
94 spin_button->adjustment = gail_adjustment_new (adjustment);
95 g_signal_connect (adjustment,
97 G_CALLBACK (gail_spin_button_value_changed),
101 spin_button->adjustment = NULL;
103 obj->role = ATK_ROLE_SPIN_BUTTON;
108 atk_value_interface_init (AtkValueIface *iface)
110 iface->get_current_value = gail_spin_button_get_current_value;
111 iface->get_maximum_value = gail_spin_button_get_maximum_value;
112 iface->get_minimum_value = gail_spin_button_get_minimum_value;
113 iface->get_minimum_increment = gail_spin_button_get_minimum_increment;
114 iface->set_current_value = gail_spin_button_set_current_value;
118 gail_spin_button_get_current_value (AtkValue *obj,
121 GailSpinButton *spin_button;
123 g_return_if_fail (GAIL_IS_SPIN_BUTTON (obj));
125 spin_button = GAIL_SPIN_BUTTON (obj);
126 if (spin_button->adjustment == NULL)
128 * Adjustment has not been specified
132 atk_value_get_current_value (ATK_VALUE (spin_button->adjustment), value);
136 gail_spin_button_get_maximum_value (AtkValue *obj,
139 GailSpinButton *spin_button;
141 g_return_if_fail (GAIL_IS_SPIN_BUTTON (obj));
143 spin_button = GAIL_SPIN_BUTTON (obj);
144 if (spin_button->adjustment == NULL)
146 * Adjustment has not been specified
150 atk_value_get_maximum_value (ATK_VALUE (spin_button->adjustment), value);
154 gail_spin_button_get_minimum_value (AtkValue *obj,
157 GailSpinButton *spin_button;
159 g_return_if_fail (GAIL_IS_SPIN_BUTTON (obj));
161 spin_button = GAIL_SPIN_BUTTON (obj);
162 if (spin_button->adjustment == NULL)
164 * Adjustment has not been specified
168 atk_value_get_minimum_value (ATK_VALUE (spin_button->adjustment), value);
172 gail_spin_button_get_minimum_increment (AtkValue *obj, GValue *value)
174 GailSpinButton *spin_button;
176 g_return_if_fail (GAIL_IS_SPIN_BUTTON (obj));
178 spin_button = GAIL_SPIN_BUTTON (obj);
179 if (spin_button->adjustment == NULL)
181 * Adjustment has not been specified
185 atk_value_get_minimum_increment (ATK_VALUE (spin_button->adjustment), value);
189 gail_spin_button_set_current_value (AtkValue *obj,
192 GailSpinButton *spin_button;
194 g_return_val_if_fail (GAIL_IS_SPIN_BUTTON (obj), FALSE);
196 spin_button = GAIL_SPIN_BUTTON (obj);
197 if (spin_button->adjustment == NULL)
199 * Adjustment has not been specified
203 return atk_value_set_current_value (ATK_VALUE (spin_button->adjustment), value);
207 gail_spin_button_finalize (GObject *object)
209 GailSpinButton *spin_button = GAIL_SPIN_BUTTON (object);
211 if (spin_button->adjustment)
213 g_object_unref (spin_button->adjustment);
214 spin_button->adjustment = NULL;
216 G_OBJECT_CLASS (gail_spin_button_parent_class)->finalize (object);
221 gail_spin_button_real_notify_gtk (GObject *obj,
224 GtkWidget *widget = GTK_WIDGET (obj);
225 GailSpinButton *spin_button = GAIL_SPIN_BUTTON (gtk_widget_get_accessible (widget));
227 if (strcmp (pspec->name, "adjustment") == 0)
230 * Get rid of the GailAdjustment for the GtkAdjustment
231 * which was associated with the spin_button.
233 GtkAdjustment* adjustment;
234 GtkSpinButton* gtk_spin_button;
236 if (spin_button->adjustment)
238 g_object_unref (spin_button->adjustment);
239 spin_button->adjustment = NULL;
242 * Create the GailAdjustment when notify for "adjustment" property
245 gtk_spin_button = GTK_SPIN_BUTTON (widget);
246 adjustment = gtk_spin_button_get_adjustment (gtk_spin_button);
247 spin_button->adjustment = gail_adjustment_new (adjustment);
248 g_signal_connect (adjustment,
250 G_CALLBACK (gail_spin_button_value_changed),
254 GAIL_WIDGET_CLASS (gail_spin_button_parent_class)->notify_gtk (obj, pspec);
259 gail_spin_button_value_changed (GtkAdjustment *adjustment,
262 GailSpinButton *spin_button;
264 gail_return_if_fail (adjustment != NULL);
265 gail_return_if_fail (data != NULL);
267 spin_button = GAIL_SPIN_BUTTON (data);
269 g_object_notify (G_OBJECT (spin_button), "accessible-value");