]> Pileus Git - ~andy/gtk/blob - modules/other/gail/gailprogressbar.c
Include <config.h>. Bug #504720.
[~andy/gtk] / modules / other / gail / gailprogressbar.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 "gailprogressbar.h"
25 #include "gailadjustment.h"
26
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,
30                                                       gpointer       data);
31 static void      gail_progress_bar_finalize          (GObject        *object);
32
33
34 static void      atk_value_interface_init            (AtkValueIface  *iface);
35
36
37 static void      gail_progress_bar_real_notify_gtk   (GObject        *obj,
38                                                       GParamSpec     *pspec);
39
40 static void      gail_progress_bar_get_current_value (AtkValue       *obj,
41                                                       GValue         *value);
42 static void      gail_progress_bar_get_maximum_value (AtkValue       *obj,
43                                                       GValue         *value);
44 static void      gail_progress_bar_get_minimum_value (AtkValue       *obj,
45                                                       GValue         *value);
46 static void      gail_progress_bar_value_changed     (GtkAdjustment  *adjustment,
47                                                       gpointer       data);
48
49 G_DEFINE_TYPE_WITH_CODE (GailProgressBar, gail_progress_bar, GAIL_TYPE_WIDGET,
50                          G_IMPLEMENT_INTERFACE (ATK_TYPE_VALUE, atk_value_interface_init))
51
52 static void      
53 gail_progress_bar_class_init            (GailProgressBarClass *klass)
54 {
55   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
56   AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
57   GailWidgetClass *widget_class;
58
59   widget_class = (GailWidgetClass*)klass;
60
61   widget_class->notify_gtk = gail_progress_bar_real_notify_gtk;
62
63   class->initialize = gail_progress_bar_real_initialize;
64
65   gobject_class->finalize = gail_progress_bar_finalize;
66 }
67
68 static void
69 gail_progress_bar_init (GailProgressBar *bar)
70 {
71 }
72
73 AtkObject* 
74 gail_progress_bar_new (GtkWidget *widget)
75 {
76   GObject *object;
77   AtkObject *accessible;
78
79   g_return_val_if_fail (GTK_IS_PROGRESS_BAR (widget), NULL);
80
81   object = g_object_new (GAIL_TYPE_PROGRESS_BAR, NULL);
82
83   accessible = ATK_OBJECT (object);
84   atk_object_initialize (accessible, widget);
85
86   return accessible;
87 }
88
89 static void
90 gail_progress_bar_real_initialize (AtkObject *obj,
91                                    gpointer  data)
92 {
93   GailProgressBar *progress_bar = GAIL_PROGRESS_BAR (obj);
94   GtkProgress *gtk_progress;
95
96   ATK_OBJECT_CLASS (gail_progress_bar_parent_class)->initialize (obj, data);
97
98   gtk_progress = GTK_PROGRESS (data);
99   /*
100    * If a GtkAdjustment already exists for the spin_button,
101    * create the GailAdjustment
102    */
103   if (gtk_progress->adjustment)
104     {
105       progress_bar->adjustment = gail_adjustment_new (gtk_progress->adjustment);
106       g_signal_connect (gtk_progress->adjustment,
107                         "value-changed",
108                         G_CALLBACK (gail_progress_bar_value_changed),
109                         obj);
110     }
111   else
112     progress_bar->adjustment = NULL;
113
114   obj->role = ATK_ROLE_PROGRESS_BAR;
115 }
116
117 static void      
118 atk_value_interface_init (AtkValueIface *iface)
119 {
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;
123 }
124
125 static void      
126 gail_progress_bar_get_current_value (AtkValue   *obj,
127                                      GValue     *value)
128 {
129   GailProgressBar *progress_bar;
130
131   g_return_if_fail (GAIL_IS_PROGRESS_BAR (obj));
132
133   progress_bar = GAIL_PROGRESS_BAR (obj);
134   if (progress_bar->adjustment == NULL)
135     /*
136      * Adjustment has not been specified
137      */
138     return;
139
140   atk_value_get_current_value (ATK_VALUE (progress_bar->adjustment), value);
141 }
142
143 static void      
144 gail_progress_bar_get_maximum_value (AtkValue   *obj,
145                                      GValue     *value)
146 {
147   GailProgressBar *progress_bar;
148
149   g_return_if_fail (GAIL_IS_PROGRESS_BAR (obj));
150
151   progress_bar = GAIL_PROGRESS_BAR (obj);
152   if (progress_bar->adjustment == NULL)
153     /*
154      * Adjustment has not been specified
155      */
156     return;
157
158   atk_value_get_maximum_value (ATK_VALUE (progress_bar->adjustment), value);
159 }
160
161 static void      
162 gail_progress_bar_get_minimum_value (AtkValue    *obj,
163                                      GValue      *value)
164 {
165   GailProgressBar *progress_bar;
166
167   g_return_if_fail (GAIL_IS_PROGRESS_BAR (obj));
168
169   progress_bar = GAIL_PROGRESS_BAR (obj);
170   if (progress_bar->adjustment == NULL)
171     /*
172      * Adjustment has not been specified
173      */
174     return;
175
176   atk_value_get_minimum_value (ATK_VALUE (progress_bar->adjustment), value);
177 }
178
179 static void
180 gail_progress_bar_finalize (GObject            *object)
181 {
182   GailProgressBar *progress_bar = GAIL_PROGRESS_BAR (object);
183
184   if (progress_bar->adjustment)
185     {
186       g_object_unref (progress_bar->adjustment);
187       progress_bar->adjustment = NULL;
188     }
189
190   G_OBJECT_CLASS (gail_progress_bar_parent_class)->finalize (object);
191 }
192
193
194 static void
195 gail_progress_bar_real_notify_gtk (GObject           *obj,
196                                    GParamSpec        *pspec)
197 {
198   GtkWidget *widget = GTK_WIDGET (obj);
199   GailProgressBar *progress_bar = GAIL_PROGRESS_BAR (gtk_widget_get_accessible (widget));
200
201   if (strcmp (pspec->name, "adjustment") == 0)
202     {
203       /*
204        * Get rid of the GailAdjustment for the GtkAdjustment
205        * which was associated with the progress_bar.
206        */
207       if (progress_bar->adjustment)
208         {
209           g_object_unref (progress_bar->adjustment);
210           progress_bar->adjustment = NULL;
211         }
212       /*
213        * Create the GailAdjustment when notify for "adjustment" property
214        * is received
215        */
216       progress_bar->adjustment = gail_adjustment_new (GTK_PROGRESS (widget)->adjustment);
217       g_signal_connect (GTK_PROGRESS (widget)->adjustment,
218                         "value-changed",
219                         G_CALLBACK (gail_progress_bar_value_changed),
220                         progress_bar);
221     }
222   else
223     GAIL_WIDGET_CLASS (gail_progress_bar_parent_class)->notify_gtk (obj, pspec);
224 }
225
226 static void
227 gail_progress_bar_value_changed (GtkAdjustment    *adjustment,
228                                  gpointer         data)
229 {
230   GailProgressBar *progress_bar;
231
232   g_return_if_fail (adjustment != NULL);
233   g_return_if_fail (data != NULL);
234
235   progress_bar = GAIL_PROGRESS_BAR (data);
236
237   g_object_notify (G_OBJECT (progress_bar), "accessible-value");
238 }