1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
30 #include <boost/ptr_container/ptr_set.hpp>
31 #include <boost/ptr_container/ptr_map.hpp>
33 //------------------------------------------------------------------------
39 //------------------------------------------------------------------------
41 typedef sal_uInt16 RangeType
;
43 #define RT_NAME ((RangeType)0x0000)
44 #define RT_DATABASE ((RangeType)0x0001)
45 #define RT_CRITERIA ((RangeType)0x0002)
46 #define RT_PRINTAREA ((RangeType)0x0004)
47 #define RT_COLHEADER ((RangeType)0x0008)
48 #define RT_ROWHEADER ((RangeType)0x0010)
49 #define RT_ABSAREA ((RangeType)0x0020)
50 #define RT_REFAREA ((RangeType)0x0040)
51 #define RT_ABSPOS ((RangeType)0x0080)
52 #define RT_SHARED ((RangeType)0x0100)
53 #define RT_SHAREDMOD ((RangeType)0x0200)
55 //------------------------------------------------------------------------
63 OUString aUpperName
; // #i62977# for faster searching (aName is never modified after ctor)
68 formula::FormulaGrammar::Grammar eTempGrammar
; // needed for unresolved XML compiles
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.
77 void CompileRangeData( const String
& rSymbol
, bool bSetError
);
80 typedef ::std::map
<sal_uInt16
, sal_uInt16
> IndexMap
;
82 SC_DLLPUBLIC
ScRangeData( ScDocument
* pDoc
,
83 const OUString
& rName
,
84 const String
& rSymbol
,
85 const ScAddress
& rAdr
= ScAddress(),
86 RangeType nType
= RT_NAME
,
87 const formula::FormulaGrammar::Grammar eGrammar
= formula::FormulaGrammar::GRAM_DEFAULT
);
88 SC_DLLPUBLIC
ScRangeData( ScDocument
* pDoc
,
89 const OUString
& rName
,
90 const ScTokenArray
& rArr
,
91 const ScAddress
& rAdr
= ScAddress(),
92 RangeType nType
= RT_NAME
);
93 SC_DLLPUBLIC
ScRangeData( ScDocument
* pDoc
,
94 const OUString
& rName
,
95 const ScAddress
& rTarget
);
96 // rTarget is ABSPOS jump label
97 ScRangeData(const ScRangeData
& rScRangeData
, ScDocument
* pDocument
= NULL
);
99 SC_DLLPUBLIC
~ScRangeData();
101 bool operator== (const ScRangeData
& rData
) const;
103 void GetName( OUString
& rName
) const { rName
= aName
; }
104 const OUString
& GetName( void ) const { return aName
; }
105 const OUString
& GetUpperName( void ) const { return aUpperName
; }
106 ScAddress
GetPos() const { return aPos
; }
107 // The index has to be unique. If index=0 a new index value is assigned.
108 void SetIndex( sal_uInt16 nInd
) { nIndex
= nInd
; }
109 sal_uInt16
GetIndex() const { return nIndex
; }
110 ScTokenArray
* GetCode() { return pCode
; }
111 SC_DLLPUBLIC
void SetCode( ScTokenArray
& );
112 const ScTokenArray
* GetCode() const { return pCode
; }
113 SC_DLLPUBLIC sal_uInt16
GetErrCode() const;
114 bool HasReferences() const;
115 void SetDocument( ScDocument
* pDocument
){ pDoc
= pDocument
; }
116 ScDocument
* GetDocument() const { return pDoc
; }
117 void SetType( RangeType nType
) { eType
= nType
; }
118 void AddType( RangeType nType
) { eType
= eType
|nType
; }
119 RangeType
GetType() const { return eType
; }
120 bool HasType( RangeType nType
) const;
121 sal_uInt32
GetUnoType() const;
122 SC_DLLPUBLIC
void GetSymbol( String
& rSymbol
, const formula::FormulaGrammar::Grammar eGrammar
= formula::FormulaGrammar::GRAM_DEFAULT
) 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
);
127 void UpdateReference( UpdateRefMode eUpdateRefMode
,
129 SCsCOL nDx
, SCsROW nDy
, SCsTAB nDz
, bool bLocal
= false );
130 bool IsModified() const { return bModified
; }
132 SC_DLLPUBLIC
void GuessPosition();
134 void UpdateTranspose( const ScRange
& rSource
, const ScAddress
& rDest
);
135 void UpdateGrow( const ScRange
& rArea
, SCCOL nGrowX
, SCROW nGrowY
);
137 SC_DLLPUBLIC
bool IsReference( ScRange
& rRef
) const;
138 bool IsReference( ScRange
& rRef
, const ScAddress
& rPos
) const;
139 SC_DLLPUBLIC
bool IsValidReference( ScRange
& rRef
) const;
140 bool IsRangeAtBlock( const ScRange
& ) const;
142 void UpdateTabRef(SCTAB nOldTable
, sal_uInt16 nFlag
, SCTAB nNewTable
, SCTAB nNewSheets
);
144 void ValidateTabRefs();
146 static void MakeValidName( String
& rName
);
147 SC_DLLPUBLIC
static bool IsNameValid( const String
& rName
, ScDocument
* pDoc
);
149 SC_DLLPUBLIC
void SetMaxRow(SCROW nRow
);
150 SCROW
GetMaxRow() const;
151 SC_DLLPUBLIC
void SetMaxCol(SCCOL nCol
);
152 SCCOL
GetMaxCol() const;
154 void CompileUnresolvedXML();
157 inline bool ScRangeData::HasType( RangeType nType
) const
159 return ( ( eType
& nType
) == nType
);
162 extern "C" int SAL_CALL
ScRangeData_QsortNameCompare( const void*, const void* );
164 bool operator< (const ScRangeData
& left
, const ScRangeData
& right
);
169 typedef std::vector
<ScRangeData
*> IndexDataType
;
170 typedef ::boost::ptr_map
<OUString
, ScRangeData
> DataType
;
172 IndexDataType maIndexToData
;
175 /// Map that manages stored ScRangeName instances.
176 typedef ::boost::ptr_map
<SCTAB
, ScRangeName
> TabNameMap
;
177 /// Map that stores non-managed pointers to ScRangeName instances.
178 typedef ::std::map
<SCTAB
, const ScRangeName
*> TabNameCopyMap
;
180 typedef DataType::const_iterator const_iterator
;
181 typedef DataType::iterator iterator
;
184 SC_DLLPUBLIC
ScRangeName(const ScRangeName
& r
);
186 SC_DLLPUBLIC
const ScRangeData
* findByRange(const ScRange
& rRange
) const;
187 SC_DLLPUBLIC ScRangeData
* findByUpperName(const OUString
& rName
);
188 SC_DLLPUBLIC
const ScRangeData
* findByUpperName(const OUString
& rName
) const;
189 SC_DLLPUBLIC ScRangeData
* findByIndex(sal_uInt16 i
) const;
190 void UpdateReference(UpdateRefMode eUpdateRefMode
, const ScRange
& rRange
,
191 SCsCOL nDx
, SCsROW nDy
, SCsTAB nDz
, bool bLocal
= false);
192 void UpdateTabRef(SCTAB nTable
, sal_uInt16 nFlag
, SCTAB nNewTable
= 0, SCTAB nNewSheets
= 1);
193 void UpdateTranspose(const ScRange
& rSource
, const ScAddress
& rDest
);
194 void UpdateGrow(const ScRange
& rArea
, SCCOL nGrowX
, SCROW nGrowY
);
196 /** Compile those names that couldn't be resolved during loading and
197 inserting because they may have referred a name that was inserted later.
199 void CompileUnresolvedXML();
201 SC_DLLPUBLIC const_iterator
begin() const;
202 SC_DLLPUBLIC const_iterator
end() const;
203 SC_DLLPUBLIC iterator
begin();
204 SC_DLLPUBLIC iterator
end();
205 SC_DLLPUBLIC
size_t size() const;
208 /** Insert object into set.
209 @ATTENTION: The underlying ::boost::ptr_set_adapter::insert(p) takes
210 ownership of p and if it can't insert it deletes the object! So, if
211 this insert here returns false the object where p pointed to is gone!
213 SC_DLLPUBLIC
bool insert(ScRangeData
* p
);
215 void erase(const ScRangeData
& r
);
216 void erase(const OUString
& rName
);
219 * Erase by iterator position. Note that this method doesn't check for
220 * iterator's validity. The caller must make sure that the iterator is
223 void erase(const iterator
& itr
);
225 bool operator== (const ScRangeName
& r
) const;
230 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */