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