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