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 58967 : 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 9534 : inline void SetColRel( sal_Bool bVal ) { Flags.bColRel = (bVal ? sal_True : false ); }
71 8272 : inline sal_Bool IsColRel() const { return Flags.bColRel; }
72 9534 : inline void SetRowRel( sal_Bool bVal ) { Flags.bRowRel = (bVal ? sal_True : false ); }
73 8062 : inline sal_Bool IsRowRel() const { return Flags.bRowRel; }
74 9534 : inline void SetTabRel( sal_Bool bVal ) { Flags.bTabRel = (bVal ? sal_True : false ); }
75 16873 : inline sal_Bool IsTabRel() const { return Flags.bTabRel; }
76 :
77 38 : inline void SetColDeleted( sal_Bool bVal ) { Flags.bColDeleted = (bVal ? sal_True : false ); }
78 7495 : inline sal_Bool IsColDeleted() const { return Flags.bColDeleted; }
79 38 : inline void SetRowDeleted( sal_Bool bVal ) { Flags.bRowDeleted = (bVal ? sal_True : false ); }
80 7495 : inline sal_Bool IsRowDeleted() const { return Flags.bRowDeleted; }
81 53 : inline void SetTabDeleted( sal_Bool bVal ) { Flags.bTabDeleted = (bVal ? sal_True : false ); }
82 7438 : inline sal_Bool IsTabDeleted() const { return Flags.bTabDeleted; }
83 51 : inline sal_Bool IsDeleted() const { return IsColDeleted() || IsRowDeleted() || IsTabDeleted(); }
84 :
85 9643 : inline void SetFlag3D( sal_Bool bVal ) { Flags.bFlag3D = (bVal ? sal_True : false ); }
86 6903 : inline sal_Bool IsFlag3D() const { return Flags.bFlag3D; }
87 241 : inline void SetRelName( sal_Bool bVal ) { Flags.bRelName = (bVal ? sal_True : false ); }
88 80 : 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 : void SmartRelAbs( const ScAddress& rPos );
95 : void CalcRelFromAbs( const ScAddress& rPos );
96 : void CalcAbsIfRel( const ScAddress& rPos );
97 : sal_Bool operator==( const ScSingleRefData& ) const;
98 : bool operator!=( const ScSingleRefData& ) const;
99 : };
100 :
101 787 : inline void ScSingleRefData::InitAddress( SCCOL nColP, SCROW nRowP, SCTAB nTabP )
102 : {
103 787 : InitFlags();
104 787 : nCol = nColP;
105 787 : nRow = nRowP;
106 787 : nTab = nTabP;
107 787 : }
108 :
109 787 : inline void ScSingleRefData::InitAddress( const ScAddress& rAdr )
110 : {
111 787 : InitAddress( rAdr.Col(), rAdr.Row(), rAdr.Tab());
112 787 : }
113 :
114 0 : inline void ScSingleRefData::InitAddressRel( const ScAddress& rAdr,
115 : const ScAddress& rPos )
116 : {
117 0 : InitAddress( rAdr.Col(), rAdr.Row(), rAdr.Tab());
118 0 : SetColRel( sal_True );
119 0 : SetRowRel( sal_True );
120 0 : SetTabRel( sal_True );
121 0 : CalcRelFromAbs( rPos );
122 0 : }
123 :
124 10448 : inline sal_Bool ScSingleRefData::Valid() const
125 : {
126 : return nCol >= 0 && nCol <= MAXCOL &&
127 : nRow >= 0 && nRow <= MAXROW &&
128 10448 : nTab >= 0 && nTab <= MAXTAB;
129 : }
130 :
131 0 : inline bool ScSingleRefData::ValidExternal() const
132 : {
133 : return nCol >= 0 && nCol <= MAXCOL &&
134 : nRow >= 0 && nRow <= MAXROW &&
135 0 : nTab == -1;
136 : }
137 :
138 :
139 : struct ScComplexRefData // Complex reference (a range) into the sheet
140 : {
141 : ScSingleRefData Ref1;
142 : ScSingleRefData Ref2;
143 :
144 19365 : inline void InitFlags()
145 19365 : { Ref1.InitFlags(); Ref2.InitFlags(); }
146 191 : inline void InitRange( const ScRange& rRange )
147 : {
148 191 : Ref1.InitAddress( rRange.aStart );
149 191 : Ref2.InitAddress( rRange.aEnd );
150 191 : }
151 0 : inline void InitRangeRel( const ScRange& rRange, const ScAddress& rPos )
152 : {
153 0 : Ref1.InitAddressRel( rRange.aStart, rPos );
154 0 : Ref2.InitAddressRel( rRange.aEnd, rPos );
155 0 : }
156 0 : inline void InitRange( SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
157 : SCCOL nCol2, SCROW nRow2, SCTAB nTab2 )
158 : {
159 0 : Ref1.InitAddress( nCol1, nRow1, nTab1 );
160 0 : Ref2.InitAddress( nCol2, nRow2, nTab2 );
161 0 : }
162 0 : inline void SmartRelAbs( const ScAddress& rPos )
163 0 : { Ref1.SmartRelAbs( rPos ); Ref2.SmartRelAbs( rPos ); }
164 446 : inline void CalcRelFromAbs( const ScAddress& rPos )
165 446 : { Ref1.CalcRelFromAbs( rPos ); Ref2.CalcRelFromAbs( rPos ); }
166 2286 : inline void CalcAbsIfRel( const ScAddress& rPos )
167 2286 : { Ref1.CalcAbsIfRel( rPos ); Ref2.CalcAbsIfRel( rPos ); }
168 : inline sal_Bool IsDeleted() const
169 : { return Ref1.IsDeleted() || Ref2.IsDeleted(); }
170 175 : inline sal_Bool Valid() const
171 175 : { return Ref1.Valid() && Ref2.Valid(); }
172 : /** In external references nTab is -1 for the start tab and -1 for the end
173 : tab if one sheet, or >=0 if more than one sheets. */
174 : inline bool ValidExternal() const;
175 :
176 : /// Absolute references have to be up-to-date when calling this!
177 : void PutInOrder();
178 0 : inline sal_Bool operator==( const ScComplexRefData& r ) const
179 0 : { return Ref1 == r.Ref1 && Ref2 == r.Ref2; }
180 : /** Enlarge range if reference passed is not within existing range.
181 : ScAddress position is used to calculate absolute references from
182 : relative references. */
183 : ScComplexRefData& Extend( const ScSingleRefData & rRef, const ScAddress & rPos );
184 : ScComplexRefData& Extend( const ScComplexRefData & rRef, const ScAddress & rPos );
185 : };
186 :
187 0 : inline bool ScComplexRefData::ValidExternal() const
188 : {
189 0 : return Ref1.ValidExternal() &&
190 : Ref2.nCol >= 0 && Ref2.nCol <= MAXCOL &&
191 : Ref2.nRow >= 0 && Ref2.nRow <= MAXROW &&
192 0 : Ref2.nTab >= Ref1.nTab;
193 : }
194 :
195 : #endif
196 :
197 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|