Bump version to 4.3-4
[LibreOffice.git] / sc / inc / rangenam.hxx
blob5d782e99e525ebf95513dbc913a5cc47396607fe
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SC_INC_RANGENAM_HXX
21 #define INCLUDED_SC_INC_RANGENAM_HXX
23 #include "global.hxx"
24 #include "address.hxx"
25 #include <formula/grammar.hxx>
26 #include "scdllapi.h"
27 #include "calcmacros.hxx"
29 #include <map>
30 #include <vector>
31 #include <boost/ptr_container/ptr_set.hpp>
32 #include <boost/ptr_container/ptr_map.hpp>
34 class ScDocument;
35 class ScTokenArray;
37 namespace sc {
39 struct RefUpdateContext;
40 struct RefUpdateInsertTabContext;
41 struct RefUpdateDeleteTabContext;
42 struct RefUpdateMoveTabContext;
43 class CompileFormulaContext;
47 typedef sal_uInt16 RangeType;
49 #define RT_NAME ((RangeType)0x0000)
50 #define RT_DATABASE ((RangeType)0x0001)
51 #define RT_CRITERIA ((RangeType)0x0002)
52 #define RT_PRINTAREA ((RangeType)0x0004)
53 #define RT_COLHEADER ((RangeType)0x0008)
54 #define RT_ROWHEADER ((RangeType)0x0010)
55 #define RT_ABSAREA ((RangeType)0x0020)
56 #define RT_REFAREA ((RangeType)0x0040)
57 #define RT_ABSPOS ((RangeType)0x0080)
59 class ScRangeData
61 private:
62 OUString aName;
63 OUString aUpperName; // #i62977# for faster searching (aName is never modified after ctor)
64 ScTokenArray* pCode;
65 ScAddress aPos;
66 RangeType eType;
67 ScDocument* pDoc;
68 formula::FormulaGrammar::Grammar eTempGrammar; // needed for unresolved XML compiles
69 sal_uInt16 nIndex;
70 bool bModified; // is set/cleared by UpdateReference
72 // max row and column to use for wrapping of references. If -1 use the
73 // application's default.
74 SCROW mnMaxRow;
75 SCCOL mnMaxCol;
77 void CompileRangeData( const OUString& rSymbol, bool bSetError );
78 void InitCode();
79 public:
81 typedef ::std::map<sal_uInt16, sal_uInt16> IndexMap;
83 SC_DLLPUBLIC ScRangeData( ScDocument* pDoc,
84 const OUString& rName,
85 const OUString& rSymbol,
86 const ScAddress& rAdr = ScAddress(),
87 RangeType nType = RT_NAME,
88 const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT );
89 SC_DLLPUBLIC ScRangeData( ScDocument* pDoc,
90 const OUString& rName,
91 const ScTokenArray& rArr,
92 const ScAddress& rAdr = ScAddress(),
93 RangeType nType = RT_NAME );
94 SC_DLLPUBLIC ScRangeData( ScDocument* pDoc,
95 const OUString& rName,
96 const ScAddress& rTarget );
97 // rTarget is ABSPOS jump label
98 ScRangeData(const ScRangeData& rScRangeData, ScDocument* pDocument = NULL);
100 SC_DLLPUBLIC ~ScRangeData();
102 bool operator== (const ScRangeData& rData) const;
104 void GetName( OUString& rName ) const { rName = aName; }
105 const OUString& GetName( void ) const { return aName; }
106 const OUString& GetUpperName( void ) const { return aUpperName; }
107 ScAddress GetPos() const { return aPos; }
108 // The index has to be unique. If index=0 a new index value is assigned.
109 void SetIndex( sal_uInt16 nInd ) { nIndex = nInd; }
110 sal_uInt16 GetIndex() const { return nIndex; }
111 ScTokenArray* GetCode() { return pCode; }
112 SC_DLLPUBLIC void SetCode( ScTokenArray& );
113 const ScTokenArray* GetCode() const { return pCode; }
114 SC_DLLPUBLIC sal_uInt16 GetErrCode() const;
115 bool HasReferences() const;
116 void SetDocument( ScDocument* pDocument){ pDoc = pDocument; }
117 ScDocument* GetDocument() const { return pDoc; }
118 void SetType( RangeType nType ) { eType = nType; }
119 void AddType( RangeType nType ) { eType = eType|nType; }
120 RangeType GetType() const { return eType; }
121 bool HasType( RangeType nType ) const;
122 sal_uInt32 GetUnoType() const;
123 SC_DLLPUBLIC void GetSymbol( OUString& rSymbol, const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT ) const;
124 SC_DLLPUBLIC void GetSymbol( OUString& rSymbol, const ScAddress& rPos, const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT ) const;
125 void UpdateSymbol( OUStringBuffer& rBuffer, const ScAddress&,
126 const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT );
129 * @param nLocalTab sheet index where this name belongs, or -1 for global
130 * name.
132 void UpdateReference( sc::RefUpdateContext& rCxt, SCTAB nLocalTab = -1 );
133 bool IsModified() const { return bModified; }
135 SC_DLLPUBLIC void GuessPosition();
137 void UpdateTranspose( const ScRange& rSource, const ScAddress& rDest );
138 void UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY );
140 SC_DLLPUBLIC bool IsReference( ScRange& rRef ) const;
141 bool IsReference( ScRange& rRef, const ScAddress& rPos ) const;
142 SC_DLLPUBLIC bool IsValidReference( ScRange& rRef ) const;
143 bool IsRangeAtBlock( const ScRange& ) const;
145 void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt, SCTAB nLocalTab = -1 );
146 void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt, SCTAB nLocalTab = -1 );
147 void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt, SCTAB nLocalTab = -1 );
149 void ValidateTabRefs();
151 static void MakeValidName( OUString& rName );
152 SC_DLLPUBLIC static bool IsNameValid( const OUString& rName, ScDocument* pDoc );
154 SCROW GetMaxRow() const;
155 SCCOL GetMaxCol() const;
157 void CompileUnresolvedXML( sc::CompileFormulaContext& rCxt );
159 #if DEBUG_FORMULA_COMPILER
160 void Dump() const;
161 #endif
164 inline bool ScRangeData::HasType( RangeType nType ) const
166 return ( ( eType & nType ) == nType );
169 extern "C" int SAL_CALL ScRangeData_QsortNameCompare( const void*, const void* );
171 bool operator< (const ScRangeData& left, const ScRangeData& right);
173 class ScRangeName
175 private:
176 typedef std::vector<ScRangeData*> IndexDataType;
177 typedef ::boost::ptr_map<OUString, ScRangeData> DataType;
178 DataType maData;
179 IndexDataType maIndexToData;
181 public:
182 /// Map that manages stored ScRangeName instances.
183 typedef ::boost::ptr_map<SCTAB, ScRangeName> TabNameMap;
184 /// Map that stores non-managed pointers to ScRangeName instances.
185 typedef ::std::map<SCTAB, const ScRangeName*> TabNameCopyMap;
187 typedef DataType::const_iterator const_iterator;
188 typedef DataType::iterator iterator;
190 ScRangeName();
191 SC_DLLPUBLIC ScRangeName(const ScRangeName& r);
193 SC_DLLPUBLIC const ScRangeData* findByRange(const ScRange& rRange) const;
194 SC_DLLPUBLIC ScRangeData* findByUpperName(const OUString& rName);
195 SC_DLLPUBLIC const ScRangeData* findByUpperName(const OUString& rName) const;
196 SC_DLLPUBLIC ScRangeData* findByIndex(sal_uInt16 i) const;
197 void UpdateReference( sc::RefUpdateContext& rCxt, SCTAB nLocalTab = -1 );
198 void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt, SCTAB nLocalTab = -1 );
199 void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt, SCTAB nLocalTab = -1 );
200 void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt, SCTAB nLocalTab = -1 );
201 void UpdateTranspose(const ScRange& rSource, const ScAddress& rDest);
202 void UpdateGrow(const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY);
204 /** Compile those names that couldn't be resolved during loading and
205 inserting because they may have referred a name that was inserted later.
207 void CompileUnresolvedXML( sc::CompileFormulaContext& rCxt );
209 SC_DLLPUBLIC const_iterator begin() const;
210 SC_DLLPUBLIC const_iterator end() const;
211 SC_DLLPUBLIC iterator begin();
212 SC_DLLPUBLIC iterator end();
213 SC_DLLPUBLIC size_t size() const;
214 bool empty() const;
216 /** Insert object into set.
217 @ATTENTION: The underlying ::boost::ptr_set_adapter::insert(p) takes
218 ownership of p and if it can't insert it deletes the object! So, if
219 this insert here returns false the object where p pointed to is gone!
221 SC_DLLPUBLIC bool insert(ScRangeData* p);
223 void erase(const ScRangeData& r);
224 void erase(const OUString& rName);
227 * Erase by iterator position. Note that this method doesn't check for
228 * iterator's validity. The caller must make sure that the iterator is
229 * valid.
231 void erase(const iterator& itr);
232 void clear();
233 bool operator== (const ScRangeName& r) const;
236 #endif
238 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */