~stomato463/+junk/nvdajp

« back to all changes in this revision

Viewing changes to source/JABHandler.py

  • Committer: Masataka Shinke
  • Date: 2011-10-25 12:35:26 UTC
  • mfrom: (4185 jpmain)
  • mto: This revision was merged to the branch mainline in revision 4211.
  • Revision ID: mshinke@users.sourceforge.jp-20111025123526-ze527a2rl3z0g2ky
lp:~nishimotz/nvdajp/main : 4185 をマージ

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
import controlTypes
18
18
import NVDAObjects.JAB
19
19
 
20
 
bridgeDll=None
 
20
#Some utility functions to help with function defines
 
21
 
 
22
def _errcheck(res, func, args):
 
23
        if not res:
 
24
                raise RuntimeError("Result %s" % res)
 
25
        return res
 
26
 
 
27
def _fixBridgeFunc(restype,name,*argtypes,**kwargs):
 
28
        try:
 
29
                func=getattr(bridgeDll,name)
 
30
        except AttributeError:
 
31
                log.warning("%s not found in Java Access Bridge dll"%name)
 
32
                return
 
33
        func.restype=restype
 
34
        func.argtypes=argtypes
 
35
        if kwargs.get('errcheck'):
 
36
                func.errcheck=_errcheck
 
37
 
 
38
#Load the first available access bridge dll
 
39
legacyAccessBridge=True
 
40
try:
 
41
        bridgeDll=getattr(cdll,'windowsAccessBridge-32')
 
42
        legacyAccessBridge=False
 
43
except WindowsError:
 
44
        try:
 
45
                bridgeDll=cdll.windowsAccessBridge
 
46
        except WindowsError:
 
47
                bridgeDll=None
 
48
 
 
49
#Definitions of access bridge types, structs and prototypes
 
50
 
 
51
jint=c_int
 
52
jfloat=c_float
 
53
class JOBJECT64(c_int if legacyAccessBridge else c_int64):
 
54
        pass
 
55
 
 
56
MAX_STRING_SIZE=1024
 
57
SHORT_STRING_SIZE=256
 
58
 
 
59
class AccessBridgeVersionInfo(Structure):
 
60
        _fields_=[
 
61
                ('VMVersion',WCHAR*SHORT_STRING_SIZE),
 
62
                ('bridgeJavaClassVersion',WCHAR*SHORT_STRING_SIZE),
 
63
                ('bridgeJavaDLLVersion',WCHAR*SHORT_STRING_SIZE),
 
64
                ('bridgeWinDLLVersion',WCHAR*SHORT_STRING_SIZE),
 
65
        ]
 
66
 
 
67
class AccessibleContextInfo(Structure):
 
68
        _fields_=[
 
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),
 
77
                ('x',jint),
 
78
                ('y',jint),
 
79
                ('width',jint),
 
80
                ('height',jint),
 
81
                ('accessibleComponent',BOOL),
 
82
                ('accessibleAction',BOOL),
 
83
                ('accessibleSelection',BOOL),
 
84
                ('accessibleText',BOOL),
 
85
                ('accessibleValue',BOOL),
 
86
        ]
 
87
 
 
88
class AccessibleTextInfo(Structure):
 
89
        _fields_=[
 
90
                ('charCount',jint),
 
91
                ('caretIndex',jint),
 
92
                ('indexAtPoint',jint),
 
93
        ]
 
94
 
 
95
class AccessibleTextItemsInfo(Structure):
 
96
        _fields_=[
 
97
                ('letter',WCHAR),
 
98
                ('word',WCHAR*SHORT_STRING_SIZE),
 
99
                ('sentence',WCHAR*MAX_STRING_SIZE),
 
100
        ]
 
101
 
 
102
class AccessibleTextSelectionInfo(Structure):
 
103
        _fields_=[
 
104
                ('selectionStartIndex',jint),
 
105
                ('selectionEndIndex',jint),
 
106
                ('selectedText',WCHAR*MAX_STRING_SIZE),
 
107
        ]
 
108
 
 
109
class AccessibleTextRectInfo(Structure):
 
110
        _fields_=[
 
111
                ('x',jint),
 
112
                ('y',jint),
 
113
                ('width',jint),
 
114
                ('height',jint),
 
115
        ]
 
116
 
 
117
class AccessibleTextAttributesInfo(Structure):
 
118
        _fields_=[
 
119
                ('bold',BOOL),
 
120
                ('italic',BOOL),
 
121
                ('underline',BOOL),
 
122
                ('strikethrough',BOOL),
 
123
                ('superscript',BOOL),
 
124
                ('subscript',BOOL),
 
125
                ('backgroundColor',WCHAR*SHORT_STRING_SIZE),
 
126
                ('foregroundColor',WCHAR*SHORT_STRING_SIZE),
 
127
                ('fontFamily',WCHAR*SHORT_STRING_SIZE),
 
128
                ('fontSize',jint),
 
129
                ('alignment',jint),
 
130
                ('bidiLevel',jint),
 
131
                ('firstLineIndent',jfloat),
 
132
                ('LeftIndent',jfloat),
 
133
                ('rightIndent',jfloat),
 
134
                ('lineSpacing',jfloat),
 
135
                ('spaceAbove',jfloat),
 
136
                ('spaceBelow',jfloat),
 
137
                ('fullAttributesString',WCHAR*MAX_STRING_SIZE),
 
138
        ]
 
139
 
 
140
MAX_RELATION_TARGETS = 25
 
141
MAX_RELATIONS = 5
 
142
 
 
143
class AccessibleRelationInfo(Structure):
 
144
        _fields_ = [
 
145
                ("key", WCHAR * SHORT_STRING_SIZE),
 
146
                ("targetCount", jint),
 
147
                ("targets", JOBJECT64 * MAX_RELATION_TARGETS),
 
148
        ]
 
149
 
 
150
class AccessibleRelationSetInfo(Structure):
 
151
        _fields_ = [
 
152
                ("relationCount", jint),
 
153
                ("relations", AccessibleRelationInfo * MAX_RELATIONS),
 
154
        ]
 
155
 
 
156
MAX_ACTION_INFO = 256
 
157
MAX_ACTIONS_TO_DO = 32
 
158
 
 
159
class AccessibleActionInfo(Structure):
 
160
        _fields_ = (
 
161
                ("name", c_wchar * SHORT_STRING_SIZE),
 
162
        )
 
163
 
 
164
class AccessibleActions(Structure):
 
165
        _fields_ = (
 
166
                ("actionsCount", jint),
 
167
                ("actionInfo", AccessibleActionInfo * MAX_ACTION_INFO),
 
168
        )
 
169
 
 
170
class AccessibleActionsToDo(Structure):
 
171
        _fields_ = (
 
172
                ("actionsCount", jint),
 
173
                ("actions", AccessibleActionInfo * MAX_ACTIONS_TO_DO),
 
174
        )
 
175
 
 
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)
 
180
 
 
181
#Appropriately set the return and argument types of all the access bridge dll functions
 
182
if bridgeDll:
 
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)
 
217
 
 
218
#NVDA specific code
 
219
 
21
220
isRunning=False
22
221
vmIDsToWindowHandles={}
23
222
internalFunctionQueue=Queue.Queue(1000)
26
225
def internalQueueFunction(func,*args,**kwargs):
27
226
        internalFunctionQueue.put_nowait((func,args,kwargs))
28
227
 
29
 
MAX_STRING_SIZE=1024
30
 
SHORT_STRING_SIZE=256
31
 
 
32
228
class JABContext(object):
33
229
 
34
230
        def __init__(self,hwnd=None,vmID=None,accContext=None):
35
231
                if hwnd and not vmID:
36
232
                        vmID=c_int()
37
 
                        accContext=c_int()
 
233
                        accContext=JOBJECT64()
38
234
                        bridgeDll.getAccessibleContextFromHWND(hwnd,byref(vmID),byref(accContext))
39
235
                        vmID=vmID.value
40
 
                        accContext=accContext.value
41
236
                        #Record  this vm ID and window handle for later use with other objects
42
237
                        vmIDsToWindowHandles[vmID]=hwnd
43
238
                elif vmID and not hwnd:
44
 
                        hwnd=vmIDsToWindowHandles.get(vmID,0)
 
239
                        hwnd=vmIDsToWindowHandles.get(vmID)
 
240
                        if not hwnd:
 
241
                                topAC=bridgeDll.getTopLevelObject(vmID,accContext)
 
242
                                hwnd=bridgeDll.getHWNDFromAccessibleContext(vmID,topAC)
 
243
                                bridgeDll.releaseJavaObject(vmID,topAC)
 
244
                                #Record  this vm ID and window handle for later use with other objects
 
245
                                vmIDsToWindowHandles[vmID]=hwnd
45
246
                self.hwnd=hwnd
46
247
                self.vmID=vmID
47
248
                self.accContext=accContext
163
364
                        return None
164
365
 
165
366
        def getAccessibleContextAt(self,x,y):
166
 
                newAccContext=c_int()
 
367
                newAccContext=JOBJECT64()
167
368
                res=bridgeDll.getAccessibleContextAt(self.vmID,self.accContext,x,y,byref(newAccContext))
168
 
                newAccContext=newAccContext.value
169
369
                if not res or not newAccContext:
170
370
                        return None
171
371
                if not bridgeDll.isSameObject(self.vmID,newAccContext,self.accContext):
191
391
                bridgeDll.getTextAttributesInRange(self.vmID, self.accContext, startIndex, endIndex, byref(attributes), byref(length))
192
392
                return attributes, length.value
193
393
 
194
 
class AccessBridgeVersionInfo(Structure):
195
 
        _fields_=[
196
 
                ('VMVersion',WCHAR*SHORT_STRING_SIZE),
197
 
                ('bridgeJavaClassVersion',WCHAR*SHORT_STRING_SIZE),
198
 
                ('bridgeJavaDLLVersion',WCHAR*SHORT_STRING_SIZE),
199
 
                ('bridgeWinDLLVersion',WCHAR*SHORT_STRING_SIZE),
200
 
        ]
201
 
 
202
 
class AccessibleContextInfo(Structure):
203
 
        _fields_=[
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),
212
 
                ('x',c_int),
213
 
                ('y',c_int),
214
 
                ('width',c_int),
215
 
                ('height',c_int),
216
 
                ('accessibleComponent',BOOL),
217
 
                ('accessibleAction',BOOL),
218
 
                ('accessibleSelection',BOOL),
219
 
                ('accessibleText',BOOL),
220
 
                ('accessibleValue',BOOL),
221
 
        ]
222
 
 
223
 
class AccessibleTextInfo(Structure):
224
 
        _fields_=[
225
 
                ('charCount',c_int),
226
 
                ('caretIndex',c_int),
227
 
                ('indexAtPoint',c_int),
228
 
        ]
229
 
 
230
 
class AccessibleTextItemsInfo(Structure):
231
 
        _fields_=[
232
 
                ('letter',WCHAR),
233
 
                ('word',WCHAR*SHORT_STRING_SIZE),
234
 
                ('sentence',WCHAR*MAX_STRING_SIZE),
235
 
        ]
236
 
 
237
 
class AccessibleTextSelectionInfo(Structure):
238
 
        _fields_=[
239
 
                ('selectionStartIndex',c_int),
240
 
                ('selectionEndIndex',c_int),
241
 
                ('selectedText',WCHAR*MAX_STRING_SIZE),
242
 
        ]
243
 
 
244
 
class AccessibleTextRectInfo(Structure):
245
 
        _fields_=[
246
 
                ('x',c_int),
247
 
                ('y',c_int),
248
 
                ('width',c_int),
249
 
                ('height',c_int),
250
 
        ]
251
 
 
252
 
class AccessibleTextAttributesInfo(Structure):
253
 
        _fields_=[
254
 
                ('bold',BOOL),
255
 
                ('italic',BOOL),
256
 
                ('underline',BOOL),
257
 
                ('strikethrough',BOOL),
258
 
                ('superscript',BOOL),
259
 
                ('subscript',BOOL),
260
 
                ('backgroundColor',WCHAR*SHORT_STRING_SIZE),
261
 
                ('foregroundColor',WCHAR*SHORT_STRING_SIZE),
262
 
                ('fontFamily',WCHAR*SHORT_STRING_SIZE),
263
 
                ('fontSize',c_int),
264
 
                ('alignment',c_int),
265
 
                ('bidiLevel',c_int),
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),
273
 
        ]
274
 
 
275
 
 
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))
 
397
                return relations
 
398
 
 
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)
305
428
                return
306
429
        eventHandler.queueEvent("gainFocus",obj)
307
430
 
308
 
@CFUNCTYPE(None,c_int,c_int,c_int,c_int,c_int)
 
431
@AccessBridge_PropertyActiveDescendentChangeFP
309
432
def internal_event_activeDescendantChange(vmID, event,source,oldDescendant,newDescendant):
310
433
        internalQueueFunction(event_gainFocus,vmID,newDescendant)
311
434
        for accContext in [event,oldDescendant]:
312
435
                bridgeDll.releaseJavaObject(vmID,accContext)
313
436
 
314
 
@CFUNCTYPE(None,c_int,c_int,c_int,c_wchar_p,c_wchar_p)
 
437
@AccessBridge_PropertyStateChangeFP
315
438
def internal_event_stateChange(vmID,event,source,oldState,newState):
316
439
        internalQueueFunction(event_stateChange,vmID,source,oldState,newState)
317
440
        bridgeDll.releaseJavaObject(vmID,event)
323
446
        stateList=newState.split(',')
324
447
        if "focused" in stateList or "selected" in stateList:
325
448
                obj=NVDAObjects.JAB.JAB(jabContext=jabContext)
 
449
                if not obj:
 
450
                        return
326
451
                if focus!=obj and eventHandler.lastQueuedFocusObject!=obj and obj.role in (controlTypes.ROLE_MENUITEM,controlTypes.ROLE_TAB,controlTypes.ROLE_MENU):
327
452
                        eventHandler.queueEvent("gainFocus",obj)
328
453
                        return
330
455
                obj=focus
331
456
        else:
332
457
                obj=NVDAObjects.JAB.JAB(jabContext=jabContext)
 
458
                if not obj:
 
459
                        return
333
460
        eventHandler.queueEvent("stateChange",obj)
334
461
 
335
 
@CFUNCTYPE(None,c_int,c_int,c_int,c_int,c_int)
 
462
@AccessBridge_PropertyCaretChangeFP
336
463
def internal_event_caretChange(vmID, event,source,oldPos,newPos):
337
464
        if oldPos<0 and newPos>=0:
338
465
                internalQueueFunction(event_gainFocus,vmID,source)
340
467
 
341
468
def event_enterJavaWindow(hwnd):
342
469
        vmID=c_int()
343
 
        accContext=c_int()
 
470
        accContext=JOBJECT64()
344
471
        try:
345
472
                bridgeDll.getAccessibleContextFromHWND(hwnd,byref(vmID),byref(accContext))
346
473
        except:
347
474
                return
348
 
        vmIDsToWindowHandles[vmID.value]=hwnd
 
475
        vmID=vmID.value
 
476
        vmIDsToWindowHandles[vmID]=hwnd
349
477
        lastFocus=eventHandler.lastQueuedFocusObject
350
478
        if isinstance(lastFocus,NVDAObjects.JAB.JAB) and lastFocus.windowHandle==hwnd:
351
479
                return
352
 
        internalQueueFunction(event_gainFocus,vmID.value,accContext.value)
 
480
        internalQueueFunction(event_gainFocus,vmID,accContext)
353
481
 
354
482
def isJavaWindow(hwnd):
355
 
        if not isRunning:
 
483
        if not bridgeDll or not isRunning:
356
484
                return False
357
485
        return bridgeDll.isJavaWindow(hwnd)
358
486
 
359
 
def _errcheck(res, func, args):
360
 
        if not res:
361
 
                raise RuntimeError("Result %d" % res)
362
 
 
363
487
def initialize():
364
 
        global bridgeDll, isRunning
365
 
        try:
366
 
                bridgeDll=cdll.WINDOWSACCESSBRIDGE
367
 
                for func in (
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, 
373
 
                ):
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):
 
488
        global isRunning
 
489
        if not bridgeDll:
 
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):
 
496
                        raise WinError()
 
497
                for msg in xrange(winUser.WM_USER+1,65535):
 
498
                        if not ChangeWindowMessageFilter(msg,1):
380
499
                                raise WinError()
381
 
                        for msg in xrange(winUser.WM_USER+1,65535):
382
 
                                if not ChangeWindowMessageFilter(msg,1):
383
 
                                        raise WinError()
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)
389
 
                isRunning=True
390
 
                return True
391
 
        except:
392
 
                log.debugWarning("Error initializing java access bridge",exc_info=True)
393
 
                return False
 
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)
 
505
        isRunning=True
394
506
 
395
507
def pumpAll():
396
508
        if isRunning: 
398
510
 
399
511
def terminate():
400
512
        global isRunning, bridgeDll
401
 
        if not isRunning:
 
513
        if not bridgeDll or not isRunning:
402
514
                return
403
515
        bridgeDll.setFocusGainedFP(None)
404
516
        bridgeDll.setPropertyActiveDescendentChangeFP(None)
405
517
        bridgeDll.setPropertyStateChangeFP(None)
406
518
        bridgeDll.setPropertyCaretChangeFP(None)
407
 
        windll.kernel32.FreeLibrary(bridgeDll._handle)
408
 
        cdll.WINDOWSACCESSBRIDGE=bridgeDll=None
 
519
        h=bridgeDll._handle
 
520
        bridgeDll=None
 
521
        if legacyAccessBridge:
 
522
                del cdll.windowsAccessBridge 
 
523
        else:
 
524
                delattr(cdll,'windowsAccessBridge-32')
 
525
        windll.kernel32.FreeLibrary(h)
409
526
        isRunning=False