bump product version to 4.1.6.2
[LibreOffice.git] / tools / source / generic / gen.cxx
blobd7d7ff0403e891eae199c8ee2f718ab795dbd80a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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;
31 rPair.nA = nTmpA;
32 rPair.nB = nTmpB;
34 return rIStream;
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);
44 return rOStream;
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;
53 else
54 nRight = RECT_EMPTY;
56 if ( rSize.Height() < 0 )
57 nBottom = nTop + rSize.Height() +1;
58 else if ( rSize.Height() > 0 )
59 nBottom = nTop + rSize.Height() -1;
60 else
61 nBottom = RECT_EMPTY;
64 Rectangle& Rectangle::Union( const Rectangle& rRect )
66 if ( rRect.IsEmpty() )
67 return *this;
69 if ( IsEmpty() )
70 *this = rRect;
71 else
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 ) );
79 return *this;
82 Rectangle& Rectangle::Intersection( const Rectangle& rRect )
84 if ( IsEmpty() )
85 return *this;
86 if ( rRect.IsEmpty() )
88 *this = Rectangle();
89 return *this;
92 // Justify rectangle
93 Rectangle aTmpRect( rRect );
94 Justify();
95 aTmpRect.Justify();
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 )
105 *this = Rectangle();
107 return *this;
110 void Rectangle::Justify()
112 long nHelp;
114 if ( (nRight < nLeft) && (nRight != RECT_EMPTY) )
116 nHelp = nLeft;
117 nLeft = nRight;
118 nRight = nHelp;
121 if ( (nBottom < nTop) && (nBottom != RECT_EMPTY) )
123 nHelp = nBottom;
124 nBottom = nTop;
125 nTop = nHelp;
129 sal_Bool Rectangle::IsInside( const Point& rPoint ) const
131 if ( IsEmpty() )
132 return sal_False;
134 sal_Bool bRet = sal_True;
135 if ( nLeft <= nRight )
137 if ( (rPoint.X() < nLeft) || (rPoint.X() > nRight) )
138 bRet = sal_False;
140 else
142 if ( (rPoint.X() > nLeft) || (rPoint.X() < nRight) )
143 bRet = sal_False;
145 if ( nTop <= nBottom )
147 if ( (rPoint.Y() < nTop) || (rPoint.Y() > nBottom) )
148 bRet = sal_False;
150 else
152 if ( (rPoint.Y() > nTop) || (rPoint.Y() < nBottom) )
153 bRet = sal_False;
155 return bRet;
158 sal_Bool Rectangle::IsInside( const Rectangle& rRect ) const
160 if ( IsInside( rRect.TopLeft() ) && IsInside( rRect.BottomRight() ) )
161 return sal_True;
162 else
163 return sal_False;
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;
181 rRect.nLeft = nTmpL;
182 rRect.nTop = nTmpT;
183 rRect.nRight = nTmpR;
184 rRect.nBottom = nTmpB;
186 return rIStream;
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);
199 return rOStream;
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */