update dev300-m57
[ooovba.git] / sc / inc / bigrange.hxx
blobd4c988962df77303f2a43d12d7659599ce6dd54f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: bigrange.hxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SC_BIGRANGE_HXX
32 #define SC_BIGRANGE_HXX
35 #include "global.hxx"
36 #include "document.hxx"
39 static const INT32 nInt32Min = 0x80000000;
40 static const INT32 nInt32Max = 0x7fffffff;
43 class ScBigAddress
45 INT32 nRow;
46 INT32 nCol;
47 INT32 nTab;
49 public:
50 ScBigAddress() : nRow(0), nCol(0), nTab(0) {}
51 ScBigAddress( INT32 nColP, INT32 nRowP, INT32 nTabP )
52 : nRow( nRowP ), nCol( nColP ), nTab( nTabP ) {}
53 ScBigAddress( const ScBigAddress& r )
54 : nRow( r.nRow ), nCol( r.nCol ), nTab( r.nTab ) {}
55 ScBigAddress( const ScAddress& r )
56 : nRow( r.Row() ), nCol( r.Col() ), nTab( r.Tab() ) {}
58 INT32 Col() const { return nCol; }
59 INT32 Row() const { return nRow; }
60 INT32 Tab() const { return nTab; }
62 void Set( INT32 nColP, INT32 nRowP, INT32 nTabP )
63 { nCol = nColP; nRow = nRowP; nTab = nTabP; }
64 void SetCol( INT32 nColP ) { nCol = nColP; }
65 void SetRow( INT32 nRowP ) { nRow = nRowP; }
66 void SetTab( INT32 nTabP ) { nTab = nTabP; }
67 void IncCol( INT32 n = 1 ) { nCol += n; }
68 void IncRow( INT32 n = 1 ) { nRow += n; }
69 void IncTab( INT32 n = 1 ) { nTab += n; }
71 void GetVars( INT32& nColP, INT32& nRowP, INT32& nTabP ) const
72 { nColP = nCol; nRowP = nRow; nTabP = nTab; }
74 inline void PutInOrder( ScBigAddress& r );
75 inline BOOL IsValid( const ScDocument* ) const;
76 inline ScAddress MakeAddress() const;
78 ScBigAddress& operator=( const ScBigAddress& r )
79 { nCol = r.nCol; nRow = r.nRow; nTab = r.nTab; return *this; }
80 ScBigAddress& operator=( const ScAddress& r )
81 { nCol = r.Col(); nRow = r.Row(); nTab = r.Tab(); return *this; }
82 int operator==( const ScBigAddress& r ) const
83 { return nCol == r.nCol && nRow == r.nRow && nTab == r.nTab; }
84 int operator!=( const ScBigAddress& r ) const
85 { return !operator==( r ); }
87 friend inline SvStream& operator<< ( SvStream& rStream, const ScBigAddress& rAdr );
88 friend inline SvStream& operator>> ( SvStream& rStream, ScBigAddress& rAdr );
92 inline void ScBigAddress::PutInOrder( ScBigAddress& r )
94 INT32 nTmp;
95 if ( r.nCol < nCol )
97 nTmp = r.nCol;
98 r.nCol = nCol;
99 nCol = nTmp;
101 if ( r.nRow < nRow )
103 nTmp = r.nRow;
104 r.nRow = nRow;
105 nRow = nTmp;
107 if ( r.nTab < nTab )
109 nTmp = r.nTab;
110 r.nTab = nTab;
111 nTab = nTmp;
116 inline BOOL ScBigAddress::IsValid( const ScDocument* pDoc ) const
117 { //! Min/Max sind ok, kennzeichnen ganze Col/Row/Tab
118 return
119 ((0 <= nCol && nCol <= MAXCOL)
120 || nCol == nInt32Min || nCol == nInt32Max) &&
121 ((0 <= nRow && nRow <= MAXROW)
122 || nRow == nInt32Min || nRow == nInt32Max) &&
123 ((0 <= nTab && nTab < pDoc->GetTableCount())
124 || nTab == nInt32Min || nTab == nInt32Max)
129 inline ScAddress ScBigAddress::MakeAddress() const
131 SCCOL nColA;
132 SCROW nRowA;
133 SCTAB nTabA;
135 if ( nCol < 0 )
136 nColA = 0;
137 else if ( nCol > MAXCOL )
138 nColA = MAXCOL;
139 else
140 nColA = (SCCOL) nCol;
142 if ( nRow < 0 )
143 nRowA = 0;
144 else if ( nRow > MAXROW )
145 nRowA = MAXROW;
146 else
147 nRowA = (SCROW) nRow;
149 if ( nTab < 0 )
150 nTabA = 0;
151 else if ( nTab > MAXTAB )
152 nTabA = MAXTAB;
153 else
154 nTabA = (SCTAB) nTab;
156 return ScAddress( nColA, nRowA, nTabA );
160 inline SvStream& operator<< ( SvStream& rStream, const ScBigAddress& rAdr )
162 rStream << rAdr.nCol << rAdr.nRow << rAdr.nTab;
163 return rStream;
167 inline SvStream& operator>> ( SvStream& rStream, ScBigAddress& rAdr )
169 rStream >> rAdr.nCol >> rAdr.nRow >> rAdr.nTab;
170 return rStream;
174 class ScBigRange
176 public:
178 ScBigAddress aStart;
179 ScBigAddress aEnd;
181 ScBigRange() : aStart(), aEnd() {}
182 ScBigRange( const ScBigAddress& s, const ScBigAddress& e )
183 : aStart( s ), aEnd( e ) { aStart.PutInOrder( aEnd ); }
184 ScBigRange( const ScBigRange& r )
185 : aStart( r.aStart ), aEnd( r.aEnd ) {}
186 ScBigRange( const ScRange& r )
187 : aStart( r.aStart ), aEnd( r.aEnd ) {}
188 ScBigRange( const ScBigAddress& r )
189 : aStart( r ), aEnd( r ) {}
190 ScBigRange( const ScAddress& r )
191 : aStart( r ), aEnd( r ) {}
192 ScBigRange( INT32 nCol, INT32 nRow, INT32 nTab )
193 : aStart( nCol, nRow, nTab ), aEnd( aStart ) {}
194 ScBigRange( INT32 nCol1, INT32 nRow1, INT32 nTab1,
195 INT32 nCol2, INT32 nRow2, INT32 nTab2 )
196 : aStart( nCol1, nRow1, nTab1 ),
197 aEnd( nCol2, nRow2, nTab2 ) {}
199 void Set( INT32 nCol1, INT32 nRow1, INT32 nTab1,
200 INT32 nCol2, INT32 nRow2, INT32 nTab2 )
201 { aStart.Set( nCol1, nRow1, nTab1 );
202 aEnd.Set( nCol2, nRow2, nTab2 ); }
204 void GetVars( INT32& nCol1, INT32& nRow1, INT32& nTab1,
205 INT32& nCol2, INT32& nRow2, INT32& nTab2 ) const
206 { aStart.GetVars( nCol1, nRow1, nTab1 );
207 aEnd.GetVars( nCol2, nRow2, nTab2 ); }
209 BOOL IsValid( const ScDocument* pDoc ) const
210 { return aStart.IsValid( pDoc ) && aEnd.IsValid( pDoc ); }
211 inline ScRange MakeRange() const
212 { return ScRange( aStart.MakeAddress(),
213 aEnd.MakeAddress() ); }
215 inline BOOL In( const ScBigAddress& ) const; // ist Address& in Range?
216 inline BOOL In( const ScBigRange& ) const; // ist Range& in Range?
217 inline BOOL Intersects( const ScBigRange& ) const; // ueberschneiden sich zwei Ranges?
219 ScBigRange& operator=( const ScBigRange& r )
220 { aStart = r.aStart; aEnd = r.aEnd; return *this; }
221 int operator==( const ScBigRange& r ) const
222 { return (aStart == r.aStart) && (aEnd == r.aEnd); }
223 int operator!=( const ScBigRange& r ) const
224 { return !operator==( r ); }
226 friend inline SvStream& operator<< ( SvStream& rStream, const ScBigRange& rRange );
227 friend inline SvStream& operator>> ( SvStream& rStream, ScBigRange& rRange );
231 inline BOOL ScBigRange::In( const ScBigAddress& rAddr ) const
233 return
234 aStart.Col() <= rAddr.Col() && rAddr.Col() <= aEnd.Col() &&
235 aStart.Row() <= rAddr.Row() && rAddr.Row() <= aEnd.Row() &&
236 aStart.Tab() <= rAddr.Tab() && rAddr.Tab() <= aEnd.Tab();
240 inline BOOL ScBigRange::In( const ScBigRange& r ) const
242 return
243 aStart.Col() <= r.aStart.Col() && r.aEnd.Col() <= aEnd.Col() &&
244 aStart.Row() <= r.aStart.Row() && r.aEnd.Row() <= aEnd.Row() &&
245 aStart.Tab() <= r.aStart.Tab() && r.aEnd.Tab() <= aEnd.Tab();
249 inline BOOL ScBigRange::Intersects( const ScBigRange& r ) const
251 return !(
252 Min( aEnd.Col(), r.aEnd.Col() ) < Max( aStart.Col(), r.aStart.Col() )
253 || Min( aEnd.Row(), r.aEnd.Row() ) < Max( aStart.Row(), r.aStart.Row() )
254 || Min( aEnd.Tab(), r.aEnd.Tab() ) < Max( aStart.Tab(), r.aStart.Tab() )
259 inline SvStream& operator<< ( SvStream& rStream, const ScBigRange& rRange )
261 rStream << rRange.aStart;
262 rStream << rRange.aEnd;
263 return rStream;
267 inline SvStream& operator>> ( SvStream& rStream, ScBigRange& rRange )
269 rStream >> rRange.aStart;
270 rStream >> rRange.aEnd;
271 return rStream;
276 #endif