Bump version to 4.3-4
[LibreOffice.git] / sc / inc / bigrange.hxx
blobb9a8beb0a04ca3c44894eaa6366b194bbd9013fc
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 #ifndef INCLUDED_SC_INC_BIGRANGE_HXX
21 #define INCLUDED_SC_INC_BIGRANGE_HXX
23 #include "global.hxx"
25 static const sal_Int32 nInt32Min = 0x80000000;
26 static const sal_Int32 nInt32Max = 0x7fffffff;
28 class ScDocument;
30 class ScBigAddress
32 sal_Int32 nRow;
33 sal_Int32 nCol;
34 sal_Int32 nTab;
36 public:
37 ScBigAddress() : nRow(0), nCol(0), nTab(0) {}
38 ScBigAddress( sal_Int32 nColP, sal_Int32 nRowP, sal_Int32 nTabP )
39 : nRow( nRowP ), nCol( nColP ), nTab( nTabP ) {}
40 ScBigAddress( const ScBigAddress& r )
41 : nRow( r.nRow ), nCol( r.nCol ), nTab( r.nTab ) {}
42 ScBigAddress( const ScAddress& r )
43 : nRow( r.Row() ), nCol( r.Col() ), nTab( r.Tab() ) {}
45 sal_Int32 Col() const { return nCol; }
46 sal_Int32 Row() const { return nRow; }
47 sal_Int32 Tab() const { return nTab; }
49 void Set( sal_Int32 nColP, sal_Int32 nRowP, sal_Int32 nTabP )
50 { nCol = nColP; nRow = nRowP; nTab = nTabP; }
51 void SetCol( sal_Int32 nColP ) { nCol = nColP; }
52 void SetRow( sal_Int32 nRowP ) { nRow = nRowP; }
53 void SetTab( sal_Int32 nTabP ) { nTab = nTabP; }
54 void IncCol( sal_Int32 n = 1 ) { nCol += n; }
55 void IncRow( sal_Int32 n = 1 ) { nRow += n; }
56 void IncTab( sal_Int32 n = 1 ) { nTab += n; }
58 void GetVars( sal_Int32& nColP, sal_Int32& nRowP, sal_Int32& nTabP ) const
59 { nColP = nCol; nRowP = nRow; nTabP = nTab; }
61 inline void PutInOrder( ScBigAddress& r );
62 bool IsValid( const ScDocument* pDoc ) const;
63 inline ScAddress MakeAddress() const;
65 ScBigAddress& operator=( const ScBigAddress& r )
66 { nCol = r.nCol; nRow = r.nRow; nTab = r.nTab; return *this; }
67 ScBigAddress& operator=( const ScAddress& r )
68 { nCol = r.Col(); nRow = r.Row(); nTab = r.Tab(); return *this; }
69 bool operator==( const ScBigAddress& r ) const
70 { return nCol == r.nCol && nRow == r.nRow && nTab == r.nTab; }
71 bool operator!=( const ScBigAddress& r ) const
72 { return !operator==( r ); }
74 friend inline SvStream& WriteScBigAddress( SvStream& rStream, const ScBigAddress& rAdr );
75 friend inline SvStream& ReadScBigAddress( SvStream& rStream, ScBigAddress& rAdr );
78 inline void ScBigAddress::PutInOrder( ScBigAddress& r )
80 sal_Int32 nTmp;
81 if ( r.nCol < nCol )
83 nTmp = r.nCol;
84 r.nCol = nCol;
85 nCol = nTmp;
87 if ( r.nRow < nRow )
89 nTmp = r.nRow;
90 r.nRow = nRow;
91 nRow = nTmp;
93 if ( r.nTab < nTab )
95 nTmp = r.nTab;
96 r.nTab = nTab;
97 nTab = nTmp;
101 inline ScAddress ScBigAddress::MakeAddress() const
103 SCCOL nColA;
104 SCROW nRowA;
105 SCTAB nTabA;
107 if ( nCol < 0 )
108 nColA = 0;
109 else if ( nCol > MAXCOL )
110 nColA = MAXCOL;
111 else
112 nColA = (SCCOL) nCol;
114 if ( nRow < 0 )
115 nRowA = 0;
116 else if ( nRow > MAXROW )
117 nRowA = MAXROW;
118 else
119 nRowA = (SCROW) nRow;
121 if ( nTab < 0 )
122 nTabA = 0;
123 else if ( nTab > MAXTAB )
124 nTabA = MAXTAB;
125 else
126 nTabA = (SCTAB) nTab;
128 return ScAddress( nColA, nRowA, nTabA );
132 inline SvStream& WriteScBigAddress( SvStream& rStream, const ScBigAddress& rAdr )
134 rStream.WriteInt32( rAdr.nCol ).WriteInt32( rAdr.nRow ).WriteInt32( rAdr.nTab );
135 return rStream;
139 inline SvStream& ReadScBigAddress( SvStream& rStream, ScBigAddress& rAdr )
141 rStream.ReadInt32( rAdr.nCol ).ReadInt32( rAdr.nRow ).ReadInt32( rAdr.nTab );
142 return rStream;
146 class ScBigRange
148 public:
150 ScBigAddress aStart;
151 ScBigAddress aEnd;
153 ScBigRange() : aStart(), aEnd() {}
154 ScBigRange( const ScBigAddress& s, const ScBigAddress& e )
155 : aStart( s ), aEnd( e ) { aStart.PutInOrder( aEnd ); }
156 ScBigRange( const ScBigRange& r )
157 : aStart( r.aStart ), aEnd( r.aEnd ) {}
158 ScBigRange( const ScRange& r )
159 : aStart( r.aStart ), aEnd( r.aEnd ) {}
160 ScBigRange( const ScBigAddress& r )
161 : aStart( r ), aEnd( r ) {}
162 ScBigRange( const ScAddress& r )
163 : aStart( r ), aEnd( r ) {}
164 ScBigRange( sal_Int32 nCol, sal_Int32 nRow, sal_Int32 nTab )
165 : aStart( nCol, nRow, nTab ), aEnd( aStart ) {}
166 ScBigRange( sal_Int32 nCol1, sal_Int32 nRow1, sal_Int32 nTab1,
167 sal_Int32 nCol2, sal_Int32 nRow2, sal_Int32 nTab2 )
168 : aStart( nCol1, nRow1, nTab1 ),
169 aEnd( nCol2, nRow2, nTab2 ) {}
171 void Set( sal_Int32 nCol1, sal_Int32 nRow1, sal_Int32 nTab1,
172 sal_Int32 nCol2, sal_Int32 nRow2, sal_Int32 nTab2 )
173 { aStart.Set( nCol1, nRow1, nTab1 );
174 aEnd.Set( nCol2, nRow2, nTab2 ); }
176 void GetVars( sal_Int32& nCol1, sal_Int32& nRow1, sal_Int32& nTab1,
177 sal_Int32& nCol2, sal_Int32& nRow2, sal_Int32& nTab2 ) const
178 { aStart.GetVars( nCol1, nRow1, nTab1 );
179 aEnd.GetVars( nCol2, nRow2, nTab2 ); }
181 bool IsValid( const ScDocument* pDoc ) const
182 { return aStart.IsValid( pDoc ) && aEnd.IsValid( pDoc ); }
183 inline ScRange MakeRange() const
184 { return ScRange( aStart.MakeAddress(),
185 aEnd.MakeAddress() ); }
187 inline bool In( const ScBigAddress& ) const; ///< is Address& in range?
188 inline bool In( const ScBigRange& ) const; ///< is Range& in range?
189 inline bool Intersects( const ScBigRange& ) const; ///< do two ranges overlap?
191 ScBigRange& operator=( const ScBigRange& r )
192 { aStart = r.aStart; aEnd = r.aEnd; return *this; }
193 bool operator==( const ScBigRange& r ) const
194 { return (aStart == r.aStart) && (aEnd == r.aEnd); }
195 bool operator!=( const ScBigRange& r ) const
196 { return !operator==( r ); }
198 friend inline SvStream& WriteScBigRange( SvStream& rStream, const ScBigRange& rRange );
199 friend inline SvStream& ReadScBigRange( SvStream& rStream, ScBigRange& rRange );
203 inline bool ScBigRange::In( const ScBigAddress& rAddr ) const
205 return
206 aStart.Col() <= rAddr.Col() && rAddr.Col() <= aEnd.Col() &&
207 aStart.Row() <= rAddr.Row() && rAddr.Row() <= aEnd.Row() &&
208 aStart.Tab() <= rAddr.Tab() && rAddr.Tab() <= aEnd.Tab();
212 inline bool ScBigRange::In( const ScBigRange& r ) const
214 return
215 aStart.Col() <= r.aStart.Col() && r.aEnd.Col() <= aEnd.Col() &&
216 aStart.Row() <= r.aStart.Row() && r.aEnd.Row() <= aEnd.Row() &&
217 aStart.Tab() <= r.aStart.Tab() && r.aEnd.Tab() <= aEnd.Tab();
221 inline bool ScBigRange::Intersects( const ScBigRange& r ) const
223 return !(
224 std::min( aEnd.Col(), r.aEnd.Col() ) < std::max( aStart.Col(), r.aStart.Col() )
225 || std::min( aEnd.Row(), r.aEnd.Row() ) < std::max( aStart.Row(), r.aStart.Row() )
226 || std::min( aEnd.Tab(), r.aEnd.Tab() ) < std::max( aStart.Tab(), r.aStart.Tab() )
231 inline SvStream& WriteScBigRange ( SvStream& rStream, const ScBigRange& rRange )
233 WriteScBigAddress( rStream, rRange.aStart );
234 WriteScBigAddress( rStream, rRange.aEnd );
235 return rStream;
239 inline SvStream& ReadScBigRange( SvStream& rStream, ScBigRange& rRange )
241 ReadScBigAddress( rStream, rRange.aStart );
242 ReadScBigAddress( rStream, rRange.aEnd );
243 return rStream;
246 #endif
248 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */