From 17ec1d96a58924340751d1eb4beb2ba756d70cf4 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Wed, 4 Sep 2019 15:04:39 +0200 Subject: ui: syntax: xor colors with background This makes syntax highlighting retain text contrast on black background (e.g. high-contrast mode) Maybe using a smarter arithmetic than XOR could be used to retain errors in red. They turn cyan on black background now. Signed-off-by: Simon Rozman --- ui/syntax/syntaxedit.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ui/syntax/syntaxedit.c b/ui/syntax/syntaxedit.c index 0050af4c..921cc7b6 100644 --- a/ui/syntax/syntaxedit.c +++ b/ui/syntax/syntaxedit.c @@ -141,6 +141,7 @@ static void highlight_text(HWND hWnd) CHARRANGE orig_selection; POINT original_scroll; bool found_private_key = false; + COLORREF bg_color, bg_inversion; if (this->highlight_guard) return; @@ -175,10 +176,13 @@ static void highlight_text(HWND hWnd) SendMessage(hWnd, EM_GETSCROLLPOS, 0, (LPARAM)&original_scroll); SendMessage(hWnd, EM_HIDESELECTION, TRUE, 0); SendMessage(hWnd, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&format); + bg_color = GetSysColor(COLOR_WINDOW); + bg_inversion = (bg_color & RGB(0xFF, 0xFF, 0xFF)) ^ RGB(0xFF, 0xFF, 0xFF); + SendMessage(hWnd, EM_SETBKGNDCOLOR, 0, bg_color); for (struct highlight_span *span = spans; span->type != HighlightEnd; ++span) { CHARRANGE selection = { span->start, span->len + span->start }; SendMessage(hWnd, EM_EXSETSEL, 0, (LPARAM)&selection); - format.crTextColor = stylemap[span->type].color; + format.crTextColor = stylemap[span->type].color ^ bg_inversion; format.dwEffects = stylemap[span->type].effects; SendMessage(hWnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format); if (span->type == HighlightPrivateKey && !found_private_key) { @@ -354,6 +358,9 @@ static LRESULT CALLBACK child_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lP case WM_CONTEXTMENU: context_menu(hWnd, LOWORD(lParam), HIWORD(lParam)); return 0; + case WM_THEMECHANGED: + highlight_text(hWnd); + break; } return parent_proc(hWnd, Msg, wParam, lParam); } -- cgit v1.2.3-59-g8ed1b