LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sc/source/filter/excel - excdoc.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 281 361 77.8 %
Date: 2013-07-09 Functions: 22 24 91.7 %
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 String 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           9 : static void lcl_AddBookviews( XclExpRecordList<>& aRecList, ExcTable& self )
      89             : {
      90           9 :     aRecList.AppendNewRecord( new XclExpXmlStartElementRecord( XML_bookViews ) );
      91           9 :     aRecList.AppendNewRecord( new XclExpWindow1( self.GetRoot() ) );
      92           9 :     aRecList.AppendNewRecord( new XclExpXmlEndElementRecord( XML_bookViews ) );
      93           9 : }
      94             : 
      95          11 : static void lcl_AddCalcPr( XclExpRecordList<>& aRecList, ExcTable& self )
      96             : {
      97          11 :     ScDocument& rDoc = self.GetDoc();
      98             : 
      99          11 :     aRecList.AppendNewRecord( new XclExpXmlStartSingleElementRecord( XML_calcPr ) );
     100             :     // OOXTODO: calcCompleted, calcId, calcMode, calcOnSave,
     101             :     //          concurrentCalc, concurrentManualCount,
     102             :     //          forceFullCalc, fullCalcOnLoad, fullPrecision
     103          11 :     aRecList.AppendNewRecord( new XclCalccount( rDoc ) );
     104          11 :     aRecList.AppendNewRecord( new XclRefmode( rDoc ) );
     105          11 :     aRecList.AppendNewRecord( new XclIteration( rDoc ) );
     106          11 :     aRecList.AppendNewRecord( new XclDelta( rDoc ) );
     107          11 :     aRecList.AppendNewRecord( new XclExpBoolRecord(0x005F, true) ); // SAVERECALC
     108          11 :     aRecList.AppendNewRecord( new XclExpXmlEndSingleElementRecord() );  // XML_calcPr
     109          11 : }
     110             : 
     111           9 : static void lcl_AddWorkbookProtection( XclExpRecordList<>& aRecList, ExcTable& self )
     112             : {
     113           9 :     aRecList.AppendNewRecord( new XclExpXmlStartSingleElementRecord( XML_workbookProtection ) );
     114             : 
     115           9 :     const ScDocProtection* pProtect = self.GetDoc().GetDocProtection();
     116           9 :     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           9 :     aRecList.AppendNewRecord( new XclExpXmlEndSingleElementRecord() );   // XML_workbookProtection
     124           9 : }
     125             : 
     126          14 : static void lcl_AddScenariosAndFilters( XclExpRecordList<>& aRecList, const XclExpRoot& rRoot, SCTAB nScTab )
     127             : {
     128             :     // Scenarios
     129          14 :     aRecList.AppendNewRecord( new ExcEScenarioManager( rRoot, nScTab ) );
     130             :     // filter
     131          14 :     aRecList.AppendRecord( rRoot.GetFilterManager().CreateRecord( nScTab ) );
     132          14 : }
     133             : 
     134             : 
     135           9 : ExcTable::ExcTable( const XclExpRoot& rRoot ) :
     136             :     XclExpRoot( rRoot ),
     137             :     mnScTab( SCTAB_GLOBAL ),
     138             :     nExcTab( EXC_NOTAB ),
     139           9 :     pTabNames( new NameBuffer( 0, 16 ) ),
     140          18 :     mxNoteList( new XclExpNoteList )
     141             : {
     142           9 : }
     143             : 
     144             : 
     145          14 : ExcTable::ExcTable( const XclExpRoot& rRoot, SCTAB nScTab ) :
     146             :     XclExpRoot( rRoot ),
     147             :     mnScTab( nScTab ),
     148          14 :     nExcTab( rRoot.GetTabInfo().GetXclTab( nScTab ) ),
     149          14 :     pTabNames( new NameBuffer( 0, 16 ) ),
     150          42 :     mxNoteList( new XclExpNoteList )
     151             : {
     152          14 : }
     153             : 
     154             : 
     155          60 : ExcTable::~ExcTable()
     156             : {
     157          23 :     delete pTabNames;
     158          37 : }
     159             : 
     160             : 
     161         314 : void ExcTable::Add( XclExpRecordBase* pRec )
     162             : {
     163             :     OSL_ENSURE( pRec, "-ExcTable::Add(): pRec is NULL!" );
     164         314 :     aRecList.AppendNewRecord( pRec );
     165         314 : }
     166             : 
     167             : 
     168           9 : void ExcTable::FillAsHeader( ExcBoundsheetList& rBoundsheetList )
     169             : {
     170           9 :     InitializeGlobals();
     171             : 
     172           9 :     RootData& rR = GetOldRoot();
     173           9 :     ScDocument& rDoc = GetDoc();
     174           9 :     XclExpTabInfo& rTabInfo = GetTabInfo();
     175             : 
     176           9 :     if ( GetBiff() <= EXC_BIFF5 )
     177           0 :         Add( new ExcBofW );
     178             :     else
     179           9 :         Add( new ExcBofW8 );
     180             : 
     181             :     SCTAB   nC;
     182           9 :     OUString aTmpString;
     183           9 :     SCTAB  nScTabCount     = rTabInfo.GetScTabCount();
     184           9 :     sal_uInt16  nExcTabCount    = rTabInfo.GetXclTabCount();
     185           9 :     sal_uInt16  nCodenames      = static_cast< sal_uInt16 >( GetExtDocOptions().GetCodeNameCount() );
     186             : 
     187           9 :     SfxObjectShell* pShell = GetDocShell();
     188           9 :     sal_uInt16 nWriteProtHash = pShell ? pShell->GetModifyPasswordHash() : 0;
     189           9 :     bool bRecommendReadOnly = pShell && pShell->IsLoadReadonly();
     190             : 
     191           9 :     if( (nWriteProtHash > 0) || bRecommendReadOnly )
     192           0 :         Add( new XclExpEmptyRecord( EXC_ID_WRITEPROT ) );
     193             : 
     194             :     // TODO: correct codepage for BIFF5?
     195           9 :     sal_uInt16 nCodePage = XclTools::GetXclCodePage( (GetBiff() <= EXC_BIFF5) ? RTL_TEXTENCODING_MS_1252 : RTL_TEXTENCODING_UNICODE );
     196             : 
     197           9 :     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           9 :         if( IsDocumentEncrypted() )
     209           0 :             Add( new XclExpFileEncryption( GetRoot() ) );
     210           9 :         Add( new XclExpInterfaceHdr( nCodePage ) );
     211           9 :         Add( new XclExpUInt16Record( EXC_ID_MMS, 0 ) );
     212           9 :         Add( new XclExpInterfaceEnd );
     213           9 :         Add( new XclExpWriteAccess );
     214             :     }
     215             : 
     216           9 :     Add( new XclExpFileSharing( GetRoot(), nWriteProtHash, bRecommendReadOnly ) );
     217           9 :     Add( new XclExpUInt16Record( EXC_ID_CODEPAGE, nCodePage ) );
     218             : 
     219           9 :     if( GetBiff() == EXC_BIFF8 )
     220             :     {
     221           9 :         Add( new XclExpBoolRecord( EXC_ID_DSF, false ) );
     222           9 :         Add( new XclExpEmptyRecord( EXC_ID_XL9FILE ) );
     223           9 :         rR.pTabId = new XclExpChTrTabId( std::max( nExcTabCount, nCodenames ) );
     224           9 :         Add( rR.pTabId );
     225           9 :         if( HasVbaStorage() )
     226             :         {
     227           0 :             Add( new XclObproj );
     228           0 :             const String& rCodeName = GetExtDocOptions().GetDocSettings().maGlobCodeName;
     229           0 :             if( rCodeName.Len() )
     230           0 :                 Add( new XclCodename( rCodeName ) );
     231             :         }
     232             :     }
     233             : 
     234           9 :     Add( new XclExpUInt16Record( EXC_ID_FNGROUPCOUNT, 14 ) );
     235             : 
     236             :     // erst Namen- und Tabellen-Eintraege aufbauen
     237             : 
     238          23 :     for( nC = 0 ; nC < nScTabCount ; nC++ )
     239          14 :         if( rTabInfo.IsExportTab( nC ) )
     240             :         {
     241          14 :             rDoc.GetName( nC, aTmpString );
     242          14 :             *pTabNames << aTmpString;
     243             :         }
     244             : 
     245           9 :     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           9 :     if( GetOutput() == EXC_OUTPUT_BINARY )
     254             :     {
     255           3 :         lcl_AddWorkbookProtection( aRecList, *this );
     256             : 
     257           3 :         if( GetBiff() == EXC_BIFF8 )
     258             :         {
     259           3 :             Add( new XclExpProt4Rev );
     260           3 :             Add( new XclExpProt4RevPass );
     261             :         }
     262             : 
     263           3 :         lcl_AddBookviews( aRecList, *this );
     264             :     }
     265             : 
     266           9 :     Add( new XclExpXmlStartSingleElementRecord( XML_workbookPr ) );
     267           9 :     if ( GetBiff() == EXC_BIFF8 && GetOutput() != EXC_OUTPUT_BINARY )
     268             :     {
     269           6 :         Add( new XclExpBoolRecord(0x0040, false, XML_backupFile ) );    // BACKUP
     270           6 :         Add( new XclExpBoolRecord(0x008D, false, XML_showObjects ) );   // HIDEOBJ
     271             :     }
     272             : 
     273           9 :     if ( GetBiff() == EXC_BIFF8 )
     274             :     {
     275           9 :         Add( new XclExpBoolRecord(0x0040, false) ); // BACKUP
     276           9 :         Add( new XclExpBoolRecord(0x008D, false) ); // HIDEOBJ
     277             :     }
     278             : 
     279           9 :     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           9 :         Add( new Exc1904( rDoc ) );
     289           9 :         Add( new XclExpBoolRecord( 0x000E, !rDoc.GetDocOptions().IsCalcAsShown() ) );
     290           9 :         Add( new XclExpBoolRecord(0x01B7, false) ); // REFRESHALL
     291           9 :         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           9 :     Add( new XclExpXmlEndSingleElementRecord() );   // XML_workbookPr
     311             : 
     312             :     // Formatting: FONT, FORMAT, XF, STYLE, PALETTE
     313           9 :     if( GetOutput() != EXC_OUTPUT_BINARY )
     314             :     {
     315           6 :         aRecList.AppendNewRecord( new XclExpXmlStyleSheet( *this ) );
     316             :     }
     317             :     else
     318             :     {
     319           3 :         aRecList.AppendRecord( CreateRecord( EXC_ID_FONTLIST ) );
     320           3 :         aRecList.AppendRecord( CreateRecord( EXC_ID_FORMATLIST ) );
     321           3 :         aRecList.AppendRecord( CreateRecord( EXC_ID_XFLIST ) );
     322           3 :         aRecList.AppendRecord( CreateRecord( EXC_ID_PALETTE ) );
     323             :     }
     324             : 
     325             : 
     326           9 :     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           9 :         GetPivotTableManager().CreatePivotTables();
     341           9 :         aRecList.AppendRecord( GetPivotTableManager().CreatePivotCachesRecord() );
     342             : 
     343             :         // Change tracking
     344           9 :         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           9 :         aRecList.AppendNewRecord( new XclExpBoolRecord( EXC_ID_USESELFS, GetDoc().GetDocOptions().IsLookUpColRowNames() ) );
     352             : 
     353           9 :         if( GetOutput() != EXC_OUTPUT_BINARY )
     354             :         {
     355           6 :             lcl_AddWorkbookProtection( aRecList, *this );
     356           6 :             lcl_AddBookviews( aRecList, *this );
     357             :         }
     358             : 
     359             :         // Bundlesheet
     360           9 :         aRecList.AppendNewRecord( new XclExpXmlStartElementRecord( XML_sheets ) );
     361          23 :         for( nC = 0 ; nC < nScTabCount ; nC++ )
     362          14 :             if( rTabInfo.IsExportTab( nC ) )
     363             :             {
     364          14 :                 ExcBoundsheetList::RecordRefType xBoundsheet( new ExcBundlesheet8( rR, nC ) );
     365          14 :                 aRecList.AppendRecord( xBoundsheet );
     366          14 :                 rBoundsheetList.AppendRecord( xBoundsheet );
     367             :             }
     368           9 :         aRecList.AppendNewRecord( new XclExpXmlEndElementRecord( XML_sheets ) );
     369             : 
     370           9 :         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           9 :         Add( new XclExpCountry( GetRoot() ) );
     380             :         // link table: SUPBOOK, XCT, CRN, EXTERNNAME, EXTERNSHEET, NAME
     381           9 :         aRecList.AppendRecord( CreateRecord( EXC_ID_EXTERNSHEET ) );
     382           9 :         aRecList.AppendRecord( CreateRecord( EXC_ID_NAME ) );
     383             : 
     384           9 :         if( GetOutput() != EXC_OUTPUT_BINARY )
     385           6 :             lcl_AddCalcPr( aRecList, *this );
     386             : 
     387           9 :         Add( new XclExpRecalcId );
     388             : 
     389             :         // MSODRAWINGGROUP per-document data
     390           9 :         aRecList.AppendRecord( GetObjectManager().CreateDrawingGroup() );
     391             :         // Shared string table: SST, EXTSST
     392           9 :         aRecList.AppendRecord( CreateRecord( EXC_ID_SST ) );
     393             : 
     394           9 :         Add( new XclExpBookExt );
     395             :     }
     396             : 
     397           9 :     Add( new ExcEof );
     398           9 : }
     399             : 
     400             : 
     401          14 : void ExcTable::FillAsTable( SCTAB nCodeNameIdx )
     402             : {
     403          14 :     InitializeTable( mnScTab );
     404             : 
     405          14 :     RootData& rR = GetOldRoot();
     406          14 :     XclBiff eBiff = GetBiff();
     407          14 :     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          14 :     if( eBiff == EXC_BIFF8 )
     414          14 :         GetObjectManager().StartSheet();
     415             : 
     416             :     // cell table: DEFROWHEIGHT, DEFCOLWIDTH, COLINFO, DIMENSIONS, ROW, cell records
     417          14 :     mxCellTable.reset( new XclExpCellTable( GetRoot() ) );
     418             : 
     419             :     //export cell notes
     420          14 :     ScNotes::iterator itr = rDoc.GetNotes(mnScTab)->begin();
     421          14 :     ScNotes::iterator itrEnd = rDoc.GetNotes(mnScTab)->end();
     422          14 :     for (; itr != itrEnd; ++itr)
     423             :     {
     424             :         // notes
     425           0 :         const ScPostIt* pScNote = itr->second;
     426           0 :         ScAddress aScPos( itr->first.first, itr->first.second, mnScTab );
     427           0 :         mxNoteList->AppendNewRecord( new XclExpNote( GetRoot(), aScPos, pScNote, OUString() ) );
     428             :     }
     429             : 
     430          14 :     if( GetOutput() != EXC_OUTPUT_BINARY )
     431             :     {
     432           9 :         FillAsXmlTable( nCodeNameIdx );
     433          23 :         return;
     434             :     }
     435             : 
     436             : 
     437             :     // WSBOOL needs data from page settings, create it here, add it later
     438           5 :     boost::shared_ptr< XclExpPageSettings > xPageSett( new XclExpPageSettings( GetRoot() ) );
     439           5 :     bool bFitToPages = xPageSett->GetPageData().mbFitToPages;
     440             : 
     441           5 :     if( eBiff <= EXC_BIFF5 )
     442             :     {
     443           0 :         Add( new ExcBof );
     444           0 :         Add( new ExcDummy_02a );
     445             :     }
     446             :     else
     447             :     {
     448           5 :         Add( new ExcBof8 );
     449           5 :         lcl_AddCalcPr( aRecList, *this );
     450             :     }
     451             : 
     452             :     // GUTS (count & size of outline icons)
     453           5 :     aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_GUTS ) );
     454             :     // DEFROWHEIGHT, created by the cell table
     455           5 :     aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID2_DEFROWHEIGHT ) );
     456             : 
     457             :     // COUNTRY - in BIFF5/7 in every worksheet
     458           5 :     if( eBiff <= EXC_BIFF5 )
     459           0 :         Add( new XclExpCountry( GetRoot() ) );
     460             : 
     461           5 :     Add( new XclExpWsbool( bFitToPages ) );
     462             : 
     463             :     // page settings (SETUP and various other records)
     464           5 :     aRecList.AppendRecord( xPageSett );
     465             : 
     466           5 :     const ScTableProtection* pTabProtect = rDoc.GetTabProtection(mnScTab);
     467           5 :     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           5 :     if( eBiff <= EXC_BIFF5 )
     477           0 :         aRecList.AppendRecord( CreateRecord( EXC_ID_EXTERNSHEET ) );
     478             : 
     479           5 :     if ( eBiff == EXC_BIFF8 )
     480           5 :         lcl_AddScenariosAndFilters( aRecList, GetRoot(), mnScTab );
     481             : 
     482             :     // cell table: DEFCOLWIDTH, COLINFO, DIMENSIONS, ROW, cell records
     483           5 :     aRecList.AppendRecord( mxCellTable );
     484             : 
     485             :     // MERGEDCELLS record, generated by the cell table
     486           5 :     aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_MERGEDCELLS ) );
     487             :     // label ranges
     488           5 :     if( eBiff == EXC_BIFF8 )
     489           5 :         Add( new XclExpLabelranges( GetRoot() ) );
     490             :     // data validation (DVAL and list of DV records), generated by the cell table
     491           5 :     aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_DVAL ) );
     492             : 
     493           5 :     if( eBiff == EXC_BIFF8 )
     494             :     {
     495             :         // all MSODRAWING and OBJ stuff of this sheet goes here
     496           5 :         aRecList.AppendRecord( GetObjectManager().ProcessDrawing( GetSdrPage( mnScTab ) ) );
     497             :         // pivot tables
     498           5 :         aRecList.AppendRecord( GetPivotTableManager().CreatePivotTablesRecord( mnScTab ) );
     499             :     }
     500             : 
     501             :     // list of NOTE records, generated by the cell table
     502           5 :     aRecList.AppendRecord( mxNoteList );
     503             : 
     504             :     // sheet view settings: WINDOW2, SCL, PANE, SELECTION
     505           5 :     aRecList.AppendNewRecord( new XclExpTabViewSettings( GetRoot(), mnScTab ) );
     506             : 
     507           5 :     if( eBiff == EXC_BIFF8 )
     508             :     {
     509             :         // sheet protection options
     510           5 :         Add( new XclExpSheetProtectOptions( GetRoot(), mnScTab ) );
     511             : 
     512             :         // web queries
     513           5 :         Add( new XclExpWebQueryBuffer( GetRoot() ) );
     514             : 
     515             :         // conditional formats
     516           5 :         Add( new XclExpCondFormatBuffer( GetRoot(), XclExtLstRef() ) );
     517             : 
     518           5 :         if( HasVbaStorage() )
     519           0 :             if( nCodeNameIdx < GetExtDocOptions().GetCodeNameCount() )
     520           0 :                 Add( new XclCodename( GetExtDocOptions().GetCodeName( nCodeNameIdx ) ) );
     521             :     }
     522             : 
     523             :     // list of HLINK records, generated by the cell table
     524           5 :     aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_HLINK ) );
     525             : 
     526             :     // change tracking
     527           5 :     if( rR.pUserBViewList )
     528             :     {
     529           0 :         XclExpUserBViewList::const_iterator iter;
     530           0 :         for ( iter = rR.pUserBViewList->begin(); iter != rR.pUserBViewList->end(); ++iter)
     531             :         {
     532           0 :             Add( new XclExpUsersViewBegin( (*iter)->GetGUID(), nExcTab ) );
     533           0 :             Add( new XclExpUsersViewEnd );
     534             :         }
     535             :     }
     536             : 
     537             :     // EOF
     538           5 :     Add( new ExcEof );
     539             : }
     540             : 
     541           9 : void ExcTable::FillAsXmlTable( SCTAB nCodeNameIdx )
     542             : {
     543           9 :     RootData& rR = GetOldRoot();
     544             : 
     545             :     // WSBOOL needs data from page settings, create it here, add it later
     546           9 :     boost::shared_ptr< XclExpPageSettings > xPageSett( new XclExpPageSettings( GetRoot() ) );
     547          18 :     XclExtLstRef xExtLst( new XclExtLst( GetRoot() ) );
     548           9 :     bool bFitToPages = xPageSett->GetPageData().mbFitToPages;
     549             : 
     550           9 :     Add( new ExcBof8 );
     551             : 
     552           9 :     Add( new XclExpWsbool( bFitToPages, mnScTab, &GetFilterManager() ) );
     553             : 
     554             :     // GUTS (count & size of outline icons)
     555           9 :     aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_GUTS ) );
     556             :     // DEFROWHEIGHT, created by the cell table
     557           9 :     aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID2_DEFROWHEIGHT ) );
     558             : 
     559           9 :     aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID3_DIMENSIONS ) );
     560             : 
     561             :     // sheet view settings: WINDOW2, SCL, PANE, SELECTION
     562           9 :     aRecList.AppendNewRecord( new XclExpTabViewSettings( GetRoot(), mnScTab ) );
     563             : 
     564             :     // cell table: DEFCOLWIDTH, COLINFO, DIMENSIONS, ROW, cell records
     565           9 :     aRecList.AppendRecord( mxCellTable );
     566             : 
     567             :     // label ranges
     568           9 :     Add( new XclExpLabelranges( GetRoot() ) );
     569             : 
     570             :     // DFF not needed in MSOOXML export
     571             : //    GetObjectManager().AddSdrPage();
     572             : //    //! close Escher group shape and ESCHER_DgContainer
     573             : //    //! opened by XclExpObjList ctor MSODRAWING
     574             : //    rR.pObjRecs->EndSheet();
     575             : //    // all MSODRAWING and OBJ stuff of this sheet goes here
     576             : //    Add( rR.pObjRecs );
     577             : 
     578             :     // pivot tables
     579           9 :     aRecList.AppendRecord( GetPivotTableManager().CreatePivotTablesRecord( mnScTab ) );
     580             : 
     581             :     // list of NOTE records, generated by the cell table
     582           9 :     if( mxNoteList != 0 && !mxNoteList->IsEmpty() )
     583           0 :         aRecList.AppendNewRecord( new XclExpComments( mnScTab, *mxNoteList ) );
     584             : 
     585             :     // web queries
     586           9 :     Add( new XclExpWebQueryBuffer( GetRoot() ) );
     587             : 
     588           9 :     lcl_AddScenariosAndFilters( aRecList, GetRoot(), mnScTab );
     589             : 
     590             :     // MERGEDCELLS record, generated by the cell table
     591           9 :     aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_MERGEDCELLS ) );
     592             : 
     593             :     // conditional formats
     594           9 :     Add( new XclExpCondFormatBuffer( GetRoot(), xExtLst ) );
     595             : 
     596           9 :     if( HasVbaStorage() )
     597           0 :         if( nCodeNameIdx < GetExtDocOptions().GetCodeNameCount() )
     598           0 :             Add( new XclCodename( GetExtDocOptions().GetCodeName( nCodeNameIdx ) ) );
     599             : 
     600             :     // data validation (DVAL and list of DV records), generated by the cell table
     601           9 :     aRecList.AppendRecord( mxCellTable->CreateRecord( EXC_ID_DVAL ) );
     602             : 
     603             :     // list of HLINK records, generated by the cell table
     604          18 :     XclExpRecordRef xHyperlinks = mxCellTable->CreateRecord( EXC_ID_HLINK );
     605           9 :     XclExpHyperlinkList* xHyperlinkList = dynamic_cast<XclExpHyperlinkList*>(xHyperlinks.get());
     606           9 :     if( xHyperlinkList != NULL && !xHyperlinkList->IsEmpty() )
     607             :     {
     608           0 :         aRecList.AppendNewRecord( new XclExpXmlStartElementRecord( XML_hyperlinks ) );
     609           0 :         aRecList.AppendRecord( xHyperlinks );
     610           0 :         aRecList.AppendNewRecord( new XclExpXmlEndElementRecord( XML_hyperlinks ) );
     611             :     }
     612             : 
     613           9 :     aRecList.AppendRecord( xPageSett );
     614             : 
     615             :     // change tracking
     616           9 :     if( rR.pUserBViewList )
     617             :     {
     618           0 :         XclExpUserBViewList::const_iterator iter;
     619           0 :         for ( iter = rR.pUserBViewList->begin(); iter != rR.pUserBViewList->end(); ++iter )
     620             :         {
     621           0 :             Add( new XclExpUsersViewBegin( (*iter)->GetGUID(), nExcTab ) );
     622           0 :             Add( new XclExpUsersViewEnd );
     623             :         }
     624             :     }
     625             : 
     626             :     // all MSODRAWING and OBJ stuff of this sheet goes here
     627           9 :     aRecList.AppendRecord( GetObjectManager().ProcessDrawing( GetSdrPage( mnScTab ) ) );
     628             : 
     629           9 :     aRecList.AppendRecord( xExtLst );
     630             : 
     631             :     // EOF
     632          18 :     Add( new ExcEof );
     633           9 : }
     634             : 
     635             : 
     636           0 : void ExcTable::FillAsEmptyTable( SCTAB nCodeNameIdx )
     637             : {
     638           0 :     InitializeTable( mnScTab );
     639             : 
     640           0 :     if( HasVbaStorage() && (nCodeNameIdx < GetExtDocOptions().GetCodeNameCount()) )
     641             :     {
     642           0 :         if( GetBiff() <= EXC_BIFF5 )
     643             :         {
     644           0 :             Add( new ExcBof );
     645             :         }
     646             :         else
     647             :         {
     648           0 :             Add( new ExcBof8 );
     649           0 :             Add( new XclCodename( GetExtDocOptions().GetCodeName( nCodeNameIdx ) ) );
     650             :         }
     651             :         // sheet view settings: WINDOW2, SCL, PANE, SELECTION
     652           0 :         aRecList.AppendNewRecord( new XclExpTabViewSettings( GetRoot(), mnScTab ) );
     653           0 :         Add( new ExcEof );
     654             :     }
     655           0 : }
     656             : 
     657             : 
     658           8 : void ExcTable::Write( XclExpStream& rStrm )
     659             : {
     660           8 :     SetCurrScTab( mnScTab );
     661           8 :     if( mxCellTable.get() )
     662           5 :         mxCellTable->Finalize();
     663           8 :     aRecList.Save( rStrm );
     664           8 : }
     665             : 
     666             : 
     667          15 : void ExcTable::WriteXml( XclExpXmlStream& rStrm )
     668             : {
     669          15 :     if (GetTabInfo().IsExportTab( mnScTab ) )
     670             :     {
     671             :         // worksheet export
     672           9 :         String sSheetName = XclXmlUtils::GetStreamName( "xl/", "worksheets/sheet", mnScTab+1 );
     673             : 
     674          18 :         sax_fastparser::FSHelperPtr pWorksheet = rStrm.GetStreamForPath( sSheetName );
     675             : 
     676           9 :         rStrm.PushStream( pWorksheet );
     677             : 
     678             :         pWorksheet->startElement( XML_worksheet,
     679             :                 XML_xmlns, "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
     680             :                 FSNS( XML_xmlns, XML_r ), "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
     681          18 :                 FSEND );
     682             :     }
     683             : 
     684          15 :     SetCurrScTab( mnScTab );
     685          15 :     if( mxCellTable.get() )
     686           9 :         mxCellTable->Finalize();
     687          15 :     aRecList.SaveXml( rStrm );
     688             : 
     689          15 :     if (GetTabInfo().IsExportTab( mnScTab ) )
     690             :     {
     691           9 :         rStrm.GetCurrentStream()->endElement( XML_worksheet );
     692           9 :         rStrm.PopStream();
     693             :     }
     694          15 : }
     695             : 
     696             : 
     697           9 : ExcDocument::ExcDocument( const XclExpRoot& rRoot ) :
     698             :     XclExpRoot( rRoot ),
     699             :     aHeader( rRoot ),
     700           9 :     pExpChangeTrack( NULL )
     701             : {
     702           9 : }
     703             : 
     704             : 
     705          21 : ExcDocument::~ExcDocument()
     706             : {
     707           9 :     maTableList.RemoveAllRecords();    //! for the following assertion
     708           9 :     delete pExpChangeTrack;
     709          12 : }
     710             : 
     711             : 
     712           9 : void ExcDocument::ReadDoc( void )
     713             : {
     714           9 :     InitializeConvert();
     715             : 
     716           9 :     aHeader.FillAsHeader( maBoundsheetList );
     717             : 
     718           9 :     SCTAB nScTab = 0, nScTabCount = GetTabInfo().GetScTabCount();
     719           9 :     SCTAB nCodeNameIdx = 0, nCodeNameCount = GetExtDocOptions().GetCodeNameCount();
     720             : 
     721          23 :     for( ; nScTab < nScTabCount; ++nScTab )
     722             :     {
     723          14 :         if( GetTabInfo().IsExportTab( nScTab ) )
     724             :         {
     725          14 :             ExcTableList::RecordRefType xTab( new ExcTable( GetRoot(), nScTab ) );
     726          14 :             maTableList.AppendRecord( xTab );
     727          14 :             xTab->FillAsTable( nCodeNameIdx );
     728          14 :             ++nCodeNameIdx;
     729             :         }
     730             :     }
     731           9 :     for( ; nCodeNameIdx < nCodeNameCount; ++nScTab, ++nCodeNameIdx )
     732             :     {
     733           0 :         ExcTableList::RecordRefType xTab( new ExcTable( GetRoot(), nScTab ) );
     734           0 :         maTableList.AppendRecord( xTab );
     735           0 :         xTab->FillAsEmptyTable( nCodeNameIdx );
     736           0 :     }
     737             : 
     738           9 :     if ( GetBiff() == EXC_BIFF8 )
     739             :     {
     740             :         // complete temporary Escher stream
     741           9 :         GetObjectManager().EndDocument();
     742             : 
     743             :         // change tracking
     744           9 :         if ( GetDoc().GetChangeTrack() )
     745           0 :             pExpChangeTrack = new XclExpChangeTrack( GetRoot() );
     746             :     }
     747           9 : }
     748             : 
     749             : 
     750           3 : void ExcDocument::Write( SvStream& rSvStrm )
     751             : {
     752           3 :     if( !maTableList.IsEmpty() )
     753             :     {
     754           3 :         InitializeSave();
     755             : 
     756           3 :         XclExpStream aXclStrm( rSvStrm, GetRoot() );
     757             : 
     758           3 :         aHeader.Write( aXclStrm );
     759             : 
     760             :         OSL_ENSURE( maTableList.GetSize() == maBoundsheetList.GetSize(),
     761             :             "ExcDocument::Write - different number of sheets and BOUNDSHEET records" );
     762             : 
     763           8 :         for( size_t nTab = 0, nTabCount = maTableList.GetSize(); nTab < nTabCount; ++nTab )
     764             :         {
     765             :             // set current stream position in BOUNDSHEET record
     766           5 :             ExcBoundsheetRef xBoundsheet = maBoundsheetList.GetRecord( nTab );
     767           5 :             if( xBoundsheet.get() )
     768           5 :                 xBoundsheet->SetStreamPos( aXclStrm.GetSvStreamPos() );
     769             :             // write the table
     770           5 :             maTableList.GetRecord( nTab )->Write( aXclStrm );
     771           5 :         }
     772             : 
     773             :         // write the table stream positions into the BOUNDSHEET records
     774           8 :         for( size_t nBSheet = 0, nBSheetCount = maBoundsheetList.GetSize(); nBSheet < nBSheetCount; ++nBSheet )
     775           8 :             maBoundsheetList.GetRecord( nBSheet )->UpdateStreamPos( aXclStrm );
     776             :     }
     777           3 :     if( pExpChangeTrack )
     778           0 :         pExpChangeTrack->Write();
     779           3 : }
     780             : 
     781           6 : void ExcDocument::WriteXml( XclExpXmlStream& rStrm )
     782             : {
     783           6 :     SfxObjectShell* pDocShell = GetDocShell();
     784             : 
     785             :     using namespace ::com::sun::star;
     786           6 :     uno::Reference<document::XDocumentPropertiesSupplier> xDPS( pDocShell->GetModel(), uno::UNO_QUERY_THROW );
     787          12 :     uno::Reference<document::XDocumentProperties> xDocProps = xDPS->getDocumentProperties();
     788             : 
     789           6 :     rStrm.exportDocumentProperties( xDocProps );
     790             : 
     791           6 :     sax_fastparser::FSHelperPtr& rWorkbook = rStrm.GetCurrentStream();
     792             :     rWorkbook->startElement( XML_workbook,
     793             :             XML_xmlns, "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
     794             :             FSNS(XML_xmlns, XML_r), "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
     795           6 :             FSEND );
     796             :     rWorkbook->singleElement( XML_fileVersion,
     797             :             XML_appName, "Calc",
     798             :             // OOXTODO: XML_codeName
     799             :             // OOXTODO: XML_lastEdited
     800             :             // OOXTODO: XML_lowestEdited
     801             :             // OOXTODO: XML_rupBuild
     802           6 :             FSEND );
     803             : 
     804           6 :     if( !maTableList.IsEmpty() )
     805             :     {
     806           6 :         InitializeSave();
     807             : 
     808           6 :         aHeader.WriteXml( rStrm );
     809             : 
     810          15 :         for( size_t nTab = 0, nTabCount = maTableList.GetSize(); nTab < nTabCount; ++nTab )
     811             :         {
     812             :             // write the table
     813           9 :             maTableList.GetRecord( nTab )->WriteXml( rStrm );
     814             :         }
     815             :     }
     816             : 
     817           6 :     if( pExpChangeTrack )
     818           0 :         pExpChangeTrack->WriteXml( rStrm );
     819             : 
     820           6 :     rWorkbook->endElement( XML_workbook );
     821           6 :     rWorkbook.reset();
     822             : 
     823          12 :     rStrm.commitStorage();
     824          21 : }
     825             : 
     826             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10