1*38d50f7bSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*38d50f7bSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*38d50f7bSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*38d50f7bSAndrew Rist * distributed with this work for additional information
6*38d50f7bSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*38d50f7bSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*38d50f7bSAndrew Rist * "License"); you may not use this file except in compliance
9*38d50f7bSAndrew Rist * with the License. You may obtain a copy of the License at
10*38d50f7bSAndrew Rist *
11*38d50f7bSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*38d50f7bSAndrew Rist *
13*38d50f7bSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*38d50f7bSAndrew Rist * software distributed under the License is distributed on an
15*38d50f7bSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*38d50f7bSAndrew Rist * KIND, either express or implied. See the License for the
17*38d50f7bSAndrew Rist * specific language governing permissions and limitations
18*38d50f7bSAndrew Rist * under the License.
19*38d50f7bSAndrew Rist *
20*38d50f7bSAndrew Rist *************************************************************/
21*38d50f7bSAndrew Rist
22*38d50f7bSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #ifndef SC_NAMEBUFF_HXX
25cdf0e10cSrcweir #define SC_NAMEBUFF_HXX
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <tools/debug.hxx>
28cdf0e10cSrcweir #include <tools/string.hxx>
29cdf0e10cSrcweir #include "compiler.hxx"
30cdf0e10cSrcweir #include "root.hxx"
31cdf0e10cSrcweir #include "xiroot.hxx"
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include "rangenam.hxx"
34cdf0e10cSrcweir #include <hash_map>
35cdf0e10cSrcweir #include <list>
36cdf0e10cSrcweir
37cdf0e10cSrcweir class ScDocument;
38cdf0e10cSrcweir class ScTokenArray;
39cdf0e10cSrcweir class NameBuffer;
40cdf0e10cSrcweir
41cdf0e10cSrcweir
42cdf0e10cSrcweir
43cdf0e10cSrcweir
44cdf0e10cSrcweir class StringHashEntry
45cdf0e10cSrcweir {
46cdf0e10cSrcweir private:
47cdf0e10cSrcweir friend class NameBuffer;
48cdf0e10cSrcweir String aString;
49cdf0e10cSrcweir sal_uInt32 nHash;
50cdf0e10cSrcweir
51cdf0e10cSrcweir static sal_uInt32 MakeHashCode( const String& );
52cdf0e10cSrcweir public:
53cdf0e10cSrcweir inline StringHashEntry( const String& );
54cdf0e10cSrcweir inline StringHashEntry( void );
55cdf0e10cSrcweir inline void operator =( const sal_Char* );
56cdf0e10cSrcweir inline void operator =( const String& );
57cdf0e10cSrcweir inline void operator =( const StringHashEntry& );
58cdf0e10cSrcweir inline sal_Bool operator ==( const StringHashEntry& ) const;
59cdf0e10cSrcweir };
60cdf0e10cSrcweir
61cdf0e10cSrcweir
StringHashEntry(void)62cdf0e10cSrcweir inline StringHashEntry::StringHashEntry( void )
63cdf0e10cSrcweir {
64cdf0e10cSrcweir }
65cdf0e10cSrcweir
66cdf0e10cSrcweir
StringHashEntry(const String & r)67cdf0e10cSrcweir inline StringHashEntry::StringHashEntry( const String& r ) : aString( r )
68cdf0e10cSrcweir {
69cdf0e10cSrcweir nHash = MakeHashCode( r );
70cdf0e10cSrcweir }
71cdf0e10cSrcweir
72cdf0e10cSrcweir
operator =(const sal_Char * p)73cdf0e10cSrcweir inline void StringHashEntry::operator =( const sal_Char* p )
74cdf0e10cSrcweir {
75cdf0e10cSrcweir aString.AssignAscii( p );
76cdf0e10cSrcweir nHash = MakeHashCode( aString );
77cdf0e10cSrcweir }
78cdf0e10cSrcweir
79cdf0e10cSrcweir
operator =(const String & r)80cdf0e10cSrcweir inline void StringHashEntry::operator =( const String& r )
81cdf0e10cSrcweir {
82cdf0e10cSrcweir aString = r;
83cdf0e10cSrcweir nHash = MakeHashCode( r );
84cdf0e10cSrcweir }
85cdf0e10cSrcweir
86cdf0e10cSrcweir
operator =(const StringHashEntry & r)87cdf0e10cSrcweir inline void StringHashEntry::operator =( const StringHashEntry& r )
88cdf0e10cSrcweir {
89cdf0e10cSrcweir nHash = r.nHash;
90cdf0e10cSrcweir aString = r.aString;
91cdf0e10cSrcweir }
92cdf0e10cSrcweir
93cdf0e10cSrcweir
operator ==(const StringHashEntry & r) const94cdf0e10cSrcweir inline sal_Bool StringHashEntry::operator ==( const StringHashEntry& r ) const
95cdf0e10cSrcweir {
96cdf0e10cSrcweir return ( nHash == r.nHash && aString == r.aString );
97cdf0e10cSrcweir }
98cdf0e10cSrcweir
99cdf0e10cSrcweir
100cdf0e10cSrcweir
101cdf0e10cSrcweir class NameBuffer : private List, public ExcRoot
102cdf0e10cSrcweir {
103cdf0e10cSrcweir private:
104cdf0e10cSrcweir sal_uInt16 nBase; // Index-Basis
105cdf0e10cSrcweir public:
106cdf0e10cSrcweir // inline NameBuffer( void ); //#94039# prevent empty rootdata
107cdf0e10cSrcweir inline NameBuffer( RootData* );
108cdf0e10cSrcweir inline NameBuffer( RootData*, sal_uInt16 nNewBase );
109cdf0e10cSrcweir
110cdf0e10cSrcweir virtual ~NameBuffer();
111cdf0e10cSrcweir inline const String* Get( sal_uInt16 nIndex );
112cdf0e10cSrcweir inline sal_uInt16 GetLastIndex( void );
113cdf0e10cSrcweir inline void SetBase( sal_uInt16 nNewBase = 0 );
114cdf0e10cSrcweir void operator <<( const String& rNewString );
115cdf0e10cSrcweir };
116cdf0e10cSrcweir
117cdf0e10cSrcweir //#94039# prevent empty rootdata
118cdf0e10cSrcweir //inline NameBuffer::NameBuffer( void )
119cdf0e10cSrcweir //{
120cdf0e10cSrcweir // nBase = 0;
121cdf0e10cSrcweir //}
122cdf0e10cSrcweir
123cdf0e10cSrcweir
NameBuffer(RootData * p)124cdf0e10cSrcweir inline NameBuffer::NameBuffer( RootData* p ) : ExcRoot( p )
125cdf0e10cSrcweir {
126cdf0e10cSrcweir nBase = 0;
127cdf0e10cSrcweir }
128cdf0e10cSrcweir
129cdf0e10cSrcweir
NameBuffer(RootData * p,sal_uInt16 nNewBase)130cdf0e10cSrcweir inline NameBuffer::NameBuffer( RootData* p, sal_uInt16 nNewBase ) : ExcRoot( p )
131cdf0e10cSrcweir {
132cdf0e10cSrcweir nBase = nNewBase;
133cdf0e10cSrcweir }
134cdf0e10cSrcweir
135cdf0e10cSrcweir
Get(sal_uInt16 n)136cdf0e10cSrcweir inline const String* NameBuffer::Get( sal_uInt16 n )
137cdf0e10cSrcweir {
138cdf0e10cSrcweir if( n < nBase )
139cdf0e10cSrcweir return NULL;
140cdf0e10cSrcweir else
141cdf0e10cSrcweir {
142cdf0e10cSrcweir StringHashEntry* pObj = ( StringHashEntry* ) List::GetObject( n );
143cdf0e10cSrcweir
144cdf0e10cSrcweir if( pObj )
145cdf0e10cSrcweir return &pObj->aString;
146cdf0e10cSrcweir else
147cdf0e10cSrcweir return NULL;
148cdf0e10cSrcweir }
149cdf0e10cSrcweir }
150cdf0e10cSrcweir
151cdf0e10cSrcweir
GetLastIndex(void)152cdf0e10cSrcweir inline sal_uInt16 NameBuffer::GetLastIndex( void )
153cdf0e10cSrcweir {
154cdf0e10cSrcweir DBG_ASSERT( Count() + nBase <= 0xFFFF, "*NameBuffer::GetLastIndex(): Ich hab' die Nase voll!" );
155cdf0e10cSrcweir
156cdf0e10cSrcweir return ( sal_uInt16 ) ( Count() + nBase );
157cdf0e10cSrcweir }
158cdf0e10cSrcweir
159cdf0e10cSrcweir
SetBase(sal_uInt16 nNewBase)160cdf0e10cSrcweir inline void NameBuffer::SetBase( sal_uInt16 nNewBase )
161cdf0e10cSrcweir {
162cdf0e10cSrcweir nBase = nNewBase;
163cdf0e10cSrcweir }
164cdf0e10cSrcweir
165cdf0e10cSrcweir
166cdf0e10cSrcweir
167cdf0e10cSrcweir
168cdf0e10cSrcweir class ShrfmlaBuffer : public ExcRoot
169cdf0e10cSrcweir {
170cdf0e10cSrcweir struct ScAddressHashFunc : public std::unary_function< const ScAddress &, size_t >
171cdf0e10cSrcweir {
172cdf0e10cSrcweir size_t operator() (const ScAddress &addr) const;
173cdf0e10cSrcweir };
174cdf0e10cSrcweir typedef std::hash_map <ScAddress, sal_uInt16, ScAddressHashFunc> ShrfmlaHash;
175cdf0e10cSrcweir typedef std::list <ScRange> ShrfmlaList;
176cdf0e10cSrcweir
177cdf0e10cSrcweir ShrfmlaHash index_hash;
178cdf0e10cSrcweir ShrfmlaList index_list;
179cdf0e10cSrcweir size_t mnCurrIdx;
180cdf0e10cSrcweir
181cdf0e10cSrcweir public:
182cdf0e10cSrcweir ShrfmlaBuffer( RootData* pRD );
183cdf0e10cSrcweir virtual ~ShrfmlaBuffer();
184cdf0e10cSrcweir void Clear();
185cdf0e10cSrcweir void Store( const ScRange& rRange, const ScTokenArray& );
186cdf0e10cSrcweir sal_uInt16 Find (const ScAddress & rAddress ) const;
187cdf0e10cSrcweir
188cdf0e10cSrcweir static String CreateName( const ScRange& );
189cdf0e10cSrcweir };
190cdf0e10cSrcweir
191cdf0e10cSrcweir
192cdf0e10cSrcweir
193cdf0e10cSrcweir
194cdf0e10cSrcweir class RangeNameBufferWK3 : private List
195cdf0e10cSrcweir {
196cdf0e10cSrcweir private:
197cdf0e10cSrcweir struct ENTRY
198cdf0e10cSrcweir {
199cdf0e10cSrcweir StringHashEntry aStrHashEntry;
200cdf0e10cSrcweir ScComplexRefData aScComplexRefDataRel;
201cdf0e10cSrcweir String aScAbsName;
202cdf0e10cSrcweir sal_uInt16 nAbsInd; // == 0 -> noch keine Abs-Name!
203cdf0e10cSrcweir sal_uInt16 nRelInd;
204cdf0e10cSrcweir sal_Bool bSingleRef;
ENTRYRangeNameBufferWK3::ENTRY205cdf0e10cSrcweir ENTRY( const String& rName, const String& rScName, const ScComplexRefData& rCRD ) :
206cdf0e10cSrcweir aStrHashEntry( rName ),
207cdf0e10cSrcweir aScComplexRefDataRel( rCRD ),
208cdf0e10cSrcweir aScAbsName( rScName )
209cdf0e10cSrcweir {
210cdf0e10cSrcweir nAbsInd = 0;
211cdf0e10cSrcweir aScAbsName.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "_ABS" ) );
212cdf0e10cSrcweir }
213cdf0e10cSrcweir };
214cdf0e10cSrcweir
215cdf0e10cSrcweir ScTokenArray* pScTokenArray;
216cdf0e10cSrcweir sal_uInt16 nIntCount;
217cdf0e10cSrcweir public:
218cdf0e10cSrcweir RangeNameBufferWK3( void );
219cdf0e10cSrcweir virtual ~RangeNameBufferWK3();
220cdf0e10cSrcweir void Add( const String& rName, const ScComplexRefData& rCRD );
221cdf0e10cSrcweir inline void Add( const String& rName, const ScRange& aScRange );
222cdf0e10cSrcweir sal_Bool FindRel( const String& rRef, sal_uInt16& rIndex );
223cdf0e10cSrcweir sal_Bool FindAbs( const String& rRef, sal_uInt16& rIndex );
224cdf0e10cSrcweir };
225cdf0e10cSrcweir
226cdf0e10cSrcweir
Add(const String & rName,const ScRange & aScRange)227cdf0e10cSrcweir inline void RangeNameBufferWK3::Add( const String& rName, const ScRange& aScRange )
228cdf0e10cSrcweir {
229cdf0e10cSrcweir ScComplexRefData aCRD;
230cdf0e10cSrcweir ScSingleRefData* pSRD;
231cdf0e10cSrcweir const ScAddress* pScAddr;
232cdf0e10cSrcweir
233cdf0e10cSrcweir pSRD = &aCRD.Ref1;
234cdf0e10cSrcweir pScAddr = &aScRange.aStart;
235cdf0e10cSrcweir pSRD->SetFlag3D( sal_True );
236cdf0e10cSrcweir pSRD->nCol = pScAddr->Col();
237cdf0e10cSrcweir pSRD->nRow = pScAddr->Row();
238cdf0e10cSrcweir pSRD->nTab = pScAddr->Tab();
239cdf0e10cSrcweir
240cdf0e10cSrcweir // zunaechst ALLE Refs nur absolut
241cdf0e10cSrcweir pSRD->SetColRel( sal_False );
242cdf0e10cSrcweir pSRD->SetRowRel( sal_False );
243cdf0e10cSrcweir pSRD->SetTabRel( sal_False );
244cdf0e10cSrcweir
245cdf0e10cSrcweir pSRD = &aCRD.Ref2;
246cdf0e10cSrcweir pScAddr = &aScRange.aEnd;
247cdf0e10cSrcweir pSRD->SetFlag3D( sal_True );
248cdf0e10cSrcweir pSRD->nCol = pScAddr->Col();
249cdf0e10cSrcweir pSRD->nRow = pScAddr->Row();
250cdf0e10cSrcweir pSRD->nTab = pScAddr->Tab();
251cdf0e10cSrcweir
252cdf0e10cSrcweir // zunaechst ALLE Refs nur absolut
253cdf0e10cSrcweir pSRD->SetColRel( sal_False );
254cdf0e10cSrcweir pSRD->SetRowRel( sal_False );
255cdf0e10cSrcweir pSRD->SetTabRel( sal_False );
256cdf0e10cSrcweir
257cdf0e10cSrcweir Add( rName, aCRD );
258cdf0e10cSrcweir }
259cdf0e10cSrcweir
260cdf0e10cSrcweir
261cdf0e10cSrcweir
262cdf0e10cSrcweir
263cdf0e10cSrcweir class ExtSheetBuffer : private List, public ExcRoot
264cdf0e10cSrcweir {
265cdf0e10cSrcweir private:
266cdf0e10cSrcweir struct Cont
267cdf0e10cSrcweir {
268cdf0e10cSrcweir String aFile;
269cdf0e10cSrcweir String aTab;
270cdf0e10cSrcweir sal_uInt16 nTabNum; // 0xFFFF -> noch nicht angelegt
271cdf0e10cSrcweir // 0xFFFE -> versucht anzulegen, ging aber schief
272cdf0e10cSrcweir // 0xFFFD -> soll im selben Workbook sein, findet's aber nicht
273cdf0e10cSrcweir sal_Bool bSWB;
274cdf0e10cSrcweir sal_Bool bLink;
ContExtSheetBuffer::Cont275cdf0e10cSrcweir Cont( const String& rFilePathAndName, const String& rTabName ) :
276cdf0e10cSrcweir aFile( rFilePathAndName ),
277cdf0e10cSrcweir aTab( rTabName )
278cdf0e10cSrcweir {
279cdf0e10cSrcweir nTabNum = 0xFFFF; // -> Tabelle noch nicht erzeugt
280cdf0e10cSrcweir bSWB = bLink = sal_False;
281cdf0e10cSrcweir }
ContExtSheetBuffer::Cont282cdf0e10cSrcweir Cont( const String& rFilePathAndName, const String& rTabName,
283cdf0e10cSrcweir const sal_Bool bSameWB ) :
284cdf0e10cSrcweir aFile( rFilePathAndName ),
285cdf0e10cSrcweir aTab( rTabName )
286cdf0e10cSrcweir {
287cdf0e10cSrcweir nTabNum = 0xFFFF; // -> Tabelle noch nicht erzeugt
288cdf0e10cSrcweir bSWB = bSameWB;
289cdf0e10cSrcweir bLink = sal_False;
290cdf0e10cSrcweir }
291cdf0e10cSrcweir };
292cdf0e10cSrcweir public:
293cdf0e10cSrcweir inline ExtSheetBuffer( RootData* );
294cdf0e10cSrcweir virtual ~ExtSheetBuffer();
295cdf0e10cSrcweir
296cdf0e10cSrcweir sal_Int16 Add( const String& rFilePathAndName,
297cdf0e10cSrcweir const String& rTabName, const sal_Bool bSameWorkbook = sal_False );
298cdf0e10cSrcweir
299cdf0e10cSrcweir sal_Bool GetScTabIndex( sal_uInt16 nExcSheetIndex, sal_uInt16& rIn_LastTab_Out_ScIndex );
300cdf0e10cSrcweir sal_Bool IsLink( const sal_uInt16 nExcSheetIndex ) const;
301cdf0e10cSrcweir sal_Bool GetLink( const sal_uInt16 nExcSheetIndex, String &rAppl, String &rDoc ) const;
302cdf0e10cSrcweir
303cdf0e10cSrcweir void Reset( void );
304cdf0e10cSrcweir };
305cdf0e10cSrcweir
306cdf0e10cSrcweir
ExtSheetBuffer(RootData * p)307cdf0e10cSrcweir inline ExtSheetBuffer::ExtSheetBuffer( RootData* p ) : ExcRoot( p )
308cdf0e10cSrcweir {
309cdf0e10cSrcweir }
310cdf0e10cSrcweir
311cdf0e10cSrcweir
312cdf0e10cSrcweir
313cdf0e10cSrcweir
314cdf0e10cSrcweir struct ExtName
315cdf0e10cSrcweir {
316cdf0e10cSrcweir String aName;
317cdf0e10cSrcweir sal_uInt32 nStorageId;
318cdf0e10cSrcweir sal_uInt16 nFlags;
319cdf0e10cSrcweir
ExtNameExtName320cdf0e10cSrcweir inline ExtName( const String& r, sal_uInt16 n ) : aName( r ), nStorageId( 0 ), nFlags( n ) {}
321cdf0e10cSrcweir
322cdf0e10cSrcweir sal_Bool IsDDE( void ) const;
323cdf0e10cSrcweir sal_Bool IsOLE( void ) const;
324cdf0e10cSrcweir };
325cdf0e10cSrcweir
326cdf0e10cSrcweir
327cdf0e10cSrcweir
328cdf0e10cSrcweir
329cdf0e10cSrcweir class ExtNameBuff : protected XclImpRoot
330cdf0e10cSrcweir {
331cdf0e10cSrcweir public:
332cdf0e10cSrcweir explicit ExtNameBuff( const XclImpRoot& rRoot );
333cdf0e10cSrcweir
334cdf0e10cSrcweir void AddDDE( const String& rName, sal_Int16 nRefIdx );
335cdf0e10cSrcweir void AddOLE( const String& rName, sal_Int16 nRefIdx, sal_uInt32 nStorageId );
336cdf0e10cSrcweir void AddName( const String& rName, sal_Int16 nRefIdx );
337cdf0e10cSrcweir
338cdf0e10cSrcweir const ExtName* GetNameByIndex( sal_Int16 nRefIdx, sal_uInt16 nNameIdx ) const;
339cdf0e10cSrcweir
340cdf0e10cSrcweir void Reset();
341cdf0e10cSrcweir
342cdf0e10cSrcweir private:
343cdf0e10cSrcweir typedef ::std::vector< ExtName > ExtNameVec;
344cdf0e10cSrcweir typedef ::std::map< sal_Int16, ExtNameVec > ExtNameMap;
345cdf0e10cSrcweir
346cdf0e10cSrcweir ExtNameMap maExtNames;
347cdf0e10cSrcweir };
348cdf0e10cSrcweir
349cdf0e10cSrcweir
350cdf0e10cSrcweir #endif
351cdf0e10cSrcweir
352cdf0e10cSrcweir
353