Impress Remote 1.0.5, tag sdremote-1.0.5
[LibreOffice.git] / sc / inc / rangenam.hxx
blob27b9262194b7a22981912bbaa879e5b9429bc1f6
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 SC_RANGENAM_HXX
21 #define SC_RANGENAM_HXX
23 #include "global.hxx" // -> enum UpdateRefMode
24 #include "address.hxx"
25 #include "formula/grammar.hxx"
26 #include "scdllapi.h"
28 #include <map>
29 #include <vector>
30 #include <boost/ptr_container/ptr_set.hpp>
31 #include <boost/ptr_container/ptr_map.hpp>
33 //------------------------------------------------------------------------
35 class ScDocument;
37 namespace rtl {
38 class OUStringBuffer;
42 //------------------------------------------------------------------------
44 typedef sal_uInt16 RangeType;
46 #define RT_NAME ((RangeType)0x0000)
47 #define RT_DATABASE ((RangeType)0x0001)
48 #define RT_CRITERIA ((RangeType)0x0002)
49 #define RT_PRINTAREA ((RangeType)0x0004)
50 #define RT_COLHEADER ((RangeType)0x0008)
51 #define RT_ROWHEADER ((RangeType)0x0010)
52 #define RT_ABSAREA ((RangeType)0x0020)
53 #define RT_REFAREA ((RangeType)0x0040)
54 #define RT_ABSPOS ((RangeType)0x0080)
55 #define RT_SHARED ((RangeType)0x0100)
56 #define RT_SHAREDMOD ((RangeType)0x0200)
58 //------------------------------------------------------------------------
60 class ScTokenArray;
62 class ScRangeData
64 private:
65 rtl::OUString aName;
66 rtl::OUString aUpperName; // #i62977# for faster searching (aName is never modified after ctor)
67 ScTokenArray* pCode;
68 ScAddress aPos;
69 RangeType eType;
70 ScDocument* pDoc;
71 formula::FormulaGrammar::Grammar eTempGrammar; // needed for unresolved XML compiles
72 sal_uInt16 nIndex;
73 bool bModified; // is set/cleared by UpdateReference
75 // max row and column to use for wrapping of references. If -1 use the
76 // application's default.
77 SCROW mnMaxRow;
78 SCCOL mnMaxCol;
80 void CompileRangeData( const String& rSymbol, bool bSetError );
81 void InitCode();
82 public:
83 typedef ::std::map<sal_uInt16, sal_uInt16> IndexMap;
85 SC_DLLPUBLIC ScRangeData( ScDocument* pDoc,
86 const rtl::OUString& rName,
87 const String& rSymbol,
88 const ScAddress& rAdr = ScAddress(),
89 RangeType nType = RT_NAME,
90 const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT );
91 SC_DLLPUBLIC ScRangeData( ScDocument* pDoc,
92 const rtl::OUString& rName,
93 const ScTokenArray& rArr,
94 const ScAddress& rAdr = ScAddress(),
95 RangeType nType = RT_NAME );
96 SC_DLLPUBLIC ScRangeData( ScDocument* pDoc,
97 const rtl::OUString& rName,
98 const ScAddress& rTarget );
99 // rTarget is ABSPOS jump label
100 ScRangeData(const ScRangeData& rScRangeData, ScDocument* pDocument = NULL);
102 SC_DLLPUBLIC ~ScRangeData();
104 bool operator== (const ScRangeData& rData) const;
106 void GetName( rtl::OUString& rName ) const { rName = aName; }
107 const rtl::OUString& GetName( void ) const { return aName; }
108 const rtl::OUString& GetUpperName( void ) const { return aUpperName; }
109 ScAddress GetPos() const { return aPos; }
110 // The index has to be unique. If index=0 a new index value is assigned.
111 void SetIndex( sal_uInt16 nInd ) { nIndex = nInd; }
112 sal_uInt16 GetIndex() const { return nIndex; }
113 ScTokenArray* GetCode() { return pCode; }
114 SC_DLLPUBLIC void SetCode( ScTokenArray& );
115 const ScTokenArray* GetCode() const { return pCode; }
116 SC_DLLPUBLIC sal_uInt16 GetErrCode() const;
117 bool HasReferences() const;
118 void SetDocument( ScDocument* pDocument){ pDoc = pDocument; }
119 ScDocument* GetDocument() const { return pDoc; }
120 void SetType( RangeType nType ) { eType = nType; }
121 void AddType( RangeType nType ) { eType = eType|nType; }
122 RangeType GetType() const { return eType; }
123 bool HasType( RangeType nType ) const;
124 sal_uInt32 GetUnoType() const;
125 SC_DLLPUBLIC void GetSymbol( String& rSymbol, const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT ) const;
126 SC_DLLPUBLIC void GetSymbol( rtl::OUString& rSymbol, const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT ) const;
127 SC_DLLPUBLIC void GetSymbol( rtl::OUString& rSymbol, const ScAddress& rPos, const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT ) const;
128 void UpdateSymbol( rtl::OUStringBuffer& rBuffer, const ScAddress&,
129 const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT );
130 void UpdateReference( UpdateRefMode eUpdateRefMode,
131 const ScRange& r,
132 SCsCOL nDx, SCsROW nDy, SCsTAB nDz, bool bLocal = false );
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 UpdateTabRef(SCTAB nOldTable, sal_uInt16 nFlag, SCTAB nNewTable, SCTAB nNewSheets);
147 void ValidateTabRefs();
149 static void MakeValidName( String& rName );
150 SC_DLLPUBLIC static bool IsNameValid( const String& rName, ScDocument* pDoc );
152 SC_DLLPUBLIC void SetMaxRow(SCROW nRow);
153 SCROW GetMaxRow() const;
154 SC_DLLPUBLIC void SetMaxCol(SCCOL nCol);
155 SCCOL GetMaxCol() const;
157 void CompileUnresolvedXML();
160 inline bool ScRangeData::HasType( RangeType nType ) const
162 return ( ( eType & nType ) == nType );
165 extern "C" int SAL_CALL ScRangeData_QsortNameCompare( const void*, const void* );
167 bool operator< (const ScRangeData& left, const ScRangeData& right);
169 class ScRangeName
171 private:
172 typedef std::vector<ScRangeData*> IndexDataType;
173 typedef ::boost::ptr_map<rtl::OUString, ScRangeData> DataType;
174 DataType maData;
175 IndexDataType maIndexToData;
177 public:
178 /// Map that manages stored ScRangeName instances.
179 typedef ::boost::ptr_map<SCTAB, ScRangeName> TabNameMap;
180 /// Map that stores non-managed pointers to ScRangeName instances.
181 typedef ::std::map<SCTAB, const ScRangeName*> TabNameCopyMap;
183 typedef DataType::const_iterator const_iterator;
184 typedef DataType::iterator iterator;
186 ScRangeName();
187 SC_DLLPUBLIC ScRangeName(const ScRangeName& r);
189 SC_DLLPUBLIC const ScRangeData* findByRange(const ScRange& rRange) const;
190 SC_DLLPUBLIC ScRangeData* findByUpperName(const rtl::OUString& rName);
191 SC_DLLPUBLIC const ScRangeData* findByUpperName(const rtl::OUString& rName) const;
192 SC_DLLPUBLIC ScRangeData* findByIndex(sal_uInt16 i) const;
193 void UpdateReference(UpdateRefMode eUpdateRefMode, const ScRange& rRange,
194 SCsCOL nDx, SCsROW nDy, SCsTAB nDz, bool bLocal = false);
195 void UpdateTabRef(SCTAB nTable, sal_uInt16 nFlag, SCTAB nNewTable = 0, SCTAB nNewSheets = 1);
196 void UpdateTranspose(const ScRange& rSource, const ScAddress& rDest);
197 void UpdateGrow(const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY);
199 /** Compile those names that couldn't be resolved during loading and
200 inserting because they may have referred a name that was inserted later.
202 void CompileUnresolvedXML();
204 SC_DLLPUBLIC const_iterator begin() const;
205 SC_DLLPUBLIC const_iterator end() const;
206 SC_DLLPUBLIC iterator begin();
207 SC_DLLPUBLIC iterator end();
208 SC_DLLPUBLIC size_t size() const;
209 bool empty() const;
211 /** Insert object into set.
212 @ATTENTION: The underlying ::boost::ptr_set_adapter::insert(p) takes
213 ownership of p and if it can't insert it deletes the object! So, if
214 this insert here returns false the object where p pointed to is gone!
216 SC_DLLPUBLIC bool insert(ScRangeData* p);
218 void erase(const ScRangeData& r);
219 void erase(const rtl::OUString& rName);
222 * Erase by iterator position. Note that this method doesn't check for
223 * iterator's validity. The caller must make sure that the iterator is
224 * valid.
226 void erase(const iterator& itr);
227 void clear();
228 bool operator== (const ScRangeName& r) const;
231 #endif
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */