1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <osl/diagnose.h>
22 #include <tools/gen.hxx>
25 class SAL_WARN_UNUSED SwRect
33 inline SwRect( const SwRect
&rRect
);
34 inline SwRect( const Point
& rLT
, const Size
& rSize
);
35 inline SwRect( const Point
& rLT
, const Point
& rRB
);
36 inline SwRect( long X
, long Y
, long Width
, long Height
);
38 //SV-SS e.g. SwRect( pWin->GetClipRect() );
39 SwRect( const Rectangle
&rRect
);
42 inline void Chg( const Point
& rNP
, const Size
&rNS
);
43 inline void Pos( const Point
& rNew
);
44 inline void Pos( const long nNewX
, const long nNewY
);
45 inline void SSize( const Size
& rNew
);
46 inline void SSize( const long nHeight
, const long nWidth
);
47 inline void Width( long nNew
);
48 inline void Height( long nNew
);
49 inline void Left( const long nLeft
);
50 inline void Right( const long nRight
);
51 inline void Top( const long nTop
);
52 inline void Bottom( const long nBottom
);
55 inline const Point
&Pos() const;
56 inline const Size
&SSize() const;
57 inline long Width() const;
58 inline long Height() const;
59 inline long Left() const;
60 inline long Right() const;
61 inline long Top() const;
62 inline long Bottom() const;
64 // In order to be able to access the members of Pos and SSize from the layout side.
72 SwRect
&Union( const SwRect
& rRect
);
73 SwRect
&Intersection( const SwRect
& rRect
);
75 // Same as Intersection, only assume that Rects are overlapping!
76 SwRect
&_Intersection( const SwRect
&rRect
);
77 inline SwRect
GetIntersection( const SwRect
& rRect
) const;
79 sal_Bool
IsInside( const Point
& rPOINT
) const;
80 sal_Bool
IsNear(const Point
& rPoint
, long nTolerance
) const;
81 sal_Bool
IsInside( const SwRect
& rRect
) const;
82 sal_Bool
IsOver( const SwRect
& rRect
) const;
83 inline sal_Bool
HasArea() const;
84 inline sal_Bool
IsEmpty() const;
87 inline SwRect
&operator = ( const SwRect
&rRect
);
89 inline sal_Bool
operator == ( const SwRect
& rRect
) const;
90 inline sal_Bool
operator != ( const SwRect
& rRect
) const;
92 inline SwRect
&operator+=( const Point
&rPt
);
93 inline SwRect
&operator-=( const Point
&rPt
);
95 inline SwRect
&operator+=( const Size
&rSz
);
96 inline SwRect
&operator-=( const Size
&rSz
);
98 //SV-SS e.g. pWin->DrawRect( aSwRect.SVRect() );
99 inline Rectangle
SVRect() const;
101 // Output operator for debugging.
102 friend SvStream
&operator<<( SvStream
&rStream
, const SwRect
&rRect
);
105 void _Top( const long nTop
);
106 void _Bottom( const long nBottom
);
107 void _Left( const long nLeft
);
108 void _Right( const long nRight
);
109 void _Width( const long nNew
);
110 void _Height( const long nNew
);
112 long _Bottom() const;
116 long _Height() const;
117 void SubTop( const long nSub
);
118 void AddBottom( const long nAdd
);
119 void SubLeft( const long nSub
);
120 void AddRight( const long nAdd
);
121 void AddWidth( const long nAdd
);
122 void AddHeight( const long nAdd
);
123 void SetPosX( const long nNew
);
124 void SetPosY( const long nNew
);
125 void SetLeftAndWidth( long nLeft
, long nNew
);
126 void SetTopAndHeight( long nTop
, long nNew
);
127 void SetRightAndWidth( long nRight
, long nNew
);
128 void SetBottomAndHeight( long nBottom
, long nNew
);
129 void SetUpperLeftCorner( const Point
& rNew
);
130 void SetUpperRightCorner( const Point
& rNew
);
131 void SetLowerLeftCorner( const Point
& rNew
);
132 const Size
_Size() const;
133 const Point
TopLeft() const;
134 const Point
TopRight() const;
135 const Point
BottomLeft() const;
136 const Point
BottomRight() const;
137 const Size
SwappedSize() const;
138 long GetLeftDistance( long ) const;
139 long GetBottomDistance( long ) const;
140 long GetRightDistance( long ) const;
141 long GetTopDistance( long ) const;
142 sal_Bool
OverStepLeft( long ) const;
143 sal_Bool
OverStepBottom( long ) const;
144 sal_Bool
OverStepTop( long ) const;
145 sal_Bool
OverStepRight( long ) const;
149 // Implementation in swrect.cxx
150 extern SvStream
&operator<<( SvStream
&rStream
, const SwRect
&rRect
);
153 typedef void (SwRect:: *SwRectSet
)( const long nNew
);
154 typedef long (SwRect:: *SwRectGet
)() const;
155 typedef const Point (SwRect:: *SwRectPoint
)() const;
156 typedef const Size (SwRect:: *SwRectSize
)() const;
157 typedef sal_Bool (SwRect:: *SwRectMax
)( long ) const;
158 typedef long (SwRect:: *SwRectDist
)( long ) const;
159 typedef void (SwRect:: *SwRectSetTwice
)( long, long );
160 typedef void (SwRect:: *SwRectSetPos
)( const Point
& );
163 inline void SwRect::Chg( const Point
& rNP
, const Size
&rNS
)
168 inline void SwRect::Pos( const Point
& rNew
)
172 inline void SwRect::Pos( const long nNewX
, const long nNewY
)
177 inline void SwRect::SSize( const Size
& rNew
)
181 inline void SwRect::SSize( const long nNewHeight
, const long nNewWidth
)
183 m_Size
.setWidth(nNewWidth
);
184 m_Size
.setHeight(nNewHeight
);
186 inline void SwRect::Width( long nNew
)
188 m_Size
.setWidth(nNew
);
190 inline void SwRect::Height( long nNew
)
192 m_Size
.setHeight(nNew
);
194 inline void SwRect::Left( const long nLeft
)
196 m_Size
.Width() += m_Point
.getX() - nLeft
;
199 inline void SwRect::Right( const long nRight
)
201 m_Size
.setWidth(nRight
- m_Point
.getX() + 1);
203 inline void SwRect::Top( const long nTop
)
205 m_Size
.Height() += m_Point
.getY() - nTop
;
208 inline void SwRect::Bottom( const long nBottom
)
210 m_Size
.setHeight(nBottom
- m_Point
.getY() + 1);
214 inline const Point
&SwRect::Pos() const
218 inline Point
&SwRect::Pos()
222 inline const Size
&SwRect::SSize() const
226 inline Size
&SwRect::SSize()
230 inline long SwRect::Width() const
232 return m_Size
.Width();
234 inline long SwRect::Height() const
236 return m_Size
.Height();
238 inline long SwRect::Left() const
242 inline long SwRect::Right() const
244 return m_Size
.getWidth() ? m_Point
.getX() + m_Size
.getWidth() - 1 : m_Point
.getX();
246 inline long SwRect::Top() const
250 inline long SwRect::Bottom() const
252 return m_Size
.getHeight() ? m_Point
.getY() + m_Size
.getHeight() - 1 : m_Point
.getY();
256 inline SwRect
&SwRect::operator = ( const SwRect
&rRect
)
258 m_Point
= rRect
.m_Point
;
259 m_Size
= rRect
.m_Size
;
262 inline sal_Bool
SwRect::operator == ( const SwRect
& rRect
) const
264 return (m_Point
== rRect
.m_Point
&& m_Size
== rRect
.m_Size
);
266 inline sal_Bool
SwRect::operator != ( const SwRect
& rRect
) const
268 return (m_Point
!= rRect
.m_Point
|| m_Size
!= rRect
.m_Size
);
271 inline SwRect
&SwRect::operator+=( const Point
&rPt
)
276 inline SwRect
&SwRect::operator-=( const Point
&rPt
)
282 inline SwRect
&SwRect::operator+=( const Size
&rSz
)
284 m_Size
.Width() += rSz
.Width();
285 m_Size
.Height() += rSz
.Height();
288 inline SwRect
&SwRect::operator-=( const Size
&rSz
)
290 m_Size
.Width() -= rSz
.Width();
291 m_Size
.Height() -= rSz
.Height();
297 inline Rectangle
SwRect::SVRect() const
299 OSL_ENSURE( !IsEmpty(), "SVRect() without Width or Height" );
300 return Rectangle( m_Point
.getX(), m_Point
.getY(),
301 m_Point
.getX() + m_Size
.getWidth() - 1, //Right()
302 m_Point
.getY() + m_Size
.getHeight() - 1 ); //Bottom()
305 inline SwRect
SwRect::GetIntersection( const SwRect
& rRect
) const
307 return SwRect( *this ).Intersection( rRect
);
310 inline sal_Bool
SwRect::HasArea() const
314 inline sal_Bool
SwRect::IsEmpty() const
316 return !(m_Size
.getHeight() && m_Size
.getWidth());
318 inline void SwRect::Clear()
327 inline SwRect::SwRect() :
332 inline SwRect::SwRect( const SwRect
&rRect
) :
333 m_Point( rRect
.m_Point
),
334 m_Size( rRect
.m_Size
)
337 inline SwRect::SwRect( const Point
& rLT
, const Size
& rSize
) :
342 inline SwRect::SwRect( const Point
& rLT
, const Point
& rRB
) :
344 m_Size( rRB
.X() - rLT
.X() + 1, rRB
.Y() - rLT
.Y() + 1 )
347 inline SwRect::SwRect( long X
, long Y
, long W
, long H
) :
356 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */