Update ooo320-m1
[ooovba.git] / binfilter / inc / bf_sw / swrect.hxx
blob955e6382544668baccde479fc5b321d4a1457f3e
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.5 $
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
33 #include "errhdl.hxx"
35 #ifndef _GEN_HXX //autogen
36 #include <tools/gen.hxx>
37 #endif
38 class SvStream;
39 namespace binfilter {
42 class SwRect
44 long nX;
45 long nY;
46 long nWidth;
47 long nHeight;
50 public:
51 inline SwRect();
52 inline SwRect( const SwRect &rRect );
53 inline SwRect( const Point& rLT, const Size& rSize );
54 inline SwRect( const Point& rLT, const Point& rRB );
55 inline SwRect( long X, long Y, long Width, long Height );
57 //SV-SS z.B. SwRect( pWin->GetClipRect() );
58 SwRect( const Rectangle &rRect );
60 //Set-Methoden
61 inline void Chg( const Point& rNP, const Size &rNS );
62 inline void Pos( const Point& rNew );
63 inline void Pos( const long nNewX, const long nNewY );
64 inline void SSize( const Size& rNew );
65 inline void SSize( const long nHeight, const long nWidth );
66 inline void Width( long nNew );
67 inline void Height( long nNew );
68 inline void Left( const long nLeft );
69 inline void Right( const long nRight );
70 inline void Top( const long nTop );
71 inline void Bottom( const long nBottom );
73 //Get-Methoden
74 inline const Point &Pos() const;
75 inline const Size &SSize() const;
76 inline long Width() const;
77 inline long Height() const;
78 inline long Left() const;
79 inline long Right() const;
80 inline long Top() const;
81 inline long Bottom() const;
83 //Damit Layoutseitig per Memberpointer auf die Member von Pos und SSize
84 //zugegriffen werden kann.
85 inline Point &Pos();
86 inline Size &SSize();
88 Point Center() const;
90 void Justify();
92 SwRect &Union( const SwRect& rRect );
93 SwRect &Intersection( const SwRect& rRect );
94 //Wie Intersection nur wird davon ausgegangen, dass die Rects ueberlappen!
95 SwRect &_Intersection( const SwRect &rRect );
96 inline SwRect GetUnion( const SwRect& rRect ) const;
97 inline SwRect GetIntersection( const SwRect& rRect ) const;
99 BOOL IsInside( const Point& rPOINT ) const;
100 BOOL IsInside( const SwRect& rRect ) const;
101 BOOL IsOver( const SwRect& rRect ) const;
102 inline BOOL HasArea() const;
103 inline BOOL IsEmpty() const;
104 inline void Clear();
106 inline SwRect &operator = ( const SwRect &rRect );
108 inline BOOL operator == ( const SwRect& rRect ) const;
109 inline BOOL operator != ( const SwRect& rRect ) const;
111 inline SwRect &operator+=( const Point &rPt );
112 inline SwRect &operator-=( const Point &rPt );
114 inline SwRect &operator+=( const Size &rSz );
115 inline SwRect &operator-=( const Size &rSz );
117 //SV-SS z.B. pWin->DrawRect( aSwRect.SVRect() );
118 inline Rectangle SVRect() const;
120 //Zortech wuerde hier fehlerhaften Code erzeugen.
121 // inline operator SRectangle() const;
122 // inline operator Rectangle() const { return Rectangle( aPos, aSize ); }
124 // Ausgabeoperator fuer die Debugging-Gemeinde
127 #ifdef VERTICAL_LAYOUT
128 void _Top( const long nTop );
129 void _Bottom( const long nBottom );
130 void _Left( const long nLeft );
131 void _Right( const long nRight );
132 void _Width( const long nNew );
133 void _Height( const long nNew );
134 long _Top() const;
135 long _Bottom() const;
136 long _Left() const;
137 long _Right() const;
138 long _Width() const;
139 long _Height() const;
140 void SubTop( const long nSub );
141 void AddBottom( const long nAdd );
142 void SubLeft( const long nSub );
143 void AddRight( const long nAdd );
144 void AddWidth( const long nAdd );
145 void AddHeight( const long nAdd );
146 void SetPosX( const long nNew );
147 void SetPosY( const long nNew );
148 void SetLeftAndWidth( long nLeft, long nNew );
149 void SetTopAndHeight( long nTop, long nNew );
150 void SetRightAndWidth( long nRight, long nNew );
151 void SetBottomAndHeight( long nBottom, long nNew );
152 void SetUpperLeftCorner( const Point& rNew );
153 void SetUpperRightCorner( const Point& rNew );
154 void SetLowerLeftCorner( const Point& rNew );
155 const Size _Size() const;
156 const Point TopLeft() const;
157 const Point TopRight() const;
158 const Point BottomLeft() const;
159 const Point BottomRight() const;
160 const Size SwappedSize() const;
161 long GetLeftDistance( long ) const;
162 long GetBottomDistance( long ) const;
163 long GetRightDistance( long ) const;
164 long GetTopDistance( long ) const;
165 BOOL OverStepLeft( long ) const;
166 BOOL OverStepBottom( long ) const;
167 BOOL OverStepTop( long ) const;
168 BOOL OverStepRight( long ) const;
169 #endif
172 // Implementation in in swrect.cxx
173 extern SvStream &operator<<( SvStream &rStream, const SwRect &rRect );
175 #ifdef VERTICAL_LAYOUT
176 typedef void (SwRect:: *SwRectSet)( const long nNew );
177 typedef long (SwRect:: *SwRectGet)() const;
178 typedef const Point (SwRect:: *SwRectPoint)() const;
179 typedef const Size (SwRect:: *SwRectSize)() const;
180 typedef BOOL (SwRect:: *SwRectMax)( long ) const;
181 typedef long (SwRect:: *SwRectDist)( long ) const;
182 typedef void (SwRect:: *SwRectSetTwice)( long, long );
183 typedef void (SwRect:: *SwRectSetPos)( const Point& );
184 #endif
186 //---------------------------------- Set-Methoden
187 inline void SwRect::Chg( const Point& rNP, const Size &rNS )
189 nX = rNP.X(); nY = rNP.Y();
190 nWidth = rNS.Width(); nHeight = rNS.Height();
192 inline void SwRect::Pos( const Point& rNew )
194 nX = rNew.X(); nY = rNew.Y();
196 inline void SwRect::Pos( const long nNewX, const long nNewY )
198 nX = nNewX; nY = nNewY;
200 inline void SwRect::SSize( const Size& rNew )
202 nWidth = rNew.Width(); nHeight = rNew.Height();
204 inline void SwRect::SSize( const long nNewHeight, const long nNewWidth )
206 nWidth = nNewWidth; nHeight = nNewHeight;
208 inline void SwRect::Width( long nNew )
210 nWidth = nNew;
212 inline void SwRect::Height( long nNew )
214 nHeight = nNew;
216 inline void SwRect::Left( const long nLeft )
218 nWidth += nX - nLeft;
219 nX = nLeft;
221 inline void SwRect::Right( const long nRight )
223 nWidth = nRight - nX + 1;
225 inline void SwRect::Top( const long nTop )
227 nHeight += nY - nTop;
228 nY = nTop;
230 inline void SwRect::Bottom( const long nBottom )
232 nHeight = nBottom - nY + 1;
235 //----------------------------------- Get-Methoden
236 inline const Point &SwRect::Pos() const
238 return *(Point*)(&nX);
240 inline Point &SwRect::Pos()
242 return *(Point*)(&nX);
244 inline const Size &SwRect::SSize() const
246 return *(Size*)(&nWidth);
248 inline Size &SwRect::SSize()
250 return *(Size*)(&nWidth);
252 inline long SwRect::Width() const
254 return nWidth;
256 inline long SwRect::Height() const
258 return nHeight;
260 inline long SwRect::Left() const
262 return nX;
264 inline long SwRect::Right() const
266 return nWidth ? nX + nWidth - 1 : nX;
268 inline long SwRect::Top() const
270 return nY;
272 inline long SwRect::Bottom() const
274 return nHeight ? nY + nHeight - 1 : nY;
277 //----------------------------------- operatoren
278 inline SwRect &SwRect::operator = ( const SwRect &rRect )
280 nX = rRect.Left();
281 nY = rRect.Top();
282 nWidth = rRect.Width();
283 nHeight = rRect.Height();
284 return *this;
286 inline BOOL SwRect::operator == ( const SwRect& rRect ) const
288 return (nX == rRect.Left() &&
289 nY == rRect.Top() &&
290 nWidth == rRect.Width() &&
291 nHeight == rRect.Height());
293 inline BOOL SwRect::operator != ( const SwRect& rRect ) const
295 return (nX != rRect.Left() ||
296 nY != rRect.Top() ||
297 nWidth != rRect.Width() ||
298 nHeight != rRect.Height());
301 inline SwRect &SwRect::operator+=( const Point &rPt )
303 nX += rPt.X(); nY += rPt.Y();
304 return *this;
306 inline SwRect &SwRect::operator-=( const Point &rPt )
308 nX -= rPt.X(); nY -= rPt.Y();
309 return *this;
312 inline SwRect &SwRect::operator+=( const Size &rSz )
314 nWidth += rSz.Width(); nHeight += rSz.Height();
315 return *this;
317 inline SwRect &SwRect::operator-=( const Size &rSz )
319 nWidth -= rSz.Width(); nHeight -= rSz.Height();
320 return *this;
324 //--------------------------- Sonstiges
325 inline Rectangle SwRect::SVRect() const
327 ASSERT( nWidth && nHeight, "SVRect() ohne Widht oder Height" );
328 return Rectangle( nX, nY,
329 nX + nWidth - 1, //Right()
330 nY + nHeight - 1 ); //Bottom()
333 inline SwRect SwRect::GetUnion( const SwRect& rRect ) const
335 return SwRect( *this ).Union( rRect );
337 inline SwRect SwRect::GetIntersection( const SwRect& rRect ) const
339 return SwRect( *this ).Intersection( rRect );
342 inline BOOL SwRect::HasArea() const
344 return nHeight && nWidth;
346 inline BOOL SwRect::IsEmpty() const
348 return !(nHeight && nWidth);
350 inline void SwRect::Clear()
352 nX = nY = nWidth = nHeight = 0;
355 //-------------------------- CToren
356 inline SwRect::SwRect() :
357 nX( 0 ),
358 nY( 0 ),
359 nWidth ( 0 ),
360 nHeight( 0 )
363 inline SwRect::SwRect( const SwRect &rRect ) :
364 nX( rRect.Left() ),
365 nY( rRect.Top() ),
366 nWidth ( rRect.Width() ),
367 nHeight( rRect.Height() )
370 inline SwRect::SwRect( const Point& rLT, const Size& rSize ) :
371 nX( rLT.X() ),
372 nY( rLT.Y() ),
373 nWidth ( rSize.Width() ),
374 nHeight( rSize.Height())
377 inline SwRect::SwRect( const Point& rLT, const Point& rRB ) :
378 nX( rLT.X() ),
379 nY( rLT.Y() ),
380 nWidth ( rRB.X() - rLT.X() + 1 ),
381 nHeight( rRB.Y() - rLT.Y() + 1 )
384 inline SwRect::SwRect( long X, long Y, long Width, long Height ) :
385 nX( X ),
386 nY( Y ),
387 nWidth ( Width ),
388 nHeight( Height )
393 } //namespace binfilter
394 #endif //_SWRECT_HXX