1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <tools/solar.h>
25 #include <rangelst.hxx>
26 #include "xlstyle.hxx"
33 enum class SvxBoxItemLine
;
35 /* ============================================================================
36 - Buffers for style records (PALETTE, FONT, FORMAT, XF)
37 and a container for XF indexes for every used cell in a sheet.
38 ============================================================================ */
40 // PALETTE record - color information =========================================
42 /** Stores the default colors for the current BIFF version and the contents of
44 class XclImpPalette
: public XclDefaultPalette
47 explicit XclImpPalette( const XclImpRoot
& rRoot
);
49 /** Clears all buffered data, used to set up for a new sheet. */
52 /** Returns the color for a (non-zero-based) Excel palette entry.
53 @descr First looks for a color read from file, then looks for a default color.
54 @return The color from current or default palette or COL_AUTO, if nothing else found. */
55 Color
GetColor( sal_uInt16 nXclIndex
) const;
57 /** Reads a PALETTE record. */
58 void ReadPalette( XclImpStream
& rStrm
);
62 typedef ::std::vector
< Color
> ColorVec
;
63 ColorVec maColorTable
; /// Colors read from file.
64 const XclImpRoot
& mrRoot
;
67 // FONT record - font information =============================================
69 /** Stores all data of an Excel font and provides import of FONT records. */
70 class XclImpFont
: protected XclImpRoot
73 explicit XclImpFont( const XclImpRoot
& rRoot
);
75 /** Constructs a font from font data.
76 @descr Special handling for font style (bold, italic) in font name,
77 overwrites settings in rFontData. */
78 explicit XclImpFont( const XclImpRoot
& rRoot
, const XclFontData
& rFontData
);
80 /** Sets all font attributes to used or unused. */
81 void SetAllUsedFlags( bool bUsed
);
82 /** Sets the passed font data and all used flags to 'used'. */
83 void SetFontData( const XclFontData
& rFontData
, bool bHasCharSet
);
85 /** Returns read-only access to font data. */
86 const XclFontData
& GetFontData() const { return maData
; }
87 /** Returns true, if the font character set is valid. */
88 bool HasCharSet() const { return mbHasCharSet
; }
89 /** Returns true, if the font contains superscript or subscript. */
90 bool HasEscapement() const { return maData
.mnEscapem
!= EXC_FONTESC_NONE
; }
91 /** Returns the text encoding for strings used with this font. */
92 rtl_TextEncoding
GetFontEncoding() const;
94 /** Returns true, if this font contains characters for Asian scripts (CJK). */
95 bool HasAsianChars() const { return mbHasAsian
; }
97 /** Reads a FONT record for all BIFF versions. */
98 void ReadFont( XclImpStream
& rStrm
);
99 /** Reads an EFONT record (BIFF2 font color). */
100 void ReadEfont( XclImpStream
& rStrm
);
101 /** Reads the font block from a CF (conditional format) record. */
102 void ReadCFFontBlock( XclImpStream
& rStrm
);
104 /** Fills all font properties to the item set.
105 @param rItemSet The destination item set.
106 @param eType The type of Which-IDs.
107 @param bSkipPoolDefs true = Do not put items equal to pool default; false = Put all items. */
108 void FillToItemSet( SfxItemSet
& rItemSet
, XclFontItemType eType
,
109 bool bSkipPoolDefs
= false ) const;
110 /** Writes all font properties to the passed property set.
111 @param pFontColor If set, overrides internal stored font color. */
112 void WriteFontProperties( ScfPropertySet
& rPropSet
,
113 XclFontPropSetType eType
, const Color
* pFontColor
= nullptr ) const;
116 /** Reads and sets height and flags. */
117 void ReadFontData2( XclImpStream
& rStrm
);
118 /** Reads and sets height, flags, color, boldness, script, family and charset. */
119 void ReadFontData5( XclImpStream
& rStrm
);
121 /** Reads and sets the font color. */
122 void ReadFontColor( XclImpStream
& rStrm
);
124 /** Reads and sets a byte string as font name. */
125 void ReadFontName2( XclImpStream
& rStrm
);
126 /** Reads and sets a Unicode string as font name. */
127 void ReadFontName8( XclImpStream
& rStrm
);
129 /** Tests whether the font contains CJK or CTL characters.
130 @descr This is only a weak guess using preselected characters. */
131 void GuessScriptType();
134 XclFontData maData
; /// All font attributes.
135 bool mbHasCharSet
; /// true = Font contains own character set info.
136 bool mbHasWstrn
; /// true = Font contains Western script characters.
137 bool mbHasAsian
; /// true = Font contains Asian script characters.
138 bool mbHasCmplx
; /// true = Font contains Complex script characters.
139 bool mbFontNameUsed
; /// true = Font name, family, charset used.
140 bool mbHeightUsed
; /// true = Font height used.
141 bool mbColorUsed
; /// true = Color used.
142 bool mbWeightUsed
; /// true = Weight used.
143 bool mbEscapemUsed
; /// true = Escapement type used.
144 bool mbUnderlUsed
; /// true = Underline style used.
145 bool mbItalicUsed
; /// true = Italic used.
146 bool mbStrikeUsed
; /// true = Strikeout used.
147 bool mbOutlineUsed
; /// true = Outlined used.
148 bool mbShadowUsed
; /// true = Shadowed used.
151 /** Stores the data of all fonts occurred in an Excel file. */
152 class XclImpFontBuffer
: protected XclImpRoot
155 /** delete copy constructor */
156 XclImpFontBuffer(const XclImpFontBuffer
&) = delete;
157 /** delete copy-assignment operator */
158 const XclImpFontBuffer
& operator=(const XclImpFontBuffer
&) = delete;
160 explicit XclImpFontBuffer( const XclImpRoot
& rRoot
);
162 /** Clears all buffered data, used to set up for a new sheet. */
165 /** Returns the object that stores all contents of a FONT record. */
166 const XclImpFont
* GetFont( sal_uInt16 nFontIndex
) const;
167 /** Returns the application font data of this file, needed i.e. for column width. */
168 const XclFontData
& GetAppFontData() const { return maAppFont
; }
170 /** Reads a FONT record. */
171 void ReadFont( XclImpStream
& rStrm
);
172 /** Reads an EFONT record (BIFF2 font color). */
173 void ReadEfont( XclImpStream
& rStrm
);
175 /** Fills all font properties from a FONT record to the item set.
176 @param rItemSet The destination item set.
177 @param eType The type of Which-IDs.
178 @param nFontIdx The Excel index of the font.
179 @param bSkipPoolDefs true = Do not put items equal to pool default; false = Put all items. */
180 void FillToItemSet( SfxItemSet
& rItemSet
, XclFontItemType eType
,
181 sal_uInt16 nFontIdx
, bool bSkipPoolDefs
= false ) const;
182 /** Writes all font properties to the passed property set.
183 @param pFontColor If set, overrides internal stored font color. */
184 void WriteFontProperties(
185 ScfPropertySet
& rPropSet
, XclFontPropSetType eType
,
186 sal_uInt16 nFontIdx
, const Color
* pFontColor
= nullptr ) const;
187 /** Writes default font properties for form controls to the passed property set. */
188 void WriteDefaultCtrlFontProperties( ScfPropertySet
& rPropSet
) const;
191 /** Updates the application default font. */
192 void UpdateAppFont( const XclFontData
& rFontData
, bool bHasCharSet
);
195 std::vector
< XclImpFont
> maFontList
; /// List of all FONT records in the Excel file.
196 XclFontData maAppFont
; /// Application font (for column width).
197 XclImpFont maFont4
; /// Built-in font with index 4.
198 XclImpFont maCtrlFont
; /// BIFF5 default form controls font (Helv,8pt,bold).
201 // FORMAT record - number formats =============================================
203 /** Stores all user defined number formats occurred in the file. */
204 class XclImpNumFmtBuffer
: public XclNumFmtBuffer
, protected XclImpRoot
207 explicit XclImpNumFmtBuffer( const XclImpRoot
& rRoot
);
209 /** Clears all buffered data, used to set up for a new sheet. */
212 /** Reads a FORMAT record. */
213 void ReadFormat( XclImpStream
& rStrm
);
215 /** Read NumFmt from conditional format record */
216 sal_uInt16
ReadCFFormat( XclImpStream
& rStrm
, bool bIFmt
);
218 /** Creates the number formats in the Calc document. */
219 void CreateScFormats();
221 /** Returns the format key with the passed Excel index or NUMBERFORMAT_ENTRY_NOT_FOUND on error. */
222 sal_uInt32
GetScFormat( sal_uInt16 nXclNumFmt
) const;
224 /** Fills an Excel number format to the passed item set.
225 @param rItemSet The destination item set.
226 @param nXclNumFmt The Excel number format index.
227 @param bSkipPoolDefs true = Do not put items equal to pool default; false = Put all items. */
229 SfxItemSet
& rItemSet
, sal_uInt16 nXclNumFmt
,
230 bool bSkipPoolDefs
= false ) const;
231 /** Fills a Calc number format to the passed item set.
232 @param rItemSet The destination item set.
233 @param nScNumFmt The Calc number formatter index of the format.
234 @param bSkipPoolDefs true = Do not put items equal to pool default; false = Put all items. */
235 void FillScFmtToItemSet(
236 SfxItemSet
& rItemSet
, sal_uInt32 nScNumFmt
,
237 bool bSkipPoolDefs
= false ) const;
240 typedef ::std::map
< sal_uInt16
, sal_uLong
> XclImpIndexMap
;
242 XclImpIndexMap maIndexMap
; /// Maps Excel format indexes to Calc formats.
243 sal_uInt16 mnNextXclIdx
; /// Index counter for BIFF2-BIFF4.
246 // XF, STYLE record - Cell formatting =========================================
248 /** Extends the XclCellProt struct for import.
249 @descr Provides functions to fill from Excel record data and to fill to item sets. */
250 struct XclImpCellProt
: public XclCellProt
252 /** Fills this struct with BIFF2 XF record data. */
253 void FillFromXF2( sal_uInt8 nNumFmt
);
254 /** Fills this struct with BIFF3-BIFF8 XF record data. */
255 void FillFromXF3( sal_uInt16 nProt
);
257 /** Inserts items representing this protection style into the item set.
258 @param bSkipPoolDefs true = Do not put items equal to pool default; false = Put all items. */
259 void FillToItemSet( SfxItemSet
& rItemSet
, bool bSkipPoolDefs
= false ) const;
262 /** Extends the XclCellAlign struct for import.
263 @descr Provides functions to fill from Excel record data and to fill to item sets. */
264 struct XclImpCellAlign
: public XclCellAlign
266 /** Fills this struct with BIFF2 XF record data. */
267 void FillFromXF2( sal_uInt8 nFlags
);
268 /** Fills this struct with BIFF3 XF record data. */
269 void FillFromXF3( sal_uInt16 nAlign
);
270 /** Fills this struct with BIFF4 XF record data. */
271 void FillFromXF4( sal_uInt16 nAlign
);
272 /** Fills this struct with BIFF5/BIFF7 XF record data. */
273 void FillFromXF5( sal_uInt16 nAlign
);
274 /** Fills this struct with BIFF8 XF record data. */
275 void FillFromXF8( sal_uInt16 nAlign
, sal_uInt16 nMiscAttrib
);
276 /** Fills this struct with CF record data. */
277 void FillFromCF( sal_uInt16 nAlign
, sal_uInt16 nMiscAttrib
);
279 /** Inserts items representing this alignment style into the item set.
280 @param bSkipPoolDefs true = Do not put items equal to pool default; false = Put all items. */
281 void FillToItemSet( SfxItemSet
& rItemSet
, const XclImpFont
* pFont
, bool bSkipPoolDefs
= false ) const;
284 /** Extends the XclCellBorder struct for import.
285 @descr Provides functions to fill from Excel record data and to fill to item sets. */
286 struct XclImpCellBorder
: public XclCellBorder
288 bool mbLeftUsed
; /// true = Left line style used.
289 bool mbRightUsed
; /// true = Right line style used.
290 bool mbTopUsed
; /// true = Top line style used.
291 bool mbBottomUsed
; /// true = Bottom line style used.
292 bool mbDiagUsed
; /// true = Diagonal line style used.
294 explicit XclImpCellBorder();
296 /** Sets outer line states and diagonal line states to used or unused. */
297 void SetUsedFlags( bool bOuterUsed
, bool bDiagUsed
);
299 /** Fills this struct with BIFF2 XF record data. */
300 void FillFromXF2( sal_uInt8 nFlags
);
301 /** Fills this struct with BIFF3/BIFF4 XF record data. */
302 void FillFromXF3( sal_uInt32 nBorder
);
303 /** Fills this struct with BIFF5/BIFF7 XF record data. */
304 void FillFromXF5( sal_uInt32 nBorder
, sal_uInt32 nArea
);
305 /** Fills this struct with BIFF8 XF record data. */
306 void FillFromXF8( sal_uInt32 nBorder1
, sal_uInt32 nBorder2
);
308 /** Fills this struct with BIFF8 CF (conditional format) record data. */
309 void FillFromCF8( sal_uInt16 nLineStyle
, sal_uInt32 nLineColor
, sal_uInt32 nFlags
);
311 /** Returns true, if any of the outer border lines is visible. */
312 bool HasAnyOuterBorder() const;
314 /** Inserts a box item representing this border style into the item set.
315 @param bSkipPoolDefs true = Do not put items equal to pool default; false = Put all items. */
317 SfxItemSet
& rItemSet
,
318 const XclImpPalette
& rPalette
,
319 bool bSkipPoolDefs
= false ) const;
322 /** Extends the XclCellArea struct for import.
323 @descr Provides functions to fill from Excel record data and to fill to item sets. */
324 struct XclImpCellArea
: public XclCellArea
326 bool mbForeUsed
; /// true = Foreground color used.
327 bool mbBackUsed
; /// true = Background color used.
328 bool mbPattUsed
; /// true = Pattern used.
330 explicit XclImpCellArea();
332 /** Sets colors and pattern state to used or unused. */
333 void SetUsedFlags( bool bUsed
);
335 /** Fills this struct with BIFF2 XF record data. */
336 void FillFromXF2( sal_uInt8 nFlags
);
337 /** Fills this struct with BIFF3/BIFF4 XF record data. */
338 void FillFromXF3( sal_uInt16 nArea
);
339 /** Fills this struct with BIFF5/BIFF7 XF record data. */
340 void FillFromXF5( sal_uInt32 nArea
);
341 /** Fills this struct with BIFF8 XF record data. */
342 void FillFromXF8( sal_uInt32 nBorder2
, sal_uInt16 nArea
);
344 /** Fills this struct with BIFF8 CF (conditional format) record data. */
345 void FillFromCF8( sal_uInt16 nPattern
, sal_uInt16 nColor
, sal_uInt32 nFlags
);
347 /** Inserts a brush item representing this area style into the item set.
348 @param bSkipPoolDefs true = Do not put items equal to pool default; false = Put all items. */
350 SfxItemSet
& rItemSet
,
351 const XclImpPalette
& rPalette
,
352 bool bSkipPoolDefs
= false ) const;
355 /** Represents an XF record index with additional information. */
359 explicit XclImpXFIndex( sal_uInt16 nXFIndex
, bool bBoolCell
= false ) :
360 mnXFIndex( nXFIndex
), mbBoolCell( bBoolCell
) {}
362 sal_uInt16
GetXFIndex() const { return mnXFIndex
; }
363 bool IsBoolCell() const { return mbBoolCell
; }
366 sal_uInt16 mnXFIndex
; /// The XF record index.
367 bool mbBoolCell
; /// true = A Boolean value cell.
370 inline bool operator==( const XclImpXFIndex
& rLeft
, const XclImpXFIndex
& rRight
)
371 { return (rLeft
.GetXFIndex() == rRight
.GetXFIndex()) && (rLeft
.IsBoolCell() == rRight
.IsBoolCell()); }
373 inline bool operator!=( const XclImpXFIndex
& rLeft
, const XclImpXFIndex
& rRight
)
374 { return !(rLeft
== rRight
); }
376 /** Contains all data of a XF record and a Calc item set. */
377 class XclImpXF
: public XclXFBase
, protected XclImpRoot
380 /** make noncopyable */
381 XclImpXF(const XclImpXF
&) = delete;
382 const XclImpXF
& operator=(const XclImpXF
&) = delete;
384 explicit XclImpXF( const XclImpRoot
& rRoot
);
385 virtual ~XclImpXF() override
;
387 /** Reads an XF record. */
388 void ReadXF( XclImpStream
& rStrm
);
390 sal_uInt8
GetHorAlign() const { return maAlignment
.mnHorAlign
; }
391 sal_uInt16
GetFontIndex() const { return mnXclFont
; }
393 /** Creates a Calc item set containing an item set with all cell properties.
394 @param bSkipPoolDefs true = Do not put items equal to pool default; false = Put all items.
395 @return A read-only reference to the item set stored internally. */
396 const ScPatternAttr
& CreatePattern( bool bSkipPoolDefs
= false );
398 void ApplyPatternToAttrVector(
399 ::std::vector
<ScAttrEntry
>& rAttrs
, SCROW nRow1
, SCROW nRow2
,
400 sal_uInt32 nForceScNumFmt
);
402 /** Inserts all formatting attributes to the specified area in the Calc document.
403 @param nForcedNumFmt If not set to NUMBERFORMAT_ENTRY_NOT_FOUND, it will overwrite
404 the number format of the XF. */
406 SCCOL nScCol1
, SCROW nScRow1
,
407 SCCOL nScCol2
, SCROW nScRow2
,
410 /** Converts formatting information from BIFF2 cell record data directly. */
411 static void ApplyPatternForBiff2CellFormat(
412 const XclImpRoot
& rRoot
, const ScAddress
& rScPos
,
413 sal_uInt8 nFlags1
, sal_uInt8 nFlags2
, sal_uInt8 nFlags3
);
416 void ReadXF2( XclImpStream
& rStrm
);
417 void ReadXF3( XclImpStream
& rStrm
);
418 void ReadXF4( XclImpStream
& rStrm
);
419 void ReadXF5( XclImpStream
& rStrm
);
420 void ReadXF8( XclImpStream
& rStrm
);
422 /** Sets all "attribute used" flags according to the passed mask.
423 @descr In cell XFs, a set bit represents "used", in style XFs it is a cleared bit.
424 Therefore mbCellXF must be set correctly before calling this method. */
425 void SetUsedFlags( sal_uInt8 nUsedFlags
);
428 typedef ::std::unique_ptr
< ScPatternAttr
> ScPatternAttrPtr
;
430 ScPatternAttrPtr mpPattern
; /// Calc item set.
431 ScStyleSheet
* mpStyleSheet
; /// Calc cell style sheet.
433 XclImpCellProt maProtection
; /// Cell protection flags.
434 XclImpCellAlign maAlignment
; /// All alignment attributes.
435 XclImpCellBorder maBorder
; /// Border line style.
436 XclImpCellArea maArea
; /// Background area style.
437 sal_uInt16 mnXclNumFmt
; /// Index to number format.
438 sal_uInt16 mnXclFont
; /// Index to font record.
441 /** Contains all data of a cell style associated with an XF record. */
442 class XclImpStyle
: protected XclImpRoot
445 explicit XclImpStyle( const XclImpRoot
& rRoot
);
447 /** Reads a STYLE record. */
448 void ReadStyle( XclImpStream
& rStrm
);
450 const OUString
& GetName() const { return maName
; }
451 sal_uInt16
GetXfId() const { return mnXfId
; }
452 bool IsBuiltin() const { return mbBuiltin
&& (mnBuiltinId
!= EXC_STYLE_USERDEF
); }
453 sal_uInt8
GetBuiltinId() const { return mnBuiltinId
; }
454 sal_uInt8
GetLevel() const { return mnLevel
; }
456 /** Creates a cell style sheet and inserts it into the Calc document.
457 @return The pointer to the cell style sheet, or 0, if there is no style sheet. */
458 ScStyleSheet
* CreateStyleSheet();
459 /** Creates the Calc style sheet, if this is a user-defined style. */
460 void CreateUserStyle( const OUString
& rFinalName
);
463 OUString maName
; /// Cell style name.
464 sal_uInt16 mnXfId
; /// Formatting for this cell style.
465 sal_uInt8 mnBuiltinId
; /// Identifier for builtin styles.
466 sal_uInt8 mnLevel
; /// Level for builtin column/row styles.
467 bool mbBuiltin
; /// True = builtin style.
468 bool mbCustom
; /// True = customized builtin style.
469 bool mbHidden
; /// True = style not visible in GUI.
471 OUString maFinalName
; /// Final name used in the Calc document.
472 ScStyleSheet
* mpStyleSheet
; /// Calc cell style sheet.
475 /** Contains all XF records occurred in the file.
476 @descr This class is able to read XF records (BIFF2 - BIFF8) and STYLE records (BIFF8). */
477 class XclImpXFBuffer
: protected XclImpRoot
480 /** make noncopyable */
481 XclImpXFBuffer(const XclImpXFBuffer
&) = delete;
482 const XclImpXFBuffer
& operator=(const XclImpXFBuffer
&) = delete;
484 explicit XclImpXFBuffer( const XclImpRoot
& rRoot
);
486 /** Clears all buffered data, used to set up for a new sheet. */
489 /** Reads an XF record. */
490 void ReadXF( XclImpStream
& rStrm
);
491 /** Reads a STYLE record. */
492 void ReadStyle( XclImpStream
& rStrm
);
494 /** Returns the object that stores all contents of an XF record. */
495 XclImpXF
* GetXF( sal_uInt16 nXFIndex
)
496 { return (nXFIndex
>= maXFList
.size()) ? nullptr : maXFList
.at(nXFIndex
).get(); }
498 const XclImpXF
* GetXF( sal_uInt16 nXFIndex
) const
499 { return (nXFIndex
>= maXFList
.size()) ? nullptr : maXFList
.at(nXFIndex
).get(); }
501 /** Returns the index to the Excel font used in the specified XF record. */
502 sal_uInt16
GetFontIndex( sal_uInt16 nXFIndex
) const;
503 /** Returns the Excel font used in the specified XF record. */
504 const XclImpFont
* GetFont( sal_uInt16 nXFIndex
) const;
506 /** Creates all user defined style sheets. */
507 void CreateUserStyles();
508 /** Creates a cell style sheet of the passed XF and inserts it into the Calc document.
509 @return The pointer to the cell style sheet, or 0, if there is no style sheet. */
510 ScStyleSheet
* CreateStyleSheet( sal_uInt16 nXFIndex
);
513 typedef std::vector
< std::unique_ptr
<XclImpStyle
> > XclImpStyleList
;
514 typedef ::std::map
< sal_uInt16
, XclImpStyle
* > XclImpStyleMap
;
516 std::vector
< std::unique_ptr
<XclImpXF
> > maXFList
; /// List of contents of all XF record.
517 XclImpStyleList maBuiltinStyles
; /// List of built-in cell styles.
518 XclImpStyleList maUserStyles
; /// List of user defined cell styles.
519 XclImpStyleMap maStylesByXf
; /// Maps XF records to cell styles.
522 // Buffer for XF indexes in cells =============================================
524 /** Contains an (encoded) XF index for a range of rows in a single column. */
528 SCROW mnScRow1
; /// The first row of an equal-formatted range.
529 SCROW mnScRow2
; /// The last row of an equal-formatted range.
530 XclImpXFIndex maXFIndex
; /// Extended XF index.
532 inline explicit XclImpXFRange( SCROW nScRow
, const XclImpXFIndex
& rXFIndex
);
533 inline explicit XclImpXFRange( SCROW nFirstScRow
, SCROW nLastScRow
, const XclImpXFIndex
& rXFIndex
);
535 /** Returns true, if nScRow is contained in own row range. */
536 inline bool Contains( SCROW nScRow
) const;
538 /** Returns true, if the range has been expanded. */
539 bool Expand( SCROW nScRow
, const XclImpXFIndex
& rXFIndex
);
540 /** Returns true, if the range has been expanded. */
541 bool Expand( const XclImpXFRange
& rNextRange
);
544 inline XclImpXFRange::XclImpXFRange( SCROW nScRow
, const XclImpXFIndex
& rXFIndex
) :
547 maXFIndex( rXFIndex
)
551 inline XclImpXFRange::XclImpXFRange( SCROW nFirstScRow
, SCROW nLastScRow
, const XclImpXFIndex
& rXFIndex
) :
552 mnScRow1( nFirstScRow
),
553 mnScRow2( nLastScRow
),
554 maXFIndex( rXFIndex
)
558 inline bool XclImpXFRange::Contains( SCROW nScRow
) const
560 return (mnScRow1
<= nScRow
) && (nScRow
<= mnScRow2
);
563 /** Contains the XF indexes for every used cell in a column. */
564 class XclImpXFRangeColumn
567 /** make noncopyable */
568 XclImpXFRangeColumn(const XclImpXFRangeColumn
&) = delete;
569 const XclImpXFRangeColumn
& operator=(const XclImpXFRangeColumn
&) = delete;
571 typedef std::vector
< std::unique_ptr
<XclImpXFRange
> > IndexList
;
573 explicit XclImpXFRangeColumn() {}
575 IndexList::iterator
begin() { return maIndexList
.begin(); }
576 IndexList::iterator
end() { return maIndexList
.end(); }
578 /** Inserts a single row range into the list. */
579 void SetDefaultXF( const XclImpXFIndex
& rXFIndex
, const XclImpRoot
& rRoot
);
581 /** Inserts a new (encoded) XF index (first try to expand the last range). */
582 void SetXF( SCROW nScRow
, const XclImpXFIndex
& rXFIndex
);
585 /** Finds the previous and next row range from row position nScRow.
586 @descr If an XF still exists, it is contained in rpPrevRange. */
588 XclImpXFRange
*& rpPrevRange
,
589 XclImpXFRange
*& rpNextRange
,
590 sal_uLong
& rnNextIndex
,
593 /** Tries to concatenate a range with its predecessor.
594 @descr The ranges must have the same XF index and must not have a gap.
595 The resulting range has the index nIndex-1. */
596 void TryConcatPrev( sal_uLong nIndex
);
598 /** Insert a range into the list at the specified index. */
599 void Insert(XclImpXFRange
* pXFRange
, sal_uLong nIndex
);
602 IndexList maIndexList
; /// The list of XF index range.
605 /** Contains the XF indexes for every used cell in a single sheet. */
606 class XclImpXFRangeBuffer
: protected XclImpRoot
609 /** make noncopyable */
610 XclImpXFRangeBuffer(const XclImpXFRangeBuffer
&) = delete;
611 const XclImpXFRangeBuffer
& operator=(const XclImpXFRangeBuffer
&) = delete;
613 explicit XclImpXFRangeBuffer( const XclImpRoot
& rRoot
);
614 virtual ~XclImpXFRangeBuffer() override
;
616 /** Clears all buffered data, used to set up for a new sheet. */
619 /** Inserts a new XF index. */
620 void SetXF( const ScAddress
& rScPos
, sal_uInt16 nXFIndex
);
621 /** Inserts a new XF index for blank cells. */
622 void SetBlankXF( const ScAddress
& rScPos
, sal_uInt16 nXFIndex
);
623 /** Inserts a new XF index for boolean cells. */
624 void SetBoolXF( const ScAddress
& rScPos
, sal_uInt16 nXFIndex
);
625 /** Inserts a new XF index for all cells in a row. */
626 void SetRowDefXF( SCROW nScRow
, sal_uInt16 nXFIndex
);
627 /** Inserts a new XF index for all cells in a column. */
628 void SetColumnDefXF( SCCOL nScCol
, sal_uInt16 nXFIndex
);
630 /** Inserts a range of hyperlink cells. */
631 void SetHyperlink( const XclRange
& rXclRange
, const OUString
& rUrl
);
633 /** Inserts a complete merged cell range. */
634 void SetMerge( SCCOL nScCol1
, SCROW nScRow1
, SCCOL nScCol2
, SCROW nScRow2
);
636 /** Applies styles and cell merging to the current sheet in the document. */
640 /** Insertion mode of an XF index. */
641 enum XclImpXFInsertMode
643 xlXFModeCell
, /// Filled cell.
644 xlXFModeBoolCell
, /// Cell with a single Boolean value.
645 xlXFModeBlank
, /// Blank cell.
646 xlXFModeRow
/// Row default XF.
650 /** Inserts a new XF index for the specified cell type. */
651 void SetXF( const ScAddress
& rScPos
, sal_uInt16 nXFIndex
, XclImpXFInsertMode eMode
);
653 /** Copies border of the last cell of the range to the first cell to keep it visible
654 when the range is merged.
656 SvxBoxItemLine::RIGHT = copy most-right border of top row;
657 SvxBoxItemLine::BOTTOM = copy most-bottom border of first column. */
658 void SetBorderLine( const ScRange
& rRange
, SCTAB nScTab
, SvxBoxItemLine nLine
);
662 std::vector
< std::shared_ptr
< XclImpXFRangeColumn
> >
663 maColumns
; /// Array of column XF index buffers.
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: */