LCOV - code coverage report
Current view: top level - sc/source/filter/inc - xestyle.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 25 0.0 %
Date: 2014-04-14 Functions: 0 36 0.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_XESTYLE_HXX
      21             : #define SC_XESTYLE_HXX
      22             : 
      23             : #include <map>
      24             : #include <tools/mempool.hxx>
      25             : #include <svl/zforlist.hxx>
      26             : #include <svl/nfkeytab.hxx>
      27             : #include <editeng/svxfont.hxx>
      28             : #include "xerecord.hxx"
      29             : #include "xlstyle.hxx"
      30             : #include "xeroot.hxx"
      31             : #include "conditio.hxx"
      32             : #include <boost/shared_ptr.hpp>
      33             : #include <boost/scoped_ptr.hpp>
      34             : #include <boost/ptr_container/ptr_vector.hpp>
      35             : 
      36             : /* ============================================================================
      37             : - Buffers for style records (PALETTE, FONT, FORMAT, XF, STYLE).
      38             : ============================================================================ */
      39             : 
      40             : const sal_uInt16 EXC_ID_FONTLIST    = 0x8031;   /// For internal use only.
      41             : const sal_uInt16 EXC_ID_FORMATLIST  = 0x801E;   /// For internal use only.
      42             : const sal_uInt16 EXC_ID_XFLIST      = 0x8043;   /// For internal use only.
      43             : const sal_uInt16 EXC_ID_DXFS        = 0x9999;   /// For internal use only. TODO:moggi: find a better/correct value
      44             : 
      45             : // PALETTE record - color information =========================================
      46             : 
      47             : /** Different types of colors in a document. */
      48             : enum XclExpColorType
      49             : {
      50             :     EXC_COLOR_CELLTEXT,         /// Text in a cell.
      51             :     EXC_COLOR_CELLBORDER,       /// Border of a cell.
      52             :     EXC_COLOR_CELLAREA,         /// Background area of a cell.
      53             :     EXC_COLOR_CHARTTEXT,        /// Text color in a chart.
      54             :     EXC_COLOR_CHARTLINE,        /// Line in a chart.
      55             :     EXC_COLOR_CHARTAREA,        /// Area in a chart.
      56             :     EXC_COLOR_CTRLTEXT,         /// Text color in a form control.
      57             :     EXC_COLOR_GRID,              /// Spreadsheet grid color.
      58             :     EXC_COLOR_TABBG             /// Spreadsheet tab bg color.
      59             : };
      60             : 
      61             : class XclExpPaletteImpl;
      62             : 
      63             : /** Stores all used colors in the document.
      64             : 
      65             :     Supports color reduction to the maximum count of the current BIFF version.
      66             :     An instance of this class collects all colors in the conversion phase of
      67             :     the export, using the InsertColor() function. It returns a unique
      68             :     identidier for each passed color.
      69             : 
      70             :     After the entire document is converted, the Finalize() function will reduce
      71             :     the palette to the  number of colors supported by the current BIFF version.
      72             : 
      73             :     Then, in the streaming phase, the functions GetColorIndex() and
      74             :     GetMixedColors() return the real Excel palette index for all color
      75             :     identifiers.
      76             :  */
      77             : class XclExpPalette : public XclDefaultPalette, public XclExpRecord
      78             : {
      79             : public:
      80             :     explicit            XclExpPalette( const XclExpRoot& rRoot );
      81             :     virtual             ~XclExpPalette();
      82             : 
      83             :     /** Inserts the color into the list and updates weighting.
      84             :         @param nAutoDefault  The Excel palette index for automatic color.
      85             :         @return  A unique ID for this color. */
      86             :     sal_uInt32          InsertColor( const Color& rColor, XclExpColorType eType, sal_uInt16 nAutoDefault = 0 );
      87             :     /** Returns the color ID representing a fixed Excel palette index (i.e. for auto colors). */
      88             :     static sal_uInt32   GetColorIdFromIndex( sal_uInt16 nIndex );
      89             : 
      90             :     /** Reduces the color list to the maximum count of the current BIFF version. */
      91             :     void                Finalize();
      92             : 
      93             :     /** Returns the Excel palette index of the color with passed color ID. */
      94             :     sal_uInt16          GetColorIndex( sal_uInt32 nColorId ) const;
      95             : 
      96             :     /** Returns a foreground and background color for the two passed color IDs.
      97             :         @descr  If rnXclPattern contains a solid pattern, this function tries to find
      98             :         the two best fitting colors and a mix pattern (25%, 50% or 75%) for nForeColorId.
      99             :         This will result in a better approximation to the passed foreground color. */
     100             :     void                GetMixedColors(
     101             :                             sal_uInt16& rnXclForeIx, sal_uInt16& rnXclBackIx, sal_uInt8& rnXclPattern,
     102             :                             sal_uInt32 nForeColorId, sal_uInt32 nBackColorId ) const;
     103             : 
     104             :     /** Returns the RGB color data for a (non-zero-based) Excel palette entry.
     105             :         @return  The color from current or default palette or COL_AUTO, if nothing else found. */
     106             :     ColorData           GetColorData( sal_uInt16 nXclIndex ) const;
     107             :     /** Returns the color for a (non-zero-based) Excel palette entry.
     108             :         @return  The color from current or default palette or COL_AUTO, if nothing else found. */
     109           0 :     inline Color        GetColor( sal_uInt16 nXclIndex ) const
     110           0 :                             { return Color( GetColorData( nXclIndex ) ); }
     111             : 
     112             :     /** Saves the PALETTE record, if it differs from the default palette. */
     113             :     virtual void        Save( XclExpStream& rStrm ) SAL_OVERRIDE;
     114             :     virtual void        SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
     115             : 
     116             : private:
     117             :     /** Writes the contents of the PALETTE record. */
     118             :     virtual void        WriteBody( XclExpStream& rStrm ) SAL_OVERRIDE;
     119             : 
     120             : private:
     121             :     typedef boost::shared_ptr< XclExpPaletteImpl > XclExpPaletteImplRef;
     122             :     XclExpPaletteImplRef mxImpl;
     123             : };
     124             : 
     125             : // FONT record - font information =============================================
     126             : 
     127             : class Font;
     128             : class SvxFont;
     129             : 
     130             : const size_t EXC_FONTLIST_NOTFOUND = static_cast< size_t >( -1 );
     131             : 
     132             : /** Static helper functions for font export. */
     133             : class XclExpFontHelper
     134             : {
     135             : public:
     136             :     /** Returns the script type of the first font item found in the item set and its parents. */
     137             :     static sal_Int16    GetFirstUsedScript(
     138             :                             const XclExpRoot& rRoot,
     139             :                             const SfxItemSet& rItemSet );
     140             : 
     141             :     /** Returns a VCL font object filled from the passed item set. */
     142             :     static Font         GetFontFromItemSet(
     143             :                             const XclExpRoot& rRoot,
     144             :                             const SfxItemSet& rItemSet,
     145             :                             sal_Int16 nScript );
     146             : 
     147             :     /** Returns true, if at least one font related item is set in the passed item set.
     148             :         @param bDeep  true = Searches in parent item sets too. */
     149             :     static bool         CheckItems(
     150             :                             const XclExpRoot& rRoot,
     151             :                             const SfxItemSet& rItemSet,
     152             :                             sal_Int16 nScript,
     153             :                             bool bDeep );
     154             : 
     155             : private:
     156             :                             XclExpFontHelper();
     157             :                             ~XclExpFontHelper();
     158             : };
     159             : 
     160             : /** Stores all data of an Excel font and provides export of FONT records. */
     161           0 : class XclExpFont : public XclExpRecord, protected XclExpRoot
     162             : {
     163             : public:
     164             :     explicit            XclExpFont( const XclExpRoot& rRoot,
     165             :                             const XclFontData& rFontData, XclExpColorType eColorType );
     166             : 
     167             :     /** Returns read-only access to font data. */
     168           0 :     inline const XclFontData& GetFontData() const { return maData; }
     169             :     /** Returns the font color identifier. */
     170           0 :     inline sal_uInt32   GetFontColorId() const { return mnColorId; }
     171             :     /** Compares this font with the passed font data.
     172             :         @param nHash  The hash value calculated from the font data. */
     173             :     virtual bool        Equals( const XclFontData& rFontData, sal_uInt32 nHash ) const;
     174             : 
     175             :     virtual void        SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
     176             : 
     177             : private:
     178             :     /** Writes the contents of the FONT record. */
     179             :     virtual void        WriteBody( XclExpStream& rStrm ) SAL_OVERRIDE;
     180             : 
     181             : private:
     182             :     XclFontData         maData;         /// All font attributes.
     183             :     sal_uInt32          mnColorId;      /// Unique color ID for text color.
     184             :     sal_uInt32          mnHash;         /// Hash value for fast comparison.
     185             : };
     186             : 
     187             : /** Used as placeholder for font index 4, which is not used in Excel. */
     188           0 : class XclExpBlindFont : public XclExpFont
     189             : {
     190             : public:
     191             :     explicit            XclExpBlindFont( const XclExpRoot& rRoot );
     192             : 
     193             :     /** Returns always false to never find this font while searching the font list. */
     194             :     virtual bool        Equals( const XclFontData& rFontData, sal_uInt32 nHash ) const SAL_OVERRIDE;
     195             : 
     196             :     /** Skips writing this record. */
     197             :     virtual void        Save( XclExpStream& rStrm ) SAL_OVERRIDE;
     198             : };
     199             : 
     200             : class ScPatternAttr;
     201             : 
     202             : /** Stores the data of all fonts used in the document. */
     203           0 : class XclExpFontBuffer : public XclExpRecordBase, protected XclExpRoot
     204             : {
     205             : public:
     206             :     explicit            XclExpFontBuffer( const XclExpRoot& rRoot );
     207             : 
     208             :     /** Returns the specified font from font list. */
     209             :     const XclExpFont*   GetFont( sal_uInt16 nXclFont ) const;
     210             :     /** Returns the application font data of this file, needed e.g. for column width. */
     211             :     const XclFontData&  GetAppFontData() const;
     212             : 
     213             :     /** Inserts a new font with the passed font data into the buffer if not present.
     214             :         @param bAppFont  true = Sets the application font; false = Inserts a new font.
     215             :         @return  The resulting Excel font index. */
     216             :     sal_uInt16          Insert( const XclFontData& rFontData,
     217             :                             XclExpColorType eColorType, bool bAppFont = false );
     218             :     /** Inserts the font into the buffer if not present.
     219             :         @param bAppFont  true = Sets the application font; false = Inserts a new font.
     220             :         @return  The resulting Excel font index. */
     221             :     sal_uInt16          Insert( const Font& rFont,
     222             :                             XclExpColorType eColorType, bool bAppFont = false );
     223             :     /** Inserts the SvxFont into the buffer if not present, e.g. where escapements are used.
     224             :         @param bAppFont  true = Sets the application font; false = Inserts a new font.
     225             :         @return  The resulting Excel font index. */
     226             :     sal_uInt16          Insert( const SvxFont& rFont,
     227             :                             XclExpColorType eColorType, bool bAppFont = false );
     228             :     /** Inserts the font contained in the passed item set into the buffer, if not present.
     229             :         @param nScript  The script type of the font properties to be used.
     230             :         @param bAppFont  true = Sets the application font; false = Inserts a new font.
     231             :         @return  The resulting Excel font index. */
     232             :     sal_uInt16          Insert( const SfxItemSet& rItemSet, sal_Int16 nScript,
     233             :                             XclExpColorType eColorType, bool bAppFont = false );
     234             : 
     235             :     /** Writes all FONT records contained in this buffer. */
     236             :     virtual void        Save( XclExpStream& rStrm ) SAL_OVERRIDE;
     237             :     virtual void        SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
     238             : 
     239             : private:
     240             :     /** Initializes the default fonts for the current BIFF version. */
     241             :     void                InitDefaultFonts();
     242             :     /** Tries to find the passed font and returns the current list index. */
     243             :     size_t              Find( const XclFontData& rFontData );
     244             : 
     245             : private:
     246             :     typedef XclExpRecordList< XclExpFont >  XclExpFontList;
     247             :     typedef XclExpFontList::RecordRefType   XclExpFontRef;
     248             : 
     249             :     XclExpFontList      maFontList;     /// List of all FONT records.
     250             :     size_t              mnXclMaxSize;   /// Maximum number of fonts.
     251             : };
     252             : 
     253             : // FORMAT record - number formats =============================================
     254             : 
     255             : /** Stores a core number format index with corresponding Excel format index. */
     256           0 : struct XclExpNumFmt
     257             : {
     258             :     sal_uLong           mnScNumFmt;     /// Core index of the number format.
     259             :     sal_uInt16          mnXclNumFmt;    /// Resulting Excel format index.
     260             :     OUString            maNumFmtString; /// format string
     261             : 
     262           0 :     inline explicit     XclExpNumFmt( sal_uLong nScNumFmt, sal_uInt16 nXclNumFmt, const OUString& rFrmt ) :
     263           0 :                             mnScNumFmt( nScNumFmt ), mnXclNumFmt( nXclNumFmt ), maNumFmtString( rFrmt ) {}
     264             : 
     265             :     void SaveXml( XclExpXmlStream& rStrm );
     266             : };
     267             : 
     268             : class SvNumberFormatter;
     269             : typedef ::std::auto_ptr< SvNumberFormatter >    SvNumberFormatterPtr;
     270             : 
     271             : /** Stores all number formats used in the document. */
     272             : class XclExpNumFmtBuffer : public XclExpRecordBase, protected XclExpRoot
     273             : {
     274             : public:
     275             :     explicit            XclExpNumFmtBuffer( const XclExpRoot& rRoot );
     276             :     virtual             ~XclExpNumFmtBuffer();
     277             : 
     278             :     /** Returns the core index of the current standard number format. */
     279           0 :     inline sal_uLong    GetStandardFormat() const { return mnStdFmt; }
     280             : 
     281             :     /** Inserts a number format into the format buffer.
     282             :         @param nScNumFmt  The core index of the number format.
     283             :         @return  The resulting Excel format index. */
     284             :     sal_uInt16          Insert( sal_uLong nScNumFmt );
     285             : 
     286             :     /** Writes all FORMAT records contained in this buffer. */
     287             :     virtual void        Save( XclExpStream& rStrm ) SAL_OVERRIDE;
     288             :     virtual void        SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
     289             : 
     290             : private:
     291             :     /** Writes the FORMAT record with index nXclIx and format string rFormatStr. */
     292             :     void                WriteFormatRecord( XclExpStream& rStrm, sal_uInt16 nXclNumFmt, const OUString& rFormatStr );
     293             :     /** Writes the FORMAT record represented by rFormat. */
     294             :     void                WriteFormatRecord( XclExpStream& rStrm, const XclExpNumFmt& rFormat );
     295             : 
     296             :     OUString            GetFormatCode ( sal_uInt16 nScNumFmt );
     297             : 
     298             : private:
     299             :     typedef ::std::vector< XclExpNumFmt >           XclExpNumFmtVec;
     300             : 
     301             :     SvNumberFormatterPtr mxFormatter;   /// Special number formatter for conversion.
     302             :     XclExpNumFmtVec     maFormatMap;    /// Maps core formats to Excel indexes.
     303             :     boost::scoped_ptr<NfKeywordTable>   mpKeywordTable; /// Replacement table.
     304             :     sal_uLong           mnStdFmt;       /// Key for standard number format.
     305             :     sal_uInt16          mnXclOffset;    /// Offset to first user defined format.
     306             : };
     307             : 
     308             : // XF, STYLE record - Cell formatting =========================================
     309             : 
     310             : /** Extends the XclCellProt struct for export.
     311             :     @descr  Provides functions to fill from item sets and to fill to Excel record data. */
     312           0 : struct XclExpCellProt : public XclCellProt
     313             : {
     314             :     /** Fills the protection attributes from the passed item set.
     315             :         @return  true = At least one protection item is set. */
     316             :     bool                FillFromItemSet( const SfxItemSet& rItemSet, bool bStyle = false );
     317             : 
     318             :     /** Fills the data to the passed fields of a BIFF3-BIFF8 XF record. */
     319             :     void                FillToXF3( sal_uInt16& rnProt ) const;
     320             : 
     321             :     void                SaveXml( XclExpXmlStream& rStrm ) const;
     322             : };
     323             : 
     324             : /** Extends the XclCellAlign struct for export.
     325             :     @descr  Provides functions to fill from item sets and to fill to Excel record data. */
     326           0 : struct XclExpCellAlign : public XclCellAlign
     327             : {
     328             :     /** Fills the alignment attributes from the passed item set.
     329             :         @descr  Fills only the attributes exported in the passed BIFF version.
     330             :         @param bForceLineBreak  true = Set line break flag unconditionally.
     331             :         @return  true = At least one alignment item is set. */
     332             :     bool                FillFromItemSet( const SfxItemSet& rItemSet,
     333             :                             bool bForceLineBreak, XclBiff eBiff, bool bStyle = false );
     334             : 
     335             :     /** Fills the data to the passed fields of a BIFF5/BIFF7 XF record. */
     336             :     void                FillToXF5( sal_uInt16& rnAlign ) const;
     337             :     /** Fills the data to the passed fields of a BIFF8 XF record. */
     338             :     void                FillToXF8( sal_uInt16& rnAlign, sal_uInt16& rnMiscAttrib ) const;
     339             : 
     340             :     void                SaveXml( XclExpXmlStream& rStrm ) const;
     341             : };
     342             : 
     343             : /** Extends the XclCellBorder struct for export.
     344             :     @descr  Provides functions to fill from item sets and to fill to Excel record data. */
     345             : struct XclExpCellBorder : public XclCellBorder
     346             : {
     347             :     sal_uInt32          mnLeftColorId;      /// Color ID for left line.
     348             :     sal_uInt32          mnRightColorId;     /// Color ID for right line.
     349             :     sal_uInt32          mnTopColorId;       /// Color ID for top line.
     350             :     sal_uInt32          mnBottomColorId;    /// Color ID for bottom line.
     351             :     sal_uInt32          mnDiagColorId;      /// Color ID for diagonal line(s).
     352             : 
     353             :     explicit            XclExpCellBorder();
     354             : 
     355             :     /** Fills the border attributes from the passed item set.
     356             :         @descr  Fills only the attributes exported in the passed BIFF version.
     357             :         @return  true = At least one border item is set. */
     358             :     bool                FillFromItemSet( const SfxItemSet& rItemSet,
     359             :                             XclExpPalette& rPalette, XclBiff eBiff, bool bStyle = false );
     360             :     /** Fills the mn***Color base members from the mn***ColorId members. */
     361             :     void                SetFinalColors( const XclExpPalette& rPalette );
     362             : 
     363             :     /** Fills the data to the passed fields of a BIFF5/BIFF7 XF record. */
     364             :     void                FillToXF5( sal_uInt32& rnBorder, sal_uInt32& rnArea ) const;
     365             :     /** Fills the data to the passed fields of a BIFF8 XF record. */
     366             :     void                FillToXF8( sal_uInt32& rnBorder1, sal_uInt32& rnBorder2 ) const;
     367             : 
     368             :     /** Fills the data to the passed fields of a BIFF8 CF (conditional format) record. */
     369             :     void                FillToCF8( sal_uInt16& rnLine, sal_uInt32& rnColor ) const;
     370             : 
     371             :     void                SaveXml( XclExpXmlStream& rStrm ) const;
     372             : };
     373             : 
     374             : /** Extends the XclCellArea struct for export.
     375             :     @descr  Provides functions to fill from item sets and to fill to Excel record data. */
     376             : struct XclExpCellArea : public XclCellArea
     377             : {
     378             :     sal_uInt32          mnForeColorId;  /// Foreground color ID.
     379             :     sal_uInt32          mnBackColorId;  /// Background color ID.
     380             : 
     381             :     explicit            XclExpCellArea();
     382             : 
     383             :     /** Fills the area attributes from the passed item set.
     384             :         @return  true = At least one area item is set. */
     385             :     bool                FillFromItemSet(
     386             :                             const SfxItemSet& rItemSet, XclExpPalette& rPalette,
     387             :                             bool bStyle = false );
     388             :     /** Fills the mn***Color base members from the mn***ColorId members. */
     389             :     void                SetFinalColors( const XclExpPalette& rPalette );
     390             : 
     391             :     /** Fills the data to the passed fields of a BIFF5/BIFF7 XF record. */
     392             :     void                FillToXF5( sal_uInt32& rnArea ) const;
     393             :     /** Fills the data to the passed fields of a BIFF8 XF record. */
     394             :     void                FillToXF8( sal_uInt32& rnBorder2, sal_uInt16& rnArea ) const;
     395             : 
     396             :     /** Fills the data to the passed fields of a BIFF8 CF (conditional format) record. */
     397             :     void                FillToCF8( sal_uInt16& rnPattern, sal_uInt16& rnColor ) const;
     398             : 
     399             :     void                SaveXml( XclExpXmlStream& rStrm ) const;
     400             : };
     401             : 
     402           0 : struct XclExpColor
     403             : {
     404             :     Color maColor;
     405             : 
     406             :     bool FillFromItemSet( const SfxItemSet& rItemSet );
     407             : 
     408             :     void SaveXml( XclExpXmlStream& rStrm ) const;
     409             : };
     410             : 
     411             : /** A combination of unique XF identifier with real Excel XF index. */
     412             : struct XclExpXFId
     413             : {
     414             :     sal_uInt32          mnXFId;         /// Temporary XF identifier.
     415             :     sal_uInt16          mnXFIndex;      /// Real Excel XF index.
     416             : 
     417             :     explicit            XclExpXFId();
     418             :     explicit            XclExpXFId( sal_uInt32 nXFId );
     419             : 
     420             :     /** Converts the XF identifier in mnXFId to an Excel XF index and stores it in mnXFIndex. */
     421             :     void                ConvertXFIndex( const XclExpRoot& rRoot );
     422             : };
     423             : 
     424             : class SfxStyleSheetBase;
     425             : 
     426             : /** Represents an XF record which contains all formatting data of a cell or cell style. */
     427           0 : class XclExpXF : public XclXFBase, public XclExpRecord, protected XclExpRoot
     428             : {
     429             : public:
     430             :     /** Constructs a cell XF record from the passed Calc cell formatting. */
     431             :     explicit            XclExpXF(
     432             :                             const XclExpRoot& rRoot,
     433             :                             const ScPatternAttr& rPattern,
     434             :                             sal_Int16 nScript,
     435             :                             sal_uLong nScForceNumFmt = NUMBERFORMAT_ENTRY_NOT_FOUND,
     436             :                             sal_uInt16 nForceXclFont = EXC_FONT_NOTFOUND,
     437             :                             bool bForceLineBreak = false );
     438             :     /** Constructs a style XF record from the passed cell style sheet. */
     439             :     explicit            XclExpXF(
     440             :                             const XclExpRoot& rRoot,
     441             :                             const SfxStyleSheetBase& rStyleSheet );
     442             : 
     443             :     /** Returns the cell protection settings of this XF. */
     444           0 :     const XclExpCellProt& GetProtectionData() const { return maProtection; }
     445             :     /** Returns the alignment settings of this XF. */
     446           0 :     const XclExpCellAlign& GetAlignmentData() const { return maAlignment; }
     447             :     /** Returns the cell border settings of this XF. */
     448           0 :     const XclExpCellBorder& GetBorderData() const { return maBorder; }
     449             :     /** Returns the cell fill settings of this XF. */
     450           0 :     const XclExpCellArea& GetAreaData() const { return maArea; }
     451             : 
     452             :     /** Returns true, if this XF record represents the passed cell formatting.
     453             :         @descr  Searches for cell XFs only. */
     454             :     bool                Equals(
     455             :                             const ScPatternAttr& rPattern,
     456             :                             sal_uLong nScForceNumFmt,
     457             :                             sal_uInt16 nForceXclFont,
     458             :                             bool bForceLineBreak ) const;
     459             : 
     460             :     /** Returns true, if this XF record represents the passed style.
     461             :         @descr  Searches for style XFs only. */
     462             :     bool                Equals( const SfxStyleSheetBase& rStyleSheet ) const;
     463             : 
     464             :     /** Sets the resulting Excel palette index from all used color IDs (border and area). */
     465             :     void                SetFinalColors();
     466             : 
     467             :     /** Returns true, if this XF record is completely equal to the passed. */
     468             :     bool                Equals( const XclExpXF& rCmpXF ) const;
     469             : 
     470             :     void                SetXmlIds( sal_uInt32 nBorderId, sal_uInt32 nFillId );
     471             : 
     472             :     virtual void        SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
     473             : 
     474             : protected:
     475             :     explicit            XclExpXF( const XclExpRoot& rRoot, bool bCellXF );
     476             : 
     477             : protected:  // access for XclExpDefaultXF
     478             :     const SfxItemSet*   mpItemSet;          /// Pointer to the item set (we do not own it).
     479             : 
     480             :     XclExpCellProt      maProtection;       /// Cell protection flags.
     481             :     XclExpCellAlign     maAlignment;        /// All alignment attributes.
     482             :     XclExpCellBorder    maBorder;           /// Border line style.
     483             :     XclExpCellArea      maArea;             /// Background area style.
     484             :     sal_uInt32          mnParentXFId;       /// XF ID of parent XF record.
     485             :     sal_uLong               mnScNumFmt;         /// Calc number format index.
     486             :     sal_uInt16          mnXclFont;          /// Excel font index.
     487             :     sal_uInt16          mnXclNumFmt;        /// Excel number format index.
     488             :     sal_Int32           mnBorderId;         /// OOXML Border Index
     489             :     sal_Int32           mnFillId;           /// OOXML Fill Index
     490             : 
     491             : private:
     492             :     using               XclXFBase::Equals;
     493             : 
     494             :     /** Initializes with default values. */
     495             :     void                InitDefault();
     496             :     /** Fills all members from the passed item set.
     497             :         @param bDefStyle  true = This is the "Default"/"Normal" style - needs special handling. */
     498             :     void                Init(
     499             :                             const SfxItemSet& rItemSet,
     500             :                             sal_Int16 nScript,
     501             :                             sal_uLong nForceScNumFmt,
     502             :                             sal_uInt16 nForceXclFont,
     503             :                             bool bForceLineBreak,
     504             :                             bool bDefStyle );
     505             : 
     506             :     /** Returns the bits specifying the used attributes.
     507             :         @descr  In cell XFs a set bit means a used attribute, in style XF a cleared
     508             :         bit means a used attribute. This method regards the cell/style state.
     509             :         @return  The mask based on bit 0 (not yet bit-shifted as needed for export). */
     510             :     sal_uInt8           GetUsedFlags() const;
     511             : 
     512             :     void                WriteBody5( XclExpStream& rStrm );
     513             :     void                WriteBody8( XclExpStream& rStrm );
     514             : 
     515             :     /** Writes the contents of the XF record. */
     516             :     virtual void        WriteBody( XclExpStream& rStrm ) SAL_OVERRIDE;
     517             : };
     518             : 
     519             : /** Represents a default XF record. Supports methods to set attributes directly. */
     520           0 : class XclExpDefaultXF : public XclExpXF
     521             : {
     522             : public:
     523             :     explicit            XclExpDefaultXF( const XclExpRoot& rRoot, bool bCellXF );
     524             : 
     525             :     /** Sets the Excel font index. */
     526             :     void                SetFont( sal_uInt16 nXclFont );
     527             :     /** Sets the Excel number format index. */
     528             :     void                SetNumFmt( sal_uInt16 nXclNumFmt );
     529             : };
     530             : 
     531             : /** Represents a STYLE record containing the data of a cell style.
     532             :     @descr  The calss is able to store built-in and user-defined styles. */
     533           0 : class XclExpStyle : public XclExpRecord
     534             : {
     535             : public:
     536             :     explicit            XclExpStyle( sal_uInt32 nXFId, const OUString& rStyleName );
     537             :     explicit            XclExpStyle( sal_uInt32 nXFId, sal_uInt8 nStyleId, sal_uInt8 nLevel = EXC_STYLE_NOLEVEL );
     538             : 
     539             :     /** Returns true, if this record represents an Excel built-in style. */
     540           0 :     inline bool         IsBuiltIn() const { return mnStyleId != EXC_STYLE_USERDEF; }
     541             : 
     542             :     inline const OUString&    GetName() const { return maName; }
     543             : 
     544             :     virtual void        SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
     545             : 
     546             : private:
     547             :     /** Writes the contents of the STYLE record. */
     548             :     virtual void        WriteBody( XclExpStream& rStrm ) SAL_OVERRIDE;
     549             : 
     550             : private:
     551             :     OUString            maName;         /// Name of the cell style.
     552             :     XclExpXFId          maXFId;         /// XF identifier for style formatting.
     553             :     sal_uInt8           mnStyleId;      /// Built-in style identifier.
     554             :     sal_uInt8           mnLevel;        /// Outline level for RowLevel and ColLevel styles.
     555             : };
     556             : 
     557             : /** Stores all XF records (cell formats and cell styles) in the document.
     558             : 
     559             :     Stores also the names of user defined cell styles (STYLE records). Supports
     560             :     reduction to the maximum count of XF records of the current BIFF version.
     561             : 
     562             :     An instance of this class collects all XF records in the conversion phase
     563             :     of the export, using the Insert() and InsertStyle() functions. It returns a
     564             :     unique identidier for each XF record.
     565             : 
     566             :     After the entire document is converted, the Finalize() function will reduce
     567             :     the list to the number of XF records supported by the current BIFF version.
     568             : 
     569             :     Then, in the streaming phase, the function GetXFIndex() returns the real
     570             :     Excel XF index for all XF identifiers.
     571             :  */
     572           0 : class XclExpXFBuffer : public XclExpRecordBase, protected XclExpRoot
     573             : {
     574             : public:
     575             :     explicit            XclExpXFBuffer( const XclExpRoot& rRoot );
     576             : 
     577             :     /** Inserts predefined built-in styles and user-defined styles. */
     578             :     void                Initialize();
     579             : 
     580             :     /** Finds or creates a cell XF record for the passed item set.
     581             :         @return  A unique XF record ID. */
     582             :     sal_uInt32          Insert( const ScPatternAttr* pPattern, sal_Int16 nScript );
     583             :     /** Finds or creates a cell XF record for the passed item set.
     584             :         @param nForceXclFont  The font to be exported. If not equal to EXC_FONT_NOTFOUND,
     585             :             this font index will be used unconditionally and the cell font will be ignored.
     586             :         @param bForceLineBreak  true = Set line break flag unconditionally.
     587             :             This is required for cells that contain multi-line text.
     588             :         @return  A unique XF record ID. */
     589             :     sal_uInt32          InsertWithFont(
     590             :                             const ScPatternAttr* pPattern, sal_Int16 nScript,
     591             :                             sal_uInt16 nForceXclFont,
     592             :                             bool bForceLineBreak );
     593             :     /** Finds or creates a cell XF record for the passed item set, with custom number format.
     594             :         @param nXFFlags  Additional flags allowing to control the creation of an XF.
     595             :         @param nForceScNumFmt  The number format to be exported, e.g. formula
     596             :             result type. This format will always overwrite the cell's number format.
     597             :         @param bForceLineBreak  true = Set line break flag unconditionally.
     598             :             This is required for cells that contain multi-line text.
     599             :         @return  A unique XF record ID. */
     600             :     sal_uInt32          InsertWithNumFmt(
     601             :                             const ScPatternAttr* pPattern, sal_Int16 nScript,
     602             :                             sal_uLong nForceScNumFmt,
     603             :                             bool bForceLineBreak );
     604             :     /** Inserts the passed cell style. Creates a style XF record and a STYLE record.
     605             :         @return  A unique XF record ID. */
     606             :     sal_uInt32          InsertStyle( const SfxStyleSheetBase* pStyleSheet );
     607             :     /** Returns the XF identifier representing a fixed Excel XF index (e.g. for built-in XFs). */
     608             :     static sal_uInt32   GetXFIdFromIndex( sal_uInt16 nXFIndex );
     609             :     /** Returns the XF identifier representing the default cell XF. */
     610             :     static sal_uInt32   GetDefCellXFId();
     611             : 
     612             :     /** Returns an XF record by its unique identifier. */
     613             :     const XclExpXF*     GetXFById( sal_uInt32 nXFId ) const;
     614             : 
     615             :     /** Reduces the XF record list to the maximum allowed number of records. */
     616             :     void                Finalize();
     617             : 
     618             :     /** Returns the Excel XF index of the XF record with passed XF ID. */
     619             :     sal_uInt16          GetXFIndex( sal_uInt32 nXFId ) const;
     620             : 
     621             :     sal_Int32           GetXmlStyleIndex( sal_uInt32 nXFId ) const;
     622             :     sal_Int32           GetXmlCellIndex( sal_uInt32 nXFId ) const;
     623             : 
     624             :     /** Writes all XF records contained in this buffer. */
     625             :     virtual void        Save( XclExpStream& rStrm ) SAL_OVERRIDE;
     626             :     virtual void        SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
     627             : 
     628             : private:
     629             :     typedef XclExpRecordList< XclExpXF >    XclExpXFList;
     630             :     typedef XclExpXFList::RecordRefType     XclExpXFRef;
     631             :     typedef XclExpRecordList< XclExpStyle > XclExpStyleList;
     632             : 
     633             : private:
     634             :     /** Returns the XF ID of the cell XF containing the passed format. */
     635             :     sal_uInt32          FindXF( const ScPatternAttr& rPattern, sal_uLong nForceScNumFmt,
     636             :                             sal_uInt16 nForceXclFont, bool bForceLineBreak ) const;
     637             :     /** Returns the XF ID of the style XF containing the passed style. */
     638             :     sal_uInt32          FindXF( const SfxStyleSheetBase& rStyleSheet ) const;
     639             : 
     640             :     /** Returns the XF ID of a built-in style XF, searches by style identifier. */
     641             :     sal_uInt32          FindBuiltInXF( sal_uInt8 nStyleId, sal_uInt8 nLevel = EXC_STYLE_NOLEVEL ) const;
     642             : 
     643             :     /** Tries to find the XF record containing the passed format or inserts a new record.
     644             :         @return  The XF record ID. */
     645             :     sal_uInt32          InsertCellXF( const ScPatternAttr* pPattern, sal_Int16 nScript,
     646             :                             sal_uLong nForceScNumFmt,
     647             :                             sal_uInt16 nForceXclFont, bool bForceLineBreak );
     648             :     /** Inserts the passed cell style. Creates a style XF record and a STYLE record.
     649             :         @return  The XF record ID. */
     650             :     sal_uInt32          InsertStyleXF( const SfxStyleSheetBase& rStyleSheet );
     651             : 
     652             :     /** Inserts an XF and a STYLE record for all user defined style sheets. */
     653             :     void                InsertUserStyles();
     654             : 
     655             :     /** Inserts a built-in XF record without a STYLE record and returns the XF ID.
     656             :         @param bCreateStyleRec  true = Creates the related STYLE record. */
     657             :     sal_uInt32          AppendBuiltInXF( XclExpXFRef xXF,
     658             :                             sal_uInt8 nStyleId, sal_uInt8 nLevel = EXC_STYLE_NOLEVEL );
     659             :     /** Inserts a built-in XF and STYLE record and returns the XF ID.
     660             :         @param bCreateStyleRec  true = Creates the related STYLE record. */
     661             :     sal_uInt32          AppendBuiltInXFWithStyle( XclExpXFRef xXF,
     662             :                             sal_uInt8 nStyleId, sal_uInt8 nLevel = EXC_STYLE_NOLEVEL );
     663             : 
     664             :     /** Inserts all default XF and STYLE records. */
     665             :     void                InsertDefaultRecords();
     666             : 
     667             :     /** Appends a XF index to the internal ID<->index maps. */
     668             :     void                AppendXFIndex( sal_uInt32 nXFId );
     669             : 
     670             :     void                AddBorderAndFill( const XclExpXF& rXF );
     671             :     void                SaveXFXml( XclExpXmlStream& rStrm, XclExpXF& rXF );
     672             : 
     673             : private:
     674             :     /** Extended info about a built-in XF. */
     675             :     struct XclExpBuiltInInfo
     676             :     {
     677             :         sal_uInt8           mnStyleId;          /// Built-in style identifier.
     678             :         sal_uInt8           mnLevel;            /// Level for RowLevel/ColLevel styles.
     679             :         bool                mbPredefined;       /// true = XF still predefined.
     680             :         bool                mbHasStyleRec;      /// true = STYLE record created.
     681             :         explicit            XclExpBuiltInInfo();
     682             :     };
     683             :     typedef ::std::map< sal_uInt32, XclExpBuiltInInfo > XclExpBuiltInMap;
     684             :     typedef ::std::vector< XclExpCellBorder >           XclExpBorderList;
     685             :     typedef ::std::vector< XclExpCellArea >             XclExpFillList;
     686             : 
     687             :     XclExpXFList        maXFList;           /// List of all XF records.
     688             :     XclExpStyleList     maStyleList;        /// List of all STYLE records.
     689             :     XclExpBuiltInMap    maBuiltInMap;       /// Contained elements describe built-in XFs.
     690             :     ScfUInt16Vec        maXFIndexVec;       /// Maps XF IDs to XF indexes.
     691             :     ScfUInt16Vec        maStyleIndexes;     /// Maps XF IDs to OOXML Style indexes
     692             :     ScfUInt16Vec        maCellIndexes;      /// Maps XF IDs to OOXML Cell indexes
     693             :     XclExpXFList        maSortedXFList;     /// List of XF records in XF index order.
     694             :     XclExpBorderList    maBorders;          /// List of borders used by XF records
     695             :     XclExpFillList      maFills;            /// List of fills used by XF records
     696             : 
     697             : };
     698             : 
     699             : struct XclDxfStyle
     700             : {
     701             : };
     702             : 
     703             : class XclExpDxf : public XclExpRecordBase, protected XclExpRoot
     704             : {
     705             : public:
     706             :     XclExpDxf( const XclExpRoot& rRoot, XclExpCellAlign* pAlign, XclExpCellBorder* pBorder,
     707             :             XclExpFont* pFont, XclExpNumFmt* pNumberFmt, XclExpCellProt* pProt, XclExpColor* pColor);
     708             :     virtual ~XclExpDxf();
     709             : 
     710             :     virtual void SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
     711             : 
     712             : private:
     713             :     boost::scoped_ptr<XclExpCellAlign> mpAlign;
     714             :     boost::scoped_ptr<XclExpCellBorder> mpBorder;
     715             :     boost::scoped_ptr<XclExpFont> mpFont;
     716             :     boost::scoped_ptr<XclExpNumFmt> mpNumberFmt;
     717             :     boost::scoped_ptr<XclExpCellProt> mpProt;
     718             :     boost::scoped_ptr<XclExpColor> mpColor;
     719             : };
     720             : 
     721             : class XclExpDxfs : public XclExpRecordBase, protected XclExpRoot
     722             : {
     723             : public:
     724             :     XclExpDxfs( const XclExpRoot& rRoot );
     725           0 :     virtual ~XclExpDxfs() {}
     726             : 
     727             :     sal_Int32 GetDxfId(const OUString& rName);
     728             : 
     729             :     virtual void SaveXml( XclExpXmlStream& rStrm) SAL_OVERRIDE;
     730             : private:
     731             :     typedef boost::ptr_vector<XclExpDxf> DxfContainer;
     732             :     std::map<OUString, sal_Int32> maStyleNameToDxfId;
     733             :     DxfContainer maDxf;
     734             :     SvNumberFormatterPtr mxFormatter;   /// Special number formatter for conversion.
     735             :     boost::scoped_ptr<NfKeywordTable>   mpKeywordTable; /// Replacement table.
     736             : };
     737             : 
     738           0 : class XclExpXmlStyleSheet : public XclExpRecordBase, protected XclExpRoot
     739             : {
     740             : public:
     741             :     explicit            XclExpXmlStyleSheet( const XclExpRoot& rRoot );
     742             : 
     743             :     virtual void        SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
     744             : };
     745             : 
     746             : #endif
     747             : 
     748             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10