vcl/win/window/salframe.cxx | 181 ++++++++++++++++++++++---------------------- 1 file changed, 93 insertions(+), 88 deletions(-)
New commits: commit 1759fb1f50015a4ce4f8b9843891e71a615b5a2e Author: Jan-Marek Glogowski <glo...@fbihome.de> AuthorDate: Mon Jun 13 18:57:11 2022 +0200 Commit: Jan-Marek Glogowski <glo...@fbihome.de> CommitDate: Sat Jun 25 18:46:57 2022 +0200 WIN flatten and assert some code Thanks to Mike Kaganski to come up with the correct asserts. Change-Id: I01b2b0026fc4de67a14fa803357a4c28951088ec Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135810 Tested-by: Jenkins Reviewed-by: Jan-Marek Glogowski <glo...@fbihome.de> diff --git a/vcl/win/window/salframe.cxx b/vcl/win/window/salframe.cxx index 9306d35d77fe..b419a259c450 100644 --- a/vcl/win/window/salframe.cxx +++ b/vcl/win/window/salframe.cxx @@ -44,7 +44,7 @@ #include <sal/log.hxx> #include <osl/module.h> - +#include <comphelper/scopeguard.hxx> #include <tools/debug.hxx> #include <o3tl/enumarray.hxx> #include <o3tl/char16_t2wchar_t.hxx> @@ -3959,18 +3959,6 @@ static void UpdateFrameGeometry(WinSalFrame* pFrame) pFrame->updateScreenNumber(); } -static void ImplCallMoveHdl( HWND hWnd ) -{ - WinSalFrame* pFrame = GetWindowPtr( hWnd ); - if ( pFrame ) - { - pFrame->CallCallback( SalEvent::Move, nullptr ); - // to avoid doing Paint twice by VCL and SAL - //if ( IsWindowVisible( hWnd ) && !pFrame->mbInShow ) - // UpdateWindow( hWnd ); - } -} - static void ImplCallClosePopupsHdl( HWND hWnd ) { WinSalFrame* pFrame = GetWindowPtr( hWnd ); @@ -3980,40 +3968,51 @@ static void ImplCallClosePopupsHdl( HWND hWnd ) } } -static void ImplHandleMoveMsg( HWND hWnd ) +static void ImplCallMoveHdl(HWND hWnd) { - WinSalFrame* pFrame = ProcessOrDeferMessage( hWnd, SAL_MSG_POSTMOVE ); - if ( pFrame ) - { - UpdateFrameGeometry(pFrame); + WinSalFrame* pFrame = ProcessOrDeferMessage(hWnd, SAL_MSG_POSTMOVE); + if (!pFrame) + return; - if ( GetWindowStyle( hWnd ) & WS_VISIBLE ) - pFrame->mbDefPos = false; + pFrame->CallCallback(SalEvent::Move, nullptr); - // protect against recursion - if ( !pFrame->mbInMoveMsg ) - { - // adjust window again for FullScreenMode - pFrame->mbInMoveMsg = true; - if (pFrame->isFullScreen()) - ImplSalFrameFullScreenPos( pFrame ); - pFrame->mbInMoveMsg = false; - } + ImplSalYieldMutexRelease(); +} - pFrame->UpdateFrameState(); +static void ImplHandleMoveMsg(HWND hWnd, LPARAM lParam) +{ + WinSalFrame* pFrame = GetWindowPtr( hWnd ); + if (!pFrame) + return; - // Call Hdl - //#93851 if we call this handler, VCL floating windows are not updated correctly - ImplCallMoveHdl( hWnd ); + UpdateFrameGeometry(pFrame); - ImplSalYieldMutexRelease(); +#ifdef NDEBUG + (void) lParam; +#endif + assert(IsIconic(hWnd) || (pFrame->maGeometry.x() == static_cast<sal_Int16>(LOWORD(lParam)))); + assert(IsIconic(hWnd) || (pFrame->maGeometry.y() == static_cast<sal_Int16>(HIWORD(lParam)))); + + if (GetWindowStyle(hWnd) & WS_VISIBLE) + pFrame->mbDefPos = false; + + // protect against recursion + if (!pFrame->mbInMoveMsg) + { + // adjust window again for FullScreenMode + pFrame->mbInMoveMsg = true; + if (pFrame->isFullScreen()) + ImplSalFrameFullScreenPos(pFrame); + pFrame->mbInMoveMsg = false; } + + pFrame->UpdateFrameState(); + + ImplCallMoveHdl(hWnd); } static void ImplCallSizeHdl( HWND hWnd ) { - // as Windows can send these messages also, we have to use - // the Solar semaphore WinSalFrame* pFrame = ProcessOrDeferMessage( hWnd, SAL_MSG_POSTCALLSIZE ); if (!pFrame) return; @@ -4026,7 +4025,7 @@ static void ImplCallSizeHdl( HWND hWnd ) ImplSalYieldMutexRelease(); } -static void ImplHandleSizeMsg(HWND hWnd, WPARAM wParam, LPARAM) +static void ImplHandleSizeMsg(HWND hWnd, WPARAM wParam, LPARAM lParam) { if ((wParam == SIZE_MAXSHOW) || (wParam == SIZE_MAXHIDE)) return; @@ -4036,7 +4035,15 @@ static void ImplHandleSizeMsg(HWND hWnd, WPARAM wParam, LPARAM) return; UpdateFrameGeometry(pFrame); + +#ifdef NDEBUG + (void) lParam; +#endif + assert(pFrame->maGeometry.width() == static_cast<sal_Int16>(LOWORD(lParam))); + assert(pFrame->maGeometry.height() == static_cast<sal_Int16>(HIWORD(lParam))); + pFrame->UpdateFrameState(); + ImplCallSizeHdl(hWnd); WinSalTimer* pTimer = static_cast<WinSalTimer*>(ImplGetSVData()->maSchedCtx.mpSalTimer); @@ -4047,30 +4054,30 @@ static void ImplHandleSizeMsg(HWND hWnd, WPARAM wParam, LPARAM) static void ImplHandleFocusMsg( HWND hWnd ) { WinSalFrame* pFrame = ProcessOrDeferMessage( hWnd, SAL_MSG_POSTFOCUS ); - if ( pFrame ) - { - if ( !WinSalFrame::mbInReparent ) - { - bool bGotFocus = ::GetFocus() == hWnd; - if ( bGotFocus ) - { - if ( IsWindowVisible( hWnd ) && !pFrame->mbInShow ) - UpdateWindow( hWnd ); + if (!pFrame) + return; + const ::comphelper::ScopeGuard aScopeGuard([](){ ImplSalYieldMutexRelease(); }); - // do we support IME? - if ( pFrame->mbIME && pFrame->mhDefIMEContext ) - { - UINT nImeProps = ImmGetProperty( GetKeyboardLayout( 0 ), IGP_PROPERTY ); + if (WinSalFrame::mbInReparent) + return; - pFrame->mbSpezIME = (nImeProps & IME_PROP_SPECIAL_UI) != 0; - pFrame->mbAtCursorIME = (nImeProps & IME_PROP_AT_CARET) != 0; - pFrame->mbHandleIME = !pFrame->mbSpezIME; - } - } - pFrame->CallCallback( bGotFocus ? SalEvent::GetFocus : SalEvent::LoseFocus, nullptr ); + const bool bGotFocus = ::GetFocus() == hWnd; + if (bGotFocus) + { + if (IsWindowVisible(hWnd) && !pFrame->mbInShow) + UpdateWindow(hWnd); + + // do we support IME? + if (pFrame->mbIME && pFrame->mhDefIMEContext) + { + UINT nImeProps = ImmGetProperty(GetKeyboardLayout(0), IGP_PROPERTY); + pFrame->mbSpezIME = (nImeProps & IME_PROP_SPECIAL_UI) != 0; + pFrame->mbAtCursorIME = (nImeProps & IME_PROP_AT_CARET) != 0; + pFrame->mbHandleIME = !pFrame->mbSpezIME; } - ImplSalYieldMutexRelease(); } + + pFrame->CallCallback(bGotFocus ? SalEvent::GetFocus : SalEvent::LoseFocus, nullptr); } static void ImplHandleCloseMsg( HWND hWnd ) @@ -4129,17 +4136,15 @@ static void ImplHandleSettingsChangeMsg( HWND hWnd, UINT nMsg, ImplUpdateSysColorEntries(); WinSalFrame* pFrame = ProcessOrDeferMessage( hWnd, 0, 0, DeferPolicy::Blocked ); - if ( pFrame ) - { - if ( (nMsg == WM_DISPLAYCHANGE) || (nMsg == WM_WININICHANGE) ) - { - if (pFrame->isFullScreen()) - ImplSalFrameFullScreenPos( pFrame ); - } + if (!pFrame) + return; - pFrame->CallCallback( nSalEvent, nullptr ); - ImplSalYieldMutexRelease(); - } + if (((nMsg == WM_DISPLAYCHANGE) || (nMsg == WM_WININICHANGE)) && pFrame->isFullScreen()) + ImplSalFrameFullScreenPos(pFrame); + + pFrame->CallCallback(nSalEvent, nullptr); + + ImplSalYieldMutexRelease(); } static void ImplHandleUserEvent( HWND hWnd, LPARAM lParam ) @@ -4156,25 +4161,22 @@ static void ImplHandleForcePalette( HWND hWnd ) { SalData* pSalData = GetSalData(); HPALETTE hPal = pSalData->mhDitherPal; - if ( hPal ) - { - WinSalFrame* pFrame = ProcessOrDeferMessage( hWnd, SAL_MSG_FORCEPALETTE ); - if ( pFrame && pFrame->mpLocalGraphics && pFrame->mpLocalGraphics->getHDC() ) - { - WinSalGraphics* pGraphics = pFrame->mpLocalGraphics; - if (pGraphics->getDefPal()) - { - if (pGraphics->setPalette(hPal, FALSE) != GDI_ERROR) - { - InvalidateRect( hWnd, nullptr, FALSE ); - UpdateWindow( hWnd ); - pFrame->CallCallback( SalEvent::DisplayChanged, nullptr ); - } - } - } - if ( pFrame ) - ImplSalYieldMutexRelease(); - } + if (!hPal) + return; + + WinSalFrame* pFrame = ProcessOrDeferMessage(hWnd, SAL_MSG_FORCEPALETTE); + if (!pFrame) + return; + const ::comphelper::ScopeGuard aScopeGuard([](){ ImplSalYieldMutexRelease(); }); + + WinSalGraphics* pGraphics = pFrame->mpLocalGraphics; + if (!pGraphics || !pGraphics->getHDC() || !pGraphics->getDefPal() + || (pGraphics->setPalette(hPal, FALSE) == GDI_ERROR)) + return; + + InvalidateRect(hWnd, nullptr, FALSE); + UpdateWindow(hWnd); + pFrame->CallCallback(SalEvent::DisplayChanged, nullptr); } static LRESULT ImplHandlePalette( bool bFrame, HWND hWnd, UINT nMsg, @@ -5653,12 +5655,15 @@ static LRESULT CALLBACK SalFrameWndProc( HWND hWnd, UINT nMsg, WPARAM wParam, LP break; case WM_MOVE: + ImplHandleMoveMsg(hWnd, lParam); + rDef = false; + break; case SAL_MSG_POSTMOVE: - ImplHandleMoveMsg( hWnd ); + ImplCallMoveHdl(hWnd); rDef = false; break; case WM_SIZE: - ImplHandleSizeMsg( hWnd, wParam, lParam ); + ImplHandleSizeMsg(hWnd, wParam, lParam); rDef = false; break; case SAL_MSG_POSTCALLSIZE: