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 <scextopt.hxx>
24 #include <tokenarray.hxx>
29 #include <osl/diagnose.h>
31 sal_uInt32
StringHashEntry::MakeHashCode( const OUString
& r
)
34 const sal_Unicode
* pCurrent
= r
.getStr();
35 sal_Unicode cCurrent
= *pCurrent
;
40 n
+= static_cast<sal_uInt32
>(cCurrent
);
48 SharedFormulaBuffer::SharedFormulaBuffer(RootData
* pRD
)
53 SharedFormulaBuffer::~SharedFormulaBuffer()
58 void SharedFormulaBuffer::Clear()
60 maTokenArrays
.clear();
63 void SharedFormulaBuffer::Store( const ScAddress
& rPos
, const ScTokenArray
& rArray
)
65 std::unique_ptr
<ScTokenArray
> xCode(rArray
.Clone());
67 maTokenArrays
.emplace(rPos
, std::move(xCode
));
70 const ScTokenArray
* SharedFormulaBuffer::Find( const ScAddress
& rRefPos
) const
72 TokenArraysType::const_iterator it
= maTokenArrays
.find(rRefPos
);
73 if (it
== maTokenArrays
.end())
76 return it
->second
.get();
79 sal_Int16
ExtSheetBuffer::Add( const OUString
& rFPAN
, const OUString
& rTN
, const bool bSWB
)
81 maEntries
.emplace_back( rFPAN
, rTN
, bSWB
);
82 // return 1-based index of EXTERNSHEET
83 return static_cast< sal_Int16
>( maEntries
.size() );
86 bool ExtSheetBuffer::GetScTabIndex( sal_uInt16 nExcIndex
, sal_uInt16
& rScIndex
)
88 OSL_ENSURE( nExcIndex
,
89 "*ExtSheetBuffer::GetScTabIndex(): Sheet-Index == 0!" );
91 if ( !nExcIndex
|| nExcIndex
> maEntries
.size() )
94 Cont
* pCur
= &maEntries
[ nExcIndex
- 1 ];
95 sal_uInt16
& rTabNum
= pCur
->nTabNum
;
97 if( rTabNum
< 0xFFFD )
103 if( rTabNum
== 0xFFFF )
107 {// table is in the same workbook!
108 if( pExcRoot
->pIR
->GetDoc().GetTable( pCur
->aTab
, nNewTabNum
) )
110 rScIndex
= rTabNum
= static_cast<sal_uInt16
>(nNewTabNum
);
116 else if( pExcRoot
->pIR
->GetDocShell() )
117 {// table is 'really' external
118 if( pExcRoot
->pIR
->GetExtDocOptions().GetDocSettings().mnLinkCnt
== 0 )
120 OUString
aURL( ScGlobal::GetAbsDocName( pCur
->aFile
,
121 pExcRoot
->pIR
->GetDocShell() ) );
122 OUString
aTabName( ScGlobal::GetDocTabName( aURL
, pCur
->aTab
) );
123 if( pExcRoot
->pIR
->GetDoc().LinkExternalTab( nNewTabNum
, aTabName
, aURL
, pCur
->aTab
) )
125 rScIndex
= rTabNum
= static_cast<sal_uInt16
>(nNewTabNum
);
129 rTabNum
= 0xFFFE; // no table is created for now -> and likely
130 // will not be created later...
141 void ExtSheetBuffer::Reset()
146 bool ExtName::IsOLE() const
148 return ( nFlags
& 0x0002 ) != 0;
151 ExtNameBuff::ExtNameBuff( const XclImpRoot
& rRoot
) :
156 void ExtNameBuff::AddDDE( sal_Int16 nRefIdx
)
158 ExtName
aNew( 0x0001 );
159 maExtNames
[ nRefIdx
].push_back( aNew
);
162 void ExtNameBuff::AddOLE( sal_Int16 nRefIdx
, sal_uInt32 nStorageId
)
164 ExtName
aNew( 0x0002 );
165 aNew
.nStorageId
= nStorageId
;
166 maExtNames
[ nRefIdx
].push_back( aNew
);
169 void ExtNameBuff::AddName( sal_Int16 nRefIdx
)
171 ExtName
aNew( 0x0004 );
172 maExtNames
[ nRefIdx
].push_back( aNew
);
175 const ExtName
* ExtNameBuff::GetNameByIndex( sal_Int16 nRefIdx
, sal_uInt16 nNameIdx
) const
177 OSL_ENSURE( nNameIdx
> 0, "ExtNameBuff::GetNameByIndex() - invalid name index" );
178 ExtNameMap::const_iterator aIt
= maExtNames
.find( nRefIdx
);
179 return ((aIt
!= maExtNames
.end()) && (0 < nNameIdx
) && (nNameIdx
<= aIt
->second
.size())) ? &aIt
->second
[ nNameIdx
- 1 ] : nullptr;
182 void ExtNameBuff::Reset()
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */