Update ooo320-m1
[ooovba.git] / binfilter / inc / bf_sc / bigrange.hxx
blob8b55098676298de0707649df4d12aadc60c33113
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.6 $
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 #ifndef SC_DOCUMENT_HXX
36 #include "document.hxx"
37 #endif
38 namespace binfilter {
41 static const INT32 nInt32Min = 0x80000000;
42 static const INT32 nInt32Max = 0x7fffffff;
45 class ScBigAddress
47 INT32 nRow;
48 INT32 nCol;
49 INT32 nTab;
51 public:
52 ScBigAddress() : nCol(0), nRow(0), nTab(0) {}
53 ScBigAddress( INT32 nColP, INT32 nRowP, INT32 nTabP )
54 : nCol( nColP ), nRow( nRowP ), nTab( nTabP ) {}
55 ScBigAddress( const ScBigAddress& r )
56 : nCol( r.nCol ), nRow( r.nRow ), nTab( r.nTab ) {}
57 ScBigAddress( const ScAddress& r )
58 : nCol( r.Col() ), nRow( r.Row() ), nTab( r.Tab() ) {}
60 INT32 Col() const { return nCol; }
61 INT32 Row() const { return nRow; }
62 INT32 Tab() const { return nTab; }
64 void Set( INT32 nColP, INT32 nRowP, INT32 nTabP )
65 { nCol = nColP; nRow = nRowP; nTab = nTabP; }
66 void SetCol( INT32 nColP ) { nCol = nColP; }
67 void SetRow( INT32 nRowP ) { nRow = nRowP; }
68 void SetTab( INT32 nTabP ) { nTab = nTabP; }
69 void IncCol( INT32 n = 1 ) { nCol += n; }
70 void IncRow( INT32 n = 1 ) { nRow += n; }
71 void IncTab( INT32 n = 1 ) { nTab += n; }
73 void GetVars( INT32& nColP, INT32& nRowP, INT32& nTabP ) const
74 { nColP = nCol; nRowP = nRow; nTabP = nTab; }
76 inline void PutInOrder( ScBigAddress& r );
77 inline BOOL IsValid( const ScDocument* ) const;
78 inline ScAddress MakeAddress() const;
80 ScBigAddress& operator=( const ScBigAddress& r )
81 { nCol = r.nCol; nRow = r.nRow; nTab = r.nTab; return *this; }
82 ScBigAddress& operator=( const ScAddress& r )
83 { nCol = r.Col(); nRow = r.Row(); nTab = r.Tab(); return *this; }
84 int operator==( const ScBigAddress& r ) const
85 { return nCol == r.nCol && nRow == r.nRow && nTab == r.nTab; }
86 int operator!=( const ScBigAddress& r ) const
87 { return !operator==( r ); }
89 friend inline SvStream& operator<< ( SvStream& rStream, const ScBigAddress& rAdr );
90 friend inline SvStream& operator>> ( SvStream& rStream, ScBigAddress& rAdr );
94 inline void ScBigAddress::PutInOrder( ScBigAddress& r )
96 INT32 nTmp;
97 if ( r.nCol < nCol )
99 nTmp = r.nCol;
100 r.nCol = nCol;
101 nCol = nTmp;
103 if ( r.nRow < nRow )
105 nTmp = r.nRow;
106 r.nRow = nRow;
107 nRow = nTmp;
109 if ( r.nTab < nTab )
111 nTmp = r.nTab;
112 r.nTab = nTab;
113 nTab = nTmp;
118 inline BOOL ScBigAddress::IsValid( const ScDocument* pDoc ) const
119 { //! Min/Max sind ok, kennzeichnen ganze Col/Row/Tab
120 return
121 ((0 <= nCol && nCol <= MAXCOL)
122 || nCol == nInt32Min || nCol == nInt32Max) &&
123 ((0 <= nRow && nRow <= MAXROW)
124 || nRow == nInt32Min || nRow == nInt32Max) &&
125 ((0 <= nTab && nTab < pDoc->GetTableCount())
126 || nTab == nInt32Min || nTab == nInt32Max)
131 inline ScAddress ScBigAddress::MakeAddress() const
133 USHORT nColA, nRowA, nTabA;
135 if ( nCol < 0 )
136 nColA = 0;
137 else if ( nCol > MAXCOL )
138 nColA = MAXCOL;
139 else
140 nColA = (USHORT) nCol;
142 if ( nRow < 0 )
143 nRowA = 0;
144 else if ( nRow > MAXROW )
145 nRowA = MAXROW;
146 else
147 nRowA = (USHORT) nRow;
149 if ( nTab < 0 )
150 nTabA = 0;
151 else if ( nTab > MAXTAB )
152 nTabA = MAXTAB;
153 else
154 nTabA = (USHORT) 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 } //namespace binfilter
277 #endif