xref: /trunk/main/sc/inc/rangenam.hxx (revision 38d50f7b)
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 
81 	friend class ScRangeName;
82 	ScRangeData( sal_uInt16 nIndex );
83 public:
84     typedef ::std::map<sal_uInt16, sal_uInt16> IndexMap;
85 
86 	SC_DLLPUBLIC				ScRangeData( ScDocument* pDoc,
87 								 const String& rName,
88 								 const String& rSymbol,
89                                  const ScAddress& rAdr = ScAddress(),
90 								 RangeType nType = RT_NAME,
91                                  const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT );
92 	SC_DLLPUBLIC				ScRangeData( ScDocument* pDoc,
93 								 const String& rName,
94 								 const ScTokenArray& rArr,
95                                  const ScAddress& rAdr = ScAddress(),
96 								 RangeType nType = RT_NAME );
97 	SC_DLLPUBLIC				ScRangeData( ScDocument* pDoc,
98 								 const String& rName,
99 								 const ScAddress& rTarget );
100 								// rTarget ist ABSPOS Sprungmarke
101 					ScRangeData(const ScRangeData& rScRangeData);
102 
103     SC_DLLPUBLIC virtual        ~ScRangeData();
104 
105 
106 	virtual	ScDataObject* Clone() const;
107 
108 	sal_Bool			operator== (const ScRangeData& rData) const;
109 
110 	void			GetName( String& rName ) const	{ rName = aName; }
111 	const String&	GetName( void ) const			{ return aName; }
112 	const String&   GetUpperName( void ) const      { return aUpperName; }
113 	ScAddress 		GetPos() const					{ return aPos; }
114 	// Der Index muss eindeutig sein. Ist er 0, wird ein neuer Index vergeben
115 	void            SetIndex( sal_uInt16 nInd )         { nIndex = nInd; }
116 	sal_uInt16    GetIndex() const                { return nIndex; }
117 	ScTokenArray*	GetCode()						{ return pCode; }
118 	sal_uInt16			GetErrCode();
119 	sal_Bool			HasReferences() const;
120 	void			SetDocument( ScDocument* pDocument){ pDoc = pDocument; }
121 	ScDocument*		GetDocument() const				{ return pDoc; }
122 	void			SetType( RangeType nType )		{ eType = nType; }
123 	void			AddType( RangeType nType )		{ eType = eType|nType; }
124 	RangeType		GetType() const					{ return eType; }
125 	sal_Bool			HasType( RangeType nType ) const;
126 	SC_DLLPUBLIC void 			GetSymbol( String& rSymbol, const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT ) const;
127 	void 			UpdateSymbol( rtl::OUStringBuffer& rBuffer, const ScAddress&,
128 									const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT );
129 	void 			UpdateReference( UpdateRefMode eUpdateRefMode,
130 							 const ScRange& r,
131 							 SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
132 	sal_Bool			IsModified() const				{ return bModified; }
133 
134 	SC_DLLPUBLIC void			GuessPosition();
135 
136 	void			UpdateTranspose( const ScRange& rSource, const ScAddress& rDest );
137 	void			UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY );
138 
139 	SC_DLLPUBLIC sal_Bool			IsReference( ScRange& rRef ) const;
140 	sal_Bool			IsReference( ScRange& rRef, const ScAddress& rPos ) const;
141 	sal_Bool			IsValidReference( ScRange& rRef ) const;
142 
143 //UNUSED2009-05 sal_Bool			IsRangeAtCursor( const ScAddress&, sal_Bool bStartOnly ) const;
144 	sal_Bool			IsRangeAtBlock( const ScRange& ) const;
145 
146 	void 			UpdateTabRef(SCTAB nOldTable, sal_uInt16 nFlag, SCTAB nNewTable);
147 	void			TransferTabRef( SCTAB nOldTab, SCTAB nNewTab );
148 
149 	void			ValidateTabRefs();
150 
151     void            ReplaceRangeNamesInUse( const IndexMap& rMap );
152 
153 	static void		MakeValidName( String& rName );
154 	SC_DLLPUBLIC static sal_Bool		IsNameValid( const String& rName, ScDocument* pDoc );
155 
156     SC_DLLPUBLIC void SetMaxRow(SCROW nRow);
157     SCROW GetMaxRow() const;
158     SC_DLLPUBLIC void SetMaxCol(SCCOL nCol);
159     SCCOL GetMaxCol() const;
160 };
161 
162 inline sal_Bool ScRangeData::HasType( RangeType nType ) const
163 {
164 	return ( ( eType & nType ) == nType );
165 }
166 
167 extern "C" int SAL_CALL ScRangeData_QsortNameCompare( const void*, const void* );
168 
169 #if defined( ICC ) && defined( OS2 )
170 	static int _Optlink	 ICCQsortNameCompare( const void* a, const void* b)
171 							{ return ScRangeData_QsortNameCompare(a,b); }
172 #endif
173 
174 //------------------------------------------------------------------------
175 
176 class ScRangeName : public ScSortedCollection
177 {
178 private:
179 	ScDocument* pDoc;
180 	sal_uInt16 nSharedMaxIndex;
181 
182     using ScSortedCollection::Clone;    // calcwarnings: shouldn't be used
183 
184 public:
185 	ScRangeName(sal_uInt16 nLim = 4, sal_uInt16 nDel = 4, sal_Bool bDup = sal_False,
186 				ScDocument* pDocument = NULL) :
187 		ScSortedCollection	( nLim, nDel, bDup ),
188 		pDoc				( pDocument ),
189 		nSharedMaxIndex		( 1 ) {}			// darf nicht 0 sein!!
190 
191 	ScRangeName(const ScRangeName& rScRangeName, ScDocument* pDocument);
192 
193     virtual	ScDataObject*     Clone(ScDocument* pDocP) const
194                              { return new ScRangeName(*this, pDocP); }
195 	ScRangeData*			operator[]( const sal_uInt16 nIndex) const
196 							 { return (ScRangeData*)At(nIndex); }
197 	virtual	short			Compare(ScDataObject* pKey1, ScDataObject* pKey2) const;
198 	virtual	sal_Bool			IsEqual(ScDataObject* pKey1, ScDataObject* pKey2) const;
199 
200 //UNUSED2009-05 ScRangeData*			GetRangeAtCursor( const ScAddress&, sal_Bool bStartOnly ) const;
201 	SC_DLLPUBLIC ScRangeData*			GetRangeAtBlock( const ScRange& ) const;
202 
203 	SC_DLLPUBLIC sal_Bool					SearchName( const String& rName, sal_uInt16& rPos ) const;
204                             // SearchNameUpper must be called with an upper-case search string
205 	sal_Bool					SearchNameUpper( const String& rUpperName, sal_uInt16& rPos ) const;
206 	void					UpdateReference(UpdateRefMode eUpdateRefMode,
207 								const ScRange& rRange,
208 								SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
209 	void 					UpdateTabRef(SCTAB nTable, sal_uInt16 nFlag, SCTAB nNewTable = 0);
210 	void					UpdateTranspose( const ScRange& rSource, const ScAddress& rDest );
211 	void					UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY );
212 	virtual	sal_Bool			Insert(ScDataObject* pScDataObject);
213 	SC_DLLPUBLIC ScRangeData* 			FindIndex(sal_uInt16 nIndex);
214 	sal_uInt16 					GetSharedMaxIndex()				{ return nSharedMaxIndex; }
215 	void 					SetSharedMaxIndex(sal_uInt16 nInd)	{ nSharedMaxIndex = nInd; }
216 	sal_uInt16 					GetEntryIndex();
217 };
218 
219 #endif
220 
221