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
33 #include "document.hxx"
36 static const INT32 nInt32Min
= 0x80000000;
37 static const INT32 nInt32Max
= 0x7fffffff;
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
)
113 inline BOOL
ScBigAddress::IsValid( const ScDocument
* pDoc
) const
114 { //! Min/Max sind ok, kennzeichnen ganze Col/Row/Tab
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
134 else if ( nCol
> MAXCOL
)
137 nColA
= (SCCOL
) nCol
;
141 else if ( nRow
> MAXROW
)
144 nRowA
= (SCROW
) nRow
;
148 else if ( nTab
> MAXTAB
)
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
;
164 inline SvStream
& operator>> ( SvStream
& rStream
, ScBigAddress
& rAdr
)
166 rStream
>> rAdr
.nCol
>> rAdr
.nRow
>> rAdr
.nTab
;
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
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
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
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
;
264 inline SvStream
& operator>> ( SvStream
& rStream
, ScBigRange
& rRange
)
266 rStream
>> rRange
.aStart
;
267 rStream
>> rRange
.aEnd
;