Windows 10/11 Calculator: refactor results announcement with UIA notification event (#13625)
Link to issue number:
Fixes #13383
Summary of the issue:
With the initial version of Windows 10/11 Calculator app module, only a select number of keys were defined to announce results. However it turns out there are commands that should be announced such as equals (=) and scientific calculator commands such as s (sign).
Description of how this pull request fixes the issue:
Refactor UIA notification event handler with use of a new flag specifying gestures that should not announce results. If this flag is on (for now when number keys are pressed), NVDA will not announce results. Also, existing result announcement commands will not announce results in Calculator version 10.1908 as notification event will announce result.
* appModules/calculator: explain the fact that Windows 10 Calculator is the base app module for Windows 11 Calculator (calculatorapp) as well.
* Calculator: introduce a 'no result gestures' flag. Re #13383.
In recent Calculator releases (prominently from 10.1908 but exact version unknown), UIA notification event is used to anounce results. Back when Calculator used name change and live region events, it was necessary to define result announcement keys such as Enter key that will cause NVDA to announce results. With the introduction of UIA notification event, the new event is used to announce results. This resulted in NVDA announcing repeats when numbers were entered, more so if speak typed characters is on.
In the initial version of Windows 10 Calculator app module (2020) and subsequently amended in 2021, only a select number of keyboard commands (gestures) were defined to announce results. This however led to NVDA not announcing Calculator display when additional result keys such as equals (=) and scientific calculator commands such as S for sine were pressed, requiring users to perform read current line/focused object to obtain results. To resolve this and to respond to UIA notification events properly while keeping the number entry bug fix intact, a new flag is used to preventNVDA from handling notification event if number row and/or numpad keys with num lock on are pressed. This flag is set if number keys are indeed entered and cleared from notification event (next set of commits). In addition, existing result announcement commands wil be tweaked to do nothing if using later Calculator releases since notification event is used to announce resuts anyway (this means verbosity changes such as NVDA not announcing display content if Escape key is pressed multiple times, for example). Note that the new flag (no result gestures) should not be confused with existing 'should announce results' flag as the existing flag is used to handle old Calculator releases with no support for notification event.
* Calculator: do not announce Calculator display content if no result gestures are pressed. Re #13383.
Do not handle UIA notification event if no result gestures flag is set in order to avoid repetitions. As the flag is set from a script (see next commit), have a copy of this flag before clearing the flag from notification event. The event handler copy of the no results flag will be used later when handling 'DisplayUpdated' activity Id (results display), and if set, return from the event handler.
* Calculator: add a script identifying no result announcement gestures. Re #13383.
In addition to notification event handler tweak, add a script that defines gestures for which NVDA should not announce Calculator results. For now number row and numpad keys with num lock turned on are defined specifically to keep no repetition announcement bug fix intact (where NVDA will repeat things if speak typed characters is on).
* Calculator: return from announcing results if this is Calculator version 10.1908 and later. Re #13383.
Bonus: becasue UIA notification event is used to announce results, there is no need for NVDA to check focus in app version 10.1908 and later. Therefore return early from existing results announcement script if running on later Calculator releases (version string comparison will work).
* Calculator: use integer comparisons for versions. Re #13383.
Comment from Sean Budd (NV Access): better not to use string comparisons (what if comparisons fail for odd Calculator version strings that does not necessarily fit what humans think of newer releases versus what Python gives). Therefore obtain integers for major and minor Calculator releases and compare versions accordingly (integer list comparison).
* update changes
Co-authored-by: Sean Budd <sean@nvaccess.org>