Update ooo320-m1
[ooovba.git] / sc / source / filter / inc / xestyle.hxx
blob9508c8b3fe05e0bfccb671a53a0c61d18e300bf7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xestyle.hxx,v $
10 * $Revision: 1.20.32.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SC_XESTYLE_HXX
32 #define SC_XESTYLE_HXX
34 #include <map>
35 #include <tools/mempool.hxx>
36 #include <tools/string.hxx>
37 #include <svtools/zforlist.hxx>
38 #include <svtools/nfkeytab.hxx>
39 #include <svx/svxfont.hxx>
40 #include "xerecord.hxx"
41 #include "xlstyle.hxx"
42 #include "xeroot.hxx"
44 /* ============================================================================
45 - Buffers for style records (PALETTE, FONT, FORMAT, XF, STYLE).
46 ============================================================================ */
48 const sal_uInt16 EXC_ID_FONTLIST = 0x8031; /// For internal use only.
49 const sal_uInt16 EXC_ID_FORMATLIST = 0x801E; /// For internal use only.
50 const sal_uInt16 EXC_ID_XFLIST = 0x8043; /// For internal use only.
52 // PALETTE record - color information =========================================
54 /** Different types of colors in a document. */
55 enum XclExpColorType
57 EXC_COLOR_CELLTEXT, /// Text in a cell.
58 EXC_COLOR_CELLBORDER, /// Border of a cell.
59 EXC_COLOR_CELLAREA, /// Background area of a cell.
60 EXC_COLOR_CHARTTEXT, /// Text color in a chart.
61 EXC_COLOR_CHARTLINE, /// Line in a chart.
62 EXC_COLOR_CHARTAREA, /// Area in a chart.
63 EXC_COLOR_CTRLTEXT, /// Text color in a form control.
64 EXC_COLOR_GRID, /// Spreadsheet grid color.
65 EXC_COLOR_TABBG /// Spreadsheet tab bg color.
68 // ----------------------------------------------------------------------------
70 class XclExpPaletteImpl;
72 /** Stores all used colors in the document.
74 Supports color reduction to the maximum count of the current BIFF version.
75 An instance of this class collects all colors in the conversion phase of
76 the export, using the InsertColor() function. It returns a unique
77 identidier for each passed color.
79 After the entire document is converted, the Finalize() function will reduce
80 the palette to the number of colors supported by the current BIFF version.
82 Then, in the streaming phase, the functions GetColorIndex() and
83 GetMixedColors() return the real Excel palette index for all color
84 identifiers.
86 class XclExpPalette : public XclDefaultPalette, public XclExpRecord
88 public:
89 explicit XclExpPalette( const XclExpRoot& rRoot );
90 virtual ~XclExpPalette();
92 /** Inserts the color into the list and updates weighting.
93 @param nAutoDefault The Excel palette index for automatic color.
94 @return A unique ID for this color. */
95 sal_uInt32 InsertColor( const Color& rColor, XclExpColorType eType, sal_uInt16 nAutoDefault = 0 );
96 /** Returns the color ID representing a fixed Excel palette index (i.e. for auto colors). */
97 static sal_uInt32 GetColorIdFromIndex( sal_uInt16 nIndex );
99 /** Reduces the color list to the maximum count of the current BIFF version. */
100 void Finalize();
102 /** Returns the Excel palette index of the color with passed color ID. */
103 sal_uInt16 GetColorIndex( sal_uInt32 nColorId ) const;
105 /** Returns a foreground and background color for the two passed color IDs.
106 @descr If rnXclPattern contains a solid pattern, this function tries to find
107 the two best fitting colors and a mix pattern (25%, 50% or 75%) for nForeColorId.
108 This will result in a better approximation to the passed foreground color. */
109 void GetMixedColors(
110 sal_uInt16& rnXclForeIx, sal_uInt16& rnXclBackIx, sal_uInt8& rnXclPattern,
111 sal_uInt32 nForeColorId, sal_uInt32 nBackColorId ) const;
113 /** Returns the RGB color data for a (non-zero-based) Excel palette entry.
114 @return The color from current or default palette or COL_AUTO, if nothing else found. */
115 ColorData GetColorData( sal_uInt16 nXclIndex ) const;
116 /** Returns the color for a (non-zero-based) Excel palette entry.
117 @return The color from current or default palette or COL_AUTO, if nothing else found. */
118 inline Color GetColor( sal_uInt16 nXclIndex ) const
119 { return Color( GetColorData( nXclIndex ) ); }
121 /** Saves the PALETTE record, if it differs from the default palette. */
122 virtual void Save( XclExpStream& rStrm );
123 virtual void SaveXml( XclExpXmlStream& rStrm );
125 private:
126 /** Writes the contents of the PALETTE record. */
127 virtual void WriteBody( XclExpStream& rStrm );
129 private:
130 typedef ScfRef< XclExpPaletteImpl > XclExpPaletteImplRef;
131 XclExpPaletteImplRef mxImpl;
134 // FONT record - font information =============================================
136 class Font;
137 class SvxFont;
139 const size_t EXC_FONTLIST_NOTFOUND = static_cast< size_t >( -1 );
141 // ----------------------------------------------------------------------------
143 /** Stores all data of an Excel font and provides export of FONT records. */
144 class XclExpFont : public XclExpRecord, protected XclExpRoot
146 public:
147 explicit XclExpFont( const XclExpRoot& rRoot,
148 const XclFontData& rFontData, XclExpColorType eColorType );
150 /** Returns read-only access to font data. */
151 inline const XclFontData& GetFontData() const { return maData; }
152 /** Returns the font color identifier. */
153 inline sal_uInt32 GetFontColorId() const { return mnColorId; }
154 /** Compares this font with the passed font data.
155 @param nHash The hash value calculated from the font data. */
156 virtual bool Equals( const XclFontData& rFontData, sal_uInt32 nHash ) const;
158 virtual void SaveXml( XclExpXmlStream& rStrm );
160 private:
161 /** Writes the contents of the FONT record. */
162 virtual void WriteBody( XclExpStream& rStrm );
164 private:
165 XclFontData maData; /// All font attributes.
166 sal_uInt32 mnColorId; /// Unique color ID for text color.
167 sal_uInt32 mnHash; /// Hash value for fast comparison.
170 // ----------------------------------------------------------------------------
172 /** Used as placeholder for font index 4, which is not used in Excel. */
173 class XclExpBlindFont : public XclExpFont
175 public:
176 explicit XclExpBlindFont( const XclExpRoot& rRoot );
178 /** Returns always false to never find this font while searching the font list. */
179 virtual bool Equals( const XclFontData& rFontData, sal_uInt32 nHash ) const;
181 /** Skips writing this record. */
182 virtual void Save( XclExpStream& rStrm );
185 // ----------------------------------------------------------------------------
187 class ScPatternAttr;
189 /** Stores the data of all fonts used in the document. */
190 class XclExpFontBuffer : public XclExpRecordBase, protected XclExpRoot
192 public:
193 explicit XclExpFontBuffer( const XclExpRoot& rRoot );
195 /** Returns the specified font from font list. */
196 const XclExpFont* GetFont( sal_uInt16 nXclFont ) const;
197 /** Returns the application font data of this file, needed e.g. for column width. */
198 const XclFontData& GetAppFontData() const;
200 /** Inserts a new font with the passed font data into the buffer if not present.
201 @param bAppFont true = Sets the application font; false = Inserts a new font.
202 @return The resulting Excel font index. */
203 sal_uInt16 Insert( const XclFontData& rFontData,
204 XclExpColorType eColorType, bool bAppFont = false );
205 /** Inserts the font into the buffer if not present.
206 @param bAppFont true = Sets the application font; false = Inserts a new font.
207 @return The resulting Excel font index. */
208 sal_uInt16 Insert( const Font& rFont,
209 XclExpColorType eColorType, bool bAppFont = false );
210 /** Inserts the SvxFont into the buffer if not present, e.g. where escapements are used.
211 @param bAppFont true = Sets the application font; false = Inserts a new font.
212 @return The resulting Excel font index. */
213 sal_uInt16 Insert( const SvxFont& rFont,
214 XclExpColorType eColorType, bool bAppFont = false );
215 /** Inserts the font contained in the passed item set into the buffer, if not present.
216 @param nScript The script type of the font properties to be used.
217 @param bAppFont true = Sets the application font; false = Inserts a new font.
218 @return The resulting Excel font index. */
219 sal_uInt16 Insert( const SfxItemSet& rItemSet, sal_Int16 nScript,
220 XclExpColorType eColorType, bool bAppFont = false );
221 /** Inserts the font contained in rPattern into the buffer if not present.
222 @param nScript The script type of the font properties to be used.
223 @param bAppFont true = Sets the application font; false = Inserts a new font.
224 @return The resulting Excel font index. */
225 sal_uInt16 Insert( const ScPatternAttr& rPattern, sal_Int16 nScript,
226 XclExpColorType eColorType, bool bAppFont = false );
228 /** Writes all FONT records contained in this buffer. */
229 virtual void Save( XclExpStream& rStrm );
230 virtual void SaveXml( XclExpXmlStream& rStrm );
232 /** Returns the script type of the first font item found in the item set and its parents. */
233 static sal_Int16 GetFirstUsedScript( const SfxItemSet& rItemSet );
235 /** Returns a VCL font object filled from the passed item set. */
236 static Font GetFontFromItemSet( const SfxItemSet& rItemSet, sal_Int16 nScript );
237 /** Returns true, if at least one font related item is set in the passed item set.
238 @param bDeep true = Searches in parent item sets too. */
239 static bool CheckItems( const SfxItemSet& rItemSet, sal_Int16 nScript, bool bDeep );
241 private:
242 /** Initializes the default fonts for the current BIFF version. */
243 void InitDefaultFonts();
244 /** Tries to find the passed font and returns the current list index. */
245 size_t Find( const XclFontData& rFontData );
247 private:
248 typedef XclExpRecordList< XclExpFont > XclExpFontList;
249 typedef XclExpFontList::RecordRefType XclExpFontRef;
251 XclExpFontList maFontList; /// List of all FONT records.
252 size_t mnXclMaxSize; /// Maximum number of fonts.
255 // FORMAT record - number formats =============================================
257 /** Stores a core number format index with corresponding Excel format index. */
258 struct XclExpNumFmt
260 ULONG mnScNumFmt; /// Core index of the number format.
261 sal_uInt16 mnXclNumFmt; /// Resulting Excel format index.
263 inline explicit XclExpNumFmt( ULONG nScNumFmt, sal_uInt16 nXclNumFmt ) :
264 mnScNumFmt( nScNumFmt ), mnXclNumFmt( nXclNumFmt ) {}
267 // ----------------------------------------------------------------------------
269 class SvNumberFormatter;
271 /** Stores all number formats used in the document. */
272 class XclExpNumFmtBuffer : public XclExpRecordBase, protected XclExpRoot
274 public:
275 explicit XclExpNumFmtBuffer( const XclExpRoot& rRoot );
276 virtual ~XclExpNumFmtBuffer();
278 /** Returns the core index of the current standard number format. */
279 inline ULONG GetStandardFormat() const { return mnStdFmt; }
281 /** Inserts a number format into the format buffer.
282 @param nScNumFmt The core index of the number format.
283 @return The resulting Excel format index. */
284 sal_uInt16 Insert( ULONG nScNumFmt );
286 /** Writes all FORMAT records contained in this buffer. */
287 virtual void Save( XclExpStream& rStrm );
288 virtual void SaveXml( XclExpXmlStream& rStrm );
290 private:
291 /** Writes the FORMAT record with index nXclIx and format string rFormatStr. */
292 void WriteFormatRecord( XclExpStream& rStrm, sal_uInt16 nXclNumFmt, const String& rFormatStr );
293 /** Writes the FORMAT record represented by rFormat. */
294 void WriteFormatRecord( XclExpStream& rStrm, const XclExpNumFmt& rFormat );
296 String GetFormatCode ( const XclExpNumFmt& rFormat );
298 private:
299 typedef ::std::auto_ptr< SvNumberFormatter > SvNumberFormatterPtr;
300 typedef ::std::vector< XclExpNumFmt > XclExpNumFmtVec;
301 typedef NfKeywordTable* NfKeywordTablePtr;
303 SvNumberFormatterPtr mxFormatter; /// Special number formatter for conversion.
304 XclExpNumFmtVec maFormatMap; /// Maps core formats to Excel indexes.
305 NfKeywordTablePtr mpKeywordTable; /// Replacement table.
306 ULONG mnStdFmt; /// Key for standard number format.
307 sal_uInt16 mnXclOffset; /// Offset to first user defined format.
310 // XF, STYLE record - Cell formatting =========================================
312 /** Extends the XclCellProt struct for export.
313 @descr Provides functions to fill from item sets and to fill to Excel record data. */
314 struct XclExpCellProt : public XclCellProt
316 /** Fills the protection attributes from the passed item set.
317 @return true = At least one protection item is set. */
318 bool FillFromItemSet( const SfxItemSet& rItemSet, bool bStyle = false );
320 #if 0
321 /** Fills the data to the passed fields of a BIFF2 XF record. */
322 void FillToXF2( sal_uInt8& rnNumFmt ) const;
323 #endif
324 /** Fills the data to the passed fields of a BIFF3-BIFF8 XF record. */
325 void FillToXF3( sal_uInt16& rnProt ) const;
327 void SaveXml( XclExpXmlStream& rStrm ) const;
330 // ----------------------------------------------------------------------------
332 /** Extends the XclCellAlign struct for export.
333 @descr Provides functions to fill from item sets and to fill to Excel record data. */
334 struct XclExpCellAlign : public XclCellAlign
336 /** Fills the alignment attributes from the passed item set.
337 @descr Fills only the attributes exported in the passed BIFF version.
338 @param bForceLineBreak true = Set line break flag unconditionally.
339 @return true = At least one alignment item is set. */
340 bool FillFromItemSet( const SfxItemSet& rItemSet,
341 bool bForceLineBreak, XclBiff eBiff, bool bStyle = false );
343 #if 0
344 /** Fills the data to the passed fields of a BIFF2 XF record. */
345 void FillToXF2( sal_uInt8& rnFlags ) const;
346 /** Fills the data to the passed fields of a BIFF3 XF record. */
347 void FillToXF3( sal_uInt16& rnAlign ) const;
348 /** Fills the data to the passed fields of a BIFF4 XF record. */
349 void FillToXF4( sal_uInt16& rnAlign ) const;
350 #endif
351 /** Fills the data to the passed fields of a BIFF5/BIFF7 XF record. */
352 void FillToXF5( sal_uInt16& rnAlign ) const;
353 /** Fills the data to the passed fields of a BIFF8 XF record. */
354 void FillToXF8( sal_uInt16& rnAlign, sal_uInt16& rnMiscAttrib ) const;
356 void SaveXml( XclExpXmlStream& rStrm ) const;
359 // ----------------------------------------------------------------------------
361 /** Extends the XclCellBorder struct for export.
362 @descr Provides functions to fill from item sets and to fill to Excel record data. */
363 struct XclExpCellBorder : public XclCellBorder
365 sal_uInt32 mnLeftColorId; /// Color ID for left line.
366 sal_uInt32 mnRightColorId; /// Color ID for right line.
367 sal_uInt32 mnTopColorId; /// Color ID for top line.
368 sal_uInt32 mnBottomColorId; /// Color ID for bottom line.
369 sal_uInt32 mnDiagColorId; /// Color ID for diagonal line(s).
371 explicit XclExpCellBorder();
373 /** Fills the border attributes from the passed item set.
374 @descr Fills only the attributes exported in the passed BIFF version.
375 @return true = At least one border item is set. */
376 bool FillFromItemSet( const SfxItemSet& rItemSet,
377 XclExpPalette& rPalette, XclBiff eBiff, bool bStyle = false );
378 /** Fills the mn***Color base members from the mn***ColorId members. */
379 void SetFinalColors( const XclExpPalette& rPalette );
381 #if 0
382 /** Fills the data to the passed fields of a BIFF2 XF record. */
383 void FillToXF2( sal_uInt8& rnFlags ) const;
384 /** Fills the data to the passed fields of a BIFF3/BIFF4 XF record. */
385 void FillToXF3( sal_uInt32& rnBorder ) const;
386 #endif
387 /** Fills the data to the passed fields of a BIFF5/BIFF7 XF record. */
388 void FillToXF5( sal_uInt32& rnBorder, sal_uInt32& rnArea ) const;
389 /** Fills the data to the passed fields of a BIFF8 XF record. */
390 void FillToXF8( sal_uInt32& rnBorder1, sal_uInt32& rnBorder2 ) const;
392 /** Fills the data to the passed fields of a BIFF8 CF (conditional format) record. */
393 void FillToCF8( sal_uInt16& rnLine, sal_uInt32& rnColor ) const;
395 void SaveXml( XclExpXmlStream& rStrm ) const;
398 // ----------------------------------------------------------------------------
400 /** Extends the XclCellArea struct for export.
401 @descr Provides functions to fill from item sets and to fill to Excel record data. */
402 struct XclExpCellArea : public XclCellArea
404 sal_uInt32 mnForeColorId; /// Foreground color ID.
405 sal_uInt32 mnBackColorId; /// Background color ID.
407 explicit XclExpCellArea();
409 /** Fills the area attributes from the passed item set.
410 @return true = At least one area item is set. */
411 bool FillFromItemSet(
412 const SfxItemSet& rItemSet, XclExpPalette& rPalette,
413 bool bStyle = false );
414 /** Fills the mn***Color base members from the mn***ColorId members. */
415 void SetFinalColors( const XclExpPalette& rPalette );
417 #if 0
418 /** Fills the data to the passed fields of a BIFF2 XF record. */
419 void FillToXF2( sal_uInt8& rnFlags ) const;
420 /** Fills the data to the passed fields of a BIFF3/BIFF4 XF record. */
421 void FillToXF3( sal_uInt16& rnArea ) const;
422 #endif
423 /** Fills the data to the passed fields of a BIFF5/BIFF7 XF record. */
424 void FillToXF5( sal_uInt32& rnArea ) const;
425 /** Fills the data to the passed fields of a BIFF8 XF record. */
426 void FillToXF8( sal_uInt32& rnBorder2, sal_uInt16& rnArea ) const;
428 /** Fills the data to the passed fields of a BIFF8 CF (conditional format) record. */
429 void FillToCF8( sal_uInt16& rnPattern, sal_uInt16& rnColor ) const;
431 void SaveXml( XclExpXmlStream& rStrm ) const;
434 // ----------------------------------------------------------------------------
436 /** A combination of unique XF identifier with real Excel XF index. */
437 struct XclExpXFId
439 sal_uInt32 mnXFId; /// Temporary XF identifier.
440 sal_uInt16 mnXFIndex; /// Real Excel XF index.
442 explicit XclExpXFId();
443 explicit XclExpXFId( sal_uInt32 nXFId );
445 /** Converts the XF identifier in mnXFId to an Excel XF index and stores it in mnXFIndex. */
446 void ConvertXFIndex( const XclExpRoot& rRoot );
449 // ----------------------------------------------------------------------------
451 class SfxStyleSheetBase;
453 /** Represents an XF record which contains all formatting data of a cell or cell style. */
454 class XclExpXF : public XclXFBase, public XclExpRecord, protected XclExpRoot
456 public:
457 /** Constructs a cell XF record from the passed Calc cell formatting. */
458 explicit XclExpXF(
459 const XclExpRoot& rRoot,
460 const ScPatternAttr& rPattern,
461 sal_Int16 nScript,
462 ULONG nScForceNumFmt = NUMBERFORMAT_ENTRY_NOT_FOUND,
463 sal_uInt16 nForceXclFont = EXC_FONT_NOTFOUND,
464 bool bForceLineBreak = false );
465 /** Constructs a style XF record from the passed cell style sheet. */
466 explicit XclExpXF(
467 const XclExpRoot& rRoot,
468 const SfxStyleSheetBase& rStyleSheet );
470 /** Returns the cell protection settings of this XF. */
471 const XclExpCellProt& GetProtectionData() const { return maProtection; }
472 /** Returns the alignment settings of this XF. */
473 const XclExpCellAlign& GetAlignmentData() const { return maAlignment; }
474 /** Returns the cell border settings of this XF. */
475 const XclExpCellBorder& GetBorderData() const { return maBorder; }
476 /** Returns the cell fill settings of this XF. */
477 const XclExpCellArea& GetAreaData() const { return maArea; }
479 /** Returns true, if this XF record represents the passed cell formatting.
480 @descr Searches for cell XFs only. */
481 bool Equals(
482 const ScPatternAttr& rPattern,
483 ULONG nScForceNumFmt,
484 sal_uInt16 nForceXclFont,
485 bool bForceLineBreak ) const;
487 /** Returns true, if this XF record represents the passed style.
488 @descr Searches for style XFs only. */
489 bool Equals( const SfxStyleSheetBase& rStyleSheet ) const;
491 /** Sets the resulting Excel palette index from all used color IDs (border and area). */
492 void SetFinalColors();
494 /** Returns true, if this XF record is completely equal to the passed. */
495 bool Equals( const XclExpXF& rCmpXF ) const;
497 void SetXmlIds( sal_uInt32 nBorderId, sal_uInt32 nFillId );
499 virtual void SaveXml( XclExpXmlStream& rStrm );
501 protected:
502 explicit XclExpXF( const XclExpRoot& rRoot, bool bCellXF );
504 protected: // access for XclExpDefaultXF
505 const SfxItemSet* mpItemSet; /// Pointer to the item set (we do not own it).
507 XclExpCellProt maProtection; /// Cell protection flags.
508 XclExpCellAlign maAlignment; /// All alignment attributes.
509 XclExpCellBorder maBorder; /// Border line style.
510 XclExpCellArea maArea; /// Background area style.
511 sal_uInt32 mnParentXFId; /// XF ID of parent XF record.
512 ULONG mnScNumFmt; /// Calc number format index.
513 sal_uInt16 mnXclFont; /// Excel font index.
514 sal_uInt16 mnXclNumFmt; /// Excel number format index.
515 sal_Int32 mnBorderId; /// OOXML Border Index
516 sal_Int32 mnFillId; /// OOXML Fill Index
518 private:
519 using XclXFBase::Equals;
521 /** Initializes with default values. */
522 void InitDefault();
523 /** Fills all members from the passed item set.
524 @param bDefStyle true = This is the "Default"/"Normal" style - needs special handling. */
525 void Init(
526 const SfxItemSet& rItemSet,
527 sal_Int16 nScript,
528 ULONG nForceScNumFmt,
529 sal_uInt16 nForceXclFont,
530 bool bForceLineBreak,
531 bool bDefStyle );
533 /** Returns the bits specifying the used attributes.
534 @descr In cell XFs a set bit means a used attribute, in style XF a cleared
535 bit means a used attribute. This method regards the cell/style state.
536 @return The mask based on bit 0 (not yet bit-shifted as needed for export). */
537 sal_uInt8 GetUsedFlags() const;
539 void WriteBody5( XclExpStream& rStrm );
540 void WriteBody8( XclExpStream& rStrm );
542 /** Writes the contents of the XF record. */
543 virtual void WriteBody( XclExpStream& rStrm );
546 // ----------------------------------------------------------------------------
548 /** Represents a default XF record. Supports methods to set attributes directly. */
549 class XclExpDefaultXF : public XclExpXF
551 public:
552 explicit XclExpDefaultXF( const XclExpRoot& rRoot, bool bCellXF );
554 //UNUSED2008-05 /** Sets the parent XF ID. Only allowed for cell XFs. */
555 //UNUSED2008-05 void SetParent( sal_uInt32 nParentXFId );
556 //UNUSED2008-05
557 //UNUSED2008-05 /** Sets all "attribute used" flags explicitely.
558 //UNUSED2008-05 @descr The following Set***() functions set the appropriate flag too. */
559 //UNUSED2008-05 void SetUsedFlags(
560 //UNUSED2008-05 bool bProtUsed, bool bFontUsed, bool bFmtUsed,
561 //UNUSED2008-05 bool bAlignUsed, bool bBorderUsed, bool bAreaUsed );
562 //UNUSED2008-05 /** Sets the cell protection flags. */
563 //UNUSED2008-05 void SetProtection( const XclExpCellProt& rProtection );
564 //UNUSED2008-05 /** Sets cell alignment attributes. */
565 //UNUSED2008-05 void SetAlignment( const XclExpCellAlign& rAlignment );
566 //UNUSED2008-05 /** Sets a cell border style. */
567 //UNUSED2008-05 void SetBorder( const XclExpCellBorder& rBorder );
568 //UNUSED2008-05 /** Sets a cell area style. */
569 //UNUSED2008-05 void SetArea( const XclExpCellArea& rArea );
571 /** Sets the Excel font index. */
572 void SetFont( sal_uInt16 nXclFont );
573 /** Sets the Excel number format index. */
574 void SetNumFmt( sal_uInt16 nXclNumFmt );
577 // ----------------------------------------------------------------------------
579 /** Represents a STYLE record containing the data of a cell style.
580 @descr The calss is able to store built-in and user-defined styles. */
581 class XclExpStyle : public XclExpRecord
583 public:
584 explicit XclExpStyle( sal_uInt32 nXFId, const String& rStyleName );
585 explicit XclExpStyle( sal_uInt32 nXFId, sal_uInt8 nStyleId, sal_uInt8 nLevel = EXC_STYLE_NOLEVEL );
587 /** Returns true, if this record represents an Excel built-in style. */
588 inline bool IsBuiltIn() const { return mnStyleId != EXC_STYLE_USERDEF; }
590 inline const String& GetName() const { return maName; }
592 virtual void SaveXml( XclExpXmlStream& rStrm );
594 private:
595 /** Writes the contents of the STYLE record. */
596 virtual void WriteBody( XclExpStream& rStrm );
598 private:
599 String maName; /// Name of the cell style.
600 XclExpXFId maXFId; /// XF identifier for style formatting.
601 sal_uInt8 mnStyleId; /// Built-in style identifier.
602 sal_uInt8 mnLevel; /// Outline level for RowLevel and ColLevel styles.
605 // ----------------------------------------------------------------------------
607 /** Stores all XF records (cell formats and cell styles) in the document.
609 Stores also the names of user defined cell styles (STYLE records). Supports
610 reduction to the maximum count of XF records of the current BIFF version.
612 An instance of this class collects all XF records in the conversion phase
613 of the export, using the Insert() and InsertStyle() functions. It returns a
614 unique identidier for each XF record.
616 After the entire document is converted, the Finalize() function will reduce
617 the list to the number of XF records supported by the current BIFF version.
619 Then, in the streaming phase, the function GetXFIndex() returns the real
620 Excel XF index for all XF identifiers.
622 class XclExpXFBuffer : public XclExpRecordBase, protected XclExpRoot
624 public:
625 explicit XclExpXFBuffer( const XclExpRoot& rRoot );
627 /** Inserts predefined built-in styles and user-defined styles. */
628 void Initialize();
630 /** Finds or creates a cell XF record for the passed item set.
631 @return A unique XF record ID. */
632 sal_uInt32 Insert( const ScPatternAttr* pPattern, sal_Int16 nScript );
633 /** Finds or creates a cell XF record for the passed item set.
634 @param nForceXclFont The font to be exported. If not equal to EXC_FONT_NOTFOUND,
635 this font index will be used unconditionally and the cell font will be ignored.
636 @param bForceLineBreak true = Set line break flag unconditionally.
637 This is required for cells that contain multi-line text.
638 @return A unique XF record ID. */
639 sal_uInt32 InsertWithFont(
640 const ScPatternAttr* pPattern, sal_Int16 nScript,
641 sal_uInt16 nForceXclFont,
642 bool bForceLineBreak );
643 /** Finds or creates a cell XF record for the passed item set, with custom number format.
644 @param nXFFlags Additional flags allowing to control the creation of an XF.
645 @param nForceScNumFmt The number format to be exported, e.g. formula
646 result type. This format will always overwrite the cell's number format.
647 @param bForceLineBreak true = Set line break flag unconditionally.
648 This is required for cells that contain multi-line text.
649 @return A unique XF record ID. */
650 sal_uInt32 InsertWithNumFmt(
651 const ScPatternAttr* pPattern, sal_Int16 nScript,
652 ULONG nForceScNumFmt,
653 bool bForceLineBreak );
654 /** Inserts the passed cell style. Creates a style XF record and a STYLE record.
655 @return A unique XF record ID. */
656 sal_uInt32 InsertStyle( const SfxStyleSheetBase* pStyleSheet );
657 /** Returns the XF identifier representing a fixed Excel XF index (e.g. for built-in XFs). */
658 static sal_uInt32 GetXFIdFromIndex( sal_uInt16 nXFIndex );
659 /** Returns the XF identifier representing the default cell XF. */
660 static sal_uInt32 GetDefCellXFId();
662 /** Returns an XF record by its unique identifier. */
663 const XclExpXF* GetXFById( sal_uInt32 nXFId ) const;
665 /** Reduces the XF record list to the maximum allowed number of records. */
666 void Finalize();
668 /** Returns the Excel XF index of the XF record with passed XF ID. */
669 sal_uInt16 GetXFIndex( sal_uInt32 nXFId ) const;
671 sal_Int32 GetXmlStyleIndex( sal_uInt32 nXFId ) const;
672 sal_Int32 GetXmlCellIndex( sal_uInt32 nXFId ) const;
674 /** Writes all XF records contained in this buffer. */
675 virtual void Save( XclExpStream& rStrm );
676 virtual void SaveXml( XclExpXmlStream& rStrm );
678 private:
679 typedef XclExpRecordList< XclExpXF > XclExpXFList;
680 typedef XclExpXFList::RecordRefType XclExpXFRef;
681 typedef XclExpRecordList< XclExpStyle > XclExpStyleList;
683 private:
684 /** Returns the XF ID of the cell XF containing the passed format. */
685 sal_uInt32 FindXF( const ScPatternAttr& rPattern, ULONG nForceScNumFmt,
686 sal_uInt16 nForceXclFont, bool bForceLineBreak ) const;
687 /** Returns the XF ID of the style XF containing the passed style. */
688 sal_uInt32 FindXF( const SfxStyleSheetBase& rStyleSheet ) const;
690 /** Returns the XF ID of a built-in style XF, searches by style identifier. */
691 sal_uInt32 FindBuiltInXF( sal_uInt8 nStyleId, sal_uInt8 nLevel = EXC_STYLE_NOLEVEL ) const;
693 /** Tries to find the XF record containing the passed format or inserts a new record.
694 @return The XF record ID. */
695 sal_uInt32 InsertCellXF( const ScPatternAttr* pPattern, sal_Int16 nScript,
696 ULONG nForceScNumFmt,
697 sal_uInt16 nForceXclFont, bool bForceLineBreak );
698 /** Inserts the passed cell style. Creates a style XF record and a STYLE record.
699 @return The XF record ID. */
700 sal_uInt32 InsertStyleXF( const SfxStyleSheetBase& rStyleSheet );
702 /** Inserts an XF and a STYLE record for all user defined style sheets. */
703 void InsertUserStyles();
705 /** Inserts a built-in XF record without a STYLE record and returns the XF ID.
706 @param bCreateStyleRec true = Creates the related STYLE record. */
707 sal_uInt32 AppendBuiltInXF( XclExpXFRef xXF,
708 sal_uInt8 nStyleId, sal_uInt8 nLevel = EXC_STYLE_NOLEVEL );
709 /** Inserts a built-in XF and STYLE record and returns the XF ID.
710 @param bCreateStyleRec true = Creates the related STYLE record. */
711 sal_uInt32 AppendBuiltInXFWithStyle( XclExpXFRef xXF,
712 sal_uInt8 nStyleId, sal_uInt8 nLevel = EXC_STYLE_NOLEVEL );
714 /** Inserts all default XF and STYLE records. */
715 void InsertDefaultRecords();
717 /** Appends a XF index to the internal ID<->index maps. */
718 void AppendXFIndex( sal_uInt32 nXFId );
720 void AddBorderAndFill( const XclExpXF& rXF );
721 void SaveXFXml( XclExpXmlStream& rStrm, XclExpXF& rXF );
723 private:
724 /** Extended info about a built-in XF. */
725 struct XclExpBuiltInInfo
727 sal_uInt8 mnStyleId; /// Built-in style identifier.
728 sal_uInt8 mnLevel; /// Level for RowLevel/ColLevel styles.
729 bool mbPredefined; /// true = XF still predefined.
730 bool mbHasStyleRec; /// true = STYLE record created.
731 explicit XclExpBuiltInInfo();
733 typedef ::std::map< sal_uInt32, XclExpBuiltInInfo > XclExpBuiltInMap;
734 typedef ::std::vector< XclExpCellBorder > XclExpBorderList;
735 typedef ::std::vector< XclExpCellArea > XclExpFillList;
737 XclExpXFList maXFList; /// List of all XF records.
738 XclExpStyleList maStyleList; /// List of all STYLE records.
739 XclExpBuiltInMap maBuiltInMap; /// Contained elements describe built-in XFs.
740 ScfUInt16Vec maXFIndexVec; /// Maps XF IDs to XF indexes.
741 ScfUInt16Vec maStyleIndexes; /// Maps XF IDs to OOXML Style indexes
742 ScfUInt16Vec maCellIndexes; /// Maps XF IDs to OOXML Cell indexes
743 XclExpXFList maSortedXFList; /// List of XF records in XF index order.
744 XclExpBorderList maBorders; /// List of borders used by XF records
745 XclExpFillList maFills; /// List of fills used by XF records
749 // ============================================================================
751 class XclExpXmlStyleSheet : public XclExpRecordBase, protected XclExpRoot
753 public:
754 explicit XclExpXmlStyleSheet( const XclExpRoot& rRoot );
756 virtual void SaveXml( XclExpXmlStream& rStrm );
757 private:
760 // ============================================================================
762 #endif