LCOV - code coverage report
Current view: top level - sc/source/filter/inc - xistyle.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 46 47 97.9 %
Date: 2012-08-25 Functions: 41 42 97.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 32 56 57.1 %

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

Generated by: LCOV version 1.10