Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / sc / inc / bigrange.hxx
blob8fc3aaf33a76f0db3731da77ae8b069ab5610551
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SC_INC_BIGRANGE_HXX
21 #define INCLUDED_SC_INC_BIGRANGE_HXX
23 #include "global.hxx"
24 #include <algorithm>
26 static const sal_Int32 nInt32Min = 0x80000000;
27 static const sal_Int32 nInt32Max = 0x7fffffff;
29 class ScDocument;
31 class ScBigAddress
33 sal_Int32 nRow;
34 sal_Int32 nCol;
35 sal_Int32 nTab;
37 public:
38 ScBigAddress() : nRow(0), nCol(0), nTab(0) {}
39 ScBigAddress( sal_Int32 nColP, sal_Int32 nRowP, sal_Int32 nTabP )
40 : nRow( nRowP ), nCol( nColP ), nTab( nTabP ) {}
41 ScBigAddress( const ScBigAddress& r )
42 : nRow( r.nRow ), nCol( r.nCol ), nTab( r.nTab ) {}
43 ScBigAddress( const ScAddress& r )
44 : nRow( r.Row() ), nCol( r.Col() ), nTab( r.Tab() ) {}
46 sal_Int32 Col() const { return nCol; }
47 sal_Int32 Row() const { return nRow; }
48 sal_Int32 Tab() const { return nTab; }
50 void Set( sal_Int32 nColP, sal_Int32 nRowP, sal_Int32 nTabP )
51 { nCol = nColP; nRow = nRowP; nTab = nTabP; }
52 void SetCol( sal_Int32 nColP ) { nCol = nColP; }
53 void SetRow( sal_Int32 nRowP ) { nRow = nRowP; }
54 void SetTab( sal_Int32 nTabP ) { nTab = nTabP; }
55 void IncCol( sal_Int32 n = 1 ) { nCol += n; }
56 void IncRow( sal_Int32 n = 1 ) { nRow += n; }
57 void IncTab( sal_Int32 n = 1 ) { nTab += n; }
59 void GetVars( sal_Int32& nColP, sal_Int32& nRowP, sal_Int32& nTabP ) const
60 { nColP = nCol; nRowP = nRow; nTabP = nTab; }
62 inline void PutInOrder( ScBigAddress& r );
63 bool IsValid( const ScDocument* pDoc ) const;
64 inline ScAddress MakeAddress() const;
66 ScBigAddress& operator=( const ScBigAddress& r )
67 { nCol = r.nCol; nRow = r.nRow; nTab = r.nTab; return *this; }
68 ScBigAddress& operator=( const ScAddress& r )
69 { nCol = r.Col(); nRow = r.Row(); nTab = r.Tab(); return *this; }
70 bool operator==( const ScBigAddress& r ) const
71 { return nCol == r.nCol && nRow == r.nRow && nTab == r.nTab; }
72 bool operator!=( const ScBigAddress& r ) const
73 { return !operator==( r ); }
76 inline void ScBigAddress::PutInOrder( ScBigAddress& r )
78 sal_Int32 nTmp;
79 if ( r.nCol < nCol )
81 nTmp = r.nCol;
82 r.nCol = nCol;
83 nCol = nTmp;
85 if ( r.nRow < nRow )
87 nTmp = r.nRow;
88 r.nRow = nRow;
89 nRow = nTmp;
91 if ( r.nTab < nTab )
93 nTmp = r.nTab;
94 r.nTab = nTab;
95 nTab = nTmp;
99 inline ScAddress ScBigAddress::MakeAddress() const
101 SCCOL nColA;
102 SCROW nRowA;
103 SCTAB nTabA;
105 if ( nCol < 0 )
106 nColA = 0;
107 else if ( nCol > MAXCOL )
108 nColA = MAXCOL;
109 else
110 nColA = (SCCOL) nCol;
112 if ( nRow < 0 )
113 nRowA = 0;
114 else if ( nRow > MAXROW )
115 nRowA = MAXROW;
116 else
117 nRowA = (SCROW) nRow;
119 if ( nTab < 0 )
120 nTabA = 0;
121 else if ( nTab > MAXTAB )
122 nTabA = MAXTAB;
123 else
124 nTabA = (SCTAB) nTab;
126 return ScAddress( nColA, nRowA, nTabA );
129 class ScBigRange
131 public:
133 ScBigAddress aStart;
134 ScBigAddress aEnd;
136 ScBigRange() : aStart(), aEnd() {}
137 ScBigRange( const ScBigRange& r )
138 : aStart( r.aStart ), aEnd( r.aEnd ) {}
139 ScBigRange( const ScRange& r )
140 : aStart( r.aStart ), aEnd( r.aEnd ) {}
141 ScBigRange( sal_Int32 nCol1, sal_Int32 nRow1, sal_Int32 nTab1,
142 sal_Int32 nCol2, sal_Int32 nRow2, sal_Int32 nTab2 )
143 : aStart( nCol1, nRow1, nTab1 ),
144 aEnd( nCol2, nRow2, nTab2 ) {}
146 void Set( sal_Int32 nCol1, sal_Int32 nRow1, sal_Int32 nTab1,
147 sal_Int32 nCol2, sal_Int32 nRow2, sal_Int32 nTab2 )
148 { aStart.Set( nCol1, nRow1, nTab1 );
149 aEnd.Set( nCol2, nRow2, nTab2 ); }
151 void GetVars( sal_Int32& nCol1, sal_Int32& nRow1, sal_Int32& nTab1,
152 sal_Int32& nCol2, sal_Int32& nRow2, sal_Int32& nTab2 ) const
153 { aStart.GetVars( nCol1, nRow1, nTab1 );
154 aEnd.GetVars( nCol2, nRow2, nTab2 ); }
156 bool IsValid( const ScDocument* pDoc ) const
157 { return aStart.IsValid( pDoc ) && aEnd.IsValid( pDoc ); }
158 inline ScRange MakeRange() const
159 { return ScRange( aStart.MakeAddress(),
160 aEnd.MakeAddress() ); }
162 inline bool In( const ScBigAddress& ) const; ///< is Address& in range?
163 inline bool In( const ScBigRange& ) const; ///< is Range& in range?
164 inline bool Intersects( const ScBigRange& ) const; ///< do two ranges overlap?
166 ScBigRange& operator=( const ScBigRange& r )
167 { aStart = r.aStart; aEnd = r.aEnd; return *this; }
168 bool operator==( const ScBigRange& r ) const
169 { return (aStart == r.aStart) && (aEnd == r.aEnd); }
170 bool operator!=( const ScBigRange& r ) const
171 { return !operator==( r ); }
174 inline bool ScBigRange::In( const ScBigAddress& rAddr ) const
176 return
177 aStart.Col() <= rAddr.Col() && rAddr.Col() <= aEnd.Col() &&
178 aStart.Row() <= rAddr.Row() && rAddr.Row() <= aEnd.Row() &&
179 aStart.Tab() <= rAddr.Tab() && rAddr.Tab() <= aEnd.Tab();
182 inline bool ScBigRange::In( const ScBigRange& r ) const
184 return
185 aStart.Col() <= r.aStart.Col() && r.aEnd.Col() <= aEnd.Col() &&
186 aStart.Row() <= r.aStart.Row() && r.aEnd.Row() <= aEnd.Row() &&
187 aStart.Tab() <= r.aStart.Tab() && r.aEnd.Tab() <= aEnd.Tab();
190 inline bool ScBigRange::Intersects( const ScBigRange& r ) const
192 return !(
193 std::min( aEnd.Col(), r.aEnd.Col() ) < std::max( aStart.Col(), r.aStart.Col() )
194 || std::min( aEnd.Row(), r.aEnd.Row() ) < std::max( aStart.Row(), r.aStart.Row() )
195 || std::min( aEnd.Tab(), r.aEnd.Tab() ) < std::max( aStart.Tab(), r.aStart.Tab() )
199 #endif
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */