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