Debian Codegraph @

gtk/a11y/gtkscalebuttonaccessible.c

raw
1 /* GTK+ - accessibility implementations
2 * Copyright 2008 Jan Arne Petersen
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 <glib/gi18n-lib.h>
21 #include <gtk/gtk.h>
22 #include "gtkscalebuttonaccessible.h"
23
24 #include <string.h>
25
26
27 static void atk_action_interface_init (AtkActionIface *iface);
28 static void atk_value_interface_init (AtkValueIface *iface);
29
30 G_DEFINE_TYPE_WITH_CODE (GtkScaleButtonAccessible, gtk_scale_button_accessible, GTK_TYPE_BUTTON_ACCESSIBLE,
31 G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_interface_init)
32 G_IMPLEMENT_INTERFACE (ATK_TYPE_VALUE, atk_value_interface_init));
33
34 static void
35 gtk_scale_button_accessible_value_changed (GtkAdjustment *adjustment,
36 gpointer data)
37 {
38 g_object_notify (G_OBJECT (data), "accessible-value");
39 }
40
41 static void
42 gtk_scale_button_accessible_initialize (AtkObject *obj,
43 gpointer data)
44 {
45 GtkAdjustment *adjustment;
46
47 ATK_OBJECT_CLASS (gtk_scale_button_accessible_parent_class)->initialize (obj, data);
48
49 adjustment = gtk_scale_button_get_adjustment (GTK_SCALE_BUTTON (data));
50 if (adjustment)
51 g_signal_connect (adjustment,
52 "value-changed",
53 G_CALLBACK (gtk_scale_button_accessible_value_changed),
54 obj);
55
56 obj->role = ATK_ROLE_SLIDER;
57 }
58
59 static void
60 gtk_scale_button_accessible_notify_gtk (GObject *obj,
61 GParamSpec *pspec)
62 {
63 GtkScaleButton *scale_button;
64 GtkScaleButtonAccessible *accessible;
65
66 scale_button = GTK_SCALE_BUTTON (obj);
67 accessible = GTK_SCALE_BUTTON_ACCESSIBLE (gtk_widget_get_accessible (GTK_WIDGET (scale_button)));
68
69 if (strcmp (pspec->name, "adjustment") == 0)
70 {
71 GtkAdjustment* adjustment;
72
73 adjustment = gtk_scale_button_get_adjustment (scale_button);
74 g_signal_connect (adjustment,
75 "value-changed",
76 G_CALLBACK (gtk_scale_button_accessible_value_changed),
77 accessible);
78 }
79 else
80 {
81 GTK_WIDGET_ACCESSIBLE_CLASS (gtk_scale_button_accessible_parent_class)->notify_gtk (obj, pspec);
82 }
83 }
84
85 static void
86 gtk_scale_button_accessible_class_init (GtkScaleButtonAccessibleClass *klass)
87 {
88 AtkObjectClass *atk_object_class = ATK_OBJECT_CLASS (klass);
89 GtkWidgetAccessibleClass *widget_class = GTK_WIDGET_ACCESSIBLE_CLASS (klass);
90
91 atk_object_class->initialize = gtk_scale_button_accessible_initialize;
92
93 widget_class->notify_gtk = gtk_scale_button_accessible_notify_gtk;
94 }
95
96 static void
97 gtk_scale_button_accessible_init (GtkScaleButtonAccessible *button)
98 {
99 }
100
101 static gboolean
102 gtk_scale_button_accessible_do_action (AtkAction *action,
103 gint i)
104 {
105 GtkWidget *widget;
106
107 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (action));
108 if (widget == NULL)
109 return FALSE;
110
111 if (!gtk_widget_is_sensitive (widget) || !gtk_widget_get_visible (widget))
112 return FALSE;
113
114 switch (i)
115 {
116 case 0:
117 g_signal_emit_by_name (widget, "popup");
118 return TRUE;
119 case 1:
120 g_signal_emit_by_name (widget, "popdown");
121 return TRUE;
122 default:
123 return FALSE;
124 }
125 }
126
127 static gint
128 gtk_scale_button_accessible_get_n_actions (AtkAction *action)
129 {
130 return 2;
131 }
132
133 static const gchar *
134 gtk_scale_button_accessible_get_description (AtkAction *action,
135 gint i)
136 {
137 switch (i)
138 {
139 case 0:
140 return C_("Action description", "Pops up the slider");
141 case 1:
142 return C_("Action description", "Dismisses the slider");
143 default:
144 return NULL;
145 }
146 }
147
148 static const gchar *
149 gtk_scale_button_accessible_action_get_name (AtkAction *action,
150 gint i)
151 {
152 switch (i)
153 {
154 case 0:
155 return "popup";
156 case 1:
157 return "popdown";
158 default:
159 return NULL;
160 }
161 }
162
163 static const gchar *
164 gtk_scale_button_accessible_action_get_localized_name (AtkAction *action,
165 gint i)
166 {
167 switch (i)
168 {
169 case 0:
170 return C_("Action name", "Popup");
171 case 1:
172 return C_("Action name", "Dismiss");
173 default:
174 return NULL;
175 }
176 }
177
178 static void
179 atk_action_interface_init (AtkActionIface *iface)
180 {
181 iface->do_action = gtk_scale_button_accessible_do_action;
182 iface->get_n_actions = gtk_scale_button_accessible_get_n_actions;
183 iface->get_description = gtk_scale_button_accessible_get_description;
184 iface->get_name = gtk_scale_button_accessible_action_get_name;
185 iface->get_localized_name = gtk_scale_button_accessible_action_get_localized_name;
186 }
187
188 static void
189 gtk_scale_button_accessible_get_current_value (AtkValue *obj,
190 GValue *value)
191 {
192 GtkWidget *widget;
193 GtkAdjustment *adjustment;
194
195 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
196 adjustment = gtk_scale_button_get_adjustment (GTK_SCALE_BUTTON (widget));
197 if (adjustment == NULL)
198 return;
199
200 memset (value, 0, sizeof (GValue));
201 g_value_init (value, G_TYPE_DOUBLE);
202 g_value_set_double (value, gtk_adjustment_get_value (adjustment));
203 }
204
205 static void
206 gtk_scale_button_accessible_get_maximum_value (AtkValue *obj,
207 GValue *value)
208 {
209 GtkWidget *widget;
210 GtkAdjustment *adjustment;
211
212 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
213 adjustment = gtk_scale_button_get_adjustment (GTK_SCALE_BUTTON (widget));
214 if (adjustment == NULL)
215 return;
216
217 memset (value, 0, sizeof (GValue));
218 g_value_init (value, G_TYPE_DOUBLE);
219 g_value_set_double (value, gtk_adjustment_get_upper (adjustment));
220 }
221
222 static void
223 gtk_scale_button_accessible_get_minimum_value (AtkValue *obj,
224 GValue *value)
225 {
226 GtkWidget *widget;
227 GtkAdjustment *adjustment;
228
229 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
230 adjustment = gtk_scale_button_get_adjustment (GTK_SCALE_BUTTON (widget));
231 if (adjustment == NULL)
232 return;
233
234 memset (value, 0, sizeof (GValue));
235 g_value_init (value, G_TYPE_DOUBLE);
236 g_value_set_double (value, gtk_adjustment_get_lower (adjustment));
237 }
238
239 static void
240 gtk_scale_button_accessible_get_minimum_increment (AtkValue *obj,
241 GValue *value)
242 {
243 GtkWidget *widget;
244 GtkAdjustment *adjustment;
245
246 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
247 adjustment = gtk_scale_button_get_adjustment (GTK_SCALE_BUTTON (widget));
248 if (adjustment == NULL)
249 return;
250
251 memset (value, 0, sizeof (GValue));
252 g_value_init (value, G_TYPE_DOUBLE);
253 g_value_set_double (value, gtk_adjustment_get_minimum_increment (adjustment));
254 }
255
256 static gboolean
257 gtk_scale_button_accessible_set_current_value (AtkValue *obj,
258 const GValue *value)
259 {
260 GtkWidget *widget;
261 GtkAdjustment *adjustment;
262
263 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
264 adjustment = gtk_scale_button_get_adjustment (GTK_SCALE_BUTTON (widget));
265 if (adjustment == NULL)
266 return FALSE;
267
268 gtk_adjustment_set_value (adjustment, g_value_get_double (value));
269
270 return TRUE;
271 }
272
273 static void
274 gtk_scale_button_accessible_get_value_and_text (AtkValue *obj,
275 gdouble *value,
276 gchar **text)
277 {
278 GtkWidget *widget;
279 GtkAdjustment *adjustment;
280
281 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
282 adjustment = gtk_scale_button_get_adjustment (GTK_SCALE_BUTTON (widget));
283 if (adjustment == NULL)
284 return;
285
286 *value = gtk_adjustment_get_value (adjustment);
287 *text = NULL;
288 }
289
290 static AtkRange *
291 gtk_scale_button_accessible_get_range (AtkValue *obj)
292 {
293 GtkWidget *widget;
294 GtkAdjustment *adjustment;
295
296 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
297 adjustment = gtk_scale_button_get_adjustment (GTK_SCALE_BUTTON (widget));
298 if (adjustment == NULL)
299 return NULL;
300
301 return atk_range_new (gtk_adjustment_get_lower (adjustment),
302 gtk_adjustment_get_upper (adjustment),
303 NULL);
304 }
305
306 static void
307 gtk_scale_button_accessible_set_value (AtkValue *obj,
308 const gdouble value)
309 {
310 GtkWidget *widget;
311 GtkAdjustment *adjustment;
312
313 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
314 adjustment = gtk_scale_button_get_adjustment (GTK_SCALE_BUTTON (widget));
315 if (adjustment == NULL)
316 return;
317
318 gtk_adjustment_set_value (adjustment, value);
319 }
320
321 static gdouble
322 gtk_scale_button_accessible_get_increment (AtkValue *obj)
323 {
324 GtkWidget *widget;
325 GtkAdjustment *adjustment;
326
327 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
328 adjustment = gtk_scale_button_get_adjustment (GTK_SCALE_BUTTON (widget));
329 if (adjustment == NULL)
330 return 0;
331
332 return gtk_adjustment_get_minimum_increment (adjustment);
333 }
334
335 static void
336 atk_value_interface_init (AtkValueIface *iface)
337 {
338 iface->get_current_value = gtk_scale_button_accessible_get_current_value;
339 iface->get_maximum_value = gtk_scale_button_accessible_get_maximum_value;
340 iface->get_minimum_value = gtk_scale_button_accessible_get_minimum_value;
341 iface->get_minimum_increment = gtk_scale_button_accessible_get_minimum_increment;
342 iface->set_current_value = gtk_scale_button_accessible_set_current_value;
343
344 iface->get_value_and_text = gtk_scale_button_accessible_get_value_and_text;
345 iface->get_range = gtk_scale_button_accessible_get_range;
346 iface->set_value = gtk_scale_button_accessible_set_value;
347 iface->get_increment = gtk_scale_button_accessible_get_increment;
348 }