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

Generated by: LCOV version 1.10