LibreOffice Module sc (master) 1
namebuff.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <namebuff.hxx>
21
22#include <document.hxx>
23#include <scextopt.hxx>
24#include <tokenarray.hxx>
25
26#include <root.hxx>
27#include <xiroot.hxx>
28
29#include <osl/diagnose.h>
30
31sal_uInt32 StringHashEntry::MakeHashCode( const OUString& r )
32{
33 sal_uInt32 n = 0;
34 const sal_Unicode* pCurrent = r.getStr();
35 sal_Unicode cCurrent = *pCurrent;
36
37 while( cCurrent )
38 {
39 n *= 70;
40 n += static_cast<sal_uInt32>(cCurrent);
41 pCurrent++;
42 cCurrent = *pCurrent;
43 }
44
45 return n;
46}
47
49 : ExcRoot(pRD)
50{
51}
52
54{
55 Clear();
56}
57
59{
60 maTokenArrays.clear();
61}
62
63void SharedFormulaBuffer::Store( const ScAddress& rPos, const ScTokenArray& rArray )
64{
65 ScTokenArray aCode(rArray.CloneValue());
66 aCode.GenHash();
67 maTokenArrays.emplace(rPos, std::move(aCode));
68}
69
70const ScTokenArray* SharedFormulaBuffer::Find( const ScAddress& rRefPos ) const
71{
72 TokenArraysType::const_iterator it = maTokenArrays.find(rRefPos);
73 if (it == maTokenArrays.end())
74 return nullptr;
75
76 return &it->second;
77}
78
79sal_Int16 ExtSheetBuffer::Add( const OUString& rFPAN, const OUString& rTN, const bool bSWB )
80{
81 maEntries.emplace_back( rFPAN, rTN, bSWB );
82 // return 1-based index of EXTERNSHEET
83 return static_cast< sal_Int16 >( maEntries.size() );
84}
85
86bool ExtSheetBuffer::GetScTabIndex( sal_uInt16 nExcIndex, sal_uInt16& rScIndex )
87{
88 OSL_ENSURE( nExcIndex,
89 "*ExtSheetBuffer::GetScTabIndex(): Sheet-Index == 0!" );
90
91 if ( !nExcIndex || nExcIndex > maEntries.size() )
92 return false;
93
94 Cont* pCur = &maEntries[ nExcIndex - 1 ];
95 sal_uInt16& rTabNum = pCur->nTabNum;
96
97 if( rTabNum < 0xFFFD )
98 {
99 rScIndex = rTabNum;
100 return true;
101 }
102
103 if( rTabNum == 0xFFFF )
104 {// create new table
105 SCTAB nNewTabNum;
106 if( pCur->bSWB )
107 {// table is in the same workbook!
108 if( pExcRoot->pIR->GetDoc().GetTable( pCur->aTab, nNewTabNum ) )
109 {
110 rScIndex = rTabNum = static_cast<sal_uInt16>(nNewTabNum);
111 return true;
112 }
113 else
114 rTabNum = 0xFFFD;
115 }
116 else if( pExcRoot->pIR->GetDocShell() )
117 {// table is 'really' external
119 {
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 ) )
124 {
125 rScIndex = rTabNum = static_cast<sal_uInt16>(nNewTabNum);
126 return true;
127 }
128 else
129 rTabNum = 0xFFFE; // no table is created for now -> and likely
130 // will not be created later...
131 }
132 else
133 rTabNum = 0xFFFE;
134
135 }
136 }
137
138 return false;
139}
140
142{
143 maEntries.clear();
144}
145
146bool ExtName::IsOLE() const
147{
148 return ( nFlags & 0x0002 ) != 0;
149}
150
152 XclImpRoot( rRoot )
153{
154}
155
156void ExtNameBuff::AddDDE( sal_Int16 nRefIdx )
157{
158 ExtName aNew( 0x0001 );
159 maExtNames[ nRefIdx ].push_back( aNew );
160}
161
162void ExtNameBuff::AddOLE( sal_Int16 nRefIdx, sal_uInt32 nStorageId )
163{
164 ExtName aNew( 0x0002 );
165 aNew.nStorageId = nStorageId;
166 maExtNames[ nRefIdx ].push_back( aNew );
167}
168
169void ExtNameBuff::AddName( sal_Int16 nRefIdx )
170{
171 ExtName aNew( 0x0004 );
172 maExtNames[ nRefIdx ].push_back( aNew );
173}
174
175const ExtName* ExtNameBuff::GetNameByIndex( sal_Int16 nRefIdx, sal_uInt16 nNameIdx ) const
176{
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;
180}
181
183{
184 maExtNames.clear();
185}
186
187/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition: root.hxx:67
RootData * pExcRoot
Definition: root.hxx:69
ExtNameBuff(const XclImpRoot &rRoot)
Definition: namebuff.cxx:151
void AddDDE(sal_Int16 nRefIdx)
Definition: namebuff.cxx:156
void AddOLE(sal_Int16 nRefIdx, sal_uInt32 nStorageId)
Definition: namebuff.cxx:162
const ExtName * GetNameByIndex(sal_Int16 nRefIdx, sal_uInt16 nNameIdx) const
Definition: namebuff.cxx:175
void AddName(sal_Int16 nRefIdx)
Definition: namebuff.cxx:169
ExtNameMap maExtNames
Definition: namebuff.hxx:188
void Reset()
Definition: namebuff.cxx:182
std::vector< Cont > maEntries
Definition: namebuff.hxx:144
sal_Int16 Add(const OUString &rFilePathAndName, const OUString &rTabName, const bool bSameWorkbook)
Definition: namebuff.cxx:79
bool GetScTabIndex(sal_uInt16 nExcSheetIndex, sal_uInt16 &rIn_LastTab_Out_ScIndex)
Definition: namebuff.cxx:86
SC_DLLPUBLIC bool LinkExternalTab(SCTAB &nTab, const OUString &aDocTab, const OUString &aFileName, const OUString &aTabName)
Definition: documen3.cxx:566
SC_DLLPUBLIC bool GetTable(const OUString &rName, SCTAB &rTab) const
Definition: document.cxx:244
const ScExtDocSettings & GetDocSettings() const
Definition: scextopt.cxx:170
static SC_DLLPUBLIC OUString GetDocTabName(std::u16string_view rFileName, std::u16string_view rTabName)
Definition: global2.cxx:324
static SC_DLLPUBLIC OUString GetAbsDocName(const OUString &rFileName, const SfxObjectShell *pShell)
Definition: global2.cxx:287
ScTokenArray CloneValue() const
True copy!
Definition: token.cxx:1989
void GenHash()
True copy!
Definition: token.cxx:1730
virtual ~SharedFormulaBuffer()
Definition: namebuff.cxx:53
SharedFormulaBuffer(RootData *pRD)
Definition: namebuff.cxx:48
const ScTokenArray * Find(const ScAddress &rRefPos) const
Definition: namebuff.cxx:70
void Store(const ScAddress &rPos, const ScTokenArray &rArray)
Definition: namebuff.cxx:63
TokenArraysType maTokenArrays
Definition: namebuff.hxx:63
static sal_uInt32 MakeHashCode(const OUString &)
Definition: namebuff.cxx:31
Access to global data from other classes.
Definition: xiroot.hxx:129
SfxObjectShell * GetDocShell() const
Returns the object shell of the Calc document.
Definition: xlroot.cxx:290
ScExtDocOptions & GetExtDocOptions() const
Returns the extended document options.
Definition: xlroot.cxx:429
ScDocument & GetDoc() const
Returns reference to the destination document (import) or source document (export).
Definition: xlroot.cxx:285
URL aURL
sal_Int64 n
sal_uInt32 nStorageId
Definition: namebuff.hxx:163
sal_uInt16 nFlags
Definition: namebuff.hxx:164
bool IsOLE() const
Definition: namebuff.cxx:146
sal_uInt16 nTabNum
Definition: namebuff.hxx:130
XclImpRoot * pIR
Definition: root.hxx:59
sal_uInt32 mnLinkCnt
Recursive counter for loading external documents.
Definition: scextopt.hxx:31
sal_uInt16 sal_Unicode
sal_Int16 SCTAB
Definition: types.hxx:22