LibreOffice Module sc (master)  1
rangenam.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 #pragma once
21 
22 #include "global.hxx"
23 #include "address.hxx"
24 #include <formula/grammar.hxx>
25 #include "scdllapi.h"
26 #include "calcmacros.hxx"
27 
28 #include <memory>
29 #include <map>
30 #include <vector>
31 
32 class ScDocument;
33 class ScTokenArray;
34 
35 namespace sc {
36 
37 struct RefUpdateContext;
38 struct RefUpdateInsertTabContext;
39 struct RefUpdateDeleteTabContext;
40 struct RefUpdateMoveTabContext;
41 class CompileFormulaContext;
42 
43 }
44 
46 {
47 public:
48  enum class Type //specialization to typed_flags outside of class
49  {
50  Name = 0x0000,
51  Database = 0x0001,
52  Criteria = 0x0002,
53  PrintArea = 0x0004,
54  ColHeader = 0x0008,
55  RowHeader = 0x0010,
56  AbsArea = 0x0020,
57  RefArea = 0x0040,
58  AbsPos = 0x0080
59  };
60 
61  enum class IsNameValidType
62  {
63  NAME_VALID,
66  };
67 
68 private:
69  OUString aName;
70  OUString aUpperName; // #i62977# for faster searching (aName is never modified after ctor)
71  OUString maNewName;
72  std::unique_ptr<ScTokenArray>
77  formula::FormulaGrammar::Grammar eTempGrammar; // needed for unresolved XML compiles
78  sal_uInt16 nIndex;
79  bool bModified; // is set/cleared by UpdateReference
80 
81  void CompileRangeData( const OUString& rSymbol, bool bSetError );
82  void InitCode();
83 public:
84 
86  const OUString& rName,
87  const OUString& rSymbol,
88  const ScAddress& rAdr = ScAddress(),
92  const OUString& rName,
93  const ScTokenArray& rArr,
94  const ScAddress& rAdr = ScAddress(),
95  Type nType = Type::Name );
97  const OUString& rName,
98  const ScAddress& rTarget );
99  // rTarget is ABSPOS jump label
100 
101  /* Exact copy, not recompiled, no other index (!), nothing... except if
102  * pDocument or pPos are passed, those values are assigned instead of the
103  * copies. */
104  ScRangeData( const ScRangeData& rScRangeData, ScDocument* pDocument = nullptr, const ScAddress* pPos = nullptr );
105 
107 
108  bool operator== (const ScRangeData& rData) const;
109 
110  void GetName( OUString& rName ) const { rName = maNewName.isEmpty() ? aName : maNewName; }
111  const OUString& GetName() const { return maNewName.isEmpty() ? aName : maNewName; }
112  const OUString& GetUpperName() const { return aUpperName; }
113  const ScAddress& GetPos() const { return aPos; }
114  // The index has to be unique. If index=0 a new index value is assigned.
115  void SetIndex( sal_uInt16 nInd ) { nIndex = nInd; }
116  sal_uInt16 GetIndex() const { return nIndex; }
118  void SetNewName( const OUString& rNewName ) { maNewName = rNewName; }
119  ScTokenArray* GetCode() { return pCode.get(); }
120  SC_DLLPUBLIC void SetCode( const ScTokenArray& );
121  const ScTokenArray* GetCode() const { return pCode.get(); }
123  bool HasReferences() const;
124  void AddType( Type nType );
125  Type GetType() const { return eType; }
126  bool HasType( Type nType ) const;
127  sal_uInt32 GetUnoType() const;
128  SC_DLLPUBLIC void GetSymbol( OUString& rSymbol, const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT ) const;
129  SC_DLLPUBLIC void GetSymbol( OUString& rSymbol, const ScAddress& rPos, const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT ) const;
130  void UpdateSymbol( OUStringBuffer& rBuffer, const ScAddress& );
131 
136  void UpdateReference( sc::RefUpdateContext& rCxt, SCTAB nLocalTab );
137  bool IsModified() const { return bModified; }
138 
140 
141  void UpdateTranspose( const ScRange& rSource, const ScAddress& rDest );
142  void UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY );
143 
144  SC_DLLPUBLIC bool IsReference( ScRange& rRef ) const;
145  bool IsReference( ScRange& rRef, const ScAddress& rPos ) const;
146  SC_DLLPUBLIC bool IsValidReference( ScRange& rRef ) const;
147  bool IsRangeAtBlock( const ScRange& ) const;
148 
149  void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt, SCTAB nLocalTab );
150  void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt, SCTAB nLocalTab );
151  void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt, SCTAB nLocalTab );
152 
153  void ValidateTabRefs();
154 
155  static void MakeValidName( const ScDocument& rDoc, OUString& rName );
156 
157  SC_DLLPUBLIC static IsNameValidType IsNameValid( const OUString& rName, const ScDocument& rDoc );
158 
160 
161 #if DEBUG_FORMULA_COMPILER
162  void Dump() const;
163 #endif
164 };
165 namespace o3tl
166 {
167  template<> struct typed_flags<ScRangeData::Type> : is_typed_flags<ScRangeData::Type, 0xff> {};
168 }
169 
170 
172 {
173  eType = eType|nType;
174 }
175 
176 inline bool ScRangeData::HasType( Type nType ) const
177 {
178  return ( ( eType & nType ) == nType );
179 }
180 
181 extern "C" int ScRangeData_QsortNameCompare( const void*, const void* );
182 
184 {
185 private:
186  typedef std::vector<ScRangeData*> IndexDataType;
187  typedef ::std::map<OUString, std::unique_ptr<ScRangeData>> DataType;
188  DataType m_Data;
189  IndexDataType maIndexToData;
190 
191 public:
193  typedef ::std::map<SCTAB, const ScRangeName*> TabNameCopyMap;
194 
195  typedef DataType::const_iterator const_iterator;
196  typedef DataType::iterator iterator;
197 
198  ScRangeName();
200 
201  SC_DLLPUBLIC const ScRangeData* findByRange(const ScRange& rRange) const;
202  SC_DLLPUBLIC ScRangeData* findByUpperName(const OUString& rName);
203  SC_DLLPUBLIC const ScRangeData* findByUpperName(const OUString& rName) const;
204  SC_DLLPUBLIC ScRangeData* findByIndex(sal_uInt16 i) const;
205  void UpdateReference( sc::RefUpdateContext& rCxt, SCTAB nLocalTab = -1 );
206  void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt, SCTAB nLocalTab = -1 );
207  void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt, SCTAB nLocalTab = -1 );
208  void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt, SCTAB nLocalTab = -1 );
209  void UpdateTranspose(const ScRange& rSource, const ScAddress& rDest);
210  void UpdateGrow(const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY);
211 
216 
234  void CopyUsedNames( const SCTAB nLocalTab, const SCTAB nOldTab, const SCTAB nNewTab,
235  const ScDocument& rOldDoc, ScDocument& rNewDoc, const bool bGlobalNamesToLocal ) const;
236 
237  SC_DLLPUBLIC const_iterator begin() const;
238  SC_DLLPUBLIC const_iterator end() const;
239  SC_DLLPUBLIC iterator begin();
240  SC_DLLPUBLIC iterator end();
241  SC_DLLPUBLIC size_t size() const;
242  bool empty() const;
243 
256  SC_DLLPUBLIC bool insert( ScRangeData* p, bool bReuseFreeIndex = true );
257 
258  void erase(const ScRangeData& r);
259  void erase(const OUString& rName);
260 
266  void erase(const iterator& itr);
267  void clear();
268  bool operator== (const ScRangeName& r) const;
269 };
270 
271 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Type
sal_uInt32 GetUnoType() const
Definition: rangenam.cxx:506
void UpdateDeleteTab(sc::RefUpdateDeleteTabContext &rCxt, SCTAB nLocalTab=-1)
Definition: rangenam.cxx:721
void CompileUnresolvedXML(sc::CompileFormulaContext &rCxt)
Compile those names that couldn't be resolved during loading and inserting because they may have refe...
Definition: rangenam.cxx:753
SC_DLLPUBLIC void SetCode(const ScTokenArray &)
Definition: rangenam.cxx:602
const OUString & GetUpperName() const
Definition: rangenam.hxx:112
sal_uInt16 GetIndex() const
Definition: rangenam.hxx:116
Context for reference update during shifting, moving or copying of cell ranges.
void UpdateTranspose(const ScRange &rSource, const ScAddress &rDest)
Definition: rangenam.cxx:273
bool operator==(const ScRangeName &r) const
Definition: rangenam.cxx:877
static void MakeValidName(const ScDocument &rDoc, OUString &rName)
Definition: rangenam.cxx:419
DataType::iterator iterator
Definition: rangenam.hxx:196
void clear()
Definition: rangenam.cxx:871
void CompileUnresolvedXML(sc::CompileFormulaContext &rCxt)
Definition: rangenam.cxx:177
IndexDataType maIndexToData
Definition: rangenam.hxx:189
::std::map< SCTAB, const ScRangeName * > TabNameCopyMap
Map that stores non-managed pointers to ScRangeName instances.
Definition: rangenam.hxx:193
DataType::const_iterator const_iterator
Definition: rangenam.hxx:195
formula::FormulaGrammar::Grammar eTempGrammar
Definition: rangenam.hxx:77
bool empty() const
Definition: rangenam.cxx:802
DataType m_Data
Definition: rangenam.hxx:188
void UpdateGrow(const ScRange &rArea, SCCOL nGrowX, SCROW nGrowY)
Definition: rangenam.cxx:305
void CopyUsedNames(const SCTAB nLocalTab, const SCTAB nOldTab, const SCTAB nNewTab, const ScDocument &rOldDoc, ScDocument &rNewDoc, const bool bGlobalNamesToLocal) const
Copy names while copying a sheet if they reference the sheet to be copied.
Definition: rangenam.cxx:761
void UpdateGrow(const ScRange &rArea, SCCOL nGrowX, SCROW nGrowY)
Definition: rangenam.cxx:745
SC_DLLPUBLIC void GuessPosition()
Definition: rangenam.cxx:205
SC_DLLPUBLIC const_iterator begin() const
Definition: rangenam.cxx:777
void GetName(OUString &rName) const
Definition: rangenam.hxx:110
OUString aName
Definition: rangenam.hxx:69
void UpdateInsertTab(sc::RefUpdateInsertTabContext &rCxt, SCTAB nLocalTab)
Definition: rangenam.cxx:390
void UpdateReference(sc::RefUpdateContext &rCxt, SCTAB nLocalTab=-1)
Definition: rangenam.cxx:701
bool HasReferences() const
Definition: rangenam.cxx:501
std::unique_ptr< ScTokenArray > pCode
Definition: rangenam.hxx:73
void UpdateInsertTab(sc::RefUpdateInsertTabContext &rCxt, SCTAB nLocalTab=-1)
Definition: rangenam.cxx:713
bool IsRangeAtBlock(const ScRange &) const
Definition: rangenam.cxx:357
SC_DLLPUBLIC ScRangeData * findByUpperName(const OUString &rName)
Definition: rangenam.cxx:679
SC_DLLPUBLIC const ScRangeData * findByRange(const ScRange &rRange) const
Definition: rangenam.cxx:672
SC_DLLPUBLIC const_iterator end() const
Definition: rangenam.cxx:782
std::vector< ScRangeData * > IndexDataType
Definition: rangenam.hxx:186
SC_DLLPUBLIC void GetSymbol(OUString &rSymbol, const formula::FormulaGrammar::Grammar eGrammar=formula::FormulaGrammar::GRAM_DEFAULT) const
Definition: rangenam.cxx:243
void UpdateTranspose(const ScRange &rSource, const ScAddress &rDest)
Definition: rangenam.cxx:737
sal_Int16 SCCOL
Definition: types.hxx:21
static SC_DLLPUBLIC IsNameValidType IsNameValid(const OUString &rName, const ScDocument &rDoc)
Definition: rangenam.cxx:464
const OUString & GetName() const
Definition: rangenam.hxx:111
OUString aUpperName
Definition: rangenam.hxx:70
void AddType(Type nType)
Definition: rangenam.hxx:171
void UpdateMoveTab(sc::RefUpdateMoveTabContext &rCxt, SCTAB nLocalTab)
Definition: rangenam.cxx:410
ScAddress aPos
Definition: rangenam.hxx:74
SC_DLLPUBLIC ScRangeData * findByIndex(sal_uInt16 i) const
Definition: rangenam.cxx:691
void erase(const ScRangeData &r)
Definition: rangenam.cxx:850
bool operator==(const ScRangeData &rData) const
Definition: rangenam.cxx:337
bool HasType(Type nType) const
Definition: rangenam.hxx:176
void CompileRangeData(const OUString &rSymbol, bool bSetError)
Definition: rangenam.cxx:140
FormulaError
void UpdateMoveTab(sc::RefUpdateMoveTabContext &rCxt, SCTAB nLocalTab=-1)
Definition: rangenam.cxx:729
int ScRangeData_QsortNameCompare(const void *, const void *)
Definition: rangenam.cxx:625
ScDocument & rDoc
Definition: rangenam.hxx:76
sal_Int32 SCROW
Definition: types.hxx:17
void SetIndex(sal_uInt16 nInd)
Definition: rangenam.hxx:115
void UpdateDeleteTab(sc::RefUpdateDeleteTabContext &rCxt, SCTAB nLocalTab)
Definition: rangenam.cxx:400
const ScAddress & GetPos() const
Definition: rangenam.hxx:113
const ScTokenArray * GetCode() const
Definition: rangenam.hxx:121
sal_uInt16 nIndex
Definition: rangenam.hxx:78
void SetNewName(const OUString &rNewName)
Does not change the name, but sets maNewName for formula update after dialog.
Definition: rangenam.hxx:118
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:400
SC_DLLPUBLIC FormulaError GetErrCode() const
Definition: rangenam.cxx:496
bool IsModified() const
Definition: rangenam.hxx:137
SC_DLLPUBLIC bool IsValidReference(ScRange &rRef) const
Definition: rangenam.cxx:382
SC_DLLPUBLIC bool IsReference(ScRange &rRef) const
Definition: rangenam.cxx:366
Type eType
Definition: rangenam.hxx:75
Type GetType() const
Definition: rangenam.hxx:125
void InitCode()
Definition: rangenam.cxx:609
SC_DLLPUBLIC size_t size() const
Definition: rangenam.cxx:797
bool bModified
Definition: rangenam.hxx:79
void UpdateSymbol(OUStringBuffer &rBuffer, const ScAddress &)
Definition: rangenam.cxx:257
ScTokenArray * GetCode()
Definition: rangenam.hxx:119
::std::map< OUString, std::unique_ptr< ScRangeData > > DataType
Definition: rangenam.hxx:187
void ValidateTabRefs()
Definition: rangenam.cxx:516
#define SC_DLLPUBLIC
Definition: scdllapi.h:27
SC_DLLPUBLIC ScRangeData(ScDocument &rDoc, const OUString &rName, const OUString &rSymbol, const ScAddress &rAdr=ScAddress(), Type nType=Type::Name, const formula::FormulaGrammar::Grammar eGrammar=formula::FormulaGrammar::GRAM_DEFAULT)
Definition: rangenam.cxx:44
SC_DLLPUBLIC bool insert(ScRangeData *p, bool bReuseFreeIndex=true)
Insert object into set.
Definition: rangenam.cxx:807
SC_DLLPUBLIC ~ScRangeData()
Definition: rangenam.cxx:136
sal_Int16 SCTAB
Definition: types.hxx:22
void UpdateReference(sc::RefUpdateContext &rCxt, SCTAB nLocalTab)
Definition: rangenam.cxx:265
OUString maNewName
used for formulas after changing names in the dialog
Definition: rangenam.hxx:71