Mercurial > projects > dwt-mac
annotate dwt/accessibility/SWTAccessibleDelegate.d @ 156:969e7de37c3d default tip
Fixes to get dwt to work with dmd and ldc
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Wed, 08 Jul 2009 21:56:44 +0200 |
parents | ad4e1fe71a5a |
children |
rev | line source |
---|---|
45 | 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 | |
59 | 10 * |
11 * Port to the D programming language: | |
12 * Jacob Carlborg <doob@me.com> | |
45 | 13 *******************************************************************************/ |
14 module dwt.accessibility.SWTAccessibleDelegate; | |
15 | |
16 import dwt.dwthelper.utils; | |
17 | |
18 | |
19 import dwt.DWT; | |
20 import dwt.internal.C; | |
21 import dwt.internal.cocoa.NSArray; | |
22 import dwt.internal.cocoa.NSObject; | |
23 import dwt.internal.cocoa.NSPoint; | |
24 import dwt.internal.cocoa.NSString; | |
25 import dwt.internal.cocoa.OS; | |
59 | 26 import cocoa = dwt.internal.cocoa.id; |
45 | 27 |
59 | 28 import dwt.accessibility.Accessible; |
29 import objc = dwt.internal.objc.runtime; | |
30 | |
31 class SWTAccessibleDelegate : NSObject { | |
123 | 32 |
45 | 33 /** |
34 * Accessible Key: The string constant for looking up the accessible | |
35 * for a control using <code>getData(String)</code>. When an accessible | |
36 * is created for a control, it is stored as a property in the control | |
37 * using <code>setData(String, Object)</code>. | |
38 */ | |
39 static final String ACCESSIBLE_KEY = "Accessible"; //$NON-NLS-1$ | |
129 | 40 static final String SWT_OBJECT = "SWT_OBJECT"; |
123 | 41 |
59 | 42 static objc.IMP proc2Args, proc3Args, proc4Args; |
123 | 43 |
45 | 44 Accessible accessibleParent; |
59 | 45 void* delegateJniRef; |
45 | 46 int childID; |
123 | 47 |
45 | 48 NSArray attributeNames = null; |
49 NSArray parameterizedAttributeNames = null; | |
50 NSArray actionNames = null; | |
123 | 51 |
59 | 52 static this (){ |
53 ClassInfo clazz = SWTAccessibleDelegate.classinfo; | |
123 | 54 |
59 | 55 proc2Args = cast(objc.IMP) &accessibleProc2; |
123 | 56 |
59 | 57 proc3Args = cast(objc.IMP) &accessibleProc3; |
123 | 58 |
59 | 59 proc4Args = cast(objc.IMP) &accessibleProc4; |
123 | 60 |
45 | 61 // Accessible custom controls need to implement the NSAccessibility protocol. To do that, |
62 // we dynamically add the methods to the control's class that are required | |
63 // by NSAccessibility. Then, when external assistive technology services are used, | |
64 // those methods get called to provide the needed information. | |
123 | 65 |
45 | 66 String className = "SWTAccessibleDelegate"; |
123 | 67 |
45 | 68 // TODO: These should either move out of Display or be accessible to this class. |
69 String types = "*"; | |
59 | 70 size_t size = C.PTR_SIZEOF, align_ = C.PTR_SIZEOF is 4 ? 2 : 3; |
123 | 71 |
59 | 72 objc.Class cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSObject, className, 0); |
129 | 73 OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types); |
123 | 74 |
45 | 75 // Add the NSAccessibility overrides |
76 OS.class_addMethod(cls, OS.sel_accessibilityActionNames, proc2Args, "@:"); | |
77 OS.class_addMethod(cls, OS.sel_accessibilityAttributeNames, proc2Args, "@:"); | |
78 OS.class_addMethod(cls, OS.sel_accessibilityParameterizedAttributeNames, proc2Args, "@:"); | |
79 OS.class_addMethod(cls, OS.sel_accessibilityIsIgnored, proc2Args, "@:"); | |
80 OS.class_addMethod(cls, OS.sel_accessibilityFocusedUIElement, proc2Args, "@:"); | |
123 | 81 |
45 | 82 OS.class_addMethod(cls, OS.sel_accessibilityAttributeValue_, proc3Args, "@:@"); |
83 OS.class_addMethod(cls, OS.sel_accessibilityHitTest_, proc3Args, "@:{NSPoint}"); | |
84 OS.class_addMethod(cls, OS.sel_accessibilityIsAttributeSettable_, proc3Args, "@:@"); | |
85 OS.class_addMethod(cls, OS.sel_accessibilityActionDescription_, proc3Args, "@:@"); | |
86 OS.class_addMethod(cls, OS.sel_accessibilityPerformAction_, proc3Args, "@:@"); | |
123 | 87 |
45 | 88 OS.class_addMethod(cls, OS.sel_accessibilityAttributeValue_forParameter_, proc4Args, "@:@@"); |
89 OS.class_addMethod(cls, OS.sel_accessibilitySetValue_forAttribute_, proc4Args, "@:@@"); | |
123 | 90 |
45 | 91 OS.objc_registerClassPair(cls); |
92 } | |
123 | 93 |
94 | |
59 | 95 public this(Accessible accessible, int childID) { |
96 super(cast(objc.id) null); | |
45 | 97 this.accessibleParent = accessible; |
98 this.childID = childID; | |
99 alloc().init(); | |
100 delegateJniRef = OS.NewGlobalRef(this); | |
59 | 101 if (delegateJniRef is null) DWT.error(DWT.ERROR_NO_HANDLES); |
129 | 102 OS.object_setInstanceVariable(this.id, SWT_OBJECT, delegateJniRef); |
45 | 103 } |
123 | 104 |
45 | 105 NSArray accessibilityActionNames() { |
106 | |
107 if (actionNames !is null) | |
108 return retainedAutoreleased(actionNames); | |
109 | |
110 actionNames = accessibleParent.internal_accessibilityActionNames(childID); | |
111 actionNames.retain(); | |
112 return retainedAutoreleased(actionNames); | |
113 } | |
123 | 114 |
45 | 115 NSArray accessibilityAttributeNames() { |
116 | |
117 if (attributeNames !is null) | |
118 return retainedAutoreleased(attributeNames); | |
119 | |
120 attributeNames = accessibleParent.internal_accessibilityAttributeNames(childID); | |
121 attributeNames.retain(); | |
122 return retainedAutoreleased(attributeNames); | |
123 } | |
123 | 124 |
59 | 125 cocoa.id accessibilityAttributeValue(NSString attribute) { |
45 | 126 return accessibleParent.internal_accessibilityAttributeValue(attribute, childID); |
127 } | |
128 | |
129 // parameterized attribute methods | |
130 NSArray accessibilityParameterizedAttributeNames() { | |
131 | |
132 if (parameterizedAttributeNames !is null) | |
133 return retainedAutoreleased(parameterizedAttributeNames); | |
134 | |
135 parameterizedAttributeNames = accessibleParent.internal_accessibilityParameterizedAttributeNames(childID); | |
136 parameterizedAttributeNames.retain(); | |
137 return retainedAutoreleased(parameterizedAttributeNames); | |
138 } | |
139 | |
59 | 140 cocoa.id accessibilityAttributeValue_forParameter(NSString attribute, cocoa.id parameter) { |
45 | 141 return accessibleParent.internal_accessibilityAttributeValue_forParameter(attribute, parameter, childID); |
142 } | |
123 | 143 |
45 | 144 // Return YES if the UIElement doesn't show up to the outside world - i.e. its parent should return the UIElement's children as its own - cutting the UIElement out. E.g. NSControls are ignored when they are single-celled. |
145 bool accessibilityIsIgnored() { | |
146 return accessibleParent.internal_accessibilityIsIgnored(childID); | |
147 } | |
123 | 148 |
45 | 149 bool accessibilityIsAttributeSettable(NSString attribute) { |
150 return accessibleParent.internal_accessibilityIsAttributeSettable(attribute, childID); | |
151 } | |
123 | 152 |
45 | 153 // Returns the deepest descendant of the UIElement hierarchy that contains the point. You can assume the point has already been determined to lie within the receiver. Override this method to do deeper hit testing within a UIElement - e.g. a NSMatrix would test its cells. The point is bottom-left relative screen coordinates. |
59 | 154 cocoa.id accessibilityHitTest(NSPoint point) { |
45 | 155 return accessibleParent.internal_accessibilityHitTest(point, childID); |
156 } | |
123 | 157 |
45 | 158 // Returns the UI Element that has the focus. You can assume that the search for the focus has already been narrowed down to the reciever. Override this method to do a deeper search with a UIElement - e.g. a NSMatrix would determine if one of its cells has the focus. |
59 | 159 cocoa.id accessibilityFocusedUIElement() { |
45 | 160 return accessibleParent.internal_accessibilityFocusedUIElement(childID); |
161 } | |
123 | 162 |
45 | 163 void accessibilityPerformAction(NSString action) { |
164 accessibleParent.internal_accessibilityPerformAction(action, childID); | |
165 } | |
166 | |
59 | 167 cocoa.id accessibilityActionDescription(NSString action) { |
45 | 168 return accessibleParent.internal_accessibilityActionDescription(action, childID); |
169 } | |
170 | |
171 | |
59 | 172 void accessibilitySetValue_forAttribute(cocoa.id value, NSString attribute) { |
45 | 173 // This shouldn't be called! |
61
c74ba20de292
Fix: The application responds to events now
Jacob Carlborg <doob@me.com>
parents:
60
diff
changeset
|
174 System.out_.println("Ignoring attribute: " ~ attribute.getString()); |
45 | 175 } |
176 | |
177 static NSArray retainedAutoreleased(NSArray inObject) { | |
59 | 178 cocoa.id temp = inObject.retain(); |
60
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
59
diff
changeset
|
179 cocoa.id temp2 = (new NSObject(temp.id)).autorelease(); |
45 | 180 return new NSArray(temp2.id); |
181 } | |
123 | 182 extern (C){ |
59 | 183 static objc.id accessibleProc2(objc.id id, objc.SEL sel) { |
45 | 184 SWTAccessibleDelegate swtAcc = getAccessibleDelegate(id); |
59 | 185 if (swtAcc is null) return null; |
123 | 186 |
45 | 187 if (sel is OS.sel_accessibilityAttributeNames) { |
188 NSArray retObject = swtAcc.accessibilityAttributeNames(); | |
59 | 189 return (retObject is null ? null : retObject.id); |
45 | 190 } else if (sel is OS.sel_accessibilityActionNames) { |
191 NSArray retObject = swtAcc.accessibilityActionNames(); | |
59 | 192 return (retObject is null ? null : retObject.id); |
45 | 193 } else if (sel is OS.sel_accessibilityParameterizedAttributeNames) { |
194 NSArray retObject = swtAcc.accessibilityParameterizedAttributeNames(); | |
59 | 195 return (retObject is null ? null : retObject.id); |
45 | 196 } else if (sel is OS.sel_accessibilityIsIgnored) { |
197 bool retVal = swtAcc.accessibilityIsIgnored(); | |
59 | 198 return (retVal ? cast(objc.id)1 : null); |
45 | 199 } else if (sel is OS.sel_accessibilityFocusedUIElement) { |
59 | 200 cocoa.id retObject = swtAcc.accessibilityFocusedUIElement(); |
201 return (retObject is null ? null : retObject.id); | |
45 | 202 } |
123 | 203 |
59 | 204 return null; |
45 | 205 } |
123 | 206 |
59 | 207 static objc.id accessibleProc3(objc.id id, objc.SEL sel, objc.id arg0) { |
45 | 208 SWTAccessibleDelegate swtAcc = getAccessibleDelegate(id); |
59 | 209 if (swtAcc is null) return null; |
45 | 210 |
211 if (sel is OS.sel_accessibilityAttributeValue_) { | |
212 NSString attribute = new NSString(arg0); | |
59 | 213 cocoa.id retObject = swtAcc.accessibilityAttributeValue(attribute); |
214 return (retObject is null ? null : retObject.id); | |
45 | 215 } else if (sel is OS.sel_accessibilityHitTest_) { |
46
cfa563df4fdd
Updated Widget and Display to 3.514
Jacob Carlborg <doob@me.com>
parents:
45
diff
changeset
|
216 NSPoint point= NSPoint(); |
60
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
59
diff
changeset
|
217 OS.memmove(&point, arg0, NSPoint.sizeof); |
59 | 218 cocoa.id retObject = swtAcc.accessibilityHitTest(point); |
219 return (retObject is null ? null : retObject.id); | |
45 | 220 } else if (sel is OS.sel_accessibilityIsAttributeSettable_) { |
221 NSString attribute = new NSString(arg0); | |
60
62202ce0039f
Updated and fixed many modules to 3.514
Jacob Carlborg <doob@me.com>
parents:
59
diff
changeset
|
222 return (swtAcc.accessibilityIsAttributeSettable(attribute) ? cast(objc.id) 1 : null); |
45 | 223 } else if (sel is OS.sel_accessibilityActionDescription_) { |
224 NSString action = new NSString(arg0); | |
59 | 225 cocoa.id retObject = swtAcc.accessibilityActionDescription(action); |
226 return (retObject is null ? null : retObject.id); | |
45 | 227 } else if (sel is OS.sel_accessibilityPerformAction_) { |
228 NSString action = new NSString(arg0); | |
229 swtAcc.accessibilityPerformAction(action); | |
230 } | |
123 | 231 |
59 | 232 return null; |
45 | 233 } |
123 | 234 |
59 | 235 static objc.id accessibleProc4(objc.id id, objc.SEL sel, objc.id arg0, objc.id arg1) { |
45 | 236 SWTAccessibleDelegate swtAcc = getAccessibleDelegate(id); |
59 | 237 if (swtAcc is null) return null; |
45 | 238 |
239 if (sel is OS.sel_accessibilityAttributeValue_forParameter_) { | |
240 NSString attribute = new NSString(arg0); | |
59 | 241 cocoa.id parameter = new cocoa.id(arg1); |
242 cocoa.id retObject = swtAcc.accessibilityAttributeValue_forParameter(attribute, parameter); | |
243 return (retObject is null ? null : retObject.id); | |
45 | 244 } else if (sel is OS.sel_accessibilitySetValue_forAttribute_) { |
59 | 245 cocoa.id value = new cocoa.id(arg0); |
45 | 246 NSString attribute = new NSString(arg1); |
247 swtAcc.accessibilitySetValue_forAttribute(value, attribute); | |
248 } | |
123 | 249 |
59 | 250 return null; |
45 | 251 } |
123 | 252 } |
59 | 253 static SWTAccessibleDelegate getAccessibleDelegate(objc.id id) { |
254 if (id is null) return null; | |
255 void* jniRef; | |
129 | 256 OS.object_getInstanceVariable(id, SWT_OBJECT, jniRef); |
59 | 257 if (jniRef is null) return null; |
258 return cast(SWTAccessibleDelegate)OS.JNIGetObject(jniRef); | |
45 | 259 } |
123 | 260 |
45 | 261 public void internal_dispose_SWTAccessibleDelegate() { |
262 if (actionNames !is null) actionNames.release(); | |
263 actionNames = null; | |
264 if (attributeNames !is null) attributeNames.release(); | |
265 attributeNames = null; | |
266 if (parameterizedAttributeNames !is null) parameterizedAttributeNames.release(); | |
267 parameterizedAttributeNames = null; | |
268 } | |
123 | 269 |
45 | 270 } |