merged tag ooo/OOO330_m14
[LibreOffice.git] / sc / inc / rangenam.hxx
bloba9f324b8b7370b466fac8f7cfe64a9f7035f3a09
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #ifndef SC_RANGENAM_HXX
29 #define SC_RANGENAM_HXX
31 #include "global.hxx" // -> enum UpdateRefMode
32 #include "address.hxx"
33 #include "collect.hxx"
34 #include "formula/grammar.hxx"
35 #include "scdllapi.h"
37 #include <map>
39 //------------------------------------------------------------------------
41 class ScDocument;
43 namespace rtl {
44 class OUStringBuffer;
48 //------------------------------------------------------------------------
50 typedef USHORT RangeType;
52 #define RT_NAME ((RangeType)0x0000)
53 #define RT_DATABASE ((RangeType)0x0001)
54 #define RT_CRITERIA ((RangeType)0x0002)
55 #define RT_PRINTAREA ((RangeType)0x0004)
56 #define RT_COLHEADER ((RangeType)0x0008)
57 #define RT_ROWHEADER ((RangeType)0x0010)
58 #define RT_ABSAREA ((RangeType)0x0020)
59 #define RT_REFAREA ((RangeType)0x0040)
60 #define RT_ABSPOS ((RangeType)0x0080)
61 #define RT_SHARED ((RangeType)0x0100)
62 #define RT_SHAREDMOD ((RangeType)0x0200)
64 //------------------------------------------------------------------------
66 class ScTokenArray;
68 class ScRangeData : public ScDataObject
70 private:
71 String aName;
72 String aUpperName; // #i62977# for faster searching (aName is never modified after ctor)
73 ScTokenArray* pCode;
74 ScAddress aPos;
75 RangeType eType;
76 ScDocument* pDoc;
77 USHORT nIndex;
78 BOOL bModified; // wird bei UpdateReference gesetzt/geloescht
80 // max row and column to use for wrapping of references. If -1 use the
81 // application's default.
82 SCROW mnMaxRow;
83 SCCOL mnMaxCol;
85 friend class ScRangeName;
86 ScRangeData( USHORT nIndex );
87 public:
88 typedef ::std::map<sal_uInt16, sal_uInt16> IndexMap;
90 SC_DLLPUBLIC ScRangeData( ScDocument* pDoc,
91 const String& rName,
92 const String& rSymbol,
93 const ScAddress& rAdr = ScAddress(),
94 RangeType nType = RT_NAME,
95 const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT );
96 SC_DLLPUBLIC ScRangeData( ScDocument* pDoc,
97 const String& rName,
98 const ScTokenArray& rArr,
99 const ScAddress& rAdr = ScAddress(),
100 RangeType nType = RT_NAME );
101 SC_DLLPUBLIC ScRangeData( ScDocument* pDoc,
102 const String& rName,
103 const ScAddress& rTarget );
104 // rTarget ist ABSPOS Sprungmarke
105 ScRangeData(const ScRangeData& rScRangeData);
107 SC_DLLPUBLIC virtual ~ScRangeData();
110 virtual ScDataObject* Clone() const;
112 BOOL operator== (const ScRangeData& rData) const;
114 void GetName( String& rName ) const { rName = aName; }
115 const String& GetName( void ) const { return aName; }
116 const String& GetUpperName( void ) const { return aUpperName; }
117 ScAddress GetPos() const { return aPos; }
118 // Der Index muss eindeutig sein. Ist er 0, wird ein neuer Index vergeben
119 void SetIndex( USHORT nInd ) { nIndex = nInd; }
120 USHORT GetIndex() const { return nIndex; }
121 ScTokenArray* GetCode() { return pCode; }
122 USHORT GetErrCode();
123 BOOL HasReferences() const;
124 void SetDocument( ScDocument* pDocument){ pDoc = pDocument; }
125 ScDocument* GetDocument() const { return pDoc; }
126 void SetType( RangeType nType ) { eType = nType; }
127 void AddType( RangeType nType ) { eType = eType|nType; }
128 RangeType GetType() const { return eType; }
129 BOOL HasType( RangeType nType ) const;
130 SC_DLLPUBLIC void GetSymbol( String& rSymbol, const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT ) const;
131 void UpdateSymbol( rtl::OUStringBuffer& rBuffer, const ScAddress&,
132 const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT );
133 void UpdateReference( UpdateRefMode eUpdateRefMode,
134 const ScRange& r,
135 SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
136 BOOL IsModified() const { return bModified; }
138 SC_DLLPUBLIC void GuessPosition();
140 void UpdateTranspose( const ScRange& rSource, const ScAddress& rDest );
141 void UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY );
143 SC_DLLPUBLIC BOOL IsReference( ScRange& rRef ) const;
144 BOOL IsReference( ScRange& rRef, const ScAddress& rPos ) const;
145 BOOL IsValidReference( ScRange& rRef ) const;
147 //UNUSED2009-05 BOOL IsRangeAtCursor( const ScAddress&, BOOL bStartOnly ) const;
148 BOOL IsRangeAtBlock( const ScRange& ) const;
150 void UpdateTabRef(SCTAB nOldTable, USHORT nFlag, SCTAB nNewTable);
151 void TransferTabRef( SCTAB nOldTab, SCTAB nNewTab );
153 void ValidateTabRefs();
155 void ReplaceRangeNamesInUse( const IndexMap& rMap );
157 static void MakeValidName( String& rName );
158 SC_DLLPUBLIC static BOOL IsNameValid( const String& rName, ScDocument* pDoc );
160 SC_DLLPUBLIC void SetMaxRow(SCROW nRow);
161 SCROW GetMaxRow() const;
162 SC_DLLPUBLIC void SetMaxCol(SCCOL nCol);
163 SCCOL GetMaxCol() const;
166 inline BOOL ScRangeData::HasType( RangeType nType ) const
168 return ( ( eType & nType ) == nType );
171 extern "C" int SAL_CALL ScRangeData_QsortNameCompare( const void*, const void* );
173 #if defined( ICC ) && defined( OS2 )
174 static int _Optlink ICCQsortNameCompare( const void* a, const void* b)
175 { return ScRangeData_QsortNameCompare(a,b); }
176 #endif
178 //------------------------------------------------------------------------
180 class ScRangeName : public ScSortedCollection
182 private:
183 ScDocument* pDoc;
184 USHORT nSharedMaxIndex;
186 using ScSortedCollection::Clone; // calcwarnings: shouldn't be used
188 public:
189 ScRangeName(USHORT nLim = 4, USHORT nDel = 4, BOOL bDup = FALSE,
190 ScDocument* pDocument = NULL) :
191 ScSortedCollection ( nLim, nDel, bDup ),
192 pDoc ( pDocument ),
193 nSharedMaxIndex ( 1 ) {} // darf nicht 0 sein!!
195 ScRangeName(const ScRangeName& rScRangeName, ScDocument* pDocument);
197 virtual ScDataObject* Clone(ScDocument* pDocP) const
198 { return new ScRangeName(*this, pDocP); }
199 ScRangeData* operator[]( const USHORT nIndex) const
200 { return (ScRangeData*)At(nIndex); }
201 virtual short Compare(ScDataObject* pKey1, ScDataObject* pKey2) const;
202 virtual BOOL IsEqual(ScDataObject* pKey1, ScDataObject* pKey2) const;
204 //UNUSED2009-05 ScRangeData* GetRangeAtCursor( const ScAddress&, BOOL bStartOnly ) const;
205 SC_DLLPUBLIC ScRangeData* GetRangeAtBlock( const ScRange& ) const;
207 SC_DLLPUBLIC BOOL SearchName( const String& rName, USHORT& rPos ) const;
208 // SearchNameUpper must be called with an upper-case search string
209 BOOL SearchNameUpper( const String& rUpperName, USHORT& rPos ) const;
210 void UpdateReference(UpdateRefMode eUpdateRefMode,
211 const ScRange& rRange,
212 SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
213 void UpdateTabRef(SCTAB nTable, USHORT nFlag, SCTAB nNewTable = 0);
214 void UpdateTranspose( const ScRange& rSource, const ScAddress& rDest );
215 void UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY );
216 virtual BOOL Insert(ScDataObject* pScDataObject);
217 SC_DLLPUBLIC ScRangeData* FindIndex(USHORT nIndex);
218 USHORT GetSharedMaxIndex() { return nSharedMaxIndex; }
219 void SetSharedMaxIndex(USHORT nInd) { nSharedMaxIndex = nInd; }
220 USHORT GetEntryIndex();
223 #endif