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