From f98e1cb9f0d401ff02f779906788d48a3fcdfd7c Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Thu, 16 May 2019 10:48:03 +0200 Subject: ui: react to DPI changes in syntax editor Signed-off-by: Jason A. Donenfeld --- ui/syntax/syntaxedit.c | 16 ++++++++++++---- ui/syntax/syntaxedit.go | 6 ++++++ ui/syntax/syntaxedit.h | 1 + 3 files changed, 19 insertions(+), 4 deletions(-) (limited to 'ui') diff --git a/ui/syntax/syntaxedit.c b/ui/syntax/syntaxedit.c index cf2d1b33..0050af4c 100644 --- a/ui/syntax/syntaxedit.c +++ b/ui/syntax/syntaxedit.c @@ -22,6 +22,7 @@ struct syntaxedit_data { IRichEditOle *irich; ITextDocument *idoc; enum block_state last_block_state; + LONG yheight; bool highlight_guard; }; @@ -118,6 +119,7 @@ done: static void highlight_text(HWND hWnd) { + struct syntaxedit_data *this = (struct syntaxedit_data *)GetWindowLongPtr(hWnd, GWLP_USERDATA); GETTEXTLENGTHEX gettextlengthex = { .flags = GTL_NUMBYTES, .codepage = CP_ACP /* Probably CP_UTF8 would be better, but (wine at least) returns utf32 sizes. */ @@ -130,10 +132,9 @@ static void highlight_text(HWND hWnd) .cbSize = sizeof(CHARFORMAT2), .dwMask = CFM_COLOR | CFM_CHARSET | CFM_SIZE | CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE, .dwEffects = CFE_AUTOCOLOR, - .yHeight = 20 * 10, + .yHeight = this->yheight ?: 20 * 10, .bCharSet = ANSI_CHARSET }; - struct syntaxedit_data *this = (struct syntaxedit_data *)GetWindowLongPtr(hWnd, GWLP_USERDATA); LRESULT msg_size; char *msg = NULL; struct highlight_span *spans = NULL; @@ -318,9 +319,16 @@ static LRESULT CALLBACK child_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lP SendMessage(hWnd, EM_EMPTYUNDOBUFFER, 0, 0); return ret; } - case WM_DPICHANGED: + case SE_SET_PARENT_DPI: { + struct syntaxedit_data *this = (struct syntaxedit_data *)GetWindowLongPtr(hWnd, GWLP_USERDATA); + HDC hdc = GetDC(hWnd); + if (this->yheight) + SendMessage(hWnd, EM_SETZOOM, GetDeviceCaps(hdc, LOGPIXELSY), wParam); + this->yheight = MulDiv(20 * 10, wParam, GetDeviceCaps(hdc, LOGPIXELSY)); + ReleaseDC(hWnd, hdc); highlight_text(hWnd); - break; + return 0; + } case WM_REFLECT + WM_COMMAND: case WM_COMMAND: case WM_REFLECT + WM_NOTIFY: diff --git a/ui/syntax/syntaxedit.go b/ui/syntax/syntaxedit.go index 67e132c4..62b4310b 100644 --- a/ui/syntax/syntaxedit.go +++ b/ui/syntax/syntaxedit.go @@ -15,6 +15,7 @@ import ( "github.com/lxn/win" ) +// #cgo LDFLAGS: -lgdi32 // #include "syntaxedit.h" import "C" @@ -108,6 +109,7 @@ func NewSyntaxEdit(parent walk.Container) (*SyntaxEdit, error) { if err != nil { return nil, err } + se.SendMessage(C.SE_SET_PARENT_DPI, uintptr(parent.DPI()), 0) se.GraphicsEffects().Add(walk.InteractionEffect) se.GraphicsEffects().Add(walk.FocusEffect) @@ -126,3 +128,7 @@ func NewSyntaxEdit(parent walk.Container) (*SyntaxEdit, error) { return se, nil } + +func (se *SyntaxEdit) ApplyDPI(dpi int) { + se.SendMessage(C.SE_SET_PARENT_DPI, uintptr(dpi), 0) +} diff --git a/ui/syntax/syntaxedit.h b/ui/syntax/syntaxedit.h index 7d158b29..048e7bc4 100644 --- a/ui/syntax/syntaxedit.h +++ b/ui/syntax/syntaxedit.h @@ -18,6 +18,7 @@ #define SE_PRIVATE_KEY (WM_USER + 0x3100) #define SE_TRAFFIC_BLOCK (WM_USER + 0x3101) +#define SE_SET_PARENT_DPI (WM_USER + 0x3102) enum block_state { InevaluableBlockingUntunneledTraffic, -- cgit v1.2.3-59-g8ed1b