xref: /trunk/main/sc/inc/refdata.hxx (revision 9cd893a1)
138d50f7bSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
338d50f7bSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
438d50f7bSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
538d50f7bSAndrew Rist  * distributed with this work for additional information
638d50f7bSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
738d50f7bSAndrew Rist  * to you under the Apache License, Version 2.0 (the
838d50f7bSAndrew Rist  * "License"); you may not use this file except in compliance
938d50f7bSAndrew Rist  * with the License.  You may obtain a copy of the License at
1038d50f7bSAndrew Rist  *
1138d50f7bSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
1238d50f7bSAndrew Rist  *
1338d50f7bSAndrew Rist  * Unless required by applicable law or agreed to in writing,
1438d50f7bSAndrew Rist  * software distributed under the License is distributed on an
1538d50f7bSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1638d50f7bSAndrew Rist  * KIND, either express or implied.  See the License for the
1738d50f7bSAndrew Rist  * specific language governing permissions and limitations
1838d50f7bSAndrew Rist  * under the License.
1938d50f7bSAndrew Rist  *
2038d50f7bSAndrew Rist  *************************************************************/
2138d50f7bSAndrew Rist 
2238d50f7bSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef SC_REFDATA_HXX
25cdf0e10cSrcweir #define SC_REFDATA_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "global.hxx"
28cdf0e10cSrcweir #include "address.hxx"
29cdf0e10cSrcweir #include "scdllapi.h"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir 
32cdf0e10cSrcweir // Ref-Flags for old (until release 3.1) documents
33cdf0e10cSrcweir 
34cdf0e10cSrcweir struct OldSingleRefBools
35cdf0e10cSrcweir {
36cdf0e10cSrcweir     sal_uInt8    bRelCol;    // Flag values (see further down), 2 bits each in file format
37cdf0e10cSrcweir     sal_uInt8    bRelRow;
38cdf0e10cSrcweir     sal_uInt8    bRelTab;
39cdf0e10cSrcweir     sal_uInt8    bOldFlag3D; // two sal_Bool flags (see further down)
40cdf0e10cSrcweir };
41cdf0e10cSrcweir 
42cdf0e10cSrcweir #define SR_ABSOLUTE 0       // Absolute value
43cdf0e10cSrcweir #define SR_RELABS   1       // Relative value as absolute value (until release 3.1)
44cdf0e10cSrcweir #define SR_RELATIVE 2       // Relative value as delta value (after release 3.1)
45cdf0e10cSrcweir #define SR_DELETED  3       // Deleted col/row/tab
46cdf0e10cSrcweir 
47cdf0e10cSrcweir #define SRF_3D      0x01    // 3D reference, was the sal_Bool (before build 304a)
48cdf0e10cSrcweir #define SRF_RELNAME 0x02    // Reference derived from RangeName with relative values
49cdf0e10cSrcweir #define SRF_BITS    0x03    // Mask of possible bits
50cdf0e10cSrcweir 
51cdf0e10cSrcweir 
52cdf0e10cSrcweir struct SC_DLLPUBLIC ScSingleRefData        // Single reference (one address) into the sheet
53cdf0e10cSrcweir {
54cdf0e10cSrcweir     SCsCOL  nCol;       // Absolute values
55cdf0e10cSrcweir     SCsROW  nRow;
56cdf0e10cSrcweir     SCsTAB  nTab;
57cdf0e10cSrcweir     SCsCOL  nRelCol;    // Values relative to the position
58cdf0e10cSrcweir     SCsROW  nRelRow;
59cdf0e10cSrcweir     SCsTAB  nRelTab;
60cdf0e10cSrcweir 
61cdf0e10cSrcweir     union
62cdf0e10cSrcweir     {
63cdf0e10cSrcweir         sal_Bool bFlags;
64cdf0e10cSrcweir         struct
65cdf0e10cSrcweir         {
66cdf0e10cSrcweir             sal_Bool    bColRel     :1;
67cdf0e10cSrcweir             sal_Bool    bColDeleted :1;
68cdf0e10cSrcweir             sal_Bool    bRowRel     :1;
69cdf0e10cSrcweir             sal_Bool    bRowDeleted :1;
70cdf0e10cSrcweir             sal_Bool    bTabRel     :1;
71cdf0e10cSrcweir             sal_Bool    bTabDeleted :1;
72cdf0e10cSrcweir             sal_Bool    bFlag3D     :1;     // 3D-Ref
73cdf0e10cSrcweir             sal_Bool    bRelName    :1;     // Reference derived from RangeName with relative values
74cdf0e10cSrcweir         }Flags;
75cdf0e10cSrcweir     };
76cdf0e10cSrcweir 
77cdf0e10cSrcweir     // No default ctor, because used in ScRawToken union, set InitFlags!
InitFlagsScSingleRefData78cdf0e10cSrcweir     inline  void InitFlags() { bFlags = 0; }    // all FALSE
7938e63b1dSArmin Le Grand 
8038e63b1dSArmin Le Grand     // #123870# Make it possible to init members to some defined values
InitMembersScSingleRefData81*9cd893a1SAndre Fischer     inline void InitMembers() { nRow = nRelRow = 0; nCol = nRelCol = 0; nTab = nRelTab = 0; }
8238e63b1dSArmin Le Grand 
83cdf0e10cSrcweir     // InitAddress: InitFlags and set address
84cdf0e10cSrcweir     inline  void InitAddress( const ScAddress& rAdr );
85cdf0e10cSrcweir     inline  void InitAddress( SCCOL nCol, SCROW nRow, SCTAB nTab );
86cdf0e10cSrcweir     // InitAddressRel: InitFlags and set address, everything relative to rPos
87cdf0e10cSrcweir     inline  void InitAddressRel( const ScAddress& rAdr, const ScAddress& rPos );
SetColRelScSingleRefData88cdf0e10cSrcweir     inline  void SetColRel( sal_Bool bVal ) { Flags.bColRel = (bVal ? sal_True : sal_False ); }
IsColRelScSingleRefData89cdf0e10cSrcweir     inline  sal_Bool IsColRel() const       { return Flags.bColRel; }
SetRowRelScSingleRefData90cdf0e10cSrcweir     inline  void SetRowRel( sal_Bool bVal ) { Flags.bRowRel = (bVal ? sal_True : sal_False ); }
IsRowRelScSingleRefData91cdf0e10cSrcweir     inline  sal_Bool IsRowRel() const       { return Flags.bRowRel; }
SetTabRelScSingleRefData92cdf0e10cSrcweir     inline  void SetTabRel( sal_Bool bVal ) { Flags.bTabRel = (bVal ? sal_True : sal_False ); }
IsTabRelScSingleRefData93cdf0e10cSrcweir     inline  sal_Bool IsTabRel() const       { return Flags.bTabRel; }
94cdf0e10cSrcweir 
SetColDeletedScSingleRefData95cdf0e10cSrcweir     inline  void SetColDeleted( sal_Bool bVal ) { Flags.bColDeleted = (bVal ? sal_True : sal_False ); }
IsColDeletedScSingleRefData96cdf0e10cSrcweir     inline  sal_Bool IsColDeleted() const       { return Flags.bColDeleted; }
SetRowDeletedScSingleRefData97cdf0e10cSrcweir     inline  void SetRowDeleted( sal_Bool bVal ) { Flags.bRowDeleted = (bVal ? sal_True : sal_False ); }
IsRowDeletedScSingleRefData98cdf0e10cSrcweir     inline  sal_Bool IsRowDeleted() const       { return Flags.bRowDeleted; }
SetTabDeletedScSingleRefData99cdf0e10cSrcweir     inline  void SetTabDeleted( sal_Bool bVal ) { Flags.bTabDeleted = (bVal ? sal_True : sal_False ); }
IsTabDeletedScSingleRefData100cdf0e10cSrcweir     inline  sal_Bool IsTabDeleted() const       { return Flags.bTabDeleted; }
IsDeletedScSingleRefData101cdf0e10cSrcweir     inline  sal_Bool IsDeleted() const          { return IsColDeleted() || IsRowDeleted() || IsTabDeleted(); }
102cdf0e10cSrcweir 
SetFlag3DScSingleRefData103cdf0e10cSrcweir     inline  void SetFlag3D( sal_Bool bVal ) { Flags.bFlag3D = (bVal ? sal_True : sal_False ); }
IsFlag3DScSingleRefData104cdf0e10cSrcweir     inline  sal_Bool IsFlag3D() const       { return Flags.bFlag3D; }
SetRelNameScSingleRefData105cdf0e10cSrcweir     inline  void SetRelName( sal_Bool bVal )    { Flags.bRelName = (bVal ? sal_True : sal_False ); }
IsRelNameScSingleRefData106cdf0e10cSrcweir     inline  sal_Bool IsRelName() const          { return Flags.bRelName; }
107cdf0e10cSrcweir 
108cdf0e10cSrcweir     inline  sal_Bool Valid() const;
109cdf0e10cSrcweir     /// In external references nTab is -1
110cdf0e10cSrcweir     inline  bool ValidExternal() const;
111cdf0e10cSrcweir 
112cdf0e10cSrcweir             void SmartRelAbs( const ScAddress& rPos );
113cdf0e10cSrcweir             void CalcRelFromAbs( const ScAddress& rPos );
114cdf0e10cSrcweir             void CalcAbsIfRel( const ScAddress& rPos );
115cdf0e10cSrcweir             sal_Bool operator==( const ScSingleRefData& ) const;
116cdf0e10cSrcweir             bool operator!=( const ScSingleRefData& ) const;
117cdf0e10cSrcweir };
118cdf0e10cSrcweir 
InitAddress(SCCOL nColP,SCROW nRowP,SCTAB nTabP)119cdf0e10cSrcweir inline void ScSingleRefData::InitAddress( SCCOL nColP, SCROW nRowP, SCTAB nTabP )
120cdf0e10cSrcweir {
121cdf0e10cSrcweir     InitFlags();
122cdf0e10cSrcweir     nCol = nColP;
123cdf0e10cSrcweir     nRow = nRowP;
124cdf0e10cSrcweir     nTab = nTabP;
125cdf0e10cSrcweir }
126cdf0e10cSrcweir 
InitAddress(const ScAddress & rAdr)127cdf0e10cSrcweir inline void ScSingleRefData::InitAddress( const ScAddress& rAdr )
128cdf0e10cSrcweir {
129cdf0e10cSrcweir     InitAddress( rAdr.Col(), rAdr.Row(), rAdr.Tab());
130cdf0e10cSrcweir }
131cdf0e10cSrcweir 
InitAddressRel(const ScAddress & rAdr,const ScAddress & rPos)132cdf0e10cSrcweir inline void ScSingleRefData::InitAddressRel( const ScAddress& rAdr,
133cdf0e10cSrcweir                                             const ScAddress& rPos )
134cdf0e10cSrcweir {
135cdf0e10cSrcweir     InitAddress( rAdr.Col(), rAdr.Row(), rAdr.Tab());
136cdf0e10cSrcweir     SetColRel( sal_True );
137cdf0e10cSrcweir     SetRowRel( sal_True );
138cdf0e10cSrcweir     SetTabRel( sal_True );
139cdf0e10cSrcweir     CalcRelFromAbs( rPos );
140cdf0e10cSrcweir }
141cdf0e10cSrcweir 
Valid() const142cdf0e10cSrcweir inline sal_Bool ScSingleRefData::Valid() const
143cdf0e10cSrcweir {
144cdf0e10cSrcweir     return  nCol >= 0 && nCol <= MAXCOL &&
145cdf0e10cSrcweir             nRow >= 0 && nRow <= MAXROW &&
146cdf0e10cSrcweir             nTab >= 0 && nTab <= MAXTAB;
147cdf0e10cSrcweir }
148cdf0e10cSrcweir 
ValidExternal() const149cdf0e10cSrcweir inline bool ScSingleRefData::ValidExternal() const
150cdf0e10cSrcweir {
151cdf0e10cSrcweir     return  nCol >= 0 && nCol <= MAXCOL &&
152cdf0e10cSrcweir             nRow >= 0 && nRow <= MAXROW &&
153cdf0e10cSrcweir             nTab == -1;
154cdf0e10cSrcweir }
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 
157cdf0e10cSrcweir struct ScComplexRefData         // Complex reference (a range) into the sheet
158cdf0e10cSrcweir {
159cdf0e10cSrcweir     ScSingleRefData Ref1;
160cdf0e10cSrcweir     ScSingleRefData Ref2;
161cdf0e10cSrcweir 
InitFlagsScComplexRefData162cdf0e10cSrcweir     inline  void InitFlags()
163cdf0e10cSrcweir         { Ref1.InitFlags(); Ref2.InitFlags(); }
16438e63b1dSArmin Le Grand 
16538e63b1dSArmin Le Grand     // #123870# Make it possible to init members to some defined values
InitMembersScComplexRefData16638e63b1dSArmin Le Grand     inline void InitMembers()
16738e63b1dSArmin Le Grand     {
16838e63b1dSArmin Le Grand         Ref1.InitMembers();
16938e63b1dSArmin Le Grand         Ref2.InitMembers();
17038e63b1dSArmin Le Grand     }
17138e63b1dSArmin Le Grand 
InitRangeScComplexRefData172cdf0e10cSrcweir     inline  void InitRange( const ScRange& rRange )
173cdf0e10cSrcweir         {
174cdf0e10cSrcweir             Ref1.InitAddress( rRange.aStart );
175cdf0e10cSrcweir             Ref2.InitAddress( rRange.aEnd );
176cdf0e10cSrcweir         }
InitRangeRelScComplexRefData177cdf0e10cSrcweir     inline  void InitRangeRel( const ScRange& rRange, const ScAddress& rPos )
178cdf0e10cSrcweir         {
179cdf0e10cSrcweir             Ref1.InitAddressRel( rRange.aStart, rPos );
180cdf0e10cSrcweir             Ref2.InitAddressRel( rRange.aEnd, rPos );
181cdf0e10cSrcweir         }
InitRangeScComplexRefData182cdf0e10cSrcweir     inline  void InitRange( SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
183cdf0e10cSrcweir                             SCCOL nCol2, SCROW nRow2, SCTAB nTab2 )
184cdf0e10cSrcweir         {
185cdf0e10cSrcweir             Ref1.InitAddress( nCol1, nRow1, nTab1 );
186cdf0e10cSrcweir             Ref2.InitAddress( nCol2, nRow2, nTab2 );
187cdf0e10cSrcweir         }
SmartRelAbsScComplexRefData188cdf0e10cSrcweir     inline  void SmartRelAbs( const ScAddress& rPos )
189cdf0e10cSrcweir         { Ref1.SmartRelAbs( rPos ); Ref2.SmartRelAbs( rPos ); }
CalcRelFromAbsScComplexRefData190cdf0e10cSrcweir     inline  void CalcRelFromAbs( const ScAddress& rPos )
191cdf0e10cSrcweir         { Ref1.CalcRelFromAbs( rPos ); Ref2.CalcRelFromAbs( rPos ); }
CalcAbsIfRelScComplexRefData192cdf0e10cSrcweir     inline  void CalcAbsIfRel( const ScAddress& rPos )
193cdf0e10cSrcweir         { Ref1.CalcAbsIfRel( rPos ); Ref2.CalcAbsIfRel( rPos ); }
IsDeletedScComplexRefData194cdf0e10cSrcweir     inline  sal_Bool IsDeleted() const
195cdf0e10cSrcweir         { return Ref1.IsDeleted() || Ref2.IsDeleted(); }
ValidScComplexRefData196cdf0e10cSrcweir     inline  sal_Bool Valid() const
197cdf0e10cSrcweir         { return Ref1.Valid() && Ref2.Valid(); }
198cdf0e10cSrcweir     /** In external references nTab is -1 for the start tab and -1 for the end
199cdf0e10cSrcweir         tab if one sheet, or >=0 if more than one sheets. */
200cdf0e10cSrcweir     inline  bool ValidExternal() const;
201cdf0e10cSrcweir 
202cdf0e10cSrcweir     /// Absolute references have to be up-to-date when calling this!
203cdf0e10cSrcweir     void PutInOrder();
operator ==ScComplexRefData204cdf0e10cSrcweir     inline  sal_Bool operator==( const ScComplexRefData& r ) const
205cdf0e10cSrcweir         { return Ref1 == r.Ref1 && Ref2 == r.Ref2; }
206cdf0e10cSrcweir     /** Enlarge range if reference passed is not within existing range.
207cdf0e10cSrcweir         ScAddress position is used to calculate absolute references from
208cdf0e10cSrcweir         relative references. */
209cdf0e10cSrcweir     ScComplexRefData& Extend( const ScSingleRefData & rRef, const ScAddress & rPos );
210cdf0e10cSrcweir     ScComplexRefData& Extend( const ScComplexRefData & rRef, const ScAddress & rPos );
211cdf0e10cSrcweir };
212cdf0e10cSrcweir 
ValidExternal() const213cdf0e10cSrcweir inline bool ScComplexRefData::ValidExternal() const
214cdf0e10cSrcweir {
215cdf0e10cSrcweir     return Ref1.ValidExternal() &&
216cdf0e10cSrcweir         Ref2.nCol >= 0 && Ref2.nCol <= MAXCOL &&
217cdf0e10cSrcweir         Ref2.nRow >= 0 && Ref2.nRow <= MAXROW &&
218cdf0e10cSrcweir         Ref2.nTab >= Ref1.nTab;
219cdf0e10cSrcweir }
220cdf0e10cSrcweir 
221cdf0e10cSrcweir #endif
222