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

Generated by: LCOV version 1.10