xref: /aoo42x/main/sc/inc/bigrange.hxx (revision 38d50f7b)
1*38d50f7bSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*38d50f7bSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*38d50f7bSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*38d50f7bSAndrew Rist  * distributed with this work for additional information
6*38d50f7bSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*38d50f7bSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*38d50f7bSAndrew Rist  * "License"); you may not use this file except in compliance
9*38d50f7bSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*38d50f7bSAndrew Rist  *
11*38d50f7bSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*38d50f7bSAndrew Rist  *
13*38d50f7bSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*38d50f7bSAndrew Rist  * software distributed under the License is distributed on an
15*38d50f7bSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*38d50f7bSAndrew Rist  * KIND, either express or implied.  See the License for the
17*38d50f7bSAndrew Rist  * specific language governing permissions and limitations
18*38d50f7bSAndrew Rist  * under the License.
19*38d50f7bSAndrew Rist  *
20*38d50f7bSAndrew Rist  *************************************************************/
21*38d50f7bSAndrew Rist 
22*38d50f7bSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef SC_BIGRANGE_HXX
25cdf0e10cSrcweir #define SC_BIGRANGE_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include "global.hxx"
29cdf0e10cSrcweir #include "document.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir 
32cdf0e10cSrcweir static const sal_Int32 nInt32Min = 0x80000000;
33cdf0e10cSrcweir static const sal_Int32 nInt32Max = 0x7fffffff;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir 
36cdf0e10cSrcweir class ScBigAddress
37cdf0e10cSrcweir {
38cdf0e10cSrcweir 	sal_Int32	nRow;
39cdf0e10cSrcweir 	sal_Int32	nCol;
40cdf0e10cSrcweir 	sal_Int32	nTab;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir public:
ScBigAddress()43cdf0e10cSrcweir 			ScBigAddress() : nRow(0), nCol(0), nTab(0) {}
ScBigAddress(sal_Int32 nColP,sal_Int32 nRowP,sal_Int32 nTabP)44cdf0e10cSrcweir 			ScBigAddress( sal_Int32 nColP, sal_Int32 nRowP, sal_Int32 nTabP )
45cdf0e10cSrcweir 				: nRow( nRowP ), nCol( nColP ), nTab( nTabP ) {}
ScBigAddress(const ScBigAddress & r)46cdf0e10cSrcweir 			ScBigAddress( const ScBigAddress& r )
47cdf0e10cSrcweir 				: nRow( r.nRow ), nCol( r.nCol ), nTab( r.nTab ) {}
ScBigAddress(const ScAddress & r)48cdf0e10cSrcweir 			ScBigAddress( const ScAddress& r )
49cdf0e10cSrcweir 				: nRow( r.Row() ), nCol( r.Col() ), nTab( r.Tab() ) {}
50cdf0e10cSrcweir 
Col() const51cdf0e10cSrcweir 	sal_Int32	Col() const { return nCol; }
Row() const52cdf0e10cSrcweir 	sal_Int32	Row() const { return nRow; }
Tab() const53cdf0e10cSrcweir 	sal_Int32	Tab() const { return nTab; }
54cdf0e10cSrcweir 
Set(sal_Int32 nColP,sal_Int32 nRowP,sal_Int32 nTabP)55cdf0e10cSrcweir 	void	Set( sal_Int32 nColP, sal_Int32 nRowP, sal_Int32 nTabP )
56cdf0e10cSrcweir 				{ nCol = nColP; nRow = nRowP; nTab = nTabP; }
SetCol(sal_Int32 nColP)57cdf0e10cSrcweir 	void	SetCol( sal_Int32 nColP ) { nCol = nColP; }
SetRow(sal_Int32 nRowP)58cdf0e10cSrcweir 	void	SetRow( sal_Int32 nRowP ) { nRow = nRowP; }
SetTab(sal_Int32 nTabP)59cdf0e10cSrcweir 	void	SetTab( sal_Int32 nTabP ) { nTab = nTabP; }
IncCol(sal_Int32 n=1)60cdf0e10cSrcweir 	void	IncCol( sal_Int32 n = 1 ) { nCol += n; }
IncRow(sal_Int32 n=1)61cdf0e10cSrcweir 	void	IncRow( sal_Int32 n = 1 ) { nRow += n; }
IncTab(sal_Int32 n=1)62cdf0e10cSrcweir 	void	IncTab( sal_Int32 n = 1 ) { nTab += n; }
63cdf0e10cSrcweir 
GetVars(sal_Int32 & nColP,sal_Int32 & nRowP,sal_Int32 & nTabP) const64cdf0e10cSrcweir 	void	GetVars( sal_Int32& nColP, sal_Int32& nRowP, sal_Int32& nTabP ) const
65cdf0e10cSrcweir 				{ nColP = nCol; nRowP = nRow; nTabP = nTab; }
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 	inline void		PutInOrder( ScBigAddress& r );
68cdf0e10cSrcweir 	inline sal_Bool		IsValid( const ScDocument* ) const;
69cdf0e10cSrcweir 	inline ScAddress	MakeAddress() const;
70cdf0e10cSrcweir 
operator =(const ScBigAddress & r)71cdf0e10cSrcweir 	ScBigAddress&	operator=( const ScBigAddress& r )
72cdf0e10cSrcweir 					{ nCol = r.nCol; nRow = r.nRow; nTab = r.nTab; return *this; }
operator =(const ScAddress & r)73cdf0e10cSrcweir 	ScBigAddress&	operator=( const ScAddress& r )
74cdf0e10cSrcweir 					{ nCol = r.Col(); nRow = r.Row(); nTab = r.Tab(); return *this; }
operator ==(const ScBigAddress & r) const75cdf0e10cSrcweir 	int				operator==( const ScBigAddress& r ) const
76cdf0e10cSrcweir 					{ return nCol == r.nCol && nRow == r.nRow && nTab == r.nTab; }
operator !=(const ScBigAddress & r) const77cdf0e10cSrcweir 	int				operator!=( const ScBigAddress& r ) const
78cdf0e10cSrcweir 					{ return !operator==( r ); }
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 	friend inline SvStream& operator<< ( SvStream& rStream, const ScBigAddress& rAdr );
81cdf0e10cSrcweir 	friend inline SvStream& operator>> ( SvStream& rStream, ScBigAddress& rAdr );
82cdf0e10cSrcweir };
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 
PutInOrder(ScBigAddress & r)85cdf0e10cSrcweir inline void ScBigAddress::PutInOrder( ScBigAddress& r )
86cdf0e10cSrcweir {
87cdf0e10cSrcweir 	sal_Int32 nTmp;
88cdf0e10cSrcweir 	if ( r.nCol < nCol )
89cdf0e10cSrcweir 	{
90cdf0e10cSrcweir 		nTmp = r.nCol;
91cdf0e10cSrcweir 		r.nCol = nCol;
92cdf0e10cSrcweir 		nCol = nTmp;
93cdf0e10cSrcweir 	}
94cdf0e10cSrcweir 	if ( r.nRow < nRow )
95cdf0e10cSrcweir 	{
96cdf0e10cSrcweir 		nTmp = r.nRow;
97cdf0e10cSrcweir 		r.nRow = nRow;
98cdf0e10cSrcweir 		nRow = nTmp;
99cdf0e10cSrcweir 	}
100cdf0e10cSrcweir 	if ( r.nTab < nTab )
101cdf0e10cSrcweir 	{
102cdf0e10cSrcweir 		nTmp = r.nTab;
103cdf0e10cSrcweir 		r.nTab = nTab;
104cdf0e10cSrcweir 		nTab = nTmp;
105cdf0e10cSrcweir 	}
106cdf0e10cSrcweir }
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 
IsValid(const ScDocument * pDoc) const109cdf0e10cSrcweir inline sal_Bool ScBigAddress::IsValid( const ScDocument* pDoc ) const
110cdf0e10cSrcweir {	//! Min/Max sind ok, kennzeichnen ganze Col/Row/Tab
111cdf0e10cSrcweir 	return
112cdf0e10cSrcweir 		((0 <= nCol && nCol <= MAXCOL)
113cdf0e10cSrcweir 			|| nCol == nInt32Min || nCol == nInt32Max) &&
114cdf0e10cSrcweir 		((0 <= nRow && nRow <= MAXROW)
115cdf0e10cSrcweir 			|| nRow == nInt32Min || nRow == nInt32Max) &&
116cdf0e10cSrcweir 		((0 <= nTab && nTab < pDoc->GetTableCount())
117cdf0e10cSrcweir 			|| nTab == nInt32Min || nTab == nInt32Max)
118cdf0e10cSrcweir 		;
119cdf0e10cSrcweir }
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 
MakeAddress() const122cdf0e10cSrcweir inline ScAddress ScBigAddress::MakeAddress() const
123cdf0e10cSrcweir {
124cdf0e10cSrcweir 	SCCOL nColA;
125cdf0e10cSrcweir 	SCROW nRowA;
126cdf0e10cSrcweir 	SCTAB nTabA;
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 	if ( nCol < 0 )
129cdf0e10cSrcweir 		nColA = 0;
130cdf0e10cSrcweir 	else if ( nCol > MAXCOL )
131cdf0e10cSrcweir 		nColA = MAXCOL;
132cdf0e10cSrcweir 	else
133cdf0e10cSrcweir 		nColA = (SCCOL) nCol;
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 	if ( nRow < 0 )
136cdf0e10cSrcweir 		nRowA = 0;
137cdf0e10cSrcweir 	else if ( nRow > MAXROW )
138cdf0e10cSrcweir 		nRowA = MAXROW;
139cdf0e10cSrcweir 	else
140cdf0e10cSrcweir 		nRowA = (SCROW) nRow;
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 	if ( nTab < 0 )
143cdf0e10cSrcweir 		nTabA = 0;
144cdf0e10cSrcweir 	else if ( nTab > MAXTAB )
145cdf0e10cSrcweir 		nTabA = MAXTAB;
146cdf0e10cSrcweir 	else
147cdf0e10cSrcweir 		nTabA = (SCTAB) nTab;
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 	return ScAddress( nColA, nRowA, nTabA );
150cdf0e10cSrcweir }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir 
operator <<(SvStream & rStream,const ScBigAddress & rAdr)153cdf0e10cSrcweir inline SvStream& operator<< ( SvStream& rStream, const ScBigAddress& rAdr )
154cdf0e10cSrcweir {
155cdf0e10cSrcweir 	rStream << rAdr.nCol << rAdr.nRow << rAdr.nTab;
156cdf0e10cSrcweir 	return rStream;
157cdf0e10cSrcweir }
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 
operator >>(SvStream & rStream,ScBigAddress & rAdr)160cdf0e10cSrcweir inline SvStream& operator>> ( SvStream& rStream, ScBigAddress& rAdr )
161cdf0e10cSrcweir {
162cdf0e10cSrcweir 	rStream >> rAdr.nCol >> rAdr.nRow >> rAdr.nTab;
163cdf0e10cSrcweir 	return rStream;
164cdf0e10cSrcweir }
165cdf0e10cSrcweir 
166cdf0e10cSrcweir 
167cdf0e10cSrcweir class ScBigRange
168cdf0e10cSrcweir {
169cdf0e10cSrcweir public:
170cdf0e10cSrcweir 
171cdf0e10cSrcweir 	ScBigAddress	aStart;
172cdf0e10cSrcweir 	ScBigAddress	aEnd;
173cdf0e10cSrcweir 
ScBigRange()174cdf0e10cSrcweir 					ScBigRange() : aStart(), aEnd() {}
ScBigRange(const ScBigAddress & s,const ScBigAddress & e)175cdf0e10cSrcweir 					ScBigRange( const ScBigAddress& s, const ScBigAddress& e )
176cdf0e10cSrcweir 						: aStart( s ), aEnd( e ) { aStart.PutInOrder( aEnd ); }
ScBigRange(const ScBigRange & r)177cdf0e10cSrcweir 					ScBigRange( const ScBigRange& r )
178cdf0e10cSrcweir 						: aStart( r.aStart ), aEnd( r.aEnd ) {}
ScBigRange(const ScRange & r)179cdf0e10cSrcweir 					ScBigRange( const ScRange& r )
180cdf0e10cSrcweir 						: aStart( r.aStart ), aEnd( r.aEnd ) {}
ScBigRange(const ScBigAddress & r)181cdf0e10cSrcweir 					ScBigRange( const ScBigAddress& r )
182cdf0e10cSrcweir 						: aStart( r ), aEnd( r ) {}
ScBigRange(const ScAddress & r)183cdf0e10cSrcweir 					ScBigRange( const ScAddress& r )
184cdf0e10cSrcweir 						: aStart( r ), aEnd( r ) {}
ScBigRange(sal_Int32 nCol,sal_Int32 nRow,sal_Int32 nTab)185cdf0e10cSrcweir 					ScBigRange( sal_Int32 nCol, sal_Int32 nRow, sal_Int32 nTab )
186cdf0e10cSrcweir 						: aStart( nCol, nRow, nTab ), aEnd( aStart ) {}
ScBigRange(sal_Int32 nCol1,sal_Int32 nRow1,sal_Int32 nTab1,sal_Int32 nCol2,sal_Int32 nRow2,sal_Int32 nTab2)187cdf0e10cSrcweir 					ScBigRange( sal_Int32 nCol1, sal_Int32 nRow1, sal_Int32 nTab1,
188cdf0e10cSrcweir 							sal_Int32 nCol2, sal_Int32 nRow2, sal_Int32 nTab2 )
189cdf0e10cSrcweir 						: aStart( nCol1, nRow1, nTab1 ),
190cdf0e10cSrcweir 						aEnd( nCol2, nRow2, nTab2 ) {}
191cdf0e10cSrcweir 
Set(sal_Int32 nCol1,sal_Int32 nRow1,sal_Int32 nTab1,sal_Int32 nCol2,sal_Int32 nRow2,sal_Int32 nTab2)192cdf0e10cSrcweir 	void	Set( sal_Int32 nCol1, sal_Int32 nRow1, sal_Int32 nTab1,
193cdf0e10cSrcweir 					 sal_Int32 nCol2, sal_Int32 nRow2, sal_Int32 nTab2 )
194cdf0e10cSrcweir 				{ aStart.Set( nCol1, nRow1, nTab1 );
195cdf0e10cSrcweir 					aEnd.Set( nCol2, nRow2, nTab2 ); }
196cdf0e10cSrcweir 
GetVars(sal_Int32 & nCol1,sal_Int32 & nRow1,sal_Int32 & nTab1,sal_Int32 & nCol2,sal_Int32 & nRow2,sal_Int32 & nTab2) const197cdf0e10cSrcweir 	void	GetVars( sal_Int32& nCol1, sal_Int32& nRow1, sal_Int32& nTab1,
198cdf0e10cSrcweir 					 sal_Int32& nCol2, sal_Int32& nRow2, sal_Int32& nTab2 ) const
199cdf0e10cSrcweir 				{ aStart.GetVars( nCol1, nRow1, nTab1 );
200cdf0e10cSrcweir 					aEnd.GetVars( nCol2, nRow2, nTab2 ); }
201cdf0e10cSrcweir 
IsValid(const ScDocument * pDoc) const202cdf0e10cSrcweir 	sal_Bool 	IsValid( const ScDocument* pDoc ) const
203cdf0e10cSrcweir 				{ return aStart.IsValid( pDoc ) && aEnd.IsValid( pDoc ); }
MakeRange() const204cdf0e10cSrcweir 	inline ScRange	MakeRange() const
205cdf0e10cSrcweir 					{ return ScRange( aStart.MakeAddress(),
206cdf0e10cSrcweir 						aEnd.MakeAddress() ); }
207cdf0e10cSrcweir 
208cdf0e10cSrcweir 	inline sal_Bool In( const ScBigAddress& ) const;	// ist Address& in Range?
209cdf0e10cSrcweir 	inline sal_Bool In( const ScBigRange& ) const;		// ist Range& in Range?
210cdf0e10cSrcweir 	inline sal_Bool Intersects( const ScBigRange& ) const;	// ueberschneiden sich zwei Ranges?
211cdf0e10cSrcweir 
operator =(const ScBigRange & r)212cdf0e10cSrcweir 	ScBigRange&		operator=( const ScBigRange& r )
213cdf0e10cSrcweir 						{ aStart = r.aStart; aEnd = r.aEnd; return *this; }
operator ==(const ScBigRange & r) const214cdf0e10cSrcweir 	int				operator==( const ScBigRange& r ) const
215cdf0e10cSrcweir 						{ return (aStart == r.aStart) && (aEnd == r.aEnd); }
operator !=(const ScBigRange & r) const216cdf0e10cSrcweir 	int				operator!=( const ScBigRange& r ) const
217cdf0e10cSrcweir 						{ return !operator==( r ); }
218cdf0e10cSrcweir 
219cdf0e10cSrcweir 	friend inline SvStream& operator<< ( SvStream& rStream, const ScBigRange& rRange );
220cdf0e10cSrcweir 	friend inline SvStream& operator>> ( SvStream& rStream, ScBigRange& rRange );
221cdf0e10cSrcweir };
222cdf0e10cSrcweir 
223cdf0e10cSrcweir 
In(const ScBigAddress & rAddr) const224cdf0e10cSrcweir inline sal_Bool ScBigRange::In( const ScBigAddress& rAddr ) const
225cdf0e10cSrcweir {
226cdf0e10cSrcweir 	return
227cdf0e10cSrcweir 		aStart.Col() <= rAddr.Col() && rAddr.Col() <= aEnd.Col() &&
228cdf0e10cSrcweir 		aStart.Row() <= rAddr.Row() && rAddr.Row() <= aEnd.Row() &&
229cdf0e10cSrcweir 		aStart.Tab() <= rAddr.Tab() && rAddr.Tab() <= aEnd.Tab();
230cdf0e10cSrcweir }
231cdf0e10cSrcweir 
232cdf0e10cSrcweir 
In(const ScBigRange & r) const233cdf0e10cSrcweir inline sal_Bool ScBigRange::In( const ScBigRange& r ) const
234cdf0e10cSrcweir {
235cdf0e10cSrcweir 	return
236cdf0e10cSrcweir 		aStart.Col() <= r.aStart.Col() && r.aEnd.Col() <= aEnd.Col() &&
237cdf0e10cSrcweir 		aStart.Row() <= r.aStart.Row() && r.aEnd.Row() <= aEnd.Row() &&
238cdf0e10cSrcweir 		aStart.Tab() <= r.aStart.Tab() && r.aEnd.Tab() <= aEnd.Tab();
239cdf0e10cSrcweir }
240cdf0e10cSrcweir 
241cdf0e10cSrcweir 
Intersects(const ScBigRange & r) const242cdf0e10cSrcweir inline sal_Bool ScBigRange::Intersects( const ScBigRange& r ) const
243cdf0e10cSrcweir {
244cdf0e10cSrcweir 	return !(
245cdf0e10cSrcweir 		Min( aEnd.Col(), r.aEnd.Col() ) < Max( aStart.Col(), r.aStart.Col() )
246cdf0e10cSrcweir 	 || Min( aEnd.Row(), r.aEnd.Row() ) < Max( aStart.Row(), r.aStart.Row() )
247cdf0e10cSrcweir 	 || Min( aEnd.Tab(), r.aEnd.Tab() ) < Max( aStart.Tab(), r.aStart.Tab() )
248cdf0e10cSrcweir 		);
249cdf0e10cSrcweir }
250cdf0e10cSrcweir 
251cdf0e10cSrcweir 
operator <<(SvStream & rStream,const ScBigRange & rRange)252cdf0e10cSrcweir inline SvStream& operator<< ( SvStream& rStream, const ScBigRange& rRange )
253cdf0e10cSrcweir {
254cdf0e10cSrcweir 	rStream << rRange.aStart;
255cdf0e10cSrcweir 	rStream << rRange.aEnd;
256cdf0e10cSrcweir 	return rStream;
257cdf0e10cSrcweir }
258cdf0e10cSrcweir 
259cdf0e10cSrcweir 
operator >>(SvStream & rStream,ScBigRange & rRange)260cdf0e10cSrcweir inline SvStream& operator>> ( SvStream& rStream, ScBigRange& rRange )
261cdf0e10cSrcweir {
262cdf0e10cSrcweir 	rStream >> rRange.aStart;
263cdf0e10cSrcweir 	rStream >> rRange.aEnd;
264cdf0e10cSrcweir 	return rStream;
265cdf0e10cSrcweir }
266cdf0e10cSrcweir 
267cdf0e10cSrcweir 
268cdf0e10cSrcweir 
269cdf0e10cSrcweir #endif
270