From 56bbc626c67ab1bcbc69d14ac2b2fc288ecbb341 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Sat, 21 Mar 2020 22:20:23 +0100 Subject: [PATCH] + fix: refactoring for Scintilla DLL version --- scintilla/ScintillaDLL.vcxproj | 8 +-- scintilla/include/Scintilla.h | 12 +++-- scintilla/win32/PlatWin.cxx | 84 ++++++++++++++++++++++++++---- scintilla/win32/PlatWin.h | 15 +++--- scintilla/win32/ScintillaWin.cxx | 24 ++++++++- src/ChooseFont/ChooseFont.cpp | 1 + src/Dialogs.c | 6 +-- src/Helpers.c | 87 +++++--------------------------- src/Helpers.h | 44 ++++------------ src/Notepad3.c | 29 ++++------- src/Styles.c | 4 +- src/TypeDefs.h | 6 --- 12 files changed, 155 insertions(+), 165 deletions(-) diff --git a/scintilla/ScintillaDLL.vcxproj b/scintilla/ScintillaDLL.vcxproj index ce7b75d7f..fc420233d 100644 --- a/scintilla/ScintillaDLL.vcxproj +++ b/scintilla/ScintillaDLL.vcxproj @@ -138,7 +138,7 @@ false - imm32.lib;Shlwapi.lib;%(AdditionalDependencies) + imm32.lib;Shlwapi.lib;Comctl32.lib;%(AdditionalDependencies) @@ -165,7 +165,7 @@ true - imm32.lib;Shlwapi.lib;%(AdditionalDependencies) + imm32.lib;Shlwapi.lib;Comctl32.lib;%(AdditionalDependencies) @@ -192,7 +192,7 @@ true - imm32.lib;Shlwapi.lib;%(AdditionalDependencies) + imm32.lib;Shlwapi.lib;Comctl32.lib;%(AdditionalDependencies) @@ -220,7 +220,7 @@ true - imm32.lib;Shlwapi.lib;%(AdditionalDependencies) + imm32.lib;Shlwapi.lib;Comctl32.lib;%(AdditionalDependencies) diff --git a/scintilla/include/Scintilla.h b/scintilla/include/Scintilla.h index dbc53bbe6..3e46fea1a 100644 --- a/scintilla/include/Scintilla.h +++ b/scintilla/include/Scintilla.h @@ -15,14 +15,20 @@ extern "C" { #endif +typedef struct _dpi_t { int x; int y; } DPI_T; + #if defined(_WIN32) /* Return false on failure: */ // >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>> -__declspec(dllexport) int Scintilla_RegisterClasses(void *hInstance); -__declspec(dllexport) int Scintilla_ReleaseResources(void); -__declspec(dllexport) int Scintilla_InputCodePage(void); + +__declspec(dllexport) int Scintilla_RegisterClasses(void *hInstance); +__declspec(dllexport) int Scintilla_ReleaseResources(void); +__declspec(dllexport) int Scintilla_InputCodePage(void); +__declspec(dllexport) DPI_T Scintilla_GetCurrentDPI(void* hwnd); +__declspec(dllexport) int Scintilla_GetSystemMetricsEx(void* hwnd, int nIndex); // <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<< #endif + int Scintilla_LinkLexers(void); #ifdef __cplusplus diff --git a/scintilla/win32/PlatWin.cxx b/scintilla/win32/PlatWin.cxx index 887fb5d9f..279095299 100644 --- a/scintilla/win32/PlatWin.cxx +++ b/scintilla/win32/PlatWin.cxx @@ -43,6 +43,7 @@ #include #include #include +#include #include "Platform.h" #include "Scintilla.h" @@ -69,13 +70,9 @@ #endif #if _WIN32_WINNT < _WIN32_WINNT_WIN8 -#if NP2_FORCE_COMPILE_C_AS_CPP extern DWORD kSystemLibraryLoadFlags; #else -extern "C" DWORD kSystemLibraryLoadFlags; -#endif -#else -#define kSystemLibraryLoadFlags LOAD_LIBRARY_SEARCH_SYSTEM32 +#define kSystemLibraryLoadFlags LOAD_LIBRARY_SEARCH_SYSTEM32 #endif namespace Scintilla { @@ -2631,7 +2628,7 @@ PRectangle ListBoxX::GetDesiredRect() { rcDesired.right = rcDesired.left + TextOffset() + width + (TextInset.x * 2); if (Length() > rows) - rcDesired.right += GetSystemMetricsEx(SM_CXVSCROLL); + rcDesired.right += GetSystemMetricsEx(GetHWND(), SM_CXVSCROLL); AdjustWindowRect(&rcDesired); return rcDesired; @@ -2879,7 +2876,7 @@ POINT ListBoxX::MinTrackSize() const { POINT ListBoxX::MaxTrackSize() const { const int width = maxCharWidth * maxItemCharacters + static_cast(TextInset.x) * 2 + - TextOffset() + GetSystemMetricsEx(SM_CXVSCROLL); + TextOffset() + GetSystemMetricsEx(GetHWND(), SM_CXVSCROLL); PRectangle rc = PRectangle::FromInts(0, 0, std::max(MinClientWidth(), width), ItemHeight() * lti.Count()); @@ -2990,7 +2987,7 @@ LRESULT ListBoxX::NcHitTest(WPARAM wParam, LPARAM lParam) const noexcept { // window caption height + frame, even if one is hovering over the bottom edge of // the frame, so workaround that here if (hit >= HTTOP && hit <= HTTOPRIGHT) { - const int minHeight = GetSystemMetricsEx(SM_CYMINTRACK); + const int minHeight = GetSystemMetricsEx(GetHWND(), SM_CYMINTRACK); const int yPos = GET_Y_LPARAM(lParam); if ((rc.Height() < minHeight) && (yPos > ((rc.top + rc.bottom)/2))) { hit += HTBOTTOM - HTTOP; @@ -2998,9 +2995,9 @@ LRESULT ListBoxX::NcHitTest(WPARAM wParam, LPARAM lParam) const noexcept { } #if LISTBOXX_USE_BORDER || LISTBOXX_USE_FAKE_FRAME else if (hit < HTSIZEFIRST || hit > HTSIZELAST) { - const int cx = GetSystemMetricsEx(SM_CXVSCROLL); + const int cx = GetSystemMetricsEx(GetHWND(), SM_CXVSCROLL); #if LISTBOXX_USE_BORDER - const PRectangle rcInner = rc.Deflate(GetSystemMetricsEx(SM_CXBORDER), GetSystemMetricsEx(SM_CYBORDER)); + const PRectangle rcInner = rc.Deflate(GetSystemMetricsEx(GetHWND(), SM_CXBORDER), GetSystemMetricsEx(GetHWND(), SM_CYBORDER)); #else const PRectangle rcInner = rc.Deflate(ListBoxXFakeFrameSize, ListBoxXFakeFrameSize); #endif @@ -3575,4 +3572,71 @@ void Platform_Finalise(bool fromDllMain) noexcept { #endif } + +//============================================================================= +// +// GetCurrentDPI() +// +#ifdef _WIN64 +typedef INT_PTR(FAR WINAPI* FARPROCHWND)(HWND); +typedef INT_PTR(FAR WINAPI* FARPROCMONI)(HMONITOR, int, UINT*, UINT*); +#else +typedef int (FAR WINAPI* FARPROCHWND)(HWND); +typedef int (FAR WINAPI* FARPROCMONI)(HMONITOR, int, UINT*, UINT*); +#endif // _WIN64 + + +DPI_T GetCurrentDPI(HWND hwnd) { + + DPI_T curDPI = { 0, 0 }; + + if (IsWindows10OrGreater()) { + HMODULE const hModule = GetModuleHandle(L"user32.dll"); + if (hModule) { + FARPROCHWND const pfnGetDpiForWindow = (FARPROCHWND)GetProcAddress(hModule, "GetDpiForWindow"); + if (pfnGetDpiForWindow) { + curDPI.x = curDPI.y = (int)pfnGetDpiForWindow(hwnd); + } + } + } + + if ((curDPI.x == 0) && IsWindows8Point1OrGreater()) { + HMODULE hShcore = LoadLibrary(L"shcore.dll"); + if (hShcore) { + FARPROCMONI const pfnGetDpiForMonitor = (FARPROCMONI)GetProcAddress(hShcore, "GetDpiForMonitor"); + if (pfnGetDpiForMonitor) { + HMONITOR const hMonitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST); + UINT dpiX = 0, dpiY = 0; + if (pfnGetDpiForMonitor(hMonitor, 0 /* MDT_EFFECTIVE_DPI */, &dpiX, &dpiY) == S_OK) { + curDPI.x = dpiX; + curDPI.y = dpiY; + } + } + FreeLibrary(hShcore); + } + } + + if (curDPI.x == 0) { + HDC hDC = GetDC(hwnd); + curDPI.x = GetDeviceCaps(hDC, LOGPIXELSX); + curDPI.y = GetDeviceCaps(hDC, LOGPIXELSY); + ReleaseDC(hwnd, hDC); + } + + curDPI.x = std::max((int)curDPI.x, USER_DEFAULT_SCREEN_DPI); + curDPI.y = std::max((int)curDPI.y, USER_DEFAULT_SCREEN_DPI); + return curDPI; +} + +//============================================================================= +// +// GetSystemMetricsEx() +// get system metric for current DPI +// https://docs.microsoft.com/de-de/windows/desktop/api/winuser/nf-winuser-getsystemmetricsfordpi +// +int GetSystemMetricsEx(HWND hwnd, int nIndex) +{ + return ScaleIntToDPI_Y(hwnd, GetSystemMetrics(nIndex)); +} + } diff --git a/scintilla/win32/PlatWin.h b/scintilla/win32/PlatWin.h index 37b542a15..8e46eb253 100644 --- a/scintilla/win32/PlatWin.h +++ b/scintilla/win32/PlatWin.h @@ -43,15 +43,6 @@ #endif -// force compile C as CPP -#define NP2_FORCE_COMPILE_C_AS_CPP 0 - -#if NP2_FORCE_COMPILE_C_AS_CPP -extern int GetSystemMetricsEx(int nIndex); -#else -extern "C" int GetSystemMetricsEx(int nIndex); -#endif - namespace Scintilla { @@ -86,6 +77,12 @@ extern ID2D1Factory *pD2DFactory; extern IDWriteFactory *pIDWriteFactory; #endif + +DPI_T GetCurrentDPI(HWND hwnd); +int GetSystemMetricsEx(HWND hwnd, int nIndex); +inline int ScaleIntToDPI_X(HWND hwnd, int val) { DPI_T const dpi = GetCurrentDPI(hwnd); return MulDiv((val), dpi.x, USER_DEFAULT_SCREEN_DPI); } +inline int ScaleIntToDPI_Y(HWND hwnd, int val) { DPI_T const dpi = GetCurrentDPI(hwnd); return MulDiv((val), dpi.y, USER_DEFAULT_SCREEN_DPI); } + } #endif diff --git a/scintilla/win32/ScintillaWin.cxx b/scintilla/win32/ScintillaWin.cxx index ff44d7980..d88a1af22 100644 --- a/scintilla/win32/ScintillaWin.cxx +++ b/scintilla/win32/ScintillaWin.cxx @@ -50,6 +50,7 @@ #include #include #include +#include #define DebugDragAndDropDataFormat 0 @@ -150,6 +151,7 @@ constexpr UINT SC_WORK_IDLE = 5002; #endif #if _WIN32_WINNT < _WIN32_WINNT_WIN8 +DWORD kSystemLibraryLoadFlags = 0; using SetCoalescableTimerSig = UINT_PTR (WINAPI *)(HWND hwnd, UINT_PTR nIDEvent, UINT uElapse, TIMERPROC lpTimerFunc, ULONG uToleranceDelay); #endif @@ -822,8 +824,8 @@ bool ScintillaWin::DragThreshold(Point ptStart, Point ptNow) noexcept { const Point ptDifference = ptStart - ptNow; const XYPOSITION xMove = std::trunc(std::abs(ptDifference.x)); const XYPOSITION yMove = std::trunc(std::abs(ptDifference.y)); - return (xMove > GetSystemMetricsEx(SM_CXDRAG)) || - (yMove > GetSystemMetricsEx(SM_CYDRAG)); + return (xMove > GetSystemMetricsEx(MainHWND(), SM_CXDRAG)) || + (yMove > GetSystemMetricsEx(MainHWND(), SM_CYDRAG)); } void ScintillaWin::StartDrag() { @@ -3779,7 +3781,14 @@ namespace Scintilla { // Must be called once only. extern "C" __declspec(dllexport) int Scintilla_RegisterClasses(void *hInstance) { + +#if _WIN32_WINNT < _WIN32_WINNT_WIN8 + // see LoadD2D() in PlatWin.cxx + kSystemLibraryLoadFlags = (IsWindows8Point1OrGreater() || GetProcAddress(GetModuleHandle(L"kernel32.dll"), "SetDefaultDllDirectories")) ? LOAD_LIBRARY_SEARCH_SYSTEM32 : 0; +#endif + Platform_Initialise(hInstance); + const bool result = ScintillaWin::Register(static_cast(hInstance)); #ifdef SCI_LEXER Scintilla_LinkLexers(); @@ -3797,3 +3806,14 @@ extern "C" __declspec(dllexport) int Scintilla_InputCodePage(void) { return InputCodePage(); } + +extern "C" __declspec(dllexport) +DPI_T Scintilla_GetCurrentDPI(void* hwnd) { + return GetCurrentDPI(static_cast(hwnd)); +} + +extern "C" __declspec(dllexport) +int Scintilla_GetSystemMetricsEx(void* hwnd, int nIndex) { + return GetSystemMetricsEx(static_cast(hwnd), nIndex); +} + diff --git a/src/ChooseFont/ChooseFont.cpp b/src/ChooseFont/ChooseFont.cpp index d61320648..708970882 100644 --- a/src/ChooseFont/ChooseFont.cpp +++ b/src/ChooseFont/ChooseFont.cpp @@ -12,6 +12,7 @@ #include "ChooseFont.h" #include "FontEnumeration.h" #include "GdiTextRenderer.h" +#include "Scintilla.h" extern "C" { #include "../resource.h" diff --git a/src/Dialogs.c b/src/Dialogs.c index 95185774e..ee531ba49 100644 --- a/src/Dialogs.c +++ b/src/Dialogs.c @@ -699,7 +699,7 @@ INT_PTR CALLBACK AboutDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam { UpdateWindowLayoutForDPI(hwnd, 0, 0, 0, 0); - DPI_T const dpi = GetCurrentDPI(hwnd); + DPI_T const dpi = Scintilla_GetCurrentDPI(hwnd); SendDlgItemMessage(hwnd, IDC_RICHEDITABOUT, EM_SETZOOM, (WPARAM)dpi.y, (LPARAM)USER_DEFAULT_SCREEN_DPI); //~~// get current richedit box format @@ -844,7 +844,7 @@ INT_PTR CALLBACK AboutDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam StringCchPrintf(wchBuf, COUNTOF(wchBuf), L"\n- Screen-Resolution = %i x %i [pix]", ResX, ResY); StringCchCat(wchVerInfo, COUNTOF(wchVerInfo), wchBuf); - DPI_T dpi = GetCurrentDPI(hwnd); + DPI_T dpi = Scintilla_GetCurrentDPI(hwnd); StringCchPrintf(wchBuf, COUNTOF(wchBuf), L"\n- Display-DPI = %i x %i (Scale: %i%%).", dpi.x, dpi.y, ScaleIntToDPI_X(hwnd, 100)); StringCchCat(wchVerInfo, COUNTOF(wchVerInfo), wchBuf); @@ -3778,7 +3778,7 @@ void ResizeDlg_InitEx(HWND hwnd, int cxFrame, int cyFrame, int nIdGrip, int iDir HWND hwndCtl = GetDlgItem(hwnd, nIdGrip); SetWindowLongPtr(hwndCtl, GWL_STYLE, GetWindowLongPtr(hwndCtl, GWL_STYLE) | SBS_SIZEGRIP | WS_CLIPSIBLINGS); /// TODO: per-window DPI - const int cGrip = GetSystemMetricsEx(hwnd, SM_CXHTHUMB); + const int cGrip = Scintilla_GetSystemMetricsEx(hwnd, SM_CXHTHUMB); SetWindowPos(hwndCtl, NULL, pm->cxClient - cGrip, pm->cyClient - cGrip, cGrip, cGrip, SWP_NOZORDER); } diff --git a/src/Helpers.c b/src/Helpers.c index b55f65eb8..d6b5703d3 100644 --- a/src/Helpers.c +++ b/src/Helpers.c @@ -214,26 +214,26 @@ void GetWinVersionString(LPWSTR szVersionStr, size_t cchVersionStr) { StringCchCopy(szVersionStr, cchVersionStr, L"OS Version: Windows "); - if (IsWin10OrHigher()) { - StringCchCat(szVersionStr, cchVersionStr, IsWinServer() ? L"Server 2016 " : L"10 "); + if (IsWindows10OrGreater()) { + StringCchCat(szVersionStr, cchVersionStr, IsWindowsServer() ? L"Server 2016 " : L"10 "); } - else if (IsWin81OrHigher()) { - StringCchCat(szVersionStr, cchVersionStr, IsWinServer() ? L"Server 2012 R2 " : L"8.1"); + else if (IsWindows8Point1OrGreater()) { + StringCchCat(szVersionStr, cchVersionStr, IsWindowsServer() ? L"Server 2012 R2 " : L"8.1"); } - else if (IsWin8OrHigher()) { - StringCchCat(szVersionStr, cchVersionStr, IsWinServer() ? L"Server 2012 " : L"8"); + else if (IsWindows8OrGreater()) { + StringCchCat(szVersionStr, cchVersionStr, IsWindowsServer() ? L"Server 2012 " : L"8"); } - else if (IsWin71OrHigher()) { - StringCchCat(szVersionStr, cchVersionStr, IsWinServer() ? L"Server 2008 R2 " : L"7 (SP1)"); + else if (IsWindows7SP1OrGreater()) { + StringCchCat(szVersionStr, cchVersionStr, IsWindowsServer() ? L"Server 2008 R2 " : L"7 (SP1)"); } - else if (IsWin7OrHigher()) { - StringCchCat(szVersionStr, cchVersionStr, IsWinServer() ? L"Server 2008 " : L"7"); + else if (IsWindows7OrGreater()) { + StringCchCat(szVersionStr, cchVersionStr, IsWindowsServer() ? L"Server 2008 " : L"7"); } else { - StringCchCat(szVersionStr, cchVersionStr, IsWinServer() ? L"Unkown Server " : L"?"); + StringCchCat(szVersionStr, cchVersionStr, IsWindowsServer() ? L"Unkown Server " : L"?"); } - if (IsWin10OrHigher()) { + if (IsWindows10OrGreater()) { WCHAR win10ver[80] = { L'\0' }; if (s_OSversion.dwOSVersionInfoSize == 0) { _GetTrueWindowsVersion(); } DWORD const build = s_OSversion.dwBuildNumber; @@ -318,53 +318,6 @@ void SetUACIcon(const HMENU hMenu, const UINT nItem) } -//============================================================================= -// -// GetCurrentDPI() -// -DPI_T GetCurrentDPI(HWND hwnd) { - - DPI_T curDPI = { 0, 0 }; - - if (IsWin10OrHigher()) { - HMODULE const hModule = GetModuleHandle(L"user32.dll"); - if (hModule) { - FARPROC const pfnGetDpiForWindow = GetProcAddress(hModule, "GetDpiForWindow"); - if (pfnGetDpiForWindow) { - curDPI.x = curDPI.y = (UINT)pfnGetDpiForWindow(hwnd); - } - } - } - - if ((curDPI.x == 0) && IsWin81OrHigher()) { - HMODULE hShcore = LoadLibrary(L"shcore.dll"); - if (hShcore) { - FARPROC const pfnGetDpiForMonitor = GetProcAddress(hShcore, "GetDpiForMonitor"); - if (pfnGetDpiForMonitor) { - HMONITOR const hMonitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST); - UINT dpiX = 0, dpiY = 0; - if (pfnGetDpiForMonitor(hMonitor, 0 /* MDT_EFFECTIVE_DPI */, &dpiX, &dpiY) == S_OK) { - curDPI.x = dpiX; - curDPI.y = dpiY; - } - } - FreeLibrary(hShcore); - } - } - - if (curDPI.x == 0) { - HDC hDC = GetDC(hwnd); - curDPI.x = GetDeviceCaps(hDC, LOGPIXELSX); - curDPI.y = GetDeviceCaps(hDC, LOGPIXELSY); - ReleaseDC(hwnd, hDC); - } - - curDPI.x = max_u(curDPI.x, USER_DEFAULT_SCREEN_DPI); - curDPI.y = max_u(curDPI.y, USER_DEFAULT_SCREEN_DPI); - return curDPI; -} - - //============================================================================= // // GetCurrentPPI() @@ -392,18 +345,6 @@ if (!bSucceed) { }*/ -//============================================================================= -// -// GetSystemMetricsEx() -// get system metric for current DPI -// https://docs.microsoft.com/de-de/windows/desktop/api/winuser/nf-winuser-getsystemmetricsfordpi -// -int GetSystemMetricsEx(HWND hwnd, int nValue) { - - return ScaleIntToDPI_Y(hwnd, GetSystemMetrics(nValue)); -} - - //============================================================================= // // UpdateWindowLayoutForDPI() @@ -438,7 +379,7 @@ HBITMAP ResizeImageForCurrentDPI(HWND hwnd, HBITMAP hbmp) if (hbmp) { BITMAP bmp; if (GetObject(hbmp, sizeof(BITMAP), &bmp)) { - DPI_T const DPI = GetCurrentDPI(hwnd); + DPI_T const DPI = Scintilla_GetCurrentDPI(hwnd); int const width = MulDiv(bmp.bmWidth, DPI.x, USER_DEFAULT_SCREEN_DPI); int const height = MulDiv(bmp.bmHeight, DPI.y, USER_DEFAULT_SCREEN_DPI); if ((width != bmp.bmWidth) || (height != bmp.bmHeight)) { @@ -497,7 +438,7 @@ bool IsProcessElevated() { // Vista, GetTokenInformation returns FALSE with the // ERROR_INVALID_PARAMETER error code because TokenElevation is // not supported on those operating systems. - if (!IsVistaOrHigher()) { return false; } + if (!IsWindowsVistaOrGreater()) { return false; } bool bIsElevated = false; HANDLE hToken = NULL; diff --git a/src/Helpers.h b/src/Helpers.h index d456a10c9..048614dac 100644 --- a/src/Helpers.h +++ b/src/Helpers.h @@ -24,6 +24,8 @@ #include #include +#include + // ============================================================================ // --- Disable/Enable some CodeAnalysis Warnings --- @@ -178,30 +180,6 @@ inline COLORREF GetBackgroundColor(HWND hwnd) { return GetBkColor(GetDC(hwnd)); // ---------------------------------------------------------------------------- -//#define Is2k() (g_uWinVer >= 0x0500) -#define IsXPOrHigher() IsWindowsXPOrGreater() // Indicates if the current OS version matches,or is greater than,the Windows XP version. -#define IsXP1OrHigher() IsWindowsXPSP1OrGreater() // Indicates if the current OS version matches,or is greater than,the Windows XP with Service Pack 1 (SP1)version. -#define IsXP2OrHigher() IsWindowsXPSP2OrGreater() // Indicates if the current OS version matches,or is greater than,the Windows XP with Service Pack 2 (SP2)version. -#define IsXP3OrHigher() IsWindowsXPSP3OrGreater() // Indicates if the current OS version matches,or is greater than,the Windows XP with Service Pack 3 (SP3)version. - -#define IsVistaOrHigher() IsWindowsVistaOrGreater() // Indicates if the current OS version matches,or is greater than,the Windows Vista version. -#define IsVista1OrHigher() IsWindowsVistaSP1OrGreater() // Indicates if the current OS version matches,or is greater than,the Windows Vista with Service Pack 1 (SP1)version. -#define IsVista2OrHigher() IsWindowsVistaSP2OrGreater() // Indicates if the current OS version matches,or is greater than,the Windows Vista with Service Pack 2 (SP2)version. - -#define IsWin7OrHigher() IsWindows7OrGreater() // Indicates if the current OS version matches,or is greater than,the Windows 7 version. -#define IsWin71OrHigher() IsWindows7SP1OrGreater() // Indicates if the current OS version matches,or is greater than,the Windows 7 with Service Pack 1 (SP1)version. -#define IsWin8OrHigher() IsWindows8OrGreater() // Indicates if the current OS version matches,or is greater than,the Windows 8 version. -#define IsWin81OrHigher() IsWindows8Point1OrGreater() // Indicates if the current OS version matches,or is greater than,the Windows 8.1 version. - // For Windows 10,IsWindows8Point1OrGreater returns false unless the application contains a manifest that includes - // a compatibility section that contains the GUIDs that designate Windows 8.1 and/or Windows 10. - -#define IsWin10OrHigher() IsWindows10OrGreater() // Indicates if the current OS version matches, or is greater than, the Windows 10 version. - // For Windows 10,IsWindows10OrGreater returns false unless the application contains a manifest that includes - // a compatibility section that contains the GUID that designates Windows 10. - -#define IsWinServer() IsWindowsServer() // Indicates if the current OS is a Windows Server release. - // Applications that need to distinguish between server and client versions of Windows should call this function. - void GetWinVersionString(LPWSTR szVersionStr, size_t cchVersionStr); // ---------------------------------------------------------------------------- @@ -218,22 +196,20 @@ void SetUACIcon(const HMENU hMenu, const UINT nItem); // ---------------------------------------------------------------------------- -DPI_T GetCurrentDPI(HWND hwnd); DPI_T GetCurrentPPI(HWND hwnd); void UpdateWindowLayoutForDPI(HWND hWnd, int x_96dpi, int y_96dpi, int w_96dpi, int h_96dpi); HBITMAP ResizeImageForCurrentDPI(HWND hwnd, HBITMAP hbmp); -inline int ScaleIntToDPI_X(HWND hwnd, int val) { DPI_T const dpi = GetCurrentDPI(hwnd); return MulDiv((val), dpi.x, USER_DEFAULT_SCREEN_DPI); } -inline int ScaleIntToDPI_Y(HWND hwnd, int val) { DPI_T const dpi = GetCurrentDPI(hwnd); return MulDiv((val), dpi.y, USER_DEFAULT_SCREEN_DPI); } -inline int ScaleToCurrentDPIX(HWND hwnd, float fVal) { DPI_T const dpi = GetCurrentDPI(hwnd); return float2int((fVal * dpi.x) / (float)USER_DEFAULT_SCREEN_DPI); } -inline int ScaleToCurrentDPIY(HWND hwnd, float fVal) { DPI_T const dpi = GetCurrentDPI(hwnd); return float2int((fVal * dpi.y) / (float)USER_DEFAULT_SCREEN_DPI); } -inline int ScaleIntFontSizeW(HWND hwnd, int val) { DPI_T const dpi = GetCurrentDPI(hwnd); DPI_T const ppi = GetCurrentPPI(hwnd); return MulDiv((val), dpi.x, ppi.x); } -inline int ScaleIntFontSizeH(HWND hwnd, int val) { DPI_T const dpi = GetCurrentDPI(hwnd); DPI_T const ppi = GetCurrentPPI(hwnd); return MulDiv((val), dpi.y, ppi.y); } -inline int ScaleFontSize(HWND hwnd, float fSize) { DPI_T const dpi = GetCurrentDPI(hwnd); DPI_T const ppi = GetCurrentPPI(hwnd); return float2int((fSize * dpi.y) / (float)ppi.y); } -inline int ScaleFractionalFontSize(HWND hwnd, float fSize) { DPI_T const dpi = GetCurrentDPI(hwnd); DPI_T const ppi = GetCurrentPPI(hwnd); return float2int((fSize * 10.0f * dpi.y) / (float)ppi.y) * 10; } +inline int ScaleIntToDPI_X(HWND hwnd, int val) { DPI_T const dpi = Scintilla_GetCurrentDPI(hwnd); return MulDiv((val), dpi.x, USER_DEFAULT_SCREEN_DPI); } +inline int ScaleIntToDPI_Y(HWND hwnd, int val) { DPI_T const dpi = Scintilla_GetCurrentDPI(hwnd); return MulDiv((val), dpi.y, USER_DEFAULT_SCREEN_DPI); } +inline int ScaleToCurrentDPIX(HWND hwnd, float fVal) { DPI_T const dpi = Scintilla_GetCurrentDPI(hwnd); return float2int((fVal * dpi.x) / (float)USER_DEFAULT_SCREEN_DPI); } +inline int ScaleToCurrentDPIY(HWND hwnd, float fVal) { DPI_T const dpi = Scintilla_GetCurrentDPI(hwnd); return float2int((fVal * dpi.y) / (float)USER_DEFAULT_SCREEN_DPI); } +inline int ScaleIntFontSizeW(HWND hwnd, int val) { DPI_T const dpi = Scintilla_GetCurrentDPI(hwnd); DPI_T const ppi = GetCurrentPPI(hwnd); return MulDiv((val), dpi.x, ppi.x); } +inline int ScaleIntFontSizeH(HWND hwnd, int val) { DPI_T const dpi = Scintilla_GetCurrentDPI(hwnd); DPI_T const ppi = GetCurrentPPI(hwnd); return MulDiv((val), dpi.y, ppi.y); } +inline int ScaleFontSize(HWND hwnd, float fSize) { DPI_T const dpi = Scintilla_GetCurrentDPI(hwnd); DPI_T const ppi = GetCurrentPPI(hwnd); return float2int((fSize * dpi.y) / (float)ppi.y); } +inline int ScaleFractionalFontSize(HWND hwnd, float fSize) { DPI_T const dpi = Scintilla_GetCurrentDPI(hwnd); DPI_T const ppi = GetCurrentPPI(hwnd); return float2int((fSize * 10.0f * dpi.y) / (float)ppi.y) * 10; } -int GetSystemMetricsEx(HWND hwnd, int nValue); // ---------------------------------------------------------------------------- diff --git a/src/Notepad3.c b/src/Notepad3.c index 7ac149730..b1c6da249 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -201,10 +201,6 @@ static TBBUTTON s_tbbMainWnd[] = { }; static const int NUMTOOLBITMAPS = 29; -#if _WIN32_WINNT < _WIN32_WINNT_WIN8 -DWORD kSystemLibraryLoadFlags = 0; -#endif - // ---------------------------------------------------------------------------- const WCHAR* const TBBUTTON_DEFAULT_IDS_V1 = L"1 2 4 3 28 0 5 6 0 7 8 9 0 10 11 0 12 0 24 26 0 22 23 0 13 14 0 27 0 15 0 25 0 17"; @@ -661,7 +657,7 @@ static void _InitGlobals() Flags.RelativeFileMRU = DefaultFlags.RelativeFileMRU = true; Flags.PortableMyDocs = DefaultFlags.PortableMyDocs = Flags.RelativeFileMRU; Flags.NoFadeHidden = DefaultFlags.NoFadeHidden = false; - Flags.ToolbarLook = DefaultFlags.ToolbarLook = IsXPOrHigher() ? 1 : 2; + Flags.ToolbarLook = DefaultFlags.ToolbarLook = IsWindowsXPSP3OrGreater() ? 1 : 2; Flags.SimpleIndentGuides = DefaultFlags.SimpleIndentGuides = false; Flags.NoHTMLGuess =DefaultFlags.NoHTMLGuess = false; Flags.NoCGIGuess = DefaultFlags.NoCGIGuess = false; @@ -811,8 +807,8 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX); - // check if running at least on Windows 7 - if (!IsWin7OrHigher()) { + // check if running at least on Windows 7 (SP1) + if (!IsWindows7SP1OrGreater()) { MsgBoxLastError(L"Application Initialization", ERROR_OLD_WIN_VERSION); return 1; // exit } @@ -850,11 +846,6 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, icex.dwICC = ICC_WIN95_CLASSES | ICC_COOL_CLASSES | ICC_BAR_CLASSES | ICC_USEREX_CLASSES; InitCommonControlsEx(&icex); -#if _WIN32_WINNT < _WIN32_WINNT_WIN8 - // see LoadD2D() in PlatWin.cxx - kSystemLibraryLoadFlags = (IsWin8OrHigher() || GetProcAddress(GetModuleHandle(L"kernel32.dll"), "SetDefaultDllDirectories")) ? LOAD_LIBRARY_SEARCH_SYSTEM32 : 0; -#endif - Scintilla_RegisterClasses(hInstance); //SetProcessDPIAware(); -> .manifest @@ -1750,7 +1741,7 @@ static void _SetWrapVisualFlags(HWND hwndEditCtrl) // static void _InitializeSciEditCtrl(HWND hwndEditCtrl) { - if (IsVistaOrHigher()) { + if (IsWindowsVistaOrGreater()) { // Current platforms perform window buffering so it is almost always better for this option to be turned off. // There are some older platforms and unusual modes where buffering may still be useful - so keep it ON //~SciCall_SetBufferedDraw(true); // default is true @@ -1988,7 +1979,7 @@ LRESULT MsgCreate(HWND hwnd, WPARAM wParam,LPARAM lParam) SetWindowLongPtr(Globals.hwndEdit,GWL_EXSTYLE,GetWindowLongPtr(Globals.hwndEdit,GWL_EXSTYLE) & ~WS_EX_CLIENTEDGE); SetWindowPos(Globals.hwndEdit,NULL,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_FRAMECHANGED); - if (IsVistaOrHigher()) { + if (IsWindowsVistaOrGreater()) { s_cxEditFrame = 0; s_cyEditFrame = 0; } @@ -2184,7 +2175,7 @@ static HIMAGELIST CreateScaledImageListFromBitmap(HWND hWnd, HBITMAP hBmp) HIMAGELIST himl = ImageList_Create(cx, cy, ILC_COLOR32 | ILC_MASK, NUMTOOLBITMAPS, NUMTOOLBITMAPS); ImageList_AddMasked(himl, hBmp, CLR_DEFAULT); - DPI_T dpi = GetCurrentDPI(hWnd); + DPI_T dpi = Scintilla_GetCurrentDPI(hWnd); if (!Settings.DpiScaleToolBar || ((dpi.x == USER_DEFAULT_SCREEN_DPI) && (dpi.y == USER_DEFAULT_SCREEN_DPI))) { @@ -2335,10 +2326,10 @@ void CreateBars(HWND hwnd, HINSTANCE hInstance) if (Flags.ToolbarLook == 1) { bProcessed = BitmapAlphaBlend(hbmpCopy, GetSysColor(COLOR_3DFACE), 0x60); } - else if (Flags.ToolbarLook == 2 || (!IsXPOrHigher() && Flags.ToolbarLook == 0)) { + else if (Flags.ToolbarLook == 2 || (!IsWindowsXPSP3OrGreater() && Flags.ToolbarLook == 0)) { bProcessed = BitmapGrayScale(hbmpCopy); } - if (bProcessed && !IsXPOrHigher()) { + if (bProcessed && !IsWindowsXPSP3OrGreater()) { BitmapMergeAlpha(hbmpCopy, GetSysColor(COLOR_3DFACE)); } if (bProcessed) @@ -2554,7 +2545,7 @@ LRESULT MsgThemeChanged(HWND hwnd, WPARAM wParam ,LPARAM lParam) SetWindowLongPtr(Globals.hwndEdit,GWL_EXSTYLE,GetWindowLongPtr(Globals.hwndEdit,GWL_EXSTYLE) & ~WS_EX_CLIENTEDGE); SetWindowPos(Globals.hwndEdit,NULL,0,0,0,0,SWP_NOZORDER|SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE); - if (IsVistaOrHigher()) { + if (IsWindowsVistaOrGreater()) { s_cxEditFrame = 0; s_cyEditFrame = 0; } @@ -10384,7 +10375,7 @@ bool RelaunchMultiInst() { // bool RelaunchElevated(LPWSTR lpNewCmdLnArgs) { - if (!IsVistaOrHigher() || !Flags.bDoRelaunchElevated || + if (!IsWindowsVistaOrGreater() || !Flags.bDoRelaunchElevated || s_bIsProcessElevated || s_IsThisAnElevatedRelaunch || s_bIsRunAsAdmin || s_flagDisplayHelp) { diff --git a/src/Styles.c b/src/Styles.c index d8705c4b7..cedc546f2 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -3094,7 +3094,7 @@ bool Style_SelectFont(HWND hwnd,LPWSTR lpszStyle,int cchStyle, LPCWSTR sLexerNam // --- open systems Font Selection dialog --- if (Settings.RenderingTechnology > 0) { - DPI_T const dpi = GetCurrentDPI(hwnd); + DPI_T const dpi = Scintilla_GetCurrentDPI(hwnd); if (!ChooseFontDirectWrite(Globals.hwndMain, Settings2.PreferredLanguageLocaleName, dpi, &cf) || (lf.lfFaceName[0] == L'\0')) { return false; @@ -4452,7 +4452,7 @@ INT_PTR CALLBACK Style_SelectLexerDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPAR SetWindowLongPtr(GetDlgItem(hwnd,IDC_RESIZEGRIP),GWL_STYLE, GetWindowLongPtr(GetDlgItem(hwnd,IDC_RESIZEGRIP),GWL_STYLE)|SBS_SIZEGRIP|WS_CLIPSIBLINGS); - int cGrip = GetSystemMetricsEx(hwnd, SM_CXHTHUMB); + int cGrip = Scintilla_GetSystemMetricsEx(hwnd, SM_CXHTHUMB); SetWindowPos(GetDlgItem(hwnd,IDC_RESIZEGRIP),NULL,cxClient-cGrip, cyClient-cGrip,cGrip,cGrip,SWP_NOZORDER); diff --git a/src/TypeDefs.h b/src/TypeDefs.h index ebadb29bc..3dd3b718f 100644 --- a/src/TypeDefs.h +++ b/src/TypeDefs.h @@ -72,12 +72,6 @@ typedef DocPos DocLn; // Sci::Line //typedef intptr_t cpi_enc_t; typedef int cpi_enc_t; -typedef struct _dpi_t -{ - UINT x; - UINT y; -} DPI_T; - typedef struct _wi { int x;