merged tag ooo/OOO330_m14
[LibreOffice.git] / sc / inc / bigrange.hxx
blobd5a066d522cc82bde95e3b542316b579e9e484c1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #ifndef SC_BIGRANGE_HXX
29 #define SC_BIGRANGE_HXX
32 #include "global.hxx"
33 #include "document.hxx"
36 static const INT32 nInt32Min = 0x80000000;
37 static const INT32 nInt32Max = 0x7fffffff;
40 class ScBigAddress
42 INT32 nRow;
43 INT32 nCol;
44 INT32 nTab;
46 public:
47 ScBigAddress() : nRow(0), nCol(0), nTab(0) {}
48 ScBigAddress( INT32 nColP, INT32 nRowP, INT32 nTabP )
49 : nRow( nRowP ), nCol( nColP ), nTab( nTabP ) {}
50 ScBigAddress( const ScBigAddress& r )
51 : nRow( r.nRow ), nCol( r.nCol ), nTab( r.nTab ) {}
52 ScBigAddress( const ScAddress& r )
53 : nRow( r.Row() ), nCol( r.Col() ), nTab( r.Tab() ) {}
55 INT32 Col() const { return nCol; }
56 INT32 Row() const { return nRow; }
57 INT32 Tab() const { return nTab; }
59 void Set( INT32 nColP, INT32 nRowP, INT32 nTabP )
60 { nCol = nColP; nRow = nRowP; nTab = nTabP; }
61 void SetCol( INT32 nColP ) { nCol = nColP; }
62 void SetRow( INT32 nRowP ) { nRow = nRowP; }
63 void SetTab( INT32 nTabP ) { nTab = nTabP; }
64 void IncCol( INT32 n = 1 ) { nCol += n; }
65 void IncRow( INT32 n = 1 ) { nRow += n; }
66 void IncTab( INT32 n = 1 ) { nTab += n; }
68 void GetVars( INT32& nColP, INT32& nRowP, INT32& nTabP ) const
69 { nColP = nCol; nRowP = nRow; nTabP = nTab; }
71 inline void PutInOrder( ScBigAddress& r );
72 inline BOOL IsValid( const ScDocument* ) const;
73 inline ScAddress MakeAddress() const;
75 ScBigAddress& operator=( const ScBigAddress& r )
76 { nCol = r.nCol; nRow = r.nRow; nTab = r.nTab; return *this; }
77 ScBigAddress& operator=( const ScAddress& r )
78 { nCol = r.Col(); nRow = r.Row(); nTab = r.Tab(); return *this; }
79 int operator==( const ScBigAddress& r ) const
80 { return nCol == r.nCol && nRow == r.nRow && nTab == r.nTab; }
81 int operator!=( const ScBigAddress& r ) const
82 { return !operator==( r ); }
84 friend inline SvStream& operator<< ( SvStream& rStream, const ScBigAddress& rAdr );
85 friend inline SvStream& operator>> ( SvStream& rStream, ScBigAddress& rAdr );
89 inline void ScBigAddress::PutInOrder( ScBigAddress& r )
91 INT32 nTmp;
92 if ( r.nCol < nCol )
94 nTmp = r.nCol;
95 r.nCol = nCol;
96 nCol = nTmp;
98 if ( r.nRow < nRow )
100 nTmp = r.nRow;
101 r.nRow = nRow;
102 nRow = nTmp;
104 if ( r.nTab < nTab )
106 nTmp = r.nTab;
107 r.nTab = nTab;
108 nTab = nTmp;
113 inline BOOL ScBigAddress::IsValid( const ScDocument* pDoc ) const
114 { //! Min/Max sind ok, kennzeichnen ganze Col/Row/Tab
115 return
116 ((0 <= nCol && nCol <= MAXCOL)
117 || nCol == nInt32Min || nCol == nInt32Max) &&
118 ((0 <= nRow && nRow <= MAXROW)
119 || nRow == nInt32Min || nRow == nInt32Max) &&
120 ((0 <= nTab && nTab < pDoc->GetTableCount())
121 || nTab == nInt32Min || nTab == nInt32Max)
126 inline ScAddress ScBigAddress::MakeAddress() const
128 SCCOL nColA;
129 SCROW nRowA;
130 SCTAB nTabA;
132 if ( nCol < 0 )
133 nColA = 0;
134 else if ( nCol > MAXCOL )
135 nColA = MAXCOL;
136 else
137 nColA = (SCCOL) nCol;
139 if ( nRow < 0 )
140 nRowA = 0;
141 else if ( nRow > MAXROW )
142 nRowA = MAXROW;
143 else
144 nRowA = (SCROW) nRow;
146 if ( nTab < 0 )
147 nTabA = 0;
148 else if ( nTab > MAXTAB )
149 nTabA = MAXTAB;
150 else
151 nTabA = (SCTAB) nTab;
153 return ScAddress( nColA, nRowA, nTabA );
157 inline SvStream& operator<< ( SvStream& rStream, const ScBigAddress& rAdr )
159 rStream << rAdr.nCol << rAdr.nRow << rAdr.nTab;
160 return rStream;
164 inline SvStream& operator>> ( SvStream& rStream, ScBigAddress& rAdr )
166 rStream >> rAdr.nCol >> rAdr.nRow >> rAdr.nTab;
167 return rStream;
171 class ScBigRange
173 public:
175 ScBigAddress aStart;
176 ScBigAddress aEnd;
178 ScBigRange() : aStart(), aEnd() {}
179 ScBigRange( const ScBigAddress& s, const ScBigAddress& e )
180 : aStart( s ), aEnd( e ) { aStart.PutInOrder( aEnd ); }
181 ScBigRange( const ScBigRange& r )
182 : aStart( r.aStart ), aEnd( r.aEnd ) {}
183 ScBigRange( const ScRange& r )
184 : aStart( r.aStart ), aEnd( r.aEnd ) {}
185 ScBigRange( const ScBigAddress& r )
186 : aStart( r ), aEnd( r ) {}
187 ScBigRange( const ScAddress& r )
188 : aStart( r ), aEnd( r ) {}
189 ScBigRange( INT32 nCol, INT32 nRow, INT32 nTab )
190 : aStart( nCol, nRow, nTab ), aEnd( aStart ) {}
191 ScBigRange( INT32 nCol1, INT32 nRow1, INT32 nTab1,
192 INT32 nCol2, INT32 nRow2, INT32 nTab2 )
193 : aStart( nCol1, nRow1, nTab1 ),
194 aEnd( nCol2, nRow2, nTab2 ) {}
196 void Set( INT32 nCol1, INT32 nRow1, INT32 nTab1,
197 INT32 nCol2, INT32 nRow2, INT32 nTab2 )
198 { aStart.Set( nCol1, nRow1, nTab1 );
199 aEnd.Set( nCol2, nRow2, nTab2 ); }
201 void GetVars( INT32& nCol1, INT32& nRow1, INT32& nTab1,
202 INT32& nCol2, INT32& nRow2, INT32& nTab2 ) const
203 { aStart.GetVars( nCol1, nRow1, nTab1 );
204 aEnd.GetVars( nCol2, nRow2, nTab2 ); }
206 BOOL IsValid( const ScDocument* pDoc ) const
207 { return aStart.IsValid( pDoc ) && aEnd.IsValid( pDoc ); }
208 inline ScRange MakeRange() const
209 { return ScRange( aStart.MakeAddress(),
210 aEnd.MakeAddress() ); }
212 inline BOOL In( const ScBigAddress& ) const; // ist Address& in Range?
213 inline BOOL In( const ScBigRange& ) const; // ist Range& in Range?
214 inline BOOL Intersects( const ScBigRange& ) const; // ueberschneiden sich zwei Ranges?
216 ScBigRange& operator=( const ScBigRange& r )
217 { aStart = r.aStart; aEnd = r.aEnd; return *this; }
218 int operator==( const ScBigRange& r ) const
219 { return (aStart == r.aStart) && (aEnd == r.aEnd); }
220 int operator!=( const ScBigRange& r ) const
221 { return !operator==( r ); }
223 friend inline SvStream& operator<< ( SvStream& rStream, const ScBigRange& rRange );
224 friend inline SvStream& operator>> ( SvStream& rStream, ScBigRange& rRange );
228 inline BOOL ScBigRange::In( const ScBigAddress& rAddr ) const
230 return
231 aStart.Col() <= rAddr.Col() && rAddr.Col() <= aEnd.Col() &&
232 aStart.Row() <= rAddr.Row() && rAddr.Row() <= aEnd.Row() &&
233 aStart.Tab() <= rAddr.Tab() && rAddr.Tab() <= aEnd.Tab();
237 inline BOOL ScBigRange::In( const ScBigRange& r ) const
239 return
240 aStart.Col() <= r.aStart.Col() && r.aEnd.Col() <= aEnd.Col() &&
241 aStart.Row() <= r.aStart.Row() && r.aEnd.Row() <= aEnd.Row() &&
242 aStart.Tab() <= r.aStart.Tab() && r.aEnd.Tab() <= aEnd.Tab();
246 inline BOOL ScBigRange::Intersects( const ScBigRange& r ) const
248 return !(
249 Min( aEnd.Col(), r.aEnd.Col() ) < Max( aStart.Col(), r.aStart.Col() )
250 || Min( aEnd.Row(), r.aEnd.Row() ) < Max( aStart.Row(), r.aStart.Row() )
251 || Min( aEnd.Tab(), r.aEnd.Tab() ) < Max( aStart.Tab(), r.aStart.Tab() )
256 inline SvStream& operator<< ( SvStream& rStream, const ScBigRange& rRange )
258 rStream << rRange.aStart;
259 rStream << rRange.aEnd;
260 return rStream;
264 inline SvStream& operator>> ( SvStream& rStream, ScBigRange& rRange )
266 rStream >> rRange.aStart;
267 rStream >> rRange.aEnd;
268 return rStream;
273 #endif