xref: /aoo4110/main/sw/inc/swrect.hxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _SWRECT_HXX
24 #define _SWRECT_HXX
25 #include "errhdl.hxx"
26 #include <tools/gen.hxx>
27 class SvStream;
28 
29 class SwRect
30 {
31 	Point m_Point;
32 	Size m_Size;
33 
34 
35 public:
36 	inline SwRect();
37 	inline SwRect( const SwRect &rRect );
38 	inline SwRect( const Point& rLT, const Size&  rSize );
39 	inline SwRect( const Point& rLT, const Point& rRB );
40 	inline SwRect( long X, long Y, long Width, long Height );
41 
42 		//SV-SS z.B. SwRect( pWin->GetClipRect() );
43 	SwRect( const Rectangle &rRect );
44 
45 	//Set-Methoden
46 	inline void Chg( const Point& rNP, const Size &rNS );
47 	inline void Pos(  const Point& rNew );
48 	inline void Pos( const long nNewX, const long nNewY );
49 	inline void SSize( const Size&  rNew  );
50 	inline void SSize( const long nHeight, const long nWidth );
51 	inline void Width(  long nNew );
52 	inline void Height( long nNew );
53 	inline void Left( const long nLeft );
54 	inline void Right( const long nRight );
55 	inline void Top( const long nTop );
56 	inline void Bottom( const long nBottom );
57 
58 	//Get-Methoden
59 	inline const Point &Pos()  const;
60 	inline const Size  &SSize() const;
61 	inline long Width()  const;
62 	inline long Height() const;
63 	inline long Left()   const;
64 	inline long Right()  const;
65 	inline long Top()	 const;
66 	inline long Bottom() const;
67 
68 	//Damit Layoutseitig per Memberpointer auf die Member von Pos und SSize
69 	//zugegriffen werden kann.
70 	inline Point &Pos();
71 	inline Size  &SSize();
72 
73 	Point Center() const;
74 
75 	void Justify();
76 
77 		   SwRect &Union( const SwRect& rRect );
78 		   SwRect &Intersection( const SwRect& rRect );
79    //Wie Intersection nur wird davon ausgegangen, dass die Rects ueberlappen!
80 		   SwRect &_Intersection( const SwRect &rRect );
81     inline SwRect  GetIntersection( const SwRect& rRect ) const;
82 
83 		   sal_Bool IsInside( const Point& rPOINT ) const;
84 		   sal_Bool IsNear(const Point& rPoint, long nTolerance ) const;
85 		   sal_Bool IsInside( const SwRect& rRect ) const;
86 		   sal_Bool IsOver( const SwRect& rRect ) const;
87 	inline sal_Bool HasArea() const;
88 	inline sal_Bool IsEmpty() const;
89 	inline void Clear();
90 
91 	inline SwRect &operator = ( const SwRect &rRect );
92 
93 	inline sal_Bool operator == ( const SwRect& rRect ) const;
94 	inline sal_Bool operator != ( const SwRect& rRect ) const;
95 
96 	inline SwRect &operator+=( const Point &rPt );
97 	inline SwRect &operator-=( const Point &rPt );
98 
99 	inline SwRect &operator+=( const Size &rSz );
100 	inline SwRect &operator-=( const Size &rSz );
101 
102 	//SV-SS z.B. pWin->DrawRect( aSwRect.SVRect() );
103 	inline Rectangle  SVRect() const;
104 
105 	//Zortech wuerde hier fehlerhaften Code erzeugen.
106 //	inline operator SRectangle()  const;
107 //	inline operator Rectangle() const { return Rectangle( aPos, aSize ); }
108 
109 	// Ausgabeoperator fuer die Debugging-Gemeinde
110 	friend SvStream &operator<<( SvStream &rStream, const SwRect &rRect );
111 
112 
113     void _Top(      const long nTop );
114     void _Bottom(   const long nBottom );
115     void _Left(     const long nLeft );
116     void _Right(    const long nRight );
117     void _Width(    const long nNew );
118     void _Height(   const long nNew );
119     long _Top()     const;
120     long _Bottom()  const;
121     long _Left()    const;
122     long _Right()   const;
123     long _Width()   const;
124     long _Height()  const;
125     void SubTop(    const long nSub );
126     void AddBottom( const long nAdd );
127     void SubLeft(   const long nSub );
128     void AddRight(  const long nAdd );
129     void AddWidth(  const long nAdd );
130     void AddHeight( const long nAdd );
131     void SetPosX(   const long nNew );
132     void SetPosY(   const long nNew );
133     void SetLeftAndWidth( long nLeft, long nNew );
134     void SetTopAndHeight( long nTop, long nNew );
135     void SetRightAndWidth( long nRight, long nNew );
136     void SetBottomAndHeight( long nBottom, long nNew );
137     void SetUpperLeftCorner(  const Point& rNew );
138     void SetUpperRightCorner(  const Point& rNew );
139     void SetLowerLeftCorner(  const Point& rNew );
140     const Size  _Size() const;
141     const Point TopLeft()  const;
142     const Point TopRight()  const;
143     const Point BottomLeft()  const;
144     const Point BottomRight()  const;
145     const Size  SwappedSize() const;
146     long GetLeftDistance( long ) const;
147     long GetBottomDistance( long ) const;
148     long GetRightDistance( long ) const;
149     long GetTopDistance( long ) const;
150     sal_Bool OverStepLeft( long ) const;
151     sal_Bool OverStepBottom( long ) const;
152     sal_Bool OverStepTop( long ) const;
153     sal_Bool OverStepRight( long ) const;
154 };
155 
156 // Implementation in in swrect.cxx
157 extern SvStream &operator<<( SvStream &rStream, const SwRect &rRect );
158 
159 typedef void (SwRect:: *SwRectSet)( const long nNew );
160 typedef long (SwRect:: *SwRectGet)() const;
161 typedef const Point (SwRect:: *SwRectPoint)() const;
162 typedef const Size (SwRect:: *SwRectSize)() const;
163 typedef sal_Bool (SwRect:: *SwRectMax)( long ) const;
164 typedef long (SwRect:: *SwRectDist)( long ) const;
165 typedef void (SwRect:: *SwRectSetTwice)( long, long );
166 typedef void (SwRect:: *SwRectSetPos)( const Point& );
167 
168 //---------------------------------- Set-Methoden
Chg(const Point & rNP,const Size & rNS)169 inline void SwRect::Chg( const Point& rNP, const Size &rNS )
170 {
171 	m_Point = rNP;
172 	m_Size = rNS;
173 }
Pos(const Point & rNew)174 inline void SwRect::Pos(  const Point& rNew )
175 {
176 	m_Point = rNew;
177 }
Pos(const long nNewX,const long nNewY)178 inline void SwRect::Pos( const long nNewX, const long nNewY )
179 {
180 	m_Point.setX(nNewX);
181 	m_Point.setY(nNewY);
182 }
SSize(const Size & rNew)183 inline void SwRect::SSize( const Size&  rNew  )
184 {
185 	m_Size = rNew;
186 }
SSize(const long nNewHeight,const long nNewWidth)187 inline void SwRect::SSize( const long nNewHeight, const long nNewWidth )
188 {
189 	m_Size.setWidth(nNewWidth);
190 	m_Size.setHeight(nNewHeight);
191 }
Width(long nNew)192 inline void SwRect::Width(  long nNew )
193 {
194 	m_Size.setWidth(nNew);
195 }
Height(long nNew)196 inline void SwRect::Height( long nNew )
197 {
198 	m_Size.setHeight(nNew);
199 }
Left(const long nLeft)200 inline void SwRect::Left( const long nLeft )
201 {
202 	m_Size.Width() += m_Point.getX() - nLeft;
203 	m_Point.setX(nLeft);
204 }
Right(const long nRight)205 inline void SwRect::Right( const long nRight )
206 {
207 	m_Size.setWidth(nRight - m_Point.getX() + 1);
208 }
Top(const long nTop)209 inline void SwRect::Top( const long nTop )
210 {
211 	m_Size.Height() += m_Point.getY() - nTop;
212 	m_Point.setY(nTop);
213 }
Bottom(const long nBottom)214 inline void SwRect::Bottom( const long nBottom )
215 {
216 	m_Size.setHeight(nBottom - m_Point.getY() + 1);
217 }
218 
219 //----------------------------------- Get-Methoden
Pos() const220 inline const Point &SwRect::Pos()  const
221 {
222 	return m_Point;
223 }
Pos()224 inline Point &SwRect::Pos()
225 {
226 	return m_Point;
227 }
SSize() const228 inline const Size  &SwRect::SSize() const
229 {
230 	return m_Size;
231 }
SSize()232 inline Size  &SwRect::SSize()
233 {
234 	return m_Size;
235 }
Width() const236 inline long SwRect::Width()  const
237 {
238 	return m_Size.Width();
239 }
Height() const240 inline long SwRect::Height() const
241 {
242 	return m_Size.Height();
243 }
Left() const244 inline long SwRect::Left()   const
245 {
246 	return m_Point.X();
247 }
Right() const248 inline long SwRect::Right()  const
249 {
250 	return m_Size.getWidth() ? m_Point.getX() + m_Size.getWidth() - 1 : m_Point.getX();
251 }
Top() const252 inline long SwRect::Top()	 const
253 {
254 	return m_Point.Y();
255 }
Bottom() const256 inline long SwRect::Bottom() const
257 {
258 	return m_Size.getHeight() ? m_Point.getY() + m_Size.getHeight() - 1 : m_Point.getY();
259 }
260 
261 //----------------------------------- operatoren
operator =(const SwRect & rRect)262 inline SwRect &SwRect::operator = ( const SwRect &rRect )
263 {
264 	m_Point = rRect.m_Point;
265 	m_Size = rRect.m_Size;
266 	return *this;
267 }
operator ==(const SwRect & rRect) const268 inline sal_Bool SwRect::operator == ( const SwRect& rRect ) const
269 {
270 	return (m_Point == rRect.m_Point && m_Size == rRect.m_Size);
271 }
operator !=(const SwRect & rRect) const272 inline sal_Bool SwRect::operator != ( const SwRect& rRect ) const
273 {
274 	return (m_Point != rRect.m_Point || m_Size != rRect.m_Size);
275 }
276 
operator +=(const Point & rPt)277 inline SwRect &SwRect::operator+=( const Point &rPt )
278 {
279 	m_Point += rPt;
280 	return *this;
281 }
operator -=(const Point & rPt)282 inline SwRect &SwRect::operator-=( const Point &rPt )
283 {
284 	m_Point -= rPt;
285 	return *this;
286 }
287 
operator +=(const Size & rSz)288 inline SwRect &SwRect::operator+=( const Size &rSz )
289 {
290 	m_Size.Width() += rSz.Width();
291 	m_Size.Height() += rSz.Height();
292 	return *this;
293 }
operator -=(const Size & rSz)294 inline SwRect &SwRect::operator-=( const Size &rSz )
295 {
296 	m_Size.Width() -= rSz.Width();
297 	m_Size.Height() -= rSz.Height();
298 	return *this;
299 }
300 
301 
302 //--------------------------- Sonstiges
SVRect() const303 inline Rectangle SwRect::SVRect() const
304 {
305 	ASSERT( !IsEmpty(), "SVRect() without Width or Height" );
306 	return Rectangle( m_Point.getX(), m_Point.getY(),
307 		m_Point.getX() + m_Size.getWidth() - 1,         //Right()
308 		m_Point.getY() + m_Size.getHeight() - 1 );      //Bottom()
309 }
310 
GetIntersection(const SwRect & rRect) const311 inline SwRect SwRect::GetIntersection( const SwRect& rRect ) const
312 {
313 	return SwRect( *this ).Intersection( rRect );
314 }
315 
HasArea() const316 inline sal_Bool SwRect::HasArea() const
317 {
318 	return !IsEmpty();
319 }
IsEmpty() const320 inline sal_Bool SwRect::IsEmpty() const
321 {
322 	return !(m_Size.getHeight() && m_Size.getWidth());
323 }
Clear()324 inline void SwRect::Clear()
325 {
326 	m_Point.setX(0);
327 	m_Point.setY(0);
328 	m_Size.setWidth(0);
329 	m_Size.setHeight(0);
330 }
331 
332 //-------------------------- CToren
SwRect()333 inline SwRect::SwRect() :
334 	m_Point( 0, 0 ),
335 	m_Size( 0, 0 )
336 {
337 }
SwRect(const SwRect & rRect)338 inline SwRect::SwRect( const SwRect &rRect ) :
339 	m_Point( rRect.m_Point ),
340 	m_Size( rRect.m_Size )
341 {
342 }
SwRect(const Point & rLT,const Size & rSize)343 inline SwRect::SwRect( const Point& rLT, const Size&  rSize ) :
344 	m_Point( rLT ),
345 	m_Size( rSize )
346 {
347 }
SwRect(const Point & rLT,const Point & rRB)348 inline SwRect::SwRect( const Point& rLT, const Point& rRB ) :
349 	m_Point( rLT ),
350 	m_Size( rRB.X() - rLT.X() + 1, rRB.Y() - rLT.Y() + 1 )
351 {
352 }
SwRect(long X,long Y,long W,long H)353 inline SwRect::SwRect( long X, long Y, long W, long H ) :
354 	m_Point( X, Y ),
355 	m_Size( W, H )
356 {
357 }
358 
359 
360 #endif	//_SWRECT_HXX
361