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

Generated by: LCOV version 1.10