1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "namebuff.hxx"
22 #include "document.hxx"
23 #include "compiler.hxx"
24 #include "scextopt.hxx"
27 #include "tokstack.hxx"
28 #include "xltools.hxx"
33 sal_uInt32
StringHashEntry::MakeHashCode( const OUString
& r
)
36 const sal_Unicode
* pAkt
= r
.getStr();
37 sal_Unicode cAkt
= *pAkt
;
42 n
+= ( sal_uInt32
) cAkt
;
50 NameBuffer::~NameBuffer()
52 std::vector
<StringHashEntry
*>::iterator pIter
;
53 for ( pIter
= maHashes
.begin(); pIter
!= maHashes
.end(); ++pIter
)
57 //void NameBuffer::operator <<( const SpString &rNewString )
58 void NameBuffer::operator <<( const OUString
&rNewString
)
60 OSL_ENSURE( maHashes
.size() + nBase
< 0xFFFF,
61 "*NameBuffer::GetLastIndex(): Ich hab' die Nase voll!" );
63 maHashes
.push_back( new StringHashEntry( rNewString
) );
66 SharedFormulaBuffer::SharedFormulaBuffer( RootData
* pRD
) : ExcRoot(pRD
) {}
68 SharedFormulaBuffer::~SharedFormulaBuffer()
73 void SharedFormulaBuffer::Clear()
75 TokenArraysType::iterator it
= maTokenArrays
.begin(), itEnd
= maTokenArrays
.end();
76 for (; it
!= itEnd
; ++it
)
79 maTokenArrays
.clear();
82 void SharedFormulaBuffer::Store( const ScAddress
& rPos
, const ScTokenArray
& rArray
)
84 ScTokenArray
* pCode
= rArray
.Clone();
86 maTokenArrays
.insert(TokenArraysType::value_type(rPos
, pCode
));
89 const ScTokenArray
* SharedFormulaBuffer::Find( const ScAddress
& rRefPos
) const
91 TokenArraysType::const_iterator it
= maTokenArrays
.find(rRefPos
);
92 if (it
== maTokenArrays
.end())
98 sal_Int16
ExtSheetBuffer::Add( const OUString
& rFPAN
, const OUString
& rTN
, const bool bSWB
)
100 maEntries
.push_back( Cont( rFPAN
, rTN
, bSWB
) );
101 // return 1-based index of EXTERNSHEET
102 return static_cast< sal_Int16
>( maEntries
.size() );
105 bool ExtSheetBuffer::GetScTabIndex( sal_uInt16 nExcIndex
, sal_uInt16
& rScIndex
)
107 OSL_ENSURE( nExcIndex
,
108 "*ExtSheetBuffer::GetScTabIndex(): Sheet-Index == 0!" );
110 if ( !nExcIndex
|| nExcIndex
> maEntries
.size() )
113 Cont
* pCur
= &maEntries
[ nExcIndex
- 1 ];
114 sal_uInt16
& rTabNum
= pCur
->nTabNum
;
116 if( rTabNum
< 0xFFFD )
122 if( rTabNum
== 0xFFFF )
126 {// table is in the same workbook!
127 if( pExcRoot
->pIR
->GetDoc().GetTable( pCur
->aTab
, nNewTabNum
) )
129 rScIndex
= rTabNum
= static_cast<sal_uInt16
>(nNewTabNum
);
135 else if( pExcRoot
->pIR
->GetDocShell() )
136 {// table is 'really' external
137 if( pExcRoot
->pIR
->GetExtDocOptions().GetDocSettings().mnLinkCnt
== 0 )
139 OUString
aURL( ScGlobal::GetAbsDocName( pCur
->aFile
,
140 pExcRoot
->pIR
->GetDocShell() ) );
141 OUString
aTabName( ScGlobal::GetDocTabName( aURL
, pCur
->aTab
) );
142 if( pExcRoot
->pIR
->GetDoc().LinkExternalTab( nNewTabNum
, aTabName
, aURL
, pCur
->aTab
) )
144 rScIndex
= rTabNum
= static_cast<sal_uInt16
>(nNewTabNum
);
148 rTabNum
= 0xFFFE; // no table is created for now -> and likely
149 // will not be created later...
160 bool ExtSheetBuffer::IsLink( const sal_uInt16 nExcIndex
) const
162 OSL_ENSURE( nExcIndex
> 0, "*ExtSheetBuffer::IsLink(): Index has to be >0!" );
164 if (!nExcIndex
|| nExcIndex
> maEntries
.size() )
167 return maEntries
[ nExcIndex
-1 ].bLink
;
170 bool ExtSheetBuffer::GetLink( const sal_uInt16 nExcIndex
, OUString
& rAppl
, OUString
& rDoc
) const
172 OSL_ENSURE( nExcIndex
> 0, "*ExtSheetBuffer::GetLink(): Index has to be >0!" );
174 if (!nExcIndex
|| nExcIndex
> maEntries
.size() )
177 const Cont
&rRet
= maEntries
[ nExcIndex
-1 ];
185 void ExtSheetBuffer::Reset()
190 bool ExtName::IsDDE() const
192 return ( nFlags
& 0x0001 ) != 0;
195 bool ExtName::IsOLE() const
197 return ( nFlags
& 0x0002 ) != 0;
200 ExtNameBuff::ExtNameBuff( const XclImpRoot
& rRoot
) :
205 void ExtNameBuff::AddDDE( const OUString
& rName
, sal_Int16 nRefIdx
)
207 ExtName
aNew( rName
, 0x0001 );
208 maExtNames
[ nRefIdx
].push_back( aNew
);
211 void ExtNameBuff::AddOLE( const OUString
& rName
, sal_Int16 nRefIdx
, sal_uInt32 nStorageId
)
213 ExtName
aNew( rName
, 0x0002 );
214 aNew
.nStorageId
= nStorageId
;
215 maExtNames
[ nRefIdx
].push_back( aNew
);
218 void ExtNameBuff::AddName( const OUString
& rName
, sal_Int16 nRefIdx
)
220 ExtName
aNew( GetScAddInName( rName
), 0x0004 );
221 maExtNames
[ nRefIdx
].push_back( aNew
);
224 const ExtName
* ExtNameBuff::GetNameByIndex( sal_Int16 nRefIdx
, sal_uInt16 nNameIdx
) const
226 OSL_ENSURE( nNameIdx
> 0, "ExtNameBuff::GetNameByIndex() - invalid name index" );
227 ExtNameMap::const_iterator aIt
= maExtNames
.find( nRefIdx
);
228 return ((aIt
!= maExtNames
.end()) && (0 < nNameIdx
) && (nNameIdx
<= aIt
->second
.size())) ? &aIt
->second
[ nNameIdx
- 1 ] : 0;
231 void ExtNameBuff::Reset()
236 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */