diff options
author | Neil <nyamatongwe@gmail.com> | 2025-03-19 12:16:41 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2025-03-19 12:16:41 +1100 |
commit | ef7a5121743a207b5f0629614b486c431bb55af6 (patch) | |
tree | be37a96172df6994479abc79a161d8fb355ff4d7 /win32 | |
parent | 11679dfe30db5890a183bebe4e2e974c69aad116 (diff) | |
download | scintilla-mirror-ef7a5121743a207b5f0629614b486c431bb55af6.tar.gz |
Encapsulate WM_PAINT handling.
Diffstat (limited to 'win32')
-rw-r--r-- | win32/PlatWin.cxx | 4 | ||||
-rw-r--r-- | win32/PlatWin.h | 12 | ||||
-rw-r--r-- | win32/ScintillaWin.cxx | 24 |
3 files changed, 23 insertions, 17 deletions
diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index 3d34b2d95..9cd792e09 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -4041,9 +4041,7 @@ LRESULT ListBoxX::WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam break; case WM_PAINT: { - PAINTSTRUCT ps; - ::BeginPaint(hWnd, &ps); - ::EndPaint(hWnd, &ps); + Painter painter(hWnd); } break; diff --git a/win32/PlatWin.h b/win32/PlatWin.h index 6c51ec8ad..de99a5fc0 100644 --- a/win32/PlatWin.h +++ b/win32/PlatWin.h @@ -60,6 +60,18 @@ int SystemMetricsForDpi(int nIndex, UINT dpi) noexcept; HCURSOR LoadReverseArrowCursor(UINT dpi) noexcept; +// Encapsulate WM_PAINT handling so that EndPaint is always called even with unexpected returns or exceptions. +struct Painter { + HWND hWnd{}; + PAINTSTRUCT ps{}; + explicit Painter(HWND hWnd_) noexcept : hWnd(hWnd_) { + ::BeginPaint(hWnd, &ps); + } + ~Painter() { + ::EndPaint(hWnd, &ps); + } +}; + class MouseWheelDelta { int wheelDelta = 0; public: diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index 4ce8aad0c..d5ce9b433 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -1271,25 +1271,24 @@ sptr_t ScintillaWin::WndPaint() { // Redirect assertions to debug output and save current state const bool assertsPopup = Platform::ShowAssertionPopUps(false); paintState = PaintState::painting; - PAINTSTRUCT ps = {}; // Removed since this interferes with reporting other assertions as it occurs repeatedly //PLATFORM_ASSERT(hRgnUpdate == NULL); hRgnUpdate = ::CreateRectRgn(0, 0, 0, 0); ::GetUpdateRgn(MainHWND(), hRgnUpdate, FALSE); - ::BeginPaint(MainHWND(), &ps); - rcPaint = PRectangleFromRECT(ps.rcPaint); - const PRectangle rcClient = GetClientRectangle(); - paintingAllText = BoundsContains(rcPaint, hRgnUpdate, rcClient); - if (!PaintDC(ps.hdc)) { - paintState = PaintState::abandoned; + { + Painter painter(MainHWND()); + rcPaint = PRectangleFromRECT(painter.ps.rcPaint); + const PRectangle rcClient = GetClientRectangle(); + paintingAllText = BoundsContains(rcPaint, hRgnUpdate, rcClient); + if (!PaintDC(painter.ps.hdc)) { + paintState = PaintState::abandoned; + } } if (hRgnUpdate) { ::DeleteRgn(hRgnUpdate); hRgnUpdate = {}; } - - ::EndPaint(MainHWND(), &ps); if (paintState == PaintState::abandoned) { // Painting area was insufficient to cover new styling or brace highlight positions FullPaint(); @@ -3927,15 +3926,14 @@ LRESULT PASCAL ScintillaWin::CTWndProc( SetWindowPointer(hWnd, nullptr); return ::DefWindowProc(hWnd, iMessage, wParam, lParam); } else if (iMessage == WM_PAINT) { - PAINTSTRUCT ps; - ::BeginPaint(hWnd, &ps); + Painter painter(hWnd); std::unique_ptr<Surface> surfaceWindow(Surface::Allocate(sciThis->technology)); #if defined(USE_D2D) HwndRenderTarget pCTRenderTarget; #endif const RECT rc = GetClientRect(hWnd); if (sciThis->technology == Technology::Default) { - surfaceWindow->Init(ps.hdc, hWnd); + surfaceWindow->Init(painter.ps.hdc, hWnd); } else { #if defined(USE_D2D) const int scaleFactor = sciThis->GetFirstIntegralMultipleDeviceScaleFactor(); @@ -3959,7 +3957,6 @@ LRESULT PASCAL ScintillaWin::CTWndProc( const HRESULT hr = CreateHwndRenderTarget(&drtp, &dhrtp, pCTRenderTarget); if (!SUCCEEDED(hr)) { surfaceWindow->Release(); - ::EndPaint(hWnd, &ps); return 0; } // If above SUCCEEDED, then pCTRenderTarget not nullptr @@ -3978,7 +3975,6 @@ LRESULT PASCAL ScintillaWin::CTWndProc( pCTRenderTarget->EndDraw(); #endif surfaceWindow->Release(); - ::EndPaint(hWnd, &ps); return 0; } else if ((iMessage == WM_NCLBUTTONDOWN) || (iMessage == WM_NCLBUTTONDBLCLK)) { POINT pt = POINTFromLParam(lParam); |