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

Generated by: LCOV version 1.10