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 "gailprogressbar.h"
25 #include "gailadjustment.h"
27 static void gail_progress_bar_class_init (GailProgressBarClass *klass);
28 static void gail_progress_bar_init (GailProgressBar *bar);
29 static void gail_progress_bar_real_initialize (AtkObject *obj,
31 static void gail_progress_bar_finalize (GObject *object);
34 static void atk_value_interface_init (AtkValueIface *iface);
37 static void gail_progress_bar_real_notify_gtk (GObject *obj,
40 static void gail_progress_bar_get_current_value (AtkValue *obj,
42 static void gail_progress_bar_get_maximum_value (AtkValue *obj,
44 static void gail_progress_bar_get_minimum_value (AtkValue *obj,
46 static void gail_progress_bar_value_changed (GtkAdjustment *adjustment,
49 G_DEFINE_TYPE_WITH_CODE (GailProgressBar, gail_progress_bar, GAIL_TYPE_WIDGET,
50 G_IMPLEMENT_INTERFACE (ATK_TYPE_VALUE, atk_value_interface_init))
53 gail_progress_bar_class_init (GailProgressBarClass *klass)
55 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
56 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
57 GailWidgetClass *widget_class;
59 widget_class = (GailWidgetClass*)klass;
61 widget_class->notify_gtk = gail_progress_bar_real_notify_gtk;
63 class->initialize = gail_progress_bar_real_initialize;
65 gobject_class->finalize = gail_progress_bar_finalize;
69 gail_progress_bar_init (GailProgressBar *bar)
74 gail_progress_bar_new (GtkWidget *widget)
77 AtkObject *accessible;
79 g_return_val_if_fail (GTK_IS_PROGRESS_BAR (widget), NULL);
81 object = g_object_new (GAIL_TYPE_PROGRESS_BAR, NULL);
83 accessible = ATK_OBJECT (object);
84 atk_object_initialize (accessible, widget);
90 gail_progress_bar_real_initialize (AtkObject *obj,
93 GailProgressBar *progress_bar = GAIL_PROGRESS_BAR (obj);
94 GtkProgress *gtk_progress;
96 ATK_OBJECT_CLASS (gail_progress_bar_parent_class)->initialize (obj, data);
98 gtk_progress = GTK_PROGRESS (data);
100 * If a GtkAdjustment already exists for the spin_button,
101 * create the GailAdjustment
103 if (gtk_progress->adjustment)
105 progress_bar->adjustment = gail_adjustment_new (gtk_progress->adjustment);
106 g_signal_connect (gtk_progress->adjustment,
108 G_CALLBACK (gail_progress_bar_value_changed),
112 progress_bar->adjustment = NULL;
114 obj->role = ATK_ROLE_PROGRESS_BAR;
118 atk_value_interface_init (AtkValueIface *iface)
120 iface->get_current_value = gail_progress_bar_get_current_value;
121 iface->get_maximum_value = gail_progress_bar_get_maximum_value;
122 iface->get_minimum_value = gail_progress_bar_get_minimum_value;
126 gail_progress_bar_get_current_value (AtkValue *obj,
129 GailProgressBar *progress_bar;
131 g_return_if_fail (GAIL_IS_PROGRESS_BAR (obj));
133 progress_bar = GAIL_PROGRESS_BAR (obj);
134 if (progress_bar->adjustment == NULL)
136 * Adjustment has not been specified
140 atk_value_get_current_value (ATK_VALUE (progress_bar->adjustment), value);
144 gail_progress_bar_get_maximum_value (AtkValue *obj,
147 GailProgressBar *progress_bar;
149 g_return_if_fail (GAIL_IS_PROGRESS_BAR (obj));
151 progress_bar = GAIL_PROGRESS_BAR (obj);
152 if (progress_bar->adjustment == NULL)
154 * Adjustment has not been specified
158 atk_value_get_maximum_value (ATK_VALUE (progress_bar->adjustment), value);
162 gail_progress_bar_get_minimum_value (AtkValue *obj,
165 GailProgressBar *progress_bar;
167 g_return_if_fail (GAIL_IS_PROGRESS_BAR (obj));
169 progress_bar = GAIL_PROGRESS_BAR (obj);
170 if (progress_bar->adjustment == NULL)
172 * Adjustment has not been specified
176 atk_value_get_minimum_value (ATK_VALUE (progress_bar->adjustment), value);
180 gail_progress_bar_finalize (GObject *object)
182 GailProgressBar *progress_bar = GAIL_PROGRESS_BAR (object);
184 if (progress_bar->adjustment)
186 g_object_unref (progress_bar->adjustment);
187 progress_bar->adjustment = NULL;
190 G_OBJECT_CLASS (gail_progress_bar_parent_class)->finalize (object);
195 gail_progress_bar_real_notify_gtk (GObject *obj,
198 GtkWidget *widget = GTK_WIDGET (obj);
199 GailProgressBar *progress_bar = GAIL_PROGRESS_BAR (gtk_widget_get_accessible (widget));
201 if (strcmp (pspec->name, "adjustment") == 0)
204 * Get rid of the GailAdjustment for the GtkAdjustment
205 * which was associated with the progress_bar.
207 if (progress_bar->adjustment)
209 g_object_unref (progress_bar->adjustment);
210 progress_bar->adjustment = NULL;
213 * Create the GailAdjustment when notify for "adjustment" property
216 progress_bar->adjustment = gail_adjustment_new (GTK_PROGRESS (widget)->adjustment);
217 g_signal_connect (GTK_PROGRESS (widget)->adjustment,
219 G_CALLBACK (gail_progress_bar_value_changed),
223 GAIL_WIDGET_CLASS (gail_progress_bar_parent_class)->notify_gtk (obj, pspec);
227 gail_progress_bar_value_changed (GtkAdjustment *adjustment,
230 GailProgressBar *progress_bar;
232 g_return_if_fail (adjustment != NULL);
233 g_return_if_fail (data != NULL);
235 progress_bar = GAIL_PROGRESS_BAR (data);
237 g_object_notify (G_OBJECT (progress_bar), "accessible-value");