1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_scfilt.hxx"
26 #include "xiroot.hxx"
27 #include "addincol.hxx"
28 #include "document.hxx"
29 #include "scextopt.hxx"
30 #include "xltracer.hxx"
31 #include "xihelper.hxx"
32 #include "xiformula.hxx"
33 #include "xilink.hxx"
34 #include "xiname.hxx"
35 #include "xistyle.hxx"
36 #include "xicontent.hxx"
37 #include "xiescher.hxx"
38 #include "xipivot.hxx"
39 #include "xipage.hxx"
40 #include "xiview.hxx"
41
42 #include "root.hxx"
43 #include "excimp8.hxx"
44
45 // Global data ================================================================
46
XclImpRootData(XclBiff eBiff,SfxMedium & rMedium,SotStorageRef xRootStrg,ScDocument & rDoc,rtl_TextEncoding eTextEnc)47 XclImpRootData::XclImpRootData( XclBiff eBiff, SfxMedium& rMedium,
48 SotStorageRef xRootStrg, ScDocument& rDoc, rtl_TextEncoding eTextEnc ) :
49 XclRootData( eBiff, rMedium, xRootStrg, rDoc, eTextEnc, false ),
50 mbHasCodePage( false ),
51 mbHasBasic( false )
52 {
53 }
54
~XclImpRootData()55 XclImpRootData::~XclImpRootData()
56 {
57 }
58
59 // ----------------------------------------------------------------------------
60
XclImpRoot(XclImpRootData & rImpRootData)61 XclImpRoot::XclImpRoot( XclImpRootData& rImpRootData ) :
62 XclRoot( rImpRootData ),
63 mrImpData( rImpRootData )
64 {
65 mrImpData.mxAddrConv.reset( new XclImpAddressConverter( GetRoot() ) );
66 mrImpData.mxFmlaComp.reset( new XclImpFormulaCompiler( GetRoot() ) );
67 mrImpData.mxPalette.reset( new XclImpPalette( GetRoot() ) );
68 mrImpData.mxFontBfr.reset( new XclImpFontBuffer( GetRoot() ) );
69 mrImpData.mxNumFmtBfr.reset( new XclImpNumFmtBuffer( GetRoot() ) );
70 mrImpData.mpXFBfr.reset( new XclImpXFBuffer( GetRoot() ) );
71 mrImpData.mxXFRangeBfr.reset( new XclImpXFRangeBuffer( GetRoot() ) );
72 mrImpData.mxTabInfo.reset( new XclImpTabInfo );
73 mrImpData.mxNameMgr.reset( new XclImpNameManager( GetRoot() ) );
74 mrImpData.mxObjMgr.reset( new XclImpObjectManager( GetRoot() ) );
75
76 if( GetBiff() == EXC_BIFF8 )
77 {
78 mrImpData.mxLinkMgr.reset( new XclImpLinkManager( GetRoot() ) );
79 mrImpData.mxSst.reset( new XclImpSst( GetRoot() ) );
80 mrImpData.mxCondFmtMgr.reset( new XclImpCondFormatManager( GetRoot() ) );
81 // TODO still in old RootData (deleted by RootData)
82 GetOldRoot().pAutoFilterBuffer = new XclImpAutoFilterBuffer;
83 mrImpData.mxWebQueryBfr.reset( new XclImpWebQueryBuffer( GetRoot() ) );
84 mrImpData.mxPTableMgr.reset( new XclImpPivotTableManager( GetRoot() ) );
85 mrImpData.mxTabProtect.reset( new XclImpSheetProtectBuffer( GetRoot() ) );
86 mrImpData.mxDocProtect.reset( new XclImpDocProtectBuffer( GetRoot() ) );
87 }
88
89 mrImpData.mxPageSett.reset( new XclImpPageSettings( GetRoot() ) );
90 mrImpData.mxDocViewSett.reset( new XclImpDocViewSettings( GetRoot() ) );
91 mrImpData.mxTabViewSett.reset( new XclImpTabViewSettings( GetRoot() ) );
92 }
93
SetCodePage(sal_uInt16 nCodePage)94 void XclImpRoot::SetCodePage( sal_uInt16 nCodePage )
95 {
96 SetTextEncoding( XclTools::GetTextEncoding( nCodePage ) );
97 mrImpData.mbHasCodePage = true;
98 }
99
SetAppFontEncoding(rtl_TextEncoding eAppFontEnc)100 void XclImpRoot::SetAppFontEncoding( rtl_TextEncoding eAppFontEnc )
101 {
102 if( !mrImpData.mbHasCodePage )
103 SetTextEncoding( eAppFontEnc );
104 }
105
InitializeTable(SCTAB nScTab)106 void XclImpRoot::InitializeTable( SCTAB nScTab )
107 {
108 if( GetBiff() <= EXC_BIFF4 )
109 {
110 GetPalette().Initialize();
111 GetFontBuffer().Initialize();
112 GetNumFmtBuffer().Initialize();
113 GetXFBuffer().Initialize();
114 }
115 GetXFRangeBuffer().Initialize();
116 GetPageSettings().Initialize();
117 GetTabViewSettings().Initialize();
118 // delete the automatically generated codename
119 GetDoc().SetCodeName( nScTab, String::EmptyString() );
120 }
121
FinalizeTable()122 void XclImpRoot::FinalizeTable()
123 {
124 GetXFRangeBuffer().Finalize();
125 GetOldRoot().pColRowBuff->Convert( GetCurrScTab() );
126 GetPageSettings().Finalize();
127 GetTabViewSettings().Finalize();
128 }
129
GetAddressConverter() const130 XclImpAddressConverter& XclImpRoot::GetAddressConverter() const
131 {
132 return *mrImpData.mxAddrConv;
133 }
134
GetFormulaCompiler() const135 XclImpFormulaCompiler& XclImpRoot::GetFormulaCompiler() const
136 {
137 return *mrImpData.mxFmlaComp;
138 }
139
GetOldFmlaConverter() const140 ExcelToSc& XclImpRoot::GetOldFmlaConverter() const
141 {
142 // TODO still in old RootData
143 return *GetOldRoot().pFmlaConverter;
144 }
145
GetSst() const146 XclImpSst& XclImpRoot::GetSst() const
147 {
148 DBG_ASSERT( mrImpData.mxSst.is(), "XclImpRoot::GetSst - invalid call, wrong BIFF" );
149 return *mrImpData.mxSst;
150 }
151
GetPalette() const152 XclImpPalette& XclImpRoot::GetPalette() const
153 {
154 return *mrImpData.mxPalette;
155 }
156
GetFontBuffer() const157 XclImpFontBuffer& XclImpRoot::GetFontBuffer() const
158 {
159 return *mrImpData.mxFontBfr;
160 }
161
GetNumFmtBuffer() const162 XclImpNumFmtBuffer& XclImpRoot::GetNumFmtBuffer() const
163 {
164 return *mrImpData.mxNumFmtBfr;
165 }
166
GetXFBuffer() const167 XclImpXFBuffer& XclImpRoot::GetXFBuffer() const
168 {
169 return *mrImpData.mpXFBfr;
170 }
171
GetXFRangeBuffer() const172 XclImpXFRangeBuffer& XclImpRoot::GetXFRangeBuffer() const
173 {
174 return *mrImpData.mxXFRangeBfr;
175 }
176
GetPrintAreaBuffer() const177 _ScRangeListTabs& XclImpRoot::GetPrintAreaBuffer() const
178 {
179 // TODO still in old RootData
180 return *GetOldRoot().pPrintRanges;
181 }
182
GetTitleAreaBuffer() const183 _ScRangeListTabs& XclImpRoot::GetTitleAreaBuffer() const
184 {
185 // TODO still in old RootData
186 return *GetOldRoot().pPrintTitles;
187 }
188
GetTabInfo() const189 XclImpTabInfo& XclImpRoot::GetTabInfo() const
190 {
191 return *mrImpData.mxTabInfo;
192 }
193
GetNameManager() const194 XclImpNameManager& XclImpRoot::GetNameManager() const
195 {
196 return *mrImpData.mxNameMgr;
197 }
198
GetLinkManager() const199 XclImpLinkManager& XclImpRoot::GetLinkManager() const
200 {
201 DBG_ASSERT( mrImpData.mxLinkMgr.is(), "XclImpRoot::GetLinkManager - invalid call, wrong BIFF" );
202 return *mrImpData.mxLinkMgr;
203 }
204
GetObjectManager() const205 XclImpObjectManager& XclImpRoot::GetObjectManager() const
206 {
207 return *mrImpData.mxObjMgr;
208 }
209
GetCurrSheetDrawing() const210 XclImpSheetDrawing& XclImpRoot::GetCurrSheetDrawing() const
211 {
212 DBG_ASSERT( !IsInGlobals(), "XclImpRoot::GetCurrSheetDrawing - must not be called from workbook globals" );
213 return mrImpData.mxObjMgr->GetSheetDrawing( GetCurrScTab() );
214 }
215
GetCondFormatManager() const216 XclImpCondFormatManager& XclImpRoot::GetCondFormatManager() const
217 {
218 DBG_ASSERT( mrImpData.mxCondFmtMgr.is(), "XclImpRoot::GetCondFormatManager - invalid call, wrong BIFF" );
219 return *mrImpData.mxCondFmtMgr;
220 }
221
GetFilterManager() const222 XclImpAutoFilterBuffer& XclImpRoot::GetFilterManager() const
223 {
224 // TODO still in old RootData
225 DBG_ASSERT( GetOldRoot().pAutoFilterBuffer, "XclImpRoot::GetFilterManager - invalid call, wrong BIFF" );
226 return *GetOldRoot().pAutoFilterBuffer;
227 }
228
GetWebQueryBuffer() const229 XclImpWebQueryBuffer& XclImpRoot::GetWebQueryBuffer() const
230 {
231 DBG_ASSERT( mrImpData.mxWebQueryBfr.is(), "XclImpRoot::GetWebQueryBuffer - invalid call, wrong BIFF" );
232 return *mrImpData.mxWebQueryBfr;
233 }
234
GetPivotTableManager() const235 XclImpPivotTableManager& XclImpRoot::GetPivotTableManager() const
236 {
237 DBG_ASSERT( mrImpData.mxPTableMgr.is(), "XclImpRoot::GetPivotTableManager - invalid call, wrong BIFF" );
238 return *mrImpData.mxPTableMgr;
239 }
240
GetSheetProtectBuffer() const241 XclImpSheetProtectBuffer& XclImpRoot::GetSheetProtectBuffer() const
242 {
243 DBG_ASSERT( mrImpData.mxTabProtect.is(), "XclImpRoot::GetSheetProtectBuffer - invalid call, wrong BIFF" );
244 return *mrImpData.mxTabProtect;
245 }
246
GetDocProtectBuffer() const247 XclImpDocProtectBuffer& XclImpRoot::GetDocProtectBuffer() const
248 {
249 DBG_ASSERT( mrImpData.mxDocProtect.is(), "XclImpRoot::GetDocProtectBuffer - invalid call, wrong BIFF" );
250 return *mrImpData.mxDocProtect;
251 }
252
GetPageSettings() const253 XclImpPageSettings& XclImpRoot::GetPageSettings() const
254 {
255 return *mrImpData.mxPageSett;
256 }
257
GetDocViewSettings() const258 XclImpDocViewSettings& XclImpRoot::GetDocViewSettings() const
259 {
260 return *mrImpData.mxDocViewSett;
261 }
262
GetTabViewSettings() const263 XclImpTabViewSettings& XclImpRoot::GetTabViewSettings() const
264 {
265 return *mrImpData.mxTabViewSett;
266 }
267
GetScAddInName(const String & rXclName) const268 String XclImpRoot::GetScAddInName( const String& rXclName ) const
269 {
270 String aScName;
271 if( ScGlobal::GetAddInCollection()->GetCalcName( rXclName, aScName ) )
272 return aScName;
273 return rXclName;
274 }
275
ReadCodeName(XclImpStream & rStrm,bool bGlobals)276 void XclImpRoot::ReadCodeName( XclImpStream& rStrm, bool bGlobals )
277 {
278 if( mrImpData.mbHasBasic && (GetBiff() == EXC_BIFF8) )
279 {
280 String aName = rStrm.ReadUniString();
281 if( aName.Len() > 0 )
282 {
283 if( bGlobals )
284 {
285 GetExtDocOptions().GetDocSettings().maGlobCodeName = aName;
286 GetDoc().SetCodeName( aName );
287 }
288 else
289 {
290 GetExtDocOptions().SetCodeName( GetCurrScTab(), aName );
291 GetDoc().SetCodeName( GetCurrScTab(), aName );
292 }
293 }
294 }
295 }
296
297 // ============================================================================
298