LCOV - code coverage report
Current view: top level - sc/source/filter/inc - sheetdatabuffer.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 6 6 100.0 %
Date: 2015-06-13 12:38:46 Functions: 7 9 77.8 %
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_SHEETDATABUFFER_HXX
      21             : #define INCLUDED_SC_SOURCE_FILTER_INC_SHEETDATABUFFER_HXX
      22             : 
      23             : #include <list>
      24             : #include <map>
      25             : #include "richstring.hxx"
      26             : #include "worksheethelper.hxx"
      27             : 
      28             : namespace com { namespace sun { namespace star {
      29             :     namespace util { struct DateTime; }
      30             : } } }
      31             : 
      32             : namespace oox {
      33             : namespace xls {
      34             : 
      35             : /** Stores basic data about cell values and formatting. */
      36             : struct CellModel
      37             : {
      38             :     ::com::sun::star::table::CellAddress
      39             :                         maCellAddr;         /// The address of the current cell.
      40             :     sal_Int32           mnCellType;         /// Data type of the cell value.
      41             :     sal_Int32           mnXfId;             /// XF (cell formatting) identifier.
      42             :     bool                mbShowPhonetic;     /// True = show phonetic text.
      43             : 
      44             :     explicit            CellModel();
      45             : };
      46             : 
      47             : /** Stores data about cell formulas. */
      48             : struct CellFormulaModel
      49             : {
      50             :     ::com::sun::star::table::CellRangeAddress
      51             :                         maFormulaRef;       /// Formula range for array/shared formulas and data tables.
      52             :     sal_Int32           mnFormulaType;      /// Type of the formula (regular, array, shared, table).
      53             :     sal_Int32           mnSharedId;         /// Identifier of a shared formula (OOXML only).
      54             : 
      55             :     explicit            CellFormulaModel();
      56             : 
      57             :     /** Returns true, if the passed cell address is valid for an array formula. */
      58             :     bool                isValidArrayRef( const ::com::sun::star::table::CellAddress& rCellAddr );
      59             :     /** Returns true, if the passed cell address is valid for a shared formula. */
      60             :     bool                isValidSharedRef( const ::com::sun::star::table::CellAddress& rCellAddr );
      61             : };
      62             : 
      63             : /** Stores data about table operations. */
      64         281 : struct DataTableModel
      65             : {
      66             :     OUString     maRef1;             /// First reference cell for table operations.
      67             :     OUString     maRef2;             /// Second reference cell for table operations.
      68             :     bool                mb2dTable;          /// True = 2-dimensional data table.
      69             :     bool                mbRowTable;         /// True = row oriented data table.
      70             :     bool                mbRef1Deleted;      /// True = first reference cell deleted.
      71             :     bool                mbRef2Deleted;      /// True = second reference cell deleted.
      72             : 
      73             :     explicit            DataTableModel();
      74             : };
      75             : 
      76             : /** Manages all cell blocks currently in use. */
      77         269 : class CellBlockBuffer : public WorksheetHelper
      78             : {
      79             : public:
      80             :     explicit            CellBlockBuffer( const WorksheetHelper& rHelper );
      81             : 
      82             :     /** Sets column span information for a row. */
      83             :     void                setColSpans( sal_Int32 nRow, const ValueRangeSet& rColSpans );
      84             : 
      85             : private:
      86             :     typedef ::std::map< sal_Int32, ValueRangeVector >   ColSpanVectorMap;
      87             : 
      88             :     ColSpanVectorMap    maColSpans;             /// Buffereed column spans, mapped by row index.
      89             :     sal_Int32           mnCurrRow;              /// Current row index used for buffered cell import.
      90             : };
      91             : 
      92             : /** Manages the cell contents and cell formatting of a sheet.
      93             :  */
      94         269 : class SheetDataBuffer : public WorksheetHelper
      95             : {
      96             : public:
      97             :     explicit            SheetDataBuffer( const WorksheetHelper& rHelper );
      98             : 
      99             :     /** Sets column span information for a row. */
     100             :     void                setColSpans( sal_Int32 nRow, const ValueRangeSet& rColSpans );
     101             : 
     102             :     /** Inserts a blank cell (with formatting) into the sheet. */
     103             :     void                setBlankCell( const CellModel& rModel );
     104             :     /** Inserts a value cell into the sheet. */
     105             :     void                setValueCell( const CellModel& rModel, double fValue );
     106             :     /** Inserts a simple string cell into the sheet. */
     107             :     void                setStringCell( const CellModel& rModel, const OUString& rText );
     108             :     /** Inserts a rich-string cell into the sheet. */
     109             :     void                setStringCell( const CellModel& rModel, const RichStringRef& rxString );
     110             :     /** Inserts a shared string cell into the sheet. */
     111             :     void                setStringCell( const CellModel& rModel, sal_Int32 nStringId );
     112             :     /** Inserts a date/time cell into the sheet and adjusts number format. */
     113             :     void                setDateTimeCell( const CellModel& rModel, const ::com::sun::star::util::DateTime& rDateTime );
     114             :     /** Inserts a boolean cell into the sheet and adjusts number format. */
     115             :     void                setBooleanCell( const CellModel& rModel, bool bValue );
     116             :     /** Inserts an error cell from the passed error code into the sheet. */
     117             :     void                setErrorCell( const CellModel& rModel, const OUString& rErrorCode );
     118             :     /** Inserts an error cell from the passed BIFF error code into the sheet. */
     119             :     void                setErrorCell( const CellModel& rModel, sal_uInt8 nErrorCode );
     120             :     /** Inserts a formula cell into the sheet. */
     121             :     void                setFormulaCell( const CellModel& rModel, const ApiTokenSequence& rTokens );
     122             :     /** Inserts a ISO 8601 date cell into the sheet. */
     123             :     void                setDateCell( const CellModel& rModel, const OUString& rDateString );
     124             : 
     125             :     void                createSharedFormula(
     126             :             const com::sun::star::table::CellAddress& rRange,
     127             :             const ApiTokenSequence& rTokens);
     128             : 
     129             :     /** Inserts the passed token array as array formula. */
     130             :     void                createArrayFormula(
     131             :                             const ::com::sun::star::table::CellRangeAddress& rRange,
     132             :                             const ApiTokenSequence& rTokens );
     133             :     /** Sets a multiple table operation to the passed range. */
     134             :     void                createTableOperation(
     135             :                             const ::com::sun::star::table::CellRangeAddress& rRange,
     136             :                             const DataTableModel& rModel );
     137             : 
     138             :     /** Sets default cell formatting for the specified range of rows. */
     139             :     void                setRowFormat( sal_Int32 nRow, sal_Int32 nXfId, bool bCustomFormat );
     140             :     /** Merges the cells in the passed cell range. */
     141             :     void                setMergedRange( const ::com::sun::star::table::CellRangeAddress& rRange );
     142             :     /** Sets a standard number format (constant from com.sun.star.util.NumberFormat) to the specified cell. */
     143             :     void                setStandardNumFmt(
     144             :                             const ::com::sun::star::table::CellAddress& rCellAddr,
     145             :                             sal_Int16 nStdNumFmt );
     146             :     /** Processes the cell formatting data of the passed cell.
     147             :         @param nNumFmtId  If set, overrides number format of the cell XF. */
     148             :     void                setCellFormat( const CellModel& rModel, sal_Int32 nNumFmtId = -1 );
     149             : 
     150             :     /** Final processing after the sheet has been imported. */
     151             :     void                finalizeImport();
     152             : 
     153             :     /** Sets the passed formula token array into a cell. */
     154             :     void                setCellFormula(
     155             :                             const ::com::sun::star::table::CellAddress& rCellAddr,
     156             :                             const ApiTokenSequence& rTokens );
     157             : 
     158             : private:
     159             :     struct XfIdRowRange;
     160             : 
     161             :     /** Creates a formula token array representing the shared formula with the
     162             :         passed identifier. */
     163             :     ApiTokenSequence    resolveSharedFormula( const css::table::CellAddress& rMapKey ) const;
     164             : 
     165             :     /** Inserts the passed array formula into the sheet. */
     166             :     void                finalizeArrayFormula(
     167             :                             const ::com::sun::star::table::CellRangeAddress& rRange,
     168             :                             const ApiTokenSequence& rTokens ) const;
     169             :     /** Inserts the passed table operation into the sheet. */
     170             :     void finalizeTableOperation(
     171             :         const ::com::sun::star::table::CellRangeAddress& rRange, const DataTableModel& rModel );
     172             : 
     173             :     /** Writes all cell formatting attributes to the passed cell range list. (depreciates writeXfIdRangeProperties) */
     174             :     void                applyCellMerging( const ::com::sun::star::table::CellRangeAddress& rRange );
     175             :     void                addColXfStyle( sal_Int32 nXfId, sal_Int32 nFormatId, const ::com::sun::star::table::CellRangeAddress& rAddress, bool bProcessRowRange = false );
     176             : private:
     177             :     /** Stores cell range address and formula token array of an array formula. */
     178             :     typedef ::std::pair< ::com::sun::star::table::CellRangeAddress, ApiTokenSequence > ArrayFormula;
     179             :     typedef ::std::list< ArrayFormula > ArrayFormulaList;
     180             : 
     181             :     /** Stores cell range address and settings of a table operation. */
     182             :     typedef ::std::pair< ::com::sun::star::table::CellRangeAddress, DataTableModel > TableOperation;
     183             :     typedef ::std::list< TableOperation > TableOperationList;
     184             : 
     185             :     /** Stores information about a range of rows with equal cell formatting. */
     186             :     struct XfIdRowRange
     187             :     {
     188             :         ValueRange          maRowRange;         /// Indexes of first and last row.
     189             :         sal_Int32           mnXfId;             /// XF identifier for the row range.
     190             : 
     191             :         explicit            XfIdRowRange();
     192             :         void                set( sal_Int32 nRow, sal_Int32 nXfId );
     193             :         bool                tryExpand( sal_Int32 nRow, sal_Int32 nXfId );
     194             :     };
     195             : 
     196             :     typedef ::std::pair< sal_Int32, sal_Int32 > XfIdNumFmtKey;
     197             :     typedef ::std::map< XfIdNumFmtKey, ApiCellRangeList > XfIdRangeListMap;
     198             : 
     199             :     typedef ::std::pair< sal_Int32, sal_Int32 > RowRange;
     200         419 :     struct RowRangeStyle
     201             :     {
     202             :         sal_Int32 mnStartRow;
     203             :         sal_Int32 mnEndRow;
     204             :         XfIdNumFmtKey mnNumFmt;
     205             :     };
     206             :     struct StyleRowRangeComp
     207             :     {
     208        1918 :         bool operator() (const RowRangeStyle& lhs, const RowRangeStyle& rhs) const
     209             :         {
     210        1918 :             return lhs.mnEndRow<rhs.mnStartRow;
     211             :         }
     212             :     };
     213             :     typedef ::std::set< RowRangeStyle, StyleRowRangeComp > RowStyles;
     214             :     typedef ::std::map< sal_Int32, RowStyles > ColStyles;
     215             :     /** Stores information about a merged cell range. */
     216             :     struct MergedRange
     217             :     {
     218             :         ::com::sun::star::table::CellRangeAddress
     219             :                             maRange;            /// The formatted cell range.
     220             :         sal_Int32           mnHorAlign;         /// Horizontal alignment in the range.
     221             : 
     222             :         explicit            MergedRange( const ::com::sun::star::table::CellRangeAddress& rRange );
     223             :         explicit            MergedRange( const ::com::sun::star::table::CellAddress& rAddress, sal_Int32 nHorAlign );
     224             :         bool                tryExpand( const ::com::sun::star::table::CellAddress& rAddress, sal_Int32 nHorAlign );
     225             :     };
     226             :     typedef ::std::list< MergedRange > MergedRangeList;
     227             : 
     228             :     ColStyles           maStylesPerColumn;      /// Stores cell styles by column ( in row ranges )
     229             :     CellBlockBuffer     maCellBlocks;           /// Manages all open cell blocks.
     230             :     ArrayFormulaList    maArrayFormulas;        /// All array formulas in the sheet.
     231             :     TableOperationList  maTableOperations;      /// All table operations in the sheet.
     232             :     SharedFormulaMap    maSharedFormulas;       /// Maps shared formula base address to defined name token index.
     233             :     ::com::sun::star::table::CellAddress
     234             :                         maSharedFmlaAddr;       /// Address of a cell containing a pending shared formula.
     235             :     css::table::CellAddress maSharedBaseAddr;       /// Base address of the pending shared formula.
     236             :     XfIdRowRange        maXfIdRowRange;         /// Cached XF identifier for a range of rows.
     237             :     XfIdRangeListMap    maXfIdRangeLists;       /// Collected XF identifiers for cell rangelists.
     238             :     MergedRangeList     maMergedRanges;         /// Merged cell ranges.
     239             :     MergedRangeList     maCenterFillRanges;     /// Merged cell ranges from 'center across' or 'fill' alignment.
     240             :     bool                mbPendingSharedFmla;    /// True = maSharedFmlaAddr and maSharedBaseAddr are valid.
     241             :     std::map< sal_Int32, std::vector< ValueRange > > maXfIdRowRangeList; /// Cached XF identifiers for a ranges of rows, we try and process rowranges with the same XF id together
     242             : };
     243             : 
     244             : } // namespace xls
     245             : } // namespace oox
     246             : 
     247             : #endif
     248             : 
     249             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11