diff options
| author | Neil <nyamatongwe@gmail.com> | 2025-12-04 20:27:53 +1100 |
|---|---|---|
| committer | Neil <nyamatongwe@gmail.com> | 2025-12-04 20:27:53 +1100 |
| commit | 7ad8458f1bd5a6460bf320096219c494d5bab69b (patch) | |
| tree | 48e7081de02582fffc4cbe1f6212ed557c6a70c4 | |
| parent | 3370ea39fa730ec22e4a2f5496729543c96cc98b (diff) | |
| download | scintilla-mirror-7ad8458f1bd5a6460bf320096219c494d5bab69b.tar.gz | |
Replace 'magic' literals with named constants.
| -rw-r--r-- | win32/PlatWin.cxx | 24 | ||||
| -rw-r--r-- | win32/ScintillaWin.cxx | 12 |
2 files changed, 22 insertions, 14 deletions
diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index ff47c28ab..01b41f5cc 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -628,13 +628,14 @@ HCURSOR LoadReverseArrowCursor(UINT dpi) noexcept { COLORREF strokeColour = RGB(0, 0, 1); status = ::RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Accessibility", 0, KEY_QUERY_VALUE, &hKey); if (status == ERROR_SUCCESS) { + constexpr DWORD customColour = 6; if (std::optional<DWORD> cursorType = RegGetDWORD(hKey, L"CursorType")) { switch (*cursorType) { case 1: // black case 4: // black std::swap(fillColour, strokeColour); break; - case 6: // custom + case customColour: // custom if (std::optional<DWORD> cursorColor = RegGetDWORD(hKey, L"CursorColor")) { fillColour = *cursorColor; } @@ -696,6 +697,15 @@ void Menu::Show(Point pt, const Window &w) { Destroy(); } +namespace { + +bool assertionPopUps = true; + +constexpr int defaultFontSize = 8; +constexpr size_t lengthDiagnostic = 2000; + +} + ColourRGBA ColourFromSys(int nIndex) noexcept { const DWORD colourValue = ::GetSysColor(nIndex); return ColourRGBA::FromRGB(colourValue); @@ -714,7 +724,7 @@ const char *Platform::DefaultFont() { } int Platform::DefaultFontSize() { - return 8; + return defaultFontSize; } unsigned int Platform::DoubleClickTime() { @@ -729,7 +739,7 @@ void Platform::DebugDisplay(const char *s) noexcept { #ifdef TRACE void Platform::DebugPrintf(const char *format, ...) noexcept { - char buffer[2000]; + char buffer[lengthDiagnostic]; va_list pArguments; va_start(pArguments, format); vsnprintf(buffer, std::size(buffer), format, pArguments); @@ -741,12 +751,6 @@ void Platform::DebugPrintf(const char *, ...) noexcept { } #endif -namespace { - -bool assertionPopUps = true; - -} - bool Platform::ShowAssertionPopUps(bool assertionPopUps_) noexcept { const bool ret = assertionPopUps; assertionPopUps = assertionPopUps_; @@ -754,7 +758,7 @@ bool Platform::ShowAssertionPopUps(bool assertionPopUps_) noexcept { } void Platform::Assert(const char *c, const char *file, int line) noexcept { - char buffer[2000] {}; + char buffer[lengthDiagnostic] {}; snprintf(buffer, std::size(buffer), "Assertion [%s] failed at %s %d%s", c, file, line, assertionPopUps ? "" : "\r\n"); if (assertionPopUps) { const int idButton = ::MessageBoxA({}, buffer, "Assertion failure", diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index 5f3258a5f..8f79ef011 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -152,7 +152,7 @@ constexpr Point PointFromLParam(sptr_t lpoint) noexcept { } bool KeyboardIsKeyDown(int key) noexcept { - return (::GetKeyState(key) & 0x80000000) != 0; + return ::GetKeyState(key) < 0; } // Bit 24 is the extended keyboard flag and the numeric keypad is non-extended @@ -406,7 +406,8 @@ CLIPFORMAT RegisterClipboardType(LPCWSTR lpszFormat) noexcept { // Registered clipboard format values are 0xC000 through 0xFFFF. // RegisterClipboardFormatW returns 32-bit unsigned and CLIPFORMAT is 16-bit // unsigned so choose the low 16-bits with &. - return ::RegisterClipboardFormatW(lpszFormat) & 0xFFFF; + constexpr CLIPFORMAT LowBits = 0xFFFF; + return ::RegisterClipboardFormatW(lpszFormat) & LowBits; } RECT GetClientRect(HWND hwnd) noexcept { @@ -856,7 +857,9 @@ bool ScintillaWin::UpdateRenderingParams(bool force) noexcept { UINT clearTypeContrast = 0; if (SUCCEEDED(hr) && monitorRenderingParams && ::SystemParametersInfo(SPI_GETFONTSMOOTHINGCONTRAST, 0, &clearTypeContrast, 0) != 0) { - if (clearTypeContrast >= 1000 && clearTypeContrast <= 2200) { + constexpr UINT minContrast = 1000; + constexpr UINT maxContrast = 2200; + if (clearTypeContrast >= minContrast && clearTypeContrast <= maxContrast) { const FLOAT gamma = static_cast<FLOAT>(clearTypeContrast) / 1000.0f; pIDWriteFactory->CreateCustomRenderingParams(gamma, monitorRenderingParams->GetEnhancedContrast(), @@ -1112,7 +1115,8 @@ namespace { int InputCodePage() noexcept { HKL inputLocale = ::GetKeyboardLayout(0); const LANGID inputLang = LOWORD(inputLocale); - char sCodePage[10]; + constexpr size_t lengthCodePage = 10; + char sCodePage[lengthCodePage]; const int res = ::GetLocaleInfoA(MAKELCID(inputLang, SORT_DEFAULT), LOCALE_IDEFAULTANSICODEPAGE, sCodePage, sizeof(sCodePage)); if (!res) |
