1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: swrect.hxx,v $
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 ************************************************************************/
35 #ifndef _GEN_HXX //autogen
36 #include <tools/gen.hxx>
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
);
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
);
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.
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;
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
);
135 long _Bottom() 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;
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
& );
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
)
212 inline void SwRect::Height( long nNew
)
216 inline void SwRect::Left( const long nLeft
)
218 nWidth
+= 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
;
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
256 inline long SwRect::Height() const
260 inline long SwRect::Left() const
264 inline long SwRect::Right() const
266 return nWidth
? nX
+ nWidth
- 1 : nX
;
268 inline long SwRect::Top() const
272 inline long SwRect::Bottom() const
274 return nHeight
? nY
+ nHeight
- 1 : nY
;
277 //----------------------------------- operatoren
278 inline SwRect
&SwRect::operator = ( const SwRect
&rRect
)
282 nWidth
= rRect
.Width();
283 nHeight
= rRect
.Height();
286 inline BOOL
SwRect::operator == ( const SwRect
& rRect
) const
288 return (nX
== rRect
.Left() &&
290 nWidth
== rRect
.Width() &&
291 nHeight
== rRect
.Height());
293 inline BOOL
SwRect::operator != ( const SwRect
& rRect
) const
295 return (nX
!= rRect
.Left() ||
297 nWidth
!= rRect
.Width() ||
298 nHeight
!= rRect
.Height());
301 inline SwRect
&SwRect::operator+=( const Point
&rPt
)
303 nX
+= rPt
.X(); nY
+= rPt
.Y();
306 inline SwRect
&SwRect::operator-=( const Point
&rPt
)
308 nX
-= rPt
.X(); nY
-= rPt
.Y();
312 inline SwRect
&SwRect::operator+=( const Size
&rSz
)
314 nWidth
+= rSz
.Width(); nHeight
+= rSz
.Height();
317 inline SwRect
&SwRect::operator-=( const Size
&rSz
)
319 nWidth
-= rSz
.Width(); nHeight
-= rSz
.Height();
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() :
363 inline SwRect::SwRect( const SwRect
&rRect
) :
366 nWidth ( rRect
.Width() ),
367 nHeight( rRect
.Height() )
370 inline SwRect::SwRect( const Point
& rLT
, const Size
& rSize
) :
373 nWidth ( rSize
.Width() ),
374 nHeight( rSize
.Height())
377 inline SwRect::SwRect( const Point
& rLT
, const Point
& rRB
) :
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
) :
393 } //namespace binfilter