Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef SC_REFDATA_HXX
21 : #define SC_REFDATA_HXX
22 :
23 : #include "global.hxx"
24 : #include "address.hxx"
25 : #include "scdllapi.h"
26 :
27 :
28 : // Ref-Flags for old (until release 3.1) documents
29 :
30 : struct OldSingleRefBools
31 : {
32 : sal_uInt8 bRelCol; // Flag values (see further down), 2 bits each in file format
33 : sal_uInt8 bRelRow;
34 : sal_uInt8 bRelTab;
35 : sal_uInt8 bOldFlag3D; // two sal_Bool flags (see further down)
36 : };
37 :
38 : struct SC_DLLPUBLIC ScSingleRefData // Single reference (one address) into the sheet
39 : {
40 : SCsCOL nCol; // Absolute values
41 : SCsROW nRow;
42 : SCsTAB nTab;
43 : SCsCOL nRelCol; // Values relative to the position
44 : SCsROW nRelRow;
45 : SCsTAB nRelTab;
46 :
47 : union
48 : {
49 : sal_Bool bFlags;
50 : struct
51 : {
52 : sal_Bool bColRel :1;
53 : sal_Bool bColDeleted :1;
54 : sal_Bool bRowRel :1;
55 : sal_Bool bRowDeleted :1;
56 : sal_Bool bTabRel :1;
57 : sal_Bool bTabDeleted :1;
58 : sal_Bool bFlag3D :1; // 3D-Ref
59 : sal_Bool bRelName :1; // Reference derived from RangeName with relative values
60 : }Flags;
61 : };
62 :
63 : // No default ctor, because used in ScRawToken union, set InitFlags!
64 68639 : inline void InitFlags() { bFlags = 0; } // all FALSE
65 : // InitAddress: InitFlags and set address
66 : inline void InitAddress( const ScAddress& rAdr );
67 : inline void InitAddress( SCCOL nCol, SCROW nRow, SCTAB nTab );
68 : // InitAddressRel: InitFlags and set address, everything relative to rPos
69 : inline void InitAddressRel( const ScAddress& rAdr, const ScAddress& rPos );
70 18980 : inline void SetColRel( sal_Bool bVal ) { Flags.bColRel = (bVal ? sal_True : false ); }
71 46887 : inline sal_Bool IsColRel() const { return Flags.bColRel; }
72 18980 : inline void SetRowRel( sal_Bool bVal ) { Flags.bRowRel = (bVal ? sal_True : false ); }
73 51205 : inline sal_Bool IsRowRel() const { return Flags.bRowRel; }
74 18980 : inline void SetTabRel( sal_Bool bVal ) { Flags.bTabRel = (bVal ? sal_True : false ); }
75 43748 : inline sal_Bool IsTabRel() const { return Flags.bTabRel; }
76 :
77 58 : inline void SetColDeleted( sal_Bool bVal ) { Flags.bColDeleted = (bVal ? sal_True : false ); }
78 45944 : inline sal_Bool IsColDeleted() const { return Flags.bColDeleted; }
79 62 : inline void SetRowDeleted( sal_Bool bVal ) { Flags.bRowDeleted = (bVal ? sal_True : false ); }
80 45944 : inline sal_Bool IsRowDeleted() const { return Flags.bRowDeleted; }
81 69 : inline void SetTabDeleted( sal_Bool bVal ) { Flags.bTabDeleted = (bVal ? sal_True : false ); }
82 33813 : inline sal_Bool IsTabDeleted() const { return Flags.bTabDeleted; }
83 531 : inline sal_Bool IsDeleted() const { return IsColDeleted() || IsRowDeleted() || IsTabDeleted(); }
84 :
85 36543 : inline void SetFlag3D( sal_Bool bVal ) { Flags.bFlag3D = (bVal ? sal_True : false ); }
86 45071 : inline sal_Bool IsFlag3D() const { return Flags.bFlag3D; }
87 284 : inline void SetRelName( sal_Bool bVal ) { Flags.bRelName = (bVal ? sal_True : false ); }
88 164 : inline sal_Bool IsRelName() const { return Flags.bRelName; }
89 :
90 : inline sal_Bool Valid() const;
91 : /// In external references nTab is -1
92 : inline bool ValidExternal() const;
93 :
94 : ScAddress toAbs( const ScAddress& rPos ) const;
95 :
96 : void SmartRelAbs( const ScAddress& rPos );
97 : void CalcRelFromAbs( const ScAddress& rPos );
98 : void CalcAbsIfRel( const ScAddress& rPos );
99 : sal_Bool operator==( const ScSingleRefData& ) const;
100 : bool operator!=( const ScSingleRefData& ) const;
101 : };
102 :
103 4332 : inline void ScSingleRefData::InitAddress( SCCOL nColP, SCROW nRowP, SCTAB nTabP )
104 : {
105 4332 : InitFlags();
106 4332 : nCol = nColP;
107 4332 : nRow = nRowP;
108 4332 : nTab = nTabP;
109 4332 : }
110 :
111 4332 : inline void ScSingleRefData::InitAddress( const ScAddress& rAdr )
112 : {
113 4332 : InitAddress( rAdr.Col(), rAdr.Row(), rAdr.Tab());
114 4332 : }
115 :
116 0 : inline void ScSingleRefData::InitAddressRel( const ScAddress& rAdr,
117 : const ScAddress& rPos )
118 : {
119 0 : InitAddress( rAdr.Col(), rAdr.Row(), rAdr.Tab());
120 0 : SetColRel( sal_True );
121 0 : SetRowRel( sal_True );
122 0 : SetTabRel( sal_True );
123 0 : CalcRelFromAbs( rPos );
124 0 : }
125 :
126 7254 : inline sal_Bool ScSingleRefData::Valid() const
127 : {
128 21762 : return nCol >= 0 && nCol <= MAXCOL &&
129 21762 : nRow >= 0 && nRow <= MAXROW &&
130 21762 : nTab >= 0 && nTab <= MAXTAB;
131 : }
132 :
133 0 : inline bool ScSingleRefData::ValidExternal() const
134 : {
135 0 : return nCol >= 0 && nCol <= MAXCOL &&
136 0 : nRow >= 0 && nRow <= MAXROW &&
137 0 : nTab == -1;
138 : }
139 :
140 :
141 : struct ScComplexRefData // Complex reference (a range) into the sheet
142 : {
143 : ScSingleRefData Ref1;
144 : ScSingleRefData Ref2;
145 :
146 19552 : inline void InitFlags()
147 19552 : { Ref1.InitFlags(); Ref2.InitFlags(); }
148 1400 : inline void InitRange( const ScRange& rRange )
149 : {
150 1400 : Ref1.InitAddress( rRange.aStart );
151 1400 : Ref2.InitAddress( rRange.aEnd );
152 1400 : }
153 0 : inline void InitRangeRel( const ScRange& rRange, const ScAddress& rPos )
154 : {
155 0 : Ref1.InitAddressRel( rRange.aStart, rPos );
156 0 : Ref2.InitAddressRel( rRange.aEnd, rPos );
157 0 : }
158 0 : inline void InitRange( SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
159 : SCCOL nCol2, SCROW nRow2, SCTAB nTab2 )
160 : {
161 0 : Ref1.InitAddress( nCol1, nRow1, nTab1 );
162 0 : Ref2.InitAddress( nCol2, nRow2, nTab2 );
163 0 : }
164 8 : inline void SmartRelAbs( const ScAddress& rPos )
165 8 : { Ref1.SmartRelAbs( rPos ); Ref2.SmartRelAbs( rPos ); }
166 1740 : inline void CalcRelFromAbs( const ScAddress& rPos )
167 1740 : { Ref1.CalcRelFromAbs( rPos ); Ref2.CalcRelFromAbs( rPos ); }
168 196 : inline void CalcAbsIfRel( const ScAddress& rPos )
169 196 : { Ref1.CalcAbsIfRel( rPos ); Ref2.CalcAbsIfRel( rPos ); }
170 : inline sal_Bool IsDeleted() const
171 : { return Ref1.IsDeleted() || Ref2.IsDeleted(); }
172 2492 : inline sal_Bool Valid() const
173 2492 : { return Ref1.Valid() && Ref2.Valid(); }
174 : /** In external references nTab is -1 for the start tab and -1 for the end
175 : tab if one sheet, or >=0 if more than one sheets. */
176 : inline bool ValidExternal() const;
177 :
178 : /// Absolute references have to be up-to-date when calling this!
179 : void PutInOrder();
180 15 : inline sal_Bool operator==( const ScComplexRefData& r ) const
181 15 : { return Ref1 == r.Ref1 && Ref2 == r.Ref2; }
182 : /** Enlarge range if reference passed is not within existing range.
183 : ScAddress position is used to calculate absolute references from
184 : relative references. */
185 : ScComplexRefData& Extend( const ScSingleRefData & rRef, const ScAddress & rPos );
186 : ScComplexRefData& Extend( const ScComplexRefData & rRef, const ScAddress & rPos );
187 : };
188 :
189 0 : inline bool ScComplexRefData::ValidExternal() const
190 : {
191 0 : return Ref1.ValidExternal() &&
192 0 : Ref2.nCol >= 0 && Ref2.nCol <= MAXCOL &&
193 0 : Ref2.nRow >= 0 && Ref2.nRow <= MAXROW &&
194 0 : Ref2.nTab >= Ref1.nTab;
195 : }
196 :
197 : #endif
198 :
199 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|