diff options
author | Jan-Marek Glogowski <glogow@fbihome.de> | 2017-10-16 17:04:24 +0200 |
---|---|---|
committer | Jan-Marek Glogowski <glogow@fbihome.de> | 2017-10-20 22:25:15 +0200 |
commit | 8ba60ca42d4d1873b8cd85c5d3b5ed2f0e19df60 (patch) | |
tree | 1e7fc5b10059959b65fea23932c20c70a52552a6 /vcl/win | |
parent | 4f05fdffbe4483ae0a466a6460b63560c3fb45ca (diff) |
WIN message handling cleanup and refactoring
Replace a lot of duplicated case code with macros.
Some minor constifications of function parameters.
I restrained from shorten the SAL_MSG_* via preprocessor concat,
so a grep will still find the whole names.
Change-Id: If1f2477fc8817b4ae7816e807154e35004bb4da9
Reviewed-on: https://gerrit.libreoffice.org/43531
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
Diffstat (limited to 'vcl/win')
-rw-r--r-- | vcl/win/app/salinst.cxx | 144 | ||||
-rw-r--r-- | vcl/win/window/salobj.cxx | 6 |
2 files changed, 67 insertions, 83 deletions
diff --git a/vcl/win/app/salinst.cxx b/vcl/win/app/salinst.cxx index 693411a0583c..68ad7deb994d 100644 --- a/vcl/win/app/salinst.cxx +++ b/vcl/win/app/salinst.cxx @@ -459,14 +459,14 @@ void WinSalInstance::AcquireYieldMutex( sal_uInt32 nCount ) mpSalYieldMutex->acquire( nCount ); } -static LRESULT ImplSalDispatchMessage( MSG* pMsg ) +static LRESULT ImplSalDispatchMessage( const MSG* pMsg ) { SalData* pSalData = GetSalData(); if ( pSalData->mpFirstObject && ImplSalPreDispatchMsg( pMsg ) ) return 0; LRESULT lResult = DispatchMessageW( pMsg ); if ( pSalData->mpFirstObject ) - ImplSalPostDispatchMsg( pMsg, lResult ); + ImplSalPostDispatchMsg( pMsg ); return lResult; } @@ -569,124 +569,108 @@ bool WinSalInstance::DoYield(bool bWait, bool bHandleAllCurrentEvents) return bDidWork; } -LRESULT CALLBACK SalComWndProc( HWND, UINT nMsg, WPARAM wParam, LPARAM lParam, int& rDef ) +#define CASE_NOYIELDLOCK( salmsg, function ) \ + case salmsg: \ + assert( !pInst->mbNoYieldLock ); \ + pInst->mbNoYieldLock = true; \ + function; \ + pInst->mbNoYieldLock = false; \ + break; + +#define CASE_NOYIELDLOCK_RESULT( salmsg, function ) \ + case salmsg: \ + assert( !pInst->mbNoYieldLock ); \ + pInst->mbNoYieldLock = true; \ + nRet = reinterpret_cast<LRESULT>( function ); \ + pInst->mbNoYieldLock = false; \ + break; + +LRESULT CALLBACK SalComWndProc( HWND, UINT nMsg, WPARAM wParam, LPARAM lParam, bool& rDef ) { LRESULT nRet = 0; WinSalInstance *pInst = GetSalData()->mpInstance; + WinSalTimer *const pTimer = static_cast<WinSalTimer*>( ImplGetSVData()->maSchedCtx.mpSalTimer ); switch ( nMsg ) { case SAL_MSG_THREADYIELD: assert( !(bool)wParam ); - nRet = static_cast<LRESULT>(ImplSalYield( false, (bool)lParam )); - rDef = FALSE; + nRet = static_cast<LRESULT>(ImplSalYield( + false, static_cast<bool>( lParam ) )); break; + case SAL_MSG_STARTTIMER: { sal_uInt64 nTime = tools::Time::GetSystemTicks(); - if ( nTime < (sal_uInt64) lParam ) - nTime = (sal_uInt64) lParam - nTime; + if ( nTime < static_cast<sal_uInt64>( lParam ) ) + nTime = static_cast<sal_uInt64>( lParam ) - nTime; else nTime = 0; - static_cast<WinSalTimer*>(ImplGetSVData()->maSchedCtx.mpSalTimer)->ImplStart( nTime ); - rDef = FALSE; + assert( pTimer != nullptr ); + pTimer->ImplStart( nTime ); break; } + case SAL_MSG_STOPTIMER: - static_cast<WinSalTimer*>(ImplGetSVData()->maSchedCtx.mpSalTimer)->ImplStop(); - break; - case SAL_MSG_CREATEFRAME: - assert( !pInst->mbNoYieldLock ); - pInst->mbNoYieldLock = true; - nRet = reinterpret_cast<LRESULT>(ImplSalCreateFrame( GetSalData()->mpInstance, reinterpret_cast<HWND>(lParam), (SalFrameStyleFlags)wParam )); - pInst->mbNoYieldLock = false; - rDef = FALSE; - break; - case SAL_MSG_RECREATEHWND: - assert( !pInst->mbNoYieldLock ); - pInst->mbNoYieldLock = true; - nRet = reinterpret_cast<LRESULT>(ImplSalReCreateHWND( reinterpret_cast<HWND>(wParam), reinterpret_cast<HWND>(lParam), false )); - pInst->mbNoYieldLock = false; - rDef = FALSE; - break; - case SAL_MSG_RECREATECHILDHWND: - assert( !pInst->mbNoYieldLock ); - pInst->mbNoYieldLock = true; - nRet = reinterpret_cast<LRESULT>(ImplSalReCreateHWND( reinterpret_cast<HWND>(wParam), reinterpret_cast<HWND>(lParam), true )); - pInst->mbNoYieldLock = false; - rDef = FALSE; - break; - case SAL_MSG_DESTROYFRAME: - assert( !pInst->mbNoYieldLock ); - pInst->mbNoYieldLock = true; - delete reinterpret_cast<SalFrame*>(lParam); - pInst->mbNoYieldLock = false; - rDef = FALSE; + assert( pTimer != nullptr ); + pTimer->ImplStop(); break; + + CASE_NOYIELDLOCK_RESULT( SAL_MSG_CREATEFRAME, ImplSalCreateFrame( GetSalData()->mpInstance, + reinterpret_cast<HWND>(lParam), static_cast<SalFrameStyleFlags>(wParam)) ) + CASE_NOYIELDLOCK_RESULT( SAL_MSG_RECREATEHWND, ImplSalReCreateHWND( + reinterpret_cast<HWND>(wParam), reinterpret_cast<HWND>(lParam), false) ) + CASE_NOYIELDLOCK_RESULT( SAL_MSG_RECREATECHILDHWND, ImplSalReCreateHWND( + reinterpret_cast<HWND>(wParam), reinterpret_cast<HWND>(lParam), true) ) + CASE_NOYIELDLOCK( SAL_MSG_DESTROYFRAME, delete reinterpret_cast<SalFrame*>(lParam) ) + case SAL_MSG_DESTROYHWND: - //We only destroy the native window here. We do NOT destroy the SalFrame contained - //in the structure (GetWindowPtr()). + // We only destroy the native window here. We do NOT destroy the SalFrame contained + // in the structure (GetWindowPtr()). if (DestroyWindow(reinterpret_cast<HWND>(lParam)) == 0) { OSL_FAIL("DestroyWindow failed!"); - //Failure: We remove the SalFrame from the window structure. So we avoid that + // Failure: We remove the SalFrame from the window structure. So we avoid that // the window structure may contain an invalid pointer, once the SalFrame is deleted. - SetWindowPtr(reinterpret_cast<HWND>(lParam), nullptr); + SetWindowPtr(reinterpret_cast<HWND>(lParam), nullptr); } - rDef = FALSE; - break; - case SAL_MSG_CREATEOBJECT: - assert( !pInst->mbNoYieldLock ); - pInst->mbNoYieldLock = true; - nRet = reinterpret_cast<LRESULT>(ImplSalCreateObject( GetSalData()->mpInstance, reinterpret_cast<WinSalFrame*>(lParam) )); - pInst->mbNoYieldLock = false; - rDef = FALSE; - break; - case SAL_MSG_DESTROYOBJECT: - assert( !pInst->mbNoYieldLock ); - pInst->mbNoYieldLock = true; - delete reinterpret_cast<SalObject*>(lParam); - pInst->mbNoYieldLock = false; - rDef = FALSE; - break; - case SAL_MSG_GETDC: - assert( !pInst->mbNoYieldLock ); - pInst->mbNoYieldLock = true; - nRet = reinterpret_cast<LRESULT>(GetDCEx( reinterpret_cast<HWND>(wParam), nullptr, DCX_CACHE )); - pInst->mbNoYieldLock = false; - rDef = FALSE; - break; - case SAL_MSG_RELEASEDC: - assert( !pInst->mbNoYieldLock ); - pInst->mbNoYieldLock = true; - ReleaseDC( reinterpret_cast<HWND>(wParam), reinterpret_cast<HDC>(lParam) ); - pInst->mbNoYieldLock = false; - rDef = FALSE; break; + + CASE_NOYIELDLOCK_RESULT( SAL_MSG_CREATEOBJECT, ImplSalCreateObject( + GetSalData()->mpInstance, reinterpret_cast<WinSalFrame*>(lParam)) ) + CASE_NOYIELDLOCK( SAL_MSG_DESTROYOBJECT, delete reinterpret_cast<SalObject*>(lParam) ) + CASE_NOYIELDLOCK_RESULT( SAL_MSG_GETDC, GetDCEx( + reinterpret_cast<HWND>(wParam), nullptr, DCX_CACHE) ) + CASE_NOYIELDLOCK( SAL_MSG_RELEASEDC, ReleaseDC( + reinterpret_cast<HWND>(wParam), reinterpret_cast<HDC>(lParam)) ) + case SAL_MSG_TIMER_CALLBACK: - { - WinSalTimer *const pTimer = static_cast<WinSalTimer*>( ImplGetSVData()->maSchedCtx.mpSalTimer ); assert( pTimer != nullptr ); nRet = static_cast<LRESULT>( pTimer->ImplHandleTimerEvent( wParam ) ); - rDef = FALSE; break; - } + case WM_TIMER: - { - WinSalTimer *const pTimer = static_cast<WinSalTimer*>( ImplGetSVData()->maSchedCtx.mpSalTimer ); assert( pTimer != nullptr ); nRet = static_cast<LRESULT>( pTimer->ImplHandle_WM_TIMER( wParam ) ); - rDef = FALSE; break; - } + + case SAL_MSG_DUMMY: + break; + + default: + rDef = true; + break; } return nRet; } +#undef CASE_NOYIELDLOCK +#undef CASE_NOYIELDLOCK_RESULT + LRESULT CALLBACK SalComWndProcW( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam ) { - int bDef = TRUE; + bool bDef = false; LRESULT nRet = 0; __try { diff --git a/vcl/win/window/salobj.cxx b/vcl/win/window/salobj.cxx index 172f61e923d3..75e406c33f61 100644 --- a/vcl/win/window/salobj.cxx +++ b/vcl/win/window/salobj.cxx @@ -145,7 +145,7 @@ LRESULT CALLBACK SalSysMsgProc( int nCode, WPARAM wParam, LPARAM lParam ) return CallNextHookEx( pSalData->mhSalObjMsgHook, nCode, wParam, lParam ); } -bool ImplSalPreDispatchMsg( MSG* pMsg ) +bool ImplSalPreDispatchMsg( const MSG* pMsg ) { // Used for Unicode and none Unicode SalData* pSalData = GetSalData(); @@ -231,10 +231,10 @@ bool ImplSalPreDispatchMsg( MSG* pMsg ) return FALSE; } -void ImplSalPostDispatchMsg( MSG* pMsg, LRESULT /* nDispatchResult */ ) +void ImplSalPostDispatchMsg( const MSG* pMsg ) { // Used for Unicode and none Unicode - SalData* pSalData = GetSalData(); + SalData *pSalData = GetSalData(); if ( (pMsg->message == WM_KEYDOWN) || (pMsg->message == WM_KEYUP) ) { |