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 .
20 #include <tools/debug.hxx>
21 #include <tools/gen.hxx>
22 #include <tools/stream.hxx>
24 SvStream
& operator>>( SvStream
& rIStream
, Pair
& rPair
)
26 DBG_ASSERTWARNING( rIStream
.GetVersion(), "Pair::>> - Solar-Version not set on rIStream" );
28 //39428 SvStream no longer supports operator>>(long&)
29 sal_Int32
nTmpA(0), nTmpB(0);
30 rIStream
>> nTmpA
>> nTmpB
;
37 SvStream
& operator<<( SvStream
& rOStream
, const Pair
& rPair
)
39 DBG_ASSERTWARNING( rOStream
.GetVersion(), "Pair::<< - Solar-Version not set on rOStream" );
41 //39428 SvStream no longer supports operator<<(long)
42 rOStream
<< sal::static_int_cast
<sal_Int32
>(rPair
.nA
) << sal::static_int_cast
<sal_Int32
>(rPair
.nB
);
47 void Rectangle::SetSize( const Size
& rSize
)
49 if ( rSize
.Width() < 0 )
50 nRight
= nLeft
+ rSize
.Width() +1;
51 else if ( rSize
.Width() > 0 )
52 nRight
= nLeft
+ rSize
.Width() -1;
56 if ( rSize
.Height() < 0 )
57 nBottom
= nTop
+ rSize
.Height() +1;
58 else if ( rSize
.Height() > 0 )
59 nBottom
= nTop
+ rSize
.Height() -1;
64 Rectangle
& Rectangle::Union( const Rectangle
& rRect
)
66 if ( rRect
.IsEmpty() )
73 nLeft
= std::min( std::min( nLeft
, rRect
.nLeft
), std::min( nRight
, rRect
.nRight
) );
74 nRight
= std::max( std::max( nLeft
, rRect
.nLeft
), std::max( nRight
, rRect
.nRight
) );
75 nTop
= std::min( std::min( nTop
, rRect
.nTop
), std::min( nBottom
, rRect
.nBottom
) );
76 nBottom
= std::max( std::max( nTop
, rRect
.nTop
), std::max( nBottom
, rRect
.nBottom
) );
82 Rectangle
& Rectangle::Intersection( const Rectangle
& rRect
)
86 if ( rRect
.IsEmpty() )
93 Rectangle
aTmpRect( rRect
);
97 // Perform intersection
98 nLeft
= std::max( nLeft
, aTmpRect
.nLeft
);
99 nRight
= std::min( nRight
, aTmpRect
.nRight
);
100 nTop
= std::max( nTop
, aTmpRect
.nTop
);
101 nBottom
= std::min( nBottom
, aTmpRect
.nBottom
);
103 // Determine if intersection is empty
104 if ( nRight
< nLeft
|| nBottom
< nTop
)
110 void Rectangle::Justify()
114 if ( (nRight
< nLeft
) && (nRight
!= RECT_EMPTY
) )
121 if ( (nBottom
< nTop
) && (nBottom
!= RECT_EMPTY
) )
129 sal_Bool
Rectangle::IsInside( const Point
& rPoint
) const
134 sal_Bool bRet
= sal_True
;
135 if ( nLeft
<= nRight
)
137 if ( (rPoint
.X() < nLeft
) || (rPoint
.X() > nRight
) )
142 if ( (rPoint
.X() > nLeft
) || (rPoint
.X() < nRight
) )
145 if ( nTop
<= nBottom
)
147 if ( (rPoint
.Y() < nTop
) || (rPoint
.Y() > nBottom
) )
152 if ( (rPoint
.Y() > nTop
) || (rPoint
.Y() < nBottom
) )
158 sal_Bool
Rectangle::IsInside( const Rectangle
& rRect
) const
160 if ( IsInside( rRect
.TopLeft() ) && IsInside( rRect
.BottomRight() ) )
166 sal_Bool
Rectangle::IsOver( const Rectangle
& rRect
) const
168 // If there's no intersection, they don't overlap
169 return !GetIntersection( rRect
).IsEmpty();
172 SvStream
& operator>>( SvStream
& rIStream
, Rectangle
& rRect
)
174 DBG_ASSERTWARNING( rIStream
.GetVersion(), "Rectangle::>> - Solar-Version not set on rIStream" );
176 //fdo#39428 SvStream no longer supports operator>>(long&)
177 sal_Int32
nTmpL(0), nTmpT(0), nTmpR(0), nTmpB(0);
179 rIStream
>> nTmpL
>> nTmpT
>> nTmpR
>> nTmpB
;
183 rRect
.nRight
= nTmpR
;
184 rRect
.nBottom
= nTmpB
;
189 SvStream
& operator<<( SvStream
& rOStream
, const Rectangle
& rRect
)
191 DBG_ASSERTWARNING( rOStream
.GetVersion(), "Rectangle::<< - Solar-Version not set on rOStream" );
193 //fdo#39428 SvStream no longer supports operator<<(long)
194 rOStream
<< sal::static_int_cast
<sal_Int32
>(rRect
.nLeft
)
195 << sal::static_int_cast
<sal_Int32
>(rRect
.nTop
)
196 << sal::static_int_cast
<sal_Int32
>(rRect
.nRight
)
197 << sal::static_int_cast
<sal_Int32
>(rRect
.nBottom
);
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */