xref: /aoo41x/main/sc/inc/refdata.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 #ifndef SC_REFDATA_HXX
29 #define SC_REFDATA_HXX
30 
31 #include "global.hxx"
32 #include "address.hxx"
33 #include "scdllapi.h"
34 
35 
36 // Ref-Flags for old (until release 3.1) documents
37 
38 struct OldSingleRefBools
39 {
40     sal_uInt8    bRelCol;    // Flag values (see further down), 2 bits each in file format
41     sal_uInt8    bRelRow;
42     sal_uInt8    bRelTab;
43     sal_uInt8    bOldFlag3D; // two sal_Bool flags (see further down)
44 };
45 
46 #define SR_ABSOLUTE 0       // Absolute value
47 #define SR_RELABS   1       // Relative value as absolute value (until release 3.1)
48 #define SR_RELATIVE 2       // Relative value as delta value (after release 3.1)
49 #define SR_DELETED  3       // Deleted col/row/tab
50 
51 #define SRF_3D      0x01    // 3D reference, was the sal_Bool (before build 304a)
52 #define SRF_RELNAME 0x02    // Reference derived from RangeName with relative values
53 #define SRF_BITS    0x03    // Mask of possible bits
54 
55 
56 struct SC_DLLPUBLIC ScSingleRefData        // Single reference (one address) into the sheet
57 {
58     SCsCOL  nCol;       // Absolute values
59     SCsROW  nRow;
60     SCsTAB  nTab;
61     SCsCOL  nRelCol;    // Values relative to the position
62     SCsROW  nRelRow;
63     SCsTAB  nRelTab;
64 
65     union
66     {
67         sal_Bool bFlags;
68         struct
69         {
70             sal_Bool    bColRel     :1;
71             sal_Bool    bColDeleted :1;
72             sal_Bool    bRowRel     :1;
73             sal_Bool    bRowDeleted :1;
74             sal_Bool    bTabRel     :1;
75             sal_Bool    bTabDeleted :1;
76             sal_Bool    bFlag3D     :1;     // 3D-Ref
77             sal_Bool    bRelName    :1;     // Reference derived from RangeName with relative values
78         }Flags;
79     };
80 
81     // No default ctor, because used in ScRawToken union, set InitFlags!
82     inline  void InitFlags() { bFlags = 0; }    // all FALSE
83     // InitAddress: InitFlags and set address
84     inline  void InitAddress( const ScAddress& rAdr );
85     inline  void InitAddress( SCCOL nCol, SCROW nRow, SCTAB nTab );
86     // InitAddressRel: InitFlags and set address, everything relative to rPos
87     inline  void InitAddressRel( const ScAddress& rAdr, const ScAddress& rPos );
88     inline  void SetColRel( sal_Bool bVal ) { Flags.bColRel = (bVal ? sal_True : sal_False ); }
89     inline  sal_Bool IsColRel() const       { return Flags.bColRel; }
90     inline  void SetRowRel( sal_Bool bVal ) { Flags.bRowRel = (bVal ? sal_True : sal_False ); }
91     inline  sal_Bool IsRowRel() const       { return Flags.bRowRel; }
92     inline  void SetTabRel( sal_Bool bVal ) { Flags.bTabRel = (bVal ? sal_True : sal_False ); }
93     inline  sal_Bool IsTabRel() const       { return Flags.bTabRel; }
94 
95     inline  void SetColDeleted( sal_Bool bVal ) { Flags.bColDeleted = (bVal ? sal_True : sal_False ); }
96     inline  sal_Bool IsColDeleted() const       { return Flags.bColDeleted; }
97     inline  void SetRowDeleted( sal_Bool bVal ) { Flags.bRowDeleted = (bVal ? sal_True : sal_False ); }
98     inline  sal_Bool IsRowDeleted() const       { return Flags.bRowDeleted; }
99     inline  void SetTabDeleted( sal_Bool bVal ) { Flags.bTabDeleted = (bVal ? sal_True : sal_False ); }
100     inline  sal_Bool IsTabDeleted() const       { return Flags.bTabDeleted; }
101     inline  sal_Bool IsDeleted() const          { return IsColDeleted() || IsRowDeleted() || IsTabDeleted(); }
102 
103     inline  void SetFlag3D( sal_Bool bVal ) { Flags.bFlag3D = (bVal ? sal_True : sal_False ); }
104     inline  sal_Bool IsFlag3D() const       { return Flags.bFlag3D; }
105     inline  void SetRelName( sal_Bool bVal )    { Flags.bRelName = (bVal ? sal_True : sal_False ); }
106     inline  sal_Bool IsRelName() const          { return Flags.bRelName; }
107 
108     inline  sal_Bool Valid() const;
109     /// In external references nTab is -1
110     inline  bool ValidExternal() const;
111 
112             void SmartRelAbs( const ScAddress& rPos );
113             void CalcRelFromAbs( const ScAddress& rPos );
114             void CalcAbsIfRel( const ScAddress& rPos );
115             sal_Bool operator==( const ScSingleRefData& ) const;
116             bool operator!=( const ScSingleRefData& ) const;
117 };
118 
119 inline void ScSingleRefData::InitAddress( SCCOL nColP, SCROW nRowP, SCTAB nTabP )
120 {
121     InitFlags();
122     nCol = nColP;
123     nRow = nRowP;
124     nTab = nTabP;
125 }
126 
127 inline void ScSingleRefData::InitAddress( const ScAddress& rAdr )
128 {
129     InitAddress( rAdr.Col(), rAdr.Row(), rAdr.Tab());
130 }
131 
132 inline void ScSingleRefData::InitAddressRel( const ScAddress& rAdr,
133                                             const ScAddress& rPos )
134 {
135     InitAddress( rAdr.Col(), rAdr.Row(), rAdr.Tab());
136     SetColRel( sal_True );
137     SetRowRel( sal_True );
138     SetTabRel( sal_True );
139     CalcRelFromAbs( rPos );
140 }
141 
142 inline sal_Bool ScSingleRefData::Valid() const
143 {
144     return  nCol >= 0 && nCol <= MAXCOL &&
145             nRow >= 0 && nRow <= MAXROW &&
146             nTab >= 0 && nTab <= MAXTAB;
147 }
148 
149 inline bool ScSingleRefData::ValidExternal() const
150 {
151     return  nCol >= 0 && nCol <= MAXCOL &&
152             nRow >= 0 && nRow <= MAXROW &&
153             nTab == -1;
154 }
155 
156 
157 struct ScComplexRefData         // Complex reference (a range) into the sheet
158 {
159     ScSingleRefData Ref1;
160     ScSingleRefData Ref2;
161 
162     inline  void InitFlags()
163         { Ref1.InitFlags(); Ref2.InitFlags(); }
164     inline  void InitRange( const ScRange& rRange )
165         {
166             Ref1.InitAddress( rRange.aStart );
167             Ref2.InitAddress( rRange.aEnd );
168         }
169     inline  void InitRangeRel( const ScRange& rRange, const ScAddress& rPos )
170         {
171             Ref1.InitAddressRel( rRange.aStart, rPos );
172             Ref2.InitAddressRel( rRange.aEnd, rPos );
173         }
174     inline  void InitRange( SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
175                             SCCOL nCol2, SCROW nRow2, SCTAB nTab2 )
176         {
177             Ref1.InitAddress( nCol1, nRow1, nTab1 );
178             Ref2.InitAddress( nCol2, nRow2, nTab2 );
179         }
180     inline  void SmartRelAbs( const ScAddress& rPos )
181         { Ref1.SmartRelAbs( rPos ); Ref2.SmartRelAbs( rPos ); }
182     inline  void CalcRelFromAbs( const ScAddress& rPos )
183         { Ref1.CalcRelFromAbs( rPos ); Ref2.CalcRelFromAbs( rPos ); }
184     inline  void CalcAbsIfRel( const ScAddress& rPos )
185         { Ref1.CalcAbsIfRel( rPos ); Ref2.CalcAbsIfRel( rPos ); }
186     inline  sal_Bool IsDeleted() const
187         { return Ref1.IsDeleted() || Ref2.IsDeleted(); }
188     inline  sal_Bool Valid() const
189         { return Ref1.Valid() && Ref2.Valid(); }
190     /** In external references nTab is -1 for the start tab and -1 for the end
191         tab if one sheet, or >=0 if more than one sheets. */
192     inline  bool ValidExternal() const;
193 
194     /// Absolute references have to be up-to-date when calling this!
195     void PutInOrder();
196     inline  sal_Bool operator==( const ScComplexRefData& r ) const
197         { return Ref1 == r.Ref1 && Ref2 == r.Ref2; }
198     /** Enlarge range if reference passed is not within existing range.
199         ScAddress position is used to calculate absolute references from
200         relative references. */
201     ScComplexRefData& Extend( const ScSingleRefData & rRef, const ScAddress & rPos );
202     ScComplexRefData& Extend( const ScComplexRefData & rRef, const ScAddress & rPos );
203 };
204 
205 inline bool ScComplexRefData::ValidExternal() const
206 {
207     return Ref1.ValidExternal() &&
208         Ref2.nCol >= 0 && Ref2.nCol <= MAXCOL &&
209         Ref2.nRow >= 0 && Ref2.nRow <= MAXROW &&
210         Ref2.nTab >= Ref1.nTab;
211 }
212 
213 #endif
214