1 /* GAIL - The GNOME Accessibility Implementation Library
2 * Copyright 2008 Jan Arne Petersen
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.
23 #include "gailscalebutton.h"
24 #include "gailadjustment.h"
25 #include "gail-private-macros.h"
29 static void gail_scale_button_class_init (GailScaleButtonClass *klass);
30 static void gail_scale_button_init (GailScaleButton *button);
33 static void gail_scale_button_real_notify_gtk (GObject *obj,
37 static void gail_scale_button_real_initialize (AtkObject *obj,
41 static void atk_action_interface_init (AtkActionIface *iface);
42 static gboolean gail_scale_button_do_action (AtkAction *action,
44 static gint gail_scale_button_get_n_actions (AtkAction *action);
45 static const gchar* gail_scale_button_get_description(AtkAction *action,
47 static const gchar* gail_scale_button_action_get_name(AtkAction *action,
49 static const gchar* gail_scale_button_get_keybinding (AtkAction *action,
51 static gboolean gail_scale_button_set_description(AtkAction *action,
56 static void atk_value_interface_init (AtkValueIface *iface);
57 static void gail_scale_button_get_current_value (AtkValue *obj,
59 static void gail_scale_button_get_maximum_value (AtkValue *obj,
61 static void gail_scale_button_get_minimum_value (AtkValue *obj,
63 static void gail_scale_button_get_minimum_increment (AtkValue *obj,
65 static gboolean gail_scale_button_set_current_value (AtkValue *obj,
67 static void gail_scale_button_value_changed (GtkAdjustment *adjustment,
70 G_DEFINE_TYPE_WITH_CODE (GailScaleButton, gail_scale_button, GAIL_TYPE_BUTTON,
71 G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_interface_init)
72 G_IMPLEMENT_INTERFACE (ATK_TYPE_VALUE, atk_value_interface_init));
75 gail_scale_button_class_init (GailScaleButtonClass *klass)
77 AtkObjectClass *atk_object_class = ATK_OBJECT_CLASS (klass);
78 GailWidgetClass *widget_class = GAIL_WIDGET_CLASS (klass);
80 atk_object_class->initialize = gail_scale_button_real_initialize;
82 widget_class->notify_gtk = gail_scale_button_real_notify_gtk;
86 gail_scale_button_init (GailScaleButton *button)
91 gail_scale_button_real_initialize (AtkObject *obj,
94 GailScaleButton *scale_button = GAIL_SCALE_BUTTON (obj);
95 GtkScaleButton *gtk_scale_button;
96 GtkAdjustment *gtk_adjustment;
98 ATK_OBJECT_CLASS (gail_scale_button_parent_class)->initialize (obj, data);
100 gtk_scale_button = GTK_SCALE_BUTTON (data);
101 gtk_adjustment = gtk_scale_button_get_adjustment (gtk_scale_button);
103 * If a GtkAdjustment already exists for the scale_button,
104 * create the GailAdjustment
108 scale_button->adjustment = gail_adjustment_new (gtk_adjustment);
109 g_signal_connect (gtk_adjustment,
111 G_CALLBACK (gail_scale_button_value_changed),
115 scale_button->adjustment = NULL;
117 obj->role = ATK_ROLE_SLIDER;
121 atk_action_interface_init (AtkActionIface *iface)
123 iface->do_action = gail_scale_button_do_action;
124 iface->get_n_actions = gail_scale_button_get_n_actions;
125 iface->get_description = gail_scale_button_get_description;
126 iface->get_keybinding = gail_scale_button_get_keybinding;
127 iface->get_name = gail_scale_button_action_get_name;
128 iface->set_description = gail_scale_button_set_description;
132 gail_scale_button_do_action(AtkAction *action,
137 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (action));
141 if (!gtk_widget_is_sensitive (widget) || !gtk_widget_get_visible (widget))
146 g_signal_emit_by_name (widget, "popup");
149 g_signal_emit_by_name (widget, "podown");
157 gail_scale_button_get_n_actions (AtkAction *action)
163 gail_scale_button_get_description (AtkAction *action,
170 gail_scale_button_action_get_name (AtkAction *action,
184 gail_scale_button_get_keybinding (AtkAction *action,
191 gail_scale_button_set_description (AtkAction *action,
200 atk_value_interface_init (AtkValueIface *iface)
202 iface->get_current_value = gail_scale_button_get_current_value;
203 iface->get_maximum_value = gail_scale_button_get_maximum_value;
204 iface->get_minimum_value = gail_scale_button_get_minimum_value;
205 iface->get_minimum_increment = gail_scale_button_get_minimum_increment;
206 iface->set_current_value = gail_scale_button_set_current_value;
210 gail_scale_button_get_current_value (AtkValue *obj,
213 GailScaleButton *scale_button;
215 g_return_if_fail (GAIL_IS_SCALE_BUTTON (obj));
217 scale_button = GAIL_SCALE_BUTTON (obj);
218 if (scale_button->adjustment == NULL)
220 * Adjustment has not been specified
224 atk_value_get_current_value (ATK_VALUE (scale_button->adjustment), value);
228 gail_scale_button_get_maximum_value (AtkValue *obj,
231 GailScaleButton *scale_button;
233 g_return_if_fail (GAIL_IS_SCALE_BUTTON (obj));
235 scale_button = GAIL_SCALE_BUTTON (obj);
236 if (scale_button->adjustment == NULL)
238 * Adjustment has not been specified
242 atk_value_get_maximum_value (ATK_VALUE (scale_button->adjustment), value);
246 gail_scale_button_get_minimum_value (AtkValue *obj,
249 GailScaleButton *scale_button;
251 g_return_if_fail (GAIL_IS_SCALE_BUTTON (obj));
253 scale_button = GAIL_SCALE_BUTTON (obj);
254 if (scale_button->adjustment == NULL)
256 * Adjustment has not been specified
260 atk_value_get_minimum_value (ATK_VALUE (scale_button->adjustment), value);
264 gail_scale_button_get_minimum_increment (AtkValue *obj,
267 GailScaleButton *scale_button;
269 g_return_if_fail (GAIL_IS_SCALE_BUTTON (obj));
271 scale_button = GAIL_SCALE_BUTTON (obj);
272 if (scale_button->adjustment == NULL)
274 * Adjustment has not been specified
278 atk_value_get_minimum_increment (ATK_VALUE (scale_button->adjustment), value);
282 gail_scale_button_set_current_value (AtkValue *obj,
285 GailScaleButton *scale_button;
287 g_return_val_if_fail (GAIL_IS_SCALE_BUTTON (obj), FALSE);
289 scale_button = GAIL_SCALE_BUTTON (obj);
290 if (scale_button->adjustment == NULL)
292 * Adjustment has not been specified
296 return atk_value_set_current_value (ATK_VALUE (scale_button->adjustment), value);
300 gail_scale_button_real_notify_gtk (GObject *obj,
303 GtkScaleButton *gtk_scale_button;
304 GailScaleButton *scale_button;
306 g_return_if_fail (GTK_IS_SCALE_BUTTON (obj));
308 gtk_scale_button = GTK_SCALE_BUTTON (obj);
309 scale_button = GAIL_SCALE_BUTTON (gtk_widget_get_accessible (GTK_WIDGET (gtk_scale_button)));
311 if (strcmp (pspec->name, "adjustment") == 0)
314 * Get rid of the GailAdjustment for the GtkAdjustment
315 * which was associated with the scale_button.
317 GtkAdjustment* gtk_adjustment;
319 if (scale_button->adjustment)
321 g_object_unref (scale_button->adjustment);
322 scale_button->adjustment = NULL;
325 * Create the GailAdjustment when notify for "adjustment" property
328 gtk_adjustment = gtk_scale_button_get_adjustment (gtk_scale_button);
329 scale_button->adjustment = gail_adjustment_new (gtk_adjustment);
330 g_signal_connect (gtk_adjustment,
332 G_CALLBACK (gail_scale_button_value_changed),
337 GAIL_WIDGET_CLASS (gail_scale_button_parent_class)->notify_gtk (obj, pspec);
342 gail_scale_button_value_changed (GtkAdjustment *adjustment,
345 GailScaleButton *scale_button;
347 gail_return_if_fail (adjustment != NULL);
348 gail_return_if_fail (data != NULL);
350 scale_button = GAIL_SCALE_BUTTON (data);
352 g_object_notify (G_OBJECT (scale_button), "accessible-value");