|
1 | 1 | # A part of NonVisual Desktop Access (NVDA) |
2 | | -# Copyright (C) 2008-2021 NV Access Limited, Joseph Lee, Babbage B.V., Leonard de Ruijter, Bill Dengler |
| 2 | +# Copyright (C) 2008-2022 NV Access Limited, Joseph Lee, Babbage B.V., Leonard de Ruijter, Bill Dengler |
3 | 3 | # This file is covered by the GNU General Public License. |
4 | 4 | # See the file COPYING for more details. |
5 | 5 |
|
|
99 | 99 | "Shell_SystemDialog", # Various dialogs in Windows 10 Settings app |
100 | 100 | ] |
101 | 101 |
|
| 102 | +textChangeUIAClassNames = ( |
| 103 | + "_WwG", |
| 104 | + "ConsoleWindowClass", |
| 105 | + "TermControl", |
| 106 | + "TermControl2" |
| 107 | +) |
| 108 | + |
102 | 109 | NVDAUnitsToUIAUnits: Dict[str, int] = { |
103 | 110 | textInfos.UNIT_CHARACTER: UIA.TextUnit_Character, |
104 | 111 | textInfos.UNIT_WORD: UIA.TextUnit_Word, |
|
206 | 213 | autoSelectDetectionAvailable = False |
207 | 214 | if winVersion.getWinVer() >= winVersion.WIN10: |
208 | 215 | UIAEventIdsToNVDAEventNames.update({ |
209 | | - UIA.UIA_Text_TextChangedEventId: "textChange", |
210 | 216 | UIA.UIA_Text_TextSelectionChangedEventId: "caret", |
211 | 217 | }) |
212 | 218 | localEventHandlerGroupUIAEventIds.update({ |
213 | | - UIA.UIA_Text_TextChangedEventId, |
214 | 219 | UIA.UIA_Text_TextSelectionChangedEventId, |
215 | 220 | }) |
216 | 221 | autoSelectDetectionAvailable = True |
@@ -421,21 +426,41 @@ def _registerGlobalEventHandlers(self): |
421 | 426 | def _createLocalEventHandlerGroup(self): |
422 | 427 | if isinstance(self.clientObject, UIA.IUIAutomation6): |
423 | 428 | self.localEventHandlerGroup = self.clientObject.CreateEventHandlerGroup() |
| 429 | + self.localEventHandlerGroupWithTextChanges = self.clientObject.CreateEventHandlerGroup() |
424 | 430 | else: |
425 | 431 | self.localEventHandlerGroup = utils.FakeEventHandlerGroup(self.clientObject) |
| 432 | + self.localEventHandlerGroupWithTextChanges = utils.FakeEventHandlerGroup(self.clientObject) |
426 | 433 | self.localEventHandlerGroup.AddPropertyChangedEventHandler( |
427 | 434 | UIA.TreeScope_Ancestors | UIA.TreeScope_Element, |
428 | 435 | self.baseCacheRequest, |
429 | 436 | self, |
430 | 437 | *self.clientObject.IntSafeArrayToNativeArray(localEventHandlerGroupUIAPropertyIds) |
431 | 438 | ) |
| 439 | + self.localEventHandlerGroupWithTextChanges.AddPropertyChangedEventHandler( |
| 440 | + UIA.TreeScope_Ancestors | UIA.TreeScope_Element, |
| 441 | + self.baseCacheRequest, |
| 442 | + self, |
| 443 | + *self.clientObject.IntSafeArrayToNativeArray(localEventHandlerGroupUIAPropertyIds) |
| 444 | + ) |
432 | 445 | for eventId in localEventHandlerGroupUIAEventIds: |
433 | 446 | self.localEventHandlerGroup.AddAutomationEventHandler( |
434 | 447 | eventId, |
435 | 448 | UIA.TreeScope_Ancestors | UIA.TreeScope_Element, |
436 | 449 | self.baseCacheRequest, |
437 | 450 | self |
438 | 451 | ) |
| 452 | + self.localEventHandlerGroupWithTextChanges.AddAutomationEventHandler( |
| 453 | + eventId, |
| 454 | + UIA.TreeScope_Ancestors | UIA.TreeScope_Element, |
| 455 | + self.baseCacheRequest, |
| 456 | + self |
| 457 | + ) |
| 458 | + self.localEventHandlerGroupWithTextChanges.AddAutomationEventHandler( |
| 459 | + UIA.UIA_Text_TextChangedEventId, |
| 460 | + UIA.TreeScope_Ancestors | UIA.TreeScope_Element, |
| 461 | + self.baseCacheRequest, |
| 462 | + self |
| 463 | + ) |
439 | 464 |
|
440 | 465 | def addEventHandlerGroup(self, element, eventHandlerGroup): |
441 | 466 | if isinstance(eventHandlerGroup, UIA.IUIAutomationEventHandlerGroup): |
@@ -466,7 +491,12 @@ def func(): |
466 | 491 | if not isStillFocus: |
467 | 492 | return |
468 | 493 | try: |
469 | | - self.addEventHandlerGroup(element, self.localEventHandlerGroup) |
| 494 | + group = ( |
| 495 | + self.localEventHandlerGroupWithTextChanges |
| 496 | + if element.currentClassName in textChangeUIAClassNames |
| 497 | + else self.localEventHandlerGroup |
| 498 | + ) |
| 499 | + self.addEventHandlerGroup(element, group) |
470 | 500 | except COMError: |
471 | 501 | log.error("Could not register for UIA events for element", exc_info=True) |
472 | 502 | else: |
@@ -500,7 +530,15 @@ def IUIAutomationEventHandler_HandleAutomationEvent(self,sender,eventID): |
500 | 530 | if _isDebug(): |
501 | 531 | log.debug("HandleAutomationEvent: Ignored MenuOpenedEvent while focus event pending") |
502 | 532 | return |
503 | | - NVDAEventName=UIAEventIdsToNVDAEventNames.get(eventID,None) |
| 533 | + if eventID == UIA.UIA_Text_TextChangedEventId: |
| 534 | + if sender.currentClassName in textChangeUIAClassNames: |
| 535 | + NVDAEventName = "textChange" |
| 536 | + else: |
| 537 | + if _isDebug(): |
| 538 | + log.debugWarning(f"HandleAutomationEvent: Dropping unused textChange event") |
| 539 | + return |
| 540 | + else: |
| 541 | + NVDAEventName = UIAEventIdsToNVDAEventNames.get(eventID, None) |
504 | 542 | if not NVDAEventName: |
505 | 543 | if _isDebug(): |
506 | 544 | log.debugWarning(f"HandleAutomationEvent: Don't know how to handle event {eventID}") |
|
0 commit comments