1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir #ifndef _SWRECT_HXX 28*cdf0e10cSrcweir #define _SWRECT_HXX 29*cdf0e10cSrcweir #include "errhdl.hxx" 30*cdf0e10cSrcweir #include <tools/gen.hxx> 31*cdf0e10cSrcweir class SvStream; 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir class SwRect 34*cdf0e10cSrcweir { 35*cdf0e10cSrcweir Point m_Point; 36*cdf0e10cSrcweir Size m_Size; 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir public: 40*cdf0e10cSrcweir inline SwRect(); 41*cdf0e10cSrcweir inline SwRect( const SwRect &rRect ); 42*cdf0e10cSrcweir inline SwRect( const Point& rLT, const Size& rSize ); 43*cdf0e10cSrcweir inline SwRect( const Point& rLT, const Point& rRB ); 44*cdf0e10cSrcweir inline SwRect( long X, long Y, long Width, long Height ); 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir //SV-SS z.B. SwRect( pWin->GetClipRect() ); 47*cdf0e10cSrcweir SwRect( const Rectangle &rRect ); 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir //Set-Methoden 50*cdf0e10cSrcweir inline void Chg( const Point& rNP, const Size &rNS ); 51*cdf0e10cSrcweir inline void Pos( const Point& rNew ); 52*cdf0e10cSrcweir inline void Pos( const long nNewX, const long nNewY ); 53*cdf0e10cSrcweir inline void SSize( const Size& rNew ); 54*cdf0e10cSrcweir inline void SSize( const long nHeight, const long nWidth ); 55*cdf0e10cSrcweir inline void Width( long nNew ); 56*cdf0e10cSrcweir inline void Height( long nNew ); 57*cdf0e10cSrcweir inline void Left( const long nLeft ); 58*cdf0e10cSrcweir inline void Right( const long nRight ); 59*cdf0e10cSrcweir inline void Top( const long nTop ); 60*cdf0e10cSrcweir inline void Bottom( const long nBottom ); 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir //Get-Methoden 63*cdf0e10cSrcweir inline const Point &Pos() const; 64*cdf0e10cSrcweir inline const Size &SSize() const; 65*cdf0e10cSrcweir inline long Width() const; 66*cdf0e10cSrcweir inline long Height() const; 67*cdf0e10cSrcweir inline long Left() const; 68*cdf0e10cSrcweir inline long Right() const; 69*cdf0e10cSrcweir inline long Top() const; 70*cdf0e10cSrcweir inline long Bottom() const; 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir //Damit Layoutseitig per Memberpointer auf die Member von Pos und SSize 73*cdf0e10cSrcweir //zugegriffen werden kann. 74*cdf0e10cSrcweir inline Point &Pos(); 75*cdf0e10cSrcweir inline Size &SSize(); 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir Point Center() const; 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir void Justify(); 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir SwRect &Union( const SwRect& rRect ); 82*cdf0e10cSrcweir SwRect &Intersection( const SwRect& rRect ); 83*cdf0e10cSrcweir //Wie Intersection nur wird davon ausgegangen, dass die Rects ueberlappen! 84*cdf0e10cSrcweir SwRect &_Intersection( const SwRect &rRect ); 85*cdf0e10cSrcweir inline SwRect GetIntersection( const SwRect& rRect ) const; 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir sal_Bool IsInside( const Point& rPOINT ) const; 88*cdf0e10cSrcweir sal_Bool IsNear(const Point& rPoint, long nTolerance ) const; 89*cdf0e10cSrcweir sal_Bool IsInside( const SwRect& rRect ) const; 90*cdf0e10cSrcweir sal_Bool IsOver( const SwRect& rRect ) const; 91*cdf0e10cSrcweir inline sal_Bool HasArea() const; 92*cdf0e10cSrcweir inline sal_Bool IsEmpty() const; 93*cdf0e10cSrcweir inline void Clear(); 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir inline SwRect &operator = ( const SwRect &rRect ); 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir inline sal_Bool operator == ( const SwRect& rRect ) const; 98*cdf0e10cSrcweir inline sal_Bool operator != ( const SwRect& rRect ) const; 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir inline SwRect &operator+=( const Point &rPt ); 101*cdf0e10cSrcweir inline SwRect &operator-=( const Point &rPt ); 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir inline SwRect &operator+=( const Size &rSz ); 104*cdf0e10cSrcweir inline SwRect &operator-=( const Size &rSz ); 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir //SV-SS z.B. pWin->DrawRect( aSwRect.SVRect() ); 107*cdf0e10cSrcweir inline Rectangle SVRect() const; 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir //Zortech wuerde hier fehlerhaften Code erzeugen. 110*cdf0e10cSrcweir // inline operator SRectangle() const; 111*cdf0e10cSrcweir // inline operator Rectangle() const { return Rectangle( aPos, aSize ); } 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir // Ausgabeoperator fuer die Debugging-Gemeinde 114*cdf0e10cSrcweir friend SvStream &operator<<( SvStream &rStream, const SwRect &rRect ); 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir void _Top( const long nTop ); 118*cdf0e10cSrcweir void _Bottom( const long nBottom ); 119*cdf0e10cSrcweir void _Left( const long nLeft ); 120*cdf0e10cSrcweir void _Right( const long nRight ); 121*cdf0e10cSrcweir void _Width( const long nNew ); 122*cdf0e10cSrcweir void _Height( const long nNew ); 123*cdf0e10cSrcweir long _Top() const; 124*cdf0e10cSrcweir long _Bottom() const; 125*cdf0e10cSrcweir long _Left() const; 126*cdf0e10cSrcweir long _Right() const; 127*cdf0e10cSrcweir long _Width() const; 128*cdf0e10cSrcweir long _Height() const; 129*cdf0e10cSrcweir void SubTop( const long nSub ); 130*cdf0e10cSrcweir void AddBottom( const long nAdd ); 131*cdf0e10cSrcweir void SubLeft( const long nSub ); 132*cdf0e10cSrcweir void AddRight( const long nAdd ); 133*cdf0e10cSrcweir void AddWidth( const long nAdd ); 134*cdf0e10cSrcweir void AddHeight( const long nAdd ); 135*cdf0e10cSrcweir void SetPosX( const long nNew ); 136*cdf0e10cSrcweir void SetPosY( const long nNew ); 137*cdf0e10cSrcweir void SetLeftAndWidth( long nLeft, long nNew ); 138*cdf0e10cSrcweir void SetTopAndHeight( long nTop, long nNew ); 139*cdf0e10cSrcweir void SetRightAndWidth( long nRight, long nNew ); 140*cdf0e10cSrcweir void SetBottomAndHeight( long nBottom, long nNew ); 141*cdf0e10cSrcweir void SetUpperLeftCorner( const Point& rNew ); 142*cdf0e10cSrcweir void SetUpperRightCorner( const Point& rNew ); 143*cdf0e10cSrcweir void SetLowerLeftCorner( const Point& rNew ); 144*cdf0e10cSrcweir const Size _Size() const; 145*cdf0e10cSrcweir const Point TopLeft() const; 146*cdf0e10cSrcweir const Point TopRight() const; 147*cdf0e10cSrcweir const Point BottomLeft() const; 148*cdf0e10cSrcweir const Point BottomRight() const; 149*cdf0e10cSrcweir const Size SwappedSize() const; 150*cdf0e10cSrcweir long GetLeftDistance( long ) const; 151*cdf0e10cSrcweir long GetBottomDistance( long ) const; 152*cdf0e10cSrcweir long GetRightDistance( long ) const; 153*cdf0e10cSrcweir long GetTopDistance( long ) const; 154*cdf0e10cSrcweir sal_Bool OverStepLeft( long ) const; 155*cdf0e10cSrcweir sal_Bool OverStepBottom( long ) const; 156*cdf0e10cSrcweir sal_Bool OverStepTop( long ) const; 157*cdf0e10cSrcweir sal_Bool OverStepRight( long ) const; 158*cdf0e10cSrcweir }; 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir // Implementation in in swrect.cxx 161*cdf0e10cSrcweir extern SvStream &operator<<( SvStream &rStream, const SwRect &rRect ); 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir typedef void (SwRect:: *SwRectSet)( const long nNew ); 164*cdf0e10cSrcweir typedef long (SwRect:: *SwRectGet)() const; 165*cdf0e10cSrcweir typedef const Point (SwRect:: *SwRectPoint)() const; 166*cdf0e10cSrcweir typedef const Size (SwRect:: *SwRectSize)() const; 167*cdf0e10cSrcweir typedef sal_Bool (SwRect:: *SwRectMax)( long ) const; 168*cdf0e10cSrcweir typedef long (SwRect:: *SwRectDist)( long ) const; 169*cdf0e10cSrcweir typedef void (SwRect:: *SwRectSetTwice)( long, long ); 170*cdf0e10cSrcweir typedef void (SwRect:: *SwRectSetPos)( const Point& ); 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir //---------------------------------- Set-Methoden 173*cdf0e10cSrcweir inline void SwRect::Chg( const Point& rNP, const Size &rNS ) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir m_Point = rNP; 176*cdf0e10cSrcweir m_Size = rNS; 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir inline void SwRect::Pos( const Point& rNew ) 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir m_Point = rNew; 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir inline void SwRect::Pos( const long nNewX, const long nNewY ) 183*cdf0e10cSrcweir { 184*cdf0e10cSrcweir m_Point.setX(nNewX); 185*cdf0e10cSrcweir m_Point.setY(nNewY); 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir inline void SwRect::SSize( const Size& rNew ) 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir m_Size = rNew; 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir inline void SwRect::SSize( const long nNewHeight, const long nNewWidth ) 192*cdf0e10cSrcweir { 193*cdf0e10cSrcweir m_Size.setWidth(nNewWidth); 194*cdf0e10cSrcweir m_Size.setHeight(nNewHeight); 195*cdf0e10cSrcweir } 196*cdf0e10cSrcweir inline void SwRect::Width( long nNew ) 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir m_Size.setWidth(nNew); 199*cdf0e10cSrcweir } 200*cdf0e10cSrcweir inline void SwRect::Height( long nNew ) 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir m_Size.setHeight(nNew); 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir inline void SwRect::Left( const long nLeft ) 205*cdf0e10cSrcweir { 206*cdf0e10cSrcweir m_Size.Width() += m_Point.getX() - nLeft; 207*cdf0e10cSrcweir m_Point.setX(nLeft); 208*cdf0e10cSrcweir } 209*cdf0e10cSrcweir inline void SwRect::Right( const long nRight ) 210*cdf0e10cSrcweir { 211*cdf0e10cSrcweir m_Size.setWidth(nRight - m_Point.getX() + 1); 212*cdf0e10cSrcweir } 213*cdf0e10cSrcweir inline void SwRect::Top( const long nTop ) 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir m_Size.Height() += m_Point.getY() - nTop; 216*cdf0e10cSrcweir m_Point.setY(nTop); 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir inline void SwRect::Bottom( const long nBottom ) 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir m_Size.setHeight(nBottom - m_Point.getY() + 1); 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir //----------------------------------- Get-Methoden 224*cdf0e10cSrcweir inline const Point &SwRect::Pos() const 225*cdf0e10cSrcweir { 226*cdf0e10cSrcweir return m_Point; 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir inline Point &SwRect::Pos() 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir return m_Point; 231*cdf0e10cSrcweir } 232*cdf0e10cSrcweir inline const Size &SwRect::SSize() const 233*cdf0e10cSrcweir { 234*cdf0e10cSrcweir return m_Size; 235*cdf0e10cSrcweir } 236*cdf0e10cSrcweir inline Size &SwRect::SSize() 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir return m_Size; 239*cdf0e10cSrcweir } 240*cdf0e10cSrcweir inline long SwRect::Width() const 241*cdf0e10cSrcweir { 242*cdf0e10cSrcweir return m_Size.Width(); 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir inline long SwRect::Height() const 245*cdf0e10cSrcweir { 246*cdf0e10cSrcweir return m_Size.Height(); 247*cdf0e10cSrcweir } 248*cdf0e10cSrcweir inline long SwRect::Left() const 249*cdf0e10cSrcweir { 250*cdf0e10cSrcweir return m_Point.X(); 251*cdf0e10cSrcweir } 252*cdf0e10cSrcweir inline long SwRect::Right() const 253*cdf0e10cSrcweir { 254*cdf0e10cSrcweir return m_Size.getWidth() ? m_Point.getX() + m_Size.getWidth() - 1 : m_Point.getX(); 255*cdf0e10cSrcweir } 256*cdf0e10cSrcweir inline long SwRect::Top() const 257*cdf0e10cSrcweir { 258*cdf0e10cSrcweir return m_Point.Y(); 259*cdf0e10cSrcweir } 260*cdf0e10cSrcweir inline long SwRect::Bottom() const 261*cdf0e10cSrcweir { 262*cdf0e10cSrcweir return m_Size.getHeight() ? m_Point.getY() + m_Size.getHeight() - 1 : m_Point.getY(); 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir //----------------------------------- operatoren 266*cdf0e10cSrcweir inline SwRect &SwRect::operator = ( const SwRect &rRect ) 267*cdf0e10cSrcweir { 268*cdf0e10cSrcweir m_Point = rRect.m_Point; 269*cdf0e10cSrcweir m_Size = rRect.m_Size; 270*cdf0e10cSrcweir return *this; 271*cdf0e10cSrcweir } 272*cdf0e10cSrcweir inline sal_Bool SwRect::operator == ( const SwRect& rRect ) const 273*cdf0e10cSrcweir { 274*cdf0e10cSrcweir return (m_Point == rRect.m_Point && m_Size == rRect.m_Size); 275*cdf0e10cSrcweir } 276*cdf0e10cSrcweir inline sal_Bool SwRect::operator != ( const SwRect& rRect ) const 277*cdf0e10cSrcweir { 278*cdf0e10cSrcweir return (m_Point != rRect.m_Point || m_Size != rRect.m_Size); 279*cdf0e10cSrcweir } 280*cdf0e10cSrcweir 281*cdf0e10cSrcweir inline SwRect &SwRect::operator+=( const Point &rPt ) 282*cdf0e10cSrcweir { 283*cdf0e10cSrcweir m_Point += rPt; 284*cdf0e10cSrcweir return *this; 285*cdf0e10cSrcweir } 286*cdf0e10cSrcweir inline SwRect &SwRect::operator-=( const Point &rPt ) 287*cdf0e10cSrcweir { 288*cdf0e10cSrcweir m_Point -= rPt; 289*cdf0e10cSrcweir return *this; 290*cdf0e10cSrcweir } 291*cdf0e10cSrcweir 292*cdf0e10cSrcweir inline SwRect &SwRect::operator+=( const Size &rSz ) 293*cdf0e10cSrcweir { 294*cdf0e10cSrcweir m_Size.Width() += rSz.Width(); 295*cdf0e10cSrcweir m_Size.Height() += rSz.Height(); 296*cdf0e10cSrcweir return *this; 297*cdf0e10cSrcweir } 298*cdf0e10cSrcweir inline SwRect &SwRect::operator-=( const Size &rSz ) 299*cdf0e10cSrcweir { 300*cdf0e10cSrcweir m_Size.Width() -= rSz.Width(); 301*cdf0e10cSrcweir m_Size.Height() -= rSz.Height(); 302*cdf0e10cSrcweir return *this; 303*cdf0e10cSrcweir } 304*cdf0e10cSrcweir 305*cdf0e10cSrcweir 306*cdf0e10cSrcweir //--------------------------- Sonstiges 307*cdf0e10cSrcweir inline Rectangle SwRect::SVRect() const 308*cdf0e10cSrcweir { 309*cdf0e10cSrcweir ASSERT( !IsEmpty(), "SVRect() without Width or Height" ); 310*cdf0e10cSrcweir return Rectangle( m_Point.getX(), m_Point.getY(), 311*cdf0e10cSrcweir m_Point.getX() + m_Size.getWidth() - 1, //Right() 312*cdf0e10cSrcweir m_Point.getY() + m_Size.getHeight() - 1 ); //Bottom() 313*cdf0e10cSrcweir } 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir inline SwRect SwRect::GetIntersection( const SwRect& rRect ) const 316*cdf0e10cSrcweir { 317*cdf0e10cSrcweir return SwRect( *this ).Intersection( rRect ); 318*cdf0e10cSrcweir } 319*cdf0e10cSrcweir 320*cdf0e10cSrcweir inline sal_Bool SwRect::HasArea() const 321*cdf0e10cSrcweir { 322*cdf0e10cSrcweir return !IsEmpty(); 323*cdf0e10cSrcweir } 324*cdf0e10cSrcweir inline sal_Bool SwRect::IsEmpty() const 325*cdf0e10cSrcweir { 326*cdf0e10cSrcweir return !(m_Size.getHeight() && m_Size.getWidth()); 327*cdf0e10cSrcweir } 328*cdf0e10cSrcweir inline void SwRect::Clear() 329*cdf0e10cSrcweir { 330*cdf0e10cSrcweir m_Point.setX(0); 331*cdf0e10cSrcweir m_Point.setY(0); 332*cdf0e10cSrcweir m_Size.setWidth(0); 333*cdf0e10cSrcweir m_Size.setHeight(0); 334*cdf0e10cSrcweir } 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir //-------------------------- CToren 337*cdf0e10cSrcweir inline SwRect::SwRect() : 338*cdf0e10cSrcweir m_Point( 0, 0 ), 339*cdf0e10cSrcweir m_Size( 0, 0 ) 340*cdf0e10cSrcweir { 341*cdf0e10cSrcweir } 342*cdf0e10cSrcweir inline SwRect::SwRect( const SwRect &rRect ) : 343*cdf0e10cSrcweir m_Point( rRect.m_Point ), 344*cdf0e10cSrcweir m_Size( rRect.m_Size ) 345*cdf0e10cSrcweir { 346*cdf0e10cSrcweir } 347*cdf0e10cSrcweir inline SwRect::SwRect( const Point& rLT, const Size& rSize ) : 348*cdf0e10cSrcweir m_Point( rLT ), 349*cdf0e10cSrcweir m_Size( rSize ) 350*cdf0e10cSrcweir { 351*cdf0e10cSrcweir } 352*cdf0e10cSrcweir inline SwRect::SwRect( const Point& rLT, const Point& rRB ) : 353*cdf0e10cSrcweir m_Point( rLT ), 354*cdf0e10cSrcweir m_Size( rRB.X() - rLT.X() + 1, rRB.Y() - rLT.Y() + 1 ) 355*cdf0e10cSrcweir { 356*cdf0e10cSrcweir } 357*cdf0e10cSrcweir inline SwRect::SwRect( long X, long Y, long W, long H ) : 358*cdf0e10cSrcweir m_Point( X, Y ), 359*cdf0e10cSrcweir m_Size( W, H ) 360*cdf0e10cSrcweir { 361*cdf0e10cSrcweir } 362*cdf0e10cSrcweir 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir #endif //_SWRECT_HXX 365