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
@@ -161,6 +161,12 @@ class getTextLengthExStruct(ctypes.Structure):
161161WB_LEFTBREAK = 6
162162WB_RIGHTBREAK = 7
163163
164+ # Color index for GetSystemColor
165+ # See https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getsyscolor
166+ SC_COLOR_WINDOW = 5
167+ SC_COLOR_WINDOWTEXT = 8
168+
169+
164170class EditTextInfo (textInfos .offsets .OffsetsTextInfo ):
165171
166172 def _getPointFromOffset (self ,offset ):
@@ -282,8 +288,16 @@ def _getFormatFieldAndOffsets(self,offset,formatConfig,calculateOffsets=True):
282288 formatField ["text-position" ] = TextPosition .BASELINE
283289 if formatConfig ["reportColor" ]:
284290 if charFormat is None : charFormat = self ._getCharFormat (offset )
285- formatField ["color" ]= colors .RGB .fromCOLORREF (charFormat .crTextColor ) if not charFormat .dwEffects & CFE_AUTOCOLOR else _ ("default color" )
286- formatField ["background-color" ]= colors .RGB .fromCOLORREF (charFormat .crBackColor ) if not charFormat .dwEffects & CFE_AUTOBACKCOLOR else _ ("default color" )
291+ if charFormat .dwEffects & CFE_AUTOCOLOR :
292+ rgb = winUser .user32 .GetSysColor (SC_COLOR_WINDOWTEXT )
293+ else :
294+ rgb = charFormat .crTextColor
295+ formatField ["color" ] = colors .RGB .fromCOLORREF (rgb )
296+ if charFormat .dwEffects & CFE_AUTOBACKCOLOR :
297+ rgb = winUser .user32 .GetSysColor (SC_COLOR_WINDOW )
298+ else :
299+ rgb = charFormat .crBackColor
300+ formatField ["background-color" ] = colors .RGB .fromCOLORREF (rgb )
287301 if formatConfig ["reportLineNumber" ]:
288302 formatField ["line-number" ]= self ._getLineNumFromOffset (offset )+ 1
289303 if formatConfig ["reportLinks" ]:
@@ -536,8 +550,7 @@ def _getFormatFieldAtRange(self, textRange, formatConfig):
536550 fontObj = textRange .font
537551 fgColor = fontObj .foreColor
538552 if fgColor == comInterfaces .tom .tomAutoColor :
539- # Translators: The default color of text when a color has not been set by the author.
540- formatField ['color' ]= _ ("default color" )
553+ formatField ['color' ] = colors .RGB .fromCOLORREF (winUser .user32 .GetSysColor (SC_COLOR_WINDOWTEXT ))
541554 elif fgColor & 0xff000000 :
542555 # The color is a palet index (we don't know the palet)
543556 # Translators: The color of text cannot be detected.
@@ -546,8 +559,7 @@ def _getFormatFieldAtRange(self, textRange, formatConfig):
546559 formatField ["color" ]= colors .RGB .fromCOLORREF (fgColor )
547560 bkColor = fontObj .backColor
548561 if bkColor == comInterfaces .tom .tomAutoColor :
549- # Translators: The default background color when a color has not been set by the author.
550- formatField ['background-color' ]= _ ("default color" )
562+ formatField ['background-color' ] = colors .RGB .fromCOLORREF (winUser .user32 .GetSysColor (SC_COLOR_WINDOW ))
551563 elif bkColor & 0xff000000 :
552564 # The color is a palet index (we don't know the palet)
553565 # Translators: The background color cannot be detected.
0 commit comments