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>
24 #include <scextopt.hxx>
25 #include <tokenarray.hxx>
30 #include <osl/diagnose.h>
32 sal_uInt32
StringHashEntry::MakeHashCode( const OUString
& r
)
35 const sal_Unicode
* pCurrent
= r
.getStr();
36 sal_Unicode cCurrent
= *pCurrent
;
41 n
+= static_cast<sal_uInt32
>(cCurrent
);
49 SharedFormulaBuffer::SharedFormulaBuffer(RootData
* pRD
)
54 SharedFormulaBuffer::~SharedFormulaBuffer()
59 void SharedFormulaBuffer::Clear()
61 maTokenArrays
.clear();
64 void SharedFormulaBuffer::Store( const ScAddress
& rPos
, const ScTokenArray
& rArray
)
66 ScTokenArray
aCode(rArray
.CloneValue());
68 maTokenArrays
.emplace(rPos
, std::move(aCode
));
71 const ScTokenArray
* SharedFormulaBuffer::Find( const ScAddress
& rRefPos
) const
73 TokenArraysType::const_iterator it
= maTokenArrays
.find(rRefPos
);
74 if (it
== maTokenArrays
.end())
80 sal_Int16
ExtSheetBuffer::Add( const OUString
& rFPAN
, const OUString
& rTN
, const bool bSWB
)
82 maEntries
.emplace_back( rFPAN
, rTN
, bSWB
);
83 // return 1-based index of EXTERNSHEET
84 return static_cast< sal_Int16
>( maEntries
.size() );
87 bool ExtSheetBuffer::GetScTabIndex( sal_uInt16 nExcIndex
, sal_uInt16
& rScIndex
)
89 OSL_ENSURE( nExcIndex
,
90 "*ExtSheetBuffer::GetScTabIndex(): Sheet-Index == 0!" );
92 if ( !nExcIndex
|| nExcIndex
> maEntries
.size() )
95 Cont
* pCur
= &maEntries
[ nExcIndex
- 1 ];
96 sal_uInt16
& rTabNum
= pCur
->nTabNum
;
98 if( rTabNum
< 0xFFFD )
104 if( rTabNum
== 0xFFFF )
108 {// table is in the same workbook!
109 if( pExcRoot
->pIR
->GetDoc().GetTable( pCur
->aTab
, nNewTabNum
) )
111 rScIndex
= rTabNum
= static_cast<sal_uInt16
>(nNewTabNum
);
117 else if( pExcRoot
->pIR
->GetDocShell() )
118 {// table is 'really' external
119 if( pExcRoot
->pIR
->GetExtDocOptions().GetDocSettings().mnLinkCnt
== 0 )
121 OUString
aURL( ScGlobal::GetAbsDocName( pCur
->aFile
,
122 pExcRoot
->pIR
->GetDocShell() ) );
123 OUString
aTabName( ScGlobal::GetDocTabName( aURL
, pCur
->aTab
) );
124 if( pExcRoot
->pIR
->GetDoc().LinkExternalTab( nNewTabNum
, aTabName
, aURL
, pCur
->aTab
) )
126 rScIndex
= rTabNum
= static_cast<sal_uInt16
>(nNewTabNum
);
130 rTabNum
= 0xFFFE; // no table is created for now -> and likely
131 // will not be created later...
142 void ExtSheetBuffer::Reset()
147 bool ExtName::IsOLE() const
149 return ( nFlags
& 0x0002 ) != 0;
152 ExtNameBuff::ExtNameBuff( const XclImpRoot
& rRoot
) :
157 void ExtNameBuff::AddDDE( sal_Int16 nRefIdx
)
159 ExtName
aNew( 0x0001 );
160 maExtNames
[ nRefIdx
].push_back( aNew
);
163 void ExtNameBuff::AddOLE( sal_Int16 nRefIdx
, sal_uInt32 nStorageId
)
165 ExtName
aNew( 0x0002 );
166 aNew
.nStorageId
= nStorageId
;
167 maExtNames
[ nRefIdx
].push_back( aNew
);
170 void ExtNameBuff::AddName( sal_Int16 nRefIdx
)
172 ExtName
aNew( 0x0004 );
173 maExtNames
[ nRefIdx
].push_back( aNew
);
176 const ExtName
* ExtNameBuff::GetNameByIndex( sal_Int16 nRefIdx
, sal_uInt16 nNameIdx
) const
178 OSL_ENSURE( nNameIdx
> 0, "ExtNameBuff::GetNameByIndex() - invalid name index" );
179 ExtNameMap::const_iterator aIt
= maExtNames
.find( nRefIdx
);
180 return ((aIt
!= maExtNames
.end()) && (0 < nNameIdx
) && (nNameIdx
<= aIt
->second
.size())) ? &aIt
->second
[ nNameIdx
- 1 ] : nullptr;
183 void ExtNameBuff::Reset()
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */