merge the formfield patch from ooo-build
[ooovba.git] / sc / source / filter / excel / xeroot.cxx
blob600a9281588accc84debcb8f465e2247421ab8aa
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xeroot.cxx,v $
10 * $Revision: 1.23 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
33 #include <sfx2/docfile.hxx>
34 #include <sfx2/sfxsids.hrc>
35 #include <svtools/saveopt.hxx>
36 #include <svtools/itemset.hxx>
37 #include <svtools/stritem.hxx>
38 #include <svtools/eitem.hxx>
39 #include "xecontent.hxx"
40 #include "xltracer.hxx"
41 #include "xehelper.hxx"
42 #include "xeformula.hxx"
43 #include "xelink.hxx"
44 #include "xename.hxx"
45 #include "xestyle.hxx"
46 #include "xepivot.hxx"
47 #include "xeroot.hxx"
49 #include "excrecds.hxx" // for filter manager
50 #include "tabprotection.hxx"
51 #include "document.hxx"
52 #include "scextopt.hxx"
54 // Global data ================================================================
56 XclExpRootData::XclExpRootData( XclBiff eBiff, SfxMedium& rMedium,
57 SotStorageRef xRootStrg, ScDocument& rDoc, rtl_TextEncoding eTextEnc ) :
58 XclRootData( eBiff, rMedium, xRootStrg, rDoc, eTextEnc, true )
60 SvtSaveOptions aSaveOpt;
61 mbRelUrl = mrMedium.IsRemote() ? aSaveOpt.IsSaveRelINet() : aSaveOpt.IsSaveRelFSys();
64 XclExpRootData::~XclExpRootData()
68 // ----------------------------------------------------------------------------
70 XclExpRoot::XclExpRoot( XclExpRootData& rExpRootData ) :
71 XclRoot( rExpRootData ),
72 mrExpData( rExpRootData )
76 XclExpTabInfo& XclExpRoot::GetTabInfo() const
78 DBG_ASSERT( mrExpData.mxTabInfo.is(), "XclExpRoot::GetTabInfo - missing object (wrong BIFF?)" );
79 return *mrExpData.mxTabInfo;
82 XclExpAddressConverter& XclExpRoot::GetAddressConverter() const
84 DBG_ASSERT( mrExpData.mxAddrConv.is(), "XclExpRoot::GetAddressConverter - missing object (wrong BIFF?)" );
85 return *mrExpData.mxAddrConv;
88 XclExpFormulaCompiler& XclExpRoot::GetFormulaCompiler() const
90 DBG_ASSERT( mrExpData.mxFmlaComp.is(), "XclExpRoot::GetFormulaCompiler - missing object (wrong BIFF?)" );
91 return *mrExpData.mxFmlaComp;
94 XclExpProgressBar& XclExpRoot::GetProgressBar() const
96 DBG_ASSERT( mrExpData.mxProgress.is(), "XclExpRoot::GetProgressBar - missing object (wrong BIFF?)" );
97 return *mrExpData.mxProgress;
100 XclExpSst& XclExpRoot::GetSst() const
102 DBG_ASSERT( mrExpData.mxSst.is(), "XclExpRoot::GetSst - missing object (wrong BIFF?)" );
103 return *mrExpData.mxSst;
106 XclExpPalette& XclExpRoot::GetPalette() const
108 DBG_ASSERT( mrExpData.mxPalette.is(), "XclExpRoot::GetPalette - missing object (wrong BIFF?)" );
109 return *mrExpData.mxPalette;
112 XclExpFontBuffer& XclExpRoot::GetFontBuffer() const
114 DBG_ASSERT( mrExpData.mxFontBfr.is(), "XclExpRoot::GetFontBuffer - missing object (wrong BIFF?)" );
115 return *mrExpData.mxFontBfr;
118 XclExpNumFmtBuffer& XclExpRoot::GetNumFmtBuffer() const
120 DBG_ASSERT( mrExpData.mxNumFmtBfr.is(), "XclExpRoot::GetNumFmtBuffer - missing object (wrong BIFF?)" );
121 return *mrExpData.mxNumFmtBfr;
124 XclExpXFBuffer& XclExpRoot::GetXFBuffer() const
126 DBG_ASSERT( mrExpData.mxXFBfr.is(), "XclExpRoot::GetXFBuffer - missing object (wrong BIFF?)" );
127 return *mrExpData.mxXFBfr;
130 XclExpLinkManager& XclExpRoot::GetGlobalLinkManager() const
132 DBG_ASSERT( mrExpData.mxGlobLinkMgr.is(), "XclExpRoot::GetGlobalLinkManager - missing object (wrong BIFF?)" );
133 return *mrExpData.mxGlobLinkMgr;
136 XclExpLinkManager& XclExpRoot::GetLocalLinkManager() const
138 DBG_ASSERT( GetLocalLinkMgrRef().is(), "XclExpRoot::GetLocalLinkManager - missing object (wrong BIFF?)" );
139 return *GetLocalLinkMgrRef();
142 XclExpNameManager& XclExpRoot::GetNameManager() const
144 DBG_ASSERT( mrExpData.mxNameMgr.is(), "XclExpRoot::GetNameManager - missing object (wrong BIFF?)" );
145 return *mrExpData.mxNameMgr;
148 XclExpFilterManager& XclExpRoot::GetFilterManager() const
150 DBG_ASSERT( mrExpData.mxFilterMgr.is(), "XclExpRoot::GetFilterManager - missing object (wrong BIFF?)" );
151 return *mrExpData.mxFilterMgr;
154 XclExpPivotTableManager& XclExpRoot::GetPivotTableManager() const
156 DBG_ASSERT( mrExpData.mxPTableMgr.is(), "XclExpRoot::GetPivotTableManager - missing object (wrong BIFF?)" );
157 return *mrExpData.mxPTableMgr;
160 void XclExpRoot::InitializeConvert()
162 mrExpData.mxTabInfo.reset( new XclExpTabInfo( GetRoot() ) );
163 mrExpData.mxAddrConv.reset( new XclExpAddressConverter( GetRoot() ) );
164 mrExpData.mxFmlaComp.reset( new XclExpFormulaCompiler( GetRoot() ) );
165 mrExpData.mxProgress.reset( new XclExpProgressBar( GetRoot() ) );
167 GetProgressBar().Initialize();
170 void XclExpRoot::InitializeGlobals()
172 SetCurrScTab( SCTAB_GLOBAL );
174 if( GetBiff() >= EXC_BIFF5 )
176 mrExpData.mxPalette.reset( new XclExpPalette( GetRoot() ) );
177 mrExpData.mxFontBfr.reset( new XclExpFontBuffer( GetRoot() ) );
178 mrExpData.mxNumFmtBfr.reset( new XclExpNumFmtBuffer( GetRoot() ) );
179 mrExpData.mxXFBfr.reset( new XclExpXFBuffer( GetRoot() ) );
180 mrExpData.mxGlobLinkMgr.reset( new XclExpLinkManager( GetRoot() ) );
181 mrExpData.mxNameMgr.reset( new XclExpNameManager( GetRoot() ) );
184 if( GetBiff() == EXC_BIFF8 )
186 mrExpData.mxSst.reset( new XclExpSst );
187 mrExpData.mxFilterMgr.reset( new XclExpFilterManager( GetRoot() ) );
188 mrExpData.mxPTableMgr.reset( new XclExpPivotTableManager( GetRoot() ) );
189 // BIFF8: only one link manager for all sheets
190 mrExpData.mxLocLinkMgr = mrExpData.mxGlobLinkMgr;
193 GetXFBuffer().Initialize();
194 GetNameManager().Initialize();
197 void XclExpRoot::InitializeTable( SCTAB nScTab )
199 SetCurrScTab( nScTab );
200 if( GetBiff() == EXC_BIFF5 )
202 // local link manager per sheet
203 mrExpData.mxLocLinkMgr.reset( new XclExpLinkManager( GetRoot() ) );
207 void XclExpRoot::InitializeSave()
209 GetPalette().Finalize();
210 GetXFBuffer().Finalize();
213 XclExpRecordRef XclExpRoot::CreateRecord( sal_uInt16 nRecId ) const
215 XclExpRecordRef xRec;
216 switch( nRecId )
218 case EXC_ID_PALETTE: xRec = mrExpData.mxPalette; break;
219 case EXC_ID_FONTLIST: xRec = mrExpData.mxFontBfr; break;
220 case EXC_ID_FORMATLIST: xRec = mrExpData.mxNumFmtBfr; break;
221 case EXC_ID_XFLIST: xRec = mrExpData.mxXFBfr; break;
222 case EXC_ID_SST: xRec = mrExpData.mxSst; break;
223 case EXC_ID_EXTERNSHEET: xRec = GetLocalLinkMgrRef(); break;
224 case EXC_ID_NAME: xRec = mrExpData.mxNameMgr; break;
226 DBG_ASSERT( xRec.is(), "XclExpRoot::CreateRecord - unknown record ID or missing object" );
227 return xRec;
230 bool XclExpRoot::IsDocumentEncrypted() const
232 // We need to encrypt the content when the document structure is protected.
233 const ScDocProtection* pDocProt = GetDoc().GetDocProtection();
234 if (pDocProt && pDocProt->isProtected() && pDocProt->isOptionEnabled(ScDocProtection::STRUCTURE))
235 return true;
237 if (GetPassword().Len() > 0)
238 // Password is entered directly into the save dialog.
239 return true;
241 return false;
244 const String XclExpRoot::GetPassword() const
246 SfxItemSet* pSet = GetMedium().GetItemSet();
247 if (!pSet)
248 return String();
250 const SfxPoolItem* pItem = NULL;
251 if (SFX_ITEM_SET == pSet->GetItemState(SID_PASSWORD, sal_True, &pItem))
253 const SfxStringItem* pStrItem = dynamic_cast<const SfxStringItem*>(pItem);
254 if (pStrItem)
256 // Password from the save dialog.
257 return pStrItem->GetValue();
261 return String();
264 XclExpRootData::XclExpLinkMgrRef XclExpRoot::GetLocalLinkMgrRef() const
266 return IsInGlobals() ? mrExpData.mxGlobLinkMgr : mrExpData.mxLocLinkMgr;
269 // ============================================================================