]> Pileus Git - ~andy/gtk/blob - modules/other/gail/gailprogressbar.c
Remove relocations from the atk factories. Remove unused gail_foo_new()
[~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 static void
74 gail_progress_bar_real_initialize (AtkObject *obj,
75                                    gpointer  data)
76 {
77   GailProgressBar *progress_bar = GAIL_PROGRESS_BAR (obj);
78   GtkProgress *gtk_progress;
79
80   ATK_OBJECT_CLASS (gail_progress_bar_parent_class)->initialize (obj, data);
81
82   gtk_progress = GTK_PROGRESS (data);
83   /*
84    * If a GtkAdjustment already exists for the spin_button,
85    * create the GailAdjustment
86    */
87   if (gtk_progress->adjustment)
88     {
89       progress_bar->adjustment = gail_adjustment_new (gtk_progress->adjustment);
90       g_signal_connect (gtk_progress->adjustment,
91                         "value-changed",
92                         G_CALLBACK (gail_progress_bar_value_changed),
93                         obj);
94     }
95   else
96     progress_bar->adjustment = NULL;
97
98   obj->role = ATK_ROLE_PROGRESS_BAR;
99 }
100
101 static void      
102 atk_value_interface_init (AtkValueIface *iface)
103 {
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;
107 }
108
109 static void      
110 gail_progress_bar_get_current_value (AtkValue   *obj,
111                                      GValue     *value)
112 {
113   GailProgressBar *progress_bar;
114
115   g_return_if_fail (GAIL_IS_PROGRESS_BAR (obj));
116
117   progress_bar = GAIL_PROGRESS_BAR (obj);
118   if (progress_bar->adjustment == NULL)
119     /*
120      * Adjustment has not been specified
121      */
122     return;
123
124   atk_value_get_current_value (ATK_VALUE (progress_bar->adjustment), value);
125 }
126
127 static void      
128 gail_progress_bar_get_maximum_value (AtkValue   *obj,
129                                      GValue     *value)
130 {
131   GailProgressBar *progress_bar;
132
133   g_return_if_fail (GAIL_IS_PROGRESS_BAR (obj));
134
135   progress_bar = GAIL_PROGRESS_BAR (obj);
136   if (progress_bar->adjustment == NULL)
137     /*
138      * Adjustment has not been specified
139      */
140     return;
141
142   atk_value_get_maximum_value (ATK_VALUE (progress_bar->adjustment), value);
143 }
144
145 static void      
146 gail_progress_bar_get_minimum_value (AtkValue    *obj,
147                                      GValue      *value)
148 {
149   GailProgressBar *progress_bar;
150
151   g_return_if_fail (GAIL_IS_PROGRESS_BAR (obj));
152
153   progress_bar = GAIL_PROGRESS_BAR (obj);
154   if (progress_bar->adjustment == NULL)
155     /*
156      * Adjustment has not been specified
157      */
158     return;
159
160   atk_value_get_minimum_value (ATK_VALUE (progress_bar->adjustment), value);
161 }
162
163 static void
164 gail_progress_bar_finalize (GObject            *object)
165 {
166   GailProgressBar *progress_bar = GAIL_PROGRESS_BAR (object);
167
168   if (progress_bar->adjustment)
169     {
170       g_object_unref (progress_bar->adjustment);
171       progress_bar->adjustment = NULL;
172     }
173
174   G_OBJECT_CLASS (gail_progress_bar_parent_class)->finalize (object);
175 }
176
177
178 static void
179 gail_progress_bar_real_notify_gtk (GObject           *obj,
180                                    GParamSpec        *pspec)
181 {
182   GtkWidget *widget = GTK_WIDGET (obj);
183   GailProgressBar *progress_bar = GAIL_PROGRESS_BAR (gtk_widget_get_accessible (widget));
184
185   if (strcmp (pspec->name, "adjustment") == 0)
186     {
187       /*
188        * Get rid of the GailAdjustment for the GtkAdjustment
189        * which was associated with the progress_bar.
190        */
191       if (progress_bar->adjustment)
192         {
193           g_object_unref (progress_bar->adjustment);
194           progress_bar->adjustment = NULL;
195         }
196       /*
197        * Create the GailAdjustment when notify for "adjustment" property
198        * is received
199        */
200       progress_bar->adjustment = gail_adjustment_new (GTK_PROGRESS (widget)->adjustment);
201       g_signal_connect (GTK_PROGRESS (widget)->adjustment,
202                         "value-changed",
203                         G_CALLBACK (gail_progress_bar_value_changed),
204                         progress_bar);
205     }
206   else
207     GAIL_WIDGET_CLASS (gail_progress_bar_parent_class)->notify_gtk (obj, pspec);
208 }
209
210 static void
211 gail_progress_bar_value_changed (GtkAdjustment    *adjustment,
212                                  gpointer         data)
213 {
214   GailProgressBar *progress_bar;
215
216   g_return_if_fail (adjustment != NULL);
217   g_return_if_fail (data != NULL);
218
219   progress_bar = GAIL_PROGRESS_BAR (data);
220
221   g_object_notify (G_OBJECT (progress_bar), "accessible-value");
222 }