From 3b515f1242dbba7bd7d3d7196d8b24e77a217a3b Mon Sep 17 00:00:00 2001 From: ozone10 Date: Sun, 5 May 2024 18:12:08 +0200 Subject: [PATCH] Initial new dpi management support for Shortcut Mapper ref #14959 Close #15089 --- .../src/WinControls/Grid/ShortcutMapper.cpp | 41 +++++++++---------- .../src/WinControls/Grid/ShortcutMapper.h | 6 +-- .../src/WinControls/Grid/ShortcutMapper.rc | 14 +++---- PowerEditor/src/dpiManagerV2.h | 6 +++ 4 files changed, 36 insertions(+), 31 deletions(-) diff --git a/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp b/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp index 870f11adf..638c041b9 100644 --- a/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp +++ b/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp @@ -46,7 +46,7 @@ void ShortcutMapper::initTabs() ::GetWindowPlacement(hTab, &wp); ::SendMessage(hTab, TCM_GETITEMRECT, 0, reinterpret_cast(&rcTab)); - wp.rcNormalPosition.bottom = NppParameters::getInstance()._dpiManager.scaleY(30); + wp.rcNormalPosition.bottom = _dpiManager.scale(30); wp.rcNormalPosition.top = wp.rcNormalPosition.bottom - rcTab.bottom; ::SetWindowPlacement(hTab, &wp); @@ -54,6 +54,7 @@ void ShortcutMapper::initTabs() void ShortcutMapper::getClientRect(RECT & rc) const { + const UINT dpi = _dpiManager.getDpi(); Window::getClientRect(rc); RECT tabRect{}, btnRect{}; @@ -69,11 +70,11 @@ void ShortcutMapper::getClientRect(RECT & rc) const int infoH = infoRect.bottom - infoRect.top; int filterH = filterRect.bottom - filterRect.top; int btnH = btnRect.bottom - btnRect.top; - int paddingBottom = btnH + NppParameters::getInstance()._dpiManager.scaleY(16); + int paddingBottom = btnH + _dpiManager.scale(16, dpi); rc.bottom -= btnH + filterH + infoH + paddingBottom; - rc.left += NppParameters::getInstance()._dpiManager.scaleX(5); - rc.right -= NppParameters::getInstance()._dpiManager.scaleX(5); + rc.left += _dpiManager.scale(5, dpi); + rc.right -= _dpiManager.scale(5, dpi); } generic_string ShortcutMapper::getTabString(size_t i) const @@ -111,14 +112,12 @@ void ShortcutMapper::initBabyGrid() _lastCursorRow.resize(5, 1); _hGridFonts.resize(MAX_GRID_FONTS); - _hGridFonts.at(GFONT_HEADER) = ::CreateFont( - NppParameters::getInstance()._dpiManager.scaleY(18), 0, 0, 0, FW_BOLD, - FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, - TEXT("MS Shell Dlg")); - _hGridFonts.at(GFONT_ROWS) = ::CreateFont( - NppParameters::getInstance()._dpiManager.scaleY(16), 0, 0, 0, FW_NORMAL, - FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, - TEXT("MS Shell Dlg")); + LOGFONT lf{ _dpiManager.getDefaultGUIFontForDpi() }; + lf.lfHeight = _dpiManager.scaleFont(10); + _hGridFonts.at(GFONT_ROWS) = ::CreateFontIndirect(&lf); + lf.lfHeight = _dpiManager.scaleFont(12); + lf.lfWeight = FW_BOLD; + _hGridFonts.at(GFONT_HEADER) = ::CreateFontIndirect(&lf); _babygrid.init(_hInst, _hSelf, IDD_BABYGRID_ID1); @@ -132,9 +131,9 @@ void ShortcutMapper::initBabyGrid() _babygrid.makeColAutoWidth(true); _babygrid.setAutoRow(true); _babygrid.setColsNumbered(false); - _babygrid.setColWidth(0, NppParameters::getInstance()._dpiManager.scaleX(30)); // Force the first col to be small, others col will be automatically sized - _babygrid.setHeaderHeight(NppParameters::getInstance()._dpiManager.scaleY(21)); - _babygrid.setRowHeight(NppParameters::getInstance()._dpiManager.scaleY(21)); + _babygrid.setColWidth(0, _dpiManager.scale(30)); // Force the first col to be small, others col will be automatically sized + _babygrid.setHeaderHeight(_dpiManager.scale(21)); + _babygrid.setRowHeight(_dpiManager.scale(21)); if (NppDarkMode::isEnabled()) { @@ -510,10 +509,11 @@ void ShortcutMapper::fillOutBabyGrid() intptr_t CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) { - switch (message) + switch (message) { - case WM_INITDIALOG : + case WM_INITDIALOG: { + setDpi(); initBabyGrid(); initTabs(); fillOutBabyGrid(); @@ -527,10 +527,9 @@ intptr_t CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARA _clientWidth = rect.right - rect.left; _clientHeight = rect.bottom - rect.top; - int cy_border = GetSystemMetrics(SM_CYFRAME); - int cy_caption = GetSystemMetrics(SM_CYCAPTION); - _initClientWidth = _clientWidth; - _initClientHeight = _clientHeight + cy_caption + cy_border; + Window::getWindowRect(rect); + _initClientWidth = rect.right - rect.left; + _initClientHeight = rect.bottom - rect.top; _dialogInitDone = true; return TRUE; diff --git a/PowerEditor/src/WinControls/Grid/ShortcutMapper.h b/PowerEditor/src/WinControls/Grid/ShortcutMapper.h index f8d1208c3..f5be90124 100644 --- a/PowerEditor/src/WinControls/Grid/ShortcutMapper.h +++ b/PowerEditor/src/WinControls/Grid/ShortcutMapper.h @@ -37,7 +37,7 @@ public: _currentState = initState; }; - void destroy() {}; + void destroy() override {}; void doDialog(bool isRTL = false) { if (isRTL) { @@ -49,7 +49,7 @@ public: else ::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_SHORTCUTMAPPER_DLG), _hParent, dlgProc, reinterpret_cast(this)); }; - void getClientRect(RECT & rc) const; + void getClientRect(RECT & rc) const override; bool findKeyConflicts(__inout_opt generic_string * const keyConflictLocation, const KeyCombo & itemKeyCombo, const size_t & itemIndex) const; @@ -60,7 +60,7 @@ public: bool isFilterValid(ScintillaKeyMap sc); protected : - intptr_t CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); + intptr_t CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) override; private: BabyGridWrapper _babygrid; diff --git a/PowerEditor/src/WinControls/Grid/ShortcutMapper.rc b/PowerEditor/src/WinControls/Grid/ShortcutMapper.rc index 62ddf0749..653e1947f 100755 --- a/PowerEditor/src/WinControls/Grid/ShortcutMapper.rc +++ b/PowerEditor/src/WinControls/Grid/ShortcutMapper.rc @@ -29,11 +29,11 @@ CAPTION "Shortcut mapper" FONT 8, TEXT("MS Shell Dlg"), 400, 0, 0x1 BEGIN CONTROL "",IDC_BABYGRID_TABBAR,"SysTabControl32",WS_TABSTOP,4,6,384,12 - EDITTEXT IDC_BABYGRID_INFO,3,281,443,29,ES_MULTILINE | ES_AUTOHSCROLL | ES_READONLY | WS_VSCROLL | NOT WS_TABSTOP - RTEXT "Filter :", IDC_BABYGRID_STATIC,4,313,25,12 - EDITTEXT IDC_BABYGRID_FILTER,31,312,415,12,ES_AUTOHSCROLL | ES_WANTRETURN - PUSHBUTTON "Modify",IDM_BABYGRID_MODIFY,118,330,47,14 - PUSHBUTTON "Clear",IDM_BABYGRID_CLEAR,172,330,47,14 - PUSHBUTTON "Delete",IDM_BABYGRID_DELETE,226,330,47,14 - DEFPUSHBUTTON "Close",IDOK,280,330,47,14 + EDITTEXT IDC_BABYGRID_INFO,3,283,443,29,ES_MULTILINE | ES_AUTOHSCROLL | ES_READONLY | WS_VSCROLL | NOT WS_TABSTOP + RTEXT "Filter:",IDC_BABYGRID_STATIC,4,318,25,8 + EDITTEXT IDC_BABYGRID_FILTER,31,317,415,12,ES_AUTOHSCROLL | ES_WANTRETURN + PUSHBUTTON "Modify",IDM_BABYGRID_MODIFY,126,335,47,14 + PUSHBUTTON "Clear",IDM_BABYGRID_CLEAR,180,335,47,14 + PUSHBUTTON "Delete",IDM_BABYGRID_DELETE,234,335,47,14 + DEFPUSHBUTTON "Close",IDOK,288,335,47,14 END diff --git a/PowerEditor/src/dpiManagerV2.h b/PowerEditor/src/dpiManagerV2.h index 0bbc7779e..8d3e9ca57 100644 --- a/PowerEditor/src/dpiManagerV2.h +++ b/PowerEditor/src/dpiManagerV2.h @@ -47,6 +47,9 @@ public: static void initDpiAPI(); static int getSystemMetricsForDpi(int nIndex, UINT dpi); + int getSystemMetricsForDpi(int nIndex) { + return getSystemMetricsForDpi(nIndex, _dpi); + } static DPI_AWARENESS_CONTEXT setThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT dpiContext); static UINT getDpiForSystem(); @@ -126,6 +129,9 @@ public: static LOGFONT getDefaultGUIFontForDpi(HWND hWnd, FontType type = FontType::message) { return getDefaultGUIFontForDpi(getDpiForWindow(hWnd), type); } + LOGFONT getDefaultGUIFontForDpi(FontType type = FontType::message) { + return getDefaultGUIFontForDpi(_dpi, type); + } static void sendMessageToChildControls(HWND hwndParent, UINT msg, WPARAM wParam, LPARAM lParam); static void loadIcon(HINSTANCE hinst, const wchar_t* pszName, int cx, int cy, HICON* phico, UINT fuLoad = LR_DEFAULTCOLOR);