fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / filter / inc / xestyle.hxx
blob0899d3395de91bac9a236ecba94c34ce28995a83
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SC_SOURCE_FILTER_INC_XESTYLE_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_INC_XESTYLE_HXX
23 #include <map>
24 #include <tools/mempool.hxx>
25 #include <svl/zforlist.hxx>
26 #include <svl/nfkeytab.hxx>
27 #include <editeng/svxfont.hxx>
28 #include "xerecord.hxx"
29 #include "xlstyle.hxx"
30 #include "xeroot.hxx"
31 #include "conditio.hxx"
32 #include "fonthelper.hxx"
33 #include <boost/shared_ptr.hpp>
34 #include <boost/scoped_ptr.hpp>
35 #include <boost/ptr_container/ptr_vector.hpp>
37 /* ============================================================================
38 - Buffers for style records (PALETTE, FONT, FORMAT, XF, STYLE).
39 ============================================================================ */
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
46 // PALETTE record - color information =========================================
48 /** Different types of colors in a document. */
49 enum XclExpColorType
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.
62 class XclExpPaletteImpl;
64 /** Stores all used colors in the document.
66 Supports color reduction to the maximum count of the current BIFF version.
67 An instance of this class collects all colors in the conversion phase of
68 the export, using the InsertColor() function. It returns a unique
69 identidier for each passed color.
71 After the entire document is converted, the Finalize() function will reduce
72 the palette to the number of colors supported by the current BIFF version.
74 Then, in the streaming phase, the functions GetColorIndex() and
75 GetMixedColors() return the real Excel palette index for all color
76 identifiers.
78 class XclExpPalette : public XclDefaultPalette, public XclExpRecord
80 public:
81 explicit XclExpPalette( const XclExpRoot& rRoot );
82 virtual ~XclExpPalette();
84 /** Inserts the color into the list and updates weighting.
85 @param nAutoDefault The Excel palette index for automatic color.
86 @return A unique ID for this color. */
87 sal_uInt32 InsertColor( const Color& rColor, XclExpColorType eType, sal_uInt16 nAutoDefault = 0 );
88 /** Returns the color ID representing a fixed Excel palette index (i.e. for auto colors). */
89 static sal_uInt32 GetColorIdFromIndex( sal_uInt16 nIndex );
91 /** Reduces the color list to the maximum count of the current BIFF version. */
92 void Finalize();
94 /** Returns the Excel palette index of the color with passed color ID. */
95 sal_uInt16 GetColorIndex( sal_uInt32 nColorId ) const;
97 /** Returns a foreground and background color for the two passed color IDs.
98 @descr If rnXclPattern contains a solid pattern, this function tries to find
99 the two best fitting colors and a mix pattern (25%, 50% or 75%) for nForeColorId.
100 This will result in a better approximation to the passed foreground color. */
101 void GetMixedColors(
102 sal_uInt16& rnXclForeIx, sal_uInt16& rnXclBackIx, sal_uInt8& rnXclPattern,
103 sal_uInt32 nForeColorId, sal_uInt32 nBackColorId ) const;
105 /** Returns the RGB color data for a (non-zero-based) Excel palette entry.
106 @return The color from current or default palette or COL_AUTO, if nothing else found. */
107 ColorData GetColorData( sal_uInt16 nXclIndex ) const;
108 /** Returns the color for a (non-zero-based) Excel palette entry.
109 @return The color from current or default palette or COL_AUTO, if nothing else found. */
110 inline Color GetColor( sal_uInt16 nXclIndex ) const
111 { return Color( GetColorData( nXclIndex ) ); }
113 /** Saves the PALETTE record, if it differs from the default palette. */
114 virtual void Save( XclExpStream& rStrm ) SAL_OVERRIDE;
115 virtual void SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
117 private:
118 /** Writes the contents of the PALETTE record. */
119 virtual void WriteBody( XclExpStream& rStrm ) SAL_OVERRIDE;
121 private:
122 typedef boost::shared_ptr< XclExpPaletteImpl > XclExpPaletteImplRef;
123 XclExpPaletteImplRef mxImpl;
126 // FONT record - font information =============================================
128 namespace { class Font; }
129 class SvxFont;
131 const size_t EXC_FONTLIST_NOTFOUND = static_cast< size_t >( -1 );
133 /** Helper functions for font export. */
134 namespace XclExpFontHelper
136 /** Returns the script type of the first font item found in the item set and its parents. */
137 sal_Int16 GetFirstUsedScript(
138 const XclExpRoot& rRoot,
139 const SfxItemSet& rItemSet );
141 /** Returns a VCL font object filled from the passed item set. */
142 vcl::Font GetFontFromItemSet(
143 const XclExpRoot& rRoot,
144 const SfxItemSet& rItemSet,
145 sal_Int16 nScript );
148 * Get a dxf related font object from the item set.
149 * Only items that are explicitly set in the item set
150 * are also set in the returned object.
152 ScDxfFont GetDxfFontFromItemSet(const XclExpRoot& rRoot, const SfxItemSet& rSet);
154 /** Returns true, if at least one font related item is set in the passed item set.
155 @param bDeep true = Searches in parent item sets too. */
156 bool CheckItems(
157 const XclExpRoot& rRoot,
158 const SfxItemSet& rItemSet,
159 sal_Int16 nScript,
160 bool bDeep );
163 /** Stores all data of an Excel font and provides export of FONT records. */
164 class XclExpFont : public XclExpRecord, protected XclExpRoot
166 public:
167 explicit XclExpFont( const XclExpRoot& rRoot,
168 const XclFontData& rFontData, XclExpColorType eColorType );
170 /** Returns read-only access to font data. */
171 inline const XclFontData& GetFontData() const { return maData; }
172 /** Returns the font color identifier. */
173 inline sal_uInt32 GetFontColorId() const { return mnColorId; }
174 /** Compares this font with the passed font data.
175 @param nHash The hash value calculated from the font data. */
176 virtual bool Equals( const XclFontData& rFontData, sal_uInt32 nHash ) const;
178 virtual void SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
180 private:
181 /** Writes the contents of the FONT record. */
182 virtual void WriteBody( XclExpStream& rStrm ) SAL_OVERRIDE;
184 private:
185 XclFontData maData; /// All font attributes.
186 sal_uInt32 mnColorId; /// Unique color ID for text color.
187 sal_uInt32 mnHash; /// Hash value for fast comparison.
190 class XclExpDxfFont : public XclExpRecordBase, protected XclExpRoot
192 public:
193 XclExpDxfFont(const XclExpRoot& rRoot, const SfxItemSet& rItemSet);
195 virtual void SaveXml(XclExpXmlStream& rStrm) SAL_OVERRIDE;
196 private:
198 ScDxfFont maDxfData;
201 /** Used as placeholder for font index 4, which is not used in Excel. */
202 class XclExpBlindFont : public XclExpFont
204 public:
205 explicit XclExpBlindFont( const XclExpRoot& rRoot );
207 /** Returns always false to never find this font while searching the font list. */
208 virtual bool Equals( const XclFontData& rFontData, sal_uInt32 nHash ) const SAL_OVERRIDE;
210 /** Skips writing this record. */
211 virtual void Save( XclExpStream& rStrm ) SAL_OVERRIDE;
214 class ScPatternAttr;
216 /** Stores the data of all fonts used in the document. */
217 class XclExpFontBuffer : public XclExpRecordBase, protected XclExpRoot
219 public:
220 explicit XclExpFontBuffer( const XclExpRoot& rRoot );
222 /** Returns the specified font from font list. */
223 const XclExpFont* GetFont( sal_uInt16 nXclFont ) const;
224 /** Returns the application font data of this file, needed e.g. for column width. */
225 const XclFontData& GetAppFontData() const;
227 /** Inserts a new font with the passed font data into the buffer if not present.
228 @param bAppFont true = Sets the application font; false = Inserts a new font.
229 @return The resulting Excel font index. */
230 sal_uInt16 Insert( const XclFontData& rFontData,
231 XclExpColorType eColorType, bool bAppFont = false );
232 /** Inserts the font into the buffer if not present.
233 @param bAppFont true = Sets the application font; false = Inserts a new font.
234 @return The resulting Excel font index. */
235 sal_uInt16 Insert( const vcl::Font& rFont,
236 XclExpColorType eColorType, bool bAppFont = false );
237 /** Inserts the SvxFont into the buffer if not present, e.g. where escapements are used.
238 @param bAppFont true = Sets the application font; false = Inserts a new font.
239 @return The resulting Excel font index. */
240 sal_uInt16 Insert( const SvxFont& rFont,
241 XclExpColorType eColorType, bool bAppFont = false );
242 /** Inserts the font contained in the passed item set into the buffer, if not present.
243 @param nScript The script type of the font properties to be used.
244 @param bAppFont true = Sets the application font; false = Inserts a new font.
245 @return The resulting Excel font index. */
246 sal_uInt16 Insert( const SfxItemSet& rItemSet, sal_Int16 nScript,
247 XclExpColorType eColorType, bool bAppFont = false );
249 /** Writes all FONT records contained in this buffer. */
250 virtual void Save( XclExpStream& rStrm ) SAL_OVERRIDE;
251 virtual void SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
253 private:
254 /** Initializes the default fonts for the current BIFF version. */
255 void InitDefaultFonts();
256 /** Tries to find the passed font and returns the current list index. */
257 size_t Find( const XclFontData& rFontData );
259 private:
260 typedef XclExpRecordList< XclExpFont > XclExpFontList;
261 typedef XclExpFontList::RecordRefType XclExpFontRef;
263 XclExpFontList maFontList; /// List of all FONT records.
264 size_t mnXclMaxSize; /// Maximum number of fonts.
267 // FORMAT record - number formats =============================================
269 /** Stores a core number format index with corresponding Excel format index. */
270 struct XclExpNumFmt
272 sal_uLong mnScNumFmt; /// Core index of the number format.
273 sal_uInt16 mnXclNumFmt; /// Resulting Excel format index.
274 OUString maNumFmtString; /// format string
276 inline explicit XclExpNumFmt( sal_uLong nScNumFmt, sal_uInt16 nXclNumFmt, const OUString& rFrmt ) :
277 mnScNumFmt( nScNumFmt ), mnXclNumFmt( nXclNumFmt ), maNumFmtString( rFrmt ) {}
279 void SaveXml( XclExpXmlStream& rStrm );
282 class SvNumberFormatter;
283 typedef ::std::unique_ptr< SvNumberFormatter > SvNumberFormatterPtr;
285 /** Stores all number formats used in the document. */
286 class XclExpNumFmtBuffer : public XclExpRecordBase, protected XclExpRoot
288 public:
289 explicit XclExpNumFmtBuffer( const XclExpRoot& rRoot );
290 virtual ~XclExpNumFmtBuffer();
292 /** Returns the core index of the current standard number format. */
293 inline sal_uLong GetStandardFormat() const { return mnStdFmt; }
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 );
300 /** Writes all FORMAT records contained in this buffer. */
301 virtual void Save( XclExpStream& rStrm ) SAL_OVERRIDE;
302 virtual void SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
304 private:
305 /** Writes the FORMAT record with index nXclIx and format string rFormatStr. */
306 void WriteFormatRecord( XclExpStream& rStrm, sal_uInt16 nXclNumFmt, const OUString& rFormatStr );
307 /** Writes the FORMAT record represented by rFormat. */
308 void WriteFormatRecord( XclExpStream& rStrm, const XclExpNumFmt& rFormat );
310 OUString GetFormatCode ( sal_uInt16 nScNumFmt );
312 private:
313 typedef ::std::vector< XclExpNumFmt > XclExpNumFmtVec;
315 SvNumberFormatterPtr mxFormatter; /// Special number formatter for conversion.
316 XclExpNumFmtVec maFormatMap; /// Maps core formats to Excel indexes.
317 boost::scoped_ptr<NfKeywordTable> mpKeywordTable; /// Replacement table.
318 sal_uLong mnStdFmt; /// Key for standard number format.
319 sal_uInt16 mnXclOffset; /// Offset to first user defined format.
322 // XF, STYLE record - Cell formatting =========================================
324 /** Extends the XclCellProt struct for export.
325 @descr Provides functions to fill from item sets and to fill to Excel record data. */
326 struct XclExpCellProt : public XclCellProt
328 /** Fills the protection attributes from the passed item set.
329 @return true = At least one protection item is set. */
330 bool FillFromItemSet( const SfxItemSet& rItemSet, bool bStyle = false );
332 /** Fills the data to the passed fields of a BIFF3-BIFF8 XF record. */
333 void FillToXF3( sal_uInt16& rnProt ) const;
335 void SaveXml( XclExpXmlStream& rStrm ) const;
338 /** Extends the XclCellAlign struct for export.
339 @descr Provides functions to fill from item sets and to fill to Excel record data. */
340 struct XclExpCellAlign : public XclCellAlign
342 /** Fills the alignment attributes from the passed item set.
343 @descr Fills only the attributes exported in the passed BIFF version.
344 @param bForceLineBreak true = Set line break flag unconditionally.
345 @return true = At least one alignment item is set. */
346 bool FillFromItemSet( const SfxItemSet& rItemSet,
347 bool bForceLineBreak, XclBiff eBiff, bool bStyle = false );
349 /** Fills the data to the passed fields of a BIFF5/BIFF7 XF record. */
350 void FillToXF5( sal_uInt16& rnAlign ) const;
351 /** Fills the data to the passed fields of a BIFF8 XF record. */
352 void FillToXF8( sal_uInt16& rnAlign, sal_uInt16& rnMiscAttrib ) const;
354 void SaveXml( XclExpXmlStream& rStrm ) const;
357 /** Extends the XclCellBorder struct for export.
358 @descr Provides functions to fill from item sets and to fill to Excel record data. */
359 struct XclExpCellBorder : public XclCellBorder
361 sal_uInt32 mnLeftColorId; /// Color ID for left line.
362 sal_uInt32 mnRightColorId; /// Color ID for right line.
363 sal_uInt32 mnTopColorId; /// Color ID for top line.
364 sal_uInt32 mnBottomColorId; /// Color ID for bottom line.
365 sal_uInt32 mnDiagColorId; /// Color ID for diagonal line(s).
367 explicit XclExpCellBorder();
369 /** Fills the border attributes from the passed item set.
370 @descr Fills only the attributes exported in the passed BIFF version.
371 @return true = At least one border item is set. */
372 bool FillFromItemSet( const SfxItemSet& rItemSet,
373 XclExpPalette& rPalette, XclBiff eBiff, bool bStyle = false );
374 /** Fills the mn***Color base members from the mn***ColorId members. */
375 void SetFinalColors( const XclExpPalette& rPalette );
377 /** Fills the data to the passed fields of a BIFF5/BIFF7 XF record. */
378 void FillToXF5( sal_uInt32& rnBorder, sal_uInt32& rnArea ) const;
379 /** Fills the data to the passed fields of a BIFF8 XF record. */
380 void FillToXF8( sal_uInt32& rnBorder1, sal_uInt32& rnBorder2 ) const;
382 /** Fills the data to the passed fields of a BIFF8 CF (conditional format) record. */
383 void FillToCF8( sal_uInt16& rnLine, sal_uInt32& rnColor ) const;
385 void SaveXml( XclExpXmlStream& rStrm ) const;
388 /** Extends the XclCellArea struct for export.
389 @descr Provides functions to fill from item sets and to fill to Excel record data. */
390 struct XclExpCellArea : public XclCellArea
392 sal_uInt32 mnForeColorId; /// Foreground color ID.
393 sal_uInt32 mnBackColorId; /// Background color ID.
395 explicit XclExpCellArea();
397 /** Fills the area attributes from the passed item set.
398 @return true = At least one area item is set. */
399 bool FillFromItemSet(
400 const SfxItemSet& rItemSet, XclExpPalette& rPalette,
401 bool bStyle = false );
402 /** Fills the mn***Color base members from the mn***ColorId members. */
403 void SetFinalColors( const XclExpPalette& rPalette );
405 /** Fills the data to the passed fields of a BIFF5/BIFF7 XF record. */
406 void FillToXF5( sal_uInt32& rnArea ) const;
407 /** Fills the data to the passed fields of a BIFF8 XF record. */
408 void FillToXF8( sal_uInt32& rnBorder2, sal_uInt16& rnArea ) const;
410 /** Fills the data to the passed fields of a BIFF8 CF (conditional format) record. */
411 void FillToCF8( sal_uInt16& rnPattern, sal_uInt16& rnColor ) const;
413 void SaveXml( XclExpXmlStream& rStrm ) const;
416 struct XclExpColor
418 Color maColor;
420 bool FillFromItemSet( const SfxItemSet& rItemSet );
422 void SaveXml( XclExpXmlStream& rStrm ) const;
425 /** A combination of unique XF identifier with real Excel XF index. */
426 struct XclExpXFId
428 sal_uInt32 mnXFId; /// Temporary XF identifier.
429 sal_uInt16 mnXFIndex; /// Real Excel XF index.
431 explicit XclExpXFId();
432 explicit XclExpXFId( sal_uInt32 nXFId );
434 /** Converts the XF identifier in mnXFId to an Excel XF index and stores it in mnXFIndex. */
435 void ConvertXFIndex( const XclExpRoot& rRoot );
438 class SfxStyleSheetBase;
440 /** Represents an XF record which contains all formatting data of a cell or cell style. */
441 class XclExpXF : public XclXFBase, public XclExpRecord, protected XclExpRoot
443 public:
444 /** Constructs a cell XF record from the passed Calc cell formatting. */
445 explicit XclExpXF(
446 const XclExpRoot& rRoot,
447 const ScPatternAttr& rPattern,
448 sal_Int16 nScript,
449 sal_uLong nScForceNumFmt = NUMBERFORMAT_ENTRY_NOT_FOUND,
450 sal_uInt16 nForceXclFont = EXC_FONT_NOTFOUND,
451 bool bForceLineBreak = false );
452 /** Constructs a style XF record from the passed cell style sheet. */
453 explicit XclExpXF(
454 const XclExpRoot& rRoot,
455 const SfxStyleSheetBase& rStyleSheet );
457 /** Returns the cell protection settings of this XF. */
458 const XclExpCellProt& GetProtectionData() const { return maProtection; }
459 /** Returns the alignment settings of this XF. */
460 const XclExpCellAlign& GetAlignmentData() const { return maAlignment; }
461 /** Returns the cell border settings of this XF. */
462 const XclExpCellBorder& GetBorderData() const { return maBorder; }
463 /** Returns the cell fill settings of this XF. */
464 const XclExpCellArea& GetAreaData() const { return maArea; }
466 /** Returns true, if this XF record represents the passed cell formatting.
467 @descr Searches for cell XFs only. */
468 bool Equals(
469 const ScPatternAttr& rPattern,
470 sal_uLong nScForceNumFmt,
471 sal_uInt16 nForceXclFont,
472 bool bForceLineBreak ) const;
474 /** Returns true, if this XF record represents the passed style.
475 @descr Searches for style XFs only. */
476 bool Equals( const SfxStyleSheetBase& rStyleSheet ) const;
478 /** Sets the resulting Excel palette index from all used color IDs (border and area). */
479 void SetFinalColors();
481 /** Returns true, if this XF record is completely equal to the passed. */
482 bool Equals( const XclExpXF& rCmpXF ) const;
484 void SetXmlIds( sal_uInt32 nBorderId, sal_uInt32 nFillId );
486 virtual void SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
488 protected:
489 explicit XclExpXF( const XclExpRoot& rRoot, bool bCellXF );
491 protected: // access for XclExpDefaultXF
492 const SfxItemSet* mpItemSet; /// Pointer to the item set (we do not own it).
494 XclExpCellProt maProtection; /// Cell protection flags.
495 XclExpCellAlign maAlignment; /// All alignment attributes.
496 XclExpCellBorder maBorder; /// Border line style.
497 XclExpCellArea maArea; /// Background area style.
498 sal_uInt32 mnParentXFId; /// XF ID of parent XF record.
499 sal_uLong mnScNumFmt; /// Calc number format index.
500 sal_uInt16 mnXclFont; /// Excel font index.
501 sal_uInt16 mnXclNumFmt; /// Excel number format index.
502 sal_Int32 mnBorderId; /// OOXML Border Index
503 sal_Int32 mnFillId; /// OOXML Fill Index
505 private:
506 using XclXFBase::Equals;
508 /** Initializes with default values. */
509 void InitDefault();
510 /** Fills all members from the passed item set.
511 @param bDefStyle true = This is the "Default"/"Normal" style - needs special handling. */
512 void Init(
513 const SfxItemSet& rItemSet,
514 sal_Int16 nScript,
515 sal_uLong nForceScNumFmt,
516 sal_uInt16 nForceXclFont,
517 bool bForceLineBreak,
518 bool bDefStyle );
520 /** Returns the bits specifying the used attributes.
521 @descr In cell XFs a set bit means a used attribute, in style XF a cleared
522 bit means a used attribute. This method regards the cell/style state.
523 @return The mask based on bit 0 (not yet bit-shifted as needed for export). */
524 sal_uInt8 GetUsedFlags() const;
526 void WriteBody5( XclExpStream& rStrm );
527 void WriteBody8( XclExpStream& rStrm );
529 /** Writes the contents of the XF record. */
530 virtual void WriteBody( XclExpStream& rStrm ) SAL_OVERRIDE;
533 /** Represents a default XF record. Supports methods to set attributes directly. */
534 class XclExpDefaultXF : public XclExpXF
536 public:
537 explicit XclExpDefaultXF( const XclExpRoot& rRoot, bool bCellXF );
539 /** Sets the Excel font index. */
540 void SetFont( sal_uInt16 nXclFont );
541 /** Sets the Excel number format index. */
542 void SetNumFmt( sal_uInt16 nXclNumFmt );
545 /** Represents a STYLE record containing the data of a cell style.
546 @descr The calss is able to store built-in and user-defined styles. */
547 class XclExpStyle : public XclExpRecord
549 public:
550 explicit XclExpStyle( sal_uInt32 nXFId, const OUString& rStyleName );
551 explicit XclExpStyle( sal_uInt32 nXFId, sal_uInt8 nStyleId, sal_uInt8 nLevel = EXC_STYLE_NOLEVEL );
553 /** Returns true, if this record represents an Excel built-in style. */
554 inline bool IsBuiltIn() const { return mnStyleId != EXC_STYLE_USERDEF; }
556 inline const OUString& GetName() const { return maName; }
558 virtual void SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
560 private:
561 /** Writes the contents of the STYLE record. */
562 virtual void WriteBody( XclExpStream& rStrm ) SAL_OVERRIDE;
564 private:
565 OUString maName; /// Name of the cell style.
566 XclExpXFId maXFId; /// XF identifier for style formatting.
567 sal_uInt8 mnStyleId; /// Built-in style identifier.
568 sal_uInt8 mnLevel; /// Outline level for RowLevel and ColLevel styles.
571 /** Stores all XF records (cell formats and cell styles) in the document.
573 Stores also the names of user defined cell styles (STYLE records). Supports
574 reduction to the maximum count of XF records of the current BIFF version.
576 An instance of this class collects all XF records in the conversion phase
577 of the export, using the Insert() and InsertStyle() functions. It returns a
578 unique identidier for each XF record.
580 After the entire document is converted, the Finalize() function will reduce
581 the list to the number of XF records supported by the current BIFF version.
583 Then, in the streaming phase, the function GetXFIndex() returns the real
584 Excel XF index for all XF identifiers.
586 class XclExpXFBuffer : public XclExpRecordBase, protected XclExpRoot
588 public:
589 explicit XclExpXFBuffer( const XclExpRoot& rRoot );
591 /** Inserts predefined built-in styles and user-defined styles. */
592 void Initialize();
594 /** Finds or creates a cell XF record for the passed item set.
595 @return A unique XF record ID. */
596 sal_uInt32 Insert( const ScPatternAttr* pPattern, sal_Int16 nScript );
597 /** Finds or creates a cell XF record for the passed item set.
598 @param nForceXclFont The font to be exported. If not equal to EXC_FONT_NOTFOUND,
599 this font index will be used unconditionally and the cell font will be ignored.
600 @param bForceLineBreak true = Set line break flag unconditionally.
601 This is required for cells that contain multi-line text.
602 @return A unique XF record ID. */
603 sal_uInt32 InsertWithFont(
604 const ScPatternAttr* pPattern, sal_Int16 nScript,
605 sal_uInt16 nForceXclFont,
606 bool bForceLineBreak );
607 /** Finds or creates a cell XF record for the passed item set, with custom number format.
608 @param nXFFlags Additional flags allowing to control the creation of an XF.
609 @param nForceScNumFmt The number format to be exported, e.g. formula
610 result type. This format will always overwrite the cell's number format.
611 @param bForceLineBreak true = Set line break flag unconditionally.
612 This is required for cells that contain multi-line text.
613 @return A unique XF record ID. */
614 sal_uInt32 InsertWithNumFmt(
615 const ScPatternAttr* pPattern, sal_Int16 nScript,
616 sal_uLong nForceScNumFmt,
617 bool bForceLineBreak );
618 /** Inserts the passed cell style. Creates a style XF record and a STYLE record.
619 @return A unique XF record ID. */
620 sal_uInt32 InsertStyle( const SfxStyleSheetBase* pStyleSheet );
621 /** Returns the XF identifier representing a fixed Excel XF index (e.g. for built-in XFs). */
622 static sal_uInt32 GetXFIdFromIndex( sal_uInt16 nXFIndex );
623 /** Returns the XF identifier representing the default cell XF. */
624 static sal_uInt32 GetDefCellXFId();
626 /** Returns an XF record by its unique identifier. */
627 const XclExpXF* GetXFById( sal_uInt32 nXFId ) const;
629 /** Reduces the XF record list to the maximum allowed number of records. */
630 void Finalize();
632 /** Returns the Excel XF index of the XF record with passed XF ID. */
633 sal_uInt16 GetXFIndex( sal_uInt32 nXFId ) const;
635 sal_Int32 GetXmlStyleIndex( sal_uInt32 nXFId ) const;
636 sal_Int32 GetXmlCellIndex( sal_uInt32 nXFId ) const;
638 /** Writes all XF records contained in this buffer. */
639 virtual void Save( XclExpStream& rStrm ) SAL_OVERRIDE;
640 virtual void SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
642 private:
643 typedef XclExpRecordList< XclExpXF > XclExpXFList;
644 typedef XclExpXFList::RecordRefType XclExpXFRef;
645 typedef XclExpRecordList< XclExpStyle > XclExpStyleList;
647 private:
648 /** Returns the XF ID of the cell XF containing the passed format. */
649 sal_uInt32 FindXF( const ScPatternAttr& rPattern, sal_uLong nForceScNumFmt,
650 sal_uInt16 nForceXclFont, bool bForceLineBreak ) const;
651 /** Returns the XF ID of the style XF containing the passed style. */
652 sal_uInt32 FindXF( const SfxStyleSheetBase& rStyleSheet ) const;
654 /** Returns the XF ID of a built-in style XF, searches by style identifier. */
655 sal_uInt32 FindBuiltInXF( sal_uInt8 nStyleId, sal_uInt8 nLevel = EXC_STYLE_NOLEVEL ) const;
657 /** Tries to find the XF record containing the passed format or inserts a new record.
658 @return The XF record ID. */
659 sal_uInt32 InsertCellXF( const ScPatternAttr* pPattern, sal_Int16 nScript,
660 sal_uLong nForceScNumFmt,
661 sal_uInt16 nForceXclFont, bool bForceLineBreak );
662 /** Inserts the passed cell style. Creates a style XF record and a STYLE record.
663 @return The XF record ID. */
664 sal_uInt32 InsertStyleXF( const SfxStyleSheetBase& rStyleSheet );
666 /** Inserts an XF and a STYLE record for all user defined style sheets. */
667 void InsertUserStyles();
669 /** Inserts a built-in XF record without a STYLE record and returns the XF ID.
670 @param bCreateStyleRec true = Creates the related STYLE record. */
671 sal_uInt32 AppendBuiltInXF( XclExpXFRef xXF,
672 sal_uInt8 nStyleId, sal_uInt8 nLevel = EXC_STYLE_NOLEVEL );
673 /** Inserts a built-in XF and STYLE record and returns the XF ID.
674 @param bCreateStyleRec true = Creates the related STYLE record. */
675 sal_uInt32 AppendBuiltInXFWithStyle( XclExpXFRef xXF,
676 sal_uInt8 nStyleId, sal_uInt8 nLevel = EXC_STYLE_NOLEVEL );
678 /** Inserts all default XF and STYLE records. */
679 void InsertDefaultRecords();
681 /** Appends a XF index to the internal ID<->index maps. */
682 void AppendXFIndex( sal_uInt32 nXFId );
684 void AddBorderAndFill( const XclExpXF& rXF );
685 void SaveXFXml( XclExpXmlStream& rStrm, XclExpXF& rXF );
687 private:
688 /** Extended info about a built-in XF. */
689 struct XclExpBuiltInInfo
691 sal_uInt8 mnStyleId; /// Built-in style identifier.
692 sal_uInt8 mnLevel; /// Level for RowLevel/ColLevel styles.
693 bool mbPredefined; /// true = XF still predefined.
694 bool mbHasStyleRec; /// true = STYLE record created.
695 explicit XclExpBuiltInInfo();
697 typedef ::std::map< sal_uInt32, XclExpBuiltInInfo > XclExpBuiltInMap;
698 typedef ::std::vector< XclExpCellBorder > XclExpBorderList;
699 typedef ::std::vector< XclExpCellArea > XclExpFillList;
701 XclExpXFList maXFList; /// List of all XF records.
702 XclExpStyleList maStyleList; /// List of all STYLE records.
703 XclExpBuiltInMap maBuiltInMap; /// Contained elements describe built-in XFs.
704 ScfUInt16Vec maXFIndexVec; /// Maps XF IDs to XF indexes.
705 ScfUInt16Vec maStyleIndexes; /// Maps XF IDs to OOXML Style indexes
706 ScfUInt16Vec maCellIndexes; /// Maps XF IDs to OOXML Cell indexes
707 XclExpXFList maSortedXFList; /// List of XF records in XF index order.
708 XclExpBorderList maBorders; /// List of borders used by XF records
709 XclExpFillList maFills; /// List of fills used by XF records
713 class XclExpDxf : public XclExpRecordBase, protected XclExpRoot
715 public:
716 XclExpDxf( const XclExpRoot& rRoot, XclExpCellAlign* pAlign, XclExpCellBorder* pBorder,
717 XclExpDxfFont* pFont, XclExpNumFmt* pNumberFmt, XclExpCellProt* pProt, XclExpColor* pColor);
718 virtual ~XclExpDxf();
720 virtual void SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
722 private:
723 boost::scoped_ptr<XclExpCellAlign> mpAlign;
724 boost::scoped_ptr<XclExpCellBorder> mpBorder;
725 boost::scoped_ptr<XclExpDxfFont> mpFont;
726 boost::scoped_ptr<XclExpNumFmt> mpNumberFmt;
727 boost::scoped_ptr<XclExpCellProt> mpProt;
728 boost::scoped_ptr<XclExpColor> mpColor;
731 class XclExpDxfs : public XclExpRecordBase, protected XclExpRoot
733 public:
734 XclExpDxfs( const XclExpRoot& rRoot );
735 virtual ~XclExpDxfs() {}
737 sal_Int32 GetDxfId(const OUString& rName);
739 virtual void SaveXml( XclExpXmlStream& rStrm) SAL_OVERRIDE;
740 private:
741 typedef boost::ptr_vector<XclExpDxf> DxfContainer;
742 std::map<OUString, sal_Int32> maStyleNameToDxfId;
743 DxfContainer maDxf;
744 SvNumberFormatterPtr mxFormatter; /// Special number formatter for conversion.
745 boost::scoped_ptr<NfKeywordTable> mpKeywordTable; /// Replacement table.
748 class XclExpXmlStyleSheet : public XclExpRecordBase, protected XclExpRoot
750 public:
751 explicit XclExpXmlStyleSheet( const XclExpRoot& rRoot );
753 virtual void SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
756 #endif
758 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */