Kaydet (Commit) 5ab1b4f9 authored tarafından Noel Grandin's avatar Noel Grandin

make RECT_EMPTY purely an implementation detail

and make outside code use the IsEmpty/SetEmpty methods

Change-Id: I4821d1bdceb99bb6a837a85ff2131003f9a160a5
Reviewed-on: https://gerrit.libreoffice.org/48584Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 6e641f93
......@@ -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() );
}
}
......
......@@ -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; }
......
......@@ -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());
......
......@@ -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
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment