1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #include "refdata.hxx"
22 void ScSingleRefData::InitAddress( const ScAddress
& rAdr
)
24 InitAddress( rAdr
.Col(), rAdr
.Row(), rAdr
.Tab());
27 void ScSingleRefData::InitAddress( SCCOL nColP
, SCROW nRowP
, SCTAB nTabP
)
35 void ScSingleRefData::InitAddressRel( const ScAddress
& rAdr
, const ScAddress
& rPos
)
41 SetAddress(rAdr
, rPos
);
44 sal_uInt8
ScSingleRefData::FlagValue() const
49 void ScSingleRefData::SetAbsCol( SCCOL nVal
)
51 Flags
.bColRel
= false;
55 void ScSingleRefData::SetRelCol( SCCOL nVal
)
61 void ScSingleRefData::IncCol( SCCOL nInc
)
66 void ScSingleRefData::SetAbsRow( SCROW nVal
)
68 Flags
.bRowRel
= false;
72 void ScSingleRefData::SetRelRow( SCROW nVal
)
78 void ScSingleRefData::IncRow( SCROW nInc
)
83 void ScSingleRefData::SetAbsTab( SCTAB nVal
)
85 Flags
.bTabRel
= false;
89 void ScSingleRefData::SetRelTab( SCTAB nVal
)
95 void ScSingleRefData::IncTab( SCTAB nInc
)
100 void ScSingleRefData::SetColDeleted( bool bVal
)
102 Flags
.bColDeleted
= bVal
;
105 bool ScSingleRefData::IsColDeleted() const
107 return Flags
.bColDeleted
;
110 void ScSingleRefData::SetRowDeleted( bool bVal
)
112 Flags
.bRowDeleted
= bVal
;
115 bool ScSingleRefData::IsRowDeleted() const
117 return Flags
.bRowDeleted
;
120 void ScSingleRefData::SetTabDeleted( bool bVal
)
122 Flags
.bTabDeleted
= bVal
;
125 bool ScSingleRefData::IsTabDeleted() const
127 return Flags
.bTabDeleted
;
130 bool ScSingleRefData::IsDeleted() const
132 return IsColDeleted() || IsRowDeleted() || IsTabDeleted();
135 bool ScSingleRefData::Valid() const
137 return ColValid() && RowValid() && TabValid();
140 bool ScSingleRefData::ColValid() const
144 if (mnCol
< -MAXCOL
|| MAXCOL
< mnCol
)
149 if (mnCol
< 0 || MAXCOL
< mnCol
)
156 bool ScSingleRefData::RowValid() const
160 if (mnRow
< -MAXROW
|| MAXROW
< mnRow
)
165 if (mnRow
< 0 || MAXROW
< mnRow
)
172 bool ScSingleRefData::TabValid() const
176 if (mnTab
< -MAXTAB
|| MAXTAB
< mnTab
)
181 if (mnTab
< 0 || MAXTAB
< mnTab
)
188 bool ScSingleRefData::ValidExternal() const
190 return ColValid() && RowValid() && mnTab
== -1;
193 ScAddress
ScSingleRefData::toAbs( const ScAddress
& rPos
) const
195 SCCOL nRetCol
= Flags
.bColRel
? mnCol
+ rPos
.Col() : mnCol
;
196 SCROW nRetRow
= Flags
.bRowRel
? mnRow
+ rPos
.Row() : mnRow
;
197 SCTAB nRetTab
= Flags
.bTabRel
? mnTab
+ rPos
.Tab() : mnTab
;
199 ScAddress
aAbs(ScAddress::INITIALIZE_INVALID
);
201 if (ValidCol(nRetCol
))
202 aAbs
.SetCol(nRetCol
);
204 if (ValidRow(nRetRow
))
205 aAbs
.SetRow(nRetRow
);
207 if (ValidTab(nRetTab
))
208 aAbs
.SetTab(nRetTab
);
213 void ScSingleRefData::SetAddress( const ScAddress
& rAddr
, const ScAddress
& rPos
)
216 mnCol
= rAddr
.Col() - rPos
.Col();
221 mnRow
= rAddr
.Row() - rPos
.Row();
226 mnTab
= rAddr
.Tab() - rPos
.Tab();
231 SCROW
ScSingleRefData::Row() const
233 if (Flags
.bRowDeleted
)
238 SCCOL
ScSingleRefData::Col() const
240 if (Flags
.bColDeleted
)
245 SCTAB
ScSingleRefData::Tab() const
247 if (Flags
.bTabDeleted
)
252 bool ScSingleRefData::operator==( const ScSingleRefData
& r
) const
254 return mnFlagValue
== r
.mnFlagValue
&& mnCol
== r
.mnCol
&& mnRow
== r
.mnRow
&& mnTab
== r
.mnTab
;
257 bool ScSingleRefData::operator!=( const ScSingleRefData
& r
) const
259 return !operator==(r
);
262 #if DEBUG_FORMULA_COMPILER
263 void ScSingleRefData::Dump( int nIndent
) const
266 for (int i
= 0; i
< nIndent
; ++i
)
269 cout
<< aIndent
<< "address type column: " << (IsColRel()?"relative":"absolute")
270 << " row : " << (IsRowRel()?"relative":"absolute") << " sheet: "
271 << (IsTabRel()?"relative":"absolute") << endl
;
272 cout
<< aIndent
<< "deleted column: " << (IsColDeleted()?"yes":"no")
273 << " row : " << (IsRowDeleted()?"yes":"no") << " sheet: "
274 << (IsTabDeleted()?"yes":"no") << endl
;
275 cout
<< aIndent
<< "column: " << mnCol
<< " row: " << mnRow
<< " sheet: " << mnTab
<< endl
;
276 cout
<< aIndent
<< "3d ref: " << (IsFlag3D()?"yes":"no") << endl
;
280 ScComplexRefData
& ScComplexRefData::Extend( const ScSingleRefData
& rRef
, const ScAddress
& rPos
)
282 ScRange aAbsRange
= toAbs(rPos
);
283 ScAddress aAbs
= rRef
.toAbs(rPos
);
285 if (aAbs
.Col() < aAbsRange
.aStart
.Col())
286 aAbsRange
.aStart
.SetCol(aAbs
.Col());
288 if (aAbs
.Row() < aAbsRange
.aStart
.Row())
289 aAbsRange
.aStart
.SetRow(aAbs
.Row());
291 if (aAbs
.Tab() < aAbsRange
.aStart
.Tab())
292 aAbsRange
.aStart
.SetTab(aAbs
.Tab());
294 if (aAbsRange
.aEnd
.Col() < aAbs
.Col())
295 aAbsRange
.aEnd
.SetCol(aAbs
.Col());
297 if (aAbsRange
.aEnd
.Row() < aAbs
.Row())
298 aAbsRange
.aEnd
.SetRow(aAbs
.Row());
300 if (aAbsRange
.aEnd
.Tab() < aAbs
.Tab())
301 aAbsRange
.aEnd
.SetTab(aAbs
.Tab());
303 SetRange(aAbsRange
, rPos
);
309 ScComplexRefData
& ScComplexRefData::Extend( const ScComplexRefData
& rRef
, const ScAddress
& rPos
)
311 return Extend( rRef
.Ref1
, rPos
).Extend( rRef
.Ref2
, rPos
);
314 bool ScComplexRefData::IsDeleted() const
316 return Ref1
.IsDeleted() || Ref2
.IsDeleted();
319 bool ScComplexRefData::Valid() const
321 return Ref1
.Valid() && Ref2
.Valid();
324 bool ScComplexRefData::ValidExternal() const
326 return Ref1
.ValidExternal() && Ref2
.ColValid() && Ref2
.RowValid() && Ref1
.Tab() <= Ref2
.Tab();
329 ScRange
ScComplexRefData::toAbs( const ScAddress
& rPos
) const
331 return ScRange(Ref1
.toAbs(rPos
), Ref2
.toAbs(rPos
));
334 void ScComplexRefData::SetRange( const ScRange
& rRange
, const ScAddress
& rPos
)
336 Ref1
.SetAddress(rRange
.aStart
, rPos
);
337 Ref2
.SetAddress(rRange
.aEnd
, rPos
);
340 #if DEBUG_FORMULA_COMPILER
341 void ScComplexRefData::Dump( int nIndent
) const
344 for (int i
= 0; i
< nIndent
; ++i
)
347 cout
<< aIndent
<< "ref 1" << endl
;
348 Ref1
.Dump(nIndent
+1);
349 cout
<< aIndent
<< "ref 2" << endl
;
350 Ref2
.Dump(nIndent
+1);
354 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */