LCOV - code coverage report
Current view: top level - sc/source/filter/inc - xetable.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 66 71 93.0 %
Date: 2015-06-13 12:38:46 Functions: 78 98 79.6 %
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             : #ifndef INCLUDED_SC_SOURCE_FILTER_INC_XETABLE_HXX
      21             : #define INCLUDED_SC_SOURCE_FILTER_INC_XETABLE_HXX
      22             : 
      23             : #include "xltable.hxx"
      24             : 
      25             : #include <vector>
      26             : #include <tools/mempool.hxx>
      27             : #include "xladdress.hxx"
      28             : #include "xerecord.hxx"
      29             : #include "xestring.hxx"
      30             : #include "xeformula.hxx"
      31             : #include "xestyle.hxx"
      32             : #include "xeextlst.hxx"
      33             : 
      34             : #include <map>
      35             : #include <memory>
      36             : #include <unordered_map>
      37             : #include <unordered_set>
      38             : 
      39             : /* ============================================================================
      40             : Export of cell tables including row and column description.
      41             : - Managing all used and formatted cells in a sheet.
      42             : - Row and column properties, i.e. width/height, visibility.
      43             : - Find default row formatting and default column formatting.
      44             : - Merged cell ranges.
      45             : ============================================================================ */
      46             : 
      47             : // Helper records for cell records
      48             : 
      49             : /** Represents a STRING record that contains the result of a string formula. */
      50           0 : class XclExpStringRec : public XclExpRecord
      51             : {
      52             : public:
      53             :     explicit            XclExpStringRec( const XclExpRoot& rRoot, const OUString& rResult );
      54             : 
      55             : private:
      56             :     virtual void        WriteBody( XclExpStream& rStrm ) SAL_OVERRIDE;
      57             : 
      58             : private:
      59             :     XclExpStringRef     mxResult;
      60             : };
      61             : 
      62             : // Additional records for special formula ranges ==============================
      63             : 
      64             : /** Base record for additional range formula records (i.e. ARRAY, SHRFMLA). */
      65         130 : class XclExpRangeFmlaBase : public XclExpRecord
      66             : {
      67             : public:
      68             :     /** Returns true, if the passed cell position is equal to own base position. */
      69             :     bool                IsBasePos( sal_uInt16 nXclCol, sal_uInt32 nXclRow ) const;
      70             : 
      71             :     /** Derived classes create the token array for a corresponding FORMULA cell record. */
      72             :     virtual XclTokenArrayRef CreateCellTokenArray( const XclExpRoot& rRoot ) const = 0;
      73             :     /** Derived classes return true, if the own formula contains volatile functions. */
      74             :     virtual bool        IsVolatile() const = 0;
      75             : 
      76             : protected:
      77             :     /** Constructs the record with a single cell. */
      78             :     explicit            XclExpRangeFmlaBase(
      79             :                             sal_uInt16 nRecId, sal_uInt32 nRecSize, const ScAddress& rScPos );
      80             :     /** Constructs the record with a cell range. */
      81             :     explicit            XclExpRangeFmlaBase(
      82             :                             sal_uInt16 nRecId, sal_uInt32 nRecSize, const ScRange& rScRange );
      83             : 
      84             :     /** Extends the cell range to include the passed cell address. */
      85             :     void                Extend( const ScAddress& rScPos );
      86             : 
      87             :     /** Writes the range address covered by this record. */
      88             :     void                WriteRangeAddress( XclExpStream& rStrm ) const;
      89             : 
      90             : protected:
      91             :     XclRange            maXclRange;     /// Range described by this record.
      92             :     XclAddress          maBaseXclPos;   /// Address of base cell (first FORMULA record).
      93             : };
      94             : 
      95             : typedef std::shared_ptr< XclExpRangeFmlaBase > XclExpRangeFmlaRef;
      96             : 
      97             : // Array formulas =============================================================
      98             : 
      99             : class ScTokenArray;
     100             : 
     101             : /** Represents an ARRAY record that contains the token array of a matrix formula.
     102             : 
     103             :     An ARRAY record is stored following the first FORMULA record that is part
     104             :     of a matrix formula. All FORMULA records of a matrix formula contain a
     105             :     reference to the ARRAY record, while the ARRAY record contains the formula
     106             :     token array used by all formulas.
     107             :  */
     108           6 : class XclExpArray : public XclExpRangeFmlaBase
     109             : {
     110             : public:
     111             :     explicit            XclExpArray( XclTokenArrayRef xTokArr, const ScRange& rScRange );
     112             : 
     113             :     /** Creates and returns the token array for a corresponding FORMULA cell record. */
     114             :     virtual XclTokenArrayRef CreateCellTokenArray( const XclExpRoot& rRoot ) const SAL_OVERRIDE;
     115             :     /** Returns true, if the array formula contains volatile functions. */
     116             :     virtual bool        IsVolatile() const SAL_OVERRIDE;
     117             : 
     118             : private:
     119             :     virtual void        WriteBody( XclExpStream& rStrm ) SAL_OVERRIDE;
     120             : 
     121             : private:
     122             :     XclTokenArrayRef    mxTokArr;       /// The token array of a matrix formula.
     123             : };
     124             : 
     125             : typedef std::shared_ptr< XclExpArray > XclExpArrayRef;
     126             : 
     127             : /** Caches all ARRAY records. */
     128         129 : class XclExpArrayBuffer : protected XclExpRoot
     129             : {
     130             : public:
     131             :     explicit            XclExpArrayBuffer( const XclExpRoot& rRoot );
     132             : 
     133             :     /** Inserts a new ARRAY record into the buffer and returns it. */
     134             :     XclExpArrayRef      CreateArray( const ScTokenArray& rScTokArr, const ScRange& rScRange );
     135             :     /** Tries to find an ARRAY record that corresponds to an ocMatRef token. */
     136             :     XclExpArrayRef FindArray( const ScTokenArray& rScTokArr, const ScAddress& rBasePos ) const;
     137             : 
     138             : private:
     139             :     typedef ::std::map< ScAddress, XclExpArrayRef > XclExpArrayMap;
     140             :     XclExpArrayMap      maRecMap;       /// Map containing the ARRAY records.
     141             : };
     142             : 
     143             : // Shared formulas ============================================================
     144             : 
     145             : /** Represents a SHRFMLA record that contains the token array of a shared formula.
     146             : 
     147             :     A SHRFMLA record is stored following the first FORMULA record that is part
     148             :     of a shared formula. All FORMULA records of a shared formula contain a
     149             :     reference to the SHRFMLA record, while the SHRFMLA record contains the
     150             :     formula token array used by all formulas.
     151             :  */
     152         254 : class XclExpShrfmla : public XclExpRangeFmlaBase
     153             : {
     154             : public:
     155             :     /** Creates a SHRFMLA record that consists of the passed cell address only. */
     156             :     explicit            XclExpShrfmla( XclTokenArrayRef xTokArr, const ScAddress& rScPos );
     157             : 
     158             :     /** Extends the cell range to include the passed cell address. */
     159             :     void                ExtendRange( const ScAddress& rScPos );
     160             : 
     161             :     /** Creates and returns the token array for a corresponding FORMULA cell record. */
     162             :     virtual XclTokenArrayRef CreateCellTokenArray( const XclExpRoot& rRoot ) const SAL_OVERRIDE;
     163             :     /** Returns true, if the shared formula contains volatile functions. */
     164             :     virtual bool        IsVolatile() const SAL_OVERRIDE;
     165             : 
     166             : private:
     167             :     virtual void        WriteBody( XclExpStream& rStrm ) SAL_OVERRIDE;
     168             : 
     169             : private:
     170             :     XclTokenArrayRef    mxTokArr;       /// The token array of a shared formula.
     171             :     sal_uInt8           mnUsedCount;    /// Number of FORMULA records referring to this record.
     172             : };
     173             : 
     174             : typedef std::shared_ptr< XclExpShrfmla > XclExpShrfmlaRef;
     175             : 
     176             : /** Caches all SHRFMLA records and provides functions to update their ranges. */
     177         129 : class XclExpShrfmlaBuffer : protected XclExpRoot
     178             : {
     179             : public:
     180             :     explicit            XclExpShrfmlaBuffer( const XclExpRoot& rRoot );
     181             : 
     182             :     /** Tries to create a new or to update an existing SHRFMLA record.
     183             :         @return  An empty reference, if the passed token array does not contain
     184             :             a shared formula. If the token array is a shared formula, this
     185             :             function updates its cell range to include the passed cell position,
     186             :             if there is a SHRFMLA record for the passed token array; otherwise
     187             :             this function creates and returns a new SHRFMLA record. */
     188             :     XclExpShrfmlaRef CreateOrExtendShrfmla( const ScFormulaCell& rScCell, const ScAddress& rScPos );
     189             : 
     190             : private:
     191             :     /**
     192             :      * Check for presence of token that's not allowed in Excel's shared
     193             :      * formula. Refer to the "SharedParsedFormula" section of [MS-XLS] spec
     194             :      * for more info.
     195             :      */
     196             :     bool IsValidTokenArray( const ScTokenArray& rArray ) const;
     197             : 
     198             :     typedef std::unordered_map<const ScTokenArray*, XclExpShrfmlaRef> TokensType;
     199             :     typedef std::unordered_set<const ScTokenArray*> BadTokenArraysType;
     200             : 
     201             :     TokensType         maRecMap;    /// Map containing the SHRFMLA records.
     202             :     BadTokenArraysType maBadTokens; /// shared tokens we should *not* export as SHRFMLA
     203             : };
     204             : 
     205             : // Multiple operations ========================================================
     206             : 
     207             : struct XclMultipleOpRefs;
     208             : 
     209             : /** Represents a TABLEOP record for a multiple operations range. */
     210           0 : class XclExpTableop : public XclExpRangeFmlaBase
     211             : {
     212             : public:
     213             :     explicit            XclExpTableop( const ScAddress& rScPos,
     214             :                             const XclMultipleOpRefs& rRefs, sal_uInt8 nScMode );
     215             : 
     216             :     /** Returns true, if the cell range has been extended to the passed position.
     217             :         @descr  All references passed in rRefs must fit the ranges passed in the constructor. */
     218             :     bool                TryExtend( const ScAddress& rScPos, const XclMultipleOpRefs& rRefs );
     219             : 
     220             :     /** Finalizes the record. Tests on valid cell range and reference addresses. */
     221             :     void                Finalize();
     222             : 
     223             :     /** Creates and returns the token array for a corresponding FORMULA cell record. */
     224             :     virtual XclTokenArrayRef CreateCellTokenArray( const XclExpRoot& rRoot ) const SAL_OVERRIDE;
     225             :     /** Returns true, if the multiple operations range is volatile. */
     226             :     virtual bool        IsVolatile() const SAL_OVERRIDE;
     227             :     /** Writes the record if it is valid. */
     228             :     virtual void        Save( XclExpStream& rStrm ) SAL_OVERRIDE;
     229             : 
     230             : private:
     231             :     /** Returns true, if the passed cell position can be appended to this record. */
     232             :     bool                IsAppendable( sal_uInt16 nXclCol, sal_uInt16 nXclRow ) const;
     233             : 
     234             :     /** Writes the contents of the TABLEOP record. */
     235             :     virtual void        WriteBody( XclExpStream& rStrm ) SAL_OVERRIDE;
     236             : 
     237             : private:
     238             :     sal_uInt16          mnLastAppXclCol;/// Column index of last appended cell.
     239             :     sal_uInt16          mnColInpXclCol; /// Column index of column input cell.
     240             :     sal_uInt32          mnColInpXclRow; /// Row index of column input cell.
     241             :     sal_uInt16          mnRowInpXclCol; /// Column index of row input cell.
     242             :     sal_uInt32          mnRowInpXclRow; /// Row index of row input cell.
     243             :     sal_uInt8           mnScMode;       /// Type of the multiple operation (Calc constant).
     244             :     bool                mbValid;        /// true = Contains valid references.
     245             : };
     246             : 
     247             : typedef std::shared_ptr< XclExpTableop > XclExpTableopRef;
     248             : 
     249             : /** Contains all created TABLEOP records and supports creating or updating them. */
     250         129 : class XclExpTableopBuffer : protected XclExpRoot
     251             : {
     252             : public:
     253             :     explicit            XclExpTableopBuffer( const XclExpRoot& rRoot );
     254             : 
     255             :     /** Tries to update an existing or to create a new TABLEOP record.
     256             :         @return  Reference to the TABLEOP record for this cell (existing or new),
     257             :             or an empty reference, if rScTokArr does not contain a multiple
     258             :             operations formula. */
     259             :     XclExpTableopRef    CreateOrExtendTableop(
     260             :                             const ScTokenArray& rScTokArr, const ScAddress& rScPos );
     261             : 
     262             :     /** Finalizes all contained TABLEOP records. */
     263             :     void                Finalize();
     264             : 
     265             : private:
     266             :     /** Tries to create a new TABLEOP record, if rRefs contains valid references. */
     267             :     XclExpTableopRef    TryCreate( const ScAddress& rScPos, const XclMultipleOpRefs& rRefs );
     268             : 
     269             : private:
     270             :     typedef XclExpRecordList< XclExpTableop > XclExpTableopList;
     271             :     XclExpTableopList   maTableopList;  /// List of all TABLEOP records.
     272             : };
     273             : 
     274             : // Cell records
     275             : 
     276             : /** The base class of all cell records. */
     277        4455 : class XclExpCellBase : public XclExpRecord
     278             : {
     279             : public:
     280             :     /** Returns the (first) address of the cell(s). */
     281         948 :     inline const XclAddress& GetXclPos() const { return maXclPos; }
     282             :     /** Returns the (first) Excel column index of the cell(s). */
     283       19160 :     inline sal_uInt16   GetXclCol() const { return maXclPos.mnCol; }
     284             :     /** Returns the Excel row index of the cell. */
     285        5822 :     inline sal_uInt32   GetXclRow() const { return maXclPos.mnRow; }
     286             : 
     287             :     /** Derived classes return the column index of the last contained cell. */
     288             :     virtual sal_uInt16  GetLastXclCol() const = 0;
     289             :     /** Derived classes return the XF identifier of the first contained cell. */
     290             :     virtual sal_uInt32  GetFirstXFId() const = 0;
     291             :     /** Derived classes return true, if this record does not contain at least one valid cell. */
     292             :     virtual bool        IsEmpty() const = 0;
     293             :     /** Derived classes return whether the cell contains multi-line text. */
     294             :     virtual bool        IsMultiLineText() const;
     295             : 
     296             :     /** Derived classes try to merge the contents of the passed cell to own data. */
     297             :     virtual bool        TryMerge( const XclExpCellBase& rCell );
     298             :     /** Derived classes convert the XF identifier(s) into the Excel XF index(es).
     299             :         @param rXFIndexes  The converted XF index(es) are inserted here. */
     300             :     virtual void        ConvertXFIndexes( const XclExpRoot& rRoot ) = 0;
     301             :     /** Derived classes for blank cells insert the Excel XF index(es) into the passed vector. */
     302             :     virtual void        GetBlankXFIndexes( ScfUInt16Vec& rXFIndexes ) const;
     303             :     /** Derived classes for blank cells remove unused Excel XF index(es). */
     304             :     virtual void        RemoveUnusedBlankCells( const ScfUInt16Vec& rXFIndexes );
     305             : 
     306             : protected:
     307             :     explicit            XclExpCellBase(
     308             :                             sal_uInt16 nRecId, sal_Size nContSize, const XclAddress& rXclPos );
     309             : 
     310             :     /** Sets this record to a new column position. */
     311        1064 :     inline void         SetXclCol( sal_uInt16 nXclCol ) { maXclPos.mnCol = nXclCol; }
     312             :     /** Sets this record to a new row position. */
     313             :     inline void         SetXclRow( sal_uInt32 nXclRow ) { maXclPos.mnRow = nXclRow; }
     314             : 
     315             : private:
     316             :     XclAddress          maXclPos;       /// Address of the cell.
     317             : };
     318             : 
     319             : typedef std::shared_ptr< XclExpCellBase > XclExpCellRef;
     320             : 
     321             : // Single cell records ========================================================
     322             : 
     323             : /** Base class for all cell records not supporting multiple contents. */
     324        1793 : class XclExpSingleCellBase : public XclExpCellBase
     325             : {
     326             : public:
     327             :     /** Returns the last column, which is equal to the first column for single cells. */
     328             :     virtual sal_uInt16  GetLastXclCol() const SAL_OVERRIDE;
     329             :     /** Return the XF identifier of the cell. */
     330             :     virtual sal_uInt32  GetFirstXFId() const SAL_OVERRIDE;
     331             :     /** Returns true, if this record does not contain at least one valid cell. */
     332             :     virtual bool        IsEmpty() const SAL_OVERRIDE;
     333             :     /** Converts the XF identifier into the Excel XF index. */
     334             :     virtual void        ConvertXFIndexes( const XclExpRoot& rRoot ) SAL_OVERRIDE;
     335             :     /** Writes cell address, XF index, and calls WriteContents() for each cell. */
     336             :     virtual void        Save( XclExpStream& rStrm ) SAL_OVERRIDE;
     337             : 
     338             : protected:
     339             :     explicit            XclExpSingleCellBase( sal_uInt16 nRecId, sal_Size nContSize,
     340             :                             const XclAddress& rXclPos, sal_uInt32 nXFId );
     341             : 
     342             :     explicit            XclExpSingleCellBase( const XclExpRoot& rRoot,
     343             :                             sal_uInt16 nRecId, sal_Size nContSize, const XclAddress& rXclPos,
     344             :                             const ScPatternAttr* pPattern, sal_Int16 nScript, sal_uInt32 nForcedXFId );
     345             : 
     346        1011 :     inline void         SetContSize( sal_Size nContSize ) { mnContSize = nContSize; }
     347           0 :     inline sal_Size     GetContSize() const { return mnContSize; }
     348             : 
     349        1793 :     inline void         SetXFId( sal_uInt32 nXFId ) { maXFId.mnXFId = nXFId; }
     350        3196 :     inline sal_uInt32   GetXFId() const { return maXFId.mnXFId; }
     351             : 
     352             : private:
     353             :     /** Writes cell address, XF index, and calls WriteContents() for each cell. */
     354             :     virtual void        WriteBody( XclExpStream& rStrm ) SAL_OVERRIDE;
     355             :     /** Derived classes write the contents of the specified cell (without XF index). */
     356             :     virtual void        WriteContents( XclExpStream& rStrm ) = 0;
     357             : 
     358             : private:
     359             :     XclExpXFId          maXFId;         /// The XF identifier of the cell formatting.
     360             :     sal_Size            mnContSize;     /// The size of the cell contents.
     361             : };
     362             : 
     363             : /** Represents a NUMBER record that describes a cell with a double value. */
     364         466 : class XclExpNumberCell : public XclExpSingleCellBase
     365             : {
     366         466 :     DECL_FIXEDMEMPOOL_NEWDEL( XclExpNumberCell )
     367             : 
     368             : public:
     369             :     explicit            XclExpNumberCell( const XclExpRoot& rRoot, const XclAddress& rXclPos,
     370             :                             const ScPatternAttr* pPattern, sal_uInt32 nForcedXFId,
     371             :                             double fValue );
     372             : 
     373             :     virtual void        SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
     374             : private:
     375             :     virtual void        WriteContents( XclExpStream& rStrm ) SAL_OVERRIDE;
     376             : 
     377             : private:
     378             :     double              mfValue;        /// The cell value.
     379             : };
     380             : 
     381             : /** Represents a BOOLERR record that describes a cell with a Boolean value. */
     382           0 : class XclExpBooleanCell : public XclExpSingleCellBase
     383             : {
     384           0 :     DECL_FIXEDMEMPOOL_NEWDEL( XclExpBooleanCell )
     385             : 
     386             : public:
     387             :     explicit            XclExpBooleanCell( const XclExpRoot& rRoot, const XclAddress& rXclPos,
     388             :                             const ScPatternAttr* pPattern, sal_uInt32 nForcedXFId,
     389             :                             bool bValue );
     390             : 
     391             :     virtual void        SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
     392             : private:
     393             :     virtual void        WriteContents( XclExpStream& rStrm ) SAL_OVERRIDE;
     394             : 
     395             : private:
     396             :     bool                mbValue;        /// The cell value.
     397             : };
     398             : 
     399             : class XclExpHyperlinkHelper;
     400             : class EditTextObject;
     401             : 
     402             : /** Represents a text cell record.
     403             : 
     404             :     May contain a BIFF2-BIFF7 LABEL record for a simple string, or a BIFF2-BIFF7
     405             :     RSTRING record for a formatted string, or a BIFF8 LABELSST string for any
     406             :     string (simply stores a reference to the Shared String Table).
     407             :  */
     408         898 : class XclExpLabelCell : public XclExpSingleCellBase
     409             : {
     410         898 :     DECL_FIXEDMEMPOOL_NEWDEL( XclExpLabelCell )
     411             : 
     412             : public:
     413             :     /** Constructs the record from an unformatted Calc string cell. */
     414             :     explicit            XclExpLabelCell( const XclExpRoot& rRoot, const XclAddress& rXclPos,
     415             :                             const ScPatternAttr* pPattern, sal_uInt32 nForcedXFId,
     416             :                             const OUString& rStr );
     417             : 
     418             :     /** Constructs the record from a formatted Calc edit cell. */
     419             :     explicit            XclExpLabelCell( const XclExpRoot& rRoot, const XclAddress& rXclPos,
     420             :                             const ScPatternAttr* pPattern, sal_uInt32 nForcedXFId,
     421             :                             const EditTextObject* pEditText, XclExpHyperlinkHelper& rHlinkHelper );
     422             : 
     423             :     /** Returns true if the cell contains multi-line text. */
     424             :     virtual bool        IsMultiLineText() const SAL_OVERRIDE;
     425             : 
     426             :     virtual void        SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
     427             : private:
     428             :     /** Initializes the record contents. Called from constructors. */
     429             :     void                Init( const XclExpRoot& rRoot,
     430             :                             const ScPatternAttr* pPattern, XclExpStringRef xText );
     431             : 
     432             :     virtual void        WriteContents( XclExpStream& rStrm ) SAL_OVERRIDE;
     433             : 
     434             : private:
     435             :     XclExpStringRef     mxText;         /// The cell text.
     436             :     sal_uInt32          mnSstIndex;     /// Index into Shared String Table (only used for BIFF8).
     437             :     bool                mbLineBreak;    /// True = cell has automatic linebreaks enabled.
     438             : };
     439             : 
     440             : class ScFormulaCell;
     441             : 
     442             : /** Represents a FORMULA record that describes a cell with a formula. */
     443        2222 : class XclExpFormulaCell : public XclExpSingleCellBase
     444             : {
     445        2222 :     DECL_FIXEDMEMPOOL_NEWDEL( XclExpFormulaCell )
     446             : 
     447             : public:
     448             :     explicit            XclExpFormulaCell( const XclExpRoot& rRoot, const XclAddress& rXclPos,
     449             :                             const ScPatternAttr* pPattern, sal_uInt32 nForcedXFId,
     450             :                             const ScFormulaCell& rScFmlaCell,
     451             :                             XclExpArrayBuffer& rArrayBfr,
     452             :                             XclExpShrfmlaBuffer& rShrfmlaBfr,
     453             :                             XclExpTableopBuffer& rTableopBfr );
     454             : 
     455             :     /** Writes the FORMULA record and additional records related to the formula. */
     456             :     virtual void        Save( XclExpStream& rStrm ) SAL_OVERRIDE;
     457             :     virtual void        SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
     458             : 
     459             : private:
     460             :     virtual void        WriteContents( XclExpStream& rStrm ) SAL_OVERRIDE;
     461             : 
     462             : private:
     463             :     ScFormulaCell&      mrScFmlaCell;   /// The Calc formula cell.
     464             :     XclTokenArrayRef    mxTokArr;       /// The token array of the formula.
     465             :     XclExpRangeFmlaRef  mxAddRec;       /// Additional record for matrix/shared formulas.
     466             :     XclExpRecordRef     mxStringRec;    /// STRING record for string result.
     467             : };
     468             : 
     469             : // Multiple cell records ======================================================
     470             : 
     471             : struct XclExpMultiXFId : public XclExpXFId
     472             : {
     473             :     sal_uInt16          mnCount;        /// Number of XF identifiers.
     474             : 
     475        3469 :     inline explicit     XclExpMultiXFId( sal_uInt32 nXFId, sal_uInt16 nCount = 1 ) :
     476        3469 :                             XclExpXFId( nXFId ), mnCount( nCount ) {}
     477             : };
     478             : 
     479             : /** Base class for all cell records supporting multiple contents. */
     480        2662 : class XclExpMultiCellBase : public XclExpCellBase
     481             : {
     482             : public:
     483             :     /** Returns the column index of the last cell this record describes. */
     484             :     virtual sal_uInt16  GetLastXclCol() const SAL_OVERRIDE;
     485             :     /** Return the XF identifier of the first contained cell. */
     486             :     virtual sal_uInt32  GetFirstXFId() const SAL_OVERRIDE;
     487             :     /** Returns true, if this record does not contain at least one valid cell. */
     488             :     virtual bool        IsEmpty() const SAL_OVERRIDE;
     489             : 
     490             :     /** Convert all XF identifiers into the Excel XF indexes. */
     491             :     virtual void        ConvertXFIndexes( const XclExpRoot& rRoot ) SAL_OVERRIDE;
     492             :     /** Writes the record, calls WriteContents() for each contained cell.
     493             :         @descr  May write several records, if unused XF indexes are contained. */
     494             :     virtual void        Save( XclExpStream& rStrm ) SAL_OVERRIDE;
     495             :     virtual void        SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
     496             : 
     497             : protected:
     498             :     explicit            XclExpMultiCellBase( sal_uInt16 nRecId, sal_uInt16 nMulRecId,
     499             :                             sal_Size nContSize, const XclAddress& rXclPos );
     500             : 
     501             :     /** Sets the size of the remaining contents of one cell (without the XF index). */
     502             :     inline void         SetContSize( sal_Size nContSize ) { mnContSize = nContSize; }
     503             :     /** Returns the size of the remaining contents of one cell (without the XF index). */
     504             :     inline sal_Size     GetContSize() const { return mnContSize; }
     505             : 
     506             :     /** Returns the number of cells this record represents. */
     507             :     sal_uInt16          GetCellCount() const;
     508             : 
     509             :     /** Appends the passed XF identifier nCount times to the list of XF identifiers. */
     510             :     void                AppendXFId( const XclExpMultiXFId& rXFId );
     511             :     /** Appends the passed cell format nCount times to the list of XF identifiers. */
     512             :     void                AppendXFId( const XclExpRoot& rRoot,
     513             :                             const ScPatternAttr* pPattern, sal_uInt16 nScript,
     514             :                             sal_uInt32 nForcedXFId, sal_uInt16 nCount = 1 );
     515             : 
     516             :     /** Tries to merge the XF ID list of the passed cell with the own list. */
     517             :     bool                TryMergeXFIds( const XclExpMultiCellBase& rCell );
     518             :     /** Inserts the Excel XF index(es) into the passed vector. */
     519             :     void                GetXFIndexes( ScfUInt16Vec& rXFIndexes ) const;
     520             : 
     521             :     /** Removes unused Excel XF index(es).
     522             :         @param rXFIndexes  Specifies which XF indexes are used. */
     523             :     void                RemoveUnusedXFIndexes( const ScfUInt16Vec& rXFIndexes );
     524             : 
     525             : private:
     526             :     /** Derived classes write the remaining contents of the specified cell (without XF index).
     527             :         @param nRelCol  Relative column index (starts with 0 for first cell of this record). */
     528             :     virtual void        WriteContents( XclExpStream& rStrm, sal_uInt16 nRelCol ) = 0;
     529             :     virtual void        WriteXmlContents( XclExpXmlStream& rStrm, const XclAddress& rAddress, sal_uInt32 nXFId, sal_uInt16 nRelCol ) = 0;
     530             : 
     531             : private:
     532             :     typedef ::std::vector< XclExpMultiXFId > XclExpMultiXFIdDeq;
     533             : 
     534             :     sal_uInt16          mnMulRecId;     /// Record ID for multiple record variant.
     535             :     sal_Size            mnContSize;     /// Data size of contents for one cell
     536             :     XclExpMultiXFIdDeq  maXFIds;        /// The XF identifiers of the cell formatting.
     537             : };
     538             : 
     539             : /** Represents a BLANK or MULBLANK record that describes empty but formatted cells. */
     540        3328 : class XclExpBlankCell : public XclExpMultiCellBase
     541             : {
     542        3328 :     DECL_FIXEDMEMPOOL_NEWDEL( XclExpBlankCell )
     543             : 
     544             : public:
     545             :     explicit            XclExpBlankCell( const XclAddress& rXclPos, const XclExpMultiXFId& rXFId );
     546             : 
     547             :     explicit            XclExpBlankCell( const XclExpRoot& rRoot,
     548             :                             const XclAddress& rXclPos, sal_uInt16 nLastXclCol,
     549             :                             const ScPatternAttr* pPattern, sal_uInt32 nForcedXFId );
     550             : 
     551             :     /** Tries to merge the contents of the passed cell to own data. */
     552             :     virtual bool        TryMerge( const XclExpCellBase& rCell ) SAL_OVERRIDE;
     553             :     /** Inserts the Excel XF index(es) into the passed vector. */
     554             :     virtual void        GetBlankXFIndexes( ScfUInt16Vec& rXFIndexes ) const SAL_OVERRIDE;
     555             :     /** Tries to remove unused Excel XF index(es). */
     556             :     virtual void        RemoveUnusedBlankCells( const ScfUInt16Vec& rXFIndexes ) SAL_OVERRIDE;
     557             : 
     558             : private:
     559             :     /** Writes the remaining contents of the specified cell (without XF index). */
     560             :     virtual void        WriteContents( XclExpStream& rStrm, sal_uInt16 nRelCol ) SAL_OVERRIDE;
     561             :     virtual void        WriteXmlContents( XclExpXmlStream& rStrm, const XclAddress& rAddress, sal_uInt32 nXFId, sal_uInt16 nRelCol ) SAL_OVERRIDE;
     562             : };
     563             : 
     564             : /** Represents an RK or MULRK record that describes cells with a compressed double values. */
     565        1996 : class XclExpRkCell : public XclExpMultiCellBase
     566             : {
     567        1996 :     DECL_FIXEDMEMPOOL_NEWDEL( XclExpRkCell )
     568             : 
     569             : public:
     570             :     explicit            XclExpRkCell( const XclExpRoot& rRoot, const XclAddress& rXclPos,
     571             :                             const ScPatternAttr* pPattern, sal_uInt32 nForcedXFId,
     572             :                             sal_Int32 nRkValue );
     573             : 
     574             :     /** Tries to merge the contents of the passed cell to own data. */
     575             :     virtual bool        TryMerge( const XclExpCellBase& rCell ) SAL_OVERRIDE;
     576             : 
     577             : private:
     578             :     /** Writes the remaining contents of the specified cell (without XF index). */
     579             :     virtual void        WriteContents( XclExpStream& rStrm, sal_uInt16 nRelCol ) SAL_OVERRIDE;
     580             :     virtual void        WriteXmlContents( XclExpXmlStream& rStrm, const XclAddress& rAddress, sal_uInt32 nXFId, sal_uInt16 nRelCol ) SAL_OVERRIDE;
     581             : 
     582             : private:
     583             :     ScfInt32Vec         maRkValues;     /// The cell values.
     584             : };
     585             : 
     586             : // Rows and Columns
     587             : 
     588             : class ScOutlineArray;
     589             : 
     590             : /** Base class for buffers containing row or column outline data. */
     591         258 : class XclExpOutlineBuffer
     592             : {
     593             : public:
     594             :     /** Returns true, if a collapsed group ends at the last processed position. */
     595      110743 :     inline bool         IsCollapsed() const { return mbCurrCollapse; }
     596             :     /** Returns the highest level of an open group at the last processed position. */
     597      111662 :     inline sal_uInt8    GetLevel() const { return ::std::min( mnCurrLevel, EXC_OUTLINE_MAX ); }
     598             : 
     599             : protected:
     600             :     /** Constructs the outline buffer.
     601             :         @param bRows  true = Process row ouline array; false = Process column outline array. */
     602             :     explicit            XclExpOutlineBuffer( const XclExpRoot& rRoot, bool bRows );
     603             : 
     604             :     /** Updates the current state by processing the settings at the passed Calc position. */
     605             :     void                UpdateColRow( SCCOLROW nScPos );
     606             : 
     607             : private:
     608             :     /** Data about an outline level. */
     609             :     struct XclExpLevelInfo
     610             :     {
     611             :         SCCOLROW            mnScEndPos;         /// The end position of a group in a level.
     612             :         bool                mbHidden;           /// true = Group in this level is hidden.
     613        1806 :         inline explicit     XclExpLevelInfo() : mnScEndPos( 0 ), mbHidden( false ) {}
     614             :     };
     615             :     typedef ::std::vector< XclExpLevelInfo > XclExpLevelInfoVec;
     616             : 
     617             :     const ScOutlineArray* mpScOLArray;      /// Pointer to Calc outline array.
     618             :     XclExpLevelInfoVec  maLevelInfos;       /// Info for current row and all levels.
     619             :     sal_uInt8           mnCurrLevel;        /// Highest level of an open group for current position.
     620             :     bool                mbCurrCollapse;     /// true = Collapsed group ends at current position.
     621             : };
     622             : 
     623             : /** The outline buffer for column outlines. */
     624         129 : class XclExpColOutlineBuffer : public XclExpOutlineBuffer
     625             : {
     626             : public:
     627         129 :     inline explicit     XclExpColOutlineBuffer( const XclExpRoot& rRoot ) :
     628         129 :                             XclExpOutlineBuffer( rRoot, false ) {}
     629             : 
     630             :     /** Updates the current state by processing the settings of the passed Calc column. */
     631      109824 :     inline void         Update( SCCOL nScCol )
     632      109824 :                             { UpdateColRow( static_cast< SCCOLROW >( nScCol ) ); }
     633             : };
     634             : 
     635             : /** The outline buffer for row outlines. */
     636         129 : class XclExpRowOutlineBuffer : public XclExpOutlineBuffer
     637             : {
     638             : public:
     639         129 :     inline explicit     XclExpRowOutlineBuffer( const XclExpRoot& rRoot ) :
     640         129 :                             XclExpOutlineBuffer( rRoot, true ) {}
     641             : 
     642             :     /** Updates the current state by processing the settings of the passed Calc row. */
     643         919 :     inline void         Update( SCROW nScRow )
     644         919 :                             { UpdateColRow( static_cast< SCCOLROW >( nScRow ) ); }
     645             : };
     646             : 
     647             : /** Represents a GUTS record containing the level count of row and column outlines. */
     648         258 : class XclExpGuts : public XclExpRecord
     649             : {
     650             : public:
     651             :     explicit            XclExpGuts( const XclExpRoot& rRoot );
     652             : 
     653             : private:
     654             :     virtual void        WriteBody( XclExpStream& rStrm ) SAL_OVERRIDE;
     655             : 
     656             : private:
     657             :     sal_uInt16          mnColLevels;    /// Number of visible column outline levels.
     658             :     sal_uInt16          mnColWidth;     /// Width of column outline area (pixels).
     659             :     sal_uInt16          mnRowLevels;    /// Number of visible row outline levels.
     660             :     sal_uInt16          mnRowWidth;     /// Width of row outline area (pixels).
     661             : };
     662             : 
     663             : /** Represents a DIMENSIONS record containing the used area of a sheet. */
     664         129 : class XclExpDimensions : public XclExpRecord
     665             : {
     666             : public:
     667             :     explicit            XclExpDimensions( const XclExpRoot& rRoot );
     668             : 
     669             :     /** Sets the used area to the record. */
     670             :     void                SetDimensions(
     671             :                             sal_uInt16 nFirstUsedXclCol, sal_uInt32 nFirstUsedXclRow,
     672             :                             sal_uInt16 nFirstFreeXclCol, sal_uInt32 nFirstFreeXclRow );
     673             : 
     674             :     virtual void        SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
     675             : private:
     676             :     /** Writes the contents of the DIMENSIONS record. */
     677             :     virtual void        WriteBody( XclExpStream& rStrm ) SAL_OVERRIDE;
     678             : 
     679             : private:
     680             :     sal_uInt32          mnFirstUsedXclRow;  /// First used row.
     681             :     sal_uInt32          mnFirstFreeXclRow;  /// First unused row after used area.
     682             :     sal_uInt16          mnFirstUsedXclCol;  /// First used column.
     683             :     sal_uInt16          mnFirstFreeXclCol;  /// First free column after used area.
     684             : };
     685             : 
     686             : /** Represents the DEFCOLWIDTH record containing the default column width of a sheet.
     687             : 
     688             :     Excel stores the default column width in entire character widths of the '0'
     689             :     character using the application default font (i.e. the default width is 10,
     690             :     if the '0' character fits 10 times into a cell in a column with default
     691             :     width.
     692             : 
     693             :     The IsDefWidth() function returns true, if the passed width (measured in
     694             :     1/256 of the width of the '0' character) could be converted exactly to the
     695             :     default width. If the passed width is rounded up or down to get the default
     696             :     width, the function returns false.
     697             :  */
     698         129 : class XclExpDefcolwidth : public XclExpUInt16Record, protected XclExpRoot
     699             : {
     700             : public:
     701             :     explicit            XclExpDefcolwidth( const XclExpRoot& rRoot );
     702             : 
     703             :     /** Returns true, if the own default width exactly matches the passed width. */
     704             :     bool                IsDefWidth( sal_uInt16 nXclColWidth ) const;
     705             : 
     706             :     /** Sets the passed column width (in 1/256 character width) as default width. */
     707             :     void                SetDefWidth( sal_uInt16 nXclColWidth );
     708             : };
     709             : 
     710             : /** Contains the column settings for a range of columns.
     711             : 
     712             :     After construction the record contains a temporary XF identifier returned
     713             :     from the XF buffer. After creating the entire Excel document in memory, the
     714             :     ConvertXFIndexes() function converts it into the real Excel XF index.
     715             :  */
     716      219648 : class XclExpColinfo : public XclExpRecord, protected XclExpRoot
     717             : {
     718             : public:
     719             :     /** Constructs the record with the settings in the Calc document. */
     720             :     explicit            XclExpColinfo( const XclExpRoot& rRoot,
     721             :                             SCCOL nScCol, SCROW nLastScRow,
     722             :                             XclExpColOutlineBuffer& rOutlineBfr );
     723             : 
     724             :     /** Converts the XF identifier into the Excel XF index, returns the latter. */
     725             :     sal_uInt16          ConvertXFIndexes();
     726             : 
     727             :     /** Tries to merge this record with the passed record.
     728             :         @descr  Possible, if passed record directly follows this record and has equal contents.
     729             :         @return  true = This record is equal to passed record and has been updated. */
     730             :     bool                TryMerge( const XclExpColinfo& rColInfo );
     731             : 
     732             :     /** Returns the Excel width of the column(s). */
     733         188 :     inline sal_uInt16   GetColWidth() const { return mnWidth; }
     734             :     /** Returns the final Excel XF index of the column(s). */
     735         188 :     inline sal_uInt16   GetXFIndex() const { return maXFId.mnXFIndex; }
     736             :     /** Returns the number of columns represented by this record. */
     737         188 :     inline sal_uInt16   GetColCount() const { return mnLastXclCol - mnFirstXclCol + 1; }
     738             : 
     739             :     /** Returns true, if the column has default format and width. */
     740             :     bool                IsDefault( const XclExpDefcolwidth& rDefColWidth ) const;
     741             : 
     742             :     virtual void        SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
     743             : 
     744             : private:
     745             :     /** Writes the contents of this COLINFO record. */
     746             :     virtual void        WriteBody( XclExpStream& rStrm ) SAL_OVERRIDE;
     747             : 
     748             : private:
     749             :     XclExpXFId          maXFId;             /// The XF identifier for column default format.
     750             :     sal_uInt16          mnWidth;            /// Excel width of the column.
     751             :     sal_uInt16          mnScWidth;          /// Calc width of the column.
     752             :     sal_uInt16          mnFlags;            /// Additional column flags.
     753             :     sal_uInt16          mnFirstXclCol;      /// Index to first column.
     754             :     sal_uInt16          mnLastXclCol;       /// Index to last column.
     755             : };
     756             : 
     757             : /** Contains COLINFO records for all columns of a Calc sheet.
     758             : 
     759             :     On construction one COLINFO record per column is created. After creating
     760             :     the entire Excel document in memory, the ConvertXFIndexes() function converts
     761             :     all temporary XF identifiers into real Excel XF indexes and merges all equal
     762             :     COLINFO records together.
     763             :  */
     764         129 : class XclExpColinfoBuffer : public XclExpRecordBase, protected XclExpRoot
     765             : {
     766             : public:
     767             :     explicit            XclExpColinfoBuffer( const XclExpRoot& rRoot );
     768             : 
     769             :     /** Initializes the buffer: finds settings and formatting of all columns.
     770             :         @param nLastScRow  Last row used to find default formatting. */
     771             :     void                Initialize( SCROW nLastScRow );
     772             :     /** Converts the XF identifiers into the Excel XF indexes and merges equal columns.
     773             :         @param rXFIndexes  Returns the final XF indexes of all columns. */
     774             :     void                Finalize( ScfUInt16Vec& rXFIndexes );
     775             : 
     776             :     /** Writes all COLINFO records of this buffer. */
     777             :     virtual void        Save( XclExpStream& rStrm ) SAL_OVERRIDE;
     778             :     virtual void        SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
     779             : 
     780             : private:
     781             :     typedef XclExpRecordList< XclExpColinfo >   XclExpColinfoList;
     782             :     typedef XclExpColinfoList::RecordRefType    XclExpColinfoRef;
     783             : 
     784             :     XclExpColinfoList   maColInfos;         /// List of COLINFO records.
     785             :     XclExpDefcolwidth   maDefcolwidth;      /// The DEFCOLWIDTH record.
     786             :     XclExpColOutlineBuffer maOutlineBfr;    /// Buffer for column outline groups.
     787             : };
     788             : 
     789             : class XclExpRow;
     790             : 
     791             : /** Contains all possible default row settings. */
     792             : struct XclExpDefaultRowData
     793             : {
     794             :     sal_uInt16          mnFlags;            /// Default flags for unspecified rows.
     795             :     sal_uInt16          mnHeight;           /// Default height for unspecified rows.
     796             : 
     797             :     explicit            XclExpDefaultRowData();
     798             :     explicit            XclExpDefaultRowData( const XclExpRow& rRow );
     799             : 
     800             :     /** Returns true, if rows are hidden by default. */
     801         283 :     inline bool         IsHidden() const { return ::get_flag( mnFlags, EXC_DEFROW_HIDDEN ); }
     802             :     /** Returns true, if the rows have a manually set height by default. */
     803         283 :     inline bool         IsUnsynced() const { return ::get_flag( mnFlags, EXC_DEFROW_UNSYNCED ); }
     804             : };
     805             : 
     806             : /** Represents a DEFROWHEIGHT record containing default format for unused rows. */
     807         258 : class XclExpDefrowheight : public XclExpRecord
     808             : {
     809             : public:
     810             :     explicit            XclExpDefrowheight();
     811             : 
     812             :     /** Sets the passed default data as current record contents. */
     813             :     void                SetDefaultData( const XclExpDefaultRowData& rDefData );
     814         100 :     XclExpDefaultRowData& GetDefaultData() { return maDefData; }
     815             : private:
     816             :     /** Writes the contents of the record. */
     817             :     virtual void        WriteBody( XclExpStream& rStrm ) SAL_OVERRIDE;
     818             : 
     819             : private:
     820             :     XclExpDefaultRowData maDefData;         /// Record data.
     821             : };
     822             : 
     823             : /** Represents a ROW record and additionally contains all cells records of a row.
     824             : 
     825             :     This class contains all cell records of a row in a spreadsheet. There are 2
     826             :     cell records in Excel that support storing a range of cells in one record
     827             :     (MULBLANK for multiple blank cells, and MULRK for multiple RK values). The
     828             :     insertion functions try to merge a new inserted cell with existing
     829             :     neighbors, if this is supported by the current type of cell record.
     830             : 
     831             :     The Finalize() function converts the XF identifiers of all cell records to
     832             :     the final Excel XF indexes. Then a default
     833             :  */
     834        1838 : class XclExpRow : public XclExpRecord, protected XclExpRoot
     835             : {
     836             : public:
     837             :     /** Constructs the ROW record and converts the Calc row settings.
     838             :         @param bAlwaysEmpty  true = This row will not be filled with blank cells
     839             :             in the Finalize() function. */
     840             :     explicit            XclExpRow( const XclExpRoot& rRoot, sal_uInt32 nXclRow,
     841             :                             XclExpRowOutlineBuffer& rOutlineBfr, bool bAlwaysEmpty );
     842             : 
     843             :     /** Returns the excel row index of this ROW record. */
     844        1336 :     inline sal_uInt32   GetXclRow() const { return mnXclRow; }
     845             :     /** Returns the height of the row in twips. */
     846         617 :     inline sal_uInt16   GetHeight() const { return mnHeight; }
     847             :     /** Returns true, if this row does not contain at least one valid cell. */
     848        3535 :     inline bool         IsEmpty() const { return maCellList.IsEmpty(); }
     849             :     /** Returns true, if this row is hidden. */
     850         772 :     inline bool         IsHidden() const { return ::get_flag( mnFlags, EXC_ROW_HIDDEN ); }
     851             :     /** Returns true, if this row contains a manually set height. */
     852         772 :     inline bool         IsUnsynced() const { return ::get_flag( mnFlags, EXC_ROW_UNSYNCED ); }
     853             :     /** Returns true, if this row is enabled (will be exported). */
     854        1527 :     inline bool         IsEnabled() const { return mbEnabled; }
     855             : 
     856             :     /** Appends the passed cell object to this row. */
     857             :     void                AppendCell( XclExpCellRef xCell, bool bIsMergedBase );
     858             : 
     859             :     /** Converts all XF identifiers into the Excel XF indexes. */
     860             :     void                Finalize( const ScfUInt16Vec& rColXFIndexes,
     861             :                                   bool bUpdateProgress );
     862             : 
     863             :     /** Returns the column index of the first used cell in this row.
     864             :         @descr  This function can only be called after Finalize(). */
     865             :     sal_uInt16          GetFirstUsedXclCol() const;
     866             :     /** Returns the column index of the first unused cell following all used cells in this row.
     867             :         @descr  This function can only be called after Finalize(). */
     868             :     sal_uInt16          GetFirstFreeXclCol() const;
     869             : 
     870             :     /** Returns true, if this row may be omitted by using the DEFROWHEIGHT record.
     871             :         @descr  A row may be omitted, if it does not contain any cell or
     872             :         explicit default cell formatting, and is not part of an outline.
     873             :         This function can only be called after Finalize(). */
     874             :     bool                IsDefaultable() const;
     875             :     /** Disables this row, if it is defaultable and has the passed default format.
     876             :         @descr  Disabled rows will not be saved.
     877             :             This function can only be called after Finalize(). */
     878             :     void                DisableIfDefault( const XclExpDefaultRowData& rDefRowData );
     879             : 
     880             :     /** Writes all cell records of this row. */
     881             :     void                WriteCellList( XclExpStream& rStrm );
     882             : 
     883             :     /** Writes the ROW record if the row is not disabled (see DisableIfDefault() function). */
     884             :     virtual void        Save( XclExpStream& rStrm ) SAL_OVERRIDE;
     885             :     virtual void        SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
     886             : 
     887         308 :     inline sal_uInt32   GetXclRowRpt() const { return mnXclRowRpt; }
     888         296 :     inline void         SetXclRowRpt( sal_uInt32 nRpt ){ mnXclRowRpt = nRpt; }
     889             : private:
     890             :     /** Initializes the record data. Called from constructors. */
     891             :     void                Init( sal_uInt16 nXclRow, XclExpRowOutlineBuffer* pOutlineBfr );
     892             :     /** Inserts a cell at the specified list position, tries to merge with neighbors. */
     893             :     void                InsertCell( XclExpCellRef xCell, size_t nPos, bool bIsMergedBase );
     894             : 
     895             :     /** Writes the contents of the ROW record. */
     896             :     virtual void        WriteBody( XclExpStream& rStrm ) SAL_OVERRIDE;
     897             : 
     898             : private:
     899             :     typedef XclExpRecordList< XclExpCellBase > XclExpCellList;
     900             : 
     901             :     XclExpCellList      maCellList;         /// List of cell records for this row.
     902             :     sal_uInt32          mnXclRow;           /// Excel row index of this row.
     903             :     sal_uInt16          mnHeight;           /// Row height in twips.
     904             :     sal_uInt16          mnFlags;            /// Flags for the ROW record.
     905             :     sal_uInt16          mnXFIndex;          /// Default row formatting.
     906             :     sal_uInt16          mnOutlineLevel;     /// Outline Level (for OOXML)
     907             :     sal_uInt32          mnXclRowRpt;
     908             :     sal_uInt32          mnCurrentRow;
     909             :     bool                mbAlwaysEmpty;      /// true = Do not add blank cells in Finalize().
     910             :     bool                mbEnabled;          /// true = Write this ROW record.
     911             : };
     912             : 
     913             : /** Collects all rows which contain all cells of a sheet.
     914             : 
     915             :     This row buffer automatically creates ROW records when cells are inserted
     916             :     with the AppendCell() function. It is possible to force creation of more
     917             :     ROW records with the CreateRows() function. In both cases, all preceding
     918             :     missing ROW records are inserted too.
     919             :  */
     920         129 : class XclExpRowBuffer : public XclExpRecordBase, protected XclExpRoot
     921             : {
     922             : public:
     923             :     explicit            XclExpRowBuffer( const XclExpRoot& rRoot );
     924             : 
     925             :     /** Appends the passed cell object to the row that the cell specifies. */
     926             :     void                AppendCell( XclExpCellRef xCell, bool bIsMergedBase );
     927             :     /** Forces insertion of all ROW records before the passed row. */
     928             :     void                CreateRows( SCROW nFirstFreeScRow );
     929             : 
     930             :     /** Converts all XF identifiers into the Excel XF indexes and calculates default formats.
     931             :         @param rDefRowData  (out-param) The default row format is returned here.
     932             :         @param rColXFIndexes  The column default XF indexes. */
     933             :     void                Finalize( XclExpDefaultRowData& rDefRowData, const ScfUInt16Vec& rColXFIndexes );
     934             : 
     935             :     /** Writes the DIMENSIONS record, all ROW records and all cell records. */
     936             :     virtual void        Save( XclExpStream& rStrm ) SAL_OVERRIDE;
     937             :     virtual void        SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
     938             : 
     939         100 :     XclExpDimensions&   GetDimensions() { return maDimensions;}
     940             : 
     941             : private:
     942             :     /** Returns access to the specified ROW record. Inserts preceding missing ROW records.
     943             :         @param bRowAlwaysEmpty  true = Created rows will not be filled with blank cells
     944             :             in the XclExpRow::Finalize() function. */
     945             :     XclExpRow&          GetOrCreateRow( sal_uInt32 nXclRow, bool bRowAlwaysEmpty );
     946             : 
     947             : private:
     948             :     typedef std::shared_ptr<XclExpRow>  RowRef;
     949             :     typedef ::std::map<sal_uInt32, RowRef>  RowMap;
     950             : 
     951             :     RowMap              maRowMap;
     952             :     XclExpRowOutlineBuffer maOutlineBfr;    /// Buffer for row outline groups.
     953             :     XclExpDimensions    maDimensions;       /// DIMENSIONS record for used area.
     954             : };
     955             : 
     956             : // Cell Table
     957             : 
     958             : class XclExpNote;
     959             : class XclExpMergedcells;
     960             : class XclExpHyperlink;
     961             : class XclExpDval;
     962             : 
     963             : /** This class contains the cell contents and more of an entire sheet.
     964             : 
     965             :     The cell table includes the settings and default formatting of all columns,
     966             :     the settings and default formatting of all used rows, and the contents of
     967             :     all cells of one sheet in a spreadsheet document.
     968             : 
     969             :     The constructor does all the work creating the cell table. It reads the
     970             :     Calc sheet and converts all columns, rows, and cells to Excel record data.
     971             :     Additioanlly, hyperlink records, note records, additional records for
     972             :     formula cells, data validation records, and outline records are created.
     973             : 
     974             :     The Finalize() function does even more work. It calculates default column
     975             :     settings and removes column records that are equal to this default. The
     976             :     same happens with rows: A default format is calculated for each row, and
     977             :     all blank cells in this row that have the same format are removed. Then,
     978             :     the most used row settings are calculated, and all empty rows that have the
     979             :     same settings are removed too.
     980             : 
     981             :     Records that are not stored inside the cell table area in an Excel file
     982             :     (i.e. DEFROWHEIGHT record, NOTE records, MERGEDCELLS record, HLINK records,
     983             :     DVAL and DV records for data validation) can be accessed with the function
     984             :     CreateRecord(). It returns the reference to the respective record (or
     985             :     record list) which can be inserted into a record list.
     986             :  */
     987         258 : class XclExpCellTable : public XclExpRecordBase, protected XclExpRoot
     988             : {
     989             : public:
     990             :     explicit            XclExpCellTable( const XclExpRoot& rRoot );
     991             : 
     992             :     /** Converts all XF identifiers into the Excel XF indexes and calculates default formats. */
     993             :     void                Finalize();
     994             : 
     995             :     /** Returns the reference to an internal record specified by the passed record id.
     996             :         @param nRecId  The record identifier that specifies which record is
     997             :             returned. Possible values are: EXC_ID_DEFROWHEIGHT, EXC_ID_NOTE,
     998             :             EXC_ID_MERGEDCELLS, EXC_ID_HLINK, EXC_ID_DVAL. */
     999             :     XclExpRecordRef     CreateRecord( sal_uInt16 nRecId ) const;
    1000             :     /** Saves the entire cell table. */
    1001             :     virtual void        Save( XclExpStream& rStrm ) SAL_OVERRIDE;
    1002             :     virtual void        SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
    1003             : 
    1004             : private:
    1005             :     typedef XclExpRecordList< XclExpNote >      XclExpNoteList;
    1006             :     typedef XclExpRecordList< XclExpHyperlink > XclExpHyperlinkList;
    1007             : 
    1008             :     typedef std::shared_ptr< XclExpDefrowheight >        XclExpDefrowhRef;
    1009             :     typedef std::shared_ptr< XclExpNoteList >            XclExpNoteListRef;
    1010             :     typedef std::shared_ptr< XclExpMergedcells >         XclExpMergedcellsRef;
    1011             :     typedef std::shared_ptr< XclExpHyperlinkList >       XclExpHyperlinkRef;
    1012             :     typedef std::shared_ptr< XclExpDval >                XclExpDvalRef;
    1013             :     typedef std::shared_ptr< XclExtLst >                 XclExtLstRef;
    1014             : 
    1015             :     XclExpColinfoBuffer maColInfoBfr;       /// Buffer for column formatting.
    1016             :     XclExpRowBuffer     maRowBfr;           /// Rows and cell records.
    1017             :     XclExpArrayBuffer   maArrayBfr;         /// Buffer for ARRAY records.
    1018             :     XclExpShrfmlaBuffer maShrfmlaBfr;       /// Buffer for SHRFMLA records.
    1019             :     XclExpTableopBuffer maTableopBfr;       /// Buffer for TABLEOP records.
    1020             :     XclExpDefrowhRef    mxDefrowheight;     /// DEFROWHEIGHT record for default row format.
    1021             :     XclExpRecordRef     mxGuts;             /// GUTS record for outline areas.
    1022             :     XclExpNoteListRef   mxNoteList;         /// List of NOTE records.
    1023             :     XclExpMergedcellsRef mxMergedcells;     /// MERGEDCELLS record for merged cell ranges.
    1024             :     XclExpHyperlinkRef  mxHyperlinkList;    /// List of HLINK records.
    1025             :     XclExpDvalRef       mxDval;             /// Data validation with DVAL and DV records.
    1026             :     XclExtLstRef        mxExtLst;
    1027             : };
    1028             : 
    1029             : #endif
    1030             : 
    1031             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11