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 .
19 #ifndef INCLUDED_SW_INC_SWRECT_HXX
20 #define INCLUDED_SW_INC_SWRECT_HXX
24 #include <sal/log.hxx>
25 #include <tools/gen.hxx>
29 typedef struct _xmlTextWriter
* xmlTextWriterPtr
;
31 /// *Of course* Writer needs its own rectangles.
32 /// This is half-open so m_Point.X() + m_Size.getWidth() is *not* included.
33 /// Note the tools Rectangle is (usually? sometimes?) closed so there's a
34 /// SVRect() to subtract 1 for the conversion.
35 class SAL_WARN_UNUSED SW_DLLPUBLIC SwRect
42 inline SwRect( const SwRect
&rRect
);
43 inline SwRect( const Point
& rLT
, const Size
& rSize
);
44 inline SwRect( const Point
& rLT
, const Point
& rRB
);
45 inline SwRect( tools::Long X
, tools::Long Y
, tools::Long Width
, tools::Long Height
);
47 //SV-SS e.g. SwRect( pWin->GetClipRect() );
48 SwRect( const tools::Rectangle
&rRect
);
51 inline void Chg( const Point
& rNP
, const Size
&rNS
);
52 inline void Pos( const Point
& rNew
);
53 inline void Pos( const tools::Long nNewX
, const tools::Long nNewY
);
54 inline void SSize( const Size
& rNew
);
55 inline void SSize( const tools::Long nHeight
, const tools::Long nWidth
);
56 inline void Width( tools::Long nNew
);
57 inline void Height( tools::Long nNew
);
58 inline void Left( const tools::Long nLeft
);
59 inline void Right( const tools::Long nRight
);
60 inline void Top( const tools::Long nTop
);
61 inline void Bottom( const tools::Long nBottom
);
64 inline const Point
&Pos() const;
65 inline const Size
&SSize() const;
66 inline tools::Long
Width() const;
67 inline tools::Long
Height() const;
68 inline tools::Long
Left() const;
69 inline tools::Long
Right() const;
70 inline tools::Long
Top() const;
71 inline tools::Long
Bottom() const;
73 // In order to be able to access the members of Pos and SSize from the layout side.
80 SwRect
&Union( const SwRect
& rRect
);
81 SwRect
&Intersection( const SwRect
& rRect
);
83 // Same as Intersection, only assume that Rects are overlapping!
84 SwRect
&Intersection_( const SwRect
&rRect
);
86 bool IsInside( const Point
& rPOINT
) const;
87 bool IsNear(const Point
& rPoint
, tools::Long nTolerance
) const;
88 bool IsInside( const SwRect
& rRect
) const;
89 bool IsOver( const SwRect
& rRect
) const;
90 inline bool HasArea() const;
91 inline bool IsEmpty() const;
94 inline SwRect
&operator = ( const SwRect
&rRect
);
96 inline bool operator == ( const SwRect
& rRect
) const;
97 inline bool operator != ( const SwRect
& rRect
) const;
99 inline SwRect
&operator+=( const Point
&rPt
);
100 inline SwRect
&operator-=( const Point
&rPt
);
102 //SV-SS e.g. pWin->DrawRect( aSwRect.SVRect() );
103 inline tools::Rectangle
SVRect() const;
105 // Output operator for debugging.
106 friend SvStream
& WriteSwRect( SvStream
&rStream
, const SwRect
&rRect
);
107 void dumpAsXmlAttributes(xmlTextWriterPtr writer
) const;
109 void Top_( const tools::Long nTop
);
110 void Bottom_( const tools::Long nBottom
);
111 void Left_( const tools::Long nLeft
);
112 void Right_( const tools::Long nRight
);
113 void Width_( const tools::Long nNew
);
114 void Height_( const tools::Long nNew
);
115 tools::Long
Top_() const;
116 tools::Long
Bottom_() const;
117 tools::Long
Left_() const;
118 tools::Long
Right_() const;
119 tools::Long
Width_() const;
120 tools::Long
Height_() const;
121 void SubTop( const tools::Long nSub
);
122 void AddTop( const tools::Long nAdd
);
123 void AddBottom( const tools::Long nAdd
);
124 void AddLeft( const tools::Long nAdd
);
125 void SubLeft( const tools::Long nSub
);
126 void AddRight( const tools::Long nAdd
);
127 void AddWidth( const tools::Long nAdd
);
128 void AddHeight( const tools::Long nAdd
);
129 void SetPosX( const tools::Long nNew
);
130 void SetPosY( const tools::Long nNew
);
131 void SetLeftAndWidth( tools::Long nLeft
, tools::Long nNew
);
132 void SetTopAndHeight( tools::Long nTop
, tools::Long nNew
);
133 void SetRightAndWidth( tools::Long nRight
, tools::Long nNew
);
134 void SetBottomAndHeight( tools::Long nBottom
, tools::Long nNew
);
135 void SetUpperLeftCorner( const Point
& rNew
);
136 void SetUpperRightCorner( const Point
& rNew
);
137 void SetLowerLeftCorner( const Point
& rNew
);
139 Point
TopLeft() const;
140 Point
TopRight() const;
141 Point
BottomLeft() const;
142 Point
BottomRight() const;
143 Size
SwappedSize() const;
144 tools::Long
GetLeftDistance( tools::Long
) const;
145 tools::Long
GetBottomDistance( tools::Long
) const;
146 tools::Long
GetRightDistance( tools::Long
) const;
147 tools::Long
GetTopDistance( tools::Long
) const;
148 bool OverStepLeft( tools::Long
) const;
149 bool OverStepBottom( tools::Long
) const;
150 bool OverStepTop( tools::Long
) const;
151 bool OverStepRight( tools::Long
) const;
154 typedef void (SwRect::*SwRectSet
)( const tools::Long nNew
);
155 typedef tools::Long (SwRect::*SwRectGet
)() const;
156 typedef Point (SwRect::*SwRectPoint
)() const;
157 typedef Size (SwRect::*SwRectSize
)() const;
158 typedef bool (SwRect::*SwRectMax
)( tools::Long
) const;
159 typedef tools::Long (SwRect::*SwRectDist
)( tools::Long
) const;
160 typedef void (SwRect::*SwRectSetTwice
)( tools::Long
, tools::Long
);
161 typedef void (SwRect::*SwRectSetPos
)( const Point
& );
164 inline void SwRect::Chg( const Point
& rNP
, const Size
&rNS
)
169 inline void SwRect::Pos( const Point
& rNew
)
173 inline void SwRect::Pos( const tools::Long nNewX
, const tools::Long nNewY
)
178 inline void SwRect::SSize( const Size
& rNew
)
182 inline void SwRect::SSize( const tools::Long nNewHeight
, const tools::Long nNewWidth
)
184 m_Size
.setWidth(nNewWidth
);
185 m_Size
.setHeight(nNewHeight
);
187 inline void SwRect::Width( tools::Long nNew
)
189 m_Size
.setWidth(nNew
);
191 inline void SwRect::Height( tools::Long nNew
)
193 m_Size
.setHeight(nNew
);
195 inline void SwRect::Left( const tools::Long nLeft
)
197 m_Size
.AdjustWidth( m_Point
.getX() - nLeft
);
200 inline void SwRect::Right( const tools::Long nRight
)
202 m_Size
.setWidth(nRight
- m_Point
.getX() + 1);
204 inline void SwRect::Top( const tools::Long nTop
)
206 m_Size
.AdjustHeight( m_Point
.getY() - nTop
);
209 inline void SwRect::Bottom( const tools::Long nBottom
)
211 m_Size
.setHeight(nBottom
- m_Point
.getY() + 1);
215 inline const Point
&SwRect::Pos() const
219 inline Point
&SwRect::Pos()
223 inline const Size
&SwRect::SSize() const
227 inline tools::Long
SwRect::Width() const
229 return m_Size
.Width();
231 inline tools::Long
SwRect::Height() const
233 return m_Size
.Height();
235 inline tools::Long
SwRect::Left() const
239 inline tools::Long
SwRect::Right() const
241 return m_Size
.getWidth() ? m_Point
.getX() + m_Size
.getWidth() - 1 : m_Point
.getX();
243 inline tools::Long
SwRect::Top() const
247 inline tools::Long
SwRect::Bottom() const
249 return m_Size
.getHeight() ? m_Point
.getY() + m_Size
.getHeight() - 1 : m_Point
.getY();
253 inline SwRect
&SwRect::operator = ( const SwRect
&rRect
)
255 m_Point
= rRect
.m_Point
;
256 m_Size
= rRect
.m_Size
;
259 inline bool SwRect::operator == ( const SwRect
& rRect
) const
261 return (m_Point
== rRect
.m_Point
&& m_Size
== rRect
.m_Size
);
263 inline bool SwRect::operator != ( const SwRect
& rRect
) const
265 return (m_Point
!= rRect
.m_Point
|| m_Size
!= rRect
.m_Size
);
268 inline SwRect
&SwRect::operator+=( const Point
&rPt
)
273 inline SwRect
&SwRect::operator-=( const Point
&rPt
)
280 inline tools::Rectangle
SwRect::SVRect() const
282 SAL_WARN_IF( IsEmpty(), "sw", "SVRect() without Width or Height" );
283 return tools::Rectangle( m_Point
.getX(), m_Point
.getY(),
284 m_Point
.getX() + m_Size
.getWidth() - 1, //Right()
285 m_Point
.getY() + m_Size
.getHeight() - 1 ); //Bottom()
288 inline bool SwRect::HasArea() const
292 inline bool SwRect::IsEmpty() const
294 return !(m_Size
.getHeight() && m_Size
.getWidth());
296 inline void SwRect::Clear()
305 inline SwRect::SwRect() :
310 inline SwRect::SwRect( const SwRect
&rRect
) :
311 m_Point( rRect
.m_Point
),
312 m_Size( rRect
.m_Size
)
315 inline SwRect::SwRect( const Point
& rLT
, const Size
& rSize
) :
320 inline SwRect::SwRect( const Point
& rLT
, const Point
& rRB
) :
322 m_Size( rRB
.X() - rLT
.X() + 1, rRB
.Y() - rLT
.Y() + 1 )
325 inline SwRect::SwRect( tools::Long X
, tools::Long Y
, tools::Long W
, tools::Long H
) :
331 template< typename charT
, typename traits
>
332 inline std::basic_ostream
<charT
, traits
> & operator <<(
333 std::basic_ostream
<charT
, traits
> & stream
, const SwRect
& rectangle
)
335 if (rectangle
.IsEmpty())
337 return stream
<< rectangle
.SSize()
338 << "@(" << rectangle
.Pos() << ")";
341 #endif // INCLUDED_SW_INC_SWRECT_HXX
343 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */