summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2016-10-29 12:00:08 +0200
committerJan-Marek Glogowski <glogow@fbihome.de>2017-07-13 12:10:25 +0200
commit46c33bf281f7288c8c48ca7e1a2b7c4ad32123a8 (patch)
tree59428c48a7300c3923332dea6a6a877529f782ed /vcl
parent51cc064661417134eb4e9c74d2d38d4e1b4e8e0e (diff)
WIN unify deferred message handling
Moves the common code into ProcessOrDeferMessage. All callers (try to) aquire the mutex before getting the WinSalFrame pointer, except for ImplHandleDeferredPaintMsg. This was probably an oversight, so this reverses the order in this function, so the GetWindowPtr is now always protected by the Solar mutex. Change-Id: Icb8f34f7e8716f0faa90a95903b1681f7489aed2
Diffstat (limited to 'vcl')
-rw-r--r--vcl/win/window/salframe.cxx187
1 files changed, 87 insertions, 100 deletions
diff --git a/vcl/win/window/salframe.cxx b/vcl/win/window/salframe.cxx
index f7b2afebc7fe..cee3ef1b48de 100644
--- a/vcl/win/window/salframe.cxx
+++ b/vcl/win/window/salframe.cxx
@@ -3692,47 +3692,82 @@ long ImplHandleSalObjSysCharMsg( HWND hWnd, WPARAM wParam, LPARAM lParam )
return nRet;
}
-enum class PostPaint
+enum class DeferPolicy
{
- IsPosted,
- IsInitial
+ Blocked,
+ Allowed
};
-static bool ImplHandlePostPaintMsg( HWND hWnd, RECT* pRect,
- PostPaint eProcessed = PostPaint::IsPosted )
+// Remember to release the solar mutex on success!
+static inline WinSalFrame* ProcessOrDeferMessage( HWND hWnd, INT nMsg, WPARAM pWParam = 0,
+ DeferPolicy eCanDefer = DeferPolicy::Allowed )
{
- bool bGotMutex = false;
+ bool bFailedCondition = FALSE, bGotMutex = FALSE;
+ WinSalFrame* pFrame = nullptr;
- WinSalFrame* pFrame = GetWindowPtr( hWnd );
- if ( pFrame )
+ if ( DeferPolicy::Blocked == eCanDefer )
+ assert( (DeferPolicy::Blocked == eCanDefer) && (nMsg == 0) && (pWParam == 0) );
+ else
+ assert( (DeferPolicy::Allowed == eCanDefer) && (nMsg != 0) );
+
+ if ( DeferPolicy::Blocked == eCanDefer )
{
- if ( ImplSalYieldMutexTryToAcquire() )
- bGotMutex = true;
+ ImplSalYieldMutexAcquireWithWait();
+ bGotMutex = TRUE;
+ }
+ else if ( !(bGotMutex = ImplSalYieldMutexTryToAcquire()) )
+ bFailedCondition = TRUE;
+
+ if ( !bFailedCondition )
+ {
+ pFrame = GetWindowPtr( hWnd );
+ bFailedCondition = pFrame == nullptr;
+ }
+ if ( bFailedCondition )
+ {
if ( bGotMutex )
- {
- SalPaintEvent aPEvt( pRect->left, pRect->top, pRect->right-pRect->left, pRect->bottom-pRect->top );
- pFrame->CallCallback( SalEvent::Paint, &aPEvt );
ImplSalYieldMutexRelease();
- if ( PostPaint::IsPosted == eProcessed )
- delete pRect;
- }
- else
+ if ( DeferPolicy::Allowed == eCanDefer )
{
- RECT* pMsgRect;
- if ( PostPaint::IsInitial == eProcessed )
- {
- pMsgRect = new RECT;
- CopyRect( pMsgRect, pRect );
- }
- else
- pMsgRect = pRect;
- BOOL const ret = PostMessageW(hWnd, SAL_MSG_POSTPAINT, reinterpret_cast<WPARAM>(pMsgRect), 0);
+ BOOL const ret = PostMessageW(hWnd, nMsg, pWParam, 0);
SAL_WARN_IF(0 == ret, "vcl", "ERROR: PostMessage() failed!");
}
}
- return bGotMutex;
+ return pFrame;
+}
+
+enum class PostedState
+{
+ IsPosted,
+ IsInitial
+};
+
+static bool ImplHandlePostPaintMsg( HWND hWnd, RECT* pRect,
+ PostedState eProcessed = PostedState::IsPosted )
+{
+ RECT* pMsgRect;
+ if ( PostedState::IsInitial == eProcessed )
+ {
+ pMsgRect = new RECT;
+ CopyRect( pMsgRect, pRect );
+ }
+ else
+ pMsgRect = pRect;
+
+ WinSalFrame* pFrame = ProcessOrDeferMessage( hWnd, SAL_MSG_POSTPAINT,
+ reinterpret_cast<WPARAM>(pMsgRect) );
+ if ( pFrame )
+ {
+ SalPaintEvent aPEvt( pRect->left, pRect->top, pRect->right-pRect->left, pRect->bottom-pRect->top );
+ pFrame->CallCallback( SalEvent::Paint, &aPEvt );
+ ImplSalYieldMutexRelease();
+ if ( PostedState::IsPosted == eProcessed )
+ delete pRect;
+ }
+
+ return (pFrame != nullptr);
}
static bool ImplHandlePaintMsg( HWND hWnd )
@@ -3773,8 +3808,8 @@ static bool ImplHandlePaintMsg( HWND hWnd )
// try painting
if ( bHasPaintRegion )
{
- bPaintSuccessful = ImplHandlePostPaintMsg( hWnd, &aUpdateRect,
- PostPaint::IsInitial );
+ bPaintSuccessful = ImplHandlePostPaintMsg(
+ hWnd, &aUpdateRect, PostedState::IsInitial );
EndPaint( hWnd, &aPs );
}
else // if there is nothing to paint, the paint is successful
@@ -3891,9 +3926,7 @@ static void ImplCallClosePopupsHdl( HWND hWnd )
static void ImplHandleMoveMsg( HWND hWnd )
{
- if ( ImplSalYieldMutexTryToAcquire() )
- {
- WinSalFrame* pFrame = GetWindowPtr( hWnd );
+ WinSalFrame* pFrame = ProcessOrDeferMessage( hWnd, SAL_MSG_POSTMOVE );
if ( pFrame )
{
UpdateFrameGeometry( hWnd, pFrame );
@@ -3918,39 +3951,24 @@ static void ImplHandleMoveMsg( HWND hWnd )
//#93851 if we call this handler, VCL floating windows are not updated correctly
ImplCallMoveHdl( hWnd );
+ ImplSalYieldMutexRelease();
}
-
- ImplSalYieldMutexRelease();
- }
- else
- {
- BOOL const ret = PostMessageW( hWnd, SAL_MSG_POSTMOVE, 0, 0 );
- SAL_WARN_IF(0 == ret, "vcl", "ERROR: PostMessage() failed!");
- }
}
static void ImplCallSizeHdl( HWND hWnd )
{
// as Windows can send these messages also, we have to use
// the Solar semaphore
- if ( ImplSalYieldMutexTryToAcquire() )
- {
- WinSalFrame* pFrame = GetWindowPtr( hWnd );
+ WinSalFrame* pFrame = ProcessOrDeferMessage( hWnd, SAL_MSG_POSTCALLSIZE );
if ( pFrame )
{
pFrame->CallCallback( SalEvent::Resize, nullptr );
// to avoid double Paints by VCL and SAL
if ( IsWindowVisible( hWnd ) && !pFrame->mbInShow )
UpdateWindow( hWnd );
- }
- ImplSalYieldMutexRelease();
- }
- else
- {
- BOOL const ret = PostMessageW( hWnd, SAL_MSG_POSTCALLSIZE, 0, 0 );
- SAL_WARN_IF(0 == ret, "vcl", "ERROR: PostMessage() failed!");
- }
+ ImplSalYieldMutexRelease();
+ }
}
static void ImplHandleSizeMsg( HWND hWnd, WPARAM wParam, LPARAM lParam )
@@ -3974,12 +3992,13 @@ static void ImplHandleSizeMsg( HWND hWnd, WPARAM wParam, LPARAM lParam )
static void ImplHandleFocusMsg( HWND hWnd )
{
- if ( ImplSalYieldMutexTryToAcquire() )
+ WinSalFrame* pFrame = ProcessOrDeferMessage( hWnd, SAL_MSG_POSTFOCUS );
+ if ( pFrame )
{
- WinSalFrame* pFrame = GetWindowPtr( hWnd );
- if ( pFrame && !WinSalFrame::mbInReparent )
+ if ( !WinSalFrame::mbInReparent )
{
- if ( ::GetFocus() == hWnd )
+ bool bGotFocus = ::GetFocus() == hWnd;
+ if ( bGotFocus )
{
if ( IsWindowVisible( hWnd ) && !pFrame->mbInShow )
UpdateWindow( hWnd );
@@ -3993,53 +4012,32 @@ static void ImplHandleFocusMsg( HWND hWnd )
pFrame->mbAtCursorIME = (nImeProps & IME_PROP_AT_CARET) != 0;
pFrame->mbHandleIME = !pFrame->mbSpezIME;
}
-
- pFrame->CallCallback( SalEvent::GetFocus, nullptr );
- }
- else
- {
- pFrame->CallCallback( SalEvent::LoseFocus, nullptr );
}
+ pFrame->CallCallback( bGotFocus ? SalEvent::GetFocus : SalEvent::LoseFocus, nullptr );
}
-
ImplSalYieldMutexRelease();
}
- else
- {
- BOOL const ret = PostMessageW( hWnd, SAL_MSG_POSTFOCUS, 0, 0 );
- SAL_WARN_IF(0 == ret, "vcl", "ERROR: PostMessage() failed!");
- }
}
static void ImplHandleCloseMsg( HWND hWnd )
{
- if ( ImplSalYieldMutexTryToAcquire() )
- {
- WinSalFrame* pFrame = GetWindowPtr( hWnd );
+ WinSalFrame* pFrame = ProcessOrDeferMessage( hWnd, WM_CLOSE );
if ( pFrame )
{
pFrame->CallCallback( SalEvent::Close, nullptr );
+ ImplSalYieldMutexRelease();
}
-
- ImplSalYieldMutexRelease();
- }
- else
- {
- BOOL const ret = PostMessageW( hWnd, WM_CLOSE, 0, 0 );
- SAL_WARN_IF(0 == ret, "vcl", "ERROR: PostMessage() failed!");
- }
}
static long ImplHandleShutDownMsg( HWND hWnd )
{
- ImplSalYieldMutexAcquireWithWait();
- long nRet = 0;
- WinSalFrame* pFrame = GetWindowPtr( hWnd );
+ long nRet = 0;
+ WinSalFrame* pFrame = ProcessOrDeferMessage( hWnd, 0, 0, DeferPolicy::Blocked );
if ( pFrame )
{
nRet = pFrame->CallCallback( SalEvent::Shutdown, nullptr );
+ ImplSalYieldMutexRelease();
}
- ImplSalYieldMutexRelease();
return nRet;
}
@@ -4074,9 +4072,7 @@ static void ImplHandleSettingsChangeMsg( HWND hWnd, UINT nMsg,
if ( WM_SYSCOLORCHANGE == nMsg && GetSalData()->mhDitherPal )
ImplUpdateSysColorEntries();
- ImplSalYieldMutexAcquireWithWait();
-
- WinSalFrame* pFrame = GetWindowPtr( hWnd );
+ WinSalFrame* pFrame = ProcessOrDeferMessage( hWnd, 0, 0, DeferPolicy::Blocked );
if ( pFrame )
{
if ( (nMsg == WM_DISPLAYCHANGE) || (nMsg == WM_WININICHANGE) )
@@ -4086,20 +4082,18 @@ static void ImplHandleSettingsChangeMsg( HWND hWnd, UINT nMsg,
}
pFrame->CallCallback( nSalEvent, nullptr );
+ ImplSalYieldMutexRelease();
}
-
- ImplSalYieldMutexRelease();
}
static void ImplHandleUserEvent( HWND hWnd, LPARAM lParam )
{
- ImplSalYieldMutexAcquireWithWait();
- WinSalFrame* pFrame = GetWindowPtr( hWnd );
+ WinSalFrame* pFrame = ProcessOrDeferMessage( hWnd, 0, 0, DeferPolicy::Blocked );
if ( pFrame )
{
pFrame->CallCallback( SalEvent::UserEvent, reinterpret_cast<void*>(lParam) );
+ ImplSalYieldMutexRelease();
}
- ImplSalYieldMutexRelease();
}
static void ImplHandleForcePalette( HWND hWnd )
@@ -4108,14 +4102,7 @@ static void ImplHandleForcePalette( HWND hWnd )
HPALETTE hPal = pSalData->mhDitherPal;
if ( hPal )
{
- if ( !ImplSalYieldMutexTryToAcquire() )
- {
- BOOL const ret = PostMessageW( hWnd, SAL_MSG_FORCEPALETTE, 0, 0 );
- SAL_WARN_IF(0 == ret, "vcl", "ERROR: PostMessage() failed!");
- return;
- }
-
- WinSalFrame* pFrame = GetWindowPtr( hWnd );
+ WinSalFrame* pFrame = ProcessOrDeferMessage( hWnd, SAL_MSG_FORCEPALETTE );
if ( pFrame && pFrame->mpGraphics )
{
WinSalGraphics* pGraphics = pFrame->mpGraphics;
@@ -4130,8 +4117,8 @@ static void ImplHandleForcePalette( HWND hWnd )
}
}
}
-
- ImplSalYieldMutexRelease();
+ if ( pFrame )
+ ImplSalYieldMutexRelease();
}
}