17
17
import controlTypes
18
18
import NVDAObjects.JAB
20
#Some utility functions to help with function defines
22
def _errcheck(res, func, args):
24
raise RuntimeError("Result %s" % res)
27
def _fixBridgeFunc(restype,name,*argtypes,**kwargs):
29
func=getattr(bridgeDll,name)
30
except AttributeError:
31
log.warning("%s not found in Java Access Bridge dll"%name)
34
func.argtypes=argtypes
35
if kwargs.get('errcheck'):
36
func.errcheck=_errcheck
38
#Load the first available access bridge dll
39
legacyAccessBridge=True
41
bridgeDll=getattr(cdll,'windowsAccessBridge-32')
42
legacyAccessBridge=False
45
bridgeDll=cdll.windowsAccessBridge
49
#Definitions of access bridge types, structs and prototypes
53
class JOBJECT64(c_int if legacyAccessBridge else c_int64):
59
class AccessBridgeVersionInfo(Structure):
61
('VMVersion',WCHAR*SHORT_STRING_SIZE),
62
('bridgeJavaClassVersion',WCHAR*SHORT_STRING_SIZE),
63
('bridgeJavaDLLVersion',WCHAR*SHORT_STRING_SIZE),
64
('bridgeWinDLLVersion',WCHAR*SHORT_STRING_SIZE),
67
class AccessibleContextInfo(Structure):
69
('name',WCHAR*MAX_STRING_SIZE),
70
('description',WCHAR*MAX_STRING_SIZE),
71
('role',WCHAR*SHORT_STRING_SIZE),
72
('role_en_US',WCHAR*SHORT_STRING_SIZE),
73
('states',WCHAR*SHORT_STRING_SIZE),
74
('states_en_US',WCHAR*SHORT_STRING_SIZE),
75
('indexInParent',jint),
76
('childrenCount',jint),
81
('accessibleComponent',BOOL),
82
('accessibleAction',BOOL),
83
('accessibleSelection',BOOL),
84
('accessibleText',BOOL),
85
('accessibleValue',BOOL),
88
class AccessibleTextInfo(Structure):
92
('indexAtPoint',jint),
95
class AccessibleTextItemsInfo(Structure):
98
('word',WCHAR*SHORT_STRING_SIZE),
99
('sentence',WCHAR*MAX_STRING_SIZE),
102
class AccessibleTextSelectionInfo(Structure):
104
('selectionStartIndex',jint),
105
('selectionEndIndex',jint),
106
('selectedText',WCHAR*MAX_STRING_SIZE),
109
class AccessibleTextRectInfo(Structure):
117
class AccessibleTextAttributesInfo(Structure):
122
('strikethrough',BOOL),
123
('superscript',BOOL),
125
('backgroundColor',WCHAR*SHORT_STRING_SIZE),
126
('foregroundColor',WCHAR*SHORT_STRING_SIZE),
127
('fontFamily',WCHAR*SHORT_STRING_SIZE),
131
('firstLineIndent',jfloat),
132
('LeftIndent',jfloat),
133
('rightIndent',jfloat),
134
('lineSpacing',jfloat),
135
('spaceAbove',jfloat),
136
('spaceBelow',jfloat),
137
('fullAttributesString',WCHAR*MAX_STRING_SIZE),
140
MAX_RELATION_TARGETS = 25
143
class AccessibleRelationInfo(Structure):
145
("key", WCHAR * SHORT_STRING_SIZE),
146
("targetCount", jint),
147
("targets", JOBJECT64 * MAX_RELATION_TARGETS),
150
class AccessibleRelationSetInfo(Structure):
152
("relationCount", jint),
153
("relations", AccessibleRelationInfo * MAX_RELATIONS),
156
MAX_ACTION_INFO = 256
157
MAX_ACTIONS_TO_DO = 32
159
class AccessibleActionInfo(Structure):
161
("name", c_wchar * SHORT_STRING_SIZE),
164
class AccessibleActions(Structure):
166
("actionsCount", jint),
167
("actionInfo", AccessibleActionInfo * MAX_ACTION_INFO),
170
class AccessibleActionsToDo(Structure):
172
("actionsCount", jint),
173
("actions", AccessibleActionInfo * MAX_ACTIONS_TO_DO),
176
AccessBridge_FocusGainedFP=CFUNCTYPE(None,c_long,JOBJECT64,JOBJECT64)
177
AccessBridge_PropertyStateChangeFP=CFUNCTYPE(None,c_long,JOBJECT64,JOBJECT64,c_wchar_p,c_wchar_p)
178
AccessBridge_PropertyCaretChangeFP=CFUNCTYPE(None,c_long,JOBJECT64,JOBJECT64,c_int,c_int)
179
AccessBridge_PropertyActiveDescendentChangeFP=CFUNCTYPE(None,c_long,JOBJECT64,JOBJECT64,JOBJECT64,JOBJECT64)
181
#Appropriately set the return and argument types of all the access bridge dll functions
183
_fixBridgeFunc(None,'Windows_run')
184
_fixBridgeFunc(None,'setFocusGainedFP',c_void_p)
185
_fixBridgeFunc(None,'setPropertyStateChangeFP',c_void_p)
186
_fixBridgeFunc(None,'setPropertyCaretChangeFP',c_void_p)
187
_fixBridgeFunc(None,'setPropertyActiveDescendentChangeFP',c_void_p)
188
_fixBridgeFunc(None,'releaseJavaObject',c_long,JOBJECT64)
189
_fixBridgeFunc(BOOL,'getVersionInfo',POINTER(AccessBridgeVersionInfo),errcheck=True)
190
_fixBridgeFunc(BOOL,'isJavaWindow',HWND)
191
_fixBridgeFunc(BOOL,'isSameObject',c_long,JOBJECT64,JOBJECT64)
192
_fixBridgeFunc(BOOL,'getAccessibleContextFromHWND',HWND,POINTER(c_long),POINTER(JOBJECT64),errcheck=True)
193
_fixBridgeFunc(HWND,'getHWNDFromAccessibleContext',c_long,JOBJECT64,errcheck=True)
194
_fixBridgeFunc(BOOL,'getAccessibleContextAt',c_long,JOBJECT64,jint,jint,POINTER(JOBJECT64),errcheck=True)
195
_fixBridgeFunc(BOOL,'getAccessibleContextWithFocus',HWND,POINTER(c_long),POINTER(JOBJECT64),errcheck=True)
196
_fixBridgeFunc(BOOL,'getAccessibleContextInfo',c_long,JOBJECT64,POINTER(AccessibleContextInfo),errcheck=True)
197
_fixBridgeFunc(JOBJECT64,'getAccessibleChildFromContext',c_long,JOBJECT64,jint,errcheck=True)
198
_fixBridgeFunc(JOBJECT64,'getAccessibleParentFromContext',c_long,JOBJECT64)
199
_fixBridgeFunc(BOOL,'getAccessibleRelationSet',c_long,JOBJECT64,POINTER(AccessibleRelationSetInfo),errcheck=True)
200
_fixBridgeFunc(BOOL,'getAccessibleTextInfo',c_long,JOBJECT64,POINTER(AccessibleTextInfo),jint,jint,errcheck=True)
201
_fixBridgeFunc(BOOL,'getAccessibleTextItems',c_long,JOBJECT64,POINTER(AccessibleTextItemsInfo),jint,errcheck=True)
202
_fixBridgeFunc(BOOL,'getAccessibleTextSelectionInfo',c_long,JOBJECT64,POINTER(AccessibleTextSelectionInfo),errcheck=True)
203
_fixBridgeFunc(BOOL,'getAccessibleTextAttributes',c_long,JOBJECT64,jint,POINTER(AccessibleTextAttributesInfo),errcheck=True)
204
_fixBridgeFunc(BOOL,'getAccessibleTextLineBounds',c_long,JOBJECT64,jint,POINTER(jint),POINTER(jint),errcheck=True)
205
_fixBridgeFunc(BOOL,'getAccessibleTextRange',c_long,JOBJECT64,jint,jint,POINTER(c_wchar),c_short,errcheck=True)
206
_fixBridgeFunc(BOOL,'getCurrentAccessibleValueFromContext',c_long,JOBJECT64,POINTER(c_wchar),c_short,errcheck=True)
207
_fixBridgeFunc(BOOL,'selectTextRange',c_long,JOBJECT64,c_int,c_int,errcheck=True)
208
_fixBridgeFunc(BOOL,'getTextAttributesInRange',c_long,JOBJECT64,c_int,c_int,POINTER(AccessibleTextAttributesInfo),POINTER(c_short),errcheck=True)
209
_fixBridgeFunc(JOBJECT64,'getTopLevelObject',c_long,JOBJECT64,errcheck=True)
210
_fixBridgeFunc(c_int,'getObjectDepth',c_long,JOBJECT64)
211
_fixBridgeFunc(JOBJECT64,'getActiveDescendent',c_long,JOBJECT64)
212
_fixBridgeFunc(BOOL,'requestFocus',c_long,JOBJECT64,errcheck=True)
213
_fixBridgeFunc(BOOL,'setCaretPosition',c_long,JOBJECT64,c_int,errcheck=True)
214
_fixBridgeFunc(BOOL,'getCaretLocation',c_long,JOBJECT64,POINTER(AccessibleTextRectInfo),jint,errcheck=True)
215
_fixBridgeFunc(BOOL,'getAccessibleActions',c_long,JOBJECT64,POINTER(AccessibleActions),errcheck=True)
216
_fixBridgeFunc(BOOL,'doAccessibleActions',c_long,JOBJECT64,POINTER(AccessibleActionsToDo),POINTER(jint),errcheck=True)
22
221
vmIDsToWindowHandles={}
23
222
internalFunctionQueue=Queue.Queue(1000)
191
391
bridgeDll.getTextAttributesInRange(self.vmID, self.accContext, startIndex, endIndex, byref(attributes), byref(length))
192
392
return attributes, length.value
194
class AccessBridgeVersionInfo(Structure):
196
('VMVersion',WCHAR*SHORT_STRING_SIZE),
197
('bridgeJavaClassVersion',WCHAR*SHORT_STRING_SIZE),
198
('bridgeJavaDLLVersion',WCHAR*SHORT_STRING_SIZE),
199
('bridgeWinDLLVersion',WCHAR*SHORT_STRING_SIZE),
202
class AccessibleContextInfo(Structure):
204
('name',WCHAR*MAX_STRING_SIZE),
205
('description',WCHAR*MAX_STRING_SIZE),
206
('role',WCHAR*SHORT_STRING_SIZE),
207
('role_en_US',WCHAR*SHORT_STRING_SIZE),
208
('states',WCHAR*SHORT_STRING_SIZE),
209
('states_en_US',WCHAR*SHORT_STRING_SIZE),
210
('indexInParent',c_int),
211
('childrenCount',c_int),
216
('accessibleComponent',BOOL),
217
('accessibleAction',BOOL),
218
('accessibleSelection',BOOL),
219
('accessibleText',BOOL),
220
('accessibleValue',BOOL),
223
class AccessibleTextInfo(Structure):
226
('caretIndex',c_int),
227
('indexAtPoint',c_int),
230
class AccessibleTextItemsInfo(Structure):
233
('word',WCHAR*SHORT_STRING_SIZE),
234
('sentence',WCHAR*MAX_STRING_SIZE),
237
class AccessibleTextSelectionInfo(Structure):
239
('selectionStartIndex',c_int),
240
('selectionEndIndex',c_int),
241
('selectedText',WCHAR*MAX_STRING_SIZE),
244
class AccessibleTextRectInfo(Structure):
252
class AccessibleTextAttributesInfo(Structure):
257
('strikethrough',BOOL),
258
('superscript',BOOL),
260
('backgroundColor',WCHAR*SHORT_STRING_SIZE),
261
('foregroundColor',WCHAR*SHORT_STRING_SIZE),
262
('fontFamily',WCHAR*SHORT_STRING_SIZE),
266
('firstLineIndent',c_float),
267
('LeftIndent',c_float),
268
('rightIndent',c_float),
269
('lineSpacing',c_float),
270
('spaceAbove',c_float),
271
('spaceBelow',c_float),
272
('fullAttributesString',WCHAR*MAX_STRING_SIZE),
276
@CFUNCTYPE(None,c_int,c_int,c_int)
394
def getAccessibleRelationSet(self):
395
relations = AccessibleRelationSetInfo()
396
bridgeDll.getAccessibleRelationSet(self.vmID, self.accContext, byref(relations))
399
@AccessBridge_FocusGainedFP
277
400
def internal_event_focusGained(vmID, event,source):
278
401
internalQueueFunction(event_gainFocus,vmID,source)
279
402
bridgeDll.releaseJavaObject(vmID,event)
341
468
def event_enterJavaWindow(hwnd):
470
accContext=JOBJECT64()
345
472
bridgeDll.getAccessibleContextFromHWND(hwnd,byref(vmID),byref(accContext))
348
vmIDsToWindowHandles[vmID.value]=hwnd
476
vmIDsToWindowHandles[vmID]=hwnd
349
477
lastFocus=eventHandler.lastQueuedFocusObject
350
478
if isinstance(lastFocus,NVDAObjects.JAB.JAB) and lastFocus.windowHandle==hwnd:
352
internalQueueFunction(event_gainFocus,vmID.value,accContext.value)
480
internalQueueFunction(event_gainFocus,vmID,accContext)
354
482
def isJavaWindow(hwnd):
483
if not bridgeDll or not isRunning:
357
485
return bridgeDll.isJavaWindow(hwnd)
359
def _errcheck(res, func, args):
361
raise RuntimeError("Result %d" % res)
363
487
def initialize():
364
global bridgeDll, isRunning
366
bridgeDll=cdll.WINDOWSACCESSBRIDGE
368
bridgeDll.Windows_run, bridgeDll.getAccessibleContextFromHWND, bridgeDll.getVersionInfo,
369
bridgeDll.getAccessibleContextInfo, bridgeDll.getAccessibleTextInfo, bridgeDll.getAccessibleTextItems,
370
bridgeDll.getAccessibleTextSelectionInfo, bridgeDll.getAccessibleTextRange, bridgeDll.getAccessibleTextLineBounds,
371
bridgeDll.getCurrentAccessibleValueFromContext, bridgeDll.selectTextRange, bridgeDll.setCaretPosition,
372
bridgeDll.getAccessibleContextWithFocus,
374
func.errcheck = _errcheck
375
bridgeDll.Windows_run()
376
#Accept wm_copydata and any wm_user messages from other processes even if running with higher privilages
377
ChangeWindowMessageFilter=getattr(windll.user32,'ChangeWindowMessageFilter',None)
378
if ChangeWindowMessageFilter:
379
if not ChangeWindowMessageFilter(winUser.WM_COPYDATA,1):
490
raise NotImplementedError("dll not available")
491
bridgeDll.Windows_run()
492
#Accept wm_copydata and any wm_user messages from other processes even if running with higher privilages
493
ChangeWindowMessageFilter=getattr(windll.user32,'ChangeWindowMessageFilter',None)
494
if ChangeWindowMessageFilter:
495
if not ChangeWindowMessageFilter(winUser.WM_COPYDATA,1):
497
for msg in xrange(winUser.WM_USER+1,65535):
498
if not ChangeWindowMessageFilter(msg,1):
381
for msg in xrange(winUser.WM_USER+1,65535):
382
if not ChangeWindowMessageFilter(msg,1):
384
#Register java events
385
bridgeDll.setFocusGainedFP(internal_event_focusGained)
386
bridgeDll.setPropertyActiveDescendentChangeFP(internal_event_activeDescendantChange)
387
bridgeDll.setPropertyStateChangeFP(internal_event_stateChange)
388
bridgeDll.setPropertyCaretChangeFP(internal_event_caretChange)
392
log.debugWarning("Error initializing java access bridge",exc_info=True)
500
#Register java events
501
bridgeDll.setFocusGainedFP(internal_event_focusGained)
502
bridgeDll.setPropertyActiveDescendentChangeFP(internal_event_activeDescendantChange)
503
bridgeDll.setPropertyStateChangeFP(internal_event_stateChange)
504
bridgeDll.setPropertyCaretChangeFP(internal_event_caretChange)