merge the formfield patch from ooo-build
[ooovba.git] / sw / inc / swrect.hxx
blob136eff09224e925ff394425ed75145997d16f564
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: swrect.hxx,v $
10 * $Revision: 1.14 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef _SWRECT_HXX
31 #define _SWRECT_HXX
32 #include "errhdl.hxx"
33 #include <tools/gen.hxx>
34 class SvStream;
36 class SwRect
38 long nX;
39 long nY;
40 long nWidth;
41 long nHeight;
44 public:
45 inline SwRect();
46 inline SwRect( const SwRect &rRect );
47 inline SwRect( const Point& rLT, const Size& rSize );
48 inline SwRect( const Point& rLT, const Point& rRB );
49 inline SwRect( long X, long Y, long Width, long Height );
51 //SV-SS z.B. SwRect( pWin->GetClipRect() );
52 SwRect( const Rectangle &rRect );
54 //Set-Methoden
55 inline void Chg( const Point& rNP, const Size &rNS );
56 inline void Pos( const Point& rNew );
57 inline void Pos( const long nNewX, const long nNewY );
58 inline void SSize( const Size& rNew );
59 inline void SSize( const long nHeight, const long nWidth );
60 inline void Width( long nNew );
61 inline void Height( long nNew );
62 inline void Left( const long nLeft );
63 inline void Right( const long nRight );
64 inline void Top( const long nTop );
65 inline void Bottom( const long nBottom );
67 //Get-Methoden
68 inline const Point &Pos() const;
69 inline const Size &SSize() const;
70 inline long Width() const;
71 inline long Height() const;
72 inline long Left() const;
73 inline long Right() const;
74 inline long Top() const;
75 inline long Bottom() const;
77 //Damit Layoutseitig per Memberpointer auf die Member von Pos und SSize
78 //zugegriffen werden kann.
79 inline Point &Pos();
80 inline Size &SSize();
82 Point Center() const;
84 void Justify();
86 SwRect &Union( const SwRect& rRect );
87 SwRect &Intersection( const SwRect& rRect );
88 //Wie Intersection nur wird davon ausgegangen, dass die Rects ueberlappen!
89 SwRect &_Intersection( const SwRect &rRect );
90 inline SwRect GetIntersection( const SwRect& rRect ) const;
92 BOOL IsInside( const Point& rPOINT ) const;
93 BOOL IsNear(const Point& rPoint, long nTolerance ) const;
94 BOOL IsInside( const SwRect& rRect ) const;
95 BOOL IsOver( const SwRect& rRect ) const;
96 inline BOOL HasArea() const;
97 inline BOOL IsEmpty() const;
98 inline void Clear();
100 inline SwRect &operator = ( const SwRect &rRect );
102 inline BOOL operator == ( const SwRect& rRect ) const;
103 inline BOOL operator != ( const SwRect& rRect ) const;
105 inline SwRect &operator+=( const Point &rPt );
106 inline SwRect &operator-=( const Point &rPt );
108 inline SwRect &operator+=( const Size &rSz );
109 inline SwRect &operator-=( const Size &rSz );
111 //SV-SS z.B. pWin->DrawRect( aSwRect.SVRect() );
112 inline Rectangle SVRect() const;
114 //Zortech wuerde hier fehlerhaften Code erzeugen.
115 // inline operator SRectangle() const;
116 // inline operator Rectangle() const { return Rectangle( aPos, aSize ); }
118 // Ausgabeoperator fuer die Debugging-Gemeinde
119 friend SvStream &operator<<( SvStream &rStream, const SwRect &rRect );
122 void _Top( const long nTop );
123 void _Bottom( const long nBottom );
124 void _Left( const long nLeft );
125 void _Right( const long nRight );
126 void _Width( const long nNew );
127 void _Height( const long nNew );
128 long _Top() const;
129 long _Bottom() const;
130 long _Left() const;
131 long _Right() const;
132 long _Width() const;
133 long _Height() const;
134 void SubTop( const long nSub );
135 void AddBottom( const long nAdd );
136 void SubLeft( const long nSub );
137 void AddRight( const long nAdd );
138 void AddWidth( const long nAdd );
139 void AddHeight( const long nAdd );
140 void SetPosX( const long nNew );
141 void SetPosY( const long nNew );
142 void SetLeftAndWidth( long nLeft, long nNew );
143 void SetTopAndHeight( long nTop, long nNew );
144 void SetRightAndWidth( long nRight, long nNew );
145 void SetBottomAndHeight( long nBottom, long nNew );
146 void SetUpperLeftCorner( const Point& rNew );
147 void SetUpperRightCorner( const Point& rNew );
148 void SetLowerLeftCorner( const Point& rNew );
149 const Size _Size() const;
150 const Point TopLeft() const;
151 const Point TopRight() const;
152 const Point BottomLeft() const;
153 const Point BottomRight() const;
154 const Size SwappedSize() const;
155 long GetLeftDistance( long ) const;
156 long GetBottomDistance( long ) const;
157 long GetRightDistance( long ) const;
158 long GetTopDistance( long ) const;
159 BOOL OverStepLeft( long ) const;
160 BOOL OverStepBottom( long ) const;
161 BOOL OverStepTop( long ) const;
162 BOOL OverStepRight( long ) const;
165 // Implementation in in swrect.cxx
166 extern SvStream &operator<<( SvStream &rStream, const SwRect &rRect );
168 typedef void (SwRect:: *SwRectSet)( const long nNew );
169 typedef long (SwRect:: *SwRectGet)() const;
170 typedef const Point (SwRect:: *SwRectPoint)() const;
171 typedef const Size (SwRect:: *SwRectSize)() const;
172 typedef BOOL (SwRect:: *SwRectMax)( long ) const;
173 typedef long (SwRect:: *SwRectDist)( long ) const;
174 typedef void (SwRect:: *SwRectSetTwice)( long, long );
175 typedef void (SwRect:: *SwRectSetPos)( const Point& );
177 //---------------------------------- Set-Methoden
178 inline void SwRect::Chg( const Point& rNP, const Size &rNS )
180 nX = rNP.X(); nY = rNP.Y();
181 nWidth = rNS.Width(); nHeight = rNS.Height();
183 inline void SwRect::Pos( const Point& rNew )
185 nX = rNew.X(); nY = rNew.Y();
187 inline void SwRect::Pos( const long nNewX, const long nNewY )
189 nX = nNewX; nY = nNewY;
191 inline void SwRect::SSize( const Size& rNew )
193 nWidth = rNew.Width(); nHeight = rNew.Height();
195 inline void SwRect::SSize( const long nNewHeight, const long nNewWidth )
197 nWidth = nNewWidth; nHeight = nNewHeight;
199 inline void SwRect::Width( long nNew )
201 nWidth = nNew;
203 inline void SwRect::Height( long nNew )
205 nHeight = nNew;
207 inline void SwRect::Left( const long nLeft )
209 nWidth += nX - nLeft;
210 nX = nLeft;
212 inline void SwRect::Right( const long nRight )
214 nWidth = nRight - nX + 1;
216 inline void SwRect::Top( const long nTop )
218 nHeight += nY - nTop;
219 nY = nTop;
221 inline void SwRect::Bottom( const long nBottom )
223 nHeight = nBottom - nY + 1;
226 //----------------------------------- Get-Methoden
227 inline const Point &SwRect::Pos() const
229 return *(Point*)(&nX);
231 inline Point &SwRect::Pos()
233 return *(Point*)(&nX);
235 inline const Size &SwRect::SSize() const
237 return *(Size*)(&nWidth);
239 inline Size &SwRect::SSize()
241 return *(Size*)(&nWidth);
243 inline long SwRect::Width() const
245 return nWidth;
247 inline long SwRect::Height() const
249 return nHeight;
251 inline long SwRect::Left() const
253 return nX;
255 inline long SwRect::Right() const
257 return nWidth ? nX + nWidth - 1 : nX;
259 inline long SwRect::Top() const
261 return nY;
263 inline long SwRect::Bottom() const
265 return nHeight ? nY + nHeight - 1 : nY;
268 //----------------------------------- operatoren
269 inline SwRect &SwRect::operator = ( const SwRect &rRect )
271 nX = rRect.Left();
272 nY = rRect.Top();
273 nWidth = rRect.Width();
274 nHeight = rRect.Height();
275 return *this;
277 inline BOOL SwRect::operator == ( const SwRect& rRect ) const
279 return (nX == rRect.Left() &&
280 nY == rRect.Top() &&
281 nWidth == rRect.Width() &&
282 nHeight == rRect.Height());
284 inline BOOL SwRect::operator != ( const SwRect& rRect ) const
286 return (nX != rRect.Left() ||
287 nY != rRect.Top() ||
288 nWidth != rRect.Width() ||
289 nHeight != rRect.Height());
292 inline SwRect &SwRect::operator+=( const Point &rPt )
294 nX += rPt.X(); nY += rPt.Y();
295 return *this;
297 inline SwRect &SwRect::operator-=( const Point &rPt )
299 nX -= rPt.X(); nY -= rPt.Y();
300 return *this;
303 inline SwRect &SwRect::operator+=( const Size &rSz )
305 nWidth += rSz.Width(); nHeight += rSz.Height();
306 return *this;
308 inline SwRect &SwRect::operator-=( const Size &rSz )
310 nWidth -= rSz.Width(); nHeight -= rSz.Height();
311 return *this;
315 //--------------------------- Sonstiges
316 inline Rectangle SwRect::SVRect() const
318 ASSERT( nWidth && nHeight, "SVRect() ohne Widht oder Height" );
319 return Rectangle( nX, nY,
320 nX + nWidth - 1, //Right()
321 nY + nHeight - 1 ); //Bottom()
324 inline SwRect SwRect::GetIntersection( const SwRect& rRect ) const
326 return SwRect( *this ).Intersection( rRect );
329 inline BOOL SwRect::HasArea() const
331 return nHeight && nWidth;
333 inline BOOL SwRect::IsEmpty() const
335 return !(nHeight && nWidth);
337 inline void SwRect::Clear()
339 nX = nY = nWidth = nHeight = 0;
342 //-------------------------- CToren
343 inline SwRect::SwRect() :
344 nX( 0 ),
345 nY( 0 ),
346 nWidth ( 0 ),
347 nHeight( 0 )
350 inline SwRect::SwRect( const SwRect &rRect ) :
351 nX( rRect.Left() ),
352 nY( rRect.Top() ),
353 nWidth ( rRect.Width() ),
354 nHeight( rRect.Height() )
357 inline SwRect::SwRect( const Point& rLT, const Size& rSize ) :
358 nX( rLT.X() ),
359 nY( rLT.Y() ),
360 nWidth ( rSize.Width() ),
361 nHeight( rSize.Height())
364 inline SwRect::SwRect( const Point& rLT, const Point& rRB ) :
365 nX( rLT.X() ),
366 nY( rLT.Y() ),
367 nWidth ( rRB.X() - rLT.X() + 1 ),
368 nHeight( rRB.Y() - rLT.Y() + 1 )
371 inline SwRect::SwRect( long X, long Y, long W, long H ) :
372 nX( X ),
373 nY( Y ),
374 nWidth ( W ),
375 nHeight( H )
380 #endif //_SWRECT_HXX