diff options
author | Jan-Marek Glogowski <glogow@fbihome.de> | 2022-06-02 22:42:20 +0200 |
---|---|---|
committer | Jan-Marek Glogowski <glogow@fbihome.de> | 2022-06-08 18:17:17 +0200 |
commit | ea5a0918c8c32309821ab239c4b95f4d6a3b5c12 (patch) | |
tree | 04ff84b7c076a2f178e90d0eb32eb1731b10fd3c /vcl/win | |
parent | d4123356c61db269651e950a0a2cc93e6d801c90 (diff) |
VCL add vcl::WindowPosSize abstract class
... and use it to remove a duplicate and simplify code.
Should mostly be a refactoring, which was mainly done by some
larger sed calls, except for the new API calls, which helped
shrinking some LOC. All data is also now private.
Originally two of the "replaced" "classes" had unsigned width
and height and one had signed. Noel pointed out, that during
calculations, the value might get negative temporarly, so this
now settles with signed values. Still the set size should never
be negative and this is enforced this way. Not sure that is what
Noel had in mind.
This also includes:
- rename WindowState => WindowData
- rename WindowStateMask => WindowDataMask
- rename WindowStateState => WindowState
- move WindowState and WindowDataMask to vcl/windowstate.hxx
- move WindowData(Mask) and WindowState into vcl namespace
- readability: replace or'ed WindowState enums with "meta" enums
+ add "meta" WindowState enums PosSize and PosSizeState
Change-Id: Icd16cfb498531aa7238ddbde83fcb0ed6d9e4f77
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135426
Tested-by: Jenkins
Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
Diffstat (limited to 'vcl/win')
-rw-r--r-- | vcl/win/gdi/gdiimpl.cxx | 4 | ||||
-rw-r--r-- | vcl/win/window/salframe.cxx | 145 |
2 files changed, 69 insertions, 80 deletions
diff --git a/vcl/win/gdi/gdiimpl.cxx b/vcl/win/gdi/gdiimpl.cxx index 2c418732561b..afe4492a83e7 100644 --- a/vcl/win/gdi/gdiimpl.cxx +++ b/vcl/win/gdi/gdiimpl.cxx @@ -964,8 +964,8 @@ tools::Long WinSalGraphicsImpl::GetGraphicsWidth() const WinSalFrame* pFrame = GetWindowPtr( mrParent.gethWnd() ); if( pFrame ) { - if( pFrame->maGeometry.nWidth ) - return pFrame->maGeometry.nWidth; + if (pFrame->maGeometry.width()) + return pFrame->maGeometry.width(); else { // TODO: perhaps not needed, maGeometry should always be up-to-date diff --git a/vcl/win/window/salframe.cxx b/vcl/win/window/salframe.cxx index 2ae47ec57630..44ca954e28ad 100644 --- a/vcl/win/window/salframe.cxx +++ b/vcl/win/window/salframe.cxx @@ -131,6 +131,12 @@ bool WinSalFrame::mbInReparent = false; static void UpdateFrameGeometry( HWND hWnd, WinSalFrame* pFrame ); static void SetMaximizedFrameGeometry( HWND hWnd, WinSalFrame* pFrame, RECT* pParentRect = nullptr ); +static void SetGeometrySize(vcl::WindowPosSize& rWinPosSize, const Size& rSize) +{ + rWinPosSize.setWidth(rSize.Width() < 0 ? 0 : rSize.Width()); + rWinPosSize.setHeight(rSize.Height() < 0 ? 0 : rSize.Height()); +} + static void UpdateGeometry(WinSalFrame* pFrame, RECT& aRect) { RECT aRect2 = aRect; @@ -141,10 +147,10 @@ static void UpdateGeometry(WinSalFrame* pFrame, RECT& aRect) tools::Long nBottomDeco = abs(aRect.bottom - aRect2.bottom); tools::Long nRightDeco = abs(aRect.right - aRect2.right); - pFrame->maState.mnX = aRect.left + nLeftDeco; - pFrame->maState.mnY = aRect.top + nTopDeco; - pFrame->maState.mnWidth = aRect.right - aRect.left - nLeftDeco - nRightDeco; - pFrame->maState.mnHeight = aRect.bottom - aRect.top - nTopDeco - nBottomDeco; + pFrame->maState.setPos({ aRect.left + nLeftDeco, aRect.top + nTopDeco }); + tools::Long nWidth(aRect.right - aRect.left - nLeftDeco - nRightDeco); + tools::Long nHeight(aRect.bottom - aRect.top - nTopDeco - nBottomDeco); + SetGeometrySize(pFrame->maState, { nWidth, nHeight }); } static void ImplSaveFrameState( WinSalFrame* pFrame ) @@ -155,14 +161,14 @@ static void ImplSaveFrameState( WinSalFrame* pFrame ) bool bVisible = (GetWindowStyle( pFrame->mhWnd ) & WS_VISIBLE) != 0; if ( IsIconic( pFrame->mhWnd ) ) { - pFrame->maState.mnState |= WindowStateState::Minimized; + pFrame->maState.rState() |= vcl::WindowState::Minimized; if ( bVisible ) pFrame->mnShowState = SW_SHOWMAXIMIZED; } else if ( IsZoomed( pFrame->mhWnd ) ) { - pFrame->maState.mnState &= ~WindowStateState::Minimized; - pFrame->maState.mnState |= WindowStateState::Maximized; + pFrame->maState.rState() &= ~vcl::WindowState::Minimized; + pFrame->maState.rState() |= vcl::WindowState::Maximized; if ( bVisible ) pFrame->mnShowState = SW_SHOWMAXIMIZED; pFrame->mbRestoreMaximize = true; @@ -177,8 +183,7 @@ static void ImplSaveFrameState( WinSalFrame* pFrame ) RECT aRect; GetWindowRect( pFrame->mhWnd, &aRect ); UpdateGeometry(pFrame, aRect); - - pFrame->maState.mnState &= ~WindowStateState(WindowStateState::Minimized | WindowStateState::Maximized); + pFrame->maState.rState() &= ~vcl::WindowState(vcl::WindowState::Minimized | vcl::WindowState::Maximized); if ( bVisible ) pFrame->mnShowState = SW_SHOWNORMAL; pFrame->mbRestoreMaximize = false; @@ -911,14 +916,14 @@ void WinSalFrame::updateScreenNumber() { const std::vector<WinSalSystem::DisplayMonitor>& rMonitors = pSys->getMonitors(); - Point aPoint( maGeometry.nX, maGeometry.nY ); + Point aPoint(maGeometry.pos()); size_t nMon = rMonitors.size(); for( size_t i = 0; i < nMon; i++ ) { if( rMonitors[i].m_aArea.Contains( aPoint ) ) { mnDisplay = static_cast<sal_Int32>(i); - maGeometry.nDisplayScreenNumber = static_cast<unsigned int>(i); + maGeometry.setScreen(static_cast<unsigned int>(i)); } } } @@ -1311,8 +1316,8 @@ void WinSalFrame::SetPosSize( tools::Long nX, tools::Long nY, tools::Long nWidth // #i42485#: parent will be shown maximized in which case // a ClientToScreen uses the wrong coordinates (i.e. those from the restore pos) // so use the (already updated) frame geometry for the transformation - aPt.x += pParentFrame->maGeometry.nX; - aPt.y += pParentFrame->maGeometry.nY; + aPt.x += pParentFrame->maGeometry.x(); + aPt.y += pParentFrame->maGeometry.y(); } else ClientToScreen( parentHwnd, &aPt ); @@ -1587,11 +1592,11 @@ void WinSalFrame::GetWorkArea( tools::Rectangle &rRect ) void WinSalFrame::GetClientSize( tools::Long& rWidth, tools::Long& rHeight ) { - rWidth = maGeometry.nWidth; - rHeight = maGeometry.nHeight; + rWidth = maGeometry.width(); + rHeight = maGeometry.height(); } -void WinSalFrame::SetWindowState( const SalFrameState* pState ) +void WinSalFrame::SetWindowState(const vcl::WindowData* pState) { // Check if the window fits into the screen, in case the screen // resolution changed @@ -1627,24 +1632,24 @@ void WinSalFrame::SetWindowState( const SalFrameState* pState ) tools::Long nRightDeco = abs( aWinRect.right - aRect2.right ); // adjust window position/size to fit the screen - if ( !(pState->mnMask & (WindowStateMask::X | WindowStateMask::Y)) ) + if ( !(pState->mask() & vcl::WindowDataMask::Pos) ) nPosSize |= SWP_NOMOVE; - if ( !(pState->mnMask & (WindowStateMask::Width | WindowStateMask::Height)) ) + if ( !(pState->mask() & vcl::WindowDataMask::Size) ) nPosSize |= SWP_NOSIZE; - if ( pState->mnMask & WindowStateMask::X ) - nX = static_cast<int>(pState->mnX) - nLeftDeco; + if ( pState->mask() & vcl::WindowDataMask::X ) + nX = static_cast<int>(pState->x()) - nLeftDeco; else nX = aWinRect.left; - if ( pState->mnMask & WindowStateMask::Y ) - nY = static_cast<int>(pState->mnY) - nTopDeco; + if ( pState->mask() & vcl::WindowDataMask::Y ) + nY = static_cast<int>(pState->y()) - nTopDeco; else nY = aWinRect.top; - if ( pState->mnMask & WindowStateMask::Width ) - nWidth = static_cast<int>(pState->mnWidth) + nLeftDeco + nRightDeco; + if ( pState->mask() & vcl::WindowDataMask::Width ) + nWidth = static_cast<int>(pState->width()) + nLeftDeco + nRightDeco; else nWidth = aWinRect.right-aWinRect.left; - if ( pState->mnMask & WindowStateMask::Height ) - nHeight = static_cast<int>(pState->mnHeight) + nTopDeco + nBottomDeco; + if ( pState->mask() & vcl::WindowDataMask::Height ) + nHeight = static_cast<int>(pState->height()) + nTopDeco + nBottomDeco; else nHeight = aWinRect.bottom-aWinRect.top; @@ -1678,33 +1683,33 @@ void WinSalFrame::SetWindowState( const SalFrameState* pState ) if ( mbOverwriteState ) { - if ( pState->mnMask & WindowStateMask::State ) + if ( pState->mask() & vcl::WindowDataMask::State ) { - if ( pState->mnState & WindowStateState::Minimized ) + if ( pState->state() & vcl::WindowState::Minimized ) mnShowState = SW_SHOWMINIMIZED; - else if ( pState->mnState & WindowStateState::Maximized ) + else if ( pState->state() & vcl::WindowState::Maximized ) { mnShowState = SW_SHOWMAXIMIZED; bUpdateHiddenFramePos = true; } - else if ( pState->mnState & WindowStateState::Normal ) + else if ( pState->state() & vcl::WindowState::Normal ) mnShowState = SW_SHOWNORMAL; } } } else { - if ( pState->mnMask & WindowStateMask::State ) + if ( pState->mask() & vcl::WindowDataMask::State ) { - if ( pState->mnState & WindowStateState::Minimized ) + if ( pState->state() & vcl::WindowState::Minimized ) { - if ( pState->mnState & WindowStateState::Maximized ) + if ( pState->state() & vcl::WindowState::Maximized ) aPlacement.flags |= WPF_RESTORETOMAXIMIZED; aPlacement.showCmd = SW_SHOWMINIMIZED; } - else if ( pState->mnState & WindowStateState::Maximized ) + else if ( pState->state() & vcl::WindowState::Maximized ) aPlacement.showCmd = SW_SHOWMAXIMIZED; - else if ( pState->mnState & WindowStateState::Normal ) + else if ( pState->state() & vcl::WindowState::Normal ) aPlacement.showCmd = SW_RESTORE; } } @@ -1726,7 +1731,7 @@ void WinSalFrame::SetWindowState( const SalFrameState* pState ) // the window will not be maximized (and the size updated) before show() SetMaximizedFrameGeometry( mhWnd, this, &aStateRect ); SetWindowPos( mhWnd, nullptr, - maGeometry.nX, maGeometry.nY, maGeometry.nWidth, maGeometry.nHeight, + maGeometry.x(), maGeometry.y(), maGeometry.width(), maGeometry.height(), SWP_NOZORDER | SWP_NOACTIVATE | nPosSize ); } else @@ -1750,16 +1755,15 @@ void WinSalFrame::SetWindowState( const SalFrameState* pState ) mbDefPos = false; // window was positioned } -bool WinSalFrame::GetWindowState( SalFrameState* pState ) +bool WinSalFrame::GetWindowState(vcl::WindowData* pState) { - if ( maState.mnWidth && maState.mnHeight ) + if (maState.width() && maState.height()) { *pState = maState; // #94144# allow Minimize again, should be masked out when read from configuration // 91625 - Don't save minimize - //if ( !(pState->mnState & WindowStateState::Maximized) ) - if ( !(pState->mnState & (WindowStateState::Minimized | WindowStateState::Maximized)) ) - pState->mnState |= WindowStateState::Normal; + if ( !(pState->state() & (vcl::WindowState::Minimized | vcl::WindowState::Maximized)) ) + pState->rState() |= vcl::WindowState::Normal; return true; } @@ -1777,7 +1781,7 @@ void WinSalFrame::SetScreenNumber( unsigned int nNewScreen ) if( nNewScreen < nMon ) { Point aOldMonPos, aNewMonPos( rMonitors[nNewScreen].m_aArea.TopLeft() ); - Point aCurPos( maGeometry.nX, maGeometry.nY ); + Point aCurPos(maGeometry.pos()); for( size_t i = 0; i < nMon; i++ ) { if( rMonitors[i].m_aArea.Contains( aCurPos ) ) @@ -1787,9 +1791,9 @@ void WinSalFrame::SetScreenNumber( unsigned int nNewScreen ) } } mnDisplay = nNewScreen; - maGeometry.nDisplayScreenNumber = nNewScreen; - SetPosSize( aNewMonPos.X() + (maGeometry.nX - aOldMonPos.X()), - aNewMonPos.Y() + (maGeometry.nY - aOldMonPos.Y()), + maGeometry.setScreen(nNewScreen); + SetPosSize( aNewMonPos.X() + (maGeometry.x() - aOldMonPos.X()), + aNewMonPos.Y() + (maGeometry.y() - aOldMonPos.Y()), 0, 0, SAL_FRAME_POSSIZE_X | SAL_FRAME_POSSIZE_Y ); } @@ -2920,7 +2924,7 @@ SalFrame::SalPointerState WinSalFrame::GetPointerState() POINT pt; GetCursorPos( &pt ); - aState.maPos = Point( pt.x - maGeometry.nX, pt.y - maGeometry.nY ); + aState.maPos = Point(pt.x - maGeometry.x(), pt.y - maGeometry.y()); return aState; } @@ -3223,7 +3227,7 @@ static bool ImplHandleMouseMsg( HWND hWnd, UINT nMsg, UpdateWindow( hWnd ); if( AllSettings::GetLayoutRTL() ) - aMouseEvt.mnX = pFrame->maGeometry.nWidth-1-aMouseEvt.mnX; + aMouseEvt.mnX = pFrame->maGeometry.width() - 1 - aMouseEvt.mnX; nRet = pFrame->CallCallback( nEvent, &aMouseEvt ); if ( nMsg == WM_MOUSEMOVE ) @@ -3306,7 +3310,7 @@ static bool ImplHandleWheelMsg( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lPar aWheelEvt.mnCode |= KEY_MOD2; if( AllSettings::GetLayoutRTL() ) - aWheelEvt.mnX = pFrame->maGeometry.nWidth-1-aWheelEvt.mnX; + aWheelEvt.mnX = pFrame->maGeometry.width() - 1 - aWheelEvt.mnX; nRet = pFrame->CallCallback( SalEvent::WheelMouse, &aWheelEvt ); } @@ -3936,14 +3940,11 @@ static void SetMaximizedFrameGeometry( HWND hWnd, WinSalFrame* pFrame, RECT* pPa ImplSalGetWorkArea( hWnd, &aRect, pParentRect ); // a maximized window has no other borders than the caption - pFrame->maGeometry.nLeftDecoration = pFrame->maGeometry.nRightDecoration = pFrame->maGeometry.nBottomDecoration = 0; - pFrame->maGeometry.nTopDecoration = pFrame->mbCaption ? GetSystemMetrics( SM_CYCAPTION ) : 0; + pFrame->maGeometry.setDecorations(0, pFrame->mbCaption ? GetSystemMetrics(SM_CYCAPTION) : 0, 0, 0); - aRect.top += pFrame->maGeometry.nTopDecoration; - pFrame->maGeometry.nX = aRect.left; - pFrame->maGeometry.nY = aRect.top; - pFrame->maGeometry.nWidth = aRect.right - aRect.left; - pFrame->maGeometry.nHeight = aRect.bottom - aRect.top; + aRect.top += pFrame->maGeometry.topDecoration(); + pFrame->maGeometry.setPos({ aRect.left, aRect.top }); + SetGeometrySize(pFrame->maGeometry, { aRect.right - aRect.left, aRect.bottom - aRect.top }); } static void UpdateFrameGeometry( HWND hWnd, WinSalFrame* pFrame ) @@ -3953,15 +3954,9 @@ static void UpdateFrameGeometry( HWND hWnd, WinSalFrame* pFrame ) RECT aRect; GetWindowRect( hWnd, &aRect ); - pFrame->maGeometry.nX = 0; - pFrame->maGeometry.nY = 0; - pFrame->maGeometry.nWidth = 0; - pFrame->maGeometry.nHeight = 0; - pFrame->maGeometry.nLeftDecoration = 0; - pFrame->maGeometry.nTopDecoration = 0; - pFrame->maGeometry.nRightDecoration = 0; - pFrame->maGeometry.nBottomDecoration = 0; - pFrame->maGeometry.nDisplayScreenNumber = 0; + pFrame->maGeometry.setPosSize({ 0, 0 }, { 0, 0 }); + pFrame->maGeometry.setDecorations(0, 0, 0, 0); + pFrame->maGeometry.setScreen(0); if ( IsIconic( hWnd ) ) return; @@ -3971,13 +3966,9 @@ static void UpdateFrameGeometry( HWND hWnd, WinSalFrame* pFrame ) aPt.y=0; ClientToScreen(hWnd, &aPt); int cx = aPt.x - aRect.left; - pFrame->maGeometry.nTopDecoration = aPt.y - aRect.top; - - pFrame->maGeometry.nLeftDecoration = cx; - pFrame->maGeometry.nRightDecoration = cx; - pFrame->maGeometry.nX = aPt.x; - pFrame->maGeometry.nY = aPt.y; + pFrame->maGeometry.setDecorations(cx, aPt.y - aRect.top, cx, 0); + pFrame->maGeometry.setPos({ aPt.x, aPt.y }); RECT aInnerRect; GetClientRect( hWnd, &aInnerRect ); @@ -3987,21 +3978,19 @@ static void UpdateFrameGeometry( HWND hWnd, WinSalFrame* pFrame ) aPt.x=aInnerRect.right; aPt.y=aInnerRect.top; ClientToScreen(hWnd, &aPt); - pFrame->maGeometry.nRightDecoration = aRect.right - aPt.x; + pFrame->maGeometry.setRightDecoration(aRect.right - aPt.x); } if( aInnerRect.bottom ) // may be zero if window was not shown yet - pFrame->maGeometry.nBottomDecoration += aRect.bottom - aPt.y - aInnerRect.bottom; + pFrame->maGeometry.setBottomDecoration(aRect.bottom - aPt.y - aInnerRect.bottom); else // bottom border is typically the same as left/right - pFrame->maGeometry.nBottomDecoration = pFrame->maGeometry.nLeftDecoration; + pFrame->maGeometry.setBottomDecoration(pFrame->maGeometry.leftDecoration()); int nWidth = aRect.right - aRect.left - - pFrame->maGeometry.nRightDecoration - pFrame->maGeometry.nLeftDecoration; + - pFrame->maGeometry.rightDecoration() - pFrame->maGeometry.leftDecoration(); int nHeight = aRect.bottom - aRect.top - - pFrame->maGeometry.nBottomDecoration - pFrame->maGeometry.nTopDecoration; - // clamp to zero - pFrame->maGeometry.nHeight = nHeight < 0 ? 0 : nHeight; - pFrame->maGeometry.nWidth = nWidth < 0 ? 0 : nWidth; + - pFrame->maGeometry.bottomDecoration() - pFrame->maGeometry.topDecoration(); + SetGeometrySize(pFrame->maGeometry, { nWidth, nHeight }); pFrame->updateScreenNumber(); } |