diff --git a/source/_UIAHandler.py b/source/_UIAHandler.py index 76e0047d0a3..e377a88c045 100644 --- a/source/_UIAHandler.py +++ b/source/_UIAHandler.py @@ -58,7 +58,6 @@ goodUIAWindowClassNames=[ # A WDAG (Windows Defender Application Guard) Window is always native UIA, even if it doesn't report as such. 'RAIL_WINDOW', - "EXCEL6", ] badUIAWindowClassNames=[ diff --git a/source/appModules/excel.py b/source/appModules/excel.py index afe6cac130e..adac3378961 100644 --- a/source/appModules/excel.py +++ b/source/appModules/excel.py @@ -5,6 +5,7 @@ # For more details see: https://www.gnu.org/licenses/gpl-2.0.html import time +import config import eventHandler import api import UIAHandler @@ -15,6 +16,8 @@ from NVDAObjects.window.edit import UnidentifiedEdit from NVDAObjects.window import Window from NVDAObjects.window.excel import ExcelCell +from NVDAObjects.IAccessible import IAccessible + class Excel6(Window): """ @@ -43,6 +46,17 @@ def _get_focusRedirect(self): self.focusRedirect=obj return obj + +class Excel6_WhenUIAEnabled(IAccessible): + """ + #12303: When accessing Microsoft Excel via UI Automation + MSAA focus events on the old formula edit window should be completely ignored. + UI Automation will fire its own ones. + """ + + shouldAllowIAccessibleFocusEvent = False + + class AppModule(appModuleHandler.AppModule): def chooseNVDAObjectOverlayClasses(self, obj, clsList): @@ -55,4 +69,14 @@ def chooseNVDAObjectOverlayClasses(self, obj, clsList): pass clsList.insert(0, DisplayModelEditableText) if windowClass=="EXCEL6": - clsList.insert(0,Excel6) + if config.conf["UIA"]["useInMSExcelWhenAvailable"]: + # #12303: When accessing Microsoft Excel via UI Automation + # MSAA focus events on the old formula edit window should be completely ignored. + # UI Automation will fire its own ones. + clsList.insert(0, Excel6_WhenUIAEnabled) + else: + # #12303: The old Formula Edit window in recent versions of Excel + # may not be accessible with display models as GDI is no longer used. + # However, UI Automation does expose an accessible edit control within the active cell, + # So use a class that will redirect focus to that. + clsList.insert(0, Excel6)