diff options
-rw-r--r-- | include/tools/gen.hxx | 32 | ||||
-rw-r--r-- | svx/source/svdraw/svdopath.cxx | 8 | ||||
-rw-r--r-- | svx/source/unodraw/unoshape.cxx | 4 | ||||
-rw-r--r-- | sw/source/core/bastyp/swrect.cxx | 6 | ||||
-rw-r--r-- | vcl/source/control/scrbar.cxx | 8 |
5 files changed, 34 insertions, 24 deletions
diff --git a/include/tools/gen.hxx b/include/tools/gen.hxx index a10b74e03b0b..ca0c43d272a5 100644 --- a/include/tools/gen.hxx +++ b/include/tools/gen.hxx @@ -327,7 +327,6 @@ inline std::basic_ostream<charT, traits> & operator <<( } // Rectangle -#define RECT_EMPTY (short(-32767)) #define RECT_MAX LONG_MAX #define RECT_MIN LONG_MIN @@ -344,11 +343,14 @@ namespace tools { class SAL_WARN_UNUSED TOOLS_DLLPUBLIC Rectangle { + static constexpr short RECT_EMPTY = -32767; public: Rectangle(); Rectangle( const Point& rLT, const Point& rRB ); Rectangle( long nLeft, long nTop, long nRight, long nBottom ); + /// Constructs an empty Rectangle, with top/left at the specified params + Rectangle( long nLeft, long nTop ); Rectangle( const Point& rLT, const Size& rSize ); long Left() const { return nLeft; } @@ -394,7 +396,11 @@ public: bool IsOver( const tools::Rectangle& rRect ) const; void SetEmpty() { nRight = nBottom = RECT_EMPTY; } + void SetWidthEmpty() { nRight = RECT_EMPTY; } + void SetHeightEmpty() { nBottom = RECT_EMPTY; } inline bool IsEmpty() const; + bool IsWidthEmpty() const { return nRight == RECT_EMPTY; } + bool IsHeightEmpty() const { return nBottom == RECT_EMPTY; } inline bool operator == ( const tools::Rectangle& rRect ) const; inline bool operator != ( const tools::Rectangle& rRect ) const; @@ -465,6 +471,13 @@ inline tools::Rectangle::Rectangle( long _nLeft, long _nTop, nBottom = _nBottom; } +inline tools::Rectangle::Rectangle( long _nLeft, long _nTop ) +{ + nLeft = _nLeft; + nTop = _nTop; + nRight = nBottom = RECT_EMPTY; +} + inline tools::Rectangle::Rectangle( const Point& rLT, const Size& rSize ) { nLeft = rLT.X(); @@ -654,19 +667,18 @@ namespace tools { inline Rectangle operator + ( const Rectangle& rRect, const Point& rPt ) { - Rectangle aRect( rRect.nLeft + rPt.X(), rRect.nTop + rPt.Y(), - (rRect.nRight == RECT_EMPTY) ? RECT_EMPTY : rRect.nRight + rPt.X(), - (rRect.nBottom == RECT_EMPTY) ? RECT_EMPTY : rRect.nBottom + rPt.Y() ); - return aRect; + return rRect.IsEmpty() + ? Rectangle( rRect.nLeft + rPt.X(), rRect.nTop + rPt.Y() ) + : Rectangle( rRect.nLeft + rPt.X(), rRect.nTop + rPt.Y(), + rRect.nRight + rPt.X(), rRect.nBottom + rPt.Y() ); } inline Rectangle operator - ( const Rectangle& rRect, const Point& rPt ) { - Rectangle aRect( rRect.nLeft - rPt.X(), - rRect.nTop - rPt.Y(), - (rRect.nRight == RECT_EMPTY) ? RECT_EMPTY : rRect.nRight - rPt.X(), - (rRect.nBottom == RECT_EMPTY) ? RECT_EMPTY : rRect.nBottom - rPt.Y() ); - return aRect; + return rRect.IsEmpty() + ? Rectangle( rRect.nLeft - rPt.X(), rRect.nTop - rPt.Y() ) + : Rectangle( rRect.nLeft - rPt.X(), rRect.nTop - rPt.Y(), + rRect.nRight - rPt.X(), rRect.nBottom - rPt.Y() ); } } diff --git a/svx/source/svdraw/svdopath.cxx b/svx/source/svdraw/svdopath.cxx index 8a14da00bfdd..b71e20f92a94 100644 --- a/svx/source/svdraw/svdopath.cxx +++ b/svx/source/svdraw/svdopath.cxx @@ -2425,13 +2425,13 @@ void SdrPathObj::NbcSetSnapRect(const tools::Rectangle& rRect) { tools::Rectangle aOld(GetSnapRect()); - // Take RECT_EMPTY into account when calculating scale factors - long nMulX = (RECT_EMPTY == rRect.Right()) ? 0 : rRect.Right() - rRect.Left(); + // Take empty into account when calculating scale factors + long nMulX = rRect.IsWidthEmpty() ? 0 : rRect.Right() - rRect.Left(); long nDivX = aOld.Right() - aOld.Left(); - // Take RECT_EMPTY into account when calculating scale factors - long nMulY = (RECT_EMPTY == rRect.Bottom()) ? 0 : rRect.Bottom() - rRect.Top(); + // Take empty into account when calculating scale factors + long nMulY = rRect.IsHeightEmpty() ? 0 : rRect.Bottom() - rRect.Top(); long nDivY = aOld.Bottom() - aOld.Top(); if ( nDivX == 0 ) { nMulX = 1; nDivX = 1; } diff --git a/svx/source/unodraw/unoshape.cxx b/svx/source/unodraw/unoshape.cxx index 14cc1a0f108f..0f33c8287e87 100644 --- a/svx/source/unodraw/unoshape.cxx +++ b/svx/source/unodraw/unoshape.cxx @@ -1220,13 +1220,13 @@ void SAL_CALL SvxShape::setSize( const awt::Size& rSize ) //aRect.SetSize(aLocalSize); // this call subtract 1 // http://www.openoffice.org/issues/show_bug.cgi?id=83193 if ( !aLocalSize.Width() ) { - aRect.Right() = RECT_EMPTY; + aRect.SetWidthEmpty(); } else aRect.setWidth(aLocalSize.Width()); if ( !aLocalSize.Height() ) { - aRect.Bottom() = RECT_EMPTY; + aRect.SetHeightEmpty(); } else aRect.setHeight(aLocalSize.Height()); diff --git a/sw/source/core/bastyp/swrect.cxx b/sw/source/core/bastyp/swrect.cxx index dab5547f6c3f..ac71a2023de3 100644 --- a/sw/source/core/bastyp/swrect.cxx +++ b/sw/source/core/bastyp/swrect.cxx @@ -29,10 +29,8 @@ SwRect::SwRect( const tools::Rectangle &rRect ) : m_Point( rRect.Left(), rRect.Top() ) { - m_Size.setWidth(rRect.Right() == RECT_EMPTY ? 0 : - rRect.Right() - rRect.Left() +1); - m_Size.setHeight(rRect.Bottom() == RECT_EMPTY ? 0 : - rRect.Bottom() - rRect.Top() + 1); + m_Size.setWidth( rRect.IsWidthEmpty() ? 0 : rRect.Right() - rRect.Left() + 1); + m_Size.setHeight(rRect.IsHeightEmpty() ? 0 : rRect.Bottom() - rRect.Top() + 1); } Point SwRect::Center() const diff --git a/vcl/source/control/scrbar.cxx b/vcl/source/control/scrbar.cxx index 2695f6da714b..56a23f2c9cc2 100644 --- a/vcl/source/control/scrbar.cxx +++ b/vcl/source/control/scrbar.cxx @@ -131,11 +131,11 @@ void ScrollBar::ImplUpdateRects( bool bUpdate ) maThumbRect.Left() = maTrackRect.Left()+mnThumbPixPos; maThumbRect.Right() = maThumbRect.Left()+mnThumbPixSize-1; if ( !mnThumbPixPos ) - maPage1Rect.Right() = RECT_EMPTY; + maPage1Rect.SetWidthEmpty(); else maPage1Rect.Right() = maThumbRect.Left()-1; if ( mnThumbPixPos >= (mnThumbPixRange-mnThumbPixSize) ) - maPage2Rect.Right() = RECT_EMPTY; + maPage2Rect.SetWidthEmpty(); else { maPage2Rect.Left() = maThumbRect.Right()+1; @@ -147,11 +147,11 @@ void ScrollBar::ImplUpdateRects( bool bUpdate ) maThumbRect.Top() = maTrackRect.Top()+mnThumbPixPos; maThumbRect.Bottom() = maThumbRect.Top()+mnThumbPixSize-1; if ( !mnThumbPixPos ) - maPage1Rect.Bottom() = RECT_EMPTY; + maPage1Rect.SetHeightEmpty(); else maPage1Rect.Bottom() = maThumbRect.Top()-1; if ( mnThumbPixPos >= (mnThumbPixRange-mnThumbPixSize) ) - maPage2Rect.Bottom() = RECT_EMPTY; + maPage2Rect.SetHeightEmpty(); else { maPage2Rect.Top() = maThumbRect.Bottom()+1; |