Initial new dpi management support for Shortcut Mapper

ref #14959

Close #15089
pull/15145/head
ozone10 2024-05-05 18:12:08 +02:00 committed by Don Ho
parent 8329a9fec9
commit 3b515f1242
4 changed files with 36 additions and 31 deletions

View File

@ -46,7 +46,7 @@ void ShortcutMapper::initTabs()
::GetWindowPlacement(hTab, &wp);
::SendMessage(hTab, TCM_GETITEMRECT, 0, reinterpret_cast<LPARAM>(&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;

View File

@ -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<LPARAM>(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;

View File

@ -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

View File

@ -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);