Add basic text scale support

Fix #16427, close #17091
This commit is contained in:
ozone10 2025-10-19 14:24:40 +02:00 committed by Don HO
parent 2170115d1e
commit 5996ed7171
22 changed files with 292 additions and 215 deletions

View File

@ -70,15 +70,7 @@ const wchar_t defExtArray[nbSupportedLang][nbExtMax][extNameMax] =
void RegExtDlg::doDialog(bool isRTL) void RegExtDlg::doDialog(bool isRTL)
{ {
if (isRTL) StaticDialog::myCreateDialogBoxIndirectParam(IDD_REGEXT_BOX, isRTL);
{
DLGTEMPLATE *pMyDlgTemplate = nullptr;
HGLOBAL hMyDlgTemplate = makeRTLResource(IDD_REGEXT_BOX, &pMyDlgTemplate);
::DialogBoxIndirectParam(_hInst, pMyDlgTemplate, _hParent, dlgProc, reinterpret_cast<LPARAM>(this));
::GlobalFree(hMyDlgTemplate);
}
else
::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_REGEXT_BOX), _hParent, dlgProc, reinterpret_cast<LPARAM>(this));
} }
intptr_t CALLBACK RegExtDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) intptr_t CALLBACK RegExtDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam)

View File

@ -1609,7 +1609,8 @@ intptr_t CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
const bool isMonospaced = NppParameters::getInstance().getNppGUI()._monospacedFontFindDlg; const bool isMonospaced = NppParameters::getInstance().getNppGUI()._monospacedFontFindDlg;
if (isMonospaced) 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 else
{ {
@ -1623,7 +1624,8 @@ intptr_t CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
LOGFONT lf{}; LOGFONT lf{};
::GetObject(hFont, sizeof(lf), &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); _hComboBoxFont = ::CreateFontIndirect(&lf);
for (const auto& hComboBox : { hFindCombo, hReplaceCombo, hFiltersCombo, hDirCombo }) for (const auto& hComboBox : { hFindCombo, hReplaceCombo, hFiltersCombo, hDirCombo })
@ -4833,16 +4835,7 @@ void FindReplaceDlg::initOptionsFromDlg()
void FindInFinderDlg::doDialog(Finder *launcher, bool isRTL) void FindInFinderDlg::doDialog(Finder *launcher, bool isRTL)
{ {
_pFinder2Search = launcher; _pFinder2Search = launcher;
if (isRTL) StaticDialog::myCreateDialogBoxIndirectParam(IDD_FINDINFINDER_DLG, isRTL);
{
DLGTEMPLATE *pMyDlgTemplate = NULL;
HGLOBAL hMyDlgTemplate = makeRTLResource(IDD_FINDINFINDER_DLG, &pMyDlgTemplate);
::DialogBoxIndirectParam(_hInst, pMyDlgTemplate, _hParent, dlgProc, reinterpret_cast<LPARAM>(this));
::GlobalFree(hMyDlgTemplate);
}
else
::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_FINDINFINDER_DLG), _hParent, dlgProc, reinterpret_cast<LPARAM>(this));
} }
void FindReplaceDlg::doDialog(DIALOG_TYPE whichType, bool isRTL, bool toShow) void FindReplaceDlg::doDialog(DIALOG_TYPE whichType, bool isRTL, bool toShow)

View File

@ -1788,38 +1788,31 @@ void StylerDlg::move2CtrlRight(HWND hwndDlg, int ctrlID, HWND handle2Move, int h
::MoveWindow(handle2Move, p.x, p.y, handle2MoveWidth, handle2MoveHeight, TRUE); ::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<StylerDlg*>(::GetProp(_hSelf, L"Styler dialog prop"));
NppParameters& nppParam = NppParameters::getInstance(); NppParameters& nppParam = NppParameters::getInstance();
switch (message) switch (message)
{ {
case WM_INITDIALOG : case WM_INITDIALOG :
{ {
NppDarkMode::setDarkTitleBar(hwnd); NppDarkMode::setDarkTitleBar(_hSelf);
NppDarkMode::autoSubclassAndThemeChildControls(hwnd); NppDarkMode::autoSubclassAndThemeChildControls(_hSelf);
NativeLangSpeaker *pNativeLangSpeaker = nppParam.getNativeLangSpeaker(); NativeLangSpeaker *pNativeLangSpeaker = nppParam.getNativeLangSpeaker();
pNativeLangSpeaker->changeUserDefineLangPopupDlg(hwnd); pNativeLangSpeaker->changeUserDefineLangPopupDlg(_hSelf);
::SetProp(hwnd, L"Styler dialog prop", (HANDLE)lParam); ::SetProp(_hSelf, L"Styler dialog prop", reinterpret_cast<HANDLE>(lParam));
dlg = (StylerDlg *)::GetProp(hwnd, L"Styler dialog prop"); dlg = static_cast<StylerDlg*>(::GetProp(_hSelf, L"Styler dialog prop"));
Style & style = SharedParametersDialog::_pUserLang->_styles.getStyler(dlg->_stylerIndex); 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 ::SendDlgItemMessage(_hSelf, IDC_STYLER_CHECK_UNDERLINE, BM_SETCHECK, style._fontStyle & FONTSTYLE_UNDERLINE, 0);
RECT wrc{}; ::SendDlgItemMessage(_hSelf, IDC_STYLER_CHECK_ITALIC, BM_SETCHECK, style._fontStyle & FONTSTYLE_ITALIC, 0);
::GetWindowRect(dlg->_parent, &wrc); ::SendDlgItemMessage(_hSelf, IDC_STYLER_CHECK_BOLD, BM_SETCHECK, style._fontStyle & FONTSTYLE_BOLD, 0);
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);
// for the font size combo // 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) for (size_t j = 0 ; j < int(sizeof(fontSizeStrs))/(3*sizeof(wchar_t)) ; ++j)
::SendMessage(hFontSizeCombo, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(fontSizeStrs[j])); ::SendMessage(hFontSizeCombo, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(fontSizeStrs[j]));
@ -1834,7 +1827,7 @@ intptr_t CALLBACK StylerDlg::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPA
::SendMessage(hFontSizeCombo, CB_SETCURSEL, i, 0); ::SendMessage(hFontSizeCombo, CB_SETCURSEL, i, 0);
// for the font name combo // 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<wstring> & fontlist = nppParam.getFontList(); const std::vector<wstring> & fontlist = nppParam.getFontList();
for (size_t j = 0, len = fontlist.size() ; j < len ; ++j) 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)) if (style._bgColor == COLORREF(-1))
style._bgColor = white; style._bgColor = white;
dlg->_pFgColour->init(dlg->_hInst, hwnd); dlg->_pFgColour->init(dlg->_hInst, _hSelf);
dlg->_pFgColour->setColour(style._fgColor); dlg->_pFgColour->setColour(style._fgColor);
bool isFgEnabled = (style._colorStyle & COLORSTYLE_FOREGROUND) != 0; bool isFgEnabled = (style._colorStyle & COLORSTYLE_FOREGROUND) != 0;
dlg->_pFgColour->setEnabled(isFgEnabled); dlg->_pFgColour->setEnabled(isFgEnabled);
::SendDlgItemMessage(hwnd, IDC_STYLER_CHECK_FG_TRANSPARENT, BM_SETCHECK, !isFgEnabled, 0); ::SendDlgItemMessage(_hSelf, IDC_STYLER_CHECK_FG_TRANSPARENT, BM_SETCHECK, !isFgEnabled, 0);
dlg->_pBgColour->init(dlg->_hInst, hwnd); dlg->_pBgColour->init(dlg->_hInst, _hSelf);
dlg->_pBgColour->setColour(style._bgColor); dlg->_pBgColour->setColour(style._bgColor);
bool isBgEnabled = (style._colorStyle & COLORSTYLE_BACKGROUND) != 0; bool isBgEnabled = (style._colorStyle & COLORSTYLE_BACKGROUND) != 0;
dlg->_pBgColour->setEnabled(isBgEnabled); 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); const int moveSize = DPIManagerV2::scale(25, _hSelf);
dlg->move2CtrlRight(hwnd, IDC_STYLER_FG_STATIC, dlg->_pFgColour->getHSelf(), moveSize, moveSize); dlg->move2CtrlRight(_hSelf, IDC_STYLER_FG_STATIC, dlg->_pFgColour->getHSelf(), moveSize, moveSize);
dlg->move2CtrlRight(hwnd, IDC_STYLER_BG_STATIC, dlg->_pBgColour->getHSelf(), moveSize, moveSize); dlg->move2CtrlRight(_hSelf, IDC_STYLER_BG_STATIC, dlg->_pBgColour->getHSelf(), moveSize, moveSize);
dlg->_pFgColour->display(); dlg->_pFgColour->display();
dlg->_pBgColour->display(); dlg->_pBgColour->display();
@ -1874,9 +1867,12 @@ intptr_t CALLBACK StylerDlg::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPA
unordered_map<int, int>::iterator iter = globalMappper().nestingMapper.begin(); unordered_map<int, int>::iterator iter = globalMappper().nestingMapper.begin();
for (; iter != globalMappper().nestingMapper.end(); ++iter) for (; iter != globalMappper().nestingMapper.end(); ++iter)
{ {
::SendDlgItemMessage(hwnd, iter->first, BM_SETCHECK, style._nesting & iter->second, 0); ::SendDlgItemMessage(_hSelf, iter->first, BM_SETCHECK, style._nesting & iter->second, 0);
::EnableWindow(::GetDlgItem(hwnd, iter->first), dlg->_enabledNesters & iter->second); ::EnableWindow(::GetDlgItem(_hSelf, iter->first), dlg->_enabledNesters & iter->second);
} }
goToCenter();
return TRUE; return TRUE;
} }
@ -1907,19 +1903,19 @@ intptr_t CALLBACK StylerDlg::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPA
case NPPM_INTERNAL_REFRESHDARKMODE: case NPPM_INTERNAL_REFRESHDARKMODE:
{ {
NppDarkMode::setDarkTitleBar(hwnd); NppDarkMode::setDarkTitleBar(_hSelf);
NppDarkMode::autoThemeChildControls(hwnd); NppDarkMode::autoThemeChildControls(_hSelf);
::SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); ::SetWindowPos(_hSelf, nullptr, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
return TRUE; return TRUE;
} }
case WM_DPICHANGED: case WM_DPICHANGED:
{ {
const int moveSize = DPIManagerV2::scale(25, hwnd); const int moveSize = DPIManagerV2::scale(25, _hSelf);
dlg->move2CtrlRight(hwnd, IDC_STYLER_FG_STATIC, dlg->_pFgColour->getHSelf(), moveSize, moveSize); dlg->move2CtrlRight(_hSelf, IDC_STYLER_FG_STATIC, dlg->_pFgColour->getHSelf(), moveSize, moveSize);
dlg->move2CtrlRight(hwnd, IDC_STYLER_BG_STATIC, dlg->_pBgColour->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; 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); Style & style = SharedParametersDialog::_pUserLang->_styles.getStyler(dlg->_stylerIndex);
if (HIWORD(wParam) == CBN_SELCHANGE) 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 (LOWORD(wParam) == IDC_STYLER_COMBO_FONT_SIZE)
{ {
if (i != 0) if (i != 0)
{ {
const size_t intStrLen = 3; const size_t intStrLen = 3;
wchar_t intStr[intStrLen] = { '\0' }; 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<size_t>(lbTextLen) > intStrLen - 1) if (static_cast<size_t>(lbTextLen) > intStrLen - 1)
return TRUE; return TRUE;
::SendDlgItemMessage(hwnd, LOWORD(wParam), CB_GETLBTEXT, i, reinterpret_cast<LPARAM>(intStr)); ::SendDlgItemMessage(_hSelf, LOWORD(wParam), CB_GETLBTEXT, i, reinterpret_cast<LPARAM>(intStr));
if (!intStr[0]) if (!intStr[0])
style._fontSize = -1; style._fontSize = -1;
else 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) 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<wchar_t*>(::SendDlgItemMessage(_hSelf, LOWORD(wParam), CB_GETITEMDATA, i, 0));
} }
// show changes to user, re-color document // 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) if (SharedParametersDialog::_pScintilla->getCurrentBuffer()->getLangType() == L_USER)
SharedParametersDialog::_pScintilla->styleChange(); SharedParametersDialog::_pScintilla->styleChange();
::RemoveProp(hwnd, L"Styler dialog prop"); ::RemoveProp(_hSelf, L"Styler dialog prop");
::EndDialog(hwnd, IDCANCEL); ::EndDialog(_hSelf, IDCANCEL);
return TRUE; return TRUE;
} }
if (wParam == IDOK) if (wParam == IDOK)
{ {
::RemoveProp(hwnd, L"Styler dialog prop"); ::RemoveProp(_hSelf, L"Styler dialog prop");
::EndDialog(hwnd, IDOK); ::EndDialog(_hSelf, IDOK);
return TRUE; 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) 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->setEnabled(!isTransparent);
dlg->_pFgColour->redraw(); dlg->_pFgColour->redraw();
if (isTransparent) 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) 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->setEnabled(!isTransparent);
dlg->_pBgColour->redraw(); dlg->_pBgColour->redraw();
if (isTransparent) if (isTransparent)
@ -2028,7 +2024,7 @@ intptr_t CALLBACK StylerDlg::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPA
{ {
style._colorStyle &= ~COLORSTYLE_FOREGROUND; 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()) if (dlg->_pBgColour->isEnabled())
{ {
@ -2038,21 +2034,21 @@ intptr_t CALLBACK StylerDlg::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPA
{ {
style._colorStyle &= ~COLORSTYLE_BACKGROUND; 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; 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; 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; 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._fontStyle |= FONTSTYLE_UNDERLINE;
style._nesting = SCE_USER_MASK_NESTING_NONE; style._nesting = SCE_USER_MASK_NESTING_NONE;
unordered_map<int, int>::iterator iter = globalMappper().nestingMapper.begin(); unordered_map<int, int>::iterator iter = globalMappper().nestingMapper.begin();
for (; iter != globalMappper().nestingMapper.end(); ++iter) 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; style._nesting |= iter->second;
} }
@ -2064,11 +2060,22 @@ intptr_t CALLBACK StylerDlg::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPA
} }
return FALSE; return FALSE;
} }
case WM_CLOSE: 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; return TRUE;
} }
default :
default:
return FALSE; return FALSE;
} }
return FALSE; return FALSE;

View File

@ -399,8 +399,8 @@ public :
}; };
intptr_t doDialog() { intptr_t doDialog() {
return ::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_STRING_DLG), _hParent, dlgProc, reinterpret_cast<LPARAM>(this)); return StaticDialog::myCreateDialogBoxIndirectParam(IDD_STRING_DLG, false);
}; }
void destroy() override {}; void destroy() override {};
@ -423,32 +423,34 @@ private :
WNDPROC _oldEditProc = nullptr; WNDPROC _oldEditProc = nullptr;
}; };
class StylerDlg class StylerDlg : public StaticDialog
{ {
public: public:
StylerDlg( HINSTANCE hInst, HWND parent, int stylerIndex = 0, int enabledNesters = -1): StylerDlg(HINSTANCE hInst, HWND parent, int stylerIndex = 0, int enabledNesters = -1):
_hInst(hInst), _parent(parent), _stylerIndex(stylerIndex), _enabledNesters(enabledNesters) { _stylerIndex(stylerIndex), _enabledNesters(enabledNesters) {
Window::init(hInst, parent);
_pFgColour = new ColourPicker; _pFgColour = new ColourPicker;
_pBgColour = new ColourPicker; _pBgColour = new ColourPicker;
_initialStyle = SharedParametersDialog::_pUserLang->_styles.getStyler(stylerIndex); _initialStyle = SharedParametersDialog::_pUserLang->_styles.getStyler(stylerIndex);
}; }
~StylerDlg() { ~StylerDlg() override {
_pFgColour->destroy(); _pFgColour->destroy();
_pBgColour->destroy(); _pBgColour->destroy();
delete _pFgColour; delete _pFgColour;
delete _pBgColour; delete _pBgColour;
}; }
long doDialog() { void destroy() override {}
return long(::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_STYLER_POPUP_DLG), _parent, dlgProc, reinterpret_cast<LPARAM>(this)));
};
static intptr_t CALLBACK dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); int doDialog() {
return static_cast<int>(StaticDialog::myCreateDialogBoxIndirectParam(IDD_STYLER_POPUP_DLG, false));
}
protected:
intptr_t CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) override;
private: private:
HINSTANCE _hInst = nullptr;
HWND _parent = nullptr;
int _stylerIndex = 0; int _stylerIndex = 0;
int _enabledNesters = 0; int _enabledNesters = 0;
ColourPicker * _pFgColour = nullptr; ColourPicker * _pFgColour = nullptr;

View File

@ -251,7 +251,7 @@ BEGIN
END END
IDD_STYLER_POPUP_DLG DIALOGEX 0, 0, 324, 305 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" CAPTION "Styler Dialog"
FONT 8, "MS Shell Dlg", 400, 0, 0x1 FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN BEGIN

View File

@ -29,10 +29,6 @@ public :
ColumnEditorDlg() = default; ColumnEditorDlg() = default;
void init(HINSTANCE hInst, HWND hPere, ScintillaEditView **ppEditView); 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) { void doDialog(bool isRTL = false) {
if (!isCreated()) if (!isCreated())
create(IDD_COLUMNEDIT, isRTL); create(IDD_COLUMNEDIT, isRTL);

View File

@ -764,16 +764,7 @@ intptr_t CALLBACK CmdLineArgsDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
void DoSaveOrNotBox::doDialog(bool isRTL) void DoSaveOrNotBox::doDialog(bool isRTL)
{ {
StaticDialog::myCreateDialogBoxIndirectParam(IDD_DOSAVEORNOTBOX, isRTL);
if (isRTL)
{
DLGTEMPLATE *pMyDlgTemplate = NULL;
HGLOBAL hMyDlgTemplate = makeRTLResource(IDD_DOSAVEORNOTBOX, &pMyDlgTemplate);
::DialogBoxIndirectParam(_hInst, pMyDlgTemplate, _hParent, dlgProc, reinterpret_cast<LPARAM>(this));
::GlobalFree(hMyDlgTemplate);
}
else
::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_DOSAVEORNOTBOX), _hParent, dlgProc, reinterpret_cast<LPARAM>(this));
} }
void DoSaveOrNotBox::changeLang() void DoSaveOrNotBox::changeLang()
@ -885,16 +876,7 @@ intptr_t CALLBACK DoSaveOrNotBox::run_dlgProc(UINT message, WPARAM wParam, LPARA
void DoSaveAllBox::doDialog(bool isRTL) void DoSaveAllBox::doDialog(bool isRTL)
{ {
StaticDialog::myCreateDialogBoxIndirectParam(IDD_DOSAVEALLBOX, isRTL);
if (isRTL)
{
DLGTEMPLATE* pMyDlgTemplate = NULL;
HGLOBAL hMyDlgTemplate = makeRTLResource(IDD_DOSAVEALLBOX, &pMyDlgTemplate);
::DialogBoxIndirectParam(_hInst, pMyDlgTemplate, _hParent, dlgProc, reinterpret_cast<LPARAM>(this));
::GlobalFree(hMyDlgTemplate);
}
else
::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_DOSAVEALLBOX), _hParent, dlgProc, reinterpret_cast<LPARAM>(this));
} }
void DoSaveAllBox::changeLang() void DoSaveAllBox::changeLang()

View File

@ -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()) if ((NppParameters::getInstance()).isTransparentAvailable())
{ {

View File

@ -71,7 +71,7 @@ class WordStyleDlg : public StaticDialog
{ {
public : public :
WordStyleDlg() = default; WordStyleDlg() = default;
~WordStyleDlg() { ~WordStyleDlg() override {
_goToSettings.destroy(); _goToSettings.destroy();
_globalOverrideLinkTip.destroy(); _globalOverrideLinkTip.destroy();
@ -79,7 +79,7 @@ public :
::DestroyWindow(_globalOverrideTip); ::DestroyWindow(_globalOverrideTip);
}; };
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); void doDialog(bool isRTL = false);
void destroy() override; void destroy() override;
void prepare2Cancel(); void prepare2Cancel();

View File

@ -79,7 +79,7 @@ void DockingCont::doDialog(bool willBeShown, bool isFloating)
if (!isCreated()) if (!isCreated())
{ {
NativeLangSpeaker* pNativeSpeaker = NppParameters::getInstance().getNativeLangSpeaker(); NativeLangSpeaker* pNativeSpeaker = NppParameters::getInstance().getNativeLangSpeaker();
create(IDD_CONTAINER_DLG, pNativeSpeaker->isRTL()); create(IDD_CONTAINER_DLG, pNativeSpeaker->isRTL(), true, 0);
_isFloating = isFloating; _isFloating = isFloating;

View File

@ -39,16 +39,8 @@ public:
void destroy() override {}; void destroy() override {};
void doDialog(bool isRTL = false) { void doDialog(bool isRTL = false) {
if (isRTL) StaticDialog::myCreateDialogBoxIndirectParam(IDD_SHORTCUTMAPPER_DLG, isRTL);
{
DLGTEMPLATE *pMyDlgTemplate = NULL;
HGLOBAL hMyDlgTemplate = makeRTLResource(IDD_SHORTCUTMAPPER_DLG, &pMyDlgTemplate);
::DialogBoxIndirectParam(_hInst, pMyDlgTemplate, _hParent, dlgProc, reinterpret_cast<LPARAM>(this));
::GlobalFree(hMyDlgTemplate);
} }
else
::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_SHORTCUTMAPPER_DLG), _hParent, dlgProc, reinterpret_cast<LPARAM>(this));
};
void getClientRect(RECT & rc) const override; void getClientRect(RECT & rc) const override;
bool findKeyConflicts(__inout_opt std::wstring * const keyConflictLocation, bool findKeyConflicts(__inout_opt std::wstring * const keyConflictLocation,

View File

@ -120,12 +120,12 @@ long PluginsAdminDlg::searchFromCurrentSel(const PluginViewList& inWhichList, co
return -1; 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) // get plugin installation path and launch mode (Admin or normal)
collectNppCurrentStatusInfos(); collectNppCurrentStatusInfos();
StaticDialog::create(dialogID, isRTL, msgDestParent); StaticDialog::create(dialogID, isRTL, msgDestParent, fontSize);
RECT rect{}; RECT rect{};
getClientRect(rect); getClientRect(rect);

View File

@ -143,9 +143,8 @@ class PluginsAdminDlg final : public StaticDialog
{ {
public : public :
PluginsAdminDlg(); 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) { void doDialog(bool isRTL = false) {
if (!isCreated()) if (!isCreated())

View File

@ -1424,13 +1424,5 @@ int FileRelocalizerDlg::doDialog(const wchar_t *fn, bool isRTL)
{ {
_fullFilePath = fn; _fullFilePath = fn;
if (isRTL) return static_cast<int>(StaticDialog::myCreateDialogBoxIndirectParam(IDD_FILERELOCALIZER_DIALOG, isRTL));
{
DLGTEMPLATE *pMyDlgTemplate = NULL;
HGLOBAL hMyDlgTemplate = makeRTLResource(IDD_FILERELOCALIZER_DIALOG, &pMyDlgTemplate);
int result = static_cast<int32_t>(::DialogBoxIndirectParam(_hInst, pMyDlgTemplate, _hParent, dlgProc, reinterpret_cast<LPARAM>(this)));
::GlobalFree(hMyDlgTemplate);
return result;
}
return static_cast<int32_t>(::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_FILERELOCALIZER_DIALOG), _hParent, dlgProc, reinterpret_cast<LPARAM>(this)));
} }

View File

@ -14,19 +14,20 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <stdio.h>
#include <windows.h> #include <windows.h>
#include <cstring>
#include "StaticDialog.h" #include "StaticDialog.h"
#include "Common.h" #include "Common.h"
//#include "NppDarkMode.h" //#include "NppDarkMode.h"
StaticDialog::~StaticDialog() StaticDialog::~StaticDialog()
{ {
if (isCreated()) if (StaticDialog::isCreated())
{ {
// Prevent run_dlgProc from doing anything, since its virtual // Prevent run_dlgProc from doing anything, since its virtual
::SetWindowLongPtr(_hSelf, GWLP_USERDATA, 0); ::SetWindowLongPtr(_hSelf, GWLP_USERDATA, 0);
destroy(); StaticDialog::destroy();
} }
} }
@ -213,53 +214,145 @@ RECT StaticDialog::getViewablePositionRect(RECT testPositionRc) const
return returnRc; return returnRc;
} }
HGLOBAL StaticDialog::makeRTLResource(int dialogID, DLGTEMPLATE **ppMyDlgTemplate) [[nodiscard]] static bool dupDlgTemplate(HINSTANCE hInst, int dialogID, std::vector<std::byte>& dlgTemplateData)
{ {
// Get Dlg Template resource // Get Dlg Template resource
HRSRC hDialogRC = ::FindResource(_hInst, MAKEINTRESOURCE(dialogID), RT_DIALOG); HRSRC hDialogRC = ::FindResourceW(hInst, MAKEINTRESOURCE(dialogID), RT_DIALOG);
if (!hDialogRC) if (!hDialogRC)
return NULL; return false;
HGLOBAL hDlgTemplate = ::LoadResource(_hInst, hDialogRC); HGLOBAL hDlgTemplate = ::LoadResource(hInst, hDialogRC);
if (!hDlgTemplate) if (!hDlgTemplate)
return NULL; return false;
const DLGTEMPLATE *pDlgTemplate = static_cast<DLGTEMPLATE *>(::LockResource(hDlgTemplate)); const auto* pDlgTemplate = static_cast<DLGTEMPLATE*>(::LockResource(hDlgTemplate));
if (!pDlgTemplate) if (!pDlgTemplate)
return NULL; return false;
// Duplicate Dlg Template resource // Duplicate Dlg Template resource
unsigned long sizeDlg = ::SizeofResource(_hInst, hDialogRC); const size_t sizeDlg = ::SizeofResource(hInst, hDialogRC);
HGLOBAL hMyDlgTemplate = ::GlobalAlloc(GPTR, sizeDlg); dlgTemplateData.resize(sizeDlg);
if (!hMyDlgTemplate) return nullptr; ::memcpy(dlgTemplateData.data(), pDlgTemplate, sizeDlg);
*ppMyDlgTemplate = static_cast<DLGTEMPLATE *>(::GlobalLock(hMyDlgTemplate)); return true;
if (!*ppMyDlgTemplate) return nullptr;
::memcpy(*ppMyDlgTemplate, pDlgTemplate, sizeDlg);
DLGTEMPLATEEX* pMyDlgTemplateEx = reinterpret_cast<DLGTEMPLATEEX *>(*ppMyDlgTemplate);
if (!pMyDlgTemplateEx) return nullptr;
if (pMyDlgTemplateEx->signature == 0xFFFF)
pMyDlgTemplateEx->exStyle |= WS_EX_LAYOUTRTL;
else
(*ppMyDlgTemplate)->dwExtendedStyle |= WS_EX_LAYOUTRTL;
return hMyDlgTemplate;
} }
void StaticDialog::create(int dialogID, bool isRTL, bool msgDestParent) [[nodiscard]] static bool setRTLResource(std::vector<std::byte>& dlgTemplateData)
{ {
if (isRTL) auto* pMyDlgTemplateEx = reinterpret_cast<DLGTEMPLATEEX*>(dlgTemplateData.data());
if (!pMyDlgTemplateEx)
return false;
if (pMyDlgTemplateEx->signature == 0xFFFF && pMyDlgTemplateEx->dlgVer == 1)
{ {
DLGTEMPLATE *pMyDlgTemplate = NULL; pMyDlgTemplateEx->exStyle |= WS_EX_LAYOUTRTL;
HGLOBAL hMyDlgTemplate = makeRTLResource(dialogID, &pMyDlgTemplate);
_hSelf = ::CreateDialogIndirectParam(_hInst, pMyDlgTemplate, _hParent, dlgProc, reinterpret_cast<LPARAM>(this));
::GlobalFree(hMyDlgTemplate);
} }
else else
_hSelf = ::CreateDialogParam(_hInst, MAKEINTRESOURCE(dialogID), _hParent, dlgProc, reinterpret_cast<LPARAM>(this)); {
auto* pMyDlgTemplate = reinterpret_cast<DLGTEMPLATE*>(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<WCHAR*>(pData); // string
const size_t length = std::wcslen(str);
return reinterpret_cast<std::byte*>(str + length + 1);
}
[[nodiscard]] static std::byte* skipSzOrOrd(std::byte* pData)
{
auto* ptrElement = reinterpret_cast<WORD*>(pData);
if (*ptrElement == 0xFFFF) // ordinal
{
ptrElement += 2;
}
else // string or no element, same as skipSz
{
const auto* str = reinterpret_cast<WCHAR*>(ptrElement);
ptrElement += (std::wcslen(str) + 1);
}
return reinterpret_cast<std::byte*>(ptrElement);
}
[[nodiscard]] static int setFontResource(std::vector<std::byte>& dlgTemplateData, WORD fontSize)
{
enum result { failed = -1, noFont, success };
auto* pMyDlgTemplateEx = reinterpret_cast<DLGTEMPLATEEX*>(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<std::byte*>(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<WORD*>(pData);
if (fontSize > 0)
{
*pointSize = static_cast<WORD>(DPIManagerV2::scaleFontForFactor(fontSize));
}
return success;
}
[[nodiscard]] static bool modifyResource(
HINSTANCE hInst,
int dialogID,
std::vector<std::byte>& 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<std::byte> dlgTemplateData;
if (!modifyResource(_hInst, dialogID, dlgTemplateData, isRTL, fontSize))
return ::CreateDialogParam(_hInst, MAKEINTRESOURCE(dialogID), _hParent, dlgProc, reinterpret_cast<LPARAM>(this));
return ::CreateDialogIndirectParam(_hInst, reinterpret_cast<DLGTEMPLATE*>(dlgTemplateData.data()), _hParent, dlgProc, reinterpret_cast<LPARAM>(this));
}
INT_PTR StaticDialog::myCreateDialogBoxIndirectParam(int dialogID, bool isRTL, WORD fontSize)
{
std::vector<std::byte> dlgTemplateData;
if (!modifyResource(_hInst, dialogID, dlgTemplateData, isRTL, fontSize))
return ::DialogBoxParam(_hInst, MAKEINTRESOURCE(dialogID), _hParent, dlgProc, reinterpret_cast<LPARAM>(this));
return ::DialogBoxIndirectParam(_hInst, reinterpret_cast<DLGTEMPLATE*>(dlgTemplateData.data()), _hParent, dlgProc, reinterpret_cast<LPARAM>(this));
}
void StaticDialog::create(int dialogID, bool isRTL, bool msgDestParent, WORD fontSize)
{
_hSelf = StaticDialog::myCreateDialogIndirectParam(dialogID, isRTL, fontSize);
if (!_hSelf) if (!_hSelf)
{ {

View File

@ -23,6 +23,7 @@ typedef HRESULT (WINAPI * ETDTProc) (HWND, DWORD);
enum class PosAlign { left, right, top, bottom }; enum class PosAlign { left, right, top, bottom };
#pragma pack(push, 1)
struct DLGTEMPLATEEX struct DLGTEMPLATEEX
{ {
WORD dlgVer = 0; WORD dlgVer = 0;
@ -36,14 +37,23 @@ struct DLGTEMPLATEEX
short cx = 0; short cx = 0;
short cy = 0; short cy = 0;
// The structure has more fields but are variable length // 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 class StaticDialog : public Window
{ {
public : 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 { virtual bool isCreated() const {
return (_hSelf != nullptr); return (_hSelf != nullptr);
@ -91,5 +101,6 @@ protected:
static intptr_t CALLBACK dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); 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; 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);
}; };

View File

@ -68,11 +68,11 @@ void TabBar::init(HINSTANCE hInst, HWND parent, bool isVertical, bool isMultiLin
{ {
const UINT dpi = DPIManagerV2::getDpiForWindow(_hParent); const UINT dpi = DPIManagerV2::getDpiForWindow(_hParent);
LOGFONT lf{ DPIManagerV2::getDefaultGUIFontForDpi(dpi) }; 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); _hFont = ::CreateFontIndirect(&lf);
::SendMessage(_hSelf, WM_SETFONT, reinterpret_cast<WPARAM>(_hFont), 0); ::SendMessage(_hSelf, WM_SETFONT, reinterpret_cast<WPARAM>(_hFont), 0);
} }
} }
void TabBar::destroy() void TabBar::destroy()
@ -398,7 +398,8 @@ void TabBar::setFont()
_hFont = ::CreateFontIndirect(&lf); _hFont = ::CreateFontIndirect(&lf);
lf.lfWeight = FW_HEAVY; 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); _hLargeFont = ::CreateFontIndirect(&lf);

View File

@ -47,17 +47,9 @@ static LRESULT CALLBACK hookProc(int nCode, WPARAM wParam, LPARAM lParam)
return ::CallNextHookEx(hook, nCode, wParam, lParam); return ::CallNextHookEx(hook, nCode, wParam, lParam);
} }
int TaskListDlg::doDialog(bool isRTL) int TaskListDlg::doDialog(bool isRTL)
{ {
if (isRTL) return static_cast<int>(StaticDialog::myCreateDialogBoxIndirectParam(IDD_TASKLIST_DLG, isRTL));
{
DLGTEMPLATE *pMyDlgTemplate = nullptr;
HGLOBAL hMyDlgTemplate = makeRTLResource(IDD_TASKLIST_DLG, &pMyDlgTemplate);
int result = static_cast<int32_t>(::DialogBoxIndirectParam(_hInst, pMyDlgTemplate, _hParent, dlgProc, reinterpret_cast<LPARAM>(this)));
::GlobalFree(hMyDlgTemplate);
return result;
}
return static_cast<int32_t>(::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_TASKLIST_DLG), _hParent, dlgProc, reinterpret_cast<LPARAM>(this)));
} }
intptr_t CALLBACK TaskListDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) intptr_t CALLBACK TaskListDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam)

View File

@ -729,7 +729,7 @@ int WindowsDlg::doDialog()
{ {
const auto dpiContext = DPIManagerV2::setThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED); const auto dpiContext = DPIManagerV2::setThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED);
int result = static_cast<int>(DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_WINDOWS), _hParent, dlgProc, reinterpret_cast<LPARAM>(this))); const auto result = static_cast<int>(StaticDialog::myCreateDialogBoxIndirectParam(IDD_WINDOWS, false));
if (dpiContext != NULL) if (dpiContext != NULL)
{ {

View File

@ -121,10 +121,9 @@ public:
return !(a == b); return !(a == b);
}; };
virtual intptr_t doDialog() virtual int doDialog() {
{ return static_cast<int>(StaticDialog::myCreateDialogBoxIndirectParam(IDD_SHORTCUT_DLG, false));
return ::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_SHORTCUT_DLG), _hParent, dlgProc, reinterpret_cast<LPARAM>(this)); }
};
virtual bool isValid() const { //valid should only be used in cases where the shortcut isEnabled(). virtual bool isValid() const { //valid should only be used in cases where the shortcut isEnabled().
if (_keyCombo._key == 0) if (_keyCombo._key == 0)
@ -238,10 +237,9 @@ public:
std::string toString() const override; std::string toString() const override;
std::string toString(size_t index) const; std::string toString(size_t index) const;
intptr_t doDialog() override int doDialog() override {
{ return static_cast<int>(StaticDialog::myCreateDialogBoxIndirectParam(IDD_SHORTCUTSCINT_DLG, false));
return ::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_SHORTCUTSCINT_DLG), _hParent, dlgProc, reinterpret_cast<LPARAM>(this)); }
};
//only compares the internal KeyCombos, nothing else //only compares the internal KeyCombos, nothing else
friend inline bool operator==(const ScintillaKeyMap & a, const ScintillaKeyMap & b) { friend inline bool operator==(const ScintillaKeyMap & a, const ScintillaKeyMap & b) {

View File

@ -207,3 +207,18 @@ void DPIManagerV2::loadIcon(HINSTANCE hinst, const wchar_t* pszName, int cx, int
*phico = static_cast<HICON>(::LoadImage(hinst, pszName, IMAGE_ICON, cx, cy, fuLoad)); *phico = static_cast<HICON>(::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;
}

View File

@ -137,6 +137,18 @@ public:
static void loadIcon(HINSTANCE hinst, const wchar_t* pszName, int cx, int cy, HICON* phico, UINT fuLoad = LR_DEFAULTCOLOR); 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: private:
UINT _dpi = USER_DEFAULT_SCREEN_DPI; UINT _dpi = USER_DEFAULT_SCREEN_DPI;
}; };