From 5996ed7171a277480bbfc7b110e6db285935db7b Mon Sep 17 00:00:00 2001 From: ozone10 Date: Sun, 19 Oct 2025 14:24:40 +0200 Subject: [PATCH] Add basic text scale support Fix #16427, close #17091 --- PowerEditor/src/MISC/RegExt/regExtDlg.cpp | 10 +- .../src/ScintillaComponent/FindReplaceDlg.cpp | 17 +- .../ScintillaComponent/UserDefineDialog.cpp | 111 ++++++------ .../src/ScintillaComponent/UserDefineDialog.h | 30 ++-- .../ScintillaComponent/UserDefineDialog.rc | 2 +- .../src/ScintillaComponent/columnEditor.h | 4 - .../src/WinControls/AboutDlg/AboutDlg.cpp | 22 +-- .../WinControls/ColourPicker/WordStyleDlg.cpp | 4 +- .../WinControls/ColourPicker/WordStyleDlg.h | 6 +- .../WinControls/DockingWnd/DockingCont.cpp | 2 +- .../src/WinControls/Grid/ShortcutMapper.h | 18 +- .../WinControls/PluginsAdmin/pluginsAdmin.cpp | 4 +- .../WinControls/PluginsAdmin/pluginsAdmin.h | 3 +- .../WinControls/ProjectPanel/ProjectPanel.cpp | 10 +- .../WinControls/StaticDialog/StaticDialog.cpp | 161 ++++++++++++++---- .../WinControls/StaticDialog/StaticDialog.h | 39 +++-- PowerEditor/src/WinControls/TabBar/TabBar.cpp | 7 +- .../src/WinControls/TaskList/TaskListDlg.cpp | 14 +- .../src/WinControls/WindowsDlg/WindowsDlg.cpp | 2 +- .../src/WinControls/shortcut/shortcut.h | 14 +- PowerEditor/src/dpiManagerV2.cpp | 15 ++ PowerEditor/src/dpiManagerV2.h | 12 ++ 22 files changed, 292 insertions(+), 215 deletions(-) diff --git a/PowerEditor/src/MISC/RegExt/regExtDlg.cpp b/PowerEditor/src/MISC/RegExt/regExtDlg.cpp index 1fd67f406..eb4156b56 100644 --- a/PowerEditor/src/MISC/RegExt/regExtDlg.cpp +++ b/PowerEditor/src/MISC/RegExt/regExtDlg.cpp @@ -70,15 +70,7 @@ const wchar_t defExtArray[nbSupportedLang][nbExtMax][extNameMax] = void RegExtDlg::doDialog(bool isRTL) { - if (isRTL) - { - DLGTEMPLATE *pMyDlgTemplate = nullptr; - HGLOBAL hMyDlgTemplate = makeRTLResource(IDD_REGEXT_BOX, &pMyDlgTemplate); - ::DialogBoxIndirectParam(_hInst, pMyDlgTemplate, _hParent, dlgProc, reinterpret_cast(this)); - ::GlobalFree(hMyDlgTemplate); - } - else - ::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_REGEXT_BOX), _hParent, dlgProc, reinterpret_cast(this)); + StaticDialog::myCreateDialogBoxIndirectParam(IDD_REGEXT_BOX, isRTL); } intptr_t CALLBACK RegExtDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) diff --git a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp index 71b576e1b..d28dfccfe 100644 --- a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp +++ b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp @@ -1609,7 +1609,8 @@ intptr_t CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA const bool isMonospaced = NppParameters::getInstance().getNppGUI()._monospacedFontFindDlg; if (isMonospaced) { - hFont = createFont(L"Courier New", 8, false, _hSelf); + static const UINT fontSize = DPIManagerV2::scaleFontForFactor(8); + hFont = createFont(L"Courier New", fontSize, false, _hSelf); } else { @@ -1623,7 +1624,8 @@ intptr_t CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA LOGFONT lf{}; ::GetObject(hFont, sizeof(lf), &lf); - lf.lfHeight = -(_dpiManager.scale(16) - 5); + static const UINT fontSize = DPIManagerV2::scaleFontForFactor(16) - 5; + lf.lfHeight = -(_dpiManager.scale(fontSize)); _hComboBoxFont = ::CreateFontIndirect(&lf); for (const auto& hComboBox : { hFindCombo, hReplaceCombo, hFiltersCombo, hDirCombo }) @@ -4833,16 +4835,7 @@ void FindReplaceDlg::initOptionsFromDlg() void FindInFinderDlg::doDialog(Finder *launcher, bool isRTL) { _pFinder2Search = launcher; - if (isRTL) - { - DLGTEMPLATE *pMyDlgTemplate = NULL; - HGLOBAL hMyDlgTemplate = makeRTLResource(IDD_FINDINFINDER_DLG, &pMyDlgTemplate); - ::DialogBoxIndirectParam(_hInst, pMyDlgTemplate, _hParent, dlgProc, reinterpret_cast(this)); - ::GlobalFree(hMyDlgTemplate); - } - else - ::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_FINDINFINDER_DLG), _hParent, dlgProc, reinterpret_cast(this)); - + StaticDialog::myCreateDialogBoxIndirectParam(IDD_FINDINFINDER_DLG, isRTL); } void FindReplaceDlg::doDialog(DIALOG_TYPE whichType, bool isRTL, bool toShow) diff --git a/PowerEditor/src/ScintillaComponent/UserDefineDialog.cpp b/PowerEditor/src/ScintillaComponent/UserDefineDialog.cpp index 348c956bb..dd28b9a28 100644 --- a/PowerEditor/src/ScintillaComponent/UserDefineDialog.cpp +++ b/PowerEditor/src/ScintillaComponent/UserDefineDialog.cpp @@ -1788,38 +1788,31 @@ void StylerDlg::move2CtrlRight(HWND hwndDlg, int ctrlID, HWND handle2Move, int h ::MoveWindow(handle2Move, p.x, p.y, handle2MoveWidth, handle2MoveHeight, TRUE); } -intptr_t CALLBACK StylerDlg::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +intptr_t CALLBACK StylerDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) { - StylerDlg * dlg = (StylerDlg *)::GetProp(hwnd, L"Styler dialog prop"); + auto* dlg = static_cast(::GetProp(_hSelf, L"Styler dialog prop")); NppParameters& nppParam = NppParameters::getInstance(); switch (message) { case WM_INITDIALOG : { - NppDarkMode::setDarkTitleBar(hwnd); - NppDarkMode::autoSubclassAndThemeChildControls(hwnd); + NppDarkMode::setDarkTitleBar(_hSelf); + NppDarkMode::autoSubclassAndThemeChildControls(_hSelf); NativeLangSpeaker *pNativeLangSpeaker = nppParam.getNativeLangSpeaker(); - pNativeLangSpeaker->changeUserDefineLangPopupDlg(hwnd); + pNativeLangSpeaker->changeUserDefineLangPopupDlg(_hSelf); - ::SetProp(hwnd, L"Styler dialog prop", (HANDLE)lParam); - dlg = (StylerDlg *)::GetProp(hwnd, L"Styler dialog prop"); + ::SetProp(_hSelf, L"Styler dialog prop", reinterpret_cast(lParam)); + dlg = static_cast(::GetProp(_hSelf, L"Styler dialog prop")); Style & style = SharedParametersDialog::_pUserLang->_styles.getStyler(dlg->_stylerIndex); - // move dialog over UDL GUI (position 0,0 of UDL window) so it wouldn't cover the code - RECT wrc{}; - ::GetWindowRect(dlg->_parent, &wrc); - wrc.left = wrc.left < 0 ? 200 : wrc.left; // if outside of visible area - wrc.top = wrc.top < 0 ? 200 : wrc.top; - ::SetWindowPos(hwnd, HWND_TOP, wrc.left, wrc.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER); - - ::SendDlgItemMessage(hwnd, IDC_STYLER_CHECK_UNDERLINE, BM_SETCHECK, style._fontStyle & FONTSTYLE_UNDERLINE, 0); - ::SendDlgItemMessage(hwnd, IDC_STYLER_CHECK_ITALIC, BM_SETCHECK, style._fontStyle & FONTSTYLE_ITALIC, 0); - ::SendDlgItemMessage(hwnd, IDC_STYLER_CHECK_BOLD, BM_SETCHECK, style._fontStyle & FONTSTYLE_BOLD, 0); + ::SendDlgItemMessage(_hSelf, IDC_STYLER_CHECK_UNDERLINE, BM_SETCHECK, style._fontStyle & FONTSTYLE_UNDERLINE, 0); + ::SendDlgItemMessage(_hSelf, IDC_STYLER_CHECK_ITALIC, BM_SETCHECK, style._fontStyle & FONTSTYLE_ITALIC, 0); + ::SendDlgItemMessage(_hSelf, IDC_STYLER_CHECK_BOLD, BM_SETCHECK, style._fontStyle & FONTSTYLE_BOLD, 0); // for the font size combo - HWND hFontSizeCombo = ::GetDlgItem(hwnd, IDC_STYLER_COMBO_FONT_SIZE); + HWND hFontSizeCombo = ::GetDlgItem(_hSelf, IDC_STYLER_COMBO_FONT_SIZE); for (size_t j = 0 ; j < int(sizeof(fontSizeStrs))/(3*sizeof(wchar_t)) ; ++j) ::SendMessage(hFontSizeCombo, CB_ADDSTRING, 0, reinterpret_cast(fontSizeStrs[j])); @@ -1834,7 +1827,7 @@ intptr_t CALLBACK StylerDlg::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPA ::SendMessage(hFontSizeCombo, CB_SETCURSEL, i, 0); // for the font name combo - HWND hFontNameCombo = ::GetDlgItem(hwnd, IDC_STYLER_COMBO_FONT_NAME); + HWND hFontNameCombo = ::GetDlgItem(_hSelf, IDC_STYLER_COMBO_FONT_NAME); const std::vector & fontlist = nppParam.getFontList(); for (size_t j = 0, len = fontlist.size() ; j < len ; ++j) { @@ -1853,20 +1846,20 @@ intptr_t CALLBACK StylerDlg::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPA if (style._bgColor == COLORREF(-1)) style._bgColor = white; - dlg->_pFgColour->init(dlg->_hInst, hwnd); + dlg->_pFgColour->init(dlg->_hInst, _hSelf); dlg->_pFgColour->setColour(style._fgColor); bool isFgEnabled = (style._colorStyle & COLORSTYLE_FOREGROUND) != 0; dlg->_pFgColour->setEnabled(isFgEnabled); - ::SendDlgItemMessage(hwnd, IDC_STYLER_CHECK_FG_TRANSPARENT, BM_SETCHECK, !isFgEnabled, 0); - dlg->_pBgColour->init(dlg->_hInst, hwnd); + ::SendDlgItemMessage(_hSelf, IDC_STYLER_CHECK_FG_TRANSPARENT, BM_SETCHECK, !isFgEnabled, 0); + dlg->_pBgColour->init(dlg->_hInst, _hSelf); dlg->_pBgColour->setColour(style._bgColor); bool isBgEnabled = (style._colorStyle & COLORSTYLE_BACKGROUND) != 0; dlg->_pBgColour->setEnabled(isBgEnabled); - ::SendDlgItemMessage(hwnd, IDC_STYLER_CHECK_BG_TRANSPARENT, BM_SETCHECK, !isBgEnabled, 0); + ::SendDlgItemMessage(_hSelf, IDC_STYLER_CHECK_BG_TRANSPARENT, BM_SETCHECK, !isBgEnabled, 0); - const int moveSize = DPIManagerV2::scale(25, hwnd); - dlg->move2CtrlRight(hwnd, IDC_STYLER_FG_STATIC, dlg->_pFgColour->getHSelf(), moveSize, moveSize); - dlg->move2CtrlRight(hwnd, IDC_STYLER_BG_STATIC, dlg->_pBgColour->getHSelf(), moveSize, moveSize); + const int moveSize = DPIManagerV2::scale(25, _hSelf); + dlg->move2CtrlRight(_hSelf, IDC_STYLER_FG_STATIC, dlg->_pFgColour->getHSelf(), moveSize, moveSize); + dlg->move2CtrlRight(_hSelf, IDC_STYLER_BG_STATIC, dlg->_pBgColour->getHSelf(), moveSize, moveSize); dlg->_pFgColour->display(); dlg->_pBgColour->display(); @@ -1874,9 +1867,12 @@ intptr_t CALLBACK StylerDlg::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPA unordered_map::iterator iter = globalMappper().nestingMapper.begin(); for (; iter != globalMappper().nestingMapper.end(); ++iter) { - ::SendDlgItemMessage(hwnd, iter->first, BM_SETCHECK, style._nesting & iter->second, 0); - ::EnableWindow(::GetDlgItem(hwnd, iter->first), dlg->_enabledNesters & iter->second); + ::SendDlgItemMessage(_hSelf, iter->first, BM_SETCHECK, style._nesting & iter->second, 0); + ::EnableWindow(::GetDlgItem(_hSelf, iter->first), dlg->_enabledNesters & iter->second); } + + goToCenter(); + return TRUE; } @@ -1907,19 +1903,19 @@ intptr_t CALLBACK StylerDlg::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPA case NPPM_INTERNAL_REFRESHDARKMODE: { - NppDarkMode::setDarkTitleBar(hwnd); - NppDarkMode::autoThemeChildControls(hwnd); - ::SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); + NppDarkMode::setDarkTitleBar(_hSelf); + NppDarkMode::autoThemeChildControls(_hSelf); + ::SetWindowPos(_hSelf, nullptr, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); return TRUE; } case WM_DPICHANGED: { - const int moveSize = DPIManagerV2::scale(25, hwnd); - dlg->move2CtrlRight(hwnd, IDC_STYLER_FG_STATIC, dlg->_pFgColour->getHSelf(), moveSize, moveSize); - dlg->move2CtrlRight(hwnd, IDC_STYLER_BG_STATIC, dlg->_pBgColour->getHSelf(), moveSize, moveSize); + const int moveSize = DPIManagerV2::scale(25, _hSelf); + dlg->move2CtrlRight(_hSelf, IDC_STYLER_FG_STATIC, dlg->_pFgColour->getHSelf(), moveSize, moveSize); + dlg->move2CtrlRight(_hSelf, IDC_STYLER_BG_STATIC, dlg->_pBgColour->getHSelf(), moveSize, moveSize); - DPIManagerV2::setPositionDpi(lParam, hwnd, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE); + DPIManagerV2::setPositionDpi(lParam, _hSelf, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE); return TRUE; } @@ -1932,18 +1928,18 @@ intptr_t CALLBACK StylerDlg::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPA Style & style = SharedParametersDialog::_pUserLang->_styles.getStyler(dlg->_stylerIndex); if (HIWORD(wParam) == CBN_SELCHANGE) { - auto i = ::SendDlgItemMessage(hwnd, LOWORD(wParam), CB_GETCURSEL, 0, 0); + auto i = ::SendDlgItemMessage(_hSelf, LOWORD(wParam), CB_GETCURSEL, 0, 0); if (LOWORD(wParam) == IDC_STYLER_COMBO_FONT_SIZE) { if (i != 0) { const size_t intStrLen = 3; wchar_t intStr[intStrLen] = { '\0' }; - auto lbTextLen = ::SendDlgItemMessage(hwnd, LOWORD(wParam), CB_GETLBTEXTLEN, i, 0); + auto lbTextLen = ::SendDlgItemMessage(_hSelf, LOWORD(wParam), CB_GETLBTEXTLEN, i, 0); if (static_cast(lbTextLen) > intStrLen - 1) return TRUE; - ::SendDlgItemMessage(hwnd, LOWORD(wParam), CB_GETLBTEXT, i, reinterpret_cast(intStr)); + ::SendDlgItemMessage(_hSelf, LOWORD(wParam), CB_GETLBTEXT, i, reinterpret_cast(intStr)); if (!intStr[0]) style._fontSize = -1; else @@ -1961,7 +1957,7 @@ intptr_t CALLBACK StylerDlg::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPA } else if (LOWORD(wParam) == IDC_STYLER_COMBO_FONT_NAME) { - style._fontName = (wchar_t *)::SendDlgItemMessage(hwnd, LOWORD(wParam), CB_GETITEMDATA, i, 0); + style._fontName = reinterpret_cast(::SendDlgItemMessage(_hSelf, LOWORD(wParam), CB_GETITEMDATA, i, 0)); } // show changes to user, re-color document @@ -1979,15 +1975,15 @@ intptr_t CALLBACK StylerDlg::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPA if (SharedParametersDialog::_pScintilla->getCurrentBuffer()->getLangType() == L_USER) SharedParametersDialog::_pScintilla->styleChange(); - ::RemoveProp(hwnd, L"Styler dialog prop"); - ::EndDialog(hwnd, IDCANCEL); + ::RemoveProp(_hSelf, L"Styler dialog prop"); + ::EndDialog(_hSelf, IDCANCEL); return TRUE; } if (wParam == IDOK) { - ::RemoveProp(hwnd, L"Styler dialog prop"); - ::EndDialog(hwnd, IDOK); + ::RemoveProp(_hSelf, L"Styler dialog prop"); + ::EndDialog(_hSelf, IDOK); return TRUE; } @@ -1998,7 +1994,7 @@ intptr_t CALLBACK StylerDlg::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPA { if (wParam == IDC_STYLER_CHECK_FG_TRANSPARENT) { - bool isTransparent = (BST_CHECKED == ::SendDlgItemMessage(hwnd, IDC_STYLER_CHECK_FG_TRANSPARENT, BM_GETCHECK, 0, 0)); + bool isTransparent = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_STYLER_CHECK_FG_TRANSPARENT, BM_GETCHECK, 0, 0)); dlg->_pFgColour->setEnabled(!isTransparent); dlg->_pFgColour->redraw(); if (isTransparent) @@ -2009,7 +2005,7 @@ intptr_t CALLBACK StylerDlg::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPA if (wParam == IDC_STYLER_CHECK_BG_TRANSPARENT) { - bool isTransparent = (BST_CHECKED == ::SendDlgItemMessage(hwnd, IDC_STYLER_CHECK_BG_TRANSPARENT, BM_GETCHECK, 0, 0)); + bool isTransparent = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_STYLER_CHECK_BG_TRANSPARENT, BM_GETCHECK, 0, 0)); dlg->_pBgColour->setEnabled(!isTransparent); dlg->_pBgColour->redraw(); if (isTransparent) @@ -2028,7 +2024,7 @@ intptr_t CALLBACK StylerDlg::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPA { style._colorStyle &= ~COLORSTYLE_FOREGROUND; } - ::SendDlgItemMessage(hwnd, IDC_STYLER_CHECK_FG_TRANSPARENT, BM_SETCHECK, !dlg->_pFgColour->isEnabled(), 0); + ::SendDlgItemMessage(_hSelf, IDC_STYLER_CHECK_FG_TRANSPARENT, BM_SETCHECK, !dlg->_pFgColour->isEnabled(), 0); if (dlg->_pBgColour->isEnabled()) { @@ -2038,21 +2034,21 @@ intptr_t CALLBACK StylerDlg::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPA { style._colorStyle &= ~COLORSTYLE_BACKGROUND; } - ::SendDlgItemMessage(hwnd, IDC_STYLER_CHECK_BG_TRANSPARENT, BM_SETCHECK, !dlg->_pBgColour->isEnabled(), 0); + ::SendDlgItemMessage(_hSelf, IDC_STYLER_CHECK_BG_TRANSPARENT, BM_SETCHECK, !dlg->_pBgColour->isEnabled(), 0); } style._fontStyle = FONTSTYLE_NONE; - if (BST_CHECKED == ::SendMessage(::GetDlgItem(hwnd, IDC_STYLER_CHECK_BOLD), BM_GETCHECK, 0, 0)) + if (BST_CHECKED == ::SendMessage(::GetDlgItem(_hSelf, IDC_STYLER_CHECK_BOLD), BM_GETCHECK, 0, 0)) style._fontStyle |= FONTSTYLE_BOLD; - if (BST_CHECKED == ::SendMessage(::GetDlgItem(hwnd, IDC_STYLER_CHECK_ITALIC), BM_GETCHECK, 0, 0)) + if (BST_CHECKED == ::SendMessage(::GetDlgItem(_hSelf, IDC_STYLER_CHECK_ITALIC), BM_GETCHECK, 0, 0)) style._fontStyle |= FONTSTYLE_ITALIC; - if (BST_CHECKED == ::SendMessage(::GetDlgItem(hwnd, IDC_STYLER_CHECK_UNDERLINE), BM_GETCHECK, 0, 0)) + if (BST_CHECKED == ::SendMessage(::GetDlgItem(_hSelf, IDC_STYLER_CHECK_UNDERLINE), BM_GETCHECK, 0, 0)) style._fontStyle |= FONTSTYLE_UNDERLINE; style._nesting = SCE_USER_MASK_NESTING_NONE; unordered_map::iterator iter = globalMappper().nestingMapper.begin(); for (; iter != globalMappper().nestingMapper.end(); ++iter) { - if (BST_CHECKED == ::SendMessage(::GetDlgItem(hwnd, iter->first), BM_GETCHECK, 0, 0)) + if (BST_CHECKED == ::SendMessage(::GetDlgItem(_hSelf, iter->first), BM_GETCHECK, 0, 0)) style._nesting |= iter->second; } @@ -2064,11 +2060,22 @@ intptr_t CALLBACK StylerDlg::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPA } return FALSE; } + case WM_CLOSE: { + Style& style = SharedParametersDialog::_pUserLang->_styles.getStyler(dlg->_stylerIndex); + style = dlg->_initialStyle; + + // show changes to user, re-color document + if (SharedParametersDialog::_pScintilla->getCurrentBuffer()->getLangType() == L_USER) + SharedParametersDialog::_pScintilla->styleChange(); + + ::RemoveProp(_hSelf, L"Styler dialog prop"); + ::EndDialog(_hSelf, IDCANCEL); return TRUE; } - default : + + default: return FALSE; } return FALSE; diff --git a/PowerEditor/src/ScintillaComponent/UserDefineDialog.h b/PowerEditor/src/ScintillaComponent/UserDefineDialog.h index 24c982428..29bd36159 100644 --- a/PowerEditor/src/ScintillaComponent/UserDefineDialog.h +++ b/PowerEditor/src/ScintillaComponent/UserDefineDialog.h @@ -399,8 +399,8 @@ public : }; intptr_t doDialog() { - return ::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_STRING_DLG), _hParent, dlgProc, reinterpret_cast(this)); - }; + return StaticDialog::myCreateDialogBoxIndirectParam(IDD_STRING_DLG, false); + } void destroy() override {}; @@ -423,32 +423,34 @@ private : WNDPROC _oldEditProc = nullptr; }; -class StylerDlg +class StylerDlg : public StaticDialog { public: - StylerDlg( HINSTANCE hInst, HWND parent, int stylerIndex = 0, int enabledNesters = -1): - _hInst(hInst), _parent(parent), _stylerIndex(stylerIndex), _enabledNesters(enabledNesters) { + StylerDlg(HINSTANCE hInst, HWND parent, int stylerIndex = 0, int enabledNesters = -1): + _stylerIndex(stylerIndex), _enabledNesters(enabledNesters) { + Window::init(hInst, parent); _pFgColour = new ColourPicker; _pBgColour = new ColourPicker; _initialStyle = SharedParametersDialog::_pUserLang->_styles.getStyler(stylerIndex); - }; + } - ~StylerDlg() { + ~StylerDlg() override { _pFgColour->destroy(); _pBgColour->destroy(); delete _pFgColour; delete _pBgColour; - }; + } - long doDialog() { - return long(::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_STYLER_POPUP_DLG), _parent, dlgProc, reinterpret_cast(this))); - }; + void destroy() override {} - static intptr_t CALLBACK dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); + int doDialog() { + return static_cast(StaticDialog::myCreateDialogBoxIndirectParam(IDD_STYLER_POPUP_DLG, false)); + } + +protected: + intptr_t CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) override; private: - HINSTANCE _hInst = nullptr; - HWND _parent = nullptr; int _stylerIndex = 0; int _enabledNesters = 0; ColourPicker * _pFgColour = nullptr; diff --git a/PowerEditor/src/ScintillaComponent/UserDefineDialog.rc b/PowerEditor/src/ScintillaComponent/UserDefineDialog.rc index fd2e76710..198485b29 100644 --- a/PowerEditor/src/ScintillaComponent/UserDefineDialog.rc +++ b/PowerEditor/src/ScintillaComponent/UserDefineDialog.rc @@ -251,7 +251,7 @@ BEGIN END IDD_STYLER_POPUP_DLG DIALOGEX 0, 0, 324, 305 -STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Styler Dialog" FONT 8, "MS Shell Dlg", 400, 0, 0x1 BEGIN diff --git a/PowerEditor/src/ScintillaComponent/columnEditor.h b/PowerEditor/src/ScintillaComponent/columnEditor.h index 140640792..f69380813 100644 --- a/PowerEditor/src/ScintillaComponent/columnEditor.h +++ b/PowerEditor/src/ScintillaComponent/columnEditor.h @@ -29,10 +29,6 @@ public : ColumnEditorDlg() = default; void init(HINSTANCE hInst, HWND hPere, ScintillaEditView **ppEditView); - void create(int dialogID, bool isRTL = false, bool msgDestParent = true) override { - StaticDialog::create(dialogID, isRTL, msgDestParent); - }; - void doDialog(bool isRTL = false) { if (!isCreated()) create(IDD_COLUMNEDIT, isRTL); diff --git a/PowerEditor/src/WinControls/AboutDlg/AboutDlg.cpp b/PowerEditor/src/WinControls/AboutDlg/AboutDlg.cpp index b8b7d82da..dc23882f4 100644 --- a/PowerEditor/src/WinControls/AboutDlg/AboutDlg.cpp +++ b/PowerEditor/src/WinControls/AboutDlg/AboutDlg.cpp @@ -764,16 +764,7 @@ intptr_t CALLBACK CmdLineArgsDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA void DoSaveOrNotBox::doDialog(bool isRTL) { - - if (isRTL) - { - DLGTEMPLATE *pMyDlgTemplate = NULL; - HGLOBAL hMyDlgTemplate = makeRTLResource(IDD_DOSAVEORNOTBOX, &pMyDlgTemplate); - ::DialogBoxIndirectParam(_hInst, pMyDlgTemplate, _hParent, dlgProc, reinterpret_cast(this)); - ::GlobalFree(hMyDlgTemplate); - } - else - ::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_DOSAVEORNOTBOX), _hParent, dlgProc, reinterpret_cast(this)); + StaticDialog::myCreateDialogBoxIndirectParam(IDD_DOSAVEORNOTBOX, isRTL); } void DoSaveOrNotBox::changeLang() @@ -885,16 +876,7 @@ intptr_t CALLBACK DoSaveOrNotBox::run_dlgProc(UINT message, WPARAM wParam, LPARA void DoSaveAllBox::doDialog(bool isRTL) { - - if (isRTL) - { - DLGTEMPLATE* pMyDlgTemplate = NULL; - HGLOBAL hMyDlgTemplate = makeRTLResource(IDD_DOSAVEALLBOX, &pMyDlgTemplate); - ::DialogBoxIndirectParam(_hInst, pMyDlgTemplate, _hParent, dlgProc, reinterpret_cast(this)); - ::GlobalFree(hMyDlgTemplate); - } - else - ::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_DOSAVEALLBOX), _hParent, dlgProc, reinterpret_cast(this)); + StaticDialog::myCreateDialogBoxIndirectParam(IDD_DOSAVEALLBOX, isRTL); } void DoSaveAllBox::changeLang() diff --git a/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp b/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp index 19b8744a9..d7b9af24b 100644 --- a/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp +++ b/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp @@ -1366,9 +1366,9 @@ void WordStyleDlg::setVisualFromStyleList() } -void WordStyleDlg::create(int dialogID, bool isRTL, bool msgDestParent) +void WordStyleDlg::create(int dialogID, bool isRTL, bool msgDestParent, WORD fontSize) { - StaticDialog::create(dialogID, isRTL, msgDestParent); + StaticDialog::create(dialogID, isRTL, msgDestParent, fontSize); if ((NppParameters::getInstance()).isTransparentAvailable()) { diff --git a/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.h b/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.h index 748da30bb..98c28b261 100644 --- a/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.h +++ b/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.h @@ -71,7 +71,7 @@ class WordStyleDlg : public StaticDialog { public : WordStyleDlg() = default; - ~WordStyleDlg() { + ~WordStyleDlg() override { _goToSettings.destroy(); _globalOverrideLinkTip.destroy(); @@ -79,8 +79,8 @@ public : ::DestroyWindow(_globalOverrideTip); }; - void create(int dialogID, bool isRTL = false, bool msgDestParent = true) override; - void doDialog(bool isRTL = false); + void create(int dialogID, bool isRTL = false, bool msgDestParent = true, WORD fontSize = 8) override; + void doDialog(bool isRTL = false); void destroy() override; void prepare2Cancel(); void redraw(bool forceUpdate = false) const override; diff --git a/PowerEditor/src/WinControls/DockingWnd/DockingCont.cpp b/PowerEditor/src/WinControls/DockingWnd/DockingCont.cpp index 8f86e4790..5d05153c8 100644 --- a/PowerEditor/src/WinControls/DockingWnd/DockingCont.cpp +++ b/PowerEditor/src/WinControls/DockingWnd/DockingCont.cpp @@ -79,7 +79,7 @@ void DockingCont::doDialog(bool willBeShown, bool isFloating) if (!isCreated()) { NativeLangSpeaker* pNativeSpeaker = NppParameters::getInstance().getNativeLangSpeaker(); - create(IDD_CONTAINER_DLG, pNativeSpeaker->isRTL()); + create(IDD_CONTAINER_DLG, pNativeSpeaker->isRTL(), true, 0); _isFloating = isFloating; diff --git a/PowerEditor/src/WinControls/Grid/ShortcutMapper.h b/PowerEditor/src/WinControls/Grid/ShortcutMapper.h index fa0ff4140..d28121df4 100644 --- a/PowerEditor/src/WinControls/Grid/ShortcutMapper.h +++ b/PowerEditor/src/WinControls/Grid/ShortcutMapper.h @@ -33,22 +33,14 @@ public: ~ShortcutMapper() = default; void init(HINSTANCE hInst, HWND parent, GridState initState = STATE_MENU) { - Window::init(hInst, parent); - _currentState = initState; - }; + Window::init(hInst, parent); + _currentState = initState; + }; void destroy() override {}; void doDialog(bool isRTL = false) { - if (isRTL) - { - DLGTEMPLATE *pMyDlgTemplate = NULL; - HGLOBAL hMyDlgTemplate = makeRTLResource(IDD_SHORTCUTMAPPER_DLG, &pMyDlgTemplate); - ::DialogBoxIndirectParam(_hInst, pMyDlgTemplate, _hParent, dlgProc, reinterpret_cast(this)); - ::GlobalFree(hMyDlgTemplate); - } - else - ::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_SHORTCUTMAPPER_DLG), _hParent, dlgProc, reinterpret_cast(this)); - }; + StaticDialog::myCreateDialogBoxIndirectParam(IDD_SHORTCUTMAPPER_DLG, isRTL); + } void getClientRect(RECT & rc) const override; bool findKeyConflicts(__inout_opt std::wstring * const keyConflictLocation, diff --git a/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.cpp b/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.cpp index 783eb7681..9fd408c9e 100644 --- a/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.cpp +++ b/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.cpp @@ -120,12 +120,12 @@ long PluginsAdminDlg::searchFromCurrentSel(const PluginViewList& inWhichList, co return -1; } -void PluginsAdminDlg::create(int dialogID, bool isRTL, bool msgDestParent) +void PluginsAdminDlg::create(int dialogID, bool isRTL, bool msgDestParent, WORD fontSize) { // get plugin installation path and launch mode (Admin or normal) collectNppCurrentStatusInfos(); - StaticDialog::create(dialogID, isRTL, msgDestParent); + StaticDialog::create(dialogID, isRTL, msgDestParent, fontSize); RECT rect{}; getClientRect(rect); diff --git a/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.h b/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.h index d59269910..f8c6b8d79 100644 --- a/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.h +++ b/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.h @@ -143,9 +143,8 @@ class PluginsAdminDlg final : public StaticDialog { public : PluginsAdminDlg(); - ~PluginsAdminDlg() = default; - void create(int dialogID, bool isRTL = false, bool msgDestParent = true) override; + void create(int dialogID, bool isRTL = false, bool msgDestParent = true, WORD fontSize = 8) override; void doDialog(bool isRTL = false) { if (!isCreated()) diff --git a/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp b/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp index 4bd0f49f5..28d04ffab 100644 --- a/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp +++ b/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp @@ -1424,13 +1424,5 @@ int FileRelocalizerDlg::doDialog(const wchar_t *fn, bool isRTL) { _fullFilePath = fn; - if (isRTL) - { - DLGTEMPLATE *pMyDlgTemplate = NULL; - HGLOBAL hMyDlgTemplate = makeRTLResource(IDD_FILERELOCALIZER_DIALOG, &pMyDlgTemplate); - int result = static_cast(::DialogBoxIndirectParam(_hInst, pMyDlgTemplate, _hParent, dlgProc, reinterpret_cast(this))); - ::GlobalFree(hMyDlgTemplate); - return result; - } - return static_cast(::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_FILERELOCALIZER_DIALOG), _hParent, dlgProc, reinterpret_cast(this))); + return static_cast(StaticDialog::myCreateDialogBoxIndirectParam(IDD_FILERELOCALIZER_DIALOG, isRTL)); } diff --git a/PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp b/PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp index dfda93c4c..c664083fe 100644 --- a/PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp +++ b/PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp @@ -14,19 +14,20 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#include #include +#include + #include "StaticDialog.h" #include "Common.h" //#include "NppDarkMode.h" StaticDialog::~StaticDialog() { - if (isCreated()) + if (StaticDialog::isCreated()) { // Prevent run_dlgProc from doing anything, since its virtual ::SetWindowLongPtr(_hSelf, GWLP_USERDATA, 0); - destroy(); + StaticDialog::destroy(); } } @@ -213,53 +214,145 @@ RECT StaticDialog::getViewablePositionRect(RECT testPositionRc) const return returnRc; } -HGLOBAL StaticDialog::makeRTLResource(int dialogID, DLGTEMPLATE **ppMyDlgTemplate) +[[nodiscard]] static bool dupDlgTemplate(HINSTANCE hInst, int dialogID, std::vector& dlgTemplateData) { // Get Dlg Template resource - HRSRC hDialogRC = ::FindResource(_hInst, MAKEINTRESOURCE(dialogID), RT_DIALOG); + HRSRC hDialogRC = ::FindResourceW(hInst, MAKEINTRESOURCE(dialogID), RT_DIALOG); if (!hDialogRC) - return NULL; + return false; - HGLOBAL hDlgTemplate = ::LoadResource(_hInst, hDialogRC); + HGLOBAL hDlgTemplate = ::LoadResource(hInst, hDialogRC); if (!hDlgTemplate) - return NULL; + return false; - const DLGTEMPLATE *pDlgTemplate = static_cast(::LockResource(hDlgTemplate)); + const auto* pDlgTemplate = static_cast(::LockResource(hDlgTemplate)); if (!pDlgTemplate) - return NULL; + return false; // Duplicate Dlg Template resource - unsigned long sizeDlg = ::SizeofResource(_hInst, hDialogRC); - HGLOBAL hMyDlgTemplate = ::GlobalAlloc(GPTR, sizeDlg); - if (!hMyDlgTemplate) return nullptr; + const size_t sizeDlg = ::SizeofResource(hInst, hDialogRC); + dlgTemplateData.resize(sizeDlg); + ::memcpy(dlgTemplateData.data(), pDlgTemplate, sizeDlg); - *ppMyDlgTemplate = static_cast(::GlobalLock(hMyDlgTemplate)); - if (!*ppMyDlgTemplate) return nullptr; - - ::memcpy(*ppMyDlgTemplate, pDlgTemplate, sizeDlg); - - DLGTEMPLATEEX* pMyDlgTemplateEx = reinterpret_cast(*ppMyDlgTemplate); - if (!pMyDlgTemplateEx) return nullptr; - - if (pMyDlgTemplateEx->signature == 0xFFFF) - pMyDlgTemplateEx->exStyle |= WS_EX_LAYOUTRTL; - else - (*ppMyDlgTemplate)->dwExtendedStyle |= WS_EX_LAYOUTRTL; - - return hMyDlgTemplate; + return true; } -void StaticDialog::create(int dialogID, bool isRTL, bool msgDestParent) +[[nodiscard]] static bool setRTLResource(std::vector& dlgTemplateData) { - if (isRTL) + auto* pMyDlgTemplateEx = reinterpret_cast(dlgTemplateData.data()); + if (!pMyDlgTemplateEx) + return false; + + if (pMyDlgTemplateEx->signature == 0xFFFF && pMyDlgTemplateEx->dlgVer == 1) { - DLGTEMPLATE *pMyDlgTemplate = NULL; - HGLOBAL hMyDlgTemplate = makeRTLResource(dialogID, &pMyDlgTemplate); - _hSelf = ::CreateDialogIndirectParam(_hInst, pMyDlgTemplate, _hParent, dlgProc, reinterpret_cast(this)); - ::GlobalFree(hMyDlgTemplate); + pMyDlgTemplateEx->exStyle |= WS_EX_LAYOUTRTL; } else - _hSelf = ::CreateDialogParam(_hInst, MAKEINTRESOURCE(dialogID), _hParent, dlgProc, reinterpret_cast(this)); + { + auto* pMyDlgTemplate = reinterpret_cast(dlgTemplateData.data()); + pMyDlgTemplate->dwExtendedStyle |= WS_EX_LAYOUTRTL; + } + + return true; +} + +// inspired by https://stackoverflow.com/questions/14370238 +[[nodiscard]] static std::byte* skipSz(std::byte* pData) +{ + auto* str = reinterpret_cast(pData); // string + const size_t length = std::wcslen(str); + return reinterpret_cast(str + length + 1); +} + +[[nodiscard]] static std::byte* skipSzOrOrd(std::byte* pData) +{ + auto* ptrElement = reinterpret_cast(pData); + + if (*ptrElement == 0xFFFF) // ordinal + { + ptrElement += 2; + } + else // string or no element, same as skipSz + { + const auto* str = reinterpret_cast(ptrElement); + ptrElement += (std::wcslen(str) + 1); + } + + return reinterpret_cast(ptrElement); +} + +[[nodiscard]] static int setFontResource(std::vector& dlgTemplateData, WORD fontSize) +{ + enum result { failed = -1, noFont, success }; + + auto* pMyDlgTemplateEx = reinterpret_cast(dlgTemplateData.data()); + if (!pMyDlgTemplateEx || pMyDlgTemplateEx->signature != 0xFFFF || pMyDlgTemplateEx->dlgVer != 1) + return failed; + + // No need to check DS_SHELLFONT, as it already includes DS_SETFONT (DS_SETFONT | DS_FIXEDSYS) + if ((pMyDlgTemplateEx->style & DS_SETFONT) != DS_SETFONT) + return noFont; // allow RTL set before + + auto* pData = reinterpret_cast(pMyDlgTemplateEx); + pData += sizeof(DLGTEMPLATEEX); + // sz_Or_Ord menu + pData = skipSzOrOrd(pData); + // sz_Or_Ord windowClass; + pData = skipSzOrOrd(pData); + // WCHAR title[titleLen] + pData = skipSz(pData); + // WORD pointSize; + auto* pointSize = reinterpret_cast(pData); + if (fontSize > 0) + { + *pointSize = static_cast(DPIManagerV2::scaleFontForFactor(fontSize)); + } + + return success; +} + +[[nodiscard]] static bool modifyResource( + HINSTANCE hInst, + int dialogID, + std::vector& dlgTemplateData, + bool isRTL, + WORD fontSize) +{ + if (!dupDlgTemplate(hInst, dialogID, dlgTemplateData)) + return false; + + if (isRTL && !setRTLResource(dlgTemplateData)) + return false; + + if (fontSize != 0 && setFontResource(dlgTemplateData, fontSize) < 0) + return false; + + return true; +} + +HWND StaticDialog::myCreateDialogIndirectParam(int dialogID, bool isRTL, WORD fontSize) +{ + std::vector dlgTemplateData; + + if (!modifyResource(_hInst, dialogID, dlgTemplateData, isRTL, fontSize)) + return ::CreateDialogParam(_hInst, MAKEINTRESOURCE(dialogID), _hParent, dlgProc, reinterpret_cast(this)); + + return ::CreateDialogIndirectParam(_hInst, reinterpret_cast(dlgTemplateData.data()), _hParent, dlgProc, reinterpret_cast(this)); +} + +INT_PTR StaticDialog::myCreateDialogBoxIndirectParam(int dialogID, bool isRTL, WORD fontSize) +{ + std::vector dlgTemplateData; + + if (!modifyResource(_hInst, dialogID, dlgTemplateData, isRTL, fontSize)) + return ::DialogBoxParam(_hInst, MAKEINTRESOURCE(dialogID), _hParent, dlgProc, reinterpret_cast(this)); + + return ::DialogBoxIndirectParam(_hInst, reinterpret_cast(dlgTemplateData.data()), _hParent, dlgProc, reinterpret_cast(this)); +} + +void StaticDialog::create(int dialogID, bool isRTL, bool msgDestParent, WORD fontSize) +{ + _hSelf = StaticDialog::myCreateDialogIndirectParam(dialogID, isRTL, fontSize); if (!_hSelf) { diff --git a/PowerEditor/src/WinControls/StaticDialog/StaticDialog.h b/PowerEditor/src/WinControls/StaticDialog/StaticDialog.h index b475bdbb2..db9e193db 100644 --- a/PowerEditor/src/WinControls/StaticDialog/StaticDialog.h +++ b/PowerEditor/src/WinControls/StaticDialog/StaticDialog.h @@ -23,27 +23,37 @@ typedef HRESULT (WINAPI * ETDTProc) (HWND, DWORD); enum class PosAlign { left, right, top, bottom }; +#pragma pack(push, 1) struct DLGTEMPLATEEX { - WORD dlgVer = 0; - WORD signature = 0; - DWORD helpID = 0; - DWORD exStyle = 0; - DWORD style = 0; - WORD cDlgItems = 0; - short x = 0; - short y = 0; - short cx = 0; - short cy = 0; - // The structure has more fields but are variable length + WORD dlgVer = 0; + WORD signature = 0; + DWORD helpID = 0; + DWORD exStyle = 0; + DWORD style = 0; + WORD cDlgItems = 0; + short x = 0; + short y = 0; + short cx = 0; + short cy = 0; + // The structure has more fields but are variable length + //sz_Or_Ord menu; + //sz_Or_Ord windowClass; + //WCHAR title[titleLen]; + //WORD pointsize; + //WORD weight; + //BYTE italic; + //BYTE charset; + //WCHAR typeface[stringLen]; }; +#pragma pack(pop) class StaticDialog : public Window { public : - virtual ~StaticDialog(); + ~StaticDialog() override; - virtual void create(int dialogID, bool isRTL = false, bool msgDestParent = true); + virtual void create(int dialogID, bool isRTL = false, bool msgDestParent = true, WORD fontSize = 8); virtual bool isCreated() const { return (_hSelf != nullptr); @@ -91,5 +101,6 @@ protected: static intptr_t CALLBACK dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); virtual intptr_t CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) = 0; - HGLOBAL makeRTLResource(int dialogID, DLGTEMPLATE **ppMyDlgTemplate); + HWND myCreateDialogIndirectParam(int dialogID, bool isRTL, WORD fontSize); + INT_PTR myCreateDialogBoxIndirectParam(int dialogID, bool isRTL, WORD fontSize = 8); }; diff --git a/PowerEditor/src/WinControls/TabBar/TabBar.cpp b/PowerEditor/src/WinControls/TabBar/TabBar.cpp index 0e9608264..a5cfabca0 100644 --- a/PowerEditor/src/WinControls/TabBar/TabBar.cpp +++ b/PowerEditor/src/WinControls/TabBar/TabBar.cpp @@ -68,11 +68,11 @@ void TabBar::init(HINSTANCE hInst, HWND parent, bool isVertical, bool isMultiLin { const UINT dpi = DPIManagerV2::getDpiForWindow(_hParent); LOGFONT lf{ DPIManagerV2::getDefaultGUIFontForDpi(dpi) }; - lf.lfHeight = DPIManagerV2::scaleFont(8, dpi); + static const UINT fontSize = DPIManagerV2::scaleFontForFactor(8); + lf.lfHeight = DPIManagerV2::scaleFont(fontSize, dpi); _hFont = ::CreateFontIndirect(&lf); ::SendMessage(_hSelf, WM_SETFONT, reinterpret_cast(_hFont), 0); } - } void TabBar::destroy() @@ -398,7 +398,8 @@ void TabBar::setFont() _hFont = ::CreateFontIndirect(&lf); lf.lfWeight = FW_HEAVY; - lf.lfHeight = DPIManagerV2::scaleFont(10, _dpiManager.getDpi()); + static const UINT fontSize = DPIManagerV2::scaleFontForFactor(10); + lf.lfHeight = DPIManagerV2::scaleFont(fontSize, _dpiManager.getDpi()); _hLargeFont = ::CreateFontIndirect(&lf); diff --git a/PowerEditor/src/WinControls/TaskList/TaskListDlg.cpp b/PowerEditor/src/WinControls/TaskList/TaskListDlg.cpp index a92fbd533..8f6268f0a 100644 --- a/PowerEditor/src/WinControls/TaskList/TaskListDlg.cpp +++ b/PowerEditor/src/WinControls/TaskList/TaskListDlg.cpp @@ -47,17 +47,9 @@ static LRESULT CALLBACK hookProc(int nCode, WPARAM wParam, LPARAM lParam) return ::CallNextHookEx(hook, nCode, wParam, lParam); } - int TaskListDlg::doDialog(bool isRTL) - { - if (isRTL) - { - DLGTEMPLATE *pMyDlgTemplate = nullptr; - HGLOBAL hMyDlgTemplate = makeRTLResource(IDD_TASKLIST_DLG, &pMyDlgTemplate); - int result = static_cast(::DialogBoxIndirectParam(_hInst, pMyDlgTemplate, _hParent, dlgProc, reinterpret_cast(this))); - ::GlobalFree(hMyDlgTemplate); - return result; - } - return static_cast(::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_TASKLIST_DLG), _hParent, dlgProc, reinterpret_cast(this))); +int TaskListDlg::doDialog(bool isRTL) +{ + return static_cast(StaticDialog::myCreateDialogBoxIndirectParam(IDD_TASKLIST_DLG, isRTL)); } intptr_t CALLBACK TaskListDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) diff --git a/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.cpp b/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.cpp index 4286b95c9..c69ff1efe 100644 --- a/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.cpp +++ b/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.cpp @@ -729,7 +729,7 @@ int WindowsDlg::doDialog() { const auto dpiContext = DPIManagerV2::setThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED); - int result = static_cast(DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_WINDOWS), _hParent, dlgProc, reinterpret_cast(this))); + const auto result = static_cast(StaticDialog::myCreateDialogBoxIndirectParam(IDD_WINDOWS, false)); if (dpiContext != NULL) { diff --git a/PowerEditor/src/WinControls/shortcut/shortcut.h b/PowerEditor/src/WinControls/shortcut/shortcut.h index 465c78cab..56aef5d62 100644 --- a/PowerEditor/src/WinControls/shortcut/shortcut.h +++ b/PowerEditor/src/WinControls/shortcut/shortcut.h @@ -121,10 +121,9 @@ public: return !(a == b); }; - virtual intptr_t doDialog() - { - return ::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_SHORTCUT_DLG), _hParent, dlgProc, reinterpret_cast(this)); - }; + virtual int doDialog() { + return static_cast(StaticDialog::myCreateDialogBoxIndirectParam(IDD_SHORTCUT_DLG, false)); + } virtual bool isValid() const { //valid should only be used in cases where the shortcut isEnabled(). if (_keyCombo._key == 0) @@ -238,10 +237,9 @@ public: std::string toString() const override; std::string toString(size_t index) const; - intptr_t doDialog() override - { - return ::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_SHORTCUTSCINT_DLG), _hParent, dlgProc, reinterpret_cast(this)); - }; + int doDialog() override { + return static_cast(StaticDialog::myCreateDialogBoxIndirectParam(IDD_SHORTCUTSCINT_DLG, false)); + } //only compares the internal KeyCombos, nothing else friend inline bool operator==(const ScintillaKeyMap & a, const ScintillaKeyMap & b) { diff --git a/PowerEditor/src/dpiManagerV2.cpp b/PowerEditor/src/dpiManagerV2.cpp index 0379b7524..1784e159f 100644 --- a/PowerEditor/src/dpiManagerV2.cpp +++ b/PowerEditor/src/dpiManagerV2.cpp @@ -207,3 +207,18 @@ void DPIManagerV2::loadIcon(HINSTANCE hinst, const wchar_t* pszName, int cx, int *phico = static_cast(::LoadImage(hinst, pszName, IMAGE_ICON, cx, cy, fuLoad)); } } + +DWORD DPIManagerV2::getTextScaleFactor() +{ + static constexpr DWORD defaultVal = 100; + DWORD data = defaultVal; + DWORD dwBufSize = sizeof(data); + static constexpr LPCWSTR lpSubKey = L"Software\\Microsoft\\Accessibility"; + static constexpr LPCWSTR lpValue = L"TextScaleFactor"; + + if (::RegGetValueW(HKEY_CURRENT_USER, lpSubKey, lpValue, RRF_RT_REG_DWORD, nullptr, &data, &dwBufSize) == ERROR_SUCCESS) + { + return data; + } + return defaultVal; +} diff --git a/PowerEditor/src/dpiManagerV2.h b/PowerEditor/src/dpiManagerV2.h index dc4d6b177..d73c40ac0 100644 --- a/PowerEditor/src/dpiManagerV2.h +++ b/PowerEditor/src/dpiManagerV2.h @@ -137,6 +137,18 @@ public: static void loadIcon(HINSTANCE hinst, const wchar_t* pszName, int cx, int cy, HICON* phico, UINT fuLoad = LR_DEFAULTCOLOR); + [[nodiscard]] static DWORD getTextScaleFactor(); + + [[nodiscard]] static int scaleFontForFactor(int pt, UINT textScaleFactor) { + static constexpr UINT defaultFontScaleFactor = 100; + return scale(pt, textScaleFactor, defaultFontScaleFactor); + } + + [[nodiscard]] static int scaleFontForFactor(int pt) { + static const int scaleFactor = DPIManagerV2::getTextScaleFactor(); + return scaleFontForFactor(pt, scaleFactor); + } + private: UINT _dpi = USER_DEFAULT_SCREEN_DPI; };