1717import sayAllHandler
1818import eventHandler
1919import braille
20- from scriptHandler import script
20+ from scriptHandler import script , getLastScriptRepeatCount
2121import languageHandler
2222import ui
2323import NVDAHelper
7373wdMaximumNumberOfRows = 15
7474wdStartOfRangeColumnNumber = 16
7575wdMaximumNumberOfColumns = 18
76+
77+ # Underline style
78+ wdUnderlineNone = 0
79+ wdUnderlineSingle = 1
80+ wdUnderlineWords = 2
81+ wdUnderlineDouble = 3
82+ wdUnderlineDotted = 4
83+ wdUnderlineThick = 6
84+ wdUnderlineDash = 7
85+ wdUnderlineDotDash = 9
86+ wdUnderlineDotDotDash = 10
87+ wdUnderlineWavy = 11
88+ wdUnderlineDottedHeavy = 20
89+ wdUnderlineDashHeavy = 23
90+ wdUnderlineDotDashHeavy = 25
91+ wdUnderlineDotDotDashHeavy = 26
92+ wdUnderlineWavyHeavy = 27
93+ wdUnderlineDashLong = 39
94+ wdUnderlineWavyDouble = 43
95+ wdUnderlineDashLongHeavy = 55
96+
7697#Horizontal alignment
7798wdAlignParagraphLeft = 0
7899wdAlignParagraphCenter = 1
195216wdThemeColorText1 = 13
196217wdThemeColorText2 = 15
197218
219+ # WdCharacterCase enumeration
220+ wdNextCase = - 1
221+ wdLowerCase = 0
222+ wdUpperCase = 1
223+ wdTitleWord = 2
224+ wdTitleSentence = 4
225+ wdToggleCase = 5
226+ wdHalfWidth = 6
227+ wdFullWidth = 7
228+ wdKatakana = 8
229+ wdHiragana = 9
230+
198231# Word Field types
199232FIELD_TYPE_REF = 3 # cross reference field
200233FIELD_TYPE_HYPERLINK = 88 # hyperlink field
258291 wdRevisionCellMerge :_ ("cell merge" ),
259292}
260293
294+ wdUnderlineTypeDescriptions = {
295+ # Translators: an underline style in Microsoft Word as announced in the font window.
296+ wdUnderlineSingle : _ ("Single" ),
297+ # Translators: an underline style in Microsoft Word as announced in the font window.
298+ wdUnderlineWords : _ ("Words only" ),
299+ # Translators: an underline style in Microsoft Word as announced in the font window.
300+ wdUnderlineDouble : _ ("Double" ),
301+ # Translators: an underline style in Microsoft Word as announced in the font window.
302+ wdUnderlineDotted : _ ("Dotted" ),
303+ # Translators: an underline style in Microsoft Word as announced in the font window.
304+ wdUnderlineThick : _ ("Thick" ),
305+ # Translators: an underline style in Microsoft Word as announced in the font window.
306+ wdUnderlineDash : _ ("Dash" ),
307+ # Translators: an underline style in Microsoft Word as announced in the font window.
308+ wdUnderlineDotDash : _ ("Dot dash" ),
309+ # Translators: an underline style in Microsoft Word as announced in the font window.
310+ wdUnderlineDotDotDash : _ ("Dot dot dash" ),
311+ # Translators: an underline style in Microsoft Word as announced in the font window.
312+ wdUnderlineWavy : _ ("Wave" ),
313+ # Translators: an underline style in Microsoft Word as announced in the font window.
314+ wdUnderlineDottedHeavy : _ ("Dotted heavy" ),
315+ # Translators: an underline style in Microsoft Word as announced in the font window.
316+ wdUnderlineDashHeavy : _ ("Dashed heavy" ),
317+ # Translators: an underline style in Microsoft Word as announced in the font window.
318+ wdUnderlineDotDashHeavy : _ ("Dot dash heavy" ),
319+ # Translators: an underline style in Microsoft Word as announced in the font window.
320+ wdUnderlineDotDotDashHeavy : _ ("Dot dot dash heavy" ),
321+ # Translators: an underline style in Microsoft Word as announced in the font window.
322+ wdUnderlineWavyHeavy : _ ("Wave heavy" ),
323+ # Translators: an underline style in Microsoft Word as announced in the font window.
324+ wdUnderlineDashLong : _ ("Dashed long" ),
325+ # Translators: an underline style in Microsoft Word as announced in the font window.
326+ wdUnderlineWavyDouble : _ ("Wave double" ),
327+ # Translators: an underline style in Microsoft Word as announced in the font window.
328+ wdUnderlineDashLongHeavy : _ ("Dashed long heavy" ),
329+ }
330+
261331storyTypeLocalizedLabels = {
262332 wdCommentsStory :_ ("Comments" ),
263333 wdEndnotesStory :_ ("Endnotes" ),
271341 wdTextFrameStory :_ ("Text frame" ),
272342}
273343
344+ wdCharacterCaseTypeLabels = {
345+ # Translators: a Microsoft Word character case type
346+ wdNextCase : _ ("No case" ), # Returned when selection range contains only case-insensitive characters
347+ # Translators: a Microsoft Word character case type
348+ wdLowerCase : _ ("Lowercase" ),
349+ # Translators: a Microsoft Word character case type
350+ wdUpperCase : _ ("Uppercase" ),
351+ # Translators: a Microsoft Word character case type
352+ wdTitleWord : _ ("Each word capitalized" ),
353+ # Translators: a Microsoft Word character case type
354+ wdTitleSentence : _ ("Sentence case" ),
355+ # Translators: a Microsoft Word character case type
356+ wdToggleCase : _ ("Mixed case" ),
357+ # Translators: a Microsoft Word character case type
358+ wdHalfWidth : _ ("Half width:" ),
359+ # Translators: a Microsoft Word character case type
360+ wdFullWidth : _ ("Full width" ),
361+ # Translators: a Microsoft Word character case type
362+ wdKatakana : _ ("Katakana" ),
363+ # Translators: a Microsoft Word character case type
364+ wdHiragana : _ ("Hiragana" ),
365+ }
366+
274367wdFieldTypesToNVDARoles = {
275368 wdFieldFormTextInput :controlTypes .ROLE_EDITABLETEXT ,
276369 wdFieldFormCheckBox :controlTypes .ROLE_CHECKBOX ,
@@ -1228,6 +1321,7 @@ def _WaitForValueChangeForAction(self,action,fetcher,timeout=0.15):
12281321 curTime = time .time ()
12291322 return curVal
12301323
1324+ @script (gestures = ["kb:control+b" , "kb:control+shift+b" ])
12311325 def script_toggleBold (self ,gesture ):
12321326 if not self .WinwordSelectionObject :
12331327 # We cannot fetch the Word object model, so we therefore cannot report the format change.
@@ -1242,6 +1336,7 @@ def script_toggleBold(self,gesture):
12421336 # Translators: a message when toggling formatting in Microsoft word
12431337 ui .message (_ ("Bold off" ))
12441338
1339+ @script (gestures = ["kb:control+i" , "kb:control+shift+i" ])
12451340 def script_toggleItalic (self ,gesture ):
12461341 if not self .WinwordSelectionObject :
12471342 # We cannot fetch the Word object model, so we therefore cannot report the format change.
@@ -1256,16 +1351,24 @@ def script_toggleItalic(self,gesture):
12561351 # Translators: a message when toggling formatting in Microsoft word
12571352 ui .message (_ ("Italic off" ))
12581353
1259- def script_toggleUnderline (self ,gesture ):
1354+ @script (gestures = ["kb:control+u" , "kb:control+shift+u" , "kb:control+shift+d" , "kb:control+shift+w" ])
1355+ def script_toggleUnderline (self , gesture ):
12601356 if not self .WinwordSelectionObject :
12611357 # We cannot fetch the Word object model, so we therefore cannot report the format change.
1262- # 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.
1263- # Eventually UIA will have its own way of detecting format changes at the cursor. For now, just let the gesture through and don't erport anything.
1358+ # The object model may be unavailable because this is a pure UIA implementation such as Windows 10 Mail,
1359+ # or its within Windows Defender Application Guard.
1360+ # Eventually UIA will have its own way of detecting format changes at the cursor.
1361+ # For now, just let the gesture through and don't report anything.
12641362 return gesture .send ()
1265- val = self ._WaitForValueChangeForAction (lambda : gesture .send (),lambda : self .WinwordSelectionObject .font .underline )
1266- if val :
1267- # Translators: a message when toggling formatting in Microsoft word
1268- ui .message (_ ("Underline on" ))
1363+ val = self ._WaitForValueChangeForAction (
1364+ lambda : gesture .send (),
1365+ lambda : self .WinwordSelectionObject .font .underline
1366+ )
1367+ if val != wdUnderlineNone :
1368+ msg = wdUnderlineTypeDescriptions .get (val )
1369+ if msg :
1370+ # Translators: a message when toggling formatting in Microsoft word
1371+ ui .message (_ ("Underline {style}" ).format (style = msg ))
12691372 else :
12701373 # Translators: a message when toggling formatting in Microsoft word
12711374 ui .message (_ ("Underline off" ))
@@ -1291,6 +1394,51 @@ def script_toggleAlignment(self,gesture):
12911394 if msg :
12921395 ui .message (msg )
12931396
1397+ @script (gestures = ["kb:control+shift+a" , "kb:control+shift+k" ])
1398+ def script_toggleCaps (self , gesture ):
1399+ if not self .WinwordSelectionObject :
1400+ # We cannot fetch the Word object model, so we therefore cannot report the format change.
1401+ # The object model may be unavailable because this is a pure UIA implementation such as Windows 10 Mail,
1402+ # or its within Windows Defender Application Guard.
1403+ # Eventually UIA will have its own way of detecting format changes at the cursor.
1404+ # For now, just let the gesture through and don't report anything.
1405+ return gesture .send ()
1406+ val = self ._WaitForValueChangeForAction (
1407+ lambda : gesture .send (),
1408+ lambda : (self .WinwordSelectionObject .font .allcaps , self .WinwordSelectionObject .font .smallcaps )
1409+ )
1410+ if val [0 ]:
1411+ # Translators: a message when toggling formatting to 'all capital' in Microsoft word
1412+ ui .message (_ ("All caps on" ))
1413+ elif val [1 ]:
1414+ # Translators: a message when toggling formatting to 'small capital' in Microsoft word
1415+ ui .message (_ ("Small caps on" ))
1416+ else :
1417+ # Translators: a message when toggling formatting to 'No capital' in Microsoft word
1418+ ui .message (_ ("Caps off" ))
1419+
1420+ @script (gesture = "kb:shift+f3" )
1421+ def script_changeCase (self , gesture ):
1422+ if not self .WinwordSelectionObject :
1423+ # We cannot fetch the Word object model, so we therefore cannot report the format change.
1424+ # The object model may be unavailable because this is a pure UIA implementation such as Windows 10 Mail,
1425+ # or its within Windows Defender Application Guard.
1426+ # For now, just let the gesture through and don't report anything.
1427+ return gesture .send ()
1428+ val = self ._WaitForValueChangeForAction (
1429+ lambda : gesture .send (),
1430+ lambda : self .WinwordSelectionObject .Range .Case
1431+ )
1432+ # Under Outlook, calling the script quickly a second time gives strange results.
1433+ # Case value passes sometimes through an intermediate value.
1434+ # So poll the value a second time.
1435+ val = self ._WaitForValueChangeForAction (
1436+ lambda : None ,
1437+ lambda : self .WinwordSelectionObject .Range .Case
1438+ )
1439+ # Translators: a message when changing case in Microsoft Word
1440+ ui .message (wdCharacterCaseTypeLabels .get (val ))
1441+
12941442 def script_toggleSuperscriptSubscript (self ,gesture ):
12951443 if not self .WinwordSelectionObject :
12961444 # We cannot fetch the Word object model, so we therefore cannot report the format change.
@@ -1482,9 +1630,6 @@ def initOverlayClass(self):
14821630 "kb:control+]" :"increaseDecreaseFontSize" ,
14831631 "kb:control+shift+," :"increaseDecreaseFontSize" ,
14841632 "kb:control+shift+." :"increaseDecreaseFontSize" ,
1485- "kb:control+b" :"toggleBold" ,
1486- "kb:control+i" :"toggleItalic" ,
1487- "kb:control+u" :"toggleUnderline" ,
14881633 "kb:control+=" :"toggleSuperscriptSubscript" ,
14891634 "kb:control+shift+=" :"toggleSuperscriptSubscript" ,
14901635 "kb:control+l" :"toggleAlignment" ,
0 commit comments