diff options
Diffstat (limited to 'tools/source/generic')
-rw-r--r-- | tools/source/generic/gen.cxx | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/tools/source/generic/gen.cxx b/tools/source/generic/gen.cxx index 3593801579ac..6438405c99e2 100644 --- a/tools/source/generic/gen.cxx +++ b/tools/source/generic/gen.cxx @@ -55,11 +55,20 @@ OString Pair::toString() const void tools::Rectangle::SetSize( const Size& rSize ) { if ( rSize.Width() < 0 ) + { nRight = nLeft + rSize.Width() +1; + mbWidthEmpty = false; + } else if ( rSize.Width() > 0 ) + { nRight = nLeft + rSize.Width() -1; + mbWidthEmpty = false; + } else - nRight = RECT_EMPTY; + { + nRight = 0; + mbWidthEmpty = true; + } if ( rSize.Height() < 0 ) nBottom = nTop + rSize.Height() +1; @@ -72,11 +81,20 @@ void tools::Rectangle::SetSize( const Size& rSize ) void tools::Rectangle::SaturatingSetSize(const Size& rSize) { if (rSize.Width() < 0) + { nRight = o3tl::saturating_add(nLeft, (rSize.Width() + 1)); + mbWidthEmpty = false; + } else if ( rSize.Width() > 0 ) + { nRight = o3tl::saturating_add(nLeft, (rSize.Width() - 1)); + mbWidthEmpty = false; + } else - nRight = RECT_EMPTY; + { + nRight = 0; + mbWidthEmpty = true; + } if ( rSize.Height() < 0 ) nBottom = o3tl::saturating_add(nTop, (rSize.Height() + 1)); @@ -88,7 +106,8 @@ void tools::Rectangle::SaturatingSetSize(const Size& rSize) void tools::Rectangle::SaturatingSetX(long x) { - nRight = o3tl::saturating_add(nRight, x - nLeft); + if (!mbWidthEmpty) + nRight = o3tl::saturating_add(nRight, x - nLeft); nLeft = x; } @@ -146,7 +165,7 @@ tools::Rectangle& tools::Rectangle::Intersection( const tools::Rectangle& rRect void tools::Rectangle::Justify() { - if ( (nRight < nLeft) && (nRight != RECT_EMPTY) ) + if ( (nRight < nLeft) && !mbWidthEmpty ) { std::swap(nLeft, nRight); } @@ -206,8 +225,9 @@ SvStream& ReadRectangle( SvStream& rIStream, tools::Rectangle& rRect ) rRect.nLeft = nTmpL; rRect.nTop = nTmpT; - rRect.nRight = nTmpR; + rRect.nRight = nTmpR == Rectangle::RECT_EMPTY ? 0 : nTmpR; rRect.nBottom = nTmpB; + rRect.mbWidthEmpty = nTmpR == Rectangle::RECT_EMPTY; return rIStream; } @@ -216,7 +236,7 @@ SvStream& WriteRectangle( SvStream& rOStream, const tools::Rectangle& rRect ) { rOStream.WriteInt32( rRect.nLeft ) .WriteInt32( rRect.nTop ) - .WriteInt32( rRect.nRight ) + .WriteInt32( rRect.mbWidthEmpty ? Rectangle::RECT_EMPTY : rRect.nRight ) .WriteInt32( rRect.nBottom ); return rOStream; |