LCOV - code coverage report
Current view: top level - sc/source/filter/excel - excdoc.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 370 0.0 %
Date: 2014-04-14 Functions: 0 24 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 "scitems.hxx"
      21             : 
      22             : #include <comphelper/processfactory.hxx>
      23             : #include <svx/svdobj.hxx>
      24             : #include <svx/svditer.hxx>
      25             : #include <svx/svdpage.hxx>
      26             : #include <editeng/lrspitem.hxx>
      27             : #include <editeng/ulspitem.hxx>
      28             : #include <svl/intitem.hxx>
      29             : #include <svl/zformat.hxx>
      30             : #include <sot/storage.hxx>
      31             : #include <sfx2/objsh.hxx>
      32             : #include <rtl/ustring.hxx>
      33             : 
      34             : #include "formulacell.hxx"
      35             : #include "dociter.hxx"
      36             : #include "document.hxx"
      37             : #include "rangenam.hxx"
      38             : #include "dbdata.hxx"
      39             : #include "global.hxx"
      40             : #include "globstr.hrc"
      41             : #include "progress.hxx"
      42             : #include "conditio.hxx"
      43             : #include "dpobject.hxx"
      44             : #include "attrib.hxx"
      45             : #include "scextopt.hxx"
      46             : #include "stlsheet.hxx"
      47             : #include "stlpool.hxx"
      48             : #include "olinetab.hxx"
      49             : #include "unonames.hxx"
      50             : #include "convuno.hxx"
      51             : #include "patattr.hxx"
      52             : #include "docoptio.hxx"
      53             : #include "tabprotection.hxx"
      54             : #include "postit.hxx"
      55             : 
      56             : #include "excdoc.hxx"
      57             : #include "namebuff.hxx"
      58             : #include "xeextlst.hxx"
      59             : 
      60             : #include "xcl97rec.hxx"
      61             : #include "xcl97esc.hxx"
      62             : #include "xetable.hxx"
      63             : #include "xelink.hxx"
      64             : #include "xename.hxx"
      65             : #include "xepage.hxx"
      66             : #include "xeview.hxx"
      67             : #include "xecontent.hxx"
      68             : #include "xeescher.hxx"
      69             : #include "xepivot.hxx"
      70             : #include "XclExpChangeTrack.hxx"
      71             : 
      72             : #include <math.h>
      73             : 
      74             : #include <com/sun/star/document/XDocumentProperties.hpp>
      75             : #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
      76             : #include <oox/token/tokens.hxx>
      77             : #include <boost/shared_ptr.hpp>
      78             : 
      79             : using namespace oox;
      80             : 
      81           0 : static OUString lcl_GetVbaTabName( SCTAB n )
      82             : {
      83           0 :     OUString aRet = "__VBA__"  + OUString::number( static_cast<sal_uInt16>(n) );
      84           0 :     return aRet;
      85             : }
      86             : 
      87             : 
      88           0 : static void lcl_AddBookviews( XclExpRecordList<>& aRecList, ExcTable& self )
      89             : {
      90           0 :     aRecList.AppendNewRecord( new XclExpXmlStartElementRecord( XML_bookViews ) );
      91           0 :     aRecList.AppendNewRecord( new XclExpWindow1( self.GetRoot() ) );
      92           0 :     aRecList.AppendNewRecord( new XclExpXmlEndElementRecord( XML_bookViews ) );
      93           0 : }
      94             : 
      95           0 : static void lcl_AddCalcPr( XclExpRecordList<>& aRecList, ExcTable& self )
      96             : {
      97           0 :     ScDocument& rDoc = self.GetDoc();
      98             : 
      99           0 :     aRecList.AppendNewRecord( new XclExpXmlStartSingleElementRecord( XML_calcPr ) );
     100             :     // OOXTODO: calcCompleted, calcId, calcMode, calcOnSave,
     101             :     //          concurrentCalc, concurrentManualCount,
     102             :     //          forceFullCalc, fullCalcOnLoad, fullPrecision
     103           0 :     aRecList.AppendNewRecord( new XclCalccount( rDoc ) );
     104           0 :     aRecList.AppendNewRecord( new XclRefmode( rDoc ) );
     105           0 :     aRecList.AppendNewRecord( new XclIteration( rDoc ) );
     106           0 :     aRecList.AppendNewRecord( new XclDelta( rDoc ) );
     107           0 :     aRecList.AppendNewRecord( new XclExpBoolRecord(0x005F, true) ); // SAVERECALC
     108           0 :     aRecList.AppendNewRecord( new XclExpXmlEndSingleElementRecord() );  // XML_calcPr
     109           0 : }
     110             : 
     111           0 : static void lcl_AddWorkbookProtection( XclExpRecordList<>& aRecList, ExcTable& self )
     112             : {
     113           0 :     aRecList.AppendNewRecord( new XclExpXmlStartSingleElementRecord( XML_workbookProtection ) );
     114             : 
     115           0 :     const ScDocProtection* pProtect = self.GetDoc().GetDocProtection();
     116           0 :     if (pProtect && pProtect->isProtected())
     117             :     {
     118           0 :         aRecList.AppendNewRecord( new XclExpWindowProtection(pProtect->isOptionEnabled(ScDocProtection::WINDOWS)) );
     119           0 :         aRecList.AppendNewRecord( new XclExpProtection(pProtect->isOptionEnabled(ScDocProtection::STRUCTURE)) );
     120           0 :         aRecList.AppendNewRecord( new XclExpPassHash(pProtect->getPasswordHash(PASSHASH_XL)) );
     121             :     }
     122             : 
     123           0 :     aRecList.AppendNewRecord( new XclExpXmlEndSingleElementRecord() );   // XML_workbookProtection
     124           0 : }
     125             : 
     126           0 : static void lcl_AddScenariosAndFilters( XclExpRecordList<>& aRecList, const XclExpRoot& rRoot, SCTAB nScTab )
     127             : {
     128             :     // Scenarios
     129           0 :     aRecList.AppendNewRecord( new ExcEScenarioManager( rRoot, nScTab ) );
     130             :     // filter
     131           0 :     aRecList.AppendRecord( rRoot.GetFilterManager().CreateRecord( nScTab ) );
     132           0 : }
     133             : 
     134             : 
     135           0 : ExcTable::ExcTable( const XclExpRoot& rRoot ) :
     136             :     XclExpRoot( rRoot ),
     137             :     mnScTab( SCTAB_GLOBAL ),
     138             :     nExcTab( EXC_NOTAB ),
     139           0 :     pTabNames( new NameBuffer( 0, 16 ) ),
     140           0 :     mxNoteList( new XclExpNoteList )
     141             : {
     142           0 : }
     143             : 
     144             : 
     145           0 : ExcTable::ExcTable( const XclExpRoot& rRoot, SCTAB nScTab ) :
     146             :     XclExpRoot( rRoot ),
     147             :     mnScTab( nScTab ),
     148           0 :     nExcTab( rRoot.GetTabInfo().GetXclTab( nScTab ) ),
     149           0 :     pTabNames( new NameBuffer( 0, 16 ) ),
     150           0 :     mxNoteList( new XclExpNoteList )
     151             : {
     152           0 : }
     153             : 
     154             : 
     155           0 : ExcTable::~ExcTable()
     156             : {
     157           0 :     delete pTabNames;
     158           0 : }
     159             : 
     160             : 
     161           0 : void ExcTable::Add( XclExpRecordBase* pRec )
     162             : {
     163             :     OSL_ENSURE( pRec, "-ExcTable::Add(): pRec is NULL!" );
     164           0 :     aRecList.AppendNewRecord( pRec );
     165           0 : }
     166             : 
     167             : 
     168           0 : void ExcTable::FillAsHeader( ExcBoundsheetList& rBoundsheetList )
     169             : {
     170           0 :     InitializeGlobals();
     171             : 
     172           0 :     RootData& rR = GetOldRoot();
     173           0 :     ScDocument& rDoc = GetDoc();
     174           0 :     XclExpTabInfo& rTabInfo = GetTabInfo();
     175             : 
     176           0 :     if ( GetBiff() <= EXC_BIFF5 )
     177           0 :         Add( new ExcBofW );
     178             :     else
     179           0 :         Add( new ExcBofW8 );
     180             : 
     181             :     SCTAB   nC;
     182           0 :     OUString aTmpString;
     183           0 :     SCTAB  nScTabCount     = rTabInfo.GetScTabCount();
     184           0 :     sal_uInt16  nExcTabCount    = rTabInfo.GetXclTabCount();
     185           0 :     sal_uInt16  nCodenames      = static_cast< sal_uInt16 >( GetExtDocOptions().GetCodeNameCount() );
     186             : 
     187           0 :     SfxObjectShell* pShell = GetDocShell();
     188           0 :     sal_uInt16 nWriteProtHash = pShell ? pShell->GetModifyPasswordHash() : 0;
     189           0 :     bool bRecommendReadOnly = pShell && pShell->IsLoadReadonly();
     190             : 
     191           0 :     if( (nWriteProtHash > 0) || bRecommendReadOnly )
     192           0 :         Add( new XclExpEmptyRecord( EXC_ID_WRITEPROT ) );
     193             : 
     194             :     // TODO: correct codepage for BIFF5?
     195           0 :     sal_uInt16 nCodePage = XclTools::GetXclCodePage( (GetBiff() <= EXC_BIFF5) ? RTL_TEXTENCODING_MS_1252 : RTL_TEXTENCODING_UNICODE );
     196             : 
     197           0 :     if( GetBiff() <= EXC_BIFF5 )
     198             :     {
     199           0 :         Add( new XclExpEmptyRecord( EXC_ID_INTERFACEHDR ) );
     200           0 :         Add( new XclExpUInt16Record( EXC_ID_MMS, 0 ) );
     201           0 :         Add( new XclExpEmptyRecord( EXC_ID_TOOLBARHDR ) );
     202           0 :         Add( new XclExpEmptyRecord( EXC_ID_TOOLBAREND ) );
     203           0 :         Add( new XclExpEmptyRecord( EXC_ID_INTERFACEEND ) );
     204           0 :         Add( new ExcDummy_00 );
     205             :     }
     206             :     else
     207             :     {
     208           0 :         if( IsDocumentEncrypted() )
     209           0 :             Add( new XclExpFileEncryption( GetRoot() ) );
     210           0 :         Add( new XclExpInterfaceHdr( nCodePage ) );
     211           0 :         Add( new XclExpUInt16Record( EXC_ID_MMS, 0 ) );
     212           0 :         Add( new XclExpInterfaceEnd );
     213           0 :         Add( new XclExpWriteAccess );
     214             :     }
     215             : 
     216           0 :     Add( new XclExpFileSharing( GetRoot(), nWriteProtHash, bRecommendReadOnly ) );
     217           0 :     Add( new XclExpUInt16Record( EXC_ID_CODEPAGE, nCodePage ) );
     218             : 
     219           0 :     if( GetBiff() == EXC_BIFF8 )
     220             :     {
     221           0 :         Add( new XclExpBoolRecord( EXC_ID_DSF, false ) );
     222           0 :         Add( new XclExpEmptyRecord( EXC_ID_XL9FILE ) );
     223           0 :         rR.pTabId = new XclExpChTrTabId( std::max( nExcTabCount, nCodenames ) );
     224           0 :         Add( rR.pTabId );
     225           0 :         if( HasVbaStorage() )
     226             :         {
     227           0 :             Add( new XclObproj );
     228           0 :             const OUString& rCodeName = GetExtDocOptions().GetDocSettings().maGlobCodeName;
     229           0 :             if( !rCodeName.isEmpty() )
     230           0 :                 Add( new XclCodename( rCodeName ) );
     231             :         }
     232             :     }
     233             : 
     234           0 :     Add( new XclExpUInt16Record( EXC_ID_FNGROUPCOUNT, 14 ) );
     235             : 
     236             :     // erst Namen- und Tabellen-Eintraege aufbauen
     237             : 
     238           0 :     for( nC = 0 ; nC < nScTabCount ; nC++ )
     239           0 :         if( rTabInfo.IsExportTab( nC ) )
     240             :         {
     241           0 :             rDoc.GetName( nC, aTmpString );
     242           0 :             *pTabNames << aTmpString;
     243             :         }
     244             : 
     245           0 :     if ( GetBiff() <= EXC_BIFF5 )
     246             :     {
     247             :         // global link table: EXTERNCOUNT, EXTERNSHEET, NAME
     248           0 :         aRecList.AppendRecord( CreateRecord( EXC_ID_EXTERNSHEET ) );
     249           0 :         aRecList.AppendRecord( CreateRecord( EXC_ID_NAME ) );
     250             :     }
     251             : 
     252             :     // document protection options
     253           0 :     if( GetOutput() == EXC_OUTPUT_BINARY )
     254             :     {
     255           0 :         lcl_AddWorkbookProtection( aRecList, *this );
     256             : 
     257           0 :         if( GetBiff() == EXC_BIFF8 )
     258             :         {
     259           0 :             Add( new XclExpProt4Rev );
     260           0 :             Add( new XclExpProt4RevPass );
     261             :         }
     262             : 
     263           0 :         lcl_AddBookviews( aRecList, *this );
     264             :     }
     265             : 
     266           0 :     Add( new XclExpXmlStartSingleElementRecord( XML_workbookPr ) );
     267           0 :     if ( GetBiff() == EXC_BIFF8 && GetOutput() != EXC_OUTPUT_BINARY )
     268             :     {
     269           0 :         Add( new XclExpBoolRecord(0x0040, false, XML_backupFile ) );    // BACKUP
     270           0 :         Add( new XclExpBoolRecord(0x008D, false, XML_showObjects ) );   // HIDEOBJ
     271             :     }
     272             : 
     273           0 :     if ( GetBiff() == EXC_BIFF8 )
     274             :     {
     275           0 :         Add( new XclExpBoolRecord(0x0040, false) ); // BACKUP
     276           0 :         Add( new XclExpBoolRecord(0x008D, false) ); // HIDEOBJ
     277             :     }
     278             : 
     279           0 :     if( GetBiff() <= EXC_BIFF5 )
     280             :     {
     281           0 :         Add( new ExcDummy_040 );
     282           0 :         Add( new Exc1904( rDoc ) );
     283           0 :         Add( new ExcDummy_041 );
     284             :     }
     285             :     else
     286             :     {
     287             :         // BIFF8
     288           0 :         Add( new Exc1904( rDoc ) );
     289           0 :         Add( new XclExpBoolRecord( 0x000E, !rDoc.GetDocOptions().IsCalcAsShown() ) );
     290           0 :         Add( new XclExpBoolRecord(0x01B7, false) ); // REFRESHALL
     291           0 :         Add( new XclExpBoolRecord(0x00DA, false) ); // BOOKBOOL
     292             :         // OOXTODO: The following /workbook/workbookPr attributes are mapped
     293             :         //          to various BIFF records that are not currently supported:
     294             :         //
     295             :         //          XML_allowRefreshQuery:          QSISTAG 802h: fEnableRefresh
     296             :         //          XML_autoCompressPictures:       COMPRESSPICTURES 89Bh: fAutoCompressPictures
     297             :         //          XML_checkCompatibility:         COMPAT12 88Ch: fNoCompatChk
     298             :         //          XML_codeName:                   "Calc"
     299             :         //          XML_defaultThemeVersion:        ???
     300             :         //          XML_filterPrivacy:              BOOKEXT 863h: fFilterPrivacy
     301             :         //          XML_hidePivotFieldList:         BOOKBOOL DAh: fHidePivotTableFList
     302             :         //          XML_promptedSolutions:          BOOKEXT 863h: fBuggedUserAboutSolution
     303             :         //          XML_publishItems:               NAMEPUBLISH 893h: fPublished
     304             :         //          XML_saveExternalLinkValues:     BOOKBOOL DAh: fNoSavSupp
     305             :         //          XML_showBorderUnselectedTables: BOOKBOOL DAh: fHideBorderUnsels
     306             :         //          XML_showInkAnnotation:          BOOKEXT 863h: fShowInkAnnotation
     307             :         //          XML_showPivotChart:             PIVOTCHARTBITS 859h: fGXHide??
     308             :         //          XML_updateLinks:                BOOKBOOL DAh: grbitUpdateLinks
     309             :     }
     310           0 :     Add( new XclExpXmlEndSingleElementRecord() );   // XML_workbookPr
     311             : 
     312             :     // Formatting: FONT, FORMAT, XF, STYLE, PALETTE
     313           0 :     if( GetOutput() != EXC_OUTPUT_BINARY )
     314             :     {
     315           0 :         aRecList.AppendNewRecord( new XclExpXmlStyleSheet( *this ) );
     316             :     }
     317             :     else
     318             :     {
     319           0 :         aRecList.AppendRecord( CreateRecord( EXC_ID_FONTLIST ) );
     320           0 :         aRecList.AppendRecord( CreateRecord( EXC_ID_FORMATLIST ) );
     321           0 :         aRecList.AppendRecord( CreateRecord( EXC_ID_XFLIST ) );
     322           0 :         aRecList.AppendRecord( CreateRecord( EXC_ID_PALETTE ) );
     323             :     }
     324             : 
     325             : 
     326           0 :     if( GetBiff() <= EXC_BIFF5 )
     327             :     {
     328             :         // Bundlesheet
     329           0 :         for( nC = 0 ; nC < nScTabCount ; nC++ )
     330           0 :             if( rTabInfo.IsExportTab( nC ) )
     331             :             {
     332           0 :                 ExcBoundsheetList::RecordRefType xBoundsheet( new ExcBundlesheet( rR, nC ) );
     333           0 :                 aRecList.AppendRecord( xBoundsheet );
     334           0 :                 rBoundsheetList.AppendRecord( xBoundsheet );
     335             :             }
     336             :     }
     337             :     else
     338             :     {
     339             :         // Pivot Cache
     340           0 :         GetPivotTableManager().CreatePivotTables();
     341           0 :         aRecList.AppendRecord( GetPivotTableManager().CreatePivotCachesRecord() );
     342             : 
     343             :         // Change tracking
     344           0 :         if( rDoc.GetChangeTrack() )
     345             :         {
     346           0 :             rR.pUserBViewList = new XclExpUserBViewList( *rDoc.GetChangeTrack() );
     347           0 :             Add( rR.pUserBViewList );
     348             :         }
     349             : 
     350             :         // Natural Language Formulas Flag
     351           0 :         aRecList.AppendNewRecord( new XclExpBoolRecord( EXC_ID_USESELFS, GetDoc().GetDocOptions().IsLookUpColRowNames() ) );
     352             : 
     353           0 :         if( GetOutput() != EXC_OUTPUT_BINARY )
     354             :         {
     355           0 :             lcl_AddWorkbookProtection( aRecList, *this );
     356           0 :             lcl_AddBookviews( aRecList, *this );
     357             :         }
     358             : 
     359             :         // Bundlesheet
     360           0 :         aRecList.AppendNewRecord( new XclExpXmlStartElementRecord( XML_sheets ) );
     361           0 :         for( nC = 0 ; nC < nScTabCount ; nC++ )
     362           0 :             if( rTabInfo.IsExportTab( nC ) )
     363             :             {
     364           0 :                 ExcBoundsheetList::RecordRefType xBoundsheet( new ExcBundlesheet8( rR, nC ) );
     365           0 :                 aRecList.AppendRecord( xBoundsheet );
     366           0 :                 rBoundsheetList.AppendRecord( xBoundsheet );
     367             :             }
     368           0 :         aRecList.AppendNewRecord( new XclExpXmlEndElementRecord( XML_sheets ) );
     369             : 
     370           0 :         for( SCTAB nAdd = 0; nC < static_cast<SCTAB>(nCodenames) ; nC++, nAdd++ )
     371             :         {
     372           0 :             aTmpString = lcl_GetVbaTabName( nAdd );
     373           0 :             ExcBoundsheetList::RecordRefType xBoundsheet( new ExcBundlesheet8( aTmpString ) );
     374           0 :             aRecList.AppendRecord( xBoundsheet );
     375           0 :             rBoundsheetList.AppendRecord( xBoundsheet );
     376           0 :         }
     377             : 
     378             :         // COUNTRY - in BIFF8 in workbook globals
     379           0 :         Add( new XclExpCountry( GetRoot() ) );
     380             :         // link table: SUPBOOK, XCT, CRN, EXTERNNAME, EXTERNSHEET, NAME
     381           0 :         aRecList.AppendRecord( CreateRecord( EXC_ID_EXTERNSHEET ) );
     382           0 :         aRecList.AppendRecord( CreateRecord( EXC_ID_NAME ) );
     383             : 
     384           0 :         if( GetOutput() != EXC_OUTPUT_BINARY )
     385           0 :             lcl_AddCalcPr( aRecList, *this );
     386             : 
     387           0 :         Add( new XclExpRecalcId );
     388             : 
     389             :         // MSODRAWINGGROUP per-document data
     390           0 :         aRecList.AppendRecord( GetObjectManager().CreateDrawingGroup() );
     391             :         // Shared string table: SST, EXTSST
     392           0 :         aRecList.AppendRecord( CreateRecord( EXC_ID_SST ) );
     393             : 
     394           0 :         Add( new XclExpBookExt );
     395             :     }
     396             : 
     397           0 :     Add( new ExcEof );
     398           0 : }
     399             : 
     400             : 
     401           0 : void ExcTable::FillAsTable( SCTAB nCodeNameIdx )
     402             : {
     403           0 :     InitializeTable( mnScTab );
     404             : 
     405           0 :     RootData& rR = GetOldRoot();
     406           0 :     XclBiff eBiff = GetBiff();
     407           0 :     ScDocument& rDoc = GetDoc();
     408             : 
     409             :     OSL_ENSURE( (mnScTab >= 0L) && (mnScTab <= MAXTAB), "-ExcTable::Table(): mnScTab - no ordinary table!" );
     410             :     OSL_ENSURE( nExcTab <= static_cast<sal_uInt16>(MAXTAB), "-ExcTable::Table(): nExcTab - no ordinary table!" );
     411             : 
     412             :     // create a new OBJ list for this sheet (may be used by notes, autofilter, data validation)
     413           0 :     if( eBiff == EXC_BIFF8 )
     414           0 :         GetObjectManager().StartSheet();
     415             : 
     416             :     // cell table: DEFROWHEIGHT, DEFCOLWIDTH, COLINFO, DIMENSIONS, ROW, cell records
     417           0 :     mxCellTable.reset( new XclExpCellTable( GetRoot() ) );
     418             : 
     419             :     //export cell notes
     420           0 :     std::vector<sc::NoteEntry> aNotes;
     421           0 :     rDoc.GetAllNoteEntries(aNotes);
     422           0 :     for (std::vector<sc::NoteEntry>::const_iterator it = aNotes.begin(), itEnd = aNotes.end(); it != itEnd; ++it)
     423             :     {
     424           0 :         if (it->maPos.Tab() != mnScTab)
     425           0 :             continue;
     426             : 
     427           0 :         mxNoteList->AppendNewRecord(new XclExpNote(GetRoot(), it->maPos, it->mpNote, OUString()));
     428             :     }
     429             : 
     430           0 :     if( GetOutput() != EXC_OUTPUT_BINARY )
     431             :     {
     432           0 :         FillAsXmlTable( nCodeNameIdx );
     433           0 :         return;
     434             :     }
     435             : 
     436             : 
     437             :     // WSBOOL needs data from page settings, create it here, add it later
     438           0 :     boost::shared_ptr< XclExpPageSettings > xPageSett( new XclExpPageSettings( GetRoot() ) );
     439           0 :     bool bFitToPages = xPageSett->GetPageData().mbFitToPages;
     440             : 
     441           0 :     if( eBiff <= EXC_BIFF5 )
     442             :     {
     443           0 :         Add( new ExcBof );
     444           0 :         Add( new ExcDummy_02a );
     445             :     }
     446             :     else
     447             :     {
     448           0 :         Add( new ExcBof8 );
     449           0 :         lcl_AddCalcPr( aRecList, *this );
     450             :     }
     451             : 
     452             :     // GUTS (count & size of outline icons)
     453           0 :     aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_GUTS ) );
     454             :     // DEFROWHEIGHT, created by the cell table
     455           0 :     aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID2_DEFROWHEIGHT ) );
     456             : 
     457             :     // COUNTRY - in BIFF5/7 in every worksheet
     458           0 :     if( eBiff <= EXC_BIFF5 )
     459           0 :         Add( new XclExpCountry( GetRoot() ) );
     460             : 
     461           0 :     Add( new XclExpWsbool( bFitToPages ) );
     462             : 
     463             :     // page settings (SETUP and various other records)
     464           0 :     aRecList.AppendRecord( xPageSett );
     465             : 
     466           0 :     const ScTableProtection* pTabProtect = rDoc.GetTabProtection(mnScTab);
     467           0 :     if (pTabProtect && pTabProtect->isProtected())
     468             :     {
     469           0 :         Add( new XclExpProtection(true) );
     470           0 :         Add( new XclExpBoolRecord(0x00DD, pTabProtect->isOptionEnabled(ScTableProtection::SCENARIOS)) );
     471           0 :         Add( new XclExpBoolRecord(0x0063, pTabProtect->isOptionEnabled(ScTableProtection::OBJECTS)) );
     472           0 :         Add( new XclExpPassHash(pTabProtect->getPasswordHash(PASSHASH_XL)) );
     473             :     }
     474             : 
     475             :     // local link table: EXTERNCOUNT, EXTERNSHEET
     476           0 :     if( eBiff <= EXC_BIFF5 )
     477           0 :         aRecList.AppendRecord( CreateRecord( EXC_ID_EXTERNSHEET ) );
     478             : 
     479           0 :     if ( eBiff == EXC_BIFF8 )
     480           0 :         lcl_AddScenariosAndFilters( aRecList, GetRoot(), mnScTab );
     481             : 
     482             :     // cell table: DEFCOLWIDTH, COLINFO, DIMENSIONS, ROW, cell records
     483           0 :     aRecList.AppendRecord( mxCellTable );
     484             : 
     485             :     // MERGEDCELLS record, generated by the cell table
     486           0 :     aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_MERGEDCELLS ) );
     487             :     // label ranges
     488           0 :     if( eBiff == EXC_BIFF8 )
     489           0 :         Add( new XclExpLabelranges( GetRoot() ) );
     490             :     // data validation (DVAL and list of DV records), generated by the cell table
     491           0 :     aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_DVAL ) );
     492             : 
     493           0 :     if( eBiff == EXC_BIFF8 )
     494             :     {
     495             :         // all MSODRAWING and OBJ stuff of this sheet goes here
     496           0 :         aRecList.AppendRecord( GetObjectManager().ProcessDrawing( GetSdrPage( mnScTab ) ) );
     497             :         // pivot tables
     498           0 :         aRecList.AppendRecord( GetPivotTableManager().CreatePivotTablesRecord( mnScTab ) );
     499             :     }
     500             : 
     501             :     // list of NOTE records, generated by the cell table
     502           0 :     aRecList.AppendRecord( mxNoteList );
     503             : 
     504             :     // sheet view settings: WINDOW2, SCL, PANE, SELECTION
     505           0 :     aRecList.AppendNewRecord( new XclExpTabViewSettings( GetRoot(), mnScTab ) );
     506             : 
     507           0 :     if( eBiff == EXC_BIFF8 )
     508             :     {
     509             :         // sheet protection options
     510           0 :         Add( new XclExpSheetProtectOptions( GetRoot(), mnScTab ) );
     511             : 
     512             :         // enhanced protections if there are
     513           0 :         if (pTabProtect)
     514             :         {
     515           0 :             const ::std::vector<ScEnhancedProtection>& rProts( pTabProtect->getEnhancedProtection());
     516           0 :             for (::std::vector<ScEnhancedProtection>::const_iterator it( rProts.begin()), itEnd( rProts.end());
     517             :                     it != itEnd; ++it)
     518             :             {
     519           0 :                 Add( new XclExpSheetEnhancedProtection( GetRoot(), *it));
     520             :             }
     521             :         }
     522             : 
     523             :         // web queries
     524           0 :         Add( new XclExpWebQueryBuffer( GetRoot() ) );
     525             : 
     526             :         // conditional formats
     527           0 :         Add( new XclExpCondFormatBuffer( GetRoot(), XclExtLstRef() ) );
     528             : 
     529           0 :         if( HasVbaStorage() )
     530           0 :             if( nCodeNameIdx < GetExtDocOptions().GetCodeNameCount() )
     531           0 :                 Add( new XclCodename( GetExtDocOptions().GetCodeName( nCodeNameIdx ) ) );
     532             :     }
     533             : 
     534             :     // list of HLINK records, generated by the cell table
     535           0 :     aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_HLINK ) );
     536             : 
     537             :     // change tracking
     538           0 :     if( rR.pUserBViewList )
     539             :     {
     540           0 :         XclExpUserBViewList::const_iterator iter;
     541           0 :         for ( iter = rR.pUserBViewList->begin(); iter != rR.pUserBViewList->end(); ++iter)
     542             :         {
     543           0 :             Add( new XclExpUsersViewBegin( (*iter)->GetGUID(), nExcTab ) );
     544           0 :             Add( new XclExpUsersViewEnd );
     545             :         }
     546             :     }
     547             : 
     548             :     // EOF
     549           0 :     Add( new ExcEof );
     550             : }
     551             : 
     552           0 : void ExcTable::FillAsXmlTable( SCTAB nCodeNameIdx )
     553             : {
     554           0 :     RootData& rR = GetOldRoot();
     555             : 
     556             :     // WSBOOL needs data from page settings, create it here, add it later
     557           0 :     boost::shared_ptr< XclExpPageSettings > xPageSett( new XclExpPageSettings( GetRoot() ) );
     558           0 :     XclExtLstRef xExtLst( new XclExtLst( GetRoot() ) );
     559           0 :     bool bFitToPages = xPageSett->GetPageData().mbFitToPages;
     560             : 
     561           0 :     Add( new ExcBof8 );
     562             : 
     563           0 :     Color aTabColor = GetRoot().GetDoc().GetTabBgColor(mnScTab);
     564           0 :     Add(new XclExpXmlSheetPr(bFitToPages, mnScTab, aTabColor, &GetFilterManager()));
     565             : 
     566             :     // GUTS (count & size of outline icons)
     567           0 :     aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_GUTS ) );
     568             :     // DEFROWHEIGHT, created by the cell table
     569           0 :     aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID2_DEFROWHEIGHT ) );
     570             : 
     571           0 :     aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID3_DIMENSIONS ) );
     572             : 
     573             :     // sheet view settings: WINDOW2, SCL, PANE, SELECTION
     574           0 :     aRecList.AppendNewRecord( new XclExpTabViewSettings( GetRoot(), mnScTab ) );
     575             : 
     576             :     // cell table: DEFCOLWIDTH, COLINFO, DIMENSIONS, ROW, cell records
     577           0 :     aRecList.AppendRecord( mxCellTable );
     578             : 
     579             :     // label ranges
     580             :     // missing SaveXML
     581           0 :     Add( new XclExpLabelranges( GetRoot() ) );
     582             : 
     583             :     // DFF not needed in MSOOXML export
     584             : //    GetObjectManager().AddSdrPage();
     585             : //    //! close Escher group shape and ESCHER_DgContainer
     586             : //    //! opened by XclExpObjList ctor MSODRAWING
     587             : //    rR.pObjRecs->EndSheet();
     588             : //    // all MSODRAWING and OBJ stuff of this sheet goes here
     589             : //    Add( rR.pObjRecs );
     590             : 
     591             :     // pivot tables
     592             :     // not in the worksheet file
     593           0 :     aRecList.AppendRecord( GetPivotTableManager().CreatePivotTablesRecord( mnScTab ) );
     594             : 
     595             :     // list of NOTE records, generated by the cell table
     596             :     // not in the worksheet file
     597           0 :     if( mxNoteList != 0 && !mxNoteList->IsEmpty() )
     598           0 :         aRecList.AppendNewRecord( new XclExpComments( mnScTab, *mxNoteList ) );
     599             : 
     600             :     // web queries
     601             :     // missing SaveXML implementation
     602           0 :     Add( new XclExpWebQueryBuffer( GetRoot() ) );
     603             : 
     604           0 :     ScDocument& rDoc = GetDoc();
     605           0 :     const ScTableProtection* pTabProtect = rDoc.GetTabProtection(mnScTab);
     606           0 :     if (pTabProtect && pTabProtect->isProtected())
     607           0 :         Add( new XclExpSheetProtection(true, mnScTab) );
     608             : 
     609           0 :     lcl_AddScenariosAndFilters( aRecList, GetRoot(), mnScTab );
     610             : 
     611             :     // MERGEDCELLS record, generated by the cell table
     612           0 :     aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_MERGEDCELLS ) );
     613             : 
     614             :     // conditional formats
     615           0 :     Add( new XclExpCondFormatBuffer( GetRoot(), xExtLst ) );
     616             : 
     617           0 :     if( HasVbaStorage() )
     618           0 :         if( nCodeNameIdx < GetExtDocOptions().GetCodeNameCount() )
     619           0 :             Add( new XclCodename( GetExtDocOptions().GetCodeName( nCodeNameIdx ) ) );
     620             : 
     621             :     // data validation (DVAL and list of DV records), generated by the cell table
     622           0 :     aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_DVAL ) );
     623             : 
     624             :     // list of HLINK records, generated by the cell table
     625           0 :     XclExpRecordRef xHyperlinks = mxCellTable->CreateRecord( EXC_ID_HLINK );
     626           0 :     XclExpHyperlinkList* xHyperlinkList = dynamic_cast<XclExpHyperlinkList*>(xHyperlinks.get());
     627           0 :     if( xHyperlinkList != NULL && !xHyperlinkList->IsEmpty() )
     628             :     {
     629           0 :         aRecList.AppendNewRecord( new XclExpXmlStartElementRecord( XML_hyperlinks ) );
     630           0 :         aRecList.AppendRecord( xHyperlinks );
     631           0 :         aRecList.AppendNewRecord( new XclExpXmlEndElementRecord( XML_hyperlinks ) );
     632             :     }
     633             : 
     634           0 :     aRecList.AppendRecord( xPageSett );
     635             : 
     636             :     // change tracking
     637           0 :     if( rR.pUserBViewList )
     638             :     {
     639           0 :         XclExpUserBViewList::const_iterator iter;
     640           0 :         for ( iter = rR.pUserBViewList->begin(); iter != rR.pUserBViewList->end(); ++iter )
     641             :         {
     642           0 :             Add( new XclExpUsersViewBegin( (*iter)->GetGUID(), nExcTab ) );
     643           0 :             Add( new XclExpUsersViewEnd );
     644             :         }
     645             :     }
     646             : 
     647             :     // all MSODRAWING and OBJ stuff of this sheet goes here
     648           0 :     aRecList.AppendRecord( GetObjectManager().ProcessDrawing( GetSdrPage( mnScTab ) ) );
     649             : 
     650           0 :     aRecList.AppendRecord( xExtLst );
     651             : 
     652             :     // EOF
     653           0 :     Add( new ExcEof );
     654           0 : }
     655             : 
     656             : 
     657           0 : void ExcTable::FillAsEmptyTable( SCTAB nCodeNameIdx )
     658             : {
     659           0 :     InitializeTable( mnScTab );
     660             : 
     661           0 :     if( HasVbaStorage() && (nCodeNameIdx < GetExtDocOptions().GetCodeNameCount()) )
     662             :     {
     663           0 :         if( GetBiff() <= EXC_BIFF5 )
     664             :         {
     665           0 :             Add( new ExcBof );
     666             :         }
     667             :         else
     668             :         {
     669           0 :             Add( new ExcBof8 );
     670           0 :             Add( new XclCodename( GetExtDocOptions().GetCodeName( nCodeNameIdx ) ) );
     671             :         }
     672             :         // sheet view settings: WINDOW2, SCL, PANE, SELECTION
     673           0 :         aRecList.AppendNewRecord( new XclExpTabViewSettings( GetRoot(), mnScTab ) );
     674           0 :         Add( new ExcEof );
     675             :     }
     676           0 : }
     677             : 
     678             : 
     679           0 : void ExcTable::Write( XclExpStream& rStrm )
     680             : {
     681           0 :     SetCurrScTab( mnScTab );
     682           0 :     if( mxCellTable.get() )
     683           0 :         mxCellTable->Finalize();
     684           0 :     aRecList.Save( rStrm );
     685           0 : }
     686             : 
     687             : 
     688           0 : void ExcTable::WriteXml( XclExpXmlStream& rStrm )
     689             : {
     690           0 :     if (GetTabInfo().IsExportTab( mnScTab ) )
     691             :     {
     692             :         // worksheet export
     693           0 :         OUString sSheetName = XclXmlUtils::GetStreamName( "xl/", "worksheets/sheet", mnScTab+1 );
     694             : 
     695           0 :         sax_fastparser::FSHelperPtr pWorksheet = rStrm.GetStreamForPath( sSheetName );
     696             : 
     697           0 :         rStrm.PushStream( pWorksheet );
     698             : 
     699             :         pWorksheet->startElement( XML_worksheet,
     700             :                 XML_xmlns, "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
     701             :                 FSNS( XML_xmlns, XML_r ), "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
     702           0 :                 FSEND );
     703             :     }
     704             : 
     705           0 :     SetCurrScTab( mnScTab );
     706           0 :     if( mxCellTable.get() )
     707           0 :         mxCellTable->Finalize();
     708           0 :     aRecList.SaveXml( rStrm );
     709             : 
     710           0 :     if (GetTabInfo().IsExportTab( mnScTab ) )
     711             :     {
     712           0 :         rStrm.GetCurrentStream()->endElement( XML_worksheet );
     713           0 :         rStrm.PopStream();
     714             :     }
     715           0 : }
     716             : 
     717             : 
     718           0 : ExcDocument::ExcDocument( const XclExpRoot& rRoot ) :
     719             :     XclExpRoot( rRoot ),
     720             :     aHeader( rRoot ),
     721           0 :     pExpChangeTrack( NULL )
     722             : {
     723           0 : }
     724             : 
     725             : 
     726           0 : ExcDocument::~ExcDocument()
     727             : {
     728           0 :     maTableList.RemoveAllRecords();    //! for the following assertion
     729           0 :     delete pExpChangeTrack;
     730           0 : }
     731             : 
     732             : 
     733           0 : void ExcDocument::ReadDoc( void )
     734             : {
     735           0 :     InitializeConvert();
     736             : 
     737           0 :     aHeader.FillAsHeader( maBoundsheetList );
     738             : 
     739           0 :     SCTAB nScTab = 0, nScTabCount = GetTabInfo().GetScTabCount();
     740           0 :     SCTAB nCodeNameIdx = 0, nCodeNameCount = GetExtDocOptions().GetCodeNameCount();
     741             : 
     742           0 :     for( ; nScTab < nScTabCount; ++nScTab )
     743             :     {
     744           0 :         if( GetTabInfo().IsExportTab( nScTab ) )
     745             :         {
     746           0 :             ExcTableList::RecordRefType xTab( new ExcTable( GetRoot(), nScTab ) );
     747           0 :             maTableList.AppendRecord( xTab );
     748           0 :             xTab->FillAsTable( nCodeNameIdx );
     749           0 :             ++nCodeNameIdx;
     750             :         }
     751             :     }
     752           0 :     for( ; nCodeNameIdx < nCodeNameCount; ++nScTab, ++nCodeNameIdx )
     753             :     {
     754           0 :         ExcTableList::RecordRefType xTab( new ExcTable( GetRoot(), nScTab ) );
     755           0 :         maTableList.AppendRecord( xTab );
     756           0 :         xTab->FillAsEmptyTable( nCodeNameIdx );
     757           0 :     }
     758             : 
     759           0 :     if ( GetBiff() == EXC_BIFF8 )
     760             :     {
     761             :         // complete temporary Escher stream
     762           0 :         GetObjectManager().EndDocument();
     763             : 
     764             :         // change tracking
     765           0 :         if ( GetDoc().GetChangeTrack() )
     766           0 :             pExpChangeTrack = new XclExpChangeTrack( GetRoot() );
     767             :     }
     768           0 : }
     769             : 
     770             : 
     771           0 : void ExcDocument::Write( SvStream& rSvStrm )
     772             : {
     773           0 :     if( !maTableList.IsEmpty() )
     774             :     {
     775           0 :         InitializeSave();
     776             : 
     777           0 :         XclExpStream aXclStrm( rSvStrm, GetRoot() );
     778             : 
     779           0 :         aHeader.Write( aXclStrm );
     780             : 
     781             :         OSL_ENSURE( maTableList.GetSize() == maBoundsheetList.GetSize(),
     782             :             "ExcDocument::Write - different number of sheets and BOUNDSHEET records" );
     783             : 
     784           0 :         for( size_t nTab = 0, nTabCount = maTableList.GetSize(); nTab < nTabCount; ++nTab )
     785             :         {
     786             :             // set current stream position in BOUNDSHEET record
     787           0 :             ExcBoundsheetRef xBoundsheet = maBoundsheetList.GetRecord( nTab );
     788           0 :             if( xBoundsheet.get() )
     789           0 :                 xBoundsheet->SetStreamPos( aXclStrm.GetSvStreamPos() );
     790             :             // write the table
     791           0 :             maTableList.GetRecord( nTab )->Write( aXclStrm );
     792           0 :         }
     793             : 
     794             :         // write the table stream positions into the BOUNDSHEET records
     795           0 :         for( size_t nBSheet = 0, nBSheetCount = maBoundsheetList.GetSize(); nBSheet < nBSheetCount; ++nBSheet )
     796           0 :             maBoundsheetList.GetRecord( nBSheet )->UpdateStreamPos( aXclStrm );
     797             :     }
     798           0 :     if( pExpChangeTrack )
     799           0 :         pExpChangeTrack->Write();
     800           0 : }
     801             : 
     802           0 : void ExcDocument::WriteXml( XclExpXmlStream& rStrm )
     803             : {
     804           0 :     SfxObjectShell* pDocShell = GetDocShell();
     805             : 
     806             :     using namespace ::com::sun::star;
     807           0 :     uno::Reference<document::XDocumentPropertiesSupplier> xDPS( pDocShell->GetModel(), uno::UNO_QUERY_THROW );
     808           0 :     uno::Reference<document::XDocumentProperties> xDocProps = xDPS->getDocumentProperties();
     809             : 
     810           0 :     rStrm.exportDocumentProperties( xDocProps );
     811             : 
     812           0 :     sax_fastparser::FSHelperPtr& rWorkbook = rStrm.GetCurrentStream();
     813             :     rWorkbook->startElement( XML_workbook,
     814             :             XML_xmlns, "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
     815             :             FSNS(XML_xmlns, XML_r), "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
     816           0 :             FSEND );
     817             :     rWorkbook->singleElement( XML_fileVersion,
     818             :             XML_appName, "Calc",
     819             :             // OOXTODO: XML_codeName
     820             :             // OOXTODO: XML_lastEdited
     821             :             // OOXTODO: XML_lowestEdited
     822             :             // OOXTODO: XML_rupBuild
     823           0 :             FSEND );
     824             : 
     825           0 :     if( !maTableList.IsEmpty() )
     826             :     {
     827           0 :         InitializeSave();
     828             : 
     829           0 :         aHeader.WriteXml( rStrm );
     830             : 
     831           0 :         for( size_t nTab = 0, nTabCount = maTableList.GetSize(); nTab < nTabCount; ++nTab )
     832             :         {
     833             :             // write the table
     834           0 :             maTableList.GetRecord( nTab )->WriteXml( rStrm );
     835             :         }
     836             :     }
     837             : 
     838           0 :     if( pExpChangeTrack )
     839           0 :         pExpChangeTrack->WriteXml( rStrm );
     840             : 
     841           0 :     rWorkbook->endElement( XML_workbook );
     842           0 :     rWorkbook.reset();
     843             : 
     844           0 :     rStrm.commitStorage();
     845           0 : }
     846             : 
     847             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10