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_real_initialize (AtkObject *obj,
77 GailProgressBar *progress_bar = GAIL_PROGRESS_BAR (obj);
78 GtkProgress *gtk_progress;
80 ATK_OBJECT_CLASS (gail_progress_bar_parent_class)->initialize (obj, data);
82 gtk_progress = GTK_PROGRESS (data);
84 * If a GtkAdjustment already exists for the spin_button,
85 * create the GailAdjustment
87 if (gtk_progress->adjustment)
89 progress_bar->adjustment = gail_adjustment_new (gtk_progress->adjustment);
90 g_signal_connect (gtk_progress->adjustment,
92 G_CALLBACK (gail_progress_bar_value_changed),
96 progress_bar->adjustment = NULL;
98 obj->role = ATK_ROLE_PROGRESS_BAR;
102 atk_value_interface_init (AtkValueIface *iface)
104 iface->get_current_value = gail_progress_bar_get_current_value;
105 iface->get_maximum_value = gail_progress_bar_get_maximum_value;
106 iface->get_minimum_value = gail_progress_bar_get_minimum_value;
110 gail_progress_bar_get_current_value (AtkValue *obj,
113 GailProgressBar *progress_bar;
115 g_return_if_fail (GAIL_IS_PROGRESS_BAR (obj));
117 progress_bar = GAIL_PROGRESS_BAR (obj);
118 if (progress_bar->adjustment == NULL)
120 * Adjustment has not been specified
124 atk_value_get_current_value (ATK_VALUE (progress_bar->adjustment), value);
128 gail_progress_bar_get_maximum_value (AtkValue *obj,
131 GailProgressBar *progress_bar;
133 g_return_if_fail (GAIL_IS_PROGRESS_BAR (obj));
135 progress_bar = GAIL_PROGRESS_BAR (obj);
136 if (progress_bar->adjustment == NULL)
138 * Adjustment has not been specified
142 atk_value_get_maximum_value (ATK_VALUE (progress_bar->adjustment), value);
146 gail_progress_bar_get_minimum_value (AtkValue *obj,
149 GailProgressBar *progress_bar;
151 g_return_if_fail (GAIL_IS_PROGRESS_BAR (obj));
153 progress_bar = GAIL_PROGRESS_BAR (obj);
154 if (progress_bar->adjustment == NULL)
156 * Adjustment has not been specified
160 atk_value_get_minimum_value (ATK_VALUE (progress_bar->adjustment), value);
164 gail_progress_bar_finalize (GObject *object)
166 GailProgressBar *progress_bar = GAIL_PROGRESS_BAR (object);
168 if (progress_bar->adjustment)
170 g_object_unref (progress_bar->adjustment);
171 progress_bar->adjustment = NULL;
174 G_OBJECT_CLASS (gail_progress_bar_parent_class)->finalize (object);
179 gail_progress_bar_real_notify_gtk (GObject *obj,
182 GtkWidget *widget = GTK_WIDGET (obj);
183 GailProgressBar *progress_bar = GAIL_PROGRESS_BAR (gtk_widget_get_accessible (widget));
185 if (strcmp (pspec->name, "adjustment") == 0)
188 * Get rid of the GailAdjustment for the GtkAdjustment
189 * which was associated with the progress_bar.
191 if (progress_bar->adjustment)
193 g_object_unref (progress_bar->adjustment);
194 progress_bar->adjustment = NULL;
197 * Create the GailAdjustment when notify for "adjustment" property
200 progress_bar->adjustment = gail_adjustment_new (GTK_PROGRESS (widget)->adjustment);
201 g_signal_connect (GTK_PROGRESS (widget)->adjustment,
203 G_CALLBACK (gail_progress_bar_value_changed),
207 GAIL_WIDGET_CLASS (gail_progress_bar_parent_class)->notify_gtk (obj, pspec);
211 gail_progress_bar_value_changed (GtkAdjustment *adjustment,
214 GailProgressBar *progress_bar;
216 g_return_if_fail (adjustment != NULL);
217 g_return_if_fail (data != NULL);
219 progress_bar = GAIL_PROGRESS_BAR (data);
221 g_object_notify (G_OBJECT (progress_bar), "accessible-value");