Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / sc / source / filter / inc / stylesbuffer.hxx
blobb4813386cce8fa4ea98dfb4be88a783aba00b71d
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_STYLESBUFFER_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_INC_STYLESBUFFER_HXX
23 #include <com/sun/star/awt/FontDescriptor.hpp>
24 #include <com/sun/star/table/CellHoriJustify.hpp>
25 #include <com/sun/star/table/CellOrientation.hpp>
26 #include <com/sun/star/table/CellVertJustify2.hpp>
27 #include <com/sun/star/table/BorderLine2.hpp>
28 #include <com/sun/star/util/CellProtection.hpp>
29 #include <oox/drawingml/color.hxx>
30 #include <oox/helper/graphichelper.hxx>
31 #include <oox/helper/refmap.hxx>
32 #include <oox/helper/refvector.hxx>
33 #include "numberformatsbuffer.hxx"
34 #include "patattr.hxx"
35 #include "stlsheet.hxx"
36 #include <editeng/svxenum.hxx>
37 #include <editeng/frmdir.hxx>
38 #include "attarray.hxx"
39 #include <list>
41 class ScMarkData;
42 namespace com { namespace sun { namespace star {
43 namespace awt { struct FontDescrtiptor; }
44 } } }
46 namespace oox { class PropertySet; }
48 namespace oox {
49 namespace xls {
51 const sal_Int32 OOX_COLOR_WINDOWTEXT3 = 24; /// System window text color (BIFF3-BIFF4).
52 const sal_Int32 OOX_COLOR_WINDOWBACK3 = 25; /// System window background color (BIFF3-BIFF4).
53 const sal_Int32 OOX_COLOR_WINDOWTEXT = 64; /// System window text color (BIFF5+).
54 const sal_Int32 OOX_COLOR_WINDOWBACK = 65; /// System window background color (BIFF5+).
55 const sal_Int32 OOX_COLOR_BUTTONBACK = 67; /// System button background color (face color).
56 const sal_Int32 OOX_COLOR_CHWINDOWTEXT = 77; /// System window text color (BIFF8 charts).
57 const sal_Int32 OOX_COLOR_CHWINDOWBACK = 78; /// System window background color (BIFF8 charts).
58 const sal_Int32 OOX_COLOR_CHBORDERAUTO = 79; /// Automatic frame border (BIFF8 charts).
59 const sal_Int32 OOX_COLOR_NOTEBACK = 80; /// Note background color.
60 const sal_Int32 OOX_COLOR_NOTETEXT = 81; /// Note text color.
61 const sal_Int32 OOX_COLOR_FONTAUTO = 0x7FFF; /// Font auto color (system window text color).
63 const sal_Int16 API_LINE_NONE = 0;
64 const sal_Int16 API_LINE_HAIR = 1;
65 const sal_Int16 API_LINE_THIN = 15;
66 const sal_Int16 API_LINE_MEDIUM = 35;
67 const sal_Int16 API_LINE_THICK = 50;
69 const sal_Int16 API_ESCAPE_NONE = 0; /// No escapement.
70 const sal_Int16 API_ESCAPE_SUPERSCRIPT = 101; /// Superscript: raise characters automatically (magic value 101).
71 const sal_Int16 API_ESCAPE_SUBSCRIPT = -101; /// Subscript: lower characters automatically (magic value -101).
73 const sal_Int8 API_ESCAPEHEIGHT_NONE = 100; /// Relative character height if not escaped.
74 const sal_Int8 API_ESCAPEHEIGHT_DEFAULT = 58; /// Relative character height if escaped.
76 /** Special implementation of the GraphicHelper for Excel palette and scheme
77 colors.
79 class ExcelGraphicHelper : public GraphicHelper, public WorkbookHelper
81 public:
82 explicit ExcelGraphicHelper( const WorkbookHelper& rHelper );
84 /** Derived classes may implement to resolve a scheme color from the passed XML token identifier. */
85 virtual sal_Int32 getSchemeColor( sal_Int32 nToken ) const override;
86 /** Derived classes may implement to resolve a palette index to an RGB color. */
87 virtual sal_Int32 getPaletteColor( sal_Int32 nPaletteIdx ) const override;
90 class Color : public ::oox::drawingml::Color
92 public:
93 /** Sets the color to automatic. */
94 void setAuto();
95 /** Sets the color to the passed RGB value. */
96 void setRgb( sal_Int32 nRgbValue, double fTint = 0.0 );
97 /** Sets the color to the passed theme index. */
98 void setTheme( sal_Int32 nThemeIdx, double fTint = 0.0 );
99 /** Sets the color to the passed palette index. */
100 void setIndexed( sal_Int32 nPaletteIdx, double fTint = 0.0 );
102 /** Imports the color from the passed attribute list. */
103 void importColor( const AttributeList& rAttribs );
105 /** Imports a 64-bit color from the passed binary stream. */
106 void importColor( SequenceInputStream& rStrm );
107 /** Imports a 32-bit palette color identifier from the passed BIFF12 stream. */
108 void importColorId( SequenceInputStream& rStrm );
110 /** Returns true, if the color is set to automatic. */
111 inline bool isAuto() const { return isPlaceHolder(); }
114 SequenceInputStream& operator>>( SequenceInputStream& rStrm, Color& orColor );
116 /** Stores all colors of the color palette. */
117 class ColorPalette : public WorkbookHelper
119 public:
120 /** Constructs the color palette with predefined color values. */
121 explicit ColorPalette( const WorkbookHelper& rHelper );
123 /** Appends a new color from the passed attributes. */
124 void importPaletteColor( const AttributeList& rAttribs );
125 /** Appends a new color from the passed RGBCOLOR record. */
126 void importPaletteColor( SequenceInputStream& rStrm );
128 /** Returns the RGB value of the color with the passed index. */
129 sal_Int32 getColor( sal_Int32 nPaletteIdx ) const;
131 private:
132 /** Appends the passed color. */
133 void appendColor( sal_Int32 nRGBValue );
135 private:
136 ::std::vector< sal_Int32 > maColors; /// List of RGB values.
137 size_t mnAppendIndex; /// Index to append a new color.
140 /** Contains all XML font attributes, e.g. from a font or rPr element. */
141 struct FontModel
143 OUString maName; /// Font name.
144 Color maColor; /// Font color.
145 sal_Int32 mnScheme; /// Major/minor scheme font.
146 sal_Int32 mnFamily; /// Font family.
147 sal_Int32 mnCharSet; /// Windows font character set.
148 double mfHeight; /// Font height in points.
149 sal_Int32 mnUnderline; /// Underline style.
150 sal_Int32 mnEscapement; /// Escapement style.
151 bool mbBold; /// True = bold characters.
152 bool mbItalic; /// True = italic characters.
153 bool mbStrikeout; /// True = Strike out characters.
154 bool mbOutline; /// True = outlined characters.
155 bool mbShadow; /// True = shadowed chgaracters.
157 explicit FontModel();
159 void setBiff12Scheme( sal_uInt8 nScheme );
160 void setBiffHeight( sal_uInt16 nHeight );
161 void setBiffWeight( sal_uInt16 nWeight );
162 void setBiffUnderline( sal_uInt16 nUnderline );
163 void setBiffEscapement( sal_uInt16 nEscapement );
166 /** Enumerates different types of API font property sets. */
167 enum FontPropertyType
169 FONT_PROPTYPE_CELL, /// Font properties in a spreadsheet cell (table::Cell service).
170 FONT_PROPTYPE_TEXT /// Font properties in a text object (text::Text service).
173 /** Contains used flags for all API font attributes. */
174 struct ApiFontUsedFlags
176 bool mbNameUsed; /// True = font name/family/char set are used.
177 bool mbColorUsed; /// True = font color is used.
178 bool mbSchemeUsed; /// True = font scheme is used.
179 bool mbHeightUsed; /// True = font height is used.
180 bool mbUnderlineUsed; /// True = underline style is used.
181 bool mbEscapementUsed; /// True = escapement style is used.
182 bool mbWeightUsed; /// True = font weight (boldness) is used.
183 bool mbPostureUsed; /// True = font posture (italic) is used.
184 bool mbStrikeoutUsed; /// True = strike out style is used.
185 bool mbOutlineUsed; /// True = outline style is used.
186 bool mbShadowUsed; /// True = shadow style is used.
188 explicit ApiFontUsedFlags( bool bAllUsed );
191 /** Contains API font name, family, and charset for a script type. */
192 struct ApiScriptFontName
194 OUString maName; /// Font name.
195 sal_Int16 mnFamily; /// Font family.
196 sal_Int16 mnTextEnc; /// Font text encoding.
198 explicit ApiScriptFontName();
201 /** Contains all API font attributes. */
202 struct ApiFontData
204 ApiScriptFontName maLatinFont; /// Font name for latin scripts.
205 ApiScriptFontName maAsianFont; /// Font name for east-asian scripts.
206 ApiScriptFontName maCmplxFont; /// Font name for complex scripts.
207 css::awt::FontDescriptor maDesc; /// Font descriptor (height in twips, weight in %).
208 sal_Int32 mnColor; /// Font color.
209 sal_Int16 mnEscapement; /// Escapement style.
210 sal_Int8 mnEscapeHeight; /// Escapement font height.
211 bool mbOutline; /// True = outlined characters.
212 bool mbShadow; /// True = shadowed chgaracters.
214 explicit ApiFontData();
217 class Font : public WorkbookHelper
219 public:
220 explicit Font( const WorkbookHelper& rHelper, bool bDxf );
221 explicit Font( const WorkbookHelper& rHelper, const FontModel& rModel );
223 /** Sets font formatting attributes for the passed element. */
224 void importAttribs( sal_Int32 nElement, const AttributeList& rAttribs );
226 /** Imports the FONT record from the passed stream. */
227 void importFont( SequenceInputStream& rStrm );
228 /** Imports the font name from a DXF record. */
229 void importDxfName( SequenceInputStream& rStrm );
230 /** Imports the font color from a DXF record. */
231 void importDxfColor( SequenceInputStream& rStrm );
232 /** Imports the font scheme from a DXF record. */
233 void importDxfScheme( SequenceInputStream& rStrm );
234 /** Imports the font height from a DXF record. */
235 void importDxfHeight( SequenceInputStream& rStrm );
236 /** Imports the font weight from a DXF record. */
237 void importDxfWeight( SequenceInputStream& rStrm );
238 /** Imports the font underline style from a DXF record. */
239 void importDxfUnderline( SequenceInputStream& rStrm );
240 /** Imports the font escapement style from a DXF record. */
241 void importDxfEscapement( SequenceInputStream& rStrm );
242 /** Imports a font style flag from a DXF record. */
243 void importDxfFlag( sal_Int32 nElement, SequenceInputStream& rStrm );
245 /** Returns the font model structure. This function can be called before
246 finalizeImport() has been called. */
247 inline const FontModel& getModel() const { return maModel; }
249 /** Final processing after import of all style settings. */
250 void finalizeImport();
252 /** Returns an API font descriptor with own font information. */
253 const css::awt::FontDescriptor& getFontDescriptor() const { return maApiData.maDesc;}
254 /** Returns true, if the font requires rich text formatting in Calc.
255 @descr Example: Font escapement is a cell attribute in Excel, but Calc
256 needs an rich text cell for this attribute. */
257 bool needsRichTextFormat() const;
259 void fillToItemSet( SfxItemSet& rItemSet, bool bEditEngineText, bool bSkipPoolDefs = false ) const;
260 /** Writes all font attributes to the passed property map. */
261 void writeToPropertyMap(
262 PropertyMap& rPropMap,
263 FontPropertyType ePropType ) const;
264 /** Writes all font attributes to the passed property set. */
265 void writeToPropertySet(
266 PropertySet& rPropSet,
267 FontPropertyType ePropType ) const;
269 private:
270 FontModel maModel;
271 ApiFontData maApiData;
272 ApiFontUsedFlags maUsedFlags;
273 bool mbDxf;
276 typedef std::shared_ptr< Font > FontRef;
278 /** Contains all XML cell alignment attributes, e.g. from an alignment element. */
279 struct AlignmentModel
281 sal_Int32 mnHorAlign; /// Horizontal alignment.
282 sal_Int32 mnVerAlign; /// Vertical alignment.
283 sal_Int32 mnTextDir; /// CTL text direction.
284 sal_Int32 mnRotation; /// Text rotation angle.
285 sal_Int32 mnIndent; /// Indentation.
286 bool mbWrapText; /// True = multi-line text.
287 bool mbShrink; /// True = shrink to fit cell size.
288 bool mbJustLastLine; /// True = justify last line in block text.
290 explicit AlignmentModel();
292 /** Sets horizontal alignment from the passed BIFF data. */
293 void setBiffHorAlign( sal_uInt8 nHorAlign );
294 /** Sets vertical alignment from the passed BIFF data. */
295 void setBiffVerAlign( sal_uInt8 nVerAlign );
298 /** Contains all API cell alignment attributes. */
299 struct ApiAlignmentData
301 css::table::CellHoriJustify meHorJustify; /// Horizontal alignment.
302 sal_Int32 mnHorJustifyMethod;
303 sal_Int32 mnVerJustify; /// Vertical alignment.
304 sal_Int32 mnVerJustifyMethod;
305 css::table::CellOrientation meOrientation; /// Normal or stacked text.
306 sal_Int32 mnRotation; /// Text rotation angle.
307 sal_Int16 mnWritingMode; /// CTL text direction.
308 sal_Int16 mnIndent; /// Indentation.
309 bool mbWrapText; /// True = multi-line text.
310 bool mbShrink; /// True = shrink to fit cell size.
312 explicit ApiAlignmentData();
315 bool operator==( const ApiAlignmentData& rLeft, const ApiAlignmentData& rRight );
317 class Alignment : public WorkbookHelper
319 public:
320 explicit Alignment( const WorkbookHelper& rHelper );
322 /** Sets all attributes from the alignment element. */
323 void importAlignment( const AttributeList& rAttribs );
325 /** Sets the alignment attributes from the passed BIFF12 XF record data. */
326 void setBiff12Data( sal_uInt32 nFlags );
328 /** Final processing after import of all style settings. */
329 void finalizeImport();
331 /** Returns the alignment model structure. */
332 inline const AlignmentModel& getModel() const { return maModel; }
333 /** Returns the converted API alignment data struct. */
334 inline const ApiAlignmentData& getApiData() const { return maApiData; }
336 void fillToItemSet( SfxItemSet& rItemSet, bool bSkipPoolDefs = false ) const;
337 /** Writes all alignment attributes to the passed property map. */
338 void writeToPropertyMap( PropertyMap& rPropMap ) const;
340 private:
341 ::SvxCellHorJustify GetScHorAlign() const;
342 ::SvxCellVerJustify GetScVerAlign() const;
343 ::SvxFrameDirection GetScFrameDir() const;
344 AlignmentModel maModel; /// Alignment model data.
345 ApiAlignmentData maApiData; /// Alignment data converted to API constants.
348 /** Contains all XML cell protection attributes, e.g. from a protection element. */
349 struct ProtectionModel
351 bool mbLocked; /// True = locked against editing.
352 bool mbHidden; /// True = formula is hidden.
354 explicit ProtectionModel();
357 /** Contains all API cell protection attributes. */
358 struct ApiProtectionData
360 typedef css::util::CellProtection ApiCellProtection;
362 ApiCellProtection maCellProt;
364 explicit ApiProtectionData();
367 bool operator==( const ApiProtectionData& rLeft, const ApiProtectionData& rRight );
369 class Protection : public WorkbookHelper
371 public:
372 explicit Protection( const WorkbookHelper& rHelper );
374 /** Sets all attributes from the protection element. */
375 void importProtection( const AttributeList& rAttribs );
377 /** Sets the protection attributes from the passed BIFF12 XF record data. */
378 void setBiff12Data( sal_uInt32 nFlags );
380 /** Final processing after import of all style settings. */
381 void finalizeImport();
383 /** Returns the converted API protection data struct. */
384 inline const ApiProtectionData& getApiData() const { return maApiData; }
386 /** Writes all protection attributes to the passed property map. */
387 void writeToPropertyMap( PropertyMap& rPropMap ) const;
388 void fillToItemSet( SfxItemSet& rItemSet, bool bSkipPoolDefs = false ) const;
389 private:
390 ProtectionModel maModel; /// Protection model data.
391 ApiProtectionData maApiData; /// Protection data converted to API constants.
394 /** Contains XML attributes of a single border line. */
395 struct BorderLineModel
397 Color maColor; /// Borderline color.
398 sal_Int32 mnStyle; /// Border line style.
399 bool mbUsed; /// True = line format used.
401 explicit BorderLineModel( bool bDxf );
403 /** Sets the passed BIFF line style. */
404 void setBiffStyle( sal_Int32 nLineStyle );
407 /** Contains XML attributes of a complete cell border. */
408 struct BorderModel
410 BorderLineModel maLeft; /// Left line format.
411 BorderLineModel maRight; /// Right line format.
412 BorderLineModel maTop; /// Top line format.
413 BorderLineModel maBottom; /// Bottom line format.
414 BorderLineModel maDiagonal; /// Diagonal line format.
415 bool mbDiagTLtoBR; /// True = top-left to bottom-right on.
416 bool mbDiagBLtoTR; /// True = bottom-left to top-right on.
418 explicit BorderModel( bool bDxf );
421 /** Contains API attributes of a complete cell border. */
422 struct ApiBorderData
424 typedef css::table::BorderLine2 ApiBorderLine;
426 ApiBorderLine maLeft; /// Left line format
427 ApiBorderLine maRight; /// Right line format
428 ApiBorderLine maTop; /// Top line format
429 ApiBorderLine maBottom; /// Bottom line format
430 ApiBorderLine maTLtoBR; /// Diagonal top-left to bottom-right line format.
431 ApiBorderLine maBLtoTR; /// Diagonal bottom-left to top-right line format.
432 bool mbBorderUsed; /// True = left/right/top/bottom line format used.
433 bool mbDiagUsed; /// True = diagonal line format used.
435 explicit ApiBorderData();
437 /** Returns true, if any of the outer border lines is visible. */
438 bool hasAnyOuterBorder() const;
441 bool operator==( const ApiBorderData& rLeft, const ApiBorderData& rRight );
443 class Border : public WorkbookHelper
445 public:
446 explicit Border( const WorkbookHelper& rHelper, bool bDxf );
448 /** Sets global border attributes from the border element. */
449 void importBorder( const AttributeList& rAttribs );
450 /** Sets border attributes for the border line with the passed element identifier. */
451 void importStyle( sal_Int32 nElement, const AttributeList& rAttribs );
452 /** Sets color attributes for the border line with the passed element identifier. */
453 void importColor( sal_Int32 nElement, const AttributeList& rAttribs );
455 /** Imports the BORDER record from the passed stream. */
456 void importBorder( SequenceInputStream& rStrm );
457 /** Imports a border from a DXF record from the passed stream. */
458 void importDxfBorder( sal_Int32 nElement, SequenceInputStream& rStrm );
460 /** Final processing after import of all style settings. */
461 void finalizeImport( bool bRTL );
463 /** Returns the converted API border data struct. */
464 inline const ApiBorderData& getApiData() const { return maApiData; }
466 void fillToItemSet( SfxItemSet& rItemSet, bool bSkipPoolDefs = false ) const;
468 /** Writes all border attributes to the passed property map. */
469 void writeToPropertyMap( PropertyMap& rPropMap ) const;
471 bool hasBorder() const;
473 private:
474 /** Returns the border line struct specified by the passed XML token identifier. */
475 BorderLineModel* getBorderLine( sal_Int32 nElement );
477 /** Converts border line data to an API struct, returns true, if the line is marked as used. */
478 bool convertBorderLine(
479 css::table::BorderLine2& rBorderLine,
480 const BorderLineModel& rModel );
482 private:
483 BorderModel maModel;
484 ApiBorderData maApiData;
485 bool mbDxf;
488 typedef std::shared_ptr< Border > BorderRef;
490 /** Contains XML pattern fill attributes from the patternFill element. */
491 struct PatternFillModel
493 Color maPatternColor; /// Pattern foreground color.
494 Color maFillColor; /// Background fill color.
495 sal_Int32 mnPattern; /// Pattern identifier (e.g. solid).
496 bool mbPattColorUsed; /// True = pattern foreground color used.
497 bool mbFillColorUsed; /// True = background fill color used.
498 bool mbPatternUsed; /// True = pattern used.
500 explicit PatternFillModel( bool bDxf );
502 /** Sets the passed BIFF pattern identifier. */
503 void setBiffPattern( sal_Int32 nPattern );
506 /** Contains XML gradient fill attributes from the gradientFill element. */
507 struct GradientFillModel
509 typedef ::std::map< double, Color > ColorMap;
511 sal_Int32 mnType; /// Gradient type, linear or path.
512 double mfAngle; /// Rotation angle for type linear.
513 double mfLeft; /// Left convergence for type path.
514 double mfRight; /// Right convergence for type path.
515 double mfTop; /// Top convergence for type path.
516 double mfBottom; /// Bottom convergence for type path.
517 ColorMap maColors; /// Gradient colors.
519 explicit GradientFillModel();
521 /** Reads BIFF12 gradient settings from a FILL or DXF record. */
522 void readGradient( SequenceInputStream& rStrm );
523 /** Reads BIFF12 gradient stop settings from a FILL or DXF record. */
524 void readGradientStop( SequenceInputStream& rStrm, bool bDxf );
527 /** Contains API fill attributes. */
528 struct ApiSolidFillData
530 sal_Int32 mnColor; /// Fill color.
531 bool mbTransparent; /// True = transparent area.
532 bool mbUsed; /// True = fill data is valid.
534 explicit ApiSolidFillData();
537 bool operator==( const ApiSolidFillData& rLeft, const ApiSolidFillData& rRight );
539 /** Contains cell fill attributes, either a pattern fill or a gradient fill. */
540 class Fill : public WorkbookHelper
542 public:
543 explicit Fill( const WorkbookHelper& rHelper, bool bDxf );
545 /** Sets attributes of a patternFill element. */
546 void importPatternFill( const AttributeList& rAttribs );
547 /** Sets the pattern color from the fgColor element. */
548 void importFgColor( const AttributeList& rAttribs );
549 /** Sets the background color from the bgColor element. */
550 void importBgColor( const AttributeList& rAttribs );
551 /** Sets attributes of a gradientFill element. */
552 void importGradientFill( const AttributeList& rAttribs );
553 /** Sets a color from the color element in a gradient fill. */
554 void importColor( const AttributeList& rAttribs, double fPosition );
556 /** Imports the FILL record from the passed stream. */
557 void importFill( SequenceInputStream& rStrm );
558 /** Imports the fill pattern from a DXF record. */
559 void importDxfPattern( SequenceInputStream& rStrm );
560 /** Imports the pattern color from a DXF record. */
561 void importDxfFgColor( SequenceInputStream& rStrm );
562 /** Imports the background color from a DXF record. */
563 void importDxfBgColor( SequenceInputStream& rStrm );
564 /** Imports gradient settings from a DXF record. */
565 void importDxfGradient( SequenceInputStream& rStrm );
566 /** Imports gradient stop settings from a DXF record. */
567 void importDxfStop( SequenceInputStream& rStrm );
569 /** Final processing after import of all style settings. */
570 void finalizeImport();
572 /** Returns the converted API fill data struct. */
573 inline const ApiSolidFillData& getApiData() const { return maApiData; }
575 void fillToItemSet( SfxItemSet& rItemSet, bool bSkipPoolDefs = false ) const;
576 /** Writes all fill attributes to the passed property map. */
577 void writeToPropertyMap( PropertyMap& rPropMap ) const;
579 private:
580 typedef std::shared_ptr< PatternFillModel > PatternModelRef;
581 typedef std::shared_ptr< GradientFillModel > GradientModelRef;
583 PatternModelRef mxPatternModel;
584 GradientModelRef mxGradientModel;
585 ApiSolidFillData maApiData;
586 bool mbDxf;
589 typedef std::shared_ptr< Fill > FillRef;
591 /** Contains all data for a cell format or cell style. */
592 struct XfModel
594 sal_Int32 mnStyleXfId; /// Index to parent style XF.
595 sal_Int32 mnFontId; /// Index to font data list.
596 sal_Int32 mnNumFmtId; /// Index to number format list.
597 sal_Int32 mnBorderId; /// Index to list of cell borders.
598 sal_Int32 mnFillId; /// Index to list of cell areas.
599 bool mbCellXf; /// True = cell XF, false = style XF.
600 bool mbFontUsed; /// True = font index used.
601 bool mbNumFmtUsed; /// True = number format used.
602 bool mbAlignUsed; /// True = alignment used.
603 bool mbProtUsed; /// True = cell protection used.
604 bool mbBorderUsed; /// True = border data used.
605 bool mbAreaUsed; /// True = area data used.
607 explicit XfModel();
610 bool operator==( const XfModel& rXfModel1, const XfModel& rXfModel2 );
612 /** Represents a cell format or a cell style (called XF, extended format).
614 This class stores the type (cell/style), the index to the parent style (if
615 it is a cell format) and all "attribute used" flags, which reflect the
616 state of specific attribute groups (true = user has changed the attributes)
617 and all formatting data.
619 class Xf : public WorkbookHelper
621 friend bool operator==( const Xf& rXf1, const Xf& rXf2 );
622 public:
623 struct AttrList
625 std::list<ScAttrEntry> maAttrs;
626 bool mbLatinNumFmtOnly;
627 const ScPatternAttr* mpDefPattern;
629 AttrList(const ScPatternAttr* pDefPatternAttr);
632 explicit Xf( const WorkbookHelper& rHelper );
634 /** Sets all attributes from the xf element. */
635 void importXf( const AttributeList& rAttribs, bool bCellXf );
636 /** Sets all attributes from the alignment element. */
637 void importAlignment( const AttributeList& rAttribs );
638 /** Sets all attributes from the protection element. */
639 void importProtection( const AttributeList& rAttribs );
641 /** Imports the XF record from the passed stream. */
642 void importXf( SequenceInputStream& rStrm, bool bCellXf );
644 /** Final processing after import of all style settings. */
645 void finalizeImport();
647 /** Returns true, if the XF is a cell XF, and false, if it is a style XF. */
648 inline bool isCellXf() const { return maModel.mbCellXf; }
650 /** Returns the referred font object. */
651 FontRef getFont() const;
652 /** Returns the alignment data of this style. */
653 inline const Alignment& getAlignment() const { return maAlignment; }
655 void applyPatternToAttrList(
656 AttrList& rAttrs, SCROW nRow1, SCROW nRow2, sal_Int32 nForceScNumFmt );
658 /** Writes all formatting attributes to the passed property map. */
659 void writeToPropertyMap( PropertyMap& rPropMap ) const;
660 /** Writes all formatting attributes to the passed property set. */
661 void writeToPropertySet( PropertySet& rPropSet ) const;
663 void writeToDoc( ScDocumentImport& rDoc, const css::table::CellRangeAddress& rRange );
665 const ::ScPatternAttr& createPattern( bool bSkipPoolDefs = false );
667 private:
668 typedef ::std::unique_ptr< ::ScPatternAttr > ScPatternAttrPtr;
670 ScPatternAttrPtr mpPattern; /// Calc item set.
671 sal_uLong mnScNumFmt; /// Calc number format.
673 XfModel maModel; /// Cell XF or style XF model data.
674 Alignment maAlignment; /// Cell alignment data.
675 Protection maProtection; /// Cell protection data.
676 sal_Int32 meRotationRef; /// Rotation reference dependent on border.
677 ::ScStyleSheet* mpStyleSheet; /// Calc cell style sheet.
680 bool operator==( const Xf& rXf1, const Xf& rXf2 );
682 typedef std::shared_ptr< Xf > XfRef;
684 class Dxf : public WorkbookHelper
686 public:
687 explicit Dxf( const WorkbookHelper& rHelper );
689 /** Creates a new empty font object. */
690 FontRef createFont( bool bAlwaysNew = true );
691 /** Creates a new empty border object. */
692 BorderRef createBorder( bool bAlwaysNew = true );
693 /** Creates a new empty fill object. */
694 FillRef createFill( bool bAlwaysNew = true );
696 /** Inserts a new number format code. */
697 void importNumFmt( const AttributeList& rAttribs );
699 /** Imports the DXF record from the passed stream. */
700 void importDxf( SequenceInputStream& rStrm );
702 /** Final processing after import of all style settings. */
703 void finalizeImport();
705 void fillToItemSet( SfxItemSet& rSet ) const;
707 private:
708 FontRef mxFont; /// Font data.
709 NumberFormatRef mxNumFmt; /// Number format data.
710 std::shared_ptr< Alignment >
711 mxAlignment; /// Alignment data.
712 std::shared_ptr< Protection >
713 mxProtection; /// Protection data.
714 BorderRef mxBorder; /// Border data.
715 FillRef mxFill; /// Fill data.
718 typedef std::shared_ptr< Dxf > DxfRef;
720 /** Contains attributes of a cell style, e.g. from the cellStyle element. */
721 struct CellStyleModel
723 OUString maName; /// Cell style name.
724 sal_Int32 mnXfId; /// Formatting for this cell style.
725 sal_Int32 mnBuiltinId; /// Identifier for builtin styles.
726 sal_Int32 mnLevel; /// Level for builtin column/row styles.
727 bool mbBuiltin; /// True = builtin style.
728 bool mbCustom; /// True = customized builtin style.
729 bool mbHidden; /// True = style not visible in GUI.
731 explicit CellStyleModel();
733 /** Returns true, if this style is a builtin style. */
734 bool isBuiltin() const;
735 /** Returns true, if this style represents the default document cell style. */
736 bool isDefaultStyle() const;
739 class CellStyle : public WorkbookHelper
741 public:
742 explicit CellStyle( const WorkbookHelper& rHelper );
744 /** Imports passed attributes from the cellStyle element. */
745 void importCellStyle( const AttributeList& rAttribs );
746 /** Imports style settings from a CELLSTYLE record. */
747 void importCellStyle( SequenceInputStream& rStrm );
749 /** Creates the style sheet in the document described by this cell style object. */
750 void createCellStyle();
751 /** Stores tha passed final style name and creates the cell style, if it is
752 user-defined or modified built-in. */
753 void finalizeImport( const OUString& rFinalName );
755 /** Returns the cell style model structure. */
756 inline const CellStyleModel& getModel() const { return maModel; }
757 /** Returns the final style name used in the document. */
758 inline const OUString& getFinalStyleName() const { return maFinalName; }
759 inline ::ScStyleSheet* getStyleSheet() { return mpStyleSheet; }
760 private:
761 CellStyleModel maModel;
762 OUString maFinalName; /// Final style name used in API.
763 bool mbCreated; /// True = style sheet created.
764 ::ScStyleSheet* mpStyleSheet; /// Calc cell style sheet.
768 typedef std::shared_ptr< CellStyle > CellStyleRef;
770 class CellStyleBuffer : public WorkbookHelper
772 public:
773 explicit CellStyleBuffer( const WorkbookHelper& rHelper );
775 /** Appends and returns a new named cell style object. */
776 CellStyleRef importCellStyle( const AttributeList& rAttribs );
777 /** Imports the CELLSTYLE record from the passed stream. */
778 CellStyleRef importCellStyle( SequenceInputStream& rStrm );
780 /** Final processing after import of all style settings. */
781 void finalizeImport();
783 /** Returns the XF identifier associated to the default cell style. */
784 sal_Int32 getDefaultXfId() const;
785 /** Returns the default style sheet for unused cells. */
786 OUString getDefaultStyleName() const;
787 /** Creates the style sheet described by the style XF with the passed identifier. */
788 OUString createCellStyle( sal_Int32 nXfId ) const;
789 ::ScStyleSheet* getCellStyleSheet( sal_Int32 nXfId ) const;
791 private:
792 /** Inserts the passed cell style object into the internal maps. */
793 void insertCellStyle( CellStyleRef xCellStyle );
794 /** Creates the style sheet described by the passed cell style object. */
795 static OUString createCellStyle( const CellStyleRef& rxCellStyle );
796 static ::ScStyleSheet* getCellStyleSheet( const CellStyleRef& rxCellStyle );
798 private:
799 typedef RefVector< CellStyle > CellStyleVector;
800 typedef RefMap< sal_Int32, CellStyle > CellStyleXfIdMap;
802 CellStyleVector maBuiltinStyles; /// All built-in cell styles.
803 CellStyleVector maUserStyles; /// All user defined cell styles.
804 CellStyleXfIdMap maStylesByXf; /// All cell styles, mapped by XF identifier.
805 CellStyleRef mxDefStyle; /// Default cell style.
808 struct AutoFormatModel
810 sal_Int32 mnAutoFormatId; /// Index of predefined autoformatting.
811 bool mbApplyNumFmt; /// True = apply number format from autoformatting.
812 bool mbApplyFont; /// True = apply font from autoformatting.
813 bool mbApplyAlignment; /// True = apply alignment from autoformatting.
814 bool mbApplyBorder; /// True = apply border from autoformatting.
815 bool mbApplyFill; /// True = apply fill from autoformatting.
816 bool mbApplyProtection; /// True = apply protection from autoformatting.
818 explicit AutoFormatModel();
821 class StylesBuffer : public WorkbookHelper
823 public:
824 explicit StylesBuffer( const WorkbookHelper& rHelper );
826 /** Creates a new empty font object. */
827 FontRef createFont();
828 /** Creates a number format. */
829 NumberFormatRef createNumFmt( sal_Int32 nNumFmtId, const OUString& rFmtCode );
830 sal_Int32 nextFreeNumFmtId();
831 /** Creates a new empty border object. */
832 BorderRef createBorder();
833 /** Creates a new empty fill object. */
834 FillRef createFill();
835 /** Creates a new empty cell formatting object. */
836 XfRef createCellXf();
837 /** Creates a new empty style formatting object. */
838 XfRef createStyleXf();
839 /** Creates a new empty differential formatting object. */
840 DxfRef createDxf();
842 /** Appends a new color to the color palette. */
843 void importPaletteColor( const AttributeList& rAttribs );
844 /** Inserts a new number format code. */
845 NumberFormatRef importNumFmt( const AttributeList& rAttribs );
846 /** Appends and returns a new named cell style object. */
847 CellStyleRef importCellStyle( const AttributeList& rAttribs );
849 /** Appends a new color to the color palette. */
850 void importPaletteColor( SequenceInputStream& rStrm );
851 /** Imports the NUMFMT record from the passed stream. */
852 void importNumFmt( SequenceInputStream& rStrm );
853 /** Imports the CELLSTYLE record from the passed stream. */
854 void importCellStyle( SequenceInputStream& rStrm );
856 /** Final processing after import of all style settings. */
857 void finalizeImport();
859 /** Returns the palette color with the specified index. */
860 sal_Int32 getPaletteColor( sal_Int32 nIndex ) const;
861 /** Returns the specified font object. */
862 FontRef getFont( sal_Int32 nFontId ) const;
863 /** Returns the specified border object. */
864 BorderRef getBorder( sal_Int32 nBorderId ) const;
865 /** Returns the specified cell format object. */
866 XfRef getCellXf( sal_Int32 nXfId ) const;
867 /** Returns the specified style format object. */
868 XfRef getStyleXf( sal_Int32 nXfId ) const;
870 /** Returns the font object of the specified cell XF. */
871 FontRef getFontFromCellXf( sal_Int32 nXfId ) const;
872 /** Returns the default application font (used in the "Normal" cell style). */
873 FontRef getDefaultFont() const;
874 /** Returns the model of the default application font (used in the "Normal" cell style). */
875 const FontModel& getDefaultFontModel() const;
877 /** Returns true, if the specified borders are equal. */
878 bool equalBorders( sal_Int32 nBorderId1, sal_Int32 nBorderId2 ) const;
879 /** Returns true, if the specified fills are equal. */
880 bool equalFills( sal_Int32 nFillId1, sal_Int32 nFillId2 ) const;
882 /** Returns the default style sheet for unused cells. */
883 OUString getDefaultStyleName() const;
884 /** Creates the style sheet described by the style XF with the passed identifier. */
885 OUString createCellStyle( sal_Int32 nXfId ) const;
886 ::ScStyleSheet* getCellStyleSheet( sal_Int32 nXfId ) const;
887 /** Creates the style sheet described by the DXF with the passed identifier. */
888 OUString createDxfStyle( sal_Int32 nDxfId ) const;
890 void writeFontToItemSet( SfxItemSet& rItemSet, sal_Int32 nFontId, bool bSkipPoolDefs = false ) const;
891 /** Writes the font attributes of the specified font data to the passed property map. */
892 void writeFontToPropertyMap( PropertyMap& rPropMap, sal_Int32 nFontId ) const;
893 sal_uLong writeNumFmtToItemSet( SfxItemSet& rItemSet, sal_Int32 nNumFmtId, bool bSkipPoolDefs = false ) const;
894 /** Writes the specified number format to the passed property map. */
895 void writeNumFmtToPropertyMap( PropertyMap& rPropMap, sal_Int32 nNumFmtId ) const;
896 void writeBorderToItemSet( SfxItemSet& rItemSet, sal_Int32 nBorderId, bool bSkipPoolDefs = false ) const;
897 /** Writes the border attributes of the specified border data to the passed property map. */
898 void writeBorderToPropertyMap( PropertyMap& rPropMap, sal_Int32 nBorderId ) const;
899 /** Writes the fill attributes of the specified fill data to the passed property map. */
900 void writeFillToItemSet( SfxItemSet& rItemSet, sal_Int32 nFillId, bool bSkipPoolDefs = false ) const;
901 void writeFillToPropertyMap( PropertyMap& rPropMap, sal_Int32 nFillId ) const;
903 /** Writes the cell formatting attributes of the specified XF to the passed property set. */
904 void writeCellXfToDoc( ScDocumentImport& rDoc, const css::table::CellRangeAddress& rRange, sal_Int32 nXfId ) const;
906 private:
907 typedef RefVector< Font > FontVector;
908 typedef RefVector< Border > BorderVector;
909 typedef RefVector< Fill > FillVector;
910 typedef RefVector< Xf > XfVector;
911 typedef RefVector< Dxf > DxfVector;
912 typedef ::std::map< sal_Int32, OUString > DxfStyleMap;
914 ColorPalette maPalette; /// Color palette.
915 FontVector maFonts; /// List of font objects.
916 NumberFormatsBuffer maNumFmts; /// List of all number format codes.
917 BorderVector maBorders; /// List of cell border objects.
918 FillVector maFills; /// List of cell area fill objects.
919 XfVector maCellXfs; /// List of cell formats.
920 XfVector maStyleXfs; /// List of cell styles.
921 CellStyleBuffer maCellStyles; /// All built-in and user defined cell styles.
922 DxfVector maDxfs; /// List of differential cell styles.
923 mutable DxfStyleMap maDxfStyles; /// Maps DXF identifiers to Calc style sheet names.
926 } // namespace xls
927 } // namespace oox
929 #endif
931 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */