Get the style color and number just once
[LibreOffice.git] / sc / source / filter / inc / xistyle.hxx
blob450719832042cdc133d82330f5c85d3d13d0cb55
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 #pragma once
22 #include <tools/solar.h>
23 #include <vector>
24 #include <memory>
25 #include <optional>
26 #include <rangelst.hxx>
27 #include "xlstyle.hxx"
28 #include "xiroot.hxx"
30 class ScPatternAttr;
32 struct XclRange;
33 class ScAttrEntry;
34 enum class SvxBoxItemLine;
36 /* ============================================================================
37 - Buffers for style records (PALETTE, FONT, FORMAT, XF)
38 and a container for XF indexes for every used cell in a sheet.
39 ============================================================================ */
41 // PALETTE record - color information =========================================
43 /** Stores the default colors for the current BIFF version and the contents of
44 a PALETTE record. */
45 class XclImpPalette : public XclDefaultPalette
47 public:
48 explicit XclImpPalette( const XclImpRoot& rRoot );
50 /** Clears all buffered data, used to set up for a new sheet. */
51 void Initialize();
53 /** Returns the color for a (non-zero-based) Excel palette entry.
54 @descr First looks for a color read from file, then looks for a default color.
55 @return The color from current or default palette or COL_AUTO, if nothing else found. */
56 Color GetColor( sal_uInt16 nXclIndex ) const;
58 /** Reads a PALETTE record. */
59 void ReadPalette( XclImpStream& rStrm );
61 private:
62 void ExportPalette();
63 typedef ::std::vector< Color > ColorVec;
64 ColorVec maColorTable; /// Colors read from file.
65 const XclImpRoot& mrRoot;
68 // FONT record - font information =============================================
70 /** Stores all data of an Excel font and provides import of FONT records. */
71 class XclImpFont : protected XclImpRoot
73 public:
74 explicit XclImpFont( const XclImpRoot& rRoot );
76 /** Constructs a font from font data.
77 @descr Special handling for font style (bold, italic) in font name,
78 overwrites settings in rFontData. */
79 explicit XclImpFont( const XclImpRoot& rRoot, const XclFontData& rFontData );
81 /** Sets all font attributes to used or unused. */
82 void SetAllUsedFlags( bool bUsed );
83 /** Sets the passed font data and all used flags to 'used'. */
84 void SetFontData( const XclFontData& rFontData, bool bHasCharSet );
86 /** Returns read-only access to font data. */
87 const XclFontData& GetFontData() const { return maData; }
88 /** Returns true, if the font character set is valid. */
89 bool HasCharSet() const { return mbHasCharSet; }
90 /** Returns true, if the font contains superscript or subscript. */
91 bool HasEscapement() const { return maData.mnEscapem != EXC_FONTESC_NONE; }
92 /** Returns the text encoding for strings used with this font. */
93 rtl_TextEncoding GetFontEncoding() const;
95 /** Returns true, if this font contains characters for Asian scripts (CJK). */
96 bool HasAsianChars() const { return mbHasAsian; }
98 /** Reads a FONT record for all BIFF versions. */
99 void ReadFont( XclImpStream& rStrm );
100 /** Reads an EFONT record (BIFF2 font color). */
101 void ReadEfont( XclImpStream& rStrm );
102 /** Reads the font block from a CF (conditional format) record. */
103 void ReadCFFontBlock( XclImpStream& rStrm );
105 /** Fills all font properties to the item set.
106 @param rItemSet The destination item set.
107 @param eType The type of Which-IDs.
108 @param bSkipPoolDefs true = Do not put items equal to pool default; false = Put all items. */
109 void FillToItemSet( SfxItemSet& rItemSet, XclFontItemType eType,
110 bool bSkipPoolDefs = false ) const;
111 /** Writes all font properties to the passed property set.
112 @param pFontColor If set, overrides internal stored font color. */
113 void WriteFontProperties( ScfPropertySet& rPropSet,
114 XclFontPropSetType eType, const Color* pFontColor = nullptr ) const;
116 private:
117 /** Reads and sets height and flags. */
118 void ReadFontData2( XclImpStream& rStrm );
119 /** Reads and sets height, flags, color, boldness, script, family and charset. */
120 void ReadFontData5( XclImpStream& rStrm );
122 /** Reads and sets the font color. */
123 void ReadFontColor( XclImpStream& rStrm );
125 /** Reads and sets a byte string as font name. */
126 void ReadFontName2( XclImpStream& rStrm );
127 /** Reads and sets a Unicode string as font name. */
128 void ReadFontName8( XclImpStream& rStrm );
130 /** Tests whether the font contains CJK or CTL characters.
131 @descr This is only a weak guess using preselected characters. */
132 void GuessScriptType();
134 private:
135 XclFontData maData; /// All font attributes.
136 bool mbHasCharSet; /// true = Font contains own character set info.
137 bool mbHasWstrn; /// true = Font contains Western script characters.
138 bool mbHasAsian; /// true = Font contains Asian script characters.
139 bool mbHasCmplx; /// true = Font contains Complex script characters.
140 bool mbFontNameUsed; /// true = Font name, family, charset used.
141 bool mbHeightUsed; /// true = Font height used.
142 bool mbColorUsed; /// true = Color used.
143 bool mbWeightUsed; /// true = Weight used.
144 bool mbEscapemUsed; /// true = Escapement type used.
145 bool mbUnderlUsed; /// true = Underline style used.
146 bool mbItalicUsed; /// true = Italic used.
147 bool mbStrikeUsed; /// true = Strikeout used.
148 bool mbOutlineUsed; /// true = Outlined used.
149 bool mbShadowUsed; /// true = Shadowed used.
152 /** Stores the data of all fonts occurred in an Excel file. */
153 class XclImpFontBuffer : protected XclImpRoot
155 public:
156 /** delete copy constructor */
157 XclImpFontBuffer(const XclImpFontBuffer&) = delete;
158 /** delete copy-assignment operator */
159 const XclImpFontBuffer& operator=(const XclImpFontBuffer&) = delete;
161 explicit XclImpFontBuffer( const XclImpRoot& rRoot );
163 /** Clears all buffered data, used to set up for a new sheet. */
164 void Initialize();
166 /** Returns the object that stores all contents of a FONT record. */
167 const XclImpFont* GetFont( sal_uInt16 nFontIndex ) const;
168 /** Returns the application font data of this file, needed i.e. for column width. */
169 const XclFontData& GetAppFontData() const { return maAppFont; }
171 /** Reads a FONT record. */
172 void ReadFont( XclImpStream& rStrm );
173 /** Reads an EFONT record (BIFF2 font color). */
174 void ReadEfont( XclImpStream& rStrm );
176 /** Fills all font properties from a FONT record to the item set.
177 @param rItemSet The destination item set.
178 @param eType The type of Which-IDs.
179 @param nFontIdx The Excel index of the font.
180 @param bSkipPoolDefs true = Do not put items equal to pool default; false = Put all items. */
181 void FillToItemSet( SfxItemSet& rItemSet, XclFontItemType eType,
182 sal_uInt16 nFontIdx, bool bSkipPoolDefs = false ) const;
183 /** Writes all font properties to the passed property set.
184 @param pFontColor If set, overrides internal stored font color. */
185 void WriteFontProperties(
186 ScfPropertySet& rPropSet, XclFontPropSetType eType,
187 sal_uInt16 nFontIdx, const Color* pFontColor = nullptr ) const;
188 /** Writes default font properties for form controls to the passed property set. */
189 void WriteDefaultCtrlFontProperties( ScfPropertySet& rPropSet ) const;
191 private:
192 /** Updates the application default font. */
193 void UpdateAppFont( const XclFontData& rFontData, bool bHasCharSet );
195 private:
196 std::vector< XclImpFont > maFontList; /// List of all FONT records in the Excel file.
197 XclFontData maAppFont; /// Application font (for column width).
198 XclImpFont maFont4; /// Built-in font with index 4.
199 XclImpFont maCtrlFont; /// BIFF5 default form controls font (Helv,8pt,bold).
202 // FORMAT record - number formats =============================================
204 /** Stores all user defined number formats occurred in the file. */
205 class XclImpNumFmtBuffer : public XclNumFmtBuffer, protected XclImpRoot
207 public:
208 explicit XclImpNumFmtBuffer( const XclImpRoot& rRoot );
210 /** Clears all buffered data, used to set up for a new sheet. */
211 void Initialize();
213 /** Reads a FORMAT record. */
214 void ReadFormat( XclImpStream& rStrm );
216 /** Read NumFmt from conditional format record */
217 sal_uInt16 ReadCFFormat( XclImpStream& rStrm, bool bIFmt );
219 /** Creates the number formats in the Calc document. */
220 void CreateScFormats();
222 /** Returns the format key with the passed Excel index or NUMBERFORMAT_ENTRY_NOT_FOUND on error. */
223 sal_uInt32 GetScFormat( sal_uInt16 nXclNumFmt ) const;
225 /** Fills an Excel number format to the passed item set.
226 @param rItemSet The destination item set.
227 @param nXclNumFmt The Excel number format index.
228 @param bSkipPoolDefs true = Do not put items equal to pool default; false = Put all items. */
229 void FillToItemSet(
230 SfxItemSet& rItemSet, sal_uInt16 nXclNumFmt,
231 bool bSkipPoolDefs = false ) const;
232 /** Fills a Calc number format to the passed item set.
233 @param rItemSet The destination item set.
234 @param nScNumFmt The Calc number formatter index of the format.
235 @param bSkipPoolDefs true = Do not put items equal to pool default; false = Put all items. */
236 void FillScFmtToItemSet(
237 SfxItemSet& rItemSet, sal_uInt32 nScNumFmt,
238 bool bSkipPoolDefs = false ) const;
240 private:
241 typedef ::std::map< sal_uInt16, sal_uLong > XclImpIndexMap;
243 XclImpIndexMap maIndexMap; /// Maps Excel format indexes to Calc formats.
244 sal_uInt16 mnNextXclIdx; /// Index counter for BIFF2-BIFF4.
247 // XF, STYLE record - Cell formatting =========================================
249 /** Extends the XclCellProt struct for import.
250 @descr Provides functions to fill from Excel record data and to fill to item sets. */
251 struct XclImpCellProt : public XclCellProt
253 /** Fills this struct with BIFF2 XF record data. */
254 void FillFromXF2( sal_uInt8 nNumFmt );
255 /** Fills this struct with BIFF3-BIFF8 XF record data. */
256 void FillFromXF3( sal_uInt16 nProt );
258 /** Inserts items representing this protection style into the item set.
259 @param bSkipPoolDefs true = Do not put items equal to pool default; false = Put all items. */
260 void FillToItemSet( SfxItemSet& rItemSet, bool bSkipPoolDefs = false ) const;
263 /** Extends the XclCellAlign struct for import.
264 @descr Provides functions to fill from Excel record data and to fill to item sets. */
265 struct XclImpCellAlign : public XclCellAlign
267 /** Fills this struct with BIFF2 XF record data. */
268 void FillFromXF2( sal_uInt8 nFlags );
269 /** Fills this struct with BIFF3 XF record data. */
270 void FillFromXF3( sal_uInt16 nAlign );
271 /** Fills this struct with BIFF4 XF record data. */
272 void FillFromXF4( sal_uInt16 nAlign );
273 /** Fills this struct with BIFF5/BIFF7 XF record data. */
274 void FillFromXF5( sal_uInt16 nAlign );
275 /** Fills this struct with BIFF8 XF record data. */
276 void FillFromXF8( sal_uInt16 nAlign, sal_uInt16 nMiscAttrib );
277 /** Fills this struct with CF record data. */
278 void FillFromCF( sal_uInt16 nAlign, sal_uInt16 nMiscAttrib );
280 /** Inserts items representing this alignment style into the item set.
281 @param bSkipPoolDefs true = Do not put items equal to pool default; false = Put all items. */
282 void FillToItemSet( SfxItemSet& rItemSet, const XclImpFont* pFont, bool bSkipPoolDefs = false ) const;
285 /** Extends the XclCellBorder struct for import.
286 @descr Provides functions to fill from Excel record data and to fill to item sets. */
287 struct XclImpCellBorder : public XclCellBorder
289 bool mbLeftUsed; /// true = Left line style used.
290 bool mbRightUsed; /// true = Right line style used.
291 bool mbTopUsed; /// true = Top line style used.
292 bool mbBottomUsed; /// true = Bottom line style used.
293 bool mbDiagUsed; /// true = Diagonal line style used.
295 explicit XclImpCellBorder();
297 /** Sets outer line states and diagonal line states to used or unused. */
298 void SetUsedFlags( bool bOuterUsed, bool bDiagUsed );
300 /** Fills this struct with BIFF2 XF record data. */
301 void FillFromXF2( sal_uInt8 nFlags );
302 /** Fills this struct with BIFF3/BIFF4 XF record data. */
303 void FillFromXF3( sal_uInt32 nBorder );
304 /** Fills this struct with BIFF5/BIFF7 XF record data. */
305 void FillFromXF5( sal_uInt32 nBorder, sal_uInt32 nArea );
306 /** Fills this struct with BIFF8 XF record data. */
307 void FillFromXF8( sal_uInt32 nBorder1, sal_uInt32 nBorder2 );
309 /** Fills this struct with BIFF8 CF (conditional format) record data. */
310 void FillFromCF8( sal_uInt16 nLineStyle, sal_uInt32 nLineColor, sal_uInt32 nFlags );
312 /** Returns true, if any of the outer border lines is visible. */
313 bool HasAnyOuterBorder() const;
315 /** Inserts a box item representing this border style into the item set.
316 @param bSkipPoolDefs true = Do not put items equal to pool default; false = Put all items. */
317 void FillToItemSet(
318 SfxItemSet& rItemSet,
319 const XclImpPalette& rPalette,
320 bool bSkipPoolDefs = false ) const;
323 /** Extends the XclCellArea struct for import.
324 @descr Provides functions to fill from Excel record data and to fill to item sets. */
325 struct XclImpCellArea : public XclCellArea
327 bool mbForeUsed; /// true = Foreground color used.
328 bool mbBackUsed; /// true = Background color used.
329 bool mbPattUsed; /// true = Pattern used.
331 explicit XclImpCellArea();
333 /** Sets colors and pattern state to used or unused. */
334 void SetUsedFlags( bool bUsed );
336 /** Fills this struct with BIFF2 XF record data. */
337 void FillFromXF2( sal_uInt8 nFlags );
338 /** Fills this struct with BIFF3/BIFF4 XF record data. */
339 void FillFromXF3( sal_uInt16 nArea );
340 /** Fills this struct with BIFF5/BIFF7 XF record data. */
341 void FillFromXF5( sal_uInt32 nArea );
342 /** Fills this struct with BIFF8 XF record data. */
343 void FillFromXF8( sal_uInt32 nBorder2, sal_uInt16 nArea );
345 /** Fills this struct with BIFF8 CF (conditional format) record data. */
346 void FillFromCF8( sal_uInt16 nPattern, sal_uInt16 nColor, sal_uInt32 nFlags );
348 /** Inserts a brush item representing this area style into the item set.
349 @param bSkipPoolDefs true = Do not put items equal to pool default; false = Put all items. */
350 void FillToItemSet(
351 SfxItemSet& rItemSet,
352 const XclImpPalette& rPalette,
353 bool bSkipPoolDefs = false ) const;
356 /** Represents an XF record index with additional information. */
357 class XclImpXFIndex
359 public:
360 explicit XclImpXFIndex( sal_uInt16 nXFIndex, bool bBoolCell = false ) :
361 mnXFIndex( nXFIndex ), mbBoolCell( bBoolCell ) {}
363 sal_uInt16 GetXFIndex() const { return mnXFIndex; }
364 bool IsBoolCell() const { return mbBoolCell; }
366 private:
367 sal_uInt16 mnXFIndex; /// The XF record index.
368 bool mbBoolCell; /// true = A Boolean value cell.
371 inline bool operator==( const XclImpXFIndex& rLeft, const XclImpXFIndex& rRight )
372 { return (rLeft.GetXFIndex() == rRight.GetXFIndex()) && (rLeft.IsBoolCell() == rRight.IsBoolCell()); }
374 inline bool operator!=( const XclImpXFIndex& rLeft, const XclImpXFIndex& rRight )
375 { return !(rLeft == rRight); }
377 /** Contains all data of a XF record and a Calc item set. */
378 class XclImpXF : public XclXFBase, protected XclImpRoot
380 public:
381 /** make noncopyable */
382 XclImpXF(const XclImpXF&) = delete;
383 const XclImpXF& operator=(const XclImpXF&) = delete;
385 explicit XclImpXF( const XclImpRoot& rRoot );
386 virtual ~XclImpXF() override;
388 /** Reads an XF record. */
389 void ReadXF( XclImpStream& rStrm );
391 bool GetLineBreak() const { return maAlignment.mbLineBreak; }
392 sal_uInt8 GetHorAlign() const { return maAlignment.mnHorAlign; }
393 sal_uInt16 GetFontIndex() const { return mnXclFont; }
395 /** Creates a Calc item set containing an item set with all cell properties.
396 @param bSkipPoolDefs true = Do not put items equal to pool default; false = Put all items.
397 @return A read-only reference to the item set stored internally. */
398 const ScPatternAttr& CreatePattern( bool bSkipPoolDefs = false );
400 void ApplyPatternToAttrVector(
401 ::std::vector<ScAttrEntry>& rAttrs, SCROW nRow1, SCROW nRow2,
402 sal_uInt32 nForceScNumFmt);
404 /** Inserts all formatting attributes to the specified area in the Calc document.
405 @param nForcedNumFmt If not set to NUMBERFORMAT_ENTRY_NOT_FOUND, it will overwrite
406 the number format of the XF. */
407 void ApplyPattern(
408 SCCOL nScCol1, SCROW nScRow1,
409 SCCOL nScCol2, SCROW nScRow2,
410 SCTAB nScTab );
412 /** Converts formatting information from BIFF2 cell record data directly. */
413 static void ApplyPatternForBiff2CellFormat(
414 const XclImpRoot& rRoot, const ScAddress& rScPos,
415 sal_uInt8 nFlags1, sal_uInt8 nFlags2, sal_uInt8 nFlags3 );
417 private:
418 void ReadXF2( XclImpStream& rStrm );
419 void ReadXF3( XclImpStream& rStrm );
420 void ReadXF4( XclImpStream& rStrm );
421 void ReadXF5( XclImpStream& rStrm );
422 void ReadXF8( XclImpStream& rStrm );
424 /** Sets all "attribute used" flags according to the passed mask.
425 @descr In cell XFs, a set bit represents "used", in style XFs it is a cleared bit.
426 Therefore mbCellXF must be set correctly before calling this method. */
427 void SetUsedFlags( sal_uInt8 nUsedFlags );
429 private:
430 typedef ::std::unique_ptr< ScPatternAttr > ScPatternAttrPtr;
432 ScPatternAttrPtr mpPattern; /// Calc item set.
433 ScStyleSheet* mpStyleSheet; /// Calc cell style sheet.
435 XclImpCellProt maProtection; /// Cell protection flags.
436 XclImpCellAlign maAlignment; /// All alignment attributes.
437 XclImpCellBorder maBorder; /// Border line style.
438 XclImpCellArea maArea; /// Background area style.
439 sal_uInt16 mnXclNumFmt; /// Index to number format.
440 sal_uInt16 mnXclFont; /// Index to font record.
443 /** Contains all data of a cell style associated with an XF record. */
444 class XclImpStyle : protected XclImpRoot
446 public:
447 explicit XclImpStyle( const XclImpRoot& rRoot );
449 /** Reads a STYLE record. */
450 void ReadStyle( XclImpStream& rStrm );
452 const OUString& GetName() const { return maName; }
453 sal_uInt16 GetXfId() const { return mnXfId; }
454 bool IsBuiltin() const { return mbBuiltin && (mnBuiltinId != EXC_STYLE_USERDEF); }
455 sal_uInt8 GetBuiltinId() const { return mnBuiltinId; }
456 sal_uInt8 GetLevel() const { return mnLevel; }
458 /** Creates a cell style sheet and inserts it into the Calc document.
459 @return The pointer to the cell style sheet, or 0, if there is no style sheet. */
460 ScStyleSheet* CreateStyleSheet();
461 /** Creates the Calc style sheet, if this is a user-defined style. */
462 void CreateUserStyle( const OUString& rFinalName );
464 private:
465 OUString maName; /// Cell style name.
466 sal_uInt16 mnXfId; /// Formatting for this cell style.
467 sal_uInt8 mnBuiltinId; /// Identifier for builtin styles.
468 sal_uInt8 mnLevel; /// Level for builtin column/row styles.
469 bool mbBuiltin; /// True = builtin style.
470 bool mbCustom; /// True = customized builtin style.
471 bool mbHidden; /// True = style not visible in GUI.
473 OUString maFinalName; /// Final name used in the Calc document.
474 ScStyleSheet* mpStyleSheet; /// Calc cell style sheet.
477 /** Contains all XF records occurred in the file.
478 @descr This class is able to read XF records (BIFF2 - BIFF8) and STYLE records (BIFF8). */
479 class XclImpXFBuffer : protected XclImpRoot
481 public:
482 /** make noncopyable */
483 XclImpXFBuffer(const XclImpXFBuffer&) = delete;
484 const XclImpXFBuffer& operator=(const XclImpXFBuffer&) = delete;
486 explicit XclImpXFBuffer( const XclImpRoot& rRoot );
488 /** Clears all buffered data, used to set up for a new sheet. */
489 void Initialize();
491 /** Reads an XF record. */
492 void ReadXF( XclImpStream& rStrm );
493 /** Reads a STYLE record. */
494 void ReadStyle( XclImpStream& rStrm );
496 /** Returns the object that stores all contents of an XF record. */
497 XclImpXF* GetXF( sal_uInt16 nXFIndex )
498 { return (nXFIndex >= maXFList.size()) ? nullptr : maXFList.at(nXFIndex).get(); }
500 const XclImpXF* GetXF( sal_uInt16 nXFIndex ) const
501 { return (nXFIndex >= maXFList.size()) ? nullptr : maXFList.at(nXFIndex).get(); }
503 /** Returns the index to the Excel font used in the specified XF record. */
504 sal_uInt16 GetFontIndex( sal_uInt16 nXFIndex ) const;
505 /** Returns the Excel font used in the specified XF record. */
506 const XclImpFont* GetFont( sal_uInt16 nXFIndex ) const;
508 /** Creates all user defined style sheets. */
509 void CreateUserStyles();
510 /** Creates a cell style sheet of the passed XF and inserts it into the Calc document.
511 @return The pointer to the cell style sheet, or 0, if there is no style sheet. */
512 ScStyleSheet* CreateStyleSheet( sal_uInt16 nXFIndex );
514 private:
515 typedef std::vector< std::unique_ptr<XclImpStyle> > XclImpStyleList;
516 typedef ::std::map< sal_uInt16, XclImpStyle* > XclImpStyleMap;
518 std::vector< std::unique_ptr<XclImpXF> > maXFList; /// List of contents of all XF record.
519 XclImpStyleList maBuiltinStyles; /// List of built-in cell styles.
520 XclImpStyleList maUserStyles; /// List of user defined cell styles.
521 XclImpStyleMap maStylesByXf; /// Maps XF records to cell styles.
524 // Buffer for XF indexes in cells =============================================
526 /** Contains an (encoded) XF index for a range of rows in a single column. */
527 class XclImpXFRange
529 public:
530 SCROW mnScRow1; /// The first row of an equal-formatted range.
531 SCROW mnScRow2; /// The last row of an equal-formatted range.
532 XclImpXFIndex maXFIndex; /// Extended XF index.
534 inline explicit XclImpXFRange( SCROW nScRow, const XclImpXFIndex& rXFIndex );
535 inline explicit XclImpXFRange( SCROW nFirstScRow, SCROW nLastScRow, const XclImpXFIndex& rXFIndex );
537 /** Returns true, if nScRow is contained in own row range. */
538 inline bool Contains( SCROW nScRow ) const;
540 /** Returns true, if the range has been expanded. */
541 bool Expand( SCROW nScRow, const XclImpXFIndex& rXFIndex );
542 /** Returns true, if the range has been expanded. */
543 bool Expand( const XclImpXFRange& rNextRange );
546 inline XclImpXFRange::XclImpXFRange( SCROW nScRow, const XclImpXFIndex& rXFIndex ) :
547 mnScRow1( nScRow ),
548 mnScRow2( nScRow ),
549 maXFIndex( rXFIndex )
553 inline XclImpXFRange::XclImpXFRange( SCROW nFirstScRow, SCROW nLastScRow, const XclImpXFIndex& rXFIndex ) :
554 mnScRow1( nFirstScRow ),
555 mnScRow2( nLastScRow ),
556 maXFIndex( rXFIndex )
560 inline bool XclImpXFRange::Contains( SCROW nScRow ) const
562 return (mnScRow1 <= nScRow) && (nScRow <= mnScRow2);
565 /** Contains the XF indexes for every used cell in a column. */
566 class XclImpXFRangeColumn
568 public:
569 typedef std::vector< XclImpXFRange > IndexList;
571 explicit XclImpXFRangeColumn() {}
573 IndexList::iterator begin() { return maIndexList.begin(); }
574 IndexList::iterator end() { return maIndexList.end(); }
576 /** Inserts a single row range into the list. */
577 void SetDefaultXF( const XclImpXFIndex& rXFIndex, const XclImpRoot& rRoot );
579 /** Inserts a new (encoded) XF index (first try to expand the last range). */
580 void SetXF( SCROW nScRow, const XclImpXFIndex& rXFIndex );
582 private:
583 /** Finds the previous and next row range from row position nScRow.
584 @descr If an XF still exists, it is contained in rpPrevRange. */
585 void Find(
586 XclImpXFRange*& rpPrevRange,
587 XclImpXFRange*& rpNextRange,
588 sal_uLong& rnNextIndex,
589 SCROW nScRow );
591 /** Tries to concatenate a range with its predecessor.
592 @descr The ranges must have the same XF index and must not have a gap.
593 The resulting range has the index nIndex-1. */
594 void TryConcatPrev( sal_uLong nIndex );
596 /** Insert a range into the list at the specified index. */
597 void Insert(XclImpXFRange aXFRange, sal_uLong nIndex);
599 private:
600 IndexList maIndexList; /// The list of XF index range.
603 /** Contains the XF indexes for every used cell in a single sheet. */
604 class XclImpXFRangeBuffer : protected XclImpRoot
606 public:
607 /** make noncopyable */
608 XclImpXFRangeBuffer(const XclImpXFRangeBuffer&) = delete;
609 const XclImpXFRangeBuffer& operator=(const XclImpXFRangeBuffer&) = delete;
611 explicit XclImpXFRangeBuffer( const XclImpRoot& rRoot );
612 virtual ~XclImpXFRangeBuffer() override;
614 /** Clears all buffered data, used to set up for a new sheet. */
615 void Initialize();
617 /** Inserts a new XF index. */
618 void SetXF( const ScAddress& rScPos, sal_uInt16 nXFIndex );
619 /** Inserts a new XF index for blank cells. */
620 void SetBlankXF( const ScAddress& rScPos, sal_uInt16 nXFIndex );
621 /** Inserts a new XF index for boolean cells. */
622 void SetBoolXF( const ScAddress& rScPos, sal_uInt16 nXFIndex );
623 /** Inserts a new XF index for all cells in a row. */
624 void SetRowDefXF( SCROW nScRow, sal_uInt16 nXFIndex );
625 /** Inserts a new XF index for all cells in a column. */
626 void SetColumnDefXF( SCCOL nScCol, sal_uInt16 nXFIndex );
628 /** Inserts a range of hyperlink cells. */
629 void SetHyperlink( const XclRange& rXclRange, const OUString& rUrl );
631 /** Inserts a complete merged cell range. */
632 void SetMerge( SCCOL nScCol1, SCROW nScRow1, SCCOL nScCol2, SCROW nScRow2 );
634 /** Applies styles and cell merging to the current sheet in the document. */
635 void Finalize();
637 private:
638 /** Insertion mode of an XF index. */
639 enum XclImpXFInsertMode
641 xlXFModeCell, /// Filled cell.
642 xlXFModeBoolCell, /// Cell with a single Boolean value.
643 xlXFModeBlank, /// Blank cell.
644 xlXFModeRow /// Row default XF.
647 private:
648 /** Inserts a new XF index for the specified cell type. */
649 void SetXF( const ScAddress& rScPos, sal_uInt16 nXFIndex, XclImpXFInsertMode eMode );
651 /** Copies border of the last cell of the range to the first cell to keep it visible
652 when the range is merged.
653 @param nLine
654 SvxBoxItemLine::RIGHT = copy most-right border of top row;
655 SvxBoxItemLine::BOTTOM = copy most-bottom border of first column. */
656 void SetBorderLine( const ScRange& rRange, SCTAB nScTab, SvxBoxItemLine nLine );
658 private:
660 std::vector< std::optional<XclImpXFRangeColumn> >
661 maColumns; /// Array of column XF index buffers.
662 std::vector< std::optional<sal_uInt16> >
663 maRows; /// Array of row XF index.
664 std::vector< std::pair< XclRange, OUString > >
665 maHyperlinks; /// Maps URLs to hyperlink cells.
666 ScRangeList maMergeList; /// List of merged cell ranges.
669 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */