Skip to content

Commit

Permalink
Merge branch 'master' into moreLinks
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrilleB79 committed Nov 26, 2024
2 parents de9e73a + 16cbc6f commit b37470b
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
79 changes: 79 additions & 0 deletions source/NVDAObjects/window/winword.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import colorsys
import eventHandler
import braille
import scriptHandler
from scriptHandler import script
import languageHandler
import ui
Expand Down Expand Up @@ -267,6 +268,54 @@ def _displayStringLabels(self) -> dict[Self, str]:
wdThemeColorText1 = 13
wdThemeColorText2 = 15


class WdCharacterCase(DisplayStringIntEnum):
# Word enumeration that specifies the case of the text in the specified range.
# See https://docs.microsoft.com/en-us/office/vba/api/word.wdcharactercase

# No case: Returned when the selection range contains only case-insensitive characters.
# Note: MS also uses it as a command for "next case" (Toggles between uppercase, lowercase, and sentence
# case).
NO_CASE = -1
LOWER_CASE = 0
UPPER_CASE = 1
TITLE_WORD = 2
TITLE_SENTENCE = 4
# Mixed case: Unorganized mix of lower and upper case.
# Note: MS also uses it as a command for toggle case (Switches uppercase characters to lowercase, and
# lowercase characters to uppercase)
MIXED_CASE = 5
HALF_WIDTH = 6 # Used for Japanese characters.
FULL_WIDTH = 7 # Used for Japanese characters.
KATAKANA = 8 # Used with Japanese text.
HIRAGANA = 9 # Used with Japanese text.

@property
def _displayStringLabels(self) -> dict[Self, str]:
return {
# Translators: a Microsoft Word character case type
WdCharacterCase.NO_CASE: _("No case"),
# Translators: a Microsoft Word character case type
WdCharacterCase.LOWER_CASE: _("Lowercase"),
# Translators: a Microsoft Word character case type
WdCharacterCase.UPPER_CASE: _("Uppercase"),
# Translators: a Microsoft Word character case type
WdCharacterCase.TITLE_WORD: _("Each word capitalized"),
# Translators: a Microsoft Word character case type
WdCharacterCase.TITLE_SENTENCE: _("Sentence case"),
# Translators: a Microsoft Word character case type
WdCharacterCase.MIXED_CASE: _("Mixed case"),
# Translators: a Microsoft Word character case type
WdCharacterCase.HALF_WIDTH: _("Half width"),
# Translators: a Microsoft Word character case type
WdCharacterCase.FULL_WIDTH: _("Full width"),
# Translators: a Microsoft Word character case type
WdCharacterCase.KATAKANA: _("Katakana"),
# Translators: a Microsoft Word character case type
WdCharacterCase.HIRAGANA: _("Hiragana"),
}


# Word Field types
FIELD_TYPE_REF = 3 # cross reference field
FIELD_TYPE_HYPERLINK = 88 # hyperlink field
Expand Down Expand Up @@ -1698,6 +1747,34 @@ def script_toggleCaps(self, gesture: "inputCore.InputGesture"):
# Translators: a message when toggling formatting to 'No capital' in Microsoft word
ui.message(_("Caps off"))

@script(gesture="kb:shift+f3")
def script_changeCase(self, gesture: "inputCore.InputGesture"):
if (
# We cannot fetch the Word object model, so we therefore cannot report the format change.
# The object model may be unavailable because this is a pure UIA implementation such as Windows 10 Mail,
# or its within Windows Defender Application Guard.
not self.WinwordSelectionObject
# Or we do not want to apply the delay due in case of multipe repetition of the script.
or scriptHandler.isScriptWaiting()
):
# Just let the gesture through and don't report anything.
return gesture.send()

def action():
gesture.send()
# The object model for the "case" property is not fully reliable when using switch case command. During
# the switch, the "case" property quickly transitions through "lower case" or "no case", especially in
# Outlook. Thus we artificially add an empirical delay after the gesture has been send and before the
# first check.
time.sleep(0.15)

val = self._WaitForValueChangeForAction(
action=action,
fetcher=lambda: self.WinwordSelectionObject.Range.Case,
)
# Translators: a message when changing case in Microsoft Word
ui.message(WdCharacterCase(val).displayString)

@script(gestures=["kb:control+l", "kb:control+e", "kb:control+r", "kb:control+j"])
def script_toggleAlignment(self, gesture):
if not self.WinwordSelectionObject:
Expand Down Expand Up @@ -1976,6 +2053,8 @@ def initOverlayClass(self):
self.bindGesture("kb:alt+shift+end", "caret_changeSelection")
self.bindGesture("kb:alt+shift+pageUp", "caret_changeSelection")
self.bindGesture("kb:alt+shift+pageDown", "caret_changeSelection")
self.bindGesture("kb:f8", "caret_changeSelection")
self.bindGesture("kb:shift+f8", "caret_changeSelection")

__gestures = {
"kb:control+pageUp": "caret_moveByLine",
Expand Down
4 changes: 4 additions & 0 deletions source/appModules/outlook.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,10 @@ def _get_role(self):
True # This includes page sections, and page columns. None of which are appropriate for outlook.
)

__gestures = {
"kb:control+shift+a": "changeCase",
}


class OutlookUIAWordDocument(UIAWordDocument, BaseOutlookWordDocument):
"""Forces browse mode to be used on the UI Automation Outlook message viewer if the message is being read)."""
Expand Down
1 change: 1 addition & 0 deletions user_docs/en/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ To use this feature, "allow NVDA to control the volume of other applications" mu
* When toggling double underline in LibreOffice Writer using the corresponding keyboard shortcut, NVDA announces the new state ("double underline on"/"double underline off"). (#6915, @michaelweghorn)
* Automatic language switching is now supported when using Microsoft Speech API version 5 (SAPI5) and Microsoft Speech Platform voices. (#17146, @gexgd0419)
* NVDA can now be configured to speak the current line or paragraph when navigating with braille navigation keys. (#17053, @nvdaes)
* In Word, the selection update is now reported when using Word commands to extend or reduce the selection (`f8` or `shift+f8`). (#3293, @CyrilleB79)

### Changes

Expand Down

0 comments on commit b37470b

Please sign in to comment.