Readd dpi API
ref https://github.com/notepad-plus-plus/notepad-plus-plus/pull/14871#issuecomment-2002547565 Close #14876pull/14930/head
parent
243112d04d
commit
29fcd1ac91
|
@ -41,7 +41,7 @@ CXXFLAGS := -include $(GCC_DIRECTORY)/gcc-fixes.h -std=c++20
|
||||||
RC := $(CROSS_COMPILE)windres
|
RC := $(CROSS_COMPILE)windres
|
||||||
RCFLAGS :=
|
RCFLAGS :=
|
||||||
CPP_PATH := $(SCINTILLA_DIRECTORY)/include $(LEXILLA_DIRECTORY)/include
|
CPP_PATH := $(SCINTILLA_DIRECTORY)/include $(LEXILLA_DIRECTORY)/include
|
||||||
CPP_DEFINE := UNICODE _UNICODE OEMRESOURCE NOMINMAX _WIN32_WINNT=_WIN32_WINNT_VISTA TIXML_USE_STL TIXMLA_USE_STL
|
CPP_DEFINE := UNICODE _UNICODE OEMRESOURCE NOMINMAX _WIN32_WINNT=_WIN32_WINNT_WIN7 NTDDI_VERSION=NTDDI_WIN7 TIXML_USE_STL TIXMLA_USE_STL
|
||||||
LD := $(CXX)
|
LD := $(CXX)
|
||||||
LDFLAGS := -municode -mwindows
|
LDFLAGS := -municode -mwindows
|
||||||
LD_PATH :=
|
LD_PATH :=
|
||||||
|
|
|
@ -74,6 +74,7 @@ SET(src_files
|
||||||
./MISC/sha2/sha-256.cpp
|
./MISC/sha2/sha-256.cpp
|
||||||
./MISC/sha512/sha512.cpp
|
./MISC/sha512/sha512.cpp
|
||||||
./NppDarkMode.cpp
|
./NppDarkMode.cpp
|
||||||
|
./dpiManagerV2.cpp
|
||||||
./MISC/Process/Processus.cpp
|
./MISC/Process/Processus.cpp
|
||||||
./WinControls/AboutDlg/AboutDlg.cpp
|
./WinControls/AboutDlg/AboutDlg.cpp
|
||||||
./WinControls/AnsiCharPanel/ansiCharPanel.cpp
|
./WinControls/AnsiCharPanel/ansiCharPanel.cpp
|
||||||
|
@ -203,6 +204,7 @@ SET(include_files
|
||||||
./DarkMode/IatHook.h
|
./DarkMode/IatHook.h
|
||||||
./DarkMode/UAHMenuBar.h
|
./DarkMode/UAHMenuBar.h
|
||||||
./dpiManager.h
|
./dpiManager.h
|
||||||
|
./dpiManagerV2.h
|
||||||
./keys.h
|
./keys.h
|
||||||
./localizationString.h
|
./localizationString.h
|
||||||
./MISC/Common/Sorters.h
|
./MISC/Common/Sorters.h
|
||||||
|
@ -393,13 +395,13 @@ IF (WIN32)
|
||||||
if ( MSVC )
|
if ( MSVC )
|
||||||
#do not use for mingw builds
|
#do not use for mingw builds
|
||||||
SET(CMAKE_CXX_FLAGS "/EHa /MP /W4")
|
SET(CMAKE_CXX_FLAGS "/EHa /MP /W4")
|
||||||
SET(defs -DUNICODE -D_UNICODE -D_WIN32_WINNT=_WIN32_WINNT_VISTA -D_USE_64BIT_TIME_T -DTIXML_USE_STL -DTIXMLA_USE_STL -DNOMINMAX -DOEMRESOURCE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING )
|
SET(defs -DUNICODE -D_UNICODE -D_WIN32_WINNT=_WIN32_WINNT_WIN7 -DNTDDI_VERSION=NTDDI_WIN7 -D_USE_64BIT_TIME_T -DTIXML_USE_STL -DTIXMLA_USE_STL -DNOMINMAX -DOEMRESOURCE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING )
|
||||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
|
||||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
|
||||||
else ( MSVC )
|
else ( MSVC )
|
||||||
# For possible MinGW compilation
|
# For possible MinGW compilation
|
||||||
SET(CMAKE_CXX_FLAGS "-include../gcc/gcc-fixes.h -std=c++20 -fpermissive -municode")
|
SET(CMAKE_CXX_FLAGS "-include../gcc/gcc-fixes.h -std=c++20 -fpermissive -municode")
|
||||||
SET(defs -DUNICODE -D_UNICODE -D_WIN32_WINNT=_WIN32_WINNT_VISTA -D_USE_64BIT_TIME_T -DTIXML_USE_STL -DTIXMLA_USE_STL -DNOMINMAX -DOEMRESOURCE)
|
SET(defs -DUNICODE -D_UNICODE -D_WIN32_WINNT=_WIN32_WINNT_WIN7 -DNTDDI_VERSION=NTDDI_WIN7 -D_USE_64BIT_TIME_T -DTIXML_USE_STL -DTIXMLA_USE_STL -DNOMINMAX -DOEMRESOURCE)
|
||||||
endif ( MSVC )
|
endif ( MSVC )
|
||||||
ENDIF (WIN32)
|
ENDIF (WIN32)
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
#include "Parameters.h"
|
#include "Parameters.h"
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
|
#include "dpiManagerV2.h"
|
||||||
|
|
||||||
#include <shlwapi.h>
|
#include <shlwapi.h>
|
||||||
|
|
||||||
|
@ -52,7 +53,7 @@
|
||||||
//#pragma comment(lib, "uxtheme.lib")
|
//#pragma comment(lib, "uxtheme.lib")
|
||||||
//#endif
|
//#endif
|
||||||
|
|
||||||
constexpr COLORREF HEXRGB(DWORD rrggbb) {
|
static constexpr COLORREF HEXRGB(DWORD rrggbb) {
|
||||||
// from 0xRRGGBB like natural #RRGGBB
|
// from 0xRRGGBB like natural #RRGGBB
|
||||||
// to the little-endian 0xBBGGRR
|
// to the little-endian 0xBBGGRR
|
||||||
return
|
return
|
||||||
|
@ -327,7 +328,7 @@ namespace NppDarkMode
|
||||||
Theme tCustom(darkCustomizedColors);
|
Theme tCustom(darkCustomizedColors);
|
||||||
|
|
||||||
|
|
||||||
Theme& getTheme()
|
static Theme& getTheme()
|
||||||
{
|
{
|
||||||
switch (g_colorToneChoice)
|
switch (g_colorToneChoice)
|
||||||
{
|
{
|
||||||
|
@ -360,7 +361,7 @@ namespace NppDarkMode
|
||||||
static Options _options; // actual runtime options
|
static Options _options; // actual runtime options
|
||||||
static AdvancedOptions g_advOptions;
|
static AdvancedOptions g_advOptions;
|
||||||
|
|
||||||
Options configuredOptions()
|
static Options configuredOptions()
|
||||||
{
|
{
|
||||||
NppGUI nppGui = NppParameters::getInstance().getNppGUI();
|
NppGUI nppGui = NppParameters::getInstance().getNppGUI();
|
||||||
Options opt;
|
Options opt;
|
||||||
|
@ -1031,7 +1032,7 @@ namespace NppDarkMode
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void renderButton(HWND hwnd, HDC hdc, HTHEME hTheme, int iPartID, int iStateID)
|
static void renderButton(HWND hwnd, HDC hdc, HTHEME hTheme, int iPartID, int iStateID)
|
||||||
{
|
{
|
||||||
RECT rcClient{};
|
RECT rcClient{};
|
||||||
WCHAR szText[256] = { '\0' };
|
WCHAR szText[256] = { '\0' };
|
||||||
|
@ -1115,7 +1116,7 @@ namespace NppDarkMode
|
||||||
SelectObject(hdc, hOldFont);
|
SelectObject(hdc, hOldFont);
|
||||||
}
|
}
|
||||||
|
|
||||||
void paintButton(HWND hwnd, HDC hdc, ButtonData& buttonData)
|
static void paintButton(HWND hwnd, HDC hdc, ButtonData& buttonData)
|
||||||
{
|
{
|
||||||
DWORD nState = static_cast<DWORD>(SendMessage(hwnd, BM_GETSTATE, 0, 0));
|
DWORD nState = static_cast<DWORD>(SendMessage(hwnd, BM_GETSTATE, 0, 0));
|
||||||
const auto nStyle = GetWindowLongPtr(hwnd, GWL_STYLE);
|
const auto nStyle = GetWindowLongPtr(hwnd, GWL_STYLE);
|
||||||
|
@ -1190,7 +1191,7 @@ namespace NppDarkMode
|
||||||
|
|
||||||
constexpr UINT_PTR g_buttonSubclassID = 42;
|
constexpr UINT_PTR g_buttonSubclassID = 42;
|
||||||
|
|
||||||
LRESULT CALLBACK ButtonSubclass(
|
static LRESULT CALLBACK ButtonSubclass(
|
||||||
HWND hWnd,
|
HWND hWnd,
|
||||||
UINT uMsg,
|
UINT uMsg,
|
||||||
WPARAM wParam,
|
WPARAM wParam,
|
||||||
|
@ -1215,18 +1216,28 @@ namespace NppDarkMode
|
||||||
RemoveWindowSubclass(hWnd, ButtonSubclass, g_buttonSubclassID);
|
RemoveWindowSubclass(hWnd, ButtonSubclass, g_buttonSubclassID);
|
||||||
delete pButtonData;
|
delete pButtonData;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WM_ERASEBKGND:
|
case WM_ERASEBKGND:
|
||||||
|
{
|
||||||
if (NppDarkMode::isEnabled() && pButtonData->ensureTheme(hWnd))
|
if (NppDarkMode::isEnabled() && pButtonData->ensureTheme(hWnd))
|
||||||
{
|
{
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
else
|
break;
|
||||||
{
|
}
|
||||||
break;
|
|
||||||
}
|
case WM_DPICHANGED:
|
||||||
|
{
|
||||||
|
pButtonData->closeTheme();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
case WM_THEMECHANGED:
|
case WM_THEMECHANGED:
|
||||||
|
{
|
||||||
pButtonData->closeTheme();
|
pButtonData->closeTheme();
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case WM_PRINTCLIENT:
|
case WM_PRINTCLIENT:
|
||||||
case WM_PAINT:
|
case WM_PAINT:
|
||||||
if (NppDarkMode::isEnabled() && pButtonData->ensureTheme(hWnd))
|
if (NppDarkMode::isEnabled() && pButtonData->ensureTheme(hWnd))
|
||||||
|
@ -1274,7 +1285,7 @@ namespace NppDarkMode
|
||||||
SetWindowSubclass(hwnd, ButtonSubclass, g_buttonSubclassID, pButtonData);
|
SetWindowSubclass(hwnd, ButtonSubclass, g_buttonSubclassID, pButtonData);
|
||||||
}
|
}
|
||||||
|
|
||||||
void paintGroupbox(HWND hwnd, HDC hdc, ButtonData& buttonData)
|
static void paintGroupbox(HWND hwnd, HDC hdc, ButtonData& buttonData)
|
||||||
{
|
{
|
||||||
auto nStyle = ::GetWindowLongPtr(hwnd, GWL_STYLE);
|
auto nStyle = ::GetWindowLongPtr(hwnd, GWL_STYLE);
|
||||||
bool isDisabled = (nStyle & WS_DISABLED) == WS_DISABLED;
|
bool isDisabled = (nStyle & WS_DISABLED) == WS_DISABLED;
|
||||||
|
@ -1367,7 +1378,7 @@ namespace NppDarkMode
|
||||||
|
|
||||||
constexpr UINT_PTR g_groupboxSubclassID = 42;
|
constexpr UINT_PTR g_groupboxSubclassID = 42;
|
||||||
|
|
||||||
LRESULT CALLBACK GroupboxSubclass(
|
static LRESULT CALLBACK GroupboxSubclass(
|
||||||
HWND hWnd,
|
HWND hWnd,
|
||||||
UINT uMsg,
|
UINT uMsg,
|
||||||
WPARAM wParam,
|
WPARAM wParam,
|
||||||
|
@ -1386,18 +1397,28 @@ namespace NppDarkMode
|
||||||
RemoveWindowSubclass(hWnd, GroupboxSubclass, g_groupboxSubclassID);
|
RemoveWindowSubclass(hWnd, GroupboxSubclass, g_groupboxSubclassID);
|
||||||
delete pButtonData;
|
delete pButtonData;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WM_ERASEBKGND:
|
case WM_ERASEBKGND:
|
||||||
|
{
|
||||||
if (NppDarkMode::isEnabled() && pButtonData->ensureTheme(hWnd))
|
if (NppDarkMode::isEnabled() && pButtonData->ensureTheme(hWnd))
|
||||||
{
|
{
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
else
|
break;
|
||||||
{
|
}
|
||||||
break;
|
|
||||||
}
|
case WM_DPICHANGED:
|
||||||
|
{
|
||||||
|
pButtonData->closeTheme();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
case WM_THEMECHANGED:
|
case WM_THEMECHANGED:
|
||||||
|
{
|
||||||
pButtonData->closeTheme();
|
pButtonData->closeTheme();
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case WM_PRINTCLIENT:
|
case WM_PRINTCLIENT:
|
||||||
case WM_PAINT:
|
case WM_PAINT:
|
||||||
if (NppDarkMode::isEnabled() && pButtonData->ensureTheme(hWnd))
|
if (NppDarkMode::isEnabled() && pButtonData->ensureTheme(hWnd))
|
||||||
|
@ -1418,10 +1439,6 @@ namespace NppDarkMode
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return DefSubclassProc(hWnd, uMsg, wParam, lParam);
|
return DefSubclassProc(hWnd, uMsg, wParam, lParam);
|
||||||
|
@ -1435,7 +1452,7 @@ namespace NppDarkMode
|
||||||
|
|
||||||
constexpr UINT_PTR g_tabSubclassID = 42;
|
constexpr UINT_PTR g_tabSubclassID = 42;
|
||||||
|
|
||||||
LRESULT CALLBACK TabSubclass(
|
static LRESULT CALLBACK TabSubclass(
|
||||||
HWND hWnd,
|
HWND hWnd,
|
||||||
UINT uMsg,
|
UINT uMsg,
|
||||||
WPARAM wParam,
|
WPARAM wParam,
|
||||||
|
@ -1522,15 +1539,15 @@ namespace NppDarkMode
|
||||||
|
|
||||||
::SendMessage(hWnd, TCM_GETITEM, i, reinterpret_cast<LPARAM>(&tci));
|
::SendMessage(hWnd, TCM_GETITEM, i, reinterpret_cast<LPARAM>(&tci));
|
||||||
|
|
||||||
auto dpiManager = NppParameters::getInstance()._dpiManager;
|
const auto dpi = DPIManagerV2::getDpiForParent(hWnd);
|
||||||
|
|
||||||
RECT rcText = rcItem;
|
RECT rcText = rcItem;
|
||||||
rcText.left += dpiManager.scaleX(5);
|
rcText.left += DPIManagerV2::scale(5, dpi);
|
||||||
rcText.right -= dpiManager.scaleX(3);
|
rcText.right -= DPIManagerV2::scale(3, dpi);
|
||||||
|
|
||||||
if (isSelectedTab)
|
if (isSelectedTab)
|
||||||
{
|
{
|
||||||
rcText.bottom -= dpiManager.scaleY(4);
|
rcText.bottom -= DPIManagerV2::scale(4, dpi);
|
||||||
::InflateRect(&rcFrame, 0, 1);
|
::InflateRect(&rcFrame, 0, 1);
|
||||||
}
|
}
|
||||||
if (i != nTabs - 1)
|
if (i != nTabs - 1)
|
||||||
|
@ -1595,9 +1612,34 @@ namespace NppDarkMode
|
||||||
SetWindowSubclass(hwnd, TabSubclass, g_tabSubclassID, 0);
|
SetWindowSubclass(hwnd, TabSubclass, g_tabSubclassID, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct BorderMetricsData
|
||||||
|
{
|
||||||
|
UINT _dpi = USER_DEFAULT_SCREEN_DPI;
|
||||||
|
LONG _xEdge = ::GetSystemMetrics(SM_CXEDGE);
|
||||||
|
LONG _yEdge = ::GetSystemMetrics(SM_CYEDGE);
|
||||||
|
LONG _xScroll = ::GetSystemMetrics(SM_CXVSCROLL);
|
||||||
|
LONG _yScroll = ::GetSystemMetrics(SM_CYVSCROLL);
|
||||||
|
|
||||||
|
BorderMetricsData() {};
|
||||||
|
|
||||||
|
BorderMetricsData(HWND hWnd)
|
||||||
|
{
|
||||||
|
setMetricsForDpi(DPIManagerV2::getDpiForParent(hWnd));
|
||||||
|
}
|
||||||
|
|
||||||
|
void setMetricsForDpi(UINT dpi)
|
||||||
|
{
|
||||||
|
_dpi = dpi;
|
||||||
|
_xEdge = DPIManagerV2::getSystemMetricsForDpi(SM_CXEDGE, _dpi);
|
||||||
|
_yEdge = DPIManagerV2::getSystemMetricsForDpi(SM_CYEDGE, _dpi);
|
||||||
|
_xScroll = DPIManagerV2::getSystemMetricsForDpi(SM_CXVSCROLL, _dpi);
|
||||||
|
_yScroll = DPIManagerV2::getSystemMetricsForDpi(SM_CYVSCROLL, _dpi);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
constexpr UINT_PTR g_customBorderSubclassID = 42;
|
constexpr UINT_PTR g_customBorderSubclassID = 42;
|
||||||
|
|
||||||
LRESULT CALLBACK CustomBorderSubclass(
|
static LRESULT CALLBACK CustomBorderSubclass(
|
||||||
HWND hWnd,
|
HWND hWnd,
|
||||||
UINT uMsg,
|
UINT uMsg,
|
||||||
WPARAM wParam,
|
WPARAM wParam,
|
||||||
|
@ -1606,7 +1648,7 @@ namespace NppDarkMode
|
||||||
DWORD_PTR dwRefData
|
DWORD_PTR dwRefData
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
UNREFERENCED_PARAMETER(dwRefData);
|
auto pBorderMetricsData = reinterpret_cast<BorderMetricsData*>(dwRefData);
|
||||||
|
|
||||||
static bool isHotStatic = false;
|
static bool isHotStatic = false;
|
||||||
|
|
||||||
|
@ -1624,21 +1666,21 @@ namespace NppDarkMode
|
||||||
HDC hdc = ::GetWindowDC(hWnd);
|
HDC hdc = ::GetWindowDC(hWnd);
|
||||||
RECT rcClient{};
|
RECT rcClient{};
|
||||||
::GetClientRect(hWnd, &rcClient);
|
::GetClientRect(hWnd, &rcClient);
|
||||||
rcClient.right += (2 * ::GetSystemMetrics(SM_CXEDGE));
|
rcClient.right += (2 * pBorderMetricsData->_xEdge);
|
||||||
|
|
||||||
auto style = ::GetWindowLongPtr(hWnd, GWL_STYLE);
|
auto style = ::GetWindowLongPtr(hWnd, GWL_STYLE);
|
||||||
bool hasVerScrollbar = (style & WS_VSCROLL) == WS_VSCROLL;
|
bool hasVerScrollbar = (style & WS_VSCROLL) == WS_VSCROLL;
|
||||||
if (hasVerScrollbar)
|
if (hasVerScrollbar)
|
||||||
{
|
{
|
||||||
rcClient.right += ::GetSystemMetrics(SM_CXVSCROLL);
|
rcClient.right += pBorderMetricsData->_xScroll;
|
||||||
}
|
}
|
||||||
|
|
||||||
rcClient.bottom += (2 * ::GetSystemMetrics(SM_CYEDGE));
|
rcClient.bottom += (2 * pBorderMetricsData->_yEdge);
|
||||||
|
|
||||||
bool hasHorScrollbar = (style & WS_HSCROLL) == WS_HSCROLL;
|
bool hasHorScrollbar = (style & WS_HSCROLL) == WS_HSCROLL;
|
||||||
if (hasHorScrollbar)
|
if (hasHorScrollbar)
|
||||||
{
|
{
|
||||||
rcClient.bottom += ::GetSystemMetrics(SM_CYHSCROLL);
|
rcClient.bottom += pBorderMetricsData->_yScroll;
|
||||||
}
|
}
|
||||||
|
|
||||||
HPEN hPen = ::CreatePen(PS_SOLID, 1, NppDarkMode::getBackgroundColor());
|
HPEN hPen = ::CreatePen(PS_SOLID, 1, NppDarkMode::getBackgroundColor());
|
||||||
|
@ -1674,25 +1716,32 @@ namespace NppDarkMode
|
||||||
}
|
}
|
||||||
|
|
||||||
auto lpRect = reinterpret_cast<LPRECT>(lParam);
|
auto lpRect = reinterpret_cast<LPRECT>(lParam);
|
||||||
::InflateRect(lpRect, -(::GetSystemMetrics(SM_CXEDGE)), -(::GetSystemMetrics(SM_CYEDGE)));
|
::InflateRect(lpRect, -(pBorderMetricsData->_xEdge), -(pBorderMetricsData->_yEdge));
|
||||||
|
|
||||||
auto style = ::GetWindowLongPtr(hWnd, GWL_STYLE);
|
auto style = ::GetWindowLongPtr(hWnd, GWL_STYLE);
|
||||||
bool hasVerScrollbar = (style & WS_VSCROLL) == WS_VSCROLL;
|
bool hasVerScrollbar = (style & WS_VSCROLL) == WS_VSCROLL;
|
||||||
if (hasVerScrollbar)
|
if (hasVerScrollbar)
|
||||||
{
|
{
|
||||||
lpRect->right -= ::GetSystemMetrics(SM_CXVSCROLL);
|
lpRect->right -= pBorderMetricsData->_xScroll;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasHorScrollbar = (style & WS_HSCROLL) == WS_HSCROLL;
|
bool hasHorScrollbar = (style & WS_HSCROLL) == WS_HSCROLL;
|
||||||
if (hasHorScrollbar)
|
if (hasHorScrollbar)
|
||||||
{
|
{
|
||||||
lpRect->bottom -= ::GetSystemMetrics(SM_CYHSCROLL);
|
lpRect->bottom -= pBorderMetricsData->_yScroll;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case WM_DPICHANGED:
|
||||||
|
{
|
||||||
|
pBorderMetricsData->setMetricsForDpi(LOWORD(wParam));
|
||||||
|
::SetWindowPos(hWnd, nullptr, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
case WM_MOUSEMOVE:
|
case WM_MOUSEMOVE:
|
||||||
{
|
{
|
||||||
if (!NppDarkMode::isEnabled())
|
if (!NppDarkMode::isEnabled())
|
||||||
|
@ -1745,20 +1794,22 @@ namespace NppDarkMode
|
||||||
case WM_NCDESTROY:
|
case WM_NCDESTROY:
|
||||||
{
|
{
|
||||||
RemoveWindowSubclass(hWnd, CustomBorderSubclass, uIdSubclass);
|
RemoveWindowSubclass(hWnd, CustomBorderSubclass, uIdSubclass);
|
||||||
|
delete pBorderMetricsData;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return DefSubclassProc(hWnd, uMsg, wParam, lParam);
|
return DefSubclassProc(hWnd, uMsg, wParam, lParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
void subclassCustomBorderForListBoxAndEditControls(HWND hwnd)
|
static void subclassCustomBorderForListBoxAndEditControls(HWND hwnd)
|
||||||
{
|
{
|
||||||
SetWindowSubclass(hwnd, CustomBorderSubclass, g_customBorderSubclassID, 0);
|
auto pBorderMetricsData = reinterpret_cast<DWORD_PTR>(new BorderMetricsData(hwnd));
|
||||||
|
SetWindowSubclass(hwnd, CustomBorderSubclass, g_customBorderSubclassID, pBorderMetricsData);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr UINT_PTR g_comboBoxSubclassID = 42;
|
constexpr UINT_PTR g_comboBoxSubclassID = 42;
|
||||||
|
|
||||||
LRESULT CALLBACK ComboBoxSubclass(
|
static LRESULT CALLBACK ComboBoxSubclass(
|
||||||
HWND hWnd,
|
HWND hWnd,
|
||||||
UINT uMsg,
|
UINT uMsg,
|
||||||
WPARAM wParam,
|
WPARAM wParam,
|
||||||
|
@ -1789,7 +1840,7 @@ namespace NppDarkMode
|
||||||
|
|
||||||
auto holdBrush = ::SelectObject(hdc, NppDarkMode::getDarkerBackgroundBrush());
|
auto holdBrush = ::SelectObject(hdc, NppDarkMode::getDarkerBackgroundBrush());
|
||||||
|
|
||||||
auto& dpiManager = NppParameters::getInstance()._dpiManager;
|
const auto dpi = DPIManagerV2::getDpiForParent(hWnd);
|
||||||
|
|
||||||
RECT rcArrow{};
|
RECT rcArrow{};
|
||||||
|
|
||||||
|
@ -1804,7 +1855,7 @@ namespace NppDarkMode
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rcArrow = {
|
rcArrow = {
|
||||||
rc.right - dpiManager.scaleX(17), rc.top + 1,
|
rc.right - DPIManagerV2::scale(17, dpi), rc.top + 1,
|
||||||
rc.right - 1, rc.bottom - 1
|
rc.right - 1, rc.bottom - 1
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1887,7 +1938,7 @@ namespace NppDarkMode
|
||||||
};
|
};
|
||||||
::Polyline(hdc, edge, _countof(edge));
|
::Polyline(hdc, edge, _countof(edge));
|
||||||
|
|
||||||
int roundCornerValue = NppDarkMode::isWindows11() ? dpiManager.scaleX(4) : 0;
|
const int roundCornerValue = NppDarkMode::isWindows11() ? DPIManagerV2::scale(4, dpi) : 0;
|
||||||
NppDarkMode::paintRoundFrameRect(hdc, rc, hSelectedPen, roundCornerValue, roundCornerValue);
|
NppDarkMode::paintRoundFrameRect(hdc, rc, hSelectedPen, roundCornerValue, roundCornerValue);
|
||||||
|
|
||||||
::SelectObject(hdc, holdPen);
|
::SelectObject(hdc, holdPen);
|
||||||
|
@ -1920,7 +1971,7 @@ namespace NppDarkMode
|
||||||
|
|
||||||
constexpr UINT_PTR g_listViewSubclassID = 42;
|
constexpr UINT_PTR g_listViewSubclassID = 42;
|
||||||
|
|
||||||
LRESULT CALLBACK ListViewSubclass(
|
static LRESULT CALLBACK ListViewSubclass(
|
||||||
HWND hWnd,
|
HWND hWnd,
|
||||||
UINT uMsg,
|
UINT uMsg,
|
||||||
WPARAM wParam,
|
WPARAM wParam,
|
||||||
|
@ -1977,14 +2028,14 @@ namespace NppDarkMode
|
||||||
return DefSubclassProc(hWnd, uMsg, wParam, lParam);
|
return DefSubclassProc(hWnd, uMsg, wParam, lParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
void subclassListViewControl(HWND hwnd)
|
static void subclassListViewControl(HWND hwnd)
|
||||||
{
|
{
|
||||||
SetWindowSubclass(hwnd, ListViewSubclass, g_listViewSubclassID, 0);
|
SetWindowSubclass(hwnd, ListViewSubclass, g_listViewSubclassID, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr UINT_PTR g_upDownSubclassID = 42;
|
constexpr UINT_PTR g_upDownSubclassID = 42;
|
||||||
|
|
||||||
LRESULT CALLBACK UpDownSubclass(
|
static LRESULT CALLBACK UpDownSubclass(
|
||||||
HWND hWnd,
|
HWND hWnd,
|
||||||
UINT uMsg,
|
UINT uMsg,
|
||||||
WPARAM wParam,
|
WPARAM wParam,
|
||||||
|
@ -2090,6 +2141,12 @@ namespace NppDarkMode
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case WM_DPICHANGED:
|
||||||
|
{
|
||||||
|
pButtonData->closeTheme();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
case WM_THEMECHANGED:
|
case WM_THEMECHANGED:
|
||||||
{
|
{
|
||||||
pButtonData->closeTheme();
|
pButtonData->closeTheme();
|
||||||
|
@ -2118,7 +2175,7 @@ namespace NppDarkMode
|
||||||
return DefSubclassProc(hWnd, uMsg, wParam, lParam);
|
return DefSubclassProc(hWnd, uMsg, wParam, lParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
void subclassAndThemeUpDownControl(HWND hwnd, NppDarkModeParams p)
|
static void subclassAndThemeUpDownControl(HWND hwnd, NppDarkModeParams p)
|
||||||
{
|
{
|
||||||
if (p._subclass)
|
if (p._subclass)
|
||||||
{
|
{
|
||||||
|
@ -2445,8 +2502,12 @@ namespace NppDarkMode
|
||||||
{
|
{
|
||||||
if (NppDarkMode::isEnabled())
|
if (NppDarkMode::isEnabled())
|
||||||
{
|
{
|
||||||
auto dpiManager = NppParameters::getInstance()._dpiManager;
|
if (NppDarkMode::isWindows11())
|
||||||
roundCornerValue = NppDarkMode::isWindows11() ? dpiManager.scaleX(5) : 0;
|
{
|
||||||
|
const auto nmhdr = reinterpret_cast<LPNMHDR>(lParam);
|
||||||
|
const auto dpi = DPIManagerV2::getDpiForParent(nmhdr->hwndFrom);
|
||||||
|
roundCornerValue = DPIManagerV2::scale(5, dpi);
|
||||||
|
}
|
||||||
|
|
||||||
::FillRect(nmtbcd->nmcd.hdc, &nmtbcd->nmcd.rc, NppDarkMode::getDarkerBackgroundBrush());
|
::FillRect(nmtbcd->nmcd.hdc, &nmtbcd->nmcd.rc, NppDarkMode::getDarkerBackgroundBrush());
|
||||||
return CDRF_NOTIFYITEMDRAW;
|
return CDRF_NOTIFYITEMDRAW;
|
||||||
|
@ -2631,7 +2692,7 @@ namespace NppDarkMode
|
||||||
|
|
||||||
constexpr UINT_PTR g_pluginDockWindowSubclassID = 42;
|
constexpr UINT_PTR g_pluginDockWindowSubclassID = 42;
|
||||||
|
|
||||||
LRESULT CALLBACK PluginDockWindowSubclass(
|
static LRESULT CALLBACK PluginDockWindowSubclass(
|
||||||
HWND hWnd,
|
HWND hWnd,
|
||||||
UINT uMsg,
|
UINT uMsg,
|
||||||
WPARAM wParam,
|
WPARAM wParam,
|
||||||
|
@ -2855,7 +2916,7 @@ namespace NppDarkMode
|
||||||
|
|
||||||
constexpr UINT_PTR g_windowNotifySubclassID = 42;
|
constexpr UINT_PTR g_windowNotifySubclassID = 42;
|
||||||
|
|
||||||
LRESULT CALLBACK WindowNotifySubclass(
|
static LRESULT CALLBACK WindowNotifySubclass(
|
||||||
HWND hWnd,
|
HWND hWnd,
|
||||||
UINT uMsg,
|
UINT uMsg,
|
||||||
WPARAM wParam,
|
WPARAM wParam,
|
||||||
|
@ -2914,6 +2975,77 @@ namespace NppDarkMode
|
||||||
SetWindowSubclass(hwnd, WindowNotifySubclass, g_windowNotifySubclassID, 0);
|
SetWindowSubclass(hwnd, WindowNotifySubclass, g_windowNotifySubclassID, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// currently send message only to selected buttons; listbox and edit controls with scrollbars
|
||||||
|
void sendMessageToChildControls(HWND hwndParent, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||||
|
{
|
||||||
|
struct WMessage
|
||||||
|
{
|
||||||
|
UINT _msg = 0;
|
||||||
|
WPARAM _wParam = 0;
|
||||||
|
LPARAM _lParam = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct WMessage p { msg, wParam, lParam };
|
||||||
|
|
||||||
|
::EnumChildWindows(hwndParent, [](HWND hwnd, LPARAM childLParam) WINAPI_LAMBDA->BOOL{
|
||||||
|
auto & p = *reinterpret_cast<WMessage*>(childLParam);
|
||||||
|
constexpr size_t classNameLen = 32;
|
||||||
|
TCHAR className[classNameLen]{};
|
||||||
|
::GetClassName(hwnd, className, classNameLen);
|
||||||
|
auto style = ::GetWindowLongPtr(hwnd, GWL_STYLE);
|
||||||
|
|
||||||
|
if (wcscmp(className, WC_BUTTON) == 0)
|
||||||
|
{
|
||||||
|
switch (style & BS_TYPEMASK)
|
||||||
|
{
|
||||||
|
case BS_CHECKBOX:
|
||||||
|
case BS_AUTOCHECKBOX:
|
||||||
|
case BS_3STATE:
|
||||||
|
case BS_AUTO3STATE:
|
||||||
|
case BS_RADIOBUTTON:
|
||||||
|
case BS_AUTORADIOBUTTON:
|
||||||
|
{
|
||||||
|
if ((style & BS_PUSHLIKE) != BS_PUSHLIKE)
|
||||||
|
{
|
||||||
|
::SendMessage(hwnd, p._msg, p._wParam, p._lParam);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wcscmp(className, WC_EDIT) == 0)
|
||||||
|
{
|
||||||
|
bool hasScrollBar = ((style & WS_HSCROLL) == WS_HSCROLL) || ((style & WS_VSCROLL) == WS_VSCROLL);
|
||||||
|
if (hasScrollBar)
|
||||||
|
{
|
||||||
|
::SendMessage(hwnd, p._msg, p._wParam, p._lParam);
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wcscmp(className, WC_LISTBOX) == 0)
|
||||||
|
{
|
||||||
|
if ((style & LBS_COMBOBOX) != LBS_COMBOBOX)
|
||||||
|
{
|
||||||
|
bool hasScrollBar = ((style & WS_HSCROLL) == WS_HSCROLL) || ((style & WS_VSCROLL) == WS_VSCROLL);
|
||||||
|
if (hasScrollBar)
|
||||||
|
{
|
||||||
|
::SendMessage(hwnd, p._msg, p._wParam, p._lParam);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}, reinterpret_cast<LPARAM>(&p));
|
||||||
|
}
|
||||||
|
|
||||||
void setDarkTitleBar(HWND hwnd)
|
void setDarkTitleBar(HWND hwnd)
|
||||||
{
|
{
|
||||||
constexpr DWORD win10Build2004 = 19041;
|
constexpr DWORD win10Build2004 = 19041;
|
||||||
|
|
|
@ -222,6 +222,8 @@ namespace NppDarkMode
|
||||||
ULONG autoSubclassAndThemePlugin(HWND hwnd, ULONG dmFlags);
|
ULONG autoSubclassAndThemePlugin(HWND hwnd, ULONG dmFlags);
|
||||||
void autoSubclassAndThemeWindowNotify(HWND hwnd);
|
void autoSubclassAndThemeWindowNotify(HWND hwnd);
|
||||||
|
|
||||||
|
void sendMessageToChildControls(HWND hwndParent, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||||
|
|
||||||
void setDarkTitleBar(HWND hwnd);
|
void setDarkTitleBar(HWND hwnd);
|
||||||
void setDarkExplorerTheme(HWND hwnd);
|
void setDarkExplorerTheme(HWND hwnd);
|
||||||
void setDarkScrollBar(HWND hwnd);
|
void setDarkScrollBar(HWND hwnd);
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
|
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
|
||||||
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
||||||
<asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
|
<asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
|
||||||
<asmv3:windowsSettings
|
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
|
||||||
xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
|
<dpiAware>true</dpiAware>
|
||||||
<dpiAware>true</dpiAware>
|
</asmv3:windowsSettings>
|
||||||
</asmv3:windowsSettings>
|
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
|
||||||
</asmv3:application>
|
<dpiAwareness>system, unaware</dpiAwareness>
|
||||||
|
</asmv3:windowsSettings>
|
||||||
|
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2017/WindowsSettings">
|
||||||
|
<gdiScaling>false</gdiScaling>
|
||||||
|
</asmv3:windowsSettings>
|
||||||
|
</asmv3:application>
|
||||||
</assembly>
|
</assembly>
|
|
@ -0,0 +1,184 @@
|
||||||
|
// This file is part of Notepad++ project
|
||||||
|
// Copyright (c) 2024 ozone10 and Notepad++ team
|
||||||
|
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// at your option any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
#include "dpiManagerV2.h"
|
||||||
|
|
||||||
|
template <typename P>
|
||||||
|
bool ptrFn(HMODULE handle, P& pointer, const char* name)
|
||||||
|
{
|
||||||
|
auto p = reinterpret_cast<P>(::GetProcAddress(handle, name));
|
||||||
|
if (p != nullptr)
|
||||||
|
{
|
||||||
|
pointer = p;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
using fnGetDpiForSystem = UINT (WINAPI*)(VOID);
|
||||||
|
using fnGetDpiForWindow = UINT (WINAPI*)(HWND hwnd);
|
||||||
|
using fnGetSystemMetricsForDpi = int (WINAPI*)(int nIndex, UINT dpi);
|
||||||
|
using fnSystemParametersInfoForDpi = BOOL (WINAPI*)(UINT uiAction, UINT uiParam, PVOID pvParam, UINT fWinIni, UINT dpi);
|
||||||
|
using fnSetThreadDpiAwarenessContext = DPI_AWARENESS_CONTEXT (WINAPI*)(DPI_AWARENESS_CONTEXT dpiContext);
|
||||||
|
|
||||||
|
fnGetDpiForSystem _fnGetDpiForSystem = nullptr;
|
||||||
|
fnGetDpiForWindow _fnGetDpiForWindow = nullptr;
|
||||||
|
fnGetSystemMetricsForDpi _fnGetSystemMetricsForDpi = nullptr;
|
||||||
|
fnSystemParametersInfoForDpi _fnSystemParametersInfoForDpi = nullptr;
|
||||||
|
fnSetThreadDpiAwarenessContext _fnSetThreadDpiAwarenessContext = nullptr;
|
||||||
|
|
||||||
|
void DPIManagerV2::initDpiAPI()
|
||||||
|
{
|
||||||
|
if (NppDarkMode::isWindows10())
|
||||||
|
{
|
||||||
|
HMODULE hUser32 = ::GetModuleHandleW(L"user32.dll");
|
||||||
|
if (hUser32 != nullptr)
|
||||||
|
{
|
||||||
|
ptrFn(hUser32, _fnGetDpiForSystem, "GetDpiForSystem");
|
||||||
|
ptrFn(hUser32, _fnGetDpiForWindow, "GetDpiForWindow");
|
||||||
|
ptrFn(hUser32, _fnGetSystemMetricsForDpi, "GetSystemMetricsForDpi");
|
||||||
|
ptrFn(hUser32, _fnSystemParametersInfoForDpi, "SystemParametersInfoForDpi");
|
||||||
|
ptrFn(hUser32, _fnSetThreadDpiAwarenessContext, "SetThreadDpiAwarenessContext");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int DPIManagerV2::getSystemMetricsForDpi(int nIndex, UINT dpi)
|
||||||
|
{
|
||||||
|
if (_fnGetSystemMetricsForDpi != nullptr)
|
||||||
|
{
|
||||||
|
return _fnGetSystemMetricsForDpi(nIndex, dpi);
|
||||||
|
}
|
||||||
|
return DPIManagerV2::scale(::GetSystemMetrics(nIndex), dpi);
|
||||||
|
}
|
||||||
|
|
||||||
|
DPI_AWARENESS_CONTEXT DPIManagerV2::setThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT dpiContext)
|
||||||
|
{
|
||||||
|
if (_fnSetThreadDpiAwarenessContext != nullptr)
|
||||||
|
{
|
||||||
|
return _fnSetThreadDpiAwarenessContext(dpiContext);
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
UINT DPIManagerV2::getDpiForSystem()
|
||||||
|
{
|
||||||
|
if (_fnGetDpiForSystem != nullptr)
|
||||||
|
{
|
||||||
|
return _fnGetDpiForSystem();
|
||||||
|
}
|
||||||
|
|
||||||
|
UINT dpi = USER_DEFAULT_SCREEN_DPI;
|
||||||
|
HDC hdc = ::GetDC(nullptr);
|
||||||
|
if (hdc != nullptr)
|
||||||
|
{
|
||||||
|
dpi = ::GetDeviceCaps(hdc, LOGPIXELSX);
|
||||||
|
::ReleaseDC(nullptr, hdc);
|
||||||
|
}
|
||||||
|
return dpi;
|
||||||
|
}
|
||||||
|
|
||||||
|
UINT DPIManagerV2::getDpiForWindow(HWND hWnd)
|
||||||
|
{
|
||||||
|
if (_fnGetDpiForWindow != nullptr)
|
||||||
|
{
|
||||||
|
const auto dpi = _fnGetDpiForWindow(hWnd);
|
||||||
|
if (dpi > 0)
|
||||||
|
{
|
||||||
|
return dpi;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return getDpiForSystem();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DPIManagerV2::setPositionDpi(LPARAM lParam, HWND hWnd)
|
||||||
|
{
|
||||||
|
const auto prcNewWindow = reinterpret_cast<RECT*>(lParam);
|
||||||
|
|
||||||
|
::SetWindowPos(hWnd,
|
||||||
|
nullptr,
|
||||||
|
prcNewWindow->left,
|
||||||
|
prcNewWindow->top,
|
||||||
|
prcNewWindow->right - prcNewWindow->left,
|
||||||
|
prcNewWindow->bottom - prcNewWindow->top,
|
||||||
|
SWP_NOZORDER | SWP_NOACTIVATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
LOGFONT DPIManagerV2::getDefaultGUIFontForDpi(UINT dpi, FontType type)
|
||||||
|
{
|
||||||
|
int result = 0;
|
||||||
|
LOGFONT lf{};
|
||||||
|
NONCLIENTMETRICS ncm{};
|
||||||
|
ncm.cbSize = sizeof(NONCLIENTMETRICS);
|
||||||
|
if (_fnSystemParametersInfoForDpi != nullptr
|
||||||
|
&& (_fnSystemParametersInfoForDpi(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0, dpi) != FALSE))
|
||||||
|
{
|
||||||
|
result = 2;
|
||||||
|
}
|
||||||
|
else if (::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0) != FALSE)
|
||||||
|
{
|
||||||
|
result = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result > 0)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case FontType::menu:
|
||||||
|
{
|
||||||
|
lf = ncm.lfMenuFont;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case FontType::status:
|
||||||
|
{
|
||||||
|
lf = ncm.lfStatusFont;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case FontType::caption:
|
||||||
|
{
|
||||||
|
lf = ncm.lfCaptionFont;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case FontType::smcaption:
|
||||||
|
{
|
||||||
|
lf = ncm.lfSmCaptionFont;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//case FontType::message:
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
lf = ncm.lfMessageFont;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else // should not happen, fallback
|
||||||
|
{
|
||||||
|
auto hf = static_cast<HFONT>(::GetStockObject(DEFAULT_GUI_FONT));
|
||||||
|
::GetObject(hf, sizeof(LOGFONT), &lf);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result < 2)
|
||||||
|
{
|
||||||
|
lf.lfHeight = scaleFont(lf.lfHeight, dpi);
|
||||||
|
}
|
||||||
|
|
||||||
|
return lf;
|
||||||
|
}
|
|
@ -0,0 +1,120 @@
|
||||||
|
// This file is part of Notepad++ project
|
||||||
|
// Copyright (c) 2024 ozone10 and Notepad++ team
|
||||||
|
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// at your option any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "NppDarkMode.h"
|
||||||
|
|
||||||
|
class DPIManagerV2
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DPIManagerV2() {
|
||||||
|
setDpiWithSystem();
|
||||||
|
}
|
||||||
|
virtual ~DPIManagerV2() = default;
|
||||||
|
|
||||||
|
enum class FontType { menu, status, message, caption, smcaption };
|
||||||
|
|
||||||
|
static void initDpiAPI();
|
||||||
|
|
||||||
|
static int getSystemMetricsForDpi(int nIndex, UINT dpi);
|
||||||
|
static DPI_AWARENESS_CONTEXT setThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT dpiContext);
|
||||||
|
|
||||||
|
static UINT getDpiForSystem();
|
||||||
|
static UINT getDpiForWindow(HWND hWnd);
|
||||||
|
static UINT getDpiForParent(HWND hWnd) {
|
||||||
|
return getDpiForWindow(::GetParent(hWnd));
|
||||||
|
}
|
||||||
|
|
||||||
|
void setDpiWithSystem() {
|
||||||
|
_dpi = getDpiForSystem();
|
||||||
|
}
|
||||||
|
|
||||||
|
// parameter is WPARAM
|
||||||
|
void setDpiWP(WPARAM wParam) {
|
||||||
|
_dpi = LOWORD(wParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setDpi(UINT newDpi) {
|
||||||
|
_dpi = newDpi;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setDpi(HWND hWnd) {
|
||||||
|
setDpi(getDpiForWindow(hWnd));
|
||||||
|
}
|
||||||
|
|
||||||
|
void setDpiWithParent(HWND hWnd) {
|
||||||
|
setDpi(::GetParent(hWnd));
|
||||||
|
}
|
||||||
|
|
||||||
|
UINT getDpi() const {
|
||||||
|
return _dpi;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void setPositionDpi(LPARAM lParam, HWND hWnd);
|
||||||
|
|
||||||
|
static int scale(int x, UINT dpi, UINT dpi2) {
|
||||||
|
return MulDiv(x, dpi, dpi2);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int scale(int x, UINT dpi) {
|
||||||
|
return scale(x, dpi, USER_DEFAULT_SCREEN_DPI);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int unscale(int x, UINT dpi) {
|
||||||
|
return scale(x, USER_DEFAULT_SCREEN_DPI, dpi);
|
||||||
|
}
|
||||||
|
|
||||||
|
int scale(int x) {
|
||||||
|
return scale(x, _dpi);
|
||||||
|
}
|
||||||
|
|
||||||
|
int unscale(int x) {
|
||||||
|
return unscale(x, _dpi);
|
||||||
|
}
|
||||||
|
|
||||||
|
int scaleX(int x) {
|
||||||
|
return scale(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
int unscaleX(int x) {
|
||||||
|
return unscale(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
int scaleY(int y) {
|
||||||
|
return scale(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
int unscaleY(int y) {
|
||||||
|
return unscale(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int scaleFont(int pt, UINT dpi) {
|
||||||
|
return -(scale(pt, dpi, 72));
|
||||||
|
}
|
||||||
|
|
||||||
|
int scaleFont(int pt) {
|
||||||
|
return scaleFont(pt, _dpi);
|
||||||
|
}
|
||||||
|
|
||||||
|
static LOGFONT getDefaultGUIFontForDpi(UINT dpi, FontType type = FontType::message);
|
||||||
|
static LOGFONT getDefaultGUIFontForDpi(HWND hWnd, FontType type = FontType::message) {
|
||||||
|
return getDefaultGUIFontForDpi(getDpiForWindow(hWnd), type);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
UINT _dpi = USER_DEFAULT_SCREEN_DPI;
|
||||||
|
};
|
|
@ -20,6 +20,7 @@
|
||||||
#include "MiniDumper.h" //Write dump files
|
#include "MiniDumper.h" //Write dump files
|
||||||
#include "verifySignedfile.h"
|
#include "verifySignedfile.h"
|
||||||
#include "NppDarkMode.h"
|
#include "NppDarkMode.h"
|
||||||
|
#include "dpiManagerV2.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
typedef std::vector<std::wstring> ParamVector;
|
typedef std::vector<std::wstring> ParamVector;
|
||||||
|
@ -502,6 +503,7 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE /*hPrevInstance
|
||||||
NppGUI & nppGui = nppParameters.getNppGUI();
|
NppGUI & nppGui = nppParameters.getNppGUI();
|
||||||
|
|
||||||
NppDarkMode::initDarkMode();
|
NppDarkMode::initDarkMode();
|
||||||
|
DPIManagerV2::initDpiAPI();
|
||||||
|
|
||||||
bool doUpdateNpp = nppGui._autoUpdateOpt._doAutoUpdate;
|
bool doUpdateNpp = nppGui._autoUpdateOpt._doAutoUpdate;
|
||||||
bool doUpdatePluginList = nppGui._autoUpdateOpt._doAutoUpdate;
|
bool doUpdatePluginList = nppGui._autoUpdateOpt._doAutoUpdate;
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
<ItemDefinitionGroup Label="Globals">
|
<ItemDefinitionGroup Label="Globals">
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
<AdditionalIncludeDirectories>..\src;..\src\MISC;..\src\MISC\Common;..\src\MISC\Exception;..\src\MISC\PluginsManager;..\src\MISC\Process;..\src\MISC\RegExt;..\src\MISC\md5;..\src\MISC\sha1;..\src\MISC\sha2;..\src\MISC\sha512;..\src\MISC\SysMsg;..\src\ScintillaComponent;..\src\Win32Explr;..\src\WinControls;..\src\WinControls\AboutDlg;..\src\WinControls\AnsiCharPanel;..\src\WinControls\ClipboardHistory;..\src\WinControls\ColourPicker;..\src\WinControls\ContextMenu;..\src\WinControls\DockingWnd;..\src\WinControls\DocumentMap;..\src\WinControls\FileBrowser;..\src\WinControls\FindCharsInRange;..\src\WinControls\FunctionList;..\src\WinControls\Grid;..\src\WinControls\ImageListSet;..\src\WinControls\OpenSaveFileDialog;..\src\WinControls\PluginsAdmin;..\src\WinControls\Preference;..\src\WinControls\ProjectPanel;..\src\WinControls\ReadDirectoryChanges;..\src\WinControls\shortcut;..\src\WinControls\SplitterContainer;..\src\WinControls\StaticDialog;..\src\WinControls\StaticDialog\RunDlg;..\src\WinControls\StatusBar;..\src\WinControls\TabBar;..\src\WinControls\TaskList;..\src\WinControls\ToolBar;..\src\WinControls\ToolTip;..\src\WinControls\TrayIcon;..\src\WinControls\TreeView;..\src\WinControls\VerticalFileSwitcher;..\src\WinControls\WindowsDlg;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>..\src;..\src\MISC;..\src\MISC\Common;..\src\MISC\Exception;..\src\MISC\PluginsManager;..\src\MISC\Process;..\src\MISC\RegExt;..\src\MISC\md5;..\src\MISC\sha1;..\src\MISC\sha2;..\src\MISC\sha512;..\src\MISC\SysMsg;..\src\ScintillaComponent;..\src\Win32Explr;..\src\WinControls;..\src\WinControls\AboutDlg;..\src\WinControls\AnsiCharPanel;..\src\WinControls\ClipboardHistory;..\src\WinControls\ColourPicker;..\src\WinControls\ContextMenu;..\src\WinControls\DockingWnd;..\src\WinControls\DocumentMap;..\src\WinControls\FileBrowser;..\src\WinControls\FindCharsInRange;..\src\WinControls\FunctionList;..\src\WinControls\Grid;..\src\WinControls\ImageListSet;..\src\WinControls\OpenSaveFileDialog;..\src\WinControls\PluginsAdmin;..\src\WinControls\Preference;..\src\WinControls\ProjectPanel;..\src\WinControls\ReadDirectoryChanges;..\src\WinControls\shortcut;..\src\WinControls\SplitterContainer;..\src\WinControls\StaticDialog;..\src\WinControls\StaticDialog\RunDlg;..\src\WinControls\StatusBar;..\src\WinControls\TabBar;..\src\WinControls\TaskList;..\src\WinControls\ToolBar;..\src\WinControls\ToolTip;..\src\WinControls\TrayIcon;..\src\WinControls\TreeView;..\src\WinControls\VerticalFileSwitcher;..\src\WinControls\WindowsDlg;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
<PreprocessorDefinitions>WIN32;_WIN32_WINNT=_WIN32_WINNT_VISTA;_WINDOWS;OEMRESOURCE;NOMINMAX;_USE_64BIT_TIME_T;TIXML_USE_STL;TIXMLA_USE_STL;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT;_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;_WIN32_WINNT=_WIN32_WINNT_WIN7;NTDDI_VERSION=NTDDI_WIN7;_WINDOWS;OEMRESOURCE;NOMINMAX;_USE_64BIT_TIME_T;TIXML_USE_STL;TIXMLA_USE_STL;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT;_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ExceptionHandling>Async</ExceptionHandling>
|
<ExceptionHandling>Async</ExceptionHandling>
|
||||||
<WarningLevel>Level4</WarningLevel>
|
<WarningLevel>Level4</WarningLevel>
|
||||||
<TreatWarningAsError>true</TreatWarningAsError>
|
<TreatWarningAsError>true</TreatWarningAsError>
|
||||||
|
|
|
@ -65,7 +65,6 @@
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
<ImportGroup Label="PropertySheets">
|
<ImportGroup Label="PropertySheets">
|
||||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC70.props" />
|
|
||||||
<Import Project="notepadPlus.Cpp.props" />
|
<Import Project="notepadPlus.Cpp.props" />
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
<PropertyGroup Label="UserMacros" />
|
<PropertyGroup Label="UserMacros" />
|
||||||
|
@ -114,6 +113,7 @@
|
||||||
<ClCompile Include="..\src\MISC\sha2\sha-256.cpp" />
|
<ClCompile Include="..\src\MISC\sha2\sha-256.cpp" />
|
||||||
<ClCompile Include="..\src\MISC\sha512\sha512.cpp" />
|
<ClCompile Include="..\src\MISC\sha512\sha512.cpp" />
|
||||||
<ClCompile Include="..\src\NppDarkMode.cpp" />
|
<ClCompile Include="..\src\NppDarkMode.cpp" />
|
||||||
|
<ClCompile Include="..\src\dpiManagerV2.cpp" />
|
||||||
<ClCompile Include="..\src\WinControls\AboutDlg\AboutDlg.cpp" />
|
<ClCompile Include="..\src\WinControls\AboutDlg\AboutDlg.cpp" />
|
||||||
<ClCompile Include="..\src\WinControls\AnsiCharPanel\ansiCharPanel.cpp" />
|
<ClCompile Include="..\src\WinControls\AnsiCharPanel\ansiCharPanel.cpp" />
|
||||||
<ClCompile Include="..\src\ScintillaComponent\AutoCompletion.cpp" />
|
<ClCompile Include="..\src\ScintillaComponent\AutoCompletion.cpp" />
|
||||||
|
@ -242,6 +242,7 @@
|
||||||
<ClInclude Include="..\src\DarkMode\IatHook.h" />
|
<ClInclude Include="..\src\DarkMode\IatHook.h" />
|
||||||
<ClInclude Include="..\src\DarkMode\UAHMenuBar.h" />
|
<ClInclude Include="..\src\DarkMode\UAHMenuBar.h" />
|
||||||
<ClInclude Include="..\src\dpiManager.h" />
|
<ClInclude Include="..\src\dpiManager.h" />
|
||||||
|
<ClInclude Include="..\src\dpiManagerV2.h" />
|
||||||
<ClInclude Include="..\src\keys.h" />
|
<ClInclude Include="..\src\keys.h" />
|
||||||
<ClInclude Include="..\src\localizationString.h" />
|
<ClInclude Include="..\src\localizationString.h" />
|
||||||
<ClInclude Include="..\src\MISC\Common\Sorters.h" />
|
<ClInclude Include="..\src\MISC\Common\Sorters.h" />
|
||||||
|
|
Loading…
Reference in New Issue