LCOV - code coverage report
Current view: top level - sc/source/filter/inc - xistyle.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 47 47 100.0 %
Date: 2015-06-13 12:38:46 Functions: 42 42 100.0 %
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_XISTYLE_HXX
      21             : #define INCLUDED_SC_SOURCE_FILTER_INC_XISTYLE_HXX
      22             : 
      23             : #include <list>
      24             : #include <tools/mempool.hxx>
      25             : #include <boost/noncopyable.hpp>
      26             : #include <boost/shared_ptr.hpp>
      27             : #include <boost/ptr_container/ptr_vector.hpp>
      28             : #include "rangelst.hxx"
      29             : #include "patattr.hxx"
      30             : #include "xladdress.hxx"
      31             : #include "xlstyle.hxx"
      32             : #include "xiroot.hxx"
      33             : 
      34             : struct ScAttrEntry;
      35             : enum class SvxBoxItemLine;
      36             : 
      37             : /* ============================================================================
      38             : - Buffers for style records (PALETTE, FONT, FORMAT, XF)
      39             :     and a container for XF indexes for every used cell in a sheet.
      40             : ============================================================================ */
      41             : 
      42             : // PALETTE record - color information =========================================
      43             : 
      44             : /** Stores the default colors for the current BIFF version and the contents of
      45             :     a PALETTE record. */
      46          84 : class XclImpPalette : public XclDefaultPalette
      47             : {
      48             : public:
      49             :     explicit            XclImpPalette( const XclImpRoot& rRoot );
      50             : 
      51             :     /** Clears all buffered data, used to set up for a new sheet. */
      52             :     void                Initialize();
      53             : 
      54             :     /** Returns the RGB color data for a (non-zero-based) Excel palette entry.
      55             :         @descr  First looks for a color read from file, then looks for a default color.
      56             :         @return  The color from current or default palette or COL_AUTO, if nothing else found. */
      57             :     ColorData           GetColorData( sal_uInt16 nXclIndex ) const;
      58             :     /** Returns the color for a (non-zero-based) Excel palette entry.
      59             :         @descr  First looks for a color read from file, then looks for a default color.
      60             :         @return  The color from current or default palette or COL_AUTO, if nothing else found. */
      61        8752 :     inline Color        GetColor( sal_uInt16 nXclIndex ) const
      62        8752 :                             { return Color( GetColorData( nXclIndex ) ); }
      63             : 
      64             :     /** Reads a PALETTE record. */
      65             :     void                ReadPalette( XclImpStream& rStrm );
      66             : 
      67             : private:
      68             :     void ExportPalette();
      69             :     typedef ::std::vector< ColorData > ColorDataVec;
      70             :     ColorDataVec        maColorTable;       /// Colors read from file.
      71             :     const XclImpRoot&             mrRoot;
      72             : };
      73             : 
      74             : // FONT record - font information =============================================
      75             : 
      76             : /** Stores all data of an Excel font and provides import of FONT records. */
      77        1954 : class XclImpFont : protected XclImpRoot
      78             : {
      79             : public:
      80             :     explicit            XclImpFont( const XclImpRoot& rRoot );
      81             : 
      82             :     /** Constructs a font from font data.
      83             :         @descr  Special handling for font style (bold, italic) in font name,
      84             :         overwrites settings in rFontData. */
      85             :     explicit            XclImpFont( const XclImpRoot& rRoot, const XclFontData& rFontData );
      86             : 
      87             :     /** Sets all font attributes to used or unused. */
      88             :     void                SetAllUsedFlags( bool bUsed );
      89             :     /** Sets the passed font data and all used flags to 'used'. */
      90             :     void                SetFontData( const XclFontData& rFontData, bool bHasCharSet );
      91             : 
      92             :     /** Returns read-only access to font data. */
      93         170 :     inline const XclFontData& GetFontData() const { return maData; }
      94             :     /** Returns true, if the font character set is valid. */
      95          82 :     inline bool         HasCharSet() const { return mbHasCharSet; }
      96             :     /** Returns true, if the font contains superscript or subscript. */
      97       77310 :     inline bool         HasEscapement() const { return maData.mnEscapem != EXC_FONTESC_NONE; }
      98             :     /** Returns the text encoding for strings used with this font. */
      99             :     rtl_TextEncoding    GetFontEncoding() const;
     100             : 
     101             :     /** Returns true, if this font contains characters for Western scripts. */
     102             :     inline bool         HasWesternChars() const { return mbHasWstrn; }
     103             :     /** Returns true, if this font contains characters for Asian scripts (CJK). */
     104           7 :     inline bool         HasAsianChars() const { return mbHasAsian; }
     105             :     /** Returns true, if this font contains characters for Complex scripts (CTL). */
     106             :     inline bool         HasComplexChars() const { return mbHasCmplx; }
     107             : 
     108             :     /** Reads a FONT record for all BIFF versions. */
     109             :     void                ReadFont( XclImpStream& rStrm );
     110             :     /** Reads an EFONT record (BIFF2 font color). */
     111             :     void                ReadEfont( XclImpStream& rStrm );
     112             :     /** Reads the font block from a CF (conditional format) record. */
     113             :     void                ReadCFFontBlock( XclImpStream& rStrm );
     114             : 
     115             :     /** Fills all font properties to the item set.
     116             :         @param rItemSet  The destination item set.
     117             :         @param eType  The type of Which-IDs.
     118             :         @param bSkipPoolDefs  true = Do not put items equal to pool default; false = Put all items. */
     119             :     void                FillToItemSet( SfxItemSet& rItemSet, XclFontItemType eType,
     120             :                             bool bSkipPoolDefs = false ) const;
     121             :     /** Writes all font properties to the passed property set.
     122             :         @param pFontColor  If set, overrides internal stored font color. */
     123             :     void                WriteFontProperties( ScfPropertySet& rPropSet,
     124             :                             XclFontPropSetType eType, const Color* pFontColor = 0 ) const;
     125             : 
     126             : private:
     127             :     /** Reads and sets height and flags. */
     128             :     void                ReadFontData2( XclImpStream& rStrm );
     129             :     /** Reads and sets height, flags, color, boldness, script, family and charset. */
     130             :     void                ReadFontData5( XclImpStream& rStrm );
     131             : 
     132             :     /** Reads and sets the font color. */
     133             :     void                ReadFontColor( XclImpStream& rStrm );
     134             : 
     135             :     /** Reads and sets a byte string as font name. */
     136             :     void                ReadFontName2( XclImpStream& rStrm );
     137             :     /** Reads and sets a Unicode string as font name. */
     138             :     void                ReadFontName8( XclImpStream& rStrm );
     139             : 
     140             :     /** Tests whether the font contains CJK or CTL characters.
     141             :         @descr  This is only a weak guess using preselected characters. */
     142             :     void                GuessScriptType();
     143             : 
     144             : private:
     145             :     XclFontData         maData;         /// All font attributes.
     146             :     bool                mbHasCharSet;   /// true = Font contains own character set info.
     147             :     bool                mbHasWstrn;     /// true = Font contains Western script characters.
     148             :     bool                mbHasAsian;     /// true = Font contains Asian script characters.
     149             :     bool                mbHasCmplx;     /// true = Font contains Complex script characters.
     150             :     bool                mbFontNameUsed; /// true = Font name, family, charset used.
     151             :     bool                mbHeightUsed;   /// true = Font height used.
     152             :     bool                mbColorUsed;    /// true = Color used.
     153             :     bool                mbWeightUsed;   /// true = Weight used.
     154             :     bool                mbEscapemUsed;  /// true = Escapement type used.
     155             :     bool                mbUnderlUsed;   /// true = Underline style used.
     156             :     bool                mbItalicUsed;   /// true = Italic used.
     157             :     bool                mbStrikeUsed;   /// true = Strikeout used.
     158             :     bool                mbOutlineUsed;  /// true = Outlined used.
     159             :     bool                mbShadowUsed;   /// true = Shadowed used.
     160             : };
     161             : 
     162             : /** Stores the data of all fonts occurred in an Excel file. */
     163         168 : class XclImpFontBuffer : protected XclImpRoot, private boost::noncopyable
     164             : {
     165             : public:
     166             :     explicit            XclImpFontBuffer( const XclImpRoot& rRoot );
     167             : 
     168             :     /** Clears all buffered data, used to set up for a new sheet. */
     169             :     void                Initialize();
     170             : 
     171             :     /** Returns the object that stores all contents of a FONT record. */
     172             :     const XclImpFont*   GetFont( sal_uInt16 nFontIndex ) const;
     173             :     /** Returns the application font data of this file, needed i.e. for column width. */
     174         222 :     inline const XclFontData& GetAppFontData() const { return maAppFont; }
     175             : 
     176             :     /** Reads a FONT record. */
     177             :     void                ReadFont( XclImpStream& rStrm );
     178             :     /** Reads an EFONT record (BIFF2 font color). */
     179             :     void                ReadEfont( XclImpStream& rStrm );
     180             : 
     181             :     /** Fills all font properties from a FONT record to the item set.
     182             :         @param rItemSet  The destination item set.
     183             :         @param eType  The type of Which-IDs.
     184             :         @param nFontIdx  The Excel index of the font.
     185             :         @param bSkipPoolDefs  true = Do not put items equal to pool default; false = Put all items. */
     186             :     void                FillToItemSet( SfxItemSet& rItemSet, XclFontItemType eType,
     187             :                             sal_uInt16 nFontIdx, bool bSkipPoolDefs = false ) const;
     188             :     /** Writes all font properties to the passed property set.
     189             :         @param pFontColor  If set, overrides internal stored font color. */
     190             :     void                WriteFontProperties(
     191             :                             ScfPropertySet& rPropSet, XclFontPropSetType eType,
     192             :                             sal_uInt16 nFontIdx, const Color* pFontColor = 0 ) const;
     193             :     /** Writes default font properties for form controls to the passed property set. */
     194             :     void                WriteDefaultCtrlFontProperties( ScfPropertySet& rPropSet ) const;
     195             : 
     196             : private:
     197             :     /** Updates the application default font. */
     198             :     void                UpdateAppFont( const XclFontData& rFontData, bool bHasCharSet );
     199             : 
     200             : private:
     201             :     boost::ptr_vector< XclImpFont > maFontList; /// List of all FONT records in the Excel file.
     202             :     XclFontData         maAppFont;              /// Application font (for column width).
     203             :     XclImpFont          maFont4;                /// Built-in font with index 4.
     204             :     XclImpFont          maCtrlFont;             /// BIFF5 default form controls font (Helv,8pt,bold).
     205             : };
     206             : 
     207             : // FORMAT record - number formats =============================================
     208             : 
     209             : /** Stores all user defined number formats occurred in the file. */
     210         168 : class XclImpNumFmtBuffer : public XclNumFmtBuffer, protected XclImpRoot
     211             : {
     212             : public:
     213             :     explicit            XclImpNumFmtBuffer( const XclImpRoot& rRoot );
     214             : 
     215             :     /** Clears all buffered data, used to set up for a new sheet. */
     216             :     void                Initialize();
     217             : 
     218             :     /** Reads a FORMAT record. */
     219             :     void                ReadFormat( XclImpStream& rStrm );
     220             : 
     221             :     /** Read NumFmt from conditional format record */
     222             :     sal_uInt16          ReadCFFormat( XclImpStream& rStrm, bool bIFmt );
     223             : 
     224             :     /** Creates the number formats in the Calc document. */
     225             :     void                CreateScFormats();
     226             : 
     227             :     /** Returns the format key with the passed Excel index or NUMBERFORMAT_ENTRY_NOT_FOUND on error. */
     228             :     sal_uLong               GetScFormat( sal_uInt16 nXclNumFmt ) const;
     229             : 
     230             :     /** Fills an Excel number format to the passed item set.
     231             :         @param rItemSet  The destination item set.
     232             :         @param nXclNumFmt  The Excel number format index.
     233             :         @param bSkipPoolDefs  true = Do not put items equal to pool default; false = Put all items. */
     234             :     void                FillToItemSet(
     235             :                             SfxItemSet& rItemSet, sal_uInt16 nXclNumFmt,
     236             :                             bool bSkipPoolDefs = false ) const;
     237             :     /** Fills a Calc number format to the passed item set.
     238             :         @param rItemSet  The destination item set.
     239             :         @param nScNumFmt  The Calc number formatter index of the format.
     240             :         @param bSkipPoolDefs  true = Do not put items equal to pool default; false = Put all items. */
     241             :     void                FillScFmtToItemSet(
     242             :                             SfxItemSet& rItemSet, sal_uLong nScNumFmt,
     243             :                             bool bSkipPoolDefs = false ) const;
     244             : 
     245             : private:
     246             :     typedef ::std::map< sal_uInt16, sal_uLong > XclImpIndexMap;
     247             : 
     248             :     XclImpIndexMap      maIndexMap;     /// Maps Excel format indexes to Calc formats.
     249             :     sal_uInt16          mnNextXclIdx;   /// Index counter for BIFF2-BIFF4.
     250             : };
     251             : 
     252             : // XF, STYLE record - Cell formatting =========================================
     253             : 
     254             : /** Extends the XclCellProt struct for import.
     255             :     @descr  Provides functions to fill from Excel record data and to fill to item sets. */
     256        3822 : struct XclImpCellProt : public XclCellProt
     257             : {
     258             :     /** Fills this struct with BIFF2 XF record data. */
     259             :     void                FillFromXF2( sal_uInt8 nNumFmt );
     260             :     /** Fills this struct with BIFF3-BIFF8 XF record data. */
     261             :     void                FillFromXF3( sal_uInt16 nProt );
     262             : 
     263             :     /** Inserts items representing this protection style into the item set.
     264             :         @param bSkipPoolDefs  true = Do not put items equal to pool default; false = Put all items. */
     265             :     void                FillToItemSet( SfxItemSet& rItemSet, bool bSkipPoolDefs = false ) const;
     266             : };
     267             : 
     268             : /** Extends the XclCellAlign struct for import.
     269             :     @descr  Provides functions to fill from Excel record data and to fill to item sets. */
     270        3822 : struct XclImpCellAlign : public XclCellAlign
     271             : {
     272             :     /** Fills this struct with BIFF2 XF record data. */
     273             :     void                FillFromXF2( sal_uInt8 nFlags );
     274             :     /** Fills this struct with BIFF3 XF record data. */
     275             :     void                FillFromXF3( sal_uInt16 nAlign );
     276             :     /** Fills this struct with BIFF4 XF record data. */
     277             :     void                FillFromXF4( sal_uInt16 nAlign );
     278             :     /** Fills this struct with BIFF5/BIFF7 XF record data. */
     279             :     void                FillFromXF5( sal_uInt16 nAlign );
     280             :     /** Fills this struct with BIFF8 XF record data. */
     281             :     void                FillFromXF8( sal_uInt16 nAlign, sal_uInt16 nMiscAttrib );
     282             :     /** Fills this struct with CF record data. */
     283             :     void                FillFromCF( sal_uInt16 nAlign, sal_uInt16 nMiscAttrib );
     284             : 
     285             :     /** Inserts items representing this alignment style into the item set.
     286             :         @param bSkipPoolDefs  true = Do not put items equal to pool default; false = Put all items. */
     287             :     void                FillToItemSet( SfxItemSet& rItemSet, const XclImpFont* pFont, bool bSkipPoolDefs = false ) const;
     288             : };
     289             : 
     290             : /** Extends the XclCellBorder struct for import.
     291             :     @descr  Provides functions to fill from Excel record data and to fill to item sets. */
     292             : struct XclImpCellBorder : public XclCellBorder
     293             : {
     294             :     bool                mbLeftUsed;     /// true = Left line style used.
     295             :     bool                mbRightUsed;    /// true = Right line style used.
     296             :     bool                mbTopUsed;      /// true = Top line style used.
     297             :     bool                mbBottomUsed;   /// true = Bottom line style used.
     298             :     bool                mbDiagUsed;     /// true = Diagonal line style used.
     299             : 
     300             :     explicit            XclImpCellBorder();
     301             : 
     302             :     /** Sets outer line states and diagonal line states to used or unused. */
     303             :     void                SetUsedFlags( bool bOuterUsed, bool bDiagUsed );
     304             : 
     305             :     /** Fills this struct with BIFF2 XF record data. */
     306             :     void                FillFromXF2( sal_uInt8 nFlags );
     307             :     /** Fills this struct with BIFF3/BIFF4 XF record data. */
     308             :     void                FillFromXF3( sal_uInt32 nBorder );
     309             :     /** Fills this struct with BIFF5/BIFF7 XF record data. */
     310             :     void                FillFromXF5( sal_uInt32 nBorder, sal_uInt32 nArea );
     311             :     /** Fills this struct with BIFF8 XF record data. */
     312             :     void                FillFromXF8( sal_uInt32 nBorder1, sal_uInt32 nBorder2 );
     313             : 
     314             :     /** Fills this struct with BIFF8 CF (conditional format) record data. */
     315             :     void                FillFromCF8( sal_uInt16 nLineStyle, sal_uInt32 nLineColor, sal_uInt32 nFlags );
     316             : 
     317             :     /** Returns true, if any of the outer border lines is visible. */
     318             :     bool                HasAnyOuterBorder() const;
     319             : 
     320             :     /** Inserts a box item representing this border style into the item set.
     321             :         @param bSkipPoolDefs  true = Do not put items equal to pool default; false = Put all items. */
     322             :     void                FillToItemSet(
     323             :                             SfxItemSet& rItemSet,
     324             :                             const XclImpPalette& rPalette,
     325             :                             bool bSkipPoolDefs = false ) const;
     326             : };
     327             : 
     328             : /** Extends the XclCellArea struct for import.
     329             :     @descr  Provides functions to fill from Excel record data and to fill to item sets. */
     330             : struct XclImpCellArea : public XclCellArea
     331             : {
     332             :     bool                mbForeUsed;     /// true = Foreground color used.
     333             :     bool                mbBackUsed;     /// true = Background color used.
     334             :     bool                mbPattUsed;     /// true = Pattern used.
     335             : 
     336             :     explicit            XclImpCellArea();
     337             : 
     338             :     /** Sets colors and pattern state to used or unused. */
     339             :     void                SetUsedFlags( bool bUsed );
     340             : 
     341             :     /** Fills this struct with BIFF2 XF record data. */
     342             :     void                FillFromXF2( sal_uInt8 nFlags );
     343             :     /** Fills this struct with BIFF3/BIFF4 XF record data. */
     344             :     void                FillFromXF3( sal_uInt16 nArea );
     345             :     /** Fills this struct with BIFF5/BIFF7 XF record data. */
     346             :     void                FillFromXF5( sal_uInt32 nArea );
     347             :     /** Fills this struct with BIFF8 XF record data. */
     348             :     void                FillFromXF8( sal_uInt32 nBorder2, sal_uInt16 nArea );
     349             : 
     350             :     /** Fills this struct with BIFF8 CF (conditional format) record data. */
     351             :     void                FillFromCF8( sal_uInt16 nPattern, sal_uInt16 nColor, sal_uInt32 nFlags );
     352             : 
     353             :     /** Inserts a brush item representing this area style into the item set.
     354             :         @param bSkipPoolDefs  true = Do not put items equal to pool default; false = Put all items. */
     355             :     void                FillToItemSet(
     356             :                             SfxItemSet& rItemSet,
     357             :                             const XclImpPalette& rPalette,
     358             :                             bool bSkipPoolDefs = false ) const;
     359             : };
     360             : 
     361             : /** Represents an XF record index with additional information. */
     362             : class XclImpXFIndex
     363             : {
     364             : public:
     365      708305 :     inline explicit     XclImpXFIndex( sal_uInt16 nXFIndex, bool bBoolCell = false ) :
     366      708305 :                             mnXFIndex( nXFIndex ), mbBoolCell( bBoolCell ) {}
     367             : 
     368     2108645 :     inline sal_uInt16   GetXFIndex() const { return mnXFIndex; }
     369     1317930 :     inline bool         IsBoolCell() const { return mbBoolCell; }
     370             : 
     371             : private:
     372             :     sal_uInt16          mnXFIndex;      /// The XF record index.
     373             :     bool                mbBoolCell;     /// true = A Boolean value cell.
     374             : };
     375             : 
     376      993573 : inline bool operator==( const XclImpXFIndex& rLeft, const XclImpXFIndex& rRight )
     377      993573 : { return (rLeft.GetXFIndex() == rRight.GetXFIndex()) && (rLeft.IsBoolCell() == rRight.IsBoolCell()); }
     378             : 
     379      596199 : inline bool operator!=( const XclImpXFIndex& rLeft, const XclImpXFIndex& rRight )
     380      596199 : { return !(rLeft == rRight); }
     381             : 
     382             : /** Contains all data of a XF record and a Calc item set. */
     383             : class XclImpXF : public XclXFBase, protected XclImpRoot, private boost::noncopyable
     384             : {
     385             : public:
     386             :     explicit            XclImpXF( const XclImpRoot& rRoot );
     387             :     virtual             ~XclImpXF();
     388             : 
     389             :     /** Reads an XF record. */
     390             :     void                ReadXF( XclImpStream& rStrm );
     391             : 
     392      657678 :     inline sal_uInt8    GetHorAlign() const { return maAlignment.mnHorAlign; }
     393             :     inline sal_uInt8    GetVerAlign() const { return maAlignment.mnVerAlign; }
     394       78060 :     inline sal_uInt16   GetFontIndex() const { return mnXclFont; }
     395             : 
     396             :     /** Creates a Calc item set containing an item set with all cell properties.
     397             :         @param bSkipPoolDefs  true = Do not put items equal to pool default; false = Put all items.
     398             :         @return  A read-only reference to the item set stored internally. */
     399             :     const ScPatternAttr& CreatePattern( bool bSkipPoolDefs = false );
     400             : 
     401             :     void                ApplyPatternToAttrList(
     402             :                             ::std::list<ScAttrEntry>& rAttrs, SCROW nRow1, SCROW nRow2,
     403             :                             sal_uInt32 nForceScNumFmt = NUMBERFORMAT_ENTRY_NOT_FOUND);
     404             : 
     405             :     /** Inserts all formatting attributes to the specified area in the Calc document.
     406             :         @param nForcedNumFmt  If not set to NUMBERFORMAT_ENTRY_NOT_FOUND, it will overwrite
     407             :         the number format of the XF. */
     408             :     void                ApplyPattern(
     409             :                             SCCOL nScCol1, SCROW nScRow1,
     410             :                             SCCOL nScCol2, SCROW nScRow2,
     411             :                             SCTAB nScTab,
     412             :                             sal_uLong nForceScNumFmt = NUMBERFORMAT_ENTRY_NOT_FOUND );
     413             : 
     414             :     /** Converts formatting information from BIFF2 cell record data directly. */
     415             :     static void         ApplyPatternForBiff2CellFormat(
     416             :                             const XclImpRoot& rRoot, const ScAddress& rScPos,
     417             :                             sal_uInt8 nFlags1, sal_uInt8 nFlags2, sal_uInt8 nFlags3 );
     418             : 
     419             : private:
     420             :     void                ReadXF2( XclImpStream& rStrm );
     421             :     void                ReadXF3( XclImpStream& rStrm );
     422             :     void                ReadXF4( XclImpStream& rStrm );
     423             :     void                ReadXF5( XclImpStream& rStrm );
     424             :     void                ReadXF8( XclImpStream& rStrm );
     425             : 
     426             :     /** Sets all "attribute used" flags according to the passed mask.
     427             :         @descr  In cell XFs, a set bit represents "used", in style XFs it is a cleared bit.
     428             :         Therefore mbCellXF must be set correctly before calling this method. */
     429             :     void                SetUsedFlags( sal_uInt8 nUsedFlags );
     430             : 
     431             : private:
     432             :     typedef ::std::unique_ptr< ScPatternAttr > ScPatternAttrPtr;
     433             : 
     434             :     ScPatternAttrPtr    mpPattern;          /// Calc item set.
     435             :     ScStyleSheet*       mpStyleSheet;       /// Calc cell style sheet.
     436             : 
     437             :     XclImpCellProt      maProtection;       /// Cell protection flags.
     438             :     XclImpCellAlign     maAlignment;        /// All alignment attributes.
     439             :     XclImpCellBorder    maBorder;           /// Border line style.
     440             :     XclImpCellArea      maArea;             /// Background area style.
     441             :     sal_uInt16          mnXclNumFmt;        /// Index to number format.
     442             :     sal_uInt16          mnXclFont;          /// Index to font record.
     443             : };
     444             : 
     445             : /** Contains all data of a cell style associated with an XF record. */
     446        2636 : class XclImpStyle : protected XclImpRoot
     447             : {
     448             : public:
     449             :     explicit            XclImpStyle( const XclImpRoot& rRoot );
     450             : 
     451             :     /** Reads a STYLE record. */
     452             :     void                ReadStyle( XclImpStream& rStrm );
     453             : 
     454        2148 :     inline const OUString& GetName() const { return maName; }
     455        1318 :     inline sal_uInt16   GetXfId() const { return mnXfId; }
     456        2636 :     inline bool         IsBuiltin() const { return mbBuiltin && (mnBuiltinId != EXC_STYLE_USERDEF); }
     457         903 :     inline sal_uInt8    GetBuiltinId() const { return mnBuiltinId; }
     458         903 :     inline sal_uInt8    GetLevel() const { return mnLevel; }
     459             : 
     460             :     /** Creates a cell style sheet and inserts it into the Calc document.
     461             :         @return  The pointer to the cell style sheet, or 0, if there is no style sheet. */
     462             :     ScStyleSheet*       CreateStyleSheet();
     463             :     /** Creates the Calc style sheet, if this is a user-defined style. */
     464             :     void                CreateUserStyle( const OUString& rFinalName );
     465             : 
     466             : private:
     467             :     OUString            maName;             /// Cell style name.
     468             :     sal_uInt16          mnXfId;             /// Formatting for this cell style.
     469             :     sal_uInt8           mnBuiltinId;        /// Identifier for builtin styles.
     470             :     sal_uInt8           mnLevel;            /// Level for builtin column/row styles.
     471             :     bool                mbBuiltin;          /// True = builtin style.
     472             :     bool                mbCustom;           /// True = customized builtin style.
     473             :     bool                mbHidden;           /// True = style not visible in GUI.
     474             : 
     475             :     OUString            maFinalName;        /// Final name used in the Calc document.
     476             :     ScStyleSheet*       mpStyleSheet;       /// Calc cell style sheet.
     477             : };
     478             : 
     479             : /** Contains all XF records occurred in the file.
     480             :     @descr  This class is able to read XF records (BIFF2 - BIFF8) and STYLE records (BIFF8). */
     481         168 : class XclImpXFBuffer : protected XclImpRoot, private boost::noncopyable
     482             : {
     483             : public:
     484             :     explicit            XclImpXFBuffer( const XclImpRoot& rRoot );
     485             : 
     486             :     /** Clears all buffered data, used to set up for a new sheet. */
     487             :     void                Initialize();
     488             : 
     489             :     /** Reads an XF record. */
     490             :     void                ReadXF( XclImpStream& rStrm );
     491             :     /** Reads a STYLE record. */
     492             :     void                ReadStyle( XclImpStream& rStrm );
     493             : 
     494             :     /** Returns the object that stores all contents of an XF record. */
     495      452754 :     inline XclImpXF*    GetXF( sal_uInt16 nXFIndex )
     496      452754 :                             { return (nXFIndex >= maXFList.size()) ? NULL : &maXFList.at(nXFIndex); }
     497             : 
     498       78060 :     inline const XclImpXF*    GetXF( sal_uInt16 nXFIndex ) const
     499       78060 :                             { return (nXFIndex >= maXFList.size()) ? NULL : &maXFList.at(nXFIndex); }
     500             : 
     501             :     /** Returns the index to the Excel font used in the specified XF record. */
     502             :     sal_uInt16          GetFontIndex( sal_uInt16 nXFIndex ) const;
     503             :     /** Returns the Excel font used in the specified XF record. */
     504             :     const XclImpFont*   GetFont( sal_uInt16 nXFIndex ) const;
     505             : 
     506             :     /** Creates all user defined style sheets. */
     507             :     void                CreateUserStyles();
     508             :     /** Creates a cell style sheet of the passed XF and inserts it into the Calc document.
     509             :         @return  The pointer to the cell style sheet, or 0, if there is no style sheet. */
     510             :     ScStyleSheet*       CreateStyleSheet( sal_uInt16 nXFIndex );
     511             : 
     512             : private:
     513             :     typedef boost::ptr_vector< XclImpStyle >        XclImpStyleList;
     514             :     typedef ::std::map< sal_uInt16, XclImpStyle* >  XclImpStyleMap;
     515             : 
     516             :     boost::ptr_vector< XclImpXF > maXFList; /// List of contents of all XF record.
     517             :     XclImpStyleList     maBuiltinStyles;    /// List of built-in cell styles.
     518             :     XclImpStyleList     maUserStyles;       /// List of user defined cell styles.
     519             :     XclImpStyleMap      maStylesByXf;       /// Maps XF records to cell styles.
     520             : };
     521             : 
     522             : // Buffer for XF indexes in cells =============================================
     523             : 
     524             : /** Contains an (encoded) XF index for a range of rows in a single column. */
     525             : class XclImpXFRange
     526             : {
     527      244196 :     DECL_FIXEDMEMPOOL_NEWDEL( XclImpXFRange )
     528             : 
     529             : public:
     530             :     SCROW               mnScRow1;       /// The first row of an equal-formatted range.
     531             :     SCROW               mnScRow2;       /// The last row of an equal-formatted range.
     532             :     XclImpXFIndex       maXFIndex;      /// Extended XF index.
     533             : 
     534             :     inline explicit     XclImpXFRange( SCROW nScRow, const XclImpXFIndex& rXFIndex );
     535             :     inline explicit     XclImpXFRange( SCROW nFirstScRow, SCROW nLastScRow, const XclImpXFIndex& rXFIndex );
     536             : 
     537             :     /** Returns true, if nScRow is contained in own row range. */
     538             :     inline bool         Contains( SCROW nScRow ) const;
     539             : 
     540             :     /** Returns true, if the range has been expanded. */
     541             :     bool                Expand( SCROW nScRow, const XclImpXFIndex& rXFIndex );
     542             :     /** Returns true, if the range has been expanded. */
     543             :     bool                Expand( const XclImpXFRange& rNextRange );
     544             : };
     545             : 
     546       98095 : inline XclImpXFRange::XclImpXFRange( SCROW nScRow, const XclImpXFIndex& rXFIndex ) :
     547             :     mnScRow1( nScRow ),
     548             :     mnScRow2( nScRow ),
     549       98095 :     maXFIndex( rXFIndex )
     550             : {
     551       98095 : }
     552             : 
     553       24003 : inline XclImpXFRange::XclImpXFRange( SCROW nFirstScRow, SCROW nLastScRow, const XclImpXFIndex& rXFIndex ) :
     554             :     mnScRow1( nFirstScRow ),
     555             :     mnScRow2( nLastScRow ),
     556       24003 :     maXFIndex( rXFIndex )
     557             : {
     558       24003 : }
     559             : 
     560      674506 : inline bool XclImpXFRange::Contains( SCROW nScRow ) const
     561             : {
     562      674506 :     return (mnScRow1 <= nScRow) && (nScRow <= mnScRow2);
     563             : }
     564             : 
     565             : /** Contains the XF indexes for every used cell in a column. */
     566       33759 : class XclImpXFRangeColumn : private boost::noncopyable
     567             : {
     568             : public:
     569             :     typedef ::boost::ptr_vector<XclImpXFRange> IndexList;
     570             : 
     571       33759 :     inline explicit     XclImpXFRangeColumn() {}
     572             : 
     573       33759 :     IndexList::iterator begin() { return maIndexList.begin(); }
     574       33759 :     IndexList::iterator end() { return maIndexList.end(); }
     575             : 
     576             :     /** Inserts a single row range into the list. */
     577             :     void                SetDefaultXF( const XclImpXFIndex& rXFIndex );
     578             : 
     579             :     /** Inserts a new (encoded) XF index (first try to expand the last range). */
     580             :     void                SetXF( SCROW nScRow, const XclImpXFIndex& rXFIndex );
     581             : 
     582             : private:
     583             :     /** Finds the previous and next row range from row position nScRow.
     584             :         @descr  If an XF still exists, it is contained in rpPrevRange. */
     585             :     void                Find(
     586             :                             XclImpXFRange*& rpPrevRange,
     587             :                             XclImpXFRange*& rpNextRange,
     588             :                             sal_uLong& rnNextIndex,
     589             :                             SCROW nScRow );
     590             : 
     591             :     /** Tries to concatenate a range with its predecessor.
     592             :         @descr  The ranges must have the same XF index and must not have a gap.
     593             :         The resulting range has the index nIndex-1. */
     594             :     void                TryConcatPrev( sal_uLong nIndex );
     595             : 
     596             :     /** Insert a range into the list at the specified index. */
     597             :     void                Insert(XclImpXFRange* pXFRange, sal_uLong nIndex);
     598             : 
     599             : private:
     600             :     IndexList maIndexList;    /// The list of XF index range.
     601             : };
     602             : 
     603             : /** Contains the XF indexes for every used cell in a single sheet. */
     604             : class XclImpXFRangeBuffer : protected XclImpRoot, private boost::noncopyable
     605             : {
     606             : public:
     607             :     explicit            XclImpXFRangeBuffer( const XclImpRoot& rRoot );
     608             :     virtual             ~XclImpXFRangeBuffer();
     609             : 
     610             :     /** Clears all buffered data, used to set up for a new sheet. */
     611             :     void                Initialize();
     612             : 
     613             :     /** Inserts a new XF index. */
     614             :     void                SetXF( const ScAddress& rScPos, sal_uInt16 nXFIndex );
     615             :     /** Inserts a new XF index for blank cells. */
     616             :     void                SetBlankXF( const ScAddress& rScPos, sal_uInt16 nXFIndex );
     617             :     /** Inserts a new XF index for boolean cells. */
     618             :     void                SetBoolXF( const ScAddress& rScPos, sal_uInt16 nXFIndex );
     619             :     /** Inserts a new XF index for all cells in a row. */
     620             :     void                SetRowDefXF( SCROW nScRow, sal_uInt16 nXFIndex );
     621             :     /** Inserts a new XF index for all cells in a column. */
     622             :     void                SetColumnDefXF( SCCOL nScCol, sal_uInt16 nXFIndex );
     623             : 
     624             :     /** Inserts a range of hyperlink cells. */
     625             :     void                SetHyperlink( const XclRange& rXclRange, const OUString& rUrl );
     626             : 
     627             :     /** Inserts the first cell of a merged cell range. */
     628             :     void                SetMerge( SCCOL nScCol, SCROW nScRow );
     629             :     /** Inserts a complete merged cell range. */
     630             :     void                SetMerge( SCCOL nScCol1, SCROW nScRow1, SCCOL nScCol2, SCROW nScRow2 );
     631             : 
     632             :     /** Applies styles and cell merging to the current sheet in the document. */
     633             :     void                Finalize();
     634             : 
     635             : private:
     636             :     /** Insertion mode of an XF index. */
     637             :     enum XclImpXFInsertMode
     638             :     {
     639             :         xlXFModeCell,               /// Filled cell.
     640             :         xlXFModeBoolCell,           /// Cell with a single Boolean value.
     641             :         xlXFModeBlank,              /// Blank cell.
     642             :         xlXFModeRow                 /// Row default XF.
     643             :     };
     644             : 
     645             : private:
     646             :     /** Inserts a new XF index for the specified cell type. */
     647             :     void                SetXF( const ScAddress& rScPos, sal_uInt16 nXFIndex, XclImpXFInsertMode eMode );
     648             : 
     649             :     /** Copies border of the last cell of the range to the first cell to keep it visible
     650             :         when the range is merged.
     651             :         @param nLine
     652             :         SvxBoxItemLine::RIGHT = copy most-right border of top row;
     653             :         SvxBoxItemLine::BOTTOM = copy most-bottom border of first column. */
     654             :     void                SetBorderLine( const ScRange& rRange, SCTAB nScTab, SvxBoxItemLine nLine );
     655             : 
     656             : private:
     657             :     typedef boost::shared_ptr< XclImpXFRangeColumn > XclImpXFRangeColumnRef;
     658             :     typedef ::std::vector< XclImpXFRangeColumnRef >  XclImpXFRangeColumnVec;
     659             :     typedef ::std::pair< XclRange, OUString >        XclImpHyperlinkRange;
     660             :     typedef ::std::list< XclImpHyperlinkRange >      XclImpHyperlinkList;
     661             : 
     662             :     XclImpXFRangeColumnVec maColumns;       /// Array of column XF index buffers.
     663             :     XclImpHyperlinkList maHyperlinks;       /// Maps URLs to hyperlink cells.
     664             :     ScRangeList         maMergeList;        /// List of merged cell ranges.
     665             : };
     666             : 
     667             : #endif
     668             : 
     669             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11