Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / source / filter / inc / xistyle.hxx
blobee6664162fbff19924ecd643bf88a5bd71399715
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_XISTYLE_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_INC_XISTYLE_HXX
23 #include <tools/solar.h>
24 #include <vector>
25 #include <memory>
26 #include <rangelst.hxx>
27 #include "xlstyle.hxx"
28 #include "xiroot.hxx"
30 class ScPatternAttr;
32 struct XclRange;
33 struct 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 sal_uInt8 GetHorAlign() const { return maAlignment.mnHorAlign; }
392 sal_uInt16 GetFontIndex() const { return mnXclFont; }
394 /** Creates a Calc item set containing an item set with all cell properties.
395 @param bSkipPoolDefs true = Do not put items equal to pool default; false = Put all items.
396 @return A read-only reference to the item set stored internally. */
397 const ScPatternAttr& CreatePattern( bool bSkipPoolDefs = false );
399 void ApplyPatternToAttrVector(
400 ::std::vector<ScAttrEntry>& rAttrs, SCROW nRow1, SCROW nRow2,
401 sal_uInt32 nForceScNumFmt);
403 /** Inserts all formatting attributes to the specified area in the Calc document.
404 @param nForcedNumFmt If not set to NUMBERFORMAT_ENTRY_NOT_FOUND, it will overwrite
405 the number format of the XF. */
406 void ApplyPattern(
407 SCCOL nScCol1, SCROW nScRow1,
408 SCCOL nScCol2, SCROW nScRow2,
409 SCTAB nScTab );
411 /** Converts formatting information from BIFF2 cell record data directly. */
412 static void ApplyPatternForBiff2CellFormat(
413 const XclImpRoot& rRoot, const ScAddress& rScPos,
414 sal_uInt8 nFlags1, sal_uInt8 nFlags2, sal_uInt8 nFlags3 );
416 private:
417 void ReadXF2( XclImpStream& rStrm );
418 void ReadXF3( XclImpStream& rStrm );
419 void ReadXF4( XclImpStream& rStrm );
420 void ReadXF5( XclImpStream& rStrm );
421 void ReadXF8( XclImpStream& rStrm );
423 /** Sets all "attribute used" flags according to the passed mask.
424 @descr In cell XFs, a set bit represents "used", in style XFs it is a cleared bit.
425 Therefore mbCellXF must be set correctly before calling this method. */
426 void SetUsedFlags( sal_uInt8 nUsedFlags );
428 private:
429 typedef ::std::unique_ptr< ScPatternAttr > ScPatternAttrPtr;
431 ScPatternAttrPtr mpPattern; /// Calc item set.
432 ScStyleSheet* mpStyleSheet; /// Calc cell style sheet.
434 XclImpCellProt maProtection; /// Cell protection flags.
435 XclImpCellAlign maAlignment; /// All alignment attributes.
436 XclImpCellBorder maBorder; /// Border line style.
437 XclImpCellArea maArea; /// Background area style.
438 sal_uInt16 mnXclNumFmt; /// Index to number format.
439 sal_uInt16 mnXclFont; /// Index to font record.
442 /** Contains all data of a cell style associated with an XF record. */
443 class XclImpStyle : protected XclImpRoot
445 public:
446 explicit XclImpStyle( const XclImpRoot& rRoot );
448 /** Reads a STYLE record. */
449 void ReadStyle( XclImpStream& rStrm );
451 const OUString& GetName() const { return maName; }
452 sal_uInt16 GetXfId() const { return mnXfId; }
453 bool IsBuiltin() const { return mbBuiltin && (mnBuiltinId != EXC_STYLE_USERDEF); }
454 sal_uInt8 GetBuiltinId() const { return mnBuiltinId; }
455 sal_uInt8 GetLevel() const { return mnLevel; }
457 /** Creates a cell style sheet and inserts it into the Calc document.
458 @return The pointer to the cell style sheet, or 0, if there is no style sheet. */
459 ScStyleSheet* CreateStyleSheet();
460 /** Creates the Calc style sheet, if this is a user-defined style. */
461 void CreateUserStyle( const OUString& rFinalName );
463 private:
464 OUString maName; /// Cell style name.
465 sal_uInt16 mnXfId; /// Formatting for this cell style.
466 sal_uInt8 mnBuiltinId; /// Identifier for builtin styles.
467 sal_uInt8 mnLevel; /// Level for builtin column/row styles.
468 bool mbBuiltin; /// True = builtin style.
469 bool mbCustom; /// True = customized builtin style.
470 bool mbHidden; /// True = style not visible in GUI.
472 OUString maFinalName; /// Final name used in the Calc document.
473 ScStyleSheet* mpStyleSheet; /// Calc cell style sheet.
476 /** Contains all XF records occurred in the file.
477 @descr This class is able to read XF records (BIFF2 - BIFF8) and STYLE records (BIFF8). */
478 class XclImpXFBuffer : protected XclImpRoot
480 public:
481 /** make noncopyable */
482 XclImpXFBuffer(const XclImpXFBuffer&) = delete;
483 const XclImpXFBuffer& operator=(const XclImpXFBuffer&) = delete;
485 explicit XclImpXFBuffer( const XclImpRoot& rRoot );
487 /** Clears all buffered data, used to set up for a new sheet. */
488 void Initialize();
490 /** Reads an XF record. */
491 void ReadXF( XclImpStream& rStrm );
492 /** Reads a STYLE record. */
493 void ReadStyle( XclImpStream& rStrm );
495 /** Returns the object that stores all contents of an XF record. */
496 XclImpXF* GetXF( sal_uInt16 nXFIndex )
497 { return (nXFIndex >= maXFList.size()) ? nullptr : maXFList.at(nXFIndex).get(); }
499 const XclImpXF* GetXF( sal_uInt16 nXFIndex ) const
500 { return (nXFIndex >= maXFList.size()) ? nullptr : maXFList.at(nXFIndex).get(); }
502 /** Returns the index to the Excel font used in the specified XF record. */
503 sal_uInt16 GetFontIndex( sal_uInt16 nXFIndex ) const;
504 /** Returns the Excel font used in the specified XF record. */
505 const XclImpFont* GetFont( sal_uInt16 nXFIndex ) const;
507 /** Creates all user defined style sheets. */
508 void CreateUserStyles();
509 /** Creates a cell style sheet of the passed XF and inserts it into the Calc document.
510 @return The pointer to the cell style sheet, or 0, if there is no style sheet. */
511 ScStyleSheet* CreateStyleSheet( sal_uInt16 nXFIndex );
513 private:
514 typedef std::vector< std::unique_ptr<XclImpStyle> > XclImpStyleList;
515 typedef ::std::map< sal_uInt16, XclImpStyle* > XclImpStyleMap;
517 std::vector< std::unique_ptr<XclImpXF> > maXFList; /// List of contents of all XF record.
518 XclImpStyleList maBuiltinStyles; /// List of built-in cell styles.
519 XclImpStyleList maUserStyles; /// List of user defined cell styles.
520 XclImpStyleMap maStylesByXf; /// Maps XF records to cell styles.
523 // Buffer for XF indexes in cells =============================================
525 /** Contains an (encoded) XF index for a range of rows in a single column. */
526 class XclImpXFRange
528 public:
529 SCROW mnScRow1; /// The first row of an equal-formatted range.
530 SCROW mnScRow2; /// The last row of an equal-formatted range.
531 XclImpXFIndex maXFIndex; /// Extended XF index.
533 inline explicit XclImpXFRange( SCROW nScRow, const XclImpXFIndex& rXFIndex );
534 inline explicit XclImpXFRange( SCROW nFirstScRow, SCROW nLastScRow, const XclImpXFIndex& rXFIndex );
536 /** Returns true, if nScRow is contained in own row range. */
537 inline bool Contains( SCROW nScRow ) const;
539 /** Returns true, if the range has been expanded. */
540 bool Expand( SCROW nScRow, const XclImpXFIndex& rXFIndex );
541 /** Returns true, if the range has been expanded. */
542 bool Expand( const XclImpXFRange& rNextRange );
545 inline XclImpXFRange::XclImpXFRange( SCROW nScRow, const XclImpXFIndex& rXFIndex ) :
546 mnScRow1( nScRow ),
547 mnScRow2( nScRow ),
548 maXFIndex( rXFIndex )
552 inline XclImpXFRange::XclImpXFRange( SCROW nFirstScRow, SCROW nLastScRow, const XclImpXFIndex& rXFIndex ) :
553 mnScRow1( nFirstScRow ),
554 mnScRow2( nLastScRow ),
555 maXFIndex( rXFIndex )
559 inline bool XclImpXFRange::Contains( SCROW nScRow ) const
561 return (mnScRow1 <= nScRow) && (nScRow <= mnScRow2);
564 /** Contains the XF indexes for every used cell in a column. */
565 class XclImpXFRangeColumn
567 public:
568 /** make noncopyable */
569 XclImpXFRangeColumn(const XclImpXFRangeColumn&) = delete;
570 const XclImpXFRangeColumn& operator=(const XclImpXFRangeColumn&) = delete;
572 typedef std::vector< std::unique_ptr<XclImpXFRange> > IndexList;
574 explicit XclImpXFRangeColumn() {}
576 IndexList::iterator begin() { return maIndexList.begin(); }
577 IndexList::iterator end() { return maIndexList.end(); }
579 /** Inserts a single row range into the list. */
580 void SetDefaultXF( const XclImpXFIndex& rXFIndex );
582 /** Inserts a new (encoded) XF index (first try to expand the last range). */
583 void SetXF( SCROW nScRow, const XclImpXFIndex& rXFIndex );
585 private:
586 /** Finds the previous and next row range from row position nScRow.
587 @descr If an XF still exists, it is contained in rpPrevRange. */
588 void Find(
589 XclImpXFRange*& rpPrevRange,
590 XclImpXFRange*& rpNextRange,
591 sal_uLong& rnNextIndex,
592 SCROW nScRow );
594 /** Tries to concatenate a range with its predecessor.
595 @descr The ranges must have the same XF index and must not have a gap.
596 The resulting range has the index nIndex-1. */
597 void TryConcatPrev( sal_uLong nIndex );
599 /** Insert a range into the list at the specified index. */
600 void Insert(XclImpXFRange* pXFRange, sal_uLong nIndex);
602 private:
603 IndexList maIndexList; /// The list of XF index range.
606 /** Contains the XF indexes for every used cell in a single sheet. */
607 class XclImpXFRangeBuffer : protected XclImpRoot
609 public:
610 /** make noncopyable */
611 XclImpXFRangeBuffer(const XclImpXFRangeBuffer&) = delete;
612 const XclImpXFRangeBuffer& operator=(const XclImpXFRangeBuffer&) = delete;
614 explicit XclImpXFRangeBuffer( const XclImpRoot& rRoot );
615 virtual ~XclImpXFRangeBuffer() override;
617 /** Clears all buffered data, used to set up for a new sheet. */
618 void Initialize();
620 /** Inserts a new XF index. */
621 void SetXF( const ScAddress& rScPos, sal_uInt16 nXFIndex );
622 /** Inserts a new XF index for blank cells. */
623 void SetBlankXF( const ScAddress& rScPos, sal_uInt16 nXFIndex );
624 /** Inserts a new XF index for boolean cells. */
625 void SetBoolXF( const ScAddress& rScPos, sal_uInt16 nXFIndex );
626 /** Inserts a new XF index for all cells in a row. */
627 void SetRowDefXF( SCROW nScRow, sal_uInt16 nXFIndex );
628 /** Inserts a new XF index for all cells in a column. */
629 void SetColumnDefXF( SCCOL nScCol, sal_uInt16 nXFIndex );
631 /** Inserts a range of hyperlink cells. */
632 void SetHyperlink( const XclRange& rXclRange, const OUString& rUrl );
634 /** Inserts a complete merged cell range. */
635 void SetMerge( SCCOL nScCol1, SCROW nScRow1, SCCOL nScCol2, SCROW nScRow2 );
637 /** Applies styles and cell merging to the current sheet in the document. */
638 void Finalize();
640 private:
641 /** Insertion mode of an XF index. */
642 enum XclImpXFInsertMode
644 xlXFModeCell, /// Filled cell.
645 xlXFModeBoolCell, /// Cell with a single Boolean value.
646 xlXFModeBlank, /// Blank cell.
647 xlXFModeRow /// Row default XF.
650 private:
651 /** Inserts a new XF index for the specified cell type. */
652 void SetXF( const ScAddress& rScPos, sal_uInt16 nXFIndex, XclImpXFInsertMode eMode );
654 /** Copies border of the last cell of the range to the first cell to keep it visible
655 when the range is merged.
656 @param nLine
657 SvxBoxItemLine::RIGHT = copy most-right border of top row;
658 SvxBoxItemLine::BOTTOM = copy most-bottom border of first column. */
659 void SetBorderLine( const ScRange& rRange, SCTAB nScTab, SvxBoxItemLine nLine );
661 private:
662 typedef std::shared_ptr< XclImpXFRangeColumn > XclImpXFRangeColumnRef;
663 typedef ::std::vector< XclImpXFRangeColumnRef > XclImpXFRangeColumnVec;
664 typedef ::std::pair< XclRange, OUString > XclImpHyperlinkRange;
665 typedef ::std::vector< XclImpHyperlinkRange > XclImpHyperlinkVector;
667 XclImpXFRangeColumnVec maColumns; /// Array of column XF index buffers.
668 XclImpHyperlinkVector maHyperlinks; /// Maps URLs to hyperlink cells.
669 ScRangeList maMergeList; /// List of merged cell ranges.
672 #endif
674 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */