Add dpi support to dialogs
- About - DebugInfo - Save All - Close All ref #14959 Close #14989
This commit is contained in:
parent
01a088f994
commit
27e77cf6d6
|
@ -85,31 +85,41 @@ intptr_t CALLBACK AboutDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPar
|
|||
case NPPM_INTERNAL_REFRESHDARKMODE:
|
||||
{
|
||||
NppDarkMode::autoThemeChildControls(_hSelf);
|
||||
if (_hIcon != nullptr)
|
||||
{
|
||||
::DestroyIcon(_hIcon);
|
||||
_hIcon = nullptr;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
case WM_DRAWITEM :
|
||||
case WM_DPICHANGED:
|
||||
{
|
||||
DPIManager& dpiManager = NppParameters::getInstance()._dpiManager;
|
||||
int iconSideSize = 80;
|
||||
int w = dpiManager.scaleX(iconSideSize);
|
||||
int h = dpiManager.scaleY(iconSideSize);
|
||||
DPIManagerV2::setDpiWP(wParam);
|
||||
destroy();
|
||||
//setPositionDpi(lParam);
|
||||
getClientRect(_rc);
|
||||
|
||||
HICON hIcon = nullptr;
|
||||
if (NppDarkMode::isEnabled())
|
||||
hIcon = (HICON)::LoadImage(_hInst, MAKEINTRESOURCE(IDI_CHAMELEON_DM), IMAGE_ICON, w, h, LR_DEFAULTSIZE);
|
||||
else
|
||||
hIcon = (HICON)::LoadImage(_hInst, MAKEINTRESOURCE(IDI_CHAMELEON), IMAGE_ICON, w, h, LR_DEFAULTSIZE);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
case WM_DRAWITEM:
|
||||
{
|
||||
const int iconSize = DPIManagerV2::scale(80);
|
||||
if (_hIcon == nullptr)
|
||||
{
|
||||
DPIManagerV2::loadIcon(_hInst, MAKEINTRESOURCE(NppDarkMode::isEnabled() ? IDI_CHAMELEON_DM : IDI_CHAMELEON), iconSize, iconSize, &_hIcon);
|
||||
}
|
||||
|
||||
//HICON hIcon = (HICON)::LoadImage(_hInst, MAKEINTRESOURCE(IDI_JESUISCHARLIE), IMAGE_ICON, 64, 64, LR_DEFAULTSIZE);
|
||||
//HICON hIcon = (HICON)::LoadImage(_hInst, MAKEINTRESOURCE(IDI_GILETJAUNE), IMAGE_ICON, 64, 64, LR_DEFAULTSIZE);
|
||||
//HICON hIcon = (HICON)::LoadImage(_hInst, MAKEINTRESOURCE(IDI_SAMESEXMARRIAGE), IMAGE_ICON, 64, 64, LR_DEFAULTSIZE);
|
||||
DRAWITEMSTRUCT *pdis = (DRAWITEMSTRUCT *)lParam;
|
||||
::DrawIconEx(pdis->hDC, 0, 0, hIcon, w, h, 0, NULL, DI_NORMAL);
|
||||
auto pdis = reinterpret_cast<DRAWITEMSTRUCT*>(lParam);
|
||||
::DrawIconEx(pdis->hDC, 0, 0, _hIcon, iconSize, iconSize, 0, nullptr, DI_NORMAL);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
case WM_COMMAND :
|
||||
case WM_COMMAND:
|
||||
{
|
||||
switch (wParam)
|
||||
{
|
||||
|
@ -124,8 +134,9 @@ intptr_t CALLBACK AboutDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPar
|
|||
break;
|
||||
}
|
||||
|
||||
case WM_DESTROY :
|
||||
case WM_DESTROY:
|
||||
{
|
||||
destroy();
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
@ -138,11 +149,12 @@ void AboutDlg::doDialog()
|
|||
create(IDD_ABOUTBOX);
|
||||
|
||||
// Adjust the position of AboutBox
|
||||
goToCenter(SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOACTIVATE);
|
||||
goToCenter(SWP_SHOWWINDOW | SWP_NOSIZE);
|
||||
}
|
||||
|
||||
|
||||
intptr_t CALLBACK DebugInfoDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM /*lParam*/)
|
||||
intptr_t CALLBACK DebugInfoDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch (message)
|
||||
{
|
||||
|
@ -364,6 +376,15 @@ intptr_t CALLBACK DebugInfoDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
case WM_DPICHANGED:
|
||||
{
|
||||
DPIManagerV2::setDpiWP(wParam);
|
||||
getClientRect(_rc);
|
||||
setPositionDpi(lParam);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
case WM_COMMAND:
|
||||
{
|
||||
switch (wParam)
|
||||
|
@ -409,7 +430,8 @@ void DebugInfoDlg::doDialog()
|
|||
// For example, the command line parameters may have changed since this dialog was last opened during this session.
|
||||
refreshDebugInfo();
|
||||
|
||||
// Adjust the position of AboutBox
|
||||
// Adjust the position of DebugBox
|
||||
goToCenter(SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOACTIVATE);
|
||||
goToCenter(SWP_SHOWWINDOW | SWP_NOSIZE);
|
||||
}
|
||||
|
||||
|
@ -465,7 +487,7 @@ void DoSaveOrNotBox::changeLang()
|
|||
::SetDlgItemText(_hSelf, IDC_DOSAVEORNOTTEXT, msg.c_str());
|
||||
}
|
||||
|
||||
intptr_t CALLBACK DoSaveOrNotBox::run_dlgProc(UINT message, WPARAM wParam, LPARAM /*lParam*/)
|
||||
intptr_t CALLBACK DoSaveOrNotBox::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch (message)
|
||||
{
|
||||
|
@ -495,6 +517,14 @@ intptr_t CALLBACK DoSaveOrNotBox::run_dlgProc(UINT message, WPARAM wParam, LPARA
|
|||
break;
|
||||
}
|
||||
|
||||
case WM_DPICHANGED:
|
||||
{
|
||||
DPIManagerV2::setDpiWP(wParam);
|
||||
setPositionDpi(lParam);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
case WM_COMMAND:
|
||||
{
|
||||
switch (LOWORD(wParam))
|
||||
|
@ -577,7 +607,7 @@ void DoSaveAllBox::changeLang()
|
|||
::SetDlgItemText(_hSelf, IDC_DOSAVEALLTEXT, msg.c_str());
|
||||
}
|
||||
|
||||
intptr_t CALLBACK DoSaveAllBox::run_dlgProc(UINT message, WPARAM wParam, LPARAM /*lParam*/)
|
||||
intptr_t CALLBACK DoSaveAllBox::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch (message)
|
||||
{
|
||||
|
@ -605,6 +635,14 @@ intptr_t CALLBACK DoSaveAllBox::run_dlgProc(UINT message, WPARAM wParam, LPARAM
|
|||
break;
|
||||
}
|
||||
|
||||
case WM_DPICHANGED:
|
||||
{
|
||||
DPIManagerV2::setDpiWP(wParam);
|
||||
setPositionDpi(lParam);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
case WM_COMMAND:
|
||||
{
|
||||
switch (LOWORD(wParam))
|
||||
|
|
|
@ -46,6 +46,11 @@ public :
|
|||
void destroy() override {
|
||||
//_emailLink.destroy();
|
||||
_pageLink.destroy();
|
||||
if (_hIcon != nullptr)
|
||||
{
|
||||
::DestroyIcon(_hIcon);
|
||||
_hIcon = nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
protected :
|
||||
|
@ -54,6 +59,7 @@ protected :
|
|||
private :
|
||||
//URLCtrl _emailLink;
|
||||
URLCtrl _pageLink;
|
||||
HICON _hIcon = nullptr;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -76,8 +76,8 @@ public :
|
|||
DPIManagerV2::setDpi(_hSelf);
|
||||
}
|
||||
|
||||
void setPositionDpi(LPARAM lParam) {
|
||||
DPIManagerV2::setPositionDpi(lParam, _hSelf);
|
||||
void setPositionDpi(LPARAM lParam, UINT flags = SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE) {
|
||||
DPIManagerV2::setPositionDpi(lParam, _hSelf, flags);
|
||||
}
|
||||
|
||||
void sendDpiMsgToChildCtrls(WPARAM wParam = 0, LPARAM lParam = 0) {
|
||||
|
|
|
@ -116,7 +116,7 @@ UINT DPIManagerV2::getDpiForWindow(HWND hWnd)
|
|||
return getDpiForSystem();
|
||||
}
|
||||
|
||||
void DPIManagerV2::setPositionDpi(LPARAM lParam, HWND hWnd)
|
||||
void DPIManagerV2::setPositionDpi(LPARAM lParam, HWND hWnd, UINT flags)
|
||||
{
|
||||
const auto prcNewWindow = reinterpret_cast<RECT*>(lParam);
|
||||
|
||||
|
@ -126,7 +126,7 @@ void DPIManagerV2::setPositionDpi(LPARAM lParam, HWND hWnd)
|
|||
prcNewWindow->top,
|
||||
prcNewWindow->right - prcNewWindow->left,
|
||||
prcNewWindow->bottom - prcNewWindow->top,
|
||||
SWP_NOZORDER | SWP_NOACTIVATE);
|
||||
flags);
|
||||
}
|
||||
|
||||
LOGFONT DPIManagerV2::getDefaultGUIFontForDpi(UINT dpi, FontType type)
|
||||
|
@ -262,5 +262,13 @@ void DPIManagerV2::sendMessageToChildControls(HWND hwndParent, UINT msg, WPARAM
|
|||
return TRUE;
|
||||
}
|
||||
return TRUE;
|
||||
}, reinterpret_cast<LPARAM>(&p));
|
||||
}, reinterpret_cast<LPARAM>(&p));
|
||||
}
|
||||
|
||||
void DPIManagerV2::loadIcon(HINSTANCE hinst, wchar_t* pszName, int cx, int cy, HICON* phico, UINT fuLoad)
|
||||
{
|
||||
if (::LoadIconWithScaleDown(hinst, pszName, cx, cy, phico) != S_OK)
|
||||
{
|
||||
*phico = static_cast<HICON>(::LoadImage(hinst, pszName, IMAGE_ICON, cx, cy, fuLoad));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ public:
|
|||
return _dpi;
|
||||
}
|
||||
|
||||
static void setPositionDpi(LPARAM lParam, HWND hWnd);
|
||||
static void setPositionDpi(LPARAM lParam, HWND hWnd, UINT flags = SWP_NOZORDER | SWP_NOACTIVATE);
|
||||
|
||||
static int scale(int x, UINT dpi, UINT dpi2) {
|
||||
return MulDiv(x, dpi, dpi2);
|
||||
|
@ -132,6 +132,7 @@ public:
|
|||
}
|
||||
|
||||
static void sendMessageToChildControls(HWND hwndParent, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
static void loadIcon(HINSTANCE hinst, wchar_t* pszName, int cx, int cy, HICON* phico, UINT fuLoad = LR_DEFAULTCOLOR);
|
||||
|
||||
private:
|
||||
UINT _dpi = USER_DEFAULT_SCREEN_DPI;
|
||||
|
|
Loading…
Reference in New Issue