LibreOffice Module sc (master)  1
refdata.hxx
Go to the documentation of this file.
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 INCLUDED_SC_INC_REFDATA_HXX
21 #define INCLUDED_SC_INC_REFDATA_HXX
22 
23 #include "address.hxx"
24 #include "scdllapi.h"
25 #include "calcmacros.hxx"
26 
27 struct ScSheetLimits;
28 
31 {
32 private:
36 
37  union
38  {
40  struct
41  {
42  bool bColRel :1;
43  bool bColDeleted :1;
44  bool bRowRel :1;
45  bool bRowDeleted :1;
46  bool bTabRel :1;
47  bool bTabDeleted :1;
48  bool bFlag3D :1;
49  bool bRelName :1;
50  } Flags;
51  };
52 
53 public:
55  void InitFlags() { mnFlagValue = 0; }
56  void InitAddress( const ScAddress& rAdr );
58  void InitAddress( SCCOL nCol, SCROW nRow, SCTAB nTab );
60  void InitAddressRel( const ScDocument* pDoc, const ScAddress& rAdr, const ScAddress& rPos );
62  void InitFromRefAddress( const ScDocument* pDoc, const ScRefAddress& rRef, const ScAddress& rPos );
63  sal_uInt8 FlagValue() const { return mnFlagValue;}
64 
65  void SetColRel( bool bVal ) { Flags.bColRel = bVal; }
66  bool IsColRel() const { return Flags.bColRel; }
67  void SetRowRel( bool bVal ) { Flags.bRowRel = bVal; }
68  bool IsRowRel() const { return Flags.bRowRel; }
69  void SetTabRel( bool bVal ) { Flags.bTabRel = bVal; }
70  bool IsTabRel() const { return Flags.bTabRel; }
71 
72  void SetAbsCol( SCCOL nVal );
73  void SetRelCol( SCCOL nVal );
74  void IncCol( SCCOL nInc );
75  void SetAbsRow( SCROW nVal );
76  void SetRelRow( SCROW nVal );
77  void IncRow( SCROW nInc );
78  void SetAbsTab( SCTAB nVal );
79  void SetRelTab( SCTAB nVal );
80  void IncTab( SCTAB nInc );
81 
82  void SetColDeleted( bool bVal );
83  bool IsColDeleted() const { return Flags.bColDeleted;}
84  void SetRowDeleted( bool bVal );
85  bool IsRowDeleted() const { return Flags.bRowDeleted;}
86  void SetTabDeleted( bool bVal );
87  bool IsTabDeleted() const { return Flags.bTabDeleted;}
88  bool IsDeleted() const;
89 
90  void SetFlag3D( bool bVal ) { Flags.bFlag3D = bVal; }
91  bool IsFlag3D() const { return Flags.bFlag3D; }
92  void SetRelName( bool bVal ) { Flags.bRelName = bVal; }
93  bool IsRelName() const { return Flags.bRelName; }
94 
95  bool Valid(const ScDocument* pDoc) const;
96  bool ColValid(const ScDocument* pDoc) const;
97  bool RowValid(const ScDocument* pDoc) const;
98  bool TabValid() const;
102  bool ValidExternal(const ScDocument* pDoc) const;
103 
104  ScAddress toAbs( ScSheetLimits& rLimits, const ScAddress& rPos ) const;
105  ScAddress toAbs( const ScDocument* pDoc, const ScAddress& rPos ) const;
106  void SetAddress( ScSheetLimits& rLimits, const ScAddress& rAddr, const ScAddress& rPos );
107  SCROW Row() const;
108  SCCOL Col() const;
109  SCTAB Tab() const;
110 
112  static void PutInOrder( ScSingleRefData& rRef1, ScSingleRefData& rRef2, const ScAddress& rPos );
113 
114  bool operator==( const ScSingleRefData& ) const;
115  bool operator!=( const ScSingleRefData& ) const;
116 
117 #if DEBUG_FORMULA_COMPILER
118  void Dump( int nIndent = 0 ) const;
119 #endif
120 };
121 
124 {
127 
128  void InitFlags()
129  { Ref1.InitFlags(); Ref2.InitFlags(); }
130  void InitRange( const ScRange& rRange )
131  {
132  Ref1.InitAddress( rRange.aStart );
133  Ref2.InitAddress( rRange.aEnd );
134  }
135  void InitRangeRel( const ScDocument* pDoc, const ScRange& rRange, const ScAddress& rPos )
136  {
137  Ref1.InitAddressRel( pDoc, rRange.aStart, rPos );
138  Ref2.InitAddressRel( pDoc, rRange.aEnd, rPos );
139  }
140  void InitRange( SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
141  SCCOL nCol2, SCROW nRow2, SCTAB nTab2 )
142  {
143  Ref1.InitAddress( nCol1, nRow1, nTab1 );
144  Ref2.InitAddress( nCol2, nRow2, nTab2 );
145  }
146 
148  void InitFromRefAddresses( const ScDocument* pDoc, const ScRefAddress& rRef1, const ScRefAddress& rRef2, const ScAddress& rPos );
149 
150  bool Valid(const ScDocument* pDoc) const;
151 
155  bool ValidExternal(const ScDocument* pDoc) const;
156 
158  bool IsEntireCol() const
159  {
160  // Both row anchors must be absolute.
161  return Ref1.Row() == 0 && Ref2.Row() == MAXROW && !Ref1.IsRowRel() && !Ref2.IsRowRel();
162  }
163 
165  bool IsEntireRow() const
166  {
167  // Both column anchors must be absolute.
168  return Ref1.Col() == 0 && Ref2.Col() == MAXCOL && !Ref1.IsColRel() && !Ref2.IsColRel();
169  }
170 
171  SC_DLLPUBLIC ScRange toAbs( ScSheetLimits& rLimits, const ScAddress& rPos ) const;
172  SC_DLLPUBLIC ScRange toAbs( const ScDocument* pDoc, const ScAddress& rPos ) const;
173 
176  void SetRange( ScSheetLimits& rLimits, const ScRange& rRange, const ScAddress& rPos );
177 
179  void PutInOrder( const ScAddress& rPos );
180 
181  bool operator==( const ScComplexRefData& r ) const
182  { return Ref1 == r.Ref1 && Ref2 == r.Ref2; }
186  ScComplexRefData& Extend( ScSheetLimits& rLimits, const ScSingleRefData & rRef, const ScAddress & rPos );
187  ScComplexRefData& Extend( ScSheetLimits& rLimits, const ScComplexRefData & rRef, const ScAddress & rPos );
188 
192  bool IncEndColSticky( const ScDocument* pDoc, SCCOL nDelta, const ScAddress& rPos );
193 
197  bool IncEndRowSticky( const ScDocument* pDoc, SCROW nDelta, const ScAddress& rPos );
198 
199  bool IsDeleted() const;
200 
201 #if DEBUG_FORMULA_COMPILER
202  void Dump( int nIndent = 0 ) const;
203 #endif
204 };
205 
206 #endif
207 
208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsTabRel() const
Definition: refdata.hxx:70
bool operator==(const XclFontData &rLeft, const XclFontData &rRight)
Definition: xlstyle.cxx:517
SCCOL Col() const
Definition: refdata.cxx:247
bool IsTabDeleted() const
Definition: refdata.hxx:87
ScAddress aStart
Definition: address.hxx:500
bool operator!=(const XclExpString &rLeft, const XclExpString &rRight)
Definition: xestring.hxx:246
Flags
Single reference (one address) into the sheet.
Definition: refdata.hxx:30
void InitFlags()
Definition: refdata.hxx:128
void SetRange(ScSheetLimits &rLimits, const ScRange &rRange, const ScAddress &rPos)
Set a new range, assuming that the ordering of the range matches the ordering of the reference data f...
Definition: refdata.cxx:498
bool ValidExternal(const ScDocument *pDoc) const
In external references nTab is -1 for the start tab and -1 for the end tab if one sheet and the exter...
Definition: refdata.cxx:483
SC_DLLPUBLIC ScRange toAbs(ScSheetLimits &rLimits, const ScAddress &rPos) const
Definition: refdata.cxx:493
ScAddress aEnd
Definition: address.hxx:501
void SetRowRel(bool bVal)
Definition: refdata.hxx:67
void InitFromRefAddresses(const ScDocument *pDoc, const ScRefAddress &rRef1, const ScRefAddress &rRef2, const ScAddress &rPos)
InitFlags and set range, relative to rPos if rRef1 and rRef2 say so.
Definition: refdata.cxx:380
bool IsEntireCol() const
Whether this references entire columns, A:A.
Definition: refdata.hxx:158
void InitAddressRel(const ScDocument *pDoc, const ScAddress &rAdr, const ScAddress &rPos)
InitAddressRel: InitFlags and set address, everything relative to rPos.
Definition: refdata.cxx:40
const SCROW MAXROW
Definition: address.hxx:69
void SetTabRel(bool bVal)
Definition: refdata.hxx:69
bool IsColRel() const
Definition: refdata.hxx:66
bool IsEntireRow() const
Whether this references entire rows, 1:1.
Definition: refdata.hxx:165
void PutInOrder(T &nStart, T &nEnd)
Definition: address.hxx:954
void SetRelName(bool bVal)
Definition: refdata.hxx:92
void SetFlag3D(bool bVal)
Definition: refdata.hxx:90
void InitAddress(const ScAddress &rAdr)
InitAddress: InitFlags and set address.
Definition: refdata.cxx:27
sal_Int16 SCCOL
Definition: types.hxx:22
const SCCOL MAXCOL
Definition: address.hxx:70
bool IncEndColSticky(const ScDocument *pDoc, SCCOL nDelta, const ScAddress &rPos)
Increment or decrement end column unless or until sticky.
Definition: refdata.cxx:509
ScSingleRefData Ref1
Definition: refdata.hxx:125
bool Valid(const ScDocument *pDoc) const
Definition: refdata.cxx:478
ScSingleRefData Ref2
Definition: refdata.hxx:126
bool operator==(const ScComplexRefData &r) const
Definition: refdata.hxx:181
bool IsRowRel() const
Definition: refdata.hxx:68
bool IsFlag3D() const
Definition: refdata.hxx:91
sal_Int32 SCROW
Definition: types.hxx:18
unsigned char sal_uInt8
void InitFlags()
No default ctor, because used in ScRawToken union, set InitFlags!
Definition: refdata.hxx:55
sal_uInt8 FlagValue() const
Definition: refdata.hxx:63
void InitRange(const ScRange &rRange)
Definition: refdata.hxx:130
SCROW Row() const
Definition: refdata.cxx:240
bool IsDeleted() const
Definition: refdata.cxx:567
bool IsRelName() const
Definition: refdata.hxx:93
Complex reference (a range) into the sheet.
Definition: refdata.hxx:123
sal_uInt8 mnFlagValue
Definition: refdata.hxx:39
void InitRangeRel(const ScDocument *pDoc, const ScRange &rRange, const ScAddress &rPos)
Definition: refdata.hxx:135
void InitRange(SCCOL nCol1, SCROW nRow1, SCTAB nTab1, SCCOL nCol2, SCROW nRow2, SCTAB nTab2)
Definition: refdata.hxx:140
void PutInOrder(const ScAddress &rPos)
Adjust ordering (front-top-left/rear-bottom-right) to a new position.
Definition: refdata.cxx:504
ScComplexRefData & Extend(ScSheetLimits &rLimits, const ScSingleRefData &rRef, const ScAddress &rPos)
Enlarge range if reference passed is not within existing range.
Definition: refdata.cxx:394
bool IsRowDeleted() const
Definition: refdata.hxx:85
void SetColRel(bool bVal)
Definition: refdata.hxx:65
#define SC_DLLPUBLIC
Definition: scdllapi.h:28
sal_Int16 SCTAB
Definition: types.hxx:23
bool IsColDeleted() const
Definition: refdata.hxx:83
bool IncEndRowSticky(const ScDocument *pDoc, SCROW nDelta, const ScAddress &rPos)
Increment or decrement end row unless or until sticky.
Definition: refdata.cxx:538