xref: /AOO41X/main/sc/inc/rangenam.hxx (revision dffa72ded5962569065f7bed47aa44fcb9f744f1)
138d50f7bSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
338d50f7bSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
438d50f7bSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
538d50f7bSAndrew Rist  * distributed with this work for additional information
638d50f7bSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
738d50f7bSAndrew Rist  * to you under the Apache License, Version 2.0 (the
838d50f7bSAndrew Rist  * "License"); you may not use this file except in compliance
938d50f7bSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
1138d50f7bSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
1338d50f7bSAndrew Rist  * Unless required by applicable law or agreed to in writing,
1438d50f7bSAndrew Rist  * software distributed under the License is distributed on an
1538d50f7bSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1638d50f7bSAndrew Rist  * KIND, either express or implied.  See the License for the
1738d50f7bSAndrew Rist  * specific language governing permissions and limitations
1838d50f7bSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
2038d50f7bSAndrew Rist  *************************************************************/
2138d50f7bSAndrew Rist 
2238d50f7bSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef SC_RANGENAM_HXX
25cdf0e10cSrcweir #define SC_RANGENAM_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "global.hxx" // -> enum UpdateRefMode
28cdf0e10cSrcweir #include "address.hxx"
29cdf0e10cSrcweir #include "collect.hxx"
30cdf0e10cSrcweir #include "formula/grammar.hxx"
31cdf0e10cSrcweir #include "scdllapi.h"
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <map>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir //------------------------------------------------------------------------
36cdf0e10cSrcweir 
37cdf0e10cSrcweir class ScDocument;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir namespace rtl {
40cdf0e10cSrcweir 	class OUStringBuffer;
41cdf0e10cSrcweir }
42cdf0e10cSrcweir 
43cdf0e10cSrcweir 
44cdf0e10cSrcweir //------------------------------------------------------------------------
45cdf0e10cSrcweir 
46cdf0e10cSrcweir typedef sal_uInt16 RangeType;
47cdf0e10cSrcweir 
48cdf0e10cSrcweir #define RT_NAME				((RangeType)0x0000)
49cdf0e10cSrcweir #define RT_DATABASE			((RangeType)0x0001)
50cdf0e10cSrcweir #define RT_CRITERIA			((RangeType)0x0002)
51cdf0e10cSrcweir #define RT_PRINTAREA		((RangeType)0x0004)
52cdf0e10cSrcweir #define RT_COLHEADER		((RangeType)0x0008)
53cdf0e10cSrcweir #define RT_ROWHEADER		((RangeType)0x0010)
54cdf0e10cSrcweir #define RT_ABSAREA			((RangeType)0x0020)
55cdf0e10cSrcweir #define RT_REFAREA			((RangeType)0x0040)
56cdf0e10cSrcweir #define RT_ABSPOS			((RangeType)0x0080)
57cdf0e10cSrcweir #define RT_SHARED			((RangeType)0x0100)
58cdf0e10cSrcweir #define RT_SHAREDMOD		((RangeType)0x0200)
59cdf0e10cSrcweir 
60cdf0e10cSrcweir //------------------------------------------------------------------------
61cdf0e10cSrcweir 
62cdf0e10cSrcweir class ScTokenArray;
63cdf0e10cSrcweir 
64cdf0e10cSrcweir class ScRangeData : public ScDataObject
65cdf0e10cSrcweir {
66cdf0e10cSrcweir private:
67cdf0e10cSrcweir 	String			aName;
68cdf0e10cSrcweir     String          aUpperName;         // #i62977# for faster searching (aName is never modified after ctor)
69cdf0e10cSrcweir 	ScTokenArray*	pCode;
70cdf0e10cSrcweir 	ScAddress   	aPos;
71cdf0e10cSrcweir 	RangeType		eType;
72cdf0e10cSrcweir 	ScDocument* 	pDoc;
73cdf0e10cSrcweir 	sal_uInt16			nIndex;
74cdf0e10cSrcweir 	sal_Bool			bModified;			// wird bei UpdateReference gesetzt/geloescht
75cdf0e10cSrcweir 
76cdf0e10cSrcweir     // max row and column to use for wrapping of references.  If -1 use the
77cdf0e10cSrcweir     // application's default.
78cdf0e10cSrcweir     SCROW           mnMaxRow;
79cdf0e10cSrcweir     SCCOL           mnMaxCol;
80*dffa72deSWang Lei 	SCTAB		aRangeNameScope;		// table index reference as range name scope. 0 -  sheet1, 1- sheet2.  MAXTABCOUNT - Global
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 	friend class ScRangeName;
83cdf0e10cSrcweir 	ScRangeData( sal_uInt16 nIndex );
84cdf0e10cSrcweir public:
85cdf0e10cSrcweir     typedef ::std::map<sal_uInt16, sal_uInt16> IndexMap;
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 	SC_DLLPUBLIC				ScRangeData( ScDocument* pDoc,
88cdf0e10cSrcweir 								 const String& rName,
89cdf0e10cSrcweir 								 const String& rSymbol,
90cdf0e10cSrcweir                                  const ScAddress& rAdr = ScAddress(),
91cdf0e10cSrcweir 								 RangeType nType = RT_NAME,
92cdf0e10cSrcweir                                  const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT );
93cdf0e10cSrcweir 	SC_DLLPUBLIC				ScRangeData( ScDocument* pDoc,
94cdf0e10cSrcweir 								 const String& rName,
95cdf0e10cSrcweir 								 const ScTokenArray& rArr,
96cdf0e10cSrcweir                                  const ScAddress& rAdr = ScAddress(),
97cdf0e10cSrcweir 								 RangeType nType = RT_NAME );
98cdf0e10cSrcweir 	SC_DLLPUBLIC				ScRangeData( ScDocument* pDoc,
99cdf0e10cSrcweir 								 const String& rName,
100cdf0e10cSrcweir 								 const ScAddress& rTarget );
101cdf0e10cSrcweir 								// rTarget ist ABSPOS Sprungmarke
102cdf0e10cSrcweir 					ScRangeData(const ScRangeData& rScRangeData);
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     SC_DLLPUBLIC virtual        ~ScRangeData();
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 	virtual	ScDataObject* Clone() const;
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 	sal_Bool			operator== (const ScRangeData& rData) const;
110cdf0e10cSrcweir 
GetName(String & rName) const111cdf0e10cSrcweir 	void			GetName( String& rName ) const	{ rName = aName; }
GetName(void) const112cdf0e10cSrcweir 	const String&	GetName( void ) const			{ return aName; }
GetUpperName(void) const113cdf0e10cSrcweir 	const String&   GetUpperName( void ) const      { return aUpperName; }
114*dffa72deSWang Lei 	SC_DLLPUBLIC  bool			SetRangeScope( SCTAB Scope );	// 0 - sheet1, 1 - sheet2, MAXTABCOUNT - global
GetRangeScope() const115*dffa72deSWang Lei 	SCTAB			GetRangeScope() const { return aRangeNameScope; }
116*dffa72deSWang Lei         String	GetScopeSheetName( void ) const;
GetPos() const117cdf0e10cSrcweir 	ScAddress 		GetPos() const					{ return aPos; }
118cdf0e10cSrcweir 	// Der Index muss eindeutig sein. Ist er 0, wird ein neuer Index vergeben
SetIndex(sal_uInt16 nInd)119cdf0e10cSrcweir 	void            SetIndex( sal_uInt16 nInd )         { nIndex = nInd; }
GetIndex() const120cdf0e10cSrcweir 	sal_uInt16    GetIndex() const                { return nIndex; }
GetCode()121cdf0e10cSrcweir 	ScTokenArray*	GetCode()						{ return pCode; }
122cdf0e10cSrcweir 	sal_uInt16			GetErrCode();
123cdf0e10cSrcweir 	sal_Bool			HasReferences() const;
SetDocument(ScDocument * pDocument)124cdf0e10cSrcweir 	void			SetDocument( ScDocument* pDocument){ pDoc = pDocument; }
GetDocument() const125cdf0e10cSrcweir 	ScDocument*		GetDocument() const				{ return pDoc; }
SetType(RangeType nType)126cdf0e10cSrcweir 	void			SetType( RangeType nType )		{ eType = nType; }
AddType(RangeType nType)127cdf0e10cSrcweir 	void			AddType( RangeType nType )		{ eType = eType|nType; }
GetType() const128cdf0e10cSrcweir 	RangeType		GetType() const					{ return eType; }
129cdf0e10cSrcweir 	sal_Bool			HasType( RangeType nType ) const;
130cdf0e10cSrcweir 	SC_DLLPUBLIC void 			GetSymbol( String& rSymbol, const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT ) const;
131cdf0e10cSrcweir 	void 			UpdateSymbol( rtl::OUStringBuffer& rBuffer, const ScAddress&,
132cdf0e10cSrcweir 									const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT );
133cdf0e10cSrcweir 	void 			UpdateReference( UpdateRefMode eUpdateRefMode,
134cdf0e10cSrcweir 							 const ScRange& r,
135cdf0e10cSrcweir 							 SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
IsModified() const136cdf0e10cSrcweir 	sal_Bool			IsModified() const				{ return bModified; }
137cdf0e10cSrcweir 
138cdf0e10cSrcweir 	SC_DLLPUBLIC void			GuessPosition();
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 	void			UpdateTranspose( const ScRange& rSource, const ScAddress& rDest );
141cdf0e10cSrcweir 	void			UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY );
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 	SC_DLLPUBLIC sal_Bool			IsReference( ScRange& rRef ) const;
144cdf0e10cSrcweir 	sal_Bool			IsReference( ScRange& rRef, const ScAddress& rPos ) const;
145cdf0e10cSrcweir 	sal_Bool			IsValidReference( ScRange& rRef ) const;
146cdf0e10cSrcweir 
147cdf0e10cSrcweir //UNUSED2009-05 sal_Bool			IsRangeAtCursor( const ScAddress&, sal_Bool bStartOnly ) const;
148cdf0e10cSrcweir 	sal_Bool			IsRangeAtBlock( const ScRange& ) const;
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 	void 			UpdateTabRef(SCTAB nOldTable, sal_uInt16 nFlag, SCTAB nNewTable);
151cdf0e10cSrcweir 	void			TransferTabRef( SCTAB nOldTab, SCTAB nNewTab );
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 	void			ValidateTabRefs();
154cdf0e10cSrcweir 
155cdf0e10cSrcweir     void            ReplaceRangeNamesInUse( const IndexMap& rMap );
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 	static void		MakeValidName( String& rName );
158cdf0e10cSrcweir 	SC_DLLPUBLIC static sal_Bool		IsNameValid( const String& rName, ScDocument* pDoc );
159cdf0e10cSrcweir 
160cdf0e10cSrcweir     SC_DLLPUBLIC void SetMaxRow(SCROW nRow);
161cdf0e10cSrcweir     SCROW GetMaxRow() const;
162cdf0e10cSrcweir     SC_DLLPUBLIC void SetMaxCol(SCCOL nCol);
163cdf0e10cSrcweir     SCCOL GetMaxCol() const;
164cdf0e10cSrcweir };
165cdf0e10cSrcweir 
HasType(RangeType nType) const166cdf0e10cSrcweir inline sal_Bool ScRangeData::HasType( RangeType nType ) const
167cdf0e10cSrcweir {
168cdf0e10cSrcweir 	return ( ( eType & nType ) == nType );
169cdf0e10cSrcweir }
170cdf0e10cSrcweir 
171cdf0e10cSrcweir extern "C" int SAL_CALL ScRangeData_QsortNameCompare( const void*, const void* );
172cdf0e10cSrcweir 
173cdf0e10cSrcweir #if defined( ICC ) && defined( OS2 )
ICCQsortNameCompare(const void * a,const void * b)174cdf0e10cSrcweir 	static int _Optlink	 ICCQsortNameCompare( const void* a, const void* b)
175cdf0e10cSrcweir 							{ return ScRangeData_QsortNameCompare(a,b); }
176cdf0e10cSrcweir #endif
177cdf0e10cSrcweir 
178cdf0e10cSrcweir //------------------------------------------------------------------------
179cdf0e10cSrcweir 
180cdf0e10cSrcweir class ScRangeName : public ScSortedCollection
181cdf0e10cSrcweir {
182cdf0e10cSrcweir private:
183cdf0e10cSrcweir 	ScDocument* pDoc;
184cdf0e10cSrcweir 	sal_uInt16 nSharedMaxIndex;
185cdf0e10cSrcweir 
186cdf0e10cSrcweir     using ScSortedCollection::Clone;    // calcwarnings: shouldn't be used
187cdf0e10cSrcweir 
188cdf0e10cSrcweir public:
ScRangeName(sal_uInt16 nLim=4,sal_uInt16 nDel=4,sal_Bool bDup=sal_False,ScDocument * pDocument=NULL)189cdf0e10cSrcweir 	ScRangeName(sal_uInt16 nLim = 4, sal_uInt16 nDel = 4, sal_Bool bDup = sal_False,
190cdf0e10cSrcweir 				ScDocument* pDocument = NULL) :
191cdf0e10cSrcweir 		ScSortedCollection	( nLim, nDel, bDup ),
192cdf0e10cSrcweir 		pDoc				( pDocument ),
193cdf0e10cSrcweir 		nSharedMaxIndex		( 1 ) {}			// darf nicht 0 sein!!
194cdf0e10cSrcweir 
195cdf0e10cSrcweir 	ScRangeName(const ScRangeName& rScRangeName, ScDocument* pDocument);
196cdf0e10cSrcweir 
Clone(ScDocument * pDocP) const197cdf0e10cSrcweir     virtual	ScDataObject*     Clone(ScDocument* pDocP) const
198cdf0e10cSrcweir                              { return new ScRangeName(*this, pDocP); }
operator [](const sal_uInt16 nIndex) const199cdf0e10cSrcweir 	ScRangeData*			operator[]( const sal_uInt16 nIndex) const
200cdf0e10cSrcweir 							 { return (ScRangeData*)At(nIndex); }
201cdf0e10cSrcweir 	virtual	short			Compare(ScDataObject* pKey1, ScDataObject* pKey2) const;
202cdf0e10cSrcweir 	virtual	sal_Bool			IsEqual(ScDataObject* pKey1, ScDataObject* pKey2) const;
203cdf0e10cSrcweir 
204cdf0e10cSrcweir //UNUSED2009-05 ScRangeData*			GetRangeAtCursor( const ScAddress&, sal_Bool bStartOnly ) const;
205cdf0e10cSrcweir 	SC_DLLPUBLIC ScRangeData*			GetRangeAtBlock( const ScRange& ) const;
206cdf0e10cSrcweir 
207*dffa72deSWang Lei 	SC_DLLPUBLIC bool					SearchName( const String& rName, sal_uInt16& rPos, SCTAB Scope=MAXTABCOUNT) const;
208cdf0e10cSrcweir                             // SearchNameUpper must be called with an upper-case search string
209*dffa72deSWang Lei 	bool					SearchNameUpper( const String& rUpperName, sal_uInt16& rPos, SCTAB Scope=MAXTABCOUNT ) const;
210*dffa72deSWang Lei 	/* added by  for scope support */
211*dffa72deSWang Lei 	bool				HasRangeinSheetScope( SCTAB Scope );
212*dffa72deSWang Lei 	bool				RemoveRangeinScope(SCTAB Scope);
213*dffa72deSWang Lei 	bool				CopyRangeinScope(SCTAB oldScope, SCTAB newScope);
214*dffa72deSWang Lei 	/* end add */
215cdf0e10cSrcweir 	void					UpdateReference(UpdateRefMode eUpdateRefMode,
216cdf0e10cSrcweir 								const ScRange& rRange,
217cdf0e10cSrcweir 								SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
218cdf0e10cSrcweir 	void 					UpdateTabRef(SCTAB nTable, sal_uInt16 nFlag, SCTAB nNewTable = 0);
219cdf0e10cSrcweir 	void					UpdateTranspose( const ScRange& rSource, const ScAddress& rDest );
220cdf0e10cSrcweir 	void					UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY );
221cdf0e10cSrcweir 	virtual	sal_Bool			Insert(ScDataObject* pScDataObject);
222cdf0e10cSrcweir 	SC_DLLPUBLIC ScRangeData* 			FindIndex(sal_uInt16 nIndex);
GetSharedMaxIndex()223cdf0e10cSrcweir 	sal_uInt16 					GetSharedMaxIndex()				{ return nSharedMaxIndex; }
SetSharedMaxIndex(sal_uInt16 nInd)224cdf0e10cSrcweir 	void 					SetSharedMaxIndex(sal_uInt16 nInd)	{ nSharedMaxIndex = nInd; }
225cdf0e10cSrcweir 	sal_uInt16 					GetEntryIndex();
226cdf0e10cSrcweir };
227cdf0e10cSrcweir 
228cdf0e10cSrcweir #endif
229cdf0e10cSrcweir 
230