Skip to content

Commit becfe66

Browse files
authored
Merge 77810d6 into 7948008
2 parents 7948008 + 77810d6 commit becfe66

6 files changed

Lines changed: 83 additions & 15 deletions

File tree

source/NVDAObjects/window/edit.py

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# A part of NonVisual Desktop Access (NVDA)
2-
# Copyright (C) 2006-2022 NV Access Limited, Babbage B.V.
2+
# Copyright (C) 2006-2022 NV Access Limited, Babbage B.V., Cyrille Bougot
33
# This file is covered by the GNU General Public License.
44
# See the file COPYING for more details.
55

@@ -22,6 +22,8 @@
2222
import winKernel
2323
import api
2424
import winUser
25+
from winAPI.winUser import GetSysColor
26+
from winAPI.winUser.constants import SysColorIndex
2527
import textInfos.offsets
2628
import controlTypes
2729
from controlTypes import TextPosition
@@ -153,6 +155,7 @@ class getTextLengthExStruct(ctypes.Structure):
153155
WB_LEFTBREAK=6
154156
WB_RIGHTBREAK=7
155157

158+
156159
class EditTextInfo(textInfos.offsets.OffsetsTextInfo):
157160

158161
def _getPointFromOffset(self,offset):
@@ -274,8 +277,24 @@ def _getFormatFieldAndOffsets(self,offset,formatConfig,calculateOffsets=True):
274277
formatField["text-position"] = TextPosition.BASELINE
275278
if formatConfig["reportColor"]:
276279
if charFormat is None: charFormat=self._getCharFormat(offset)
277-
formatField["color"]=colors.RGB.fromCOLORREF(charFormat.crTextColor) if not charFormat.dwEffects&CFE_AUTOCOLOR else _("default color")
278-
formatField["background-color"]=colors.RGB.fromCOLORREF(charFormat.crBackColor) if not charFormat.dwEffects&CFE_AUTOBACKCOLOR else _("default color")
280+
if charFormat.dwEffects & CFE_AUTOCOLOR:
281+
rgb = GetSysColor(SysColorIndex.WINDOW_TEXT)
282+
# Translators: The text color as reported in Wordpad (Automatic) or NVDA log viewer.
283+
formatField["color"] = _("{color} (default color)").format(
284+
color=colors.RGB.fromCOLORREF(rgb).name,
285+
)
286+
else:
287+
rgb = charFormat.crTextColor
288+
formatField["color"] = colors.RGB.fromCOLORREF(rgb)
289+
if charFormat.dwEffects & CFE_AUTOBACKCOLOR:
290+
rgb = GetSysColor(SysColorIndex.WINDOW)
291+
# Translators: The background color as reported in Wordpad (Automatic) or NVDA log viewer.
292+
formatField["background-color"] = _("{color} (default color)").format(
293+
color=colors.RGB.fromCOLORREF(rgb).name,
294+
)
295+
else:
296+
rgb = charFormat.crBackColor
297+
formatField["background-color"] = colors.RGB.fromCOLORREF(rgb)
279298
if formatConfig["reportLineNumber"]:
280299
formatField["line-number"]=self._getLineNumFromOffset(offset)+1
281300
if formatConfig["reportLinks"]:
@@ -529,8 +548,10 @@ def _getFormatFieldAtRange(self, textRange, formatConfig):
529548
fontObj = textRange.font
530549
fgColor=fontObj.foreColor
531550
if fgColor==comInterfaces.tom.tomAutoColor:
532-
# Translators: The default color of text when a color has not been set by the author.
533-
formatField['color']=_("default color")
551+
# Translators: The text color as reported in Wordpad (Automatic) or NVDA log viewer.
552+
formatField['color'] = _("{color} (default color)").format(
553+
color=colors.RGB.fromCOLORREF(GetSysColor(SysColorIndex.WINDOW_TEXT)).name,
554+
)
534555
elif fgColor&0xff000000:
535556
# The color is a palet index (we don't know the palet)
536557
# Translators: The color of text cannot be detected.
@@ -539,8 +560,10 @@ def _getFormatFieldAtRange(self, textRange, formatConfig):
539560
formatField["color"]=colors.RGB.fromCOLORREF(fgColor)
540561
bkColor=fontObj.backColor
541562
if bkColor==comInterfaces.tom.tomAutoColor:
542-
# Translators: The default background color when a color has not been set by the author.
543-
formatField['background-color']=_("default color")
563+
# Translators: The background color as reported in Wordpad (Automatic) or NVDA log viewer.
564+
formatField['background-color'] = _("{color} (default color)").format(
565+
color=colors.RGB.fromCOLORREF(GetSysColor(SysColorIndex.WINDOW)).name,
566+
)
544567
elif bkColor&0xff000000:
545568
# The color is a palet index (we don't know the palet)
546569
# Translators: The background color cannot be detected.

source/NVDAObjects/window/excel.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import gui
3434
import gui.contextHelp
3535
import winUser
36+
from winAPI.winUser import GetSysColor
37+
from winAPI.winUser.constants import SysColorIndex
3638
import mouseHandler
3739
from displayModel import DisplayModelTextInfo
3840
import controlTypes
@@ -1618,8 +1620,8 @@ def kwargsFromSuper(cls,kwargs,relation=None):
16181620
excelCell=None
16191621

16201622
def _get__highlightColors(self):
1621-
background=colors.RGB.fromCOLORREF(winUser.user32.GetSysColor(13))
1622-
foreground=colors.RGB.fromCOLORREF(winUser.user32.GetSysColor(14))
1623+
background = colors.RGB.fromCOLORREF(GetSysColor(SysColorIndex.HIGHLIGHT))
1624+
foreground = colors.RGB.fromCOLORREF(GetSysColor(SysColorIndex.HIGHLIGHT_TEXT))
16231625
self._highlightColors=(background,foreground)
16241626
return self._highlightColors
16251627

source/NVDAObjects/window/winword.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ def winwordColorToNVDAColor(self,val):
11871187
return colors.RGB.fromCOLORREF(val).name
11881188
elif (val&0xffffffff)==0xff000000:
11891189
# Translators: the default (automatic) color in Microsoft Word
1190-
return _("default color")
1190+
return _("automatic color")
11911191
elif ((val>>28)&0xf)==0xd and ((val>>16)&0xff)==0x00:
11921192
# An MS word color index Plus intencity
11931193
# Made up of MS Word Theme Color index, hsv value ratio (MS Word darker percentage) and hsv saturation ratio (MS Word lighter percentage)

source/displayModel.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# A part of NonVisual Desktop Access (NVDA)
22
# This file is covered by the GNU General Public License.
33
# See the file COPYING for more details.
4-
# Copyright (C) 2006-2022 NV Access Limited, Babbage B.V., Joseph Lee
4+
# Copyright (C) 2006-2022 NV Access Limited, Babbage B.V., Joseph Lee, Cyrille Bougot
55

66
import ctypes
77
from ctypes import *
@@ -12,6 +12,8 @@
1212
import XMLFormatting
1313
import api
1414
import winUser
15+
from winAPI.winUser import GetSysColor
16+
from winAPI.winUser.constants import SysColorIndex
1517
import mouseHandler
1618
import NVDAHelper
1719
import textInfos
@@ -256,11 +258,11 @@ class DisplayModelTextInfo(OffsetsTextInfo):
256258
includeDescendantWindows=True
257259

258260
def _get_backgroundSelectionColor(self):
259-
self.backgroundSelectionColor=colors.RGB.fromCOLORREF(winUser.user32.GetSysColor(13))
261+
self.backgroundSelectionColor = colors.RGB.fromCOLORREF(GetSysColor(SysColorIndex.HIGHLIGHT))
260262
return self.backgroundSelectionColor
261263

262264
def _get_foregroundSelectionColor(self):
263-
self.foregroundSelectionColor=colors.RGB.fromCOLORREF(winUser.user32.GetSysColor(14))
265+
self.foregroundSelectionColor = colors.RGB.fromCOLORREF(GetSysColor(SysColorIndex.HIGHLIGHT_TEXT))
264266
return self.foregroundSelectionColor
265267

266268
def _getSelectionOffsets(self):

source/winAPI/winUser/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
# A part of NonVisual Desktop Access (NVDA)
2-
# Copyright (C) 2022 NV Access Limited
2+
# Copyright (C) 2022 NV Access Limited, Cyrille Bougot
33
# This file is covered by the GNU General Public License.
44
# See the file COPYING for more details.
5+
6+
from ctypes import windll
7+
8+
9+
# dll handles
10+
user32 = windll.user32
11+
12+
13+
def GetSysColor(index: int):
14+
return user32.GetSysColor(index)

source/winAPI/winUser/constants.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# A part of NonVisual Desktop Access (NVDA)
2-
# Copyright (C) 2022 NV Access Limited
2+
# Copyright (C) 2022 NV Access Limited, Cyrille Bougot
33
# This file is covered by the GNU General Public License.
44
# See the file COPYING for more details.
55

@@ -60,3 +60,34 @@ class SystemMetrics(IntEnum):
6060
6161
SM_CYVIRTUALSCREEN
6262
"""
63+
64+
65+
class SysColorIndex(IntEnum):
66+
"""
67+
Color index to be used with GetSystemColor.
68+
See https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getsyscolor
69+
"""
70+
71+
WINDOW = 5
72+
"""
73+
Window background.
74+
The associated foreground colors are COLOR_WINDOWTEXT and COLOR_HOTLITE.
75+
"""
76+
77+
WINDOW_TEXT = 8
78+
"""
79+
Text in windows.
80+
The associated background color is COLOR_WINDOW.
81+
"""
82+
83+
HIGHLIGHT = 13
84+
"""
85+
Item(s) selected in a control.
86+
The associated foreground color is COLOR_HIGHLIGHTTEXT.
87+
"""
88+
89+
HIGHLIGHT_TEXT = 14
90+
"""
91+
Text of item(s) selected in a control.
92+
The associated background color is COLOR_HIGHLIGHT.
93+
"""

0 commit comments

Comments
 (0)