Add dpi messages

- process WM_DPICHANGED_AFTERPARENT message
- remove unused function
- tweak 2 switches, which use enums to avoid warnings

ref #14959

Close #14980
pull/14994/head
ozone10 2024-04-11 18:05:09 +02:00 committed by Don Ho
parent 906f6e4386
commit 80e8a0dbe1
4 changed files with 43 additions and 22 deletions

View File

@ -42,9 +42,23 @@
#define WINAPI_LAMBDA #define WINAPI_LAMBDA
#endif #endif
#ifndef WM_DPICHANGED // already added in dpiManagerV2.h
#define WM_DPICHANGED 0x02E0 // keep for plugin authors
#endif //#ifndef WM_DPICHANGED
//#define WM_DPICHANGED 0x02E0
//#endif
//
//#ifndef WM_DPICHANGED_BEFOREPARENT
//#define WM_DPICHANGED_BEFOREPARENT 0x02E2
//#endif
//
//#ifndef WM_DPICHANGED_AFTERPARENT
//#define WM_DPICHANGED_AFTERPARENT 0x02E3
//#endif
//
//#ifndef WM_GETDPISCALEDSIZE
//#define WM_GETDPISCALEDSIZE 0x02E4
//#endif
// already added in project files // already added in project files
// keep for plugin authors // keep for plugin authors
@ -577,20 +591,6 @@ namespace NppDarkMode
return invert_c; return invert_c;
} }
COLORREF invertLightnessSofter(COLORREF c)
{
WORD h = 0;
WORD s = 0;
WORD l = 0;
ColorRGBToHLS(c, &h, &l, &s);
l = std::min<WORD>(240U - l, 211U);
COLORREF invert_c = ColorHLSToRGB(h, l, s);
return invert_c;
}
static TreeViewStyle g_treeViewStyle = TreeViewStyle::classic; static TreeViewStyle g_treeViewStyle = TreeViewStyle::classic;
static COLORREF g_treeViewBg = NppParameters::getInstance().getCurrentDefaultBgColor(); static COLORREF g_treeViewBg = NppParameters::getInstance().getCurrentDefaultBgColor();
static double g_lightnessTreeView = 50.0; static double g_lightnessTreeView = 50.0;
@ -918,6 +918,7 @@ namespace NppDarkMode
} }
case WM_DPICHANGED: case WM_DPICHANGED:
case WM_DPICHANGED_AFTERPARENT:
case WM_THEMECHANGED: case WM_THEMECHANGED:
{ {
if (g_menuTheme) if (g_menuTheme)
@ -1227,6 +1228,7 @@ namespace NppDarkMode
} }
case WM_DPICHANGED: case WM_DPICHANGED:
case WM_DPICHANGED_AFTERPARENT:
{ {
pButtonData->closeTheme(); pButtonData->closeTheme();
return 0; return 0;
@ -1408,6 +1410,7 @@ namespace NppDarkMode
} }
case WM_DPICHANGED: case WM_DPICHANGED:
case WM_DPICHANGED_AFTERPARENT:
{ {
pButtonData->closeTheme(); pButtonData->closeTheme();
return 0; return 0;
@ -1738,8 +1741,9 @@ namespace NppDarkMode
break; break;
case WM_DPICHANGED: case WM_DPICHANGED:
case WM_DPICHANGED_AFTERPARENT:
{ {
pBorderMetricsData->setMetricsForDpi(LOWORD(wParam)); pBorderMetricsData->setMetricsForDpi((uMsg == WM_DPICHANGED) ? LOWORD(wParam) : DPIManagerV2::getDpiForParent(hWnd));
::SetWindowPos(hWnd, nullptr, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); ::SetWindowPos(hWnd, nullptr, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
return 0; return 0;
} }
@ -2144,6 +2148,7 @@ namespace NppDarkMode
} }
case WM_DPICHANGED: case WM_DPICHANGED:
case WM_DPICHANGED_AFTERPARENT:
{ {
pButtonData->closeTheme(); pButtonData->closeTheme();
return 0; return 0;
@ -3025,7 +3030,7 @@ namespace NppDarkMode
case NppDarkMode::ToolTipsType::tabbar: case NppDarkMode::ToolTipsType::tabbar:
msg = TCM_GETTOOLTIPS; msg = TCM_GETTOOLTIPS;
break; break;
default: case NppDarkMode::ToolTipsType::tooltip:
msg = 0; msg = 0;
break; break;
} }
@ -3144,7 +3149,7 @@ namespace NppDarkMode
SetWindowTheme(hwnd, g_isAtLeastWindows10 ? L"DarkMode_Explorer" : nullptr, nullptr); SetWindowTheme(hwnd, g_isAtLeastWindows10 ? L"DarkMode_Explorer" : nullptr, nullptr);
break; break;
} }
default: case TreeViewStyle::classic:
{ {
if (hasHotStyle) if (hasHotStyle)
{ {

View File

@ -122,7 +122,6 @@ namespace NppDarkMode
DWORD getWindowsBuildNumber(); DWORD getWindowsBuildNumber();
COLORREF invertLightness(COLORREF c); COLORREF invertLightness(COLORREF c);
COLORREF invertLightnessSofter(COLORREF c);
double calculatePerceivedLightness(COLORREF c); double calculatePerceivedLightness(COLORREF c);
void setDarkTone(ColorTone colorToneChoice); void setDarkTone(ColorTone colorToneChoice);

View File

@ -241,13 +241,14 @@ static LRESULT CALLBACK StatusBarSubclass(HWND hWnd, UINT uMsg, WPARAM wParam, L
} }
case WM_DPICHANGED: case WM_DPICHANGED:
case WM_DPICHANGED_AFTERPARENT:
case WM_THEMECHANGED: case WM_THEMECHANGED:
{ {
pStatusBarInfo->closeTheme(); pStatusBarInfo->closeTheme();
LOGFONT lf{ DPIManagerV2::getDefaultGUIFontForDpi(::GetParent(hWnd), DPIManagerV2::FontType::status) }; LOGFONT lf{ DPIManagerV2::getDefaultGUIFontForDpi(::GetParent(hWnd), DPIManagerV2::FontType::status) };
pStatusBarInfo->setFont(::CreateFontIndirect(&lf)); pStatusBarInfo->setFont(::CreateFontIndirect(&lf));
if (uMsg == WM_DPICHANGED) if (uMsg != WM_THEMECHANGED)
{ {
return 0; return 0;
} }

View File

@ -18,6 +18,22 @@
#pragma once #pragma once
#include "NppDarkMode.h" #include "NppDarkMode.h"
#ifndef WM_DPICHANGED
#define WM_DPICHANGED 0x02E0
#endif
#ifndef WM_DPICHANGED_BEFOREPARENT
#define WM_DPICHANGED_BEFOREPARENT 0x02E2
#endif
#ifndef WM_DPICHANGED_AFTERPARENT
#define WM_DPICHANGED_AFTERPARENT 0x02E3
#endif
#ifndef WM_GETDPISCALEDSIZE
#define WM_GETDPISCALEDSIZE 0x02E4
#endif
class DPIManagerV2 class DPIManagerV2
{ {
public: public: