| 1 |
/* GTK+ - accessibility implementations |
| 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, see <http://www.gnu.org/licenses/>. |
| 16 |
*/ |
| 17 |
|
| 18 |
#include "config.h" |
| 19 |
|
| 20 |
#include <string.h> |
| 21 |
#include <gtk/gtk.h> |
| 22 |
#include "gtkrangeaccessible.h" |
| 23 |
|
| 24 |
struct _GtkRangeAccessiblePrivate |
| 25 |
{ |
| 26 |
GtkAdjustment *adjustment; |
| 27 |
}; |
| 28 |
|
| 29 |
static void atk_value_interface_init (AtkValueIface *iface); |
| 30 |
|
| 31 |
G_DEFINE_TYPE_WITH_CODE (GtkRangeAccessible, gtk_range_accessible, GTK_TYPE_WIDGET_ACCESSIBLE, |
| 32 |
G_ADD_PRIVATE (GtkRangeAccessible) |
| 33 |
G_IMPLEMENT_INTERFACE (ATK_TYPE_VALUE, atk_value_interface_init)) |
| 34 |
|
| 35 |
static void |
| 36 |
gtk_range_accessible_value_changed (GtkAdjustment *adjustment, |
| 37 |
gpointer data) |
| 38 |
{ |
| 39 |
g_object_notify (G_OBJECT (data), "accessible-value"); |
| 40 |
} |
| 41 |
|
| 42 |
static void |
| 43 |
gtk_range_accessible_widget_set (GtkAccessible *accessible) |
| 44 |
{ |
| 45 |
GtkRangeAccessiblePrivate *priv = GTK_RANGE_ACCESSIBLE (accessible)->priv; |
| 46 |
GtkWidget *range; |
| 47 |
GtkAdjustment *adj; |
| 48 |
|
| 49 |
range = gtk_accessible_get_widget (accessible); |
| 50 |
adj = gtk_range_get_adjustment (GTK_RANGE (range)); |
| 51 |
if (adj) |
| 52 |
{ |
| 53 |
priv->adjustment = adj; |
| 54 |
g_object_ref (priv->adjustment); |
| 55 |
g_signal_connect (priv->adjustment, "value-changed", |
| 56 |
G_CALLBACK (gtk_range_accessible_value_changed), |
| 57 |
accessible); |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
static void |
| 62 |
gtk_range_accessible_widget_unset (GtkAccessible *accessible) |
| 63 |
{ |
| 64 |
GtkRangeAccessiblePrivate *priv = GTK_RANGE_ACCESSIBLE (accessible)->priv; |
| 65 |
|
| 66 |
if (priv->adjustment) |
| 67 |
{ |
| 68 |
g_signal_handlers_disconnect_by_func (priv->adjustment, |
| 69 |
G_CALLBACK (gtk_range_accessible_value_changed), |
| 70 |
accessible); |
| 71 |
g_object_unref (priv->adjustment); |
| 72 |
priv->adjustment = NULL; |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
static void |
| 77 |
gtk_range_accessible_initialize (AtkObject *obj, |
| 78 |
gpointer data) |
| 79 |
{ |
| 80 |
ATK_OBJECT_CLASS (gtk_range_accessible_parent_class)->initialize (obj, data); |
| 81 |
obj->role = ATK_ROLE_SLIDER; |
| 82 |
} |
| 83 |
|
| 84 |
static void |
| 85 |
gtk_range_accessible_notify_gtk (GObject *obj, |
| 86 |
GParamSpec *pspec) |
| 87 |
{ |
| 88 |
GtkWidget *widget = GTK_WIDGET (obj); |
| 89 |
AtkObject *range; |
| 90 |
|
| 91 |
if (strcmp (pspec->name, "adjustment") == 0) |
| 92 |
{ |
| 93 |
range = gtk_widget_get_accessible (widget); |
| 94 |
gtk_range_accessible_widget_unset (GTK_ACCESSIBLE (range)); |
| 95 |
gtk_range_accessible_widget_set (GTK_ACCESSIBLE (range)); |
| 96 |
} |
| 97 |
else |
| 98 |
GTK_WIDGET_ACCESSIBLE_CLASS (gtk_range_accessible_parent_class)->notify_gtk (obj, pspec); |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
static void |
| 103 |
gtk_range_accessible_class_init (GtkRangeAccessibleClass *klass) |
| 104 |
{ |
| 105 |
AtkObjectClass *class = ATK_OBJECT_CLASS (klass); |
| 106 |
GtkAccessibleClass *accessible_class = (GtkAccessibleClass*)klass; |
| 107 |
GtkWidgetAccessibleClass *widget_class = (GtkWidgetAccessibleClass*)klass; |
| 108 |
|
| 109 |
class->initialize = gtk_range_accessible_initialize; |
| 110 |
|
| 111 |
accessible_class->widget_set = gtk_range_accessible_widget_set; |
| 112 |
accessible_class->widget_unset = gtk_range_accessible_widget_unset; |
| 113 |
|
| 114 |
widget_class->notify_gtk = gtk_range_accessible_notify_gtk; |
| 115 |
} |
| 116 |
|
| 117 |
static void |
| 118 |
gtk_range_accessible_init (GtkRangeAccessible *range) |
| 119 |
{ |
| 120 |
range->priv = gtk_range_accessible_get_instance_private (range); |
| 121 |
} |
| 122 |
|
| 123 |
static void |
| 124 |
gtk_range_accessible_get_current_value (AtkValue *obj, |
| 125 |
GValue *value) |
| 126 |
{ |
| 127 |
GtkWidget *widget; |
| 128 |
GtkAdjustment *adjustment; |
| 129 |
|
| 130 |
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj)); |
| 131 |
adjustment = gtk_range_get_adjustment (GTK_RANGE (widget)); |
| 132 |
if (adjustment == NULL) |
| 133 |
return; |
| 134 |
|
| 135 |
memset (value, 0, sizeof (GValue)); |
| 136 |
g_value_init (value, G_TYPE_DOUBLE); |
| 137 |
g_value_set_double (value, gtk_adjustment_get_value (adjustment)); |
| 138 |
} |
| 139 |
|
| 140 |
static void |
| 141 |
gtk_range_accessible_get_maximum_value (AtkValue *obj, |
| 142 |
GValue *value) |
| 143 |
{ |
| 144 |
GtkWidget *widget; |
| 145 |
GtkAdjustment *adjustment; |
| 146 |
gdouble max; |
| 147 |
|
| 148 |
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj)); |
| 149 |
adjustment = gtk_range_get_adjustment (GTK_RANGE (widget)); |
| 150 |
if (adjustment == NULL) |
| 151 |
return; |
| 152 |
|
| 153 |
max = gtk_adjustment_get_upper (adjustment) |
| 154 |
- gtk_adjustment_get_page_size (adjustment); |
| 155 |
|
| 156 |
if (gtk_range_get_restrict_to_fill_level (GTK_RANGE (widget))) |
| 157 |
max = MIN (max, gtk_range_get_fill_level (GTK_RANGE (widget))); |
| 158 |
|
| 159 |
memset (value, 0, sizeof (GValue)); |
| 160 |
g_value_init (value, G_TYPE_DOUBLE); |
| 161 |
g_value_set_double (value, max); |
| 162 |
} |
| 163 |
|
| 164 |
static void |
| 165 |
gtk_range_accessible_get_minimum_value (AtkValue *obj, |
| 166 |
GValue *value) |
| 167 |
{ |
| 168 |
GtkWidget *widget; |
| 169 |
GtkAdjustment *adjustment; |
| 170 |
|
| 171 |
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj)); |
| 172 |
adjustment = gtk_range_get_adjustment (GTK_RANGE (widget)); |
| 173 |
if (adjustment == NULL) |
| 174 |
return; |
| 175 |
|
| 176 |
memset (value, 0, sizeof (GValue)); |
| 177 |
g_value_init (value, G_TYPE_DOUBLE); |
| 178 |
g_value_set_double (value, gtk_adjustment_get_lower (adjustment)); |
| 179 |
} |
| 180 |
|
| 181 |
static void |
| 182 |
gtk_range_accessible_get_minimum_increment (AtkValue *obj, |
| 183 |
GValue *value) |
| 184 |
{ |
| 185 |
GtkWidget *widget; |
| 186 |
GtkAdjustment *adjustment; |
| 187 |
|
| 188 |
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj)); |
| 189 |
adjustment = gtk_range_get_adjustment (GTK_RANGE (widget)); |
| 190 |
if (adjustment == NULL) |
| 191 |
return; |
| 192 |
|
| 193 |
memset (value, 0, sizeof (GValue)); |
| 194 |
g_value_init (value, G_TYPE_DOUBLE); |
| 195 |
g_value_set_double (value, gtk_adjustment_get_minimum_increment (adjustment)); |
| 196 |
} |
| 197 |
|
| 198 |
static gboolean |
| 199 |
gtk_range_accessible_set_current_value (AtkValue *obj, |
| 200 |
const GValue *value) |
| 201 |
{ |
| 202 |
GtkWidget *widget; |
| 203 |
GtkAdjustment *adjustment; |
| 204 |
|
| 205 |
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj)); |
| 206 |
adjustment = gtk_range_get_adjustment (GTK_RANGE (widget)); |
| 207 |
if (adjustment == NULL) |
| 208 |
return FALSE; |
| 209 |
|
| 210 |
gtk_adjustment_set_value (adjustment, g_value_get_double (value)); |
| 211 |
|
| 212 |
return TRUE; |
| 213 |
} |
| 214 |
|
| 215 |
static void |
| 216 |
gtk_range_accessible_get_value_and_text (AtkValue *obj, |
| 217 |
gdouble *value, |
| 218 |
gchar **text) |
| 219 |
{ |
| 220 |
GtkWidget *widget; |
| 221 |
GtkAdjustment *adjustment; |
| 222 |
|
| 223 |
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj)); |
| 224 |
adjustment = gtk_range_get_adjustment (GTK_RANGE (widget)); |
| 225 |
if (adjustment == NULL) |
| 226 |
return; |
| 227 |
|
| 228 |
*value = gtk_adjustment_get_value (adjustment); |
| 229 |
*text = NULL; |
| 230 |
} |
| 231 |
|
| 232 |
static AtkRange * |
| 233 |
gtk_range_accessible_get_range (AtkValue *obj) |
| 234 |
{ |
| 235 |
GtkWidget *widget; |
| 236 |
GtkAdjustment *adjustment; |
| 237 |
gdouble min, max; |
| 238 |
|
| 239 |
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj)); |
| 240 |
adjustment = gtk_range_get_adjustment (GTK_RANGE (widget)); |
| 241 |
if (adjustment == NULL) |
| 242 |
return NULL; |
| 243 |
|
| 244 |
min = gtk_adjustment_get_lower (adjustment); |
| 245 |
max = gtk_adjustment_get_upper (adjustment) |
| 246 |
- gtk_adjustment_get_page_size (adjustment); |
| 247 |
|
| 248 |
if (gtk_range_get_restrict_to_fill_level (GTK_RANGE (widget))) |
| 249 |
max = MIN (max, gtk_range_get_fill_level (GTK_RANGE (widget))); |
| 250 |
|
| 251 |
return atk_range_new (min, max, NULL); |
| 252 |
} |
| 253 |
|
| 254 |
static void |
| 255 |
gtk_range_accessible_set_value (AtkValue *obj, |
| 256 |
const gdouble value) |
| 257 |
{ |
| 258 |
GtkWidget *widget; |
| 259 |
GtkAdjustment *adjustment; |
| 260 |
|
| 261 |
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj)); |
| 262 |
adjustment = gtk_range_get_adjustment (GTK_RANGE (widget)); |
| 263 |
if (adjustment == NULL) |
| 264 |
return; |
| 265 |
|
| 266 |
gtk_adjustment_set_value (adjustment, value); |
| 267 |
} |
| 268 |
|
| 269 |
static gdouble |
| 270 |
gtk_range_accessible_get_increment (AtkValue *obj) |
| 271 |
{ |
| 272 |
GtkWidget *widget; |
| 273 |
GtkAdjustment *adjustment; |
| 274 |
|
| 275 |
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj)); |
| 276 |
adjustment = gtk_range_get_adjustment (GTK_RANGE (widget)); |
| 277 |
if (adjustment == NULL) |
| 278 |
return 0; |
| 279 |
|
| 280 |
return gtk_adjustment_get_minimum_increment (adjustment); |
| 281 |
} |
| 282 |
|
| 283 |
static void |
| 284 |
atk_value_interface_init (AtkValueIface *iface) |
| 285 |
{ |
| 286 |
iface->get_current_value = gtk_range_accessible_get_current_value; |
| 287 |
iface->get_maximum_value = gtk_range_accessible_get_maximum_value; |
| 288 |
iface->get_minimum_value = gtk_range_accessible_get_minimum_value; |
| 289 |
iface->get_minimum_increment = gtk_range_accessible_get_minimum_increment; |
| 290 |
iface->set_current_value = gtk_range_accessible_set_current_value; |
| 291 |
|
| 292 |
iface->get_value_and_text = gtk_range_accessible_get_value_and_text; |
| 293 |
iface->get_range = gtk_range_accessible_get_range; |
| 294 |
iface->set_value = gtk_range_accessible_set_value; |
| 295 |
iface->get_increment = gtk_range_accessible_get_increment; |
| 296 |
} |