Mercurial > projects > dwt2
annotate org.eclipse.swt.gtk.linux.x86/src/org/eclipse/swt/accessibility/Accessible.d @ 48:ddbfe84d86df
[swt lin] versioned imports
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Fri, 27 Mar 2009 12:05:20 +0100 |
parents | 65761bc28ab2 |
children | c01d033c633a |
rev | line source |
---|---|
25 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2008 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module org.eclipse.swt.accessibility.Accessible; | |
14 | |
15 import java.lang.all; | |
16 | |
17 import org.eclipse.swt.accessibility.AccessibleListener; | |
18 import org.eclipse.swt.accessibility.AccessibleTextListener; | |
19 import org.eclipse.swt.accessibility.AccessibleControlListener; | |
20 import org.eclipse.swt.accessibility.AccessibleControlListener; | |
21 import org.eclipse.swt.accessibility.AccessibleFactory; | |
22 import org.eclipse.swt.accessibility.AccessibleObject; | |
47
65761bc28ab2
swt linux again compilable for d1.
Frank Benoit <benoit@tionex.de>
parents:
25
diff
changeset
|
23 import java.lang.Thread; |
25 | 24 import org.eclipse.swt.SWT; |
25 //import org.eclipse.swt.events.*; | |
26 import org.eclipse.swt.internal.gtk.OS; | |
27 import org.eclipse.swt.widgets.Control; | |
28 import org.eclipse.swt.events.DisposeListener; | |
29 import org.eclipse.swt.events.DisposeEvent; | |
48 | 30 version(Tango){ |
31 import tango.core.Array; | |
32 } else { // Phobos | |
33 } | |
25 | 34 |
35 /** | |
36 * Instances of this class provide a bridge between application | |
37 * code and assistive technology clients. Many platforms provide | |
38 * default accessible behavior for most widgets, and this class | |
39 * allows that default behavior to be overridden. Applications | |
40 * can get the default Accessible object for a control by sending | |
41 * it <code>getAccessible</code>, and then add an accessible listener | |
42 * to override simple items like the name and help string, or they | |
43 * can add an accessible control listener to override complex items. | |
44 * As a rule of thumb, an application would only want to use the | |
45 * accessible control listener to implement accessibility for a | |
46 * custom control. | |
47 * | |
48 * @see Control#getAccessible | |
49 * @see AccessibleListener | |
50 * @see AccessibleEvent | |
51 * @see AccessibleControlListener | |
52 * @see AccessibleControlEvent | |
53 * @see <a href="http://www.eclipse.org/swt/snippets/#accessibility">Accessibility snippets</a> | |
54 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> | |
55 * | |
56 * @since 2.0 | |
57 */ | |
58 public class Accessible { | |
59 AccessibleListener[] accessibleListeners; | |
60 AccessibleControlListener[] controlListeners; | |
61 AccessibleTextListener[] textListeners; | |
62 AccessibleObject accessibleObject; | |
63 Control control; | |
64 | |
65 this (Control control) { | |
66 this.control = control; | |
67 AccessibleFactory.registerAccessible (this); | |
68 control.addDisposeListener (new class () DisposeListener { | |
69 public void widgetDisposed (DisposeEvent e) { | |
70 release (); | |
71 } | |
72 }); | |
73 } | |
74 | |
75 /** | |
76 * Adds the listener to the collection of listeners who will | |
77 * be notified when an accessible client asks for certain strings, | |
78 * such as name, description, help, or keyboard shortcut. The | |
79 * listener is notified by sending it one of the messages defined | |
80 * in the <code>AccessibleListener</code> interface. | |
81 * | |
82 * @param listener the listener that should be notified when the receiver | |
83 * is asked for a name, description, help, or keyboard shortcut string | |
84 * | |
85 * @exception IllegalArgumentException <ul> | |
86 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
87 * </ul> | |
88 * @exception SWTException <ul> | |
89 * <li>ERROR_WIDGET_DISPOSED - if the receiver's control has been disposed</li> | |
90 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver's control</li> | |
91 * </ul> | |
92 * | |
93 * @see AccessibleListener | |
94 * @see #removeAccessibleListener | |
95 */ | |
96 public void addAccessibleListener (AccessibleListener listener) { | |
97 checkWidget (); | |
98 if (listener is null) SWT.error (SWT.ERROR_NULL_ARGUMENT); | |
99 accessibleListeners ~= listener; | |
100 } | |
101 | |
102 /** | |
103 * Adds the listener to the collection of listeners who will | |
104 * be notified when an accessible client asks for custom control | |
105 * specific information. The listener is notified by sending it | |
106 * one of the messages defined in the <code>AccessibleControlListener</code> | |
107 * interface. | |
108 * | |
109 * @param listener the listener that should be notified when the receiver | |
110 * is asked for custom control specific information | |
111 * | |
112 * @exception IllegalArgumentException <ul> | |
113 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
114 * </ul> | |
115 * @exception SWTException <ul> | |
116 * <li>ERROR_WIDGET_DISPOSED - if the receiver's control has been disposed</li> | |
117 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver's control</li> | |
118 * </ul> | |
119 * | |
120 * @see AccessibleControlListener | |
121 * @see #removeAccessibleControlListener | |
122 */ | |
123 public void addAccessibleControlListener (AccessibleControlListener listener) { | |
124 checkWidget (); | |
125 if (listener is null) SWT.error (SWT.ERROR_NULL_ARGUMENT); | |
126 controlListeners ~= listener; | |
127 } | |
128 | |
129 /** | |
130 * Adds the listener to the collection of listeners who will | |
131 * be notified when an accessible client asks for custom text control | |
132 * specific information. The listener is notified by sending it | |
133 * one of the messages defined in the <code>AccessibleTextListener</code> | |
134 * interface. | |
135 * | |
136 * @param listener the listener that should be notified when the receiver | |
137 * is asked for custom text control specific information | |
138 * | |
139 * @exception IllegalArgumentException <ul> | |
140 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
141 * </ul> | |
142 * @exception SWTException <ul> | |
143 * <li>ERROR_WIDGET_DISPOSED - if the receiver's control has been disposed</li> | |
144 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver's control</li> | |
145 * </ul> | |
146 * | |
147 * @see AccessibleTextListener | |
148 * @see #removeAccessibleTextListener | |
149 * | |
150 * @since 3.0 | |
151 */ | |
152 public void addAccessibleTextListener (AccessibleTextListener listener) { | |
153 checkWidget (); | |
154 if (listener is null) SWT.error (SWT.ERROR_NULL_ARGUMENT); | |
155 textListeners ~= listener; | |
156 } | |
157 | |
158 /** | |
159 * Returns the control for this Accessible object. | |
160 * | |
161 * @return the receiver's control | |
162 * @since 3.0 | |
163 */ | |
164 public Control getControl() { | |
165 return control; | |
166 } | |
167 | |
168 /* checkWidget was copied from Widget, and rewritten to work in this package */ | |
169 void checkWidget () { | |
170 if (!isValidThread ()) SWT.error (SWT.ERROR_THREAD_INVALID_ACCESS); | |
171 if (control.isDisposed ()) SWT.error (SWT.ERROR_WIDGET_DISPOSED); | |
172 } | |
173 | |
174 AccessibleListener[] getAccessibleListeners () { | |
175 if (accessibleListeners.length is 0 ) return null; | |
176 return accessibleListeners.dup; | |
177 } | |
178 | |
179 GtkWidget* getControlHandle () { | |
180 return control.handle; | |
181 } | |
182 | |
183 AccessibleControlListener[] getControlListeners () { | |
184 if (controlListeners.length is 0) return null; | |
185 return controlListeners.dup; | |
186 } | |
187 | |
188 AccessibleTextListener[] getTextListeners () { | |
189 if (textListeners.length is 0) return null; | |
190 return textListeners.dup; | |
191 } | |
192 | |
193 /** | |
194 * Invokes platform specific functionality to allocate a new accessible object. | |
195 * <p> | |
196 * <b>IMPORTANT:</b> This method is <em>not</em> part of the public | |
197 * API for <code>Accessible</code>. It is marked public only so that it | |
198 * can be shared within the packages provided by SWT. It is not | |
199 * available on all platforms, and should never be called from | |
200 * application code. | |
201 * </p> | |
202 * | |
203 * @param control the control to get the accessible object for | |
204 * @return the platform specific accessible object | |
205 */ | |
206 public static Accessible internal_new_Accessible (Control control) { | |
207 return new Accessible (control); | |
208 } | |
209 | |
210 /* isValidThread was copied from Widget, and rewritten to work in this package */ | |
211 bool isValidThread () { | |
47
65761bc28ab2
swt linux again compilable for d1.
Frank Benoit <benoit@tionex.de>
parents:
25
diff
changeset
|
212 return control.getDisplay ().getThread () is Thread.currentThread (); |
25 | 213 } |
214 | |
215 void release () { | |
216 AccessibleFactory.unregisterAccessible (/*Accessible.*/this); | |
217 if (accessibleObject !is null) { | |
218 accessibleObject.release (); | |
219 accessibleObject = null; | |
220 } | |
221 accessibleListeners = null; | |
222 controlListeners = null; | |
223 textListeners = null; | |
224 } | |
225 /** | |
226 * Removes the listener from the collection of listeners who will | |
227 * be notified when an accessible client asks for custom control | |
228 * specific information. | |
229 * | |
230 * @param listener the listener that should no longer be notified when the receiver | |
231 * is asked for custom control specific information | |
232 * | |
233 * @exception IllegalArgumentException <ul> | |
234 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
235 * </ul> | |
236 * @exception SWTException <ul> | |
237 * <li>ERROR_WIDGET_DISPOSED - if the receiver's control has been disposed</li> | |
238 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver's control</li> | |
239 * </ul> | |
240 * | |
241 * @see AccessibleControlListener | |
242 * @see #addAccessibleControlListener | |
243 */ | |
244 public void removeAccessibleControlListener (AccessibleControlListener listener) { | |
245 checkWidget (); | |
246 if (listener is null) SWT.error (SWT.ERROR_NULL_ARGUMENT); | |
247 controlListeners.length = remove( controlListeners, listener, delegate bool(AccessibleControlListener a1, AccessibleControlListener a2 ){ return a1 is a2; }); | |
248 } | |
249 | |
250 /** | |
251 * Removes the listener from the collection of listeners who will | |
252 * be notified when an accessible client asks for certain strings, | |
253 * such as name, description, help, or keyboard shortcut. | |
254 * | |
255 * @param listener the listener that should no longer be notified when the receiver | |
256 * is asked for a name, description, help, or keyboard shortcut string | |
257 * | |
258 * @exception IllegalArgumentException <ul> | |
259 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
260 * </ul> | |
261 * @exception SWTException <ul> | |
262 * <li>ERROR_WIDGET_DISPOSED - if the receiver's control has been disposed</li> | |
263 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver's control</li> | |
264 * </ul> | |
265 * | |
266 * @see AccessibleListener | |
267 * @see #addAccessibleListener | |
268 */ | |
269 public void removeAccessibleListener (AccessibleListener listener) { | |
270 checkWidget (); | |
271 if (listener is null) SWT.error (SWT.ERROR_NULL_ARGUMENT); | |
272 accessibleListeners.length = remove( accessibleListeners, listener, delegate bool( AccessibleListener a1, AccessibleListener a2 ){ return a1 is a2; }); | |
273 } | |
274 | |
275 /** | |
276 * Removes the listener from the collection of listeners who will | |
277 * be notified when an accessible client asks for custom text control | |
278 * specific information. | |
279 * | |
280 * @param listener the listener that should no longer be notified when the receiver | |
281 * is asked for custom text control specific information | |
282 * | |
283 * @exception IllegalArgumentException <ul> | |
284 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> | |
285 * </ul> | |
286 * @exception SWTException <ul> | |
287 * <li>ERROR_WIDGET_DISPOSED - if the receiver's control has been disposed</li> | |
288 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver's control</li> | |
289 * </ul> | |
290 * | |
291 * @see AccessibleTextListener | |
292 * @see #addAccessibleTextListener | |
293 * | |
294 * @since 3.0 | |
295 */ | |
296 public void removeAccessibleTextListener (AccessibleTextListener listener) { | |
297 checkWidget (); | |
298 if (listener is null) SWT.error (SWT.ERROR_NULL_ARGUMENT); | |
299 textListeners.length = remove( textListeners, listener, delegate bool(AccessibleTextListener a1, AccessibleTextListener a2 ){ return a1 is a2; }); | |
300 } | |
301 | |
302 /** | |
303 * Sends a message to accessible clients that the child selection | |
304 * within a custom container control has changed. | |
305 * | |
306 * @exception SWTException <ul> | |
307 * <li>ERROR_WIDGET_DISPOSED - if the receiver's control has been disposed</li> | |
308 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver's control</li> | |
309 * </ul> | |
310 * | |
311 * @since 3.0 | |
312 */ | |
313 public void selectionChanged () { | |
314 checkWidget (); | |
315 if (accessibleObject !is null) { | |
316 accessibleObject.selectionChanged (); | |
317 } | |
318 } | |
319 | |
320 /** | |
321 * Sends a message to accessible clients indicating that the focus | |
322 * has changed within a custom control. | |
323 * | |
324 * @param childID an identifier specifying a child of the control | |
325 * | |
326 * @exception SWTException <ul> | |
327 * <li>ERROR_WIDGET_DISPOSED - if the receiver's control has been disposed</li> | |
328 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver's control</li> | |
329 * </ul> | |
330 */ | |
331 public void setFocus (int childID) { | |
332 checkWidget (); | |
333 if (accessibleObject !is null) { | |
334 accessibleObject.setFocus (childID); | |
335 } | |
336 } | |
337 | |
338 /** | |
339 * Sends a message to accessible clients that the text | |
340 * caret has moved within a custom control. | |
341 * | |
342 * @param index the new caret index within the control | |
343 * | |
344 * @exception SWTException <ul> | |
345 * <li>ERROR_WIDGET_DISPOSED - if the receiver's control has been disposed</li> | |
346 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver's control</li> | |
347 * </ul> | |
348 * | |
349 * @since 3.0 | |
350 */ | |
351 public void textCaretMoved (int index) { | |
352 checkWidget (); | |
353 if (accessibleObject !is null) { | |
354 accessibleObject.textCaretMoved (index); | |
355 } | |
356 } | |
357 | |
358 /** | |
359 * Sends a message to accessible clients that the text | |
360 * within a custom control has changed. | |
361 * | |
362 * @param type the type of change, one of <code>ACC.NOTIFY_TEXT_INSERT</code> | |
363 * or <code>ACC.NOTIFY_TEXT_DELETE</code> | |
364 * @param startIndex the text index within the control where the insertion or deletion begins | |
365 * @param length the non-negative length in characters of the insertion or deletion | |
366 * | |
367 * @exception SWTException <ul> | |
368 * <li>ERROR_WIDGET_DISPOSED - if the receiver's control has been disposed</li> | |
369 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver's control</li> | |
370 * </ul> | |
371 * | |
372 * @see ACC#TEXT_INSERT | |
373 * @see ACC#TEXT_DELETE | |
374 * | |
375 * @since 3.0 | |
376 */ | |
377 public void textChanged (int type, int startIndex, int length) { | |
378 checkWidget (); | |
379 if (accessibleObject !is null) { | |
380 accessibleObject.textChanged (type, startIndex, length); | |
381 } | |
382 } | |
383 | |
384 /** | |
385 * Sends a message to accessible clients that the text | |
386 * selection has changed within a custom control. | |
387 * | |
388 * @exception SWTException <ul> | |
389 * <li>ERROR_WIDGET_DISPOSED - if the receiver's control has been disposed</li> | |
390 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver's control</li> | |
391 * </ul> | |
392 * | |
393 * @since 3.0 | |
394 */ | |
395 public void textSelectionChanged () { | |
396 checkWidget (); | |
397 if (accessibleObject !is null) { | |
398 accessibleObject.textSelectionChanged (); | |
399 } | |
400 } | |
401 } |