use insert function instead of for loop
[LibreOffice.git] / sc / source / filter / excel / xiroot.cxx
blobd8959affe5fd64aac1648fbc8b0e66870e646e60
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <xiroot.hxx>
21 #include <addincol.hxx>
22 #include <colrowst.hxx>
23 #include <document.hxx>
24 #include <formel.hxx>
25 #include <scextopt.hxx>
26 #include <xihelper.hxx>
27 #include <xiformula.hxx>
28 #include <xilink.hxx>
29 #include <xiname.hxx>
30 #include <xistyle.hxx>
31 #include <xicontent.hxx>
32 #include <xiescher.hxx>
33 #include <xipivot.hxx>
34 #include <xipage.hxx>
35 #include <xiview.hxx>
37 #include <root.hxx>
38 #include <excimp8.hxx>
39 #include <documentimport.hxx>
40 #include <sot/storage.hxx>
42 // Global data ================================================================
44 XclImpRootData::XclImpRootData( XclBiff eBiff, SfxMedium& rMedium,
45 const rtl::Reference<SotStorage>& xRootStrg, ScDocument& rDoc, rtl_TextEncoding eTextEnc ) :
46 XclRootData( eBiff, rMedium, xRootStrg, rDoc, eTextEnc, false ),
47 mxDocImport(std::make_shared<ScDocumentImport>(rDoc)),
48 mbHasCodePage( false ),
49 mbHasBasic( false )
53 XclImpRootData::~XclImpRootData()
57 XclImpRoot::XclImpRoot( XclImpRootData& rImpRootData ) :
58 XclRoot( rImpRootData ),
59 mrImpData( rImpRootData )
61 mrImpData.mxAddrConv = std::make_shared<XclImpAddressConverter>( GetRoot() );
62 mrImpData.mxFmlaComp = std::make_shared<XclImpFormulaCompiler>( GetRoot() );
63 mrImpData.mxPalette = std::make_shared<XclImpPalette>( GetRoot() );
64 mrImpData.mxFontBfr = std::make_shared<XclImpFontBuffer>( GetRoot() );
65 mrImpData.mxNumFmtBfr = std::make_shared<XclImpNumFmtBuffer>( GetRoot() );
66 mrImpData.mpXFBfr = std::make_shared<XclImpXFBuffer>( GetRoot() );
67 mrImpData.mxXFRangeBfr = std::make_shared<XclImpXFRangeBuffer>( GetRoot() );
68 mrImpData.mxTabInfo = std::make_shared<XclImpTabInfo>();
69 mrImpData.mxNameMgr = std::make_shared<XclImpNameManager>( GetRoot() );
70 mrImpData.mxObjMgr = std::make_shared<XclImpObjectManager>( GetRoot() );
72 if( GetBiff() == EXC_BIFF8 )
74 mrImpData.mxLinkMgr = std::make_shared<XclImpLinkManager>( GetRoot() );
75 mrImpData.mxSst = std::make_shared<XclImpSst>( GetRoot() );
76 mrImpData.mxCondFmtMgr = std::make_shared<XclImpCondFormatManager>( GetRoot() );
77 mrImpData.mxValidMgr = std::make_shared<XclImpValidationManager>( GetRoot() );
78 // TODO still in old RootData (deleted by RootData)
79 GetOldRoot().pAutoFilterBuffer.reset( new XclImpAutoFilterBuffer );
80 mrImpData.mxWebQueryBfr = std::make_shared<XclImpWebQueryBuffer>( GetRoot() );
81 mrImpData.mxPTableMgr = std::make_shared<XclImpPivotTableManager>( GetRoot() );
82 mrImpData.mxTabProtect = std::make_shared<XclImpSheetProtectBuffer>( GetRoot() );
83 mrImpData.mxDocProtect = std::make_shared<XclImpDocProtectBuffer>( GetRoot() );
86 mrImpData.mxPageSett = std::make_shared<XclImpPageSettings>( GetRoot() );
87 mrImpData.mxDocViewSett = std::make_shared<XclImpDocViewSettings>( GetRoot() );
88 mrImpData.mxTabViewSett = std::make_shared<XclImpTabViewSettings>( GetRoot() );
89 mrImpData.mpPrintRanges = std::make_unique<ScRangeListTabs>( GetRoot() );
90 mrImpData.mpPrintTitles = std::make_unique<ScRangeListTabs>( GetRoot() );
93 void XclImpRoot::SetCodePage( sal_uInt16 nCodePage )
95 SetTextEncoding( XclTools::GetTextEncoding( nCodePage ) );
96 mrImpData.mbHasCodePage = true;
99 void XclImpRoot::InitializeTable( SCTAB nScTab )
101 if( GetBiff() <= EXC_BIFF4 )
103 GetPalette().Initialize();
104 GetFontBuffer().Initialize();
105 GetNumFmtBuffer().Initialize();
106 GetXFBuffer().Initialize();
108 GetXFRangeBuffer().Initialize();
109 GetPageSettings().Initialize();
110 GetTabViewSettings().Initialize();
111 // delete the automatically generated codename
112 GetDoc().SetCodeName( nScTab, OUString() );
115 void XclImpRoot::FinalizeTable()
117 GetXFRangeBuffer().Finalize();
118 GetOldRoot().pColRowBuff->Convert( GetCurrScTab() );
119 GetPageSettings().Finalize();
120 GetTabViewSettings().Finalize();
123 XclImpAddressConverter& XclImpRoot::GetAddressConverter() const
125 return *mrImpData.mxAddrConv;
128 XclImpFormulaCompiler& XclImpRoot::GetFormulaCompiler() const
130 return *mrImpData.mxFmlaComp;
133 ExcelToSc& XclImpRoot::GetOldFmlaConverter() const
135 // TODO still in old RootData
136 return *GetOldRoot().pFmlaConverter;
139 XclImpSst& XclImpRoot::GetSst() const
141 assert(mrImpData.mxSst && "XclImpRoot::GetSst - invalid call, wrong BIFF");
142 return *mrImpData.mxSst;
145 XclImpPalette& XclImpRoot::GetPalette() const
147 return *mrImpData.mxPalette;
150 XclImpFontBuffer& XclImpRoot::GetFontBuffer() const
152 return *mrImpData.mxFontBfr;
155 XclImpNumFmtBuffer& XclImpRoot::GetNumFmtBuffer() const
157 return *mrImpData.mxNumFmtBfr;
160 XclImpXFBuffer& XclImpRoot::GetXFBuffer() const
162 return *mrImpData.mpXFBfr;
165 XclImpXFRangeBuffer& XclImpRoot::GetXFRangeBuffer() const
167 return *mrImpData.mxXFRangeBfr;
170 ScRangeListTabs& XclImpRoot::GetPrintAreaBuffer() const
172 return *mrImpData.mpPrintRanges;
175 ScRangeListTabs& XclImpRoot::GetTitleAreaBuffer() const
177 return *mrImpData.mpPrintTitles;
180 XclImpTabInfo& XclImpRoot::GetTabInfo() const
182 return *mrImpData.mxTabInfo;
185 XclImpNameManager& XclImpRoot::GetNameManager() const
187 return *mrImpData.mxNameMgr;
190 XclImpLinkManager& XclImpRoot::GetLinkManager() const
192 assert(mrImpData.mxLinkMgr && "XclImpRoot::GetLinkManager - invalid call, wrong BIFF");
193 return *mrImpData.mxLinkMgr;
196 XclImpObjectManager& XclImpRoot::GetObjectManager() const
198 return *mrImpData.mxObjMgr;
201 XclImpSheetDrawing& XclImpRoot::GetCurrSheetDrawing() const
203 OSL_ENSURE( !IsInGlobals(), "XclImpRoot::GetCurrSheetDrawing - must not be called from workbook globals" );
204 return mrImpData.mxObjMgr->GetSheetDrawing( GetCurrScTab() );
207 XclImpCondFormatManager& XclImpRoot::GetCondFormatManager() const
209 assert(mrImpData.mxCondFmtMgr && "XclImpRoot::GetCondFormatManager - invalid call, wrong BIFF");
210 return *mrImpData.mxCondFmtMgr;
213 XclImpValidationManager& XclImpRoot::GetValidationManager() const
215 assert(mrImpData.mxValidMgr && "XclImpRoot::GetValidationManager - invalid call, wrong BIFF");
216 return *mrImpData.mxValidMgr;
219 XclImpAutoFilterBuffer& XclImpRoot::GetFilterManager() const
221 // TODO still in old RootData
222 assert(GetOldRoot().pAutoFilterBuffer && "XclImpRoot::GetFilterManager - invalid call, wrong BIFF");
223 return *GetOldRoot().pAutoFilterBuffer;
226 XclImpWebQueryBuffer& XclImpRoot::GetWebQueryBuffer() const
228 assert(mrImpData.mxWebQueryBfr && "XclImpRoot::GetWebQueryBuffer - invalid call, wrong BIFF");
229 return *mrImpData.mxWebQueryBfr;
232 XclImpPivotTableManager& XclImpRoot::GetPivotTableManager() const
234 assert(mrImpData.mxPTableMgr && "XclImpRoot::GetPivotTableManager - invalid call, wrong BIFF");
235 return *mrImpData.mxPTableMgr;
238 XclImpSheetProtectBuffer& XclImpRoot::GetSheetProtectBuffer() const
240 assert(mrImpData.mxTabProtect && "XclImpRoot::GetSheetProtectBuffer - invalid call, wrong BIFF");
241 return *mrImpData.mxTabProtect;
244 XclImpDocProtectBuffer& XclImpRoot::GetDocProtectBuffer() const
246 assert(mrImpData.mxDocProtect && "XclImpRoot::GetDocProtectBuffer - invalid call, wrong BIFF");
247 return *mrImpData.mxDocProtect;
250 XclImpPageSettings& XclImpRoot::GetPageSettings() const
252 return *mrImpData.mxPageSett;
255 XclImpDocViewSettings& XclImpRoot::GetDocViewSettings() const
257 return *mrImpData.mxDocViewSett;
260 XclImpTabViewSettings& XclImpRoot::GetTabViewSettings() const
262 return *mrImpData.mxTabViewSett;
265 OUString XclImpRoot::GetScAddInName( const OUString& rXclName )
267 OUString aScName;
268 if( ScGlobal::GetAddInCollection()->GetCalcName( rXclName, aScName ) )
269 return aScName;
270 return rXclName;
273 void XclImpRoot::ReadCodeName( XclImpStream& rStrm, bool bGlobals )
275 if( !(mrImpData.mbHasBasic && (GetBiff() == EXC_BIFF8)) )
276 return;
278 OUString aName = rStrm.ReadUniString();
279 if( aName.isEmpty() )
280 return;
282 if( bGlobals )
284 GetExtDocOptions().GetDocSettings().maGlobCodeName = aName;
285 GetDoc().SetCodeName( aName );
287 else
289 GetExtDocOptions().SetCodeName( GetCurrScTab(), aName );
290 GetDoc().SetCodeName( GetCurrScTab(), aName );
294 ScDocumentImport& XclImpRoot::GetDocImport()
296 return *mrImpData.mxDocImport;
299 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */